From patchwork Wed Dec 20 17:21:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Matias_Bj=C3=B8rling?= X-Patchwork-Id: 10126063 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 53FA560245 for ; Wed, 20 Dec 2017 17:28:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D5AD291A1 for ; Wed, 20 Dec 2017 17:28:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 324D429243; Wed, 20 Dec 2017 17:28:29 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI 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 D26F329204 for ; Wed, 20 Dec 2017 17:28:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755856AbdLTR2V (ORCPT ); Wed, 20 Dec 2017 12:28:21 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:41914 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755954AbdLTRWX (ORCPT ); Wed, 20 Dec 2017 12:22:23 -0500 Received: by mail-wm0-f68.google.com with SMTP id g75so11393796wme.0 for ; Wed, 20 Dec 2017 09:22:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bjorling.me; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SyLq1Nmt6rOI3kWWg4AKQEAU7KGfRJmHZ7z8jBDBKNM=; b=dGdRl+sHNJfCMvyYEuk7KcgeAAapd6kCKSxXgtPnkDn3YmgaqrFdNH0tmI9HQpx2Eg ML0SfPM+jqD1Alg23pv2J/3z47OSPGppREHyCZkquSyQVFsfhucF4BsFoskilybZwdOp wqTBzYlmf3grcSa6fpFBPDzBt7+UcPmSf7yuU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SyLq1Nmt6rOI3kWWg4AKQEAU7KGfRJmHZ7z8jBDBKNM=; b=SxpE+uL+S7K3XjSDy2rRPmnlIM2lKLLleD7e1X7HJ1CQS89HOHpX0Arzioi/ZyKw2B 2OGksXekrBjetnEvzQm/vzE56sbKTSI8VEy5Wxn1LYnSGosh8h8wVVgVCf806pEcLwcg SQK1DNxxXKh2bnzU3Uwz5pTIPkUDOTkEzf60pn9VWS/Zv8QfQOCgqGG3Mo11TsukuAaj fg5cvCQS3wOayUwUV7P1ZyZvL56MvgD9gv5yi1a4NSZfr8iJukCqg4W67HneGThdxNJm ECMXY6aGZkb90qTRU78nO1pvtmR/b2X9y3h0+WsOpDyISj2EDDafaBxQjJcv3OQfbXR4 CX0Q== X-Gm-Message-State: AKGB3mKGPrBjC7vGcFBS2Bk2MMugQVynikeO7d0Gu2ZJCcchYSQunCz1 y7jNtpVT2IVyGJ0D48EoSBl+2EZu X-Google-Smtp-Source: ACJfBotxHAkPcLyLyttmbZ2p7GmvfIxZrgykOdM6tSvbxjEcieoSWeWX6N2GLi3DqgFbVqXX2yLC2w== X-Received: by 10.80.144.72 with SMTP id z8mr6393483edz.105.1513790542382; Wed, 20 Dec 2017 09:22:22 -0800 (PST) Received: from skyninja.cnexlabs.com (6164211-cl69.boa.fiberby.dk. [193.106.164.211]) by smtp.gmail.com with ESMTPSA id 26sm15339120eds.67.2017.12.20.09.22.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Dec 2017 09:22:21 -0800 (PST) From: =?UTF-8?q?Matias=20Bj=C3=B8rling?= To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Javier=20Gonz=C3=A1lez?= , =?UTF-8?q?Matias=20Bj=C3=B8rling?= Subject: [PATCH 09/25] lightnvm: guarantee target unique name across devs. Date: Wed, 20 Dec 2017 18:21:49 +0100 Message-Id: <20171220172205.26464-10-m@bjorling.me> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20171220172205.26464-1-m@bjorling.me> References: <20171220172205.26464-1-m@bjorling.me> MIME-Version: 1.0 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: Javier González Until now, target unique naming is only guaranteed per device. This is ok from a lightnvm perspective, but not from a sysfs one, since groups will collide regardless of the underlying device. Check that names are unique across all lightnvm-capable devices. Signed-off-by: Javier González Signed-off-by: Matias Bjørling --- drivers/lightnvm/core.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index 5c2d0f3..d5f231c 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c @@ -56,6 +56,30 @@ static struct nvm_target *nvm_find_target(struct nvm_dev *dev, const char *name) return NULL; } +static bool nvm_target_exists(const char *name) +{ + struct nvm_dev *dev; + struct nvm_target *tgt; + bool ret = false; + + down_write(&nvm_lock); + list_for_each_entry(dev, &nvm_devices, devices) { + mutex_lock(&dev->mlock); + list_for_each_entry(tgt, &dev->targets, list) { + if (!strcmp(name, tgt->disk->disk_name)) { + ret = true; + mutex_unlock(&dev->mlock); + goto out; + } + } + mutex_unlock(&dev->mlock); + } + +out: + up_write(&nvm_lock); + return ret; +} + static int nvm_reserve_luns(struct nvm_dev *dev, int lun_begin, int lun_end) { int i; @@ -259,14 +283,11 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create) return -EINVAL; } - mutex_lock(&dev->mlock); - t = nvm_find_target(dev, create->tgtname); - if (t) { - pr_err("nvm: target name already exists.\n"); - mutex_unlock(&dev->mlock); + if (nvm_target_exists(create->tgtname)) { + pr_err("nvm: target name already exists (%s)\n", + create->tgtname); return -EINVAL; } - mutex_unlock(&dev->mlock); ret = nvm_reserve_luns(dev, s->lun_begin, s->lun_end); if (ret)