Received: by 2002:a05:7412:f589:b0:e2:908c:2ebd with SMTP id eh9csp612291rdb; Tue, 31 Oct 2023 18:01:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF+9eyf54v/roIQBJenV3iGSIfSjSKjFg2JXoKg7aOPxdGKb+ibfckwjrtnW1tbNdAxdsMa X-Received: by 2002:a17:903:245:b0:1ca:e05a:93a2 with SMTP id j5-20020a170903024500b001cae05a93a2mr14126410plh.32.1698800496467; Tue, 31 Oct 2023 18:01:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698800496; cv=none; d=google.com; s=arc-20160816; b=vL0PONgdRV3OiyzSWlEDbNnWdpx5UrNhLxbiNCUYZiq+L/wuONnfuLA5cMnggS/V91 auYqivOa0qxzvAW9EvElLfSKKyU9zYr0/9Z8u1tDQEXAiuqLbeAO9ks0lWSAvMDS8geG oA+VzqkBjYbVR0CjCahBtDpXYfDjVbzqcgkkgZqCCmY7qG449Z8q0ctNXVLqNDSTsiKU 3Mr9/Ye+dRmjbqg9mQC7ZeCyoj8gy6s6M/BNuJWowPXIFpItP2JKei5PB80USaL2dXaW KwD+31OnwPzp9EYCHccAbJjeInvADjPzHGwnuDbrekS7/aTcJ+aDjmXfQMKulERGnUIF npkQ== 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:cc:to:from :dkim-signature:dkim-signature; bh=Scl/o8gKJcHv4TzzDIWxdel+REbpoagEpcQ1ANoph9E=; fh=oGCWKUgN5rqvEqhxhGaFnCKhx0upqxg87fHnuYmJPFg=; b=s/v0Un4qAJRTfAA5yPZc3byDrxLOhVttjsRQ/FkvA1GVfSsnnrXppAu383I6Cv+mR8 jDLeycmkBAK2WTGvBK9OGq/hc+WPoFg6Qr4dzbKE7GwuqR6BYQke0r5vGV3MLnPEU9a6 4f8jIIAwmDYWWNwOUE3JMKkdsMpO/03393meCLe3BeMSE7PFnxzNivTIl3BLQZJ11853 DaVnryPiMbZIqIlkP84ykipbOBrDYfhpsAenznrK9n73Xzotn81VG1+yaiebbU9UN6jH L2xdDHrxPzoo8hI2B1PGOClnYHPJscgrdzckEetX5WBW6EJHTQqVCj0poK8DQZh/OBdh bLHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=riY1Cu97; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id n3-20020a170902d2c300b001c9af07788csi1884248plc.76.2023.10.31.18.01.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 18:01:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=riY1Cu97; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id BBA1F80BB22E; Tue, 31 Oct 2023 18:01:33 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376970AbjKABB2 (ORCPT + 99 others); Tue, 31 Oct 2023 21:01:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376924AbjKABB2 (ORCPT ); Tue, 31 Oct 2023 21:01:28 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C337C9 for ; Tue, 31 Oct 2023 18:01:22 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 4B00D2184F; Wed, 1 Nov 2023 01:01:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1698800481; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Scl/o8gKJcHv4TzzDIWxdel+REbpoagEpcQ1ANoph9E=; b=riY1Cu97Wofn7/Go8f2B7RJ2iiF+AzP6IkqsFUHv1SOLR6rq4pZa2EypGw1wDGocFTKaoQ FFWN+7ajBFiGPtOGgTMc5ZrNN67dwST9R/cTlbOuBLWGeQ3YB4/wqjf3mAg0XN8s09ys+b 2qtPBfw8rNUWzKHXIqn2TZKNPbTRFF0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1698800481; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Scl/o8gKJcHv4TzzDIWxdel+REbpoagEpcQ1ANoph9E=; b=vzpVLswD07dwGXjF1UQwJifvIPchgB2fcCbntKEVFhRfxGv2j4CmtkQRMNYs889wrypxot 7D72uFSJC83AKUCw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 9C5CF138EF; Wed, 1 Nov 2023 01:01:17 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 2eAoFV2jQWUQOwAAMHmgww (envelope-from ); Wed, 01 Nov 2023 01:01:17 +0000 From: NeilBrown To: Chuck Lever , Jeff Layton Cc: linux-nfs@vger.kernel.org, Olga Kornievskaia , Dai Ngo , Tom Talpey Subject: [PATCH 4/6] nfsd: allow lock state ids to be revoked and then freed Date: Wed, 1 Nov 2023 11:57:11 +1100 Message-ID: <20231101010049.27315-5-neilb@suse.de> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231101010049.27315-1-neilb@suse.de> References: <20231101010049.27315-1-neilb@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.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 (groat.vger.email [0.0.0.0]); Tue, 31 Oct 2023 18:01:34 -0700 (PDT) Revoking state through 'unlock_filesystem' now revokes any lock states found. When the stateids are then freed by the client, the revoked stateids will be cleaned up correctly. Signed-off-by: NeilBrown --- fs/nfsd/nfs4state.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 13484a9cef21..c2e064f6c7c4 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -1708,7 +1708,7 @@ void nfsd4_revoke_states(struct net *net, struct super_block *sb) unsigned int idhashval; unsigned short sc_types; - sc_types = 0; + sc_types = NFS4_LOCK_STID; spin_lock(&nn->client_lock); for (idhashval = 0; idhashval < CLIENT_HASH_MASK; idhashval++) { @@ -1719,8 +1719,33 @@ void nfsd4_revoke_states(struct net *net, struct super_block *sb) struct nfs4_stid *stid = find_one_sb_stid(clp, sb, sc_types); if (stid) { + struct nfs4_ol_stateid *stp; + spin_unlock(&nn->client_lock); switch (stid->sc_type) { + case NFS4_LOCK_STID: + stp = openlockstateid(stid); + mutex_lock_nested(&stp->st_mutex, + LOCK_STATEID_MUTEX); + if (stid->sc_type == NFS4_LOCK_STID) { + struct nfs4_lockowner *lo = + lockowner(stp->st_stateowner); + struct nfsd_file *nf; + + nf = find_any_file(stp->st_stid.sc_file); + if (nf) { + get_file(nf->nf_file); + filp_close(nf->nf_file, + (fl_owner_t)lo); + nfsd_file_put(nf); + } + release_all_access(stp); + stid->sc_type = + NFS4_ADMIN_REVOKED_LOCK_STID; + atomic_inc(&clp->cl_admin_revoked); + } + mutex_unlock(&stp->st_mutex); + break; } nfs4_put_stid(stid); spin_lock(&nn->client_lock); @@ -4656,8 +4681,17 @@ nfsd4_find_existing_open(struct nfs4_file *fp, struct nfsd4_open *open) static void nfsd_drop_revoked_stid(struct nfs4_stid *s) { struct nfs4_client *cl = s->sc_client; + struct nfs4_ol_stateid *stp; + bool unhashed; switch (s->sc_type) { + case NFS4_ADMIN_REVOKED_LOCK_STID: + stp = openlockstateid(s); + unhashed = unhash_lock_stateid(stp); + spin_unlock(&cl->cl_lock); + if (unhashed) + nfs4_put_stid(s); + break; default: spin_unlock(&cl->cl_lock); } -- 2.42.0