]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
btrfs: don't go readonly on existing qgroup items
authorMark Fasheh <mfasheh@suse.de>
Mon, 18 Aug 2014 21:01:17 +0000 (14:01 -0700)
committerChris Mason <clm@fb.com>
Wed, 17 Sep 2014 20:38:19 +0000 (13:38 -0700)
btrfs_drop_snapshot() leaves subvolume qgroup items on disk after
completion. This can cause problems with snapshot creation. If a new
snapshot tries to claim the deleted subvolumes id, btrfs will get -EEXIST
from add_qgroup_item() and go read-only. The following commands will
reproduce this problem (assume btrfs is on /dev/sda and is mounted at
/btrfs)

mkfs.btrfs -f /dev/sda
mount -t btrfs /dev/sda /btrfs/
btrfs quota enable /btrfs/
btrfs su sna /btrfs/ /btrfs/snap
btrfs su de /btrfs/snap
sleep 45
umount /btrfs/
mount -t btrfs /dev/sda /btrfs/

We can fix this by catching -EEXIST in add_qgroup_item() and
initializing the existing items. We have the problem of orphaned
relation items being on disk from an old snapshot but that is outside
the scope of this patch.

Signed-off-by: Mark Fasheh <mfasheh@suse.de>
Signed-off-by: Chris Mason <clm@fb.com>
fs/btrfs/qgroup.c

index 1e4c6e95ab558cd0b77dec55fb76bf32873afb8a..cd9717ea8c9d6836fcec160be631771c69ab3323 100644 (file)
@@ -551,9 +551,15 @@ static int add_qgroup_item(struct btrfs_trans_handle *trans,
        key.type = BTRFS_QGROUP_INFO_KEY;
        key.offset = qgroupid;
 
+       /*
+        * Avoid a transaction abort by catching -EEXIST here. In that
+        * case, we proceed by re-initializing the existing structure
+        * on disk.
+        */
+
        ret = btrfs_insert_empty_item(trans, quota_root, path, &key,
                                      sizeof(*qgroup_info));
-       if (ret)
+       if (ret && ret != -EEXIST)
                goto out;
 
        leaf = path->nodes[0];
@@ -572,7 +578,7 @@ static int add_qgroup_item(struct btrfs_trans_handle *trans,
        key.type = BTRFS_QGROUP_LIMIT_KEY;
        ret = btrfs_insert_empty_item(trans, quota_root, path, &key,
                                      sizeof(*qgroup_limit));
-       if (ret)
+       if (ret && ret != -EEXIST)
                goto out;
 
        leaf = path->nodes[0];