nfsd4: use xdr_stream throughout compound encoding
authorJ. Bruce Fields <bfields@redhat.com>
Wed, 26 Feb 2014 22:00:38 +0000 (17:00 -0500)
committerJ. Bruce Fields <bfields@redhat.com>
Wed, 28 May 2014 18:52:35 +0000 (14:52 -0400)
Note this makes ADJUST_ARGS useless; we'll remove it in the following
patch.

Signed-off-by: J. Bruce Fields <bfields@redhat.com>
fs/nfsd/nfs4proc.c
fs/nfsd/nfs4xdr.c

index 41c7c0a3ddd019f48e607e6f00e872388d8674e4..109b5a84b5489cac9e006a75eed2e82a3de1a245 100644 (file)
@@ -1284,7 +1284,7 @@ nfsd4_proc_compound(struct svc_rqst *rqstp,
        svcxdr_init_encode(rqstp, resp);
        resp->tagp = resp->xdr.p;
        /* reserve space for: taglen, tag, and opcnt */
-       resp->xdr.p += 2 + XDR_QUADLEN(args->taglen);
+       xdr_reserve_space(&resp->xdr, 8 + args->taglen);
        resp->taglen = args->taglen;
        resp->tag = args->tag;
        resp->opcnt = 0;
index 27d1e94f12fb80307261f27c3886e6a276b6042b..5064cb5a0b8ed2e98189c9f42189ab4d4a962dda 100644 (file)
@@ -1747,10 +1747,10 @@ static void write_cinfo(__be32 **p, struct nfsd4_change_info *c)
 }
 
 #define RESERVE_SPACE(nbytes)  do {                            \
-       p = resp->xdr.p;                                                \
-       BUG_ON(p + XDR_QUADLEN(nbytes) > resp->xdr.end);                \
+       p = xdr_reserve_space(&resp->xdr, nbytes);              \
+       BUG_ON(!p);                                             \
 } while (0)
-#define ADJUST_ARGS()          resp->xdr.p = p
+#define ADJUST_ARGS()          WARN_ON_ONCE(p != resp->xdr.p)  \
 
 /* Encode as an array of strings the string given with components
  * separated @sep, escaped with esc_enter and esc_exit.
@@ -3056,8 +3056,11 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,
                        read->rd_offset, resp->rqstp->rq_vec, read->rd_vlen,
                        &maxcount);
 
-       if (nfserr)
+       if (nfserr) {
+               xdr->p -= 2;
+               xdr->iov->iov_len -= 8;
                return nfserr;
+       }
        eof = (read->rd_offset + maxcount >=
               read->rd_fhp->fh_dentry->d_inode->i_size);
 
@@ -3110,9 +3113,12 @@ nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd
         */
        nfserr = nfsd_readlink(readlink->rl_rqstp, readlink->rl_fhp, page, &maxcount);
        if (nfserr == nfserr_isdir)
-               return nfserr_inval;
-       if (nfserr)
+               nfserr = nfserr_inval;
+       if (nfserr) {
+               xdr->p--;
+               xdr->iov->iov_len -= 4;
                return nfserr;
+       }
 
        WRITE32(maxcount);
        ADJUST_ARGS();
@@ -3213,8 +3219,9 @@ nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4
 
        return 0;
 err_no_verf:
-       p = savep;
-       ADJUST_ARGS();
+       xdr->p = savep;
+       xdr->iov->iov_len = ((char *)resp->xdr.p)
+                               - (char *)resp->xdr.buf->head[0].iov_base;
        return nfserr;
 }