sunrpc: add IDs to multipath
authorOlga Kornievskaia <kolga@netapp.com>
Tue, 8 Jun 2021 19:59:14 +0000 (15:59 -0400)
committerTrond Myklebust <trond.myklebust@hammerspace.com>
Thu, 8 Jul 2021 18:03:23 +0000 (14:03 -0400)
This is used to uniquely identify sunrpc multipath objects in /sys.

Signed-off-by: Dan Aloni <dan@kernelim.com>
Signed-off-by: Olga Kornievskaia <kolga@netapp.com>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
include/linux/sunrpc/xprtmultipath.h
net/sunrpc/sunrpc_syms.c
net/sunrpc/xprtmultipath.c

index c6cce3fbf29dbf6a5c023351cae5c628e96541ca..ef95a6f18ccf609c46529ddc02c2317ebda352cc 100644 (file)
@@ -14,6 +14,7 @@ struct rpc_xprt_switch {
        spinlock_t              xps_lock;
        struct kref             xps_kref;
 
+       unsigned int            xps_id;
        unsigned int            xps_nxprts;
        unsigned int            xps_nactive;
        atomic_long_t           xps_queuelen;
@@ -71,4 +72,7 @@ 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);
+
+extern void xprt_multipath_cleanup_ids(void);
+
 #endif
index b61b74c004836f49fc318f147a08f13d8ed6a7ce..691c0000e9eae14c0d0dfd08b2969fa663252ed0 100644 (file)
@@ -134,6 +134,7 @@ cleanup_sunrpc(void)
        rpc_sysfs_exit();
        rpc_cleanup_clids();
        xprt_cleanup_ids();
+       xprt_multipath_cleanup_ids();
        rpcauth_remove_module();
        cleanup_socket_xprt();
        svc_cleanup_xprt_sock();
index 78c075a68c0479060869aab8355470a88dfe5e2c..4969a4c216f75cae5c9d8578080b3320a7651769 100644 (file)
@@ -86,6 +86,30 @@ void rpc_xprt_switch_remove_xprt(struct rpc_xprt_switch *xps,
        xprt_put(xprt);
 }
 
+static DEFINE_IDA(rpc_xprtswitch_ids);
+
+void xprt_multipath_cleanup_ids(void)
+{
+       ida_destroy(&rpc_xprtswitch_ids);
+}
+
+static int xprt_switch_alloc_id(struct rpc_xprt_switch *xps, gfp_t gfp_flags)
+{
+       int id;
+
+       id = ida_simple_get(&rpc_xprtswitch_ids, 0, 0, gfp_flags);
+       if (id < 0)
+               return id;
+
+       xps->xps_id = id;
+       return 0;
+}
+
+static void xprt_switch_free_id(struct rpc_xprt_switch *xps)
+{
+       ida_simple_remove(&rpc_xprtswitch_ids, xps->xps_id);
+}
+
 /**
  * xprt_switch_alloc - Allocate a new struct rpc_xprt_switch
  * @xprt: pointer to struct rpc_xprt
@@ -103,6 +127,7 @@ struct rpc_xprt_switch *xprt_switch_alloc(struct rpc_xprt *xprt,
        if (xps != NULL) {
                spin_lock_init(&xps->xps_lock);
                kref_init(&xps->xps_kref);
+               xprt_switch_alloc_id(xps, gfp_flags);
                xps->xps_nxprts = xps->xps_nactive = 0;
                atomic_long_set(&xps->xps_queuelen, 0);
                xps->xps_net = NULL;
@@ -136,6 +161,7 @@ static void xprt_switch_free(struct kref *kref)
                        struct rpc_xprt_switch, xps_kref);
 
        xprt_switch_free_entries(xps);
+       xprt_switch_free_id(xps);
        kfree_rcu(xps, xps_rcu);
 }