linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ligtnvm: if LUNs are already allocated fix return
@ 2017-05-13 19:50 Rakesh Pandit
  2017-05-15  6:31 ` Javier Gonzalez
  0 siblings, 1 reply; 7+ messages in thread
From: Rakesh Pandit @ 2017-05-13 19:50 UTC (permalink / raw)
  To: Matias Bjørling; +Cc: linux-block, linux-kernel, Javier González

While creating new device with NVM_DEV_CREATE if LUNs are already
allocated ioctl would return -ENOMEM which is wrong.  This patch
propagates -EBUSY from nvm_reserve_luns which is correct response.

Fixes: ade69e243 ("lightnvm: merge gennvm with core")
Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
---
 drivers/lightnvm/core.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
index 6a4aa60..440deb5 100644
--- a/drivers/lightnvm/core.c
+++ b/drivers/lightnvm/core.c
@@ -235,7 +235,7 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create)
 	struct nvm_target *t;
 	struct nvm_tgt_dev *tgt_dev;
 	void *targetdata;
-	int ret;
+	int ret = 0;
 
 	tt = nvm_find_target_type(create->tgttype, 1);
 	if (!tt) {
@@ -252,8 +252,9 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create)
 	}
 	mutex_unlock(&dev->mlock);
 
-	if (nvm_reserve_luns(dev, s->lun_begin, s->lun_end))
-		return -ENOMEM;
+	ret = nvm_reserve_luns(dev, s->lun_begin, s->lun_end);
+	if (ret)
+		goto err;
 
 	t = kmalloc(sizeof(struct nvm_target), GFP_KERNEL);
 	if (!t) {
@@ -314,8 +315,8 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create)
 	mutex_lock(&dev->mlock);
 	list_add_tail(&t->list, &dev->targets);
 	mutex_unlock(&dev->mlock);
-
-	return 0;
+err:
+	return ret;
 err_sysfs:
 	if (tt->exit)
 		tt->exit(targetdata);
-- 
2.9.3

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

* Re: [PATCH] ligtnvm: if LUNs are already allocated fix return
  2017-05-13 19:50 [PATCH] ligtnvm: if LUNs are already allocated fix return Rakesh Pandit
@ 2017-05-15  6:31 ` Javier Gonzalez
  2017-05-29  9:05   ` Rakesh Pandit
  0 siblings, 1 reply; 7+ messages in thread
From: Javier Gonzalez @ 2017-05-15  6:31 UTC (permalink / raw)
  To: Rakesh Pandit; +Cc: Matias Bjørling, linux-block, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1742 bytes --]

> 
> On 13 May 2017, at 21.50, Rakesh Pandit <rakesh@tuxera.com> wrote:
> 
> While creating new device with NVM_DEV_CREATE if LUNs are already
> allocated ioctl would return -ENOMEM which is wrong.  This patch
> propagates -EBUSY from nvm_reserve_luns which is correct response.
> 
> Fixes: ade69e243 ("lightnvm: merge gennvm with core")
> Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
> ---
> drivers/lightnvm/core.c | 11 ++++++-----
> 1 file changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
> index 6a4aa60..440deb5 100644
> --- a/drivers/lightnvm/core.c
> +++ b/drivers/lightnvm/core.c
> @@ -235,7 +235,7 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create)
> 	struct nvm_target *t;
> 	struct nvm_tgt_dev *tgt_dev;
> 	void *targetdata;
> -	int ret;
> +	int ret = 0;
> 
> 	tt = nvm_find_target_type(create->tgttype, 1);
> 	if (!tt) {
> @@ -252,8 +252,9 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create)
> 	}
> 	mutex_unlock(&dev->mlock);
> 
> -	if (nvm_reserve_luns(dev, s->lun_begin, s->lun_end))
> -		return -ENOMEM;
> +	ret = nvm_reserve_luns(dev, s->lun_begin, s->lun_end);
> +	if (ret)
> +		goto err;
> 
> 	t = kmalloc(sizeof(struct nvm_target), GFP_KERNEL);
> 	if (!t) {
> @@ -314,8 +315,8 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create)
> 	mutex_lock(&dev->mlock);
> 	list_add_tail(&t->list, &dev->targets);
> 	mutex_unlock(&dev->mlock);
> -
> -	return 0;
> +err:
> +	return ret;
> err_sysfs:
> 	if (tt->exit)
> 		tt->exit(targetdata);
> --
> 2.9.3

Looks good.

Reviewed-by: Javier González <javier@cnexlabs.com>


[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

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

* Re: [PATCH] ligtnvm: if LUNs are already allocated fix return
  2017-05-15  6:31 ` Javier Gonzalez
@ 2017-05-29  9:05   ` Rakesh Pandit
  2017-05-30 13:24     ` Matias Bjørling
  0 siblings, 1 reply; 7+ messages in thread
From: Rakesh Pandit @ 2017-05-29  9:05 UTC (permalink / raw)
  To: Matias Bjørling; +Cc: linux-block, linux-kernel, Javier Gonzalez

Hi Matias,

On Mon, May 15, 2017 at 06:31:58AM +0000, Javier Gonzalez wrote:
> > 
> > On 13 May 2017, at 21.50, Rakesh Pandit <rakesh@tuxera.com> wrote:
> > 
> > While creating new device with NVM_DEV_CREATE if LUNs are already
> > allocated ioctl would return -ENOMEM which is wrong.  This patch
> > propagates -EBUSY from nvm_reserve_luns which is correct response.
> > 
> > Fixes: ade69e243 ("lightnvm: merge gennvm with core")
> > Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
> > ---
> > drivers/lightnvm/core.c | 11 ++++++-----
> > 1 file changed, 6 insertions(+), 5 deletions(-)
> > 
> > diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
> > index 6a4aa60..440deb5 100644
> > --- a/drivers/lightnvm/core.c
> > +++ b/drivers/lightnvm/core.c
> > @@ -235,7 +235,7 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create)
> > 	struct nvm_target *t;
> > 	struct nvm_tgt_dev *tgt_dev;
> > 	void *targetdata;
> > -	int ret;
> > +	int ret = 0;
> > 
> > 	tt = nvm_find_target_type(create->tgttype, 1);
> > 	if (!tt) {
> > @@ -252,8 +252,9 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create)
> > 	}
> > 	mutex_unlock(&dev->mlock);
> > 
> > -	if (nvm_reserve_luns(dev, s->lun_begin, s->lun_end))
> > -		return -ENOMEM;
> > +	ret = nvm_reserve_luns(dev, s->lun_begin, s->lun_end);
> > +	if (ret)
> > +		goto err;
> > 
> > 	t = kmalloc(sizeof(struct nvm_target), GFP_KERNEL);
> > 	if (!t) {
> > @@ -314,8 +315,8 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create)
> > 	mutex_lock(&dev->mlock);
> > 	list_add_tail(&t->list, &dev->targets);
> > 	mutex_unlock(&dev->mlock);
> > -
> > -	return 0;
> > +err:
> > +	return ret;
> > err_sysfs:
> > 	if (tt->exit)
> > 		tt->exit(targetdata);
> > --
> > 2.9.3
> 
> Looks good.
> 
> Reviewed-by: Javier González <javier@cnexlabs.com>
> 

May you review/approve this so that it gets queued ?

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

* Re: [PATCH] ligtnvm: if LUNs are already allocated fix return
  2017-05-29  9:05   ` Rakesh Pandit
@ 2017-05-30 13:24     ` Matias Bjørling
  0 siblings, 0 replies; 7+ messages in thread
From: Matias Bjørling @ 2017-05-30 13:24 UTC (permalink / raw)
  To: Rakesh Pandit; +Cc: linux-block, linux-kernel, Javier Gonzalez

On Mon, May 29, 2017 at 11:05 AM, Rakesh Pandit <rakesh@tuxera.com> wrote:
> Hi Matias,
>
> On Mon, May 15, 2017 at 06:31:58AM +0000, Javier Gonzalez wrote:
>> >
>> > On 13 May 2017, at 21.50, Rakesh Pandit <rakesh@tuxera.com> wrote:
>> >
>> > While creating new device with NVM_DEV_CREATE if LUNs are already
>> > allocated ioctl would return -ENOMEM which is wrong.  This patch
>> > propagates -EBUSY from nvm_reserve_luns which is correct response.
>> >
>> > Fixes: ade69e243 ("lightnvm: merge gennvm with core")
>> > Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
>> > ---
>> > drivers/lightnvm/core.c | 11 ++++++-----
>> > 1 file changed, 6 insertions(+), 5 deletions(-)
>> >
>> > diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
>> > index 6a4aa60..440deb5 100644
>> > --- a/drivers/lightnvm/core.c
>> > +++ b/drivers/lightnvm/core.c
>> > @@ -235,7 +235,7 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create)
>> >     struct nvm_target *t;
>> >     struct nvm_tgt_dev *tgt_dev;
>> >     void *targetdata;
>> > -   int ret;
>> > +   int ret = 0;
>> >
>> >     tt = nvm_find_target_type(create->tgttype, 1);
>> >     if (!tt) {
>> > @@ -252,8 +252,9 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create)
>> >     }
>> >     mutex_unlock(&dev->mlock);
>> >
>> > -   if (nvm_reserve_luns(dev, s->lun_begin, s->lun_end))
>> > -           return -ENOMEM;
>> > +   ret = nvm_reserve_luns(dev, s->lun_begin, s->lun_end);
>> > +   if (ret)
>> > +           goto err;
>> >
>> >     t = kmalloc(sizeof(struct nvm_target), GFP_KERNEL);
>> >     if (!t) {
>> > @@ -314,8 +315,8 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create)
>> >     mutex_lock(&dev->mlock);
>> >     list_add_tail(&t->list, &dev->targets);
>> >     mutex_unlock(&dev->mlock);
>> > -
>> > -   return 0;
>> > +err:
>> > +   return ret;
>> > err_sysfs:
>> >     if (tt->exit)
>> >             tt->exit(targetdata);
>> > --
>> > 2.9.3
>>
>> Looks good.
>>
>> Reviewed-by: Javier González <javier@cnexlabs.com>
>>
>
> May you review/approve this so that it gets queued ?

Thanks, Rakesh. Will do. Queued it up for 4.13.

-Matias

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

* Re: [PATCH] ligtnvm: if LUNs are already allocated fix return
  2017-06-27  9:06   ` Frans Klaver
@ 2017-06-27  9:58     ` Rakesh Pandit
  0 siblings, 0 replies; 7+ messages in thread
From: Rakesh Pandit @ 2017-06-27  9:58 UTC (permalink / raw)
  To: Frans Klaver
  Cc: Matias Bjørling, axboe, linux-block, linux-kernel,
	Matias Bjørling

Hi Frans,

On Tue, Jun 27, 2017 at 11:06:44AM +0200, Frans Klaver wrote:
> On Tue, Jun 27, 2017 at 10:39 AM, Matias Bjørling wrote:
> > From: Rakesh Pandit <rakesh@tuxera.com>
> >
> > While creating new device with NVM_DEV_CREATE if LUNs are already
> > allocated ioctl would return -ENOMEM which is wrong.  This patch
> > propagates -EBUSY from nvm_reserve_luns which is correct response.
> >
> > Fixes: ade69e243 ("lightnvm: merge gennvm with core")
> > Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
> > Signed-off-by: Matias Bjørling <matias@cnexlabs.com>
> > ---
> >  drivers/lightnvm/core.c | 11 ++++++-----
> >  1 file changed, 6 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
> > index b8f82f5..9ff348f 100644
> > --- a/drivers/lightnvm/core.c
> > +++ b/drivers/lightnvm/core.c
> > @@ -235,7 +235,7 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create)
> >         struct nvm_target *t;
> >         struct nvm_tgt_dev *tgt_dev;
> >         void *targetdata;
> > -       int ret;
> > +       int ret = 0;
> 
> Is there any way that you can reach a 'return ret' without having ret
> set by some other assignment?
> 
>

No.

I should have been more careful.

> >         tt = nvm_find_target_type(create->tgttype, 1);
> >         if (!tt) {
> > @@ -252,8 +252,9 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create)
> >         }
> >         mutex_unlock(&dev->mlock);
> >
> > -       if (nvm_reserve_luns(dev, s->lun_begin, s->lun_end))
> > -               return -ENOMEM;
> > +       ret = nvm_reserve_luns(dev, s->lun_begin, s->lun_end);
> > +       if (ret)
> > +               goto err;
> 
> Why don't you return err straight away here?

Intent was to future-proofing if num_reserve_luns would return
anything other than -EBUSY and 0 but yes returning -EBUSY directly
would be fine.

> 
> 
> >         t = kmalloc(sizeof(struct nvm_target), GFP_KERNEL);
> >         if (!t) {
> > @@ -314,8 +315,8 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create)
> >         mutex_lock(&dev->mlock);
> >         list_add_tail(&t->list, &dev->targets);
> >         mutex_unlock(&dev->mlock);
> > -
> > -       return 0;
> > +err:
> > +       return ret;
> 
> This should not be necessary. In any case, the de-init order should
> always be the reverse of the init order, so we don't end up confused.

Only if we directly return -EBUSY.  Good point about getting confused
I would resend quickly by directly returning error.  That would not
confuse folks.

I would send an alternate patch which returns -EBUSY directly and do
same thing.

Thanks,

> 
> Frans

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

* Re: [PATCH] ligtnvm: if LUNs are already allocated fix return
  2017-06-27  8:39 ` [PATCH] ligtnvm: if LUNs are already allocated fix return Matias Bjørling
@ 2017-06-27  9:06   ` Frans Klaver
  2017-06-27  9:58     ` Rakesh Pandit
  0 siblings, 1 reply; 7+ messages in thread
From: Frans Klaver @ 2017-06-27  9:06 UTC (permalink / raw)
  To: Matias Bjørling
  Cc: axboe, linux-block, linux-kernel, Rakesh Pandit, Matias Bjørling

On Tue, Jun 27, 2017 at 10:39 AM, Matias Bjørling <m@bjorling.me> wrote:
> From: Rakesh Pandit <rakesh@tuxera.com>
>
> While creating new device with NVM_DEV_CREATE if LUNs are already
> allocated ioctl would return -ENOMEM which is wrong.  This patch
> propagates -EBUSY from nvm_reserve_luns which is correct response.
>
> Fixes: ade69e243 ("lightnvm: merge gennvm with core")
> Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
> Signed-off-by: Matias Bjørling <matias@cnexlabs.com>
> ---
>  drivers/lightnvm/core.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
> index b8f82f5..9ff348f 100644
> --- a/drivers/lightnvm/core.c
> +++ b/drivers/lightnvm/core.c
> @@ -235,7 +235,7 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create)
>         struct nvm_target *t;
>         struct nvm_tgt_dev *tgt_dev;
>         void *targetdata;
> -       int ret;
> +       int ret = 0;

Is there any way that you can reach a 'return ret' without having ret
set by some other assignment?


>         tt = nvm_find_target_type(create->tgttype, 1);
>         if (!tt) {
> @@ -252,8 +252,9 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create)
>         }
>         mutex_unlock(&dev->mlock);
>
> -       if (nvm_reserve_luns(dev, s->lun_begin, s->lun_end))
> -               return -ENOMEM;
> +       ret = nvm_reserve_luns(dev, s->lun_begin, s->lun_end);
> +       if (ret)
> +               goto err;

Why don't you return err straight away here?


>         t = kmalloc(sizeof(struct nvm_target), GFP_KERNEL);
>         if (!t) {
> @@ -314,8 +315,8 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create)
>         mutex_lock(&dev->mlock);
>         list_add_tail(&t->list, &dev->targets);
>         mutex_unlock(&dev->mlock);
> -
> -       return 0;
> +err:
> +       return ret;

This should not be necessary. In any case, the de-init order should
always be the reverse of the init order, so we don't end up confused.

Frans

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

* [PATCH] ligtnvm: if LUNs are already allocated fix return
  2017-06-27  8:39 [PATCH] Small patch for 4.13 window Matias Bjørling
@ 2017-06-27  8:39 ` Matias Bjørling
  2017-06-27  9:06   ` Frans Klaver
  0 siblings, 1 reply; 7+ messages in thread
From: Matias Bjørling @ 2017-06-27  8:39 UTC (permalink / raw)
  To: axboe; +Cc: linux-block, linux-kernel, Rakesh Pandit, Matias Bjørling

From: Rakesh Pandit <rakesh@tuxera.com>

While creating new device with NVM_DEV_CREATE if LUNs are already
allocated ioctl would return -ENOMEM which is wrong.  This patch
propagates -EBUSY from nvm_reserve_luns which is correct response.

Fixes: ade69e243 ("lightnvm: merge gennvm with core")
Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
Signed-off-by: Matias Bjørling <matias@cnexlabs.com>
---
 drivers/lightnvm/core.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
index b8f82f5..9ff348f 100644
--- a/drivers/lightnvm/core.c
+++ b/drivers/lightnvm/core.c
@@ -235,7 +235,7 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create)
 	struct nvm_target *t;
 	struct nvm_tgt_dev *tgt_dev;
 	void *targetdata;
-	int ret;
+	int ret = 0;
 
 	tt = nvm_find_target_type(create->tgttype, 1);
 	if (!tt) {
@@ -252,8 +252,9 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create)
 	}
 	mutex_unlock(&dev->mlock);
 
-	if (nvm_reserve_luns(dev, s->lun_begin, s->lun_end))
-		return -ENOMEM;
+	ret = nvm_reserve_luns(dev, s->lun_begin, s->lun_end);
+	if (ret)
+		goto err;
 
 	t = kmalloc(sizeof(struct nvm_target), GFP_KERNEL);
 	if (!t) {
@@ -314,8 +315,8 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create)
 	mutex_lock(&dev->mlock);
 	list_add_tail(&t->list, &dev->targets);
 	mutex_unlock(&dev->mlock);
-
-	return 0;
+err:
+	return ret;
 err_sysfs:
 	if (tt->exit)
 		tt->exit(targetdata);
-- 
2.9.3

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

end of thread, other threads:[~2017-06-27  9:58 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-13 19:50 [PATCH] ligtnvm: if LUNs are already allocated fix return Rakesh Pandit
2017-05-15  6:31 ` Javier Gonzalez
2017-05-29  9:05   ` Rakesh Pandit
2017-05-30 13:24     ` Matias Bjørling
2017-06-27  8:39 [PATCH] Small patch for 4.13 window Matias Bjørling
2017-06-27  8:39 ` [PATCH] ligtnvm: if LUNs are already allocated fix return Matias Bjørling
2017-06-27  9:06   ` Frans Klaver
2017-06-27  9:58     ` Rakesh Pandit

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).