NFSD: Remove the ex_pathname field from struct svc_export
[deliverable/linux.git] / fs / nfsd / nfs4state.c
index 3787ec11740014a64e13ca3eb336d6fdf80f7310..0cd346477f29ce511e7f8b5579090fbba797c52c 100644 (file)
@@ -60,13 +60,7 @@ 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_stateid * search_for_stateid(stateid_t *stid);
-static struct nfs4_delegation * search_for_delegation(stateid_t *stid);
-static struct nfs4_delegation * find_delegation_stateid(struct inode *ino, stateid_t *stid);
-static char user_recovery_dirname[PATH_MAX] = "/var/lib/nfs/v4recovery";
-static void nfs4_set_recdir(char *recdir);
-static int check_for_locks(struct nfs4_file *filp, struct nfs4_stateowner *lowner);
+static int check_for_locks(struct nfs4_file *filp, struct nfs4_lockowner *lowner);
 
 /* Locking: */
 
@@ -80,7 +74,8 @@ static DEFINE_MUTEX(client_mutex);
  */
 static DEFINE_SPINLOCK(recall_lock);
 
-static struct kmem_cache *stateowner_slab = NULL;
+static struct kmem_cache *openowner_slab = NULL;
+static struct kmem_cache *lockowner_slab = NULL;
 static struct kmem_cache *file_slab = NULL;
 static struct kmem_cache *stateid_slab = NULL;
 static struct kmem_cache *deleg_slab = NULL;
@@ -136,32 +131,47 @@ unsigned int max_delegations;
  * Open owner state (share locks)
  */
 
-/* hash tables for nfs4_stateowner */
-#define OWNER_HASH_BITS              8
-#define OWNER_HASH_SIZE             (1 << OWNER_HASH_BITS)
-#define OWNER_HASH_MASK             (OWNER_HASH_SIZE - 1)
+/* hash tables for open owners */
+#define OPEN_OWNER_HASH_BITS              8
+#define OPEN_OWNER_HASH_SIZE             (1 << OPEN_OWNER_HASH_BITS)
+#define OPEN_OWNER_HASH_MASK             (OPEN_OWNER_HASH_SIZE - 1)
 
-#define ownerid_hashval(id) \
-        ((id) & OWNER_HASH_MASK)
-#define ownerstr_hashval(clientid, ownername) \
-        (((clientid) + opaque_hashval((ownername.data), (ownername.len))) & OWNER_HASH_MASK)
+static unsigned int open_ownerid_hashval(const u32 id)
+{
+       return id & OPEN_OWNER_HASH_MASK;
+}
+
+static unsigned int open_ownerstr_hashval(u32 clientid, struct xdr_netobj *ownername)
+{
+       unsigned int ret;
+
+       ret = opaque_hashval(ownername->data, ownername->len);
+       ret += clientid;
+       return ret & OPEN_OWNER_HASH_MASK;
+}
 
-static struct list_head        ownerid_hashtbl[OWNER_HASH_SIZE];
-static struct list_head        ownerstr_hashtbl[OWNER_HASH_SIZE];
+static struct list_head        open_ownerid_hashtbl[OPEN_OWNER_HASH_SIZE];
+static struct list_head        open_ownerstr_hashtbl[OPEN_OWNER_HASH_SIZE];
 
 /* hash table for nfs4_file */
 #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)
 
-#define file_hashval(x) \
-        hash_ptr(x, FILE_HASH_BITS)
-#define stateid_hashval(owner_id, file_id)  \
-        (((owner_id) + (file_id)) & STATEID_HASH_MASK)
+static unsigned int file_hashval(struct inode *ino)
+{
+       /* XXX: why are we hashing on inode pointer, anyway? */
+       return hash_ptr(ino, FILE_HASH_BITS);
+}
+
+static unsigned int stateid_hashval(stateid_t *s)
+{
+       return opaque_hashval(&s->si_opaque, sizeof(stateid_opaque_t)) & STATEID_HASH_MASK;
+}
 
 static struct list_head file_hashtbl[FILE_HASH_SIZE];
 static struct list_head stateid_hashtbl[STATEID_HASH_SIZE];
@@ -206,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;
@@ -235,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 = 0;
+       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);
@@ -271,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);
@@ -292,10 +314,16 @@ static DEFINE_SPINLOCK(client_lock);
 #define CLIENT_HASH_SIZE                (1 << CLIENT_HASH_BITS)
 #define CLIENT_HASH_MASK                (CLIENT_HASH_SIZE - 1)
 
-#define clientid_hashval(id) \
-       ((id) & CLIENT_HASH_MASK)
-#define clientstr_hashval(name) \
-       (opaque_hashval((name), 8) & CLIENT_HASH_MASK)
+static unsigned int clientid_hashval(u32 id)
+{
+       return id & CLIENT_HASH_MASK;
+}
+
+static unsigned int clientstr_hashval(const char *name)
+{
+       return opaque_hashval(name, 8) & CLIENT_HASH_MASK;
+}
+
 /*
  * reclaim_str_hashtbl[] holds known client info from previous reset/reboot
  * used in reboot/reset lease grace period processing
@@ -362,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);
@@ -385,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 free_generic_stateid(struct nfs4_stateid *stp)
+static void close_generic_stateid(struct nfs4_ol_stateid *stp)
 {
        int i;
 
@@ -401,84 +429,88 @@ static void free_generic_stateid(struct nfs4_stateid *stp)
                        if (test_bit(i, &stp->st_access_bmap))
                                nfs4_file_put_access(stp->st_file,
                                                nfs4_access_to_omode(i));
+                       __clear_bit(i, &stp->st_access_bmap);
                }
        }
        put_nfs4_file(stp->st_file);
+       stp->st_file = NULL;
+}
+
+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;
 
        unhash_generic_stateid(stp);
        file = find_any_file(stp->st_file);
        if (file)
-               locks_remove_posix(file, (fl_owner_t)stp->st_stateowner);
+               locks_remove_posix(file, (fl_owner_t)lockowner(stp->st_stateowner));
        free_generic_stateid(stp);
 }
 
-static void unhash_lockowner(struct nfs4_stateowner *sop)
+static void unhash_lockowner(struct nfs4_lockowner *lo)
 {
-       struct nfs4_stateid *stp;
+       struct nfs4_ol_stateid *stp;
 
-       list_del(&sop->so_idhash);
-       list_del(&sop->so_strhash);
-       list_del(&sop->so_perstateid);
-       while (!list_empty(&sop->so_stateids)) {
-               stp = list_first_entry(&sop->so_stateids,
-                               struct nfs4_stateid, st_perstateowner);
+       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_ol_stateid, st_perstateowner);
                release_lock_stateid(stp);
        }
 }
 
-static void release_lockowner(struct nfs4_stateowner *sop)
+static void release_lockowner(struct nfs4_lockowner *lo)
 {
-       unhash_lockowner(sop);
-       nfs4_put_stateowner(sop);
+       unhash_lockowner(lo);
+       nfs4_free_lockowner(lo);
 }
 
 static void
-release_stateid_lockowners(struct nfs4_stateid *open_stp)
+release_stateid_lockowners(struct nfs4_ol_stateid *open_stp)
 {
-       struct nfs4_stateowner *lock_sop;
+       struct nfs4_lockowner *lo;
 
        while (!list_empty(&open_stp->st_lockowners)) {
-               lock_sop = list_entry(open_stp->st_lockowners.next,
-                               struct nfs4_stateowner, so_perstateid);
-               /* list_del(&open_stp->st_lockowners);  */
-               BUG_ON(lock_sop->so_is_open_owner);
-               release_lockowner(lock_sop);
+               lo = list_entry(open_stp->st_lockowners.next,
+                               struct nfs4_lockowner, lo_perstateid);
+               release_lockowner(lo);
        }
 }
 
-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);
        free_generic_stateid(stp);
 }
 
-static void unhash_openowner(struct nfs4_stateowner *sop)
+static void unhash_openowner(struct nfs4_openowner *oo)
 {
-       struct nfs4_stateid *stp;
+       struct nfs4_ol_stateid *stp;
 
-       list_del(&sop->so_idhash);
-       list_del(&sop->so_strhash);
-       list_del(&sop->so_perclient);
-       list_del(&sop->so_perstateid); /* XXX: necessary? */
-       while (!list_empty(&sop->so_stateids)) {
-               stp = list_first_entry(&sop->so_stateids,
-                               struct nfs4_stateid, st_perstateowner);
+       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_ol_stateid, st_perstateowner);
                release_open_stateid(stp);
        }
 }
 
-static void release_openowner(struct nfs4_stateowner *sop)
+static void release_openowner(struct nfs4_openowner *oo)
 {
-       unhash_openowner(sop);
-       list_del(&sop->so_close_lru);
-       nfs4_put_stateowner(sop);
+       unhash_openowner(oo);
+       list_del(&oo->oo_close_lru);
+       nfs4_free_openowner(oo);
 }
 
 #define SESSION_HASH_SIZE      512
@@ -943,7 +975,7 @@ unhash_client_locked(struct nfs4_client *clp)
 static void
 expire_client(struct nfs4_client *clp)
 {
-       struct nfs4_stateowner *sop;
+       struct nfs4_openowner *oo;
        struct nfs4_delegation *dp;
        struct list_head reaplist;
 
@@ -961,8 +993,8 @@ expire_client(struct nfs4_client *clp)
                unhash_delegation(dp);
        }
        while (!list_empty(&clp->cl_openowners)) {
-               sop = list_entry(clp->cl_openowners.next, struct nfs4_stateowner, so_perclient);
-               release_openowner(sop);
+               oo = list_entry(clp->cl_openowners.next, struct nfs4_openowner, oo_perclient);
+               release_openowner(oo);
        }
        nfsd4_shutdown_callback(clp);
        if (clp->cl_cb_conn.cb_xprt)
@@ -1038,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)
 {
@@ -1946,7 +2030,7 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
         * of 5 bullet points, labeled as CASE0 - CASE4 below.
         */
        unconf = find_unconfirmed_client_by_str(dname, strhashval);
-       status = nfserr_resource;
+       status = nfserr_jukebox;
        if (!conf) {
                /*
                 * RFC 3530 14.2.33 CASE 4:
@@ -2155,7 +2239,8 @@ nfsd4_free_slab(struct kmem_cache **slab)
 void
 nfsd4_free_slabs(void)
 {
-       nfsd4_free_slab(&stateowner_slab);
+       nfsd4_free_slab(&openowner_slab);
+       nfsd4_free_slab(&lockowner_slab);
        nfsd4_free_slab(&file_slab);
        nfsd4_free_slab(&stateid_slab);
        nfsd4_free_slab(&deleg_slab);
@@ -2164,16 +2249,20 @@ nfsd4_free_slabs(void)
 static int
 nfsd4_init_slabs(void)
 {
-       stateowner_slab = kmem_cache_create("nfsd4_stateowners",
-                       sizeof(struct nfs4_stateowner), 0, 0, NULL);
-       if (stateowner_slab == NULL)
+       openowner_slab = kmem_cache_create("nfsd4_openowners",
+                       sizeof(struct nfs4_openowner), 0, 0, NULL);
+       if (openowner_slab == NULL)
+               goto out_nomem;
+       lockowner_slab = kmem_cache_create("nfsd4_lockowners",
+                       sizeof(struct nfs4_openowner), 0, 0, NULL);
+       if (lockowner_slab == NULL)
                goto out_nomem;
        file_slab = kmem_cache_create("nfsd4_files",
                        sizeof(struct nfs4_file), 0, 0, NULL);
        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",
@@ -2187,82 +2276,90 @@ out_nomem:
        return -ENOMEM;
 }
 
-void
-nfs4_free_stateowner(struct kref *kref)
+void nfs4_free_openowner(struct nfs4_openowner *oo)
 {
-       struct nfs4_stateowner *sop =
-               container_of(kref, struct nfs4_stateowner, so_ref);
-       kfree(sop->so_owner.data);
-       kmem_cache_free(stateowner_slab, sop);
+       kfree(oo->oo_owner.so_owner.data);
+       kmem_cache_free(openowner_slab, oo);
 }
 
-static inline struct nfs4_stateowner *
-alloc_stateowner(struct xdr_netobj *owner)
+void nfs4_free_lockowner(struct nfs4_lockowner *lo)
 {
-       struct nfs4_stateowner *sop;
+       kfree(lo->lo_owner.so_owner.data);
+       kmem_cache_free(lockowner_slab, lo);
+}
 
-       if ((sop = kmem_cache_alloc(stateowner_slab, GFP_KERNEL))) {
-               if ((sop->so_owner.data = kmalloc(owner->len, GFP_KERNEL))) {
-                       memcpy(sop->so_owner.data, owner->data, owner->len);
-                       sop->so_owner.len = owner->len;
-                       kref_init(&sop->so_ref);
-                       return sop;
-               } 
-               kmem_cache_free(stateowner_slab, sop);
-       }
-       return NULL;
+static void init_nfs4_replay(struct nfs4_replay *rp)
+{
+       rp->rp_status = nfserr_serverfault;
+       rp->rp_buflen = 0;
+       rp->rp_buf = rp->rp_ibuf;
 }
 
-static struct nfs4_stateowner *
-alloc_init_open_stateowner(unsigned int strhashval, struct nfs4_client *clp, struct nfsd4_open *open) {
+static inline void *alloc_stateowner(struct kmem_cache *slab, struct xdr_netobj *owner, struct nfs4_client *clp)
+{
        struct nfs4_stateowner *sop;
-       struct nfs4_replay *rp;
-       unsigned int idhashval;
 
-       if (!(sop = alloc_stateowner(&open->op_owner)))
+       sop = kmem_cache_alloc(slab, GFP_KERNEL);
+       if (!sop)
+               return NULL;
+
+       sop->so_owner.data = kmemdup(owner->data, owner->len, GFP_KERNEL);
+       if (!sop->so_owner.data) {
+               kmem_cache_free(slab, sop);
                return NULL;
-       idhashval = ownerid_hashval(current_ownerid);
-       INIT_LIST_HEAD(&sop->so_idhash);
-       INIT_LIST_HEAD(&sop->so_strhash);
-       INIT_LIST_HEAD(&sop->so_perclient);
+       }
+       sop->so_owner.len = owner->len;
+
        INIT_LIST_HEAD(&sop->so_stateids);
-       INIT_LIST_HEAD(&sop->so_perstateid);  /* not used */
-       INIT_LIST_HEAD(&sop->so_close_lru);
-       sop->so_time = 0;
-       list_add(&sop->so_idhash, &ownerid_hashtbl[idhashval]);
-       list_add(&sop->so_strhash, &ownerstr_hashtbl[strhashval]);
-       list_add(&sop->so_perclient, &clp->cl_openowners);
-       sop->so_is_open_owner = 1;
        sop->so_id = current_ownerid++;
        sop->so_client = clp;
-       sop->so_seqid = open->op_seqid;
-       sop->so_confirmed = 0;
-       rp = &sop->so_replay;
-       rp->rp_status = nfserr_serverfault;
-       rp->rp_buflen = 0;
-       rp->rp_buf = rp->rp_ibuf;
+       init_nfs4_replay(&sop->so_replay);
        return sop;
 }
 
+static void hash_openowner(struct nfs4_openowner *oo, struct nfs4_client *clp, unsigned int strhashval)
+{
+       unsigned int idhashval;
+
+       idhashval = open_ownerid_hashval(oo->oo_owner.so_id);
+       list_add(&oo->oo_owner.so_idhash, &open_ownerid_hashtbl[idhashval]);
+       list_add(&oo->oo_owner.so_strhash, &open_ownerstr_hashtbl[strhashval]);
+       list_add(&oo->oo_perclient, &clp->cl_openowners);
+}
+
+static struct nfs4_openowner *
+alloc_init_open_stateowner(unsigned int strhashval, struct nfs4_client *clp, struct nfsd4_open *open) {
+       struct nfs4_openowner *oo;
+
+       oo = alloc_stateowner(openowner_slab, &open->op_owner, clp);
+       if (!oo)
+               return NULL;
+       oo->oo_owner.so_is_open_owner = 1;
+       oo->oo_owner.so_seqid = open->op_seqid;
+       oo->oo_confirmed = 0;
+       oo->oo_time = 0;
+       INIT_LIST_HEAD(&oo->oo_close_lru);
+       hash_openowner(oo, clp, strhashval);
+       return oo;
+}
+
 static inline void
-init_stateid(struct nfs4_stateid *stp, struct nfs4_file *fp, struct nfsd4_open *open) {
-       struct nfs4_stateowner *sop = open->op_stateowner;
-       unsigned int hashval = stateid_hashval(sop->so_id, fp->fi_id);
+init_open_stateid(struct nfs4_ol_stateid *stp, struct nfs4_file *fp, struct nfsd4_open *open) {
+       struct nfs4_openowner *oo = open->op_openowner;
 
-       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, &sop->so_stateids);
+       list_add(&stp->st_perstateowner, &oo->oo_owner.so_stateids);
        list_add(&stp->st_perfile, &fp->fi_stateids);
-       stp->st_stateowner = sop;
+       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 = sop->so_id;
-       stp->st_stateid.si_fileid = fp->fi_id;
-       stp->st_stateid.si_generation = 0;
+       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_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,
@@ -2272,12 +2369,12 @@ init_stateid(struct nfs4_stateid *stp, struct nfs4_file *fp, struct nfsd4_open *
 }
 
 static void
-move_to_close_lru(struct nfs4_stateowner *sop)
+move_to_close_lru(struct nfs4_openowner *oo)
 {
-       dprintk("NFSD: move_to_close_lru nfs4_stateowner %p\n", sop);
+       dprintk("NFSD: move_to_close_lru nfs4_openowner %p\n", oo);
 
-       list_move_tail(&sop->so_close_lru, &close_lru);
-       sop->so_time = get_seconds();
+       list_move_tail(&oo->oo_close_lru, &close_lru);
+       oo->oo_time = get_seconds();
 }
 
 static int
@@ -2289,14 +2386,14 @@ same_owner_str(struct nfs4_stateowner *sop, struct xdr_netobj *owner,
                (sop->so_client->cl_clientid.cl_id == clid->cl_id);
 }
 
-static struct nfs4_stateowner *
+static struct nfs4_openowner *
 find_openstateowner_str(unsigned int hashval, struct nfsd4_open *open)
 {
        struct nfs4_stateowner *so = NULL;
 
-       list_for_each_entry(so, &ownerstr_hashtbl[hashval], so_strhash) {
+       list_for_each_entry(so, &open_ownerstr_hashtbl[hashval], so_strhash) {
                if (same_owner_str(so, &open->op_owner, &open->op_clientid))
-                       return so;
+                       return container_of(so, struct nfs4_openowner, oo_owner);
        }
        return NULL;
 }
@@ -2354,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");
@@ -2429,6 +2526,16 @@ static const struct lock_manager_operations nfsd_lease_mng_ops = {
        .lm_change = nfsd_change_deleg_cb,
 };
 
+static __be32 nfsd4_check_seqid(struct nfsd4_compound_state *cstate, struct nfs4_stateowner *so, u32 seqid)
+{
+       if (nfsd4_has_session(cstate))
+               return nfs_ok;
+       if (seqid == so->so_seqid - 1)
+               return nfserr_replay_me;
+       if (seqid == so->so_seqid)
+               return nfs_ok;
+       return nfserr_bad_seqid;
+}
 
 __be32
 nfsd4_process_open1(struct nfsd4_compound_state *cstate,
@@ -2437,7 +2544,8 @@ nfsd4_process_open1(struct nfsd4_compound_state *cstate,
        clientid_t *clientid = &open->op_clientid;
        struct nfs4_client *clp = NULL;
        unsigned int strhashval;
-       struct nfs4_stateowner *sop = NULL;
+       struct nfs4_openowner *oo = NULL;
+       __be32 status;
 
        if (!check_name(open->op_owner))
                return nfserr_inval;
@@ -2445,49 +2553,35 @@ nfsd4_process_open1(struct nfsd4_compound_state *cstate,
        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);
-       open->op_stateowner = sop;
-       if (!sop) {
+       strhashval = open_ownerstr_hashval(clientid->cl_id, &open->op_owner);
+       oo = find_openstateowner_str(strhashval, open);
+       open->op_openowner = oo;
+       if (!oo) {
                /* Make sure the client's lease hasn't expired. */
                clp = find_confirmed_client(clientid);
                if (clp == NULL)
                        return nfserr_expired;
                goto renew;
        }
-       /* When sessions are used, skip open sequenceid processing */
-       if (nfsd4_has_session(cstate))
-               goto renew;
-       if (!sop->so_confirmed) {
+       if (!oo->oo_confirmed) {
                /* Replace unconfirmed owners without checking for replay. */
-               clp = sop->so_client;
-               release_openowner(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");
+               clp = oo->oo_owner.so_client;
+               release_openowner(oo);
+               open->op_openowner = NULL;
                goto renew;
        }
-       if (open->op_seqid != sop->so_seqid)
-               return nfserr_bad_seqid;
+       status = nfsd4_check_seqid(cstate, &oo->oo_owner, open->op_seqid);
+       if (status)
+               return status;
 renew:
-       if (open->op_stateowner == NULL) {
-               sop = alloc_init_open_stateowner(strhashval, clp, open);
-               if (sop == NULL)
-                       return nfserr_resource;
-               open->op_stateowner = sop;
+       if (open->op_openowner == NULL) {
+               oo = alloc_init_open_stateowner(strhashval, clp, open);
+               if (oo == NULL)
+                       return nfserr_jukebox;
+               open->op_openowner = oo;
        }
-       list_del_init(&sop->so_close_lru);
-       renew_client(sop->so_client);
+       list_del_init(&oo->oo_close_lru);
+       renew_client(oo->oo_owner.so_client);
        return nfs_ok;
 }
 
@@ -2500,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
@@ -2529,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);
@@ -2541,34 +2630,31 @@ out:
                return nfs_ok;
        if (status)
                return status;
-       open->op_stateowner->so_confirmed = 1;
+       open->op_openowner->oo_confirmed = 1;
        return nfs_ok;
 }
 
 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;
-       __be32 status = nfserr_share_denied;
-       struct nfs4_stateowner *sop = open->op_stateowner;
+       struct nfs4_ol_stateid *local;
+       struct nfs4_openowner *oo = open->op_openowner;
 
        list_for_each_entry(local, &fp->fi_stateids, st_perfile) {
                /* ignore lock owners */
                if (local->st_stateowner->so_is_open_owner == 0)
                        continue;
                /* remember if we have seen this open owner */
-               if (local->st_stateowner == sop)
+               if (local->st_stateowner == &oo->oo_owner)
                        *stpp = local;
                /* check for conflicting share reservations */
                if (!test_share(local, open))
-                       goto out;
+                       return nfserr_share_denied;
        }
-       status = 0;
-out:
-       return status;
+       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);
@@ -2610,16 +2696,16 @@ 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();
        if (stp == NULL)
-               return nfserr_resource;
+               return nfserr_jukebox;
 
        status = nfs4_get_vfs_file(rqstp, fp, cur_fh, open);
        if (status) {
@@ -2646,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;
@@ -2677,8 +2763,8 @@ nfs4_upgrade_open(struct svc_rqst *rqstp, struct nfs4_file *fp, struct svc_fh *c
 static void
 nfs4_set_claim_prev(struct nfsd4_open *open)
 {
-       open->op_stateowner->so_confirmed = 1;
-       open->op_stateowner->so_client->cl_firststate = 1;
+       open->op_openowner->oo_confirmed = 1;
+       open->op_openowner->oo_owner.so_client->cl_firststate = 1;
 }
 
 /* Should we give out recallable state?: */
@@ -2758,14 +2844,14 @@ 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_stateowner *sop = stp->st_stateowner;
+       struct nfs4_openowner *oo = container_of(stp->st_stateowner, struct nfs4_openowner, oo_owner);
        int cb_up;
        int status, flag = 0;
 
-       cb_up = nfsd4_cb_channel_good(sop->so_client);
+       cb_up = nfsd4_cb_channel_good(oo->oo_owner.so_client);
        flag = NFS4_OPEN_DELEGATE_NONE;
        open->op_recall = 0;
        switch (open->op_claim_type) {
@@ -2781,7 +2867,7 @@ nfs4_open_delegation(struct svc_fh *fh, struct nfsd4_open *open, struct nfs4_sta
                         * had the chance to reclaim theirs.... */
                        if (locks_in_grace())
                                goto out;
-                       if (!cb_up || !sop->so_confirmed)
+                       if (!cb_up || !oo->oo_confirmed)
                                goto out;
                        if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE)
                                flag = NFS4_OPEN_DELEGATE_WRITE;
@@ -2792,17 +2878,17 @@ nfs4_open_delegation(struct svc_fh *fh, struct nfsd4_open *open, struct nfs4_sta
                        goto out;
        }
 
-       dp = alloc_init_deleg(sop->so_client, stp, fh, flag);
+       dp = alloc_init_deleg(oo->oo_owner.so_client, stp, fh, flag);
        if (dp == NULL)
                goto out_no_deleg;
        status = nfs4_set_delegation(dp, flag);
        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
@@ -2826,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;
 
@@ -2850,7 +2936,7 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf
                status = nfserr_bad_stateid;
                if (open->op_claim_type == NFS4_OPEN_CLAIM_DELEGATE_CUR)
                        goto out;
-               status = nfserr_resource;
+               status = nfserr_jukebox;
                fp = alloc_init_file(ino);
                if (fp == NULL)
                        goto out;
@@ -2865,24 +2951,22 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf
                status = nfs4_upgrade_open(rqstp, fp, current_fh, stp, open);
                if (status)
                        goto out;
-               update_stateid(&stp->st_stateid);
        } else {
                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;
                }
-               if (nfsd4_has_session(&resp->cstate))
-                       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_stateowner->so_confirmed = 1;
+               open->op_openowner->oo_confirmed = 1;
 
        /*
        * Attempt to hand out a delegation. No error return, because the
@@ -2893,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);
@@ -2903,7 +2987,7 @@ out:
        * To finish the open response, we just need to set the rflags.
        */
        open->op_rflags = NFS4_OPEN_RESULT_LOCKTYPE_POSIX;
-       if (!open->op_stateowner->so_confirmed &&
+       if (!open->op_openowner->oo_confirmed &&
            !nfsd4_has_session(&resp->cstate))
                open->op_rflags |= NFS4_OPEN_RESULT_CONFIRM;
 
@@ -2962,7 +3046,7 @@ static time_t
 nfs4_laundromat(void)
 {
        struct nfs4_client *clp;
-       struct nfs4_stateowner *sop;
+       struct nfs4_openowner *oo;
        struct nfs4_delegation *dp;
        struct list_head *pos, *next, reaplist;
        time_t cutoff = get_seconds() - nfsd4_lease;
@@ -3019,16 +3103,16 @@ nfs4_laundromat(void)
        }
        test_val = nfsd4_lease;
        list_for_each_safe(pos, next, &close_lru) {
-               sop = list_entry(pos, struct nfs4_stateowner, so_close_lru);
-               if (time_after((unsigned long)sop->so_time, (unsigned long)cutoff)) {
-                       u = sop->so_time - cutoff;
+               oo = container_of(pos, struct nfs4_openowner, oo_close_lru);
+               if (time_after((unsigned long)oo->oo_time, (unsigned long)cutoff)) {
+                       u = oo->oo_time - cutoff;
                        if (test_val > u)
                                test_val = u;
                        break;
                }
                dprintk("NFSD: purging unused open stateowner (so_id %d)\n",
-                       sop->so_id);
-               release_openowner(sop);
+                       oo->oo_owner.so_id);
+               release_openowner(oo);
        }
        if (clientid_val < NFSD_LAUNDROMAT_MINTIMEOUT)
                clientid_val = NFSD_LAUNDROMAT_MINTIMEOUT;
@@ -3050,22 +3134,19 @@ laundromat_main(struct work_struct *not_used)
        queue_delayed_work(laundry_wq, &laundromat_work, t*HZ);
 }
 
-static struct nfs4_stateowner *
-search_close_lru(u32 st_id, int flags)
+static struct nfs4_openowner * search_close_lru(u32 st_id)
 {
-       struct nfs4_stateowner *local = NULL;
+       struct nfs4_openowner *local;
 
-       if (flags & CLOSE_STATE) {
-               list_for_each_entry(local, &close_lru, so_close_lru) {
-                       if (local->so_id == st_id)
-                               return local;
-               }
+       list_for_each_entry(local, &close_lru, oo_close_lru) {
+               if (local->oo_owner.so_id == st_id)
+                       return local;
        }
        return NULL;
 }
 
 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;
 }
@@ -3096,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;
 
@@ -3139,32 +3220,38 @@ grace_disallows_io(struct inode *inode)
        return locks_in_grace() && mandatory_lock(inode);
 }
 
-static int check_stateid_generation(stateid_t *in, stateid_t *ref, int flags)
+/* Returns true iff a is later than b: */
+static bool stateid_generation_after(stateid_t *a, stateid_t *b)
+{
+       return (s32)a->si_generation - (s32)b->si_generation > 0;
+}
+
+static int check_stateid_generation(stateid_t *in, stateid_t *ref, bool has_session)
 {
        /*
         * When sessions are used the stateid generation number is ignored
         * when it is zero.
         */
-       if ((flags & HAS_SESSION) && in->si_generation == 0)
-               goto out;
+       if (has_session && in->si_generation == 0)
+               return nfs_ok;
+
+       if (in->si_generation == ref->si_generation)
+               return nfs_ok;
 
        /* If the client sends us a stateid from the future, it's buggy: */
-       if (in->si_generation > ref->si_generation)
+       if (stateid_generation_after(in, ref))
                return nfserr_bad_stateid;
        /*
-        * The following, however, can happen.  For example, if the
-        * client sends an open and some IO at the same time, the open
-        * may bump si_generation while the IO is still in flight.
-        * Thanks to hard links and renames, the client never knows what
-        * file an open will affect.  So it could avoid that situation
-        * only by serializing all opens and IO from the same open
-        * owner.  To recover from the old_stateid error, the client
-        * will just have to retry the IO:
+        * However, we could see a stateid from the past, even from a
+        * non-buggy client.  For example, if the client sends a lock
+        * while some IO is outstanding, the lock may bump si_generation
+        * while the IO is still in flight.  The client could avoid that
+        * situation by waiting for responses on all the IO requests,
+        * but better performance may result in retrying IO that
+        * receives an old_stateid error if requests are rarely
+        * reordered in flight:
         */
-       if (in->si_generation < ref->si_generation)
-               return nfserr_old_stateid;
-out:
-       return nfs_ok;
+       return nfserr_old_stateid;
 }
 
 static int is_delegation_stateid(stateid_t *stateid)
@@ -3172,35 +3259,28 @@ static int is_delegation_stateid(stateid_t *stateid)
        return stateid->si_fileid == 0;
 }
 
-static int is_open_stateid(struct nfs4_stateid *stateid)
-{
-       return stateid->st_openstp == NULL;
-}
-
-__be32 nfs4_validate_stateid(stateid_t *stateid, int flags)
+__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 = search_for_stateid(stateid);
-       if (!stp)
-               goto out;
-       status = nfserr_bad_stateid;
-
-       if (!stp->st_stateowner->so_confirmed)
-               goto out;
+               return nfserr_stale_stateid;
 
-       status = check_stateid_generation(stateid, &stp->st_stateid, flags);
+       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;
 }
 
 /*
@@ -3210,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;
@@ -3222,9 +3303,6 @@ nfs4_preprocess_stateid_op(struct nfsd4_compound_state *cstate,
        if (grace_disallows_io(ino))
                return nfserr_grace;
 
-       if (nfsd4_has_session(cstate))
-               flags |= HAS_SESSION;
-
        if (ZERO_STATEID(stateid) || ONE_STATEID(stateid))
                return check_special_stateids(current_fh, stateid, flags);
 
@@ -3237,14 +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,
-                                                 flags);
-               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;
@@ -3254,17 +3332,12 @@ 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_confirmed)
-                       goto out;
-               status = check_stateid_generation(stateid, &stp->st_stateid,
-                                                 flags);
-               if (status)
+               if (stp->st_stateowner->so_is_open_owner
+                   && !openowner(stp->st_stateowner)->oo_confirmed)
                        goto out;
                status = nfs4_check_openmode(stp, flags);
                if (status)
@@ -3285,16 +3358,17 @@ 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, stp->st_stateowner))
+       if (check_for_locks(stp->st_file, lockowner(stp->st_stateowner)))
                return nfserr_locks_held;
        release_lock_stateid(stp);
        return nfs_ok;
@@ -3319,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();
@@ -3328,23 +3402,16 @@ nfsd4_free_stateid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
                goto out;
        }
 
-       stp = search_for_stateid(stateid);
+       stp = find_ol_stateid(stateid);
        if (!stp) {
                ret = nfserr_bad_stateid;
                goto out;
        }
-       if (stateid->si_generation != 0) {
-               if (stateid->si_generation < stp->st_stateid.si_generation) {
-                       ret = nfserr_old_stateid;
-                       goto out;
-               }
-               if (stateid->si_generation > stp->st_stateid.si_generation) {
-                       ret = nfserr_bad_stateid;
-                       goto out;
-               }
-       }
+       ret = check_stateid_generation(stateid, &stp->st_stid.sc_stateid, 1);
+       if (ret)
+               goto out;
 
-       if (is_open_stateid(stp)) {
+       if (stp->st_stid.sc_type == NFS4_OPEN_STID) {
                ret = nfserr_locks_held;
                goto out;
        } else {
@@ -3364,124 +3431,68 @@ 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_stateowner **sopp,
-                        struct nfs4_stateid **stpp, struct nfsd4_lock *lock)
+                        stateid_t *stateid, char typemask,
+                        struct nfs4_ol_stateid **stpp)
 {
-       struct nfs4_stateid *stp;
-       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;
-       *sopp = 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;
-
-       if (nfsd4_has_session(cstate))
-               flags |= HAS_SESSION;
-
-       /*
-       * We return BAD_STATEID if filehandle doesn't match stateid, 
-       * the confirmed flag is incorrecly set, or the generation 
-       * number is incorrect.  
-       */
-       stp = find_stateid(stateid, flags);
-       if (stp == NULL) {
-               /*
-                * Also, we should make sure this isn't just the result of
-                * a replayed close:
-                */
-               sop = search_close_lru(stateid->si_stateownerid, flags);
-               /* It's not stale; let's assume it's expired: */
-               if (sop == NULL)
-                       return nfserr_expired;
-               *sopp = sop;
-               goto check_replay;
-       }
-
-       *stpp = stp;
-       *sopp = sop = stp->st_stateowner;
-
-       if (lock) {
-               clientid_t *lockclid = &lock->v.new.clientid;
-               struct nfs4_client *clp = sop->so_client;
-               int lkflg = 0;
-               __be32 status;
-
-               lkflg = setlkflg(lock->lk_type);
-
-               if (lock->lk_is_new) {
-                       if (!sop->so_is_open_owner)
-                               return nfserr_bad_stateid;
-                       if (!(flags & HAS_SESSION) &&
-                           !same_clid(&clp->cl_clientid, lockclid))
-                               return nfserr_bad_stateid;
-                       /* stp is the open stateid */
-                       status = nfs4_check_openmode(stp, lkflg);
-                       if (status)
-                               return status;
-               } else {
-                       /* stp is the lock stateid */
-                       status = nfs4_check_openmode(stp->st_openstp, lkflg);
-                       if (status)
-                               return status;
-               }
-       }
+       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);
 
-       if (nfs4_check_fh(current_fh, stp)) {
-               dprintk("NFSD: preprocess_seqid_op: fh-stateid mismatch!\n");
-               return nfserr_bad_stateid;
-       }
+       return nfs4_seqid_op_checks(cstate, stateid, seqid, *stpp);
+}
 
-       /*
-       *  We now validate the seqid and stateid generation numbers.
-       *  For the moment, we ignore the possibility of 
-       *  generation number wraparound.
-       */
-       if (!(flags & HAS_SESSION) && seqid != sop->so_seqid)
-               goto check_replay;
+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;
 
-       if (sop->so_confirmed && flags & CONFIRM) {
-               dprintk("NFSD: preprocess_seqid_op: expected"
-                               " unconfirmed stateowner!\n");
-               return nfserr_bad_stateid;
-       }
-       if (!sop->so_confirmed && !(flags & CONFIRM)) {
-               dprintk("NFSD: preprocess_seqid_op: stateowner not"
-                               " confirmed yet!\n");
-               return nfserr_bad_stateid;
-       }
-       status = check_stateid_generation(stateid, &stp->st_stateid, flags);
+       status = nfs4_preprocess_seqid_op(cstate, seqid, stateid,
+                                               NFS4_OPEN_STID, stpp);
        if (status)
                return status;
-       renew_client(sop->so_client);
+       oo = openowner((*stpp)->st_stateowner);
+       if (!oo->oo_confirmed)
+               return nfserr_bad_stateid;
        return nfs_ok;
-
-check_replay:
-       if (seqid == sop->so_seqid - 1) {
-               dprintk("NFSD: preprocess_seqid_op: retransmission?\n");
-               /* indicate replay to calling function */
-               return nfserr_replay_me;
-       }
-       dprintk("NFSD: preprocess_seqid_op: bad seqid (expected %d, got %d)\n",
-                       sop->so_seqid, seqid);
-       *sopp = NULL;
-       return nfserr_bad_seqid;
 }
 
 __be32
@@ -3489,8 +3500,8 @@ nfsd4_open_confirm(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
                   struct nfsd4_open_confirm *oc)
 {
        __be32 status;
-       struct nfs4_stateowner *sop;
-       struct nfs4_stateid *stp;
+       struct nfs4_openowner *oo;
+       struct nfs4_ol_stateid *stp;
 
        dprintk("NFSD: nfsd4_open_confirm on file %.*s\n",
                        (int)cstate->current_fh.fh_dentry->d_name.len,
@@ -3502,30 +3513,30 @@ nfsd4_open_confirm(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 
        nfs4_lock_state();
 
-       if ((status = nfs4_preprocess_seqid_op(cstate,
+       status = nfs4_preprocess_seqid_op(cstate,
                                        oc->oc_seqid, &oc->oc_req_stateid,
-                                       CONFIRM | OPEN_STATE,
-                                       &oc->oc_stateowner, &stp, NULL)))
-               goto out; 
-
-       sop = oc->oc_stateowner;
-       sop->so_confirmed = 1;
-       update_stateid(&stp->st_stateid);
-       memcpy(&oc->oc_resp_stateid, &stp->st_stateid, sizeof(stateid_t));
+                                       NFS4_OPEN_STID, &stp);
+       if (status)
+               goto out;
+       oo = openowner(stp->st_stateowner);
+       status = nfserr_bad_stateid;
+       if (oo->oo_confirmed)
+               goto out;
+       oo->oo_confirmed = 1;
+       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(sop->so_client);
+       nfsd4_create_clid_dir(oo->oo_owner.so_client);
+       status = nfs_ok;
 out:
-       if (oc->oc_stateowner) {
-               nfs4_get_stateowner(oc->oc_stateowner);
-               cstate->replay_owner = oc->oc_stateowner;
-       }
-       nfs4_unlock_state();
+       if (!cstate->replay_owner)
+               nfs4_unlock_state();
        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;
 
@@ -3553,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,
@@ -3564,13 +3575,10 @@ nfsd4_open_downgrade(struct svc_rqst *rqstp,
                return nfserr_inval;
 
        nfs4_lock_state();
-       if ((status = nfs4_preprocess_seqid_op(cstate,
-                                       od->od_seqid,
-                                       &od->od_stateid, 
-                                       OPEN_STATE,
-                                       &od->od_stateowner, &stp, NULL)))
+       status = nfs4_preprocess_confirmed_seqid_op(cstate, od->od_seqid,
+                                       &od->od_stateid, &stp);
+       if (status)
                goto out; 
-
        status = nfserr_inval;
        if (!test_bit(od->od_share_access, &stp->st_access_bmap)) {
                dprintk("NFSD:access not a subset current bitmap: 0x%lx, input access=%08x\n",
@@ -3586,15 +3594,12 @@ 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 (od->od_stateowner) {
-               nfs4_get_stateowner(od->od_stateowner);
-               cstate->replay_owner = od->od_stateowner;
-       }
-       nfs4_unlock_state();
+       if (!cstate->replay_owner)
+               nfs4_unlock_state();
        return status;
 }
 
@@ -3606,7 +3611,8 @@ nfsd4_close(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
            struct nfsd4_close *close)
 {
        __be32 status;
-       struct nfs4_stateid *stp;
+       struct nfs4_openowner *oo;
+       struct nfs4_ol_stateid *stp;
 
        dprintk("NFSD: nfsd4_close on file %.*s\n", 
                        (int)cstate->current_fh.fh_dentry->d_name.len,
@@ -3614,15 +3620,29 @@ nfsd4_close(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 
        nfs4_lock_state();
        /* check close_lru for replay */
-       if ((status = nfs4_preprocess_seqid_op(cstate,
-                                       close->cl_seqid,
-                                       &close->cl_stateid, 
-                                       OPEN_STATE | CLOSE_STATE,
-                                       &close->cl_stateowner, &stp, NULL)))
+       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
+                * a replayed close:
+                */
+               oo = search_close_lru(close->cl_stateid.si_stateownerid);
+               /* It's not stale; let's assume it's expired: */
+               if (oo == NULL)
+                       goto out;
+               cstate->replay_owner = &oo->oo_owner;
+               status = nfsd4_check_seqid(cstate, &oo->oo_owner, close->cl_seqid);
+               if (status)
+                       goto out;
+               status = nfserr_bad_seqid;
+       }
+       if (status)
                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);
@@ -3631,14 +3651,11 @@ nfsd4_close(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
         * 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);
+       if (list_empty(&oo->oo_owner.so_stateids))
+               move_to_close_lru(oo);
 out:
-       if (close->cl_stateowner) {
-               nfs4_get_stateowner(close->cl_stateowner);
-               cstate->replay_owner = close->cl_stateowner;
-       }
-       nfs4_unlock_state();
+       if (!cstate->replay_owner)
+               nfs4_unlock_state();
        return status;
 }
 
@@ -3650,14 +3667,11 @@ nfsd4_delegreturn(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
        stateid_t *stateid = &dr->dr_stateid;
        struct inode *inode;
        __be32 status;
-       int flags = 0;
 
        if ((status = fh_verify(rqstp, &cstate->current_fh, S_IFREG, 0)))
                return status;
        inode = cstate->current_fh.fh_dentry->d_inode;
 
-       if (nfsd4_has_session(cstate))
-               flags |= HAS_SESSION;
        nfs4_lock_state();
        status = nfserr_bad_stateid;
        if (ZERO_STATEID(stateid) || ONE_STATEID(stateid))
@@ -3669,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, flags);
+       status = check_stateid_generation(stateid, &dp->dl_stid.sc_stateid, nfsd4_has_session(cstate));
        if (status)
                goto out;
        renew_client(dp->dl_client);
@@ -3713,8 +3727,10 @@ last_byte_offset(u64 start, u64 len)
        return end > start ? end - 1: NFS4_MAX_UINT64;
 }
 
-#define lockownerid_hashval(id) \
-        ((id) & LOCK_HASH_MASK)
+static unsigned int lockownerid_hashval(u32 id)
+{
+       return id & LOCK_HASH_MASK;
+}
 
 static inline unsigned int
 lock_ownerstr_hashval(struct inode *inode, u32 cl_id,
@@ -3727,99 +3743,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 struct list_head lockstateid_hashtbl[STATEID_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 *stid, int flags)
-{
-       struct nfs4_stateid *local;
-       u32 st_id = stid->si_stateownerid;
-       u32 f_id = stid->si_fileid;
-       unsigned int hashval;
-
-       dprintk("NFSD: find_stateid flags 0x%x\n",flags);
-       if (flags & (LOCK_STATE | RD_STATE | WR_STATE)) {
-               hashval = stateid_hashval(st_id, f_id);
-               list_for_each_entry(local, &lockstateid_hashtbl[hashval], st_hash) {
-                       if ((local->st_stateid.si_stateownerid == st_id) &&
-                           (local->st_stateid.si_fileid == f_id))
-                               return local;
-               }
-       } 
-
-       if (flags & (OPEN_STATE | RD_STATE | WR_STATE)) {
-               hashval = stateid_hashval(st_id, f_id);
-               list_for_each_entry(local, &stateid_hashtbl[hashval], st_hash) {
-                       if ((local->st_stateid.si_stateownerid == st_id) &&
-                           (local->st_stateid.si_fileid == f_id))
-                               return local;
-               }
-       }
-       return NULL;
-}
-
-static struct nfs4_stateid *
-search_for_stateid(stateid_t *stid)
-{
-       struct nfs4_stateid *local;
-       unsigned int hashval = stateid_hashval(stid->si_stateownerid, stid->si_fileid);
-
-       list_for_each_entry(local, &lockstateid_hashtbl[hashval], st_hash) {
-               if (same_stateid(&local->st_stateid, stid))
-                       return local;
-       }
-
-       list_for_each_entry(local, &stateid_hashtbl[hashval], st_hash) {
-               if (same_stateid(&local->st_stateid, stid))
-                       return local;
-       }
-       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
@@ -3846,15 +3769,21 @@ static const struct lock_manager_operations nfsd_posix_mng_ops  = {
 static inline void
 nfs4_set_lock_denied(struct file_lock *fl, struct nfsd4_lock_denied *deny)
 {
-       struct nfs4_stateowner *sop;
+       struct nfs4_lockowner *lo;
 
        if (fl->fl_lmops == &nfsd_posix_mng_ops) {
-               sop = (struct nfs4_stateowner *) fl->fl_owner;
-               kref_get(&sop->so_ref);
-               deny->ld_sop = sop;
-               deny->ld_clientid = sop->so_client->cl_clientid;
+               lo = (struct nfs4_lockowner *) fl->fl_owner;
+               deny->ld_owner.data = kmemdup(lo->lo_owner.so_owner.data,
+                                       lo->lo_owner.so_owner.len, GFP_KERNEL);
+               if (!deny->ld_owner.data)
+                       /* We just don't care that much */
+                       goto nevermind;
+               deny->ld_owner.len = lo->lo_owner.so_owner.len;
+               deny->ld_clientid = lo->lo_owner.so_client->cl_clientid;
        } else {
-               deny->ld_sop = NULL;
+nevermind:
+               deny->ld_owner.len = 0;
+               deny->ld_owner.data = NULL;
                deny->ld_clientid.cl_boot = 0;
                deny->ld_clientid.cl_id = 0;
        }
@@ -3867,8 +3796,8 @@ nfs4_set_lock_denied(struct file_lock *fl, struct nfsd4_lock_denied *deny)
                deny->ld_type = NFS4_WRITE_LT;
 }
 
-static struct nfs4_stateowner *
-find_lockstateowner_str(struct inode *inode, clientid_t *clid,
+static struct nfs4_lockowner *
+find_lockowner_str(struct inode *inode, clientid_t *clid,
                struct xdr_netobj *owner)
 {
        unsigned int hashval = lock_ownerstr_hashval(inode, clid->cl_id, owner);
@@ -3876,11 +3805,21 @@ find_lockstateowner_str(struct inode *inode, clientid_t *clid,
 
        list_for_each_entry(op, &lock_ownerstr_hashtbl[hashval], so_strhash) {
                if (same_owner_str(op, owner, clid))
-                       return op;
+                       return lockowner(op);
        }
        return NULL;
 }
 
+static void hash_lockowner(struct nfs4_lockowner *lo, unsigned int strhashval, struct nfs4_client *clp, struct nfs4_ol_stateid *open_stp)
+{
+       unsigned int idhashval;
+
+       idhashval = lockownerid_hashval(lo->lo_owner.so_id);
+       list_add(&lo->lo_owner.so_idhash, &lock_ownerid_hashtbl[idhashval]);
+       list_add(&lo->lo_owner.so_strhash, &lock_ownerstr_hashtbl[strhashval]);
+       list_add(&lo->lo_perstateid, &open_stp->st_lockowners);
+}
+
 /*
  * Alloc a lock owner structure.
  * Called in nfsd4_lock - therefore, OPEN and OPEN_CONFIRM (if needed) has 
@@ -3889,62 +3828,42 @@ find_lockstateowner_str(struct inode *inode, clientid_t *clid,
  * strhashval = lock_ownerstr_hashval 
  */
 
-static struct nfs4_stateowner *
-alloc_init_lock_stateowner(unsigned int strhashval, struct nfs4_client *clp, struct nfs4_stateid *open_stp, struct nfsd4_lock *lock) {
-       struct nfs4_stateowner *sop;
-       struct nfs4_replay *rp;
-       unsigned int idhashval;
+static struct nfs4_lockowner *
+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;
 
-       if (!(sop = alloc_stateowner(&lock->lk_new_owner)))
+       lo = alloc_stateowner(lockowner_slab, &lock->lk_new_owner, clp);
+       if (!lo)
                return NULL;
-       idhashval = lockownerid_hashval(current_ownerid);
-       INIT_LIST_HEAD(&sop->so_idhash);
-       INIT_LIST_HEAD(&sop->so_strhash);
-       INIT_LIST_HEAD(&sop->so_perclient);
-       INIT_LIST_HEAD(&sop->so_stateids);
-       INIT_LIST_HEAD(&sop->so_perstateid);
-       INIT_LIST_HEAD(&sop->so_close_lru); /* not used */
-       sop->so_time = 0;
-       list_add(&sop->so_idhash, &lock_ownerid_hashtbl[idhashval]);
-       list_add(&sop->so_strhash, &lock_ownerstr_hashtbl[strhashval]);
-       list_add(&sop->so_perstateid, &open_stp->st_lockowners);
-       sop->so_is_open_owner = 0;
-       sop->so_id = current_ownerid++;
-       sop->so_client = clp;
+       INIT_LIST_HEAD(&lo->lo_owner.so_stateids);
+       lo->lo_owner.so_is_open_owner = 0;
        /* It is the openowner seqid that will be incremented in encode in the
         * case of new lockowners; so increment the lock seqid manually: */
-       sop->so_seqid = lock->lk_new_lock_seqid + 1;
-       sop->so_confirmed = 1;
-       rp = &sop->so_replay;
-       rp->rp_status = nfserr_serverfault;
-       rp->rp_buflen = 0;
-       rp->rp_buf = rp->rp_ibuf;
-       return sop;
+       lo->lo_owner.so_seqid = lock->lk_new_lock_seqid + 1;
+       hash_lockowner(lo, strhashval, clp, open_stp);
+       return lo;
 }
 
-static struct nfs4_stateid *
-alloc_init_lock_stateid(struct nfs4_stateowner *sop, 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(sop->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, &lockstateid_hashtbl[hashval]);
        list_add(&stp->st_perfile, &fp->fi_stateids);
-       list_add(&stp->st_perstateowner, &sop->so_stateids);
-       stp->st_stateowner = sop;
+       list_add(&stp->st_perstateowner, &lo->lo_owner.so_stateids);
+       stp->st_stateowner = &lo->lo_owner;
+       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 = sop->so_id;
-       stp->st_stateid.si_fileid = fp->fi_id;
-       stp->st_stateid.si_generation = 0;
+       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_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;
@@ -3960,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);
@@ -3978,15 +3897,16 @@ __be32
 nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
           struct nfsd4_lock *lock)
 {
-       struct nfs4_stateowner *open_sop = NULL;
-       struct nfs4_stateowner *lock_sop = NULL;
-       struct nfs4_stateid *lock_stp;
+       struct nfs4_openowner *open_sop = NULL;
+       struct nfs4_lockowner *lock_sop = NULL;
+       struct nfs4_ol_stateid *lock_stp;
        struct nfs4_file *fp;
        struct file *filp = NULL;
        struct file_lock file_lock;
        struct file_lock conflock;
        __be32 status = 0;
        unsigned int strhashval;
+       int lkflg;
        int err;
 
        dprintk("NFSD: nfsd4_lock: start=%Ld length=%Ld\n",
@@ -4010,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) &&
@@ -4018,26 +3938,29 @@ 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,
-                                       &lock->lk_replay_owner, &open_stp,
-                                       lock);
+                                       &open_stp);
                if (status)
                        goto out;
-               open_sop = lock->lk_replay_owner;
+               open_sop = openowner(open_stp->st_stateowner);
+               status = nfserr_bad_stateid;
+               if (!nfsd4_has_session(cstate) &&
+                       !same_clid(&open_sop->oo_owner.so_client->cl_clientid,
+                                               &lock->v.new.clientid))
+                       goto out;
                /* create lockowner and lock stateid */
                fp = open_stp->st_file;
-               strhashval = lock_ownerstr_hashval(fp->fi_inode, 
-                               open_sop->so_client->cl_clientid.cl_id, 
+               strhashval = lock_ownerstr_hashval(fp->fi_inode,
+                               open_sop->oo_owner.so_client->cl_clientid.cl_id,
                                &lock->v.new.owner);
                /* XXX: Do we need to check for duplicate stateowners on
                 * the same file, or should they just be allowed (and
                 * create new stateids)? */
-               status = nfserr_resource;
+               status = nfserr_jukebox;
                lock_sop = alloc_init_lock_stateowner(strhashval,
-                               open_sop->so_client, open_stp, lock);
+                               open_sop->oo_owner.so_client, open_stp, lock);
                if (lock_sop == NULL)
                        goto out;
                lock_stp = alloc_init_lock_stateid(lock_sop, fp, open_stp);
@@ -4046,16 +3969,20 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
        } else {
                /* lock (lock owner + lock stateid) already exists */
                status = nfs4_preprocess_seqid_op(cstate,
-                                      lock->lk_old_lock_seqid, 
-                                      &lock->lk_old_lock_stateid, 
-                                      LOCK_STATE,
-                                      &lock->lk_replay_owner, &lock_stp, lock);
+                                      lock->lk_old_lock_seqid,
+                                      &lock->lk_old_lock_stateid,
+                                      NFS4_LOCK_STID, &lock_stp);
                if (status)
                        goto out;
-               lock_sop = lock->lk_replay_owner;
+               lock_sop = lockowner(lock_stp->st_stateowner);
                fp = lock_stp->st_file;
        }
-       /* lock->lk_replay_owner and lock_stp have been created or found */
+       /* lock_sop and lock_stp have been created or found */
+
+       lkflg = setlkflg(lock->lk_type);
+       status = nfs4_check_openmode(lock_stp, lkflg);
+       if (status)
+               goto out;
 
        status = nfserr_grace;
        if (locks_in_grace() && !lock->lk_reclaim)
@@ -4106,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;
@@ -4119,19 +4046,16 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
        case (EDEADLK):
                status = nfserr_deadlock;
                break;
-       default:        
+       default:
                dprintk("NFSD: nfsd4_lock: vfs_lock_file() failed! status %d\n",err);
-               status = nfserr_resource;
+               status = nfserrno(err);
                break;
        }
 out:
        if (status && lock->lk_is_new && lock_sop)
                release_lockowner(lock_sop);
-       if (lock->lk_replay_owner) {
-               nfs4_get_stateowner(lock->lk_replay_owner);
-               cstate->replay_owner = lock->lk_replay_owner;
-       }
-       nfs4_unlock_state();
+       if (!cstate->replay_owner)
+               nfs4_unlock_state();
        return status;
 }
 
@@ -4163,6 +4087,7 @@ nfsd4_lockt(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 {
        struct inode *inode;
        struct file_lock file_lock;
+       struct nfs4_lockowner *lo;
        int error;
        __be32 status;
 
@@ -4172,19 +4097,14 @@ nfsd4_lockt(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
        if (check_lock_length(lockt->lt_offset, lockt->lt_length))
                 return nfserr_inval;
 
-       lockt->lt_stateowner = NULL;
        nfs4_lock_state();
 
        status = nfserr_stale_clientid;
        if (!nfsd4_has_session(cstate) && STALE_CLIENTID(&lockt->lt_clientid))
                goto out;
 
-       if ((status = fh_verify(rqstp, &cstate->current_fh, S_IFREG, 0))) {
-               dprintk("NFSD: nfsd4_lockt: fh_verify() failed!\n");
-               if (status == nfserr_symlink)
-                       status = nfserr_inval;
+       if ((status = fh_verify(rqstp, &cstate->current_fh, S_IFREG, 0)))
                goto out;
-       }
 
        inode = cstate->current_fh.fh_dentry->d_inode;
        locks_init_lock(&file_lock);
@@ -4203,10 +4123,9 @@ nfsd4_lockt(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
                goto out;
        }
 
-       lockt->lt_stateowner = find_lockstateowner_str(inode,
-                       &lockt->lt_clientid, &lockt->lt_owner);
-       if (lockt->lt_stateowner)
-               file_lock.fl_owner = (fl_owner_t)lockt->lt_stateowner;
+       lo = find_lockowner_str(inode, &lockt->lt_clientid, &lockt->lt_owner);
+       if (lo)
+               file_lock.fl_owner = (fl_owner_t)lo;
        file_lock.fl_pid = current->tgid;
        file_lock.fl_flags = FL_POSIX;
 
@@ -4234,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;
@@ -4249,13 +4168,10 @@ nfsd4_locku(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 
        nfs4_lock_state();
                                                                                
-       if ((status = nfs4_preprocess_seqid_op(cstate,
-                                       locku->lu_seqid, 
-                                       &locku->lu_stateid, 
-                                       LOCK_STATE,
-                                       &locku->lu_stateowner, &stp, NULL)))
+       status = nfs4_preprocess_seqid_op(cstate, locku->lu_seqid,
+                                       &locku->lu_stateid, NFS4_LOCK_STID, &stp);
+       if (status)
                goto out;
-
        filp = find_any_file(stp->st_file);
        if (!filp) {
                status = nfserr_lock_range;
@@ -4264,7 +4180,7 @@ nfsd4_locku(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
        BUG_ON(!filp);
        locks_init_lock(&file_lock);
        file_lock.fl_type = F_UNLCK;
-       file_lock.fl_owner = (fl_owner_t) locku->lu_stateowner;
+       file_lock.fl_owner = (fl_owner_t)lockowner(stp->st_stateowner);
        file_lock.fl_pid = current->tgid;
        file_lock.fl_file = filp;
        file_lock.fl_flags = FL_POSIX; 
@@ -4285,14 +4201,10 @@ 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:
-       if (locku->lu_stateowner) {
-               nfs4_get_stateowner(locku->lu_stateowner);
-               cstate->replay_owner = locku->lu_stateowner;
-       }
        nfs4_unlock_state();
        return status;
 
@@ -4307,7 +4219,7 @@ out_nfserr:
  *     0: no locks held by lockowner
  */
 static int
-check_for_locks(struct nfs4_file *filp, struct nfs4_stateowner *lowner)
+check_for_locks(struct nfs4_file *filp, struct nfs4_lockowner *lowner)
 {
        struct file_lock **flpp;
        struct inode *inode = filp->fi_inode;
@@ -4332,7 +4244,8 @@ nfsd4_release_lockowner(struct svc_rqst *rqstp,
 {
        clientid_t *clid = &rlockowner->rl_clientid;
        struct nfs4_stateowner *sop;
-       struct nfs4_stateid *stp;
+       struct nfs4_lockowner *lo;
+       struct nfs4_ol_stateid *stp;
        struct xdr_netobj *owner = &rlockowner->rl_owner;
        struct list_head matches;
        int i;
@@ -4361,11 +4274,10 @@ nfsd4_release_lockowner(struct svc_rqst *rqstp,
                                continue;
                        list_for_each_entry(stp, &sop->so_stateids,
                                        st_perstateowner) {
-                               if (check_for_locks(stp->st_file, sop))
+                               lo = lockowner(sop);
+                               if (check_for_locks(stp->st_file, lo))
                                        goto out;
-                               /* Note: so_perclient unused for lockowners,
-                                * so it's OK to fool with here. */
-                               list_add(&sop->so_perclient, &matches);
+                               list_add(&lo->lo_list, &matches);
                        }
                }
        }
@@ -4374,12 +4286,12 @@ nfsd4_release_lockowner(struct svc_rqst *rqstp,
         * have been checked. */
        status = nfs_ok;
        while (!list_empty(&matches)) {
-               sop = list_entry(matches.next, struct nfs4_stateowner,
-                                                               so_perclient);
+               lo = list_entry(matches.next, struct nfs4_lockowner,
+                                                               lo_list);
                /* unhash_stateowner deletes so_perclient only
                 * for openowners. */
-               list_del(&sop->so_perclient);
-               release_lockowner(sop);
+               list_del(&lo->lo_list);
+               release_lockowner(lo);
        }
 out:
        nfs4_unlock_state();
@@ -4501,14 +4413,12 @@ nfs4_state_init(void)
        for (i = 0; i < FILE_HASH_SIZE; i++) {
                INIT_LIST_HEAD(&file_hashtbl[i]);
        }
-       for (i = 0; i < OWNER_HASH_SIZE; i++) {
-               INIT_LIST_HEAD(&ownerstr_hashtbl[i]);
-               INIT_LIST_HEAD(&ownerid_hashtbl[i]);
+       for (i = 0; i < OPEN_OWNER_HASH_SIZE; i++) {
+               INIT_LIST_HEAD(&open_ownerstr_hashtbl[i]);
+               INIT_LIST_HEAD(&open_ownerid_hashtbl[i]);
        }
-       for (i = 0; i < STATEID_HASH_SIZE; i++) {
+       for (i = 0; i < STATEID_HASH_SIZE; i++)
                INIT_LIST_HEAD(&stateid_hashtbl[i]);
-               INIT_LIST_HEAD(&lockstateid_hashtbl[i]);
-       }
        for (i = 0; i < LOCK_HASH_SIZE; i++) {
                INIT_LIST_HEAD(&lock_ownerid_hashtbl[i]);
                INIT_LIST_HEAD(&lock_ownerstr_hashtbl[i]);
@@ -4527,7 +4437,7 @@ nfsd4_load_reboot_recovery_data(void)
        int status;
 
        nfs4_lock_state();
-       nfsd4_init_recdir(user_recovery_dirname);
+       nfsd4_init_recdir();
        status = nfsd4_recdir_load();
        nfs4_unlock_state();
        if (status)
@@ -4636,40 +4546,3 @@ nfs4_state_shutdown(void)
        nfs4_unlock_state();
        nfsd4_destroy_callback_queue();
 }
-
-/*
- * user_recovery_dirname is protected by the nfsd_mutex since it's only
- * accessed when nfsd is starting.
- */
-static void
-nfs4_set_recdir(char *recdir)
-{
-       strcpy(user_recovery_dirname, recdir);
-}
-
-/*
- * Change the NFSv4 recovery directory to recdir.
- */
-int
-nfs4_reset_recoverydir(char *recdir)
-{
-       int status;
-       struct path path;
-
-       status = kern_path(recdir, LOOKUP_FOLLOW, &path);
-       if (status)
-               return status;
-       status = -ENOTDIR;
-       if (S_ISDIR(path.dentry->d_inode->i_mode)) {
-               nfs4_set_recdir(recdir);
-               status = 0;
-       }
-       path_put(&path);
-       return status;
-}
-
-char *
-nfs4_recoverydir(void)
-{
-       return user_recovery_dirname;
-}
This page took 0.082425 seconds and 5 git commands to generate.