nfsd4: add a helper function to decide if stateid is delegation
[safe/jmp/linux-2.6] / fs / nfsd / nfs4state.c
index d6ca2be..d555585 100644 (file)
@@ -2048,6 +2048,11 @@ static int check_stateid_generation(stateid_t *in, stateid_t *ref)
        return nfs_ok;
 }
 
+static int is_delegation_stateid(stateid_t *stateid)
+{
+       return stateid->si_fileid == 0;
+}
+
 /*
 * Checks for stateid operations
 */
@@ -2056,13 +2061,9 @@ nfs4_preprocess_stateid_op(struct svc_fh *current_fh, stateid_t *stateid, int fl
 {
        struct nfs4_stateid *stp = NULL;
        struct nfs4_delegation *dp = NULL;
-       stateid_t *stidp;
        struct inode *ino = current_fh->fh_dentry->d_inode;
        __be32 status;
 
-       dprintk("NFSD: preprocess_stateid_op: stateid = (%08x/%08x/%08x/%08x)\n",
-               stateid->si_boot, stateid->si_stateownerid, 
-               stateid->si_fileid, stateid->si_generation); 
        if (filpp)
                *filpp = NULL;
 
@@ -2077,47 +2078,38 @@ nfs4_preprocess_stateid_op(struct svc_fh *current_fh, stateid_t *stateid, int fl
                goto out;
 
        status = nfserr_bad_stateid;
-       if (!stateid->si_fileid) { /* delegation stateid */
+       if (is_delegation_stateid(stateid)) {
                dp = find_delegation_stateid(ino, stateid);
-               if (!dp) {
-                       dprintk("NFSD: delegation stateid not found\n");
+               if (!dp)
                        goto out;
-               }
-               stidp = &dp->dl_stateid;
-               status = check_stateid_generation(stateid, stidp);
+               status = check_stateid_generation(stateid, &dp->dl_stateid);
+               if (status)
+                       goto out;
+               status = nfs4_check_delegmode(dp, flags);
                if (status)
                        goto out;
+               renew_client(dp->dl_client);
+               if (flags & DELEG_RET)
+                       unhash_delegation(dp);
+               if (filpp)
+                       *filpp = dp->dl_vfs_file;
        } else { /* open or lock stateid */
                stp = find_stateid(stateid, flags);
-               if (!stp) {
-                       dprintk("NFSD: open or lock stateid not found\n");
+               if (!stp)
                        goto out;
-               }
                if ((flags & CHECK_FH) && nfs4_check_fh(current_fh, stp))
                        goto out;
                if (!stp->st_stateowner->so_confirmed)
                        goto out;
-               stidp = &stp->st_stateid;
-               status = check_stateid_generation(stateid, stidp);
+               status = check_stateid_generation(stateid, &stp->st_stateid);
                if (status)
                        goto out;
-       }
-       if (stp) {
                status = nfs4_check_openmode(stp, flags);
                if (status)
                        goto out;
                renew_client(stp->st_stateowner->so_client);
                if (filpp)
                        *filpp = stp->st_vfs_file;
-       } else {
-               status = nfs4_check_delegmode(dp, flags);
-               if (status)
-                       goto out;
-               renew_client(dp->dl_client);
-               if (flags & DELEG_RET)
-                       unhash_delegation(dp);
-               if (filpp)
-                       *filpp = dp->dl_vfs_file;
        }
        status = nfs_ok;
 out: