Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

NFS: Convert the NFS module list into an array

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 <anna.schumaker@oracle.com>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>

authored by

Anna Schumaker and committed by
Trond Myklebust
11eb537f 6278c86a

+14 -13
+14 -12
fs/nfs/client.c
··· 56 56 57 57 static DECLARE_WAIT_QUEUE_HEAD(nfs_client_active_wq); 58 58 static DEFINE_RWLOCK(nfs_version_lock); 59 - static LIST_HEAD(nfs_versions); 59 + 60 + static struct nfs_subversion *nfs_version_mods[5] = { 61 + [2] = NULL, 62 + [3] = NULL, 63 + [4] = NULL, 64 + }; 60 65 61 66 /* 62 67 * RPC cruft for NFS ··· 83 78 static struct nfs_subversion *find_nfs_version(unsigned int version) 84 79 { 85 80 struct nfs_subversion *nfs; 81 + 86 82 read_lock(&nfs_version_lock); 87 - 88 - list_for_each_entry(nfs, &nfs_versions, list) { 89 - if (nfs->rpc_ops->version == version) { 90 - read_unlock(&nfs_version_lock); 91 - return nfs; 92 - } 93 - } 94 - 83 + nfs = nfs_version_mods[version]; 95 84 read_unlock(&nfs_version_lock); 96 - return ERR_PTR(-EPROTONOSUPPORT); 85 + 86 + if (nfs == NULL) 87 + return ERR_PTR(-EPROTONOSUPPORT); 88 + return nfs; 97 89 } 98 90 99 91 struct nfs_subversion *get_nfs_version(unsigned int version) ··· 116 114 { 117 115 write_lock(&nfs_version_lock); 118 116 119 - list_add(&nfs->list, &nfs_versions); 117 + nfs_version_mods[nfs->rpc_ops->version] = nfs; 120 118 nfs_version[nfs->rpc_ops->version] = nfs->rpc_vers; 121 119 122 120 write_unlock(&nfs_version_lock); ··· 128 126 write_lock(&nfs_version_lock); 129 127 130 128 nfs_version[nfs->rpc_ops->version] = NULL; 131 - list_del(&nfs->list); 129 + nfs_version_mods[nfs->rpc_ops->version] = NULL; 132 130 133 131 write_unlock(&nfs_version_lock); 134 132 }
-1
fs/nfs/nfs.h
··· 19 19 const struct nfs_rpc_ops *rpc_ops; /* NFS operations */ 20 20 const struct super_operations *sops; /* NFS Super operations */ 21 21 const struct xattr_handler * const *xattr; /* NFS xattr handlers */ 22 - struct list_head list; /* List of NFS versions */ 23 22 }; 24 23 25 24 struct nfs_subversion *get_nfs_version(unsigned int);