nfsd4: shut down callback queue outside state lock
[safe/jmp/linux-2.6] / fs / nfsd / nfs4state.c
index 98aa7e8..4a27347 100644 (file)
@@ -190,7 +190,7 @@ alloc_init_deleg(struct nfs4_client *clp, struct nfs4_stateid *stp, struct svc_f
        dp->dl_vfs_file = stp->st_vfs_file;
        dp->dl_type = type;
        dp->dl_ident = cb->cb_ident;
-       dp->dl_stateid.si_boot = get_seconds();
+       dp->dl_stateid.si_boot = boot_time;
        dp->dl_stateid.si_stateownerid = current_delegid++;
        dp->dl_stateid.si_fileid = 0;
        dp->dl_stateid.si_generation = 0;
@@ -701,6 +701,22 @@ free_client(struct nfs4_client *clp)
        kfree(clp);
 }
 
+void
+release_session_client(struct nfsd4_session *session)
+{
+       struct nfs4_client *clp = session->se_client;
+
+       if (!atomic_dec_and_lock(&clp->cl_refcount, &client_lock))
+               return;
+       if (is_client_expired(clp)) {
+               free_client(clp);
+               session->se_client = NULL;
+       } else
+               renew_client_locked(clp);
+       spin_unlock(&client_lock);
+       nfsd4_put_session(session);
+}
+
 /* must be called under the client_lock */
 static inline void
 unhash_client_locked(struct nfs4_client *clp)
@@ -1411,8 +1427,10 @@ nfsd4_destroy_session(struct svc_rqst *r,
        unhash_session(ses);
        spin_unlock(&client_lock);
 
+       nfs4_lock_state();
        /* wait for callbacks */
        nfsd4_set_callback_client(ses->se_client, NULL);
+       nfs4_unlock_state();
        nfsd4_put_session(ses);
        status = nfs_ok;
 out:
@@ -1476,8 +1494,7 @@ out:
        /* Hold a session reference until done processing the compound. */
        if (cstate->session) {
                nfsd4_get_session(cstate->session);
-               /* Renew the clientid on success and on replay */
-               renew_client_locked(session->se_client);
+               atomic_inc(&session->se_client->cl_refcount);
        }
        spin_unlock(&client_lock);
        dprintk("%s: return %d\n", __func__, ntohl(status));
@@ -1485,6 +1502,35 @@ out:
 }
 
 __be32
+nfsd4_reclaim_complete(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_reclaim_complete *rc)
+{
+       if (rc->rca_one_fs) {
+               if (!cstate->current_fh.fh_dentry)
+                       return nfserr_nofilehandle;
+               /*
+                * We don't take advantage of the rca_one_fs case.
+                * That's OK, it's optional, we can safely ignore it.
+                */
+                return nfs_ok;
+       }
+       nfs4_lock_state();
+       if (is_client_expired(cstate->session->se_client)) {
+               nfs4_unlock_state();
+               /*
+                * The following error isn't really legal.
+                * But we only get here if the client just explicitly
+                * destroyed the client.  Surely it no longer cares what
+                * error it gets back on an operation for the dead
+                * client.
+                */
+               return nfserr_stale_clientid;
+       }
+       nfsd4_create_clid_dir(cstate->session->se_client);
+       nfs4_unlock_state();
+       return nfs_ok;
+}
+
+__be32
 nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
                  struct nfsd4_setclientid *setclid)
 {
@@ -1711,12 +1757,12 @@ alloc_init_file(struct inode *ino)
                INIT_LIST_HEAD(&fp->fi_hash);
                INIT_LIST_HEAD(&fp->fi_stateids);
                INIT_LIST_HEAD(&fp->fi_delegations);
-               spin_lock(&recall_lock);
-               list_add(&fp->fi_hash, &file_hashtbl[hashval]);
-               spin_unlock(&recall_lock);
                fp->fi_inode = igrab(ino);
                fp->fi_id = current_fileid++;
                fp->fi_had_conflict = false;
+               spin_lock(&recall_lock);
+               list_add(&fp->fi_hash, &file_hashtbl[hashval]);
+               spin_unlock(&recall_lock);
                return fp;
        }
        return NULL;
@@ -1838,7 +1884,7 @@ init_stateid(struct nfs4_stateid *stp, struct nfs4_file *fp, struct nfsd4_open *
        stp->st_stateowner = sop;
        get_nfs4_file(fp);
        stp->st_file = fp;
-       stp->st_stateid.si_boot = get_seconds();
+       stp->st_stateid.si_boot = boot_time;
        stp->st_stateid.si_stateownerid = sop->so_id;
        stp->st_stateid.si_fileid = fp->fi_id;
        stp->st_stateid.si_generation = 0;
@@ -2493,10 +2539,8 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf
        }
        memcpy(&open->op_stateid, &stp->st_stateid, sizeof(stateid_t));
 
-       if (nfsd4_has_session(&resp->cstate)) {
+       if (nfsd4_has_session(&resp->cstate))
                open->op_stateowner->so_confirmed = 1;
-               nfsd4_create_clid_dir(open->op_stateowner->so_client);
-       }
 
        /*
        * Attempt to hand out a delegation. No error return, because the
@@ -2598,7 +2642,13 @@ nfs4_laundromat(void)
                                clientid_val = t;
                        break;
                }
-               list_move(&clp->cl_lru, &reaplist);
+               if (atomic_read(&clp->cl_refcount)) {
+                       dprintk("NFSD: client in use (clientid %08x)\n",
+                               clp->cl_clientid.cl_id);
+                       continue;
+               }
+               unhash_client_locked(clp);
+               list_add(&clp->cl_lru, &reaplist);
        }
        spin_unlock(&client_lock);
        list_for_each_safe(pos, next, &reaplist) {
@@ -2683,39 +2733,11 @@ nfs4_check_fh(struct svc_fh *fhp, struct nfs4_stateid *stp)
 static int
 STALE_STATEID(stateid_t *stateid)
 {
-       if (time_after((unsigned long)boot_time,
-                       (unsigned long)stateid->si_boot)) {
-               dprintk("NFSD: stale stateid " STATEID_FMT "!\n",
-                       STATEID_VAL(stateid));
-               return 1;
-       }
-       return 0;
-}
-
-static int
-EXPIRED_STATEID(stateid_t *stateid)
-{
-       if (time_before((unsigned long)boot_time,
-                       ((unsigned long)stateid->si_boot)) &&
-           time_before((unsigned long)(stateid->si_boot + nfsd4_lease), get_seconds())) {
-               dprintk("NFSD: expired stateid " STATEID_FMT "!\n",
-                       STATEID_VAL(stateid));
-               return 1;
-       }
-       return 0;
-}
-
-static __be32
-stateid_error_map(stateid_t *stateid)
-{
-       if (STALE_STATEID(stateid))
-               return nfserr_stale_stateid;
-       if (EXPIRED_STATEID(stateid))
-               return nfserr_expired;
-
-       dprintk("NFSD: bad stateid " STATEID_FMT "!\n",
+       if (stateid->si_boot == boot_time)
+               return 0;
+       dprintk("NFSD: stale stateid " STATEID_FMT "!\n",
                STATEID_VAL(stateid));
-       return nfserr_bad_stateid;
+       return 1;
 }
 
 static inline int
@@ -2839,10 +2861,8 @@ nfs4_preprocess_stateid_op(struct nfsd4_compound_state *cstate,
        status = nfserr_bad_stateid;
        if (is_delegation_stateid(stateid)) {
                dp = find_delegation_stateid(ino, stateid);
-               if (!dp) {
-                       status = stateid_error_map(stateid);
+               if (!dp)
                        goto out;
-               }
                status = check_stateid_generation(stateid, &dp->dl_stateid,
                                                  flags);
                if (status)
@@ -2855,10 +2875,8 @@ nfs4_preprocess_stateid_op(struct nfsd4_compound_state *cstate,
                        *filpp = dp->dl_vfs_file;
        } else { /* open or lock stateid */
                stp = find_stateid(stateid, flags);
-               if (!stp) {
-                       status = stateid_error_map(stateid);
+               if (!stp)
                        goto out;
-               }
                if (nfs4_check_fh(current_fh, stp))
                        goto out;
                if (!stp->st_stateowner->so_confirmed)
@@ -2930,7 +2948,7 @@ nfs4_preprocess_seqid_op(struct nfsd4_compound_state *cstate, u32 seqid,
                 */
                sop = search_close_lru(stateid->si_stateownerid, flags);
                if (sop == NULL)
-                       return stateid_error_map(stateid);
+                       return nfserr_bad_stateid;
                *sopp = sop;
                goto check_replay;
        }
@@ -3197,10 +3215,8 @@ nfsd4_delegreturn(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
        if (!is_delegation_stateid(stateid))
                goto out;
        dp = find_delegation_stateid(inode, stateid);
-       if (!dp) {
-               status = stateid_error_map(stateid);
+       if (!dp)
                goto out;
-       }
        status = check_stateid_generation(stateid, &dp->dl_stateid, flags);
        if (status)
                goto out;
@@ -3426,7 +3442,7 @@ alloc_init_lock_stateid(struct nfs4_stateowner *sop, struct nfs4_file *fp, struc
        stp->st_stateowner = sop;
        get_nfs4_file(fp);
        stp->st_file = fp;
-       stp->st_stateid.si_boot = get_seconds();
+       stp->st_stateid.si_boot = boot_time;
        stp->st_stateid.si_stateownerid = sop->so_id;
        stp->st_stateid.si_fileid = fp->fi_id;
        stp->st_stateid.si_generation = 0;
@@ -4106,8 +4122,8 @@ nfs4_state_shutdown(void)
        nfs4_lock_state();
        nfs4_release_reclaim();
        __nfs4_state_shutdown();
-       nfsd4_destroy_callback_queue();
        nfs4_unlock_state();
+       nfsd4_destroy_callback_queue();
 }
 
 /*