All of lore.kernel.org
 help / color / mirror / Atom feed
From: "J. Bruce Fields" <bfields@redhat.com>
To: linux-nfs@vger.kernel.org
Cc: "J. Bruce Fields" <bfields@redhat.com>
Subject: [PATCH 6/7] nfsd4: track maximum bytes
Date: Wed, 23 Jan 2013 17:55:37 -0500	[thread overview]
Message-ID: <1358981738-5649-7-git-send-email-bfields@redhat.com> (raw)
In-Reply-To: <1358981738-5649-1-git-send-email-bfields@redhat.com>

From: "J. Bruce Fields" <bfields@redhat.com>

All reserve_space is doing currently is checking that we don't run out
of pages, but some users (e.g. readdir) also want to check some other
limit.

XXX: also for 4.1 shouldn't we be checking session-negotiated maximum?

Signed-off-by: J. Bruce Fields <bfields@redhat.com>
---
 fs/nfsd/nfs4xdr.c | 11 +++++++++--
 fs/nfsd/xdr4.h    |  1 +
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 19f773e..a378435 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -1669,6 +1669,7 @@ static __be32 svcxdr_stream_init_from_resp(struct svcxdr_stream *xdr, struct nfs
 	buf->head[0].iov_len = (char *)resp->p - (char *)buf->head[0].iov_base;
 	buf->len = buf->head[0].iov_len;
 
+	xdr->maxbytes = INT_MAX;
 	xdr->buf = buf;
 	xdr->this_iov = buf->head;
 	xdr->ptr.p = resp->p;
@@ -1683,6 +1684,7 @@ static __be32 svcxdr_stream_init_from_resp(struct svcxdr_stream *xdr, struct nfs
  */
 static void svcxdr_stream_init_from_buffer(struct svcxdr_stream *xdr, __be32 *buf, int len)
 {
+	xdr->maxbytes = INT_MAX;
 	xdr->ptr.p = buf;
 	xdr->ptr.end = buf + len;
 	xdr->ptr.next_page = NULL;
@@ -1724,8 +1726,12 @@ static bool svcxdr_reserve_space(struct svcxdr_stream *xdr, struct svcxdr_ptr *p
 	*ptr = xdr->ptr;
 
 	bytes = roundup(bytes, 4);
-
-	return svcxdr_seek(&xdr->ptr, bytes);
+	if (bytes > xdr->maxbytes)
+		return false;
+	if (!svcxdr_seek(&xdr->ptr, bytes))
+		return false;
+	xdr->maxbytes -= bytes;
+	return true;
 }
 
 /* XXX: basic idea here:
@@ -1827,6 +1833,7 @@ static int svcxdr_byte_offset(struct svcxdr_ptr *from, struct svcxdr_ptr *to)
 static void svcxdr_reset(struct svcxdr_stream *xdr, struct svcxdr_ptr *to)
 {
 	WARN_ON_ONCE(svcxdr_ptr_misordered(&xdr->last_commit, to));
+	xdr->maxbytes += svcxdr_byte_offset(to, &xdr->ptr);
 	xdr->ptr = *to;
 }
 
diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h
index 4d9c82b..36b8c2c 100644
--- a/fs/nfsd/xdr4.h
+++ b/fs/nfsd/xdr4.h
@@ -54,6 +54,7 @@ struct svcxdr_stream {
 	struct svcxdr_ptr ptr;
 	struct xdr_buf *buf;
 	struct kvec *this_iov;
+	int maxbytes;
 };
 
 #define CURRENT_STATE_ID_FLAG (1<<0)
-- 
1.7.11.7


  parent reply	other threads:[~2013-01-23 22:55 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-23 22:55 draft server xdr rewrite J. Bruce Fields
2013-01-23 22:55 ` [PATCH 1/7] nfsd4: reserve space for integrity/privacy J. Bruce Fields
2013-01-23 22:55 ` [PATCH 2/7] nfsd4: simplify nfsd4_encode_fattr interface slightly J. Bruce Fields
2013-01-23 22:55 ` [PATCH 3/7] nfsd4: nfsd4_encode_fattr cleanup J. Bruce Fields
2013-01-23 22:55 ` [PATCH 4/7] nfsd4: encode_rdattr_error cleanup J. Bruce Fields
2013-01-23 22:55 ` [PATCH 5/7] nfsd4: rewrite xdr encoding of attributes J. Bruce Fields
2013-01-24  5:22   ` Myklebust, Trond
2013-01-24 14:58     ` J. Bruce Fields
2013-01-24 15:06       ` Myklebust, Trond
2013-01-24 16:14         ` J. Bruce Fields
2013-01-24 17:03           ` Myklebust, Trond
2013-01-24 20:45             ` J. Bruce Fields
2013-01-23 22:55 ` J. Bruce Fields [this message]
2013-01-23 22:55 ` [PATCH 7/7] nfsd4: readdir encoding J. Bruce Fields

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=1358981738-5649-7-git-send-email-bfields@redhat.com \
    --to=bfields@redhat.com \
    --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.