From patchwork Mon May 23 09:13:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenwei Tao X-Patchwork-Id: 9131363 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D902060761 for ; Mon, 23 May 2016 09:11:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CCEA9281FE for ; Mon, 23 May 2016 09:11:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C165C2821F; Mon, 23 May 2016 09:11:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61568281FE for ; Mon, 23 May 2016 09:11:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753463AbcEWJLA (ORCPT ); Mon, 23 May 2016 05:11:00 -0400 Received: from m50-138.163.com ([123.125.50.138]:34535 "EHLO m50-138.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753475AbcEWJK7 (ORCPT ); Mon, 23 May 2016 05:10:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=oJfu7i1Ngq3GuBTYsE FXxl+jVvRUu6aZxvVZDvuObJQ=; b=GMudlH/fEKUJR3mY96z1T2O/SlXHSlxb3J 0SgLHUE0Db31hKw58rQSOJgji+rv6LfRROZBIAZSdlDIwJugros2a66ve4NJySI4 TG0KqNPOYr11gRTK3EGr6E3S/v64b8UIawD9LocdoYqnnKfeAzSQZEEr54kt3NK0 HUVvJSH1k= Received: from taowenwei.bj-memblaze.com (unknown [111.204.49.2]) by smtp1 (Coremail) with SMTP id C9GowACHjvYCyUJXsJrpAw--.3519S2; Mon, 23 May 2016 17:10:27 +0800 (CST) From: Wenwei Tao To: mb@lightnvm.io Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, ww.tao0320@gmail.com Subject: [PATCH v2 1/2] lightnvm: hold lock until finish the target creation Date: Mon, 23 May 2016 17:13:33 +0800 Message-Id: <1463994814-3388-1-git-send-email-wwtao0320@163.com> X-Mailer: git-send-email 2.7.1.windows.2 X-CM-TRANSID: C9GowACHjvYCyUJXsJrpAw--.3519S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7WF17CF17AF1DWryrAw47Arb_yoW8Cw1rpF WxGr9Fgw4fG397XrWDtrWUZFy5tw4qgFy7JrWxZ3WfZFn0vrWFyF1rtF90gr13GFyxCayY vF4UCa1FkwsFkrUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jFT5dUUUUU= X-Originating-IP: [111.204.49.2] X-CM-SenderInfo: 5zzwt0aqtsiqqrwthudrp/1tbiDQNysVQHAwv4oQAAsP Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Wenwei Tao 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 --- Changes since v1 -rebase to for-4.8/core drivers/lightnvm/gennvm.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/lightnvm/gennvm.c b/drivers/lightnvm/gennvm.c index c65fb67..39ff0af 100644 --- a/drivers/lightnvm/gennvm.c +++ b/drivers/lightnvm/gennvm.c @@ -44,6 +44,7 @@ static int gen_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create) struct nvm_tgt_type *tt; struct nvm_target *t; void *targetdata; + int ret = -ENOMEM; tt = nvm_find_target_type(create->tgttype, 1); if (!tt) { @@ -55,14 +56,13 @@ static int gen_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create) t = gen_find_target(gn, create->tgtname); if (t) { pr_err("nvm: target name already exists.\n"); - mutex_unlock(&gn->lock); - return -EINVAL; + ret = -EINVAL; + goto err_unlock; } - mutex_unlock(&gn->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) @@ -95,8 +95,6 @@ static int gen_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create) t->type = tt; t->disk = tdisk; t->dev = dev; - - mutex_lock(&gn->lock); list_add_tail(&t->list, &gn->targets); mutex_unlock(&gn->lock); @@ -107,7 +105,9 @@ err_queue: blk_cleanup_queue(tqueue); err_t: kfree(t); - return -ENOMEM; +err_unlock: + mutex_unlock(&gn->lock); + return ret; } static void __gen_remove_target(struct nvm_target *t)