Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Keith Busch and committed by
Jens Axboe
779ff756 a5cdb68c

+33 -11
+33 -11
drivers/nvme/host/core.c
··· 1053 1053 .is_visible = nvme_attrs_are_visible, 1054 1054 }; 1055 1055 1056 + #define nvme_show_function(field) \ 1057 + static 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 + } \ 1063 + static DEVICE_ATTR(field, S_IRUGO, field##_show, NULL); 1064 + 1065 + nvme_show_function(model); 1066 + nvme_show_function(serial); 1067 + nvme_show_function(firmware_rev); 1068 + 1069 + static 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 + 1077 + static struct attribute_group nvme_dev_attrs_group = { 1078 + .attrs = nvme_dev_attrs, 1079 + }; 1080 + 1081 + static const struct attribute_group *nvme_dev_attr_groups[] = { 1082 + &nvme_dev_attrs_group, 1083 + NULL, 1084 + }; 1085 + 1056 1086 static int ns_cmp(void *priv, struct list_head *a, struct list_head *b) 1057 1087 { 1058 1088 struct nvme_ns *nsa = container_of(a, struct nvme_ns, list); ··· 1329 1299 1330 1300 void nvme_uninit_ctrl(struct nvme_ctrl *ctrl) 1331 1301 { 1332 - device_remove_file(ctrl->device, &dev_attr_reset_controller); 1333 1302 device_destroy(nvme_class, MKDEV(nvme_char_major, ctrl->instance)); 1334 1303 1335 1304 spin_lock(&dev_list_lock); ··· 1372 1343 if (ret) 1373 1344 goto out; 1374 1345 1375 - ctrl->device = device_create(nvme_class, ctrl->dev, 1346 + ctrl->device = device_create_with_groups(nvme_class, ctrl->dev, 1376 1347 MKDEV(nvme_char_major, ctrl->instance), 1377 - dev, "nvme%d", ctrl->instance); 1348 + dev, nvme_dev_attr_groups, 1349 + "nvme%d", ctrl->instance); 1378 1350 if (IS_ERR(ctrl->device)) { 1379 1351 ret = PTR_ERR(ctrl->device); 1380 1352 goto out_release_instance; ··· 1383 1353 get_device(ctrl->device); 1384 1354 dev_set_drvdata(ctrl->device, ctrl); 1385 1355 1386 - ret = device_create_file(ctrl->device, &dev_attr_reset_controller); 1387 - if (ret) 1388 - goto out_put_device; 1389 - 1390 1356 spin_lock(&dev_list_lock); 1391 1357 list_add_tail(&ctrl->node, &nvme_ctrl_list); 1392 1358 spin_unlock(&dev_list_lock); 1393 1359 1394 1360 return 0; 1395 - 1396 - out_put_device: 1397 - put_device(ctrl->device); 1398 - device_destroy(nvme_class, MKDEV(nvme_char_major, ctrl->instance)); 1399 1361 out_release_instance: 1400 1362 nvme_release_instance(ctrl); 1401 1363 out: