From patchwork Wed Apr 11 07:29:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 10334957 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 06B916053C for ; Wed, 11 Apr 2018 07:30:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E16C62872D for ; Wed, 11 Apr 2018 07:29:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D43BD28733; Wed, 11 Apr 2018 07:29:59 +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=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, 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 30AF82872D for ; Wed, 11 Apr 2018 07:29:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751872AbeDKH35 (ORCPT ); Wed, 11 Apr 2018 03:29:57 -0400 Received: from victor.provo.novell.com ([137.65.250.26]:45647 "EHLO prv3-mh.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751699AbeDKH34 (ORCPT ); Wed, 11 Apr 2018 03:29:56 -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); Wed, 11 Apr 2018 01:29:40 -0600 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: calestyo@scientia.net Subject: [PATCH v2 2/2] btrfs-progs: Use more loose open ctree flags for dump-tree and restore Date: Wed, 11 Apr 2018 15:29:36 +0800 Message-Id: <20180411072936.12915-2-wqu@suse.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180411072936.12915-1-wqu@suse.com> References: <20180411072936.12915-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 Corrupted extent tree (either the root node or leaf) can normally block us from open the fs. As normally open_ctree() has the following call chain: __open_ctree_fd() |- btrfs_setup_all_roots() |- btrfs_read_block_groups() And we will search block group items in extent tree. And considering how block group items are scattered around the whole extent tree, any error would block the fs from being mounted. Fortunately, we already have OPEN_CTREE_NO_BLOCK_GROUPS flags to disable block group items search, which will not only allow us to open some fs, but also hugely speed up open time. Currently dump-tree and btrfs-restore is ensured that they care nothing about block group items. So specify OPEN_CTREE_NO_BLOCK_GROUPS flag as default. Also fix a typo where dump-tree is using OPEN_CTREE_FS_PARTIAL, which should be OPEN_CTREE_PARTIAL. This makes dump-tree do more check and can sometimes fail to open certain filesystems. Reported-by: Christoph Anton Mitterer Signed-off-by: Qu Wenruo --- changelog: v2: New comment to explain why OPEN_CTREE_NO_BLOCK_GROUPS is OK here. --- cmds-inspect-dump-tree.c | 10 +++++++++- cmds-restore.c | 9 ++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/cmds-inspect-dump-tree.c b/cmds-inspect-dump-tree.c index e6510851e8f4..b2091d808c55 100644 --- a/cmds-inspect-dump-tree.c +++ b/cmds-inspect-dump-tree.c @@ -220,12 +220,20 @@ int cmd_inspect_dump_tree(int argc, char **argv) int uuid_tree_only = 0; int roots_only = 0; int root_backups = 0; - unsigned open_ctree_flags = OPEN_CTREE_PARTIAL; + unsigned open_ctree_flags; u64 block_only = 0; struct btrfs_root *tree_root_scan; u64 tree_id = 0; bool follow = false; + /* + * For debug-tree, we care nothing about extent tree (it's just backref + * and usage accounting, only makes sense for RW operations). + * Use NO_BLOCK_GROUPS here could also speedup open_ctree() and allow us + * to inspect fs with corrupted extent tree blocks, and show as many good + * tree blocks as possible. + */ + open_ctree_flags = OPEN_CTREE_PARTIAL | OPEN_CTREE_NO_BLOCK_GROUPS; while (1) { int c; enum { GETOPT_VAL_FOLLOW = 256 }; diff --git a/cmds-restore.c b/cmds-restore.c index ade35f0f880f..f228acab8276 100644 --- a/cmds-restore.c +++ b/cmds-restore.c @@ -1281,8 +1281,15 @@ static struct btrfs_root *open_fs(const char *dev, u64 root_location, for (i = super_mirror; i < BTRFS_SUPER_MIRROR_MAX; i++) { bytenr = btrfs_sb_offset(i); + + /* + * Restore won't allocate extent and doesn't care anything + * in extent tree. Skip block group item search will allow + * restore to be executed on heavily damaged fs. + */ fs_info = open_ctree_fs_info(dev, bytenr, root_location, 0, - OPEN_CTREE_PARTIAL); + OPEN_CTREE_PARTIAL | + OPEN_CTREE_NO_BLOCK_GROUPS); if (fs_info) break; fprintf(stderr, "Could not open root, trying backup super\n");