Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp459456pxb; Fri, 29 Oct 2021 13:13:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzoUofqUBB5IUTTZI6bJCZGVF4Nw4ZvvZXr5gMVR5ubgrXytD+q/7YDU3/QHDDvyfzeOyB+ X-Received: by 2002:a17:906:6849:: with SMTP id a9mr12236723ejs.370.1635538384111; Fri, 29 Oct 2021 13:13:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635538384; cv=none; d=google.com; s=arc-20160816; b=LykfH5alnktiU1cc657MsRvHoJVPFIUfIvNuw67orAwIkkt8BG2toqQQh0tXAupevh UBNRn7854/jw7pVgPMJiZKQnEZdbouaf6U+UHZgR2gcaaBDEiTc6xvV4yYrIQ3P230xr vbMZsVx/goMvGgbfO9ls+yd8/Km3gXWldIHxLh0nlrddvHS/KFOpR2VoZs5Ov3tlHVLS yGBwIVhks4xzkZ+Hab1ytriVL4ao90HSpZxVQSb2lfgjoL12yov+NUtexuE/OAzyRaiz TJmUb5so8yKnZ+I++KqVGEe0/Xv0xdpcMpUbaP/OmbBfOnNlPoKCJeheTMHPsvp2ks1F z5NQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=3OxVyVOoGm2uDEFJtd17iY6X2RYSrfuJC3UQ4BAo7A4=; b=zaBUMHqUfRtMRPulyl7H5eD++tTEVZd+w+8Ne95VmASVWhYHWc+amc9KUSzY6R2sOy oWT5UfbMmhL0KtsWxLzB5DMHwPisVAFXOnkRIO9SG/mWHrSGomTFHehiL2eO7AVJxNdI cfYLMN+uJUNtp/E2KinSTRg6w9aZHZA5VBNcx1Y3XV47ixPFbaxJ/Eb8eV8mpZ0WnU0a I70BV38cfwLRqRpu96nMFnnHzWQShDGNjt8Pt0f5s+L3JSZNhlNx1EJIj5jvynbgbRE0 gma8J0AWWrBN55KaAZ8Uki2pivsX2z51s1Jj+RllIM+0+v6p4DNQbQPEjolBT8wjY2Ov tQeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VKFY375t; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ho44si10419476ejc.576.2021.10.29.13.12.27; Fri, 29 Oct 2021 13:13:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VKFY375t; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230126AbhJ2UNt (ORCPT + 99 others); Fri, 29 Oct 2021 16:13:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:41154 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230287AbhJ2UNt (ORCPT ); Fri, 29 Oct 2021 16:13:49 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E8DA961038 for ; Fri, 29 Oct 2021 20:11:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1635538280; bh=iu1S8qx4hSTqkMu+LfsmgbFkbHORK//w//ExthNUifM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=VKFY375tZtXt93b2YxkWbV62F/DscbVmwaUemlc8I5jHMQCMlmNwnk1xwb3zUtAr4 aDFmHJwCsLB2HtD/KZuqLer2pqruFO9mrLa5Q3O3okdwO5zlPU1OQdSh1QV61GpdEv +gmRs0uHmJW6BuUsppR9sZF1yD4hWxY67fHHbJwMorS7zUtTM6aQEGLlmN2qiYTbx7 2G/OMGj6bVxAASQ+/74uB+yDmMIeo8s0IwCSVSaOP2fqHxOptO2IPPWbGxlKVNLUX9 p9QyLzWl+4TKHnbQxFeibapDttIkMbbTa355tyjbEfy1ktnMbjWa8oQHlNxboVBv3+ Wknq9K24fvQdg== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH 3/4] SUNRPC: Clean up xs_tcp_setup_sock() Date: Fri, 29 Oct 2021 16:04:20 -0400 Message-Id: <20211029200421.65090-3-trondmy@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211029200421.65090-2-trondmy@kernel.org> References: <20211029200421.65090-1-trondmy@kernel.org> <20211029200421.65090-2-trondmy@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust Move the error handling into a single switch statement for clarity. Signed-off-by: Trond Myklebust --- net/sunrpc/xprtsock.c | 68 ++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 40 deletions(-) diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c index 291b63136c08..7fb302e202bc 100644 --- a/net/sunrpc/xprtsock.c +++ b/net/sunrpc/xprtsock.c @@ -2159,7 +2159,6 @@ static void xs_tcp_set_connect_timeout(struct rpc_xprt *xprt, static int xs_tcp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock) { struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt); - int ret = -ENOTCONN; if (!transport->inet) { struct sock *sk = sock->sk; @@ -2203,7 +2202,7 @@ static int xs_tcp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock) } if (!xprt_bound(xprt)) - goto out; + return -ENOTCONN; xs_set_memalloc(xprt); @@ -2211,22 +2210,7 @@ static int xs_tcp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock) /* Tell the socket layer to start connecting... */ set_bit(XPRT_SOCK_CONNECTING, &transport->sock_state); - ret = kernel_connect(sock, xs_addr(xprt), xprt->addrlen, O_NONBLOCK); - switch (ret) { - case 0: - xs_set_srcport(transport, sock); - fallthrough; - case -EINPROGRESS: - /* SYN_SENT! */ - if (xprt->reestablish_timeout < XS_TCP_INIT_REEST_TO) - xprt->reestablish_timeout = XS_TCP_INIT_REEST_TO; - break; - case -EADDRNOTAVAIL: - /* Source port number is unavailable. Try a new one! */ - transport->srcport = 0; - } -out: - return ret; + return kernel_connect(sock, xs_addr(xprt), xprt->addrlen, O_NONBLOCK); } /** @@ -2241,14 +2225,14 @@ static void xs_tcp_setup_socket(struct work_struct *work) container_of(work, struct sock_xprt, connect_worker.work); struct socket *sock = transport->sock; struct rpc_xprt *xprt = &transport->xprt; - int status = -EIO; + int status; if (!sock) { sock = xs_create_sock(xprt, transport, xs_addr(xprt)->sa_family, SOCK_STREAM, IPPROTO_TCP, true); if (IS_ERR(sock)) { - status = PTR_ERR(sock); + xprt_wake_pending_tasks(xprt, PTR_ERR(sock)); goto out; } } @@ -2265,21 +2249,21 @@ static void xs_tcp_setup_socket(struct work_struct *work) xprt, -status, xprt_connected(xprt), sock->sk->sk_state); switch (status) { - default: - printk("%s: connect returned unhandled error %d\n", - __func__, status); - fallthrough; - case -EADDRNOTAVAIL: - /* We're probably in TIME_WAIT. Get rid of existing socket, - * and retry - */ - xs_tcp_force_close(xprt); - break; case 0: + xs_set_srcport(transport, sock); + fallthrough; case -EINPROGRESS: + /* SYN_SENT! */ + if (xprt->reestablish_timeout < XS_TCP_INIT_REEST_TO) + xprt->reestablish_timeout = XS_TCP_INIT_REEST_TO; + fallthrough; case -EALREADY: - xprt_unlock_connect(xprt, transport); - return; + goto out_unlock; + case -EADDRNOTAVAIL: + /* Source port number is unavailable. Try a new one! */ + transport->srcport = 0; + status = -EAGAIN; + break; case -EINVAL: /* Happens, for instance, if the user specified a link * local IPv6 address without a scope-id. @@ -2291,18 +2275,22 @@ static void xs_tcp_setup_socket(struct work_struct *work) case -EHOSTUNREACH: case -EADDRINUSE: case -ENOBUFS: - /* xs_tcp_force_close() wakes tasks with a fixed error code. - * We need to wake them first to ensure the correct error code. - */ - xprt_wake_pending_tasks(xprt, status); - xs_tcp_force_close(xprt); - goto out; + break; + default: + printk("%s: connect returned unhandled error %d\n", + __func__, status); + status = -EAGAIN; } - status = -EAGAIN; + + /* xs_tcp_force_close() wakes tasks with a fixed error code. + * We need to wake them first to ensure the correct error code. + */ + xprt_wake_pending_tasks(xprt, status); + xs_tcp_force_close(xprt); out: xprt_clear_connecting(xprt); +out_unlock: xprt_unlock_connect(xprt, transport); - xprt_wake_pending_tasks(xprt, status); } /** -- 2.31.1