public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Matias Bjørling" <mb@lightnvm.io>
To: Wenwei Tao <wwtao0320@163.com>
Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org,
	ww.tao0320@gmail.com
Subject: Re: [PATCH 2/2] lightnvm: hold nvm_lock until finish the target creation
Date: Thu, 19 May 2016 14:42:25 +0200	[thread overview]
Message-ID: <573DB4B1.1050501@lightnvm.io> (raw)
In-Reply-To: <1463639921-1824-2-git-send-email-wwtao0320@163.com>

On 05/19/2016 08:38 AM, Wenwei Tao wrote:
> From: Wenwei Tao <ww.tao0320@gmail.com>
>
> When create a target, we check whether the target is
> already exist first. If the answer is no, we release
> the lock and continue the creation. This cannot prevent
> concurrent creation of the same target, so hold the lock
> until finish the target creation.
>
> Signed-off-by: Wenwei Tao <ww.tao0320@gmail.com>
> ---
>   drivers/lightnvm/core.c | 18 +++++++++---------
>   1 file changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
> index 160c1a6..a622081 100644
> --- a/drivers/lightnvm/core.c
> +++ b/drivers/lightnvm/core.c
> @@ -791,6 +791,7 @@ static int nvm_create_target(struct nvm_dev *dev,
>   	struct nvm_tgt_type *tt;
>   	struct nvm_target *t;
>   	void *targetdata;
> +	int ret = -ENOMEM;
>
>   	if (!dev->mt) {
>   		pr_info("nvm: device has no media manager registered.\n");
> @@ -801,21 +802,20 @@ static int nvm_create_target(struct nvm_dev *dev,
>   	tt = nvm_find_target_type(create->tgttype);
>   	if (!tt) {
>   		pr_err("nvm: target type %s not found\n", create->tgttype);
> -		up_write(&nvm_lock);
> -		return -EINVAL;
> +		ret = -EINVAL;
> +		goto err_unlock;
>   	}
>
>   	t = nvm_find_target(create->tgtname);
>   	if (t) {
>   		pr_err("nvm: target name already exists.\n");
> -		up_write(&nvm_lock);
> -		return -EINVAL;
> +		ret = -EINVAL;
> +		goto err_unlock;
>   	}
> -	up_write(&nvm_lock);
>
>   	t = kmalloc(sizeof(struct nvm_target), GFP_KERNEL);
>   	if (!t)
> -		return -ENOMEM;
> +		goto err_unlock;
>
>   	tqueue = blk_alloc_queue_node(GFP_KERNEL, dev->q->node);
>   	if (!tqueue)
> @@ -848,8 +848,6 @@ static int nvm_create_target(struct nvm_dev *dev,
>   	t->type = tt;
>   	t->disk = tdisk;
>   	t->dev = dev;
> -
> -	down_write(&nvm_lock);
>   	list_add_tail(&t->list, &nvm_targets);
>   	up_write(&nvm_lock);
>
> @@ -860,7 +858,9 @@ err_queue:
>   	blk_cleanup_queue(tqueue);
>   err_t:
>   	kfree(t);
> -	return -ENOMEM;
> +err_unlock:
> +	up_write(&nvm_lock);
> +	return ret;
>   }
>
>   static int __nvm_configure_create(struct nvm_ioctl_create *create)
>

Thanks. There is a couple of patches in the for-4.8/core that moves this 
logic to the gennvm media manager. Could you rebase this on top?

  reply	other threads:[~2016-05-19 12:42 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-19  6:38 [PATCH 1/2] lightnvm: break the loop when rqd is not null Wenwei Tao
2016-05-19  6:38 ` [PATCH 2/2] lightnvm: hold nvm_lock until finish the target creation Wenwei Tao
2016-05-19 12:42   ` Matias Bjørling [this message]
2016-05-19 15:19     ` Wenwei Tao
2016-05-19 12:40 ` [PATCH 1/2] lightnvm: break the loop when rqd is not null Matias Bjørling
2016-05-19 15:17   ` Wenwei Tao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=573DB4B1.1050501@lightnvm.io \
    --to=mb@lightnvm.io \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ww.tao0320@gmail.com \
    --cc=wwtao0320@163.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox