Skip to content

Commit 5b92687

Browse files
olgakorn1Trond Myklebust
authored andcommitted
sunrpc: add IDs to multipath
This is used to uniquely identify sunrpc multipath objects in /sys. Signed-off-by: Dan Aloni <[email protected]> Signed-off-by: Olga Kornievskaia <[email protected]> Signed-off-by: Trond Myklebust <[email protected]>
1 parent 572caba commit 5b92687

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

include/linux/sunrpc/xprtmultipath.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ struct rpc_xprt_switch {
1414
spinlock_t xps_lock;
1515
struct kref xps_kref;
1616

17+
unsigned int xps_id;
1718
unsigned int xps_nxprts;
1819
unsigned int xps_nactive;
1920
atomic_long_t xps_queuelen;
@@ -71,4 +72,7 @@ extern struct rpc_xprt *xprt_iter_get_next(struct rpc_xprt_iter *xpi);
7172

7273
extern bool rpc_xprt_switch_has_addr(struct rpc_xprt_switch *xps,
7374
const struct sockaddr *sap);
75+
76+
extern void xprt_multipath_cleanup_ids(void);
77+
7478
#endif

net/sunrpc/sunrpc_syms.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ cleanup_sunrpc(void)
134134
rpc_sysfs_exit();
135135
rpc_cleanup_clids();
136136
xprt_cleanup_ids();
137+
xprt_multipath_cleanup_ids();
137138
rpcauth_remove_module();
138139
cleanup_socket_xprt();
139140
svc_cleanup_xprt_sock();

net/sunrpc/xprtmultipath.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,30 @@ void rpc_xprt_switch_remove_xprt(struct rpc_xprt_switch *xps,
8686
xprt_put(xprt);
8787
}
8888

89+
static DEFINE_IDA(rpc_xprtswitch_ids);
90+
91+
void xprt_multipath_cleanup_ids(void)
92+
{
93+
ida_destroy(&rpc_xprtswitch_ids);
94+
}
95+
96+
static int xprt_switch_alloc_id(struct rpc_xprt_switch *xps, gfp_t gfp_flags)
97+
{
98+
int id;
99+
100+
id = ida_simple_get(&rpc_xprtswitch_ids, 0, 0, gfp_flags);
101+
if (id < 0)
102+
return id;
103+
104+
xps->xps_id = id;
105+
return 0;
106+
}
107+
108+
static void xprt_switch_free_id(struct rpc_xprt_switch *xps)
109+
{
110+
ida_simple_remove(&rpc_xprtswitch_ids, xps->xps_id);
111+
}
112+
89113
/**
90114
* xprt_switch_alloc - Allocate a new struct rpc_xprt_switch
91115
* @xprt: pointer to struct rpc_xprt
@@ -103,6 +127,7 @@ struct rpc_xprt_switch *xprt_switch_alloc(struct rpc_xprt *xprt,
103127
if (xps != NULL) {
104128
spin_lock_init(&xps->xps_lock);
105129
kref_init(&xps->xps_kref);
130+
xprt_switch_alloc_id(xps, gfp_flags);
106131
xps->xps_nxprts = xps->xps_nactive = 0;
107132
atomic_long_set(&xps->xps_queuelen, 0);
108133
xps->xps_net = NULL;
@@ -136,6 +161,7 @@ static void xprt_switch_free(struct kref *kref)
136161
struct rpc_xprt_switch, xps_kref);
137162

138163
xprt_switch_free_entries(xps);
164+
xprt_switch_free_id(xps);
139165
kfree_rcu(xps, xps_rcu);
140166
}
141167

0 commit comments

Comments
 (0)