From patchwork Mon Mar 18 20:03:44 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 2294951 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 441823FCF6 for ; Mon, 18 Mar 2013 19:56:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754639Ab3CRT42 (ORCPT ); Mon, 18 Mar 2013 15:56:28 -0400 Received: from dkim2.fusionio.com ([66.114.96.54]:52256 "EHLO dkim2.fusionio.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753197Ab3CRT41 (ORCPT ); Mon, 18 Mar 2013 15:56:27 -0400 Received: from mx1.fusionio.com (unknown [10.101.1.160]) by dkim2.fusionio.com (Postfix) with ESMTP id 11C5D9A03DD for ; Mon, 18 Mar 2013 13:56:27 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fusionio.com; s=default; t=1363636587; bh=vJ6L4s3v7PzVa5k26HWrXTdfvJYDKpLmqc7qIFfOz4o=; h=From:To:Subject:Date; b=Sj4ahyitb6nhktIsr27K3DhO1/tcWL8LeYQLW/bh031u3GmmnAUvSge9QoZ187AFr pXH5nyCnk0UAtn5/8LtHdFXEOtQaT2L267D7zBL28mSMJTcZHo3obzVeAVIOwRrG0U rDnY1E9Mp7YqRtLF2nIQwLIwdjygWThj08/sU4x8= X-ASG-Debug-ID: 1363636586-03d6a52ac02cda0001-6jHSXT Received: from mail1.int.fusionio.com (mail1.int.fusionio.com [10.101.1.21]) by mx1.fusionio.com with ESMTP id dSTqLmSmGmAbIEYw (version=TLSv1 cipher=AES128-SHA bits=128 verify=NO) for ; Mon, 18 Mar 2013 13:56:26 -0600 (MDT) X-Barracuda-Envelope-From: JBacik@fusionio.com Received: from localhost (98.26.82.158) by mail.fusionio.com (10.101.1.19) with Microsoft SMTP Server (TLS) id 8.3.83.0; Mon, 18 Mar 2013 13:56:25 -0600 From: Josef Bacik To: Subject: [PATCH] Btrfs-progs: make btrfs-image copy the tree logs if they exist Date: Mon, 18 Mar 2013 16:03:44 -0400 X-ASG-Orig-Subj: [PATCH] Btrfs-progs: make btrfs-image copy the tree logs if they exist Message-ID: <1363637024-6512-1-git-send-email-jbacik@fusionio.com> X-Mailer: git-send-email 1.7.7.6 MIME-Version: 1.0 X-Barracuda-Connect: mail1.int.fusionio.com[10.101.1.21] X-Barracuda-Start-Time: 1363636586 X-Barracuda-Encrypted: AES128-SHA X-Barracuda-URL: http://10.101.1.180:8000/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at fusionio.com X-Barracuda-Bayes: INNOCENT GLOBAL 0.0000 1.0000 -2.0210 X-Barracuda-Spam-Score: -2.02 X-Barracuda-Spam-Status: No, SCORE=-2.02 using per-user scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=9.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.2.125575 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Currently btrfs-image doesn't copy the tree logs, which doesn't help me when we're trying to debug log replay bugs. Since we don't have entries in the extent root for the blocks we have to walk down all of the trees in order to copy them. With this patch I can image a file system with a tree log and it works fine. Thanks, Signed-off-by: Josef Bacik --- btrfs-image.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 81 insertions(+), 0 deletions(-) diff --git a/btrfs-image.c b/btrfs-image.c index ee9ab56..ad028de 100644 --- a/btrfs-image.c +++ b/btrfs-image.c @@ -532,6 +532,84 @@ static int is_tree_block(struct btrfs_root *extent_root, } #endif +static int copy_log_blocks(struct btrfs_root *root, struct extent_buffer *eb, + struct metadump_struct *metadump, + int log_root_tree) +{ + struct extent_buffer *tmp; + struct btrfs_root_item *ri; + struct btrfs_key key; + u64 bytenr; + int level; + int nritems = 0; + int i = 0; + int ret; + + ret = add_metadata(btrfs_header_bytenr(eb), root->leafsize, metadump); + if (ret) { + fprintf(stderr, "Error adding metadata block\n"); + return ret; + } + + if (btrfs_header_level(eb) == 0 && !log_root_tree) + return 0; + + level = btrfs_header_level(eb); + nritems = btrfs_header_nritems(eb); + for (i = 0; i < nritems; i++) { + if (level == 0) { + btrfs_item_key_to_cpu(eb, &key, i); + if (key.type != BTRFS_ROOT_ITEM_KEY) + continue; + ri = btrfs_item_ptr(eb, i, struct btrfs_root_item); + bytenr = btrfs_disk_root_bytenr(eb, ri); + tmp = read_tree_block(root, bytenr, root->leafsize, 0); + if (!tmp) { + fprintf(stderr, "Error reading log root " + "block\n"); + return -EIO; + } + ret = copy_log_blocks(root, tmp, metadump, 0); + free_extent_buffer(tmp); + if (ret) + return ret; + } else { + bytenr = btrfs_node_blockptr(eb, i); + tmp = read_tree_block(root, bytenr, root->leafsize, 0); + if (!tmp) { + fprintf(stderr, "Error reading log block\n"); + return -EIO; + } + ret = copy_log_blocks(root, tmp, metadump, + log_root_tree); + free_extent_buffer(tmp); + if (ret) + return ret; + } + } + + return 0; +} + +static int copy_log_trees(struct btrfs_root *root, + struct metadump_struct *metadump, + struct btrfs_path *path) +{ + u64 blocknr = btrfs_super_log_root(&root->fs_info->super_copy); + + if (blocknr == 0) + return 0; + + if (!root->fs_info->log_root_tree || + !root->fs_info->log_root_tree->node) { + fprintf(stderr, "Error copying tree log, it wasn't setup\n"); + return -EIO; + } + + return copy_log_blocks(root, root->fs_info->log_root_tree->node, + metadump, 1); +} + static int create_metadump(const char *input, FILE *out, int num_threads, int compress_level) { @@ -662,6 +740,9 @@ static int create_metadump(const char *input, FILE *out, int num_threads, bytenr += num_bytes; } + ret = copy_log_trees(root, &metadump, path); + if (ret) + err = ret; out: ret = flush_pending(&metadump, 1); if (ret) {