NFSD: Remove the ex_pathname field from struct svc_export
[deliverable/linux.git] / fs / nfsd / nfs4state.c
index d0bb5a5613a9dcb429c1bf4853df8c14962f4b00..0cd346477f29ce511e7f8b5579090fbba797c52c 100644 (file)
@@ -60,8 +60,6 @@ static u64 current_sessionid = 1;
 #define ONE_STATEID(stateid)  (!memcmp((stateid), &onestateid, sizeof(stateid_t)))
 
 /* forward declarations */
-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: */
@@ -170,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];
@@ -218,6 +216,15 @@ 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_ol_stateid *stp, struct svc_fh *current_fh, u32 type)
 {
@@ -247,10 +254,12 @@ alloc_init_deleg(struct nfs4_client *clp, struct nfs4_ol_stateid *stp, struct sv
        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);
@@ -283,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);
@@ -1068,30 +1078,50 @@ same_stateid(stateid_t *id_one, stateid_t *id_two)
        return id_one->si_fileid == id_two->si_fileid;
 }
 
-static struct nfs4_ol_stateid *find_stateid(stateid_t *t)
+static struct nfs4_stid *find_stateid(stateid_t *t)
 {
        struct nfs4_stid *s;
        unsigned int hashval;
 
-       hashval = stateid_hashval(t->si_stateownerid, t->si_fileid);
+       hashval = stateid_hashval(t);
        list_for_each_entry(s, &stateid_hashtbl[hashval], sc_hash)
                if (same_stateid(&s->sc_stateid, t))
-                       return openlockstateid(s);
+                       return s;
        return NULL;
 }
 
-static struct nfs4_ol_stateid *find_stateid_by_type(stateid_t *t, char typemask)
+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_ol_stateid *s;
+       struct nfs4_stid *s;
 
        s = find_stateid(t);
        if (!s)
                return NULL;
-       if (typemask & s->st_stid.sc_type)
+       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)
 {
@@ -2316,10 +2346,8 @@ alloc_init_open_stateowner(unsigned int strhashval, struct nfs4_client *clp, str
 static inline void
 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_lockowners);
-       list_add(&stp->st_stid.sc_hash, &stateid_hashtbl[hashval]);
        list_add(&stp->st_perstateowner, &oo->oo_owner.so_stateids);
        list_add(&stp->st_perfile, &fp->fi_stateids);
        stp->st_stid.sc_type = NFS4_OPEN_STID;
@@ -2331,6 +2359,7 @@ init_open_stateid(struct nfs4_ol_stateid *stp, struct nfs4_file *fp, struct nfsd
        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,
@@ -2565,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
@@ -2594,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);
@@ -2861,10 +2885,10 @@ nfs4_open_delegation(struct svc_fh *fh, struct nfsd4_open *open, struct nfs4_ol_
        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
@@ -3237,28 +3261,26 @@ static int is_delegation_stateid(stateid_t *stateid)
 
 __be32 nfs4_validate_stateid(stateid_t *stateid, bool has_session)
 {
-       struct nfs4_ol_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);
-       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_stid.sc_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;
 }
 
 /*
@@ -3268,6 +3290,7 @@ __be32
 nfs4_preprocess_stateid_op(struct nfsd4_compound_state *cstate,
                           stateid_t *stateid, int flags, struct file **filpp)
 {
+       struct nfs4_stid *s;
        struct nfs4_ol_stateid *stp = NULL;
        struct nfs4_delegation *dp = NULL;
        struct svc_fh *current_fh = &cstate->current_fh;
@@ -3292,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;
@@ -3308,19 +3332,13 @@ nfs4_preprocess_stateid_op(struct nfsd4_compound_state *cstate,
                        BUG_ON(!*filpp);
                }
        } else { /* open or lock stateid */
-               stp = find_stateid(stateid);
-               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_stid.sc_stateid,
-                                                 nfsd4_has_session(cstate));
-               if (status)
-                       goto out;
                status = nfs4_check_openmode(stp, flags);
                if (status)
                        goto out;
@@ -3340,9 +3358,10 @@ 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;
 }
 
@@ -3383,7 +3402,7 @@ nfsd4_free_stateid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
                goto out;
        }
 
-       stp = find_stateid(stateid);
+       stp = find_ol_stateid(stateid);
        if (!stp) {
                ret = nfserr_bad_stateid;
                goto out;
@@ -3452,7 +3471,7 @@ nfs4_preprocess_seqid_op(struct nfsd4_compound_state *cstate, u32 seqid,
        status = nfs4_nospecial_stateid_checks(stateid);
        if (status)
                return status;
-       *stpp = find_stateid_by_type(stateid, typemask);
+       *stpp = find_ol_stateid_by_type(stateid, typemask);
        if (*stpp == NULL)
                return nfserr_expired;
        cstate->replay_owner = (*stpp)->st_stateowner;
@@ -3664,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);
@@ -3725,43 +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 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
@@ -3866,12 +3848,10 @@ 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_ol_stateid *stp;
-       unsigned int hashval = stateid_hashval(lo->lo_owner.so_id, fp->fi_id);
 
        stp = nfs4_alloc_stateid();
        if (stp == NULL)
                goto out;
-       list_add(&stp->st_stid.sc_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;
@@ -3883,6 +3863,7 @@ alloc_init_lock_stateid(struct nfs4_lockowner *lo, struct nfs4_file *fp, struct
        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;
This page took 0.029713 seconds and 5 git commands to generate.