Skip to content

Commit

Permalink
Btrfs: set dead flag on the right root when destroying snapshot
Browse files Browse the repository at this point in the history
We were setting the BTRFS_ROOT_SUBVOL_DEAD flag on the root of the
parent of our target snapshot, instead of setting it in the target
snapshot's root.

This is easy to observe by running the following scenario:

    mkfs.btrfs -f /dev/sdd
    mount /dev/sdd /mnt

    btrfs subvolume create /mnt/first_subvol
    btrfs subvolume snapshot -r /mnt /mnt/mysnap1

    btrfs subvolume delete /mnt/first_subvol
    btrfs subvolume snapshot -r /mnt /mnt/mysnap2

    btrfs send -p /mnt/mysnap1 /mnt/mysnap2 -f /tmp/send.data

The send command failed because the send ioctl returned -EPERM.
A test case for xfstests follows.

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Reviewed-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
  • Loading branch information
Filipe Manana authored and Chris Mason committed Jun 10, 2014
1 parent c125b8b commit c55bfa6
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions fs/btrfs/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2312,16 +2312,16 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
* again is not run concurrently.
*/
spin_lock(&dest->root_item_lock);
root_flags = btrfs_root_flags(&root->root_item);
if (root->send_in_progress == 0) {
btrfs_set_root_flags(&root->root_item,
root_flags = btrfs_root_flags(&dest->root_item);
if (dest->send_in_progress == 0) {
btrfs_set_root_flags(&dest->root_item,
root_flags | BTRFS_ROOT_SUBVOL_DEAD);
spin_unlock(&dest->root_item_lock);
} else {
spin_unlock(&dest->root_item_lock);
btrfs_warn(root->fs_info,
"Attempt to delete subvolume %llu during send",
root->root_key.objectid);
dest->root_key.objectid);
err = -EPERM;
goto out_dput;
}
Expand Down Expand Up @@ -2416,8 +2416,8 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
out_unlock:
if (err) {
spin_lock(&dest->root_item_lock);
root_flags = btrfs_root_flags(&root->root_item);
btrfs_set_root_flags(&root->root_item,
root_flags = btrfs_root_flags(&dest->root_item);
btrfs_set_root_flags(&dest->root_item,
root_flags & ~BTRFS_ROOT_SUBVOL_DEAD);
spin_unlock(&dest->root_item_lock);
}
Expand Down

0 comments on commit c55bfa6

Please sign in to comment.