Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1087274lqe; Sun, 7 Apr 2024 19:12:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV8puTxISYB0cXaC01mERGCudc+efcu/SJQfGJ2Tkmv92mLXMl6XOVPaR+SKcbHxHa+35XmDM7fS1pKSLlerhHZUL7dokvY2DXD2bMOnQ== X-Google-Smtp-Source: AGHT+IHLCiZpEf4U1Ccc7UCa8jEnYtgbS/7+0AbI4J2jFX2P5AhFTxOkq6j6vavCenbtG1oG2Jom X-Received: by 2002:a05:6830:1442:b0:6ea:ab3:5c1e with SMTP id w2-20020a056830144200b006ea0ab35c1emr4706351otp.29.1712542351579; Sun, 07 Apr 2024 19:12:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712542351; cv=pass; d=google.com; s=arc-20160816; b=loo361072goQcmOmKcU1P27wayhdvcLg9zyciNsylbdEgmyrsBTZCcnd12F9Ado/gG kep02yhIfXXtQTlVdob0+Jm0FJa5qlGQVPvDJeoT7v2qEOLPEjt/hA/mWtv34X6eDcjG Iq76hUD0HclCwHgJyejNJN1AdGD3DqIWcnnZhlx3oOGcUrEWZFRakkcMHkbC/jbLR4vG cZvxwi3mJ/HAx6GBR3Ydf+znpf9wzOdFcZEjVWnHHHbWpVM/ADvEFESHD7unfWpZ4R4B Fhu5azcYCv/wJpJitLApksJ/Hw1VEGEzbyv1HFRbIrAE8lJ+8pypODem6lkCK1JJCos8 ooNA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:dkim-signature :dkim-signature:dkim-signature; bh=ZT3M4fHTfEoy4mWAzP1BvGtZHy8GyDxkQmr2ry0lsuY=; fh=oGCWKUgN5rqvEqhxhGaFnCKhx0upqxg87fHnuYmJPFg=; b=JemTdQ4vencCRsOvywTSgSvJLGXFC3FcBHLimxHYw3YAOX5Y6P1GhaXvdlvz7Z3uYu Y4vibjopm7L2nw0gQnIn/Mk2U6ba8FUPVesdHZkNfTHqENKQs0FiGiwew8IuCgbv1u3X 0QFj9ZZ68ijKQZyWdRTkLhSHJpMdU2RTwEv/cinPSFJpK/PhY4QXhE3dHjudrvS7wEyH TQMHqMWK0XC9yjjNTMOiW3MxIiUXiiZB64TgTOxAomcA2+CJ3xKrLHPwLhJwN9nZ0zdG peDYF5Vl46XeYTUwcz/4mBIyhFpw1H3vgYLc33TYzzHxEWkO+Iyc0R1rPg6zD2Glnbqs DaZQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=RoYV4C9T; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=IGb+1q9G; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-nfs+bounces-2707-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-nfs+bounces-2707-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id i5-20020a639d05000000b005d8e3c86163si5450336pgd.142.2024.04.07.19.12.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Apr 2024 19:12:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs+bounces-2707-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=RoYV4C9T; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=IGb+1q9G; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.de dkim=pass dkdomain=suse.de dkim=pass dkdomain=suse.de dmarc=pass fromdomain=suse.de); spf=pass (google.com: domain of linux-nfs+bounces-2707-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-nfs+bounces-2707-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 125F2281746 for ; Mon, 8 Apr 2024 02:12:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5207915C9; Mon, 8 Apr 2024 02:12:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="RoYV4C9T"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="HPH1UEox"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="IGb+1q9G"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="0Tg7aFzC" X-Original-To: linux-nfs@vger.kernel.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F1321366 for ; Mon, 8 Apr 2024 02:12:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712542346; cv=none; b=FiyLr8mxFq6zWN0bo0bJKQteDkZGqMaOGgcZoYt3jVL/B6VdV/w/1Ovi5vSPbethDQfZ12VZMAtFJKwCxQn5OuSdg2yJYmoJVTlinpbxeGNKHEZzphe8nZG0ZVwHxaPAnMS/04rW8hWDoGxiUj8Z3qoaxYT8fWg1dD3/Uxwz16U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712542346; c=relaxed/simple; bh=F8hQ3mxPOf2ZPs1CsPthYzXcWB5eY3htAOdGnmzm0KI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C38NhgdmqmuyCUsk78vtM6z9Bjs8hsaQyKQCwQMt/tFU2FE6P3ObyhW8BcoOoXki8XmM9NbVCQcnN6SN/L2hmXYumrKiqFWiC9TQFh1z/fhSjlljXKXpY7A9C20cmZl4Y0r1RKWF9jm887bN1Lti8Nj12c+Kpk7T7/mI+cmvqE4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=RoYV4C9T; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=HPH1UEox; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=IGb+1q9G; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=0Tg7aFzC; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id CB2E3200A7; Mon, 8 Apr 2024 02:12:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1712542337; 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=ZT3M4fHTfEoy4mWAzP1BvGtZHy8GyDxkQmr2ry0lsuY=; b=RoYV4C9TUtQKovh/1SeqC/AaUvlzSLwVyFtxFItSK1u4ZcW0tbuspZmVxRlOk7xa6yJWSo z9jEkzJmiNLCiJfXgWast6gaNs9LTygi7/EI0PdetU2Tn8AVWU9yTkArTGIMU6rbk4eg+a dZ657rRxYzZ9LggHuRVBuOCuRBOXeYY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1712542337; 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=ZT3M4fHTfEoy4mWAzP1BvGtZHy8GyDxkQmr2ry0lsuY=; b=HPH1UEoxx6ZmExHMJbF17K8GnbEuQpM4ByHMmZwh7NrOVQIdih2gziaWAia1H4g1mS9vUR 02JvTNS6x/s9rxCg== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1712542335; 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=ZT3M4fHTfEoy4mWAzP1BvGtZHy8GyDxkQmr2ry0lsuY=; b=IGb+1q9GoH8tJDp2qR3WpQeCmcIgDxHOFHL6KksRJcRljdY89xnAR6GvVD9QDl+qR6HFCt xgiUa1XtHR+qKCIdDsf4MKw9tTs7reKv/UTobP295i+onsQ+cf9DhEg5EMDP5zg7846g7x J52IGFy8x4yFYTfVey0Dv4sEVKCuE6Q= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1712542335; 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=ZT3M4fHTfEoy4mWAzP1BvGtZHy8GyDxkQmr2ry0lsuY=; b=0Tg7aFzCIurK/tmuKwWS/CppP4iosxZHcQC9Kf1vK9aQCvypWgd6zForH3VoWi6/B0JiIb Sfy5E4ZmqLkKx+Bg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 3296F13796; Mon, 8 Apr 2024 02:12:12 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id SC7YMXxSE2b0EQAAD6G6ig (envelope-from ); Mon, 08 Apr 2024 02:12:12 +0000 From: NeilBrown To: Chuck Lever , Jeff Layton Cc: linux-nfs@vger.kernel.org, Olga Kornievskaia , Dai Ngo , Tom Talpey Subject: [PATCH 1/4] nfsd: perform all find_openstateowner_str calls in the one place. Date: Mon, 8 Apr 2024 12:09:15 +1000 Message-ID: <20240408021156.6104-2-neilb@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240408021156.6104-1-neilb@suse.de> References: <20240408021156.6104-1-neilb@suse.de> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Flag: NO X-Spam-Score: -2.80 X-Spam-Level: X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_FIVE(0.00)[6]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns]; RCVD_TLS_ALL(0.00)[] Currently find_openstateowner_str look ups are done both in nfsd4_process_open1() and alloc_init_open_stateowner() - the latter possibly being a surprise based on its name. It would be easier to follow, and more conformant to common patterns, if the lookup was all in the one place. So replace alloc_init_open_stateowner() with find_or_alloc_open_stateowner() and use the latter in nfsd4_process_open1() without any calls to find_openstateowner_str(). This means all finds are find_openstateowner_str_locked() and find_openstateowner_str() is no longer needed. So discard find_openstateowner_str() and rename find_openstateowner_str_locked() to find_openstateowner_str(). Reviewed-by: Jeff Layton Signed-off-by: NeilBrown --- fs/nfsd/nfs4state.c | 93 +++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 53 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 1824a30e7dd4..6ac1dff29d42 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -541,7 +541,7 @@ same_owner_str(struct nfs4_stateowner *sop, struct xdr_netobj *owner) } static struct nfs4_openowner * -find_openstateowner_str_locked(unsigned int hashval, struct nfsd4_open *open, +find_openstateowner_str(unsigned int hashval, struct nfsd4_open *open, struct nfs4_client *clp) { struct nfs4_stateowner *so; @@ -558,18 +558,6 @@ find_openstateowner_str_locked(unsigned int hashval, struct nfsd4_open *open, return NULL; } -static struct nfs4_openowner * -find_openstateowner_str(unsigned int hashval, struct nfsd4_open *open, - struct nfs4_client *clp) -{ - struct nfs4_openowner *oo; - - spin_lock(&clp->cl_lock); - oo = find_openstateowner_str_locked(hashval, open, clp); - spin_unlock(&clp->cl_lock); - return oo; -} - static inline u32 opaque_hashval(const void *ptr, int nbytes) { @@ -4880,34 +4868,46 @@ nfsd4_find_and_lock_existing_open(struct nfs4_file *fp, struct nfsd4_open *open) } static struct nfs4_openowner * -alloc_init_open_stateowner(unsigned int strhashval, struct nfsd4_open *open, - struct nfsd4_compound_state *cstate) +find_or_alloc_open_stateowner(unsigned int strhashval, struct nfsd4_open *open, + struct nfsd4_compound_state *cstate) { struct nfs4_client *clp = cstate->clp; - struct nfs4_openowner *oo, *ret; + struct nfs4_openowner *oo, *new = NULL; - oo = alloc_stateowner(openowner_slab, &open->op_owner, clp); - if (!oo) - return NULL; - oo->oo_owner.so_ops = &openowner_ops; - oo->oo_owner.so_is_open_owner = 1; - oo->oo_owner.so_seqid = open->op_seqid; - oo->oo_flags = 0; - if (nfsd4_has_session(cstate)) - oo->oo_flags |= NFS4_OO_CONFIRMED; - oo->oo_time = 0; - oo->oo_last_closed_stid = NULL; - INIT_LIST_HEAD(&oo->oo_close_lru); +retry: spin_lock(&clp->cl_lock); - ret = find_openstateowner_str_locked(strhashval, open, clp); - if (ret == NULL) { - hash_openowner(oo, clp, strhashval); - ret = oo; - } else - nfs4_free_stateowner(&oo->oo_owner); - + oo = find_openstateowner_str(strhashval, open, clp); + if (!oo && new) { + hash_openowner(new, clp, strhashval); + spin_unlock(&clp->cl_lock); + return new; + } spin_unlock(&clp->cl_lock); - return ret; + + if (oo && !(oo->oo_flags & NFS4_OO_CONFIRMED)) { + /* Replace unconfirmed owners without checking for replay. */ + release_openowner(oo); + oo = NULL; + } + if (oo) { + if (new) + nfs4_free_stateowner(&new->oo_owner); + return oo; + } + + new = alloc_stateowner(openowner_slab, &open->op_owner, clp); + if (!new) + return NULL; + new->oo_owner.so_ops = &openowner_ops; + new->oo_owner.so_is_open_owner = 1; + new->oo_owner.so_seqid = open->op_seqid; + new->oo_flags = 0; + if (nfsd4_has_session(cstate)) + new->oo_flags |= NFS4_OO_CONFIRMED; + new->oo_time = 0; + new->oo_last_closed_stid = NULL; + INIT_LIST_HEAD(&new->oo_close_lru); + goto retry; } static struct nfs4_ol_stateid * @@ -5356,27 +5356,14 @@ nfsd4_process_open1(struct nfsd4_compound_state *cstate, clp = cstate->clp; strhashval = ownerstr_hashval(&open->op_owner); - oo = find_openstateowner_str(strhashval, open, clp); + oo = find_or_alloc_open_stateowner(strhashval, open, cstate); open->op_openowner = oo; - if (!oo) { - goto new_owner; - } - if (!(oo->oo_flags & NFS4_OO_CONFIRMED)) { - /* Replace unconfirmed owners without checking for replay. */ - release_openowner(oo); - open->op_openowner = NULL; - goto new_owner; - } + if (!oo) + return nfserr_jukebox; status = nfsd4_check_seqid(cstate, &oo->oo_owner, open->op_seqid); if (status) return status; - goto alloc_stateid; -new_owner: - oo = alloc_init_open_stateowner(strhashval, open, cstate); - if (oo == NULL) - return nfserr_jukebox; - open->op_openowner = oo; -alloc_stateid: + open->op_stp = nfs4_alloc_open_stateid(clp); if (!open->op_stp) return nfserr_jukebox; -- 2.44.0