All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fred Isaman <iisaman@netapp.com>
To: linux-nfs@vger.kernel.org
Cc: Trond Myklebust <Trond.Myklebust@netapp.com>
Subject: [PATCH 08/15] pnfs: serialize LAYOUTGET(openstateid)
Date: Thu, 23 Dec 2010 18:54:34 -0500	[thread overview]
Message-ID: <1293148481-28420-9-git-send-email-iisaman@netapp.com> (raw)
In-Reply-To: <1293148481-28420-1-git-send-email-iisaman@netapp.com>

We shouldn't send a LAYOUTGET(openstateid) unless all outstanding RPCs
using the previous stateid are completed.  This requires choosing the
stateid to encode earlier, so we can abort if one is not available (we
want to use the open stateid, but a LAYOUTGET is already out using
it), and adding a count of the number of outstanding rpc calls using
layout state (which for now consist solely of LAYOUTGETs).

Signed-off-by: Fred Isaman <iisaman@netapp.com>
---
 fs/nfs/nfs4proc.c       |    7 ++++++-
 fs/nfs/nfs4xdr.c        |    5 +----
 fs/nfs/pnfs.c           |   24 +++++++++++++++++++-----
 fs/nfs/pnfs.h           |    1 +
 include/linux/nfs_xdr.h |    1 +
 5 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 1609a07..3b059d3 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -5308,6 +5308,12 @@ nfs4_layoutget_prepare(struct rpc_task *task, void *calldata)
 	if (nfs4_setup_sequence(server, &lgp->args.seq_args,
 				&lgp->res.seq_res, 0, task))
 		return;
+	if (pnfs_choose_layoutget_stateid(&lgp->args.stateid,
+					  NFS_I(lgp->args.inode)->layout,
+					  lgp->args.ctx->state)) {
+		rpc_exit(task, NFS4_OK);
+		return;
+	}
 	rpc_call_start(task);
 }
 
@@ -5342,7 +5348,6 @@ static void nfs4_layoutget_release(void *calldata)
 	struct nfs4_layoutget *lgp = calldata;
 
 	dprintk("--> %s\n", __func__);
-	put_layout_hdr(lgp->args.inode);
 	if (lgp->res.layout.buf != NULL)
 		free_page((unsigned long) lgp->res.layout.buf);
 	put_nfs_open_context(lgp->args.ctx);
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index 4e28242..3cbdd0c 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -1787,7 +1787,6 @@ encode_layoutget(struct xdr_stream *xdr,
 		      const struct nfs4_layoutget_args *args,
 		      struct compound_hdr *hdr)
 {
-	nfs4_stateid stateid;
 	__be32 *p;
 
 	p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE);
@@ -1798,9 +1797,7 @@ encode_layoutget(struct xdr_stream *xdr,
 	p = xdr_encode_hyper(p, args->range.offset);
 	p = xdr_encode_hyper(p, args->range.length);
 	p = xdr_encode_hyper(p, args->minlength);
-	pnfs_choose_layoutget_stateid(&stateid, NFS_I(args->inode)->layout,
-				args->ctx->state);
-	p = xdr_encode_opaque_fixed(p, &stateid.data, NFS4_STATEID_SIZE);
+	p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE);
 	*p = cpu_to_be32(args->maxcount);
 
 	dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
index 212cbc2..59ed68b 100644
--- a/fs/nfs/pnfs.c
+++ b/fs/nfs/pnfs.c
@@ -371,6 +371,14 @@ pnfs_set_layout_stateid(struct pnfs_layout_hdr *lo,
 		memcpy(&lo->plh_stateid, &new->stateid, sizeof(new->stateid));
 }
 
+/* lget is set to 1 if called from inside send_layoutget call chain */
+static bool
+pnfs_layoutgets_blocked(struct pnfs_layout_hdr *lo, int lget)
+{
+	return (list_empty(&lo->plh_segs) &&
+		 (atomic_read(&lo->plh_outstanding) > lget));
+}
+
 int
 pnfs_choose_layoutget_stateid(nfs4_stateid *dst, struct pnfs_layout_hdr *lo,
 			      struct nfs4_state *open_state)
@@ -379,7 +387,9 @@ pnfs_choose_layoutget_stateid(nfs4_stateid *dst, struct pnfs_layout_hdr *lo,
 
 	dprintk("--> %s\n", __func__);
 	spin_lock(&lo->plh_inode->i_lock);
-	if (list_empty(&lo->plh_segs)) {
+	if (pnfs_layoutgets_blocked(lo, 1)) {
+		status = -EAGAIN;
+	} else if (list_empty(&lo->plh_segs)) {
 		int seq;
 
 		do {
@@ -414,10 +424,8 @@ send_layoutget(struct pnfs_layout_hdr *lo,
 
 	BUG_ON(ctx == NULL);
 	lgp = kzalloc(sizeof(*lgp), GFP_KERNEL);
-	if (lgp == NULL) {
-		put_layout_hdr(lo->plh_inode);
+	if (lgp == NULL)
 		return NULL;
-	}
 	lgp->args.minlength = NFS4_MAX_UINT64;
 	lgp->args.maxcount = PNFS_LAYOUT_MAXSIZE;
 	lgp->args.range.iomode = iomode;
@@ -613,10 +621,16 @@ pnfs_update_layout(struct inode *ino,
 	if (test_bit(lo_fail_bit(iomode), &nfsi->layout->plh_flags))
 		goto out_unlock;
 
-	get_layout_hdr_locked(lo); /* Matched in nfs4_layoutget_release */
+	if (pnfs_layoutgets_blocked(lo, 0))
+		goto out_unlock;
+	atomic_inc(&lo->plh_outstanding);
+
+	get_layout_hdr_locked(lo);
 	spin_unlock(&ino->i_lock);
 
 	lseg = send_layoutget(lo, ctx, iomode);
+	atomic_dec(&lo->plh_outstanding);
+	put_layout_hdr(ino);
 out:
 	dprintk("%s end, state 0x%lx lseg %p\n", __func__,
 		nfsi->layout->plh_flags, lseg);
diff --git a/fs/nfs/pnfs.h b/fs/nfs/pnfs.h
index 787253e..698380d 100644
--- a/fs/nfs/pnfs.h
+++ b/fs/nfs/pnfs.h
@@ -69,6 +69,7 @@ struct pnfs_layout_hdr {
 	struct list_head	plh_layouts;   /* other client layouts */
 	struct list_head	plh_segs;      /* layout segments list */
 	nfs4_stateid		plh_stateid;
+	atomic_t		plh_outstanding; /* number of RPCs out */
 	unsigned long		plh_flags;
 	struct inode		*plh_inode;
 };
diff --git a/include/linux/nfs_xdr.h b/include/linux/nfs_xdr.h
index f923831..0843703 100644
--- a/include/linux/nfs_xdr.h
+++ b/include/linux/nfs_xdr.h
@@ -208,6 +208,7 @@ struct nfs4_layoutget_args {
 	struct inode *inode;
 	struct nfs_open_context *ctx;
 	struct nfs4_sequence_args seq_args;
+	nfs4_stateid stateid;
 };
 
 struct nfs4_layoutget_res {
-- 
1.7.2.1


  parent reply	other threads:[~2010-12-23 23:54 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-23 23:54 [PATCH 00/15] pnfs wave 2 submission, try 5 Fred Isaman
2010-12-23 23:54 ` [PATCH 01/15] pnfs: fix incorrect comment in destroy_lseg Fred Isaman
2010-12-23 23:54 ` [PATCH 02/15] pnfs: remove unnecessary field lgp->status Fred Isaman
2010-12-23 23:54 ` [PATCH 03/15] pnfs: add prefix to struct pnfs_layout_segment fields Fred Isaman
2010-12-23 23:54 ` [PATCH 04/15] pnfs: add prefix to struct pnfs_layout_hdr fields Fred Isaman
2010-12-23 23:54 ` [PATCH 05/15] pnfs: change layout state seqlock to a spinlock Fred Isaman
2010-12-23 23:54 ` [PATCH 06/15] pnfs: change how lsegs are removed from layout list Fred Isaman
2010-12-23 23:54 ` [PATCH 07/15] pnfs: layoutget rpc code cleanup Fred Isaman
2010-12-23 23:54 ` Fred Isaman [this message]
2010-12-23 23:54 ` [PATCH 09/15] pnfs: add layout to client list before sending rpc Fred Isaman
2010-12-23 23:54 ` [PATCH 10/15] pnfs: check that partial LAYOUTGET return is ignored Fred Isaman
2010-12-23 23:54 ` [PATCH 11/15] pnfs: change lo refcounting to atomic_t Fred Isaman
2010-12-23 23:54 ` [PATCH 12/15] pnfs: CB_LAYOUTRECALL xdr code Fred Isaman
2010-12-23 23:54 ` [PATCH 13/15] pnfs: add CB_LAYOUTRECALL handling Fred Isaman
2010-12-23 23:54 ` [PATCH 14/15] pnfs: update nfs4_callback_recallany to handle layouts Fred Isaman
2010-12-23 23:54 ` [PATCH 15/15] pnfs: layout roc code Fred Isaman
  -- strict thread matches above, loose matches on Subject: below --
2011-01-06 11:36 [PATCH 00/15] pnfs wave 2 submission Fred Isaman
2011-01-06 11:36 ` [PATCH 08/15] pnfs: serialize LAYOUTGET(openstateid) Fred Isaman
2010-12-23 17:29 [PATCH 00/15] pnfs wave 2 submission, try 4 Fred Isaman
2010-12-23 17:29 ` [PATCH 08/15] pnfs: serialize LAYOUTGET(openstateid) Fred Isaman
2010-12-23 12:47 [PATCH 00/15] pnfs wave 2 submission, try 3 Fred Isaman
2010-12-23 12:47 ` [PATCH 08/15] pnfs: serialize LAYOUTGET(openstateid) Fred Isaman
2010-12-22  4:00 [PATCH 00/15] pnfs wave 2 submission, try 2 Fred Isaman
2010-12-22  4:00 ` [PATCH 08/15] pnfs: serialize LAYOUTGET(openstateid) Fred Isaman

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=1293148481-28420-9-git-send-email-iisaman@netapp.com \
    --to=iisaman@netapp.com \
    --cc=Trond.Myklebust@netapp.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.