From patchwork Wed Dec 17 22:35:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Schumaker, Anna" X-Patchwork-Id: 5509491 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B7A839F1D4 for ; Wed, 17 Dec 2014 22:35:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C1331209D3 for ; Wed, 17 Dec 2014 22:35:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ABC1A209E5 for ; Wed, 17 Dec 2014 22:35:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750949AbaLQWfR (ORCPT ); Wed, 17 Dec 2014 17:35:17 -0500 Received: from mx2.netapp.com ([216.240.18.37]:47143 "EHLO mx2.netapp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751189AbaLQWfQ (ORCPT ); Wed, 17 Dec 2014 17:35:16 -0500 X-IronPort-AV: E=Sophos;i="5.07,596,1413270000"; d="scan'208";a="117478263" Received: from vmwexchts04-prd.hq.netapp.com ([10.122.105.32]) by mx2-out.netapp.com with ESMTP; 17 Dec 2014 14:35:08 -0800 Received: from smtp1.corp.netapp.com (10.57.156.124) by VMWEXCHTS04-PRD.hq.netapp.com (10.122.105.32) with Microsoft SMTP Server id 15.0.995.29; Wed, 17 Dec 2014 14:35:07 -0800 Received: from davros.com ([10.63.236.12]) by smtp1.corp.netapp.com (8.13.1/8.13.1/NTAP-1.6) with ESMTP id sBHMZ5Av001871; Wed, 17 Dec 2014 14:35:07 -0800 (PST) From: To: CC: Subject: [PATCH 1/4] NFSD: nfsd4_encode_read() should encode eof and maxcount Date: Wed, 17 Dec 2014 17:35:01 -0500 Message-ID: <1418855704-14127-2-git-send-email-Anna.Schumaker@Netapp.com> X-Mailer: git-send-email 2.1.3 In-Reply-To: <1418855704-14127-1-git-send-email-Anna.Schumaker@Netapp.com> References: <1418855704-14127-1-git-send-email-Anna.Schumaker@Netapp.com> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Anna Schumaker I intend to reuse nfsd4_encode_readv() for READ_PLUS, so I need an alternate way to encode these values. I think it makes sense for nfsd4_encode_read() to handle this in a single place for both READ paths. Signed-off-by: Anna Schumaker --- fs/nfsd/nfs4xdr.c | 59 ++++++++++++++++++++++--------------------------------- 1 file changed, 23 insertions(+), 36 deletions(-) diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index 0622d4f..1943cdb 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -3119,21 +3119,19 @@ nfsd4_encode_open_downgrade(struct nfsd4_compoundres *resp, __be32 nfserr, struc static __be32 nfsd4_encode_splice_read( struct nfsd4_compoundres *resp, struct nfsd4_read *read, - struct file *file, unsigned long maxcount) + struct file *file, unsigned long *maxcount) { struct xdr_stream *xdr = &resp->xdr; struct xdr_buf *buf = xdr->buf; - u32 eof; int space_left; __be32 nfserr; - __be32 *p = xdr->p - 2; /* Make sure there will be room for padding if needed */ if (xdr->end - xdr->p < 1) return nfserr_resource; nfserr = nfsd_splice_read(read->rd_rqstp, file, - read->rd_offset, &maxcount); + read->rd_offset, maxcount); if (nfserr) { /* * nfsd_splice_actor may have already messed with the @@ -3144,27 +3142,21 @@ static __be32 nfsd4_encode_splice_read( return nfserr; } - eof = (read->rd_offset + maxcount >= - read->rd_fhp->fh_dentry->d_inode->i_size); - - *(p++) = htonl(eof); - *(p++) = htonl(maxcount); - - buf->page_len = maxcount; - buf->len += maxcount; - xdr->page_ptr += (buf->page_base + maxcount + PAGE_SIZE - 1) + buf->page_len = *maxcount; + buf->len += *maxcount; + xdr->page_ptr += (buf->page_base + *maxcount + PAGE_SIZE - 1) / PAGE_SIZE; /* Use rest of head for padding and remaining ops: */ buf->tail[0].iov_base = xdr->p; buf->tail[0].iov_len = 0; xdr->iov = buf->tail; - if (maxcount&3) { - int pad = 4 - (maxcount&3); + if (*maxcount&3) { + int pad = 4 - (*maxcount&3); *(xdr->p++) = 0; - buf->tail[0].iov_base += maxcount&3; + buf->tail[0].iov_base += *maxcount&3; buf->tail[0].iov_len = pad; buf->len += pad; } @@ -3179,21 +3171,19 @@ static __be32 nfsd4_encode_splice_read( static __be32 nfsd4_encode_readv(struct nfsd4_compoundres *resp, struct nfsd4_read *read, - struct file *file, unsigned long maxcount) + struct file *file, unsigned long *maxcount) { struct xdr_stream *xdr = &resp->xdr; - u32 eof; int v; - int starting_len = xdr->buf->len - 8; + int starting_len = xdr->buf->len; long len; int thislen; __be32 nfserr; - __be32 tmp; __be32 *p; u32 zzz = 0; int pad; - len = maxcount; + len = *maxcount; v = 0; thislen = min_t(long, len, ((void *)xdr->end - (void *)xdr->p)); @@ -3216,22 +3206,13 @@ static __be32 nfsd4_encode_readv(struct nfsd4_compoundres *resp, read->rd_vlen = v; nfserr = nfsd_readv(file, read->rd_offset, resp->rqstp->rq_vec, - read->rd_vlen, &maxcount); + read->rd_vlen, maxcount); if (nfserr) return nfserr; - xdr_truncate_encode(xdr, starting_len + 8 + ((maxcount+3)&~3)); + xdr_truncate_encode(xdr, starting_len + ((*maxcount+3)&~3)); - eof = (read->rd_offset + maxcount >= - read->rd_fhp->fh_dentry->d_inode->i_size); - - tmp = htonl(eof); - write_bytes_to_xdr_buf(xdr->buf, starting_len , &tmp, 4); - tmp = htonl(maxcount); - write_bytes_to_xdr_buf(xdr->buf, starting_len + 4, &tmp, 4); - - pad = (maxcount&3) ? 4 - (maxcount&3) : 0; - write_bytes_to_xdr_buf(xdr->buf, starting_len + 8 + maxcount, - &zzz, pad); + pad = (*maxcount&3) ? 4 - (*maxcount&3) : 0; + write_bytes_to_xdr_buf(xdr->buf, starting_len + *maxcount, &zzz, pad); return 0; } @@ -3247,6 +3228,7 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr, struct raparms *ra; __be32 *p; __be32 err; + u32 eof; if (nfserr) return nfserr; @@ -3274,9 +3256,14 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr, } if (file->f_op->splice_read && resp->rqstp->rq_splice_ok) - err = nfsd4_encode_splice_read(resp, read, file, maxcount); + err = nfsd4_encode_splice_read(resp, read, file, &maxcount); else - err = nfsd4_encode_readv(resp, read, file, maxcount); + err = nfsd4_encode_readv(resp, read, file, &maxcount); + + eof = (read->rd_offset + maxcount >= + read->rd_fhp->fh_dentry->d_inode->i_size); + *p++ = cpu_to_be32(eof); + *p++ = cpu_to_be32(maxcount); if (!read->rd_filp) nfsd_put_tmp_read_open(file, ra);