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 2/3] NFSD: Add basic READ_PLUS support
Date: Mon, 16 Mar 2015 17:18:07 -0400	[thread overview]
Message-ID: <1426540688-32095-3-git-send-email-Anna.Schumaker@Netapp.com> (raw)
In-Reply-To: <1426540688-32095-1-git-send-email-Anna.Schumaker@Netapp.com>

This patch adds READ_PLUS support for both NFS4_CONTENT_DATA and
NFS4_CONTENT_HOLE segments.  I keep things simple for now by only
returning one segment at a time to clients issuing the READ_PLUS call.

Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
---
 fs/nfsd/nfs4proc.c |  16 ++++++++
 fs/nfsd/nfs4xdr.c  | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 124 insertions(+), 2 deletions(-)

diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
index d30bea8..e9f4d8f 100644
--- a/fs/nfsd/nfs4proc.c
+++ b/fs/nfsd/nfs4proc.c
@@ -1858,6 +1858,16 @@ static inline u32 nfsd4_read_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
 	return (op_encode_hdr_size + 2 + XDR_QUADLEN(rlen)) * sizeof(__be32);
 }
 
+static inline u32 nfsd4_read_plus_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
+{
+	u32 maxcount = svc_max_payload(rqstp);
+	u32 rlen = min(op->u.read.rd_length, maxcount);
+	/* enough extra xdr space for encoding either a hole or data segment. */
+	u32 xdr  = 5;
+
+	return (op_encode_hdr_size + 2 + xdr + XDR_QUADLEN(rlen)) * sizeof(__be32);
+}
+
 static inline u32 nfsd4_readdir_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
 {
 	u32 maxcount = 0, rlen = 0;
@@ -2290,6 +2300,12 @@ static struct nfsd4_operation nfsd4_ops[] = {
 		.op_name = "OP_DEALLOCATE",
 		.op_rsize_bop = (nfsd4op_rsize)nfsd4_write_rsize,
 	},
+	[OP_READ_PLUS] = {
+		.op_func = (nfsd4op_func)nfsd4_read,
+		.op_name = "OP_READ_PLUS",
+		.op_rsize_bop = (nfsd4op_rsize)nfsd4_read_plus_rsize,
+		.op_get_currentstateid = (stateid_getter)nfsd4_get_readstateid,
+	},
 	[OP_SEEK] = {
 		.op_func = (nfsd4op_func)nfsd4_seek,
 		.op_name = "OP_SEEK",
diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 22cd001..799d52c 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -1769,7 +1769,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
 	[OP_LAYOUTSTATS]	= (nfsd4_dec)nfsd4_decode_notsupp,
 	[OP_OFFLOAD_CANCEL]	= (nfsd4_dec)nfsd4_decode_notsupp,
 	[OP_OFFLOAD_STATUS]	= (nfsd4_dec)nfsd4_decode_notsupp,
-	[OP_READ_PLUS]		= (nfsd4_dec)nfsd4_decode_notsupp,
+	[OP_READ_PLUS]		= (nfsd4_dec)nfsd4_decode_read,
 	[OP_SEEK]		= (nfsd4_dec)nfsd4_decode_seek,
 	[OP_WRITE_SAME]		= (nfsd4_dec)nfsd4_decode_notsupp,
 };
@@ -4116,6 +4116,112 @@ nfsd4_encode_layoutreturn(struct nfsd4_compoundres *resp, __be32 nfserr,
 #endif /* CONFIG_NFSD_PNFS */
 
 static __be32
+nfsd4_encode_read_plus_data(struct nfsd4_compoundres *resp, struct nfsd4_read *read,
+			    struct file *file)
+{
+	__be32 *p, err;
+	unsigned long maxcount;
+	struct xdr_stream *xdr = &resp->xdr;
+
+	p = xdr_reserve_space(xdr, 4 + 8 + 4);
+	if (!p)
+		return nfserr_resource;
+	xdr_commit_encode(xdr);
+
+	maxcount = svc_max_payload(resp->rqstp);
+	maxcount = min_t(unsigned long, maxcount, (xdr->buf->buflen - xdr->buf->len));
+	maxcount = min_t(unsigned long, maxcount, read->rd_length);
+
+	if (file->f_op->splice_read && test_bit(RQ_SPLICE_OK, &resp->rqstp->rq_flags))
+		err = nfsd4_encode_splice_read(resp, read, file, &maxcount);
+	else
+		err = nfsd4_encode_readv(resp, read, file, &maxcount);
+
+	*p++ = cpu_to_be32(NFS4_CONTENT_DATA);
+	p = xdr_encode_hyper(p, read->rd_offset);
+	*p++ = cpu_to_be32(maxcount);
+
+	read->rd_offset += maxcount;
+	return err;
+}
+
+static __be32
+nfsd4_encode_read_plus_hole(struct nfsd4_compoundres *resp, struct nfsd4_read *read,
+			    struct file *file)
+{
+	__be32 *p;
+	unsigned long maxcount;
+	loff_t data_pos = vfs_llseek(file, read->rd_offset, SEEK_DATA);
+
+	if (data_pos == -ENXIO)
+		data_pos = i_size_read(file_inode(file));
+	if (data_pos <= read->rd_offset)
+		return nfsd4_encode_read_plus_data(resp, read, file);
+
+	maxcount = data_pos - read->rd_offset;
+	p = xdr_reserve_space(&resp->xdr, 4 + 8 + 8);
+	*p++ = cpu_to_be32(NFS4_CONTENT_HOLE);
+	p = xdr_encode_hyper(p, read->rd_offset);
+	p = xdr_encode_hyper(p, maxcount);
+
+	read->rd_offset += maxcount;
+	return nfs_ok;
+}
+
+static __be32
+nfsd4_encode_read_plus(struct nfsd4_compoundres *resp, __be32 nfserr,
+		       struct nfsd4_read *read)
+{
+	struct xdr_stream *xdr = &resp->xdr;
+	struct file *file = read->rd_filp;
+	int starting_len = xdr->buf->len;
+	struct raparms *ra;
+	loff_t hole_pos;
+	__be32 *p;
+	__be32 err;
+	u32 eof, segments = 0;
+
+	if (nfserr)
+		return nfserr;
+
+	/* eof flag, segment count */
+	p = xdr_reserve_space(xdr, 4 + 4 );
+	if (!p)
+		return nfserr_resource;
+	xdr_commit_encode(xdr);
+
+	if (!read->rd_filp) {
+		err = nfsd_get_tmp_read_open(resp->rqstp, read->rd_fhp,
+						&file, &ra);
+		if (err)
+			goto err_truncate;
+	}
+
+	hole_pos = vfs_llseek(file, read->rd_offset, SEEK_HOLE);
+	if (hole_pos == -ENXIO)
+		goto out_encode;
+
+	if (hole_pos == read->rd_offset)
+		err = nfsd4_encode_read_plus_hole(resp, read, file);
+	else
+		err = nfsd4_encode_read_plus_data(resp, read, file);
+	segments++;
+
+out_encode:
+	eof = (read->rd_offset >= i_size_read(file_inode(file)));
+	*p++ = cpu_to_be32(eof);
+	*p++ = cpu_to_be32(segments);
+
+	if (!read->rd_filp)
+		nfsd_put_tmp_read_open(file, ra);
+
+err_truncate:
+	if (err)
+		xdr_truncate_encode(xdr, starting_len);
+	return err;
+}
+
+static __be32
 nfsd4_encode_seek(struct nfsd4_compoundres *resp, __be32 nfserr,
 		  struct nfsd4_seek *seek)
 {
@@ -4222,7 +4328,7 @@ static nfsd4_enc nfsd4_enc_ops[] = {
 	[OP_LAYOUTSTATS]	= (nfsd4_enc)nfsd4_encode_noop,
 	[OP_OFFLOAD_CANCEL]	= (nfsd4_enc)nfsd4_encode_noop,
 	[OP_OFFLOAD_STATUS]	= (nfsd4_enc)nfsd4_encode_noop,
-	[OP_READ_PLUS]		= (nfsd4_enc)nfsd4_encode_noop,
+	[OP_READ_PLUS]		= (nfsd4_enc)nfsd4_encode_read_plus,
 	[OP_SEEK]		= (nfsd4_enc)nfsd4_encode_seek,
 	[OP_WRITE_SAME]		= (nfsd4_enc)nfsd4_encode_noop,
 };
-- 
2.3.3


  parent 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 ` [PATCH v3 1/3] NFSD: nfsd4_encode_read{v}() should encode eof and maxcount Anna Schumaker
2015-03-16 21:18 ` Anna Schumaker [this message]
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-3-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.