From patchwork Fri Oct 27 07:29:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 10029301 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 1DD8F60249 for ; Fri, 27 Oct 2017 07:30:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 102EF28E39 for ; Fri, 27 Oct 2017 07:30:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 03ADC28E3C; Fri, 27 Oct 2017 07:30:05 +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 A10F928E39 for ; Fri, 27 Oct 2017 07:30:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752108AbdJ0H37 (ORCPT ); Fri, 27 Oct 2017 03:29:59 -0400 Received: from prv3-mh.provo.novell.com ([137.65.250.26]:34243 "EHLO prv3-mh.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750930AbdJ0H36 (ORCPT ); Fri, 27 Oct 2017 03:29:58 -0400 Received: from adam-pc.lan (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by prv3-mh.provo.novell.com with ESMTP (NOT encrypted); Fri, 27 Oct 2017 01:29:42 -0600 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz Subject: [PATCH 3/8] btrfs-progs: qgroup-verify: Move qgroup classification out of report_qgroups Date: Fri, 27 Oct 2017 15:29:31 +0800 Message-Id: <20171027072936.4697-4-wqu@suse.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171027072936.4697-1-wqu@suse.com> References: <20171027072936.4697-1-wqu@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 The original qgroup-verify integrates qgroup classification into report_qgroups(). This behavior makes silent qgroup repair (or offline rescan) impossible. To repair qgroup, we must call report_qgroups() to trigger bad qgroup classification, which will output error message. This patch moves bad qgroup classification from report_qgroups() to qgroup_verify_all(). The functionality is not changed, but provides the basis for later silent qgroup repair. Signed-off-by: Qu Wenruo --- qgroup-verify.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/qgroup-verify.c b/qgroup-verify.c index f509cdb9317a..67bd8b96ddd3 100644 --- a/qgroup-verify.c +++ b/qgroup-verify.c @@ -1319,8 +1319,7 @@ void report_qgroups(int all) while (node) { c = rb_entry(node, struct qgroup_count, rb_node); - if (report_qgroup_difference(c, all)) - list_add_tail(&c->bad_list, &bad_qgroups); + report_qgroup_difference(c, all); node = rb_next(node); } @@ -1358,9 +1357,20 @@ void free_qgroup_counts(void) } } +static bool is_bad_qgroup(struct qgroup_count *count) +{ + struct qgroup_info *info = &count->info; + struct qgroup_info *disk = &count->diskinfo; + s64 excl_diff = info->exclusive - disk->exclusive; + s64 ref_diff = info->referenced - disk->referenced; + + return (excl_diff || ref_diff); +} + int qgroup_verify_all(struct btrfs_fs_info *info) { int ret; + struct rb_node *node; if (!info->quota_enabled) return 0; @@ -1395,6 +1405,20 @@ int qgroup_verify_all(struct btrfs_fs_info *info) ret = account_all_refs(1, 0); + /* + * Do the correctness check here, so for callers who don't want + * verbose report can skip calling report_qgroups() + */ + node = rb_first(&counts.root); + while (node) { + struct qgroup_count *c; + + c = rb_entry(node, struct qgroup_count, rb_node); + if (is_bad_qgroup(c)) + list_add_tail(&c->bad_list, &bad_qgroups); + node = rb_next(node); + } + out: /* * Don't free the qgroup count records as they will be walked