Skip to contentSkip to conversation

nvme: move sysfs code to a dedicated sysfs.c file

PATCH In review Max Gurtovoy 5 participants 7 messages Apr 24, 2023 – May 15, 2023 NVMe

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 nvme: move sysfs code to a dedicated sysfs.c file

The core.c file became long and hard to maintain. Create a dedicated file to centralize the sysfs functionality. This is a common practice to separate sysfs/configfs related logic from the main driver logic .c file. For example, in the nvmet module the configfs interface has its own dedicated file.

This patch does not include any functional changes.

---

changes from v1:
- rephrase the title from "nvme: add a dedicated .c file for sysfs interface" (Sagi)
- add Reviewed-by signature from Keith

changes from RFC:
- Removed RCF tag
- updated copyrights mistake
- fix License copy/paste bug (Sagi)

---
 drivers/nvme/host/Makefile |   2 +-
 drivers/nvme/host/core.c   | 650 +-----------------------------------
 drivers/nvme/host/nvme.h   |   4 +
 drivers/nvme/host/sysfs.c  | 655 +++++++++++++++++++++++++++++++++++++
 4 files changed, 662 insertions(+), 649 deletions(-)
 create mode 100644 drivers/nvme/host/sysfs.c
drivers/nvme/host/Makefile +1 -1
index e27202d22c7d..d3fc5063e4be 100644
@@ -10,7 +10,7 @@ obj-$(CONFIG_NVME_FC)			+= nvme-fc.o
 obj-$(CONFIG_NVME_TCP)			+= nvme-tcp.o
 obj-$(CONFIG_NVME_APPLE)		+= nvme-apple.o
 
-nvme-core-y				+= core.o ioctl.o
+nvme-core-y				+= core.o ioctl.o sysfs.o
 nvme-core-$(CONFIG_NVME_VERBOSE_ERRORS)	+= constants.o
 nvme-core-$(CONFIG_TRACING)		+= trace.o
 nvme-core-$(CONFIG_NVME_MULTIPATH)	+= multipath.o
drivers/nvme/host/core.c +2 -648

674 lines not on this page · raw message

drivers/nvme/host/nvme.h +4 -0
index bf46f122e9e1..f49a142e5013 100644
@@ -860,7 +860,11 @@ extern const struct attribute_group *nvme_ns_id_attr_groups[];
 extern const struct pr_ops nvme_pr_ops;
 extern const struct block_device_operations nvme_ns_head_ops;
 extern const struct attribute_group nvme_dev_attrs_group;
+extern const struct attribute_group *nvme_subsys_attrs_groups[];
+extern const struct attribute_group *nvme_dev_attr_groups[];
+extern const struct block_device_operations nvme_bdev_ops;
 
+void nvme_delete_ctrl_sync(struct nvme_ctrl *ctrl);
 struct nvme_ns *nvme_find_path(struct nvme_ns_head *head);
 #ifdef CONFIG_NVME_MULTIPATH
 static inline bool nvme_ctrl_use_ana(struct nvme_ctrl *ctrl)
drivers/nvme/host/sysfs.c new file +655 -0

655 lines not on this page · raw message

Signature · 1 line
2.18.1
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · Max Gurtovoy

The core.c file became long and hard to maintain. Create a dedicated file to centralize the sysfs functionality. This is a common practice to separate sysfs/configfs related logic from the main driver logic .c file. For example, in the nvmet module the configfs interface has its own dedicated file.

This patch does not include any functional changes.

Signature · 1 line
Jens Axboe
#2 lore raw

Hi Christoph,

Quoted 11 lines · Jens Axboe
Quoted 7 lines · Max Gurtovoy

The core.c file became long and hard to maintain. Create a dedicated file to centralize the sysfs functionality. This is a common practice to separate sysfs/configfs related logic from the main driver logic .c file. For example, in the nvmet module the configfs interface has its own dedicated file.

This patch does not include any functional changes.

Is there a chance to merge this for the next round of nvme PR ? We have pretty good agreement for this patch :)

Reviewed-by on v2 1/1
#3 lore raw
In reply to Max Gurtovoy
Quoted 21 lines · Max Gurtovoy

The core.c file became long and hard to maintain. Create a dedicated file to centralize the sysfs functionality. This is a common practice to separate sysfs/configfs related logic from the main driver logic .c file. For example, in the nvmet module the configfs interface has its own dedicated file.

This patch does not include any functional changes.

---

changes from v1:
- rephrase the title from "nvme: add a dedicated .c file for sysfs interface" (Sagi)
- add Reviewed-by signature from Keith

changes from RFC:
- Removed RCF tag
- updated copyrights mistake
- fix License copy/paste bug (Sagi)

Quoted 8 lines
---
  drivers/nvme/host/Makefile |   2 +-
  drivers/nvme/host/core.c   | 650 +-----------------------------------
  drivers/nvme/host/nvme.h   |   4 +
  drivers/nvme/host/sysfs.c  | 655 +++++++++++++++++++++++++++++++++++++
  4 files changed, 662 insertions(+), 649 deletions(-)

create mode 100644 drivers/nvme/host/sysfs.c

Cheers,

Hannes

maintainer
#5 lore raw
In reply to Max Gurtovoy
Quoted 7 lines · Max Gurtovoy

The core.c file became long and hard to maintain. Create a dedicated file to centralize the sysfs functionality. This is a common practice to separate sysfs/configfs related logic from the main driver logic .c file. For example, in the nvmet module the configfs interface has its own dedicated file.

This patch does not include any functional changes.

Thanks, I applied this for 6.5 with a couple minor changes:

I merged Chaitanya's dhchap memory leak fixes first, which touched some of this sysfs code, so I simply used the the result when moving the code to the new file.

I also added an 'include <linux/nvme-auth.h>' in the new sysfs.c file for when CONFIG_NVME_AUTH=y.

#6 lore raw

Hi Keith,

Quoted 9 lines · Keith Busch
Quoted 7 lines · Max Gurtovoy

The core.c file became long and hard to maintain. Create a dedicated file to centralize the sysfs functionality. This is a common practice to separate sysfs/configfs related logic from the main driver logic .c file. For example, in the nvmet module the configfs interface has its own dedicated file.

This patch does not include any functional changes.

Quoted 8 lines

Thanks, I applied this for 6.5 with a couple minor changes:

I merged Chaitanya's dhchap memory leak fixes first, which touched some of this sysfs code, so I simply used the the result when moving the code to the new file.

I also added an 'include <linux/nvme-auth.h>' in the new sysfs.c file for when CONFIG_NVME_AUTH=y.

Sound good.
Thanks.