From patchwork Mon Apr 18 02:27:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 8864471 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E69939F443 for ; Mon, 18 Apr 2016 02:29:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 06E772011B for ; Mon, 18 Apr 2016 02:29:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1A77A201C0 for ; Mon, 18 Apr 2016 02:29:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752508AbcDRC3z (ORCPT ); Sun, 17 Apr 2016 22:29:55 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:35964 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1752194AbcDRC3w (ORCPT ); Sun, 17 Apr 2016 22:29:52 -0400 X-IronPort-AV: E=Sophos;i="5.20,367,1444665600"; d="scan'208";a="438856" Received: from unknown (HELO cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 18 Apr 2016 10:29:14 +0800 Received: from localhost.localdomain (unknown [10.167.226.34]) by cn.fujitsu.com (Postfix) with ESMTP id 212004056401; Mon, 18 Apr 2016 10:29:10 +0800 (CST) From: Qu Wenruo To: linux-btrfs@vger.kernel.org, mfasheh@suse.de Subject: [PATCH 1/3] btrfs-progs: Fix return value bug of qgroups check Date: Mon, 18 Apr 2016 10:27:07 +0800 Message-Id: <1460946429-578-1-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.8.0 MIME-Version: 1.0 X-yoursite-MailScanner-ID: 212004056401.A77E4 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: quwenruo@cn.fujitsu.com X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Before this patch, although btrfsck will check qgroups if quota is enabled, it always return 0 even qgroup numbers are corrupted. Fix it by allowing return value from report_qgroups function (formally defined as print_qgroup_difference). Signed-off-by: Qu Wenruo --- cmds-check.c | 8 ++++++-- qgroup-verify.c | 9 ++++++--- qgroup-verify.h | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/cmds-check.c b/cmds-check.c index d59968b..de17be3 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -9698,7 +9698,7 @@ int cmd_check(int argc, char **argv) uuidbuf); ret = qgroup_verify_all(info); if (ret == 0) - print_qgroup_report(1); + ret = report_qgroups(1); goto close_out; } if (subvolid) { @@ -9859,7 +9859,11 @@ int cmd_check(int argc, char **argv) ret = 1; } out: - print_qgroup_report(0); + /* Don't override original ret */ + if (ret) + report_qgroups(0); + else + ret = report_qgroups(0); if (found_old_backref) { /* * there was a disk format change when mixed * backref was in testing tree. The old format diff --git a/qgroup-verify.c b/qgroup-verify.c index 10ff8e0..c4e9201 100644 --- a/qgroup-verify.c +++ b/qgroup-verify.c @@ -1016,7 +1016,7 @@ static void print_fields_signed(long long bytes, prefix, type, bytes, type, bytes_compressed); } -static void print_qgroup_difference(struct qgroup_count *count, int verbose) +static int report_qgroup_difference(struct qgroup_count *count, int verbose) { int is_different; struct qgroup_info *info = &count->info; @@ -1046,19 +1046,22 @@ static void print_qgroup_difference(struct qgroup_count *count, int verbose) print_fields_signed(excl_diff, excl_diff, "diff:", "exclusive"); } + return (is_different && count->subvol_exists); } -void print_qgroup_report(int all) +int report_qgroups(int all) { struct rb_node *node; struct qgroup_count *c; + int ret = 0; node = rb_first(&counts.root); while (node) { c = rb_entry(node, struct qgroup_count, rb_node); - print_qgroup_difference(c, all); + ret |= report_qgroup_difference(c, all); node = rb_next(node); } + return ret; } int qgroup_verify_all(struct btrfs_fs_info *info) diff --git a/qgroup-verify.h b/qgroup-verify.h index 7d91c19..3747465 100644 --- a/qgroup-verify.h +++ b/qgroup-verify.h @@ -23,7 +23,7 @@ #include "ctree.h" int qgroup_verify_all(struct btrfs_fs_info *info); -void print_qgroup_report(int all); +int report_qgroups(int all); int print_extent_state(struct btrfs_fs_info *info, u64 subvol);