Skip to content

Commit 6278c86

Browse files
Anna SchumakerTrond Myklebust
authored andcommitted
NFS: Clean up locking the nfs_versions list
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 <[email protected]> Signed-off-by: Trond Myklebust <[email protected]>
1 parent ff7afae commit 6278c86

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

fs/nfs/client.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@
5555
#define NFSDBG_FACILITY NFSDBG_CLIENT
5656

5757
static DECLARE_WAIT_QUEUE_HEAD(nfs_client_active_wq);
58-
static DEFINE_SPINLOCK(nfs_version_lock);
59-
static DEFINE_MUTEX(nfs_version_mutex);
58+
static DEFINE_RWLOCK(nfs_version_lock);
6059
static LIST_HEAD(nfs_versions);
6160

6261
/*
@@ -79,16 +78,16 @@ const struct rpc_program nfs_program = {
7978
static struct nfs_subversion *find_nfs_version(unsigned int version)
8079
{
8180
struct nfs_subversion *nfs;
82-
spin_lock(&nfs_version_lock);
81+
read_lock(&nfs_version_lock);
8382

8483
list_for_each_entry(nfs, &nfs_versions, list) {
8584
if (nfs->rpc_ops->version == version) {
86-
spin_unlock(&nfs_version_lock);
85+
read_unlock(&nfs_version_lock);
8786
return nfs;
8887
}
8988
}
9089

91-
spin_unlock(&nfs_version_lock);
90+
read_unlock(&nfs_version_lock);
9291
return ERR_PTR(-EPROTONOSUPPORT);
9392
}
9493

@@ -97,10 +96,8 @@ struct nfs_subversion *get_nfs_version(unsigned int version)
9796
struct nfs_subversion *nfs = find_nfs_version(version);
9897

9998
if (IS_ERR(nfs)) {
100-
mutex_lock(&nfs_version_mutex);
10199
request_module("nfsv%d", version);
102100
nfs = find_nfs_version(version);
103-
mutex_unlock(&nfs_version_mutex);
104101
}
105102

106103
if (!IS_ERR(nfs) && !try_module_get(nfs->owner))
@@ -115,23 +112,23 @@ void put_nfs_version(struct nfs_subversion *nfs)
115112

116113
void register_nfs_version(struct nfs_subversion *nfs)
117114
{
118-
spin_lock(&nfs_version_lock);
115+
write_lock(&nfs_version_lock);
119116

120117
list_add(&nfs->list, &nfs_versions);
121118
nfs_version[nfs->rpc_ops->version] = nfs->rpc_vers;
122119

123-
spin_unlock(&nfs_version_lock);
120+
write_unlock(&nfs_version_lock);
124121
}
125122
EXPORT_SYMBOL_GPL(register_nfs_version);
126123

127124
void unregister_nfs_version(struct nfs_subversion *nfs)
128125
{
129-
spin_lock(&nfs_version_lock);
126+
write_lock(&nfs_version_lock);
130127

131128
nfs_version[nfs->rpc_ops->version] = NULL;
132129
list_del(&nfs->list);
133130

134-
spin_unlock(&nfs_version_lock);
131+
write_unlock(&nfs_version_lock);
135132
}
136133
EXPORT_SYMBOL_GPL(unregister_nfs_version);
137134

0 commit comments

Comments
 (0)