From patchwork Wed Aug 16 16:19:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 9904133 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 15E6560231 for ; Wed, 16 Aug 2017 16:19:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0829E28A02 for ; Wed, 16 Aug 2017 16:19:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F134228A10; Wed, 16 Aug 2017 16:19:44 +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_SIGNED, 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 8C1BB28A02 for ; Wed, 16 Aug 2017 16:19:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751782AbdHPQTn (ORCPT ); Wed, 16 Aug 2017 12:19:43 -0400 Received: from mail-it0-f67.google.com ([209.85.214.67]:38224 "EHLO mail-it0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751635AbdHPQTn (ORCPT ); Wed, 16 Aug 2017 12:19:43 -0400 Received: by mail-it0-f67.google.com with SMTP id f16so2665558itb.5 for ; Wed, 16 Aug 2017 09:19:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=y00ktf9nYGiTlc4LGEhkMs2knog8YZWzXG5xbIGjcPk=; b=XiL2R4A2bsvZ2hfGYYqlZehOo+Am0v+5PbJb+UCd98K9Qwdm9mqhaH1h+6hraaqQt1 MO2XP9U3aiJpsMHYt8sO9AQSohFAc5YyQM/AOXcdFcbnCrif8C14K3GOSh2T8oxSzEUI ip1vdvj4fqNyMS6qTCvSfmsp7weTQZAzoZkGrsIJJ0cku0feUY3aI+vkoOPAVl0NPWiN U6pbg+HWDJ01vP+eVR6GT5QV/mJ+qI7aj0IZx0n8v/X7U0TKPfXHte6NY45yR2MvU2sO Gm+OMhqUl2NJsiakyWzieei8AnId69slfXScV8oaRR/PEYGPQcwIS1iXFM0GR1RafeUs v+HQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=y00ktf9nYGiTlc4LGEhkMs2knog8YZWzXG5xbIGjcPk=; b=d1D88zKFcqKgwl05IYkMXJdbRVfPV/QuahSNQ8YSRf/2D8VSLzRtxwIYiwVQUfnwC5 UgdSJjIcIBhe22qehAB4Si8tnsdlh5h7KisFCEMEE2JTq+3rwRuGkvQ6Ms7efwxh3C7f YaPoX6+ItMLukKnJ6PjxGM6tyguS/HO4nmw3AaXN65oh3sMsJj+UI6rcOZWuS//GI3Wt oT9yUVcOPQhoaBBmS/0YrdYXyxy7aIRZYbWiU3g4GIIs+Z4D913Vbyh1FwFXgQHSuoI8 88jAuPgzRB48nYNEVaKr1wfZ74kKnrNf6Sp1rPYXVXdMJgxh9N/JqzCaAj969/QGATNL MxGQ== X-Gm-Message-State: AHYfb5jiVMGbBkSZ3NZmycu94FqVcDYyd5S5+WHPXm/W+pX57+5msQXT kOU2BPHmlPv/DZxASuM= X-Received: by 10.36.46.15 with SMTP id i15mr2324335ita.75.1502900381686; Wed, 16 Aug 2017 09:19:41 -0700 (PDT) Received: from localhost.localdomain (c-68-49-162-121.hsd1.mi.comcast.net. [68.49.162.121]) by smtp.gmail.com with ESMTPSA id b79sm646110itb.5.2017.08.16.09.19.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 16 Aug 2017 09:19:40 -0700 (PDT) From: Trond Myklebust To: linux-nfs@vger.kernel.org Subject: [PATCH v2 5/6] SUNRPC: Add a function to allow waiting for RPC transmission Date: Wed, 16 Aug 2017 12:19:28 -0400 Message-Id: <20170816161929.11271-6-trond.myklebust@primarydata.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170816161929.11271-5-trond.myklebust@primarydata.com> References: <20170816161929.11271-1-trond.myklebust@primarydata.com> <20170816161929.11271-2-trond.myklebust@primarydata.com> <20170816161929.11271-3-trond.myklebust@primarydata.com> <20170816161929.11271-4-trond.myklebust@primarydata.com> <20170816161929.11271-5-trond.myklebust@primarydata.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 Sometimes, we only want to know that the RPC message is in the process of being transmitted. Add a function to allow that. Signed-off-by: Trond Myklebust --- include/linux/sunrpc/sched.h | 3 +++ net/sunrpc/sched.c | 22 ++++++++++++++++++++++ net/sunrpc/xprt.c | 6 ++++++ 3 files changed, 31 insertions(+) diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h index c1768f9d993b..148cd6c5d2eb 100644 --- a/include/linux/sunrpc/sched.h +++ b/include/linux/sunrpc/sched.h @@ -141,6 +141,8 @@ struct rpc_task_setup { #define RPC_TASK_ACTIVE 2 #define RPC_TASK_MSG_RECV 3 #define RPC_TASK_MSG_RECV_WAIT 4 +#define RPC_TASK_MSG_XMIT 5 +#define RPC_TASK_MSG_XMIT_WAIT 6 #define RPC_IS_RUNNING(t) test_bit(RPC_TASK_RUNNING, &(t)->tk_runstate) #define rpc_set_running(t) set_bit(RPC_TASK_RUNNING, &(t)->tk_runstate) @@ -246,6 +248,7 @@ void rpc_free(struct rpc_task *); int rpciod_up(void); void rpciod_down(void); int __rpc_wait_for_completion_task(struct rpc_task *task, wait_bit_action_f *); +int rpc_wait_for_msg_send(struct rpc_task *task); #if IS_ENABLED(CONFIG_SUNRPC_DEBUG) struct net; void rpc_show_tasks(struct net *); diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c index 0cc83839c13c..30509a4d7e00 100644 --- a/net/sunrpc/sched.c +++ b/net/sunrpc/sched.c @@ -320,6 +320,19 @@ int __rpc_wait_for_completion_task(struct rpc_task *task, wait_bit_action_f *act EXPORT_SYMBOL_GPL(__rpc_wait_for_completion_task); /* + * Allow callers to wait for completion of an RPC call + */ +int rpc_wait_for_msg_send(struct rpc_task *task) +{ + if (!test_bit(RPC_TASK_MSG_XMIT, &task->tk_runstate)) + return 0; + set_bit(RPC_TASK_MSG_XMIT_WAIT, &task->tk_runstate); + return wait_on_bit_action(&task->tk_runstate, RPC_TASK_MSG_XMIT, + rpc_wait_bit_killable, TASK_KILLABLE); +} +EXPORT_SYMBOL_GPL(rpc_wait_for_msg_send); + +/* * Make an RPC task runnable. * * Note: If the task is ASYNC, and is being made runnable after sitting on an @@ -700,6 +713,7 @@ rpc_reset_task_statistics(struct rpc_task *task) { task->tk_timeouts = 0; task->tk_flags &= ~(RPC_CALL_MAJORSEEN|RPC_TASK_KILLED|RPC_TASK_SENT); + set_bit(RPC_TASK_MSG_XMIT, &task->tk_runstate); rpc_init_task_statistics(task); } @@ -928,6 +942,7 @@ static void rpc_init_task(struct rpc_task *task, const struct rpc_task_setup *ta memset(task, 0, sizeof(*task)); atomic_set(&task->tk_count, 1); task->tk_flags = task_setup_data->flags; + task->tk_runstate = BIT(RPC_TASK_MSG_XMIT); task->tk_ops = task_setup_data->callback_ops; task->tk_calldata = task_setup_data->callback_data; INIT_LIST_HEAD(&task->tk_task); @@ -1012,6 +1027,13 @@ static void rpc_async_release(struct work_struct *work) static void rpc_release_resources_task(struct rpc_task *task) { + if (test_bit(RPC_TASK_MSG_XMIT, &task->tk_runstate)) { + clear_bit(RPC_TASK_MSG_XMIT, &task->tk_runstate); + smp_mb__after_atomic(); + if (test_bit(RPC_TASK_MSG_XMIT_WAIT, &task->tk_runstate)) + wake_up_bit(&task->tk_runstate, RPC_TASK_MSG_XMIT); + } + xprt_release(task); if (task->tk_msg.rpc_cred) { put_rpccred(task->tk_msg.rpc_cred); diff --git a/net/sunrpc/xprt.c b/net/sunrpc/xprt.c index a558e8c620c0..62c379865f7c 100644 --- a/net/sunrpc/xprt.c +++ b/net/sunrpc/xprt.c @@ -978,6 +978,12 @@ bool xprt_prepare_transmit(struct rpc_task *task) goto out_unlock; } ret = true; + if (test_bit(RPC_TASK_MSG_XMIT, &task->tk_runstate)) { + clear_bit(RPC_TASK_MSG_XMIT, &task->tk_runstate); + smp_mb__after_atomic(); + if (test_bit(RPC_TASK_MSG_XMIT_WAIT, &task->tk_runstate)) + wake_up_bit(&task->tk_runstate, RPC_TASK_MSG_XMIT); + } out_unlock: spin_unlock_bh(&xprt->transport_lock); return ret;