Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3839808pxv; Mon, 19 Jul 2021 10:00:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfpnbzM1f7wiBNKwllRJT8qGVDZSIeg0Up9kBGbQ/tWDXcOhRfw5tqvsxPyk6dVTPxWmTj X-Received: by 2002:a17:906:5e04:: with SMTP id n4mr27763468eju.277.1626714004279; Mon, 19 Jul 2021 10:00:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626714004; cv=none; d=google.com; s=arc-20160816; b=YG3stGhgrLcArD2IjINQreyZNxAyj6ovy5RcLWLEKCAunVs0fJiCXiNfYYP+b73a1C MIAJernlHgzawDdy73pAnwJ9KiART9GNNJrSeNuro4eTl3X2gVQ1fB1lOHYFiEmfpjHA ncIP05idG6M/Ud8HgPqjs/njML6w+ekUKDSrCDj/+e0KIfw5judlubw5POKKyqj30jmV lD3yPX2hIzvrd9RNa/X/o1mluEyL9jwXHFtm6Y67Wyp4eYzyLkooZuIKVBFRRfWYss7m LxqJjcfoShdjda9/JKSa7jOdOkNep18ZvzaHhvMO9gEEeDWnwMSUOlykfbh/r7Pmb1Z+ V60g== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=QunSS2daLYxlE2fOqgaJDMnvCiwDYe5EUtlb+2NWrlo=; b=IhJEVZBwtg8FVDZIyzZJGG3NbPcarC+bD5Excc1TneMLU2DZt+QI0P/IQsCqY0MEEz lY2S/RXDgQfjaNojNbPO/V4PeN9dZPZZex19s+Sj3cAqLX0m5CnTdM22A8Ztvk5oLOcd t01gWBvIUfKxjgk28JaKPF0WAoqWOxtBN+QZ969CfcIpdUfpX//2ifRgZaozOi5zTKi4 qFPhGqhwF6JyXS97Db4Se7Tce1YrLBXqj+8a+d3a3Gmz5RGgu0GGVBngPPGRHU9g77+E JcKyPgQ5jLfXx2Bri+P2lkin3dDDjoDU83g242rfssVjIX60AoOtrB8gFiOsgHHIUhiD Qw/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tmNBksV4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y94si22266572ede.150.2021.07.19.09.59.41; Mon, 19 Jul 2021 10:00:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@linuxfoundation.org header.s=korg header.b=tmNBksV4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353493AbhGSQQx (ORCPT + 99 others); Mon, 19 Jul 2021 12:16:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:47200 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345346AbhGSPKh (ORCPT ); Mon, 19 Jul 2021 11:10:37 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 72235610FB; Mon, 19 Jul 2021 15:51:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626709876; bh=0DJlWJfdKqNbqEU2AQwB7Aaptgw22xYq1L3YmblnEFo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tmNBksV4FYJgFVgMfD+Pl6qj5WpzbF65eDPBVrYdzRfovliG2v5sKunrXXHmv2VAg TW+Z71xooCuRR7zZAtEAviotPKMv3wYC0uyJnKHJy/ykTHAaWeHryIQF4B+GK27Bi9 I8JspVmgQIIF7OJfMfwAXNZvfOUp7HBptamao81s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Wakabayashi , Trond Myklebust , Sasha Levin Subject: [PATCH 5.4 100/149] NFSv4: Initialise connection to the server in nfs4_alloc_client() Date: Mon, 19 Jul 2021 16:53:28 +0200 Message-Id: <20210719144925.083812186@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144901.370365147@linuxfoundation.org> References: <20210719144901.370365147@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Trond Myklebust [ Upstream commit dd99e9f98fbf423ff6d365b37a98e8879170f17c ] Set up the connection to the NFSv4 server in nfs4_alloc_client(), before we've added the struct nfs_client to the net-namespace's nfs_client_list so that a downed server won't cause other mounts to hang in the trunking detection code. Reported-by: Michael Wakabayashi Fixes: 5c6e5b60aae4 ("NFS: Fix an Oops in the pNFS files and flexfiles connection setup to the DS") Signed-off-by: Trond Myklebust Signed-off-by: Sasha Levin --- fs/nfs/nfs4client.c | 82 +++++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 40 deletions(-) diff --git a/fs/nfs/nfs4client.c b/fs/nfs/nfs4client.c index 5a69dbd01a6c..8cace8350fa3 100644 --- a/fs/nfs/nfs4client.c +++ b/fs/nfs/nfs4client.c @@ -197,8 +197,11 @@ void nfs40_shutdown_client(struct nfs_client *clp) struct nfs_client *nfs4_alloc_client(const struct nfs_client_initdata *cl_init) { - int err; + char buf[INET6_ADDRSTRLEN + 1]; + const char *ip_addr = cl_init->ip_addr; struct nfs_client *clp = nfs_alloc_client(cl_init); + int err; + if (IS_ERR(clp)) return clp; @@ -222,6 +225,44 @@ struct nfs_client *nfs4_alloc_client(const struct nfs_client_initdata *cl_init) init_waitqueue_head(&clp->cl_lock_waitq); #endif INIT_LIST_HEAD(&clp->pending_cb_stateids); + + if (cl_init->minorversion != 0) + __set_bit(NFS_CS_INFINITE_SLOTS, &clp->cl_flags); + __set_bit(NFS_CS_DISCRTRY, &clp->cl_flags); + __set_bit(NFS_CS_NO_RETRANS_TIMEOUT, &clp->cl_flags); + + /* + * Set up the connection to the server before we add add to the + * global list. + */ + err = nfs_create_rpc_client(clp, cl_init, RPC_AUTH_GSS_KRB5I); + if (err == -EINVAL) + err = nfs_create_rpc_client(clp, cl_init, RPC_AUTH_UNIX); + if (err < 0) + goto error; + + /* If no clientaddr= option was specified, find a usable cb address */ + if (ip_addr == NULL) { + struct sockaddr_storage cb_addr; + struct sockaddr *sap = (struct sockaddr *)&cb_addr; + + err = rpc_localaddr(clp->cl_rpcclient, sap, sizeof(cb_addr)); + if (err < 0) + goto error; + err = rpc_ntop(sap, buf, sizeof(buf)); + if (err < 0) + goto error; + ip_addr = (const char *)buf; + } + strlcpy(clp->cl_ipaddr, ip_addr, sizeof(clp->cl_ipaddr)); + + err = nfs_idmap_new(clp); + if (err < 0) { + dprintk("%s: failed to create idmapper. Error = %d\n", + __func__, err); + goto error; + } + __set_bit(NFS_CS_IDMAP, &clp->cl_res_state); return clp; error: @@ -372,8 +413,6 @@ static int nfs4_init_client_minor_version(struct nfs_client *clp) struct nfs_client *nfs4_init_client(struct nfs_client *clp, const struct nfs_client_initdata *cl_init) { - char buf[INET6_ADDRSTRLEN + 1]; - const char *ip_addr = cl_init->ip_addr; struct nfs_client *old; int error; @@ -381,43 +420,6 @@ struct nfs_client *nfs4_init_client(struct nfs_client *clp, /* the client is initialised already */ return clp; - /* Check NFS protocol revision and initialize RPC op vector */ - clp->rpc_ops = &nfs_v4_clientops; - - if (clp->cl_minorversion != 0) - __set_bit(NFS_CS_INFINITE_SLOTS, &clp->cl_flags); - __set_bit(NFS_CS_DISCRTRY, &clp->cl_flags); - __set_bit(NFS_CS_NO_RETRANS_TIMEOUT, &clp->cl_flags); - - error = nfs_create_rpc_client(clp, cl_init, RPC_AUTH_GSS_KRB5I); - if (error == -EINVAL) - error = nfs_create_rpc_client(clp, cl_init, RPC_AUTH_UNIX); - if (error < 0) - goto error; - - /* If no clientaddr= option was specified, find a usable cb address */ - if (ip_addr == NULL) { - struct sockaddr_storage cb_addr; - struct sockaddr *sap = (struct sockaddr *)&cb_addr; - - error = rpc_localaddr(clp->cl_rpcclient, sap, sizeof(cb_addr)); - if (error < 0) - goto error; - error = rpc_ntop(sap, buf, sizeof(buf)); - if (error < 0) - goto error; - ip_addr = (const char *)buf; - } - strlcpy(clp->cl_ipaddr, ip_addr, sizeof(clp->cl_ipaddr)); - - error = nfs_idmap_new(clp); - if (error < 0) { - dprintk("%s: failed to create idmapper. Error = %d\n", - __func__, error); - goto error; - } - __set_bit(NFS_CS_IDMAP, &clp->cl_res_state); - error = nfs4_init_client_minor_version(clp); if (error < 0) goto error; -- 2.30.2