SUNRPC search xprt switch for sockaddr
authorAndy Adamson <andros@netapp.com>
Fri, 9 Sep 2016 13:22:25 +0000 (09:22 -0400)
committerAnna Schumaker <Anna.Schumaker@Netapp.com>
Mon, 19 Sep 2016 17:08:36 +0000 (13:08 -0400)
Signed-off-by: Andy Adamson <andros@netapp.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
include/linux/sunrpc/clnt.h
include/linux/sunrpc/xprtmultipath.h
net/sunrpc/clnt.c
net/sunrpc/xprtmultipath.c

index b069d6e2c3d638e90824e66a846514d978e37229..35cc539e292195ad3d16b3096954f6cc20b74446 100644 (file)
@@ -202,5 +202,7 @@ const char *rpc_proc_name(const struct rpc_task *task);
 
 void rpc_clnt_xprt_switch_put(struct rpc_clnt *);
 void rpc_clnt_xprt_switch_add_xprt(struct rpc_clnt *, struct rpc_xprt *);
+bool rpc_clnt_xprt_switch_has_addr(struct rpc_clnt *clnt,
+                       const struct sockaddr *sap);
 #endif /* __KERNEL__ */
 #endif /* _LINUX_SUNRPC_CLNT_H */
index 5a9acffa41beb046945932005d18c7d70b7fb95d..507418c1c69e984e7890ae398c0b0c0e249aad9d 100644 (file)
@@ -66,4 +66,6 @@ extern struct rpc_xprt *xprt_iter_xprt(struct rpc_xprt_iter *xpi);
 extern struct rpc_xprt *xprt_iter_get_xprt(struct rpc_xprt_iter *xpi);
 extern struct rpc_xprt *xprt_iter_get_next(struct rpc_xprt_iter *xpi);
 
+extern bool rpc_xprt_switch_has_addr(struct rpc_xprt_switch *xps,
+               const struct sockaddr *sap);
 #endif
index 43ec46547dc9a2c1164deb0abda10b21943ee10e..8d68efd2026feb12751fdfcae906a775248e5b34 100644 (file)
@@ -2708,6 +2708,21 @@ void rpc_clnt_xprt_switch_add_xprt(struct rpc_clnt *clnt, struct rpc_xprt *xprt)
 }
 EXPORT_SYMBOL_GPL(rpc_clnt_xprt_switch_add_xprt);
 
+bool rpc_clnt_xprt_switch_has_addr(struct rpc_clnt *clnt,
+                                  const struct sockaddr *sap)
+{
+       struct rpc_xprt_switch *xps;
+       bool ret;
+
+       xps = rcu_dereference(clnt->cl_xpi.xpi_xpswitch);
+
+       rcu_read_lock();
+       ret = rpc_xprt_switch_has_addr(xps, sap);
+       rcu_read_unlock();
+       return ret;
+}
+EXPORT_SYMBOL_GPL(rpc_clnt_xprt_switch_has_addr);
+
 #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
 static void rpc_show_header(void)
 {
index 66c9d63f4797bbd9a9ffd655925797dce9503952..ae92a9e9ba52fe5424289156cca444887560f4c0 100644 (file)
@@ -15,6 +15,7 @@
 #include <asm/cmpxchg.h>
 #include <linux/spinlock.h>
 #include <linux/sunrpc/xprt.h>
+#include <linux/sunrpc/addr.h>
 #include <linux/sunrpc/xprtmultipath.h>
 
 typedef struct rpc_xprt *(*xprt_switch_find_xprt_t)(struct list_head *head,
@@ -49,7 +50,8 @@ void rpc_xprt_switch_add_xprt(struct rpc_xprt_switch *xps,
        if (xprt == NULL)
                return;
        spin_lock(&xps->xps_lock);
-       if (xps->xps_net == xprt->xprt_net || xps->xps_net == NULL)
+       if ((xps->xps_net == xprt->xprt_net || xps->xps_net == NULL) &&
+           !rpc_xprt_switch_has_addr(xps, (struct sockaddr *)&xprt->addr))
                xprt_switch_add_xprt_locked(xps, xprt);
        spin_unlock(&xps->xps_lock);
 }
@@ -232,6 +234,26 @@ struct rpc_xprt *xprt_iter_current_entry(struct rpc_xprt_iter *xpi)
        return xprt_switch_find_current_entry(head, xpi->xpi_cursor);
 }
 
+bool rpc_xprt_switch_has_addr(struct rpc_xprt_switch *xps,
+                             const struct sockaddr *sap)
+{
+       struct list_head *head;
+       struct rpc_xprt *pos;
+
+       if (xps == NULL || sap == NULL)
+               return false;
+
+       head = &xps->xps_xprt_list;
+       list_for_each_entry_rcu(pos, head, xprt_switch) {
+               if (rpc_cmp_addr_port(sap, (struct sockaddr *)&pos->addr)) {
+                       pr_info("RPC:   addr %s already in xprt switch\n",
+                               pos->address_strings[RPC_DISPLAY_ADDR]);
+                       return true;
+               }
+       }
+       return false;
+}
+
 static
 struct rpc_xprt *xprt_switch_find_next_entry(struct list_head *head,
                const struct rpc_xprt *cur)