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@xxxxxxxxxxxx> --- 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