summaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2012-02-21 15:56:10 -0500
committerChris Mason <chris.mason@oracle.com>2012-02-22 10:59:55 -0500
commit8f01235dd8cf65c064f1b979d24a989ca296ea33 (patch)
treebd261d82575a8659d30dc1e97dc8e70049679a72 /utils.c
parent32eff71182a6aff67324357572308c225b2d5e34 (diff)
Scan /dev/md and device mapper devices last
When we're using multipath or raid0, it is possible that btrfs dev scan will find one of the component devices instead of the proper virtual device the kernel creates. We want to make sure the kernel scans the virtual devices last, since it always remembers the last device it finds with a given fsid. Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/utils.c b/utils.c
index f0dd5270..ee7fa1b8 100644
--- a/utils.c
+++ b/utils.c
@@ -1138,7 +1138,10 @@ int btrfs_scan_block_devices(int run_ioctl)
int i;
char buf[1024];
char fullpath[110];
+ int scans = 0;
+ int special;
+scan_again:
proc_partitions = fopen("/proc/partitions","r");
if (!proc_partitions) {
fprintf(stderr, "Unable to open '/proc/partitions' for scanning\n");
@@ -1154,8 +1157,23 @@ int btrfs_scan_block_devices(int run_ioctl)
strcpy(fullpath,"/dev/");
while(fgets(buf, 1023, proc_partitions)) {
-
i = sscanf(buf," %*d %*d %*d %99s", fullpath+5);
+
+ /*
+ * multipath and MD devices may register as a btrfs filesystem
+ * both through the original block device and through
+ * the special (/dev/mapper or /dev/mdX) entry.
+ * This scans the special entries last
+ */
+ special = strncmp(fullpath, "/dev/dm-", strlen("/dev/dm-")) == 0;
+ if (!special)
+ special = strncmp(fullpath, "/dev/md", strlen("/dev/md")) == 0;
+
+ if (scans == 0 && special)
+ continue;
+ if (scans > 0 && !special)
+ continue;
+
ret = lstat(fullpath, &st);
if (ret < 0) {
fprintf(stderr, "failed to stat %s\n", fullpath);
@@ -1180,6 +1198,11 @@ int btrfs_scan_block_devices(int run_ioctl)
}
fclose(proc_partitions);
+
+ if (scans == 0) {
+ scans++;
+ goto scan_again;
+ }
return 0;
}