Skip to contentSkip to conversation

Rendering a btrfs filesystem unmountable with the btrfs command

DISCUSSION [email protected] 2 participants 4 messages Jan 15, 2013 – Jan 17, 2013 Btrfs file system

lore
Share & tools
lore
#0 lore raw

mkfs.btrfs /dev/sdb
mkdir /tmp/mnt
mount /dev/sdb /tmp/mnt
cd /tmp/mnt
btrfs quota enable .
btrfs subvol create foo
btrfs qgroup create 1/0
btrfs qgroup assign 0/257 1/0
btrfs subvol snapshot foo bar
btrfs qgroup assign 0/258 1/0
cd ..
umount /dev/sdb
mount /dev/sdb /tmp/mnt
# Still mountable!
cd mnt
btrfs qgroup destroy 1/0
cd ..
umount /dev/sdb
mount /dev/sdb /tmp/mnt
# Oops, no longer mountable, even in recovery mode!

Help! BTW, I'm not a mailing list subscriber.

Thanks,

Signature · 3 lines
"They who can give up essential liberty to obtain a little temporary
 safety, deserve neither liberty nor safety." -- Benjanmin Franklin
-- Eric Hopper (http://www.omnifarious.org/~hopper) --
#1 lore raw
Quoted 1 line · On Tue, Jan 15, 2013 at 12:44:36PM -0800, [email protected] 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.

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

linux-3.7.2-201.fc17.x86_64/fs/btrfs/qgroup.c +6 -1
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
@@ -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)

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

Signature · 3 lines
"They who can give up essential liberty to obtain a little temporary
 safety, deserve neither liberty nor safety." -- Benjanmin Franklin
-- Eric Hopper (http://www.omnifarious.org/~hopper) --
#2 lore raw
Quoted 2 lines · On Tue, Jan 15, 2013 at 02:06:01PM -0800, [email protected] 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.

Signature · 3 lines
"They who can give up essential liberty to obtain a little temporary
 safety, deserve neither liberty nor safety." -- Benjanmin Franklin
-- Eric Hopper (http://www.omnifarious.org/~hopper) --
#3 lore raw
In reply to [email protected]

Hi Eric,

thanks for reporting this. I sent a small patch series to the list to fix this.
Sorry I forgot to CC you, will send the patches to you directly again. It would be great if you could give it some testing.

Thanks,
Arne

Quoted 24 lines · On 15.01.2013 21:44, [email protected] wrote:

mkfs.btrfs /dev/sdb
mkdir /tmp/mnt
mount /dev/sdb /tmp/mnt
cd /tmp/mnt
btrfs quota enable .
btrfs subvol create foo
btrfs qgroup create 1/0
btrfs qgroup assign 0/257 1/0
btrfs subvol snapshot foo bar
btrfs qgroup assign 0/258 1/0
cd ..
umount /dev/sdb
mount /dev/sdb /tmp/mnt
# Still mountable!
cd mnt
btrfs qgroup destroy 1/0
cd ..
umount /dev/sdb
mount /dev/sdb /tmp/mnt
# Oops, no longer mountable, even in recovery mode!

Help! BTW, I'm not a mailing list subscriber.

Thanks,