[PATCH] nfsd4: simplify process-open1 logic
[sfrench/cifs-2.6.git] / fs / nfsd / nfs4state.c
index 578ea521c82749a0fc2799bad005cba58743fdaa..b92dc9e0897324640c3d728768674c461ff102f5 100644 (file)
@@ -1178,7 +1178,6 @@ release_stateid(struct nfs4_stateid *stp, int flags)
                locks_remove_posix(filp, (fl_owner_t) stp->st_stateowner);
        put_nfs4_file(stp->st_file);
        kmem_cache_free(stateid_slab, stp);
-       stp = NULL;
 }
 
 static void
@@ -1191,22 +1190,6 @@ move_to_close_lru(struct nfs4_stateowner *sop)
        sop->so_time = get_seconds();
 }
 
-static void
-release_state_owner(struct nfs4_stateid *stp, int flag)
-{
-       struct nfs4_stateowner *sop = stp->st_stateowner;
-
-       dprintk("NFSD: release_state_owner\n");
-       release_stateid(stp, flag);
-
-       /* place unused nfs4_stateowners on so_close_lru list to be
-        * released by the laundromat service after the lease period
-        * to enable us to handle CLOSE replay
-        */
-       if (sop->so_confirmed && list_empty(&sop->so_stateids))
-               move_to_close_lru(sop);
-}
-
 static int
 cmp_owner_str(struct nfs4_stateowner *sop, struct xdr_netobj *owner, clientid_t *clid) {
        return ((sop->so_owner.len == owner->len) && 
@@ -1446,92 +1429,61 @@ static struct lock_manager_operations nfsd_lease_mng_ops = {
 };
 
 
-/*
- * nfsd4_process_open1()
- *     lookup stateowner.
- *             found:
- *                     check confirmed 
- *                             confirmed:
- *                                     check seqid
- *                             not confirmed:
- *                                     delete owner
- *                                     create new owner
- *             notfound:
- *                     verify clientid
- *                     create new owner
- *
- * called with nfs4_lock_state() held.
- */
 int
 nfsd4_process_open1(struct nfsd4_open *open)
 {
-       int status;
        clientid_t *clientid = &open->op_clientid;
        struct nfs4_client *clp = NULL;
        unsigned int strhashval;
        struct nfs4_stateowner *sop = NULL;
 
-       status = nfserr_inval;
        if (!check_name(open->op_owner))
-               goto out;
+               return nfserr_inval;
 
        if (STALE_CLIENTID(&open->op_clientid))
                return nfserr_stale_clientid;
 
        strhashval = ownerstr_hashval(clientid->cl_id, open->op_owner);
        sop = find_openstateowner_str(strhashval, open);
-       if (sop) {
-               open->op_stateowner = sop;
-               /* check for replay */
-               if (open->op_seqid == sop->so_seqid - 1){
-                       if (sop->so_replay.rp_buflen)
-                               return NFSERR_REPLAY_ME;
-                       else {
-                               /* The original OPEN failed so spectacularly
-                                * that we don't even have replay data saved!
-                                * Therefore, we have no choice but to continue
-                                * processing this OPEN; presumably, we'll
-                                * fail again for the same reason.
-                                */
-                               dprintk("nfsd4_process_open1:"
-                                       " replay with no replay cache\n");
-                               goto renew;
-                       }
-               } else if (sop->so_confirmed) {
-                       if (open->op_seqid == sop->so_seqid)
-                               goto renew;
-                       status = nfserr_bad_seqid;
-                       goto out;
-               } else {
-                       /* If we get here, we received an OPEN for an
-                        * unconfirmed nfs4_stateowner. Since the seqid's are
-                        * different, purge the existing nfs4_stateowner, and
-                        * instantiate a new one.
-                        */
-                       clp = sop->so_client;
-                       release_stateowner(sop);
-               }
-       } else {
-               /* nfs4_stateowner not found.
-                * Verify clientid and instantiate new nfs4_stateowner.
-                * If verify fails this is presumably the result of the
-                * client's lease expiring.
-                */
-               status = nfserr_expired;
+       open->op_stateowner = sop;
+       if (!sop) {
+               /* Make sure the client's lease hasn't expired. */
                clp = find_confirmed_client(clientid);
                if (clp == NULL)
-                       goto out;
+                       return nfserr_expired;
+               goto renew;
        }
-       status = nfserr_resource;
-       sop = alloc_init_open_stateowner(strhashval, clp, open);
-       if (sop == NULL)
-               goto out;
-       open->op_stateowner = sop;
+       if (!sop->so_confirmed) {
+               /* Replace unconfirmed owners without checking for replay. */
+               clp = sop->so_client;
+               release_stateowner(sop);
+               open->op_stateowner = NULL;
+               goto renew;
+       }
+       if (open->op_seqid == sop->so_seqid - 1) {
+               if (sop->so_replay.rp_buflen)
+                       return NFSERR_REPLAY_ME;
+               /* The original OPEN failed so spectacularly
+                * that we don't even have replay data saved!
+                * Therefore, we have no choice but to continue
+                * processing this OPEN; presumably, we'll
+                * fail again for the same reason.
+                */
+               dprintk("nfsd4_process_open1: replay with no replay cache\n");
+               goto renew;
+       }
+       if (open->op_seqid != sop->so_seqid)
+               return nfserr_bad_seqid;
 renew:
-       status = nfs_ok;
+       if (open->op_stateowner == NULL) {
+               sop = alloc_init_open_stateowner(strhashval, clp, open);
+               if (sop == NULL)
+                       return nfserr_resource;
+               open->op_stateowner = sop;
+       }
+       list_del_init(&sop->so_close_lru);
        renew_client(sop->so_client);
-out:
-       return status;
+       return nfs_ok;
 }
 
 static inline int
@@ -2423,15 +2375,19 @@ nfsd4_close(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_clos
                                        CHECK_FH | OPEN_STATE | CLOSE_STATE,
                                        &close->cl_stateowner, &stp, NULL)))
                goto out; 
-       /*
-       *  Return success, but first update the stateid.
-       */
        status = nfs_ok;
        update_stateid(&stp->st_stateid);
        memcpy(&close->cl_stateid, &stp->st_stateid, sizeof(stateid_t));
 
-       /* release_state_owner() calls nfsd_close() if needed */
-       release_state_owner(stp, OPEN_STATE);
+       /* release_stateid() calls nfsd_close() if needed */
+       release_stateid(stp, OPEN_STATE);
+
+       /* place unused nfs4_stateowners on so_close_lru list to be
+        * released by the laundromat service after the lease period
+        * to enable us to handle CLOSE replay
+        */
+       if (list_empty(&close->cl_stateowner->so_stateids))
+               move_to_close_lru(close->cl_stateowner);
 out:
        if (close->cl_stateowner) {
                nfs4_get_stateowner(close->cl_stateowner);
@@ -3002,9 +2958,10 @@ check_for_locks(struct file *filp, struct nfs4_stateowner *lowner)
 
        lock_kernel();
        for (flpp = &inode->i_flock; *flpp != NULL; flpp = &(*flpp)->fl_next) {
-               if ((*flpp)->fl_owner == (fl_owner_t)lowner)
+               if ((*flpp)->fl_owner == (fl_owner_t)lowner) {
                        status = 1;
                        goto out;
+               }
        }
 out:
        unlock_kernel();