btrfs-progs: skip fs with no seed when build seed/sprout mapping for fi show
authorGui Hecheng <guihc.fnst@cn.fujitsu.com>
Tue, 11 Nov 2014 06:39:14 +0000 (14:39 +0800)
committerDavid Sterba <dsterba@suse.cz>
Thu, 4 Dec 2014 15:48:13 +0000 (16:48 +0100)
There is no need to try to build seed/sprout mapping for those btrfs
without seed devices, so just skip such fs.
We could get the total number of devices from the disk super block, if it
equals the number of items in list @fs_devices->devices, then there shouldn't
be any seed devices.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
cmds-filesystem.c

index f16e586..7eaccb9 100644 (file)
@@ -713,6 +713,22 @@ static int find_and_copy_seed(struct btrfs_fs_devices *seed,
        return 1;
 }
 
+static int has_seed_devices(struct btrfs_fs_devices *fs_devices)
+{
+       struct btrfs_device *device;
+       int dev_cnt_total, dev_cnt = 0;
+
+       device = list_first_entry(&fs_devices->devices, struct btrfs_device,
+                                 dev_list);
+
+       dev_cnt_total = device->total_devs;
+
+       list_for_each_entry(device, &fs_devices->devices, dev_list)
+               dev_cnt++;
+
+       return dev_cnt_total != dev_cnt;
+}
+
 static int search_umounted_fs_uuids(struct list_head *all_uuids,
                                    char *search)
 {
@@ -774,6 +790,11 @@ static int map_seed_devices(struct list_head *all_uuids)
                                                struct btrfs_device, dev_list);
                if (!device)
                        continue;
+
+               /* skip fs without seeds */
+               if (!has_seed_devices(cur_fs))
+                       continue;
+
                /*
                 * open_ctree_* detects seed/sprout mapping
                 */
@@ -944,8 +965,8 @@ devs_only:
        }
 
        /*
-        * scan_for_btrfs() don't build seed/sprout mapping,
-        * do mapping build for each scanned fs here
+        * The seed/sprout mapping are not detected yet,
+        * do mapping build for all umounted fs
         */
        ret = map_seed_devices(&all_uuids);
        if (ret) {