Commit 1c755dc1 authored by Jeff Layton's avatar Jeff Layton Committed by J. Bruce Fields

nfsd: Add locking to protect the state owner lists

Change to using the clp->cl_lock for this. For now, there's a lot of
cl_lock thrashing, but in later patches we'll eliminate that and close
the potential races that can occur when releasing the cl_lock while
walking the lists. For now, the client_mutex prevents those races.
Signed-off-by: default avatarTrond Myklebust <trond.myklebust@primarydata.com>
Signed-off-by: default avatarJeff Layton <jlayton@primarydata.com>
Signed-off-by: default avatarJ. Bruce Fields <bfields@redhat.com>
parent b49e084d
...@@ -893,6 +893,8 @@ static void unhash_generic_stateid(struct nfs4_ol_stateid *stp) ...@@ -893,6 +893,8 @@ static void unhash_generic_stateid(struct nfs4_ol_stateid *stp)
{ {
struct nfs4_file *fp = stp->st_stid.sc_file; struct nfs4_file *fp = stp->st_stid.sc_file;
lockdep_assert_held(&stp->st_stateowner->so_client->cl_lock);
spin_lock(&fp->fi_lock); spin_lock(&fp->fi_lock);
list_del(&stp->st_perfile); list_del(&stp->st_perfile);
spin_unlock(&fp->fi_lock); spin_unlock(&fp->fi_lock);
...@@ -921,9 +923,13 @@ static void nfs4_free_lock_stateid(struct nfs4_stid *stid) ...@@ -921,9 +923,13 @@ static void nfs4_free_lock_stateid(struct nfs4_stid *stid)
static void __release_lock_stateid(struct nfs4_ol_stateid *stp) static void __release_lock_stateid(struct nfs4_ol_stateid *stp)
{ {
struct nfs4_openowner *oo = openowner(stp->st_openstp->st_stateowner);
spin_lock(&oo->oo_owner.so_client->cl_lock);
list_del(&stp->st_locks); list_del(&stp->st_locks);
unhash_generic_stateid(stp); unhash_generic_stateid(stp);
unhash_stid(&stp->st_stid); unhash_stid(&stp->st_stid);
spin_unlock(&oo->oo_owner.so_client->cl_lock);
nfs4_put_stid(&stp->st_stid); nfs4_put_stid(&stp->st_stid);
} }
...@@ -967,20 +973,26 @@ static void release_lock_stateid(struct nfs4_ol_stateid *stp) ...@@ -967,20 +973,26 @@ static void release_lock_stateid(struct nfs4_ol_stateid *stp)
} }
static void release_open_stateid_locks(struct nfs4_ol_stateid *open_stp) static void release_open_stateid_locks(struct nfs4_ol_stateid *open_stp)
__releases(&open_stp->st_stateowner->so_client->cl_lock)
__acquires(&open_stp->st_stateowner->so_client->cl_lock)
{ {
struct nfs4_ol_stateid *stp; struct nfs4_ol_stateid *stp;
while (!list_empty(&open_stp->st_locks)) { while (!list_empty(&open_stp->st_locks)) {
stp = list_entry(open_stp->st_locks.next, stp = list_entry(open_stp->st_locks.next,
struct nfs4_ol_stateid, st_locks); struct nfs4_ol_stateid, st_locks);
spin_unlock(&open_stp->st_stateowner->so_client->cl_lock);
release_lock_stateid(stp); release_lock_stateid(stp);
spin_lock(&open_stp->st_stateowner->so_client->cl_lock);
} }
} }
static void unhash_open_stateid(struct nfs4_ol_stateid *stp) static void unhash_open_stateid(struct nfs4_ol_stateid *stp)
{ {
spin_lock(&stp->st_stateowner->so_client->cl_lock);
unhash_generic_stateid(stp); unhash_generic_stateid(stp);
release_open_stateid_locks(stp); release_open_stateid_locks(stp);
spin_unlock(&stp->st_stateowner->so_client->cl_lock);
} }
static void release_open_stateid(struct nfs4_ol_stateid *stp) static void release_open_stateid(struct nfs4_ol_stateid *stp)
...@@ -2996,16 +3008,18 @@ static void init_open_stateid(struct nfs4_ol_stateid *stp, struct nfs4_file *fp, ...@@ -2996,16 +3008,18 @@ static void init_open_stateid(struct nfs4_ol_stateid *stp, struct nfs4_file *fp,
stp->st_stid.sc_type = NFS4_OPEN_STID; stp->st_stid.sc_type = NFS4_OPEN_STID;
INIT_LIST_HEAD(&stp->st_locks); INIT_LIST_HEAD(&stp->st_locks);
list_add(&stp->st_perstateowner, &oo->oo_owner.so_stateids);
stp->st_stateowner = &oo->oo_owner; stp->st_stateowner = &oo->oo_owner;
get_nfs4_file(fp); get_nfs4_file(fp);
stp->st_stid.sc_file = fp; stp->st_stid.sc_file = fp;
stp->st_access_bmap = 0; stp->st_access_bmap = 0;
stp->st_deny_bmap = 0; stp->st_deny_bmap = 0;
stp->st_openstp = NULL; stp->st_openstp = NULL;
spin_lock(&oo->oo_owner.so_client->cl_lock);
list_add(&stp->st_perstateowner, &oo->oo_owner.so_stateids);
spin_lock(&fp->fi_lock); spin_lock(&fp->fi_lock);
list_add(&stp->st_perfile, &fp->fi_stateids); list_add(&stp->st_perfile, &fp->fi_stateids);
spin_unlock(&fp->fi_lock); spin_unlock(&fp->fi_lock);
spin_unlock(&oo->oo_owner.so_client->cl_lock);
} }
static void static void
...@@ -4711,6 +4725,7 @@ alloc_init_lock_stateid(struct nfs4_lockowner *lo, struct nfs4_file *fp, ...@@ -4711,6 +4725,7 @@ alloc_init_lock_stateid(struct nfs4_lockowner *lo, struct nfs4_file *fp,
struct nfs4_ol_stateid *open_stp) struct nfs4_ol_stateid *open_stp)
{ {
struct nfs4_stid *s; struct nfs4_stid *s;
struct nfs4_openowner *oo = openowner(open_stp->st_stateowner);
struct nfs4_ol_stateid *stp; struct nfs4_ol_stateid *stp;
struct nfs4_client *clp = lo->lo_owner.so_client; struct nfs4_client *clp = lo->lo_owner.so_client;
...@@ -4719,7 +4734,6 @@ alloc_init_lock_stateid(struct nfs4_lockowner *lo, struct nfs4_file *fp, ...@@ -4719,7 +4734,6 @@ alloc_init_lock_stateid(struct nfs4_lockowner *lo, struct nfs4_file *fp,
return NULL; return NULL;
stp = openlockstateid(s); stp = openlockstateid(s);
stp->st_stid.sc_type = NFS4_LOCK_STID; stp->st_stid.sc_type = NFS4_LOCK_STID;
list_add(&stp->st_perstateowner, &lo->lo_owner.so_stateids);
stp->st_stateowner = &lo->lo_owner; stp->st_stateowner = &lo->lo_owner;
get_nfs4_file(fp); get_nfs4_file(fp);
stp->st_stid.sc_file = fp; stp->st_stid.sc_file = fp;
...@@ -4727,10 +4741,13 @@ alloc_init_lock_stateid(struct nfs4_lockowner *lo, struct nfs4_file *fp, ...@@ -4727,10 +4741,13 @@ alloc_init_lock_stateid(struct nfs4_lockowner *lo, struct nfs4_file *fp,
stp->st_access_bmap = 0; stp->st_access_bmap = 0;
stp->st_deny_bmap = open_stp->st_deny_bmap; stp->st_deny_bmap = open_stp->st_deny_bmap;
stp->st_openstp = open_stp; stp->st_openstp = open_stp;
spin_lock(&oo->oo_owner.so_client->cl_lock);
list_add(&stp->st_locks, &open_stp->st_locks); list_add(&stp->st_locks, &open_stp->st_locks);
list_add(&stp->st_perstateowner, &lo->lo_owner.so_stateids);
spin_lock(&fp->fi_lock); spin_lock(&fp->fi_lock);
list_add(&stp->st_perfile, &fp->fi_stateids); list_add(&stp->st_perfile, &fp->fi_stateids);
spin_unlock(&fp->fi_lock); spin_unlock(&fp->fi_lock);
spin_unlock(&oo->oo_owner.so_client->cl_lock);
return stp; return stp;
} }
......
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