btrfs: take the error path out if btrfs_attach_transaction() fails
PATCH 1/1 btrfs: take the error path out if btrfs_attach_transaction() fails
btrfs_init_new_device() calls btrfs_attach_transaction() to commit sys chunks, however take the error path out if it fails.
--- fs/btrfs/volumes.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/btrfs/volumes.c +2 -1
@@ -2494,7 +2494,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); }
Signature · 1 line
2.13.1
Quoted 4 lines · Anand Jain
btrfs_init_new_device()callsbtrfs_attach_transaction()to commit sys chunks, however take the error path out if it fails.Signed-off-by Anand Jain <[email protected]>
Thanks,
Qu
Quoted 19 lines
--- fs/btrfs/volumes.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)fs/btrfs/volumes.c +2
-1@@ -2494,7 +2494,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); }
Quoted 13 lines · Anand Jain
btrfs_init_new_device()callsbtrfs_attach_transaction()to commit sys chunks, however take the error path out if it fails.Signed-off-by Anand Jain <[email protected]>--- fs/btrfs/volumes.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)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 2498
Quoted 6 lines
fs/btrfs/volumes.c +2
-1@@ -2494,7 +2494,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;
The label is introduced by another patch, please resend the whole patchset, I've seen several iterations and feedback from various people and I'm not sure I'm looking at the latest version.
Regarding error handling in btrfs_init_new_device, the seeding device makes it hard to read. This patch would lead to a double unlock of uuid_mutex and sb::s_umount, because the label error_sysfs will continue to do the cleanups, that were already partially done in the containing 'if (seeding_dev)' block where the test fails.
I'd suggest to first get rid of the in-place returns and add necessary labels or separate exit sequences and then address the new error handling.
Quoted 9 lines · David Sterba
Quoted 8 lines · Anand Jain
btrfs_init_new_device()callsbtrfs_attach_transaction()to commit sys chunks, however take the error path out if it fails.Signed-off-by Anand Jain <[email protected]>--- fs/btrfs/volumes.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 15 lines
fs/btrfs/volumes.c int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path · line 2498
Quoted 11 lines
fs/btrfs/volumes.c +2
-1@@ -2494,7 +2494,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;The label is introduced by another patch, please resend the whole patchset, I've seen several iterations and feedback from various people and I'm not sure I'm looking at the latest version.
Pls consider V4, in the ML.
Quoted 5 lines
Regarding error handling in
btrfs_init_new_device, the seeding device makes it hard to read. This patch would lead to a double unlock ofuuid_mutexandsb::s_umount, because the labelerror_sysfswill continue to do the cleanups, that were already partially done in the containing 'if (seeding_dev)' block where the test fails.
Fixed this in
[PATCH v4 3/3] btrfs: error out if btrfs_attach_transaction() fails
Quoted 3 lines
I'd suggest to first get rid of the in-place returns and add necessary labels or separate exit sequences and then address the new error handling.
As it goes deeper there are quite a number of things which aren't un-done during fail error return .. adding one more to the list is sb->super_copy updates. With this current design on this function its kind of too difficult to undo and error return. As btrfs_init_new_device() is shared between normal device add and sprout device add. I am mulling on completely removing seed part to outside of the btrfs_init_new_device(). such as ..
prepare sprout.
ret = btrfs_init_new_device() which is without the seed part if(ret) undo_prepare_sprout
else finish sprouting.
Also with this I think we would find few duplicate code sections between btrfs_init_new_device() and replace device which will be a nice cleanup as a whole. This is a long term plan, for now I think v4 is good.
Thanks, Anand
Quoted 5 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 4 lines · Anand Jain
Quoted 3 lines
I'd suggest to first get rid of the in-place returns and add necessary labels or separate exit sequences and then address the new error handling.
Quoted 11 lines
As it goes deeper there are quite a number of things which aren't un-done during fail error return .. adding one more to the list is
sb->super_copyupdates. With this current design on this function its kind of too difficult to undo and error return. Asbtrfs_init_new_device()is shared between normal device add and sprout device add. I am mulling on completely removing seed part to outside of thebtrfs_init_new_device(). such as ..
prepare sprout.
ret =btrfs_init_new_device()which is without the seed part if(ret)undo_prepare_sprout
else finish sprouting.
Yeah, this would make the code better structured.
Quoted 4 lines
Also with this I think we would find few duplicate code sections between
btrfs_init_new_device()and replace device which will be a nice cleanup as a whole. This is a long term plan, for now I think v4 is good.
Ok, thanks.