diff options
author | Scott Mayhew <smayhew@redhat.com> | 2017-12-05 13:55:44 -0500 |
---|---|---|
committer | Anna Schumaker <Anna.Schumaker@Netapp.com> | 2017-12-15 14:31:49 -0500 |
commit | c156618e15101a9cc8c815108fec0300a0ec6637 (patch) | |
tree | aa9384520ea1a224d5be11bfe2614f03580791d0 /fs/nfs/client.c | |
parent | eb5b46faa693470681ec7c28cc2436edd1571198 (diff) |
nfs: fix a deadlock in nfs client initialization
The following deadlock can occur between a process waiting for a client
to initialize in while walking the client list during nfsv4 server trunking
detection and another process waiting for the nfs_clid_init_mutex so it
can initialize that client:
Process 1 Process 2
--------- ---------
spin_lock(&nn->nfs_client_lock);
list_add_tail(&CLIENTA->cl_share_link,
&nn->nfs_client_list);
spin_unlock(&nn->nfs_client_lock);
spin_lock(&nn->nfs_client_lock);
list_add_tail(&CLIENTB->cl_share_link,
&nn->nfs_client_list);
spin_unlock(&nn->nfs_client_lock);
mutex_lock(&nfs_clid_init_mutex);
nfs41_walk_client_list(clp, result, cred);
nfs_wait_client_init_complete(CLIENTA);
(waiting for nfs_clid_init_mutex)
Make sure nfs_match_client() only evaluates clients that have completed
initialization in order to prevent that deadlock.
This patch also fixes v4.0 trunking behavior by not marking the client
NFS_CS_READY until the clientid has been confirmed.
Signed-off-by: Scott Mayhew <smayhew@redhat.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
Diffstat (limited to 'fs/nfs/client.c')
-rw-r--r-- | fs/nfs/client.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/fs/nfs/client.c b/fs/nfs/client.c index 0ac2fb1c6b63..b9129e2befea 100644 --- a/fs/nfs/client.c +++ b/fs/nfs/client.c | |||
@@ -291,12 +291,23 @@ static struct nfs_client *nfs_match_client(const struct nfs_client_initdata *dat | |||
291 | const struct sockaddr *sap = data->addr; | 291 | const struct sockaddr *sap = data->addr; |
292 | struct nfs_net *nn = net_generic(data->net, nfs_net_id); | 292 | struct nfs_net *nn = net_generic(data->net, nfs_net_id); |
293 | 293 | ||
294 | again: | ||
294 | list_for_each_entry(clp, &nn->nfs_client_list, cl_share_link) { | 295 | list_for_each_entry(clp, &nn->nfs_client_list, cl_share_link) { |
295 | const struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr; | 296 | const struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr; |
296 | /* Don't match clients that failed to initialise properly */ | 297 | /* Don't match clients that failed to initialise properly */ |
297 | if (clp->cl_cons_state < 0) | 298 | if (clp->cl_cons_state < 0) |
298 | continue; | 299 | continue; |
299 | 300 | ||
301 | /* If a client is still initializing then we need to wait */ | ||
302 | if (clp->cl_cons_state > NFS_CS_READY) { | ||
303 | refcount_inc(&clp->cl_count); | ||
304 | spin_unlock(&nn->nfs_client_lock); | ||
305 | nfs_wait_client_init_complete(clp); | ||
306 | nfs_put_client(clp); | ||
307 | spin_lock(&nn->nfs_client_lock); | ||
308 | goto again; | ||
309 | } | ||
310 | |||
300 | /* Different NFS versions cannot share the same nfs_client */ | 311 | /* Different NFS versions cannot share the same nfs_client */ |
301 | if (clp->rpc_ops != data->nfs_mod->rpc_ops) | 312 | if (clp->rpc_ops != data->nfs_mod->rpc_ops) |
302 | continue; | 313 | continue; |