Skip to content

Commit 572caba

Browse files
olgakorn1Trond Myklebust
authored andcommitted
sunrpc: add xprt id
This adds a unique identifier for a sunrpc transport in sysfs, which is similarly managed to the unique IDs of clients. Signed-off-by: Dan Aloni <[email protected]> Signed-off-by: Olga Kornievskaia <[email protected]> Signed-off-by: Trond Myklebust <[email protected]>
1 parent c5a382e commit 572caba

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

include/linux/sunrpc/xprt.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ enum xprt_transports {
185185
struct rpc_xprt {
186186
struct kref kref; /* Reference count */
187187
const struct rpc_xprt_ops *ops; /* transport methods */
188+
unsigned int id; /* transport id */
188189

189190
const struct rpc_timeout *timeout; /* timeout parms */
190191
struct sockaddr_storage addr; /* server address */
@@ -370,6 +371,7 @@ struct rpc_xprt * xprt_alloc(struct net *net, size_t size,
370371
void xprt_free(struct rpc_xprt *);
371372
void xprt_add_backlog(struct rpc_xprt *xprt, struct rpc_task *task);
372373
bool xprt_wake_up_backlog(struct rpc_xprt *xprt, struct rpc_rqst *req);
374+
void xprt_cleanup_ids(void);
373375

374376
static inline int
375377
xprt_enable_swap(struct rpc_xprt *xprt)

net/sunrpc/sunrpc_syms.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ cleanup_sunrpc(void)
133133
{
134134
rpc_sysfs_exit();
135135
rpc_cleanup_clids();
136+
xprt_cleanup_ids();
136137
rpcauth_remove_module();
137138
cleanup_socket_xprt();
138139
svc_cleanup_xprt_sock();

net/sunrpc/xprt.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,6 +1746,30 @@ static void xprt_free_all_slots(struct rpc_xprt *xprt)
17461746
}
17471747
}
17481748

1749+
static DEFINE_IDA(rpc_xprt_ids);
1750+
1751+
void xprt_cleanup_ids(void)
1752+
{
1753+
ida_destroy(&rpc_xprt_ids);
1754+
}
1755+
1756+
static int xprt_alloc_id(struct rpc_xprt *xprt)
1757+
{
1758+
int id;
1759+
1760+
id = ida_simple_get(&rpc_xprt_ids, 0, 0, GFP_KERNEL);
1761+
if (id < 0)
1762+
return id;
1763+
1764+
xprt->id = id;
1765+
return 0;
1766+
}
1767+
1768+
static void xprt_free_id(struct rpc_xprt *xprt)
1769+
{
1770+
ida_simple_remove(&rpc_xprt_ids, xprt->id);
1771+
}
1772+
17491773
struct rpc_xprt *xprt_alloc(struct net *net, size_t size,
17501774
unsigned int num_prealloc,
17511775
unsigned int max_alloc)
@@ -1758,6 +1782,7 @@ struct rpc_xprt *xprt_alloc(struct net *net, size_t size,
17581782
if (xprt == NULL)
17591783
goto out;
17601784

1785+
xprt_alloc_id(xprt);
17611786
xprt_init(xprt, net);
17621787

17631788
for (i = 0; i < num_prealloc; i++) {
@@ -1786,6 +1811,7 @@ void xprt_free(struct rpc_xprt *xprt)
17861811
{
17871812
put_net(xprt->xprt_net);
17881813
xprt_free_all_slots(xprt);
1814+
xprt_free_id(xprt);
17891815
kfree_rcu(xprt, rcu);
17901816
}
17911817
EXPORT_SYMBOL_GPL(xprt_free);

0 commit comments

Comments
 (0)