All of lore.kernel.org
 help / color / mirror / Atom feed
From: Benny Halevy <bhalevy@panasas.com>
To: Fred Isaman <iisaman@netapp.com>
Cc: linux-nfs@vger.kernel.org
Subject: Re: [PATCH 03/10] pnfs-submit: remove list_empty check from put_layout
Date: Tue, 15 Jun 2010 12:56:58 -0400	[thread overview]
Message-ID: <4C17B0DA.8010206@panasas.com> (raw)
In-Reply-To: <1276566375-24566-4-git-send-email-iisaman@netapp.com>

On Jun. 14, 2010, 21:46 -0400, Fred Isaman <iisaman@netapp.com> wrote:
> The check on list empty before destroying a layout has always bothered me.
> Get rid of it by having lsegs take a reference on their backpointer.

OK, that should work and be somewhat cleaner than what we have today.
Please see notes below...

> 
> Signed-off-by: Fred Isaman <iisaman@netapp.com>
> ---
>  fs/nfs/pnfs.c |   36 +++++++++++++++++++++++++-----------
>  1 files changed, 25 insertions(+), 11 deletions(-)
> 
> diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
> index 924e6fd..21192b6 100644
> --- a/fs/nfs/pnfs.c
> +++ b/fs/nfs/pnfs.c
> @@ -348,19 +348,27 @@ put_layout(struct pnfs_layout_type *lo)
>  	BUG_ON_UNLOCKED_LO(lo);
>  	BUG_ON(lo->refcount <= 0);
>  
> -	if (--lo->refcount == 0 && list_empty(&lo->segs)) {
> +	lo->refcount--;
> +
> +	if (lo->refcount > 1)
> +		return;
> +
> +	/* Make sure is removed from inode list */
> +	clp = NFS_SERVER(&nfsi->vfs_inode)->nfs_client;
> +	spin_lock(&clp->cl_lock);
> +	if (!list_empty(&lo->lo_layouts)) {
> +		list_del_init(&lo->lo_layouts);
> +		lo->refcount--;
> +	}
> +	spin_unlock(&clp->cl_lock);

This is awkward.
If we're already doing this overhaul the right thing to do
is separate out listing/unlisting of the layout on the clp list
so that the lo is added to the clp list when its lo->segs list
goes from empty to not empty (and in this case get_layout can be called
as you did as there's a reference from the clp to the lo)
and when its segs list empties it should be unlisted and
put_layout(), then if its refcount will go back to 0
it can be destroyed.

> +
> +	if (lo->refcount == 0) {

In this case I'd like to add a
		WARN_ON(!list_empty(&lo->segs))
to make sure that the refcounting agrees with the list manipulation.

Thanks!

Benny

>  		struct layoutdriver_io_operations *io_ops =
>  			PNFS_LD_IO_OPS(lo);
>  
>  		dprintk("%s: freeing layout %p\n", __func__, lo->ld_data);
>  		io_ops->free_layout(lo->ld_data);
>  		lo->ld_data = NULL;
> -
> -		/* Unlist the layout. */
> -		clp = NFS_SERVER(&nfsi->vfs_inode)->nfs_client;
> -		spin_lock(&clp->cl_lock);
> -		list_del_init(&lo->lo_layouts);
> -		spin_unlock(&clp->cl_lock);
>  	}
>  }
>  
> @@ -404,6 +412,7 @@ init_lseg(struct pnfs_layout_type *lo, struct pnfs_layout_segment *lseg)
>  	kref_init(&lseg->kref);
>  	lseg->valid = true;
>  	lseg->layout = lo;
> +	get_layout(lo);
>  }
>  
>  static void
> @@ -413,6 +422,7 @@ destroy_lseg(struct kref *kref)
>  		container_of(kref, struct pnfs_layout_segment, kref);
>  
>  	dprintk("--> %s\n", __func__);
> +	put_layout(lseg->layout);
>  	PNFS_LD_IO_OPS(lseg->layout)->free_lseg(lseg);
>  }
>  
> @@ -897,9 +907,10 @@ alloc_init_layout(struct inode *ino)
>  	void *ld_data;
>  	struct pnfs_layout_type *lo;
>  	struct layoutdriver_io_operations *io_ops;
> +	struct nfs_inode *nfsi = NFS_I(ino);
>  
>  	io_ops = NFS_SERVER(ino)->pnfs_curr_ld->ld_io_ops;
> -	lo = &NFS_I(ino)->layout;
> +	lo  = &nfsi->layout;
>  	ld_data = io_ops->alloc_layout(ino);
>  	if (!ld_data) {
>  		printk(KERN_ERR
> @@ -908,11 +919,13 @@ alloc_init_layout(struct inode *ino)
>  		return NULL;
>  	}
>  
> +	spin_lock(&nfsi->lo_lock);
>  	BUG_ON(lo->ld_data != NULL);
>  	lo->ld_data = ld_data;
>  	memset(&lo->stateid, 0, NFS4_STATEID_SIZE);
>  	lo->refcount = 1;
>  	lo->roc_iomode = 0;
> +	spin_unlock(&nfsi->lo_lock);
>  	return lo;
>  }
>  
> @@ -970,8 +983,10 @@ get_lock_alloc_layout(struct inode *ino)
>  			spin_lock(&nfsi->lo_lock);
>  
>  			spin_lock(&clp->cl_lock);
> -			if (list_empty(&lo->lo_layouts))
> +			if (list_empty(&lo->lo_layouts)) {
>  				list_add_tail(&lo->lo_layouts, &clp->cl_layouts);
> +				get_layout(lo);
> +			}
>  			spin_unlock(&clp->cl_lock);
>  		} else
>  			lo = ERR_PTR(-ENOMEM);
> @@ -1259,14 +1274,13 @@ pnfs_layout_process(struct nfs4_pnfs_layoutget *lgp)
>  		goto out;
>  	}
>  
> +	spin_lock(&nfsi->lo_lock);
>  	init_lseg(lo, lseg);
>  	lseg->range = res->lseg;
>  	if (lgp->lsegpp) {
>  		get_lseg(lseg);
>  		*lgp->lsegpp = lseg;
>  	}
> -
> -	spin_lock(&nfsi->lo_lock);
>  	pnfs_insert_layout(lo, lseg);
>  
>  	if (res->return_on_close) {


      parent reply	other threads:[~2010-06-15 16:57 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-15  1:46 [PATCH 00/10] layout refcounting changes Fred Isaman
2010-06-15  1:46 ` [PATCH 01/10] pnfs-submit: separate locking from get and put of layout Fred Isaman
2010-06-15  1:46   ` [PATCH 02/10] pnfs-submit: split get_layout and grab_current_layout Fred Isaman
2010-06-15  1:46     ` [PATCH 03/10] pnfs-submit: remove list_empty check from put_layout Fred Isaman
2010-06-15  1:46       ` [PATCH 04/10] pnfs-submit: add backpointer to pnfs_layout_type Fred Isaman
2010-06-15  1:46         ` [PATCH 05/10] pnfs-submit: Move pnfs_layout_state and pnfs_layout_suspend back to nfs_inode Fred Isaman
2010-06-15  1:46           ` [PATCH 06/10] pnfs-submit: Add state flag for layoutcommit_needed Fred Isaman
2010-06-15  1:46             ` [PATCH 07/10] pnfs-submit: avoid race handling return on close Fred Isaman
2010-06-15  1:46               ` [PATCH 08/10] pnfs-submit: change nfsi->layout to a pointer Fred Isaman
2010-06-15  1:46                 ` [PATCH 09/10] pnfs-submit: API change: alloc_layout returns layout cache head Fred Isaman
2010-06-15  1:46                   ` [PATCH 10/10] pnfs-submit: filelayout: adjust to new alloc_layout API Fred Isaman
2010-06-15 17:06               ` [PATCH 07/10] pnfs-submit: avoid race handling return on close Benny Halevy
2010-06-15 17:32                 ` Fred Isaman
     [not found]                   ` <AANLkTilDj2Ua_t77kk5Gj_t0vqEcOJFKlqODAj18KQnm-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-06-15 17:33                     ` Trond Myklebust
     [not found]                       ` <1276623230.8767.48.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org>
2010-06-15 17:52                         ` Fred Isaman
     [not found]                           ` <AANLkTimScICltrCrtEIz7qw1GzuaTGNwCVTk-ZTsZO4_-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-06-15 18:19                             ` Trond Myklebust
     [not found]                               ` <1276625991.2988.1.camel-rJ7iovZKK19ZJLDQqaL3InhyD016LWXt@public.gmane.org>
2010-06-15 18:47                                 ` Benny Halevy
2010-06-15 17:00         ` [PATCH 04/10] pnfs-submit: add backpointer to pnfs_layout_type Benny Halevy
2010-06-15 16:56       ` Benny Halevy [this message]

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=4C17B0DA.8010206@panasas.com \
    --to=bhalevy@panasas.com \
    --cc=iisaman@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.