aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKeith Busch <keith.busch@intel.com>2016-01-12 17:09:31 -0500
committerJens Axboe <axboe@fb.com>2016-01-12 17:11:54 -0500
commit779ff75617099f4defe14e20443b95019a4c5ae8 (patch)
treefad22919b8e27d1ec32bfda8c303efa3146b0644
parenta5cdb68c2c10f0865122656833cd07636a4143ee (diff)
NVMe: Export NVMe attributes to sysfs group
Adds all controller information to attribute list exposed to sysfs, and appends the reset_controller attribute to it. The nvme device is created with this attribute list, so driver no long manages its attributes. Reported-by: Sujith Pandel <sujithpshankar@gmail.com> Cc: Sujith Pandel <sujithpshankar@ gmail.com> Cc: David Milburn <dmilburn@redhat.com> Signed-off-by: Keith Busch <keith.busch@intel.com> Signed-off-by: Jens Axboe <axboe@fb.com>
-rw-r--r--drivers/nvme/host/core.c44
1 files changed, 33 insertions, 11 deletions
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index e31a256127f7..3e9c5e1e3b6d 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1053,6 +1053,36 @@ static const struct attribute_group nvme_ns_attr_group = {
1053 .is_visible = nvme_attrs_are_visible, 1053 .is_visible = nvme_attrs_are_visible,
1054}; 1054};
1055 1055
1056#define nvme_show_function(field) \
1057static ssize_t field##_show(struct device *dev, \
1058 struct device_attribute *attr, char *buf) \
1059{ \
1060 struct nvme_ctrl *ctrl = dev_get_drvdata(dev); \
1061 return sprintf(buf, "%.*s\n", (int)sizeof(ctrl->field), ctrl->field); \
1062} \
1063static DEVICE_ATTR(field, S_IRUGO, field##_show, NULL);
1064
1065nvme_show_function(model);
1066nvme_show_function(serial);
1067nvme_show_function(firmware_rev);
1068
1069static struct attribute *nvme_dev_attrs[] = {
1070 &dev_attr_reset_controller.attr,
1071 &dev_attr_model.attr,
1072 &dev_attr_serial.attr,
1073 &dev_attr_firmware_rev.attr,
1074 NULL
1075};
1076
1077static struct attribute_group nvme_dev_attrs_group = {
1078 .attrs = nvme_dev_attrs,
1079};
1080
1081static const struct attribute_group *nvme_dev_attr_groups[] = {
1082 &nvme_dev_attrs_group,
1083 NULL,
1084};
1085
1056static int ns_cmp(void *priv, struct list_head *a, struct list_head *b) 1086static int ns_cmp(void *priv, struct list_head *a, struct list_head *b)
1057{ 1087{
1058 struct nvme_ns *nsa = container_of(a, struct nvme_ns, list); 1088 struct nvme_ns *nsa = container_of(a, struct nvme_ns, list);
@@ -1299,7 +1329,6 @@ static void nvme_release_instance(struct nvme_ctrl *ctrl)
1299 1329
1300void nvme_uninit_ctrl(struct nvme_ctrl *ctrl) 1330void nvme_uninit_ctrl(struct nvme_ctrl *ctrl)
1301 { 1331 {
1302 device_remove_file(ctrl->device, &dev_attr_reset_controller);
1303 device_destroy(nvme_class, MKDEV(nvme_char_major, ctrl->instance)); 1332 device_destroy(nvme_class, MKDEV(nvme_char_major, ctrl->instance));
1304 1333
1305 spin_lock(&dev_list_lock); 1334 spin_lock(&dev_list_lock);
@@ -1343,9 +1372,10 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
1343 if (ret) 1372 if (ret)
1344 goto out; 1373 goto out;
1345 1374
1346 ctrl->device = device_create(nvme_class, ctrl->dev, 1375 ctrl->device = device_create_with_groups(nvme_class, ctrl->dev,
1347 MKDEV(nvme_char_major, ctrl->instance), 1376 MKDEV(nvme_char_major, ctrl->instance),
1348 dev, "nvme%d", ctrl->instance); 1377 dev, nvme_dev_attr_groups,
1378 "nvme%d", ctrl->instance);
1349 if (IS_ERR(ctrl->device)) { 1379 if (IS_ERR(ctrl->device)) {
1350 ret = PTR_ERR(ctrl->device); 1380 ret = PTR_ERR(ctrl->device);
1351 goto out_release_instance; 1381 goto out_release_instance;
@@ -1353,19 +1383,11 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
1353 get_device(ctrl->device); 1383 get_device(ctrl->device);
1354 dev_set_drvdata(ctrl->device, ctrl); 1384 dev_set_drvdata(ctrl->device, ctrl);
1355 1385
1356 ret = device_create_file(ctrl->device, &dev_attr_reset_controller);
1357 if (ret)
1358 goto out_put_device;
1359
1360 spin_lock(&dev_list_lock); 1386 spin_lock(&dev_list_lock);
1361 list_add_tail(&ctrl->node, &nvme_ctrl_list); 1387 list_add_tail(&ctrl->node, &nvme_ctrl_list);
1362 spin_unlock(&dev_list_lock); 1388 spin_unlock(&dev_list_lock);
1363 1389
1364 return 0; 1390 return 0;
1365
1366out_put_device:
1367 put_device(ctrl->device);
1368 device_destroy(nvme_class, MKDEV(nvme_char_major, ctrl->instance));
1369out_release_instance: 1391out_release_instance:
1370 nvme_release_instance(ctrl); 1392 nvme_release_instance(ctrl);
1371out: 1393out: