diff options
author | Jeff Layton | 2014-07-29 21:34:29 -0400 |
---|---|---|
committer | J. Bruce Fields | 2014-07-31 14:20:20 -0400 |
commit | 8f4b54c53f0d9c67cf922c8a780b8d9075e20e07 (patch) | |
tree | ea44df538656d87ae1a24ba10c3f9e437caa4d92 | |
parent | 5db1c03feb00a72846927172d81744790e601b97 (diff) |
nfsd: add an operation for unhashing a stateowner
Allow stateowners to be unhashed and destroyed when the last reference
is put. The unhashing must be idempotent. In a future patch, we'll add
some locking around it, but for now it's only protected by the
client_mutex.
Signed-off-by: Jeff Layton <jlayton@primarydata.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
-rw-r--r-- | fs/nfsd/nfs4state.c | 49 | ||||
-rw-r--r-- | fs/nfsd/state.h | 1 |
2 files changed, 38 insertions, 12 deletions
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index eaa5f9ebf444..906c8604de30 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -894,6 +894,7 @@ static void nfs4_put_stateowner(struct nfs4_stateowner *sop) { if (!atomic_dec_and_test(&sop->so_count)) return; + sop->so_ops->so_unhash(sop); kfree(sop->so_owner.data); sop->so_ops->so_free(sop); } @@ -944,9 +945,13 @@ static void __release_lock_stateid(struct nfs4_ol_stateid *stp) static void unhash_lockowner(struct nfs4_lockowner *lo) { + list_del_init(&lo->lo_owner.so_strhash); +} + +static void release_lockowner_stateids(struct nfs4_lockowner *lo) +{ struct nfs4_ol_stateid *stp; - list_del(&lo->lo_owner.so_strhash); while (!list_empty(&lo->lo_owner.so_stateids)) { stp = list_first_entry(&lo->lo_owner.so_stateids, struct nfs4_ol_stateid, st_perstateowner); @@ -957,6 +962,7 @@ static void unhash_lockowner(struct nfs4_lockowner *lo) static void release_lockowner(struct nfs4_lockowner *lo) { unhash_lockowner(lo); + release_lockowner_stateids(lo); nfs4_put_stateowner(&lo->lo_owner); } @@ -1006,15 +1012,8 @@ static void release_open_stateid(struct nfs4_ol_stateid *stp) static void unhash_openowner(struct nfs4_openowner *oo) { - struct nfs4_ol_stateid *stp; - - list_del(&oo->oo_owner.so_strhash); - list_del(&oo->oo_perclient); - while (!list_empty(&oo->oo_owner.so_stateids)) { - stp = list_first_entry(&oo->oo_owner.so_stateids, - struct nfs4_ol_stateid, st_perstateowner); - release_open_stateid(stp); - } + list_del_init(&oo->oo_owner.so_strhash); + list_del_init(&oo->oo_perclient); } static void release_last_closed_stateid(struct nfs4_openowner *oo) @@ -1027,9 +1026,21 @@ static void release_last_closed_stateid(struct nfs4_openowner *oo) } } +static void release_openowner_stateids(struct nfs4_openowner *oo) +{ + struct nfs4_ol_stateid *stp; + + while (!list_empty(&oo->oo_owner.so_stateids)) { + stp = list_first_entry(&oo->oo_owner.so_stateids, + struct nfs4_ol_stateid, st_perstateowner); + release_open_stateid(stp); + } +} + static void release_openowner(struct nfs4_openowner *oo) { unhash_openowner(oo); + release_openowner_stateids(oo); list_del(&oo->oo_close_lru); release_last_closed_stateid(oo); nfs4_put_stateowner(&oo->oo_owner); @@ -2994,6 +3005,13 @@ static void hash_openowner(struct nfs4_openowner *oo, struct nfs4_client *clp, u list_add(&oo->oo_perclient, &clp->cl_openowners); } +static void nfs4_unhash_openowner(struct nfs4_stateowner *so) +{ + struct nfs4_openowner *oo = openowner(so); + + unhash_openowner(oo); +} + static void nfs4_free_openowner(struct nfs4_stateowner *so) { struct nfs4_openowner *oo = openowner(so); @@ -3002,7 +3020,8 @@ static void nfs4_free_openowner(struct nfs4_stateowner *so) } static const struct nfs4_stateowner_operations openowner_ops = { - .so_free = nfs4_free_openowner, + .so_unhash = nfs4_unhash_openowner, + .so_free = nfs4_free_openowner, }; static struct nfs4_openowner * @@ -4760,6 +4779,11 @@ find_lockowner_str(clientid_t *clid, struct xdr_netobj *owner, return NULL; } +static void nfs4_unhash_lockowner(struct nfs4_stateowner *sop) +{ + unhash_lockowner(lockowner(sop)); +} + static void nfs4_free_lockowner(struct nfs4_stateowner *sop) { struct nfs4_lockowner *lo = lockowner(sop); @@ -4768,7 +4792,8 @@ static void nfs4_free_lockowner(struct nfs4_stateowner *sop) } static const struct nfs4_stateowner_operations lockowner_ops = { - .so_free = nfs4_free_lockowner, + .so_unhash = nfs4_unhash_lockowner, + .so_free = nfs4_free_lockowner, }; /* diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h index 9cba295812f6..232246039db0 100644 --- a/fs/nfsd/state.h +++ b/fs/nfsd/state.h @@ -335,6 +335,7 @@ struct nfs4_replay { struct nfs4_stateowner; struct nfs4_stateowner_operations { + void (*so_unhash)(struct nfs4_stateowner *); void (*so_free)(struct nfs4_stateowner *); }; |