From e7c4e700ffa656af4b221a2068b02b391b0ed817 Mon Sep 17 00:00:00 2001 From: Gui Hecheng Date: Thu, 30 Oct 2014 10:44:49 +0800 Subject: btrfs-progs: make the search target device routine more clear for fi show Extract the procedure of searching for a target device for fi show from the @map_seed_devices() function to make it more clear. Signed-off-by: Gui Hecheng Signed-off-by: David Sterba --- cmds-filesystem.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'cmds-filesystem.c') diff --git a/cmds-filesystem.c b/cmds-filesystem.c index 0bf24ffb..f16e5869 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -713,14 +713,10 @@ static int find_and_copy_seed(struct btrfs_fs_devices *seed, return 1; } -static int map_seed_devices(struct list_head *all_uuids, - char *search, int *found) +static int search_umounted_fs_uuids(struct list_head *all_uuids, + char *search) { - struct btrfs_fs_devices *cur_fs, *cur_seed; - struct btrfs_fs_devices *fs_copy, *seed_copy; - struct btrfs_fs_devices *opened_fs; - struct btrfs_device *device; - struct btrfs_fs_info *fs_info; + struct btrfs_fs_devices *cur_fs, *fs_copy; struct list_head *fs_uuids; int ret = 0; @@ -735,7 +731,7 @@ static int map_seed_devices(struct list_head *all_uuids, if (search) { if (uuid_search(cur_fs, search) == 0) continue; - *found = 1; + ret = 1; } /* skip all fs already shown as mounted fs */ @@ -757,6 +753,22 @@ static int map_seed_devices(struct list_head *all_uuids, list_add(&fs_copy->list, all_uuids); } +out: + return ret; +} + +static int map_seed_devices(struct list_head *all_uuids) +{ + struct btrfs_fs_devices *cur_fs, *cur_seed; + struct btrfs_fs_devices *seed_copy; + struct btrfs_fs_devices *opened_fs; + struct btrfs_device *device; + struct btrfs_fs_info *fs_info; + struct list_head *fs_uuids; + int ret = 0; + + fs_uuids = btrfs_scanned_uuids(); + list_for_each_entry(cur_fs, all_uuids, list) { device = list_first_entry(&cur_fs->devices, struct btrfs_device, dev_list); @@ -924,11 +936,18 @@ devs_only: return 1; } + found = search_umounted_fs_uuids(&all_uuids, search); + if (found < 0) { + fprintf(stderr, + "ERROR: %d while searching target device\n", ret); + return 1; + } + /* * scan_for_btrfs() don't build seed/sprout mapping, * do mapping build for each scanned fs here */ - ret = map_seed_devices(&all_uuids, search, &found); + ret = map_seed_devices(&all_uuids); if (ret) { fprintf(stderr, "ERROR: %d while mapping seed devices\n", ret); -- cgit v1.2.3