NFSD: Remove the ex_pathname field from struct svc_export
[deliverable/linux.git] / fs / nfsd / nfs4state.c
index c28432a802102fd33d765f7b0f7d264ec19b01d9..0cd346477f29ce511e7f8b5579090fbba797c52c 100644 (file)
@@ -60,9 +60,6 @@ static u64 current_sessionid = 1;
 #define ONE_STATEID(stateid)  (!memcmp((stateid), &onestateid, sizeof(stateid_t)))
 
 /* forward declarations */
-static struct nfs4_stateid * find_stateid(stateid_t *stid, int flags);
-static struct nfs4_delegation * search_for_delegation(stateid_t *stid);
-static struct nfs4_delegation * find_delegation_stateid(struct inode *ino, stateid_t *stid);
 static int check_for_locks(struct nfs4_file *filp, struct nfs4_lockowner *lowner);
 
 /* Locking: */
@@ -160,7 +157,7 @@ static struct list_head     open_ownerstr_hashtbl[OPEN_OWNER_HASH_SIZE];
 #define FILE_HASH_BITS                   8
 #define FILE_HASH_SIZE                  (1 << FILE_HASH_BITS)
 
-/* hash table for (open)nfs4_stateid */
+/* hash table for (open)nfs4_ol_stateid */
 #define STATEID_HASH_BITS              10
 #define STATEID_HASH_SIZE              (1 << STATEID_HASH_BITS)
 #define STATEID_HASH_MASK              (STATEID_HASH_SIZE - 1)
@@ -171,9 +168,9 @@ static unsigned int file_hashval(struct inode *ino)
        return hash_ptr(ino, FILE_HASH_BITS);
 }
 
-static unsigned int stateid_hashval(u32 owner_id, u32 file_id)
+static unsigned int stateid_hashval(stateid_t *s)
 {
-       return (owner_id + file_id) & STATEID_HASH_MASK;
+       return opaque_hashval(&s->si_opaque, sizeof(stateid_opaque_t)) & STATEID_HASH_MASK;
 }
 
 static struct list_head file_hashtbl[FILE_HASH_SIZE];
@@ -219,8 +216,17 @@ static void nfs4_file_put_access(struct nfs4_file *fp, int oflag)
                __nfs4_file_put_access(fp, oflag);
 }
 
+static inline void hash_stid(struct nfs4_stid *stid)
+{
+       stateid_t *s = &stid->sc_stateid;
+       unsigned int hashval;
+
+       hashval = stateid_hashval(s);
+       list_add(&stid->sc_hash, &stateid_hashtbl[hashval]);
+}
+
 static struct nfs4_delegation *
-alloc_init_deleg(struct nfs4_client *clp, struct nfs4_stateid *stp, struct svc_fh *current_fh, u32 type)
+alloc_init_deleg(struct nfs4_client *clp, struct nfs4_ol_stateid *stp, struct svc_fh *current_fh, u32 type)
 {
        struct nfs4_delegation *dp;
        struct nfs4_file *fp = stp->st_file;
@@ -248,10 +254,12 @@ alloc_init_deleg(struct nfs4_client *clp, struct nfs4_stateid *stp, struct svc_f
        get_nfs4_file(fp);
        dp->dl_file = fp;
        dp->dl_type = type;
-       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 = 1;
+       dp->dl_stid.sc_type = NFS4_DELEG_STID;
+       dp->dl_stid.sc_stateid.si_boot = boot_time;
+       dp->dl_stid.sc_stateid.si_stateownerid = current_delegid++;
+       dp->dl_stid.sc_stateid.si_fileid = 0;
+       dp->dl_stid.sc_stateid.si_generation = 1;
+       hash_stid(&dp->dl_stid);
        fh_copy_shallow(&dp->dl_fh, &current_fh->fh_handle);
        dp->dl_time = 0;
        atomic_set(&dp->dl_count, 1);
@@ -284,6 +292,7 @@ static void nfs4_put_deleg_lease(struct nfs4_file *fp)
 static void
 unhash_delegation(struct nfs4_delegation *dp)
 {
+       list_del_init(&dp->dl_stid.sc_hash);
        list_del_init(&dp->dl_perclnt);
        spin_lock(&recall_lock);
        list_del_init(&dp->dl_perfile);
@@ -381,7 +390,7 @@ set_deny(unsigned int *deny, unsigned long bmap) {
 }
 
 static int
-test_share(struct nfs4_stateid *stp, struct nfsd4_open *open) {
+test_share(struct nfs4_ol_stateid *stp, struct nfsd4_open *open) {
        unsigned int access, deny;
 
        set_access(&access, stp->st_access_bmap);
@@ -404,14 +413,14 @@ static int nfs4_access_to_omode(u32 access)
        BUG();
 }
 
-static void unhash_generic_stateid(struct nfs4_stateid *stp)
+static void unhash_generic_stateid(struct nfs4_ol_stateid *stp)
 {
-       list_del(&stp->st_hash);
+       list_del(&stp->st_stid.sc_hash);
        list_del(&stp->st_perfile);
        list_del(&stp->st_perstateowner);
 }
 
-static void close_generic_stateid(struct nfs4_stateid *stp)
+static void close_generic_stateid(struct nfs4_ol_stateid *stp)
 {
        int i;
 
@@ -427,13 +436,13 @@ static void close_generic_stateid(struct nfs4_stateid *stp)
        stp->st_file = NULL;
 }
 
-static void free_generic_stateid(struct nfs4_stateid *stp)
+static void free_generic_stateid(struct nfs4_ol_stateid *stp)
 {
        close_generic_stateid(stp);
        kmem_cache_free(stateid_slab, stp);
 }
 
-static void release_lock_stateid(struct nfs4_stateid *stp)
+static void release_lock_stateid(struct nfs4_ol_stateid *stp)
 {
        struct file *file;
 
@@ -446,14 +455,14 @@ static void release_lock_stateid(struct nfs4_stateid *stp)
 
 static void unhash_lockowner(struct nfs4_lockowner *lo)
 {
-       struct nfs4_stateid *stp;
+       struct nfs4_ol_stateid *stp;
 
        list_del(&lo->lo_owner.so_idhash);
        list_del(&lo->lo_owner.so_strhash);
        list_del(&lo->lo_perstateid);
        while (!list_empty(&lo->lo_owner.so_stateids)) {
                stp = list_first_entry(&lo->lo_owner.so_stateids,
-                               struct nfs4_stateid, st_perstateowner);
+                               struct nfs4_ol_stateid, st_perstateowner);
                release_lock_stateid(stp);
        }
 }
@@ -465,7 +474,7 @@ static void release_lockowner(struct nfs4_lockowner *lo)
 }
 
 static void
-release_stateid_lockowners(struct nfs4_stateid *open_stp)
+release_stateid_lockowners(struct nfs4_ol_stateid *open_stp)
 {
        struct nfs4_lockowner *lo;
 
@@ -476,7 +485,7 @@ release_stateid_lockowners(struct nfs4_stateid *open_stp)
        }
 }
 
-static void release_open_stateid(struct nfs4_stateid *stp)
+static void release_open_stateid(struct nfs4_ol_stateid *stp)
 {
        unhash_generic_stateid(stp);
        release_stateid_lockowners(stp);
@@ -485,14 +494,14 @@ static void release_open_stateid(struct nfs4_stateid *stp)
 
 static void unhash_openowner(struct nfs4_openowner *oo)
 {
-       struct nfs4_stateid *stp;
+       struct nfs4_ol_stateid *stp;
 
        list_del(&oo->oo_owner.so_idhash);
        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_stateid, st_perstateowner);
+                               struct nfs4_ol_stateid, st_perstateowner);
                release_open_stateid(stp);
        }
 }
@@ -1061,6 +1070,58 @@ static void gen_confirm(struct nfs4_client *clp)
        *p++ = i++;
 }
 
+static int
+same_stateid(stateid_t *id_one, stateid_t *id_two)
+{
+       if (id_one->si_stateownerid != id_two->si_stateownerid)
+               return 0;
+       return id_one->si_fileid == id_two->si_fileid;
+}
+
+static struct nfs4_stid *find_stateid(stateid_t *t)
+{
+       struct nfs4_stid *s;
+       unsigned int hashval;
+
+       hashval = stateid_hashval(t);
+       list_for_each_entry(s, &stateid_hashtbl[hashval], sc_hash)
+               if (same_stateid(&s->sc_stateid, t))
+                       return s;
+       return NULL;
+}
+
+static struct nfs4_ol_stateid *find_ol_stateid(stateid_t *t)
+{
+       struct nfs4_stid *s;
+
+       s = find_stateid(t);
+       if (!s)
+               return NULL;
+       return openlockstateid(s);
+}
+
+static struct nfs4_stid *find_stateid_by_type(stateid_t *t, char typemask)
+{
+       struct nfs4_stid *s;
+
+       s = find_stateid(t);
+       if (!s)
+               return NULL;
+       if (typemask & s->sc_type)
+               return s;
+       return NULL;
+}
+
+static struct nfs4_ol_stateid *find_ol_stateid_by_type(stateid_t *t, char typemask)
+{
+       struct nfs4_stid *s;
+
+       s = find_stateid_by_type(t, typemask);
+       if (!s)
+               return NULL;
+       return openlockstateid(s);
+}
+
 static struct nfs4_client *create_client(struct xdr_netobj name, char *recdir,
                struct svc_rqst *rqstp, nfs4_verifier *verf)
 {
@@ -2201,7 +2262,7 @@ nfsd4_init_slabs(void)
        if (file_slab == NULL)
                goto out_nomem;
        stateid_slab = kmem_cache_create("nfsd4_stateids",
-                       sizeof(struct nfs4_stateid), 0, 0, NULL);
+                       sizeof(struct nfs4_ol_stateid), 0, 0, NULL);
        if (stateid_slab == NULL)
                goto out_nomem;
        deleg_slab = kmem_cache_create("nfsd4_delegations",
@@ -2283,26 +2344,22 @@ alloc_init_open_stateowner(unsigned int strhashval, struct nfs4_client *clp, str
 }
 
 static inline void
-init_stateid(struct nfs4_stateid *stp, struct nfs4_file *fp, struct nfsd4_open *open) {
+init_open_stateid(struct nfs4_ol_stateid *stp, struct nfs4_file *fp, struct nfsd4_open *open) {
        struct nfs4_openowner *oo = open->op_openowner;
-       unsigned int hashval = stateid_hashval(oo->oo_owner.so_id, fp->fi_id);
 
-       INIT_LIST_HEAD(&stp->st_hash);
-       INIT_LIST_HEAD(&stp->st_perstateowner);
        INIT_LIST_HEAD(&stp->st_lockowners);
-       INIT_LIST_HEAD(&stp->st_perfile);
-       list_add(&stp->st_hash, &stateid_hashtbl[hashval]);
        list_add(&stp->st_perstateowner, &oo->oo_owner.so_stateids);
        list_add(&stp->st_perfile, &fp->fi_stateids);
-       stp->st_type = NFS4_OPEN_STID;
+       stp->st_stid.sc_type = NFS4_OPEN_STID;
        stp->st_stateowner = &oo->oo_owner;
        get_nfs4_file(fp);
        stp->st_file = fp;
-       stp->st_stateid.si_boot = boot_time;
-       stp->st_stateid.si_stateownerid = oo->oo_owner.so_id;
-       stp->st_stateid.si_fileid = fp->fi_id;
+       stp->st_stid.sc_stateid.si_boot = boot_time;
+       stp->st_stid.sc_stateid.si_stateownerid = oo->oo_owner.so_id;
+       stp->st_stid.sc_stateid.si_fileid = fp->fi_id;
        /* note will be incremented before first return to client: */
-       stp->st_stateid.si_generation = 0;
+       stp->st_stid.sc_stateid.si_generation = 0;
+       hash_stid(&stp->st_stid);
        stp->st_access_bmap = 0;
        stp->st_deny_bmap = 0;
        __set_bit(open->op_share_access & ~NFS4_SHARE_WANT_MASK,
@@ -2394,7 +2451,7 @@ nfs4_share_conflict(struct svc_fh *current_fh, unsigned int deny_type)
 {
        struct inode *ino = current_fh->fh_dentry->d_inode;
        struct nfs4_file *fp;
-       struct nfs4_stateid *stp;
+       struct nfs4_ol_stateid *stp;
        __be32 ret;
 
        dprintk("NFSD: nfs4_share_conflict\n");
@@ -2537,26 +2594,21 @@ nfs4_check_delegmode(struct nfs4_delegation *dp, int flags)
                return nfs_ok;
 }
 
-static struct nfs4_delegation *
-find_delegation_file(struct nfs4_file *fp, stateid_t *stid)
+static int share_access_to_flags(u32 share_access)
 {
-       struct nfs4_delegation *dp;
+       share_access &= ~NFS4_SHARE_WANT_MASK;
 
-       spin_lock(&recall_lock);
-       list_for_each_entry(dp, &fp->fi_delegations, dl_perfile)
-               if (dp->dl_stateid.si_stateownerid == stid->si_stateownerid) {
-                       spin_unlock(&recall_lock);
-                       return dp;
-               }
-       spin_unlock(&recall_lock);
-       return NULL;
+       return share_access == NFS4_SHARE_ACCESS_READ ? RD_STATE : WR_STATE;
 }
 
-static int share_access_to_flags(u32 share_access)
+static struct nfs4_delegation *find_deleg_stateid(stateid_t *s)
 {
-       share_access &= ~NFS4_SHARE_WANT_MASK;
+       struct nfs4_stid *ret;
 
-       return share_access == NFS4_SHARE_ACCESS_READ ? RD_STATE : WR_STATE;
+       ret = find_stateid_by_type(s, NFS4_DELEG_STID);
+       if (!ret)
+               return NULL;
+       return delegstateid(ret);
 }
 
 static __be32
@@ -2566,7 +2618,7 @@ nfs4_check_deleg(struct nfs4_file *fp, struct nfsd4_open *open,
        int flags;
        __be32 status = nfserr_bad_stateid;
 
-       *dp = find_delegation_file(fp, &open->op_delegate_stateid);
+       *dp = find_deleg_stateid(&open->op_delegate_stateid);
        if (*dp == NULL)
                goto out;
        flags = share_access_to_flags(open->op_share_access);
@@ -2583,9 +2635,9 @@ out:
 }
 
 static __be32
-nfs4_check_open(struct nfs4_file *fp, struct nfsd4_open *open, struct nfs4_stateid **stpp)
+nfs4_check_open(struct nfs4_file *fp, struct nfsd4_open *open, struct nfs4_ol_stateid **stpp)
 {
-       struct nfs4_stateid *local;
+       struct nfs4_ol_stateid *local;
        struct nfs4_openowner *oo = open->op_openowner;
 
        list_for_each_entry(local, &fp->fi_stateids, st_perfile) {
@@ -2602,7 +2654,7 @@ nfs4_check_open(struct nfs4_file *fp, struct nfsd4_open *open, struct nfs4_state
        return nfs_ok;
 }
 
-static inline struct nfs4_stateid *
+static inline struct nfs4_ol_stateid *
 nfs4_alloc_stateid(void)
 {
        return kmem_cache_alloc(stateid_slab, GFP_KERNEL);
@@ -2644,11 +2696,11 @@ static __be32 nfs4_get_vfs_file(struct svc_rqst *rqstp, struct nfs4_file *fp,
 }
 
 static __be32
-nfs4_new_open(struct svc_rqst *rqstp, struct nfs4_stateid **stpp,
+nfs4_new_open(struct svc_rqst *rqstp, struct nfs4_ol_stateid **stpp,
                struct nfs4_file *fp, struct svc_fh *cur_fh,
                struct nfsd4_open *open)
 {
-       struct nfs4_stateid *stp;
+       struct nfs4_ol_stateid *stp;
        __be32 status;
 
        stp = nfs4_alloc_stateid();
@@ -2680,7 +2732,7 @@ nfsd4_truncate(struct svc_rqst *rqstp, struct svc_fh *fh,
 }
 
 static __be32
-nfs4_upgrade_open(struct svc_rqst *rqstp, struct nfs4_file *fp, struct svc_fh *cur_fh, struct nfs4_stateid *stp, struct nfsd4_open *open)
+nfs4_upgrade_open(struct svc_rqst *rqstp, struct nfs4_file *fp, struct svc_fh *cur_fh, struct nfs4_ol_stateid *stp, struct nfsd4_open *open)
 {
        u32 op_share_access = open->op_share_access & ~NFS4_SHARE_WANT_MASK;
        bool new_access;
@@ -2792,7 +2844,7 @@ static int nfs4_set_delegation(struct nfs4_delegation *dp, int flag)
  * Attempt to hand out a delegation.
  */
 static void
-nfs4_open_delegation(struct svc_fh *fh, struct nfsd4_open *open, struct nfs4_stateid *stp)
+nfs4_open_delegation(struct svc_fh *fh, struct nfsd4_open *open, struct nfs4_ol_stateid *stp)
 {
        struct nfs4_delegation *dp;
        struct nfs4_openowner *oo = container_of(stp->st_stateowner, struct nfs4_openowner, oo_owner);
@@ -2833,10 +2885,10 @@ nfs4_open_delegation(struct svc_fh *fh, struct nfsd4_open *open, struct nfs4_sta
        if (status)
                goto out_free;
 
-       memcpy(&open->op_delegate_stateid, &dp->dl_stateid, sizeof(dp->dl_stateid));
+       memcpy(&open->op_delegate_stateid, &dp->dl_stid.sc_stateid, sizeof(dp->dl_stid.sc_stateid));
 
        dprintk("NFSD: delegation stateid=" STATEID_FMT "\n",
-               STATEID_VAL(&dp->dl_stateid));
+               STATEID_VAL(&dp->dl_stid.sc_stateid));
 out:
        if (open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS
                        && flag == NFS4_OPEN_DELEGATE_NONE
@@ -2860,7 +2912,7 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf
        struct nfsd4_compoundres *resp = rqstp->rq_resp;
        struct nfs4_file *fp = NULL;
        struct inode *ino = current_fh->fh_dentry->d_inode;
-       struct nfs4_stateid *stp = NULL;
+       struct nfs4_ol_stateid *stp = NULL;
        struct nfs4_delegation *dp = NULL;
        __be32 status;
 
@@ -2903,15 +2955,15 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf
                status = nfs4_new_open(rqstp, &stp, fp, current_fh, open);
                if (status)
                        goto out;
-               init_stateid(stp, fp, open);
+               init_open_stateid(stp, fp, open);
                status = nfsd4_truncate(rqstp, current_fh, open);
                if (status) {
                        release_open_stateid(stp);
                        goto out;
                }
        }
-       update_stateid(&stp->st_stateid);
-       memcpy(&open->op_stateid, &stp->st_stateid, sizeof(stateid_t));
+       update_stateid(&stp->st_stid.sc_stateid);
+       memcpy(&open->op_stateid, &stp->st_stid.sc_stateid, sizeof(stateid_t));
 
        if (nfsd4_has_session(&resp->cstate))
                open->op_openowner->oo_confirmed = 1;
@@ -2925,7 +2977,7 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf
        status = nfs_ok;
 
        dprintk("%s: stateid=" STATEID_FMT "\n", __func__,
-               STATEID_VAL(&stp->st_stateid));
+               STATEID_VAL(&stp->st_stid.sc_stateid));
 out:
        if (fp)
                put_nfs4_file(fp);
@@ -3094,7 +3146,7 @@ static struct nfs4_openowner * search_close_lru(u32 st_id)
 }
 
 static inline int
-nfs4_check_fh(struct svc_fh *fhp, struct nfs4_stateid *stp)
+nfs4_check_fh(struct svc_fh *fhp, struct nfs4_ol_stateid *stp)
 {
        return fhp->fh_dentry->d_inode != stp->st_file->fi_inode;
 }
@@ -3125,7 +3177,7 @@ access_permit_write(unsigned long access_bmap)
 }
 
 static
-__be32 nfs4_check_openmode(struct nfs4_stateid *stp, int flags)
+__be32 nfs4_check_openmode(struct nfs4_ol_stateid *stp, int flags)
 {
         __be32 status = nfserr_openmode;
 
@@ -3209,29 +3261,26 @@ static int is_delegation_stateid(stateid_t *stateid)
 
 __be32 nfs4_validate_stateid(stateid_t *stateid, bool has_session)
 {
-       struct nfs4_stateid *stp = NULL;
-       __be32 status = nfserr_stale_stateid;
+       struct nfs4_stid *s;
+       struct nfs4_ol_stateid *ols;
+       __be32 status;
 
        if (STALE_STATEID(stateid))
-               goto out;
-
-       status = nfserr_expired;
-       stp = find_stateid(stateid, 0);
-       if (!stp)
-               goto out;
-       status = nfserr_bad_stateid;
-
-       if (stp->st_stateowner->so_is_open_owner
-           && !openowner(stp->st_stateowner)->oo_confirmed)
-               goto out;
+               return nfserr_stale_stateid;
 
-       status = check_stateid_generation(stateid, &stp->st_stateid, has_session);
+       s = find_stateid(stateid);
+       if (!s)
+                return nfserr_stale_stateid;
+       status = check_stateid_generation(stateid, &s->sc_stateid, has_session);
        if (status)
-               goto out;
-
-       status = nfs_ok;
-out:
-       return status;
+               return status;
+       if (!(s->sc_type & (NFS4_OPEN_STID | NFS4_LOCK_STID)))
+               return nfs_ok;
+       ols = openlockstateid(s);
+       if (ols->st_stateowner->so_is_open_owner
+           && !openowner(ols->st_stateowner)->oo_confirmed)
+               return nfserr_bad_stateid;
+       return nfs_ok;
 }
 
 /*
@@ -3241,7 +3290,8 @@ __be32
 nfs4_preprocess_stateid_op(struct nfsd4_compound_state *cstate,
                           stateid_t *stateid, int flags, struct file **filpp)
 {
-       struct nfs4_stateid *stp = NULL;
+       struct nfs4_stid *s;
+       struct nfs4_ol_stateid *stp = NULL;
        struct nfs4_delegation *dp = NULL;
        struct svc_fh *current_fh = &cstate->current_fh;
        struct inode *ino = current_fh->fh_dentry->d_inode;
@@ -3265,13 +3315,14 @@ nfs4_preprocess_stateid_op(struct nfsd4_compound_state *cstate,
         * but that we can't find, is expired:
         */
        status = nfserr_expired;
-       if (is_delegation_stateid(stateid)) {
-               dp = find_delegation_stateid(ino, stateid);
-               if (!dp)
-                       goto out;
-               status = check_stateid_generation(stateid, &dp->dl_stateid, nfsd4_has_session(cstate));
-               if (status)
-                       goto out;
+       s = find_stateid(stateid);
+       if (!s)
+               goto out;
+       status = check_stateid_generation(stateid, &s->sc_stateid, nfsd4_has_session(cstate));
+       if (status)
+               goto out;
+       if (s->sc_type == NFS4_DELEG_STID) {
+               dp = delegstateid(s);
                status = nfs4_check_delegmode(dp, flags);
                if (status)
                        goto out;
@@ -3281,19 +3332,13 @@ nfs4_preprocess_stateid_op(struct nfsd4_compound_state *cstate,
                        BUG_ON(!*filpp);
                }
        } else { /* open or lock stateid */
-               stp = find_stateid(stateid, flags);
-               if (!stp)
-                       goto out;
+               stp = openlockstateid(s);
                status = nfserr_bad_stateid;
                if (nfs4_check_fh(current_fh, stp))
                        goto out;
                if (stp->st_stateowner->so_is_open_owner
                    && !openowner(stp->st_stateowner)->oo_confirmed)
                        goto out;
-               status = check_stateid_generation(stateid, &stp->st_stateid,
-                                                 nfsd4_has_session(cstate));
-               if (status)
-                       goto out;
                status = nfs4_check_openmode(stp, flags);
                if (status)
                        goto out;
@@ -3313,14 +3358,15 @@ out:
 static __be32
 nfsd4_free_delegation_stateid(stateid_t *stateid)
 {
-       struct nfs4_delegation *dp = search_for_delegation(stateid);
+       struct nfs4_delegation *dp = find_deleg_stateid(stateid);
        if (dp)
                return nfserr_locks_held;
+
        return nfserr_bad_stateid;
 }
 
 static __be32
-nfsd4_free_lock_stateid(struct nfs4_stateid *stp)
+nfsd4_free_lock_stateid(struct nfs4_ol_stateid *stp)
 {
        if (check_for_locks(stp->st_file, lockowner(stp->st_stateowner)))
                return nfserr_locks_held;
@@ -3347,7 +3393,7 @@ nfsd4_free_stateid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
                   struct nfsd4_free_stateid *free_stateid)
 {
        stateid_t *stateid = &free_stateid->fr_stateid;
-       struct nfs4_stateid *stp;
+       struct nfs4_ol_stateid *stp;
        __be32 ret;
 
        nfs4_lock_state();
@@ -3356,16 +3402,16 @@ nfsd4_free_stateid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
                goto out;
        }
 
-       stp = find_stateid(stateid, 0);
+       stp = find_ol_stateid(stateid);
        if (!stp) {
                ret = nfserr_bad_stateid;
                goto out;
        }
-       ret = check_stateid_generation(stateid, &stp->st_stateid, 1);
+       ret = check_stateid_generation(stateid, &stp->st_stid.sc_stateid, 1);
        if (ret)
                goto out;
 
-       if (stp->st_type == NFS4_OPEN_STID) {
+       if (stp->st_stid.sc_type == NFS4_OPEN_STID) {
                ret = nfserr_locks_held;
                goto out;
        } else {
@@ -3385,62 +3431,67 @@ setlkflg (int type)
                RD_STATE : WR_STATE;
 }
 
+static __be32 nfs4_nospecial_stateid_checks(stateid_t *stateid)
+{
+       if (ZERO_STATEID(stateid) || ONE_STATEID(stateid))
+               return nfserr_bad_stateid;
+       if (STALE_STATEID(stateid))
+               return nfserr_stale_stateid;
+       return nfs_ok;
+}
+
+static __be32 nfs4_seqid_op_checks(struct nfsd4_compound_state *cstate, stateid_t *stateid, u32 seqid, struct nfs4_ol_stateid *stp)
+{
+       struct svc_fh *current_fh = &cstate->current_fh;
+       struct nfs4_stateowner *sop = stp->st_stateowner;
+       __be32 status;
+
+       if (nfs4_check_fh(current_fh, stp))
+               return nfserr_bad_stateid;
+       status = nfsd4_check_seqid(cstate, sop, seqid);
+       if (status)
+               return status;
+       return check_stateid_generation(stateid, &stp->st_stid.sc_stateid, nfsd4_has_session(cstate));
+}
+
 /* 
  * Checks for sequence id mutating operations. 
  */
 static __be32
 nfs4_preprocess_seqid_op(struct nfsd4_compound_state *cstate, u32 seqid,
-                        stateid_t *stateid, int flags,
-                        struct nfs4_stateid **stpp)
+                        stateid_t *stateid, char typemask,
+                        struct nfs4_ol_stateid **stpp)
 {
-       struct nfs4_stateowner *sop;
-       struct svc_fh *current_fh = &cstate->current_fh;
        __be32 status;
 
        dprintk("NFSD: %s: seqid=%d stateid = " STATEID_FMT "\n", __func__,
                seqid, STATEID_VAL(stateid));
 
        *stpp = NULL;
-
-       if (ZERO_STATEID(stateid) || ONE_STATEID(stateid)) {
-               dprintk("NFSD: preprocess_seqid_op: magic stateid!\n");
-               return nfserr_bad_stateid;
-       }
-
-       if (STALE_STATEID(stateid))
-               return nfserr_stale_stateid;
-
-       /*
-       * We return BAD_STATEID if filehandle doesn't match stateid, 
-       * the confirmed flag is incorrecly set, or the generation 
-       * number is incorrect.  
-       */
-       *stpp = find_stateid(stateid, flags);
+       status = nfs4_nospecial_stateid_checks(stateid);
+       if (status)
+               return status;
+       *stpp = find_ol_stateid_by_type(stateid, typemask);
        if (*stpp == NULL)
                return nfserr_expired;
+       cstate->replay_owner = (*stpp)->st_stateowner;
+       renew_client((*stpp)->st_stateowner->so_client);
 
-       sop = (*stpp)->st_stateowner;
-       cstate->replay_owner = sop;
+       return nfs4_seqid_op_checks(cstate, stateid, seqid, *stpp);
+}
 
-       if (nfs4_check_fh(current_fh, *stpp)) {
-               dprintk("NFSD: preprocess_seqid_op: fh-stateid mismatch!\n");
-               return nfserr_bad_stateid;
-       }
+static __be32 nfs4_preprocess_confirmed_seqid_op(struct nfsd4_compound_state *cstate, u32 seqid, stateid_t *stateid, struct nfs4_ol_stateid **stpp)
+{
+       __be32 status;
+       struct nfs4_openowner *oo;
 
-       status = nfsd4_check_seqid(cstate, sop, seqid);
+       status = nfs4_preprocess_seqid_op(cstate, seqid, stateid,
+                                               NFS4_OPEN_STID, stpp);
        if (status)
                return status;
-
-       if (sop->so_is_open_owner && !openowner(sop)->oo_confirmed
-                       && !(flags & CONFIRM)) {
-               dprintk("NFSD: preprocess_seqid_op: stateowner not"
-                               " confirmed yet!\n");
+       oo = openowner((*stpp)->st_stateowner);
+       if (!oo->oo_confirmed)
                return nfserr_bad_stateid;
-       }
-       status = check_stateid_generation(stateid, &(*stpp)->st_stateid, nfsd4_has_session(cstate));
-       if (status)
-               return status;
-       renew_client(sop->so_client);
        return nfs_ok;
 }
 
@@ -3450,7 +3501,7 @@ nfsd4_open_confirm(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 {
        __be32 status;
        struct nfs4_openowner *oo;
-       struct nfs4_stateid *stp;
+       struct nfs4_ol_stateid *stp;
 
        dprintk("NFSD: nfsd4_open_confirm on file %.*s\n",
                        (int)cstate->current_fh.fh_dentry->d_name.len,
@@ -3464,7 +3515,7 @@ nfsd4_open_confirm(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 
        status = nfs4_preprocess_seqid_op(cstate,
                                        oc->oc_seqid, &oc->oc_req_stateid,
-                                       CONFIRM | OPEN_STATE, &stp);
+                                       NFS4_OPEN_STID, &stp);
        if (status)
                goto out;
        oo = openowner(stp->st_stateowner);
@@ -3472,10 +3523,10 @@ nfsd4_open_confirm(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
        if (oo->oo_confirmed)
                goto out;
        oo->oo_confirmed = 1;
-       update_stateid(&stp->st_stateid);
-       memcpy(&oc->oc_resp_stateid, &stp->st_stateid, sizeof(stateid_t));
+       update_stateid(&stp->st_stid.sc_stateid);
+       memcpy(&oc->oc_resp_stateid, &stp->st_stid.sc_stateid, sizeof(stateid_t));
        dprintk("NFSD: %s: success, seqid=%d stateid=" STATEID_FMT "\n",
-               __func__, oc->oc_seqid, STATEID_VAL(&stp->st_stateid));
+               __func__, oc->oc_seqid, STATEID_VAL(&stp->st_stid.sc_stateid));
 
        nfsd4_create_clid_dir(oo->oo_owner.so_client);
        status = nfs_ok;
@@ -3485,7 +3536,7 @@ out:
        return status;
 }
 
-static inline void nfs4_file_downgrade(struct nfs4_stateid *stp, unsigned int to_access)
+static inline void nfs4_file_downgrade(struct nfs4_ol_stateid *stp, unsigned int to_access)
 {
        int i;
 
@@ -3513,7 +3564,7 @@ nfsd4_open_downgrade(struct svc_rqst *rqstp,
                     struct nfsd4_open_downgrade *od)
 {
        __be32 status;
-       struct nfs4_stateid *stp;
+       struct nfs4_ol_stateid *stp;
 
        dprintk("NFSD: nfsd4_open_downgrade on file %.*s\n", 
                        (int)cstate->current_fh.fh_dentry->d_name.len,
@@ -3524,8 +3575,8 @@ nfsd4_open_downgrade(struct svc_rqst *rqstp,
                return nfserr_inval;
 
        nfs4_lock_state();
-       status = nfs4_preprocess_seqid_op(cstate, od->od_seqid,
-                                       &od->od_stateid, OPEN_STATE, &stp);
+       status = nfs4_preprocess_confirmed_seqid_op(cstate, od->od_seqid,
+                                       &od->od_stateid, &stp);
        if (status)
                goto out; 
        status = nfserr_inval;
@@ -3543,8 +3594,8 @@ nfsd4_open_downgrade(struct svc_rqst *rqstp,
 
        reset_union_bmap_deny(od->od_share_deny, &stp->st_deny_bmap);
 
-       update_stateid(&stp->st_stateid);
-       memcpy(&od->od_stateid, &stp->st_stateid, sizeof(stateid_t));
+       update_stateid(&stp->st_stid.sc_stateid);
+       memcpy(&od->od_stateid, &stp->st_stid.sc_stateid, sizeof(stateid_t));
        status = nfs_ok;
 out:
        if (!cstate->replay_owner)
@@ -3561,7 +3612,7 @@ nfsd4_close(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 {
        __be32 status;
        struct nfs4_openowner *oo;
-       struct nfs4_stateid *stp;
+       struct nfs4_ol_stateid *stp;
 
        dprintk("NFSD: nfsd4_close on file %.*s\n", 
                        (int)cstate->current_fh.fh_dentry->d_name.len,
@@ -3569,9 +3620,8 @@ nfsd4_close(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 
        nfs4_lock_state();
        /* check close_lru for replay */
-       status = nfs4_preprocess_seqid_op(cstate, close->cl_seqid,
-                                       &close->cl_stateid, 
-                                       OPEN_STATE, &stp);
+       status = nfs4_preprocess_confirmed_seqid_op(cstate, close->cl_seqid,
+                                       &close->cl_stateid, &stp);
        if (stp == NULL && status == nfserr_expired) {
                /*
                 * Also, we should make sure this isn't just the result of
@@ -3591,8 +3641,8 @@ nfsd4_close(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
                goto out; 
        oo = openowner(stp->st_stateowner);
        status = nfs_ok;
-       update_stateid(&stp->st_stateid);
-       memcpy(&close->cl_stateid, &stp->st_stateid, sizeof(stateid_t));
+       update_stateid(&stp->st_stid.sc_stateid);
+       memcpy(&close->cl_stateid, &stp->st_stid.sc_stateid, sizeof(stateid_t));
 
        /* release_stateid() calls nfsd_close() if needed */
        release_open_stateid(stp);
@@ -3633,10 +3683,10 @@ nfsd4_delegreturn(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
        if (!is_delegation_stateid(stateid))
                goto out;
        status = nfserr_expired;
-       dp = find_delegation_stateid(inode, stateid);
+       dp = find_deleg_stateid(stateid);
        if (!dp)
                goto out;
-       status = check_stateid_generation(stateid, &dp->dl_stateid, nfsd4_has_session(cstate));
+       status = check_stateid_generation(stateid, &dp->dl_stid.sc_stateid, nfsd4_has_session(cstate));
        if (status)
                goto out;
        renew_client(dp->dl_client);
@@ -3694,69 +3744,6 @@ lock_ownerstr_hashval(struct inode *inode, u32 cl_id,
 static struct list_head lock_ownerid_hashtbl[LOCK_HASH_SIZE];
 static struct list_head        lock_ownerstr_hashtbl[LOCK_HASH_SIZE];
 
-static int
-same_stateid(stateid_t *id_one, stateid_t *id_two)
-{
-       if (id_one->si_stateownerid != id_two->si_stateownerid)
-               return 0;
-       return id_one->si_fileid == id_two->si_fileid;
-}
-
-static struct nfs4_stateid *find_stateid(stateid_t *t, int flags)
-{
-       struct nfs4_stateid *s;
-       unsigned int hashval;
-
-       hashval = stateid_hashval(t->si_stateownerid, t->si_fileid);
-       list_for_each_entry(s, &stateid_hashtbl[hashval], st_hash) {
-               if (!same_stateid(&s->st_stateid, t))
-                       continue;
-               if (flags & LOCK_STATE && s->st_type != NFS4_LOCK_STID)
-                       return NULL;
-               if (flags & OPEN_STATE && s->st_type != NFS4_OPEN_STID)
-                       return NULL;
-               return s;
-               }
-       return NULL;
-}
-
-static struct nfs4_delegation *
-search_for_delegation(stateid_t *stid)
-{
-       struct nfs4_file *fp;
-       struct nfs4_delegation *dp;
-       struct list_head *pos;
-       int i;
-
-       for (i = 0; i < FILE_HASH_SIZE; i++) {
-               list_for_each_entry(fp, &file_hashtbl[i], fi_hash) {
-                       list_for_each(pos, &fp->fi_delegations) {
-                               dp = list_entry(pos, struct nfs4_delegation, dl_perfile);
-                               if (same_stateid(&dp->dl_stateid, stid))
-                                       return dp;
-                       }
-               }
-       }
-       return NULL;
-}
-
-static struct nfs4_delegation *
-find_delegation_stateid(struct inode *ino, stateid_t *stid)
-{
-       struct nfs4_file *fp;
-       struct nfs4_delegation *dl;
-
-       dprintk("NFSD: %s: stateid=" STATEID_FMT "\n", __func__,
-               STATEID_VAL(stid));
-
-       fp = find_file(ino);
-       if (!fp)
-               return NULL;
-       dl = find_delegation_file(fp, stid);
-       put_nfs4_file(fp);
-       return dl;
-}
-
 /*
  * TODO: Linux file offsets are _signed_ 64-bit quantities, which means that
  * we can't properly handle lock requests that go beyond the (2^63 - 1)-th
@@ -3823,7 +3810,7 @@ find_lockowner_str(struct inode *inode, clientid_t *clid,
        return NULL;
 }
 
-static void hash_lockowner(struct nfs4_lockowner *lo, unsigned int strhashval, struct nfs4_client *clp, struct nfs4_stateid *open_stp)
+static void hash_lockowner(struct nfs4_lockowner *lo, unsigned int strhashval, struct nfs4_client *clp, struct nfs4_ol_stateid *open_stp)
 {
        unsigned int idhashval;
 
@@ -3842,7 +3829,7 @@ static void hash_lockowner(struct nfs4_lockowner *lo, unsigned int strhashval, s
  */
 
 static struct nfs4_lockowner *
-alloc_init_lock_stateowner(unsigned int strhashval, struct nfs4_client *clp, struct nfs4_stateid *open_stp, struct nfsd4_lock *lock) {
+alloc_init_lock_stateowner(unsigned int strhashval, struct nfs4_client *clp, struct nfs4_ol_stateid *open_stp, struct nfsd4_lock *lock) {
        struct nfs4_lockowner *lo;
 
        lo = alloc_stateowner(lockowner_slab, &lock->lk_new_owner, clp);
@@ -3857,31 +3844,26 @@ alloc_init_lock_stateowner(unsigned int strhashval, struct nfs4_client *clp, str
        return lo;
 }
 
-static struct nfs4_stateid *
-alloc_init_lock_stateid(struct nfs4_lockowner *lo, struct nfs4_file *fp, struct nfs4_stateid *open_stp)
+static struct nfs4_ol_stateid *
+alloc_init_lock_stateid(struct nfs4_lockowner *lo, struct nfs4_file *fp, struct nfs4_ol_stateid *open_stp)
 {
-       struct nfs4_stateid *stp;
-       unsigned int hashval = stateid_hashval(lo->lo_owner.so_id, fp->fi_id);
+       struct nfs4_ol_stateid *stp;
 
        stp = nfs4_alloc_stateid();
        if (stp == NULL)
                goto out;
-       INIT_LIST_HEAD(&stp->st_hash);
-       INIT_LIST_HEAD(&stp->st_perfile);
-       INIT_LIST_HEAD(&stp->st_perstateowner);
-       INIT_LIST_HEAD(&stp->st_lockowners); /* not used */
-       list_add(&stp->st_hash, &stateid_hashtbl[hashval]);
        list_add(&stp->st_perfile, &fp->fi_stateids);
        list_add(&stp->st_perstateowner, &lo->lo_owner.so_stateids);
        stp->st_stateowner = &lo->lo_owner;
-       stp->st_type = NFS4_LOCK_STID;
+       stp->st_stid.sc_type = NFS4_LOCK_STID;
        get_nfs4_file(fp);
        stp->st_file = fp;
-       stp->st_stateid.si_boot = boot_time;
-       stp->st_stateid.si_stateownerid = lo->lo_owner.so_id;
-       stp->st_stateid.si_fileid = fp->fi_id;
+       stp->st_stid.sc_stateid.si_boot = boot_time;
+       stp->st_stid.sc_stateid.si_stateownerid = lo->lo_owner.so_id;
+       stp->st_stid.sc_stateid.si_fileid = fp->fi_id;
        /* note will be incremented before first return to client: */
-       stp->st_stateid.si_generation = 0;
+       stp->st_stid.sc_stateid.si_generation = 0;
+       hash_stid(&stp->st_stid);
        stp->st_access_bmap = 0;
        stp->st_deny_bmap = open_stp->st_deny_bmap;
        stp->st_openstp = open_stp;
@@ -3897,7 +3879,7 @@ check_lock_length(u64 offset, u64 length)
             LOFF_OVERFLOW(offset, length)));
 }
 
-static void get_lock_access(struct nfs4_stateid *lock_stp, u32 access)
+static void get_lock_access(struct nfs4_ol_stateid *lock_stp, u32 access)
 {
        struct nfs4_file *fp = lock_stp->st_file;
        int oflag = nfs4_access_to_omode(access);
@@ -3917,7 +3899,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 {
        struct nfs4_openowner *open_sop = NULL;
        struct nfs4_lockowner *lock_sop = NULL;
-       struct nfs4_stateid *lock_stp;
+       struct nfs4_ol_stateid *lock_stp;
        struct nfs4_file *fp;
        struct file *filp = NULL;
        struct file_lock file_lock;
@@ -3948,7 +3930,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
                 * Use open owner and open stateid to create lock owner and
                 * lock stateid.
                 */
-               struct nfs4_stateid *open_stp = NULL;
+               struct nfs4_ol_stateid *open_stp = NULL;
                
                status = nfserr_stale_clientid;
                if (!nfsd4_has_session(cstate) &&
@@ -3956,10 +3938,10 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
                        goto out;
 
                /* validate and update open stateid and open seqid */
-               status = nfs4_preprocess_seqid_op(cstate,
+               status = nfs4_preprocess_confirmed_seqid_op(cstate,
                                        lock->lk_new_open_seqid,
                                        &lock->lk_new_open_stateid,
-                                       OPEN_STATE, &open_stp);
+                                       &open_stp);
                if (status)
                        goto out;
                open_sop = openowner(open_stp->st_stateowner);
@@ -3989,7 +3971,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
                status = nfs4_preprocess_seqid_op(cstate,
                                       lock->lk_old_lock_seqid,
                                       &lock->lk_old_lock_stateid,
-                                      LOCK_STATE, &lock_stp);
+                                      NFS4_LOCK_STID, &lock_stp);
                if (status)
                        goto out;
                lock_sop = lockowner(lock_stp->st_stateowner);
@@ -4051,8 +4033,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
        err = vfs_lock_file(filp, F_SETLK, &file_lock, &conflock);
        switch (-err) {
        case 0: /* success! */
-               update_stateid(&lock_stp->st_stateid);
-               memcpy(&lock->lk_resp_stateid, &lock_stp->st_stateid, 
+               update_stateid(&lock_stp->st_stid.sc_stateid);
+               memcpy(&lock->lk_resp_stateid, &lock_stp->st_stid.sc_stateid, 
                                sizeof(stateid_t));
                status = 0;
                break;
@@ -4171,7 +4153,7 @@ __be32
 nfsd4_locku(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
            struct nfsd4_locku *locku)
 {
-       struct nfs4_stateid *stp;
+       struct nfs4_ol_stateid *stp;
        struct file *filp = NULL;
        struct file_lock file_lock;
        __be32 status;
@@ -4187,7 +4169,7 @@ nfsd4_locku(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
        nfs4_lock_state();
                                                                                
        status = nfs4_preprocess_seqid_op(cstate, locku->lu_seqid,
-                                       &locku->lu_stateid, LOCK_STATE, &stp);
+                                       &locku->lu_stateid, NFS4_LOCK_STID, &stp);
        if (status)
                goto out;
        filp = find_any_file(stp->st_file);
@@ -4219,8 +4201,8 @@ nfsd4_locku(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
        /*
        * OK, unlock succeeded; the only thing left to do is update the stateid.
        */
-       update_stateid(&stp->st_stateid);
-       memcpy(&locku->lu_stateid, &stp->st_stateid, sizeof(stateid_t));
+       update_stateid(&stp->st_stid.sc_stateid);
+       memcpy(&locku->lu_stateid, &stp->st_stid.sc_stateid, sizeof(stateid_t));
 
 out:
        nfs4_unlock_state();
@@ -4263,7 +4245,7 @@ nfsd4_release_lockowner(struct svc_rqst *rqstp,
        clientid_t *clid = &rlockowner->rl_clientid;
        struct nfs4_stateowner *sop;
        struct nfs4_lockowner *lo;
-       struct nfs4_stateid *stp;
+       struct nfs4_ol_stateid *stp;
        struct xdr_netobj *owner = &rlockowner->rl_owner;
        struct list_head matches;
        int i;
This page took 0.070106 seconds and 5 git commands to generate.