Skip to content

Commit 7960aa9

Browse files
Olga KornievskaiaTrond Myklebust
authored andcommitted
SUNRPC restructure rpc_clnt_setup_test_and_add_xprt
In preparation for code re-use, pull out the part of the rpc_clnt_setup_test_and_add_xprt() portion that sends a NULL rpc and then calls a session trunking function into a helper function. Re-organize the end of the function for code re-use. Signed-off-by: Olga Kornievskaia <[email protected]> Signed-off-by: Trond Myklebust <[email protected]>
1 parent e818bd0 commit 7960aa9

File tree

1 file changed

+31
-21
lines changed

1 file changed

+31
-21
lines changed

net/sunrpc/clnt.c

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2874,6 +2874,30 @@ int rpc_clnt_test_and_add_xprt(struct rpc_clnt *clnt,
28742874
}
28752875
EXPORT_SYMBOL_GPL(rpc_clnt_test_and_add_xprt);
28762876

2877+
static int rpc_clnt_add_xprt_helper(struct rpc_clnt *clnt,
2878+
struct rpc_xprt *xprt,
2879+
struct rpc_add_xprt_test *data)
2880+
{
2881+
struct rpc_task *task;
2882+
int status = -EADDRINUSE;
2883+
2884+
/* Test the connection */
2885+
task = rpc_call_null_helper(clnt, xprt, NULL, 0, NULL, NULL);
2886+
if (IS_ERR(task))
2887+
return PTR_ERR(task);
2888+
2889+
status = task->tk_status;
2890+
rpc_put_task(task);
2891+
2892+
if (status < 0)
2893+
return status;
2894+
2895+
/* rpc_xprt_switch and rpc_xprt are deferrenced by add_xprt_test() */
2896+
data->add_xprt_test(clnt, xprt, data->data);
2897+
2898+
return 0;
2899+
}
2900+
28772901
/**
28782902
* rpc_clnt_setup_test_and_add_xprt()
28792903
*
@@ -2897,8 +2921,6 @@ int rpc_clnt_setup_test_and_add_xprt(struct rpc_clnt *clnt,
28972921
struct rpc_xprt *xprt,
28982922
void *data)
28992923
{
2900-
struct rpc_task *task;
2901-
struct rpc_add_xprt_test *xtest = (struct rpc_add_xprt_test *)data;
29022924
int status = -EADDRINUSE;
29032925

29042926
xprt = xprt_get(xprt);
@@ -2907,31 +2929,19 @@ int rpc_clnt_setup_test_and_add_xprt(struct rpc_clnt *clnt,
29072929
if (rpc_xprt_switch_has_addr(xps, (struct sockaddr *)&xprt->addr))
29082930
goto out_err;
29092931

2910-
/* Test the connection */
2911-
task = rpc_call_null_helper(clnt, xprt, NULL, 0, NULL, NULL);
2912-
if (IS_ERR(task)) {
2913-
status = PTR_ERR(task);
2914-
goto out_err;
2915-
}
2916-
status = task->tk_status;
2917-
rpc_put_task(task);
2918-
2932+
status = rpc_clnt_add_xprt_helper(clnt, xprt, data);
29192933
if (status < 0)
29202934
goto out_err;
29212935

2922-
/* rpc_xprt_switch and rpc_xprt are deferrenced by add_xprt_test() */
2923-
xtest->add_xprt_test(clnt, xprt, xtest->data);
2924-
2925-
xprt_put(xprt);
2926-
xprt_switch_put(xps);
2927-
2928-
/* so that rpc_clnt_add_xprt does not call rpc_xprt_switch_add_xprt */
2929-
return 1;
2936+
status = 1;
29302937
out_err:
29312938
xprt_put(xprt);
29322939
xprt_switch_put(xps);
2933-
pr_info("RPC: rpc_clnt_test_xprt failed: %d addr %s not added\n",
2934-
status, xprt->address_strings[RPC_DISPLAY_ADDR]);
2940+
if (status < 0)
2941+
pr_info("RPC: rpc_clnt_test_xprt failed: %d addr %s not "
2942+
"added\n", status,
2943+
xprt->address_strings[RPC_DISPLAY_ADDR]);
2944+
/* so that rpc_clnt_add_xprt does not call rpc_xprt_switch_add_xprt */
29352945
return status;
29362946
}
29372947
EXPORT_SYMBOL_GPL(rpc_clnt_setup_test_and_add_xprt);

0 commit comments

Comments
 (0)