Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1140759rdh; Mon, 25 Sep 2023 04:42:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFWKby32+9nvmi/4FcL7icPXmAVeYqd2v1sDH9SrHXlQ/3n1XDxwiDhzzG0lM5qrb/hWNgA X-Received: by 2002:a05:6a20:3d8f:b0:15a:7d2:a418 with SMTP id s15-20020a056a203d8f00b0015a07d2a418mr10049187pzi.19.1695642150433; Mon, 25 Sep 2023 04:42:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695642150; cv=none; d=google.com; s=arc-20160816; b=eRu66T+AXyce0sXB21Zs/XCLZGdphHjznvg0jRWm6s4sOBLQSltE7qUJiMru0kj/6G x15IPOozFzBt2AJOLMMXm63d8EV+UwKSGygDmZ40H77Bsat//qPI3EK/orAZvEAZ4bB/ Xp1RmyxWsIMVjqj3OspR0UpV9NqMRTLGXKJfdHCA/PNIJdQg7ga+HpWgZwzm4X4QzajB gn0WkRLiasVakR3BLxJDnhbwL4ccyBUrr16q/75G3w2d6+hPUAcCvSzL2Z3oz+d1zSm3 nZhOoYE+FUZdliYvOc3jXBOxmkGvXeTkZUFpB30GJHp9T0Qqr/DR+mllEmoKgjoEtWG8 GhEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=7KDeZdQbK+bgK1kAOsHfQ3IBcopmDW+JxKAmwSQlwdY=; fh=P/+DU0UUmrPt338t6+6SSS0W3ag+o2v1S/uriyG0A7Y=; b=ILYld6DZd5CrKsa2WwTwarQ4yKXp2nOjxsP+OasvY7PxT9Dc6ylMATyAM4z/NCeQ8A sVKMYxk345+QzgT3yO+GYme33zG7I4OQ4VVadYEt59Au+PdiW7KOAw36NP3rARwSp14/ HglFUg+hPNQN7G4oyHRUM6CEO1ujzW4o1lMVAbnJGlE/wHaJShb+MW50iIFUSP3U+4+F u9acm8SfehuvDfGp5szLI71lCRwoL9OxnS21H04xLa63jy0pst2InlJlAb37hcj1CabB FhHmU9XEAeAuKBza5/Aa+SNEfpNDYr2yGHQ9nEmczAVJznRoKk3Pie/tPR/wv8N0a4MP iMKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="jDi5/6dz"; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id s26-20020a056a00179a00b0068ffeb6a949si10490995pfg.73.2023.09.25.04.42.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 04:42:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="jDi5/6dz"; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 8BED080765D7; Mon, 25 Sep 2023 04:41:25 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229537AbjIYLlT (ORCPT + 99 others); Mon, 25 Sep 2023 07:41:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229449AbjIYLlT (ORCPT ); Mon, 25 Sep 2023 07:41:19 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7FA5DF for ; Mon, 25 Sep 2023 04:41:12 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D5C9EC433C8; Mon, 25 Sep 2023 11:41:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695642072; bh=pwKKr9wZ0WLihtz2SXvQsIjojN6HnaAZ6z9uqP/9hjg=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=jDi5/6dzh4WYvI3z1Vs0jawYwslu37v+wjt89oCTJzEXzblBZ+TtfoDsQlvpHwNcb 2vEIWWHcNhOs0KfQj/FLWypfp7atgLfDTlR/CRgPn6KAQZvYymKXO73EXbfdH8i6g2 0AgXdaTDXGJCYstuBELgMesK8qnRqteb2jzXQbkMOcbo6lQjddD4h1VGxGORAqlxHD bcIssi6dcj+HVLj+6lrWdu3iCFk+/bpCaqkC8To+uQSFAkYxcGB7IIE8UC2VKgfw1G IMiezqB0XdCUeASmag8pBEzDtPWYukLXoNRP2zdPdDZxsxwVfS/O7uqXczMh5buNwd s2ZcZd+octnFg== Message-ID: Subject: Re: [PATCH nfsd-next] NFSD: simplify error paths in nfsd_svc() From: Jeff Layton To: NeilBrown , Chuck Lever Cc: Olga Kornievskaia , Dai Ngo , Tom Talpey , Linux NFS list Date: Mon, 25 Sep 2023 07:41:10 -0400 In-Reply-To: <169561203735.19404.6014131036692240448@noble.neil.brown.name> References: <169561203735.19404.6014131036692240448@noble.neil.brown.name> Content-Type: text/plain; charset="ISO-8859-15" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.4 (3.48.4-1.fc38) MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Mon, 25 Sep 2023 04:41:25 -0700 (PDT) On Mon, 2023-09-25 at 12:06 +1000, NeilBrown wrote: > The error paths in nfsd_svc() are needlessly complex and can result in a > final call to svc_put() without nfsd_last_thread() being called. This > results in the listening sockets not being closed properly. >=20 > The per-netns setup provided by nfsd_startup_new() and removed by > nfsd_shutdown_net() is needed precisely when there are running threads. > So we don't need nfsd_up_before. We don't need to know if it *was* up. > We only need to know if any threads are left. If none are, then we must > call nfsd_shutdown_net(). But we don't need to do that explicitly as > nfsd_last_thread() does that for us. >=20 > So simply call nfsd_last_thread() before the last svc_put() if there are > no running threads. That will always do the right thing. >=20 > Also discard: > pr_info("nfsd: last server has exited, flushing export cache\n"); > It may not be true if an attempt to start the first server failed, and > it isn't particularly helpful and it simply reports normal behaviour. >=20 Thanks. Removing that is long overdue. > Signed-off-by: NeilBrown > --- > fs/nfsd/nfssvc.c | 14 ++++---------- > 1 file changed, 4 insertions(+), 10 deletions(-) >=20 > diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c > index c5890cdfe97b..d6122bb2d167 100644 > --- a/fs/nfsd/nfssvc.c > +++ b/fs/nfsd/nfssvc.c > @@ -572,7 +572,6 @@ static void nfsd_last_thread(struct net *net) > return; > =20 > nfsd_shutdown_net(net); > - pr_info("nfsd: last server has exited, flushing export cache\n"); > nfsd_export_flush(net); > } > =20 > @@ -786,7 +785,6 @@ int > nfsd_svc(int nrservs, struct net *net, const struct cred *cred) > { > int error; > - bool nfsd_up_before; > struct nfsd_net *nn =3D net_generic(net, nfsd_net_id); > struct svc_serv *serv; > =20 > @@ -806,8 +804,6 @@ nfsd_svc(int nrservs, struct net *net, const struct c= red *cred) > error =3D nfsd_create_serv(net); > if (error) > goto out; > - > - nfsd_up_before =3D nn->nfsd_net_up; > serv =3D nn->nfsd_serv; > =20 > error =3D nfsd_startup_net(net, cred); > @@ -815,17 +811,15 @@ nfsd_svc(int nrservs, struct net *net, const struct= cred *cred) > goto out_put; > error =3D svc_set_num_threads(serv, NULL, nrservs); > if (error) > - goto out_shutdown; > + goto out_put; > error =3D serv->sv_nrthreads; > - if (error =3D=3D 0) > - nfsd_last_thread(net); > -out_shutdown: > - if (error < 0 && !nfsd_up_before) > - nfsd_shutdown_net(net); > out_put: > /* Threads now hold service active */ > if (xchg(&nn->keep_active, 0)) > svc_put(serv); > + > + if (serv->sv_nrthreads =3D=3D 0) > + nfsd_last_thread(net); > svc_put(serv); > out: > mutex_unlock(&nfsd_mutex); Nice cleanup. Reviewed-by: Jeff Layton