[Devel,v2,3/3] sunrpc: pending tasks kill helper added

Submitted by Stanislav Kinsburskiy on June 26, 2017, 2:59 p.m.

Details

Message ID 20170626145937.31092.88436.stgit@localhost.localdomain
State New
Series "Kill SUNRPC tasks on container fast stop"
Headers show

Commit Message

Stanislav Kinsburskiy June 26, 2017, 2:59 p.m.
This patch aborts SUNRPC tasks upon raise of per-net "kill_tasks" toggle.
This is needed to abort pernding tasks, which are waiting for timeout.

Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
---
 net/sunrpc/clnt.c |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

Patch hide | download patch | download mbox

diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
index 2635c49..8543de4 100644
--- a/net/sunrpc/clnt.c
+++ b/net/sunrpc/clnt.c
@@ -2537,6 +2537,20 @@  retry:
 EXPORT_SYMBOL_GPL(rpc_clnt_swap_deactivate);
 #endif /* CONFIG_SUNRPC_SWAP */
 
+static void rpc_kill_tasks(struct net *net)
+{
+	struct rpc_clnt *clnt;
+	struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
+
+	spin_lock(&sn->rpc_client_lock);
+	list_for_each_entry(clnt, &sn->all_clients, cl_clients) {
+		spin_lock(&clnt->cl_lock);
+		xprt_wake_pending_tasks(clnt->cl_xprt, -EIO);
+		spin_unlock(&clnt->cl_lock);
+	}
+	spin_unlock(&sn->rpc_client_lock);
+}
+
 static ssize_t write_kill_tasks(struct file *file, const char __user *buf,
 			 size_t count, loff_t *ppos)
 {
@@ -2556,6 +2570,10 @@  static ssize_t write_kill_tasks(struct file *file, const char __user *buf,
 	if (res)
 		return res;
 
+	/* Kill pending tasks */
+	if (kill_tasks && !sn->kill_tasks)
+		rpc_kill_tasks(net);
+
 	sn->kill_tasks = !!kill_tasks;
 	return count;
 }