[PATCH] nvme: Fix a race condition related to creation of /dev/nvme0n<x>

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <bart.vanassche@xxxxxxx>
Cc: Keith Busch <keith.busch@xxxxxxxxx>
Cc: Sagi Grimberg <sagi@xxxxxxxxxxx>
Cc: Matias Bjorling <mb@xxxxxxxxxxx>
Cc: <stable@xxxxxxxxxxxxxxx>
---
 drivers/nvme/host/core.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index dd8ec1dd9219..f4b880c8abe6 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -2734,6 +2734,11 @@ const struct attribute_group nvme_ns_id_attr_group = {
 	.is_visible	= nvme_ns_id_attrs_are_visible,
 };
 
+static const struct attribute_group *nvme_attr_groups[] = {
+	&nvme_ns_id_attr_group,
+	NULL
+};
+
 #define nvme_show_str_function(field)						\
 static ssize_t  field##_show(struct device *dev,				\
 			    struct device_attribute *attr, char *buf)		\
@@ -3099,11 +3104,13 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
 
 	nvme_get_ctrl(ctrl);
 
+	WARN_ON_ONCE(disk_to_dev(ns->disk)->groups);
+	disk_to_dev(ns->disk)->groups = nvme_attr_groups;
 	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);
+	/*
+	 * To do: remove nvme_nvm_register_sysfs() and add the nvm attribute
+	 * groups to nvme_attr_groups.
+	 */
 	if (ns->ndev && nvme_nvm_register_sysfs(ns))
 		pr_warn("%s: failed to register lightnvm sysfs group for identification\n",
 			ns->disk->disk_name);
@@ -3132,8 +3139,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);
-- 
2.18.0




[Index of Archives]     [Linux Kernel]     [Kernel Development Newbies]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux