Commit dc030858 authored by Stanislav Kinsbursky's avatar Stanislav Kinsbursky Committed by Trond Myklebust

NFS: make nfs_client_lock per net ns

This patch makes nfs_clients_lock allocated per network namespace. All items it
protects are already network namespace aware.
Signed-off-by: default avatarStanislav Kinsbursky <skinsbursky@parallels.com>
Signed-off-by: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
parent 28cd1b3f
...@@ -55,7 +55,6 @@ ...@@ -55,7 +55,6 @@
#define NFSDBG_FACILITY NFSDBG_CLIENT #define NFSDBG_FACILITY NFSDBG_CLIENT
DEFINE_SPINLOCK(nfs_client_lock);
static DECLARE_WAIT_QUEUE_HEAD(nfs_client_active_wq); static DECLARE_WAIT_QUEUE_HEAD(nfs_client_active_wq);
#ifdef CONFIG_NFS_V4 #ifdef CONFIG_NFS_V4
...@@ -73,9 +72,9 @@ static int nfs_get_cb_ident_idr(struct nfs_client *clp, int minorversion) ...@@ -73,9 +72,9 @@ static int nfs_get_cb_ident_idr(struct nfs_client *clp, int minorversion)
retry: retry:
if (!idr_pre_get(&nn->cb_ident_idr, GFP_KERNEL)) if (!idr_pre_get(&nn->cb_ident_idr, GFP_KERNEL))
return -ENOMEM; return -ENOMEM;
spin_lock(&nfs_client_lock); spin_lock(&nn->nfs_client_lock);
ret = idr_get_new(&nn->cb_ident_idr, clp, &clp->cl_cb_ident); ret = idr_get_new(&nn->cb_ident_idr, clp, &clp->cl_cb_ident);
spin_unlock(&nfs_client_lock); spin_unlock(&nn->nfs_client_lock);
if (ret == -EAGAIN) if (ret == -EAGAIN)
goto retry; goto retry;
return ret; return ret;
...@@ -313,15 +312,18 @@ static void nfs_free_client(struct nfs_client *clp) ...@@ -313,15 +312,18 @@ static void nfs_free_client(struct nfs_client *clp)
*/ */
void nfs_put_client(struct nfs_client *clp) void nfs_put_client(struct nfs_client *clp)
{ {
struct nfs_net *nn;
if (!clp) if (!clp)
return; return;
dprintk("--> nfs_put_client({%d})\n", atomic_read(&clp->cl_count)); dprintk("--> nfs_put_client({%d})\n", atomic_read(&clp->cl_count));
nn = net_generic(clp->net, nfs_net_id);
if (atomic_dec_and_lock(&clp->cl_count, &nfs_client_lock)) { if (atomic_dec_and_lock(&clp->cl_count, &nn->nfs_client_lock)) {
list_del(&clp->cl_share_link); list_del(&clp->cl_share_link);
nfs_cb_idr_remove_locked(clp); nfs_cb_idr_remove_locked(clp);
spin_unlock(&nfs_client_lock); spin_unlock(&nn->nfs_client_lock);
BUG_ON(!list_empty(&clp->cl_superblocks)); BUG_ON(!list_empty(&clp->cl_superblocks));
...@@ -516,7 +518,7 @@ nfs_get_client(const struct nfs_client_initdata *cl_init, ...@@ -516,7 +518,7 @@ nfs_get_client(const struct nfs_client_initdata *cl_init,
/* see if the client already exists */ /* see if the client already exists */
do { do {
spin_lock(&nfs_client_lock); spin_lock(&nn->nfs_client_lock);
clp = nfs_match_client(cl_init); clp = nfs_match_client(cl_init);
if (clp) if (clp)
...@@ -524,7 +526,7 @@ nfs_get_client(const struct nfs_client_initdata *cl_init, ...@@ -524,7 +526,7 @@ nfs_get_client(const struct nfs_client_initdata *cl_init,
if (new) if (new)
goto install_client; goto install_client;
spin_unlock(&nfs_client_lock); spin_unlock(&nn->nfs_client_lock);
new = nfs_alloc_client(cl_init); new = nfs_alloc_client(cl_init);
} while (!IS_ERR(new)); } while (!IS_ERR(new));
...@@ -536,7 +538,7 @@ nfs_get_client(const struct nfs_client_initdata *cl_init, ...@@ -536,7 +538,7 @@ nfs_get_client(const struct nfs_client_initdata *cl_init,
install_client: install_client:
clp = new; clp = new;
list_add(&clp->cl_share_link, &nn->nfs_client_list); list_add(&clp->cl_share_link, &nn->nfs_client_list);
spin_unlock(&nfs_client_lock); spin_unlock(&nn->nfs_client_lock);
error = cl_init->rpc_ops->init_client(clp, timeparms, ip_addr, error = cl_init->rpc_ops->init_client(clp, timeparms, ip_addr,
authflavour, noresvport); authflavour, noresvport);
...@@ -551,7 +553,7 @@ nfs_get_client(const struct nfs_client_initdata *cl_init, ...@@ -551,7 +553,7 @@ nfs_get_client(const struct nfs_client_initdata *cl_init,
* - make sure it's ready before returning * - make sure it's ready before returning
*/ */
found_client: found_client:
spin_unlock(&nfs_client_lock); spin_unlock(&nn->nfs_client_lock);
if (new) if (new)
nfs_free_client(new); nfs_free_client(new);
...@@ -1041,24 +1043,25 @@ static void nfs_server_insert_lists(struct nfs_server *server) ...@@ -1041,24 +1043,25 @@ static void nfs_server_insert_lists(struct nfs_server *server)
struct nfs_client *clp = server->nfs_client; struct nfs_client *clp = server->nfs_client;
struct nfs_net *nn = net_generic(clp->net, nfs_net_id); struct nfs_net *nn = net_generic(clp->net, nfs_net_id);
spin_lock(&nfs_client_lock); spin_lock(&nn->nfs_client_lock);
list_add_tail_rcu(&server->client_link, &clp->cl_superblocks); list_add_tail_rcu(&server->client_link, &clp->cl_superblocks);
list_add_tail(&server->master_link, &nn->nfs_volume_list); list_add_tail(&server->master_link, &nn->nfs_volume_list);
clear_bit(NFS_CS_STOP_RENEW, &clp->cl_res_state); clear_bit(NFS_CS_STOP_RENEW, &clp->cl_res_state);
spin_unlock(&nfs_client_lock); spin_unlock(&nn->nfs_client_lock);
} }
static void nfs_server_remove_lists(struct nfs_server *server) static void nfs_server_remove_lists(struct nfs_server *server)
{ {
struct nfs_client *clp = server->nfs_client; struct nfs_client *clp = server->nfs_client;
struct nfs_net *nn = net_generic(clp->net, nfs_net_id);
spin_lock(&nfs_client_lock); spin_lock(&nn->nfs_client_lock);
list_del_rcu(&server->client_link); list_del_rcu(&server->client_link);
if (clp && list_empty(&clp->cl_superblocks)) if (clp && list_empty(&clp->cl_superblocks))
set_bit(NFS_CS_STOP_RENEW, &clp->cl_res_state); set_bit(NFS_CS_STOP_RENEW, &clp->cl_res_state);
list_del(&server->master_link); list_del(&server->master_link);
spin_unlock(&nfs_client_lock); spin_unlock(&nn->nfs_client_lock);
synchronize_rcu(); synchronize_rcu();
} }
...@@ -1212,11 +1215,11 @@ nfs4_find_client_ident(struct net *net, int cb_ident) ...@@ -1212,11 +1215,11 @@ nfs4_find_client_ident(struct net *net, int cb_ident)
struct nfs_client *clp; struct nfs_client *clp;
struct nfs_net *nn = net_generic(net, nfs_net_id); struct nfs_net *nn = net_generic(net, nfs_net_id);
spin_lock(&nfs_client_lock); spin_lock(&nn->nfs_client_lock);
clp = idr_find(&nn->cb_ident_idr, cb_ident); clp = idr_find(&nn->cb_ident_idr, cb_ident);
if (clp) if (clp)
atomic_inc(&clp->cl_count); atomic_inc(&clp->cl_count);
spin_unlock(&nfs_client_lock); spin_unlock(&nn->nfs_client_lock);
return clp; return clp;
} }
...@@ -1235,7 +1238,7 @@ nfs4_find_client_sessionid(const struct sockaddr *addr, ...@@ -1235,7 +1238,7 @@ nfs4_find_client_sessionid(const struct sockaddr *addr,
struct nfs_client *clp; struct nfs_client *clp;
struct nfs_net *nn = net_generic(&init_net, nfs_net_id); struct nfs_net *nn = net_generic(&init_net, nfs_net_id);
spin_lock(&nfs_client_lock); spin_lock(&nn->nfs_client_lock);
list_for_each_entry(clp, &nn->nfs_client_list, cl_share_link) { list_for_each_entry(clp, &nn->nfs_client_list, cl_share_link) {
if (nfs4_cb_match_client(addr, clp, 1) == false) if (nfs4_cb_match_client(addr, clp, 1) == false)
continue; continue;
...@@ -1249,10 +1252,10 @@ nfs4_find_client_sessionid(const struct sockaddr *addr, ...@@ -1249,10 +1252,10 @@ nfs4_find_client_sessionid(const struct sockaddr *addr,
continue; continue;
atomic_inc(&clp->cl_count); atomic_inc(&clp->cl_count);
spin_unlock(&nfs_client_lock); spin_unlock(&nn->nfs_client_lock);
return clp; return clp;
} }
spin_unlock(&nfs_client_lock); spin_unlock(&nn->nfs_client_lock);
return NULL; return NULL;
} }
...@@ -1849,7 +1852,7 @@ static void *nfs_server_list_start(struct seq_file *m, loff_t *_pos) ...@@ -1849,7 +1852,7 @@ static void *nfs_server_list_start(struct seq_file *m, loff_t *_pos)
struct nfs_net *nn = net_generic(m->private, nfs_net_id); struct nfs_net *nn = net_generic(m->private, nfs_net_id);
/* lock the list against modification */ /* lock the list against modification */
spin_lock(&nfs_client_lock); spin_lock(&nn->nfs_client_lock);
return seq_list_start_head(&nn->nfs_client_list, *_pos); return seq_list_start_head(&nn->nfs_client_list, *_pos);
} }
...@@ -1868,7 +1871,9 @@ static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos) ...@@ -1868,7 +1871,9 @@ static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos)
*/ */
static void nfs_server_list_stop(struct seq_file *p, void *v) static void nfs_server_list_stop(struct seq_file *p, void *v)
{ {
spin_unlock(&nfs_client_lock); struct nfs_net *nn = net_generic(p->private, nfs_net_id);
spin_unlock(&nn->nfs_client_lock);
} }
/* /*
...@@ -1930,7 +1935,7 @@ static void *nfs_volume_list_start(struct seq_file *m, loff_t *_pos) ...@@ -1930,7 +1935,7 @@ static void *nfs_volume_list_start(struct seq_file *m, loff_t *_pos)
struct nfs_net *nn = net_generic(m->private, nfs_net_id); struct nfs_net *nn = net_generic(m->private, nfs_net_id);
/* lock the list against modification */ /* lock the list against modification */
spin_lock(&nfs_client_lock); spin_lock(&nn->nfs_client_lock);
return seq_list_start_head(&nn->nfs_volume_list, *_pos); return seq_list_start_head(&nn->nfs_volume_list, *_pos);
} }
...@@ -1949,7 +1954,9 @@ static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos) ...@@ -1949,7 +1954,9 @@ static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos)
*/ */
static void nfs_volume_list_stop(struct seq_file *p, void *v) static void nfs_volume_list_stop(struct seq_file *p, void *v)
{ {
spin_unlock(&nfs_client_lock); struct nfs_net *nn = net_generic(p->private, nfs_net_id);
spin_unlock(&nn->nfs_client_lock);
} }
/* /*
......
...@@ -536,7 +536,7 @@ static int rpc_pipefs_event(struct notifier_block *nb, unsigned long event, ...@@ -536,7 +536,7 @@ static int rpc_pipefs_event(struct notifier_block *nb, unsigned long event,
struct nfs_client *clp; struct nfs_client *clp;
int error = 0; int error = 0;
spin_lock(&nfs_client_lock); spin_lock(&nn->nfs_client_lock);
list_for_each_entry(clp, &nn->nfs_client_list, cl_share_link) { list_for_each_entry(clp, &nn->nfs_client_list, cl_share_link) {
if (clp->rpc_ops != &nfs_v4_clientops) if (clp->rpc_ops != &nfs_v4_clientops)
continue; continue;
...@@ -544,7 +544,7 @@ static int rpc_pipefs_event(struct notifier_block *nb, unsigned long event, ...@@ -544,7 +544,7 @@ static int rpc_pipefs_event(struct notifier_block *nb, unsigned long event,
if (error) if (error)
break; break;
} }
spin_unlock(&nfs_client_lock); spin_unlock(&nn->nfs_client_lock);
return error; return error;
} }
......
...@@ -182,9 +182,6 @@ static inline void nfs_fs_proc_exit(void) ...@@ -182,9 +182,6 @@ static inline void nfs_fs_proc_exit(void)
{ {
} }
#endif #endif
#ifdef CONFIG_NFS_V4
extern spinlock_t nfs_client_lock;
#endif
/* nfs4namespace.c */ /* nfs4namespace.c */
#ifdef CONFIG_NFS_V4 #ifdef CONFIG_NFS_V4
......
...@@ -12,6 +12,7 @@ struct nfs_net { ...@@ -12,6 +12,7 @@ struct nfs_net {
#ifdef CONFIG_NFS_V4 #ifdef CONFIG_NFS_V4
struct idr cb_ident_idr; /* Protected by nfs_client_lock */ struct idr cb_ident_idr; /* Protected by nfs_client_lock */
#endif #endif
spinlock_t nfs_client_lock;
}; };
extern int nfs_net_id; extern int nfs_net_id;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment