nfs41: Handle session errors during delegation return
[safe/jmp/linux-2.6] / fs / nfs / nfs3xdr.c
index fb03048..5fe5492 100644 (file)
@@ -10,7 +10,6 @@
 #include <linux/time.h>
 #include <linux/mm.h>
 #include <linux/slab.h>
-#include <linux/utsname.h>
 #include <linux/errno.h>
 #include <linux/string.h>
 #include <linux/in.h>
 #define NFS3_commitres_sz      (1+NFS3_wcc_data_sz+2)
 
 #define ACL3_getaclargs_sz     (NFS3_fh_sz+1)
-#define ACL3_setaclargs_sz     (NFS3_fh_sz+1+2*(2+5*3))
-#define ACL3_getaclres_sz      (1+NFS3_post_op_attr_sz+1+2*(2+5*3))
+#define ACL3_setaclargs_sz     (NFS3_fh_sz+1+ \
+                               XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
+#define ACL3_getaclres_sz      (1+NFS3_post_op_attr_sz+1+ \
+                               XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
 #define ACL3_setaclres_sz      (1+NFS3_post_op_attr_sz)
 
 /*
  * Map file type to S_IFMT bits
  */
-static struct {
-       unsigned int    mode;
-       unsigned int    nfs2type;
-} nfs_type2fmt[] = {
-      { 0,             NFNON   },
-      { S_IFREG,       NFREG   },
-      { S_IFDIR,       NFDIR   },
-      { S_IFBLK,       NFBLK   },
-      { S_IFCHR,       NFCHR   },
-      { S_IFLNK,       NFLNK   },
-      { S_IFSOCK,      NFSOCK  },
-      { S_IFIFO,       NFFIFO  },
-      { 0,             NFBAD   }
+static const umode_t nfs_type2fmt[] = {
+       [NF3BAD] = 0,
+       [NF3REG] = S_IFREG,
+       [NF3DIR] = S_IFDIR,
+       [NF3BLK] = S_IFBLK,
+       [NF3CHR] = S_IFCHR,
+       [NF3LNK] = S_IFLNK,
+       [NF3SOCK] = S_IFSOCK,
+       [NF3FIFO] = S_IFIFO,
 };
 
 /*
@@ -146,13 +143,12 @@ static __be32 *
 xdr_decode_fattr(__be32 *p, struct nfs_fattr *fattr)
 {
        unsigned int    type, major, minor;
-       int             fmode;
+       umode_t         fmode;
 
        type = ntohl(*p++);
-       if (type >= NF3BAD)
-               type = NF3BAD;
-       fmode = nfs_type2fmt[type].mode;
-       fattr->type = nfs_type2fmt[type].nfs2type;
+       if (type > NF3FIFO)
+               type = NF3NON;
+       fmode = nfs_type2fmt[type];
        fattr->mode = (ntohl(*p++) & ~S_IFMT) | fmode;
        fattr->nlink = ntohl(*p++);
        fattr->uid = ntohl(*p++);
@@ -175,7 +171,7 @@ xdr_decode_fattr(__be32 *p, struct nfs_fattr *fattr)
        p = xdr_decode_time3(p, &fattr->ctime);
 
        /* Update the mode bits */
-       fattr->valid |= (NFS_ATTR_FATTR | NFS_ATTR_FATTR_V3);
+       fattr->valid |= NFS_ATTR_FATTR_V3;
        return p;
 }
 
@@ -231,7 +227,9 @@ xdr_decode_wcc_attr(__be32 *p, struct nfs_fattr *fattr)
        p = xdr_decode_hyper(p, &fattr->pre_size);
        p = xdr_decode_time3(p, &fattr->pre_mtime);
        p = xdr_decode_time3(p, &fattr->pre_ctime);
-       fattr->valid |= NFS_ATTR_WCC;
+       fattr->valid |= NFS_ATTR_FATTR_PRESIZE
+               | NFS_ATTR_FATTR_PREMTIME
+               | NFS_ATTR_FATTR_PRECTIME;
        return p;
 }
 
@@ -515,7 +513,7 @@ nfs3_xdr_readdirres(struct rpc_rqst *req, __be32 *p, struct nfs3_readdirres *res
        /* Decode post_op_attrs */
        p = xdr_decode_post_op_attr(p, res->dir_attr);
        if (status)
-               return -nfs_stat_to_errno(status);
+               return nfs_stat_to_errno(status);
        /* Decode verifier cookie */
        if (res->verf) {
                res->verf[0] = *p++;
@@ -703,28 +701,19 @@ nfs3_xdr_setaclargs(struct rpc_rqst *req, __be32 *p,
                    struct nfs3_setaclargs *args)
 {
        struct xdr_buf *buf = &req->rq_snd_buf;
-       unsigned int base, len_in_head, len = nfsacl_size(
-               (args->mask & NFS_ACL)   ? args->acl_access  : NULL,
-               (args->mask & NFS_DFACL) ? args->acl_default : NULL);
-       int count, err;
+       unsigned int base;
+       int err;
 
        p = xdr_encode_fhandle(p, NFS_FH(args->inode));
        *p++ = htonl(args->mask);
-       base = (char *)p - (char *)buf->head->iov_base;
-       /* put as much of the acls into head as possible. */
-       len_in_head = min_t(unsigned int, buf->head->iov_len - base, len);
-       len -= len_in_head;
-       req->rq_slen = xdr_adjust_iovec(req->rq_svec, p + (len_in_head >> 2));
-
-       for (count = 0; (count << PAGE_SHIFT) < len; count++) {
-               args->pages[count] = alloc_page(GFP_KERNEL);
-               if (!args->pages[count]) {
-                       while (count)
-                               __free_page(args->pages[--count]);
-                       return -ENOMEM;
-               }
-       }
-       xdr_encode_pages(buf, args->pages, 0, len);
+       req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
+       base = req->rq_slen;
+
+       if (args->npages != 0)
+               xdr_encode_pages(buf, args->pages, 0, args->len);
+       else
+               req->rq_slen = xdr_adjust_iovec(req->rq_svec,
+                               p + XDR_QUADLEN(args->len));
 
        err = nfsacl_encode(buf, base, args->inode,
                            (args->mask & NFS_ACL) ?
@@ -751,7 +740,7 @@ nfs3_xdr_attrstat(struct rpc_rqst *req, __be32 *p, struct nfs_fattr *fattr)
        int     status;
 
        if ((status = ntohl(*p++)))
-               return -nfs_stat_to_errno(status);
+               return nfs_stat_to_errno(status);
        xdr_decode_fattr(p, fattr);
        return 0;
 }
@@ -766,7 +755,7 @@ nfs3_xdr_wccstat(struct rpc_rqst *req, __be32 *p, struct nfs_fattr *fattr)
        int     status;
 
        if ((status = ntohl(*p++)))
-               status = -nfs_stat_to_errno(status);
+               status = nfs_stat_to_errno(status);
        xdr_decode_wcc_data(p, fattr);
        return status;
 }
@@ -786,7 +775,7 @@ nfs3_xdr_lookupres(struct rpc_rqst *req, __be32 *p, struct nfs3_diropres *res)
        int     status;
 
        if ((status = ntohl(*p++))) {
-               status = -nfs_stat_to_errno(status);
+               status = nfs_stat_to_errno(status);
        } else {
                if (!(p = xdr_decode_fhandle(p, res->fh)))
                        return -errno_NFSERR_IO;
@@ -806,7 +795,7 @@ nfs3_xdr_accessres(struct rpc_rqst *req, __be32 *p, struct nfs3_accessres *res)
 
        p = xdr_decode_post_op_attr(p, res->fattr);
        if (status)
-               return -nfs_stat_to_errno(status);
+               return nfs_stat_to_errno(status);
        res->access = ntohl(*p++);
        return 0;
 }
@@ -843,7 +832,7 @@ nfs3_xdr_readlinkres(struct rpc_rqst *req, __be32 *p, struct nfs_fattr *fattr)
        p = xdr_decode_post_op_attr(p, fattr);
 
        if (status != 0)
-               return -nfs_stat_to_errno(status);
+               return nfs_stat_to_errno(status);
 
        /* Convert length of symlink */
        len = ntohl(*p++);
@@ -891,7 +880,7 @@ nfs3_xdr_readres(struct rpc_rqst *req, __be32 *p, struct nfs_readres *res)
        p = xdr_decode_post_op_attr(p, res->fattr);
 
        if (status != 0)
-               return -nfs_stat_to_errno(status);
+               return nfs_stat_to_errno(status);
 
        /* Decode reply count and EOF flag. NFSv3 is somewhat redundant
         * in that it puts the count both in the res struct and in the
@@ -941,7 +930,7 @@ nfs3_xdr_writeres(struct rpc_rqst *req, __be32 *p, struct nfs_writeres *res)
        p = xdr_decode_wcc_data(p, res->fattr);
 
        if (status != 0)
-               return -nfs_stat_to_errno(status);
+               return nfs_stat_to_errno(status);
 
        res->count = ntohl(*p++);
        res->verf->committed = (enum nfs3_stable_how)ntohl(*p++);
@@ -972,7 +961,7 @@ nfs3_xdr_createres(struct rpc_rqst *req, __be32 *p, struct nfs3_diropres *res)
                        res->fattr->valid = 0;
                }
        } else {
-               status = -nfs_stat_to_errno(status);
+               status = nfs_stat_to_errno(status);
        }
        p = xdr_decode_wcc_data(p, res->dir_attr);
        return status;
@@ -987,7 +976,7 @@ nfs3_xdr_renameres(struct rpc_rqst *req, __be32 *p, struct nfs3_renameres *res)
        int     status;
 
        if ((status = ntohl(*p++)) != 0)
-               status = -nfs_stat_to_errno(status);
+               status = nfs_stat_to_errno(status);
        p = xdr_decode_wcc_data(p, res->fromattr);
        p = xdr_decode_wcc_data(p, res->toattr);
        return status;
@@ -1002,7 +991,7 @@ nfs3_xdr_linkres(struct rpc_rqst *req, __be32 *p, struct nfs3_linkres *res)
        int     status;
 
        if ((status = ntohl(*p++)) != 0)
-               status = -nfs_stat_to_errno(status);
+               status = nfs_stat_to_errno(status);
        p = xdr_decode_post_op_attr(p, res->fattr);
        p = xdr_decode_wcc_data(p, res->dir_attr);
        return status;
@@ -1020,7 +1009,7 @@ nfs3_xdr_fsstatres(struct rpc_rqst *req, __be32 *p, struct nfs_fsstat *res)
 
        p = xdr_decode_post_op_attr(p, res->fattr);
        if (status != 0)
-               return -nfs_stat_to_errno(status);
+               return nfs_stat_to_errno(status);
 
        p = xdr_decode_hyper(p, &res->tbytes);
        p = xdr_decode_hyper(p, &res->fbytes);
@@ -1045,7 +1034,7 @@ nfs3_xdr_fsinfores(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *res)
 
        p = xdr_decode_post_op_attr(p, res->fattr);
        if (status != 0)
-               return -nfs_stat_to_errno(status);
+               return nfs_stat_to_errno(status);
 
        res->rtmax  = ntohl(*p++);
        res->rtpref = ntohl(*p++);
@@ -1073,7 +1062,7 @@ nfs3_xdr_pathconfres(struct rpc_rqst *req, __be32 *p, struct nfs_pathconf *res)
 
        p = xdr_decode_post_op_attr(p, res->fattr);
        if (status != 0)
-               return -nfs_stat_to_errno(status);
+               return nfs_stat_to_errno(status);
        res->max_link = ntohl(*p++);
        res->max_namelen = ntohl(*p++);
 
@@ -1092,7 +1081,7 @@ nfs3_xdr_commitres(struct rpc_rqst *req, __be32 *p, struct nfs_writeres *res)
        status = ntohl(*p++);
        p = xdr_decode_wcc_data(p, res->fattr);
        if (status != 0)
-               return -nfs_stat_to_errno(status);
+               return nfs_stat_to_errno(status);
 
        res->verf->verifier[0] = *p++;
        res->verf->verifier[1] = *p++;
@@ -1114,7 +1103,7 @@ nfs3_xdr_getaclres(struct rpc_rqst *req, __be32 *p,
        int err, base;
 
        if (status != 0)
-               return -nfs_stat_to_errno(status);
+               return nfs_stat_to_errno(status);
        p = xdr_decode_post_op_attr(p, res->fattr);
        res->mask = ntohl(*p++);
        if (res->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT))
@@ -1141,7 +1130,7 @@ nfs3_xdr_setaclres(struct rpc_rqst *req, __be32 *p, struct nfs_fattr *fattr)
        int status = ntohl(*p++);
 
        if (status)
-               return -nfs_stat_to_errno(status);
+               return nfs_stat_to_errno(status);
        xdr_decode_post_op_attr(p, fattr);
        return 0;
 }