* [PATCH RFC 0/13] xdr macros cleanup
@ 2009-08-12 15:15 Benny Halevy
2009-08-12 15:21 ` [PATCH RFC 01/13] sunrpc: hton -> cpu_to_be* Benny Halevy
` (12 more replies)
0 siblings, 13 replies; 20+ messages in thread
From: Benny Halevy @ 2009-08-12 15:15 UTC (permalink / raw)
To: Trond Myklebust; +Cc: NFS list
Hi Trond,
I took a stab at eliminating the Xcoding macros in fs/nfs/nfs4xdr.c
by using generic xdr functions and local helpers that do not rely
on hidden side effects such as assigning to a pointer on the stack
or returning an error from the calling function.
The patches in this series are listed below.
Please let me know if this is the direction you were heading
and if ok with you I'd be happy to help with moving this
mini-project forward.
Benny
[PATCH RFC 01/13] sunrpc: hton -> cpu_to_be*
[PATCH RFC 02/13] sunrpc: ntoh -> be*_to_cpu
[PATCH RFC 03/13] sunrpc: introduce 32-bit Xcoding helpers
[PATCH RFC 04/13] nfs: nfs4xdr: get rid of WRITE32
[PATCH RFC 05/13] nfs: nfs4xdr: get rid of WRITE64
[PATCH RFC 06/13] nfs: nfs4xdr: get rid of WRITEMEM
[PATCH RFC 07/13] nfs: nfs4xdr: merge xdr_encode_int+xdr_encode_opaque_fixed into xdr_encode_opaque
[PATCH RFC 08/13] nfs: nfs4xdr: change RESERVE_SPACE macro into a static helper
[PATCH RFC 09/13] nfs: nfs4xdr: get rid of READ32
[PATCH RFC 10/13] nfs: nfs4xdr: get rid of READ64
[PATCH RFC 11/13] nfs: nfs4xdr: get rid of READTIME macro
[PATCH RFC 12/13] nfs: nfs4xdr: change COPYMEM macro into a static function
[PATCH RFC 13/13] nfs: nfs4xdr: get rid of READ_BUF
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH RFC 01/13] sunrpc: hton -> cpu_to_be*
2009-08-12 15:15 [PATCH RFC 0/13] xdr macros cleanup Benny Halevy
@ 2009-08-12 15:21 ` Benny Halevy
2009-08-12 15:21 ` [PATCH RFC 02/13] sunrpc: ntoh -> be*_to_cpu Benny Halevy
` (11 subsequent siblings)
12 siblings, 0 replies; 20+ messages in thread
From: Benny Halevy @ 2009-08-12 15:21 UTC (permalink / raw)
To: Trond Myklebust; +Cc: linux-nfs
htonl is already defined as cpu_to_be32.
cpu_to_be64 has architecture specific optimized implementations.
Signed-off-by: Benny Halevy <bhalevy@panasas.com>
---
include/linux/sunrpc/xdr.h | 5 ++---
net/sunrpc/xdr.c | 6 +++---
2 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/include/linux/sunrpc/xdr.h b/include/linux/sunrpc/xdr.h
index b99c625..f94bbdc 100644
--- a/include/linux/sunrpc/xdr.h
+++ b/include/linux/sunrpc/xdr.h
@@ -117,9 +117,8 @@ static inline __be32 *xdr_encode_array(__be32 *p, const void *s, unsigned int le
static inline __be32 *
xdr_encode_hyper(__be32 *p, __u64 val)
{
- *p++ = htonl(val >> 32);
- *p++ = htonl(val & 0xFFFFFFFF);
- return p;
+ *(__be64 *)p = cpu_to_be64(val);
+ return p + 2;
}
static inline __be32 *
diff --git a/net/sunrpc/xdr.c b/net/sunrpc/xdr.c
index 406e26d..0d05d25 100644
--- a/net/sunrpc/xdr.c
+++ b/net/sunrpc/xdr.c
@@ -24,7 +24,7 @@ xdr_encode_netobj(__be32 *p, const struct xdr_netobj *obj)
unsigned int quadlen = XDR_QUADLEN(obj->len);
p[quadlen] = 0; /* zero trailing bytes */
- *p++ = htonl(obj->len);
+ *p++ = cpu_to_be32(obj->len);
memcpy(p, obj->data, obj->len);
return p + XDR_QUADLEN(obj->len);
}
@@ -83,7 +83,7 @@ EXPORT_SYMBOL_GPL(xdr_encode_opaque_fixed);
*/
__be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes)
{
- *p++ = htonl(nbytes);
+ *p++ = cpu_to_be32(nbytes);
return xdr_encode_opaque_fixed(p, ptr, nbytes);
}
EXPORT_SYMBOL_GPL(xdr_encode_opaque);
@@ -779,7 +779,7 @@ EXPORT_SYMBOL_GPL(xdr_decode_word);
int
xdr_encode_word(struct xdr_buf *buf, unsigned int base, u32 obj)
{
- __be32 raw = htonl(obj);
+ __be32 raw = cpu_to_be32(obj);
return write_bytes_to_xdr_buf(buf, base, &raw, sizeof(obj));
}
--
1.6.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH RFC 02/13] sunrpc: ntoh -> be*_to_cpu
2009-08-12 15:15 [PATCH RFC 0/13] xdr macros cleanup Benny Halevy
2009-08-12 15:21 ` [PATCH RFC 01/13] sunrpc: hton -> cpu_to_be* Benny Halevy
@ 2009-08-12 15:21 ` Benny Halevy
2009-09-12 14:00 ` Al Viro
2009-08-12 15:21 ` [PATCH RFC 03/13] sunrpc: introduce 32-bit Xcoding helpers Benny Halevy
` (10 subsequent siblings)
12 siblings, 1 reply; 20+ messages in thread
From: Benny Halevy @ 2009-08-12 15:21 UTC (permalink / raw)
To: Trond Myklebust; +Cc: linux-nfs
ntohl is already defined as be32_to_cpu.
be64_to_cpu has architecture specific optimized implementations.
Signed-off-by: Benny Halevy <bhalevy@panasas.com>
---
include/linux/sunrpc/xdr.h | 5 ++---
net/sunrpc/xdr.c | 6 +++---
2 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/include/linux/sunrpc/xdr.h b/include/linux/sunrpc/xdr.h
index f94bbdc..7da466b 100644
--- a/include/linux/sunrpc/xdr.h
+++ b/include/linux/sunrpc/xdr.h
@@ -124,9 +124,8 @@ xdr_encode_hyper(__be32 *p, __u64 val)
static inline __be32 *
xdr_decode_hyper(__be32 *p, __u64 *valp)
{
- *valp = ((__u64) ntohl(*p++)) << 32;
- *valp |= ntohl(*p++);
- return p;
+ *valp = be64_to_cpup((__be64 *)p);
+ return p + 2;
}
/*
diff --git a/net/sunrpc/xdr.c b/net/sunrpc/xdr.c
index 0d05d25..8bd690c 100644
--- a/net/sunrpc/xdr.c
+++ b/net/sunrpc/xdr.c
@@ -35,7 +35,7 @@ xdr_decode_netobj(__be32 *p, struct xdr_netobj *obj)
{
unsigned int len;
- if ((len = ntohl(*p++)) > XDR_MAX_NETOBJ)
+ if ((len = be32_to_cpu(*p++)) > XDR_MAX_NETOBJ)
return NULL;
obj->len = len;
obj->data = (u8 *) p;
@@ -101,7 +101,7 @@ xdr_decode_string_inplace(__be32 *p, char **sp,
{
u32 len;
- len = ntohl(*p++);
+ len = be32_to_cpu(*p++);
if (len > maxlen)
return NULL;
*lenp = len;
@@ -771,7 +771,7 @@ xdr_decode_word(struct xdr_buf *buf, unsigned int base, u32 *obj)
status = read_bytes_from_xdr_buf(buf, base, &raw, sizeof(*obj));
if (status)
return status;
- *obj = ntohl(raw);
+ *obj = be32_to_cpu(raw);
return 0;
}
EXPORT_SYMBOL_GPL(xdr_decode_word);
--
1.6.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH RFC 03/13] sunrpc: introduce 32-bit Xcoding helpers
2009-08-12 15:15 [PATCH RFC 0/13] xdr macros cleanup Benny Halevy
2009-08-12 15:21 ` [PATCH RFC 01/13] sunrpc: hton -> cpu_to_be* Benny Halevy
2009-08-12 15:21 ` [PATCH RFC 02/13] sunrpc: ntoh -> be*_to_cpu Benny Halevy
@ 2009-08-12 15:21 ` Benny Halevy
2009-08-12 20:12 ` Trond Myklebust
2009-08-12 15:21 ` [PATCH RFC 04/13] nfs: nfs4xdr: get rid of WRITE32 Benny Halevy
` (9 subsequent siblings)
12 siblings, 1 reply; 20+ messages in thread
From: Benny Halevy @ 2009-08-12 15:21 UTC (permalink / raw)
To: Trond Myklebust; +Cc: linux-nfs
To be used instead of WRITE32/READ32.
Signed-off-by: Benny Halevy <bhalevy@panasas.com>
---
include/linux/sunrpc/xdr.h | 17 +++++++++++++++++
1 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/include/linux/sunrpc/xdr.h b/include/linux/sunrpc/xdr.h
index 7da466b..466ea12 100644
--- a/include/linux/sunrpc/xdr.h
+++ b/include/linux/sunrpc/xdr.h
@@ -112,6 +112,23 @@ static inline __be32 *xdr_encode_array(__be32 *p, const void *s, unsigned int le
}
/*
+ * Xcode 32bit quantities
+ */
+static inline __be32 *
+xdr_encode_int(__be32 *p, __u32 val)
+{
+ *p = cpu_to_be32(val);
+ return p + 1;
+}
+
+static inline __be32 *
+xdr_decode_int(__be32 *p, __u32 *valp)
+{
+ *valp = be32_to_cpu(*p);
+ return p + 1;
+}
+
+/*
* Decode 64bit quantities (NFSv3 support)
*/
static inline __be32 *
--
1.6.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH RFC 04/13] nfs: nfs4xdr: get rid of WRITE32
2009-08-12 15:15 [PATCH RFC 0/13] xdr macros cleanup Benny Halevy
` (2 preceding siblings ...)
2009-08-12 15:21 ` [PATCH RFC 03/13] sunrpc: introduce 32-bit Xcoding helpers Benny Halevy
@ 2009-08-12 15:21 ` Benny Halevy
2009-08-12 15:22 ` [PATCH RFC 05/13] nfs: nfs4xdr: get rid of WRITE64 Benny Halevy
` (8 subsequent siblings)
12 siblings, 0 replies; 20+ messages in thread
From: Benny Halevy @ 2009-08-12 15:21 UTC (permalink / raw)
To: Trond Myklebust; +Cc: linux-nfs
use xdr_encode_int instead.
Signed-off-by: Benny Halevy <bhalevy@panasas.com>
---
fs/nfs/nfs4xdr.c | 291 +++++++++++++++++++++++++++---------------------------
1 files changed, 145 insertions(+), 146 deletions(-)
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index 617273e..98500b5 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -712,7 +712,6 @@ struct compound_hdr {
* task to translate them into Linux-specific versions which are more
* consistent with the style used in NFSv2/v3...
*/
-#define WRITE32(n) *p++ = htonl(n)
#define WRITE64(n) do { \
*p++ = htonl((uint32_t)((n) >> 32)); \
*p++ = htonl((uint32_t)(n)); \
@@ -750,11 +749,11 @@ static void encode_compound_hdr(struct xdr_stream *xdr,
dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
- WRITE32(hdr->taglen);
+ p = xdr_encode_int(p, hdr->taglen);
WRITEMEM(hdr->tag, hdr->taglen);
- WRITE32(hdr->minorversion);
+ p = xdr_encode_int(p, hdr->minorversion);
hdr->nops_p = p;
- WRITE32(hdr->nops);
+ p = xdr_encode_int(p, hdr->nops);
}
static void encode_nops(struct compound_hdr *hdr)
@@ -835,7 +834,7 @@ static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const
* We write the bitmap length now, but leave the bitmap and the attribute
* buffer length to be backfilled at the end of this routine.
*/
- WRITE32(2);
+ p = xdr_encode_int(p, 2);
q = p;
p += 3;
@@ -845,39 +844,39 @@ static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const
}
if (iap->ia_valid & ATTR_MODE) {
bmval1 |= FATTR4_WORD1_MODE;
- WRITE32(iap->ia_mode & S_IALLUGO);
+ p = xdr_encode_int(p, iap->ia_mode & S_IALLUGO);
}
if (iap->ia_valid & ATTR_UID) {
bmval1 |= FATTR4_WORD1_OWNER;
- WRITE32(owner_namelen);
+ p = xdr_encode_int(p, owner_namelen);
WRITEMEM(owner_name, owner_namelen);
}
if (iap->ia_valid & ATTR_GID) {
bmval1 |= FATTR4_WORD1_OWNER_GROUP;
- WRITE32(owner_grouplen);
+ p = xdr_encode_int(p, owner_grouplen);
WRITEMEM(owner_group, owner_grouplen);
}
if (iap->ia_valid & ATTR_ATIME_SET) {
bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
- WRITE32(NFS4_SET_TO_CLIENT_TIME);
- WRITE32(0);
- WRITE32(iap->ia_mtime.tv_sec);
- WRITE32(iap->ia_mtime.tv_nsec);
+ p = xdr_encode_int(p, NFS4_SET_TO_CLIENT_TIME);
+ p = xdr_encode_int(p, 0);
+ p = xdr_encode_int(p, iap->ia_mtime.tv_sec);
+ p = xdr_encode_int(p, iap->ia_mtime.tv_nsec);
}
else if (iap->ia_valid & ATTR_ATIME) {
bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
- WRITE32(NFS4_SET_TO_SERVER_TIME);
+ p = xdr_encode_int(p, NFS4_SET_TO_SERVER_TIME);
}
if (iap->ia_valid & ATTR_MTIME_SET) {
bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
- WRITE32(NFS4_SET_TO_CLIENT_TIME);
- WRITE32(0);
- WRITE32(iap->ia_mtime.tv_sec);
- WRITE32(iap->ia_mtime.tv_nsec);
+ p = xdr_encode_int(p, NFS4_SET_TO_CLIENT_TIME);
+ p = xdr_encode_int(p, 0);
+ p = xdr_encode_int(p, iap->ia_mtime.tv_sec);
+ p = xdr_encode_int(p, iap->ia_mtime.tv_nsec);
}
else if (iap->ia_valid & ATTR_MTIME) {
bmval1 |= FATTR4_WORD1_TIME_MODIFY_SET;
- WRITE32(NFS4_SET_TO_SERVER_TIME);
+ p = xdr_encode_int(p, NFS4_SET_TO_SERVER_TIME);
}
/*
@@ -901,8 +900,8 @@ static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hd
__be32 *p;
RESERVE_SPACE(8);
- WRITE32(OP_ACCESS);
- WRITE32(access);
+ p = xdr_encode_int(p, OP_ACCESS);
+ p = xdr_encode_int(p, access);
hdr->nops++;
hdr->replen += decode_access_maxsz;
}
@@ -912,8 +911,8 @@ static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg
__be32 *p;
RESERVE_SPACE(8+NFS4_STATEID_SIZE);
- WRITE32(OP_CLOSE);
- WRITE32(arg->seqid->sequence->counter);
+ p = xdr_encode_int(p, OP_CLOSE);
+ p = xdr_encode_int(p, arg->seqid->sequence->counter);
WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
hdr->nops++;
hdr->replen += decode_close_maxsz;
@@ -924,9 +923,9 @@ static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *ar
__be32 *p;
RESERVE_SPACE(16);
- WRITE32(OP_COMMIT);
+ p = xdr_encode_int(p, OP_COMMIT);
WRITE64(args->offset);
- WRITE32(args->count);
+ p = xdr_encode_int(p, args->count);
hdr->nops++;
hdr->replen += decode_commit_maxsz;
}
@@ -936,20 +935,20 @@ static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *
__be32 *p;
RESERVE_SPACE(8);
- WRITE32(OP_CREATE);
- WRITE32(create->ftype);
+ p = xdr_encode_int(p, OP_CREATE);
+ p = xdr_encode_int(p, create->ftype);
switch (create->ftype) {
case NF4LNK:
RESERVE_SPACE(4);
- WRITE32(create->u.symlink.len);
+ p = xdr_encode_int(p, create->u.symlink.len);
xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
break;
case NF4BLK: case NF4CHR:
RESERVE_SPACE(8);
- WRITE32(create->u.device.specdata1);
- WRITE32(create->u.device.specdata2);
+ p = xdr_encode_int(p, create->u.device.specdata1);
+ p = xdr_encode_int(p, create->u.device.specdata2);
break;
default:
@@ -957,7 +956,7 @@ static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *
}
RESERVE_SPACE(4 + create->name->len);
- WRITE32(create->name->len);
+ p = xdr_encode_int(p, create->name->len);
WRITEMEM(create->name->name, create->name->len);
hdr->nops++;
hdr->replen += decode_create_maxsz;
@@ -970,9 +969,9 @@ static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct c
__be32 *p;
RESERVE_SPACE(12);
- WRITE32(OP_GETATTR);
- WRITE32(1);
- WRITE32(bitmap);
+ p = xdr_encode_int(p, OP_GETATTR);
+ p = xdr_encode_int(p, 1);
+ p = xdr_encode_int(p, bitmap);
hdr->nops++;
hdr->replen += decode_getattr_maxsz;
}
@@ -982,10 +981,10 @@ static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm
__be32 *p;
RESERVE_SPACE(16);
- WRITE32(OP_GETATTR);
- WRITE32(2);
- WRITE32(bm0);
- WRITE32(bm1);
+ p = xdr_encode_int(p, OP_GETATTR);
+ p = xdr_encode_int(p, 2);
+ p = xdr_encode_int(p, bm0);
+ p = xdr_encode_int(p, bm1);
hdr->nops++;
hdr->replen += decode_getattr_maxsz;
}
@@ -1013,7 +1012,7 @@ static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
__be32 *p;
RESERVE_SPACE(4);
- WRITE32(OP_GETFH);
+ p = xdr_encode_int(p, OP_GETFH);
hdr->nops++;
hdr->replen += decode_getfh_maxsz;
}
@@ -1023,8 +1022,8 @@ static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct
__be32 *p;
RESERVE_SPACE(8 + name->len);
- WRITE32(OP_LINK);
- WRITE32(name->len);
+ p = xdr_encode_int(p, OP_LINK);
+ p = xdr_encode_int(p, name->len);
WRITEMEM(name->name, name->len);
hdr->nops++;
hdr->replen += decode_link_maxsz;
@@ -1053,26 +1052,26 @@ static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args
__be32 *p;
RESERVE_SPACE(32);
- WRITE32(OP_LOCK);
- WRITE32(nfs4_lock_type(args->fl, args->block));
- WRITE32(args->reclaim);
+ p = xdr_encode_int(p, OP_LOCK);
+ p = xdr_encode_int(p, nfs4_lock_type(args->fl, args->block));
+ p = xdr_encode_int(p, args->reclaim);
WRITE64(args->fl->fl_start);
WRITE64(nfs4_lock_length(args->fl));
- WRITE32(args->new_lock_owner);
+ p = xdr_encode_int(p, args->new_lock_owner);
if (args->new_lock_owner){
RESERVE_SPACE(4+NFS4_STATEID_SIZE+32);
- WRITE32(args->open_seqid->sequence->counter);
+ p = xdr_encode_int(p, args->open_seqid->sequence->counter);
WRITEMEM(args->open_stateid->data, NFS4_STATEID_SIZE);
- WRITE32(args->lock_seqid->sequence->counter);
+ p = xdr_encode_int(p, args->lock_seqid->sequence->counter);
WRITE64(args->lock_owner.clientid);
- WRITE32(16);
+ p = xdr_encode_int(p, 16);
WRITEMEM("lock id:", 8);
WRITE64(args->lock_owner.id);
}
else {
RESERVE_SPACE(NFS4_STATEID_SIZE+4);
WRITEMEM(args->lock_stateid->data, NFS4_STATEID_SIZE);
- WRITE32(args->lock_seqid->sequence->counter);
+ p = xdr_encode_int(p, args->lock_seqid->sequence->counter);
}
hdr->nops++;
hdr->replen += decode_lock_maxsz;
@@ -1083,12 +1082,12 @@ static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *ar
__be32 *p;
RESERVE_SPACE(52);
- WRITE32(OP_LOCKT);
- WRITE32(nfs4_lock_type(args->fl, 0));
+ p = xdr_encode_int(p, OP_LOCKT);
+ p = xdr_encode_int(p, nfs4_lock_type(args->fl, 0));
WRITE64(args->fl->fl_start);
WRITE64(nfs4_lock_length(args->fl));
WRITE64(args->lock_owner.clientid);
- WRITE32(16);
+ p = xdr_encode_int(p, 16);
WRITEMEM("lock id:", 8);
WRITE64(args->lock_owner.id);
hdr->nops++;
@@ -1100,9 +1099,9 @@ static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *ar
__be32 *p;
RESERVE_SPACE(12+NFS4_STATEID_SIZE+16);
- WRITE32(OP_LOCKU);
- WRITE32(nfs4_lock_type(args->fl, 0));
- WRITE32(args->seqid->sequence->counter);
+ p = xdr_encode_int(p, OP_LOCKU);
+ p = xdr_encode_int(p, nfs4_lock_type(args->fl, 0));
+ p = xdr_encode_int(p, args->seqid->sequence->counter);
WRITEMEM(args->stateid->data, NFS4_STATEID_SIZE);
WRITE64(args->fl->fl_start);
WRITE64(nfs4_lock_length(args->fl));
@@ -1116,8 +1115,8 @@ static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struc
__be32 *p;
RESERVE_SPACE(8 + len);
- WRITE32(OP_LOOKUP);
- WRITE32(len);
+ p = xdr_encode_int(p, OP_LOOKUP);
+ p = xdr_encode_int(p, len);
WRITEMEM(name->name, len);
hdr->nops++;
hdr->replen += decode_lookup_maxsz;
@@ -1130,18 +1129,18 @@ static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
RESERVE_SPACE(8);
switch (fmode & (FMODE_READ|FMODE_WRITE)) {
case FMODE_READ:
- WRITE32(NFS4_SHARE_ACCESS_READ);
+ p = xdr_encode_int(p, NFS4_SHARE_ACCESS_READ);
break;
case FMODE_WRITE:
- WRITE32(NFS4_SHARE_ACCESS_WRITE);
+ p = xdr_encode_int(p, NFS4_SHARE_ACCESS_WRITE);
break;
case FMODE_READ|FMODE_WRITE:
- WRITE32(NFS4_SHARE_ACCESS_BOTH);
+ p = xdr_encode_int(p, NFS4_SHARE_ACCESS_BOTH);
break;
default:
- WRITE32(0);
+ p = xdr_encode_int(p, 0);
}
- WRITE32(0); /* for linux, share_deny = 0 always */
+ p = xdr_encode_int(p, 0); /* for linux, share_deny = 0 always */
}
static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
@@ -1152,12 +1151,12 @@ static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_opena
* owner 4 = 32
*/
RESERVE_SPACE(8);
- WRITE32(OP_OPEN);
- WRITE32(arg->seqid->sequence->counter);
+ p = xdr_encode_int(p, OP_OPEN);
+ p = xdr_encode_int(p, arg->seqid->sequence->counter);
encode_share_access(xdr, arg->fmode);
RESERVE_SPACE(28);
WRITE64(arg->clientid);
- WRITE32(16);
+ p = xdr_encode_int(p, 16);
WRITEMEM("open id:", 8);
WRITE64(arg->id);
}
@@ -1169,11 +1168,11 @@ static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_op
RESERVE_SPACE(4);
switch(arg->open_flags & O_EXCL) {
case 0:
- WRITE32(NFS4_CREATE_UNCHECKED);
+ p = xdr_encode_int(p, NFS4_CREATE_UNCHECKED);
encode_attrs(xdr, arg->u.attrs, arg->server);
break;
default:
- WRITE32(NFS4_CREATE_EXCLUSIVE);
+ p = xdr_encode_int(p, NFS4_CREATE_EXCLUSIVE);
encode_nfs4_verifier(xdr, &arg->u.verifier);
}
}
@@ -1185,11 +1184,11 @@ static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *a
RESERVE_SPACE(4);
switch (arg->open_flags & O_CREAT) {
case 0:
- WRITE32(NFS4_OPEN_NOCREATE);
+ p = xdr_encode_int(p, NFS4_OPEN_NOCREATE);
break;
default:
BUG_ON(arg->claim != NFS4_OPEN_CLAIM_NULL);
- WRITE32(NFS4_OPEN_CREATE);
+ p = xdr_encode_int(p, NFS4_OPEN_CREATE);
encode_createmode(xdr, arg);
}
}
@@ -1201,13 +1200,13 @@ static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delega
RESERVE_SPACE(4);
switch (delegation_type) {
case 0:
- WRITE32(NFS4_OPEN_DELEGATE_NONE);
+ p = xdr_encode_int(p, NFS4_OPEN_DELEGATE_NONE);
break;
case FMODE_READ:
- WRITE32(NFS4_OPEN_DELEGATE_READ);
+ p = xdr_encode_int(p, NFS4_OPEN_DELEGATE_READ);
break;
case FMODE_WRITE|FMODE_READ:
- WRITE32(NFS4_OPEN_DELEGATE_WRITE);
+ p = xdr_encode_int(p, NFS4_OPEN_DELEGATE_WRITE);
break;
default:
BUG();
@@ -1219,7 +1218,7 @@ static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *
__be32 *p;
RESERVE_SPACE(4);
- WRITE32(NFS4_OPEN_CLAIM_NULL);
+ p = xdr_encode_int(p, NFS4_OPEN_CLAIM_NULL);
encode_string(xdr, name->len, name->name);
}
@@ -1228,7 +1227,7 @@ static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
__be32 *p;
RESERVE_SPACE(4);
- WRITE32(NFS4_OPEN_CLAIM_PREVIOUS);
+ p = xdr_encode_int(p, NFS4_OPEN_CLAIM_PREVIOUS);
encode_delegation_type(xdr, type);
}
@@ -1237,7 +1236,7 @@ static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struc
__be32 *p;
RESERVE_SPACE(4+NFS4_STATEID_SIZE);
- WRITE32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
+ p = xdr_encode_int(p, NFS4_OPEN_CLAIM_DELEGATE_CUR);
WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
encode_string(xdr, name->len, name->name);
}
@@ -1268,9 +1267,9 @@ static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_co
__be32 *p;
RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
- WRITE32(OP_OPEN_CONFIRM);
+ p = xdr_encode_int(p, OP_OPEN_CONFIRM);
WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
- WRITE32(arg->seqid->sequence->counter);
+ p = xdr_encode_int(p, arg->seqid->sequence->counter);
hdr->nops++;
hdr->replen += decode_open_confirm_maxsz;
}
@@ -1280,9 +1279,9 @@ static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_close
__be32 *p;
RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
- WRITE32(OP_OPEN_DOWNGRADE);
+ p = xdr_encode_int(p, OP_OPEN_DOWNGRADE);
WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
- WRITE32(arg->seqid->sequence->counter);
+ p = xdr_encode_int(p, arg->seqid->sequence->counter);
encode_share_access(xdr, arg->fmode);
hdr->nops++;
hdr->replen += decode_open_downgrade_maxsz;
@@ -1295,8 +1294,8 @@ encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hd
__be32 *p;
RESERVE_SPACE(8 + len);
- WRITE32(OP_PUTFH);
- WRITE32(len);
+ p = xdr_encode_int(p, OP_PUTFH);
+ p = xdr_encode_int(p, len);
WRITEMEM(fh->data, len);
hdr->nops++;
hdr->replen += decode_putfh_maxsz;
@@ -1307,7 +1306,7 @@ static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
__be32 *p;
RESERVE_SPACE(4);
- WRITE32(OP_PUTROOTFH);
+ p = xdr_encode_int(p, OP_PUTROOTFH);
hdr->nops++;
hdr->replen += decode_putrootfh_maxsz;
}
@@ -1330,13 +1329,13 @@ static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args,
__be32 *p;
RESERVE_SPACE(4);
- WRITE32(OP_READ);
+ p = xdr_encode_int(p, OP_READ);
encode_stateid(xdr, args->context);
RESERVE_SPACE(12);
WRITE64(args->offset);
- WRITE32(args->count);
+ p = xdr_encode_int(p, args->count);
hdr->nops++;
hdr->replen += decode_read_maxsz;
}
@@ -1350,19 +1349,19 @@ static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg
__be32 *p;
RESERVE_SPACE(12+NFS4_VERIFIER_SIZE+20);
- WRITE32(OP_READDIR);
+ p = xdr_encode_int(p, OP_READDIR);
WRITE64(readdir->cookie);
WRITEMEM(readdir->verifier.data, NFS4_VERIFIER_SIZE);
- WRITE32(readdir->count >> 1); /* We're not doing readdirplus */
- WRITE32(readdir->count);
- WRITE32(2);
+ p = xdr_encode_int(p, readdir->count >> 1); /* We're not doing readdirplus */
+ p = xdr_encode_int(p, readdir->count);
+ p = xdr_encode_int(p, 2);
/* Switch to mounted_on_fileid if the server supports it */
if (readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
attrs[0] &= ~FATTR4_WORD0_FILEID;
else
attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
- WRITE32(attrs[0] & readdir->bitmask[0]);
- WRITE32(attrs[1] & readdir->bitmask[1]);
+ p = xdr_encode_int(p, attrs[0] & readdir->bitmask[0]);
+ p = xdr_encode_int(p, attrs[1] & readdir->bitmask[1]);
hdr->nops++;
hdr->replen += decode_readdir_maxsz;
dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
@@ -1379,7 +1378,7 @@ static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *
__be32 *p;
RESERVE_SPACE(4);
- WRITE32(OP_READLINK);
+ p = xdr_encode_int(p, OP_READLINK);
hdr->nops++;
hdr->replen += decode_readlink_maxsz;
}
@@ -1389,8 +1388,8 @@ static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struc
__be32 *p;
RESERVE_SPACE(8 + name->len);
- WRITE32(OP_REMOVE);
- WRITE32(name->len);
+ p = xdr_encode_int(p, OP_REMOVE);
+ p = xdr_encode_int(p, name->len);
WRITEMEM(name->name, name->len);
hdr->nops++;
hdr->replen += decode_remove_maxsz;
@@ -1401,12 +1400,12 @@ static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, co
__be32 *p;
RESERVE_SPACE(8 + oldname->len);
- WRITE32(OP_RENAME);
- WRITE32(oldname->len);
+ p = xdr_encode_int(p, OP_RENAME);
+ p = xdr_encode_int(p, oldname->len);
WRITEMEM(oldname->name, oldname->len);
RESERVE_SPACE(4 + newname->len);
- WRITE32(newname->len);
+ p = xdr_encode_int(p, newname->len);
WRITEMEM(newname->name, newname->len);
hdr->nops++;
hdr->replen += decode_rename_maxsz;
@@ -1417,7 +1416,7 @@ static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client
__be32 *p;
RESERVE_SPACE(12);
- WRITE32(OP_RENEW);
+ p = xdr_encode_int(p, OP_RENEW);
WRITE64(client_stateid->cl_clientid);
hdr->nops++;
hdr->replen += decode_renew_maxsz;
@@ -1429,7 +1428,7 @@ encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
__be32 *p;
RESERVE_SPACE(4);
- WRITE32(OP_RESTOREFH);
+ p = xdr_encode_int(p, OP_RESTOREFH);
hdr->nops++;
hdr->replen += decode_restorefh_maxsz;
}
@@ -1440,15 +1439,15 @@ encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compoun
__be32 *p;
RESERVE_SPACE(4+NFS4_STATEID_SIZE);
- WRITE32(OP_SETATTR);
+ p = xdr_encode_int(p, OP_SETATTR);
WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
RESERVE_SPACE(2*4);
- WRITE32(1);
- WRITE32(FATTR4_WORD0_ACL);
+ p = xdr_encode_int(p, 1);
+ p = xdr_encode_int(p, FATTR4_WORD0_ACL);
if (arg->acl_len % 4)
return -EINVAL;
RESERVE_SPACE(4);
- WRITE32(arg->acl_len);
+ p = xdr_encode_int(p, arg->acl_len);
xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
hdr->nops++;
hdr->replen += decode_setacl_maxsz;
@@ -1461,7 +1460,7 @@ encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
__be32 *p;
RESERVE_SPACE(4);
- WRITE32(OP_SAVEFH);
+ p = xdr_encode_int(p, OP_SAVEFH);
hdr->nops++;
hdr->replen += decode_savefh_maxsz;
}
@@ -1471,7 +1470,7 @@ static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs
__be32 *p;
RESERVE_SPACE(4+NFS4_STATEID_SIZE);
- WRITE32(OP_SETATTR);
+ p = xdr_encode_int(p, OP_SETATTR);
WRITEMEM(arg->stateid.data, NFS4_STATEID_SIZE);
hdr->nops++;
hdr->replen += decode_setattr_maxsz;
@@ -1483,16 +1482,16 @@ static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclie
__be32 *p;
RESERVE_SPACE(4 + NFS4_VERIFIER_SIZE);
- WRITE32(OP_SETCLIENTID);
+ p = xdr_encode_int(p, OP_SETCLIENTID);
WRITEMEM(setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
RESERVE_SPACE(4);
- WRITE32(setclientid->sc_prog);
+ p = xdr_encode_int(p, setclientid->sc_prog);
encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
RESERVE_SPACE(4);
- WRITE32(setclientid->sc_cb_ident);
+ p = xdr_encode_int(p, setclientid->sc_cb_ident);
hdr->nops++;
hdr->replen += decode_setclientid_maxsz;
}
@@ -1502,7 +1501,7 @@ static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_
__be32 *p;
RESERVE_SPACE(12 + NFS4_VERIFIER_SIZE);
- WRITE32(OP_SETCLIENTID_CONFIRM);
+ p = xdr_encode_int(p, OP_SETCLIENTID_CONFIRM);
WRITE64(client_state->cl_clientid);
WRITEMEM(client_state->cl_confirm.data, NFS4_VERIFIER_SIZE);
hdr->nops++;
@@ -1514,14 +1513,14 @@ static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *arg
__be32 *p;
RESERVE_SPACE(4);
- WRITE32(OP_WRITE);
+ p = xdr_encode_int(p, OP_WRITE);
encode_stateid(xdr, args->context);
RESERVE_SPACE(16);
WRITE64(args->offset);
- WRITE32(args->stable);
- WRITE32(args->count);
+ p = xdr_encode_int(p, args->stable);
+ p = xdr_encode_int(p, args->count);
xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
hdr->nops++;
@@ -1534,7 +1533,7 @@ static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *state
RESERVE_SPACE(4+NFS4_STATEID_SIZE);
- WRITE32(OP_DELEGRETURN);
+ p = xdr_encode_int(p, OP_DELEGRETURN);
WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
hdr->nops++;
hdr->replen += decode_delegreturn_maxsz;
@@ -1549,15 +1548,15 @@ static void encode_exchange_id(struct xdr_stream *xdr,
__be32 *p;
RESERVE_SPACE(4 + sizeof(args->verifier->data));
- WRITE32(OP_EXCHANGE_ID);
+ p = xdr_encode_int(p, OP_EXCHANGE_ID);
WRITEMEM(args->verifier->data, sizeof(args->verifier->data));
encode_string(xdr, args->id_len, args->id);
RESERVE_SPACE(12);
- WRITE32(args->flags);
- WRITE32(0); /* zero length state_protect4_a */
- WRITE32(0); /* zero length implementation id array */
+ p = xdr_encode_int(p, args->flags);
+ p = xdr_encode_int(p, 0); /* zero length state_protect4_a */
+ p = xdr_encode_int(p, 0); /* zero length implementation id array */
hdr->nops++;
hdr->replen += decode_exchange_id_maxsz;
}
@@ -1572,54 +1571,54 @@ static void encode_create_session(struct xdr_stream *xdr,
struct nfs_client *clp = args->client;
RESERVE_SPACE(4);
- WRITE32(OP_CREATE_SESSION);
+ p = xdr_encode_int(p, OP_CREATE_SESSION);
RESERVE_SPACE(8);
WRITE64(clp->cl_ex_clid);
RESERVE_SPACE(8);
- WRITE32(clp->cl_seqid); /*Sequence id */
- WRITE32(args->flags); /*flags */
+ p = xdr_encode_int(p, clp->cl_seqid); /*Sequence id */
+ p = xdr_encode_int(p, args->flags); /*flags */
RESERVE_SPACE(2*28); /* 2 channel_attrs */
/* Fore Channel */
- WRITE32(args->fc_attrs.headerpadsz); /* header padding size */
- WRITE32(args->fc_attrs.max_rqst_sz); /* max req size */
- WRITE32(args->fc_attrs.max_resp_sz); /* max resp size */
- WRITE32(args->fc_attrs.max_resp_sz_cached); /* Max resp sz cached */
- WRITE32(args->fc_attrs.max_ops); /* max operations */
- WRITE32(args->fc_attrs.max_reqs); /* max requests */
- WRITE32(0); /* rdmachannel_attrs */
+ p = xdr_encode_int(p, args->fc_attrs.headerpadsz); /* header padding size */
+ p = xdr_encode_int(p, args->fc_attrs.max_rqst_sz); /* max req size */
+ p = xdr_encode_int(p, args->fc_attrs.max_resp_sz); /* max resp size */
+ p = xdr_encode_int(p, args->fc_attrs.max_resp_sz_cached); /* Max resp sz cached */
+ p = xdr_encode_int(p, args->fc_attrs.max_ops); /* max operations */
+ p = xdr_encode_int(p, args->fc_attrs.max_reqs); /* max requests */
+ p = xdr_encode_int(p, 0); /* rdmachannel_attrs */
/* Back Channel */
- WRITE32(args->fc_attrs.headerpadsz); /* header padding size */
- WRITE32(args->bc_attrs.max_rqst_sz); /* max req size */
- WRITE32(args->bc_attrs.max_resp_sz); /* max resp size */
- WRITE32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
- WRITE32(args->bc_attrs.max_ops); /* max operations */
- WRITE32(args->bc_attrs.max_reqs); /* max requests */
- WRITE32(0); /* rdmachannel_attrs */
+ p = xdr_encode_int(p, args->fc_attrs.headerpadsz); /* header padding size */
+ p = xdr_encode_int(p, args->bc_attrs.max_rqst_sz); /* max req size */
+ p = xdr_encode_int(p, args->bc_attrs.max_resp_sz); /* max resp size */
+ p = xdr_encode_int(p, args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
+ p = xdr_encode_int(p, args->bc_attrs.max_ops); /* max operations */
+ p = xdr_encode_int(p, args->bc_attrs.max_reqs); /* max requests */
+ p = xdr_encode_int(p, 0); /* rdmachannel_attrs */
RESERVE_SPACE(4);
- WRITE32(args->cb_program); /* cb_program */
+ p = xdr_encode_int(p, args->cb_program); /* cb_program */
RESERVE_SPACE(4); /* # of security flavors */
- WRITE32(1);
+ p = xdr_encode_int(p, 1);
RESERVE_SPACE(4);
- WRITE32(RPC_AUTH_UNIX); /* auth_sys */
+ p = xdr_encode_int(p, RPC_AUTH_UNIX); /* auth_sys */
/* authsys_parms rfc1831 */
RESERVE_SPACE(4);
- WRITE32((u32)clp->cl_boot_time.tv_nsec); /* stamp */
+ p = xdr_encode_int(p, (u32)clp->cl_boot_time.tv_nsec); /* stamp */
len = scnprintf(machine_name, sizeof(machine_name), "%s",
clp->cl_ipaddr);
RESERVE_SPACE(16 + len);
- WRITE32(len);
+ p = xdr_encode_int(p, len);
WRITEMEM(machine_name, len);
- WRITE32(0); /* UID */
- WRITE32(0); /* GID */
- WRITE32(0); /* No more gids */
+ p = xdr_encode_int(p, 0); /* UID */
+ p = xdr_encode_int(p, 0); /* GID */
+ p = xdr_encode_int(p, 0); /* No more gids */
hdr->nops++;
hdr->replen += decode_create_session_maxsz;
}
@@ -1630,7 +1629,7 @@ static void encode_destroy_session(struct xdr_stream *xdr,
{
__be32 *p;
RESERVE_SPACE(4 + NFS4_MAX_SESSIONID_LEN);
- WRITE32(OP_DESTROY_SESSION);
+ p = xdr_encode_int(p, OP_DESTROY_SESSION);
WRITEMEM(session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
hdr->nops++;
hdr->replen += decode_destroy_session_maxsz;
@@ -1656,7 +1655,7 @@ static void encode_sequence(struct xdr_stream *xdr,
slot = tp->slots + args->sa_slotid;
RESERVE_SPACE(4);
- WRITE32(OP_SEQUENCE);
+ p = xdr_encode_int(p, OP_SEQUENCE);
/*
* Sessionid + seqid + slotid + max slotid + cache_this
@@ -1672,10 +1671,10 @@ static void encode_sequence(struct xdr_stream *xdr,
tp->highest_used_slotid, args->sa_cache_this);
RESERVE_SPACE(NFS4_MAX_SESSIONID_LEN + 16);
WRITEMEM(session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
- WRITE32(slot->seq_nr);
- WRITE32(args->sa_slotid);
- WRITE32(tp->highest_used_slotid);
- WRITE32(args->sa_cache_this);
+ p = xdr_encode_int(p, slot->seq_nr);
+ p = xdr_encode_int(p, args->sa_slotid);
+ p = xdr_encode_int(p, tp->highest_used_slotid);
+ p = xdr_encode_int(p, args->sa_cache_this);
hdr->nops++;
hdr->replen += decode_sequence_maxsz;
#endif /* CONFIG_NFS_V4_1 */
--
1.6.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH RFC 05/13] nfs: nfs4xdr: get rid of WRITE64
2009-08-12 15:15 [PATCH RFC 0/13] xdr macros cleanup Benny Halevy
` (3 preceding siblings ...)
2009-08-12 15:21 ` [PATCH RFC 04/13] nfs: nfs4xdr: get rid of WRITE32 Benny Halevy
@ 2009-08-12 15:22 ` Benny Halevy
2009-08-12 15:22 ` [PATCH RFC 06/13] nfs: nfs4xdr: get rid of WRITEMEM Benny Halevy
` (7 subsequent siblings)
12 siblings, 0 replies; 20+ messages in thread
From: Benny Halevy @ 2009-08-12 15:22 UTC (permalink / raw)
To: Trond Myklebust; +Cc: linux-nfs
use xdr_encode_hyper instead.
Signed-off-by: Benny Halevy <bhalevy@panasas.com>
---
fs/nfs/nfs4xdr.c | 44 ++++++++++++++++++++------------------------
1 files changed, 20 insertions(+), 24 deletions(-)
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index 98500b5..fce7de3 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -712,10 +712,6 @@ struct compound_hdr {
* task to translate them into Linux-specific versions which are more
* consistent with the style used in NFSv2/v3...
*/
-#define WRITE64(n) do { \
- *p++ = htonl((uint32_t)((n) >> 32)); \
- *p++ = htonl((uint32_t)(n)); \
-} while (0)
#define WRITEMEM(ptr,nbytes) do { \
p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
} while (0)
@@ -840,7 +836,7 @@ static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const
if (iap->ia_valid & ATTR_SIZE) {
bmval0 |= FATTR4_WORD0_SIZE;
- WRITE64(iap->ia_size);
+ p = xdr_encode_hyper(p, iap->ia_size);
}
if (iap->ia_valid & ATTR_MODE) {
bmval1 |= FATTR4_WORD1_MODE;
@@ -924,7 +920,7 @@ static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *ar
RESERVE_SPACE(16);
p = xdr_encode_int(p, OP_COMMIT);
- WRITE64(args->offset);
+ p = xdr_encode_hyper(p, args->offset);
p = xdr_encode_int(p, args->count);
hdr->nops++;
hdr->replen += decode_commit_maxsz;
@@ -1055,18 +1051,18 @@ static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args
p = xdr_encode_int(p, OP_LOCK);
p = xdr_encode_int(p, nfs4_lock_type(args->fl, args->block));
p = xdr_encode_int(p, args->reclaim);
- WRITE64(args->fl->fl_start);
- WRITE64(nfs4_lock_length(args->fl));
+ p = xdr_encode_hyper(p, args->fl->fl_start);
+ p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
p = xdr_encode_int(p, args->new_lock_owner);
if (args->new_lock_owner){
RESERVE_SPACE(4+NFS4_STATEID_SIZE+32);
p = xdr_encode_int(p, args->open_seqid->sequence->counter);
WRITEMEM(args->open_stateid->data, NFS4_STATEID_SIZE);
p = xdr_encode_int(p, args->lock_seqid->sequence->counter);
- WRITE64(args->lock_owner.clientid);
+ p = xdr_encode_hyper(p, args->lock_owner.clientid);
p = xdr_encode_int(p, 16);
WRITEMEM("lock id:", 8);
- WRITE64(args->lock_owner.id);
+ p = xdr_encode_hyper(p, args->lock_owner.id);
}
else {
RESERVE_SPACE(NFS4_STATEID_SIZE+4);
@@ -1084,12 +1080,12 @@ static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *ar
RESERVE_SPACE(52);
p = xdr_encode_int(p, OP_LOCKT);
p = xdr_encode_int(p, nfs4_lock_type(args->fl, 0));
- WRITE64(args->fl->fl_start);
- WRITE64(nfs4_lock_length(args->fl));
- WRITE64(args->lock_owner.clientid);
+ p = xdr_encode_hyper(p, args->fl->fl_start);
+ p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
+ p = xdr_encode_hyper(p, args->lock_owner.clientid);
p = xdr_encode_int(p, 16);
WRITEMEM("lock id:", 8);
- WRITE64(args->lock_owner.id);
+ p = xdr_encode_hyper(p, args->lock_owner.id);
hdr->nops++;
hdr->replen += decode_lockt_maxsz;
}
@@ -1103,8 +1099,8 @@ static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *ar
p = xdr_encode_int(p, nfs4_lock_type(args->fl, 0));
p = xdr_encode_int(p, args->seqid->sequence->counter);
WRITEMEM(args->stateid->data, NFS4_STATEID_SIZE);
- WRITE64(args->fl->fl_start);
- WRITE64(nfs4_lock_length(args->fl));
+ p = xdr_encode_hyper(p, args->fl->fl_start);
+ p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
hdr->nops++;
hdr->replen += decode_locku_maxsz;
}
@@ -1155,10 +1151,10 @@ static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_opena
p = xdr_encode_int(p, arg->seqid->sequence->counter);
encode_share_access(xdr, arg->fmode);
RESERVE_SPACE(28);
- WRITE64(arg->clientid);
+ p = xdr_encode_hyper(p, arg->clientid);
p = xdr_encode_int(p, 16);
WRITEMEM("open id:", 8);
- WRITE64(arg->id);
+ p = xdr_encode_hyper(p, arg->id);
}
static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
@@ -1334,7 +1330,7 @@ static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args,
encode_stateid(xdr, args->context);
RESERVE_SPACE(12);
- WRITE64(args->offset);
+ p = xdr_encode_hyper(p, args->offset);
p = xdr_encode_int(p, args->count);
hdr->nops++;
hdr->replen += decode_read_maxsz;
@@ -1350,7 +1346,7 @@ static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg
RESERVE_SPACE(12+NFS4_VERIFIER_SIZE+20);
p = xdr_encode_int(p, OP_READDIR);
- WRITE64(readdir->cookie);
+ p = xdr_encode_hyper(p, readdir->cookie);
WRITEMEM(readdir->verifier.data, NFS4_VERIFIER_SIZE);
p = xdr_encode_int(p, readdir->count >> 1); /* We're not doing readdirplus */
p = xdr_encode_int(p, readdir->count);
@@ -1417,7 +1413,7 @@ static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client
RESERVE_SPACE(12);
p = xdr_encode_int(p, OP_RENEW);
- WRITE64(client_stateid->cl_clientid);
+ p = xdr_encode_hyper(p, client_stateid->cl_clientid);
hdr->nops++;
hdr->replen += decode_renew_maxsz;
}
@@ -1502,7 +1498,7 @@ static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_
RESERVE_SPACE(12 + NFS4_VERIFIER_SIZE);
p = xdr_encode_int(p, OP_SETCLIENTID_CONFIRM);
- WRITE64(client_state->cl_clientid);
+ p = xdr_encode_hyper(p, client_state->cl_clientid);
WRITEMEM(client_state->cl_confirm.data, NFS4_VERIFIER_SIZE);
hdr->nops++;
hdr->replen += decode_setclientid_confirm_maxsz;
@@ -1518,7 +1514,7 @@ static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *arg
encode_stateid(xdr, args->context);
RESERVE_SPACE(16);
- WRITE64(args->offset);
+ p = xdr_encode_hyper(p, args->offset);
p = xdr_encode_int(p, args->stable);
p = xdr_encode_int(p, args->count);
@@ -1574,7 +1570,7 @@ static void encode_create_session(struct xdr_stream *xdr,
p = xdr_encode_int(p, OP_CREATE_SESSION);
RESERVE_SPACE(8);
- WRITE64(clp->cl_ex_clid);
+ p = xdr_encode_hyper(p, clp->cl_ex_clid);
RESERVE_SPACE(8);
p = xdr_encode_int(p, clp->cl_seqid); /*Sequence id */
--
1.6.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH RFC 06/13] nfs: nfs4xdr: get rid of WRITEMEM
2009-08-12 15:15 [PATCH RFC 0/13] xdr macros cleanup Benny Halevy
` (4 preceding siblings ...)
2009-08-12 15:22 ` [PATCH RFC 05/13] nfs: nfs4xdr: get rid of WRITE64 Benny Halevy
@ 2009-08-12 15:22 ` Benny Halevy
2009-08-12 15:22 ` [PATCH RFC 07/13] nfs: nfs4xdr: merge xdr_encode_int+xdr_encode_opaque_fixed into xdr_encode_opaque Benny Halevy
` (6 subsequent siblings)
12 siblings, 0 replies; 20+ messages in thread
From: Benny Halevy @ 2009-08-12 15:22 UTC (permalink / raw)
To: Trond Myklebust; +Cc: linux-nfs
use xdr_encode_opaque_fixed instead.
Signed-off-by: Benny Halevy <bhalevy@panasas.com>
---
fs/nfs/nfs4xdr.c | 68 +++++++++++++++++++++++++----------------------------
1 files changed, 32 insertions(+), 36 deletions(-)
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index fce7de3..2096573 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -712,10 +712,6 @@ struct compound_hdr {
* task to translate them into Linux-specific versions which are more
* consistent with the style used in NFSv2/v3...
*/
-#define WRITEMEM(ptr,nbytes) do { \
- p = xdr_encode_opaque_fixed(p, ptr, nbytes); \
-} while (0)
-
#define RESERVE_SPACE(nbytes) do { \
p = xdr_reserve_space(xdr, nbytes); \
BUG_ON(!p); \
@@ -746,7 +742,7 @@ static void encode_compound_hdr(struct xdr_stream *xdr,
BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
p = xdr_encode_int(p, hdr->taglen);
- WRITEMEM(hdr->tag, hdr->taglen);
+ p = xdr_encode_opaque_fixed(p, hdr->tag, hdr->taglen);
p = xdr_encode_int(p, hdr->minorversion);
hdr->nops_p = p;
p = xdr_encode_int(p, hdr->nops);
@@ -845,12 +841,12 @@ static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const
if (iap->ia_valid & ATTR_UID) {
bmval1 |= FATTR4_WORD1_OWNER;
p = xdr_encode_int(p, owner_namelen);
- WRITEMEM(owner_name, owner_namelen);
+ p = xdr_encode_opaque_fixed(p, owner_name, owner_namelen);
}
if (iap->ia_valid & ATTR_GID) {
bmval1 |= FATTR4_WORD1_OWNER_GROUP;
p = xdr_encode_int(p, owner_grouplen);
- WRITEMEM(owner_group, owner_grouplen);
+ p = xdr_encode_opaque_fixed(p, owner_group, owner_grouplen);
}
if (iap->ia_valid & ATTR_ATIME_SET) {
bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
@@ -909,7 +905,7 @@ static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg
RESERVE_SPACE(8+NFS4_STATEID_SIZE);
p = xdr_encode_int(p, OP_CLOSE);
p = xdr_encode_int(p, arg->seqid->sequence->counter);
- WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
+ p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
hdr->nops++;
hdr->replen += decode_close_maxsz;
}
@@ -953,7 +949,7 @@ static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *
RESERVE_SPACE(4 + create->name->len);
p = xdr_encode_int(p, create->name->len);
- WRITEMEM(create->name->name, create->name->len);
+ p = xdr_encode_opaque_fixed(p, create->name->name, create->name->len);
hdr->nops++;
hdr->replen += decode_create_maxsz;
@@ -1020,7 +1016,7 @@ static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct
RESERVE_SPACE(8 + name->len);
p = xdr_encode_int(p, OP_LINK);
p = xdr_encode_int(p, name->len);
- WRITEMEM(name->name, name->len);
+ p = xdr_encode_opaque_fixed(p, name->name, name->len);
hdr->nops++;
hdr->replen += decode_link_maxsz;
}
@@ -1057,16 +1053,16 @@ static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args
if (args->new_lock_owner){
RESERVE_SPACE(4+NFS4_STATEID_SIZE+32);
p = xdr_encode_int(p, args->open_seqid->sequence->counter);
- WRITEMEM(args->open_stateid->data, NFS4_STATEID_SIZE);
+ p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
p = xdr_encode_int(p, args->lock_seqid->sequence->counter);
p = xdr_encode_hyper(p, args->lock_owner.clientid);
p = xdr_encode_int(p, 16);
- WRITEMEM("lock id:", 8);
+ p = xdr_encode_opaque_fixed(p, "lock id:", 8);
p = xdr_encode_hyper(p, args->lock_owner.id);
}
else {
RESERVE_SPACE(NFS4_STATEID_SIZE+4);
- WRITEMEM(args->lock_stateid->data, NFS4_STATEID_SIZE);
+ p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
p = xdr_encode_int(p, args->lock_seqid->sequence->counter);
}
hdr->nops++;
@@ -1084,7 +1080,7 @@ static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *ar
p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
p = xdr_encode_hyper(p, args->lock_owner.clientid);
p = xdr_encode_int(p, 16);
- WRITEMEM("lock id:", 8);
+ p = xdr_encode_opaque_fixed(p, "lock id:", 8);
p = xdr_encode_hyper(p, args->lock_owner.id);
hdr->nops++;
hdr->replen += decode_lockt_maxsz;
@@ -1098,7 +1094,7 @@ static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *ar
p = xdr_encode_int(p, OP_LOCKU);
p = xdr_encode_int(p, nfs4_lock_type(args->fl, 0));
p = xdr_encode_int(p, args->seqid->sequence->counter);
- WRITEMEM(args->stateid->data, NFS4_STATEID_SIZE);
+ p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
p = xdr_encode_hyper(p, args->fl->fl_start);
p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
hdr->nops++;
@@ -1113,7 +1109,7 @@ static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struc
RESERVE_SPACE(8 + len);
p = xdr_encode_int(p, OP_LOOKUP);
p = xdr_encode_int(p, len);
- WRITEMEM(name->name, len);
+ p = xdr_encode_opaque_fixed(p, name->name, len);
hdr->nops++;
hdr->replen += decode_lookup_maxsz;
}
@@ -1153,7 +1149,7 @@ static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_opena
RESERVE_SPACE(28);
p = xdr_encode_hyper(p, arg->clientid);
p = xdr_encode_int(p, 16);
- WRITEMEM("open id:", 8);
+ p = xdr_encode_opaque_fixed(p, "open id:", 8);
p = xdr_encode_hyper(p, arg->id);
}
@@ -1233,7 +1229,7 @@ static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struc
RESERVE_SPACE(4+NFS4_STATEID_SIZE);
p = xdr_encode_int(p, NFS4_OPEN_CLAIM_DELEGATE_CUR);
- WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
+ p = xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
encode_string(xdr, name->len, name->name);
}
@@ -1264,7 +1260,7 @@ static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_co
RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
p = xdr_encode_int(p, OP_OPEN_CONFIRM);
- WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
+ p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
p = xdr_encode_int(p, arg->seqid->sequence->counter);
hdr->nops++;
hdr->replen += decode_open_confirm_maxsz;
@@ -1276,7 +1272,7 @@ static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_close
RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
p = xdr_encode_int(p, OP_OPEN_DOWNGRADE);
- WRITEMEM(arg->stateid->data, NFS4_STATEID_SIZE);
+ p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
p = xdr_encode_int(p, arg->seqid->sequence->counter);
encode_share_access(xdr, arg->fmode);
hdr->nops++;
@@ -1292,7 +1288,7 @@ encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hd
RESERVE_SPACE(8 + len);
p = xdr_encode_int(p, OP_PUTFH);
p = xdr_encode_int(p, len);
- WRITEMEM(fh->data, len);
+ p = xdr_encode_opaque_fixed(p, fh->data, len);
hdr->nops++;
hdr->replen += decode_putfh_maxsz;
}
@@ -1315,9 +1311,9 @@ static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context
RESERVE_SPACE(NFS4_STATEID_SIZE);
if (ctx->state != NULL) {
nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
- WRITEMEM(stateid.data, NFS4_STATEID_SIZE);
+ p = xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
} else
- WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
+ p = xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
}
static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
@@ -1347,7 +1343,7 @@ static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg
RESERVE_SPACE(12+NFS4_VERIFIER_SIZE+20);
p = xdr_encode_int(p, OP_READDIR);
p = xdr_encode_hyper(p, readdir->cookie);
- WRITEMEM(readdir->verifier.data, NFS4_VERIFIER_SIZE);
+ p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
p = xdr_encode_int(p, readdir->count >> 1); /* We're not doing readdirplus */
p = xdr_encode_int(p, readdir->count);
p = xdr_encode_int(p, 2);
@@ -1386,7 +1382,7 @@ static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struc
RESERVE_SPACE(8 + name->len);
p = xdr_encode_int(p, OP_REMOVE);
p = xdr_encode_int(p, name->len);
- WRITEMEM(name->name, name->len);
+ p = xdr_encode_opaque_fixed(p, name->name, name->len);
hdr->nops++;
hdr->replen += decode_remove_maxsz;
}
@@ -1398,11 +1394,11 @@ static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, co
RESERVE_SPACE(8 + oldname->len);
p = xdr_encode_int(p, OP_RENAME);
p = xdr_encode_int(p, oldname->len);
- WRITEMEM(oldname->name, oldname->len);
+ p = xdr_encode_opaque_fixed(p, oldname->name, oldname->len);
RESERVE_SPACE(4 + newname->len);
p = xdr_encode_int(p, newname->len);
- WRITEMEM(newname->name, newname->len);
+ p = xdr_encode_opaque_fixed(p, newname->name, newname->len);
hdr->nops++;
hdr->replen += decode_rename_maxsz;
}
@@ -1436,7 +1432,7 @@ encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compoun
RESERVE_SPACE(4+NFS4_STATEID_SIZE);
p = xdr_encode_int(p, OP_SETATTR);
- WRITEMEM(zero_stateid.data, NFS4_STATEID_SIZE);
+ p = xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
RESERVE_SPACE(2*4);
p = xdr_encode_int(p, 1);
p = xdr_encode_int(p, FATTR4_WORD0_ACL);
@@ -1467,7 +1463,7 @@ static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs
RESERVE_SPACE(4+NFS4_STATEID_SIZE);
p = xdr_encode_int(p, OP_SETATTR);
- WRITEMEM(arg->stateid.data, NFS4_STATEID_SIZE);
+ p = xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
hdr->nops++;
hdr->replen += decode_setattr_maxsz;
encode_attrs(xdr, arg->iap, server);
@@ -1479,7 +1475,7 @@ static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclie
RESERVE_SPACE(4 + NFS4_VERIFIER_SIZE);
p = xdr_encode_int(p, OP_SETCLIENTID);
- WRITEMEM(setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
+ p = xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
RESERVE_SPACE(4);
@@ -1499,7 +1495,7 @@ static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_
RESERVE_SPACE(12 + NFS4_VERIFIER_SIZE);
p = xdr_encode_int(p, OP_SETCLIENTID_CONFIRM);
p = xdr_encode_hyper(p, client_state->cl_clientid);
- WRITEMEM(client_state->cl_confirm.data, NFS4_VERIFIER_SIZE);
+ p = xdr_encode_opaque_fixed(p, client_state->cl_confirm.data, NFS4_VERIFIER_SIZE);
hdr->nops++;
hdr->replen += decode_setclientid_confirm_maxsz;
}
@@ -1530,7 +1526,7 @@ static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *state
RESERVE_SPACE(4+NFS4_STATEID_SIZE);
p = xdr_encode_int(p, OP_DELEGRETURN);
- WRITEMEM(stateid->data, NFS4_STATEID_SIZE);
+ p = xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
hdr->nops++;
hdr->replen += decode_delegreturn_maxsz;
}
@@ -1545,7 +1541,7 @@ static void encode_exchange_id(struct xdr_stream *xdr,
RESERVE_SPACE(4 + sizeof(args->verifier->data));
p = xdr_encode_int(p, OP_EXCHANGE_ID);
- WRITEMEM(args->verifier->data, sizeof(args->verifier->data));
+ p = xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
encode_string(xdr, args->id_len, args->id);
@@ -1611,7 +1607,7 @@ static void encode_create_session(struct xdr_stream *xdr,
clp->cl_ipaddr);
RESERVE_SPACE(16 + len);
p = xdr_encode_int(p, len);
- WRITEMEM(machine_name, len);
+ p = xdr_encode_opaque_fixed(p, machine_name, len);
p = xdr_encode_int(p, 0); /* UID */
p = xdr_encode_int(p, 0); /* GID */
p = xdr_encode_int(p, 0); /* No more gids */
@@ -1626,7 +1622,7 @@ static void encode_destroy_session(struct xdr_stream *xdr,
__be32 *p;
RESERVE_SPACE(4 + NFS4_MAX_SESSIONID_LEN);
p = xdr_encode_int(p, OP_DESTROY_SESSION);
- WRITEMEM(session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
+ p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
hdr->nops++;
hdr->replen += decode_destroy_session_maxsz;
}
@@ -1666,7 +1662,7 @@ static void encode_sequence(struct xdr_stream *xdr,
slot->seq_nr, args->sa_slotid,
tp->highest_used_slotid, args->sa_cache_this);
RESERVE_SPACE(NFS4_MAX_SESSIONID_LEN + 16);
- WRITEMEM(session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
+ p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
p = xdr_encode_int(p, slot->seq_nr);
p = xdr_encode_int(p, args->sa_slotid);
p = xdr_encode_int(p, tp->highest_used_slotid);
--
1.6.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH RFC 07/13] nfs: nfs4xdr: merge xdr_encode_int+xdr_encode_opaque_fixed into xdr_encode_opaque
2009-08-12 15:15 [PATCH RFC 0/13] xdr macros cleanup Benny Halevy
` (5 preceding siblings ...)
2009-08-12 15:22 ` [PATCH RFC 06/13] nfs: nfs4xdr: get rid of WRITEMEM Benny Halevy
@ 2009-08-12 15:22 ` Benny Halevy
2009-08-12 15:22 ` [PATCH RFC 08/13] nfs: nfs4xdr: change RESERVE_SPACE macro into a static helper Benny Halevy
` (5 subsequent siblings)
12 siblings, 0 replies; 20+ messages in thread
From: Benny Halevy @ 2009-08-12 15:22 UTC (permalink / raw)
To: Trond Myklebust; +Cc: linux-nfs
Signed-off-by: Benny Halevy <bhalevy@panasas.com>
---
fs/nfs/nfs4xdr.c | 33 +++++++++++----------------------
1 files changed, 11 insertions(+), 22 deletions(-)
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index 2096573..d26c437 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -741,8 +741,7 @@ static void encode_compound_hdr(struct xdr_stream *xdr,
dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
- p = xdr_encode_int(p, hdr->taglen);
- p = xdr_encode_opaque_fixed(p, hdr->tag, hdr->taglen);
+ p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
p = xdr_encode_int(p, hdr->minorversion);
hdr->nops_p = p;
p = xdr_encode_int(p, hdr->nops);
@@ -840,13 +839,11 @@ static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const
}
if (iap->ia_valid & ATTR_UID) {
bmval1 |= FATTR4_WORD1_OWNER;
- p = xdr_encode_int(p, owner_namelen);
- p = xdr_encode_opaque_fixed(p, owner_name, owner_namelen);
+ p = xdr_encode_opaque(p, owner_name, owner_namelen);
}
if (iap->ia_valid & ATTR_GID) {
bmval1 |= FATTR4_WORD1_OWNER_GROUP;
- p = xdr_encode_int(p, owner_grouplen);
- p = xdr_encode_opaque_fixed(p, owner_group, owner_grouplen);
+ p = xdr_encode_opaque(p, owner_group, owner_grouplen);
}
if (iap->ia_valid & ATTR_ATIME_SET) {
bmval1 |= FATTR4_WORD1_TIME_ACCESS_SET;
@@ -948,8 +945,7 @@ static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *
}
RESERVE_SPACE(4 + create->name->len);
- p = xdr_encode_int(p, create->name->len);
- p = xdr_encode_opaque_fixed(p, create->name->name, create->name->len);
+ p = xdr_encode_opaque(p, create->name->name, create->name->len);
hdr->nops++;
hdr->replen += decode_create_maxsz;
@@ -1015,8 +1011,7 @@ static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct
RESERVE_SPACE(8 + name->len);
p = xdr_encode_int(p, OP_LINK);
- p = xdr_encode_int(p, name->len);
- p = xdr_encode_opaque_fixed(p, name->name, name->len);
+ p = xdr_encode_opaque(p, name->name, name->len);
hdr->nops++;
hdr->replen += decode_link_maxsz;
}
@@ -1108,8 +1103,7 @@ static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struc
RESERVE_SPACE(8 + len);
p = xdr_encode_int(p, OP_LOOKUP);
- p = xdr_encode_int(p, len);
- p = xdr_encode_opaque_fixed(p, name->name, len);
+ p = xdr_encode_opaque(p, name->name, len);
hdr->nops++;
hdr->replen += decode_lookup_maxsz;
}
@@ -1287,8 +1281,7 @@ encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hd
RESERVE_SPACE(8 + len);
p = xdr_encode_int(p, OP_PUTFH);
- p = xdr_encode_int(p, len);
- p = xdr_encode_opaque_fixed(p, fh->data, len);
+ p = xdr_encode_opaque(p, fh->data, len);
hdr->nops++;
hdr->replen += decode_putfh_maxsz;
}
@@ -1381,8 +1374,7 @@ static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struc
RESERVE_SPACE(8 + name->len);
p = xdr_encode_int(p, OP_REMOVE);
- p = xdr_encode_int(p, name->len);
- p = xdr_encode_opaque_fixed(p, name->name, name->len);
+ p = xdr_encode_opaque(p, name->name, name->len);
hdr->nops++;
hdr->replen += decode_remove_maxsz;
}
@@ -1393,12 +1385,10 @@ static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, co
RESERVE_SPACE(8 + oldname->len);
p = xdr_encode_int(p, OP_RENAME);
- p = xdr_encode_int(p, oldname->len);
- p = xdr_encode_opaque_fixed(p, oldname->name, oldname->len);
+ p = xdr_encode_opaque(p, oldname->name, oldname->len);
RESERVE_SPACE(4 + newname->len);
- p = xdr_encode_int(p, newname->len);
- p = xdr_encode_opaque_fixed(p, newname->name, newname->len);
+ p = xdr_encode_opaque(p, newname->name, newname->len);
hdr->nops++;
hdr->replen += decode_rename_maxsz;
}
@@ -1606,8 +1596,7 @@ static void encode_create_session(struct xdr_stream *xdr,
len = scnprintf(machine_name, sizeof(machine_name), "%s",
clp->cl_ipaddr);
RESERVE_SPACE(16 + len);
- p = xdr_encode_int(p, len);
- p = xdr_encode_opaque_fixed(p, machine_name, len);
+ p = xdr_encode_opaque(p, machine_name, len);
p = xdr_encode_int(p, 0); /* UID */
p = xdr_encode_int(p, 0); /* GID */
p = xdr_encode_int(p, 0); /* No more gids */
--
1.6.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH RFC 08/13] nfs: nfs4xdr: change RESERVE_SPACE macro into a static helper
2009-08-12 15:15 [PATCH RFC 0/13] xdr macros cleanup Benny Halevy
` (6 preceding siblings ...)
2009-08-12 15:22 ` [PATCH RFC 07/13] nfs: nfs4xdr: merge xdr_encode_int+xdr_encode_opaque_fixed into xdr_encode_opaque Benny Halevy
@ 2009-08-12 15:22 ` Benny Halevy
2009-08-12 15:22 ` [PATCH RFC 09/13] nfs: nfs4xdr: get rid of READ32 Benny Halevy
` (4 subsequent siblings)
12 siblings, 0 replies; 20+ messages in thread
From: Benny Halevy @ 2009-08-12 15:22 UTC (permalink / raw)
To: Trond Myklebust; +Cc: linux-nfs
In order to open code and expose the result pointer assignment.
Alternatively, we can open code the call to xdr_reserve_space
and do the BUG_ON an the error case at the call site.
Signed-off-by: Benny Halevy <bhalevy@panasas.com>
---
fs/nfs/nfs4xdr.c | 156 +++++++++++++++++++++++++----------------------------
1 files changed, 74 insertions(+), 82 deletions(-)
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index d26c437..7fac008 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -702,20 +702,12 @@ struct compound_hdr {
u32 minorversion;
};
-/*
- * START OF "GENERIC" ENCODE ROUTINES.
- * These may look a little ugly since they are imported from a "generic"
- * set of XDR encode/decode routines which are intended to be shared by
- * all of our NFSv4 implementations (OpenBSD, MacOS X...).
- *
- * If the pain of reading these is too great, it should be a straightforward
- * task to translate them into Linux-specific versions which are more
- * consistent with the style used in NFSv2/v3...
- */
-#define RESERVE_SPACE(nbytes) do { \
- p = xdr_reserve_space(xdr, nbytes); \
- BUG_ON(!p); \
-} while (0)
+static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
+{
+ __be32 *p = xdr_reserve_space(xdr, nbytes);
+ BUG_ON(!p);
+ return p;
+}
static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
{
@@ -740,7 +732,7 @@ static void encode_compound_hdr(struct xdr_stream *xdr,
dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
- RESERVE_SPACE(12+(XDR_QUADLEN(hdr->taglen)<<2));
+ p = reserve_space(xdr, 12+(XDR_QUADLEN(hdr->taglen)<<2));
p = xdr_encode_opaque(p, hdr->tag, hdr->taglen);
p = xdr_encode_int(p, hdr->minorversion);
hdr->nops_p = p;
@@ -819,7 +811,7 @@ static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const
len += 16;
else if (iap->ia_valid & ATTR_MTIME)
len += 4;
- RESERVE_SPACE(len);
+ p = reserve_space(xdr, len);
/*
* We write the bitmap length now, but leave the bitmap and the attribute
@@ -888,7 +880,7 @@ static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hd
{
__be32 *p;
- RESERVE_SPACE(8);
+ p = reserve_space(xdr, 8);
p = xdr_encode_int(p, OP_ACCESS);
p = xdr_encode_int(p, access);
hdr->nops++;
@@ -899,7 +891,7 @@ static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg
{
__be32 *p;
- RESERVE_SPACE(8+NFS4_STATEID_SIZE);
+ p = reserve_space(xdr, 8+NFS4_STATEID_SIZE);
p = xdr_encode_int(p, OP_CLOSE);
p = xdr_encode_int(p, arg->seqid->sequence->counter);
p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
@@ -911,7 +903,7 @@ static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *ar
{
__be32 *p;
- RESERVE_SPACE(16);
+ p = reserve_space(xdr, 16);
p = xdr_encode_int(p, OP_COMMIT);
p = xdr_encode_hyper(p, args->offset);
p = xdr_encode_int(p, args->count);
@@ -923,19 +915,19 @@ static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *
{
__be32 *p;
- RESERVE_SPACE(8);
+ p = reserve_space(xdr, 8);
p = xdr_encode_int(p, OP_CREATE);
p = xdr_encode_int(p, create->ftype);
switch (create->ftype) {
case NF4LNK:
- RESERVE_SPACE(4);
+ p = reserve_space(xdr, 4);
p = xdr_encode_int(p, create->u.symlink.len);
xdr_write_pages(xdr, create->u.symlink.pages, 0, create->u.symlink.len);
break;
case NF4BLK: case NF4CHR:
- RESERVE_SPACE(8);
+ p = reserve_space(xdr, 8);
p = xdr_encode_int(p, create->u.device.specdata1);
p = xdr_encode_int(p, create->u.device.specdata2);
break;
@@ -944,7 +936,7 @@ static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *
break;
}
- RESERVE_SPACE(4 + create->name->len);
+ p = reserve_space(xdr, 4 + create->name->len);
p = xdr_encode_opaque(p, create->name->name, create->name->len);
hdr->nops++;
hdr->replen += decode_create_maxsz;
@@ -956,7 +948,7 @@ static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct c
{
__be32 *p;
- RESERVE_SPACE(12);
+ p = reserve_space(xdr, 12);
p = xdr_encode_int(p, OP_GETATTR);
p = xdr_encode_int(p, 1);
p = xdr_encode_int(p, bitmap);
@@ -968,7 +960,7 @@ static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm
{
__be32 *p;
- RESERVE_SPACE(16);
+ p = reserve_space(xdr, 16);
p = xdr_encode_int(p, OP_GETATTR);
p = xdr_encode_int(p, 2);
p = xdr_encode_int(p, bm0);
@@ -999,7 +991,7 @@ static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
{
__be32 *p;
- RESERVE_SPACE(4);
+ p = reserve_space(xdr, 4);
p = xdr_encode_int(p, OP_GETFH);
hdr->nops++;
hdr->replen += decode_getfh_maxsz;
@@ -1009,7 +1001,7 @@ static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct
{
__be32 *p;
- RESERVE_SPACE(8 + name->len);
+ p = reserve_space(xdr, 8 + name->len);
p = xdr_encode_int(p, OP_LINK);
p = xdr_encode_opaque(p, name->name, name->len);
hdr->nops++;
@@ -1038,7 +1030,7 @@ static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args
{
__be32 *p;
- RESERVE_SPACE(32);
+ p = reserve_space(xdr, 32);
p = xdr_encode_int(p, OP_LOCK);
p = xdr_encode_int(p, nfs4_lock_type(args->fl, args->block));
p = xdr_encode_int(p, args->reclaim);
@@ -1046,7 +1038,7 @@ 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 = xdr_encode_int(p, args->new_lock_owner);
if (args->new_lock_owner){
- RESERVE_SPACE(4+NFS4_STATEID_SIZE+32);
+ p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+32);
p = xdr_encode_int(p, args->open_seqid->sequence->counter);
p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE);
p = xdr_encode_int(p, args->lock_seqid->sequence->counter);
@@ -1056,7 +1048,7 @@ static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args
p = xdr_encode_hyper(p, args->lock_owner.id);
}
else {
- RESERVE_SPACE(NFS4_STATEID_SIZE+4);
+ p = reserve_space(xdr, NFS4_STATEID_SIZE+4);
p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE);
p = xdr_encode_int(p, args->lock_seqid->sequence->counter);
}
@@ -1068,7 +1060,7 @@ static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *ar
{
__be32 *p;
- RESERVE_SPACE(52);
+ p = reserve_space(xdr, 52);
p = xdr_encode_int(p, OP_LOCKT);
p = xdr_encode_int(p, nfs4_lock_type(args->fl, 0));
p = xdr_encode_hyper(p, args->fl->fl_start);
@@ -1085,7 +1077,7 @@ static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *ar
{
__be32 *p;
- RESERVE_SPACE(12+NFS4_STATEID_SIZE+16);
+ p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16);
p = xdr_encode_int(p, OP_LOCKU);
p = xdr_encode_int(p, nfs4_lock_type(args->fl, 0));
p = xdr_encode_int(p, args->seqid->sequence->counter);
@@ -1101,7 +1093,7 @@ static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struc
int len = name->len;
__be32 *p;
- RESERVE_SPACE(8 + len);
+ p = reserve_space(xdr, 8 + len);
p = xdr_encode_int(p, OP_LOOKUP);
p = xdr_encode_opaque(p, name->name, len);
hdr->nops++;
@@ -1112,7 +1104,7 @@ static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
{
__be32 *p;
- RESERVE_SPACE(8);
+ p = reserve_space(xdr, 8);
switch (fmode & (FMODE_READ|FMODE_WRITE)) {
case FMODE_READ:
p = xdr_encode_int(p, NFS4_SHARE_ACCESS_READ);
@@ -1136,11 +1128,11 @@ 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
*/
- RESERVE_SPACE(8);
+ p = reserve_space(xdr, 8);
p = xdr_encode_int(p, OP_OPEN);
p = xdr_encode_int(p, arg->seqid->sequence->counter);
encode_share_access(xdr, arg->fmode);
- RESERVE_SPACE(28);
+ p = reserve_space(xdr, 28);
p = xdr_encode_hyper(p, arg->clientid);
p = xdr_encode_int(p, 16);
p = xdr_encode_opaque_fixed(p, "open id:", 8);
@@ -1151,7 +1143,7 @@ static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_op
{
__be32 *p;
- RESERVE_SPACE(4);
+ p = reserve_space(xdr, 4);
switch(arg->open_flags & O_EXCL) {
case 0:
p = xdr_encode_int(p, NFS4_CREATE_UNCHECKED);
@@ -1167,7 +1159,7 @@ static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *a
{
__be32 *p;
- RESERVE_SPACE(4);
+ p = reserve_space(xdr, 4);
switch (arg->open_flags & O_CREAT) {
case 0:
p = xdr_encode_int(p, NFS4_OPEN_NOCREATE);
@@ -1183,7 +1175,7 @@ static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delega
{
__be32 *p;
- RESERVE_SPACE(4);
+ p = reserve_space(xdr, 4);
switch (delegation_type) {
case 0:
p = xdr_encode_int(p, NFS4_OPEN_DELEGATE_NONE);
@@ -1203,7 +1195,7 @@ static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *
{
__be32 *p;
- RESERVE_SPACE(4);
+ p = reserve_space(xdr, 4);
p = xdr_encode_int(p, NFS4_OPEN_CLAIM_NULL);
encode_string(xdr, name->len, name->name);
}
@@ -1212,7 +1204,7 @@ static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
{
__be32 *p;
- RESERVE_SPACE(4);
+ p = reserve_space(xdr, 4);
p = xdr_encode_int(p, NFS4_OPEN_CLAIM_PREVIOUS);
encode_delegation_type(xdr, type);
}
@@ -1221,7 +1213,7 @@ static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struc
{
__be32 *p;
- RESERVE_SPACE(4+NFS4_STATEID_SIZE);
+ p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
p = xdr_encode_int(p, NFS4_OPEN_CLAIM_DELEGATE_CUR);
p = xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
encode_string(xdr, name->len, name->name);
@@ -1252,7 +1244,7 @@ static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_co
{
__be32 *p;
- RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
+ p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
p = xdr_encode_int(p, OP_OPEN_CONFIRM);
p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
p = xdr_encode_int(p, arg->seqid->sequence->counter);
@@ -1264,7 +1256,7 @@ static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_close
{
__be32 *p;
- RESERVE_SPACE(4+NFS4_STATEID_SIZE+4);
+ p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4);
p = xdr_encode_int(p, OP_OPEN_DOWNGRADE);
p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
p = xdr_encode_int(p, arg->seqid->sequence->counter);
@@ -1279,7 +1271,7 @@ encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hd
int len = fh->size;
__be32 *p;
- RESERVE_SPACE(8 + len);
+ p = reserve_space(xdr, 8 + len);
p = xdr_encode_int(p, OP_PUTFH);
p = xdr_encode_opaque(p, fh->data, len);
hdr->nops++;
@@ -1290,7 +1282,7 @@ static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
{
__be32 *p;
- RESERVE_SPACE(4);
+ p = reserve_space(xdr, 4);
p = xdr_encode_int(p, OP_PUTROOTFH);
hdr->nops++;
hdr->replen += decode_putrootfh_maxsz;
@@ -1301,7 +1293,7 @@ static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context
nfs4_stateid stateid;
__be32 *p;
- RESERVE_SPACE(NFS4_STATEID_SIZE);
+ p = reserve_space(xdr, NFS4_STATEID_SIZE);
if (ctx->state != NULL) {
nfs4_copy_stateid(&stateid, ctx->state, ctx->lockowner);
p = xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE);
@@ -1313,12 +1305,12 @@ static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args,
{
__be32 *p;
- RESERVE_SPACE(4);
+ p = reserve_space(xdr, 4);
p = xdr_encode_int(p, OP_READ);
encode_stateid(xdr, args->context);
- RESERVE_SPACE(12);
+ p = reserve_space(xdr, 12);
p = xdr_encode_hyper(p, args->offset);
p = xdr_encode_int(p, args->count);
hdr->nops++;
@@ -1333,7 +1325,7 @@ static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg
};
__be32 *p;
- RESERVE_SPACE(12+NFS4_VERIFIER_SIZE+20);
+ p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20);
p = xdr_encode_int(p, OP_READDIR);
p = xdr_encode_hyper(p, readdir->cookie);
p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE);
@@ -1362,7 +1354,7 @@ static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *
{
__be32 *p;
- RESERVE_SPACE(4);
+ p = reserve_space(xdr, 4);
p = xdr_encode_int(p, OP_READLINK);
hdr->nops++;
hdr->replen += decode_readlink_maxsz;
@@ -1372,7 +1364,7 @@ static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struc
{
__be32 *p;
- RESERVE_SPACE(8 + name->len);
+ p = reserve_space(xdr, 8 + name->len);
p = xdr_encode_int(p, OP_REMOVE);
p = xdr_encode_opaque(p, name->name, name->len);
hdr->nops++;
@@ -1383,11 +1375,11 @@ static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, co
{
__be32 *p;
- RESERVE_SPACE(8 + oldname->len);
+ p = reserve_space(xdr, 8 + oldname->len);
p = xdr_encode_int(p, OP_RENAME);
p = xdr_encode_opaque(p, oldname->name, oldname->len);
- RESERVE_SPACE(4 + newname->len);
+ p = reserve_space(xdr, 4 + newname->len);
p = xdr_encode_opaque(p, newname->name, newname->len);
hdr->nops++;
hdr->replen += decode_rename_maxsz;
@@ -1397,7 +1389,7 @@ static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client
{
__be32 *p;
- RESERVE_SPACE(12);
+ p = reserve_space(xdr, 12);
p = xdr_encode_int(p, OP_RENEW);
p = xdr_encode_hyper(p, client_stateid->cl_clientid);
hdr->nops++;
@@ -1409,7 +1401,7 @@ encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
{
__be32 *p;
- RESERVE_SPACE(4);
+ p = reserve_space(xdr, 4);
p = xdr_encode_int(p, OP_RESTOREFH);
hdr->nops++;
hdr->replen += decode_restorefh_maxsz;
@@ -1420,15 +1412,15 @@ encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compoun
{
__be32 *p;
- RESERVE_SPACE(4+NFS4_STATEID_SIZE);
+ p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
p = xdr_encode_int(p, OP_SETATTR);
p = xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
- RESERVE_SPACE(2*4);
+ p = reserve_space(xdr, 2*4);
p = xdr_encode_int(p, 1);
p = xdr_encode_int(p, FATTR4_WORD0_ACL);
if (arg->acl_len % 4)
return -EINVAL;
- RESERVE_SPACE(4);
+ p = reserve_space(xdr, 4);
p = xdr_encode_int(p, arg->acl_len);
xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
hdr->nops++;
@@ -1441,7 +1433,7 @@ encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
{
__be32 *p;
- RESERVE_SPACE(4);
+ p = reserve_space(xdr, 4);
p = xdr_encode_int(p, OP_SAVEFH);
hdr->nops++;
hdr->replen += decode_savefh_maxsz;
@@ -1451,7 +1443,7 @@ static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs
{
__be32 *p;
- RESERVE_SPACE(4+NFS4_STATEID_SIZE);
+ p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
p = xdr_encode_int(p, OP_SETATTR);
p = xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
hdr->nops++;
@@ -1463,16 +1455,16 @@ static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclie
{
__be32 *p;
- RESERVE_SPACE(4 + NFS4_VERIFIER_SIZE);
+ p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE);
p = xdr_encode_int(p, OP_SETCLIENTID);
p = xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
- RESERVE_SPACE(4);
+ p = reserve_space(xdr, 4);
p = xdr_encode_int(p, setclientid->sc_prog);
encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
- RESERVE_SPACE(4);
+ p = reserve_space(xdr, 4);
p = xdr_encode_int(p, setclientid->sc_cb_ident);
hdr->nops++;
hdr->replen += decode_setclientid_maxsz;
@@ -1482,7 +1474,7 @@ static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_
{
__be32 *p;
- RESERVE_SPACE(12 + NFS4_VERIFIER_SIZE);
+ p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
p = xdr_encode_int(p, OP_SETCLIENTID_CONFIRM);
p = xdr_encode_hyper(p, client_state->cl_clientid);
p = xdr_encode_opaque_fixed(p, client_state->cl_confirm.data, NFS4_VERIFIER_SIZE);
@@ -1494,12 +1486,12 @@ static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *arg
{
__be32 *p;
- RESERVE_SPACE(4);
+ p = reserve_space(xdr, 4);
p = xdr_encode_int(p, OP_WRITE);
encode_stateid(xdr, args->context);
- RESERVE_SPACE(16);
+ p = reserve_space(xdr, 16);
p = xdr_encode_hyper(p, args->offset);
p = xdr_encode_int(p, args->stable);
p = xdr_encode_int(p, args->count);
@@ -1513,7 +1505,7 @@ static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *state
{
__be32 *p;
- RESERVE_SPACE(4+NFS4_STATEID_SIZE);
+ p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
p = xdr_encode_int(p, OP_DELEGRETURN);
p = xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
@@ -1529,13 +1521,13 @@ static void encode_exchange_id(struct xdr_stream *xdr,
{
__be32 *p;
- RESERVE_SPACE(4 + sizeof(args->verifier->data));
+ p = reserve_space(xdr, 4 + sizeof(args->verifier->data));
p = xdr_encode_int(p, OP_EXCHANGE_ID);
p = xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
encode_string(xdr, args->id_len, args->id);
- RESERVE_SPACE(12);
+ p = reserve_space(xdr, 12);
p = xdr_encode_int(p, args->flags);
p = xdr_encode_int(p, 0); /* zero length state_protect4_a */
p = xdr_encode_int(p, 0); /* zero length implementation id array */
@@ -1552,17 +1544,17 @@ static void encode_create_session(struct xdr_stream *xdr,
uint32_t len;
struct nfs_client *clp = args->client;
- RESERVE_SPACE(4);
+ p = reserve_space(xdr, 4);
p = xdr_encode_int(p, OP_CREATE_SESSION);
- RESERVE_SPACE(8);
+ p = reserve_space(xdr, 8);
p = xdr_encode_hyper(p, clp->cl_ex_clid);
- RESERVE_SPACE(8);
+ p = reserve_space(xdr, 8);
p = xdr_encode_int(p, clp->cl_seqid); /*Sequence id */
p = xdr_encode_int(p, args->flags); /*flags */
- RESERVE_SPACE(2*28); /* 2 channel_attrs */
+ p = reserve_space(xdr, 2*28); /* 2 channel_attrs */
/* Fore Channel */
p = xdr_encode_int(p, args->fc_attrs.headerpadsz); /* header padding size */
p = xdr_encode_int(p, args->fc_attrs.max_rqst_sz); /* max req size */
@@ -1581,21 +1573,21 @@ static void encode_create_session(struct xdr_stream *xdr,
p = xdr_encode_int(p, args->bc_attrs.max_reqs); /* max requests */
p = xdr_encode_int(p, 0); /* rdmachannel_attrs */
- RESERVE_SPACE(4);
+ p = reserve_space(xdr, 4);
p = xdr_encode_int(p, args->cb_program); /* cb_program */
- RESERVE_SPACE(4); /* # of security flavors */
+ p = reserve_space(xdr, 4); /* # of security flavors */
p = xdr_encode_int(p, 1);
- RESERVE_SPACE(4);
+ p = reserve_space(xdr, 4);
p = xdr_encode_int(p, RPC_AUTH_UNIX); /* auth_sys */
/* authsys_parms rfc1831 */
- RESERVE_SPACE(4);
+ p = reserve_space(xdr, 4);
p = xdr_encode_int(p, (u32)clp->cl_boot_time.tv_nsec); /* stamp */
len = scnprintf(machine_name, sizeof(machine_name), "%s",
clp->cl_ipaddr);
- RESERVE_SPACE(16 + len);
+ p = reserve_space(xdr, 16 + len);
p = xdr_encode_opaque(p, machine_name, len);
p = xdr_encode_int(p, 0); /* UID */
p = xdr_encode_int(p, 0); /* GID */
@@ -1609,7 +1601,7 @@ static void encode_destroy_session(struct xdr_stream *xdr,
struct compound_hdr *hdr)
{
__be32 *p;
- RESERVE_SPACE(4 + NFS4_MAX_SESSIONID_LEN);
+ p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN);
p = xdr_encode_int(p, OP_DESTROY_SESSION);
p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
hdr->nops++;
@@ -1635,7 +1627,7 @@ static void encode_sequence(struct xdr_stream *xdr,
WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
slot = tp->slots + args->sa_slotid;
- RESERVE_SPACE(4);
+ p = reserve_space(xdr, 4);
p = xdr_encode_int(p, OP_SEQUENCE);
/*
@@ -1650,7 +1642,7 @@ static void encode_sequence(struct xdr_stream *xdr,
((u32 *)session->sess_id.data)[3],
slot->seq_nr, args->sa_slotid,
tp->highest_used_slotid, args->sa_cache_this);
- RESERVE_SPACE(NFS4_MAX_SESSIONID_LEN + 16);
+ p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
p = xdr_encode_int(p, slot->seq_nr);
p = xdr_encode_int(p, args->sa_slotid);
--
1.6.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH RFC 09/13] nfs: nfs4xdr: get rid of READ32
2009-08-12 15:15 [PATCH RFC 0/13] xdr macros cleanup Benny Halevy
` (7 preceding siblings ...)
2009-08-12 15:22 ` [PATCH RFC 08/13] nfs: nfs4xdr: change RESERVE_SPACE macro into a static helper Benny Halevy
@ 2009-08-12 15:22 ` Benny Halevy
2009-08-12 15:22 ` [PATCH RFC 10/13] nfs: nfs4xdr: get rid of READ64 Benny Halevy
` (3 subsequent siblings)
12 siblings, 0 replies; 20+ messages in thread
From: Benny Halevy @ 2009-08-12 15:22 UTC (permalink / raw)
To: Trond Myklebust; +Cc: linux-nfs
use xdr_decode_int instead.
Signed-off-by: Benny Halevy <bhalevy@panasas.com>
---
fs/nfs/nfs4xdr.c | 145 +++++++++++++++++++++++++++---------------------------
1 files changed, 72 insertions(+), 73 deletions(-)
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index 7fac008..5c2b905 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -2448,7 +2448,6 @@ static int nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, uint32_t *p,
* task to translate them into Linux-specific versions which are more
* consistent with the style used in NFSv2/v3...
*/
-#define READ32(x) (x) = ntohl(*p++)
#define READ64(x) do { \
(x) = (u64)ntohl(*p++) << 32; \
(x) |= ntohl(*p++); \
@@ -2479,7 +2478,7 @@ static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char
__be32 *p;
READ_BUF(4);
- READ32(*len);
+ p = xdr_decode_int(p, len);
READ_BUF(*len);
*string = (char *)p;
return 0;
@@ -2490,13 +2489,13 @@ static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
__be32 *p;
READ_BUF(8);
- READ32(hdr->status);
- READ32(hdr->taglen);
+ p = xdr_decode_int(p, &hdr->status);
+ p = xdr_decode_int(p, &hdr->taglen);
READ_BUF(hdr->taglen + 4);
hdr->tag = (char *)p;
p += XDR_QUADLEN(hdr->taglen);
- READ32(hdr->nops);
+ p = xdr_decode_int(p, &hdr->nops);
if (unlikely(hdr->nops < 1))
return nfs4_stat_to_errno(hdr->status);
return 0;
@@ -2509,14 +2508,14 @@ static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
int32_t nfserr;
READ_BUF(8);
- READ32(opnum);
+ p = xdr_decode_int(p, &opnum);
if (opnum != expected) {
dprintk("nfs: Server returned operation"
" %d but we issued a request for %d\n",
opnum, expected);
return -EIO;
}
- READ32(nfserr);
+ p = xdr_decode_int(p, &nfserr);
if (nfserr != NFS_OK)
return nfs4_stat_to_errno(nfserr);
return 0;
@@ -2539,14 +2538,14 @@ static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
__be32 *p;
READ_BUF(4);
- READ32(bmlen);
+ p = xdr_decode_int(p, &bmlen);
bitmap[0] = bitmap[1] = 0;
READ_BUF((bmlen << 2));
if (bmlen > 0) {
- READ32(bitmap[0]);
+ p = xdr_decode_int(p, &bitmap[0]);
if (bmlen > 1)
- READ32(bitmap[1]);
+ p = xdr_decode_int(p, &bitmap[1]);
}
return 0;
}
@@ -2556,7 +2555,7 @@ static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen,
__be32 *p;
READ_BUF(4);
- READ32(*attrlen);
+ p = xdr_decode_int(p, attrlen);
*savep = xdr->p;
return 0;
}
@@ -2582,7 +2581,7 @@ static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *
return -EIO;
if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
READ_BUF(4);
- READ32(*type);
+ p = xdr_decode_int(p, type);
if (*type < NF4REG || *type > NF4NAMEDATTR) {
dprintk("%s: bad type %d\n", __func__, *type);
return -EIO;
@@ -2640,7 +2639,7 @@ static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, ui
return -EIO;
if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
READ_BUF(4);
- READ32(*res);
+ p = xdr_decode_int(p, res);
bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
}
dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
@@ -2656,7 +2655,7 @@ static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap,
return -EIO;
if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
READ_BUF(4);
- READ32(*res);
+ p = xdr_decode_int(p, res);
bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
}
dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
@@ -2694,7 +2693,7 @@ static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint
return -EIO;
if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
READ_BUF(4);
- READ32(*res);
+ p = xdr_decode_int(p, res);
bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
}
dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
@@ -2710,7 +2709,7 @@ static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint
return -EIO;
if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
READ_BUF(4);
- READ32(*res);
+ p = xdr_decode_int(p, res);
bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
}
dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
@@ -2811,7 +2810,7 @@ static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
int status = 0;
READ_BUF(4);
- READ32(n);
+ p = xdr_decode_int(p, &n);
if (n == 0)
goto root_path;
dprintk("path ");
@@ -2863,7 +2862,7 @@ static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, st
if (unlikely(status != 0))
goto out;
READ_BUF(4);
- READ32(n);
+ p = xdr_decode_int(p, &n);
if (n <= 0)
goto out_eio;
res->nlocations = 0;
@@ -2872,7 +2871,7 @@ static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, st
struct nfs4_fs_location *loc = &res->locations[res->nlocations];
READ_BUF(4);
- READ32(m);
+ p = xdr_decode_int(p, &m);
loc->nservers = 0;
dprintk("%s: servers ", __func__);
@@ -2943,7 +2942,7 @@ static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_
return -EIO;
if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
READ_BUF(4);
- READ32(*maxlink);
+ p = xdr_decode_int(p, maxlink);
bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
}
dprintk("%s: maxlink=%u\n", __func__, *maxlink);
@@ -2960,7 +2959,7 @@ static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_
return -EIO;
if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
READ_BUF(4);
- READ32(*maxname);
+ p = xdr_decode_int(p, maxname);
bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
}
dprintk("%s: maxname=%u\n", __func__, *maxname);
@@ -3020,7 +3019,7 @@ static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *m
return -EIO;
if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
READ_BUF(4);
- READ32(tmp);
+ p = xdr_decode_int(p, &tmp);
*mode = tmp & ~S_IFMT;
bitmap[1] &= ~FATTR4_WORD1_MODE;
ret = NFS_ATTR_FATTR_MODE;
@@ -3039,7 +3038,7 @@ static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t
return -EIO;
if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
READ_BUF(4);
- READ32(*nlink);
+ p = xdr_decode_int(p, nlink);
bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
ret = NFS_ATTR_FATTR_NLINK;
}
@@ -3058,7 +3057,7 @@ static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nf
return -EIO;
if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
READ_BUF(4);
- READ32(len);
+ p = xdr_decode_int(p, &len);
READ_BUF(len);
if (len < XDR_MAX_NETOBJ) {
if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
@@ -3086,7 +3085,7 @@ static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nf
return -EIO;
if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
READ_BUF(4);
- READ32(len);
+ p = xdr_decode_int(p, &len);
READ_BUF(len);
if (len < XDR_MAX_NETOBJ) {
if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
@@ -3116,8 +3115,8 @@ static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rde
dev_t tmp;
READ_BUF(8);
- READ32(major);
- READ32(minor);
+ p = xdr_decode_int(p, &major);
+ p = xdr_decode_int(p, &minor);
tmp = MKDEV(major, minor);
if (MAJOR(tmp) == major && MINOR(tmp) == minor)
*rdev = tmp;
@@ -3206,7 +3205,7 @@ static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
READ_BUF(12);
READ64(sec);
- READ32(nsec);
+ p = xdr_decode_int(p, &nsec);
time->tv_sec = (time_t)sec;
time->tv_nsec = (long)nsec;
return 0;
@@ -3288,7 +3287,7 @@ static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *c
__be32 *p;
READ_BUF(20);
- READ32(cinfo->atomic);
+ p = xdr_decode_int(p, &cinfo->atomic);
READ64(cinfo->before);
READ64(cinfo->after);
return 0;
@@ -3304,8 +3303,8 @@ static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
if (status)
return status;
READ_BUF(8);
- READ32(supp);
- READ32(acc);
+ p = xdr_decode_int(p, &supp);
+ p = xdr_decode_int(p, &acc);
access->supported = supp;
access->access = acc;
return 0;
@@ -3351,7 +3350,7 @@ static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
if ((status = decode_change_info(xdr, cinfo)))
return status;
READ_BUF(4);
- READ32(bmlen);
+ p = xdr_decode_int(p, &bmlen);
READ_BUF(bmlen << 2);
return 0;
}
@@ -3606,7 +3605,7 @@ static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
return status;
READ_BUF(4);
- READ32(len);
+ p = xdr_decode_int(p, &len);
if (len > NFS4_FHSIZE)
return -EIO;
fh->size = len;
@@ -3637,7 +3636,7 @@ static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
READ_BUF(32);
READ64(offset);
READ64(length);
- READ32(type);
+ p = xdr_decode_int(p, &type);
if (fl != NULL) {
fl->fl_start = (loff_t)offset;
fl->fl_end = fl->fl_start + (loff_t)length - 1;
@@ -3649,7 +3648,7 @@ static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
fl->fl_pid = 0;
}
READ64(clientid);
- READ32(namelen);
+ p = xdr_decode_int(p, &namelen);
READ_BUF(namelen);
return -NFS4ERR_DENIED;
}
@@ -3710,14 +3709,14 @@ static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
uint32_t limit_type, nblocks, blocksize;
READ_BUF(12);
- READ32(limit_type);
+ p = xdr_decode_int(p, &limit_type);
switch (limit_type) {
case 1:
READ64(*maxsize);
break;
case 2:
- READ32(nblocks);
- READ32(blocksize);
+ p = xdr_decode_int(p, &nblocks);
+ p = xdr_decode_int(p, &blocksize);
*maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
}
return 0;
@@ -3729,14 +3728,14 @@ static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
uint32_t delegation_type;
READ_BUF(4);
- READ32(delegation_type);
+ p = xdr_decode_int(p, &delegation_type);
if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
res->delegation_type = 0;
return 0;
}
READ_BUF(NFS4_STATEID_SIZE+4);
COPYMEM(res->delegation.data, NFS4_STATEID_SIZE);
- READ32(res->do_recall);
+ p = xdr_decode_int(p, &res->do_recall);
switch (delegation_type) {
case NFS4_OPEN_DELEGATE_READ:
@@ -3767,15 +3766,15 @@ static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
decode_change_info(xdr, &res->cinfo);
READ_BUF(8);
- READ32(res->rflags);
- READ32(bmlen);
+ p = xdr_decode_int(p, &res->rflags);
+ p = xdr_decode_int(p, &bmlen);
if (bmlen > 10)
goto xdr_error;
READ_BUF(bmlen << 2);
savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
for (i = 0; i < savewords; ++i)
- READ32(res->attrset[i]);
+ p = xdr_decode_int(p, &res->attrset[i]);
for (; i < NFS4_BITMAP_SIZE; i++)
res->attrset[i] = 0;
@@ -3836,8 +3835,8 @@ static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_
if (status)
return status;
READ_BUF(8);
- READ32(eof);
- READ32(count);
+ p = xdr_decode_int(p, &eof);
+ p = xdr_decode_int(p, &count);
hdrlen = (u8 *) p - (u8 *) iov->iov_base;
recvd = req->rq_rcv_buf.len - hdrlen;
if (count > recvd) {
@@ -3963,7 +3962,7 @@ static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
/* Convert length of symlink */
READ_BUF(4);
- READ32(len);
+ p = xdr_decode_int(p, &len);
if (len >= rcvbuf->page_len || len <= 0) {
dprintk("nfs: server returned giant symlink!\n");
return -ENAMETOOLONG;
@@ -4085,7 +4084,7 @@ static int decode_setattr(struct xdr_stream *xdr)
if (status)
return status;
READ_BUF(4);
- READ32(bmlen);
+ p = xdr_decode_int(p, &bmlen);
READ_BUF(bmlen << 2);
return 0;
}
@@ -4097,13 +4096,13 @@ static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
int32_t nfserr;
READ_BUF(8);
- READ32(opnum);
+ p = xdr_decode_int(p, &opnum);
if (opnum != OP_SETCLIENTID) {
dprintk("nfs: decode_setclientid: Server returned operation"
" %d\n", opnum);
return -EIO;
}
- READ32(nfserr);
+ p = xdr_decode_int(p, &nfserr);
if (nfserr == NFS_OK) {
READ_BUF(8 + NFS4_VERIFIER_SIZE);
READ64(clp->cl_clientid);
@@ -4113,12 +4112,12 @@ static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
/* skip netid string */
READ_BUF(4);
- READ32(len);
+ p = xdr_decode_int(p, &len);
READ_BUF(len);
/* skip uaddr string */
READ_BUF(4);
- READ32(len);
+ p = xdr_decode_int(p, &len);
READ_BUF(len);
return -NFSERR_CLID_INUSE;
} else
@@ -4142,8 +4141,8 @@ static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
return status;
READ_BUF(16);
- READ32(res->count);
- READ32(res->verf->committed);
+ p = xdr_decode_int(p, &res->count);
+ p = xdr_decode_int(p, &res->verf->committed);
COPYMEM(res->verf->verifier, 8);
return 0;
}
@@ -4169,11 +4168,11 @@ static int decode_exchange_id(struct xdr_stream *xdr,
READ_BUF(8);
READ64(clp->cl_ex_clid);
READ_BUF(12);
- READ32(clp->cl_seqid);
- READ32(clp->cl_exchange_flags);
+ p = xdr_decode_int(p, &clp->cl_seqid);
+ p = xdr_decode_int(p, &clp->cl_exchange_flags);
/* We ask for SP4_NONE */
- READ32(dummy);
+ p = xdr_decode_int(p, &dummy);
if (dummy != SP4_NONE)
return -EIO;
@@ -4182,17 +4181,17 @@ static int decode_exchange_id(struct xdr_stream *xdr,
/* Throw away Major id */
READ_BUF(4);
- READ32(dummy);
+ p = xdr_decode_int(p, &dummy);
READ_BUF(dummy);
/* Throw away server_scope */
READ_BUF(4);
- READ32(dummy);
+ p = xdr_decode_int(p, &dummy);
READ_BUF(dummy);
/* Throw away Implementation id array */
READ_BUF(4);
- READ32(dummy);
+ p = xdr_decode_int(p, &dummy);
READ_BUF(dummy);
return 0;
@@ -4205,13 +4204,13 @@ static int decode_chan_attrs(struct xdr_stream *xdr,
u32 nr_attrs;
READ_BUF(28);
- READ32(attrs->headerpadsz);
- READ32(attrs->max_rqst_sz);
- READ32(attrs->max_resp_sz);
- READ32(attrs->max_resp_sz_cached);
- READ32(attrs->max_ops);
- READ32(attrs->max_reqs);
- READ32(nr_attrs);
+ p = xdr_decode_int(p, &attrs->headerpadsz);
+ p = xdr_decode_int(p, &attrs->max_rqst_sz);
+ p = xdr_decode_int(p, &attrs->max_resp_sz);
+ p = xdr_decode_int(p, &attrs->max_resp_sz_cached);
+ p = xdr_decode_int(p, &attrs->max_ops);
+ p = xdr_decode_int(p, &attrs->max_reqs);
+ p = xdr_decode_int(p, &nr_attrs);
if (unlikely(nr_attrs > 1)) {
printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n",
__func__, nr_attrs);
@@ -4241,8 +4240,8 @@ static int decode_create_session(struct xdr_stream *xdr,
/* seqid, flags */
READ_BUF(8);
- READ32(clp->cl_seqid);
- READ32(session->flags);
+ p = xdr_decode_int(p, &clp->cl_seqid);
+ p = xdr_decode_int(p, &session->flags);
/* Channel attributes */
status = decode_chan_attrs(xdr, &session->fc_attrs);
@@ -4290,23 +4289,23 @@ static int decode_sequence(struct xdr_stream *xdr,
goto out_err;
}
/* seqid */
- READ32(dummy);
+ p = xdr_decode_int(p, &dummy);
if (dummy != slot->seq_nr) {
dprintk("%s Invalid sequence number\n", __func__);
goto out_err;
}
/* slot id */
- READ32(dummy);
+ p = xdr_decode_int(p, &dummy);
if (dummy != res->sr_slotid) {
dprintk("%s Invalid slot id\n", __func__);
goto out_err;
}
/* highest slot id - currently not processed */
- READ32(dummy);
+ p = xdr_decode_int(p, &dummy);
/* target highest slot id - currently not processed */
- READ32(dummy);
+ p = xdr_decode_int(p, &dummy);
/* result flags - currently not processed */
- READ32(dummy);
+ p = xdr_decode_int(p, &dummy);
status = 0;
out_err:
res->sr_status = status;
--
1.6.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH RFC 10/13] nfs: nfs4xdr: get rid of READ64
2009-08-12 15:15 [PATCH RFC 0/13] xdr macros cleanup Benny Halevy
` (8 preceding siblings ...)
2009-08-12 15:22 ` [PATCH RFC 09/13] nfs: nfs4xdr: get rid of READ32 Benny Halevy
@ 2009-08-12 15:22 ` Benny Halevy
2009-08-12 15:22 ` [PATCH RFC 11/13] nfs: nfs4xdr: get rid of READTIME macro Benny Halevy
` (2 subsequent siblings)
12 siblings, 0 replies; 20+ messages in thread
From: Benny Halevy @ 2009-08-12 15:22 UTC (permalink / raw)
To: Trond Myklebust; +Cc: linux-nfs
use xdr_decode_hyper instead.
Signed-off-by: Benny Halevy <bhalevy@panasas.com>
---
fs/nfs/nfs4xdr.c | 54 +++++++++++++++++++++++++-----------------------------
1 files changed, 25 insertions(+), 29 deletions(-)
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index 5c2b905..db17685 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -2448,10 +2448,6 @@ static int nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, uint32_t *p,
* task to translate them into Linux-specific versions which are more
* consistent with the style used in NFSv2/v3...
*/
-#define READ64(x) do { \
- (x) = (u64)ntohl(*p++) << 32; \
- (x) |= ntohl(*p++); \
-} while (0)
#define READTIME(x) do { \
p++; \
(x.tv_sec) = ntohl(*p++); \
@@ -2603,7 +2599,7 @@ static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t
return -EIO;
if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
READ_BUF(8);
- READ64(*change);
+ p = xdr_decode_hyper(p, change);
bitmap[0] &= ~FATTR4_WORD0_CHANGE;
ret = NFS_ATTR_FATTR_CHANGE;
}
@@ -2622,7 +2618,7 @@ static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *
return -EIO;
if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
READ_BUF(8);
- READ64(*size);
+ p = xdr_decode_hyper(p, size);
bitmap[0] &= ~FATTR4_WORD0_SIZE;
ret = NFS_ATTR_FATTR_SIZE;
}
@@ -2673,8 +2669,8 @@ static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs
return -EIO;
if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
READ_BUF(16);
- READ64(fsid->major);
- READ64(fsid->minor);
+ p = xdr_decode_hyper(p, &fsid->major);
+ p = xdr_decode_hyper(p, &fsid->minor);
bitmap[0] &= ~FATTR4_WORD0_FSID;
ret = NFS_ATTR_FATTR_FSID;
}
@@ -2726,7 +2722,7 @@ static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t
return -EIO;
if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
READ_BUF(8);
- READ64(*fileid);
+ p = xdr_decode_hyper(p, fileid);
bitmap[0] &= ~FATTR4_WORD0_FILEID;
ret = NFS_ATTR_FATTR_FILEID;
}
@@ -2744,7 +2740,7 @@ static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitma
return -EIO;
if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
READ_BUF(8);
- READ64(*fileid);
+ p = xdr_decode_hyper(p, fileid);
bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
ret = NFS_ATTR_FATTR_FILEID;
}
@@ -2762,7 +2758,7 @@ static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uin
return -EIO;
if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
READ_BUF(8);
- READ64(*res);
+ p = xdr_decode_hyper(p, res);
bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
}
dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
@@ -2779,7 +2775,7 @@ static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint
return -EIO;
if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
READ_BUF(8);
- READ64(*res);
+ p = xdr_decode_hyper(p, res);
bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
}
dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
@@ -2796,7 +2792,7 @@ static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uin
return -EIO;
if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
READ_BUF(8);
- READ64(*res);
+ p = xdr_decode_hyper(p, res);
bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
}
dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
@@ -2925,7 +2921,7 @@ static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uin
return -EIO;
if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
READ_BUF(8);
- READ64(*res);
+ p = xdr_decode_hyper(p, res);
bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
}
dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
@@ -2977,7 +2973,7 @@ static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_
if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
uint64_t maxread;
READ_BUF(8);
- READ64(maxread);
+ p = xdr_decode_hyper(p, &maxread);
if (maxread > 0x7FFFFFFF)
maxread = 0x7FFFFFFF;
*res = (uint32_t)maxread;
@@ -2998,7 +2994,7 @@ static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32
if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
uint64_t maxwrite;
READ_BUF(8);
- READ64(maxwrite);
+ p = xdr_decode_hyper(p, &maxwrite);
if (maxwrite > 0x7FFFFFFF)
maxwrite = 0x7FFFFFFF;
*res = (uint32_t)maxwrite;
@@ -3137,7 +3133,7 @@ static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uin
return -EIO;
if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
READ_BUF(8);
- READ64(*res);
+ p = xdr_decode_hyper(p, res);
bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
}
dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
@@ -3154,7 +3150,7 @@ static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint
return -EIO;
if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
READ_BUF(8);
- READ64(*res);
+ p = xdr_decode_hyper(p, res);
bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
}
dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
@@ -3171,7 +3167,7 @@ static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uin
return -EIO;
if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
READ_BUF(8);
- READ64(*res);
+ p = xdr_decode_hyper(p, res);
bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
}
dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
@@ -3188,7 +3184,7 @@ static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint
return -EIO;
if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
READ_BUF(8);
- READ64(*used);
+ p = xdr_decode_hyper(p, used);
bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
ret = NFS_ATTR_FATTR_SPACE_USED;
}
@@ -3204,7 +3200,7 @@ static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
uint32_t nsec;
READ_BUF(12);
- READ64(sec);
+ p = xdr_decode_hyper(p, &sec);
p = xdr_decode_int(p, &nsec);
time->tv_sec = (time_t)sec;
time->tv_nsec = (long)nsec;
@@ -3288,8 +3284,8 @@ static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *c
READ_BUF(20);
p = xdr_decode_int(p, &cinfo->atomic);
- READ64(cinfo->before);
- READ64(cinfo->after);
+ p = xdr_decode_hyper(p, &cinfo->before);
+ p = xdr_decode_hyper(p, &cinfo->after);
return 0;
}
@@ -3634,8 +3630,8 @@ static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
uint32_t namelen, type;
READ_BUF(32);
- READ64(offset);
- READ64(length);
+ p = xdr_decode_hyper(p, &offset);
+ p = xdr_decode_hyper(p, &length);
p = xdr_decode_int(p, &type);
if (fl != NULL) {
fl->fl_start = (loff_t)offset;
@@ -3647,7 +3643,7 @@ static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
fl->fl_type = F_RDLCK;
fl->fl_pid = 0;
}
- READ64(clientid);
+ p = xdr_decode_hyper(p, &clientid);
p = xdr_decode_int(p, &namelen);
READ_BUF(namelen);
return -NFS4ERR_DENIED;
@@ -3712,7 +3708,7 @@ static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
p = xdr_decode_int(p, &limit_type);
switch (limit_type) {
case 1:
- READ64(*maxsize);
+ p = xdr_decode_hyper(p, maxsize);
break;
case 2:
p = xdr_decode_int(p, &nblocks);
@@ -4105,7 +4101,7 @@ static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
p = xdr_decode_int(p, &nfserr);
if (nfserr == NFS_OK) {
READ_BUF(8 + NFS4_VERIFIER_SIZE);
- READ64(clp->cl_clientid);
+ p = xdr_decode_hyper(p, &clp->cl_clientid);
COPYMEM(clp->cl_confirm.data, NFS4_VERIFIER_SIZE);
} else if (nfserr == NFSERR_CLID_INUSE) {
uint32_t len;
@@ -4166,7 +4162,7 @@ static int decode_exchange_id(struct xdr_stream *xdr,
return status;
READ_BUF(8);
- READ64(clp->cl_ex_clid);
+ p = xdr_decode_hyper(p, &clp->cl_ex_clid);
READ_BUF(12);
p = xdr_decode_int(p, &clp->cl_seqid);
p = xdr_decode_int(p, &clp->cl_exchange_flags);
--
1.6.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH RFC 11/13] nfs: nfs4xdr: get rid of READTIME macro
2009-08-12 15:15 [PATCH RFC 0/13] xdr macros cleanup Benny Halevy
` (9 preceding siblings ...)
2009-08-12 15:22 ` [PATCH RFC 10/13] nfs: nfs4xdr: get rid of READ64 Benny Halevy
@ 2009-08-12 15:22 ` Benny Halevy
2009-08-12 15:22 ` [PATCH RFC 12/13] nfs: nfs4xdr: change COPYMEM macro into a static function Benny Halevy
2009-08-12 15:22 ` [PATCH RFC 13/13] nfs: nfs4xdr: get rid of READ_BUF Benny Halevy
12 siblings, 0 replies; 20+ messages in thread
From: Benny Halevy @ 2009-08-12 15:22 UTC (permalink / raw)
To: Trond Myklebust; +Cc: linux-nfs
It has no users.
Signed-off-by: Benny Halevy <bhalevy@panasas.com>
---
fs/nfs/nfs4xdr.c | 5 -----
1 files changed, 0 insertions(+), 5 deletions(-)
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index db17685..2e83aef 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -2448,11 +2448,6 @@ static int nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, uint32_t *p,
* task to translate them into Linux-specific versions which are more
* consistent with the style used in NFSv2/v3...
*/
-#define READTIME(x) do { \
- p++; \
- (x.tv_sec) = ntohl(*p++); \
- (x.tv_nsec) = ntohl(*p++); \
-} while (0)
#define COPYMEM(x,nbytes) do { \
memcpy((x), p, nbytes); \
p += XDR_QUADLEN(nbytes); \
--
1.6.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH RFC 12/13] nfs: nfs4xdr: change COPYMEM macro into a static function
2009-08-12 15:15 [PATCH RFC 0/13] xdr macros cleanup Benny Halevy
` (10 preceding siblings ...)
2009-08-12 15:22 ` [PATCH RFC 11/13] nfs: nfs4xdr: get rid of READTIME macro Benny Halevy
@ 2009-08-12 15:22 ` Benny Halevy
2009-08-12 20:36 ` Trond Myklebust
2009-08-12 15:22 ` [PATCH RFC 13/13] nfs: nfs4xdr: get rid of READ_BUF Benny Halevy
12 siblings, 1 reply; 20+ messages in thread
From: Benny Halevy @ 2009-08-12 15:22 UTC (permalink / raw)
To: Trond Myklebust; +Cc: linux-nfs
Signed-off-by: Benny Halevy <bhalevy@panasas.com>
---
fs/nfs/nfs4xdr.c | 39 ++++++++++++++++++++-------------------
1 files changed, 20 insertions(+), 19 deletions(-)
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index 2e83aef..ed9bbd2 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -2448,11 +2448,6 @@ static int nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, uint32_t *p,
* task to translate them into Linux-specific versions which are more
* consistent with the style used in NFSv2/v3...
*/
-#define COPYMEM(x,nbytes) do { \
- memcpy((x), p, nbytes); \
- p += XDR_QUADLEN(nbytes); \
-} while (0)
-
#define READ_BUF(nbytes) do { \
p = xdr_inline_decode(xdr, nbytes); \
if (unlikely(!p)) { \
@@ -2464,6 +2459,12 @@ static int nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, uint32_t *p,
} \
} while (0)
+static __be32 *copymem(void *x, __be32 *p, u32 nbytes)
+{
+ memcpy(x, p, nbytes);
+ return p + XDR_QUADLEN(nbytes);
+}
+
static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
{
__be32 *p;
@@ -3312,7 +3313,7 @@ static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
if (status)
return status;
READ_BUF(NFS4_STATEID_SIZE);
- COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
+ copymem(res->stateid.data, p, NFS4_STATEID_SIZE);
return 0;
}
@@ -3325,7 +3326,7 @@ static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
if (status)
return status;
READ_BUF(8);
- COPYMEM(res->verf->verifier, 8);
+ copymem(res->verf->verifier, p, 8);
return 0;
}
@@ -3601,7 +3602,7 @@ static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
return -EIO;
fh->size = len;
READ_BUF(len);
- COPYMEM(fh->data, len);
+ copymem(fh->data, p, len);
return 0;
}
@@ -3654,7 +3655,7 @@ static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
goto out;
if (status == 0) {
READ_BUF(NFS4_STATEID_SIZE);
- COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
+ copymem(res->stateid.data, p, NFS4_STATEID_SIZE);
} else if (status == -NFS4ERR_DENIED)
status = decode_lock_denied(xdr, NULL);
if (res->open_seqid != NULL)
@@ -3683,7 +3684,7 @@ static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
nfs_increment_lock_seqid(status, res->seqid);
if (status == 0) {
READ_BUF(NFS4_STATEID_SIZE);
- COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
+ copymem(res->stateid.data, p, NFS4_STATEID_SIZE);
}
return status;
}
@@ -3725,7 +3726,7 @@ static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
return 0;
}
READ_BUF(NFS4_STATEID_SIZE+4);
- COPYMEM(res->delegation.data, NFS4_STATEID_SIZE);
+ p = copymem(res->delegation.data, p, NFS4_STATEID_SIZE);
p = xdr_decode_int(p, &res->do_recall);
switch (delegation_type) {
@@ -3752,7 +3753,7 @@ static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
if (status)
return status;
READ_BUF(NFS4_STATEID_SIZE);
- COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
+ p = copymem(res->stateid.data, p, NFS4_STATEID_SIZE);
decode_change_info(xdr, &res->cinfo);
@@ -3786,7 +3787,7 @@ static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmre
if (status)
return status;
READ_BUF(NFS4_STATEID_SIZE);
- COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
+ copymem(res->stateid.data, p, NFS4_STATEID_SIZE);
return 0;
}
@@ -3801,7 +3802,7 @@ static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *re
if (status)
return status;
READ_BUF(NFS4_STATEID_SIZE);
- COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
+ copymem(res->stateid.data, p, NFS4_STATEID_SIZE);
return 0;
}
@@ -3857,7 +3858,7 @@ static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct n
if (status)
return status;
READ_BUF(8);
- COPYMEM(readdir->verifier.data, 8);
+ p = copymem(readdir->verifier.data, p, 8);
dprintk("%s: verifier = %08x:%08x\n",
__func__,
((u32 *)readdir->verifier.data)[0],
@@ -4097,7 +4098,7 @@ static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
if (nfserr == NFS_OK) {
READ_BUF(8 + NFS4_VERIFIER_SIZE);
p = xdr_decode_hyper(p, &clp->cl_clientid);
- COPYMEM(clp->cl_confirm.data, NFS4_VERIFIER_SIZE);
+ copymem(clp->cl_confirm.data, p, NFS4_VERIFIER_SIZE);
} else if (nfserr == NFSERR_CLID_INUSE) {
uint32_t len;
@@ -4134,7 +4135,7 @@ static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
READ_BUF(16);
p = xdr_decode_int(p, &res->count);
p = xdr_decode_int(p, &res->verf->committed);
- COPYMEM(res->verf->verifier, 8);
+ copymem(res->verf->verifier, p, 8);
return 0;
}
@@ -4227,7 +4228,7 @@ static int decode_create_session(struct xdr_stream *xdr,
/* sessionid */
READ_BUF(NFS4_MAX_SESSIONID_LEN);
- COPYMEM(&session->sess_id, NFS4_MAX_SESSIONID_LEN);
+ copymem(&session->sess_id, p, NFS4_MAX_SESSIONID_LEN);
/* seqid, flags */
READ_BUF(8);
@@ -4273,7 +4274,7 @@ static int decode_sequence(struct xdr_stream *xdr,
slot = &res->sr_session->fc_slot_table.slots[res->sr_slotid];
READ_BUF(NFS4_MAX_SESSIONID_LEN + 20);
- COPYMEM(id.data, NFS4_MAX_SESSIONID_LEN);
+ p = copymem(id.data, p, NFS4_MAX_SESSIONID_LEN);
if (memcmp(id.data, res->sr_session->sess_id.data,
NFS4_MAX_SESSIONID_LEN)) {
dprintk("%s Invalid session id\n", __func__);
--
1.6.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH RFC 13/13] nfs: nfs4xdr: get rid of READ_BUF
2009-08-12 15:15 [PATCH RFC 0/13] xdr macros cleanup Benny Halevy
` (11 preceding siblings ...)
2009-08-12 15:22 ` [PATCH RFC 12/13] nfs: nfs4xdr: change COPYMEM macro into a static function Benny Halevy
@ 2009-08-12 15:22 ` Benny Halevy
2009-08-12 21:05 ` Trond Myklebust
12 siblings, 1 reply; 20+ messages in thread
From: Benny Halevy @ 2009-08-12 15:22 UTC (permalink / raw)
To: Trond Myklebust; +Cc: linux-nfs
Open code return pointer assignment and error checking using
a read_buf helper (macro), yet keep the dprintk on failure using an
internal __read_buf helper that gets the function name for printing.
Signed-off-by: Benny Halevy <bhalevy@panasas.com>
---
fs/nfs/nfs4xdr.c | 386 ++++++++++++++++++++++++++++++++++++++---------------
1 files changed, 277 insertions(+), 109 deletions(-)
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index ed9bbd2..fb10a77 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -2438,26 +2438,17 @@ static int nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, uint32_t *p,
}
#endif /* CONFIG_NFS_V4_1 */
-/*
- * START OF "GENERIC" DECODE ROUTINES.
- * These may look a little ugly since they are imported from a "generic"
- * set of XDR encode/decode routines which are intended to be shared by
- * all of our NFSv4 implementations (OpenBSD, MacOS X...).
- *
- * If the pain of reading these is too great, it should be a straightforward
- * task to translate them into Linux-specific versions which are more
- * consistent with the style used in NFSv2/v3...
- */
-#define READ_BUF(nbytes) do { \
- p = xdr_inline_decode(xdr, nbytes); \
- if (unlikely(!p)) { \
- dprintk("nfs: %s: prematurely hit end of receive" \
- " buffer\n", __func__); \
- dprintk("nfs: %s: xdr->p=%p, bytes=%u, xdr->end=%p\n", \
- __func__, xdr->p, nbytes, xdr->end); \
- return -EIO; \
- } \
-} while (0)
+static __be32 *__read_buf(struct xdr_stream *xdr, size_t nbytes, char *func)
+{
+ __be32 *p = xdr_inline_decode(xdr, nbytes);
+ if (unlikely(!p))
+ dprintk("nfs: %s: prematurely hit end of receive buffer: "
+ "xdr->p=%p, bytes=%u, xdr->end=%p\n",
+ func, xdr->p, nbytes, xdr->end);
+ return p;
+}
+
+#define read_buf(xdr, nbytes) __read_buf(xdr, nbytes, __func__)
static __be32 *copymem(void *x, __be32 *p, u32 nbytes)
{
@@ -2469,9 +2460,13 @@ static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char
{
__be32 *p;
- READ_BUF(4);
+ p = read_buf(xdr, 4);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, len);
- READ_BUF(*len);
+ p = read_buf(xdr, *len);
+ if (unlikely(!p))
+ return -EIO;
*string = (char *)p;
return 0;
}
@@ -2480,11 +2475,15 @@ static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
{
__be32 *p;
- READ_BUF(8);
+ p = read_buf(xdr, 8);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, &hdr->status);
p = xdr_decode_int(p, &hdr->taglen);
- READ_BUF(hdr->taglen + 4);
+ p = read_buf(xdr, hdr->taglen + 4);
+ if (unlikely(!p))
+ return -EIO;
hdr->tag = (char *)p;
p += XDR_QUADLEN(hdr->taglen);
p = xdr_decode_int(p, &hdr->nops);
@@ -2499,7 +2498,9 @@ static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
uint32_t opnum;
int32_t nfserr;
- READ_BUF(8);
+ p = read_buf(xdr, 8);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, &opnum);
if (opnum != expected) {
dprintk("nfs: Server returned operation"
@@ -2520,7 +2521,9 @@ static int decode_ace(struct xdr_stream *xdr, void *ace, struct nfs_client *clp)
unsigned int strlen;
char *str;
- READ_BUF(12);
+ p = read_buf(xdr, 12);
+ if (unlikely(!p))
+ return -EIO;
return decode_opaque_inline(xdr, &strlen, &str);
}
@@ -2529,11 +2532,15 @@ static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
uint32_t bmlen;
__be32 *p;
- READ_BUF(4);
+ p = read_buf(xdr, 4);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, &bmlen);
bitmap[0] = bitmap[1] = 0;
- READ_BUF((bmlen << 2));
+ p = read_buf(xdr, (bmlen << 2));
+ if (unlikely(!p))
+ return -EIO;
if (bmlen > 0) {
p = xdr_decode_int(p, &bitmap[0]);
if (bmlen > 1)
@@ -2546,7 +2553,9 @@ static inline int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen,
{
__be32 *p;
- READ_BUF(4);
+ p = read_buf(xdr, 4);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, attrlen);
*savep = xdr->p;
return 0;
@@ -2572,7 +2581,9 @@ static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *
if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
return -EIO;
if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
- READ_BUF(4);
+ p = read_buf(xdr, 4);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, type);
if (*type < NF4REG || *type > NF4NAMEDATTR) {
dprintk("%s: bad type %d\n", __func__, *type);
@@ -2594,7 +2605,9 @@ static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t
if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
return -EIO;
if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
- READ_BUF(8);
+ p = read_buf(xdr, 8);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_hyper(p, change);
bitmap[0] &= ~FATTR4_WORD0_CHANGE;
ret = NFS_ATTR_FATTR_CHANGE;
@@ -2613,7 +2626,9 @@ static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *
if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
return -EIO;
if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
- READ_BUF(8);
+ p = read_buf(xdr, 8);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_hyper(p, size);
bitmap[0] &= ~FATTR4_WORD0_SIZE;
ret = NFS_ATTR_FATTR_SIZE;
@@ -2630,7 +2645,9 @@ static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, ui
if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
return -EIO;
if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
- READ_BUF(4);
+ p = read_buf(xdr, 4);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, res);
bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
}
@@ -2646,7 +2663,9 @@ static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap,
if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
return -EIO;
if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
- READ_BUF(4);
+ p = read_buf(xdr, 4);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, res);
bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
}
@@ -2664,7 +2683,9 @@ static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs
if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
return -EIO;
if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
- READ_BUF(16);
+ p = read_buf(xdr, 16);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_hyper(p, &fsid->major);
p = xdr_decode_hyper(p, &fsid->minor);
bitmap[0] &= ~FATTR4_WORD0_FSID;
@@ -2684,7 +2705,9 @@ static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint
if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
return -EIO;
if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
- READ_BUF(4);
+ p = read_buf(xdr, 4);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, res);
bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
}
@@ -2700,7 +2723,9 @@ static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint
if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
return -EIO;
if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
- READ_BUF(4);
+ p = read_buf(xdr, 4);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, res);
bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
}
@@ -2717,7 +2742,9 @@ static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t
if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
return -EIO;
if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
- READ_BUF(8);
+ p = read_buf(xdr, 8);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_hyper(p, fileid);
bitmap[0] &= ~FATTR4_WORD0_FILEID;
ret = NFS_ATTR_FATTR_FILEID;
@@ -2735,7 +2762,9 @@ static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitma
if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
return -EIO;
if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
- READ_BUF(8);
+ p = read_buf(xdr, 8);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_hyper(p, fileid);
bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
ret = NFS_ATTR_FATTR_FILEID;
@@ -2753,7 +2782,9 @@ static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uin
if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
return -EIO;
if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
- READ_BUF(8);
+ p = read_buf(xdr, 8);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_hyper(p, res);
bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
}
@@ -2770,7 +2801,9 @@ static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint
if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
return -EIO;
if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
- READ_BUF(8);
+ p = read_buf(xdr, 8);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_hyper(p, res);
bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
}
@@ -2787,7 +2820,9 @@ static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uin
if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
return -EIO;
if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
- READ_BUF(8);
+ p = read_buf(xdr, 8);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_hyper(p, res);
bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
}
@@ -2801,7 +2836,9 @@ static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
__be32 *p;
int status = 0;
- READ_BUF(4);
+ p = read_buf(xdr, 4);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, &n);
if (n == 0)
goto root_path;
@@ -2853,7 +2890,9 @@ static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, st
status = decode_pathname(xdr, &res->fs_path);
if (unlikely(status != 0))
goto out;
- READ_BUF(4);
+ p = read_buf(xdr, 4);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, &n);
if (n <= 0)
goto out_eio;
@@ -2862,7 +2901,9 @@ static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, st
u32 m;
struct nfs4_fs_location *loc = &res->locations[res->nlocations];
- READ_BUF(4);
+ p = read_buf(xdr, 4);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, &m);
loc->nservers = 0;
@@ -2916,7 +2957,9 @@ static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uin
if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
return -EIO;
if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
- READ_BUF(8);
+ p = read_buf(xdr, 8);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_hyper(p, res);
bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
}
@@ -2933,7 +2976,9 @@ static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_
if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
return -EIO;
if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
- READ_BUF(4);
+ p = read_buf(xdr, 4);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, maxlink);
bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
}
@@ -2950,7 +2995,9 @@ static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_
if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
return -EIO;
if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
- READ_BUF(4);
+ p = read_buf(xdr, 4);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, maxname);
bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
}
@@ -2968,7 +3015,9 @@ static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_
return -EIO;
if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
uint64_t maxread;
- READ_BUF(8);
+ p = read_buf(xdr, 8);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_hyper(p, &maxread);
if (maxread > 0x7FFFFFFF)
maxread = 0x7FFFFFFF;
@@ -2989,7 +3038,9 @@ static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32
return -EIO;
if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
uint64_t maxwrite;
- READ_BUF(8);
+ p = read_buf(xdr, 8);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_hyper(p, &maxwrite);
if (maxwrite > 0x7FFFFFFF)
maxwrite = 0x7FFFFFFF;
@@ -3010,7 +3061,9 @@ static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *m
if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
return -EIO;
if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
- READ_BUF(4);
+ p = read_buf(xdr, 4);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, &tmp);
*mode = tmp & ~S_IFMT;
bitmap[1] &= ~FATTR4_WORD1_MODE;
@@ -3029,7 +3082,9 @@ static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t
if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
return -EIO;
if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
- READ_BUF(4);
+ p = read_buf(xdr, 4);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, nlink);
bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
ret = NFS_ATTR_FATTR_NLINK;
@@ -3048,9 +3103,13 @@ static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap, struct nf
if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
return -EIO;
if (likely(bitmap[1] & FATTR4_WORD1_OWNER)) {
- READ_BUF(4);
+ p = read_buf(xdr, 4);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, &len);
- READ_BUF(len);
+ p = read_buf(xdr, len);
+ if (unlikely(!p))
+ return -EIO;
if (len < XDR_MAX_NETOBJ) {
if (nfs_map_name_to_uid(clp, (char *)p, len, uid) == 0)
ret = NFS_ATTR_FATTR_OWNER;
@@ -3076,9 +3135,13 @@ static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap, struct nf
if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
return -EIO;
if (likely(bitmap[1] & FATTR4_WORD1_OWNER_GROUP)) {
- READ_BUF(4);
+ p = read_buf(xdr, 4);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, &len);
- READ_BUF(len);
+ p = read_buf(xdr, len);
+ if (unlikely(!p))
+ return -EIO;
if (len < XDR_MAX_NETOBJ) {
if (nfs_map_group_to_gid(clp, (char *)p, len, gid) == 0)
ret = NFS_ATTR_FATTR_GROUP;
@@ -3106,7 +3169,9 @@ static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rde
if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
dev_t tmp;
- READ_BUF(8);
+ p = read_buf(xdr, 8);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, &major);
p = xdr_decode_int(p, &minor);
tmp = MKDEV(major, minor);
@@ -3128,7 +3193,9 @@ static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uin
if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
return -EIO;
if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
- READ_BUF(8);
+ p = read_buf(xdr, 8);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_hyper(p, res);
bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
}
@@ -3145,7 +3212,9 @@ static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint
if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
return -EIO;
if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
- READ_BUF(8);
+ p = read_buf(xdr, 8);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_hyper(p, res);
bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
}
@@ -3162,7 +3231,9 @@ static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uin
if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
return -EIO;
if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
- READ_BUF(8);
+ p = read_buf(xdr, 8);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_hyper(p, res);
bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
}
@@ -3179,7 +3250,9 @@ static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint
if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
return -EIO;
if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
- READ_BUF(8);
+ p = read_buf(xdr, 8);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_hyper(p, used);
bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
ret = NFS_ATTR_FATTR_SPACE_USED;
@@ -3195,7 +3268,9 @@ static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
uint64_t sec;
uint32_t nsec;
- READ_BUF(12);
+ p = read_buf(xdr, 12);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_hyper(p, &sec);
p = xdr_decode_int(p, &nsec);
time->tv_sec = (time_t)sec;
@@ -3278,7 +3353,9 @@ static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *c
{
__be32 *p;
- READ_BUF(20);
+ p = read_buf(xdr, 20);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, &cinfo->atomic);
p = xdr_decode_hyper(p, &cinfo->before);
p = xdr_decode_hyper(p, &cinfo->after);
@@ -3294,7 +3371,9 @@ static int decode_access(struct xdr_stream *xdr, struct nfs4_accessres *access)
status = decode_op_hdr(xdr, OP_ACCESS);
if (status)
return status;
- READ_BUF(8);
+ p = read_buf(xdr, 8);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, &supp);
p = xdr_decode_int(p, &acc);
access->supported = supp;
@@ -3312,7 +3391,9 @@ static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
nfs_increment_open_seqid(status, res->seqid);
if (status)
return status;
- READ_BUF(NFS4_STATEID_SIZE);
+ p = read_buf(xdr, NFS4_STATEID_SIZE);
+ if (unlikely(!p))
+ return -EIO;
copymem(res->stateid.data, p, NFS4_STATEID_SIZE);
return 0;
}
@@ -3325,7 +3406,9 @@ static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
status = decode_op_hdr(xdr, OP_COMMIT);
if (status)
return status;
- READ_BUF(8);
+ p = read_buf(xdr, 8);
+ if (unlikely(!p))
+ return -EIO;
copymem(res->verf->verifier, p, 8);
return 0;
}
@@ -3341,9 +3424,13 @@ static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
return status;
if ((status = decode_change_info(xdr, cinfo)))
return status;
- READ_BUF(4);
+ p = read_buf(xdr, 4);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, &bmlen);
- READ_BUF(bmlen << 2);
+ p = read_buf(xdr, bmlen << 2);
+ if (unlikely(!p))
+ return -EIO;
return 0;
}
@@ -3596,12 +3683,16 @@ static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
if (status)
return status;
- READ_BUF(4);
+ p = read_buf(xdr, 4);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, &len);
if (len > NFS4_FHSIZE)
return -EIO;
fh->size = len;
- READ_BUF(len);
+ p = read_buf(xdr, len);
+ if (unlikely(!p))
+ return -EIO;
copymem(fh->data, p, len);
return 0;
}
@@ -3625,7 +3716,9 @@ static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
__be32 *p;
uint32_t namelen, type;
- READ_BUF(32);
+ p = read_buf(xdr, 32);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_hyper(p, &offset);
p = xdr_decode_hyper(p, &length);
p = xdr_decode_int(p, &type);
@@ -3641,7 +3734,9 @@ static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
}
p = xdr_decode_hyper(p, &clientid);
p = xdr_decode_int(p, &namelen);
- READ_BUF(namelen);
+ p = read_buf(xdr, namelen);
+ if (unlikely(!p))
+ return -EIO;
return -NFS4ERR_DENIED;
}
@@ -3654,7 +3749,9 @@ static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
if (status == -EIO)
goto out;
if (status == 0) {
- READ_BUF(NFS4_STATEID_SIZE);
+ p = read_buf(xdr, NFS4_STATEID_SIZE);
+ if (unlikely(!p))
+ return -EIO;
copymem(res->stateid.data, p, NFS4_STATEID_SIZE);
} else if (status == -NFS4ERR_DENIED)
status = decode_lock_denied(xdr, NULL);
@@ -3683,7 +3780,9 @@ static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
if (status != -EIO)
nfs_increment_lock_seqid(status, res->seqid);
if (status == 0) {
- READ_BUF(NFS4_STATEID_SIZE);
+ p = read_buf(xdr, NFS4_STATEID_SIZE);
+ if (unlikely(!p))
+ return -EIO;
copymem(res->stateid.data, p, NFS4_STATEID_SIZE);
}
return status;
@@ -3700,7 +3799,9 @@ static int decode_space_limit(struct xdr_stream *xdr, u64 *maxsize)
__be32 *p;
uint32_t limit_type, nblocks, blocksize;
- READ_BUF(12);
+ p = read_buf(xdr, 12);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, &limit_type);
switch (limit_type) {
case 1:
@@ -3719,13 +3820,17 @@ static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
__be32 *p;
uint32_t delegation_type;
- READ_BUF(4);
+ p = read_buf(xdr, 4);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, &delegation_type);
if (delegation_type == NFS4_OPEN_DELEGATE_NONE) {
res->delegation_type = 0;
return 0;
}
- READ_BUF(NFS4_STATEID_SIZE+4);
+ p = read_buf(xdr, NFS4_STATEID_SIZE+4);
+ if (unlikely(!p))
+ return -EIO;
p = copymem(res->delegation.data, p, NFS4_STATEID_SIZE);
p = xdr_decode_int(p, &res->do_recall);
@@ -3752,18 +3857,24 @@ static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
nfs_increment_open_seqid(status, res->seqid);
if (status)
return status;
- READ_BUF(NFS4_STATEID_SIZE);
+ p = read_buf(xdr, NFS4_STATEID_SIZE);
+ if (unlikely(!p))
+ return -EIO;
p = copymem(res->stateid.data, p, NFS4_STATEID_SIZE);
decode_change_info(xdr, &res->cinfo);
- READ_BUF(8);
+ p = read_buf(xdr, 8);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, &res->rflags);
p = xdr_decode_int(p, &bmlen);
if (bmlen > 10)
goto xdr_error;
- READ_BUF(bmlen << 2);
+ p = read_buf(xdr, bmlen << 2);
+ if (unlikely(!p))
+ return -EIO;
savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
for (i = 0; i < savewords; ++i)
p = xdr_decode_int(p, &res->attrset[i]);
@@ -3786,7 +3897,9 @@ static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmre
nfs_increment_open_seqid(status, res->seqid);
if (status)
return status;
- READ_BUF(NFS4_STATEID_SIZE);
+ p = read_buf(xdr, NFS4_STATEID_SIZE);
+ if (unlikely(!p))
+ return -EIO;
copymem(res->stateid.data, p, NFS4_STATEID_SIZE);
return 0;
}
@@ -3801,7 +3914,9 @@ static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *re
nfs_increment_open_seqid(status, res->seqid);
if (status)
return status;
- READ_BUF(NFS4_STATEID_SIZE);
+ p = read_buf(xdr, NFS4_STATEID_SIZE);
+ if (unlikely(!p))
+ return -EIO;
copymem(res->stateid.data, p, NFS4_STATEID_SIZE);
return 0;
}
@@ -3826,7 +3941,9 @@ static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_
status = decode_op_hdr(xdr, OP_READ);
if (status)
return status;
- READ_BUF(8);
+ p = read_buf(xdr, 8);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, &eof);
p = xdr_decode_int(p, &count);
hdrlen = (u8 *) p - (u8 *) iov->iov_base;
@@ -3857,7 +3974,9 @@ static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct n
status = decode_op_hdr(xdr, OP_READDIR);
if (status)
return status;
- READ_BUF(8);
+ p = read_buf(xdr, 8);
+ if (unlikely(!p))
+ return -EIO;
p = copymem(readdir->verifier.data, p, 8);
dprintk("%s: verifier = %08x:%08x\n",
__func__,
@@ -3953,7 +4072,9 @@ static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
return status;
/* Convert length of symlink */
- READ_BUF(4);
+ p = read_buf(xdr, 4);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, &len);
if (len >= rcvbuf->page_len || len <= 0) {
dprintk("nfs: server returned giant symlink!\n");
@@ -4075,9 +4196,13 @@ static int decode_setattr(struct xdr_stream *xdr)
status = decode_op_hdr(xdr, OP_SETATTR);
if (status)
return status;
- READ_BUF(4);
+ p = read_buf(xdr, 4);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, &bmlen);
- READ_BUF(bmlen << 2);
+ p = read_buf(xdr, bmlen << 2);
+ if (unlikely(!p))
+ return -EIO;
return 0;
}
@@ -4087,7 +4212,9 @@ static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
uint32_t opnum;
int32_t nfserr;
- READ_BUF(8);
+ p = read_buf(xdr, 8);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, &opnum);
if (opnum != OP_SETCLIENTID) {
dprintk("nfs: decode_setclientid: Server returned operation"
@@ -4096,21 +4223,31 @@ static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
}
p = xdr_decode_int(p, &nfserr);
if (nfserr == NFS_OK) {
- READ_BUF(8 + NFS4_VERIFIER_SIZE);
+ p = read_buf(xdr, 8 + NFS4_VERIFIER_SIZE);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_hyper(p, &clp->cl_clientid);
copymem(clp->cl_confirm.data, p, NFS4_VERIFIER_SIZE);
} else if (nfserr == NFSERR_CLID_INUSE) {
uint32_t len;
/* skip netid string */
- READ_BUF(4);
+ p = read_buf(xdr, 4);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, &len);
- READ_BUF(len);
+ p = read_buf(xdr, len);
+ if (unlikely(!p))
+ return -EIO;
/* skip uaddr string */
- READ_BUF(4);
+ p = read_buf(xdr, 4);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, &len);
- READ_BUF(len);
+ p = read_buf(xdr, len);
+ if (unlikely(!p))
+ return -EIO;
return -NFSERR_CLID_INUSE;
} else
return nfs4_stat_to_errno(nfserr);
@@ -4132,7 +4269,9 @@ static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
if (status)
return status;
- READ_BUF(16);
+ p = read_buf(xdr, 16);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, &res->count);
p = xdr_decode_int(p, &res->verf->committed);
copymem(res->verf->verifier, p, 8);
@@ -4157,9 +4296,13 @@ static int decode_exchange_id(struct xdr_stream *xdr,
if (status)
return status;
- READ_BUF(8);
+ p = read_buf(xdr, 8);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_hyper(p, &clp->cl_ex_clid);
- READ_BUF(12);
+ p = read_buf(xdr, 12);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, &clp->cl_seqid);
p = xdr_decode_int(p, &clp->cl_exchange_flags);
@@ -4169,22 +4312,36 @@ static int decode_exchange_id(struct xdr_stream *xdr,
return -EIO;
/* Throw away minor_id */
- READ_BUF(8);
+ p = read_buf(xdr, 8);
+ if (unlikely(!p))
+ return -EIO;
/* Throw away Major id */
- READ_BUF(4);
+ p = read_buf(xdr, 4);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, &dummy);
- READ_BUF(dummy);
+ p = read_buf(xdr, dummy);
+ if (unlikely(!p))
+ return -EIO;
/* Throw away server_scope */
- READ_BUF(4);
+ p = read_buf(xdr, 4);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, &dummy);
- READ_BUF(dummy);
+ p = read_buf(xdr, dummy);
+ if (unlikely(!p))
+ return -EIO;
/* Throw away Implementation id array */
- READ_BUF(4);
+ p = read_buf(xdr, 4);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, &dummy);
- READ_BUF(dummy);
+ p = read_buf(xdr, dummy);
+ if (unlikely(!p))
+ return -EIO;
return 0;
}
@@ -4195,7 +4352,9 @@ static int decode_chan_attrs(struct xdr_stream *xdr,
__be32 *p;
u32 nr_attrs;
- READ_BUF(28);
+ p = read_buf(xdr, 28);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, &attrs->headerpadsz);
p = xdr_decode_int(p, &attrs->max_rqst_sz);
p = xdr_decode_int(p, &attrs->max_resp_sz);
@@ -4208,8 +4367,11 @@ static int decode_chan_attrs(struct xdr_stream *xdr,
__func__, nr_attrs);
return -EINVAL;
}
- if (nr_attrs == 1)
- READ_BUF(4); /* skip rdma_attrs */
+ if (nr_attrs == 1) {
+ p = read_buf(xdr, 4); /* skip rdma_attrs */
+ if (unlikely(!p))
+ return -EIO;
+ }
return 0;
}
@@ -4227,11 +4389,15 @@ static int decode_create_session(struct xdr_stream *xdr,
return status;
/* sessionid */
- READ_BUF(NFS4_MAX_SESSIONID_LEN);
+ p = read_buf(xdr, NFS4_MAX_SESSIONID_LEN);
+ if (unlikely(!p))
+ return -EIO;
copymem(&session->sess_id, p, NFS4_MAX_SESSIONID_LEN);
/* seqid, flags */
- READ_BUF(8);
+ p = read_buf(xdr, 8);
+ if (unlikely(!p))
+ return -EIO;
p = xdr_decode_int(p, &clp->cl_seqid);
p = xdr_decode_int(p, &session->flags);
@@ -4273,7 +4439,9 @@ static int decode_sequence(struct xdr_stream *xdr,
status = -ESERVERFAULT;
slot = &res->sr_session->fc_slot_table.slots[res->sr_slotid];
- READ_BUF(NFS4_MAX_SESSIONID_LEN + 20);
+ p = read_buf(xdr, NFS4_MAX_SESSIONID_LEN + 20);
+ if (unlikely(!p))
+ return -EIO;
p = copymem(id.data, p, NFS4_MAX_SESSIONID_LEN);
if (memcmp(id.data, res->sr_session->sess_id.data,
NFS4_MAX_SESSIONID_LEN)) {
--
1.6.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [PATCH RFC 03/13] sunrpc: introduce 32-bit Xcoding helpers
2009-08-12 15:21 ` [PATCH RFC 03/13] sunrpc: introduce 32-bit Xcoding helpers Benny Halevy
@ 2009-08-12 20:12 ` Trond Myklebust
0 siblings, 0 replies; 20+ messages in thread
From: Trond Myklebust @ 2009-08-12 20:12 UTC (permalink / raw)
To: Benny Halevy; +Cc: linux-nfs
On Wed, 2009-08-12 at 18:21 +0300, Benny Halevy wrote:
> To be used instead of WRITE32/READ32.
>
> Signed-off-by: Benny Halevy <bhalevy@panasas.com>
> ---
> include/linux/sunrpc/xdr.h | 17 +++++++++++++++++
> 1 files changed, 17 insertions(+), 0 deletions(-)
>
> diff --git a/include/linux/sunrpc/xdr.h b/include/linux/sunrpc/xdr.h
> index 7da466b..466ea12 100644
> --- a/include/linux/sunrpc/xdr.h
> +++ b/include/linux/sunrpc/xdr.h
> @@ -112,6 +112,23 @@ static inline __be32 *xdr_encode_array(__be32 *p, const void *s, unsigned int le
> }
>
> /*
> + * Xcode 32bit quantities
> + */
> +static inline __be32 *
> +xdr_encode_int(__be32 *p, __u32 val)
> +{
> + *p = cpu_to_be32(val);
> + return p + 1;
> +}
> +
> +static inline __be32 *
> +xdr_decode_int(__be32 *p, __u32 *valp)
> +{
> + *valp = be32_to_cpu(*p);
> + return p + 1;
> +}
> +
> +/*
> * Decode 64bit quantities (NFSv3 support)
> */
> static inline __be32 *
These two functions are completely superfluous. Please just open code
trivial cases like these...
Cheers
Trond
--
Trond Myklebust
Linux NFS client maintainer
NetApp
Trond.Myklebust@netapp.com
www.netapp.com
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH RFC 12/13] nfs: nfs4xdr: change COPYMEM macro into a static function
2009-08-12 15:22 ` [PATCH RFC 12/13] nfs: nfs4xdr: change COPYMEM macro into a static function Benny Halevy
@ 2009-08-12 20:36 ` Trond Myklebust
0 siblings, 0 replies; 20+ messages in thread
From: Trond Myklebust @ 2009-08-12 20:36 UTC (permalink / raw)
To: Benny Halevy; +Cc: linux-nfs
On Wed, 2009-08-12 at 18:22 +0300, Benny Halevy wrote:
> Signed-off-by: Benny Halevy <bhalevy@panasas.com>
> ---
> fs/nfs/nfs4xdr.c | 39 ++++++++++++++++++++-------------------
> 1 files changed, 20 insertions(+), 19 deletions(-)
>
> diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
> index 2e83aef..ed9bbd2 100644
> --- a/fs/nfs/nfs4xdr.c
> +++ b/fs/nfs/nfs4xdr.c
> @@ -2448,11 +2448,6 @@ static int nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, uint32_t *p,
> * task to translate them into Linux-specific versions which are more
> * consistent with the style used in NFSv2/v3...
> */
> -#define COPYMEM(x,nbytes) do { \
> - memcpy((x), p, nbytes); \
> - p += XDR_QUADLEN(nbytes); \
> -} while (0)
> -
> #define READ_BUF(nbytes) do { \
> p = xdr_inline_decode(xdr, nbytes); \
> if (unlikely(!p)) { \
> @@ -2464,6 +2459,12 @@ static int nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, uint32_t *p,
> } \
> } while (0)
>
> +static __be32 *copymem(void *x, __be32 *p, u32 nbytes)
> +{
> + memcpy(x, p, nbytes);
> + return p + XDR_QUADLEN(nbytes);
> +}
> +
> static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
> {
> __be32 *p;
> @@ -3312,7 +3313,7 @@ static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
> if (status)
> return status;
> READ_BUF(NFS4_STATEID_SIZE);
> - COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
> + copymem(res->stateid.data, p, NFS4_STATEID_SIZE);
I wouldn't mind converting the above 2 lines into a dedicated
static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
{
__be32 *p;
p = xdr_inline_decode(xdr, NFS4_STATEID_SIZE);
if (p) {
memcpy(stateid->data, p, NFS4_STATEID_SIZE);
return 0;
}
dprintk(....);
return -EIO;
}
> return 0;
> }
>
> @@ -3325,7 +3326,7 @@ static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
> if (status)
> return status;
> READ_BUF(8);
> - COPYMEM(res->verf->verifier, 8);
> + copymem(res->verf->verifier, p, 8);
Ditto for this...
> return 0;
> }
>
> @@ -3601,7 +3602,7 @@ static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
> return -EIO;
> fh->size = len;
> READ_BUF(len);
> - COPYMEM(fh->data, len);
> + copymem(fh->data, p, len);
Open code as memcpy() since we don't need to update the value of 'p'.
> return 0;
> }
>
<snip lots of verifier and stateid decodes>
>
> @@ -4227,7 +4228,7 @@ static int decode_create_session(struct xdr_stream *xdr,
>
> /* sessionid */
> READ_BUF(NFS4_MAX_SESSIONID_LEN);
> - COPYMEM(&session->sess_id, NFS4_MAX_SESSIONID_LEN);
> + copymem(&session->sess_id, p, NFS4_MAX_SESSIONID_LEN);
Convert into a 'decode_session_id()' helper.
> /* seqid, flags */
> READ_BUF(8);
> @@ -4273,7 +4274,7 @@ static int decode_sequence(struct xdr_stream *xdr,
>
> slot = &res->sr_session->fc_slot_table.slots[res->sr_slotid];
> READ_BUF(NFS4_MAX_SESSIONID_LEN + 20);
> - COPYMEM(id.data, NFS4_MAX_SESSIONID_LEN);
> + p = copymem(id.data, p, NFS4_MAX_SESSIONID_LEN);
> if (memcmp(id.data, res->sr_session->sess_id.data,
> NFS4_MAX_SESSIONID_LEN)) {
> dprintk("%s Invalid session id\n", __func__);
--
Trond Myklebust
Linux NFS client maintainer
NetApp
Trond.Myklebust@netapp.com
www.netapp.com
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH RFC 13/13] nfs: nfs4xdr: get rid of READ_BUF
2009-08-12 15:22 ` [PATCH RFC 13/13] nfs: nfs4xdr: get rid of READ_BUF Benny Halevy
@ 2009-08-12 21:05 ` Trond Myklebust
0 siblings, 0 replies; 20+ messages in thread
From: Trond Myklebust @ 2009-08-12 21:05 UTC (permalink / raw)
To: Benny Halevy; +Cc: linux-nfs
On Wed, 2009-08-12 at 18:22 +0300, Benny Halevy wrote:
> Open code return pointer assignment and error checking using
> a read_buf helper (macro), yet keep the dprintk on failure using an
> internal __read_buf helper that gets the function name for printing.
>
> Signed-off-by: Benny Halevy <bhalevy@panasas.com>
> ---
> fs/nfs/nfs4xdr.c | 386 ++++++++++++++++++++++++++++++++++++++---------------
> 1 files changed, 277 insertions(+), 109 deletions(-)
>
> diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
> index ed9bbd2..fb10a77 100644
> --- a/fs/nfs/nfs4xdr.c
> +++ b/fs/nfs/nfs4xdr.c
> @@ -2438,26 +2438,17 @@ static int nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, uint32_t *p,
> }
> #endif /* CONFIG_NFS_V4_1 */
>
> -/*
> - * START OF "GENERIC" DECODE ROUTINES.
> - * These may look a little ugly since they are imported from a "generic"
> - * set of XDR encode/decode routines which are intended to be shared by
> - * all of our NFSv4 implementations (OpenBSD, MacOS X...).
> - *
> - * If the pain of reading these is too great, it should be a straightforward
> - * task to translate them into Linux-specific versions which are more
> - * consistent with the style used in NFSv2/v3...
> - */
> -#define READ_BUF(nbytes) do { \
> - p = xdr_inline_decode(xdr, nbytes); \
> - if (unlikely(!p)) { \
> - dprintk("nfs: %s: prematurely hit end of receive" \
> - " buffer\n", __func__); \
> - dprintk("nfs: %s: xdr->p=%p, bytes=%u, xdr->end=%p\n", \
> - __func__, xdr->p, nbytes, xdr->end); \
> - return -EIO; \
> - } \
> -} while (0)
> +static __be32 *__read_buf(struct xdr_stream *xdr, size_t nbytes, char *func)
> +{
> + __be32 *p = xdr_inline_decode(xdr, nbytes);
> + if (unlikely(!p))
> + dprintk("nfs: %s: prematurely hit end of receive buffer: "
> + "xdr->p=%p, bytes=%u, xdr->end=%p\n",
> + func, xdr->p, nbytes, xdr->end);
> + return p;
> +}
> +
> +#define read_buf(xdr, nbytes) __read_buf(xdr, nbytes, __func__)
>
> static __be32 *copymem(void *x, __be32 *p, u32 nbytes)
> {
> @@ -2469,9 +2460,13 @@ static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char
> {
> __be32 *p;
>
> - READ_BUF(4);
> + p = read_buf(xdr, 4);
> + if (unlikely(!p))
> + return -EIO;
> p = xdr_decode_int(p, len);
> - READ_BUF(*len);
> + p = read_buf(xdr, *len);
> + if (unlikely(!p))
> + return -EIO;
> *string = (char *)p;
> return 0;
> }
I'd do this a little differently.
static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
{
dprintk("nfs: %s: prematurely hit end of receive buffer."
"Remaining buffer length is %tu words.\n",
func, xdr->end - xdr->p);
}
static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
{
__be32 *p;
p = xdr_inline_decode(xdr, 4);
if (unlikely(!p))
goto out_overflow;
*len = be32_to_cpu(*p++);
p = xdr_inline_decode(xdr, *len);
if (unlikely(!p))
goto out_overflow;
*string = (char *)p;
return 0;
out_overflow:
print_overflow_msg(__func__, xdr);
return -EIO;
}
--
Trond Myklebust
Linux NFS client maintainer
NetApp
Trond.Myklebust@netapp.com
www.netapp.com
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH RFC 02/13] sunrpc: ntoh -> be*_to_cpu
2009-08-12 15:21 ` [PATCH RFC 02/13] sunrpc: ntoh -> be*_to_cpu Benny Halevy
@ 2009-09-12 14:00 ` Al Viro
2009-09-13 16:14 ` Benny Halevy
2009-09-15 16:05 ` [PATCH] sunrpc: xdr_xcode_hyper helpers cannot presume 64-bit alignment Benny Halevy
0 siblings, 2 replies; 20+ messages in thread
From: Al Viro @ 2009-09-12 14:00 UTC (permalink / raw)
To: Benny Halevy; +Cc: Trond Myklebust, linux-nfs
On Wed, Aug 12, 2009 at 06:21:48PM +0300, Benny Halevy wrote:
> ntohl is already defined as be32_to_cpu.
> be64_to_cpu has architecture specific optimized implementations.
> static inline __be32 *
> xdr_decode_hyper(__be32 *p, __u64 *valp)
> {
> - *valp = ((__u64) ntohl(*p++)) << 32;
> - *valp |= ntohl(*p++);
> - return p;
> + *valp = be64_to_cpup((__be64 *)p);
> + return p + 2;
> }
Erm... Who has promised you that p will be 64bit-aligned?
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH RFC 02/13] sunrpc: ntoh -> be*_to_cpu
2009-09-12 14:00 ` Al Viro
@ 2009-09-13 16:14 ` Benny Halevy
2009-09-15 16:05 ` [PATCH] sunrpc: xdr_xcode_hyper helpers cannot presume 64-bit alignment Benny Halevy
1 sibling, 0 replies; 20+ messages in thread
From: Benny Halevy @ 2009-09-13 16:14 UTC (permalink / raw)
To: Al Viro; +Cc: Trond Myklebust, linux-nfs
On Sep. 12, 2009, 17:00 +0300, Al Viro <viro@ZenIV.linux.org.uk> wrote:
> On Wed, Aug 12, 2009 at 06:21:48PM +0300, Benny Halevy wrote:
>> ntohl is already defined as be32_to_cpu.
>> be64_to_cpu has architecture specific optimized implementations.
>
>> static inline __be32 *
>> xdr_decode_hyper(__be32 *p, __u64 *valp)
>> {
>> - *valp = ((__u64) ntohl(*p++)) << 32;
>> - *valp |= ntohl(*p++);
>> - return p;
>> + *valp = be64_to_cpup((__be64 *)p);
>> + return p + 2;
>> }
>
> Erm... Who has promised you that p will be 64bit-aligned?
Good point.
The following should do then, right?
Benny
git diff --stat -p
include/linux/sunrpc/xdr.h | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/include/linux/sunrpc/xdr.h b/include/linux/sunrpc/xdr.h
index 7da466b..f5cc089 100644
--- a/include/linux/sunrpc/xdr.h
+++ b/include/linux/sunrpc/xdr.h
@@ -11,6 +11,7 @@
#include <linux/uio.h>
#include <asm/byteorder.h>
+#include <asm/unaligned.h>
#include <linux/scatterlist.h>
/*
@@ -117,14 +118,14 @@ static inline __be32 *xdr_encode_array(__be32 *p, const void *s, unsigned int le
static inline __be32 *
xdr_encode_hyper(__be32 *p, __u64 val)
{
- *(__be64 *)p = cpu_to_be64(val);
+ put_unaligned_be64(val, p);
return p + 2;
}
static inline __be32 *
xdr_decode_hyper(__be32 *p, __u64 *valp)
{
- *valp = be64_to_cpup((__be64 *)p);
+ *valp = get_unaligned_be64(p);
return p + 2;
}
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH] sunrpc: xdr_xcode_hyper helpers cannot presume 64-bit alignment
2009-09-12 14:00 ` Al Viro
2009-09-13 16:14 ` Benny Halevy
@ 2009-09-15 16:05 ` Benny Halevy
1 sibling, 0 replies; 20+ messages in thread
From: Benny Halevy @ 2009-09-15 16:05 UTC (permalink / raw)
To: Trond Myklebust; +Cc: linux-nfs, Al Viro
Signed-off-by: Benny Halevy <bhalevy@panasas.com>
---
include/linux/sunrpc/xdr.h | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/include/linux/sunrpc/xdr.h b/include/linux/sunrpc/xdr.h
index 7da466b..f5cc089 100644
--- a/include/linux/sunrpc/xdr.h
+++ b/include/linux/sunrpc/xdr.h
@@ -11,6 +11,7 @@
#include <linux/uio.h>
#include <asm/byteorder.h>
+#include <asm/unaligned.h>
#include <linux/scatterlist.h>
/*
@@ -117,14 +118,14 @@ static inline __be32 *xdr_encode_array(__be32 *p, const void *s, unsigned int le
static inline __be32 *
xdr_encode_hyper(__be32 *p, __u64 val)
{
- *(__be64 *)p = cpu_to_be64(val);
+ put_unaligned_be64(val, p);
return p + 2;
}
static inline __be32 *
xdr_decode_hyper(__be32 *p, __u64 *valp)
{
- *valp = be64_to_cpup((__be64 *)p);
+ *valp = get_unaligned_be64(p);
return p + 2;
}
--
1.6.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
end of thread, other threads:[~2009-09-15 16:04 UTC | newest]
Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-12 15:15 [PATCH RFC 0/13] xdr macros cleanup Benny Halevy
2009-08-12 15:21 ` [PATCH RFC 01/13] sunrpc: hton -> cpu_to_be* Benny Halevy
2009-08-12 15:21 ` [PATCH RFC 02/13] sunrpc: ntoh -> be*_to_cpu Benny Halevy
2009-09-12 14:00 ` Al Viro
2009-09-13 16:14 ` Benny Halevy
2009-09-15 16:05 ` [PATCH] sunrpc: xdr_xcode_hyper helpers cannot presume 64-bit alignment Benny Halevy
2009-08-12 15:21 ` [PATCH RFC 03/13] sunrpc: introduce 32-bit Xcoding helpers Benny Halevy
2009-08-12 20:12 ` Trond Myklebust
2009-08-12 15:21 ` [PATCH RFC 04/13] nfs: nfs4xdr: get rid of WRITE32 Benny Halevy
2009-08-12 15:22 ` [PATCH RFC 05/13] nfs: nfs4xdr: get rid of WRITE64 Benny Halevy
2009-08-12 15:22 ` [PATCH RFC 06/13] nfs: nfs4xdr: get rid of WRITEMEM Benny Halevy
2009-08-12 15:22 ` [PATCH RFC 07/13] nfs: nfs4xdr: merge xdr_encode_int+xdr_encode_opaque_fixed into xdr_encode_opaque Benny Halevy
2009-08-12 15:22 ` [PATCH RFC 08/13] nfs: nfs4xdr: change RESERVE_SPACE macro into a static helper Benny Halevy
2009-08-12 15:22 ` [PATCH RFC 09/13] nfs: nfs4xdr: get rid of READ32 Benny Halevy
2009-08-12 15:22 ` [PATCH RFC 10/13] nfs: nfs4xdr: get rid of READ64 Benny Halevy
2009-08-12 15:22 ` [PATCH RFC 11/13] nfs: nfs4xdr: get rid of READTIME macro Benny Halevy
2009-08-12 15:22 ` [PATCH RFC 12/13] nfs: nfs4xdr: change COPYMEM macro into a static function Benny Halevy
2009-08-12 20:36 ` Trond Myklebust
2009-08-12 15:22 ` [PATCH RFC 13/13] nfs: nfs4xdr: get rid of READ_BUF Benny Halevy
2009-08-12 21:05 ` Trond Myklebust
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).