From patchwork Wed Sep 27 06:34:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Su Yue X-Patchwork-Id: 9973189 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 EE18360375 for ; Wed, 27 Sep 2017 06:31:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E2548290B4 for ; Wed, 27 Sep 2017 06:31:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D532E290BF; Wed, 27 Sep 2017 06:31:58 +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 755E4290B4 for ; Wed, 27 Sep 2017 06:31:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751974AbdI0Gbz (ORCPT ); Wed, 27 Sep 2017 02:31:55 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:19661 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751821AbdI0Gby (ORCPT ); Wed, 27 Sep 2017 02:31:54 -0400 X-IronPort-AV: E=Sophos;i="5.42,443,1500912000"; d="scan'208";a="28475934" Received: from localhost (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 27 Sep 2017 14:31:43 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 600EE47CAAD0 for ; Wed, 27 Sep 2017 14:31:40 +0800 (CST) Received: from archlinux.g08.fujitsu.local (10.167.226.129) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.361.1; Wed, 27 Sep 2017 14:31:39 +0800 From: Su Yue To: Subject: [PATCH 1/5] btrfs-progs: check: return value of check_extent_refs() Date: Wed, 27 Sep 2017 14:34:36 +0800 Message-ID: <20170927063440.25961-2-suy.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170927063440.25961-1-suy.fnst@cn.fujitsu.com> References: <20170927063440.25961-1-suy.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.129] X-yoursite-MailScanner-ID: 600EE47CAAD0.AB6F5 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: suy.fnst@cn.fujitsu.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 In original check mode(without option "--repair"), check_extent_refs() always returns 0. Add a variable @error to record status while checking extents. At the end of check_extent_refs(), let it return -EIO if @error is nonzero. Example: $ btrfs check bad-extent-inline-ref-type.raw Checking filesystem on bad-extent-inline-ref-type.raw UUID: 1942d6fe-617b-4499-9982-cc8ffae5447f checking extents corrupt extent record: key 29360128 169 16384 ref mismatch on [29360128 16384] extent item 0, found 1 Backref 29360128 parent 5 root 5 not found in extent tree backpointer mismatch on [29360128 16384] bad extent [29360128, 29376512), type mismatch with chunk checking free space cache checking fs roots checking csums checking root refs found 114688 bytes used, no error found total csum bytes: 0 total tree bytes: 114688 total fs tree bytes: 32768 total extent tree bytes: 16384 btree space waste bytes: 109471 file data blocks allocated: 0 referenced 0 Signed-off-by: Su Yue --- cmds-check.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmds-check.c b/cmds-check.c index 8aa136df..93b47194 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -10664,6 +10664,7 @@ static int check_extent_refs(struct btrfs_root *root, struct cache_extent *cache; int ret = 0; int had_dups = 0; + int error = 0; if (repair) { /* @@ -10807,6 +10808,7 @@ static int check_extent_refs(struct btrfs_root *root, cur_err = 1; } + error = cur_err; remove_cache_extent(extent_cache, cache); free_all_extent_backrefs(rec); if (!init_extent_tree && repair && (!cur_err || fix)) @@ -10839,7 +10841,10 @@ repair_abort: } return ret; } - return 0; + + if (error) + error = -EIO; + return error; } u64 calc_stripe_length(u64 type, u64 length, int num_stripes)