Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp237321rdb; Thu, 16 Nov 2023 18:22:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IGXePn50roheUVGux9CHeSAlWav/kowN2ON+wvSh3tNswynJIl48EilCNkUUs+48RG1C7gu X-Received: by 2002:a05:6a21:a59a:b0:16a:4f24:d30 with SMTP id gd26-20020a056a21a59a00b0016a4f240d30mr23235967pzc.53.1700187745692; Thu, 16 Nov 2023 18:22:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700187745; cv=none; d=google.com; s=arc-20160816; b=eHuqeiK+Ilwak2+DErAvisN3P5T3KCvtgpfGLJH3ktZznZ96Zm2LJXPu0jGUsxngHv b4qkVfklhQnt6UL9VJ5NKtopuqV8/4r4YvUH3LhS5KjaOw1x3ptsaM32k0kKvgM4e5qw WJz3XqEVIw/Jen4K3UCMV3wM/BKzKwLZ0LcwsLvyxuXrKQrkWf8ngbyE16PIEt+UIofY iaGXCn2OB72tdaMAXoGMOt+hcmuUCcg0/iWSIXaSQ5FcmWFNrI7PO5a12gpLVzYaDS33 fKn9POwkbvOZMyo4HJYWzrAimL9ExOpp/PwLqOBPTa6g+013gCKzC3go5DgKaVhKh9Ne Y0nw== 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=ePz2YWWBfI9gFbV1HaDPnXTDJsc4vTUzvAt6khvVR2M=; fh=oGCWKUgN5rqvEqhxhGaFnCKhx0upqxg87fHnuYmJPFg=; b=BuXas3TwP+xx3b1o7sISwXIqDLk4aNGRl/Hl1owjgdaLSkvnpHFTWMIMRIVU3ADLV4 VgYBClRuN2xYyZPshp31SVxN4D7CdAB7s7zuLB3LpCg7Qo6Cc20Lmsf8c+5k12oQMUAp +HqoeZYYBqDIEmWSlCAtOR1q139hpuors6VC8MDmjp0wPIG2xK1RosyYQqPDFDJxveWP gQSA2uAXds8kWSkE/30h/g97kYqs8r+U+YQKHWabL5rKof/XB5opVAKW194QDtFxeX1X Mf2OlVS2e+i7iZOoKD7JVakfhCcWyDUI0+VEjKqEmDgDMOmN1VVptuViuC+LLT/foUYI 0RRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=YEp2E9BP; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=O5KmP3qR; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id p1-20020a056a000b4100b006bedd373293si934996pfo.303.2023.11.16.18.22.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 18:22:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=YEp2E9BP; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=O5KmP3qR; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id B689182164C3; Thu, 16 Nov 2023 18:22:24 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229809AbjKQCWU (ORCPT + 99 others); Thu, 16 Nov 2023 21:22:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229437AbjKQCWT (ORCPT ); Thu, 16 Nov 2023 21:22:19 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1760CE for ; Thu, 16 Nov 2023 18:22:15 -0800 (PST) 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-out2.suse.de (Postfix) with ESMTPS id 9A8711F8C2; Fri, 17 Nov 2023 02:22:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1700187734; 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=ePz2YWWBfI9gFbV1HaDPnXTDJsc4vTUzvAt6khvVR2M=; b=YEp2E9BPD+H1mQ0cz7vTDfMry/UmT4/OZA1t2c4DkWEo3QSFL9TXshrHVGupLL2DgKkbRb 6v77hFR2kGrRQu54LZYql0i/p8quJbRkB5gpXe8DRJ3S/9q4ZkaVfSoiR6fhrxGlq6mtI2 X2cy0CrxczSksJo9yAvMp+nPICOhwgI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1700187734; 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=ePz2YWWBfI9gFbV1HaDPnXTDJsc4vTUzvAt6khvVR2M=; b=O5KmP3qR+jGL6JMI7hTGABc50Z50ZrKmHeO/vDjzPS2Ant/xRJi2w/hiEOxYdRueP2XNiF jMwvJ5Sha/OXKRCw== 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 985861341F; Fri, 17 Nov 2023 02:22:12 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id bBjbE1TOVmVhEwAAMHmgww (envelope-from ); Fri, 17 Nov 2023 02:22:12 +0000 From: NeilBrown To: Chuck Lever , Jeff Layton Cc: linux-nfs@vger.kernel.org, Olga Kornievskaia , Dai Ngo , Tom Talpey Subject: [PATCH 7/9] nfsd: allow lock state ids to be revoked and then freed Date: Fri, 17 Nov 2023 13:18:53 +1100 Message-ID: <20231117022121.23310-8-neilb@suse.de> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231117022121.23310-1-neilb@suse.de> References: <20231117022121.23310-1-neilb@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Authentication-Results: smtp-out2.suse.de; none X-Spam-Score: 3.70 X-Spamd-Result: default: False [3.70 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; RCPT_COUNT_FIVE(0.00)[6]; NEURAL_HAM_LONG(-1.00)[-1.000]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MID_CONTAINS_FROM(1.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-0.01)[45.00%] X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, 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 lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Thu, 16 Nov 2023 18:22:24 -0800 (PST) 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 | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 8a1b8376ff08..9fec3bf69d31 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 int 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,36 @@ 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); + spin_lock(&clp->cl_lock); + if (stid->sc_status == 0) { + struct nfs4_lockowner *lo = + lockowner(stp->st_stateowner); + struct nfsd_file *nf; + + stid->sc_status |= + NFS4_STID_ADMIN_REVOKED; + atomic_inc(&clp->cl_admin_revoked); + spin_unlock(&clp->cl_lock); + 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); + } else + spin_unlock(&clp->cl_lock); + mutex_unlock(&stp->st_mutex); + break; } nfs4_put_stid(stid); spin_lock(&nn->client_lock); @@ -4661,8 +4689,18 @@ 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; + LIST_HEAD(reaplist); + struct nfs4_ol_stateid *stp; + bool unhashed; switch (s->sc_type) { + case NFS4_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