From patchwork Wed Nov 8 14:59:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Watt X-Patchwork-Id: 10048635 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2FB0A60381 for ; Wed, 8 Nov 2017 15:00:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 26AA329341 for ; Wed, 8 Nov 2017 15:00:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1B13F2A62F; Wed, 8 Nov 2017 15:00:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E5F2A29341 for ; Wed, 8 Nov 2017 15:00:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752593AbdKHPAU (ORCPT ); Wed, 8 Nov 2017 10:00:20 -0500 Received: from mail-io0-f195.google.com ([209.85.223.195]:50359 "EHLO mail-io0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752603AbdKHPAT (ORCPT ); Wed, 8 Nov 2017 10:00:19 -0500 Received: by mail-io0-f195.google.com with SMTP id 97so6214274iok.7 for ; Wed, 08 Nov 2017 07:00:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=0BoIXQaK3Mha2ZAdfkrIeDe2xlgvB9HpQXodL9Sh/OQ=; b=l+TBI59so6IjIntI0I4ttsXQcg0g5LduwEs+YambF54pLaW2FKWON131CK6PM3QEjh ziRl2eRbeiQ4OqzITKW3wUIqSZRPAaueiDJQ0MNfl+/BPMIA5010EQoXeERI6/WcZ69a 9pOzOkY8DvcjIsHqfl77gk+2x4EuHQ47RA2A46x2I9t8MfZ7wBYJ7Gg7WudA+C3GVz4M 2vAMoFwPrWMX5t1fJAwPuwbh1QsnkVUUJ9IAEwkqeRuQ2fijS8hOKsXihOVu1Yeq+jS0 tKBiz+zaprZHqcV2CB3cUOf7GFpULheJyl/tpN1NZRREODohmScfWSrDulca9Zbz+2B0 1sZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=0BoIXQaK3Mha2ZAdfkrIeDe2xlgvB9HpQXodL9Sh/OQ=; b=rS8GXmWsVIlYy3CRtMNrhEgqIRL9ib7YF5+8Pg5iJUAykSzQ8DD+5ag2vYcxExcnmm LVUq538uQF+I/6JNh2LMiIYeRj3Qz0LFXb1cOXbK9DxkZS32qosGIFdSxcx8Yb41Wmkh 3zeZpKszWbMWZNWX11GfVW5IO63bGx9ibPP6d+Fg28F6FShOqn+rBRnyz278qtbWUcvh yB4+sRXr5Iw4xNufooU6/H9yxSOrDbcPjm9VG07JAZfNw2bEJ26u+4enLzEh3TRQBo8j /iHADCQCn1ekb82euh8OLe7x9P1fDdUw+3vtRD/MKHr8jf5IiO/8CBUZG8sNXCLYl8Z0 1O0Q== X-Gm-Message-State: AJaThX441nT7gcAofZAN1FHJQpLhMko0N1s3wloS0ERwW7jFNzYeeCyl JCLvmo4+V7XRyuz7sLq8RBFFAz0gAP8= X-Google-Smtp-Source: ABhQp+QqFuzlDK1QLL7xNdlQ5lLK0i9aN+EhK587hk12WXDfrg3DZbA4GkIJDVk2FWzXm9xfD2GfQQ== X-Received: by 10.107.43.75 with SMTP id r72mr1034843ior.31.1510153218909; Wed, 08 Nov 2017 07:00:18 -0800 (PST) Received: from ola-842mrw1.ad.garmin.com ([204.77.163.55]) by smtp.googlemail.com with ESMTPSA id q191sm9170077itb.1.2017.11.08.07.00.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 08 Nov 2017 07:00:18 -0800 (PST) From: Joshua Watt X-Google-Original-From: Joshua Watt To: NeilBrown , Jeff Layton , Trond Myklebust Cc: linux-nfs@vger.kernel.org, Al Viro , "J . Bruce Fields" , David Howells , Joshua Watt Subject: [RFC 1/4] SUNRPC: Add flag to kill new tasks Date: Wed, 8 Nov 2017 08:59:39 -0600 Message-Id: <20171108145942.5127-2-JPEWhacker@gmail.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171108145942.5127-1-JPEWhacker@gmail.com> References: <20171108145942.5127-1-JPEWhacker@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The new flag to rpc_killall_tasks() causes new tasks that are killed after to call to be killed immediately instead of being executed. This will all clients (particularly NFS) to prevents these task from delaying shutdown of the RPC session longer than necessary. Signed-off-by: Joshua Watt --- fs/nfs/super.c | 4 ++-- include/linux/sunrpc/clnt.h | 1 + include/linux/sunrpc/sched.h | 2 +- net/sunrpc/clnt.c | 13 ++++++++++--- net/sunrpc/sched.c | 7 +++++++ 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/fs/nfs/super.c b/fs/nfs/super.c index 216f67d628b3..66fda2dcadd0 100644 --- a/fs/nfs/super.c +++ b/fs/nfs/super.c @@ -903,10 +903,10 @@ void nfs_umount_begin(struct super_block *sb) /* -EIO all pending I/O */ rpc = server->client_acl; if (!IS_ERR(rpc)) - rpc_killall_tasks(rpc); + rpc_killall_tasks(rpc, 0); rpc = server->client; if (!IS_ERR(rpc)) - rpc_killall_tasks(rpc); + rpc_killall_tasks(rpc, 0); } EXPORT_SYMBOL_GPL(nfs_umount_begin); diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h index 71c237e8240e..94f4e464de1b 100644 --- a/include/linux/sunrpc/clnt.h +++ b/include/linux/sunrpc/clnt.h @@ -54,6 +54,7 @@ struct rpc_clnt { cl_noretranstimeo: 1,/* No retransmit timeouts */ cl_autobind : 1,/* use getport() */ cl_chatty : 1;/* be verbose */ + bool cl_kill_new_tasks; /* Kill all new tasks */ struct rpc_rtt * cl_rtt; /* RTO estimator data */ const struct rpc_timeout *cl_timeout; /* Timeout strategy */ diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h index d96e74e114c0..9b8bebaee0f4 100644 --- a/include/linux/sunrpc/sched.h +++ b/include/linux/sunrpc/sched.h @@ -218,7 +218,7 @@ void rpc_put_task_async(struct rpc_task *); void rpc_exit_task(struct rpc_task *); void rpc_exit(struct rpc_task *, int); void rpc_release_calldata(const struct rpc_call_ops *, void *); -void rpc_killall_tasks(struct rpc_clnt *); +void rpc_killall_tasks(struct rpc_clnt *clnt, int kill_new_tasks); void rpc_execute(struct rpc_task *); void rpc_init_priority_wait_queue(struct rpc_wait_queue *, const char *); void rpc_init_wait_queue(struct rpc_wait_queue *, const char *); diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c index df4ecb042ebe..70005252b32f 100644 --- a/net/sunrpc/clnt.c +++ b/net/sunrpc/clnt.c @@ -814,14 +814,21 @@ EXPORT_SYMBOL_GPL(rpc_clnt_iterate_for_each_xprt); * Kill all tasks for the given client. * XXX: kill their descendants as well? */ -void rpc_killall_tasks(struct rpc_clnt *clnt) +void rpc_killall_tasks(struct rpc_clnt *clnt, int kill_new_tasks) { struct rpc_task *rovr; + dprintk("RPC: killing all tasks for client %p\n", clnt); + + if (kill_new_tasks) { + WRITE_ONCE(clnt->cl_kill_new_tasks, true); + + /* Ensure the kill flag is set before checking the task list */ + smp_mb(); + } if (list_empty(&clnt->cl_tasks)) return; - dprintk("RPC: killing all tasks for client %p\n", clnt); /* * Spin lock all_tasks to prevent changes... */ @@ -854,7 +861,7 @@ void rpc_shutdown_client(struct rpc_clnt *clnt) rcu_dereference(clnt->cl_xprt)->servername); while (!list_empty(&clnt->cl_tasks)) { - rpc_killall_tasks(clnt); + rpc_killall_tasks(clnt, 0); wait_event_timeout(destroy_wait, list_empty(&clnt->cl_tasks), 1*HZ); } diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c index 0cc83839c13c..c9bf1ab9e941 100644 --- a/net/sunrpc/sched.c +++ b/net/sunrpc/sched.c @@ -748,6 +748,13 @@ static void __rpc_execute(struct rpc_task *task) dprintk("RPC: %5u __rpc_execute flags=0x%x\n", task->tk_pid, task->tk_flags); + /* Ensure the task is in the client task list before checking the kill + * flag + */ + smp_mb(); + if (READ_ONCE(task->tk_client->cl_kill_new_tasks)) + rpc_exit(task, -EIO); + WARN_ON_ONCE(RPC_IS_QUEUED(task)); if (RPC_IS_QUEUED(task)) return;