fix bug in btrfs_init_new_device()
v3 cover fix bug in btrfs_init_new_device()
1/2 fixes a bug which failed to reset writable when sprouting failed 2/2 fixes BUG_ON in btrfs_init_new_device()
Anand Jain (2):
btrfs: undo writable when sprouting fails
btrfs: fix BUG_ON in btrfs_init_new_device()
fs/btrfs/volumes.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
Signature · 1 line
2.13.1
PATCH v3 1/2 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.
--- 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
Re: [PATCH v3 1/2] btrfs: undo writable when sprouting fails
Quoted 14 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]>--- fs/btrfs/volumes.c | 2 ++ 1 file changed, 2 insertions(+)fs/btrfs/volumes.c +0
-0
fs/btrfs/volumes.c int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path · line 2505
Quoted 5 lines
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 ;
Still the same question.
---
if (seeding_dev) {
mutex_unlock(&uuid_mutex);
up_write(&sb->s_umount);
if (ret) /* transaction commit */
return ret;
ret = btrfs_relocate_sys_chunks(fs_info);
if (ret < 0)
btrfs_handle_fs_error(fs_info, ret,
"Failed to relocate sys chunks after device initialization. This
can be fixed using the \"btrfs balance\" command.");
trans = btrfs_attach_transaction(root);
if (IS_ERR(trans)) {
if (PTR_ERR(trans) == -ENOENT)
return 0;
return PTR_ERR(trans);
}---
In the above btrfs_attch_transaction() error handler, which just returned without going to error_trans tags, did we misseed the s_flag revert thing?
Thanks,
Qu
Quoted 4 lines
fs/btrfs/volumes.c +0
-0btrfs_end_transaction (trans);rcu_string_free (device->name);btrfs_sysfs_rm_device_link (fs_info->fs_devices, device);
Re: [PATCH v3 1/2] btrfs: undo writable when sprouting fails
Quoted 44 lines · Qu Wenruo
Quoted 14 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]>--- fs/btrfs/volumes.c | 2 ++ 1 file changed, 2 insertions(+)fs/btrfs/volumes.c +0
-0fs/btrfs/volumes.c int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path · line 2505
Quoted 5 lines
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 ;Still the same question.
---
if (seeding_dev) { mutex_unlock(&uuid_mutex); up_write(&sb->s_umount); if (ret) /* transaction commit */ return ret; ret = btrfs_relocate_sys_chunks(fs_info); if (ret < 0) btrfs_handle_fs_error(fs_info, ret, "Failed to relocate sys chunks after device initialization. This can be fixed using the \"btrfs balance\" command."); trans = btrfs_attach_transaction(root); if (IS_ERR(trans)) { if (PTR_ERR(trans) == -ENOENT) return 0; return PTR_ERR(trans); }
Quoted 4 lines
---
In the abovebtrfs_attch_transaction()error handler, which just returned without going toerror_transtags, did we misseed thes_flagrevert thing?
I think so. Also I think "sb->s_flags |= MS_RDONLY;" can be moved to the 'if' after the error: label, where we already check the 'seeding_dev' condition.
Re: [PATCH v3 1/2] btrfs: undo writable when sprouting fails
Quoted 50 lines · David Sterba
Quoted 44 lines · Qu Wenruo
Quoted 14 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]>--- fs/btrfs/volumes.c | 2 ++ 1 file changed, 2 insertions(+)fs/btrfs/volumes.c +0
-0fs/btrfs/volumes.c int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path · line 2505
Quoted 5 lines
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 ;Still the same question.
---
if (seeding_dev) { mutex_unlock(&uuid_mutex); up_write(&sb->s_umount); if (ret) /* transaction commit */ return ret; ret = btrfs_relocate_sys_chunks(fs_info); if (ret < 0) btrfs_handle_fs_error(fs_info, ret, "Failed to relocate sys chunks after device initialization. This can be fixed using the \"btrfs balance\" command."); trans = btrfs_attach_transaction(root); if (IS_ERR(trans)) { if (PTR_ERR(trans) == -ENOENT) return 0; return PTR_ERR(trans); }Quoted 4 lines
---
In the abovebtrfs_attch_transaction()error handler, which just returned without going toerror_transtags, did we misseed thes_flagrevert thing?
Quoted 3 lines
I think so. Also I think "
sb->s_flags|=MS_RDONLY;" can be moved to the 'if' after the error: label, where we already check the 'seeding_dev' condition.
Qu, David,
Thanks. I have fixed that in a new patch as its wasn't about fixing
the BUG_ON().
Further, there is another bug that, in the original code we failed to
undo the btrfs_prepare_sprout() part. I am attempting to fix that, its bit complicated. For now, fix for Qu found bug is sent to the ML.
-Anand
PATCH v3 2/2 btrfs: fix BUG_ON in btrfs_init_new_device()
In reply to Anand JainInstead of BUG_ON return error to the caller. And handle the fail condition by calling the abort transaction and going through the error path.
--- 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
Re: [PATCH v3 2/2] btrfs: fix BUG_ON in btrfs_init_new_device()
Quoted 5 lines · Anand Jain
Instead of
BUG_ONreturn error to the caller. And handle the fail condition by calling the abort transaction and going through the error path.Signed-off-by Anand Jain <[email protected]>
Thanks,
Qu
Quoted 62 lines
--- 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 );