All of lore.kernel.org
 help / color / mirror / Atom feed
From: Josef Bacik <jbacik@fusionio.com>
To: <linux-btrfs@vger.kernel.org>
Subject: [PATCH] Btrfs-progs: allow --init-extent-tree to work when extent tree is borked
Date: Fri, 25 Oct 2013 14:01:40 -0400	[thread overview]
Message-ID: <1382724100-5276-1-git-send-email-jbacik@fusionio.com> (raw)

Unfortunately you can't run --init-extent-tree if you can't actually read the
extent root.  Fix this by allowing partial starts with no extent root and then
have fsck only check to see if the extent root is uptodate _after_ the check to
see if we are init'ing the extent tree.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
---
 cmds-check.c |  9 ++++++---
 disk-io.c    | 16 ++++++++++++++--
 2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/cmds-check.c b/cmds-check.c
index 69b0327..8ed7baa 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -5932,7 +5932,7 @@ static int reinit_extent_tree(struct btrfs_fs_info *fs_info)
 	}
 
 	/* Ok we can allocate now, reinit the extent root */
-	ret = btrfs_fsck_reinit_root(trans, fs_info->extent_root, 1);
+	ret = btrfs_fsck_reinit_root(trans, fs_info->extent_root, 0);
 	if (ret) {
 		fprintf(stderr, "extent root initialization failed\n");
 		/*
@@ -6118,20 +6118,23 @@ int cmd_check(int argc, char **argv)
 
 	if (!extent_buffer_uptodate(info->tree_root->node) ||
 	    !extent_buffer_uptodate(info->dev_root->node) ||
-	    !extent_buffer_uptodate(info->extent_root->node) ||
 	    !extent_buffer_uptodate(info->chunk_root->node)) {
 		fprintf(stderr, "Critical roots corrupted, unable to fsck the FS\n");
 		return -EIO;
 	}
 
 	root = info->fs_root;
-
 	if (init_extent_tree) {
 		printf("Creating a new extent tree\n");
 		ret = reinit_extent_tree(info);
 		if (ret)
 			return ret;
 	}
+	if (!extent_buffer_uptodate(info->extent_root->node)) {
+		fprintf(stderr, "Critical roots corrupted, unable to fsck the FS\n");
+		return -EIO;
+	}
+
 	fprintf(stderr, "checking extents\n");
 	if (init_csum_tree) {
 		struct btrfs_trans_handle *trans;
diff --git a/disk-io.c b/disk-io.c
index 733714d..c5ee33a 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -877,7 +877,17 @@ int btrfs_setup_all_roots(struct btrfs_fs_info *fs_info,
 				  fs_info->extent_root);
 	if (ret) {
 		printk("Couldn't setup extent tree\n");
-		return -EIO;
+		if (!partial)
+			return -EIO;
+		/* Need a blank node here just so we don't screw up in the
+		 * million of places that assume a root has a valid ->node
+		 */
+		fs_info->extent_root->node =
+			btrfs_find_create_tree_block(fs_info->extent_root, 0,
+						     leafsize);
+		if (!fs_info->extent_root->node)
+			return -ENOMEM;
+		clear_extent_buffer_uptodate(NULL, fs_info->extent_root->node);
 	}
 	fs_info->extent_root->track_dirty = 1;
 
@@ -906,7 +916,9 @@ int btrfs_setup_all_roots(struct btrfs_fs_info *fs_info,
 
 	fs_info->generation = generation;
 	fs_info->last_trans_committed = generation;
-	btrfs_read_block_groups(fs_info->tree_root);
+
+	if (extent_buffer_uptodate(fs_info->extent_root->node))
+		btrfs_read_block_groups(fs_info->tree_root);
 
 	key.objectid = BTRFS_FS_TREE_OBJECTID;
 	key.type = BTRFS_ROOT_ITEM_KEY;
-- 
1.8.3.1


             reply	other threads:[~2013-10-25 18:01 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-25 18:01 Josef Bacik [this message]
2013-10-25 18:27 ` [PATCH] Btrfs-progs: allow --init-extent-tree to work when extent tree is borked Martin
2013-10-25 18:31   ` Josef Bacik
2013-10-26 23:16     ` Martin
2013-10-27  1:44       ` Josef Back
2013-10-28 15:11       ` Josef Bacik
2013-11-07  1:25         ` Martin
2013-11-11 22:52           ` Martin
2013-11-13 12:08             ` Martin
2013-11-13 13:46               ` Duncan
2013-11-15 17:18               ` Martin
2013-11-19  6:34                 ` Martin
2013-11-20  6:51                   ` btrfsck --repair /dev/sdc (Was: [PATCH] Btrfs-progs: allow --init-extent-tree to work when extent tree is borked) Martin
2013-11-20 17:08                     ` Duncan
2013-11-20 20:00                       ` Martin
2013-11-25 23:18                         ` Martin
2013-11-27  6:29                           ` Martin
2013-11-20 20:03                       ` Martin
2013-11-19  6:25           ` [PATCH] Btrfs-progs: allow --init-extent-tree to work when extent tree is borked Martin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1382724100-5276-1-git-send-email-jbacik@fusionio.com \
    --to=jbacik@fusionio.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.