From patchwork Fri May 6 18:03:03 2016 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: 9035061 Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3E3979F1D3 for ; Fri, 6 May 2016 18:04:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 495C92026F for ; Fri, 6 May 2016 18:04:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 405222039D for ; Fri, 6 May 2016 18:04:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758726AbcEFSDp (ORCPT ); Fri, 6 May 2016 14:03:45 -0400 Received: from mail-wm0-f52.google.com ([74.125.82.52]:38311 "EHLO mail-wm0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758714AbcEFSDo (ORCPT ); Fri, 6 May 2016 14:03:44 -0400 Received: by mail-wm0-f52.google.com with SMTP id g17so89892948wme.1 for ; Fri, 06 May 2016 11:03:44 -0700 (PDT) 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=GkOK2uCwOJe9Ms86+eTY/f0SdDJbzX5m2mu145fq1TY=; b=WcqZS3P50BmA/CcXB+ZwS8Jrdk6CS5kC8DOOgcSehH8I6qonBBEPXtLBQxa3nprE9r PGNI9fBYe9yO3Y7yrTbpgeXwVkb2btWBMz6vA3X0cRBBns5uvuA+PCUasGc35IXIRIv0 6EJT4ad4QtAGf5lyljaZGN0KEuMn4P7uKo6Qk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GkOK2uCwOJe9Ms86+eTY/f0SdDJbzX5m2mu145fq1TY=; b=k92LCmBe6Z6XC+8cScD28BYOlOYKFafuhTKXucw2j6HCA5kISxwitvSTFUHYT6FERd DFfZhM89W36C1NyO4yYVDzguc3jDM/B5gDHyRRkmhi44fGyXQClnu1wjSrwou0Vj8uTe Qv7InhMOM3bERoEvFiVX4IfhnPQCgEe+UabrDqdABgfxF1AAX7muGSkpAiQ2iZQsBxv1 InEGXtM/6ZUVzTH3MqT6G+VoK114iHxTb2/EZF9e0uTvmuLdYqVq1zxcrDalTQG/LORn 1QEqDVNrFwdmzmbZzQKS8c5SoO2YcZXoJFNl21aZvuLh86VcbuK/NE4EN1UBP/skqmn9 UcHQ== X-Gm-Message-State: AOPr4FUMfJRJQhYMY/M9CfPdDYUpaIIZ3YS0/5pd2AkmrBiKk/EzDPG+aYzu1e4t3hzQAA== X-Received: by 10.194.234.167 with SMTP id uf7mr21416685wjc.122.1462557823197; Fri, 06 May 2016 11:03:43 -0700 (PDT) Received: from Macroninja.cnexlabs.com (6164211-cl69.boa.fiberby.dk. [193.106.164.211]) by smtp.gmail.com with ESMTPSA id kz1sm16076559wjc.46.2016.05.06.11.03.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 06 May 2016 11:03:42 -0700 (PDT) From: =?UTF-8?q?Matias=20Bj=C3=B8rling?= To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, axboe@fb.com Cc: "Simon A. F. Lund" , =?UTF-8?q?Matias=20Bj=C3=B8rling?= Subject: [PATCH 10/28] lightnvm: refactor dev->online_target to global nvm_targets Date: Fri, 6 May 2016 20:03:03 +0200 Message-Id: <1462557801-24974-11-git-send-email-m@bjorling.me> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1462557801-24974-1-git-send-email-m@bjorling.me> References: <1462557801-24974-1-git-send-email-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-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: "Simon A. F. Lund" A target name must be unique. However, a per-device registration of targets is maintained on a dev->online_targets list, with a per-device search for targets upon registration. This results in a name collision when two targets, with the same name, are created on two different targets, where the per-device list is not shared. Signed-off-by: Simon A. F. Lund Signed-off-by: Matias Bjørling --- drivers/lightnvm/core.c | 47 +++++++++++++++++++++++++---------------------- include/linux/lightnvm.h | 1 - 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index 240b473..0296223 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c @@ -33,8 +33,20 @@ static LIST_HEAD(nvm_tgt_types); static LIST_HEAD(nvm_mgrs); static LIST_HEAD(nvm_devices); +static LIST_HEAD(nvm_targets); static DECLARE_RWSEM(nvm_lock); +static struct nvm_target *nvm_find_target(const char *name) +{ + struct nvm_target *tgt; + + list_for_each_entry(tgt, &nvm_targets, list) + if (!strcmp(name, tgt->disk->disk_name)) + return tgt; + + return NULL; +} + static struct nvm_tgt_type *nvm_find_target_type(const char *name) { struct nvm_tgt_type *tt; @@ -564,7 +576,6 @@ static int nvm_core_init(struct nvm_dev *dev) goto err_fmtype; } - INIT_LIST_HEAD(&dev->online_targets); mutex_init(&dev->mlock); spin_lock_init(&dev->lock); @@ -744,12 +755,11 @@ static int nvm_create_target(struct nvm_dev *dev, return -EINVAL; } - list_for_each_entry(t, &dev->online_targets, list) { - if (!strcmp(create->tgtname, t->disk->disk_name)) { - pr_err("nvm: target name already exists.\n"); - up_write(&nvm_lock); - return -EINVAL; - } + t = nvm_find_target(create->tgtname); + if (t) { + pr_err("nvm: target name already exists.\n"); + up_write(&nvm_lock); + return -EINVAL; } up_write(&nvm_lock); @@ -789,7 +799,7 @@ static int nvm_create_target(struct nvm_dev *dev, t->disk = tdisk; down_write(&nvm_lock); - list_add_tail(&t->list, &dev->online_targets); + list_add_tail(&t->list, &nvm_targets); up_write(&nvm_lock); return 0; @@ -852,26 +862,19 @@ 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_dev *dev; - int ret = -1; + struct nvm_target *t; down_write(&nvm_lock); - list_for_each_entry(dev, &nvm_devices, devices) - list_for_each_entry(t, &dev->online_targets, list) { - if (!strcmp(remove->tgtname, t->disk->disk_name)) { - nvm_remove_target(t); - ret = 0; - break; - } - } - up_write(&nvm_lock); - - if (ret) { + t = nvm_find_target(remove->tgtname); + if (!t) { pr_err("nvm: target \"%s\" doesn't exist.\n", remove->tgtname); + up_write(&nvm_lock); return -EINVAL; } + nvm_remove_target(t); + up_write(&nvm_lock); + return 0; } diff --git a/include/linux/lightnvm.h b/include/linux/lightnvm.h index 497da91..5eabdba 100644 --- a/include/linux/lightnvm.h +++ b/include/linux/lightnvm.h @@ -308,7 +308,6 @@ struct nvm_dev { struct nvm_dev_ops *ops; struct list_head devices; - struct list_head online_targets; /* Media manager */ struct nvmm_type *mt;