All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lightnvm: remove targets when corresponding nvm device exit
@ 2015-11-24 16:03 Wenwei Tao
  2015-11-24 18:51 ` Matias
  0 siblings, 1 reply; 3+ messages in thread
From: Wenwei Tao @ 2015-11-24 16:03 UTC (permalink / raw)
  To: mb; +Cc: linux-kernel, linux-block

the target should be unreachable when underlying device was gone.

Signed-off-by: Wenwei Tao <ww.tao0320@gmail.com>
---
 drivers/lightnvm/core.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
index f659e60..b95c6c4 100644
--- a/drivers/lightnvm/core.c
+++ b/drivers/lightnvm/core.c
@@ -278,10 +278,18 @@ err:
 	return ret;
 }
 
+static void nvm_remove_target(struct nvm_target *t);
+
 static void nvm_exit(struct nvm_dev *dev)
 {
+	struct nvm_target *t, *n;
+
 	if (dev->ppalist_pool)
 		dev->ops->destroy_dma_pool(dev->ppalist_pool);
+	down_write(&nvm_lock);
+	list_for_each_entry_safe(t, n, &dev->online_targets, list)
+		nvm_remove_target(t);
+	up_write(&nvm_lock);
 	nvm_free(dev);
 
 	pr_info("nvm: successfully unloaded\n");
@@ -496,13 +504,13 @@ static int __nvm_configure_create(struct nvm_ioctl_create *create)
 
 static int __nvm_configure_remove(struct nvm_ioctl_remove *remove)
 {
-	struct nvm_target *t = NULL;
+	struct nvm_target *n, *t = NULL;
 	struct nvm_dev *dev;
 	int ret = -1;
 
 	down_write(&nvm_lock);
 	list_for_each_entry(dev, &nvm_devices, devices)
-		list_for_each_entry(t, &dev->online_targets, list) {
+		list_for_each_entry_safe(t, n, &dev->online_targets, list) {
 			if (!strcmp(remove->tgtname, t->disk->disk_name)) {
 				nvm_remove_target(t);
 				ret = 0;
-- 
1.9.1


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

* Re: [PATCH] lightnvm: remove targets when corresponding nvm device exit
  2015-11-24 16:03 [PATCH] lightnvm: remove targets when corresponding nvm device exit Wenwei Tao
@ 2015-11-24 18:51 ` Matias
  2015-11-25  9:23   ` Wenwei Tao
  0 siblings, 1 reply; 3+ messages in thread
From: Matias @ 2015-11-24 18:51 UTC (permalink / raw)
  To: Wenwei Tao; +Cc: linux-kernel, linux-block

On 11/24/2015 05:03 PM, Wenwei Tao wrote:
> the target should be unreachable when underlying device was gone.
>
> Signed-off-by: Wenwei Tao <ww.tao0320@gmail.com>
> ---
>   drivers/lightnvm/core.c | 12 ++++++++++--
>   1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
> index f659e60..b95c6c4 100644
> --- a/drivers/lightnvm/core.c
> +++ b/drivers/lightnvm/core.c
> @@ -278,10 +278,18 @@ err:
>   	return ret;
>   }
>
> +static void nvm_remove_target(struct nvm_target *t);
> +

You can move the hole declaration up here.

>   static void nvm_exit(struct nvm_dev *dev)
>   {
> +	struct nvm_target *t, *n;
> +
>   	if (dev->ppalist_pool)
>   		dev->ops->destroy_dma_pool(dev->ppalist_pool);
> +	down_write(&nvm_lock);
> +	list_for_each_entry_safe(t, n, &dev->online_targets, list)
> +		nvm_remove_target(t);
> +	up_write(&nvm_lock);

list_for_each_entry_safe should be enough here.

Actually, we should properly block any creations of new targets when 
nvm_exit is called. To prevent new ones to be created while we clean up.

Let me know if you want to submit a patch for this. Else I'll just apply 
this one with the suggested changes. Thanks Tao.

>   	nvm_free(dev);
>
>   	pr_info("nvm: successfully unloaded\n");
> @@ -496,13 +504,13 @@ static int __nvm_configure_create(struct nvm_ioctl_create *create)
>
>   static int __nvm_configure_remove(struct nvm_ioctl_remove *remove)
>   {
> -	struct nvm_target *t = NULL;
> +	struct nvm_target *n, *t = NULL;
>   	struct nvm_dev *dev;
>   	int ret = -1;
>
>   	down_write(&nvm_lock);
>   	list_for_each_entry(dev, &nvm_devices, devices)
> -		list_for_each_entry(t, &dev->online_targets, list) {
> +		list_for_each_entry_safe(t, n, &dev->online_targets, list) {
>   			if (!strcmp(remove->tgtname, t->disk->disk_name)) {
>   				nvm_remove_target(t);
>   				ret = 0;
>

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

* Re: [PATCH] lightnvm: remove targets when corresponding nvm device exit
  2015-11-24 18:51 ` Matias
@ 2015-11-25  9:23   ` Wenwei Tao
  0 siblings, 0 replies; 3+ messages in thread
From: Wenwei Tao @ 2015-11-25  9:23 UTC (permalink / raw)
  To: Matias; +Cc: linux-kernel, linux-block

I will send a patch for that.

2015-11-25 2:51 GMT+08:00 Matias <mb@lightnvm.io>:
> On 11/24/2015 05:03 PM, Wenwei Tao wrote:
>>
>> the target should be unreachable when underlying device was gone.
>>
>> Signed-off-by: Wenwei Tao <ww.tao0320@gmail.com>
>> ---
>>   drivers/lightnvm/core.c | 12 ++++++++++--
>>   1 file changed, 10 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
>> index f659e60..b95c6c4 100644
>> --- a/drivers/lightnvm/core.c
>> +++ b/drivers/lightnvm/core.c
>> @@ -278,10 +278,18 @@ err:
>>         return ret;
>>   }
>>
>> +static void nvm_remove_target(struct nvm_target *t);
>> +
>
>
> You can move the hole declaration up here.
>
>>   static void nvm_exit(struct nvm_dev *dev)
>>   {
>> +       struct nvm_target *t, *n;
>> +
>>         if (dev->ppalist_pool)
>>                 dev->ops->destroy_dma_pool(dev->ppalist_pool);
>> +       down_write(&nvm_lock);
>> +       list_for_each_entry_safe(t, n, &dev->online_targets, list)
>> +               nvm_remove_target(t);
>> +       up_write(&nvm_lock);
>
>
> list_for_each_entry_safe should be enough here.
>
> Actually, we should properly block any creations of new targets when
> nvm_exit is called. To prevent new ones to be created while we clean up.
>
> Let me know if you want to submit a patch for this. Else I'll just apply
> this one with the suggested changes. Thanks Tao.
>
>
>>         nvm_free(dev);
>>
>>         pr_info("nvm: successfully unloaded\n");
>> @@ -496,13 +504,13 @@ static int __nvm_configure_create(struct
>> nvm_ioctl_create *create)
>>
>>   static int __nvm_configure_remove(struct nvm_ioctl_remove *remove)
>>   {
>> -       struct nvm_target *t = NULL;
>> +       struct nvm_target *n, *t = NULL;
>>         struct nvm_dev *dev;
>>         int ret = -1;
>>
>>         down_write(&nvm_lock);
>>         list_for_each_entry(dev, &nvm_devices, devices)
>> -               list_for_each_entry(t, &dev->online_targets, list) {
>> +               list_for_each_entry_safe(t, n, &dev->online_targets, list)
>> {
>>                         if (!strcmp(remove->tgtname, t->disk->disk_name))
>> {
>>                                 nvm_remove_target(t);
>>                                 ret = 0;
>>
>

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

end of thread, other threads:[~2015-11-25  9:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-24 16:03 [PATCH] lightnvm: remove targets when corresponding nvm device exit Wenwei Tao
2015-11-24 18:51 ` Matias
2015-11-25  9:23   ` Wenwei Tao

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.