From patchwork Fri Mar 2 18:39:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Mahoney X-Patchwork-Id: 10255405 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 317EF6037D for ; Fri, 2 Mar 2018 18:40:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 21CFE262FF for ; Fri, 2 Mar 2018 18:40:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 16B1B28113; Fri, 2 Mar 2018 18:40:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D21BC28112 for ; Fri, 2 Mar 2018 18:40:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1947356AbeCBSki (ORCPT ); Fri, 2 Mar 2018 13:40:38 -0500 Received: from mx2.suse.de ([195.135.220.15]:59502 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1947352AbeCBSkV (ORCPT ); Fri, 2 Mar 2018 13:40:21 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id C18F8AE8D for ; Fri, 2 Mar 2018 18:40:18 +0000 (UTC) Received: from starscream.home.jeffm.io (starscream-1.home.jeffm.io [192.168.1.254]) by mail.home.jeffm.io (Postfix) with ESMTPS id 1B61F81AD3E9; Fri, 2 Mar 2018 13:39:51 -0500 (EST) Received: by starscream.home.jeffm.io (Postfix, from userid 1000) id C178380701; Fri, 2 Mar 2018 13:40:13 -0500 (EST) From: jeffm@suse.com To: linux-btrfs@vger.kernel.org Cc: Jeff Mahoney Subject: [PATCH 6/8] btrfs-progs: qgroups: introduce and use info and limit structures Date: Fri, 2 Mar 2018 13:39:59 -0500 Message-Id: <20180302184004.22036-8-jeffm@suse.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180302184004.22036-1-jeffm@suse.com> References: <20180302184004.22036-1-jeffm@suse.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 | 83 +++++++++++++++++++++++++++++++--------------------------------- qgroup.h | 8 +++++++ 2 files changed, 48 insertions(+), 43 deletions(-) diff --git a/qgroup.c b/qgroup.c index 5a7a8530..7ec12ec1 100644 --- a/qgroup.c +++ b/qgroup.c @@ -50,20 +50,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; @@ -276,24 +268,24 @@ 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 = printf("%*s", max_len, pretty_size_mode(qgroup->info.referenced, unit_mode)); break; case BTRFS_QGROUP_EXCL: - len = printf("%*s", max_len, pretty_size_mode(qgroup->excl, unit_mode)); + len = printf("%*s", max_len, pretty_size_mode(qgroup->info.exclusive, unit_mode)); 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 = printf("%*s", max_len, pretty_size_mode(qgroup->limit.max_referenced, unit_mode)); 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 = printf("%*s", max_len, pretty_size_mode(qgroup->limit.max_exclusive, unit_mode)); else len = printf("%*s", max_len, "none"); break; @@ -436,9 +428,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; @@ -452,9 +444,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; @@ -468,9 +460,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; @@ -484,9 +476,9 @@ static int comp_entry_with_max_excl(struct btrfs_qgroup *entry1, { int ret; - if (entry1->max_excl > entry2->max_excl) + if (entry1->limit.max_exclusive > entry2->limit.max_exclusive) ret = 1; - else if (entry1->max_excl < entry2->max_excl) + else if (entry1->limit.max_exclusive < entry2->limit.max_exclusive) ret = -1; else ret = 0; @@ -743,11 +735,13 @@ static int update_qgroup_info(int fd, struct qgroup_lookup *qgroup_lookup, if (IS_ERR_OR_NULL(bq)) return PTR_ERR(bq); - bq->generation = btrfs_stack_qgroup_info_generation(info); - bq->rfer = btrfs_stack_qgroup_info_referenced(info); - bq->rfer_cmpr = btrfs_stack_qgroup_info_referenced_compressed(info); - bq->excl = btrfs_stack_qgroup_info_exclusive(info); - bq->excl_cmpr = btrfs_stack_qgroup_info_exclusive_compressed(info); + bq->info.generation = btrfs_stack_qgroup_info_generation(info); + bq->info.referenced = btrfs_stack_qgroup_info_referenced(info); + bq->info.referenced_compressed = + btrfs_stack_qgroup_info_referenced_compressed(info); + bq->info.exclusive = btrfs_stack_qgroup_info_exclusive(info); + bq->info.exclusive_compressed = + btrfs_stack_qgroup_info_exclusive_compressed(info); return 0; } @@ -762,11 +756,14 @@ static int update_qgroup_limit(int fd, struct qgroup_lookup *qgroup_lookup, if (IS_ERR_OR_NULL(bq)) return PTR_ERR(bq); - bq->flags = btrfs_stack_qgroup_limit_flags(limit); - bq->max_rfer = btrfs_stack_qgroup_limit_max_referenced(limit); - bq->max_excl = btrfs_stack_qgroup_limit_max_exclusive(limit); - bq->rsv_rfer = btrfs_stack_qgroup_limit_rsv_referenced(limit); - bq->rsv_excl = btrfs_stack_qgroup_limit_rsv_exclusive(limit); + bq->limit.flags = btrfs_stack_qgroup_limit_flags(limit); + bq->limit.max_referenced = + btrfs_stack_qgroup_limit_max_referenced(limit); + bq->limit.max_exclusive = + btrfs_stack_qgroup_limit_max_exclusive(limit); + bq->limit.rsv_referenced = + btrfs_stack_qgroup_limit_rsv_referenced(limit); + bq->limit.rsv_exclusive = btrfs_stack_qgroup_limit_rsv_exclusive(limit); return 0; } @@ -1057,22 +1054,22 @@ static void __update_columns_max_len(struct btrfs_qgroup *bq, btrfs_qgroup_columns[column].max_len = len; break; case BTRFS_QGROUP_RFER: - len = strlen(pretty_size_mode(bq->rfer, unit_mode)); + len = strlen(pretty_size_mode(bq->info.referenced, unit_mode)); if (btrfs_qgroup_columns[column].max_len < len) btrfs_qgroup_columns[column].max_len = len; break; case BTRFS_QGROUP_EXCL: - len = strlen(pretty_size_mode(bq->excl, unit_mode)); + len = strlen(pretty_size_mode(bq->info.exclusive, unit_mode)); if (btrfs_qgroup_columns[column].max_len < len) btrfs_qgroup_columns[column].max_len = len; break; case BTRFS_QGROUP_MAX_RFER: - len = strlen(pretty_size_mode(bq->max_rfer, unit_mode)); + len = strlen(pretty_size_mode(bq->limit.max_referenced, unit_mode)); if (btrfs_qgroup_columns[column].max_len < len) btrfs_qgroup_columns[column].max_len = len; break; case BTRFS_QGROUP_MAX_EXCL: - len = strlen(pretty_size_mode(bq->max_excl, unit_mode)); + len = strlen(pretty_size_mode(bq->limit.max_exclusive, unit_mode)); if (btrfs_qgroup_columns[column].max_len < len) btrfs_qgroup_columns[column].max_len = len; break; @@ -1367,27 +1364,27 @@ static bool export_one_qgroup(json_object *container, goto failure; json_object_object_add(obj, "qgroupid_raw", tmp); - tmp = export_one_u64(qgroup->generation, compat); + tmp = export_one_u64(qgroup->info.generation, compat); if (!tmp) goto failure; json_object_object_add(obj, "generation", tmp); - tmp = export_one_u64(qgroup->rfer, compat); + tmp = export_one_u64(qgroup->info.referenced, compat); if (!tmp) goto failure; json_object_object_add(obj, "referenced_bytes", tmp); - tmp = export_one_u64(qgroup->excl, compat); + tmp = export_one_u64(qgroup->info.exclusive, compat); if (!tmp) goto failure; json_object_object_add(obj, "exclusive_bytes", tmp); - tmp = export_one_u64(qgroup->max_rfer, compat); + tmp = export_one_u64(qgroup->limit.max_referenced, compat); if (!tmp) goto failure; json_object_object_add(obj, "referenced_limit_bytes", tmp); - tmp = export_one_u64(qgroup->max_excl, compat); + tmp = export_one_u64(qgroup->limit.max_exclusive, compat); if (!tmp) goto failure; json_object_object_add(obj, "exclusive_limit_bytes", tmp); diff --git a/qgroup.h b/qgroup.h index 94717b67..e11bbef3 100644 --- a/qgroup.h +++ b/qgroup.h @@ -79,6 +79,14 @@ enum btrfs_qgroup_filter_enum { BTRFS_QGROUP_FILTER_MAX, }; +struct btrfs_qgroup_info { + u64 generation; + u64 referenced; + u64 referenced_compressed; + u64 exclusive; + u64 exclusive_compressed; +}; + 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 *,