@@ -1264,6 +1264,18 @@ static void xs_xprt_free(struct rpc_xprt *xprt)
xprt_free(xprt);
}
+/**
+ * xs_destroy_xprt - close xprt socket and destroy it.
+ */
+static void xs_destroy_xprt(struct work_struct *work)
+{
+ struct rpc_xprt *xprt =
+ container_of(work, struct rpc_xprt, task_cleanup);
+
+ xs_close(xprt);
+ xs_xprt_free(xprt);
+}
+
/**
* xs_destroy - prepare to shutdown a transport
* @xprt: doomed transport
@@ -2891,7 +2903,9 @@ static struct rpc_xprt *xs_setup_local(struct xprt_create *args)
return xprt;
ret = ERR_PTR(-EINVAL);
out_err:
- xs_xprt_free(xprt);
+
+ INIT_WORK(&xprt->task_cleanup, xs_destroy_xprt);
+ schedule_work(&xprt->task_cleanup);
return ret;
}
Add mechanism in xs_setup_local() to safely tear xprt down and solve the socket leak problem. Signed-off-by: Wang Hai <wanghai38@huawei.com> --- net/sunrpc/xprtsock.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)