Skip to content

Commit c55bfa6

Browse files
fdmananamasoncl
authored andcommitted
Btrfs: set dead flag on the right root when destroying snapshot
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 <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: Chris Mason <[email protected]>
1 parent c125b8b commit c55bfa6

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

fs/btrfs/ioctl.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2312,16 +2312,16 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
23122312
* again is not run concurrently.
23132313
*/
23142314
spin_lock(&dest->root_item_lock);
2315-
root_flags = btrfs_root_flags(&root->root_item);
2316-
if (root->send_in_progress == 0) {
2317-
btrfs_set_root_flags(&root->root_item,
2315+
root_flags = btrfs_root_flags(&dest->root_item);
2316+
if (dest->send_in_progress == 0) {
2317+
btrfs_set_root_flags(&dest->root_item,
23182318
root_flags | BTRFS_ROOT_SUBVOL_DEAD);
23192319
spin_unlock(&dest->root_item_lock);
23202320
} else {
23212321
spin_unlock(&dest->root_item_lock);
23222322
btrfs_warn(root->fs_info,
23232323
"Attempt to delete subvolume %llu during send",
2324-
root->root_key.objectid);
2324+
dest->root_key.objectid);
23252325
err = -EPERM;
23262326
goto out_dput;
23272327
}
@@ -2416,8 +2416,8 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
24162416
out_unlock:
24172417
if (err) {
24182418
spin_lock(&dest->root_item_lock);
2419-
root_flags = btrfs_root_flags(&root->root_item);
2420-
btrfs_set_root_flags(&root->root_item,
2419+
root_flags = btrfs_root_flags(&dest->root_item);
2420+
btrfs_set_root_flags(&dest->root_item,
24212421
root_flags & ~BTRFS_ROOT_SUBVOL_DEAD);
24222422
spin_unlock(&dest->root_item_lock);
24232423
}

0 commit comments

Comments
 (0)