public inbox for linux-nfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Aloni <dan@kernelim.com>
To: linux-nfs@vger.kernel.org
Cc: Trond Myklebust <trond.myklebust@hammerspace.com>,
	Anna Schumaker <anna.schumaker@netapp.com>
Subject: [PATCH v1 2/5] xprtrdma: Bind to a local address if requested
Date: Thu, 21 Jan 2021 21:10:17 +0200	[thread overview]
Message-ID: <20210121191020.3144948-3-dan@kernelim.com> (raw)
In-Reply-To: <20210121191020.3144948-1-dan@kernelim.com>

Until now, rpcrdma did not make use of the local address when binding a
QP. For subnets where the local machine has multiple IP addresses that
are all connected to the same subnet, it may be desired to tell from
which interface a QP is going out.

Signed-off-by: Dan Aloni <dan@kernelim.com>
---
 net/sunrpc/xprtrdma/transport.c |  7 +++++++
 net/sunrpc/xprtrdma/verbs.c     | 15 ++++++++++++++-
 net/sunrpc/xprtrdma/xprt_rdma.h |  2 ++
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/net/sunrpc/xprtrdma/transport.c b/net/sunrpc/xprtrdma/transport.c
index 78d29d1bcc20..45726ab5f13a 100644
--- a/net/sunrpc/xprtrdma/transport.c
+++ b/net/sunrpc/xprtrdma/transport.c
@@ -355,6 +355,13 @@ xprt_setup_rdma(struct xprt_create *args)
 	xprt_rdma_format_addresses(xprt, sap);
 
 	new_xprt = rpcx_to_rdmax(xprt);
+
+	/* Copy source address if specified */
+	if (args->srcaddr) {
+		new_xprt->rx_has_srcaddr = true;
+		memcpy(&new_xprt->rx_saddr, args->srcaddr, args->addrlen);
+	}
+
 	rc = rpcrdma_buffer_create(new_xprt);
 	if (rc) {
 		xprt_rdma_free_addresses(xprt);
diff --git a/net/sunrpc/xprtrdma/verbs.c b/net/sunrpc/xprtrdma/verbs.c
index ec912cf9c618..64476161cf92 100644
--- a/net/sunrpc/xprtrdma/verbs.c
+++ b/net/sunrpc/xprtrdma/verbs.c
@@ -314,6 +314,7 @@ static struct rdma_cm_id *rpcrdma_create_id(struct rpcrdma_xprt *r_xprt,
 	unsigned long wtimeout = msecs_to_jiffies(RDMA_RESOLVE_TIMEOUT) + 1;
 	struct rpc_xprt *xprt = &r_xprt->rx_xprt;
 	struct rdma_cm_id *id;
+	struct sockaddr *saddr = NULL;
 	int rc;
 
 	init_completion(&ep->re_done);
@@ -324,7 +325,19 @@ static struct rdma_cm_id *rpcrdma_create_id(struct rpcrdma_xprt *r_xprt,
 		return id;
 
 	ep->re_async_rc = -ETIMEDOUT;
-	rc = rdma_resolve_addr(id, NULL, (struct sockaddr *)&xprt->addr,
+	if (r_xprt->rx_has_srcaddr) {
+		char buf[0x50] = {0, };
+		saddr = (struct sockaddr *)&r_xprt->rx_saddr;
+
+		rpc_ntop(saddr, buf, sizeof(buf));
+
+		dprintk("xprt=%p, source address port %s\n", xprt, buf);
+	}
+
+	dprintk("xprt=%p, %s:%s resolving addr\n", xprt,
+		rpcrdma_addrstr(r_xprt), rpcrdma_portstr(r_xprt));
+
+	rc = rdma_resolve_addr(id, saddr, (struct sockaddr *)&xprt->addr,
 			       RDMA_RESOLVE_TIMEOUT);
 	if (rc)
 		goto out;
diff --git a/net/sunrpc/xprtrdma/xprt_rdma.h b/net/sunrpc/xprtrdma/xprt_rdma.h
index 94b28657aeeb..cb4539d4740a 100644
--- a/net/sunrpc/xprtrdma/xprt_rdma.h
+++ b/net/sunrpc/xprtrdma/xprt_rdma.h
@@ -421,6 +421,8 @@ struct rpcrdma_stats {
  */
 struct rpcrdma_xprt {
 	struct rpc_xprt		rx_xprt;
+	struct sockaddr_storage rx_saddr;
+	bool			rx_has_srcaddr;
 	struct rpcrdma_ep	*rx_ep;
 	struct rpcrdma_buffer	rx_buf;
 	struct delayed_work	rx_connect_worker;
-- 
2.26.2


  parent reply	other threads:[~2021-01-21 19:11 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-21 19:10 [PATCH v1 0/5] NFSv3 client RDMA multipath enhancements Dan Aloni
2021-01-21 19:10 ` [PATCH v1 1/5] sunrpc: Allow specifying a vector of IP addresses for nconnect Dan Aloni
2021-01-21 19:10 ` Dan Aloni [this message]
2021-01-21 19:10 ` [PATCH v1 3/5] nfs: Extend nconnect with remoteports and localports mount params Dan Aloni
2021-01-21 19:10 ` [PATCH v1 4/5] sunrpc: Add srcaddr to xprt sysfs debug Dan Aloni
2021-01-21 19:10 ` [PATCH v1 5/5] nfs: Increase NFS_MAX_CONNECTIONS Dan Aloni
2021-01-21 19:50 ` [PATCH v1 0/5] NFSv3 client RDMA multipath enhancements Chuck Lever
2021-01-24 17:37   ` Dan Aloni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210121191020.3144948-3-dan@kernelim.com \
    --to=dan@kernelim.com \
    --cc=anna.schumaker@netapp.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=trond.myklebust@hammerspace.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox