From patchwork Tue Oct 1 20:33:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anna Schumaker X-Patchwork-Id: 13818732 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C7D7329A1 for ; Tue, 1 Oct 2024 20:33:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727814838; cv=none; b=mdSbVNXcmwzpiiyHhuzem5tCUpFJFG6Vf8aAveWO4d9VZWUHQ11MXCYc81y7e58hVNqWappCu2IwAtFmc+GwMwsaL2NsP/aElVBCexp9eItTEoYpwZ8YGj+kCZty5zd9Z08/2PCOcWE1frdB3iCSTHqC+MXHHOPDMhwJ5oCXazw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727814838; c=relaxed/simple; bh=BPN+CkXGShy37jfH6DzT5IFkdLaPG28FNAgrbfkcIWQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Nm708Qfxbw5QzPrY3xBeSbDDGGfuDDNytYLX6OGcJvr9G2qJReWqxLeTa8JPHY1SargVOtk6SGV37Aryo0NBecTWXcpHsPq/vGpsZuenLoLVoqPP4a7W5vDwoN8eJ5gZlpnEmFzeY4kzP8nKD9VuciaUGW5kbvt2lvSHrtgvfUM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HuHcjJp9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HuHcjJp9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0580BC4CEC6; Tue, 1 Oct 2024 20:33:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727814838; bh=BPN+CkXGShy37jfH6DzT5IFkdLaPG28FNAgrbfkcIWQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HuHcjJp94USjvYMNnhumpIqYoYQJMLwX/J7cFucmWtU1cjDuurewfxbwZ7xkFFLzE +3N1Ibb7jlr+Zb73Dadyqtu/HBdam7y2lpHL+Evf6vG8JTuuEtRv27uPIcrH+DmbYt LJYbIHVWFwT4rsNOKU/pIlz8lwldjy29sJIyeDv0cVYzmRstxCaGAIz91InLRXLkvP F4cFWdWSvkCc+2iwYzIea5nFKLo+A1R9/IqmeiX8okpUAaGYUtz/2mMMfWOlfVJTQO INi8OvjBOiF4ys245kCEM4+rU2BCHumuHUN/KNXeisSJtk+O1+cAPXDRSCCXSO4c84 E4pmc9JZ6usMQ== From: Anna Schumaker To: linux-nfs@vger.kernel.org, trond.myklebust@hammerspace.com Cc: anna@kernel.org Subject: [PATCH 1/5] NFS: Clean up locking the nfs_versions list Date: Tue, 1 Oct 2024 16:33:40 -0400 Message-ID: <20241001203344.327044-2-anna@kernel.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241001203344.327044-1-anna@kernel.org> References: <20241001203344.327044-1-anna@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Anna Schumaker This patch replaces the nfs_version_mutex and nfs_version_lock with a single RW lock that protects access to the nfs_versions list. The mutex around request_module() seemed unnecessary to me, and I couldn't find any other callers using a lock around calls to request_module() when I looked. At the same time, I saw fs/filesystems.c using a RW lock to protect their filesystems list. This seems like a better idea than a spinlock to me, so I'm also making that change while I'm here. Signed-off-by: Anna Schumaker --- fs/nfs/client.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/fs/nfs/client.c b/fs/nfs/client.c index a1d21c4be0ac..15340df117a7 100644 --- a/fs/nfs/client.c +++ b/fs/nfs/client.c @@ -55,8 +55,7 @@ #define NFSDBG_FACILITY NFSDBG_CLIENT static DECLARE_WAIT_QUEUE_HEAD(nfs_client_active_wq); -static DEFINE_SPINLOCK(nfs_version_lock); -static DEFINE_MUTEX(nfs_version_mutex); +static DEFINE_RWLOCK(nfs_version_lock); static LIST_HEAD(nfs_versions); /* @@ -79,16 +78,16 @@ const struct rpc_program nfs_program = { static struct nfs_subversion *find_nfs_version(unsigned int version) { struct nfs_subversion *nfs; - spin_lock(&nfs_version_lock); + read_lock(&nfs_version_lock); list_for_each_entry(nfs, &nfs_versions, list) { if (nfs->rpc_ops->version == version) { - spin_unlock(&nfs_version_lock); + read_unlock(&nfs_version_lock); return nfs; } } - spin_unlock(&nfs_version_lock); + read_unlock(&nfs_version_lock); return ERR_PTR(-EPROTONOSUPPORT); } @@ -97,10 +96,8 @@ struct nfs_subversion *get_nfs_version(unsigned int version) struct nfs_subversion *nfs = find_nfs_version(version); if (IS_ERR(nfs)) { - mutex_lock(&nfs_version_mutex); request_module("nfsv%d", version); nfs = find_nfs_version(version); - mutex_unlock(&nfs_version_mutex); } if (!IS_ERR(nfs) && !try_module_get(nfs->owner)) @@ -115,23 +112,23 @@ void put_nfs_version(struct nfs_subversion *nfs) void register_nfs_version(struct nfs_subversion *nfs) { - spin_lock(&nfs_version_lock); + write_lock(&nfs_version_lock); list_add(&nfs->list, &nfs_versions); nfs_version[nfs->rpc_ops->version] = nfs->rpc_vers; - spin_unlock(&nfs_version_lock); + write_unlock(&nfs_version_lock); } EXPORT_SYMBOL_GPL(register_nfs_version); void unregister_nfs_version(struct nfs_subversion *nfs) { - spin_lock(&nfs_version_lock); + write_lock(&nfs_version_lock); nfs_version[nfs->rpc_ops->version] = NULL; list_del(&nfs->list); - spin_unlock(&nfs_version_lock); + write_unlock(&nfs_version_lock); } EXPORT_SYMBOL_GPL(unregister_nfs_version); From patchwork Tue Oct 1 20:33:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anna Schumaker X-Patchwork-Id: 13818733 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC88129A1 for ; Tue, 1 Oct 2024 20:33:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727814839; cv=none; b=iVDx0P4qaVa8AITH9ClS+GIY0qpfu5poaRQYvXVPkfxjnGPnerv31229m81wXGOC4BSABAjXxUhTj6rdBEtWtJPvcexyUPDswDjqMLRcsIRpFLIeohBairrNqjL55Ks6O7eJzbdXAhFNzb/peoAVPeAGsn4TnfjXKH+F2U+USRk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727814839; c=relaxed/simple; bh=KVG+JDGwdymjA/64VP+6MuqLk+zdm+v4lYTz1BieZtY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AdKxPGLRB03/WrWa+4BOjlVpCYs44MdtIcr4wJ3qLSs82C00bg6XYL30w1Gn6skVksW/rzBAi1HS0PVB1n3dXieyoZkmP/sG7OF3VZAzNXansMfb3bXED23ApgHSIpZduBhmBO/l64OrAqghnSdnCT+9NZm8xmKKdlZTEWf7ndg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=F2jAALXz; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="F2jAALXz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 60A5EC4CEC6; Tue, 1 Oct 2024 20:33:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727814839; bh=KVG+JDGwdymjA/64VP+6MuqLk+zdm+v4lYTz1BieZtY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F2jAALXzwzjPiHKzf1TU2mZsjpe0ZE6JQxTYFx9mmWqiU+Gpa0/WDFS/Gbb8YiCKQ T+p20s0Gc/5ckxxs4+h96+P2mjQHq7/gCbzdc/FLGGIVMXeDmEfE6Z+sKt90h9V3yI i7+n51/cfsyY8YA5MlPVI0j5ijoaT4roCcM95SOWAYi5MMUd2zWi+V/nFGnpAaqx8g nUR6xAGfZVoulE4pDiam/ZLk4kvB9rgylZVaDa6vrAJWRv5XBELmvZJrWSAKt98gU1 h+rzQb5gUA/6sVS+Etqo9KtaS3FflBpkqhRzYsN2xU9xUfLIYD8Ct6OG9WOX96w6E1 6MeUFp1eW3TSg== From: Anna Schumaker To: linux-nfs@vger.kernel.org, trond.myklebust@hammerspace.com Cc: anna@kernel.org Subject: [PATCH 2/5] NFS: Convert the NFS module list into an array Date: Tue, 1 Oct 2024 16:33:41 -0400 Message-ID: <20241001203344.327044-3-anna@kernel.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241001203344.327044-1-anna@kernel.org> References: <20241001203344.327044-1-anna@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Anna Schumaker Using a linked list here seems unnecessarily complex, especially since possible index values are '2', '3', and '4'. Let's just use an array for direct access. Signed-off-by: Anna Schumaker --- fs/nfs/client.c | 26 ++++++++++++++------------ fs/nfs/nfs.h | 1 - 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/fs/nfs/client.c b/fs/nfs/client.c index 15340df117a7..f5c2be89797a 100644 --- a/fs/nfs/client.c +++ b/fs/nfs/client.c @@ -56,7 +56,12 @@ static DECLARE_WAIT_QUEUE_HEAD(nfs_client_active_wq); static DEFINE_RWLOCK(nfs_version_lock); -static LIST_HEAD(nfs_versions); + +static struct nfs_subversion *nfs_version_mods[5] = { + [2] = NULL, + [3] = NULL, + [4] = NULL, +}; /* * RPC cruft for NFS @@ -78,17 +83,14 @@ const struct rpc_program nfs_program = { static struct nfs_subversion *find_nfs_version(unsigned int version) { struct nfs_subversion *nfs; + read_lock(&nfs_version_lock); - - list_for_each_entry(nfs, &nfs_versions, list) { - if (nfs->rpc_ops->version == version) { - read_unlock(&nfs_version_lock); - return nfs; - } - } - + nfs = nfs_version_mods[version]; read_unlock(&nfs_version_lock); - return ERR_PTR(-EPROTONOSUPPORT); + + if (nfs == NULL) + return ERR_PTR(-EPROTONOSUPPORT); + return nfs; } struct nfs_subversion *get_nfs_version(unsigned int version) @@ -114,7 +116,7 @@ void register_nfs_version(struct nfs_subversion *nfs) { write_lock(&nfs_version_lock); - list_add(&nfs->list, &nfs_versions); + nfs_version_mods[nfs->rpc_ops->version] = nfs; nfs_version[nfs->rpc_ops->version] = nfs->rpc_vers; write_unlock(&nfs_version_lock); @@ -126,7 +128,7 @@ void unregister_nfs_version(struct nfs_subversion *nfs) write_lock(&nfs_version_lock); nfs_version[nfs->rpc_ops->version] = NULL; - list_del(&nfs->list); + nfs_version_mods[nfs->rpc_ops->version] = NULL; write_unlock(&nfs_version_lock); } diff --git a/fs/nfs/nfs.h b/fs/nfs/nfs.h index 0d3ce0460e35..0329fc3023d0 100644 --- a/fs/nfs/nfs.h +++ b/fs/nfs/nfs.h @@ -19,7 +19,6 @@ struct nfs_subversion { const struct nfs_rpc_ops *rpc_ops; /* NFS operations */ const struct super_operations *sops; /* NFS Super operations */ const struct xattr_handler * const *xattr; /* NFS xattr handlers */ - struct list_head list; /* List of NFS versions */ }; struct nfs_subversion *get_nfs_version(unsigned int); From patchwork Tue Oct 1 20:33:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anna Schumaker X-Patchwork-Id: 13818734 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE73229A1 for ; Tue, 1 Oct 2024 20:34:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727814840; cv=none; b=YycWkVOR/flp+0peJvOWOmqkISiCTik5GwODfwxC8Yv23o7w3AprPQ26BMf9D2d5tMuXbxO95CDxcb94de1dLEQCrX6RNmi3PrlmTjnmyWkzOjWQlNz9wzzSxahYNf4q3UYYTFWN6rnyE5LnfN1Pl7hjBSsHGrU1aelRfZOI/Vw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727814840; c=relaxed/simple; bh=cXO6Wp7k2OmhudSclTGqhq9ZHputSqedfNPyxqfq4Xg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZmP31Aq104WRyFlHPdxYvwsjmh7E3oPk/0XHDNaBU8MyT+ndYusQRN7G0HMZsR1eLojQeD9MRdpuesHVDH1u93yQ6QEttCh0PQf6TnNk4sJOInPTnQmGLTL48oqT/YmiRxrn8EkvUEp83SVZsDje8xVirKe4XSzM/4tW0QUZrBA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CV27aJEj; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CV27aJEj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB941C4CED1; Tue, 1 Oct 2024 20:33:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727814840; bh=cXO6Wp7k2OmhudSclTGqhq9ZHputSqedfNPyxqfq4Xg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CV27aJEj5dmiAasohww1VMeMLyrBI1OK2yiVp33TvUVw1giAem6pM6VEDbLS+nC/i 4Ri//yMVKA+1/pFam41fxpQUssmxO6N+37Q9OvKuMQgWdx3VtSBNxber2AXWcedKv7 6K9Y7wuzs59H+Ixh0BGtpS+qDs+aaRKlo+KGS+E8GNYBNjUaXytLvOZHAQgrJyw1Ro mrYCxbjblhHS1XEA/p9lH7GIZPD0+DhiIe/8iOXOL0vRLScOxY/2ux0qTeDKUui/br d0M6P2hq7Zra55yfYyxo8giZOKUUQRY5vE/ZlmvwiBW5y2/x/wP70ozyKWE0SmW+g6 jTu8xeP0fKLig== From: Anna Schumaker To: linux-nfs@vger.kernel.org, trond.myklebust@hammerspace.com Cc: anna@kernel.org Subject: [PATCH 3/5] NFS: Rename get_nfs_version() -> find_nfs_version() Date: Tue, 1 Oct 2024 16:33:42 -0400 Message-ID: <20241001203344.327044-4-anna@kernel.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241001203344.327044-1-anna@kernel.org> References: <20241001203344.327044-1-anna@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Anna Schumaker We have a put_nfs_version() that handles refcounting on the nfs version module, but get_nfs_version() does much more work to find a version module based on version number. Let's change 'get' to 'find' to better match what it's doing. Signed-off-by: Anna Schumaker --- fs/nfs/client.c | 8 ++++---- fs/nfs/fs_context.c | 2 +- fs/nfs/nfs.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/fs/nfs/client.c b/fs/nfs/client.c index f5c2be89797a..63620766f2a1 100644 --- a/fs/nfs/client.c +++ b/fs/nfs/client.c @@ -80,7 +80,7 @@ const struct rpc_program nfs_program = { .pipe_dir_name = NFS_PIPE_DIRNAME, }; -static struct nfs_subversion *find_nfs_version(unsigned int version) +static struct nfs_subversion *__find_nfs_version(unsigned int version) { struct nfs_subversion *nfs; @@ -93,13 +93,13 @@ static struct nfs_subversion *find_nfs_version(unsigned int version) return nfs; } -struct nfs_subversion *get_nfs_version(unsigned int version) +struct nfs_subversion *find_nfs_version(unsigned int version) { - struct nfs_subversion *nfs = find_nfs_version(version); + struct nfs_subversion *nfs = __find_nfs_version(version); if (IS_ERR(nfs)) { request_module("nfsv%d", version); - nfs = find_nfs_version(version); + nfs = __find_nfs_version(version); } if (!IS_ERR(nfs) && !try_module_get(nfs->owner)) diff --git a/fs/nfs/fs_context.c b/fs/nfs/fs_context.c index 7e000d782e28..d553daa4c09c 100644 --- a/fs/nfs/fs_context.c +++ b/fs/nfs/fs_context.c @@ -1467,7 +1467,7 @@ static int nfs_fs_context_validate(struct fs_context *fc) /* Load the NFS protocol module if we haven't done so yet */ if (!ctx->nfs_mod) { - nfs_mod = get_nfs_version(ctx->version); + nfs_mod = find_nfs_version(ctx->version); if (IS_ERR(nfs_mod)) { ret = PTR_ERR(nfs_mod); goto out_version_unavailable; diff --git a/fs/nfs/nfs.h b/fs/nfs/nfs.h index 0329fc3023d0..a30bf8ef79d7 100644 --- a/fs/nfs/nfs.h +++ b/fs/nfs/nfs.h @@ -21,7 +21,7 @@ struct nfs_subversion { const struct xattr_handler * const *xattr; /* NFS xattr handlers */ }; -struct nfs_subversion *get_nfs_version(unsigned int); +struct nfs_subversion *find_nfs_version(unsigned int); void put_nfs_version(struct nfs_subversion *); void register_nfs_version(struct nfs_subversion *); void unregister_nfs_version(struct nfs_subversion *); From patchwork Tue Oct 1 20:33:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anna Schumaker X-Patchwork-Id: 13818735 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 36A311BDABD for ; Tue, 1 Oct 2024 20:34:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727814841; cv=none; b=QpEqjQcPFiFYj6xJNDtJ079xc7o80toRUkbwVePqQemOI6bBtpEjYouCEXYrxaIZ8egimCzPhV2v8/yt4JaaA5hyJ7ZbNsJjFadH4czHUhQZz5D7lkNNmUtzFFeBuYfEzoXSF82nG5E+ZOivgS/AE21di9fmmY+OCdfxbG7DGkk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727814841; c=relaxed/simple; bh=5aTu02U4n+sG8r2Ub9RmKO/jP1weOoJsVyE7+AikJu8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IMcjPooLyz2gKJ6isCBD8odbbjClP+MRt1t54agOIoNKRqREnHbiXYGb+Lybi2Xa/4XLJG1pnYAb99oJMpaj3IJO+7U/pDhkspUI4ZB5B9rEpwpQ4bJqVavj3XzKiI1Bzwa2+clmFZlry+ZXtRK3lqgEeWu9WpQc9DXPaD68NHg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=c3znZkSm; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="c3znZkSm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 83E9DC4CECD; Tue, 1 Oct 2024 20:34:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727814840; bh=5aTu02U4n+sG8r2Ub9RmKO/jP1weOoJsVyE7+AikJu8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c3znZkSmH2Gj+KZTSjlf3wlMFpylzNPXmaYNfQ5nQIVrGLhH1xL3PkUhR43OZN7Wc avzn/hlkzRz+mj1+sQ7S3OCbxpKSy+5L3M9JuLt3fb0LfFZrgucEgKDFeC1z5SzYFj ElyrPY9//j/RqeMOIQFNxVtv8xIXul+JD4XBM0PNfAs1r2x7rRVHSs43iFPkxRUaIP tvy3EQgCL5aCJw2nyHCk3riMMShBJ43Yl6QbBEgBX7jJLp6FPXFR9uJpZSJDHsfwyq rvmqQVDH034euYnrfwGfHwr6JjUVO6JmyVIfq7+tRRZ3IWnobQ75rGHLj7EE154Kz0 ukY8c79KOt3gQ== From: Anna Schumaker To: linux-nfs@vger.kernel.org, trond.myklebust@hammerspace.com Cc: anna@kernel.org Subject: [PATCH 4/5] NFS: Clean up find_nfs_version() Date: Tue, 1 Oct 2024 16:33:43 -0400 Message-ID: <20241001203344.327044-5-anna@kernel.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241001203344.327044-1-anna@kernel.org> References: <20241001203344.327044-1-anna@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Anna Schumaker It's good practice to check the return value of request_module() to see if the module has been found. It's also a little easier to follow the code if __find_nfs_version() doesn't attempt to convert NULL pointers into -EPROTONOSUPPORT. Signed-off-by: Anna Schumaker --- fs/nfs/client.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/fs/nfs/client.c b/fs/nfs/client.c index 63620766f2a1..4fe5a635f329 100644 --- a/fs/nfs/client.c +++ b/fs/nfs/client.c @@ -87,9 +87,6 @@ static struct nfs_subversion *__find_nfs_version(unsigned int version) read_lock(&nfs_version_lock); nfs = nfs_version_mods[version]; read_unlock(&nfs_version_lock); - - if (nfs == NULL) - return ERR_PTR(-EPROTONOSUPPORT); return nfs; } @@ -97,13 +94,15 @@ struct nfs_subversion *find_nfs_version(unsigned int version) { struct nfs_subversion *nfs = __find_nfs_version(version); - if (IS_ERR(nfs)) { - request_module("nfsv%d", version); + if (!nfs && request_module("nfsv%d", version) == 0) nfs = __find_nfs_version(version); - } - if (!IS_ERR(nfs) && !try_module_get(nfs->owner)) + if (!nfs) + return ERR_PTR(-EPROTONOSUPPORT); + + if (!try_module_get(nfs->owner)) return ERR_PTR(-EAGAIN); + return nfs; } From patchwork Tue Oct 1 20:33:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anna Schumaker X-Patchwork-Id: 13818736 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 92D601CCEF2 for ; Tue, 1 Oct 2024 20:34:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727814841; cv=none; b=QVxqlPr6TE8MIebLeAoA5jZ/s1ap8x+ImoRFJCV+oD0ZlNY7XgkRG5fqUMsLf9kf8UW67Xm5mxHVhduy17pvZXxn5jzC/tIYJJ0gNzren3R18oscCDTKRzly7IEUeNC5KlhUu0sIQCGiq88aTl989gTPUQi2DurPo8XJtmBW9Kc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727814841; c=relaxed/simple; bh=4kyehUr49bd1l6Y38JTbt9Fz18jQ8I3oUMl4DAnEgKo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lMaFOVmazXrVFEHNsU8ZKVA3bVcUq4kzPtJAaSXaDOMo6tS0oWdLVaytPdopMByYZ0+pDZL+iNLZaIEyyD8jDfTqCkjUTJKmtYKMz92UeoEF1K/dSwDPk8F2QC0n+USpZBBpBILdUIwD0lSzzsScVrHTJvnfcJ2fYipR/0UuaLQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=atePX4dL; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="atePX4dL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 197EAC4CED1; Tue, 1 Oct 2024 20:34:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727814841; bh=4kyehUr49bd1l6Y38JTbt9Fz18jQ8I3oUMl4DAnEgKo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=atePX4dLYhMiEae/7SnCw0ndro64WwIGd+tZqLYmmJEi/SOZaqAYSb6ZGx59nAuhx g1u9SaLUZKzWW6wiSIYC2tQfnNAp4S/1oYyOeKdmT20DgAiesz8hGgZDx/fiy3WCQk drm8+GgJG5NMFH9kZFJrwuQcnnyGZ23R5FT4jM78itm+caCfRA6POp+DLzEEa35M0d Hr+jy2PIhcYO0lgX+fvCcYJUwiEKXXjoqqCwL8EitzEZXaZhkmpfe5zLE9DxFlRlg0 EHewLEl65vf6md61RvlzGi7fDTdGE9B6KdmQXy8rOWf2Xnr66laNpaz5KK42PDFo/Q Zhu0o06YD33WA== From: Anna Schumaker To: linux-nfs@vger.kernel.org, trond.myklebust@hammerspace.com Cc: anna@kernel.org Subject: [PATCH 5/5] NFS: Implement get_nfs_version() Date: Tue, 1 Oct 2024 16:33:44 -0400 Message-ID: <20241001203344.327044-6-anna@kernel.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241001203344.327044-1-anna@kernel.org> References: <20241001203344.327044-1-anna@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Anna Schumaker This is a pair for put_nfs_version(), and is used for incrementing the reference count on the nfs version module. I also updated the callers I could find who had this hardcoded up until now. Signed-off-by: Anna Schumaker --- fs/nfs/client.c | 10 ++++++++-- fs/nfs/fs_context.c | 4 ++-- fs/nfs/namespace.c | 2 +- fs/nfs/nfs.h | 1 + 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/fs/nfs/client.c b/fs/nfs/client.c index 4fe5a635f329..68a88f29a1d6 100644 --- a/fs/nfs/client.c +++ b/fs/nfs/client.c @@ -100,12 +100,18 @@ struct nfs_subversion *find_nfs_version(unsigned int version) if (!nfs) return ERR_PTR(-EPROTONOSUPPORT); - if (!try_module_get(nfs->owner)) + if (!get_nfs_version(nfs)) return ERR_PTR(-EAGAIN); return nfs; } +int get_nfs_version(struct nfs_subversion *nfs) +{ + return try_module_get(nfs->owner); +} +EXPORT_SYMBOL_GPL(get_nfs_version); + void put_nfs_version(struct nfs_subversion *nfs) { module_put(nfs->owner); @@ -149,7 +155,7 @@ struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_init) clp->cl_minorversion = cl_init->minorversion; clp->cl_nfs_mod = cl_init->nfs_mod; - if (!try_module_get(clp->cl_nfs_mod->owner)) + if (!get_nfs_version(clp->cl_nfs_mod)) goto error_dealloc; clp->rpc_ops = clp->cl_nfs_mod->rpc_ops; diff --git a/fs/nfs/fs_context.c b/fs/nfs/fs_context.c index d553daa4c09c..b069385eea17 100644 --- a/fs/nfs/fs_context.c +++ b/fs/nfs/fs_context.c @@ -1541,7 +1541,7 @@ static int nfs_fs_context_dup(struct fs_context *fc, struct fs_context *src_fc) } nfs_copy_fh(ctx->mntfh, src->mntfh); - __module_get(ctx->nfs_mod->owner); + get_nfs_version(ctx->nfs_mod); ctx->client_address = NULL; ctx->mount_server.hostname = NULL; ctx->nfs_server.export_path = NULL; @@ -1633,7 +1633,7 @@ static int nfs_init_fs_context(struct fs_context *fc) } ctx->nfs_mod = nfss->nfs_client->cl_nfs_mod; - __module_get(ctx->nfs_mod->owner); + get_nfs_version(ctx->nfs_mod); } else { /* defaults */ ctx->timeo = NFS_UNSPEC_TIMEO; diff --git a/fs/nfs/namespace.c b/fs/nfs/namespace.c index e7494cdd957e..2d53574da605 100644 --- a/fs/nfs/namespace.c +++ b/fs/nfs/namespace.c @@ -182,7 +182,7 @@ struct vfsmount *nfs_d_automount(struct path *path) ctx->version = client->rpc_ops->version; ctx->minorversion = client->cl_minorversion; ctx->nfs_mod = client->cl_nfs_mod; - __module_get(ctx->nfs_mod->owner); + get_nfs_version(ctx->nfs_mod); ret = client->rpc_ops->submount(fc, server); if (ret < 0) { diff --git a/fs/nfs/nfs.h b/fs/nfs/nfs.h index a30bf8ef79d7..8a5f51be013a 100644 --- a/fs/nfs/nfs.h +++ b/fs/nfs/nfs.h @@ -22,6 +22,7 @@ struct nfs_subversion { }; struct nfs_subversion *find_nfs_version(unsigned int); +int get_nfs_version(struct nfs_subversion *); void put_nfs_version(struct nfs_subversion *); void register_nfs_version(struct nfs_subversion *); void unregister_nfs_version(struct nfs_subversion *);