Skip to content

Commit 76171c6

Browse files
sagigrimbergkeithbusch
authored andcommitted
nvme: expose hostnqn via sysfs for fabrics controllers
We allow userspace to connect with a custom hostnqn which is useful for certain use-cases. However there is no way to tell what is the hostnqn used to connect to a given controller. Expose this so userspace can correlate controllers based on hostnqn. Signed-off-by: Sagi Grimberg <[email protected]> Reviewed-by: Chaitanya Kulkarni <[email protected]> Signed-off-by: Keith Busch <[email protected]>
1 parent 43cc668 commit 76171c6

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

drivers/nvme/host/core.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3242,6 +3242,16 @@ static ssize_t nvme_sysfs_show_subsysnqn(struct device *dev,
32423242
}
32433243
static DEVICE_ATTR(subsysnqn, S_IRUGO, nvme_sysfs_show_subsysnqn, NULL);
32443244

3245+
static ssize_t nvme_sysfs_show_hostnqn(struct device *dev,
3246+
struct device_attribute *attr,
3247+
char *buf)
3248+
{
3249+
struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
3250+
3251+
return snprintf(buf, PAGE_SIZE, "%s\n", ctrl->opts->host->nqn);
3252+
}
3253+
static DEVICE_ATTR(hostnqn, S_IRUGO, nvme_sysfs_show_hostnqn, NULL);
3254+
32453255
static ssize_t nvme_sysfs_show_address(struct device *dev,
32463256
struct device_attribute *attr,
32473257
char *buf)
@@ -3267,6 +3277,7 @@ static struct attribute *nvme_dev_attrs[] = {
32673277
&dev_attr_numa_node.attr,
32683278
&dev_attr_queue_count.attr,
32693279
&dev_attr_sqsize.attr,
3280+
&dev_attr_hostnqn.attr,
32703281
NULL
32713282
};
32723283

@@ -3280,6 +3291,8 @@ static umode_t nvme_dev_attrs_are_visible(struct kobject *kobj,
32803291
return 0;
32813292
if (a == &dev_attr_address.attr && !ctrl->ops->get_address)
32823293
return 0;
3294+
if (a == &dev_attr_hostnqn.attr && !ctrl->opts)
3295+
return 0;
32833296

32843297
return a->mode;
32853298
}

0 commit comments

Comments
 (0)