nvme: avoid "(efault)" from nvme_sysfs_show_subsysnqn()
PATCH 1/1 nvme: avoid "(efault)" from nvme_sysfs_show_subsysnqn()
From: Martin Wilck <[email protected]>
While a controller is still connecting, ctrl->subsys is NULL and thus reading the controller's "subsysnqn" sysfs attribute returns "(efault)". This happens all the time when user space processes "add" events for NVMe controller devices.
Fix it by returning the nvmf_ctrl_options' subsysnqn attribute if ctrl->subsys isn't initialized yet.
--- drivers/nvme/host/core.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/nvme/host/core.c +9 -1
@@ -3538,8 +3538,16 @@ static ssize_t nvme_sysfs_show_subsysnqn(struct device *dev, char *buf) {struct nvme_ctrl *ctrl =dev_get_drvdata (dev); +char *subsysnqn; -return snprintf (buf,PAGE_SIZE ,"%s\n" , ctrl->subsys->subnqn); +if (ctrl->subsys) + subsysnqn = ctrl->subsys->subnqn; +else if (ctrl->opts && ctrl->opts->subsysnqn) + subsysnqn = ctrl->opts->subsysnqn; +else + subsysnqn ="unknown" ; + +return snprintf (buf,PAGE_SIZE ,"%s\n" , subsysnqn); } static DEVICE_ATTR(subsysnqn, S_IRUGO, nvme_sysfs_show_subsysnqn, NULL);
Signature · 7 lines
2.29.2 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
drivers/nvme/host/core.c static ssize_t nvme_sysfs_show_subsysnqn(struct device *dev, · line 3548
Quoted 7 lines · On 2/1/21 14:41, [email protected] wrote:
drivers/nvme/host/core.c +6
-1-return snprintf (buf,PAGE_SIZE ,"%s\n" , ctrl->subsys->subnqn); +if (ctrl->subsys) + subsysnqn = ctrl->subsys->subnqn; +else if (ctrl->opts && ctrl->opts->subsysnqn) + subsysnqn = ctrl->opts->subsysnqn; +else + subsysnqn ="unknown" ;
Just initialize the subsysnqnq to unknown string at the time of declaration.
Also, can you please add a testcase for this bug in blktests to make sure this
behavior will not repeat ?
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Quoted 11 lines · Chaitanya Kulkarni
Quoted 8 lines · On 2/1/21 14:41, [email protected] wrote:
- return snprintf(buf,
PAGE_SIZE, "%s\n", ctrl->subsys-Quoted 1 line
subnqn);
+ if (
ctrl->subsys)
+ subsysnqn =ctrl->subsys->subnqn; + else if (ctrl->opts&&ctrl->opts->subsysnqn) + subsysnqn =ctrl->opts->subsysnqn; + else
+ subsysnqn = "unknown";Just initialize the subsysnqnq to unknown string at the time of declaration.
Just sent a v2.
Quoted 4 lines
Also, can you please add a testcase for this bug in blktests to make sure this
behavior will not repeat ?
Yes, but it'll take time because I have zero experience with blktests and little time the rest of this week. Please kindly review the kernel patch nonetheless.
Regards
Martin
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme