Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759086AbcDMMac (ORCPT ); Wed, 13 Apr 2016 08:30:32 -0400 Received: from mail-by2on0069.outbound.protection.outlook.com ([207.46.100.69]:7312 "EHLO na01-by2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753001AbcDMMab (ORCPT ); Wed, 13 Apr 2016 08:30:31 -0400 X-Greylist: delayed 872 seconds by postgrey-1.27 at vger.kernel.org; Wed, 13 Apr 2016 08:30:30 EDT Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=cnexlabs.com; From: "Simon A. F. Lund" To: , , CC: "Simon A. F. Lund" Subject: [PATCH 2/2] lightnvm: refactor dev->online_target to global nvm_targets Date: Wed, 13 Apr 2016 14:15:34 +0200 Message-ID: <1460549734-844-3-git-send-email-slund@cnexlabs.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1460549734-844-1-git-send-email-slund@cnexlabs.com> References: <1460549734-844-1-git-send-email-slund@cnexlabs.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [193.106.164.198] X-ClientProxiedBy: DB4PR07CA015.eurprd07.prod.outlook.com (10.242.229.25) To CO2PR0601MB0983.namprd06.prod.outlook.com (10.160.7.28) X-MS-Office365-Filtering-Correlation-Id: 7d902782-5b1f-4414-b901-08d36395618f X-Microsoft-Exchange-Diagnostics: 1;CO2PR0601MB0983;2:6OMgimvgPeIh7gElMOccL3N9hEa4C0WrcXHhziWcy6rTjWcJqeg+3UxJcHE1eBGzw6xqTFfgCKfp0dTVbAsVLD7frsu6CidKy+TUccsWwySuONlRl74w6b3ehaWXsus5OCn/+eWgjp4/ypEB7Jz70Xfs9rECPsp3vxgbLGaJ6wP54T6p79quydXCnW1YfhO7;3:YWJK+Tj5yqem6zhlJoytwQSG9kWmM26nXC8v/Hxl413PvoJ+108J8LAWzFkvhs9MSlGJwYn/z8FY5mZfLm/6vIdDgsWbhtPpfANXUblhU5tKGf5likk0jmioPelOM+Ca;25:ZEFWk7LemG/5Q1YHubx8bWRNGeUnbvQbACZj5sntD7vMZNcEpxM3ECBSCRKSBKDl2Zh9LlE7oaKkjPd9JBKJHHL444JpNAb/3SkPkGnKcSPY0H1Z16WU+mz9rLhvFpC+GTRM0UfEud7VA5zzoTDOLwpSG9/WU429IfjxGSlB0pj0MBKip1tTlUDC7yIuoQ+njOGRmWKimG9aSwch9DUVX5q2KhutDWzNNyRKOM9tPiDJ3cBdbWLuDK5mlk8XJ7OMwZ7PJ3QbOHgxD82FVeIiz3KJvcK1W58Q78cfOVKr2SA+x7Yf0zkXgp2N5flnr7+h8k/3CZWN+B5UtZwl8AEWew==;20:/hlqZpzpPiGOCzWun4im/YJpPTbYhdozycm73yLNS+cNf5K6YOV8XkQbc6dbp+ik1ibOkNaA7KZq1HSvse5q4hDn/3Pq7zd9oKuj+OVtqy0APYbIBerlQ5apC0/NN+6meq2RUazkkEGsDi9DTPofBfJOOyPyB1BCW2Pxy53HUWM= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CO2PR0601MB0983; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040074)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6041046)(6043046);SRVR:CO2PR0601MB0983;BCL:0;PCL:0;RULEID:;SRVR:CO2PR0601MB0983; X-Microsoft-Exchange-Diagnostics: 1;CO2PR0601MB0983;4:60NfYEOkpwAosVasSjYJKt/HiXbiwhOe/Z4A+K+ApupdUvMmk1d1qVsXPDyFSAzwVEebsRUnQ5tt5mWwULJ+ZUsOxCspNCoMCbz/NkpmwDgYvMocXTDeFSvdUR/djQleZO/3nDdxEdV6jZXzBnVbO8uIzmAot48q7BiYzTO0Dv9wtUYOWrgaQ7frxc+u9/4x55h4sCT275r5ebjNAitHlnS+GSHJXnqBe120lw/JWGo8Bx49kCRIOnb+h6U911Tbl3AMyTGFPIVzpvyWTotd7myyAjFX3ACI7W8oXMfhq9yEXN9QJwTC+EPNlYQquLBBnqnYzz+Hqd2sZN4l91GUNQAjIxlEzhNzDgsRM6g1YqI4HP6Mdd+0kF58g27C6sq7mw49i9QSQavnArrLIyYezF6Y6W9zEUEjzNV4DCHsO8I= X-Forefront-PRVS: 0911D5CE78 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(6009001)(2906002)(77096005)(48376002)(5004730100002)(6116002)(586003)(2950100001)(5001770100001)(229853001)(50466002)(81166005)(5008740100001)(33646002)(86362001)(47776003)(19580395003)(36756003)(66066001)(189998001)(2201001)(19580405001)(92566002)(50986999)(76176999)(4326007)(107886002)(53416004)(42186005)(1096002)(50226001)(4001430100002);DIR:OUT;SFP:1101;SCL:1;SRVR:CO2PR0601MB0983;H:tiger.cnexlabs.com;FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;CO2PR0601MB0983;23:wwOVQMxCCTkCoaTKfP0D/gZ7YXr/eS4SFZEw+dNNTM8hTQC7w4ZeXans9P9Ea59Jh1/UPJItPdYy6bUoFlp30O98TGj3rgK7hDv9a6M91ycLEAqDQqSrIZNa+FpT36TPIPG2a9N+mUl4najWBtXqdHDJw7uf2zdsogPFl0AIlnpm7il82b92riWRvwdbMPiiwEPiVh7yV0FXovfSgSl88zvUZJNBOPA4LE1q6d7v1D3ixSMmHphBlN2cKqczgJhjEPot182ejcuQWbjcbr7B5c5snWyPzjluooEVFc1fQufJizCu3S7bc+W65D39NwAjj1OBawsBMkdyOTsfVh30kcv36yUYc9sNpUKDNk2o7qRQ3EASz0sl1+MSM+potAubT5eaziXEauT9iTfiwsrg0OEXH3W29TYYlatb7wRGQepG0FeETZ5m0DGSHE17KTKXVFHkHRPp/oD4+ABzVFDJc9ClBVjj8Ml+DEH+Q5LOq12yeY/cpZ7xJLuF2xZb6VsTsVV5qgzkh3ufqBVjSxoY6wuSB6pwKVjxderVtlkMToILj8gApt4xzoJV393R8FrIkoEFdxSkVhanbhZ7I329gsdXeZ5h8DyyYoMuLeh/C+RlM/R5398xn5GIpoCziO4oWXUBcuzHtQ1kO/LhBHNZXp1U3fsW7VwLIKbunE9+H8ck8dXlv/8/qsfuDRk/H7mENzNV0KVZm2hoIpHHFYtur6ju60sFnv70DOhJDaNQQf0OsfG5bUUlrJJf/FIZdNSCt4jVHxAiiqRyT+W+l6/Fbd4lZ6l9YDrEXO7aehHPMa0NYd6tXJcz7ACTmD+U/TFjx6kISGu0s+tPsUhoUZIXrshyNXrYOeFhkJ7T+B9VbYwXQQYt8DoZ/fohme6kngwHBVJIbXPHCGiF11n1qygD7gSCU8uKJFo4IYTp6C8GAJo= X-Microsoft-Exchange-Diagnostics: 1;CO2PR0601MB0983;5:SJ7EU7pSlla0t5Aj7b65YOfebOWfMWyU9hiQ/WUuXJiLR/l36p+qj6TIQgsIf7U1qfe6gdgs4IaL95coNlryUZNoCDDhlETya3jMFpOud1+/wA+lU2+BjiEDBBe2XHqH63I8MJhC88vt9wOQyxc51Q==;24:fY9Sb2Q8u4HvzkrLKq+L6nUbO3FmoOPs5f25tZeIl7nBo+N4CuroTgFhEsufPFoSPDKHkvjASY7onZTjAgOa3BYYK+wd4WYb5tP9aGotqeU= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: cnexlabs.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Apr 2016 12:16:01.7301 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO2PR0601MB0983 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3242 Lines: 122 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 --- 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; -- 2.5.0