On 2018年03月08日 10:40, jeffm@xxxxxxxx wrote:
> From: Jeff Mahoney <jeffm@xxxxxxxx>
>
> The btrfs qgroup show command currently only exports qgroup IDs,
> forcing the user to resolve which subvolume each corresponds to.
>
> This patch adds pathname resolution to qgroup show so that when
> the -P option is used, the last column contains the pathname of
> the root of the subvolume it describes. In the case of nested
> qgroups, it will show the number of member qgroups or the paths
> of the members if the -v option is used.
>
> Pathname can also be used as a sort parameter.
>
> Signed-off-by: Jeff Mahoney <jeffm@xxxxxxxx>
Reviewed-by: Qu Wenruo <wqu@xxxxxxxx>
Except one nitpick inlined below.
[snip]
> }
> + if (bq->pathname)
> + free((void *)bq->pathname);
What about just free(bq->pathname);?
Is this (void *) used to get around the const prefix?
Thanks,
Qu
> free(bq);
> }
>
> @@ -1107,7 +1228,7 @@ static int __qgroups_search(int fd, struct qgroup_lookup *qgroup_lookup)
> info = (struct btrfs_qgroup_info_item *)
> (args.buf + off);
>
> - ret = update_qgroup_info(qgroup_lookup,
> + ret = update_qgroup_info(fd, qgroup_lookup,
> qgroupid, info);
> break;
> case BTRFS_QGROUP_LIMIT_KEY:
> @@ -1115,7 +1236,7 @@ static int __qgroups_search(int fd, struct qgroup_lookup *qgroup_lookup)
> limit = (struct btrfs_qgroup_limit_item *)
> (args.buf + off);
>
> - ret = update_qgroup_limit(qgroup_lookup,
> + ret = update_qgroup_limit(fd, qgroup_lookup,
> qgroupid, limit);
> break;
> case BTRFS_QGROUP_RELATION_KEY:
> @@ -1159,7 +1280,7 @@ static int __qgroups_search(int fd, struct qgroup_lookup *qgroup_lookup)
> return ret;
> }
>
> -static void print_all_qgroups(struct qgroup_lookup *qgroup_lookup)
> +static void print_all_qgroups(struct qgroup_lookup *qgroup_lookup, bool verbose)
> {
>
> struct rb_node *n;
> @@ -1170,14 +1291,15 @@ static void print_all_qgroups(struct qgroup_lookup *qgroup_lookup)
> n = rb_first(&qgroup_lookup->root);
> while (n) {
> entry = rb_entry(n, struct btrfs_qgroup, sort_node);
> - print_single_qgroup_table(entry);
> + print_single_qgroup_table(entry, verbose);
> n = rb_next(n);
> }
> }
>
> int btrfs_show_qgroups(int fd,
> struct btrfs_qgroup_filter_set *filter_set,
> - struct btrfs_qgroup_comparer_set *comp_set)
> + struct btrfs_qgroup_comparer_set *comp_set,
> + bool verbose)
> {
>
> struct qgroup_lookup qgroup_lookup;
> @@ -1189,7 +1311,7 @@ int btrfs_show_qgroups(int fd,
> return ret;
> __filter_and_sort_qgroups(&qgroup_lookup, &sort_tree,
> filter_set, comp_set);
> - print_all_qgroups(&sort_tree);
> + print_all_qgroups(&sort_tree, verbose);
>
> __free_all_qgroups(&qgroup_lookup);
> return ret;
> diff --git a/qgroup.h b/qgroup.h
> index 875fbdf3..f7ab7de5 100644
> --- a/qgroup.h
> +++ b/qgroup.h
> @@ -59,11 +59,13 @@ enum btrfs_qgroup_column_enum {
> BTRFS_QGROUP_MAX_EXCL,
> BTRFS_QGROUP_PARENT,
> BTRFS_QGROUP_CHILD,
> + BTRFS_QGROUP_PATHNAME,
> BTRFS_QGROUP_ALL,
> };
>
> enum btrfs_qgroup_comp_enum {
> BTRFS_QGROUP_COMP_QGROUPID,
> + BTRFS_QGROUP_COMP_PATHNAME,
> BTRFS_QGROUP_COMP_RFER,
> BTRFS_QGROUP_COMP_EXCL,
> BTRFS_QGROUP_COMP_MAX_RFER,
> @@ -80,7 +82,7 @@ enum btrfs_qgroup_filter_enum {
> int btrfs_qgroup_parse_sort_string(const char *opt_arg,
> struct btrfs_qgroup_comparer_set **comps);
> int btrfs_show_qgroups(int fd, struct btrfs_qgroup_filter_set *,
> - struct btrfs_qgroup_comparer_set *);
> + struct btrfs_qgroup_comparer_set *, bool verbose);
> void btrfs_qgroup_setup_print_column(enum btrfs_qgroup_column_enum column);
> void btrfs_qgroup_setup_units(unsigned unit_mode);
> struct btrfs_qgroup_filter_set *btrfs_qgroup_alloc_filter_set(void);
> diff --git a/utils.c b/utils.c
> index e9cb3a82..7b7f87f1 100644
> --- a/utils.c
> +++ b/utils.c
> @@ -2556,15 +2556,9 @@ out:
> return ret;
> }
>
> -int get_subvol_info_by_rootid(const char *mnt, struct root_info *get_ri, u64 r_id)
> +int get_subvol_info_by_rootid_fd(int fd, struct root_info *get_ri, u64 r_id)
> {
> - int fd;
> int ret;
> - DIR *dirstream = NULL;
> -
> - fd = btrfs_open_dir(mnt, &dirstream, 1);
> - if (fd < 0)
> - return -EINVAL;
>
> memset(get_ri, 0, sizeof(*get_ri));
> get_ri->root_id = r_id;
> @@ -2574,6 +2568,21 @@ int get_subvol_info_by_rootid(const char *mnt, struct root_info *get_ri, u64 r_i
> else
> ret = btrfs_get_subvol(fd, get_ri);
>
> + return ret;
> +}
> +
> +int get_subvol_info_by_rootid(const char *mnt, struct root_info *get_ri,
> + u64 r_id)
> +{
> + int fd;
> + int ret;
> + DIR *dirstream = NULL;
> +
> + fd = btrfs_open_dir(mnt, &dirstream, 1);
> + if (fd < 0)
> + return -EINVAL;
> +
> + ret = get_subvol_info_by_rootid_fd(fd, get_ri, r_id);
> if (ret)
> error("can't find rootid '%llu' on '%s': %d", r_id, mnt, ret);
>
> diff --git a/utils.h b/utils.h
> index b871c9ff..722d3c48 100644
> --- a/utils.h
> +++ b/utils.h
> @@ -154,6 +154,8 @@ int test_isdir(const char *path);
>
> const char *subvol_strip_mountpoint(const char *mnt, const char *full_path);
> int get_subvol_info(const char *fullpath, struct root_info *get_ri);
> +int get_subvol_info_by_rootid_fd(int fd, struct root_info *get_ri,
> + u64 rootid_arg);
> int get_subvol_info_by_rootid(const char *mnt, struct root_info *get_ri,
> u64 rootid_arg);
> int get_subvol_info_by_uuid(const char *mnt, struct root_info *get_ri,
>
Attachment:
signature.asc
Description: OpenPGP digital signature
