Skip to content

Commit 86adbf0

Browse files
author
Christoph Hellwig
committed
nvme: simplify transport specific device attribute handling
Allow the transport driver to override the attribute groups for the control device, so that the PCIe driver doesn't manually have to add a group after device creation and keep track of it. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Keith Busch <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]> Reviewed-by: Chaitanya Kulkarni <[email protected]> Tested-by Gerd Bayer <[email protected]>
1 parent 94cc781 commit 86adbf0

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

drivers/nvme/host/core.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3906,10 +3906,11 @@ static umode_t nvme_dev_attrs_are_visible(struct kobject *kobj,
39063906
return a->mode;
39073907
}
39083908

3909-
static const struct attribute_group nvme_dev_attrs_group = {
3909+
const struct attribute_group nvme_dev_attrs_group = {
39103910
.attrs = nvme_dev_attrs,
39113911
.is_visible = nvme_dev_attrs_are_visible,
39123912
};
3913+
EXPORT_SYMBOL_GPL(nvme_dev_attrs_group);
39133914

39143915
static const struct attribute_group *nvme_dev_attr_groups[] = {
39153916
&nvme_dev_attrs_group,
@@ -5091,7 +5092,10 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
50915092
ctrl->instance);
50925093
ctrl->device->class = nvme_class;
50935094
ctrl->device->parent = ctrl->dev;
5094-
ctrl->device->groups = nvme_dev_attr_groups;
5095+
if (ops->dev_attr_groups)
5096+
ctrl->device->groups = ops->dev_attr_groups;
5097+
else
5098+
ctrl->device->groups = nvme_dev_attr_groups;
50955099
ctrl->device->release = nvme_free_ctrl;
50965100
dev_set_drvdata(ctrl->device, ctrl);
50975101
ret = dev_set_name(ctrl->device, "nvme%d", ctrl->instance);

drivers/nvme/host/nvme.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ struct nvme_ctrl_ops {
508508
unsigned int flags;
509509
#define NVME_F_FABRICS (1 << 0)
510510
#define NVME_F_METADATA_SUPPORTED (1 << 1)
511+
const struct attribute_group **dev_attr_groups;
511512
int (*reg_read32)(struct nvme_ctrl *ctrl, u32 off, u32 *val);
512513
int (*reg_write32)(struct nvme_ctrl *ctrl, u32 off, u32 val);
513514
int (*reg_read64)(struct nvme_ctrl *ctrl, u32 off, u64 *val);
@@ -854,6 +855,7 @@ int nvme_dev_uring_cmd(struct io_uring_cmd *ioucmd, unsigned int issue_flags);
854855
extern const struct attribute_group *nvme_ns_id_attr_groups[];
855856
extern const struct pr_ops nvme_pr_ops;
856857
extern const struct block_device_operations nvme_ns_head_ops;
858+
extern const struct attribute_group nvme_dev_attrs_group;
857859

858860
struct nvme_ns *nvme_find_path(struct nvme_ns_head *head);
859861
#ifdef CONFIG_NVME_MULTIPATH

drivers/nvme/host/pci.c

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,6 @@ struct nvme_dev {
158158
unsigned int nr_allocated_queues;
159159
unsigned int nr_write_queues;
160160
unsigned int nr_poll_queues;
161-
162-
bool attrs_added;
163161
};
164162

165163
static int io_queue_depth_set(const char *val, const struct kernel_param *kp)
@@ -2234,11 +2232,17 @@ static struct attribute *nvme_pci_attrs[] = {
22342232
NULL,
22352233
};
22362234

2237-
static const struct attribute_group nvme_pci_attr_group = {
2235+
static const struct attribute_group nvme_pci_dev_attrs_group = {
22382236
.attrs = nvme_pci_attrs,
22392237
.is_visible = nvme_pci_attrs_are_visible,
22402238
};
22412239

2240+
static const struct attribute_group *nvme_pci_dev_attr_groups[] = {
2241+
&nvme_dev_attrs_group,
2242+
&nvme_pci_dev_attrs_group,
2243+
NULL,
2244+
};
2245+
22422246
/*
22432247
* nirqs is the number of interrupts available for write and read
22442248
* queues. The core already reserved an interrupt for the admin queue.
@@ -2930,10 +2934,6 @@ static void nvme_reset_work(struct work_struct *work)
29302934
goto out;
29312935
}
29322936

2933-
if (!dev->attrs_added && !sysfs_create_group(&dev->ctrl.device->kobj,
2934-
&nvme_pci_attr_group))
2935-
dev->attrs_added = true;
2936-
29372937
nvme_start_ctrl(&dev->ctrl);
29382938
return;
29392939

@@ -3006,6 +3006,7 @@ static const struct nvme_ctrl_ops nvme_pci_ctrl_ops = {
30063006
.name = "pcie",
30073007
.module = THIS_MODULE,
30083008
.flags = NVME_F_METADATA_SUPPORTED,
3009+
.dev_attr_groups = nvme_pci_dev_attr_groups,
30093010
.reg_read32 = nvme_pci_reg_read32,
30103011
.reg_write32 = nvme_pci_reg_write32,
30113012
.reg_read64 = nvme_pci_reg_read64,
@@ -3204,13 +3205,6 @@ static void nvme_shutdown(struct pci_dev *pdev)
32043205
nvme_disable_prepare_reset(dev, true);
32053206
}
32063207

3207-
static void nvme_remove_attrs(struct nvme_dev *dev)
3208-
{
3209-
if (dev->attrs_added)
3210-
sysfs_remove_group(&dev->ctrl.device->kobj,
3211-
&nvme_pci_attr_group);
3212-
}
3213-
32143208
/*
32153209
* The driver's remove may be called on a device in a partially initialized
32163210
* state. This function must not have any dependencies on the device state in
@@ -3232,7 +3226,6 @@ static void nvme_remove(struct pci_dev *pdev)
32323226
nvme_stop_ctrl(&dev->ctrl);
32333227
nvme_remove_namespaces(&dev->ctrl);
32343228
nvme_dev_disable(dev, true);
3235-
nvme_remove_attrs(dev);
32363229
nvme_free_host_mem(dev);
32373230
nvme_dev_remove_admin(dev);
32383231
nvme_free_queues(dev, 0);

0 commit comments

Comments
 (0)