diff mbox

[1/2] btrfs-progs: btrfs_scan_one_dir not to skip links when /dev/mapper is provided

Message ID 1375949368-23798-2-git-send-email-anand.jain@oracle.com (mailing list archive)
State Under Review, archived
Headers show

Commit Message

Anand Jain Aug. 8, 2013, 8:09 a.m. UTC
This is preparatory work to introduce /dev/mapper path usage

we need btrfs_scan_one_dir to san devs under /dev/mapper,
but /dev/mapper has links to the actual devs and current implementation
of btrfs_scan_one_dir skips links so it does not pick any
dev under /dev/mapper. skip the links are fine when scanning whole of
/dev But not when we just want to scan /dev/mapper

This patch just adds to check if we are scanning devs or
/dev/mapper only, if when latter it will not skip links

Thanks

v2: changes as per David review

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 utils.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/utils.c b/utils.c
index 8a57967..038e599 100644
--- a/utils.c
+++ b/utils.c
@@ -1039,13 +1039,26 @@  int btrfs_scan_one_dir(char *dirname, int run_ioctl)
 	struct list_head pending_list;
 	struct btrfs_fs_devices *tmp_devices;
 	u64 num_devices;
+	int skip_link = 1;
+	char rdir[PATH_MAX];
+	char rdirp = NULL;
 
 	INIT_LIST_HEAD(&pending_list);
 
 	pending = malloc(sizeof(*pending));
 	if (!pending)
 		return -ENOMEM;
-	strcpy(pending->name, dirname);
+
+	rdirp = realpath(dirname, rdir);
+	if (!rdirp) {
+		free(pending);
+		return -errno;
+	}
+
+	strcpy(pending->name, rdir);
+
+	if (!strcmp(rdir, "/dev/mapper"))
+		skip_link = 0;
 
 again:
 	dirname_len = strlen(pending->name);
@@ -1078,7 +1091,7 @@  again:
 			fprintf(stderr, "failed to stat %s\n", fullpath);
 			continue;
 		}
-		if (S_ISLNK(st.st_mode))
+		if (skip_link && S_ISLNK(st.st_mode))
 			continue;
 		if (S_ISDIR(st.st_mode)) {
 			struct pending_dir *next = malloc(sizeof(*next));
@@ -1089,7 +1102,7 @@  again:
 			strcpy(next->name, fullpath);
 			list_add_tail(&next->list, &pending_list);
 		}
-		if (!S_ISBLK(st.st_mode)) {
+		if (skip_link && !S_ISBLK(st.st_mode)) {
 			continue;
 		}
 		fd = open(fullpath, O_RDONLY);