mirror of
https://github.com/kdave/btrfs-progs
synced 2025-05-03 00:17:55 +00:00
Btrfs-progs: move printing subvol list outside of btrfs_list_subvols
To improve the code reuse its better to have btrfs_list_subvols just return list of subvols witout printing Signed-off-by: Anand Jain <anand.jain@oracle.com>
This commit is contained in:
parent
8c2b1be428
commit
93b3fd3879
30
btrfs-list.c
30
btrfs-list.c
@ -1453,16 +1453,11 @@ static void print_all_volume_info(struct root_lookup *sorted_tree,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int btrfs_list_subvols(int fd, struct btrfs_list_filter_set *filter_set,
|
int btrfs_list_subvols(int fd, struct root_lookup *root_lookup)
|
||||||
struct btrfs_list_comparer_set *comp_set,
|
|
||||||
int is_tab_result, int full_path)
|
|
||||||
{
|
{
|
||||||
struct root_lookup root_lookup;
|
|
||||||
struct root_lookup root_sort;
|
|
||||||
int ret;
|
int ret;
|
||||||
u64 top_id = (full_path ? 0 : btrfs_list_get_path_rootid(fd));
|
|
||||||
|
|
||||||
ret = __list_subvol_search(fd, &root_lookup);
|
ret = __list_subvol_search(fd, root_lookup);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
fprintf(stderr, "ERROR: can't perform the search - %s\n",
|
fprintf(stderr, "ERROR: can't perform the search - %s\n",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
@ -1473,16 +1468,29 @@ int btrfs_list_subvols(int fd, struct btrfs_list_filter_set *filter_set,
|
|||||||
* now we have an rbtree full of root_info objects, but we need to fill
|
* now we have an rbtree full of root_info objects, but we need to fill
|
||||||
* in their path names within the subvol that is referencing each one.
|
* in their path names within the subvol that is referencing each one.
|
||||||
*/
|
*/
|
||||||
ret = __list_subvol_fill_paths(fd, &root_lookup);
|
ret = __list_subvol_fill_paths(fd, root_lookup);
|
||||||
if (ret < 0)
|
return ret;
|
||||||
return ret;
|
}
|
||||||
|
|
||||||
|
int btrfs_list_subvols_print(int fd, struct btrfs_list_filter_set *filter_set,
|
||||||
|
struct btrfs_list_comparer_set *comp_set,
|
||||||
|
int is_tab_result, int full_path)
|
||||||
|
{
|
||||||
|
struct root_lookup root_lookup;
|
||||||
|
struct root_lookup root_sort;
|
||||||
|
int ret;
|
||||||
|
u64 top_id = (full_path ? 0 : btrfs_list_get_path_rootid(fd));
|
||||||
|
|
||||||
|
ret = btrfs_list_subvols(fd, &root_lookup);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
__filter_and_sort_subvol(&root_lookup, &root_sort, filter_set,
|
__filter_and_sort_subvol(&root_lookup, &root_sort, filter_set,
|
||||||
comp_set, top_id);
|
comp_set, top_id);
|
||||||
|
|
||||||
print_all_volume_info(&root_sort, is_tab_result);
|
print_all_volume_info(&root_sort, is_tab_result);
|
||||||
__free_all_subvolumn(&root_lookup);
|
__free_all_subvolumn(&root_lookup);
|
||||||
return ret;
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int print_one_extent(int fd, struct btrfs_ioctl_search_header *sh,
|
static int print_one_extent(int fd, struct btrfs_ioctl_search_header *sh,
|
||||||
|
@ -99,7 +99,7 @@ int btrfs_list_setup_comparer(struct btrfs_list_comparer_set **comp_set,
|
|||||||
enum btrfs_list_comp_enum comparer,
|
enum btrfs_list_comp_enum comparer,
|
||||||
int is_descending);
|
int is_descending);
|
||||||
|
|
||||||
int btrfs_list_subvols(int fd, struct btrfs_list_filter_set *filter_set,
|
int btrfs_list_subvols_print(int fd, struct btrfs_list_filter_set *filter_set,
|
||||||
struct btrfs_list_comparer_set *comp_set,
|
struct btrfs_list_comparer_set *comp_set,
|
||||||
int is_tab_result, int full_path);
|
int is_tab_result, int full_path);
|
||||||
int btrfs_list_find_updated_files(int fd, u64 root_id, u64 oldest_gen);
|
int btrfs_list_find_updated_files(int fd, u64 root_id, u64 oldest_gen);
|
||||||
|
@ -418,7 +418,7 @@ static int cmd_subvol_list(int argc, char **argv)
|
|||||||
BTRFS_LIST_FILTER_TOPID_EQUAL,
|
BTRFS_LIST_FILTER_TOPID_EQUAL,
|
||||||
top_id);
|
top_id);
|
||||||
|
|
||||||
ret = btrfs_list_subvols(fd, filter_set, comparer_set,
|
ret = btrfs_list_subvols_print(fd, filter_set, comparer_set,
|
||||||
is_tab_result,
|
is_tab_result,
|
||||||
!is_list_all && !is_only_in_path);
|
!is_list_all && !is_only_in_path);
|
||||||
if (ret)
|
if (ret)
|
||||||
@ -626,7 +626,7 @@ static int cmd_subvol_get_default(int argc, char **argv)
|
|||||||
btrfs_list_setup_filter(&filter_set, BTRFS_LIST_FILTER_ROOTID,
|
btrfs_list_setup_filter(&filter_set, BTRFS_LIST_FILTER_ROOTID,
|
||||||
default_id);
|
default_id);
|
||||||
|
|
||||||
ret = btrfs_list_subvols(fd, filter_set, NULL, 0, 1);
|
ret = btrfs_list_subvols_print(fd, filter_set, NULL, 0, 1);
|
||||||
if (ret)
|
if (ret)
|
||||||
return 19;
|
return 19;
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user