btrfs: undo writable when sprouting fails
PATCH v4 1/3 btrfs: undo writable when sprouting fails
When new device is being added to seed FS, seed FS is marked writable, but when we fail to bring in the new device, we missed to undo the writable part. This patch fixes it.
---
v4: none
v3: none
v2: add commit log
v1: moving sb->s_flags |= MS_RDONLY; to further below to error:
is not a good idea because, goto error; comes from a place where sb->s_flags &= ~MS_RDONLY; has not yet been called.
fs/btrfs/volumes.c | 2 ++ 1 file changed, 2 insertions(+)
fs/btrfs/volumes.c +2 -0
@@ -2501,6 +2501,8 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathreturn ret; error_trans: +if (seeding_dev) + sb->s_flags |=MS_RDONLY ;btrfs_end_transaction (trans);rcu_string_free (device->name);btrfs_sysfs_rm_device_link (fs_info->fs_devices, device);
Signature · 1 line
2.13.1
PATCH v4 2/3 btrfs: fix BUG_ON in btrfs_init_new_device()
Instead of BUG_ON return error to the caller. And handle the fail condition by calling the abort transaction and going through the error path.
---
v4: none;
v3: meld this with
btrfs: cleanup btrfs_init_new_device()
v2: do not consolidate btrfs_abort_transaction()
fs/btrfs/volumes.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
fs/btrfs/volumes.c +9 -5
@@ -2399,7 +2399,10 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathif (seeding_dev) { sb->s_flags &= ~MS_RDONLY ; ret =btrfs_prepare_sprout (fs_info); -BUG_ON (ret);/* -ENOMEM */ +if (ret) { +btrfs_abort_transaction (trans, ret); + goto error_trans; + } } device->fs_devices = fs_info->fs_devices;
@@ -2445,14 +2448,14 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathmutex_unlock (&fs_info->chunk_mutex);if (ret) {btrfs_abort_transaction (trans, ret); - goto error_trans; + goto error_sysfs; } } ret =btrfs_add_device (trans, fs_info, device);if (ret) {btrfs_abort_transaction (trans, ret); - goto error_trans; + goto error_sysfs; }if (seeding_dev) {
@@ -2461,7 +2464,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path ret =btrfs_finish_sprout (trans, fs_info);if (ret) {btrfs_abort_transaction (trans, ret); - goto error_trans; + goto error_sysfs; }/* Sprouting would change fsid of the mounted root,
@@ -2500,12 +2503,13 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathupdate_dev_time (device_path);return ret; +error_sysfs: +btrfs_sysfs_rm_device_link (fs_info->fs_devices, device); error_trans:if (seeding_dev) sb->s_flags |=MS_RDONLY ;btrfs_end_transaction (trans);rcu_string_free (device->name); -btrfs_sysfs_rm_device_link (fs_info->fs_devices, device);kfree (device); error:blkdev_put (bdev,FMODE_EXCL );
Signature · 1 line
2.13.1
PATCH v4 3/3 btrfs: error out if btrfs_attach_transaction() fails
In reply to Anand Jainbtrfs_init_new_device() calls btrfs_attach_transaction() to commit sys chunks, and it should error out if it fails.
---
v4: make this patch as part of this set.
avoid double mutext unlock.
v3: not part of this set
v2: patch did not exist
v1: patch did not exist
fs/btrfs/volumes.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
fs/btrfs/volumes.c +5 -2
@@ -2323,6 +2323,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathu64 tmp;int seeding_dev =0 ;int ret =0 ; +bool unlocked = false;if (sb_rdonly (sb) && !fs_info->fs_devices->seeding)return -EROFS ;
@@ -2482,6 +2483,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathif (seeding_dev) {mutex_unlock (&uuid_mutex);up_write (&sb->s_umount); + unlocked = true;if (ret)/* transaction commit */ return ret;
@@ -2494,7 +2496,8 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathif (IS_ERR (trans)) {if (PTR_ERR (trans) == -ENOENT )return 0 ; -return PTR_ERR (trans); + ret =PTR_ERR (trans); + goto error_sysfs; } ret =btrfs_commit_transaction (trans); }
@@ -2513,7 +2516,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathkfree (device); error:blkdev_put (bdev,FMODE_EXCL ); -if (seeding_dev) { +if (seeding_dev && !unlocked) {mutex_unlock (&uuid_mutex);up_write (&sb->s_umount); }
Signature · 1 line
2.13.1
Quoted 6 lines · Anand Jain
When new device is being added to seed FS, seed FS is marked writable, but when we fail to bring in the new device, we missed to undo the writable part. This patch fixes it.
Signed-off-by Anand Jain <[email protected]>Reviewed-by Nikolay Borisov <[email protected]>
Thanks, 1-3 added to the queue.