#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: */
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];
__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)
{
get_nfs4_file(fp);
dp->dl_file = fp;
dp->dl_type = type;
+ 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, ¤t_fh->fh_handle);
dp->dl_time = 0;
atomic_set(&dp->dl_count, 1);
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);
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)
{
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;
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,
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_stid.sc_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
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);
__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;
}
/*
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;
* 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_stid.sc_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;
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;
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;
}
goto out;
}
- stp = find_stateid(stateid);
+ stp = find_ol_stateid(stateid);
if (!stp) {
ret = nfserr_bad_stateid;
goto out;
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;
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_stid.sc_stateid, nfsd4_has_session(cstate));
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_stid.sc_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
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;
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;