diff mbox

Rendering a btrfs filesystem unmountable with the btrfs command

Message ID 20130115220601.GD18291@omnifarious.org (mailing list archive)
State New, archived
Headers show

Commit Message

hopper@omnifarious.org Jan. 15, 2013, 10:06 p.m. UTC
On Tue, Jan 15, 2013 at 12:44:36PM -0800, hopper@omnifarious.org wrote:
> Help!  BTW, I'm not a mailing list subscriber.

Here is a sample fix that I believe will allow the offending filesystem
to at least be mounted.  It hasn't been tested at all.

----------------------------
----------------------------

Comments

hopper@omnifarious.org Jan. 16, 2013, 3:42 p.m. UTC | #1
On Tue, Jan 15, 2013 at 02:06:01PM -0800, hopper@omnifarious.org wrote:
> Here is a sample fix that I believe will allow the offending filesystem
> to at least be mounted.  It hasn't been tested at all.

I got this patch into a kernel and tested it. It does indeed allow the
offending filesystem to be mounted.  I'm not convinced it's the best
possible patch.  Perhaps instead the place where the return value of the
function that's being patched is used should be changed instead.

Here is some data showing what the problem is...

# btrfs qgroup show .
0/266 97579008 97579008
0/268 97640448 97640448
1/1 97619968 97619968

# btrfs-debug-tree /dev/sdb3 | fgrep QGROUP_RELATION_KEY
  item 7 key (0/266 BTRFS_QGROUP_RELATION_KEY 1/0) itemoff 3723 itemsize 0
  item 8 key (0/266 BTRFS_QGROUP_RELATION_KEY 1/1) itemoff 3723 itemsize 0
  item 9 key (0/267 BTRFS_QGROUP_RELATION_KEY 1/0) itemoff 3723 itemsize 0
  item 10 key (0/268 BTRFS_QGROUP_RELATION_KEY 1/0) itemoff 3723 itemsize 0
  item 11 key (0/268 BTRFS_QGROUP_RELATION_KEY 1/1) itemoff 3723 itemsize 0
  item 12 key (1/0 BTRFS_QGROUP_RELATION_KEY 0/266) itemoff 3723 itemsize 0
  item 13 key (1/0 BTRFS_QGROUP_RELATION_KEY 0/267) itemoff 3723 itemsize 0
  item 14 key (1/0 BTRFS_QGROUP_RELATION_KEY 0/268) itemoff 3723 itemsize 0
  item 15 key (1/1 BTRFS_QGROUP_RELATION_KEY 0/266) itemoff 3723 itemsize 0
  item 16 key (1/1 BTRFS_QGROUP_RELATION_KEY 0/268) itemoff 3723 itemsize 0

Notice how there are a whole bunch of QGROUP_RELATION_KEY records that
refer to qgroups that no longer exist (1/0 and 0/267).  This is because
a qgroup destroy was done on these qgroups but the corresponding
QGROUP_RELATION_KEY records were not removed.
diff mbox

Patch

diff -ur kernel-3.7.fc17.orig/linux-3.7.2-201.fc17.x86_64/fs/btrfs/qgroup.c kernel-3.7.fc17/linux-3.7.2-201.fc17.x86_64/fs/btrfs/qgroup.c
--- kernel-3.7.fc17.orig/linux-3.7.2-201.fc17.x86_64/fs/btrfs/qgroup.c	2012-12-10 19:30:57.000000000 -0800
+++ kernel-3.7.fc17/linux-3.7.2-201.fc17.x86_64/fs/btrfs/qgroup.c	2013-01-15 14:02:39.643630137 -0800
@@ -379,8 +379,13 @@ 
 
 		ret = add_relation_rb(fs_info, found_key.objectid,
 				      found_key.offset);
-		if (ret)
+		/* Failing to add a relation because one side or the other
+		 * doesn't exist isn't a fatal error here. */
+		if (ret) {
+			if (ret == -ENOENT)
+				ret = ENOENT;
 			goto out;
+		}
 next2:
 		ret = btrfs_next_item(quota_root, path);
 		if (ret < 0)