Skip to content

Commit 7e5c3de

Browse files
Hannes Reineckekeithbusch
authored andcommitted
nvmet: add 'host_traddr' callback for debugfs
We want to display the transport address of the connected host in debugfs, but this is a property of the transport. So add a callback 'host_traddr' to allow the transport drivers to fill in the data. Signed-off-by: Hannes Reinecke <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]> Reviewed-by: Chaitanya Kulkarni <[email protected]> Signed-off-by: Daniel Wagner <[email protected]> Signed-off-by: Keith Busch <[email protected]>
1 parent 649fd41 commit 7e5c3de

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

drivers/nvme/target/core.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,6 +1542,14 @@ void nvmet_ctrl_fatal_error(struct nvmet_ctrl *ctrl)
15421542
}
15431543
EXPORT_SYMBOL_GPL(nvmet_ctrl_fatal_error);
15441544

1545+
ssize_t nvmet_ctrl_host_traddr(struct nvmet_ctrl *ctrl,
1546+
char *traddr, size_t traddr_len)
1547+
{
1548+
if (!ctrl->ops->host_traddr)
1549+
return -EOPNOTSUPP;
1550+
return ctrl->ops->host_traddr(ctrl, traddr, traddr_len);
1551+
}
1552+
15451553
static struct nvmet_subsys *nvmet_find_get_subsys(struct nvmet_port *port,
15461554
const char *subsysnqn)
15471555
{

drivers/nvme/target/debugfs.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,23 @@ static ssize_t nvmet_ctrl_state_write(struct file *file, const char __user *buf,
115115
}
116116
NVMET_DEBUGFS_RW_ATTR(nvmet_ctrl_state);
117117

118+
static int nvmet_ctrl_host_traddr_show(struct seq_file *m, void *p)
119+
{
120+
struct nvmet_ctrl *ctrl = m->private;
121+
ssize_t size;
122+
char buf[NVMF_TRADDR_SIZE + 1];
123+
124+
size = nvmet_ctrl_host_traddr(ctrl, buf, NVMF_TRADDR_SIZE);
125+
if (size < 0) {
126+
buf[0] = '\0';
127+
size = 0;
128+
}
129+
buf[size] = '\0';
130+
seq_printf(m, "%s\n", buf);
131+
return 0;
132+
}
133+
NVMET_DEBUGFS_ATTR(nvmet_ctrl_host_traddr);
134+
118135
int nvmet_debugfs_ctrl_setup(struct nvmet_ctrl *ctrl)
119136
{
120137
char name[32];
@@ -138,6 +155,8 @@ int nvmet_debugfs_ctrl_setup(struct nvmet_ctrl *ctrl)
138155
&nvmet_ctrl_kato_fops);
139156
debugfs_create_file("state", S_IRUSR | S_IWUSR, ctrl->debugfs_dir, ctrl,
140157
&nvmet_ctrl_state_fops);
158+
debugfs_create_file("host_traddr", S_IRUSR, ctrl->debugfs_dir, ctrl,
159+
&nvmet_ctrl_host_traddr_fops);
141160
return 0;
142161
}
143162

drivers/nvme/target/nvmet.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,8 @@ struct nvmet_fabrics_ops {
354354
void (*delete_ctrl)(struct nvmet_ctrl *ctrl);
355355
void (*disc_traddr)(struct nvmet_req *req,
356356
struct nvmet_port *port, char *traddr);
357+
ssize_t (*host_traddr)(struct nvmet_ctrl *ctrl,
358+
char *traddr, size_t traddr_len);
357359
u16 (*install_queue)(struct nvmet_sq *nvme_sq);
358360
void (*discovery_chg)(struct nvmet_port *port);
359361
u8 (*get_mdts)(const struct nvmet_ctrl *ctrl);
@@ -502,6 +504,8 @@ struct nvmet_ctrl *nvmet_ctrl_find_get(const char *subsysnqn,
502504
struct nvmet_req *req);
503505
void nvmet_ctrl_put(struct nvmet_ctrl *ctrl);
504506
u16 nvmet_check_ctrl_status(struct nvmet_req *req);
507+
ssize_t nvmet_ctrl_host_traddr(struct nvmet_ctrl *ctrl,
508+
char *traddr, size_t traddr_len);
505509

506510
struct nvmet_subsys *nvmet_subsys_alloc(const char *subsysnqn,
507511
enum nvme_subsys_type type);

0 commit comments

Comments
 (0)