Skip to content

Commit 597d2e0

Browse files
boryasgregkh
authored andcommitted
btrfs: do not clear read-only when adding sprout device
[ Upstream commit 70958a9 ] If you follow the seed/sprout wiki, it suggests the following workflow: btrfstune -S 1 seed_dev mount seed_dev mnt btrfs device add sprout_dev mount -o remount,rw mnt The first mount mounts the FS readonly, which results in not setting BTRFS_FS_OPEN, and setting the readonly bit on the sb. The device add somewhat surprisingly clears the readonly bit on the sb (though the mount is still practically readonly, from the users perspective...). Finally, the remount checks the readonly bit on the sb against the flag and sees no change, so it does not run the code intended to run on ro->rw transitions, leaving BTRFS_FS_OPEN unset. As a result, when the cleaner_kthread runs, it sees no BTRFS_FS_OPEN and does no work. This results in leaking deleted snapshots until we run out of space. I propose fixing it at the first departure from what feels reasonable: when we clear the readonly bit on the sb during device add. A new fstest I have written reproduces the bug and confirms the fix. Reviewed-by: Qu Wenruo <[email protected]> Signed-off-by: Boris Burkov <[email protected]> Signed-off-by: David Sterba <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 5d261f6 commit 597d2e0

File tree

1 file changed

+0
-4
lines changed

1 file changed

+0
-4
lines changed

fs/btrfs/volumes.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2842,8 +2842,6 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
28422842
set_blocksize(device->bdev_file, BTRFS_BDEV_BLOCKSIZE);
28432843

28442844
if (seeding_dev) {
2845-
btrfs_clear_sb_rdonly(sb);
2846-
28472845
/* GFP_KERNEL allocation must not be under device_list_mutex */
28482846
seed_devices = btrfs_init_sprout(fs_info);
28492847
if (IS_ERR(seed_devices)) {
@@ -2986,8 +2984,6 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
29862984
mutex_unlock(&fs_info->chunk_mutex);
29872985
mutex_unlock(&fs_info->fs_devices->device_list_mutex);
29882986
error_trans:
2989-
if (seeding_dev)
2990-
btrfs_set_sb_rdonly(sb);
29912987
if (trans)
29922988
btrfs_end_transaction(trans);
29932989
error_free_zone:

0 commit comments

Comments
 (0)