From patchwork Fri Aug 18 09:36:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9908173 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 240E2600CC for ; Fri, 18 Aug 2017 09:36:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 158CD28C4D for ; Fri, 18 Aug 2017 09:36:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0A28428C84; Fri, 18 Aug 2017 09:36:43 +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,FREEMAIL_FROM, 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 55C2528C4D for ; Fri, 18 Aug 2017 09:36:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751107AbdHRJgj (ORCPT ); Fri, 18 Aug 2017 05:36:39 -0400 Received: from mout.gmx.net ([212.227.17.20]:51744 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750810AbdHRJgi (ORCPT ); Fri, 18 Aug 2017 05:36:38 -0400 Received: from localhost.localdomain ([45.32.39.184]) by mail.gmx.com (mrgmx103 [212.227.17.174]) with ESMTPSA (Nemesis) id 0MXZNq-1e30Gi1Sje-00WSHd; Fri, 18 Aug 2017 11:36:35 +0200 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz, jared.e.vb@gmail.com Subject: [PATCH] btrfs-progs: Allow inspect dump-tree to show specified tree block even some tree roots are corrupted Date: Fri, 18 Aug 2017 18:36:30 +0900 Message-Id: <20170818093630.9892-1-quwenruo.btrfs@gmx.com> X-Mailer: git-send-email 2.13.3 X-Provags-ID: V03:K0:pigjoHx+yjVCuuaWeuAcTCLwP5yViboMumAjXup3ZMEjPoMgRBp Rg1jzygmlHTUaicpswZkw0TWxE7qMyQcgUURpVkhZYQEvQMuJ2HtyKJkOhToW0gz2U+Aokp v9+AH89/AaQXKUdlGrBJwBuEcjV4SMbKUVOdcdczskvoeILNaFUvTs1DOibA3PY8QLGWJuT CGGdhNcJFXN3XnsF3KyqQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:SfPy4P5hnc0=:ciNqCqR/PU/vE6uOCW4ZLY 5zlo2zmhE96PCcsgC3h1cOhXRAXl+RrYinC+pnxw+haDXjldtsHyLtUhwKiheN6AH8kyiDkm4 qgnG22or6zsdalMdaQGnx/EnAfZbA4YneU0RKLMbn7IAvA+3F8xNJEZbwR+HK3+nYPMrY3WC1 //WRcTP+X6gHD5/HyzxIPaooxKUvMO2mPdiDslb0BEbtv/d/37v5EUyFyqCy2e5Z7gxIEUuHN 2yObhWFdLv4haNBQMFLO4t8Zzrm4qh7t+2eNVKJJsIUaE/izabglzSKh3jLcPS3edbHXMD6Vc Mri8XsHN2oSMF1Jyzkw8jruB3XVy72iyveBiIcoRnLeYUDtrco9inQIJGCYeuRu+SLs2OUdlR V6Dhwary4qxW8A8QZ/HYk33COuIvpfs59NOXVIePukpRUeoytkwyjKISRu2eK4dUOwZzck29y 0xMIW9PH0nQ91cS8w9NOOAqPa6dJe4nstA/n+kK3jdPlPSK69mkAOLmzoXfw/DZYbK7xwEWzs eOmMUfjyMWtS6gxKoEoHyM8kqayw0egVN5oL0OebvMsx0GMxPEaL1LYrCrmRPQYqWyNBZIodk dWGBUPZd3yjXtd51l9JzYbyV+m0pndEJ/2zufsKfHYq58+F8doruOfVblYtuLTE7TbyC2csiu y5P1QXEQuVFdjQzw+1NRIsLF7Kv5G3Sww1WsmzlFgRYDOIZUs2o3CfPGdNl9nD+wo9l8CfYjN WPWiPMqMd63sieVgZTvLTIO1kIAlQPg/1Xe0WWTlNjClRg5EngjP3Dn901t+aypYJASvFCQUD AxB1Eexe/jFfhPSMRIEUN0+k4FFqg== 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 For btrfs inspect-internal dump-tree, if we use "-b" parameter to show specified tree block, then we don't really need extra tree roots. Only chunk root is needed to build up the whole chunk mapping so we can read tree blocks. This patch will add __OPEN_CTREE_RETURN_CHUNK_ROOT flag when show speicifed tree block. So even root tree is corrupted, we can still use inspect-internal dump-tree to do some debugging. Reported-by: Zirconium Hacker Signed-off-by: Qu Wenruo --- cmds-inspect-dump-tree.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/cmds-inspect-dump-tree.c b/cmds-inspect-dump-tree.c index 93dff086..876ddcb5 100644 --- a/cmds-inspect-dump-tree.c +++ b/cmds-inspect-dump-tree.c @@ -222,6 +222,7 @@ 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_FS_PARTIAL; u64 block_only = 0; struct btrfs_root *tree_root_scan; u64 tree_id = 0; @@ -260,6 +261,11 @@ int cmd_inspect_dump_tree(int argc, char **argv) root_backups = 1; break; case 'b': + /* + * If only showing one block, no need to fill roots + * other than chunk root + */ + open_ctree_flags |= __OPEN_CTREE_RETURN_CHUNK_ROOT; block_only = arg_strtou64(optarg); break; case 't': { @@ -299,19 +305,14 @@ int cmd_inspect_dump_tree(int argc, char **argv) printf("%s\n", PACKAGE_STRING); - info = open_ctree_fs_info(argv[optind], 0, 0, 0, OPEN_CTREE_PARTIAL); + info = open_ctree_fs_info(argv[optind], 0, 0, 0, open_ctree_flags); if (!info) { error("unable to open %s", argv[optind]); goto out; } - root = info->fs_root; - if (!root) { - error("unable to open %s", argv[optind]); - goto out; - } - if (block_only) { + root = info->chunk_root; leaf = read_tree_block(info, block_only, info->nodesize, 0); @@ -337,6 +338,12 @@ int cmd_inspect_dump_tree(int argc, char **argv) goto close_root; } + root = info->fs_root; + if (!root) { + error("unable to open %s", argv[optind]); + goto out; + } + if (!(extent_only || uuid_tree_only || tree_id)) { if (roots_only) { printf("root tree: %llu level %d\n",