From patchwork Mon Aug 13 17:25:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10564545 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5B55B9093 for ; Mon, 13 Aug 2018 17:25:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E4D8296BC for ; Mon, 13 Aug 2018 17:25:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 32C9D296C6; Mon, 13 Aug 2018 17:25:35 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,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 9C4AF296BF for ; Mon, 13 Aug 2018 17:25:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730137AbeHMUIm (ORCPT ); Mon, 13 Aug 2018 16:08:42 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:12170 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729029AbeHMUIl (ORCPT ); Mon, 13 Aug 2018 16:08:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1534181133; x=1565717133; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=eZ0CUoYP0USzo3w3onCJm8d9WBoxlZmdVJ56RqI0plM=; b=MVidNt9k9nHM7eJpxqsKgK1MyO+PYwAwnBSgAdxAgzLLKyBLjeY2lYp/ Qkhs87eaR/xMH9g+KjVRtK5tf8HDbwflu2NV4rt9mGZZri9A5IGQrNxfS 4F3aJg1nOSyyRan2sVPOAkJt7FQoknUoVBgPAEH4j3SL4ZVVhjExO/lAq ygcVO8mPdosbtc2RjhdvxotIP0ycl4hik0Fgcb57sitjeyzxq0Bgs2N+9 4RgvMw8yojBVg9w/jKcrvO0FTQfdra8oltSlZNInNSqjGDQ6QTwIqCKjA LuW/K9Y8A1OkwFTn7nBpPy7nDj+lbT9diOVGWgi2ZeplChrRJhbvsiWDt Q==; X-IronPort-AV: E=Sophos;i="5.53,234,1531756800"; d="scan'208";a="191415869" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 14 Aug 2018 01:25:32 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP; 13 Aug 2018 10:13:34 -0700 Received: from thinkpad-bart.sdcorp.global.sandisk.com ([10.111.67.248]) by uls-op-cesaip01.wdc.com with ESMTP; 13 Aug 2018 10:25:33 -0700 From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Greg Kroah-Hartman , Bart Van Assche , Keith Busch , Sagi Grimberg , Matias Bjorling , stable@vger.kernel.org Subject: [PATCH v2 2/2] nvme: Fix race conditions related to creation of /dev/nvme0n Date: Mon, 13 Aug 2018 10:25:31 -0700 Message-Id: <20180813172531.7451-3-bart.vanassche@wdc.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180813172531.7451-1-bart.vanassche@wdc.com> References: <20180813172531.7451-1-bart.vanassche@wdc.com> 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 For the udev rules that create symbolic links under /dev it is essential that all sysfs attributes are registered before an object becomes visible. This patch avoids that udevd fails to create the /dev/disk/by-id/nvme-uuid.* symbolic link. Fixes: 2b9b6e86bca7 ("NVMe: Export namespace attributes to sysfs") Signed-off-by: Bart Van Assche Cc: Keith Busch Cc: Christoph Hellwig Cc: Greg Kroah-Hartman Cc: Sagi Grimberg Cc: Matias Bjorling Cc: Reviewed-by: Sagi Grimberg --- drivers/nvme/host/core.c | 17 +++++------------ drivers/nvme/host/lightnvm.c | 34 +++++++--------------------------- drivers/nvme/host/nvme.h | 9 ++++----- 3 files changed, 16 insertions(+), 44 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index dd8ec1dd9219..0121db66d2c6 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -3043,6 +3043,7 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid) struct nvme_id_ns *id; char disk_name[DISK_NAME_LEN]; int node = dev_to_node(ctrl->dev), flags = GENHD_FL_EXT_DEVT; + const struct attribute_group *nvme_attr_groups[3]; ns = kzalloc_node(sizeof(*ns), GFP_KERNEL, node); if (!ns) @@ -3080,7 +3081,10 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid) } } - disk = alloc_disk_node(0, node); + nvme_attr_groups[0] = &nvme_ns_id_attr_group; + nvme_attr_groups[1] = nvme_nvm_attr_group(ns); + nvme_attr_groups[2] = NULL; + disk = alloc_disk_node_attr(0, node, nvme_attr_groups); if (!disk) goto out_unlink_ns; @@ -3100,13 +3104,6 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid) nvme_get_ctrl(ctrl); device_add_disk(ctrl->device, ns->disk); - if (sysfs_create_group(&disk_to_dev(ns->disk)->kobj, - &nvme_ns_id_attr_group)) - pr_warn("%s: failed to create sysfs group for identification\n", - ns->disk->disk_name); - if (ns->ndev && nvme_nvm_register_sysfs(ns)) - pr_warn("%s: failed to register lightnvm sysfs group for identification\n", - ns->disk->disk_name); nvme_mpath_add_disk(ns, id); nvme_fault_inject_init(ns); @@ -3132,10 +3129,6 @@ static void nvme_ns_remove(struct nvme_ns *ns) nvme_fault_inject_fini(ns); if (ns->disk && ns->disk->flags & GENHD_FL_UP) { - sysfs_remove_group(&disk_to_dev(ns->disk)->kobj, - &nvme_ns_id_attr_group); - if (ns->ndev) - nvme_nvm_unregister_sysfs(ns); del_gendisk(ns->disk); blk_cleanup_queue(ns->queue); if (blk_get_integrity(ns->disk)) diff --git a/drivers/nvme/host/lightnvm.c b/drivers/nvme/host/lightnvm.c index 6fe5923c95d4..11e687f3c36f 100644 --- a/drivers/nvme/host/lightnvm.c +++ b/drivers/nvme/host/lightnvm.c @@ -1270,39 +1270,19 @@ static const struct attribute_group nvm_dev_attr_group_20 = { .attrs = nvm_dev_attrs_20, }; -int nvme_nvm_register_sysfs(struct nvme_ns *ns) +const struct attribute_group *nvme_nvm_attr_group(const struct nvme_ns *ns) { - struct nvm_dev *ndev = ns->ndev; - struct nvm_geo *geo = &ndev->geo; + const struct nvm_dev *ndev = ns->ndev; if (!ndev) - return -EINVAL; + return NULL; - switch (geo->major_ver_id) { + switch (ndev->geo->major_ver_id) { case 1: - return sysfs_create_group(&disk_to_dev(ns->disk)->kobj, - &nvm_dev_attr_group_12); + return &nvm_dev_attr_group_12; case 2: - return sysfs_create_group(&disk_to_dev(ns->disk)->kobj, - &nvm_dev_attr_group_20); + return &nvm_dev_attr_group_20; } - return -EINVAL; -} - -void nvme_nvm_unregister_sysfs(struct nvme_ns *ns) -{ - struct nvm_dev *ndev = ns->ndev; - struct nvm_geo *geo = &ndev->geo; - - switch (geo->major_ver_id) { - case 1: - sysfs_remove_group(&disk_to_dev(ns->disk)->kobj, - &nvm_dev_attr_group_12); - break; - case 2: - sysfs_remove_group(&disk_to_dev(ns->disk)->kobj, - &nvm_dev_attr_group_20); - break; - } + return NULL; } diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index bb4a2003c097..112596ad1ed3 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -551,8 +551,7 @@ static inline void nvme_mpath_stop(struct nvme_ctrl *ctrl) void nvme_nvm_update_nvm_info(struct nvme_ns *ns); int nvme_nvm_register(struct nvme_ns *ns, char *disk_name, int node); void nvme_nvm_unregister(struct nvme_ns *ns); -int nvme_nvm_register_sysfs(struct nvme_ns *ns); -void nvme_nvm_unregister_sysfs(struct nvme_ns *ns); +const struct attribute_group *nvme_nvm_attr_group(const struct nvme_ns *ns); int nvme_nvm_ioctl(struct nvme_ns *ns, unsigned int cmd, unsigned long arg); #else static inline void nvme_nvm_update_nvm_info(struct nvme_ns *ns) {}; @@ -563,11 +562,11 @@ static inline int nvme_nvm_register(struct nvme_ns *ns, char *disk_name, } static inline void nvme_nvm_unregister(struct nvme_ns *ns) {}; -static inline int nvme_nvm_register_sysfs(struct nvme_ns *ns) +static inline const struct attribute_group * +nvme_nvm_attr_group(const struct nvme_ns *ns) { - return 0; + return NULL; } -static inline void nvme_nvm_unregister_sysfs(struct nvme_ns *ns) {}; static inline int nvme_nvm_ioctl(struct nvme_ns *ns, unsigned int cmd, unsigned long arg) {