linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: andros@netapp.com
To: bhalevy@panasas.com
Cc: linux-nfs@vger.kernel.org, Andy Adamson <andros@netapp.com>
Subject: [PATCH 05/16] SQUASHME pnfs-submit: rewrite layout allocation
Date: Wed,  7 Jul 2010 18:34:12 -0400	[thread overview]
Message-ID: <1278542063-4009-6-git-send-email-andros@netapp.com> (raw)
In-Reply-To: <1278542063-4009-5-git-send-email-andros@netapp.com>

From: Andy Adamson <andros@netapp.com>

Don't wait on a bit if layout is not allocated. Instead, allocate,
check for existance, and possibly free.

As per new layout refcounting scheme,don't take a reference on the layout.

Signed-off-by: Andy Adamson <andros@netapp.com>
---
 fs/nfs/pnfs.c          |   84 +++++++++++++----------------------------------
 include/linux/nfs_fs.h |    1 -
 2 files changed, 23 insertions(+), 62 deletions(-)

diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
index 6d435ed..92b7772 100644
--- a/fs/nfs/pnfs.c
+++ b/fs/nfs/pnfs.c
@@ -914,7 +914,6 @@ alloc_init_layout(struct inode *ino)
 	struct pnfs_layout_type *lo;
 	struct layoutdriver_io_operations *io_ops;
 
-	BUG_ON(NFS_I(ino)->layout != NULL);
 	io_ops = NFS_SERVER(ino)->pnfs_curr_ld->ld_io_ops;
 	lo = io_ops->alloc_layout(ino);
 	if (!lo) {
@@ -923,84 +922,47 @@ alloc_init_layout(struct inode *ino)
 			__func__);
 		return NULL;
 	}
-	spin_lock(&ino->i_lock);
 	lo->refcount = 1;
 	INIT_LIST_HEAD(&lo->lo_layouts);
 	INIT_LIST_HEAD(&lo->segs);
 	seqlock_init(&lo->seqlock);
 	lo->lo_inode = ino;
-	NFS_I(ino)->layout = lo;
-	spin_unlock(&ino->i_lock);
 	return lo;
 }
 
-static int pnfs_wait_schedule(void *word)
-{
-	if (signal_pending(current))
-		return -ERESTARTSYS;
-	schedule();
-	return 0;
-}
-
 /*
- * get, possibly allocate, and lock current_layout
+ * Lock and possibly allocate the inode layout
  *
- * Note: If successful, ino->i_lock is taken and the caller
- * must put and unlock current_layout when the returned layout is released.
+ * If successful, ino->i_lock is taken, and the caller must unlock.
  */
 static struct pnfs_layout_type *
-get_lock_alloc_layout(struct inode *ino)
+nfs_lock_alloc_layout(struct inode *ino)
 {
-	struct nfs_inode *nfsi = NFS_I(ino);
-	struct pnfs_layout_type *lo;
-	int res;
+	struct pnfs_layout_type *new = NULL;
 
 	dprintk("%s Begin\n", __func__);
 
 	spin_lock(&ino->i_lock);
-	while ((lo = grab_current_layout(nfsi)) == NULL) {
+	if (NFS_I(ino)->layout == NULL) {
 		spin_unlock(&ino->i_lock);
-		/* Compete against other threads on who's doing the allocation,
-		 * wait until bit is cleared if we lost this race.
-		 */
-		res = wait_on_bit_lock(
-			&nfsi->layout->pnfs_layout_state,
-			NFS_INO_LAYOUT_ALLOC,
-			pnfs_wait_schedule, TASK_KILLABLE);
-		if (res) {
-			lo = ERR_PTR(res);
-			break;
-		}
-
-		/* Was current_layout already allocated while we slept?
-		 * If so, retry get_lock'ing it. Otherwise, allocate it.
-		 */
-		if (nfsi->layout) {
-			spin_lock(&ino->i_lock);
-			continue;
+		new = alloc_init_layout(ino);
+		if (new == NULL)
+			return NULL;
+		spin_lock(&ino->i_lock);
+		if (NFS_I(ino)->layout == NULL) {
+			NFS_I(ino)->layout = new;
+			new = NULL;
 		}
-
-		lo = alloc_init_layout(ino);
-		if (lo)
-			spin_lock(&ino->i_lock);
-		else
-			lo = ERR_PTR(-ENOMEM);
-
-		/* release the NFS_INO_LAYOUT_ALLOC bit and wake up waiters */
-		clear_bit_unlock(NFS_INO_LAYOUT_ALLOC,
-				 &nfsi->layout->pnfs_layout_state);
-		wake_up_bit(&nfsi->layout->pnfs_layout_state,
-			    NFS_INO_LAYOUT_ALLOC);
-		break;
 	}
-
-#ifdef NFS_DEBUG
-	if (!IS_ERR(lo))
-		dprintk("%s Return %p\n", __func__, lo);
-	else
-		dprintk("%s Return error %ld\n", __func__, PTR_ERR(lo));
-#endif
-	return lo;
+	if (new) {
+		/* Reference the layout accross i_lock release and grab */
+		get_layout(NFS_I(ino)->layout);
+		spin_unlock(&ino->i_lock);
+		NFS_SERVER(ino)->pnfs_curr_ld->ld_io_ops->free_layout(new);
+		spin_lock(&ino->i_lock);
+		put_layout(NFS_I(ino)->layout);
+	}
+	return NFS_I(ino)->layout;
 }
 
 /*
@@ -1088,8 +1050,8 @@ _pnfs_update_layout(struct inode *ino,
 
 	if (take_ref)
 		*lsegpp = NULL;
-	lo = get_lock_alloc_layout(ino);
-	if (IS_ERR(lo)) {
+	lo = nfs_lock_alloc_layout(ino);
+	if (lo == NULL) {
 		dprintk("%s ERROR: can't get pnfs_layout_type\n", __func__);
 		goto out;
 	}
diff --git a/include/linux/nfs_fs.h b/include/linux/nfs_fs.h
index 7b999a4..005b3ea 100644
--- a/include/linux/nfs_fs.h
+++ b/include/linux/nfs_fs.h
@@ -107,7 +107,6 @@ struct pnfs_layout_type {
 	unsigned long pnfs_layout_state;
 	#define NFS_INO_RO_LAYOUT_FAILED 0      /* get ro layout failed stop trying */
 	#define NFS_INO_RW_LAYOUT_FAILED 1      /* get rw layout failed stop trying */
-	#define NFS_INO_LAYOUT_ALLOC     2      /* bit lock for layout allocation */
 	#define NFS_INO_LAYOUTCOMMIT     3      /* LAYOUTCOMMIT needed */
 	struct rpc_cred         *lo_cred; /* layoutcommit credential */
 	/* DH: These vars keep track of the maximum write range
-- 
1.6.6


  reply	other threads:[~2010-07-07 22:34 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-07 22:34 [PATCH 0/16] pnfs-submit fix layout allocation and reference counting andros
2010-07-07 22:34 ` [PATCH 01/16] SQUASHME pnfs-submit: add state flag for layoutcommit_needed andros
2010-07-07 22:34   ` [PATCH 02/16] SQUASHME: pnfs-submit: move pnfs_layout_suspend back to nfs_inode andros
2010-07-07 22:34     ` [PATCH 03/16] SQUASHME pnfs-submit embed pnfs_layout_type andros
2010-07-07 22:34       ` [PATCH 04/16] SQUASHME pnfs-submit: filelayout: use new alloc/free_layout API andros
2010-07-07 22:34         ` andros [this message]
2010-07-07 22:34           ` [PATCH 06/16] SQUASHME pnfs-submit; fix pnfs_update_layout reference counting andros
2010-07-07 22:34             ` [PATCH 07/16] SQUASHME pnfs_submit: don't get a reference on boundary calculation andros
2010-07-07 22:34               ` [PATCH 08/16] SQUASHME pnfs-submit: don't reference the layout in init_lseg andros
2010-07-07 22:34                 ` [PATCH 09/16] SQUASHME pnfs-submit: pnfs_update_layout always references the lseg andros
2010-07-07 22:34                   ` [PATCH 10/16] SQUASHME pnfs-submit: reference the layout when inserted into segs list andros
2010-07-07 22:34                     ` [PATCH 11/16] SQUASHME pnfs-submit: rename put_layout to put_layout_locked andros
2010-07-07 22:34                       ` [PATCH 12/16] SQUASHME pnfs-submit: reference layout across layoutcommit andros
2010-07-07 22:34                         ` [PATCH 13/16] SQUASHME pnfs-submit: reference layout for layoutreturn andros
2010-07-07 22:34                           ` [PATCH 14/16] SQUASHME pnfs-submit: remove put_layout from pnfs_free_layout andros
2010-07-07 22:34                             ` [PATCH 15/16] SQUASHME pnfs-submit: do not reference a layout in destroy_layout andros
2010-07-07 22:34                               ` [PATCH 16/16] SQUASHME pnfs-submit: remove grab_current_layout andros
2010-07-12 17:19                         ` [PATCH 12/16] SQUASHME pnfs-submit: reference layout across layoutcommit Benny Halevy
2010-07-12 18:27                           ` William A. (Andy) Adamson
     [not found]                             ` <AANLkTil1wUQUTht0QP7_Ttaagw0-LXef2J8wU6wSFUWG-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-07-12 18:29                               ` Benny Halevy
2010-07-13 13:50                                 ` William A. (Andy) Adamson
2010-07-12 17:25                         ` Boaz Harrosh
2010-07-12 18:09                           ` William A. (Andy) Adamson
     [not found]                             ` <AANLkTilWfV86wpO7vFho3FmL9y9Y6Sx9_-knKq7T-snu-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-07-12 18:27                               ` Benny Halevy
2010-07-12 18:28                                 ` William A. (Andy) Adamson
     [not found]                                   ` <AANLkTilrcKirEQLe5mhtYNAnaJBSn6q4edC3TlXJd1rm-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-07-12 19:54                                     ` Benny Halevy
2010-07-12  9:13                   ` [PATCH 09/16] SQUASHME pnfs-submit: pnfs_update_layout always references the lseg Benny Halevy
2010-07-12  8:30           ` [PATCH 05/16] SQUASHME pnfs-submit: rewrite layout allocation Benny Halevy
2010-07-13 13:39             ` William A. (Andy) Adamson
     [not found]               ` <AANLkTilb6ePL7s6H4TbhGfJt05Yw7Gc24V0C8cPHC22K-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-07-13 14:04                 ` Benny Halevy
2010-07-12 16:32         ` [PATCH 04/16] SQUASHME pnfs-submit: filelayout: use new alloc/free_layout API Boaz Harrosh
2010-07-12 16:29       ` [PATCH 03/16] SQUASHME pnfs-submit embed pnfs_layout_type Boaz Harrosh
2010-07-12 17:05         ` Benny Halevy
2010-07-12 17:38           ` William A. (Andy) Adamson
2010-07-12 17:34         ` William A. (Andy) Adamson
     [not found]           ` <AANLkTikTMLQJwj1PeW2Y0dfmRcVFdNr6sasxJtaAiMg4-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-07-12 17:43             ` Boaz Harrosh
2010-07-12 18:33               ` William A. (Andy) Adamson
2010-07-07 22:57 ` [PATCH 0/16] pnfs-submit fix layout allocation and reference counting Gilliam, PaulX J
2010-07-08 10:16 ` Boaz Harrosh
2010-07-08 16:14   ` William A. (Andy) Adamson
2010-07-12 15:33     ` Boaz Harrosh

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=1278542063-4009-6-git-send-email-andros@netapp.com \
    --to=andros@netapp.com \
    --cc=bhalevy@panasas.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).