nfsd4: extend the client_lock to cover cl_lru

To be used later on to hold a reference count on the client while in use by a
nfsv4.1 compound.

Signed-off-by: Benny Halevy <bhalevy@panasas.com>
Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
This commit is contained in:
Benny Halevy 2010-05-12 00:13:04 +03:00 коммит произвёл J. Bruce Fields
Родитель 328efbab0f
Коммит 36acb66bda
1 изменённых файлов: 26 добавлений и 15 удалений

Просмотреть файл

@ -250,7 +250,7 @@ unhash_delegation(struct nfs4_delegation *dp)
* SETCLIENTID state * SETCLIENTID state
*/ */
/* client_lock protects the session hash table */ /* client_lock protects the client lru list and session hash table */
static DEFINE_SPINLOCK(client_lock); static DEFINE_SPINLOCK(client_lock);
/* Hash tables for nfs4_clientid state */ /* Hash tables for nfs4_clientid state */
@ -628,8 +628,9 @@ free_session(struct kref *kref)
kfree(ses); kfree(ses);
} }
/* must be called under the client_lock */
static inline void static inline void
renew_client(struct nfs4_client *clp) renew_client_locked(struct nfs4_client *clp)
{ {
/* /*
* Move client to the end to the LRU list. * Move client to the end to the LRU list.
@ -641,6 +642,14 @@ renew_client(struct nfs4_client *clp)
clp->cl_time = get_seconds(); clp->cl_time = get_seconds();
} }
static inline void
renew_client(struct nfs4_client *clp)
{
spin_lock(&client_lock);
renew_client_locked(clp);
spin_unlock(&client_lock);
}
/* SETCLIENTID and SETCLIENTID_CONFIRM Helper functions */ /* SETCLIENTID and SETCLIENTID_CONFIRM Helper functions */
static int static int
STALE_CLIENTID(clientid_t *clid) STALE_CLIENTID(clientid_t *clid)
@ -706,14 +715,14 @@ expire_client(struct nfs4_client *clp)
list_del_init(&dp->dl_recall_lru); list_del_init(&dp->dl_recall_lru);
unhash_delegation(dp); unhash_delegation(dp);
} }
list_del(&clp->cl_idhash);
list_del(&clp->cl_strhash);
list_del(&clp->cl_lru);
while (!list_empty(&clp->cl_openowners)) { while (!list_empty(&clp->cl_openowners)) {
sop = list_entry(clp->cl_openowners.next, struct nfs4_stateowner, so_perclient); sop = list_entry(clp->cl_openowners.next, struct nfs4_stateowner, so_perclient);
release_openowner(sop); release_openowner(sop);
} }
list_del(&clp->cl_idhash);
list_del(&clp->cl_strhash);
spin_lock(&client_lock); spin_lock(&client_lock);
list_del(&clp->cl_lru);
while (!list_empty(&clp->cl_sessions)) { while (!list_empty(&clp->cl_sessions)) {
struct nfsd4_session *ses; struct nfsd4_session *ses;
ses = list_entry(clp->cl_sessions.next, struct nfsd4_session, ses = list_entry(clp->cl_sessions.next, struct nfsd4_session,
@ -848,8 +857,7 @@ add_to_unconfirmed(struct nfs4_client *clp, unsigned int strhashval)
list_add(&clp->cl_strhash, &unconf_str_hashtbl[strhashval]); list_add(&clp->cl_strhash, &unconf_str_hashtbl[strhashval]);
idhashval = clientid_hashval(clp->cl_clientid.cl_id); idhashval = clientid_hashval(clp->cl_clientid.cl_id);
list_add(&clp->cl_idhash, &unconf_id_hashtbl[idhashval]); list_add(&clp->cl_idhash, &unconf_id_hashtbl[idhashval]);
list_add_tail(&clp->cl_lru, &client_lru); renew_client(clp);
clp->cl_time = get_seconds();
} }
static void static void
@ -1447,15 +1455,12 @@ nfsd4_sequence(struct svc_rqst *rqstp,
out: out:
/* Hold a session reference until done processing the compound. */ /* Hold a session reference until done processing the compound. */
if (cstate->session)
nfsd4_get_session(cstate->session);
spin_unlock(&client_lock);
/* Renew the clientid on success and on replay */
if (cstate->session) { if (cstate->session) {
nfs4_lock_state(); nfsd4_get_session(cstate->session);
renew_client(session->se_client); /* Renew the clientid on success and on replay */
nfs4_unlock_state(); renew_client_locked(session->se_client);
} }
spin_unlock(&client_lock);
dprintk("%s: return %d\n", __func__, ntohl(status)); dprintk("%s: return %d\n", __func__, ntohl(status));
return status; return status;
} }
@ -2564,6 +2569,8 @@ nfs4_laundromat(void)
dprintk("NFSD: laundromat service - starting\n"); dprintk("NFSD: laundromat service - starting\n");
if (locks_in_grace()) if (locks_in_grace())
nfsd4_end_grace(); nfsd4_end_grace();
INIT_LIST_HEAD(&reaplist);
spin_lock(&client_lock);
list_for_each_safe(pos, next, &client_lru) { list_for_each_safe(pos, next, &client_lru) {
clp = list_entry(pos, struct nfs4_client, cl_lru); clp = list_entry(pos, struct nfs4_client, cl_lru);
if (time_after((unsigned long)clp->cl_time, (unsigned long)cutoff)) { if (time_after((unsigned long)clp->cl_time, (unsigned long)cutoff)) {
@ -2572,12 +2579,16 @@ nfs4_laundromat(void)
clientid_val = t; clientid_val = t;
break; break;
} }
list_move(&clp->cl_lru, &reaplist);
}
spin_unlock(&client_lock);
list_for_each_safe(pos, next, &reaplist) {
clp = list_entry(pos, struct nfs4_client, cl_lru);
dprintk("NFSD: purging unused client (clientid %08x)\n", dprintk("NFSD: purging unused client (clientid %08x)\n",
clp->cl_clientid.cl_id); clp->cl_clientid.cl_id);
nfsd4_remove_clid_dir(clp); nfsd4_remove_clid_dir(clp);
expire_client(clp); expire_client(clp);
} }
INIT_LIST_HEAD(&reaplist);
spin_lock(&recall_lock); spin_lock(&recall_lock);
list_for_each_safe(pos, next, &del_recall_lru) { list_for_each_safe(pos, next, &del_recall_lru) {
dp = list_entry (pos, struct nfs4_delegation, dl_recall_lru); dp = list_entry (pos, struct nfs4_delegation, dl_recall_lru);