Skip to content

Commit 02c57a8

Browse files
Martin BelangerChristoph Hellwig
authored andcommitted
nvme-tcp: print actual source IP address through sysfs "address" attr
TCP transport relies on the routing table to determine which source address and interface to use when making a connection. Currently, there is no way to tell from userspace where a connection was made. This patch exposes the actual source address using a new field named "src_addr=" in the "address" attribute. This is needed to diagnose and identify connectivity issues. With the source address we can infer the interface associated with each connection. This was tested with nvme-cli 2.0 to verify it does not have any adverse effect. The new "src_addr=" field will simply be displayed in the output of the "list-subsys" or "list -v" commands as shown here. $ nvme list-subsys nvme-subsys0 - NQN=nqn.2014-08.org.nvmexpress.discovery \ +- nvme0 tcp traddr=192.168.56.1,trsvcid=8009,src_addr=192.168.56.101 live Signed-off-by: Martin Belanger <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]> Reviewed-by: Chaitanya Kulkarni <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent 5bfaba2 commit 02c57a8

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

drivers/nvme/host/tcp.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2546,6 +2546,25 @@ static int nvme_tcp_poll(struct blk_mq_hw_ctx *hctx, struct io_comp_batch *iob)
25462546
return queue->nr_cqe;
25472547
}
25482548

2549+
static int nvme_tcp_get_address(struct nvme_ctrl *ctrl, char *buf, int size)
2550+
{
2551+
struct nvme_tcp_queue *queue = &to_tcp_ctrl(ctrl)->queues[0];
2552+
struct sockaddr_storage src_addr;
2553+
int ret, len;
2554+
2555+
len = nvmf_get_address(ctrl, buf, size);
2556+
2557+
ret = kernel_getsockname(queue->sock, (struct sockaddr *)&src_addr);
2558+
if (ret > 0) {
2559+
if (len > 0)
2560+
len--; /* strip trailing newline */
2561+
len += scnprintf(buf + len, size - len, "%ssrc_addr=%pISc\n",
2562+
(len) ? "," : "", &src_addr);
2563+
}
2564+
2565+
return len;
2566+
}
2567+
25492568
static const struct blk_mq_ops nvme_tcp_mq_ops = {
25502569
.queue_rq = nvme_tcp_queue_rq,
25512570
.commit_rqs = nvme_tcp_commit_rqs,
@@ -2577,7 +2596,7 @@ static const struct nvme_ctrl_ops nvme_tcp_ctrl_ops = {
25772596
.free_ctrl = nvme_tcp_free_ctrl,
25782597
.submit_async_event = nvme_tcp_submit_async_event,
25792598
.delete_ctrl = nvme_tcp_delete_ctrl,
2580-
.get_address = nvmf_get_address,
2599+
.get_address = nvme_tcp_get_address,
25812600
.stop_ctrl = nvme_tcp_stop_ctrl,
25822601
};
25832602

0 commit comments

Comments
 (0)