• Mark Fasheh's avatar
    btrfs: don't go readonly on existing qgroup items · 0b4699dc
    Mark Fasheh authored
    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: default avatarMark Fasheh <mfasheh@suse.de>
    Signed-off-by: default avatarChris Mason <clm@fb.com>
    0b4699dc
qgroup.c 70.9 KB