From patchwork Wed Dec 10 20:51:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mwilck@arcor.de X-Patchwork-Id: 5472541 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CACD09F444 for ; Wed, 10 Dec 2014 21:06:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EED23201B4 for ; Wed, 10 Dec 2014 21:06:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0E1DA2018E for ; Wed, 10 Dec 2014 21:06:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933312AbaLJVFl (ORCPT ); Wed, 10 Dec 2014 16:05:41 -0500 Received: from mail-in-16.arcor-online.net ([151.189.21.56]:36430 "EHLO mail-in-16.arcor-online.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933296AbaLJVFk (ORCPT ); Wed, 10 Dec 2014 16:05:40 -0500 Received: from mail-in-05-z2.arcor-online.net (mail-in-05-z2.arcor-online.net [151.189.8.17]) by mx.arcor.de (Postfix) with ESMTP id DD19982BF for ; Wed, 10 Dec 2014 22:05:38 +0100 (CET) Received: from mail-in-10.arcor-online.net (mail-in-10.arcor-online.net [151.189.21.50]) by mail-in-05-z2.arcor-online.net (Postfix) with ESMTP id E1A7D6F2F71; Wed, 10 Dec 2014 22:05:38 +0100 (CET) X-Greylist: Passed host: 188.96.131.100 X-DKIM: Sendmail DKIM Filter v2.8.2 mail-in-10.arcor-online.net 9666F2D6601 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arcor.de; s=mail-in; t=1418245538; bh=55XHcpcmtV4VjcTou0VqRWKY1DiLk5qz8pZEFQJpdIc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=G8U4Y4kv0yfDRQJGhmynZLG9zl4lSaMc5kkEP0Wl2OEZXq/NqEDQ0T1H92d2cW3DP DNV3UP/qwRnIR92lVMd120Sb4LSxRbTvyqBxIrLyy5r6RuC23C2c3y0GXlQrvWyH8D T11AFCyr7cw7joU9LXn3beKteNE483KIN8/1VRYY= X-Greylist: Passed host: 188.96.131.100 Received: from localhost.localdomain (dslb-188-096-131-100.188.096.pools.vodafone-ip.de [188.96.131.100]) (Authenticated sender: mwilck@arcor.de) by mail-in-10.arcor-online.net (Postfix) with ESMTPSA id 9666F2D6601; Wed, 10 Dec 2014 22:05:38 +0100 (CET) From: mwilck@arcor.de To: linux-btrfs@vger.kernel.org Cc: mwilck@arcor.de Subject: [PATCH 02/18] btrfs-progs: btrfs-debug-tree: add option -B (backup root) Date: Wed, 10 Dec 2014 21:51:32 +0100 Message-Id: <1418244708-7087-3-git-send-email-mwilck@arcor.de> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1418244708-7087-1-git-send-email-mwilck@arcor.de> References: <1418244708-7087-1-git-send-email-mwilck@arcor.de> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Martin Wilck Option -B causes btrfs-debug-tree to dump the tree rooted at the backup root number given instead of the real root. Signed-off-by: Martin Wilck --- btrfs-debug-tree.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 files changed, 38 insertions(+), 1 deletions(-) diff --git a/btrfs-debug-tree.c b/btrfs-debug-tree.c index e61c71c..7cdc368 100644 --- a/btrfs-debug-tree.c +++ b/btrfs-debug-tree.c @@ -45,6 +45,8 @@ static int print_usage(void) " block\n"); fprintf(stderr, "\t-t tree_id : print only the tree with the given id\n"); + fprintf(stderr, + "\t-B nr: use root backup instead of real root\n"); fprintf(stderr, "%s\n", BTRFS_BUILD_VERSION); exit(1); } @@ -140,6 +142,7 @@ int main(int ac, char **av) int root_backups = 0; u64 block_only = 0; int block_follow = 0; + int use_backup = -1; struct btrfs_root *tree_root_scan; u64 tree_id = 0; @@ -147,7 +150,7 @@ int main(int ac, char **av) while(1) { int c; - c = getopt(ac, av, "defb:rRut:"); + c = getopt(ac, av, "defb:rRut:B:"); if (c < 0) break; switch(c) { @@ -176,6 +179,9 @@ int main(int ac, char **av) case 't': tree_id = arg_strtou64(optarg); break; + case 'B': + use_backup = arg_strtou64(optarg); + break; default: print_usage(); } @@ -221,6 +227,37 @@ int main(int ac, char **av) goto close_root; } + if (use_backup >= BTRFS_NUM_BACKUP_ROOTS) { + fprintf(stderr, "Invalid backup root number %d\n", + use_backup); + exit(1); + } else if (use_backup >= 0) { + u64 bytenr, generation; + u32 blocksize; + struct btrfs_super_block *sb = info->super_copy; + struct btrfs_root_backup *backup = sb->super_roots + use_backup; + struct extent_buffer *eb; + bytenr = btrfs_backup_tree_root(backup); + generation = btrfs_backup_tree_root_gen(backup); + blocksize = btrfs_level_size(info->tree_root, + btrfs_super_root_level(sb)); + eb = info->tree_root->node; + info->tree_root->node = read_tree_block(root, bytenr, + blocksize, generation); + free_extent_buffer(eb); + bytenr = btrfs_backup_chunk_root(backup); + generation = btrfs_backup_chunk_root_gen(backup); + eb = info->chunk_root->node; + info->chunk_root->node = read_tree_block(root, bytenr, + blocksize, generation); + free_extent_buffer(eb); + if (!extent_buffer_uptodate(info->tree_root->node) || + !extent_buffer_uptodate(info->tree_root->node)) { + fprintf(stderr, "Couldn't backup root\n"); + return 1; + } + } + if (!(extent_only || uuid_tree_only || tree_id)) { if (roots_only) { printf("root tree: %llu level %d\n",