Merge commit 'v2.6.30' into for-2.6.31
[safe/jmp/linux-2.6] / fs / nfs / callback_xdr.c
index c99677e..dd0ef34 100644 (file)
@@ -5,7 +5,6 @@
  *
  * NFSv4 callback encode/decode procedures
  */
-#include <linux/config.h>
 #include <linux/kernel.h>
 #include <linux/sunrpc/svc.h>
 #include <linux/nfs4.h>
@@ -23,9 +22,9 @@
 
 #define NFSDBG_FACILITY NFSDBG_CALLBACK
 
-typedef unsigned (*callback_process_op_t)(void *, void *);
-typedef unsigned (*callback_decode_arg_t)(struct svc_rqst *, struct xdr_stream *, void *);
-typedef unsigned (*callback_encode_res_t)(struct svc_rqst *, struct xdr_stream *, void *);
+typedef __be32 (*callback_process_op_t)(void *, void *);
+typedef __be32 (*callback_decode_arg_t)(struct svc_rqst *, struct xdr_stream *, void *);
+typedef __be32 (*callback_encode_res_t)(struct svc_rqst *, struct xdr_stream *, void *);
 
 
 struct callback_op {
@@ -37,24 +36,24 @@ struct callback_op {
 
 static struct callback_op callback_ops[];
 
-static int nfs4_callback_null(struct svc_rqst *rqstp, void *argp, void *resp)
+static __be32 nfs4_callback_null(struct svc_rqst *rqstp, void *argp, void *resp)
 {
        return htonl(NFS4_OK);
 }
 
-static int nfs4_decode_void(struct svc_rqst *rqstp, uint32_t *p, void *dummy)
+static int nfs4_decode_void(struct svc_rqst *rqstp, __be32 *p, void *dummy)
 {
        return xdr_argsize_check(rqstp, p);
 }
 
-static int nfs4_encode_void(struct svc_rqst *rqstp, uint32_t *p, void *dummy)
+static int nfs4_encode_void(struct svc_rqst *rqstp, __be32 *p, void *dummy)
 {
        return xdr_ressize_check(rqstp, p);
 }
 
-static uint32_t *read_buf(struct xdr_stream *xdr, int nbytes)
+static __be32 *read_buf(struct xdr_stream *xdr, int nbytes)
 {
-       uint32_t *p;
+       __be32 *p;
 
        p = xdr_inline_decode(xdr, nbytes);
        if (unlikely(p == NULL))
@@ -62,9 +61,9 @@ static uint32_t *read_buf(struct xdr_stream *xdr, int nbytes)
        return p;
 }
 
-static unsigned decode_string(struct xdr_stream *xdr, unsigned int *len, const char **str)
+static __be32 decode_string(struct xdr_stream *xdr, unsigned int *len, const char **str)
 {
-       uint32_t *p;
+       __be32 *p;
 
        p = read_buf(xdr, 4);
        if (unlikely(p == NULL))
@@ -82,9 +81,9 @@ static unsigned decode_string(struct xdr_stream *xdr, unsigned int *len, const c
        return 0;
 }
 
-static unsigned decode_fh(struct xdr_stream *xdr, struct nfs_fh *fh)
+static __be32 decode_fh(struct xdr_stream *xdr, struct nfs_fh *fh)
 {
-       uint32_t *p;
+       __be32 *p;
 
        p = read_buf(xdr, 4);
        if (unlikely(p == NULL))
@@ -100,9 +99,9 @@ static unsigned decode_fh(struct xdr_stream *xdr, struct nfs_fh *fh)
        return 0;
 }
 
-static unsigned decode_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
+static __be32 decode_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
 {
-       uint32_t *p;
+       __be32 *p;
        unsigned int attrlen;
 
        p = read_buf(xdr, 4);
@@ -119,9 +118,9 @@ static unsigned decode_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
        return 0;
 }
 
-static unsigned decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
+static __be32 decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
 {
-       uint32_t *p;
+       __be32 *p;
 
        p = read_buf(xdr, 16);
        if (unlikely(p == NULL))
@@ -130,19 +129,19 @@ static unsigned decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
        return 0;
 }
 
-static unsigned decode_compound_hdr_arg(struct xdr_stream *xdr, struct cb_compound_hdr_arg *hdr)
+static __be32 decode_compound_hdr_arg(struct xdr_stream *xdr, struct cb_compound_hdr_arg *hdr)
 {
-       uint32_t *p;
+       __be32 *p;
        unsigned int minor_version;
-       unsigned status;
+       __be32 status;
 
        status = decode_string(xdr, &hdr->taglen, &hdr->tag);
        if (unlikely(status != 0))
                return status;
        /* We do not like overly long tags! */
-       if (hdr->taglen > CB_OP_TAGLEN_MAXSZ-12 || hdr->taglen < 0) {
+       if (hdr->taglen > CB_OP_TAGLEN_MAXSZ - 12) {
                printk("NFSv4 CALLBACK %s: client sent tag of length %u\n",
-                               __FUNCTION__, hdr->taglen);
+                               __func__, hdr->taglen);
                return htonl(NFS4ERR_RESOURCE);
        }
        p = read_buf(xdr, 12);
@@ -152,7 +151,7 @@ static unsigned decode_compound_hdr_arg(struct xdr_stream *xdr, struct cb_compou
        /* Check minor version is zero. */
        if (minor_version != 0) {
                printk(KERN_WARNING "%s: NFSv4 server callback with illegal minor version %u!\n",
-                               __FUNCTION__, minor_version);
+                               __func__, minor_version);
                return htonl(NFS4ERR_MINOR_VERS_MISMATCH);
        }
        hdr->callback_ident = ntohl(*p++);
@@ -160,9 +159,9 @@ static unsigned decode_compound_hdr_arg(struct xdr_stream *xdr, struct cb_compou
        return 0;
 }
 
-static unsigned decode_op_hdr(struct xdr_stream *xdr, unsigned int *op)
+static __be32 decode_op_hdr(struct xdr_stream *xdr, unsigned int *op)
 {
-       uint32_t *p;
+       __be32 *p;
        p = read_buf(xdr, 4);
        if (unlikely(p == NULL))
                return htonl(NFS4ERR_RESOURCE);
@@ -170,26 +169,26 @@ static unsigned decode_op_hdr(struct xdr_stream *xdr, unsigned int *op)
        return 0;
 }
 
-static unsigned decode_getattr_args(struct svc_rqst *rqstp, struct xdr_stream *xdr, struct cb_getattrargs *args)
+static __be32 decode_getattr_args(struct svc_rqst *rqstp, struct xdr_stream *xdr, struct cb_getattrargs *args)
 {
-       unsigned status;
+       __be32 status;
 
        status = decode_fh(xdr, &args->fh);
        if (unlikely(status != 0))
                goto out;
-       args->addr = &rqstp->rq_addr;
+       args->addr = svc_addr(rqstp);
        status = decode_bitmap(xdr, args->bitmap);
 out:
-       dprintk("%s: exit with status = %d\n", __FUNCTION__, status);
+       dprintk("%s: exit with status = %d\n", __func__, ntohl(status));
        return status;
 }
 
-static unsigned decode_recall_args(struct svc_rqst *rqstp, struct xdr_stream *xdr, struct cb_recallargs *args)
+static __be32 decode_recall_args(struct svc_rqst *rqstp, struct xdr_stream *xdr, struct cb_recallargs *args)
 {
-       uint32_t *p;
-       unsigned status;
+       __be32 *p;
+       __be32 status;
 
-       args->addr = &rqstp->rq_addr;
+       args->addr = svc_addr(rqstp);
        status = decode_stateid(xdr, &args->stateid);
        if (unlikely(status != 0))
                goto out;
@@ -201,13 +200,13 @@ static unsigned decode_recall_args(struct svc_rqst *rqstp, struct xdr_stream *xd
        args->truncate = ntohl(*p);
        status = decode_fh(xdr, &args->fh);
 out:
-       dprintk("%s: exit with status = %d\n", __FUNCTION__, status);
-       return 0;
+       dprintk("%s: exit with status = %d\n", __func__, ntohl(status));
+       return status;
 }
 
-static unsigned encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
+static __be32 encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
 {
-       uint32_t *p;
+       __be32 *p;
 
        p = xdr_reserve_space(xdr, 4 + len);
        if (unlikely(p == NULL))
@@ -218,10 +217,10 @@ static unsigned encode_string(struct xdr_stream *xdr, unsigned int len, const ch
 
 #define CB_SUPPORTED_ATTR0 (FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE)
 #define CB_SUPPORTED_ATTR1 (FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY)
-static unsigned encode_attr_bitmap(struct xdr_stream *xdr, const uint32_t *bitmap, uint32_t **savep)
+static __be32 encode_attr_bitmap(struct xdr_stream *xdr, const uint32_t *bitmap, __be32 **savep)
 {
-       uint32_t bm[2];
-       uint32_t *p;
+       __be32 bm[2];
+       __be32 *p;
 
        bm[0] = htonl(bitmap[0] & CB_SUPPORTED_ATTR0);
        bm[1] = htonl(bitmap[1] & CB_SUPPORTED_ATTR1);
@@ -248,61 +247,61 @@ static unsigned encode_attr_bitmap(struct xdr_stream *xdr, const uint32_t *bitma
        return 0;
 }
 
-static unsigned encode_attr_change(struct xdr_stream *xdr, const uint32_t *bitmap, uint64_t change)
+static __be32 encode_attr_change(struct xdr_stream *xdr, const uint32_t *bitmap, uint64_t change)
 {
-       uint32_t *p;
+       __be32 *p;
 
        if (!(bitmap[0] & FATTR4_WORD0_CHANGE))
                return 0;
        p = xdr_reserve_space(xdr, 8);
-       if (unlikely(p == 0))
+       if (unlikely(!p))
                return htonl(NFS4ERR_RESOURCE);
        p = xdr_encode_hyper(p, change);
        return 0;
 }
 
-static unsigned encode_attr_size(struct xdr_stream *xdr, const uint32_t *bitmap, uint64_t size)
+static __be32 encode_attr_size(struct xdr_stream *xdr, const uint32_t *bitmap, uint64_t size)
 {
-       uint32_t *p;
+       __be32 *p;
 
        if (!(bitmap[0] & FATTR4_WORD0_SIZE))
                return 0;
        p = xdr_reserve_space(xdr, 8);
-       if (unlikely(p == 0))
+       if (unlikely(!p))
                return htonl(NFS4ERR_RESOURCE);
        p = xdr_encode_hyper(p, size);
        return 0;
 }
 
-static unsigned encode_attr_time(struct xdr_stream *xdr, const struct timespec *time)
+static __be32 encode_attr_time(struct xdr_stream *xdr, const struct timespec *time)
 {
-       uint32_t *p;
+       __be32 *p;
 
        p = xdr_reserve_space(xdr, 12);
-       if (unlikely(p == 0))
+       if (unlikely(!p))
                return htonl(NFS4ERR_RESOURCE);
        p = xdr_encode_hyper(p, time->tv_sec);
        *p = htonl(time->tv_nsec);
        return 0;
 }
 
-static unsigned encode_attr_ctime(struct xdr_stream *xdr, const uint32_t *bitmap, const struct timespec *time)
+static __be32 encode_attr_ctime(struct xdr_stream *xdr, const uint32_t *bitmap, const struct timespec *time)
 {
        if (!(bitmap[1] & FATTR4_WORD1_TIME_METADATA))
                return 0;
        return encode_attr_time(xdr,time);
 }
 
-static unsigned encode_attr_mtime(struct xdr_stream *xdr, const uint32_t *bitmap, const struct timespec *time)
+static __be32 encode_attr_mtime(struct xdr_stream *xdr, const uint32_t *bitmap, const struct timespec *time)
 {
        if (!(bitmap[1] & FATTR4_WORD1_TIME_MODIFY))
                return 0;
        return encode_attr_time(xdr,time);
 }
 
-static unsigned encode_compound_hdr_res(struct xdr_stream *xdr, struct cb_compound_hdr_res *hdr)
+static __be32 encode_compound_hdr_res(struct xdr_stream *xdr, struct cb_compound_hdr_res *hdr)
 {
-       unsigned status;
+       __be32 status;
 
        hdr->status = xdr_reserve_space(xdr, 4);
        if (unlikely(hdr->status == NULL))
@@ -316,9 +315,9 @@ static unsigned encode_compound_hdr_res(struct xdr_stream *xdr, struct cb_compou
        return 0;
 }
 
-static unsigned encode_op_hdr(struct xdr_stream *xdr, uint32_t op, uint32_t res)
+static __be32 encode_op_hdr(struct xdr_stream *xdr, uint32_t op, __be32 res)
 {
-       uint32_t *p;
+       __be32 *p;
        
        p = xdr_reserve_space(xdr, 8);
        if (unlikely(p == NULL))
@@ -328,10 +327,10 @@ static unsigned encode_op_hdr(struct xdr_stream *xdr, uint32_t op, uint32_t res)
        return 0;
 }
 
-static unsigned encode_getattr_res(struct svc_rqst *rqstp, struct xdr_stream *xdr, const struct cb_getattrres *res)
+static __be32 encode_getattr_res(struct svc_rqst *rqstp, struct xdr_stream *xdr, const struct cb_getattrres *res)
 {
-       uint32_t *savep;
-       unsigned status = res->status;
+       __be32 *savep = NULL;
+       __be32 status = res->status;
        
        if (unlikely(status != 0))
                goto out;
@@ -350,31 +349,34 @@ static unsigned encode_getattr_res(struct svc_rqst *rqstp, struct xdr_stream *xd
        status = encode_attr_mtime(xdr, res->bitmap, &res->mtime);
        *savep = htonl((unsigned int)((char *)xdr->p - (char *)(savep+1)));
 out:
-       dprintk("%s: exit with status = %d\n", __FUNCTION__, status);
+       dprintk("%s: exit with status = %d\n", __func__, ntohl(status));
        return status;
 }
 
-static unsigned process_op(struct svc_rqst *rqstp,
+static __be32 process_op(struct svc_rqst *rqstp,
                struct xdr_stream *xdr_in, void *argp,
                struct xdr_stream *xdr_out, void *resp)
 {
-       struct callback_op *op;
-       unsigned int op_nr;
-       unsigned int status = 0;
+       struct callback_op *op = &callback_ops[0];
+       unsigned int op_nr = OP_CB_ILLEGAL;
+       __be32 status = 0;
        long maxlen;
-       unsigned res;
+       __be32 res;
 
-       dprintk("%s: start\n", __FUNCTION__);
+       dprintk("%s: start\n", __func__);
        status = decode_op_hdr(xdr_in, &op_nr);
-       if (unlikely(status != 0)) {
-               op_nr = OP_CB_ILLEGAL;
-               op = &callback_ops[0];
-       } else if (unlikely(op_nr != OP_CB_GETATTR && op_nr != OP_CB_RECALL)) {
-               op_nr = OP_CB_ILLEGAL;
-               op = &callback_ops[0];
-               status = htonl(NFS4ERR_OP_ILLEGAL);
-       } else
-               op = &callback_ops[op_nr];
+       if (likely(status == 0)) {
+               switch (op_nr) {
+                       case OP_CB_GETATTR:
+                       case OP_CB_RECALL:
+                               op = &callback_ops[op_nr];
+                               break;
+                       default:
+                               op_nr = OP_CB_ILLEGAL;
+                               op = &callback_ops[0];
+                               status = htonl(NFS4ERR_OP_ILLEGAL);
+               }
+       }
 
        maxlen = xdr_out->end - xdr_out->p;
        if (maxlen > 0 && maxlen < PAGE_SIZE) {
@@ -390,46 +392,46 @@ static unsigned process_op(struct svc_rqst *rqstp,
                status = res;
        if (op->encode_res != NULL && status == 0)
                status = op->encode_res(rqstp, xdr_out, resp);
-       dprintk("%s: done, status = %d\n", __FUNCTION__, status);
+       dprintk("%s: done, status = %d\n", __func__, ntohl(status));
        return status;
 }
 
 /*
  * Decode, process and encode a COMPOUND
  */
-static int nfs4_callback_compound(struct svc_rqst *rqstp, void *argp, void *resp)
+static __be32 nfs4_callback_compound(struct svc_rqst *rqstp, void *argp, void *resp)
 {
-       struct cb_compound_hdr_arg hdr_arg;
-       struct cb_compound_hdr_res hdr_res;
+       struct cb_compound_hdr_arg hdr_arg = { 0 };
+       struct cb_compound_hdr_res hdr_res = { NULL };
        struct xdr_stream xdr_in, xdr_out;
-       uint32_t *p;
-       unsigned int status;
-       unsigned int nops = 1;
+       __be32 *p;
+       __be32 status;
+       unsigned int nops = 0;
 
-       dprintk("%s: start\n", __FUNCTION__);
+       dprintk("%s: start\n", __func__);
 
        xdr_init_decode(&xdr_in, &rqstp->rq_arg, rqstp->rq_arg.head[0].iov_base);
 
-       p = (uint32_t*)((char *)rqstp->rq_res.head[0].iov_base + rqstp->rq_res.head[0].iov_len);
-       rqstp->rq_res.head[0].iov_len = PAGE_SIZE;
+       p = (__be32*)((char *)rqstp->rq_res.head[0].iov_base + rqstp->rq_res.head[0].iov_len);
        xdr_init_encode(&xdr_out, &rqstp->rq_res, p);
 
-       decode_compound_hdr_arg(&xdr_in, &hdr_arg);
+       status = decode_compound_hdr_arg(&xdr_in, &hdr_arg);
+       if (status == __constant_htonl(NFS4ERR_RESOURCE))
+               return rpc_garbage_args;
+
        hdr_res.taglen = hdr_arg.taglen;
        hdr_res.tag = hdr_arg.tag;
-       encode_compound_hdr_res(&xdr_out, &hdr_res);
+       if (encode_compound_hdr_res(&xdr_out, &hdr_res) != 0)
+               return rpc_system_err;
 
-       for (;;) {
+       while (status == 0 && nops != hdr_arg.nops) {
                status = process_op(rqstp, &xdr_in, argp, &xdr_out, resp);
-               if (status != 0)
-                       break;
-               if (nops == hdr_arg.nops)
-                       break;
                nops++;
        }
+
        *hdr_res.status = status;
        *hdr_res.nops = htonl(nops);
-       dprintk("%s: done, status = %u\n", __FUNCTION__, status);
+       dprintk("%s: done, status = %u\n", __func__, ntohl(status));
        return rpc_success;
 }