fix bug in btrfs_init_new_device()
cover fix bug in btrfs_init_new_device()
1/3 fixes a bug which failed to reset writable when sprouting failed 2/3 is cleanup and preparatory to fix 3/3
3/3 fixes BUG_ON in btrfs_init_new_device()
Anand Jain (3):
btrfs: undo writable when sprouting fails
btrfs: cleanup btrfs_init_new_device()
btrfs: fix BUG_ON in btrfs_init_new_device()
fs/btrfs/volumes.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-)
Signature · 1 line
2.13.1
PATCH 1/3 btrfs: undo writable when sprouting fails
--- 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 1/3] btrfs: undo writable when sprouting fails
Quoted 1 line · Anand Jain
Signed-off-by Anand Jain <[email protected]>
The error_trans tag needs to revert the RDONLY flag without doubt.
But just a small question.
Just lines before error_trans tag, we're committing transaction and then relocating system chunks. In which we don't use goto error branch but returning directly.
Don't we need to to revert the RDONLY flag in that error handler?
Thanks,
Qu
Quoted 18 lines
--- 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);
Re: [PATCH 1/3] btrfs: undo writable when sprouting fails
In reply to Anand JainQuoted 1 line · Anand Jain
Signed-off-by Anand Jain <[email protected]>
This does not look like change trivial enough to just leave out the description. Please explain in more detail.
PATCH 2/3 btrfs: cleanup btrfs_init_new_device()
In reply to Anand JainMoves btrfs_abort_transaction() to the error goto and renames error_trans to error_sysfs. This is a preparatory patch to remove the BUG_ON() in btrfs_init_new_device().
--- fs/btrfs/volumes.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-)
fs/btrfs/volumes.c +9 -14
@@ -2443,26 +2443,20 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathmutex_lock (&fs_info->chunk_mutex); ret =init_first_rw_device (trans, fs_info);mutex_unlock (&fs_info->chunk_mutex); -if (ret) { -btrfs_abort_transaction (trans, ret); - goto error_trans; - } +if (ret) + goto error_sysfs; } ret =btrfs_add_device (trans, fs_info, device); -if (ret) { -btrfs_abort_transaction (trans, ret); - goto error_trans; - } +if (ret) + goto error_sysfs;if (seeding_dev) {char fsid_buf[BTRFS_UUID_UNPARSED_SIZE ]; ret =btrfs_finish_sprout (trans, fs_info); -if (ret) { -btrfs_abort_transaction (trans, ret); - goto error_trans; - } +if (ret) + goto error_sysfs;/* Sprouting would change fsid of the mounted root, * so rename the fsid on the sysfs
@@ -2500,12 +2494,13 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathupdate_dev_time (device_path);return ret; -error_trans: +error_sysfs: +btrfs_sysfs_rm_device_link (fs_info->fs_devices, device);if (seeding_dev) sb->s_flags |=MS_RDONLY ; +btrfs_abort_transaction (trans, ret);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 2/3] btrfs: cleanup btrfs_init_new_device()
Quoted 47 lines · Anand Jain
Moves
btrfs_abort_transaction()to the error goto and renameserror_transtoerror_sysfs. This is a preparatory patch to remove theBUG_ON()inbtrfs_init_new_device().Signed-off-by Anand Jain <[email protected]>--- fs/btrfs/volumes.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-)fs/btrfs/volumes.c +6
-12@@ -2443,26 +2443,20 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathmutex_lock (&fs_info->chunk_mutex); ret =init_first_rw_device (trans, fs_info);mutex_unlock (&fs_info->chunk_mutex); -if (ret) { -btrfs_abort_transaction (trans, ret); - goto error_trans; - } +if (ret) + goto error_sysfs; } ret =btrfs_add_device (trans, fs_info, device); -if (ret) { -btrfs_abort_transaction (trans, ret); - goto error_trans; - } +if (ret) + goto error_sysfs;if (seeding_dev) {char fsid_buf[BTRFS_UUID_UNPARSED_SIZE ]; ret =btrfs_finish_sprout (trans, fs_info); -if (ret) { -btrfs_abort_transaction (trans, ret); - goto error_trans; - } +if (ret) + goto error_sysfs;/* Sprouting would change fsid of the mounted root, * so rename the fsid on the sysfs
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@@ -2500,12 +2494,13 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathupdate_dev_time (device_path);return ret; -error_trans: +error_sysfs: +btrfs_sysfs_rm_device_link (fs_info->fs_devices, device);
Any reason why you move btrfs_sysfs_rm_device_link?
fs/btrfs/volumes.c int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path · line 2506
Quoted 7 lines
fs/btrfs/volumes.c +0
-1if (seeding_dev) sb->s_flags |=MS_RDONL > +btrfs_abort_transaction (trans, ret);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 );
Also which branch is your code based on since in Linus' master the error handling (before your patch) looks a bit different. E.g. the MS_RDONL stuff look wrong.
error_trans:
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);
if (seeding_dev) {
mutex_unlock(&uuid_mutex);
up_write(&sb->s_umount);
}
return ret;Quoted 1 line
Re: [PATCH 2/3] btrfs: cleanup btrfs_init_new_device()
Quoted 83 lines · Nikolay Borisov
Quoted 47 lines · Anand Jain
Moves
btrfs_abort_transaction()to the error goto and renameserror_transtoerror_sysfs. This is a preparatory patch to remove theBUG_ON()inbtrfs_init_new_device().Signed-off-by Anand Jain <[email protected]>--- fs/btrfs/volumes.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-)fs/btrfs/volumes.c +6
-12@@ -2443,26 +2443,20 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathmutex_lock (&fs_info->chunk_mutex); ret =init_first_rw_device (trans, fs_info);mutex_unlock (&fs_info->chunk_mutex); -if (ret) { -btrfs_abort_transaction (trans, ret); - goto error_trans; - } +if (ret) + goto error_sysfs; } ret =btrfs_add_device (trans, fs_info, device); -if (ret) { -btrfs_abort_transaction (trans, ret); - goto error_trans; - } +if (ret) + goto error_sysfs;if (seeding_dev) {char fsid_buf[BTRFS_UUID_UNPARSED_SIZE ]; ret =btrfs_finish_sprout (trans, fs_info); -if (ret) { -btrfs_abort_transaction (trans, ret); - goto error_trans; - } +if (ret) + goto error_sysfs;/* Sprouting would change fsid of the mounted root, * so rename the fsid on the sysfs 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@@ -2500,12 +2494,13 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathupdate_dev_time (device_path);return ret; -error_trans: +error_sysfs: +btrfs_sysfs_rm_device_link (fs_info->fs_devices, device);Any reason why you move
btrfs_sysfs_rm_device_link?fs/btrfs/volumes.c int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path · line 2506
Quoted 7 lines
fs/btrfs/volumes.c +0
-1if (seeding_dev) sb->s_flags |=MS_RDONL > +btrfs_abort_transaction (trans, ret);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 );Also which branch is your code based on since in Linus' master the error handling (before your patch) looks a bit different. E.g. the
MS_RDONLstuff look wrong.
error_trans:btrfs_end_transaction(trans); rcu_string_free(device->name); btrfs_sysfs_rm_device_link(fs_info->fs_devices, device); kfree(device);error:
Quoted 11 lines
blkdev_put(bdev, FMODE_EXCL);
if (seeding_dev) {
mutex_unlock(&uuid_mutex);
up_write(&sb->s_umount);
}
return ret;Ok, turned out I hadn't received 1/3 so this answers this question. The sysfs rm stands though
Quoted 2 lines
Quoted 2 lines
Re: [PATCH 2/3] btrfs: cleanup btrfs_init_new_device()
Quoted 3 lines
The
sysfs rm stands though
This is a preparatory patch for 3/3, at BUG_ON it needs an exit
without the btrfs_sysfs_add_device_link() part.
-Anand
Re: [PATCH 2/3] btrfs: cleanup btrfs_init_new_device()
Quoted 6 lines · Anand Jain
Quoted 3 lines
The
sysfs rm stands thoughThis is a preparatory patch for 3/3, at
BUG_ONit needs an exit
without thebtrfs_sysfs_add_device_link()part.
typo s/btrfs_sysfs_add_device_link/btrfs_sysfs_rm_device_link/
Quoted 5 lines
-Anand
Signature · 3 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
Re: [PATCH 2/3] btrfs: cleanup btrfs_init_new_device()
In reply to Anand JainQuoted 6 lines · Anand Jain
Quoted 3 lines
The
sysfs rm stands thoughThis is a preparatory patch for 3/3, at
BUG_ONit needs an exit without thebtrfs_sysfs_add_device_link()part.
In this case I'd rather you have this change in 3/3, because on its own it doesn't really make sense and cannot easily be figured out if doing git blame.
Quoted 3 lines
-Anand
Re: [PATCH 2/3] btrfs: cleanup btrfs_init_new_device()
Quoted 10 lines
Quoted 6 lines
Quoted 3 lines
The
sysfs rm stands thoughThis is a preparatory patch for 3/3, at
BUG_ONit needs an exit
without thebtrfs_sysfs_add_device_link()part.In this case I'd rather you have this change in 3/3, because on its own it doesn't really make sense and cannot easily be figured out if doing git blame.
Fixed in v3. Thanks for suggesting.
-Anand
Re: [PATCH 2/3] btrfs: cleanup btrfs_init_new_device()
In reply to Anand JainQuoted 47 lines · Anand Jain
Moves
btrfs_abort_transaction()to the error goto and renameserror_transtoerror_sysfs. This is a preparatory patch to remove theBUG_ON()inbtrfs_init_new_device().Signed-off-by Anand Jain <[email protected]>--- fs/btrfs/volumes.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-)fs/btrfs/volumes.c +6
-12@@ -2443,26 +2443,20 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathmutex_lock (&fs_info->chunk_mutex); ret =init_first_rw_device (trans, fs_info);mutex_unlock (&fs_info->chunk_mutex); -if (ret) { -btrfs_abort_transaction (trans, ret); - goto error_trans; - } +if (ret) + goto error_sysfs; } ret =btrfs_add_device (trans, fs_info, device); -if (ret) { -btrfs_abort_transaction (trans, ret); - goto error_trans; - } +if (ret) + goto error_sysfs;if (seeding_dev) {char fsid_buf[BTRFS_UUID_UNPARSED_SIZE ]; ret =btrfs_finish_sprout (trans, fs_info); -if (ret) { -btrfs_abort_transaction (trans, ret); - goto error_trans; - } +if (ret) + goto error_sysfs;/* Sprouting would change fsid of the mounted root, * so rename the fsid on the sysfs
fs/btrfs/volumes.c int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path · line 2502
Quoted 10 lines
fs/btrfs/volumes.c +3
-1@@ -2500,12 +2494,13 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathupdate_dev_time (device_path);return ret; -error_trans: +error_sysfs: +btrfs_sysfs_rm_device_link (fs_info->fs_devices, device);if (seeding_dev) sb->s_flags |=MS_RDONLY ; +btrfs_abort_transaction (trans, ret);btrfs_end_transaction (trans);
Abort then end? Looks redundant at least.
fs/btrfs/volumes.c int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path · line 2508
Quoted 2 lines
fs/btrfs/volumes.c +0
-1rcu_string_free (device->name); -btrfs_sysfs_rm_device_link (fs_info->fs_devices, device);
Any particular reason to move this line ahead?
I didn't see it has something to do with transaction, so just curious about the purpose.
Thanks,
Qu
Quoted 4 lines
fs/btrfs/volumes.c +0
-0kfree (device); error:blkdev_put (bdev,FMODE_EXCL );
Re: [PATCH 2/3] btrfs: cleanup btrfs_init_new_device()
In reply to Anand JainQuoted 3 lines · Anand Jain
Moves
btrfs_abort_transaction()to the error goto and renameserror_transtoerror_sysfs. This is a preparatory patch to remove theBUG_ON()inbtrfs_init_new_device().
Please keep all transaction abort exactly at the place where they happened and do not merge them to one. This pattern should be used everwhere and is important when debugging because we can pinpoint the line in the code from the syslog message and do not have to guess which way it got to the merged call.
This makes the binary large, looks like a code duplication in the code but for a good reason.
PATCH 3/3 btrfs: fix BUG_ON in btrfs_init_new_device()
In reply to Anand JainHere we will simply return the error to the caller. And handle the fail condition by calling the abort transaction through the error path.
--- fs/btrfs/volumes.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/btrfs/volumes.c +3 -1
@@ -2399,7 +2399,8 @@ 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) + goto error_trans; } device->fs_devices = fs_info->fs_devices;
@@ -2496,6 +2497,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path error_sysfs:btrfs_sysfs_rm_device_link (fs_info->fs_devices, device); +error_trans:if (seeding_dev) sb->s_flags |=MS_RDONLY ;btrfs_abort_transaction (trans, ret);
Signature · 1 line
2.13.1
v2 cover fix bug in btrfs_init_new_device()
In reply to Anand Jain1/3 fixes a bug which failed to reset writable when sprouting failed 2/3 is cleanup and preparatory to fix 3/3
3/3 fixes BUG_ON in btrfs_init_new_device()
v2:
add commit log to 1/3
do not consolidate btrfs_abort_transaction() in 2/3
Anand Jain (3):
btrfs: undo writable when sprouting fails
btrfs: cleanup btrfs_init_new_device()
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 v2 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.
---
v2: add commit log
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 v2 2/3 btrfs: cleanup btrfs_init_new_device()
In reply to Anand JainMoves btrfs_abort_transaction() to the error goto and renames error_trans to error_sysfs. This is a preparatory patch to remove the BUG_ON() in btrfs_init_new_device().
--- fs/btrfs/volumes.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
fs/btrfs/volumes.c +5 -5
@@ -2445,14 +2445,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 +2461,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 +2500,12 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathupdate_dev_time (device_path);return ret; -error_trans: +error_sysfs: +btrfs_sysfs_rm_device_link (fs_info->fs_devices, device);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 v2 3/3 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 through the error path.
---
v2: do not consolidate btrfs_abort_transaction()
fs/btrfs/volumes.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/btrfs/volumes.c +5 -1
@@ -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;
@@ -2502,6 +2505,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path 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);
Signature · 1 line
2.13.1