All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: return accurate error code on open failure
@ 2024-03-09 13:46 Anand Jain
  2024-03-14 13:39 ` Anand Jain
  2024-03-18 22:36 ` David Sterba
  0 siblings, 2 replies; 7+ messages in thread
From: Anand Jain @ 2024-03-09 13:46 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Anand Jain

When attempting to exclusive open a device which has no exclusive open
permission, such as a physical device associated with the flakey dm
device, the open operation will fail, resulting in a mount failure.

In this particular scenario, we erroneously return -EINVAL instead of the
correct error code provided by the bdev_open_by_path() function, which is
-EBUSY.

Fix this, by returning error code from the bdev_open_by_path() function.
With this correction, the mount error message will align with that of
ext4 and xfs.

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

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index bb0857cfbef2..8a35605822bf 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1191,6 +1191,7 @@ static int open_fs_devices(struct btrfs_fs_devices *fs_devices,
 	struct btrfs_device *device;
 	struct btrfs_device *latest_dev = NULL;
 	struct btrfs_device *tmp_device;
+	int ret_err = 0;
 
 	list_for_each_entry_safe(device, tmp_device, &fs_devices->devices,
 				 dev_list) {
@@ -1205,9 +1206,15 @@ static int open_fs_devices(struct btrfs_fs_devices *fs_devices,
 			list_del(&device->dev_list);
 			btrfs_free_device(device);
 		}
+		if (ret_err == 0 && ret != 0)
+			ret_err = ret;
 	}
-	if (fs_devices->open_devices == 0)
+
+	if (fs_devices->open_devices == 0) {
+		if (ret_err)
+			return ret_err;
 		return -EINVAL;
+	}
 
 	fs_devices->opened = 1;
 	fs_devices->latest_dev = latest_dev;
-- 
2.38.1


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

* Re: [PATCH] btrfs: return accurate error code on open failure
  2024-03-09 13:46 [PATCH] btrfs: return accurate error code on open failure Anand Jain
@ 2024-03-14 13:39 ` Anand Jain
  2024-03-14 16:50   ` Boris Burkov
  2024-03-18 22:36 ` David Sterba
  1 sibling, 1 reply; 7+ messages in thread
From: Anand Jain @ 2024-03-14 13:39 UTC (permalink / raw)
  To: linux-btrfs, boris


And this one as well, for the review. Thx.


On 3/9/24 19:16, Anand Jain wrote:
> When attempting to exclusive open a device which has no exclusive open
> permission, such as a physical device associated with the flakey dm
> device, the open operation will fail, resulting in a mount failure.
> 
> In this particular scenario, we erroneously return -EINVAL instead of the
> correct error code provided by the bdev_open_by_path() function, which is
> -EBUSY.
> 
> Fix this, by returning error code from the bdev_open_by_path() function.
> With this correction, the mount error message will align with that of
> ext4 and xfs.
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
>   fs/btrfs/volumes.c | 9 ++++++++-
>   1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index bb0857cfbef2..8a35605822bf 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -1191,6 +1191,7 @@ static int open_fs_devices(struct btrfs_fs_devices *fs_devices,
>   	struct btrfs_device *device;
>   	struct btrfs_device *latest_dev = NULL;
>   	struct btrfs_device *tmp_device;
> +	int ret_err = 0;
>   
>   	list_for_each_entry_safe(device, tmp_device, &fs_devices->devices,
>   				 dev_list) {
> @@ -1205,9 +1206,15 @@ static int open_fs_devices(struct btrfs_fs_devices *fs_devices,
>   			list_del(&device->dev_list);
>   			btrfs_free_device(device);
>   		}
> +		if (ret_err == 0 && ret != 0)
> +			ret_err = ret;
>   	}
> -	if (fs_devices->open_devices == 0)
> +
> +	if (fs_devices->open_devices == 0) {
> +		if (ret_err)
> +			return ret_err;
>   		return -EINVAL;
> +	}
>   
>   	fs_devices->opened = 1;
>   	fs_devices->latest_dev = latest_dev;


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

* Re: [PATCH] btrfs: return accurate error code on open failure
  2024-03-14 13:39 ` Anand Jain
@ 2024-03-14 16:50   ` Boris Burkov
  2024-03-18 22:34     ` David Sterba
  0 siblings, 1 reply; 7+ messages in thread
From: Boris Burkov @ 2024-03-14 16:50 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs

On Thu, Mar 14, 2024 at 07:09:24PM +0530, Anand Jain wrote:
> 
> And this one as well, for the review. Thx.
> 
> 
> On 3/9/24 19:16, Anand Jain wrote:
> > When attempting to exclusive open a device which has no exclusive open
> > permission, such as a physical device associated with the flakey dm
> > device, the open operation will fail, resulting in a mount failure.
> > 
> > In this particular scenario, we erroneously return -EINVAL instead of the
> > correct error code provided by the bdev_open_by_path() function, which is
> > -EBUSY.
> > 
> > Fix this, by returning error code from the bdev_open_by_path() function.
> > With this correction, the mount error message will align with that of
> > ext4 and xfs.
> > 
> > Signed-off-by: Anand Jain <anand.jain@oracle.com>

One small "nit", but LGTM.

Reviewed-by: Boris Burkov <boris@bur.io>

> > ---
> >   fs/btrfs/volumes.c | 9 ++++++++-
> >   1 file changed, 8 insertions(+), 1 deletion(-)
> > 
> > diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> > index bb0857cfbef2..8a35605822bf 100644
> > --- a/fs/btrfs/volumes.c
> > +++ b/fs/btrfs/volumes.c
> > @@ -1191,6 +1191,7 @@ static int open_fs_devices(struct btrfs_fs_devices *fs_devices,
> >   	struct btrfs_device *device;
> >   	struct btrfs_device *latest_dev = NULL;
> >   	struct btrfs_device *tmp_device;
> > +	int ret_err = 0;

A quick grep shows that "err" is a much more common name for the
variable when using this pattern in btrfs.

> >   	list_for_each_entry_safe(device, tmp_device, &fs_devices->devices,
> >   				 dev_list) {
> > @@ -1205,9 +1206,15 @@ static int open_fs_devices(struct btrfs_fs_devices *fs_devices,
> >   			list_del(&device->dev_list);
> >   			btrfs_free_device(device);
> >   		}
> > +		if (ret_err == 0 && ret != 0)
> > +			ret_err = ret;
> >   	}
> > -	if (fs_devices->open_devices == 0)
> > +
> > +	if (fs_devices->open_devices == 0) {
> > +		if (ret_err)
> > +			return ret_err;
> >   		return -EINVAL;
> > +	}
> >   	fs_devices->opened = 1;
> >   	fs_devices->latest_dev = latest_dev;
> 

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

* Re: [PATCH] btrfs: return accurate error code on open failure
  2024-03-14 16:50   ` Boris Burkov
@ 2024-03-18 22:34     ` David Sterba
  2024-03-19 12:07       ` Anand Jain
  0 siblings, 1 reply; 7+ messages in thread
From: David Sterba @ 2024-03-18 22:34 UTC (permalink / raw)
  To: Boris Burkov; +Cc: Anand Jain, linux-btrfs

On Thu, Mar 14, 2024 at 09:50:31AM -0700, Boris Burkov wrote:
> On Thu, Mar 14, 2024 at 07:09:24PM +0530, Anand Jain wrote:
> > 
> > And this one as well, for the review. Thx.
> > 
> > 
> > On 3/9/24 19:16, Anand Jain wrote:
> > > When attempting to exclusive open a device which has no exclusive open
> > > permission, such as a physical device associated with the flakey dm
> > > device, the open operation will fail, resulting in a mount failure.
> > > 
> > > In this particular scenario, we erroneously return -EINVAL instead of the
> > > correct error code provided by the bdev_open_by_path() function, which is
> > > -EBUSY.
> > > 
> > > Fix this, by returning error code from the bdev_open_by_path() function.
> > > With this correction, the mount error message will align with that of
> > > ext4 and xfs.
> > > 
> > > Signed-off-by: Anand Jain <anand.jain@oracle.com>
> 
> One small "nit", but LGTM.
> 
> Reviewed-by: Boris Burkov <boris@bur.io>
> 
> > > ---
> > >   fs/btrfs/volumes.c | 9 ++++++++-
> > >   1 file changed, 8 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> > > index bb0857cfbef2..8a35605822bf 100644
> > > --- a/fs/btrfs/volumes.c
> > > +++ b/fs/btrfs/volumes.c
> > > @@ -1191,6 +1191,7 @@ static int open_fs_devices(struct btrfs_fs_devices *fs_devices,
> > >   	struct btrfs_device *device;
> > >   	struct btrfs_device *latest_dev = NULL;
> > >   	struct btrfs_device *tmp_device;
> > > +	int ret_err = 0;
> 
> A quick grep shows that "err" is a much more common name for the
> variable when using this pattern in btrfs.

Well 'err' is there for historical reasons and the pattern we'd like to
use everywhere is to have 'ret' matching the function return type or a
common variable for any random function called. If there's need for more
than one 'ret' (so the function-wide is not overwritten) it's ret2 etc.
https://btrfs.readthedocs.io/en/latest/dev/Development-notes.html#code

Patches to convert err -> ret are also welcome as it can be confusing
what to use in new code when there are two ways.

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

* Re: [PATCH] btrfs: return accurate error code on open failure
  2024-03-09 13:46 [PATCH] btrfs: return accurate error code on open failure Anand Jain
  2024-03-14 13:39 ` Anand Jain
@ 2024-03-18 22:36 ` David Sterba
  2024-03-19  2:43   ` Anand Jain
  1 sibling, 1 reply; 7+ messages in thread
From: David Sterba @ 2024-03-18 22:36 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs

On Sat, Mar 09, 2024 at 07:16:35PM +0530, Anand Jain wrote:
> When attempting to exclusive open a device which has no exclusive open
> permission, such as a physical device associated with the flakey dm
> device, the open operation will fail, resulting in a mount failure.
> 
> In this particular scenario, we erroneously return -EINVAL instead of the
> correct error code provided by the bdev_open_by_path() function, which is
> -EBUSY.
> 
> Fix this, by returning error code from the bdev_open_by_path() function.
> With this correction, the mount error message will align with that of
> ext4 and xfs.
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
>  fs/btrfs/volumes.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index bb0857cfbef2..8a35605822bf 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -1191,6 +1191,7 @@ static int open_fs_devices(struct btrfs_fs_devices *fs_devices,
>  	struct btrfs_device *device;
>  	struct btrfs_device *latest_dev = NULL;
>  	struct btrfs_device *tmp_device;
> +	int ret_err = 0;

Please use 'ret' here

>  
>  	list_for_each_entry_safe(device, tmp_device, &fs_devices->devices,
>  				 dev_list) {
> @@ -1205,9 +1206,15 @@ static int open_fs_devices(struct btrfs_fs_devices *fs_devices,
>  			list_del(&device->dev_list);
>  			btrfs_free_device(device);
>  		}
> +		if (ret_err == 0 && ret != 0)

and rename the original 'ret' used in the scope as 'ret2', this is the
preferred pattern. For simple changes within one function it's ok to do
it in one patch.

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

* Re: [PATCH] btrfs: return accurate error code on open failure
  2024-03-18 22:36 ` David Sterba
@ 2024-03-19  2:43   ` Anand Jain
  0 siblings, 0 replies; 7+ messages in thread
From: Anand Jain @ 2024-03-19  2:43 UTC (permalink / raw)
  To: dsterba; +Cc: linux-btrfs



On 3/19/24 04:06, David Sterba wrote:
> On Sat, Mar 09, 2024 at 07:16:35PM +0530, Anand Jain wrote:
>> When attempting to exclusive open a device which has no exclusive open
>> permission, such as a physical device associated with the flakey dm
>> device, the open operation will fail, resulting in a mount failure.
>>
>> In this particular scenario, we erroneously return -EINVAL instead of the
>> correct error code provided by the bdev_open_by_path() function, which is
>> -EBUSY.
>>
>> Fix this, by returning error code from the bdev_open_by_path() function.
>> With this correction, the mount error message will align with that of
>> ext4 and xfs.
>>
>> Signed-off-by: Anand Jain <anand.jain@oracle.com>
>> ---
>>   fs/btrfs/volumes.c | 9 ++++++++-
>>   1 file changed, 8 insertions(+), 1 deletion(-)
>>
>> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
>> index bb0857cfbef2..8a35605822bf 100644
>> --- a/fs/btrfs/volumes.c
>> +++ b/fs/btrfs/volumes.c
>> @@ -1191,6 +1191,7 @@ static int open_fs_devices(struct btrfs_fs_devices *fs_devices,
>>   	struct btrfs_device *device;
>>   	struct btrfs_device *latest_dev = NULL;
>>   	struct btrfs_device *tmp_device;
>> +	int ret_err = 0;
> 
> Please use 'ret' here
> 
>>   
>>   	list_for_each_entry_safe(device, tmp_device, &fs_devices->devices,
>>   				 dev_list) {
>> @@ -1205,9 +1206,15 @@ static int open_fs_devices(struct btrfs_fs_devices *fs_devices,
>>   			list_del(&device->dev_list);
>>   			btrfs_free_device(device);
>>   		}
>> +		if (ret_err == 0 && ret != 0)
> 
> and rename the original 'ret' used in the scope as 'ret2', this is the
> preferred pattern. For simple changes within one function it's ok to do
> it in one patch.

Yep. Done.

Thanks, Anand

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

* Re: [PATCH] btrfs: return accurate error code on open failure
  2024-03-18 22:34     ` David Sterba
@ 2024-03-19 12:07       ` Anand Jain
  0 siblings, 0 replies; 7+ messages in thread
From: Anand Jain @ 2024-03-19 12:07 UTC (permalink / raw)
  To: dsterba, Boris Burkov; +Cc: linux-btrfs

On 3/19/24 04:04, David Sterba wrote:
> On Thu, Mar 14, 2024 at 09:50:31AM -0700, Boris Burkov wrote:
>> On Thu, Mar 14, 2024 at 07:09:24PM +0530, Anand Jain wrote:
>>>
>>> And this one as well, for the review. Thx.
>>>
>>>
>>> On 3/9/24 19:16, Anand Jain wrote:
>>>> When attempting to exclusive open a device which has no exclusive open
>>>> permission, such as a physical device associated with the flakey dm
>>>> device, the open operation will fail, resulting in a mount failure.
>>>>
>>>> In this particular scenario, we erroneously return -EINVAL instead of the
>>>> correct error code provided by the bdev_open_by_path() function, which is
>>>> -EBUSY.
>>>>
>>>> Fix this, by returning error code from the bdev_open_by_path() function.
>>>> With this correction, the mount error message will align with that of
>>>> ext4 and xfs.
>>>>
>>>> Signed-off-by: Anand Jain <anand.jain@oracle.com>
>>
>> One small "nit", but LGTM.
>>
>> Reviewed-by: Boris Burkov <boris@bur.io>
>>
>>>> ---
>>>>    fs/btrfs/volumes.c | 9 ++++++++-
>>>>    1 file changed, 8 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
>>>> index bb0857cfbef2..8a35605822bf 100644
>>>> --- a/fs/btrfs/volumes.c
>>>> +++ b/fs/btrfs/volumes.c
>>>> @@ -1191,6 +1191,7 @@ static int open_fs_devices(struct btrfs_fs_devices *fs_devices,
>>>>    	struct btrfs_device *device;
>>>>    	struct btrfs_device *latest_dev = NULL;
>>>>    	struct btrfs_device *tmp_device;
>>>> +	int ret_err = 0;
>>
>> A quick grep shows that "err" is a much more common name for the
>> variable when using this pattern in btrfs.
> 

> Well 'err' is there for historical reasons and the pattern we'd like to
> use everywhere is to have 'ret' matching the function return type or a
> common variable for any random function called. If there's need for more
> than one 'ret' (so the function-wide is not overwritten) it's ret2 etc.
> https://btrfs.readthedocs.io/en/latest/dev/Development-notes.html#code
> 

> Patches to convert err -> ret are also welcome as it can be confusing
> what to use in new code when there are two ways.

I have made these changes in all the functions. I will send them soon.
It looks nice with that consistency.

Thanks, Anand

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

end of thread, other threads:[~2024-03-19 12:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-09 13:46 [PATCH] btrfs: return accurate error code on open failure Anand Jain
2024-03-14 13:39 ` Anand Jain
2024-03-14 16:50   ` Boris Burkov
2024-03-18 22:34     ` David Sterba
2024-03-19 12:07       ` Anand Jain
2024-03-18 22:36 ` David Sterba
2024-03-19  2:43   ` Anand Jain

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.