Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1311379pxb; Fri, 1 Apr 2022 09:53:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKdZ+41IZhGKluQNnR8nhT9MrI7vhQe6V9E82DnY9Z7sTSt0xpP7LWCH0Z9pM1oekGvWrX X-Received: by 2002:a63:1849:0:b0:37c:9ad9:6897 with SMTP id 9-20020a631849000000b0037c9ad96897mr15678233pgy.362.1648832032954; Fri, 01 Apr 2022 09:53:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648832032; cv=none; d=google.com; s=arc-20160816; b=oxBq9oUqe/sBfkwKCOoDUhsqV9TvJ1WoylCKRinooC3C6i+ZddWAFoiAxJKdsSxeVw NFVcMl41OzS29mVNxtnaHJzNV1oISuMpwrq7HeiGYMUdN4tsPcNaI62i3/OiVowEoBav W7TxykdZEutcmK+2mLTF8PiS5J1RaPi7Fix/xYntj2ZVmqSNkoMz/lxK6zUzTjeOQT+2 U9USCemahr/OY5KhnX+DhE+1GE5/LhxQLC9/vvruf4KbSn+kO8rsOm7isqsXWYJWokqo TFnparpxjrNpVN0acHKH06jqkvkl/wq7n1FtwSuEwvaR3J624RWXEug84bXakn9SvtTM UfbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:dkim-filter; bh=4l3wlpIs4kNvRReXOBmDIJ2f7a/O4+gaNwKWu3ut688=; b=Uqr2NNPUfHAlweR5uLnBiOc1QA8uBkCCDeN/NZ4OTytUTxdIBHDXCGYKXd4sY3fwwz 3wihOylG9vKhyvQX5c4ds2Ue9SkMzVaDlqnIMKklX7vicgPLOI7cgw/dv+wPIZ0YXQYo Z78w8sCiFSkB3LDwgs/cUiTgU+b9gqcgfSara33xi977tv97xCQYKdFj8Qyl98mlRGqm xcF0F8MrlJw9DWsnl1dLvoC11+7Lt7/5BBr7C42ZyKeGOsNFQyTp9UwRulmHtHj1soT5 Lb/yOG75vq2Y0IUDbqwY61YrhIOjAUZ2hcmAB1kVolCL5q0KWdozwBHux65toWvGYQgE Lraw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fieldses.org header.s=default header.b=galmP6du; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v15-20020a1709028d8f00b00153b2d1651asi2580171plo.290.2022.04.01.09.53.24; Fri, 01 Apr 2022 09:53:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@fieldses.org header.s=default header.b=galmP6du; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349236AbiDAP5j (ORCPT + 99 others); Fri, 1 Apr 2022 11:57:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358345AbiDAPqd (ORCPT ); Fri, 1 Apr 2022 11:46:33 -0400 Received: from fieldses.org (fieldses.org [IPv6:2600:3c00:e000:2f7::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D21B1D2041; Fri, 1 Apr 2022 08:21:10 -0700 (PDT) Received: by fieldses.org (Postfix, from userid 2815) id 4FABA2935; Fri, 1 Apr 2022 11:21:09 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.11.0 fieldses.org 4FABA2935 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fieldses.org; s=default; t=1648826469; bh=4l3wlpIs4kNvRReXOBmDIJ2f7a/O4+gaNwKWu3ut688=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=galmP6duQKF5oiJQ1aRbMUar5ztI/u16FU8KQfPppgE8sct8iqbIPnsQqVzPwqlzu nF5j8gH04DjSYf4X4FiOI54u7yUevYwTiBTCLMYI1NaaVWY21TbvOCH0E5rpfX+3re Fhlcp4NLX4vn6jHOT5YNo8X8djsdPofS35PasJJc= Date: Fri, 1 Apr 2022 11:21:09 -0400 From: "J. Bruce Fields" To: Dai Ngo Cc: chuck.lever@oracle.com, jlayton@redhat.com, viro@zeniv.linux.org.uk, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH RFC v19 06/11] NFSD: Update find_clp_in_name_tree() to handle courtesy client Message-ID: <20220401152109.GB18534@fieldses.org> References: <1648742529-28551-1-git-send-email-dai.ngo@oracle.com> <1648742529-28551-7-git-send-email-dai.ngo@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1648742529-28551-7-git-send-email-dai.ngo@oracle.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org On Thu, Mar 31, 2022 at 09:02:04AM -0700, Dai Ngo wrote: > Update find_clp_in_name_tree to check and expire courtesy client. > > Update find_confirmed_client_by_name to discard the courtesy > client by setting CLIENT_EXPIRED. > > Update nfsd4_setclientid to expire client with CLIENT_EXPIRED > state to prevent multiple confirmed clients with the same name > on the conf_name_tree. > > Signed-off-by: Dai Ngo > --- > fs/nfsd/nfs4state.c | 27 ++++++++++++++++++++++++--- > fs/nfsd/state.h | 22 ++++++++++++++++++++++ > 2 files changed, 46 insertions(+), 3 deletions(-) > > diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c > index fe8969ba94b3..eadce5d19473 100644 > --- a/fs/nfsd/nfs4state.c > +++ b/fs/nfsd/nfs4state.c > @@ -2893,8 +2893,11 @@ find_clp_in_name_tree(struct xdr_netobj *name, struct rb_root *root) > node = node->rb_left; > else if (cmp < 0) > node = node->rb_right; > - else > + else { > + if (nfsd4_courtesy_clnt_expired(clp)) > + return NULL; > return clp; > + } > } > return NULL; > } > @@ -2973,8 +2976,15 @@ static bool clp_used_exchangeid(struct nfs4_client *clp) > static struct nfs4_client * > find_confirmed_client_by_name(struct xdr_netobj *name, struct nfsd_net *nn) > { > + struct nfs4_client *clp; > + > lockdep_assert_held(&nn->client_lock); > - return find_clp_in_name_tree(name, &nn->conf_name_tree); > + clp = find_clp_in_name_tree(name, &nn->conf_name_tree); > + if (clp && clp->cl_cs_client_state == NFSD4_CLIENT_RECONNECTED) { > + nfsd4_discard_courtesy_clnt(clp); > + clp = NULL; > + } > + return clp; > } > .... > +static inline void > +nfsd4_discard_courtesy_clnt(struct nfs4_client *clp) > +{ > + spin_lock(&clp->cl_cs_lock); > + clp->cl_cs_client_state = NFSD4_CLIENT_EXPIRED; > + spin_unlock(&clp->cl_cs_lock); > +} This is a red flag to me.... What guarantees that the condition we just checked (cl_cs_client_state == NFSD4_CLIENT_RECONNECTED) is still true here? Why couldn't another thread have raced in and called reactivate_courtesy_client? Should we be holding cl_cs_lock across both the cl_cs_client_state and the assignment? Or should reactivate_courtesy_client be taking the client_lock? I'm still not clear on the need for the CLIENT_RECONNECTED state. I think analysis would be a bit simpler if the only states were ACTIVE, COURTESY, and EXPIRED, the only transitions possible were ACTIVE->COURTESY->{EXPIRED or ACTIVE} and the same lock ensured that those were the only possible transitions. (And to be honest I'd still prefer the original approach where we expire clients from the posix locking code and then retry. It handles an additional case (the one where reboot happens after a long network partition), and I don't think it requires adding these new client states....) --b.