btrfs-progs: Dont' stop scanning of devices at first failed device
authorYauhen Kharuzhy <yauhen.kharuzhy@zavadatar.com>
Fri, 11 Mar 2016 00:04:35 +0000 (16:04 -0800)
committerDavid Sterba <dsterba@suse.com>
Mon, 14 Mar 2016 12:42:47 +0000 (13:42 +0100)
When 'btrfs device scan' command is invoked, it scans all devices,
check them for btrfs superblock and add devices with btrfs to a list.

Next, each device from the list is passed to kernel where it is handled
in the btrfs_scan_one_device() function. This function can, for example,
return -EBUSY when device contains superblock matched to existing and
mounted filesystem (if this device was pulled out from RAID and
connected again after some time).

btrfs tool stops device scan if any device has been failed to add, so
other existing devices with (possibly) valid FS will never be reached.

Fix this by remove stopping at any failure in the btrfs_register_all_devices(),
just return error count. btrfs_scan_one_device() reports any kind of
error already.

Signed-off-by: Yauhen Kharuzhy <yauhen.kharuzhy@zavadatar.com>
[ initialize err to 0 ]
Signed-off-by: David Sterba <dsterba@suse.com>
cmds-device.c
utils.c

index fff05e4..a8f10f6 100644 (file)
@@ -254,7 +254,7 @@ static int cmd_device_scan(int argc, char **argv)
                ret = btrfs_scan_lblkid();
                error_on(ret, "error %d while scanning", ret);
                ret = btrfs_register_all_devices();
-               error_on(ret, "error %d while registering devices", ret);
+               error_on(ret, "there are %d errors while registering devices", ret);
                goto out;
        }
 
diff --git a/utils.c b/utils.c
index 7d5537f..d7ceaa8 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -1545,7 +1545,8 @@ int btrfs_register_one_device(const char *fname)
  */
 int btrfs_register_all_devices(void)
 {
-       int err;
+       int err = 0;
+       int ret = 0;
        struct btrfs_fs_devices *fs_devices;
        struct btrfs_device *device;
        struct list_head *all_uuids;
@@ -1554,16 +1555,15 @@ int btrfs_register_all_devices(void)
 
        list_for_each_entry(fs_devices, all_uuids, list) {
                list_for_each_entry(device, &fs_devices->devices, dev_list) {
-                       if (*device->name) {
+                       if (*device->name)
                                err = btrfs_register_one_device(device->name);
-                               if (err < 0)
-                                       return err;
-                               if (err > 0)
-                                       return -err;
-                       }
+
+                       if (err)
+                               ret++;
                }
        }
-       return 0;
+
+       return ret;
 }
 
 int btrfs_device_already_in_root(struct btrfs_root *root, int fd,