2012-03-04 23:03:09

by Myklebust, Trond

[permalink] [raw]
Subject: [PATCH 01/11] NFSv4.1: Fix matching of the stateids when returning a delegation

nfs41_validate_delegation_stateid is broken if we supply a stateid with
a non-zero sequence id. Instead of trying to match the sequence id,
the function assumes that we always want to error. While this is
true for a delegation callback, it is not true in general.

Also fix a typo in nfs4_callback_recall.

Reported-by: Andy Adamson <[email protected]>
Signed-off-by: Trond Myklebust <[email protected]>
Cc: [email protected]
---
fs/nfs/callback_proc.c | 10 +++++-----
fs/nfs/delegation.c | 2 +-
2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/fs/nfs/callback_proc.c b/fs/nfs/callback_proc.c
index 1bb2972..ea83219 100644
--- a/fs/nfs/callback_proc.c
+++ b/fs/nfs/callback_proc.c
@@ -87,8 +87,7 @@ __be32 nfs4_callback_recall(struct cb_recallargs *args, void *dummy,
res = 0;
break;
case -ENOENT:
- if (res != 0)
- res = htonl(NFS4ERR_BAD_STATEID);
+ res = htonl(NFS4ERR_BAD_STATEID);
break;
default:
res = htonl(NFS4ERR_RESOURCE);
@@ -325,10 +324,11 @@ int nfs41_validate_delegation_stateid(struct nfs_delegation *delegation, const n
if (delegation == NULL)
return 0;

- if (stateid->stateid.seqid != 0)
+ if (stateid->stateid.seqid != 0 &&
+ stateid->stateid.seqid != delegation->stateid.stateid.seqid)
return 0;
- if (memcmp(&delegation->stateid.stateid.other,
- &stateid->stateid.other,
+ if (memcmp(delegation->stateid.stateid.other,
+ stateid->stateid.other,
NFS4_STATEID_OTHER_SIZE))
return 0;

diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c
index 7f26540..1596098 100644
--- a/fs/nfs/delegation.c
+++ b/fs/nfs/delegation.c
@@ -531,7 +531,7 @@ void nfs_expire_unreferenced_delegations(struct nfs_client *clp)
/**
* nfs_async_inode_return_delegation - asynchronously return a delegation
* @inode: inode to process
- * @stateid: state ID information from CB_RECALL arguments
+ * @stateid: state ID information
*
* Returns zero on success, or a negative errno value.
*/
--
1.7.7.6



2012-03-05 17:36:01

by Myklebust, Trond

[permalink] [raw]
Subject: Re: [PATCH 08/11] NFSv4: Simplify the struct nfs4_stateid

T24gTW9uLCAyMDEyLTAzLTA1IGF0IDEyOjE0IC0wNTAwLCBCcnlhbiBTY2h1bWFrZXIgd3JvdGU6
DQo+IEkganVzdCBmaW5pc2hlZCBiaXNlY3RpbmcgYW4gb29wcyB0byB0aGlzIHBhdGNoLCBkb2Vz
IHYyIGZpeCB0aGUgcHJvYmxlbT8gIEkgaGl0IGl0IHdoaWxlIHJ1bm5pbmcgdGhlIHNwZWNpYWwg
dGVzdHMgb3ZlciB2NC4gIEkgd2FzIGFibGUgdG8gY29tcGlsZSBhZnRlciB0aGVzZSBwYXRjaGVz
LCBzbyB0aGF0J3MgYSBzdGVwIGZvcndhcmQhDQoNCkkndmUgZ290IGEgZml4IGZvciB0aGF0IGlu
IHYzLi4uDQoNCi0tIA0KVHJvbmQgTXlrbGVidXN0DQpMaW51eCBORlMgY2xpZW50IG1haW50YWlu
ZXINCg0KTmV0QXBwDQpUcm9uZC5NeWtsZWJ1c3RAbmV0YXBwLmNvbQ0Kd3d3Lm5ldGFwcC5jb20N
Cg0K

2012-03-04 23:03:09

by Myklebust, Trond

[permalink] [raw]
Subject: [PATCH 02/11] NFSv4: Further clean-ups of delegation stateid validation

Change the name to reflect what we're really doing: testing two
stateids for whether or not they match according the the rules in
RFC3530 and RFC5661.
Move the code from callback_proc.c to nfs4proc.c

Signed-off-by: Trond Myklebust <[email protected]>
---
fs/nfs/callback_proc.c | 24 ------------------------
fs/nfs/delegation.c | 2 +-
fs/nfs/nfs4_fs.h | 2 +-
fs/nfs/nfs4proc.c | 27 +++++++++++++++++++++++++--
4 files changed, 27 insertions(+), 28 deletions(-)

diff --git a/fs/nfs/callback_proc.c b/fs/nfs/callback_proc.c
index ea83219..1b5d809 100644
--- a/fs/nfs/callback_proc.c
+++ b/fs/nfs/callback_proc.c
@@ -98,14 +98,6 @@ out:
return res;
}

-int nfs4_validate_delegation_stateid(struct nfs_delegation *delegation, const nfs4_stateid *stateid)
-{
- if (delegation == NULL || memcmp(delegation->stateid.data, stateid->data,
- sizeof(delegation->stateid.data)) != 0)
- return 0;
- return 1;
-}
-
#if defined(CONFIG_NFS_V4_1)

/*
@@ -319,22 +311,6 @@ out:
return res;
}

-int nfs41_validate_delegation_stateid(struct nfs_delegation *delegation, const nfs4_stateid *stateid)
-{
- if (delegation == NULL)
- return 0;
-
- if (stateid->stateid.seqid != 0 &&
- stateid->stateid.seqid != delegation->stateid.stateid.seqid)
- return 0;
- if (memcmp(delegation->stateid.stateid.other,
- stateid->stateid.other,
- NFS4_STATEID_OTHER_SIZE))
- return 0;
-
- return 1;
-}
-
/*
* Validate the sequenceID sent by the server.
* Return success if the sequenceID is one more than what we last saw on
diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c
index 1596098..9722e15 100644
--- a/fs/nfs/delegation.c
+++ b/fs/nfs/delegation.c
@@ -545,7 +545,7 @@ int nfs_async_inode_return_delegation(struct inode *inode,
rcu_read_lock();
delegation = rcu_dereference(NFS_I(inode)->delegation);

- if (!clp->cl_mvops->validate_stateid(delegation, stateid)) {
+ if (!clp->cl_mvops->match_stateid(&delegation->stateid, stateid)) {
rcu_read_unlock();
return -ENOENT;
}
diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h
index 19079ec..9c05799 100644
--- a/fs/nfs/nfs4_fs.h
+++ b/fs/nfs/nfs4_fs.h
@@ -43,7 +43,7 @@ struct nfs4_minor_version_ops {
struct nfs4_sequence_args *args,
struct nfs4_sequence_res *res,
int cache_reply);
- int (*validate_stateid)(struct nfs_delegation *,
+ bool (*match_stateid)(const nfs4_stateid *,
const nfs4_stateid *);
int (*find_root_sec)(struct nfs_server *, struct nfs_fh *,
struct nfs_fsinfo *);
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index ea7adfc..a79f623 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -6257,8 +6257,31 @@ static int nfs41_free_stateid(struct nfs_server *server, nfs4_stateid *stateid)
} while (exception.retry);
return err;
}
+
+static bool nfs41_match_stateid(const nfs4_stateid *s1,
+ const nfs4_stateid *s2)
+{
+ if (memcmp(s1->stateid.other, s2->stateid.other,
+ sizeof(s1->stateid.other)) != 0)
+ return false;
+
+ if (s1->stateid.seqid == s2->stateid.seqid)
+ return true;
+ if (s1->stateid.seqid == 0 || s1->stateid.seqid == 0)
+ return true;
+
+ return false;
+}
+
#endif /* CONFIG_NFS_V4_1 */

+static bool nfs4_match_stateid(const nfs4_stateid *s1,
+ const nfs4_stateid *s2)
+{
+ return memcmp(s1->data, s2->data, sizeof(s1->data)) == 0;
+}
+
+
struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = {
.owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT,
.state_flag_bit = NFS_STATE_RECLAIM_REBOOT,
@@ -6317,7 +6340,7 @@ struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = {
static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = {
.minor_version = 0,
.call_sync = _nfs4_call_sync,
- .validate_stateid = nfs4_validate_delegation_stateid,
+ .match_stateid = nfs4_match_stateid,
.find_root_sec = nfs4_find_root_sec,
.reboot_recovery_ops = &nfs40_reboot_recovery_ops,
.nograce_recovery_ops = &nfs40_nograce_recovery_ops,
@@ -6328,7 +6351,7 @@ static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = {
static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = {
.minor_version = 1,
.call_sync = _nfs4_call_sync_session,
- .validate_stateid = nfs41_validate_delegation_stateid,
+ .match_stateid = nfs41_match_stateid,
.find_root_sec = nfs41_find_root_sec,
.reboot_recovery_ops = &nfs41_reboot_recovery_ops,
.nograce_recovery_ops = &nfs41_nograce_recovery_ops,
--
1.7.7.6


2012-03-04 23:03:13

by Myklebust, Trond

[permalink] [raw]
Subject: [PATCH 07/11] NFSv4: Add helpers for basic copying of stateids

Signed-off-by: Trond Myklebust <[email protected]>
---
fs/nfs/delegation.c | 10 ++++------
fs/nfs/nfs4_fs.h | 10 ++++++++++
fs/nfs/nfs4proc.c | 34 +++++++++++++++-------------------
fs/nfs/nfs4state.c | 4 ++--
fs/nfs/pnfs.c | 10 ++++------
5 files changed, 35 insertions(+), 33 deletions(-)

diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c
index 9722e15..6502e59 100644
--- a/fs/nfs/delegation.c
+++ b/fs/nfs/delegation.c
@@ -105,7 +105,7 @@ again:
continue;
if (!test_bit(NFS_DELEGATED_STATE, &state->flags))
continue;
- if (memcmp(state->stateid.data, stateid->data, sizeof(state->stateid.data)) != 0)
+ if (!nfs4_stateid_match(&state->stateid, stateid))
continue;
get_nfs_open_context(ctx);
spin_unlock(&inode->i_lock);
@@ -139,8 +139,7 @@ void nfs_inode_reclaim_delegation(struct inode *inode, struct rpc_cred *cred,
if (delegation != NULL) {
spin_lock(&delegation->lock);
if (delegation->inode != NULL) {
- memcpy(delegation->stateid.data, res->delegation.data,
- sizeof(delegation->stateid.data));
+ nfs4_stateid_copy(&delegation->stateid, &res->delegation);
delegation->type = res->delegation_type;
delegation->maxsize = res->maxsize;
oldcred = delegation->cred;
@@ -236,8 +235,7 @@ int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct
delegation = kmalloc(sizeof(*delegation), GFP_NOFS);
if (delegation == NULL)
return -ENOMEM;
- memcpy(delegation->stateid.data, res->delegation.data,
- sizeof(delegation->stateid.data));
+ nfs4_stateid_copy(&delegation->stateid, &res->delegation);
delegation->type = res->delegation_type;
delegation->maxsize = res->maxsize;
delegation->change_attr = inode->i_version;
@@ -697,7 +695,7 @@ int nfs4_copy_delegation_stateid(nfs4_stateid *dst, struct inode *inode)
rcu_read_lock();
delegation = rcu_dereference(nfsi->delegation);
if (delegation != NULL) {
- memcpy(dst->data, delegation->stateid.data, sizeof(dst->data));
+ nfs4_stateid_copy(dst, &delegation->stateid);
ret = 1;
}
rcu_read_unlock();
diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h
index e76f17c..f4cafab 100644
--- a/fs/nfs/nfs4_fs.h
+++ b/fs/nfs/nfs4_fs.h
@@ -347,6 +347,16 @@ struct nfs4_mount_data;
extern struct svc_version nfs4_callback_version1;
extern struct svc_version nfs4_callback_version4;

+static inline void nfs4_stateid_copy(nfs4_stateid *dst, const nfs4_stateid *src)
+{
+ memcpy(dst->data, src->data, sizeof(dst->data));
+}
+
+static inline bool nfs4_stateid_match(const nfs4_stateid *dst, const nfs4_stateid *src)
+{
+ return memcmp(dst->data, src->data, sizeof(dst->data)) == 0;
+}
+
#else

#define nfs4_close_state(a, b) do { } while (0)
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 9200327..3e65766 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -938,8 +938,8 @@ static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode)
static void nfs_set_open_stateid_locked(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode)
{
if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
- memcpy(state->stateid.data, stateid->data, sizeof(state->stateid.data));
- memcpy(state->open_stateid.data, stateid->data, sizeof(state->open_stateid.data));
+ nfs4_stateid_copy(&state->stateid, stateid);
+ nfs4_stateid_copy(&state->open_stateid, stateid);
switch (fmode) {
case FMODE_READ:
set_bit(NFS_O_RDONLY_STATE, &state->flags);
@@ -967,7 +967,7 @@ static void __update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_s
*/
write_seqlock(&state->seqlock);
if (deleg_stateid != NULL) {
- memcpy(state->stateid.data, deleg_stateid->data, sizeof(state->stateid.data));
+ nfs4_stateid_copy(&state->stateid, deleg_stateid);
set_bit(NFS_DELEGATED_STATE, &state->flags);
}
if (open_stateid != NULL)
@@ -998,7 +998,7 @@ static int update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stat

if (delegation == NULL)
delegation = &deleg_cur->stateid;
- else if (memcmp(deleg_cur->stateid.data, delegation->data, NFS4_STATEID_SIZE) != 0)
+ else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation))
goto no_delegation_unlock;

nfs_mark_delegation_referenced(deleg_cur);
@@ -1059,7 +1059,7 @@ static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata)
break;
}
/* Save the delegation */
- memcpy(stateid.data, delegation->stateid.data, sizeof(stateid.data));
+ nfs4_stateid_copy(&stateid, &delegation->stateid);
rcu_read_unlock();
ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode);
if (ret != 0)
@@ -1222,10 +1222,10 @@ static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *
* Check if we need to update the current stateid.
*/
if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 &&
- memcmp(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)) != 0) {
+ !nfs4_stateid_match(&state->stateid, &state->open_stateid)) {
write_seqlock(&state->seqlock);
if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
- memcpy(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data));
+ nfs4_stateid_copy(&state->stateid, &state->open_stateid);
write_sequnlock(&state->seqlock);
}
return 0;
@@ -1294,8 +1294,7 @@ static int _nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs
if (IS_ERR(opendata))
return PTR_ERR(opendata);
opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR;
- memcpy(opendata->o_arg.u.delegation.data, stateid->data,
- sizeof(opendata->o_arg.u.delegation.data));
+ nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid);
ret = nfs4_open_recover(opendata, state);
nfs4_opendata_put(opendata);
return ret;
@@ -1357,8 +1356,7 @@ static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata)

data->rpc_status = task->tk_status;
if (data->rpc_status == 0) {
- memcpy(data->o_res.stateid.data, data->c_res.stateid.data,
- sizeof(data->o_res.stateid.data));
+ nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid);
nfs_confirm_seqid(&data->owner->so_seqid, 0);
renew_lease(data->o_res.server, data->timestamp);
data->rpc_done = 1;
@@ -1918,7 +1916,7 @@ static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
} else if (state != NULL) {
nfs4_select_rw_stateid(&arg.stateid, state, current->files, current->tgid);
} else
- memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid));
+ nfs4_stateid_copy(&arg.stateid, &zero_stateid);

status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
if (status == 0 && state != NULL)
@@ -3978,7 +3976,7 @@ static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, co
data->args.stateid = &data->stateid;
data->args.bitmask = server->attr_bitmask;
nfs_copy_fh(&data->fh, NFS_FH(inode));
- memcpy(&data->stateid, stateid, sizeof(data->stateid));
+ nfs4_stateid_copy(&data->stateid, stateid);
data->res.fattr = &data->fattr;
data->res.server = server;
nfs_fattr_init(data->res.fattr);
@@ -4161,9 +4159,8 @@ static void nfs4_locku_done(struct rpc_task *task, void *data)
return;
switch (task->tk_status) {
case 0:
- memcpy(calldata->lsp->ls_stateid.data,
- calldata->res.stateid.data,
- sizeof(calldata->lsp->ls_stateid.data));
+ nfs4_stateid_copy(&calldata->lsp->ls_stateid,
+ &calldata->res.stateid);
renew_lease(calldata->server, calldata->timestamp);
break;
case -NFS4ERR_BAD_STATEID:
@@ -4376,8 +4373,7 @@ static void nfs4_lock_done(struct rpc_task *task, void *calldata)
goto out;
}
if (data->rpc_status == 0) {
- memcpy(data->lsp->ls_stateid.data, data->res.stateid.data,
- sizeof(data->lsp->ls_stateid.data));
+ nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid);
data->lsp->ls_flags |= NFS_LOCK_INITIALIZED;
renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp);
}
@@ -6278,7 +6274,7 @@ static bool nfs41_match_stateid(const nfs4_stateid *s1,
static bool nfs4_match_stateid(const nfs4_stateid *s1,
const nfs4_stateid *s2)
{
- return memcmp(s1->data, s2->data, sizeof(s1->data)) == 0;
+ return nfs4_stateid_match(s1, s2);
}


diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
index b59b39e..41e2b44 100644
--- a/fs/nfs/nfs4state.c
+++ b/fs/nfs/nfs4state.c
@@ -895,7 +895,7 @@ void nfs4_select_rw_stateid(nfs4_stateid *dst, struct nfs4_state *state, fl_owne

do {
seq = read_seqbegin(&state->seqlock);
- memcpy(dst, &state->stateid, sizeof(*dst));
+ nfs4_stateid_copy(dst, &state->stateid);
} while (read_seqretry(&state->seqlock, seq));
if (test_bit(LK_STATE_IN_USE, &state->flags) == 0)
return;
@@ -903,7 +903,7 @@ void nfs4_select_rw_stateid(nfs4_stateid *dst, struct nfs4_state *state, fl_owne
spin_lock(&state->state_lock);
lsp = __nfs4_find_lock_state(state, fl_owner, fl_pid, NFS4_ANY_LOCK_TYPE);
if (lsp != NULL && (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0)
- memcpy(dst, &lsp->ls_stateid, sizeof(*dst));
+ nfs4_stateid_copy(dst, &lsp->ls_stateid);
spin_unlock(&state->state_lock);
nfs4_put_lock_state(lsp);
}
diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
index 402efc2..c190e9c 100644
--- a/fs/nfs/pnfs.c
+++ b/fs/nfs/pnfs.c
@@ -499,7 +499,7 @@ pnfs_set_layout_stateid(struct pnfs_layout_hdr *lo, const nfs4_stateid *new,
oldseq = be32_to_cpu(lo->plh_stateid.stateid.seqid);
newseq = be32_to_cpu(new->stateid.seqid);
if ((int)(newseq - oldseq) > 0) {
- memcpy(&lo->plh_stateid, &new->stateid, sizeof(new->stateid));
+ nfs4_stateid_copy(&lo->plh_stateid, new);
if (update_barrier) {
u32 new_barrier = be32_to_cpu(new->stateid.seqid);

@@ -549,11 +549,10 @@ pnfs_choose_layoutget_stateid(nfs4_stateid *dst, struct pnfs_layout_hdr *lo,

do {
seq = read_seqbegin(&open_state->seqlock);
- memcpy(dst->data, open_state->stateid.data,
- sizeof(open_state->stateid.data));
+ nfs4_stateid_copy(dst, &open_state->stateid);
} while (read_seqretry(&open_state->seqlock, seq));
} else
- memcpy(dst->data, lo->plh_stateid.data, sizeof(lo->plh_stateid.data));
+ nfs4_stateid_copy(dst, &lo->plh_stateid);
spin_unlock(&lo->plh_inode->i_lock);
dprintk("<-- %s\n", __func__);
return status;
@@ -1527,8 +1526,7 @@ pnfs_layoutcommit_inode(struct inode *inode, bool sync)
end_pos = nfsi->layout->plh_lwb;
nfsi->layout->plh_lwb = 0;

- memcpy(&data->args.stateid.data, nfsi->layout->plh_stateid.data,
- sizeof(nfsi->layout->plh_stateid.data));
+ nfs4_stateid_copy(&data->args.stateid, &nfsi->layout->plh_stateid);
spin_unlock(&inode->i_lock);

data->args.inode = inode;
--
1.7.7.6


2012-03-04 23:03:13

by Myklebust, Trond

[permalink] [raw]
Subject: [PATCH 08/11] NFSv4: Simplify the struct nfs4_stateid

Signed-off-by: Trond Myklebust <[email protected]>
---
fs/nfs/nfs4_fs.h | 4 ++--
fs/nfs/nfs4proc.c | 8 ++++----
fs/nfs/nfs4state.c | 4 ++--
fs/nfs/nfs4xdr.c | 6 +++---
fs/nfs/pnfs.c | 10 +++++-----
include/linux/nfs4.h | 7 ++-----
6 files changed, 18 insertions(+), 21 deletions(-)

diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h
index f4cafab..4b4e48b 100644
--- a/fs/nfs/nfs4_fs.h
+++ b/fs/nfs/nfs4_fs.h
@@ -349,12 +349,12 @@ extern struct svc_version nfs4_callback_version4;

static inline void nfs4_stateid_copy(nfs4_stateid *dst, const nfs4_stateid *src)
{
- memcpy(dst->data, src->data, sizeof(dst->data));
+ memcpy(dst, src, sizeof(*dst));
}

static inline bool nfs4_stateid_match(const nfs4_stateid *dst, const nfs4_stateid *src)
{
- return memcmp(dst->data, src->data, sizeof(dst->data)) == 0;
+ return memcmp(dst, src, sizeof(*dst)) == 0;
}

#else
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 3e65766..5d90dc8 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -6257,13 +6257,13 @@ static int nfs41_free_stateid(struct nfs_server *server, nfs4_stateid *stateid)
static bool nfs41_match_stateid(const nfs4_stateid *s1,
const nfs4_stateid *s2)
{
- if (memcmp(s1->stateid.other, s2->stateid.other,
- sizeof(s1->stateid.other)) != 0)
+ if (memcmp(s1->other, s2->other,
+ sizeof(s1->other)) != 0)
return false;

- if (s1->stateid.seqid == s2->stateid.seqid)
+ if (s1->seqid == s2->seqid)
return true;
- if (s1->stateid.seqid == 0 || s1->stateid.seqid == 0)
+ if (s1->seqid == 0 || s1->seqid == 0)
return true;

return false;
diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
index 41e2b44..0b17ccc 100644
--- a/fs/nfs/nfs4state.c
+++ b/fs/nfs/nfs4state.c
@@ -1215,8 +1215,8 @@ restart:
* Open state on this file cannot be recovered
* All we can do is revert to using the zero stateid.
*/
- memset(state->stateid.data, 0,
- sizeof(state->stateid.data));
+ memset(&state->stateid, 0,
+ sizeof(state->stateid));
/* Mark the file as being 'closed' */
state->state = 0;
break;
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index 38736dc..76ef986 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -930,7 +930,7 @@ static void encode_nops(struct compound_hdr *hdr)

static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
{
- encode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
+ encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
}

static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
@@ -1548,7 +1548,7 @@ static void encode_open_stateid(struct xdr_stream *xdr, const struct nfs_open_co
if (ctx->state != NULL) {
nfs4_select_rw_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
if (zero_seqid)
- stateid.stateid.seqid = 0;
+ stateid.seqid = 0;
encode_nfs4_stateid(xdr, &stateid);
} else
encode_nfs4_stateid(xdr, &zero_stateid);
@@ -4237,7 +4237,7 @@ static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)

static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
{
- return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
+ return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
}

static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
index c190e9c..6f1c1e3 100644
--- a/fs/nfs/pnfs.c
+++ b/fs/nfs/pnfs.c
@@ -496,12 +496,12 @@ pnfs_set_layout_stateid(struct pnfs_layout_hdr *lo, const nfs4_stateid *new,
{
u32 oldseq, newseq;

- oldseq = be32_to_cpu(lo->plh_stateid.stateid.seqid);
- newseq = be32_to_cpu(new->stateid.seqid);
+ oldseq = be32_to_cpu(lo->plh_stateid.seqid);
+ newseq = be32_to_cpu(new->seqid);
if ((int)(newseq - oldseq) > 0) {
nfs4_stateid_copy(&lo->plh_stateid, new);
if (update_barrier) {
- u32 new_barrier = be32_to_cpu(new->stateid.seqid);
+ u32 new_barrier = be32_to_cpu(new->seqid);

if ((int)(new_barrier - lo->plh_barrier))
lo->plh_barrier = new_barrier;
@@ -525,7 +525,7 @@ pnfs_layoutgets_blocked(struct pnfs_layout_hdr *lo, nfs4_stateid *stateid,
int lget)
{
if ((stateid) &&
- (int)(lo->plh_barrier - be32_to_cpu(stateid->stateid.seqid)) >= 0)
+ (int)(lo->plh_barrier - be32_to_cpu(stateid->seqid)) >= 0)
return true;
return lo->plh_block_lgets ||
test_bit(NFS_LAYOUT_DESTROYED, &lo->plh_flags) ||
@@ -759,7 +759,7 @@ bool pnfs_roc_drain(struct inode *ino, u32 *barrier)
}
if (!found) {
struct pnfs_layout_hdr *lo = nfsi->layout;
- u32 current_seqid = be32_to_cpu(lo->plh_stateid.stateid.seqid);
+ u32 current_seqid = be32_to_cpu(lo->plh_stateid.seqid);

/* Since close does not return a layout stateid for use as
* a barrier, we choose the worst-case barrier.
diff --git a/include/linux/nfs4.h b/include/linux/nfs4.h
index 32345c2..834df8b 100644
--- a/include/linux/nfs4.h
+++ b/include/linux/nfs4.h
@@ -183,15 +183,12 @@ struct nfs4_acl {

typedef struct { char data[NFS4_VERIFIER_SIZE]; } nfs4_verifier;

-struct nfs41_stateid {
+struct nfs_stateid4 {
__be32 seqid;
char other[NFS4_STATEID_OTHER_SIZE];
} __attribute__ ((packed));

-typedef union {
- char data[NFS4_STATEID_SIZE];
- struct nfs41_stateid stateid;
-} nfs4_stateid;
+typedef struct nfs_stateid4 nfs4_stateid;

enum nfs_opnum4 {
OP_ACCESS = 3,
--
1.7.7.6


2012-03-04 23:03:12

by Myklebust, Trond

[permalink] [raw]
Subject: [PATCH 06/11] NFSv4: Rename nfs4_copy_stateid()

It is really a function for selecting the correct stateid to use in a
read or write situation.

Signed-off-by: Trond Myklebust <[email protected]>
---
fs/nfs/nfs4_fs.h | 2 +-
fs/nfs/nfs4proc.c | 2 +-
fs/nfs/nfs4state.c | 2 +-
fs/nfs/nfs4xdr.c | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h
index 9c05799..e76f17c 100644
--- a/fs/nfs/nfs4_fs.h
+++ b/fs/nfs/nfs4_fs.h
@@ -327,7 +327,7 @@ extern void nfs41_handle_server_scope(struct nfs_client *,
struct server_scope **);
extern void nfs4_put_lock_state(struct nfs4_lock_state *lsp);
extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl);
-extern void nfs4_copy_stateid(nfs4_stateid *, struct nfs4_state *, fl_owner_t, pid_t);
+extern void nfs4_select_rw_stateid(nfs4_stateid *, struct nfs4_state *, fl_owner_t, pid_t);

extern struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter, gfp_t gfp_mask);
extern int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task);
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index a79f623..9200327 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -1916,7 +1916,7 @@ static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
if (nfs4_copy_delegation_stateid(&arg.stateid, inode)) {
/* Use that stateid */
} else if (state != NULL) {
- nfs4_copy_stateid(&arg.stateid, state, current->files, current->tgid);
+ nfs4_select_rw_stateid(&arg.stateid, state, current->files, current->tgid);
} else
memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid));

diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
index 2f76060..b59b39e 100644
--- a/fs/nfs/nfs4state.c
+++ b/fs/nfs/nfs4state.c
@@ -888,7 +888,7 @@ int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl)
* Byte-range lock aware utility to initialize the stateid of read/write
* requests.
*/
-void nfs4_copy_stateid(nfs4_stateid *dst, struct nfs4_state *state, fl_owner_t fl_owner, pid_t fl_pid)
+void nfs4_select_rw_stateid(nfs4_stateid *dst, struct nfs4_state *state, fl_owner_t fl_owner, pid_t fl_pid)
{
struct nfs4_lock_state *lsp;
int seq;
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index c03ba77..38736dc 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -1546,7 +1546,7 @@ static void encode_open_stateid(struct xdr_stream *xdr, const struct nfs_open_co
nfs4_stateid stateid;

if (ctx->state != NULL) {
- nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
+ nfs4_select_rw_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
if (zero_seqid)
stateid.stateid.seqid = 0;
encode_nfs4_stateid(xdr, &stateid);
--
1.7.7.6


2012-03-05 17:14:55

by Anna Schumaker

[permalink] [raw]
Subject: Re: [PATCH 08/11] NFSv4: Simplify the struct nfs4_stateid

I just finished bisecting an oops to this patch, does v2 fix the problem? I hit it while running the special tests over v4. I was able to compile after these patches, so that's a step forward!

- Bryan

The oops:

[ 18.396379] general protection fault: 0000 [#1] PREEMPT SMP
[ 18.396996] CPU 0
[ 18.397116] Modules linked in: nfs nfs_acl auth_rpcgss fscache lockd sunrpc ext4 crc16 jbd2 mbcache virtio_balloon snd_hda_intel snd_hda_codec psmouse pcspkr serio_raw evdev snd_hwdep snd_pcm snd_page_alloc snd_timer snd soundcore i2c_piix4 i2c_core floppy button processor btrfs crc32c libcrc32c zlib_deflate sr_mod cdrom pata_acpi ata_piix uhci_hcd libata usbcore usb_common scsi_mod virtio_net virtio_pci virtio_blk virtio_ring virtio
[ 18.399678]
[ 18.399678] Pid: 650, comm: nfsv4.0-svc Not tainted 3.3.0-rc2-MODULES+ #14 Bochs Bochs
[ 18.399678] RIP: 0010:[<ffffffffa041cedd>] [<ffffffffa041cedd>] nfs4_callback_compound+0x37d/0x550 [nfs]
[ 18.399678] RSP: 0018:ffff88003cb33d50 EFLAGS: 00010246
[ 18.399678] RAX: 0000000000000000 RBX: 0000bd9c00000067 RCX: 0000000000000000
[ 18.399678] RDX: ffff88003cb33e00 RSI: ffff88003ba84000 RDI: ffff88003ba86000
[ 18.399678] RBP: ffff88003cb33e50 R08: 0000000000000000 R09: ffff88003ba8601a
[ 18.399678] R10: ffff88003cb33fd8 R11: 0000000000000000 R12: 0000000000000004
[ 18.399678] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
[ 18.399678] FS: 0000000000000000(0000) GS:ffff88003fc00000(0000) knlGS:0000000000000000
[ 18.399678] CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b
[ 18.399678] CR2: 00007f35163bdf40 CR3: 000000003cbc2000 CR4: 00000000000006f0
[ 18.399678] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[ 18.399678] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
[ 18.399678] Process nfsv4.0-svc (pid: 650, threadinfo ffff88003cb32000, task ffff88003c81aac0)
[ 18.399678] Stack:
[ 18.399678] ffff88003cb33d60 ffff88003b8a6000 ffff88003c934024 ffff88003c93401c
[ 18.399678] ffff88003ba86000 ffff88003ba84000 0000000100000000 ffffffffa042c300
[ 18.399678] ffff88003bb4d080 ffff88003b8a6190 ffff88003bb4d080 ffff88003b8a6190
[ 18.399678] Call Trace:
[ 18.399678] [<ffffffffa0368f83>] svc_process+0x763/0x850 [sunrpc]
[ 18.399678] [<ffffffffa041c3f6>] nfs4_callback_svc+0x56/0xb0 [nfs]
[ 18.399678] [<ffffffffa041c3a0>] ? param_set_portnr+0x60/0x60 [nfs]
[ 18.399678] [<ffffffff810732e3>] kthread+0x93/0xa0
[ 18.399678] [<ffffffff8144ec24>] kernel_thread_helper+0x4/0x10
[ 18.399678] [<ffffffff81073250>] ? kthread_freezable_should_stop+0x70/0x70
[ 18.399678] [<ffffffff8144ec20>] ? gs_change+0x13/0x13
[ 18.399678] Code: ff 48 8b bd 08 ff ff ff ff 93 88 c2 42 a0 85 c0 41 89 c6 0f 85 1d ff ff ff 48 8d 55 b0 48 8b b5 28 ff ff ff 48 8b bd 20 ff ff ff <ff> 93 80 c2 42 a0 41 89 c6 e9 fd fe ff ff 0f 1f 44 00 00 48 85
[ 18.399678] RIP [<ffffffffa041cedd>] nfs4_callback_compound+0x37d/0x550 [nfs]
[ 18.399678] RSP <ffff88003cb33d50>
[ 18.425320] ---[ end trace 1f4aaa30a0f6d27f ]---


On 03/04/2012 06:03 PM, Trond Myklebust wrote:

> Signed-off-by: Trond Myklebust <[email protected]>
> ---
> fs/nfs/nfs4_fs.h | 4 ++--
> fs/nfs/nfs4proc.c | 8 ++++----
> fs/nfs/nfs4state.c | 4 ++--
> fs/nfs/nfs4xdr.c | 6 +++---
> fs/nfs/pnfs.c | 10 +++++-----
> include/linux/nfs4.h | 7 ++-----
> 6 files changed, 18 insertions(+), 21 deletions(-)
>
> diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h
> index f4cafab..4b4e48b 100644
> --- a/fs/nfs/nfs4_fs.h
> +++ b/fs/nfs/nfs4_fs.h
> @@ -349,12 +349,12 @@ extern struct svc_version nfs4_callback_version4;
>
> static inline void nfs4_stateid_copy(nfs4_stateid *dst, const nfs4_stateid *src)
> {
> - memcpy(dst->data, src->data, sizeof(dst->data));
> + memcpy(dst, src, sizeof(*dst));
> }
>
> static inline bool nfs4_stateid_match(const nfs4_stateid *dst, const nfs4_stateid *src)
> {
> - return memcmp(dst->data, src->data, sizeof(dst->data)) == 0;
> + return memcmp(dst, src, sizeof(*dst)) == 0;
> }
>
> #else
> diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
> index 3e65766..5d90dc8 100644
> --- a/fs/nfs/nfs4proc.c
> +++ b/fs/nfs/nfs4proc.c
> @@ -6257,13 +6257,13 @@ static int nfs41_free_stateid(struct nfs_server *server, nfs4_stateid *stateid)
> static bool nfs41_match_stateid(const nfs4_stateid *s1,
> const nfs4_stateid *s2)
> {
> - if (memcmp(s1->stateid.other, s2->stateid.other,
> - sizeof(s1->stateid.other)) != 0)
> + if (memcmp(s1->other, s2->other,
> + sizeof(s1->other)) != 0)
> return false;
>
> - if (s1->stateid.seqid == s2->stateid.seqid)
> + if (s1->seqid == s2->seqid)
> return true;
> - if (s1->stateid.seqid == 0 || s1->stateid.seqid == 0)
> + if (s1->seqid == 0 || s1->seqid == 0)
> return true;
>
> return false;
> diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
> index 41e2b44..0b17ccc 100644
> --- a/fs/nfs/nfs4state.c
> +++ b/fs/nfs/nfs4state.c
> @@ -1215,8 +1215,8 @@ restart:
> * Open state on this file cannot be recovered
> * All we can do is revert to using the zero stateid.
> */
> - memset(state->stateid.data, 0,
> - sizeof(state->stateid.data));
> + memset(&state->stateid, 0,
> + sizeof(state->stateid));
> /* Mark the file as being 'closed' */
> state->state = 0;
> break;
> diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
> index 38736dc..76ef986 100644
> --- a/fs/nfs/nfs4xdr.c
> +++ b/fs/nfs/nfs4xdr.c
> @@ -930,7 +930,7 @@ static void encode_nops(struct compound_hdr *hdr)
>
> static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
> {
> - encode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
> + encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
> }
>
> static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
> @@ -1548,7 +1548,7 @@ static void encode_open_stateid(struct xdr_stream *xdr, const struct nfs_open_co
> if (ctx->state != NULL) {
> nfs4_select_rw_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
> if (zero_seqid)
> - stateid.stateid.seqid = 0;
> + stateid.seqid = 0;
> encode_nfs4_stateid(xdr, &stateid);
> } else
> encode_nfs4_stateid(xdr, &zero_stateid);
> @@ -4237,7 +4237,7 @@ static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
>
> static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
> {
> - return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
> + return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
> }
>
> static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
> diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
> index c190e9c..6f1c1e3 100644
> --- a/fs/nfs/pnfs.c
> +++ b/fs/nfs/pnfs.c
> @@ -496,12 +496,12 @@ pnfs_set_layout_stateid(struct pnfs_layout_hdr *lo, const nfs4_stateid *new,
> {
> u32 oldseq, newseq;
>
> - oldseq = be32_to_cpu(lo->plh_stateid.stateid.seqid);
> - newseq = be32_to_cpu(new->stateid.seqid);
> + oldseq = be32_to_cpu(lo->plh_stateid.seqid);
> + newseq = be32_to_cpu(new->seqid);
> if ((int)(newseq - oldseq) > 0) {
> nfs4_stateid_copy(&lo->plh_stateid, new);
> if (update_barrier) {
> - u32 new_barrier = be32_to_cpu(new->stateid.seqid);
> + u32 new_barrier = be32_to_cpu(new->seqid);
>
> if ((int)(new_barrier - lo->plh_barrier))
> lo->plh_barrier = new_barrier;
> @@ -525,7 +525,7 @@ pnfs_layoutgets_blocked(struct pnfs_layout_hdr *lo, nfs4_stateid *stateid,
> int lget)
> {
> if ((stateid) &&
> - (int)(lo->plh_barrier - be32_to_cpu(stateid->stateid.seqid)) >= 0)
> + (int)(lo->plh_barrier - be32_to_cpu(stateid->seqid)) >= 0)
> return true;
> return lo->plh_block_lgets ||
> test_bit(NFS_LAYOUT_DESTROYED, &lo->plh_flags) ||
> @@ -759,7 +759,7 @@ bool pnfs_roc_drain(struct inode *ino, u32 *barrier)
> }
> if (!found) {
> struct pnfs_layout_hdr *lo = nfsi->layout;
> - u32 current_seqid = be32_to_cpu(lo->plh_stateid.stateid.seqid);
> + u32 current_seqid = be32_to_cpu(lo->plh_stateid.seqid);
>
> /* Since close does not return a layout stateid for use as
> * a barrier, we choose the worst-case barrier.
> diff --git a/include/linux/nfs4.h b/include/linux/nfs4.h
> index 32345c2..834df8b 100644
> --- a/include/linux/nfs4.h
> +++ b/include/linux/nfs4.h
> @@ -183,15 +183,12 @@ struct nfs4_acl {
>
> typedef struct { char data[NFS4_VERIFIER_SIZE]; } nfs4_verifier;
>
> -struct nfs41_stateid {
> +struct nfs_stateid4 {
> __be32 seqid;
> char other[NFS4_STATEID_OTHER_SIZE];
> } __attribute__ ((packed));
>
> -typedef union {
> - char data[NFS4_STATEID_SIZE];
> - struct nfs41_stateid stateid;
> -} nfs4_stateid;
> +typedef struct nfs_stateid4 nfs4_stateid;
>
> enum nfs_opnum4 {
> OP_ACCESS = 3,



2012-03-05 16:52:32

by Myklebust, Trond

[permalink] [raw]
Subject: RE: [PATCH 08/11] NFSv4: Simplify the struct nfs4_stateid

T24gTW9uLCAyMDEyLTAzLTA1IGF0IDExOjMxIC0wNTAwLCBQZXRlciBTdGF1YmFjaCB3cm90ZToN
Cj4gQ29tbWVudCBpbnRlcm1peGVkIGJlbG93Li4uDQo+IA0KPiAgDQo+IA0KPiAgDQo+IA0KPiAt
LS0tLU9yaWdpbmFsIE1lc3NhZ2UtLS0tLQ0KPiBGcm9tOiBsaW51eC1uZnMtb3duZXJAdmdlci5r
ZXJuZWwub3JnDQo+IFttYWlsdG86bGludXgtbmZzLW93bmVyQHZnZXIua2VybmVsLm9yZ10gT24g
QmVoYWxmIE9mIFRyb25kIE15a2xlYnVzdA0KPiBTZW50OiBTdW5kYXksIE1hcmNoIDA0LCAyMDEy
IDY6MDMgUE0NCj4gVG86IGxpbnV4LW5mc0B2Z2VyLmtlcm5lbC5vcmcNCj4gU3ViamVjdDogW1BB
VENIIDA4LzExXSBORlN2NDogU2ltcGxpZnkgdGhlIHN0cnVjdCBuZnM0X3N0YXRlaWQNCj4gDQo+
ICANCj4gDQo+IFNpZ25lZC1vZmYtYnk6IFRyb25kIE15a2xlYnVzdCA8VHJvbmQuTXlrbGVidXN0
QG5ldGFwcC5jb20+DQo+IA0KPiAtLS0NCj4gDQo+IGZzL25mcy9uZnM0X2ZzLmggICAgIHwgICAg
NCArKy0tDQo+IA0KPiBmcy9uZnMvbmZzNHByb2MuYyAgICB8ICAgIDggKysrKy0tLS0NCj4gDQo+
IGZzL25mcy9uZnM0c3RhdGUuYyAgIHwgICAgNCArKy0tDQo+IA0KPiBmcy9uZnMvbmZzNHhkci5j
ICAgICB8ICAgIDYgKysrLS0tDQo+IA0KPiBmcy9uZnMvcG5mcy5jICAgICAgICB8ICAgMTAgKysr
KystLS0tLQ0KPiANCj4gaW5jbHVkZS9saW51eC9uZnM0LmggfCAgICA3ICsrLS0tLS0NCj4gDQo+
IDYgZmlsZXMgY2hhbmdlZCwgMTggaW5zZXJ0aW9ucygrKSwgMjEgZGVsZXRpb25zKC0pDQo+IA0K
PiAgDQo+IA0KPiBkaWZmIC0tZ2l0IGEvZnMvbmZzL25mczRfZnMuaCBiL2ZzL25mcy9uZnM0X2Zz
LmggaW5kZXgNCj4gZjRjYWZhYi4uNGI0ZTQ4YiAxMDA2NDQNCj4gDQo+IC0tLSBhL2ZzL25mcy9u
ZnM0X2ZzLmgNCj4gDQo+ICsrKyBiL2ZzL25mcy9uZnM0X2ZzLmgNCj4gDQo+IEBAIC0zNDksMTIg
KzM0OSwxMiBAQCBleHRlcm4gc3RydWN0IHN2Y192ZXJzaW9uDQo+IG5mczRfY2FsbGJhY2tfdmVy
c2lvbjQ7DQo+IA0KPiAgc3RhdGljIGlubGluZSB2b2lkIG5mczRfc3RhdGVpZF9jb3B5KG5mczRf
c3RhdGVpZCAqZHN0LCBjb25zdA0KPiBuZnM0X3N0YXRlaWQgKnNyYykgIHsNCj4gDQo+IC0gICAg
ICAgICAgICAgIG1lbWNweShkc3QtPmRhdGEsIHNyYy0+ZGF0YSwgc2l6ZW9mKGRzdC0+ZGF0YSkp
Ow0KPiANCj4gKyAgICAgICAgICAgICBtZW1jcHkoZHN0LCBzcmMsIHNpemVvZigqZHN0KSk7DQo+
IA0KPiB9DQo+IA0KPiAgc3RhdGljIGlubGluZSBib29sIG5mczRfc3RhdGVpZF9tYXRjaChjb25z
dCBuZnM0X3N0YXRlaWQgKmRzdCwgY29uc3QNCj4gbmZzNF9zdGF0ZWlkICpzcmMpICB7DQo+IA0K
PiAtICAgICAgICAgICAgICByZXR1cm4gbWVtY21wKGRzdC0+ZGF0YSwgc3JjLT5kYXRhLCBzaXpl
b2YoZHN0LT5kYXRhKSkNCj4gPT0gMDsNCj4gDQo+ICsgICAgICAgICAgICAgcmV0dXJuIG1lbWNt
cChkc3QsIHNyYywgc2l6ZW9mKCpkc3QpKSA9PSAwOw0KPiANCj4gfQ0KPiANCj4gICNlbHNlDQo+
IA0KPiBkaWZmIC0tZ2l0IGEvZnMvbmZzL25mczRwcm9jLmMgYi9mcy9uZnMvbmZzNHByb2MuYyBp
bmRleA0KPiAzZTY1NzY2Li41ZDkwZGM4IDEwMDY0NA0KPiANCj4gLS0tIGEvZnMvbmZzL25mczRw
cm9jLmMNCj4gDQo+ICsrKyBiL2ZzL25mcy9uZnM0cHJvYy5jDQo+IA0KPiBAQCAtNjI1NywxMyAr
NjI1NywxMyBAQCBzdGF0aWMgaW50IG5mczQxX2ZyZWVfc3RhdGVpZChzdHJ1Y3QNCj4gbmZzX3Nl
cnZlciAqc2VydmVyLCBuZnM0X3N0YXRlaWQgKnN0YXRlaWQpICBzdGF0aWMgYm9vbA0KPiBuZnM0
MV9tYXRjaF9zdGF0ZWlkKGNvbnN0IG5mczRfc3RhdGVpZCAqczEsDQo+IA0KPiAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgY29uc3QgbmZzNF9zdGF0ZWlkICpzMikNCj4gDQo+IHsNCj4g
DQo+IC0gICAgICAgICAgICAgIGlmIChtZW1jbXAoczEtPnN0YXRlaWQub3RoZXIsIHMyLT5zdGF0
ZWlkLm90aGVyLA0KPiANCj4gLSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNpemVv
ZihzMS0+c3RhdGVpZC5vdGhlcikpICE9IDApDQo+IA0KPiArICAgICAgICAgICAgIGlmIChtZW1j
bXAoczEtPm90aGVyLCBzMi0+b3RoZXIsDQo+IA0KPiArICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICBzaXplb2YoczEtPm90aGVyKSkgIT0gMCkNCj4gDQo+ICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICByZXR1cm4gZmFsc2U7DQo+IA0KPiAtICAgICAgICAgICAgICBpZiAoczEt
PnN0YXRlaWQuc2VxaWQgPT0gczItPnN0YXRlaWQuc2VxaWQpDQo+IA0KPiArICAgICAgICAgICAg
IGlmIChzMS0+c2VxaWQgPT0gczItPnNlcWlkKQ0KPiANCj4gICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgIHJldHVybiB0cnVlOw0KPiANCj4gLSAgICAgICAgICAgICAgaWYgKHMxLT5zdGF0
ZWlkLnNlcWlkID09IDAgfHwgczEtPnN0YXRlaWQuc2VxaWQgPT0gMCkNCj4gDQo+ICsgICAgICAg
ICAgICAgaWYgKHMxLT5zZXFpZCA9PSAwIHx8IHMxLT5zZXFpZCA9PSAwKQ0KPiANCj4gPiANCj4g
DQo+ID4gSXMgdGhpcyB0ZXN0IGNvcnJlY3Q/ICBPciBzaG91bGQgdGhlIHNlY29uZCBzMSBiZSBz
Mj8NCg0KT29wcy4uLiBUaGFua3MgZm9yIHNwb3R0aW5nIHRoYXQhIEknbGwgZml4IGl0IHVwIGlu
IHYzLi4uDQoNCi0tIA0KVHJvbmQgTXlrbGVidXN0DQpMaW51eCBORlMgY2xpZW50IG1haW50YWlu
ZXINCg0KTmV0QXBwDQpUcm9uZC5NeWtsZWJ1c3RAbmV0YXBwLmNvbQ0Kd3d3Lm5ldGFwcC5jb20N
Cg0K

2012-03-04 23:03:14

by Myklebust, Trond

[permalink] [raw]
Subject: [PATCH 09/11] NFSv4: Minor clean ups for encode_string()

Signed-off-by: Trond Myklebust <[email protected]>
---
fs/nfs/nfs4xdr.c | 40 ++++++++++++++++++----------------------
1 files changed, 18 insertions(+), 22 deletions(-)

diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index 76ef986..d6e8306 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -897,8 +897,7 @@ static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *
{
__be32 *p;

- p = xdr_reserve_space(xdr, 4 + len);
- BUG_ON(p == NULL);
+ p = reserve_space(xdr, 4 + len);
xdr_encode_opaque(p, str, len);
}

@@ -915,8 +914,8 @@ static void encode_compound_hdr(struct xdr_stream *xdr,
hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;

BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
- p = reserve_space(xdr, 4 + hdr->taglen + 8);
- p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
+ encode_string(xdr, hdr->taglen, hdr->tag);
+ p = reserve_space(xdr, 8);
*p++ = cpu_to_be32(hdr->minorversion);
hdr->nops_p = p;
*p = cpu_to_be32(hdr->nops);
@@ -1216,9 +1215,9 @@ static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct
{
__be32 *p;

- p = reserve_space(xdr, 8 + name->len);
- *p++ = cpu_to_be32(OP_LINK);
- xdr_encode_opaque(p, name->name, name->len);
+ p = reserve_space(xdr, 4);
+ *p = cpu_to_be32(OP_LINK);
+ encode_string(xdr, name->len, name->name);
hdr->nops++;
hdr->replen += decode_link_maxsz;
}
@@ -1324,12 +1323,11 @@ static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lo

static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
{
- int len = name->len;
__be32 *p;

- p = reserve_space(xdr, 8 + len);
- *p++ = cpu_to_be32(OP_LOOKUP);
- xdr_encode_opaque(p, name->name, len);
+ p = reserve_space(xdr, 4);
+ *p = cpu_to_be32(OP_LOOKUP);
+ encode_string(xdr, name->len, name->name);
hdr->nops++;
hdr->replen += decode_lookup_maxsz;
}
@@ -1521,12 +1519,11 @@ static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_close
static void
encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
{
- int len = fh->size;
__be32 *p;

- p = reserve_space(xdr, 8 + len);
- *p++ = cpu_to_be32(OP_PUTFH);
- xdr_encode_opaque(p, fh->data, len);
+ p = reserve_space(xdr, 4);
+ *p = cpu_to_be32(OP_PUTFH);
+ encode_string(xdr, fh->size, fh->data);
hdr->nops++;
hdr->replen += decode_putfh_maxsz;
}
@@ -1628,9 +1625,9 @@ static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struc
{
__be32 *p;

- p = reserve_space(xdr, 8 + name->len);
- *p++ = cpu_to_be32(OP_REMOVE);
- xdr_encode_opaque(p, name->name, name->len);
+ p = reserve_space(xdr, 4);
+ *p = cpu_to_be32(OP_REMOVE);
+ encode_string(xdr, name->len, name->name);
hdr->nops++;
hdr->replen += decode_remove_maxsz;
}
@@ -1776,12 +1773,11 @@ static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *state

static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
{
- int len = name->len;
__be32 *p;

- p = reserve_space(xdr, 8 + len);
- *p++ = cpu_to_be32(OP_SECINFO);
- xdr_encode_opaque(p, name->name, len);
+ p = reserve_space(xdr, 4);
+ *p = cpu_to_be32(OP_SECINFO);
+ encode_string(xdr, name->len, name->name);
hdr->nops++;
hdr->replen += decode_secinfo_maxsz;
}
--
1.7.7.6


2012-03-05 02:01:32

by Myklebust, Trond

[permalink] [raw]
Subject: Re: [PATCH 04/11] NFSv4: Add a helper for encoding opaque data

T24gU3VuLCAyMDEyLTAzLTA0IGF0IDIwOjA4IC0wNTAwLCBDaHVjayBMZXZlciB3cm90ZToNCj4g
RXIuICBUaGlzIGNvbGxpZGVzIHdpdGggYSBwYXRjaCBJIHNlbnQgZWFybGllciB0aGlzIHdlZWsu
DQo+IA0KPiBTZW50IGZyb20gbXkgaVBhZA0KDQpQbGVhc2UgY2hlY2sgY29tbWl0IDU2ZmVhZjQ4
NjdkY2JiYTM1NDcwNTA4ZTI1YTZiZWNmZmI4YWVlOTYgKE5GUzogRml4DQpuZnM0X3ZlcmlmaWVy
IG1lbW9yeSBhbGlnbm1lbnQpLg0KDQpDaGVlcnMNCiAgVHJvbmQNCi0tIA0KVHJvbmQgTXlrbGVi
dXN0DQpMaW51eCBORlMgY2xpZW50IG1haW50YWluZXINCg0KTmV0QXBwDQpUcm9uZC5NeWtsZWJ1
c3RAbmV0YXBwLmNvbQ0Kd3d3Lm5ldGFwcC5jb20NCg0K

2012-03-04 23:03:10

by Myklebust, Trond

[permalink] [raw]
Subject: [PATCH 03/11] NFSv4: Rename encode_stateid() to encode_open_stateid()

The current version of encode_stateid really only applies to open stateids.
You can't use it for locks, delegations or layouts.

Signed-off-by: Trond Myklebust <[email protected]>
---
fs/nfs/nfs4xdr.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index bca8c77..af11e8b 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -1528,7 +1528,7 @@ static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
hdr->replen += decode_putrootfh_maxsz;
}

-static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx, const struct nfs_lock_context *l_ctx, int zero_seqid)
+static void encode_open_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx, const struct nfs_lock_context *l_ctx, int zero_seqid)
{
nfs4_stateid stateid;
__be32 *p;
@@ -1550,7 +1550,7 @@ static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args,
p = reserve_space(xdr, 4);
*p = cpu_to_be32(OP_READ);

- encode_stateid(xdr, args->context, args->lock_context,
+ encode_open_stateid(xdr, args->context, args->lock_context,
hdr->minorversion);

p = reserve_space(xdr, 12);
@@ -1739,7 +1739,7 @@ static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *arg
p = reserve_space(xdr, 4);
*p = cpu_to_be32(OP_WRITE);

- encode_stateid(xdr, args->context, args->lock_context,
+ encode_open_stateid(xdr, args->context, args->lock_context,
hdr->minorversion);

p = reserve_space(xdr, 16);
--
1.7.7.6


2012-03-04 23:03:14

by Myklebust, Trond

[permalink] [raw]
Subject: [PATCH 10/11] NFSv4: Add a helper for encoding NFSv4 sequence ids

Signed-off-by: Trond Myklebust <[email protected]>
---
fs/nfs/nfs4xdr.c | 47 ++++++++++++++++++++++++++++-------------------
1 files changed, 28 insertions(+), 19 deletions(-)

diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index d6e8306..604da06 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -901,6 +901,20 @@ static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *
xdr_encode_opaque(p, str, len);
}

+static void encode_word(struct xdr_stream *xdr, u32 n)
+{
+ __be32 *p;
+
+ p = reserve_space(xdr, 4);
+ *p = cpu_to_be32(n);
+}
+
+static void encode_nfs4_seqid(struct xdr_stream *xdr,
+ const struct nfs_seqid *seqid)
+{
+ encode_word(xdr, seqid->sequence->counter);
+}
+
static void encode_compound_hdr(struct xdr_stream *xdr,
struct rpc_rqst *req,
struct compound_hdr *hdr)
@@ -1074,9 +1088,9 @@ static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg
{
__be32 *p;

- p = reserve_space(xdr, 8);
- *p++ = cpu_to_be32(OP_CLOSE);
- *p = cpu_to_be32(arg->seqid->sequence->counter);
+ p = reserve_space(xdr, 4);
+ *p = cpu_to_be32(OP_CLOSE);
+ encode_nfs4_seqid(xdr, arg->seqid);
encode_nfs4_stateid(xdr, arg->stateid);
hdr->nops++;
hdr->replen += decode_close_maxsz;
@@ -1264,17 +1278,14 @@ static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args
p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
*p = cpu_to_be32(args->new_lock_owner);
if (args->new_lock_owner){
- p = reserve_space(xdr, 4);
- *p = cpu_to_be32(args->open_seqid->sequence->counter);
+ encode_nfs4_seqid(xdr, args->open_seqid);
encode_nfs4_stateid(xdr, args->open_stateid);
- p = reserve_space(xdr, 4);
- *p = cpu_to_be32(args->lock_seqid->sequence->counter);
+ encode_nfs4_seqid(xdr, args->lock_seqid);
encode_lockowner(xdr, &args->lock_owner);
}
else {
encode_nfs4_stateid(xdr, args->lock_stateid);
- p = reserve_space(xdr, 4);
- *p = cpu_to_be32(args->lock_seqid->sequence->counter);
+ encode_nfs4_seqid(xdr, args->lock_seqid);
}
hdr->nops++;
hdr->replen += decode_lock_maxsz;
@@ -1298,10 +1309,10 @@ static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *ar
{
__be32 *p;

- p = reserve_space(xdr, 12);
+ p = reserve_space(xdr, 8);
*p++ = cpu_to_be32(OP_LOCKU);
- *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
- *p = cpu_to_be32(args->seqid->sequence->counter);
+ *p = cpu_to_be32(nfs4_lock_type(args->fl, 0));
+ encode_nfs4_seqid(xdr, args->seqid);
encode_nfs4_stateid(xdr, args->stateid);
p = reserve_space(xdr, 16);
p = xdr_encode_hyper(p, args->fl->fl_start);
@@ -1360,9 +1371,9 @@ static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_opena
* opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
* owner 4 = 32
*/
- p = reserve_space(xdr, 8);
- *p++ = cpu_to_be32(OP_OPEN);
- *p = cpu_to_be32(arg->seqid->sequence->counter);
+ p = reserve_space(xdr, 4);
+ *p = cpu_to_be32(OP_OPEN);
+ encode_nfs4_seqid(xdr, arg->seqid);
encode_share_access(xdr, arg->fmode);
p = reserve_space(xdr, 32);
p = xdr_encode_hyper(p, arg->clientid);
@@ -1496,8 +1507,7 @@ static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_co
p = reserve_space(xdr, 4);
*p = cpu_to_be32(OP_OPEN_CONFIRM);
encode_nfs4_stateid(xdr, arg->stateid);
- p = reserve_space(xdr, 4);
- *p = cpu_to_be32(arg->seqid->sequence->counter);
+ encode_nfs4_seqid(xdr, arg->seqid);
hdr->nops++;
hdr->replen += decode_open_confirm_maxsz;
}
@@ -1509,8 +1519,7 @@ static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_close
p = reserve_space(xdr, 4);
*p = cpu_to_be32(OP_OPEN_DOWNGRADE);
encode_nfs4_stateid(xdr, arg->stateid);
- p = reserve_space(xdr, 4);
- *p = cpu_to_be32(arg->seqid->sequence->counter);
+ encode_nfs4_seqid(xdr, arg->seqid);
encode_share_access(xdr, arg->fmode);
hdr->nops++;
hdr->replen += decode_open_downgrade_maxsz;
--
1.7.7.6


2012-03-05 02:04:58

by Myklebust, Trond

[permalink] [raw]
Subject: Re: [PATCH 04/11] NFSv4: Add a helper for encoding opaque data

T24gU3VuLCAyMDEyLTAzLTA0IGF0IDIwOjA4IC0wNTAwLCBDaHVjayBMZXZlciB3cm90ZToNCg0K
PiBTZW50IGZyb20gbXkgaVBhZA0KDQpJcyB0aGF0IHJ1bm5pbmcgTGludXg/DQoNCi0tIA0KVHJv
bmQgTXlrbGVidXN0DQpMaW51eCBORlMgY2xpZW50IG1haW50YWluZXINCg0KTmV0QXBwDQpUcm9u
ZC5NeWtsZWJ1c3RAbmV0YXBwLmNvbQ0Kd3d3Lm5ldGFwcC5jb20NCg0K

2012-03-04 23:03:11

by Myklebust, Trond

[permalink] [raw]
Subject: [PATCH 05/11] NFSv4: Add a helper for encoding stateids

Signed-off-by: Trond Myklebust <[email protected]>
---
fs/nfs/nfs4xdr.c | 113 +++++++++++++++++++++++++++++------------------------
1 files changed, 62 insertions(+), 51 deletions(-)

diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index de4cb5c..c03ba77 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -928,6 +928,11 @@ static void encode_nops(struct compound_hdr *hdr)
*hdr->nops_p = htonl(hdr->nops);
}

+static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
+{
+ encode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE);
+}
+
static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
{
encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
@@ -1070,10 +1075,10 @@ static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg
{
__be32 *p;

- p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
+ p = reserve_space(xdr, 8);
*p++ = cpu_to_be32(OP_CLOSE);
- *p++ = cpu_to_be32(arg->seqid->sequence->counter);
- xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
+ *p = cpu_to_be32(arg->seqid->sequence->counter);
+ encode_nfs4_stateid(xdr, arg->stateid);
hdr->nops++;
hdr->replen += decode_close_maxsz;
}
@@ -1260,15 +1265,16 @@ static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args
p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
*p = cpu_to_be32(args->new_lock_owner);
if (args->new_lock_owner){
- p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
- *p++ = cpu_to_be32(args->open_seqid->sequence->counter);
- p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
- *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
+ p = reserve_space(xdr, 4);
+ *p = cpu_to_be32(args->open_seqid->sequence->counter);
+ encode_nfs4_stateid(xdr, args->open_stateid);
+ p = reserve_space(xdr, 4);
+ *p = cpu_to_be32(args->lock_seqid->sequence->counter);
encode_lockowner(xdr, &args->lock_owner);
}
else {
- p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
- p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
+ encode_nfs4_stateid(xdr, args->lock_stateid);
+ p = reserve_space(xdr, 4);
*p = cpu_to_be32(args->lock_seqid->sequence->counter);
}
hdr->nops++;
@@ -1293,11 +1299,12 @@ static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *ar
{
__be32 *p;

- p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
+ p = reserve_space(xdr, 12);
*p++ = cpu_to_be32(OP_LOCKU);
*p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
- *p++ = cpu_to_be32(args->seqid->sequence->counter);
- p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
+ *p = cpu_to_be32(args->seqid->sequence->counter);
+ encode_nfs4_stateid(xdr, args->stateid);
+ p = reserve_space(xdr, 16);
p = xdr_encode_hyper(p, args->fl->fl_start);
xdr_encode_hyper(p, nfs4_lock_length(args->fl));
hdr->nops++;
@@ -1457,9 +1464,9 @@ static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struc
{
__be32 *p;

- p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
- *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
- xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
+ p = reserve_space(xdr, 4);
+ *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
+ encode_nfs4_stateid(xdr, stateid);
encode_string(xdr, name->len, name->name);
}

@@ -1488,9 +1495,10 @@ static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_co
{
__be32 *p;

- p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
- *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
- p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
+ p = reserve_space(xdr, 4);
+ *p = cpu_to_be32(OP_OPEN_CONFIRM);
+ encode_nfs4_stateid(xdr, arg->stateid);
+ p = reserve_space(xdr, 4);
*p = cpu_to_be32(arg->seqid->sequence->counter);
hdr->nops++;
hdr->replen += decode_open_confirm_maxsz;
@@ -1500,9 +1508,10 @@ static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_close
{
__be32 *p;

- p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
- *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
- p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
+ p = reserve_space(xdr, 4);
+ *p = cpu_to_be32(OP_OPEN_DOWNGRADE);
+ encode_nfs4_stateid(xdr, arg->stateid);
+ p = reserve_space(xdr, 4);
*p = cpu_to_be32(arg->seqid->sequence->counter);
encode_share_access(xdr, arg->fmode);
hdr->nops++;
@@ -1535,16 +1544,14 @@ static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
static void encode_open_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx, const struct nfs_lock_context *l_ctx, int zero_seqid)
{
nfs4_stateid stateid;
- __be32 *p;

- p = reserve_space(xdr, NFS4_STATEID_SIZE);
if (ctx->state != NULL) {
nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid);
if (zero_seqid)
stateid.stateid.seqid = 0;
- xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
+ encode_nfs4_stateid(xdr, &stateid);
} else
- xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
+ encode_nfs4_stateid(xdr, &zero_stateid);
}

static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
@@ -1668,9 +1675,9 @@ encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compoun
{
__be32 *p;

- p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
- *p++ = cpu_to_be32(OP_SETATTR);
- xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
+ p = reserve_space(xdr, 4);
+ *p = cpu_to_be32(OP_SETATTR);
+ encode_nfs4_stateid(xdr, &zero_stateid);
p = reserve_space(xdr, 2*4);
*p++ = cpu_to_be32(1);
*p = cpu_to_be32(FATTR4_WORD0_ACL);
@@ -1697,9 +1704,9 @@ static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs
{
__be32 *p;

- p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
- *p++ = cpu_to_be32(OP_SETATTR);
- xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
+ p = reserve_space(xdr, 4);
+ *p = cpu_to_be32(OP_SETATTR);
+ encode_nfs4_stateid(xdr, &arg->stateid);
hdr->nops++;
hdr->replen += decode_setattr_maxsz;
encode_attrs(xdr, arg->iap, server);
@@ -1760,10 +1767,9 @@ static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *state
{
__be32 *p;

- p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
-
- *p++ = cpu_to_be32(OP_DELEGRETURN);
- xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
+ p = reserve_space(xdr, 4);
+ *p = cpu_to_be32(OP_DELEGRETURN);
+ encode_nfs4_stateid(xdr, stateid);
hdr->nops++;
hdr->replen += decode_delegreturn_maxsz;
}
@@ -1999,7 +2005,7 @@ encode_layoutget(struct xdr_stream *xdr,
{
__be32 *p;

- p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
+ p = reserve_space(xdr, 40);
*p++ = cpu_to_be32(OP_LAYOUTGET);
*p++ = cpu_to_be32(0); /* Signal layout available */
*p++ = cpu_to_be32(args->type);
@@ -2007,7 +2013,8 @@ encode_layoutget(struct xdr_stream *xdr,
p = xdr_encode_hyper(p, args->range.offset);
p = xdr_encode_hyper(p, args->range.length);
p = xdr_encode_hyper(p, args->minlength);
- p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
+ encode_nfs4_stateid(xdr, &args->stateid);
+ p = reserve_space(xdr, 4);
*p = cpu_to_be32(args->maxcount);

dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
@@ -2032,13 +2039,14 @@ encode_layoutcommit(struct xdr_stream *xdr,
dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
NFS_SERVER(args->inode)->pnfs_curr_ld->id);

- p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
+ p = reserve_space(xdr, 24);
*p++ = cpu_to_be32(OP_LAYOUTCOMMIT);
/* Only whole file layouts */
p = xdr_encode_hyper(p, 0); /* offset */
p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
- *p++ = cpu_to_be32(0); /* reclaim */
- p = xdr_encode_opaque_fixed(p, args->stateid.data, NFS4_STATEID_SIZE);
+ *p = cpu_to_be32(0); /* reclaim */
+ encode_nfs4_stateid(xdr, &args->stateid);
+ p = reserve_space(xdr, 20);
*p++ = cpu_to_be32(1); /* newoffset = TRUE */
p = xdr_encode_hyper(p, args->lastbytewritten);
*p++ = cpu_to_be32(0); /* Never send time_modify_changed */
@@ -2070,11 +2078,11 @@ encode_layoutreturn(struct xdr_stream *xdr,
*p++ = cpu_to_be32(args->layout_type);
*p++ = cpu_to_be32(IOMODE_ANY);
*p = cpu_to_be32(RETURN_FILE);
- p = reserve_space(xdr, 16 + NFS4_STATEID_SIZE);
+ p = reserve_space(xdr, 16);
p = xdr_encode_hyper(p, 0);
p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
spin_lock(&args->inode->i_lock);
- xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
+ encode_nfs4_stateid(xdr, &args->stateid);
spin_unlock(&args->inode->i_lock);
if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
@@ -2107,10 +2115,10 @@ static void encode_test_stateid(struct xdr_stream *xdr,
{
__be32 *p;

- p = reserve_space(xdr, 8 + NFS4_STATEID_SIZE);
+ p = reserve_space(xdr, 8);
*p++ = cpu_to_be32(OP_TEST_STATEID);
- *p++ = cpu_to_be32(1);
- xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
+ *p = cpu_to_be32(1);
+ encode_nfs4_stateid(xdr, args->stateid);
hdr->nops++;
hdr->replen += decode_test_stateid_maxsz;
}
@@ -2120,9 +2128,9 @@ static void encode_free_stateid(struct xdr_stream *xdr,
struct compound_hdr *hdr)
{
__be32 *p;
- p = reserve_space(xdr, 4 + NFS4_STATEID_SIZE);
- *p++ = cpu_to_be32(OP_FREE_STATEID);
- xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
+ p = reserve_space(xdr, 4);
+ *p = cpu_to_be32(OP_FREE_STATEID);
+ encode_nfs4_stateid(xdr, args->stateid);
hdr->nops++;
hdr->replen += decode_free_stateid_maxsz;
}
@@ -5640,11 +5648,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
status = decode_op_hdr(xdr, OP_LAYOUTGET);
if (status)
return status;
- p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE);
+ p = xdr_inline_decode(xdr, 4);
+ if (unlikely(!p))
+ goto out_overflow;
+ res->return_on_close = be32_to_cpup(p);
+ decode_stateid(xdr, &res->stateid);
+ p = xdr_inline_decode(xdr, 4);
if (unlikely(!p))
goto out_overflow;
- res->return_on_close = be32_to_cpup(p++);
- p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
layout_count = be32_to_cpup(p);
if (!layout_count) {
dprintk("%s: server responded with empty layout array\n",
--
1.7.7.6


2012-03-05 01:08:02

by Chuck Lever III

[permalink] [raw]
Subject: Re: [PATCH 04/11] NFSv4: Add a helper for encoding opaque data

Er. This collides with a patch I sent earlier this week.

Sent from my iPad

On Mar 4, 2012, at 6:02 PM, Trond Myklebust <[email protected]> wrote:

> Signed-off-by: Trond Myklebust <[email protected]>
> ---
> fs/nfs/nfs4xdr.c | 14 +++++++++-----
> 1 files changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
> index af11e8b..de4cb5c 100644
> --- a/fs/nfs/nfs4xdr.c
> +++ b/fs/nfs/nfs4xdr.c
> @@ -885,6 +885,14 @@ static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
> return p;
> }
>
> +static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
> +{
> + __be32 *p;
> +
> + p = xdr_reserve_space(xdr, len);
> + xdr_encode_opaque_fixed(p, buf, len);
> +}
> +
> static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
> {
> __be32 *p;
> @@ -922,11 +930,7 @@ static void encode_nops(struct compound_hdr *hdr)
>
> static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
> {
> - __be32 *p;
> -
> - p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
> - BUG_ON(p == NULL);
> - xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
> + encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
> }
>
> static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
> --
> 1.7.7.6
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html

2012-03-04 23:03:10

by Myklebust, Trond

[permalink] [raw]
Subject: [PATCH 04/11] NFSv4: Add a helper for encoding opaque data

Signed-off-by: Trond Myklebust <[email protected]>
---
fs/nfs/nfs4xdr.c | 14 +++++++++-----
1 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index af11e8b..de4cb5c 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -885,6 +885,14 @@ static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
return p;
}

+static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
+{
+ __be32 *p;
+
+ p = xdr_reserve_space(xdr, len);
+ xdr_encode_opaque_fixed(p, buf, len);
+}
+
static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
{
__be32 *p;
@@ -922,11 +930,7 @@ static void encode_nops(struct compound_hdr *hdr)

static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
{
- __be32 *p;
-
- p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
- BUG_ON(p == NULL);
- xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE);
+ encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
}

static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
--
1.7.7.6


2012-03-04 23:03:15

by Myklebust, Trond

[permalink] [raw]
Subject: [PATCH 11/11] NFSv4: Add a encode op helper

Signed-off-by: Trond Myklebust <[email protected]>
---
fs/nfs/nfs4xdr.c | 161 +++++++++++-------------------------------------------
1 files changed, 32 insertions(+), 129 deletions(-)

diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index 604da06..7b55c3c 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -935,6 +935,15 @@ static void encode_compound_hdr(struct xdr_stream *xdr,
*p = cpu_to_be32(hdr->nops);
}

+static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
+ uint32_t replen,
+ struct compound_hdr *hdr)
+{
+ encode_word(xdr, op);
+ hdr->nops++;
+ hdr->replen += replen;
+}
+
static void encode_nops(struct compound_hdr *hdr)
{
BUG_ON(hdr->nops > NFS4_MAX_OPS);
@@ -1086,14 +1095,9 @@ static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hd

static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
{
- __be32 *p;
-
- p = reserve_space(xdr, 4);
- *p = cpu_to_be32(OP_CLOSE);
+ encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
encode_nfs4_seqid(xdr, arg->seqid);
encode_nfs4_stateid(xdr, arg->stateid);
- hdr->nops++;
- hdr->replen += decode_close_maxsz;
}

static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
@@ -1172,8 +1176,7 @@ encode_getattr_three(struct xdr_stream *xdr,
{
__be32 *p;

- p = reserve_space(xdr, 4);
- *p = cpu_to_be32(OP_GETATTR);
+ encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
if (bm2) {
p = reserve_space(xdr, 16);
*p++ = cpu_to_be32(3);
@@ -1190,8 +1193,6 @@ encode_getattr_three(struct xdr_stream *xdr,
*p++ = cpu_to_be32(1);
*p = cpu_to_be32(bm0);
}
- hdr->nops++;
- hdr->replen += decode_getattr_maxsz;
}

static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
@@ -1217,23 +1218,13 @@ static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, stru

static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
{
- __be32 *p;
-
- p = reserve_space(xdr, 4);
- *p = cpu_to_be32(OP_GETFH);
- hdr->nops++;
- hdr->replen += decode_getfh_maxsz;
+ encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
}

static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
{
- __be32 *p;
-
- p = reserve_space(xdr, 4);
- *p = cpu_to_be32(OP_LINK);
+ encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
encode_string(xdr, name->len, name->name);
- hdr->nops++;
- hdr->replen += decode_link_maxsz;
}

static inline int nfs4_lock_type(struct file_lock *fl, int block)
@@ -1323,24 +1314,14 @@ static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *ar

static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
{
- __be32 *p;
-
- p = reserve_space(xdr, 4);
- *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
+ encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
encode_lockowner(xdr, lowner);
- hdr->nops++;
- hdr->replen += decode_release_lockowner_maxsz;
}

static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
{
- __be32 *p;
-
- p = reserve_space(xdr, 4);
- *p = cpu_to_be32(OP_LOOKUP);
+ encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
encode_string(xdr, name->len, name->name);
- hdr->nops++;
- hdr->replen += decode_lookup_maxsz;
}

static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
@@ -1371,8 +1352,6 @@ static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_opena
* opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
* owner 4 = 32
*/
- p = reserve_space(xdr, 4);
- *p = cpu_to_be32(OP_OPEN);
encode_nfs4_seqid(xdr, arg->seqid);
encode_share_access(xdr, arg->fmode);
p = reserve_space(xdr, 32);
@@ -1481,6 +1460,7 @@ static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struc

static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
{
+ encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
encode_openhdr(xdr, arg);
encode_opentype(xdr, arg);
switch (arg->claim) {
@@ -1496,55 +1476,33 @@ static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg,
default:
BUG();
}
- hdr->nops++;
- hdr->replen += decode_open_maxsz;
}

static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
{
- __be32 *p;
-
- p = reserve_space(xdr, 4);
- *p = cpu_to_be32(OP_OPEN_CONFIRM);
+ encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
encode_nfs4_stateid(xdr, arg->stateid);
encode_nfs4_seqid(xdr, arg->seqid);
- hdr->nops++;
- hdr->replen += decode_open_confirm_maxsz;
}

static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
{
- __be32 *p;
-
- p = reserve_space(xdr, 4);
- *p = cpu_to_be32(OP_OPEN_DOWNGRADE);
+ encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
encode_nfs4_stateid(xdr, arg->stateid);
encode_nfs4_seqid(xdr, arg->seqid);
encode_share_access(xdr, arg->fmode);
- hdr->nops++;
- hdr->replen += decode_open_downgrade_maxsz;
}

static void
encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
{
- __be32 *p;
-
- p = reserve_space(xdr, 4);
- *p = cpu_to_be32(OP_PUTFH);
+ encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
encode_string(xdr, fh->size, fh->data);
- hdr->nops++;
- hdr->replen += decode_putfh_maxsz;
}

static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
{
- __be32 *p;
-
- p = reserve_space(xdr, 4);
- *p = cpu_to_be32(OP_PUTROOTFH);
- hdr->nops++;
- hdr->replen += decode_putrootfh_maxsz;
+ encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
}

static void encode_open_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx, const struct nfs_lock_context *l_ctx, int zero_seqid)
@@ -1564,17 +1522,13 @@ static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args,
{
__be32 *p;

- p = reserve_space(xdr, 4);
- *p = cpu_to_be32(OP_READ);
-
+ encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
encode_open_stateid(xdr, args->context, args->lock_context,
hdr->minorversion);

p = reserve_space(xdr, 12);
p = xdr_encode_hyper(p, args->offset);
*p = cpu_to_be32(args->count);
- hdr->nops++;
- hdr->replen += decode_read_maxsz;
}

static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
@@ -1622,35 +1576,20 @@ static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg

static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
{
- __be32 *p;
-
- p = reserve_space(xdr, 4);
- *p = cpu_to_be32(OP_READLINK);
- hdr->nops++;
- hdr->replen += decode_readlink_maxsz;
+ encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
}

static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
{
- __be32 *p;
-
- p = reserve_space(xdr, 4);
- *p = cpu_to_be32(OP_REMOVE);
+ encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
encode_string(xdr, name->len, name->name);
- hdr->nops++;
- hdr->replen += decode_remove_maxsz;
}

static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
{
- __be32 *p;
-
- p = reserve_space(xdr, 4);
- *p = cpu_to_be32(OP_RENAME);
+ encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
encode_string(xdr, oldname->len, oldname->name);
encode_string(xdr, newname->len, newname->name);
- hdr->nops++;
- hdr->replen += decode_rename_maxsz;
}

static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
@@ -1668,12 +1607,7 @@ static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
static void
encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
{
- __be32 *p;
-
- p = reserve_space(xdr, 4);
- *p = cpu_to_be32(OP_RESTOREFH);
- hdr->nops++;
- hdr->replen += decode_restorefh_maxsz;
+ encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
}

static void
@@ -1681,8 +1615,7 @@ encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compoun
{
__be32 *p;

- p = reserve_space(xdr, 4);
- *p = cpu_to_be32(OP_SETATTR);
+ encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
encode_nfs4_stateid(xdr, &zero_stateid);
p = reserve_space(xdr, 2*4);
*p++ = cpu_to_be32(1);
@@ -1691,30 +1624,18 @@ encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compoun
p = reserve_space(xdr, 4);
*p = cpu_to_be32(arg->acl_len);
xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
- hdr->nops++;
- hdr->replen += decode_setacl_maxsz;
}

static void
encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
{
- __be32 *p;
-
- p = reserve_space(xdr, 4);
- *p = cpu_to_be32(OP_SAVEFH);
- hdr->nops++;
- hdr->replen += decode_savefh_maxsz;
+ encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
}

static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
{
- __be32 *p;
-
- p = reserve_space(xdr, 4);
- *p = cpu_to_be32(OP_SETATTR);
+ encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
encode_nfs4_stateid(xdr, &arg->stateid);
- hdr->nops++;
- hdr->replen += decode_setattr_maxsz;
encode_attrs(xdr, arg->iap, server);
}

@@ -1753,9 +1674,7 @@ static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *arg
{
__be32 *p;

- p = reserve_space(xdr, 4);
- *p = cpu_to_be32(OP_WRITE);
-
+ encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
encode_open_stateid(xdr, args->context, args->lock_context,
hdr->minorversion);

@@ -1765,30 +1684,18 @@ static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *arg
*p = cpu_to_be32(args->count);

xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
- hdr->nops++;
- hdr->replen += decode_write_maxsz;
}

static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
{
- __be32 *p;
-
- p = reserve_space(xdr, 4);
- *p = cpu_to_be32(OP_DELEGRETURN);
+ encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
encode_nfs4_stateid(xdr, stateid);
- hdr->nops++;
- hdr->replen += decode_delegreturn_maxsz;
}

static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
{
- __be32 *p;
-
- p = reserve_space(xdr, 4);
- *p = cpu_to_be32(OP_SECINFO);
+ encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
encode_string(xdr, name->len, name->name);
- hdr->nops++;
- hdr->replen += decode_secinfo_maxsz;
}

#if defined(CONFIG_NFS_V4_1)
@@ -2132,12 +2039,8 @@ static void encode_free_stateid(struct xdr_stream *xdr,
struct nfs41_free_stateid_args *args,
struct compound_hdr *hdr)
{
- __be32 *p;
- p = reserve_space(xdr, 4);
- *p = cpu_to_be32(OP_FREE_STATEID);
+ encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
encode_nfs4_stateid(xdr, args->stateid);
- hdr->nops++;
- hdr->replen += decode_free_stateid_maxsz;
}
#endif /* CONFIG_NFS_V4_1 */

--
1.7.7.6