Re: [PATCH 07/20] btrfs-progs: qgroups: introduce and use info and limit structures

2018-03-07 Thread Qu Wenruo


On 2018年03月08日 10:40, je...@suse.com wrote:
> From: Jeff Mahoney 
> 
> We use structures to pass the info and limit from the kernel as items
> but store the individual values separately in btrfs_qgroup.  We already
> have a btrfs_qgroup_limit structure that's used for setting the limit.
> 
> This patch introduces a btrfs_qgroup_info structure and uses that and
> btrfs_qgroup_limit in btrfs_qgroup.
> 
> Signed-off-by: Jeff Mahoney 

Reviewed-by: Qu Wenruo 

Thanks,
Qu

> ---
>  qgroup.c | 82 
> ++--
>  qgroup.h |  8 +++
>  2 files changed, 52 insertions(+), 38 deletions(-)
> 
> diff --git a/qgroup.c b/qgroup.c
> index 5600da99..57815718 100644
> --- a/qgroup.c
> +++ b/qgroup.c
> @@ -46,20 +46,12 @@ struct btrfs_qgroup {
>   /*
>* info_item
>*/
> - u64 generation;
> - u64 rfer;   /*referenced*/
> - u64 rfer_cmpr;  /*referenced compressed*/
> - u64 excl;   /*exclusive*/
> - u64 excl_cmpr;  /*exclusive compressed*/
> + struct btrfs_qgroup_info info;
>  
>   /*
>*limit_item
>*/
> - u64 flags;  /*which limits are set*/
> - u64 max_rfer;
> - u64 max_excl;
> - u64 rsv_rfer;
> - u64 rsv_excl;
> + struct btrfs_qgroup_limit limit;
>  
>   /*qgroups this group is member of*/
>   struct list_head qgroups;
> @@ -260,6 +252,11 @@ void print_pathname_column(struct btrfs_qgroup *qgroup, 
> bool verbose)
>   fputs("", stdout);
>  }
>  
> +static int print_u64(u64 value, int unit_mode, int max_len)
> +{
> + return printf("%*s", max_len, pretty_size_mode(value, unit_mode));
> +}
> +
>  static void print_qgroup_column(struct btrfs_qgroup *qgroup,
>   enum btrfs_qgroup_column_enum column,
>   bool verbose)
> @@ -279,24 +276,26 @@ static void print_qgroup_column(struct btrfs_qgroup 
> *qgroup,
>   print_qgroup_column_add_blank(BTRFS_QGROUP_QGROUPID, len);
>   break;
>   case BTRFS_QGROUP_RFER:
> - len = printf("%*s", max_len, pretty_size_mode(qgroup->rfer, 
> unit_mode));
> + len = print_u64(qgroup->info.referenced, unit_mode, max_len);
>   break;
>   case BTRFS_QGROUP_EXCL:
> - len = printf("%*s", max_len, pretty_size_mode(qgroup->excl, 
> unit_mode));
> + len = print_u64(qgroup->info.exclusive, unit_mode, max_len);
>   break;
>   case BTRFS_QGROUP_PARENT:
>   len = print_parent_column(qgroup);
>   print_qgroup_column_add_blank(BTRFS_QGROUP_PARENT, len);
>   break;
>   case BTRFS_QGROUP_MAX_RFER:
> - if (qgroup->flags & BTRFS_QGROUP_LIMIT_MAX_RFER)
> - len = printf("%*s", max_len, 
> pretty_size_mode(qgroup->max_rfer, unit_mode));
> + if (qgroup->limit.flags & BTRFS_QGROUP_LIMIT_MAX_RFER)
> + len = print_u64(qgroup->limit.max_referenced,
> + unit_mode, max_len);
>   else
>   len = printf("%*s", max_len, "none");
>   break;
>   case BTRFS_QGROUP_MAX_EXCL:
> - if (qgroup->flags & BTRFS_QGROUP_LIMIT_MAX_EXCL)
> - len = printf("%*s", max_len, 
> pretty_size_mode(qgroup->max_excl, unit_mode));
> + if (qgroup->limit.flags & BTRFS_QGROUP_LIMIT_MAX_EXCL)
> + len = print_u64(qgroup->limit.max_exclusive,
> + unit_mode, max_len);
>   else
>   len = printf("%*s", max_len, "none");
>   break;
> @@ -439,9 +438,9 @@ static int comp_entry_with_rfer(struct btrfs_qgroup 
> *entry1,
>  {
>   int ret;
>  
> - if (entry1->rfer > entry2->rfer)
> + if (entry1->info.referenced > entry2->info.referenced)
>   ret = 1;
> - else if (entry1->rfer < entry2->rfer)
> + else if (entry1->info.referenced < entry2->info.referenced)
>   ret = -1;
>   else
>   ret = 0;
> @@ -455,9 +454,9 @@ static int comp_entry_with_excl(struct btrfs_qgroup 
> *entry1,
>  {
>   int ret;
>  
> - if (entry1->excl > entry2->excl)
> + if (entry1->info.exclusive > entry2->info.exclusive)
>   ret = 1;
> - else if (entry1->excl < entry2->excl)
> + else if (entry1->info.exclusive < entry2->info.exclusive)
>   ret = -1;
>   else
>   ret = 0;
> @@ -471,9 +470,9 @@ static int comp_entry_with_max_rfer(struct btrfs_qgroup 
> *entry1,
>  {
>   int ret;
>  
> - if (entry1->max_rfer > entry2->max_rfer)
> + if (entry1->limit.max_referenced > entry2->limit.max_referenced)
>   ret = 1;
> - else if (entry1->max_rfer < entry2->max_rfer)
> + else if (entry1->limit.max_referenced < entry2->limit.max_referenced)
>   ret = 

[PATCH 07/20] btrfs-progs: qgroups: introduce and use info and limit structures

2018-03-07 Thread jeffm
From: Jeff Mahoney 

We use structures to pass the info and limit from the kernel as items
but store the individual values separately in btrfs_qgroup.  We already
have a btrfs_qgroup_limit structure that's used for setting the limit.

This patch introduces a btrfs_qgroup_info structure and uses that and
btrfs_qgroup_limit in btrfs_qgroup.

Signed-off-by: Jeff Mahoney 
---
 qgroup.c | 82 ++--
 qgroup.h |  8 +++
 2 files changed, 52 insertions(+), 38 deletions(-)

diff --git a/qgroup.c b/qgroup.c
index 5600da99..57815718 100644
--- a/qgroup.c
+++ b/qgroup.c
@@ -46,20 +46,12 @@ struct btrfs_qgroup {
/*
 * info_item
 */
-   u64 generation;
-   u64 rfer;   /*referenced*/
-   u64 rfer_cmpr;  /*referenced compressed*/
-   u64 excl;   /*exclusive*/
-   u64 excl_cmpr;  /*exclusive compressed*/
+   struct btrfs_qgroup_info info;
 
/*
 *limit_item
 */
-   u64 flags;  /*which limits are set*/
-   u64 max_rfer;
-   u64 max_excl;
-   u64 rsv_rfer;
-   u64 rsv_excl;
+   struct btrfs_qgroup_limit limit;
 
/*qgroups this group is member of*/
struct list_head qgroups;
@@ -260,6 +252,11 @@ void print_pathname_column(struct btrfs_qgroup *qgroup, 
bool verbose)
fputs("", stdout);
 }
 
+static int print_u64(u64 value, int unit_mode, int max_len)
+{
+   return printf("%*s", max_len, pretty_size_mode(value, unit_mode));
+}
+
 static void print_qgroup_column(struct btrfs_qgroup *qgroup,
enum btrfs_qgroup_column_enum column,
bool verbose)
@@ -279,24 +276,26 @@ static void print_qgroup_column(struct btrfs_qgroup 
*qgroup,
print_qgroup_column_add_blank(BTRFS_QGROUP_QGROUPID, len);
break;
case BTRFS_QGROUP_RFER:
-   len = printf("%*s", max_len, pretty_size_mode(qgroup->rfer, 
unit_mode));
+   len = print_u64(qgroup->info.referenced, unit_mode, max_len);
break;
case BTRFS_QGROUP_EXCL:
-   len = printf("%*s", max_len, pretty_size_mode(qgroup->excl, 
unit_mode));
+   len = print_u64(qgroup->info.exclusive, unit_mode, max_len);
break;
case BTRFS_QGROUP_PARENT:
len = print_parent_column(qgroup);
print_qgroup_column_add_blank(BTRFS_QGROUP_PARENT, len);
break;
case BTRFS_QGROUP_MAX_RFER:
-   if (qgroup->flags & BTRFS_QGROUP_LIMIT_MAX_RFER)
-   len = printf("%*s", max_len, 
pretty_size_mode(qgroup->max_rfer, unit_mode));
+   if (qgroup->limit.flags & BTRFS_QGROUP_LIMIT_MAX_RFER)
+   len = print_u64(qgroup->limit.max_referenced,
+   unit_mode, max_len);
else
len = printf("%*s", max_len, "none");
break;
case BTRFS_QGROUP_MAX_EXCL:
-   if (qgroup->flags & BTRFS_QGROUP_LIMIT_MAX_EXCL)
-   len = printf("%*s", max_len, 
pretty_size_mode(qgroup->max_excl, unit_mode));
+   if (qgroup->limit.flags & BTRFS_QGROUP_LIMIT_MAX_EXCL)
+   len = print_u64(qgroup->limit.max_exclusive,
+   unit_mode, max_len);
else
len = printf("%*s", max_len, "none");
break;
@@ -439,9 +438,9 @@ static int comp_entry_with_rfer(struct btrfs_qgroup *entry1,
 {
int ret;
 
-   if (entry1->rfer > entry2->rfer)
+   if (entry1->info.referenced > entry2->info.referenced)
ret = 1;
-   else if (entry1->rfer < entry2->rfer)
+   else if (entry1->info.referenced < entry2->info.referenced)
ret = -1;
else
ret = 0;
@@ -455,9 +454,9 @@ static int comp_entry_with_excl(struct btrfs_qgroup *entry1,
 {
int ret;
 
-   if (entry1->excl > entry2->excl)
+   if (entry1->info.exclusive > entry2->info.exclusive)
ret = 1;
-   else if (entry1->excl < entry2->excl)
+   else if (entry1->info.exclusive < entry2->info.exclusive)
ret = -1;
else
ret = 0;
@@ -471,9 +470,9 @@ static int comp_entry_with_max_rfer(struct btrfs_qgroup 
*entry1,
 {
int ret;
 
-   if (entry1->max_rfer > entry2->max_rfer)
+   if (entry1->limit.max_referenced > entry2->limit.max_referenced)
ret = 1;
-   else if (entry1->max_rfer < entry2->max_rfer)
+   else if (entry1->limit.max_referenced < entry2->limit.max_referenced)
ret = -1;
else
ret = 0;
@@ -487,9 +486,9 @@ static int comp_entry_with_max_excl(struct btrfs_qgroup 
*entry1,
 {
int ret;
 
-   if (entry1->max_excl > entry2->max_excl)
+