Commit a902f3de authored by Anna Schumaker's avatar Anna Schumaker

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: default avatarJeff Layton <jlayton@kernel.org>
Signed-off-by: default avatarAnna Schumaker <Anna.Schumaker@Netapp.com>
parent 5f1e77b2
...@@ -797,15 +797,24 @@ int rpc_switch_client_transport(struct rpc_clnt *clnt, ...@@ -797,15 +797,24 @@ int rpc_switch_client_transport(struct rpc_clnt *clnt,
} }
EXPORT_SYMBOL_GPL(rpc_switch_client_transport); EXPORT_SYMBOL_GPL(rpc_switch_client_transport);
static static struct rpc_xprt_switch *rpc_clnt_xprt_switch_get(struct rpc_clnt *clnt)
int _rpc_clnt_xprt_iter_init(struct rpc_clnt *clnt, struct rpc_xprt_iter *xpi,
void func(struct rpc_xprt_iter *xpi, struct rpc_xprt_switch *xps))
{ {
struct rpc_xprt_switch *xps; struct rpc_xprt_switch *xps;
rcu_read_lock(); rcu_read_lock();
xps = xprt_switch_get(rcu_dereference(clnt->cl_xpi.xpi_xpswitch)); xps = xprt_switch_get(rcu_dereference(clnt->cl_xpi.xpi_xpswitch));
rcu_read_unlock(); rcu_read_unlock();
return xps;
}
static
int _rpc_clnt_xprt_iter_init(struct rpc_clnt *clnt, struct rpc_xprt_iter *xpi,
void func(struct rpc_xprt_iter *xpi, struct rpc_xprt_switch *xps))
{
struct rpc_xprt_switch *xps;
xps = rpc_clnt_xprt_switch_get(clnt);
if (xps == NULL) if (xps == NULL)
return -EAGAIN; return -EAGAIN;
func(xpi, xps); func(xpi, xps);
...@@ -2206,9 +2215,7 @@ call_connect_status(struct rpc_task *task) ...@@ -2206,9 +2215,7 @@ call_connect_status(struct rpc_task *task)
struct rpc_xprt *saved = task->tk_xprt; struct rpc_xprt *saved = task->tk_xprt;
struct rpc_xprt_switch *xps; struct rpc_xprt_switch *xps;
rcu_read_lock(); xps = rpc_clnt_xprt_switch_get(clnt);
xps = xprt_switch_get(rcu_dereference(clnt->cl_xpi.xpi_xpswitch));
rcu_read_unlock();
if (xps->xps_nxprts > 1) { if (xps->xps_nxprts > 1) {
long value; long value;
...@@ -3251,22 +3258,23 @@ void rpc_clnt_xprt_set_online(struct rpc_clnt *clnt, struct rpc_xprt *xprt) ...@@ -3251,22 +3258,23 @@ void rpc_clnt_xprt_set_online(struct rpc_clnt *clnt, struct rpc_xprt *xprt)
{ {
struct rpc_xprt_switch *xps; struct rpc_xprt_switch *xps;
rcu_read_lock(); xps = rpc_clnt_xprt_switch_get(clnt);
xps = rcu_dereference(clnt->cl_xpi.xpi_xpswitch);
rcu_read_unlock();
xprt_set_online_locked(xprt, xps); xprt_set_online_locked(xprt, xps);
xprt_switch_put(xps);
} }
void rpc_clnt_xprt_switch_add_xprt(struct rpc_clnt *clnt, struct rpc_xprt *xprt) void rpc_clnt_xprt_switch_add_xprt(struct rpc_clnt *clnt, struct rpc_xprt *xprt)
{ {
struct rpc_xprt_switch *xps;
if (rpc_clnt_xprt_switch_has_addr(clnt, if (rpc_clnt_xprt_switch_has_addr(clnt,
(const struct sockaddr *)&xprt->addr)) { (const struct sockaddr *)&xprt->addr)) {
return rpc_clnt_xprt_set_online(clnt, xprt); return rpc_clnt_xprt_set_online(clnt, xprt);
} }
rcu_read_lock();
rpc_xprt_switch_add_xprt(rcu_dereference(clnt->cl_xpi.xpi_xpswitch), xps = rpc_clnt_xprt_switch_get(clnt);
xprt); rpc_xprt_switch_add_xprt(xps, xprt);
rcu_read_unlock(); xprt_switch_put(xps);
} }
EXPORT_SYMBOL_GPL(rpc_clnt_xprt_switch_add_xprt); EXPORT_SYMBOL_GPL(rpc_clnt_xprt_switch_add_xprt);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment