From patchwork Tue Jul 25 01:57:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gu Jinxiang X-Patchwork-Id: 9861041 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 283F960385 for ; Tue, 25 Jul 2017 01:58:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 11D8F284AF for ; Tue, 25 Jul 2017 01:58:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E7A1328573; Tue, 25 Jul 2017 01:58:48 +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 570C4284AF for ; Tue, 25 Jul 2017 01:58:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752734AbdGYB6Y (ORCPT ); Mon, 24 Jul 2017 21:58:24 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:10747 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751802AbdGYB6X (ORCPT ); Mon, 24 Jul 2017 21:58:23 -0400 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="21753813" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 25 Jul 2017 09:58:21 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 2D21046B5DF4 for ; Tue, 25 Jul 2017 09:58:16 +0800 (CST) Received: from localhost.localdomain (10.167.226.132) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 25 Jul 2017 09:58:15 +0800 From: Gu Jinxiang To: Subject: [PATCH] btrfs-progs: Move check of mixed block early. Date: Tue, 25 Jul 2017 09:57:44 +0800 Message-ID: <20170725015744.12907-1-gujx@cn.fujitsu.com> X-Mailer: git-send-email 2.9.4 MIME-Version: 1.0 X-Originating-IP: [10.167.226.132] X-yoursite-MailScanner-ID: 2D21046B5DF4.A82D4 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: gujx@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 Make the check of mixed block groups early. Reason: We do not support re-initing extent tree for mixed block groups. So it will return -EINVAL in function reinit_extent_tree. In this situation, we do not need to start transaction. We do not have a btrfs_abort_transaction like kernel now, so we should prevent starting transaction not necessary. Output message when run test 003 in fuzz-test: /home/gujx/btrfs/btrfs-progs/btrfs check --init-extent-tree /home/gujx/btrfs/btrfs-progs/tests/fuzz-tests/images/bko-154961-heap-overflow-chunk-items.raw.restored We don't support re-initing the extent tree for mixed block groups yet, please notify a btrfs developer you want to do this so they can add this functionality. transaction.h:42: btrfs_start_transaction: BUG_ON fs_info->running_transaction triggered, value 11477904 /home/gujx/btrfs/btrfs-progs/btrfs[0x411adf] /home/gujx/btrfs/btrfs-progs/btrfs(close_ctree_fs_info+0x312)[0x413c93] /home/gujx/btrfs/btrfs-progs/btrfs(cmd_check+0x5b1)[0x45d46a] /home/gujx/btrfs/btrfs-progs/btrfs(main+0x85)[0x40acd9] /lib64/libc.so.6(__libc_start_main+0xf1)[0x7f0d957d3401] /home/gujx/btrfs/btrfs-progs/btrfs(_start+0x2a)[0x40a88a] Checking filesystem on /home/gujx/btrfs/btrfs-progs/tests/fuzz-tests/images/bko-154961-heap-overflow-chunk-items.raw.restored UUID: e0d334b9-d48f-49f3-9c6b-45fc8e0ec0c7 Creating a new extent tree failed (ignored, ret=134): /home/gujx/btrfs/btrfs-progs/btrfs check --init-extent-tree /home/gujx/btrfs/btrfs-progs/tests/fuzz-tests/images/bko-154961-heap-overflow-chunk-items.raw.restored mayfail: returned code 134 (SIGABRT), not ignored Signed-off-by: Gu Jinxiang --- cmds-check.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/cmds-check.c b/cmds-check.c index c5faa2b..357623e 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -11914,21 +11914,6 @@ static int reinit_extent_tree(struct btrfs_trans_handle *trans, int ret; /* - * The only reason we don't do this is because right now we're just - * walking the trees we find and pinning down their bytes, we don't look - * at any of the leaves. In order to do mixed groups we'd have to check - * the leaves of any fs roots and pin down the bytes for any file - * extents we find. Not hard but why do it if we don't have to? - */ - if (btrfs_fs_incompat(fs_info, MIXED_GROUPS)) { - fprintf(stderr, "We don't support re-initing the extent tree " - "for mixed block groups yet, please notify a btrfs " - "developer you want to do this so they can add this " - "functionality.\n"); - return -EINVAL; - } - - /* * first we need to walk all of the trees except the extent tree and pin * down the bytes that are in use so we don't overwrite any existing * metadata. @@ -12963,6 +12948,23 @@ int cmd_check(int argc, char **argv) if (init_extent_tree || init_csum_tree) { struct btrfs_trans_handle *trans; + /* + * The only reason we don't do this is because right now we're + * just walking the trees we find and pinning down their bytes, + * we don't look at any of the leaves. In order to do mixed + * groups we'd have to check the leaves of any fs roots and + * pin down the bytes for any file extents we find. + * Not hard but why do it if we don't have to? + */ + if (init_extent_tree && btrfs_fs_incompat(info, MIXED_GROUPS)) { + fprintf(stderr, "We don't support re-initing the extent tree " + "for mixed block groups yet, please notify a btrfs " + "developer you want to do this so they can add this " + "functionality.\n"); + goto close_out; + + } + trans = btrfs_start_transaction(info->extent_root, 0); if (IS_ERR(trans)) { error("error starting transaction");