All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: take the error path out if btrfs_attach_transaction() fails
@ 2017-09-27  9:50 Anand Jain
  2017-09-27 11:52 ` Qu Wenruo
  2017-09-27 14:17 ` David Sterba
  0 siblings, 2 replies; 5+ messages in thread
From: Anand Jain @ 2017-09-27  9:50 UTC (permalink / raw)
  To: linux-btrfs; +Cc: quwenruo.btrfs, dsterba

btrfs_init_new_device() calls btrfs_attach_transaction() to
commit sys chunks, however take the error path out if it fails.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/volumes.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index fad3b10a1f81..b526d13a74da 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2494,7 +2494,8 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
 		if (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);
 	}
-- 
2.13.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] btrfs: take the error path out if btrfs_attach_transaction() fails
  2017-09-27  9:50 [PATCH] btrfs: take the error path out if btrfs_attach_transaction() fails Anand Jain
@ 2017-09-27 11:52 ` Qu Wenruo
  2017-09-27 14:17 ` David Sterba
  1 sibling, 0 replies; 5+ messages in thread
From: Qu Wenruo @ 2017-09-27 11:52 UTC (permalink / raw)
  To: Anand Jain, linux-btrfs; +Cc: dsterba



On 2017年09月27日 17:50, Anand Jain wrote:
> btrfs_init_new_device() calls btrfs_attach_transaction() to
> commit sys chunks, however take the error path out if it fails.
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>

Reviewed-by: Qu Wenruo <quwenruo.btrfs@gmx.com>

Thanks,
Qu

> ---
>   fs/btrfs/volumes.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index fad3b10a1f81..b526d13a74da 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -2494,7 +2494,8 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
>   		if (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);
>   	}
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] btrfs: take the error path out if btrfs_attach_transaction() fails
  2017-09-27  9:50 [PATCH] btrfs: take the error path out if btrfs_attach_transaction() fails Anand Jain
  2017-09-27 11:52 ` Qu Wenruo
@ 2017-09-27 14:17 ` David Sterba
  2017-09-28  7:13   ` Anand Jain
  1 sibling, 1 reply; 5+ messages in thread
From: David Sterba @ 2017-09-27 14:17 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs, quwenruo.btrfs, dsterba

On Wed, Sep 27, 2017 at 05:50:52PM +0800, Anand Jain wrote:
> btrfs_init_new_device() calls btrfs_attach_transaction() to
> commit sys chunks, however take the error path out if it fails.
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
>  fs/btrfs/volumes.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index fad3b10a1f81..b526d13a74da 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -2494,7 +2494,8 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
>  		if (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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] btrfs: take the error path out if btrfs_attach_transaction() fails
  2017-09-27 14:17 ` David Sterba
@ 2017-09-28  7:13   ` Anand Jain
  2017-09-29 17:31     ` David Sterba
  0 siblings, 1 reply; 5+ messages in thread
From: Anand Jain @ 2017-09-28  7:13 UTC (permalink / raw)
  To: dsterba, linux-btrfs, quwenruo.btrfs



On 09/27/2017 10:17 PM, David Sterba wrote:
> On Wed, Sep 27, 2017 at 05:50:52PM +0800, Anand Jain wrote:
>> btrfs_init_new_device() calls btrfs_attach_transaction() to
>> commit sys chunks, however take the error path out if it fails.
>>
>> Signed-off-by: Anand Jain <anand.jain@oracle.com>
>> ---
>>   fs/btrfs/volumes.c | 3 ++-
>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
>> index fad3b10a1f81..b526d13a74da 100644
>> --- a/fs/btrfs/volumes.c
>> +++ b/fs/btrfs/volumes.c
>> @@ -2494,7 +2494,8 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
>>   		if (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.

> 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.

  Fixed this in
    [PATCH v4 3/3] btrfs: error out if btrfs_attach_transaction() 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.

   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


> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] btrfs: take the error path out if btrfs_attach_transaction() fails
  2017-09-28  7:13   ` Anand Jain
@ 2017-09-29 17:31     ` David Sterba
  0 siblings, 0 replies; 5+ messages in thread
From: David Sterba @ 2017-09-29 17:31 UTC (permalink / raw)
  To: Anand Jain; +Cc: dsterba, linux-btrfs, quwenruo.btrfs

On Thu, Sep 28, 2017 at 03:13:06PM +0800, Anand Jain wrote:
> > 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.

Yeah, this would make the code better structured.

>     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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-09-29 17:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-27  9:50 [PATCH] btrfs: take the error path out if btrfs_attach_transaction() fails Anand Jain
2017-09-27 11:52 ` Qu Wenruo
2017-09-27 14:17 ` David Sterba
2017-09-28  7:13   ` Anand Jain
2017-09-29 17:31     ` David Sterba

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.