All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anna Schumaker <Anna.Schumaker@netapp.com>
To: <bfields@fieldses.org>
Cc: <linux-nfs@vger.kernel.org>
Subject: [PATCH v3 1/3] NFSD: nfsd4_encode_read{v}() should encode eof and maxcount
Date: Mon, 16 Mar 2015 17:18:06 -0400	[thread overview]
Message-ID: <1426540688-32095-2-git-send-email-Anna.Schumaker@Netapp.com> (raw)
In-Reply-To: <1426540688-32095-1-git-send-email-Anna.Schumaker@Netapp.com>

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 splice and
readv paths.

Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
---
 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 df5e66c..22cd001 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -3286,21 +3286,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
@@ -3311,27 +3309,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;
 	}
@@ -3346,21 +3338,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));
@@ -3383,22 +3373,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;
 
 }
@@ -3414,6 +3395,7 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,
 	struct raparms *ra;
 	__be32 *p;
 	__be32 err;
+	u32 eof;
 
 	if (nfserr)
 		return nfserr;
@@ -3441,9 +3423,14 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,
 	}
 
 	if (file->f_op->splice_read && test_bit(RQ_SPLICE_OK, &resp->rqstp->rq_flags))
-		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);
-- 
2.3.3


  reply	other threads:[~2015-03-16 21:18 UTC|newest]

Thread overview: 75+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-16 21:18 [PATCH v3 0/3] NFSD: Add READ_PLUS support Anna Schumaker
2015-03-16 21:18 ` Anna Schumaker [this message]
2015-03-16 21:18 ` [PATCH v3 2/3] NFSD: Add basic " Anna Schumaker
2015-03-16 21:18 ` [PATCH v3 3/3] NFSD: Add support for encoding multiple segments Anna Schumaker
2015-03-17 19:56   ` J. Bruce Fields
2015-03-17 20:07     ` J. Bruce Fields
2015-03-17 21:36       ` J. Bruce Fields
2015-03-18 18:16         ` Anna Schumaker
2015-03-18 18:55           ` J. Bruce Fields
2015-03-18 20:39             ` Anna Schumaker
2015-03-18 20:55               ` J. Bruce Fields
2015-03-18 21:03                 ` Anna Schumaker
2015-03-18 21:11                   ` J. Bruce Fields
     [not found]                     ` <OFB111A6D8.016B8BD5-ON88257E0D.001D174D-88257E0D.005268D6@us.ibm.com>
2015-03-19 15:36                       ` J. Bruce Fields
2015-03-19 16:28                         ` Marc Eshel
2015-03-20 15:17                           ` J. Bruce Fields
2015-03-20 15:17                             ` J. Bruce Fields
2015-03-20 16:23                             ` Christoph Hellwig
2015-03-20 16:23                               ` Christoph Hellwig
2015-03-20 18:26                               ` J. Bruce Fields
2015-03-20 18:26                                 ` J. Bruce Fields
2015-03-24 12:43                                 ` Anna Schumaker
2015-03-24 12:43                                   ` Anna Schumaker
2015-03-24 17:49                                   ` Christoph Hellwig
2015-03-24 17:49                                     ` Christoph Hellwig
2015-03-25 17:15                                     ` Anna Schumaker
2015-03-25 17:15                                       ` Anna Schumaker
2015-03-26 15:21                                     ` Anna Schumaker
2015-03-26 15:21                                       ` Anna Schumaker
2015-03-26 15:32                                       ` Trond Myklebust
2015-03-26 15:32                                         ` Trond Myklebust
2015-03-26 15:36                                         ` Anna Schumaker
2015-03-26 15:36                                           ` Anna Schumaker
2015-03-26 15:38                                         ` J. Bruce Fields
2015-03-26 15:38                                           ` J. Bruce Fields
2015-03-26 15:47                                           ` Anna Schumaker
2015-03-26 15:47                                             ` Anna Schumaker
2015-03-26 16:06                                             ` Trond Myklebust
2015-03-26 16:06                                               ` Trond Myklebust
2015-03-26 16:11                                               ` Anna Schumaker
2015-03-26 16:11                                                 ` Anna Schumaker
2015-03-26 16:13                                                 ` Trond Myklebust
2015-03-26 16:13                                                   ` Trond Myklebust
2015-03-26 16:14                                                   ` Anna Schumaker
2015-03-26 16:14                                                     ` Anna Schumaker
2015-03-27 19:04                                                   ` Anna Schumaker
2015-03-27 19:04                                                     ` Anna Schumaker
2015-03-27 20:22                                                     ` Trond Myklebust
2015-03-27 20:22                                                       ` Trond Myklebust
2015-03-27 20:46                                                       ` Anna Schumaker
2015-03-27 20:46                                                         ` Anna Schumaker
2015-03-27 20:54                                                         ` J. Bruce Fields
2015-03-27 20:54                                                           ` J. Bruce Fields
2015-03-27 20:55                                                           ` Anna Schumaker
2015-03-27 20:55                                                             ` Anna Schumaker
2015-03-27 21:08                                                             ` J. Bruce Fields
2015-03-27 21:08                                                               ` J. Bruce Fields
2015-04-15 19:32                                                               ` Anna Schumaker
2015-04-15 19:32                                                                 ` Anna Schumaker
2015-04-15 19:56                                                                 ` J. Bruce Fields
2015-04-15 19:56                                                                   ` J. Bruce Fields
2015-04-15 20:00                                                                   ` J. Bruce Fields
2015-04-15 20:00                                                                     ` J. Bruce Fields
2015-04-15 22:50                                                                     ` Dave Chinner
2015-04-15 22:50                                                                       ` Dave Chinner
2015-04-17 22:07                                                                       ` J. Bruce Fields
2015-04-17 22:07                                                                         ` J. Bruce Fields
2015-04-15 22:57                                                                 ` Dave Chinner
2015-04-15 22:57                                                                   ` Dave Chinner
2015-03-26 16:11                                             ` J. Bruce Fields
2015-03-26 16:11                                               ` J. Bruce Fields
2015-03-26 16:18                                               ` Anna Schumaker
2015-03-26 16:18                                                 ` Anna Schumaker
2015-03-30 14:06                                         ` Christoph Hellwig
2015-03-30 14:06                                           ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1426540688-32095-2-git-send-email-Anna.Schumaker@Netapp.com \
    --to=anna.schumaker@netapp.com \
    --cc=bfields@fieldses.org \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.