From patchwork Fri Jan 5 13:16:05 2018 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: 10146541 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 9C5F1601A1 for ; Fri, 5 Jan 2018 13:21:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8CB5526E97 for ; Fri, 5 Jan 2018 13:21:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8087327E01; Fri, 5 Jan 2018 13:21:57 +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=unavailable 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 2D89826E97 for ; Fri, 5 Jan 2018 13:21:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751645AbeAENVp (ORCPT ); Fri, 5 Jan 2018 08:21:45 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:37560 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751279AbeAENQt (ORCPT ); Fri, 5 Jan 2018 08:16:49 -0500 Received: by mail-wm0-f67.google.com with SMTP id f140so2413919wmd.2 for ; Fri, 05 Jan 2018 05:16:48 -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=NoAWYsOp1xP8k/gdDADpnU1cCzQK09rA5HXLWQH0Oold/I17016vqtfmyXEQ3xJWey Jk1EkYXPeea55XfobiWHTdYW0L/++07yP1ksEcnDR2ITRs7bYp57CxGRJTrD09uMSh5d uChrUU7npDEJqm6NS/XTfPypAjObTUqU/d4rY= 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=XO8NmBtzuUUsLbWh9/XVRBRdzSlNN/J7HVmV3ZwQSfW/vXNqLcNw+irYhQ/w5r5UTd 8ML46V0aL44hnsC7aU9FuTEurOG04ljRe67ErlCL0BjUaXMpJIOmD9ArBTE8ACzaXors zZEmJxhIXIi+ENY5lPOpsorNqAS5O1PRHRJHOS4Zs/jnCclDCvJBsZ/it2v8C1pWUF6s Ec/hQVE2rS8+6rxH8Zx1FJLBRbNQdBVGXytyC+YJ2oh+02i9V3OwRe74Cq+024jl2xpJ lQJ6UZtEgoxoN8B/jHL/rNtW0doorn1RdG8Ukn4mr5ljWAgtz2Jn5hK+tCkqUwFh5v47 w8OQ== X-Gm-Message-State: AKGB3mKcsx11TseKJ7qvCAft7ka93GFuIZIikOA5i0rNXbm7hg1fXC9R sbhwsxD01jJ8iCeiwIpwM6Tn3w== X-Google-Smtp-Source: ACJfBosAUDg6c+IzYdpRkV6TPyvqpuoJnx2d075vKjL0S/5p44+q6ZzS+O+0q1UKzcL6uIqRmNB7ag== X-Received: by 10.80.133.33 with SMTP id 30mr4194367edr.42.1515158208202; Fri, 05 Jan 2018 05:16:48 -0800 (PST) Received: from skyninja.cnexlabs.com (6164211-cl69.boa.fiberby.dk. [193.106.164.211]) by smtp.gmail.com with ESMTPSA id e46sm4228940edb.93.2018.01.05.05.16.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 Jan 2018 05:16:47 -0800 (PST) From: =?UTF-8?q?Matias=20Bj=C3=B8rling?= To: axboe@fb.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Javier=20Gonz=C3=A1lez?= , =?UTF-8?q?Matias=20Bj=C3=B8rling?= Subject: [GIT PULL 09/25] lightnvm: guarantee target unique name across devs. Date: Fri, 5 Jan 2018 14:16:05 +0100 Message-Id: <20180105131621.20808-10-m@bjorling.me> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20180105131621.20808-1-m@bjorling.me> References: <20180105131621.20808-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)