Skip to content

Commit a902f3d

Browse files
committed
SUNRPC: Create a helper function for accessing the rpc_clnt's xprt_switch
This function takes the necessary rcu read lock to dereference the client's rpc_xprt_switch and bump the reference count so it doesn't disappear underneath us before returning. This does mean that callers are responsible for calling xprt_switch_put() on the returned object when they are done with it. Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
1 parent 5f1e77b commit a902f3d

1 file changed

Lines changed: 21 additions & 13 deletions

File tree

net/sunrpc/clnt.c

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -797,15 +797,24 @@ int rpc_switch_client_transport(struct rpc_clnt *clnt,
797797
}
798798
EXPORT_SYMBOL_GPL(rpc_switch_client_transport);
799799

800-
static
801-
int _rpc_clnt_xprt_iter_init(struct rpc_clnt *clnt, struct rpc_xprt_iter *xpi,
802-
void func(struct rpc_xprt_iter *xpi, struct rpc_xprt_switch *xps))
800+
static struct rpc_xprt_switch *rpc_clnt_xprt_switch_get(struct rpc_clnt *clnt)
803801
{
804802
struct rpc_xprt_switch *xps;
805803

806804
rcu_read_lock();
807805
xps = xprt_switch_get(rcu_dereference(clnt->cl_xpi.xpi_xpswitch));
808806
rcu_read_unlock();
807+
808+
return xps;
809+
}
810+
811+
static
812+
int _rpc_clnt_xprt_iter_init(struct rpc_clnt *clnt, struct rpc_xprt_iter *xpi,
813+
void func(struct rpc_xprt_iter *xpi, struct rpc_xprt_switch *xps))
814+
{
815+
struct rpc_xprt_switch *xps;
816+
817+
xps = rpc_clnt_xprt_switch_get(clnt);
809818
if (xps == NULL)
810819
return -EAGAIN;
811820
func(xpi, xps);
@@ -2206,9 +2215,7 @@ call_connect_status(struct rpc_task *task)
22062215
struct rpc_xprt *saved = task->tk_xprt;
22072216
struct rpc_xprt_switch *xps;
22082217

2209-
rcu_read_lock();
2210-
xps = xprt_switch_get(rcu_dereference(clnt->cl_xpi.xpi_xpswitch));
2211-
rcu_read_unlock();
2218+
xps = rpc_clnt_xprt_switch_get(clnt);
22122219
if (xps->xps_nxprts > 1) {
22132220
long value;
22142221

@@ -3251,22 +3258,23 @@ void rpc_clnt_xprt_set_online(struct rpc_clnt *clnt, struct rpc_xprt *xprt)
32513258
{
32523259
struct rpc_xprt_switch *xps;
32533260

3254-
rcu_read_lock();
3255-
xps = rcu_dereference(clnt->cl_xpi.xpi_xpswitch);
3256-
rcu_read_unlock();
3261+
xps = rpc_clnt_xprt_switch_get(clnt);
32573262
xprt_set_online_locked(xprt, xps);
3263+
xprt_switch_put(xps);
32583264
}
32593265

32603266
void rpc_clnt_xprt_switch_add_xprt(struct rpc_clnt *clnt, struct rpc_xprt *xprt)
32613267
{
3268+
struct rpc_xprt_switch *xps;
3269+
32623270
if (rpc_clnt_xprt_switch_has_addr(clnt,
32633271
(const struct sockaddr *)&xprt->addr)) {
32643272
return rpc_clnt_xprt_set_online(clnt, xprt);
32653273
}
3266-
rcu_read_lock();
3267-
rpc_xprt_switch_add_xprt(rcu_dereference(clnt->cl_xpi.xpi_xpswitch),
3268-
xprt);
3269-
rcu_read_unlock();
3274+
3275+
xps = rpc_clnt_xprt_switch_get(clnt);
3276+
rpc_xprt_switch_add_xprt(xps, xprt);
3277+
xprt_switch_put(xps);
32703278
}
32713279
EXPORT_SYMBOL_GPL(rpc_clnt_xprt_switch_add_xprt);
32723280

0 commit comments

Comments
 (0)