From patchwork Mon Feb 6 05:47:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9557107 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 5CBA56021C for ; Mon, 6 Feb 2017 05:48:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6ADEA267EC for ; Mon, 6 Feb 2017 05:48:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6005327F82; Mon, 6 Feb 2017 05:48:12 +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 085E2267EC for ; Mon, 6 Feb 2017 05:48:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751301AbdBFFsK (ORCPT ); Mon, 6 Feb 2017 00:48:10 -0500 Received: from cn.fujitsu.com ([59.151.112.132]:60909 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751218AbdBFFsI (ORCPT ); Mon, 6 Feb 2017 00:48:08 -0500 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="15312255" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 06 Feb 2017 13:47:50 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id 7491F477B1F7; Mon, 6 Feb 2017 13:47:47 +0800 (CST) Received: from localhost.localdomain (10.167.226.34) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 6 Feb 2017 13:47:49 +0800 From: Qu Wenruo To: CC: , , , Su Yue Subject: [PATCH v2 12/12] btrfs-progs: cmds-check.c: walk_down_tree_v2 break cause of leaf process Date: Mon, 6 Feb 2017 13:47:35 +0800 Message-ID: <20170206054735.5227-13-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170206054735.5227-1-quwenruo@cn.fujitsu.com> References: <20170206054735.5227-1-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.34] X-yoursite-MailScanner-ID: 7491F477B1F7.AF149 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: quwenruo@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 From: Su Yue In lowmem mode, 'walk_down_tree_v2' returns negative values wheather the error is fatal or not. It causes the loop where 'walk_down_tree_v2' is to break even the error is tolerated and then subsequent nodes process will be skipped. Fix it by redefining meanings of values 'walk_down_tree_v2' returns. Do a similar fix for 'process_one_leaf_v2'. Signed-off-by: Su Yue --- cmds-check.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/cmds-check.c b/cmds-check.c index 7d273623..fae18e00 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -1868,6 +1868,11 @@ static int update_nodes_refs(struct btrfs_root *root, u64 bytenr, static int check_inode_item(struct btrfs_root *root, struct btrfs_path *path, unsigned int ext_ref); +/* + * Returns >0 Found error, not fatal, should continue process + * Returns <0 Fata error, must exit the whole check + * returns 0 No error is found + */ static int process_one_leaf_v2(struct btrfs_root *root, struct btrfs_path *path, struct node_refs *nrefs, int *level, int ext_ref) { @@ -1937,13 +1942,8 @@ again: } out: err &= ~LAST_ITEM; - /* - * Convert any error bitmap to -EIO, as we should avoid - * mixing positive and negative return value to represent - * error - */ if (err && !ret) - ret = -EIO; + ret = err; return ret; } @@ -2213,6 +2213,11 @@ out: static int check_inode_item(struct btrfs_root *root, struct btrfs_path *path, unsigned int ext_ref); +/* + * Returns >0 Found error, should continue + * Returns 0 No error is found + * Returns <0 Fatal error, must exit the whole check + */ static int walk_down_tree_v2(struct btrfs_root *root, struct btrfs_path *path, int *level, struct node_refs *nrefs, int ext_ref) { @@ -5028,8 +5033,9 @@ static int check_fs_root_v2(struct btrfs_root *root, unsigned int ext_ref) struct btrfs_path path; struct node_refs nrefs; struct btrfs_root_item *root_item = &root->root_item; - int ret, wret; + int ret; int level; + int err = 0; /* * We need to manually check the first inode item(256) @@ -5063,16 +5069,17 @@ static int check_fs_root_v2(struct btrfs_root *root, unsigned int ext_ref) } while (1) { - wret = walk_down_tree_v2(root, &path, &level, &nrefs, ext_ref); - if (wret < 0) - ret = wret; - if (wret != 0) + ret = walk_down_tree_v2(root, &path, &level, &nrefs, ext_ref); + err |= !!ret; + + /* if ret is negative, walk shall stop */ + if (ret < 0) { + ret = err; break; + } - wret = walk_up_tree_v2(root, &path, &level); - if (wret < 0) - ret = wret; - if (wret != 0) + ret = walk_up_tree_v2(root, &path, &level); + if (ret != 0) break; }