From patchwork Tue Aug 24 15:38:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 12455353 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 09FDCC4320A for ; Tue, 24 Aug 2021 15:38:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E0C3F61357 for ; Tue, 24 Aug 2021 15:38:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238284AbhHXPjE (ORCPT ); Tue, 24 Aug 2021 11:39:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:43774 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234546AbhHXPjE (ORCPT ); Tue, 24 Aug 2021 11:39:04 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7830D61151; Tue, 24 Aug 2021 15:38:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629819499; bh=kz5dpKm3mk2Yt7edtfvSS17rQvTHBQ4kcZeU64c03Qg=; h=From:To:Cc:Subject:Date:From; b=GIHMb5feSOnGC+Au3p2g9x+vNrXRx8Njs9yj8OhIjkfr/ElENjEMaedMeN4Gb/fuH tkxiXf7/pwRgw7sgMBvs3A4Zu+cQO5mlRNmYZe42Ltd/1ICmTpO75iz4qgct+/+hRA TT2AFmqadzhjo5xRFu08CRl6LCr73LYcVJC7YuMEmxSbT7g1YhX/gzJ97RFVb2s+oQ Hu6z07eWrvsvLJzFWFwzpTFCkqPLI/ph8vBfFam3cDifhGozkLIXuCWtrjpvosn1Uk 9cYi8y3g0w7GOeLIsvfYmQk0iqNEwfJsGTXNIt/Lp01MMRS+o1TfSoLk8tkGfMf1QJ luiqD1brEZDVw== From: trondmy@kernel.org To: Anna Schumaker Cc: linux-nfs@vger.kernel.org Subject: [PATCH 1/2] SUNRPC: Simplify socket shutdown when not reusing TCP ports Date: Tue, 24 Aug 2021 11:38:17 -0400 Message-Id: <20210824153818.322833-1-trondmy@kernel.org> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust If we're not required to reuse the TCP port, then we can just immediately close the socket, and leave the cleanup details to the TCP layer. Fixes: e6237b6feb37 ("NFSv4.1: Don't rebind to the same source port when reconnecting to the server") Signed-off-by: Trond Myklebust --- net/sunrpc/xprtsock.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c index e573dcecdd66..7e94f1d17edb 100644 --- a/net/sunrpc/xprtsock.c +++ b/net/sunrpc/xprtsock.c @@ -2099,6 +2099,10 @@ static void xs_tcp_shutdown(struct rpc_xprt *xprt) if (sock == NULL) return; + if (!xprt->reuseport) { + xs_close(xprt); + return; + } switch (skst) { default: kernel_sock_shutdown(sock, SHUT_RDWR); From patchwork Tue Aug 24 15:38:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 12455355 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24CA4C432BE for ; Tue, 24 Aug 2021 15:38:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 05BE061357 for ; Tue, 24 Aug 2021 15:38:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238311AbhHXPjF (ORCPT ); Tue, 24 Aug 2021 11:39:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:43778 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234546AbhHXPjE (ORCPT ); Tue, 24 Aug 2021 11:39:04 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3081F60F21; Tue, 24 Aug 2021 15:38:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1629819500; bh=SBAfLUjaYPT3+w+gakgXifkv2GwqKpwectilx5Pu7fI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LNZDD1bQtS7dAzsvQXIMKkgXWBE0khJ4MT4nUjYtv/+gXwnw5VgBZuWlzVW1jX9MY 3l/X0p/ueZ1S6HuZt92Lfdj0fLwg9OcR7RV/S3WAsOt2NAKiTQDzM2LU5CF6z6ywzb FGErgzTXIBc+mthlwWmg7+XJrVHrUTWFI70p133eyv+zprqsaN8ltnu5lyxvj6JuI2 yBBxF0JTRa1V3i6Hxol/8RM+Z4/Tixe4H2tSqKc6Ct3bhqmPYOq257TDNitFNOVeFa 19FJiTYTwJe2ve4zVwklUc3H/CNSrM6lnqoyivX5qi3V40kwMDloBVM3Bc7QxNXfmC x+Au31SfNoXrQ== From: trondmy@kernel.org To: Anna Schumaker Cc: linux-nfs@vger.kernel.org Subject: [PATCH 2/2] SUNRPC: Tweak TCP socket shutdown in the RPC client Date: Tue, 24 Aug 2021 11:38:18 -0400 Message-Id: <20210824153818.322833-2-trondmy@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210824153818.322833-1-trondmy@kernel.org> References: <20210824153818.322833-1-trondmy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust We only really need to call shutdown() if we're in the ESTABLISHED TCP state, since that is the only case where the client is initiating a close of an established connection. If the socket is in FIN_WAIT1 or FIN_WAIT2, then we've already initiated socket shutdown and are waiting for the server's reply, so do nothing. In all other cases where we've already received a FIN from the server, we should be able to just close the socket. Signed-off-by: Trond Myklebust --- net/sunrpc/xprtsock.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c index 7e94f1d17edb..b91027d140df 100644 --- a/net/sunrpc/xprtsock.c +++ b/net/sunrpc/xprtsock.c @@ -2104,12 +2104,15 @@ static void xs_tcp_shutdown(struct rpc_xprt *xprt) return; } switch (skst) { - default: + case TCP_FIN_WAIT1: + case TCP_FIN_WAIT2: + break; + case TCP_ESTABLISHED: + case TCP_CLOSE_WAIT: kernel_sock_shutdown(sock, SHUT_RDWR); trace_rpc_socket_shutdown(xprt, sock); break; - case TCP_CLOSE: - case TCP_TIME_WAIT: + default: xs_reset_transport(transport); } }