All of lore.kernel.org
 help / color / mirror / Atom feed
From: Benny Halevy <bhalevy@tonian.com>
To: Trond Myklebust <Trond.Myklebust@netapp.com>
Cc: linux-nfs@vger.kernel.org, Boaz Harrosh <bharrosh@panasas.com>,
	Peng Tao <bergwolf@gmail.com>
Subject: Re: [PATCH 2/3] NFSv4.1: Always clear the NFS_INO_LAYOUTCOMMIT in layoutreturn
Date: Thu, 21 Mar 2013 13:25:05 +0200	[thread overview]
Message-ID: <514AEE11.1030705@tonian.com> (raw)
In-Reply-To: <1363801148-29998-2-git-send-email-Trond.Myklebust@netapp.com>

On 2013-03-20 19:39, Trond Myklebust wrote:
> Note that clearing NFS_INO_LAYOUTCOMMIT is tricky, since it requires
> you to also clear the NFS_LSEG_LAYOUTCOMMIT bits from the layout
> segments.
> The only two sites that need to do this are the ones that call
> pnfs_return_layout() without first doing a layout commit.
> 
> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
> Cc: Benny Halevy <bhalevy@tonian.com>

ACK

> Cc: stable@vger.kernel.org
> ---
>  fs/nfs/nfs4filelayout.c |  1 -
>  fs/nfs/pnfs.c           | 35 +++++++++++++++++++++++++++--------
>  2 files changed, 27 insertions(+), 9 deletions(-)
> 
> diff --git a/fs/nfs/nfs4filelayout.c b/fs/nfs/nfs4filelayout.c
> index c5656c5..22d1062 100644
> --- a/fs/nfs/nfs4filelayout.c
> +++ b/fs/nfs/nfs4filelayout.c
> @@ -129,7 +129,6 @@ static void filelayout_fenceme(struct inode *inode, struct pnfs_layout_hdr *lo)
>  {
>  	if (!test_and_clear_bit(NFS_LAYOUT_RETURN, &lo->plh_flags))
>  		return;
> -	clear_bit(NFS_INO_LAYOUTCOMMIT, &NFS_I(inode)->flags);
>  	pnfs_return_layout(inode);
>  }
>  
> diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
> index 6f6b356..45badca 100644
> --- a/fs/nfs/pnfs.c
> +++ b/fs/nfs/pnfs.c
> @@ -417,6 +417,16 @@ should_free_lseg(struct pnfs_layout_range *lseg_range,
>  	       lo_seg_intersecting(lseg_range, recall_range);
>  }
>  
> +static bool lseg_dec_and_remove_zero(struct pnfs_layout_segment *lseg,
> +		struct list_head *tmp_list)
> +{
> +	if (!atomic_dec_and_test(&lseg->pls_refcount))
> +		return false;
> +	pnfs_layout_remove_lseg(lseg->pls_layout, lseg);
> +	list_add(&lseg->pls_list, tmp_list);
> +	return true;
> +}
> +
>  /* Returns 1 if lseg is removed from list, 0 otherwise */
>  static int mark_lseg_invalid(struct pnfs_layout_segment *lseg,
>  			     struct list_head *tmp_list)
> @@ -430,11 +440,8 @@ static int mark_lseg_invalid(struct pnfs_layout_segment *lseg,
>  		 */
>  		dprintk("%s: lseg %p ref %d\n", __func__, lseg,
>  			atomic_read(&lseg->pls_refcount));
> -		if (atomic_dec_and_test(&lseg->pls_refcount)) {
> -			pnfs_layout_remove_lseg(lseg->pls_layout, lseg);
> -			list_add(&lseg->pls_list, tmp_list);
> +		if (lseg_dec_and_remove_zero(lseg, tmp_list))
>  			rv = 1;
> -		}
>  	}
>  	return rv;
>  }
> @@ -779,6 +786,21 @@ send_layoutget(struct pnfs_layout_hdr *lo,
>  	return lseg;
>  }
>  
> +static void pnfs_clear_layoutcommit(struct inode *inode,
> +		struct list_head *head)
> +{
> +	struct nfs_inode *nfsi = NFS_I(inode);
> +	struct pnfs_layout_segment *lseg, *tmp;
> +
> +	if (!test_and_clear_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags))
> +		return;
> +	list_for_each_entry_safe(lseg, tmp, &nfsi->layout->plh_segs, pls_list) {
> +		if (!test_and_clear_bit(NFS_LSEG_LAYOUTCOMMIT, &lseg->pls_flags))
> +			continue;
> +		lseg_dec_and_remove_zero(lseg, head);
> +	}
> +}
> +
>  /*
>   * Initiates a LAYOUTRETURN(FILE), and removes the pnfs_layout_hdr
>   * when the layout segment list is empty.
> @@ -810,6 +832,7 @@ _pnfs_return_layout(struct inode *ino)
>  	/* Reference matched in nfs4_layoutreturn_release */
>  	pnfs_get_layout_hdr(lo);
>  	empty = list_empty(&lo->plh_segs);
> +	pnfs_clear_layoutcommit(ino, &tmp_list);
>  	pnfs_mark_matching_lsegs_invalid(lo, &tmp_list, NULL);
>  	/* Don't send a LAYOUTRETURN if list was initially empty */
>  	if (empty) {
> @@ -822,8 +845,6 @@ _pnfs_return_layout(struct inode *ino)
>  	spin_unlock(&ino->i_lock);
>  	pnfs_free_lseg_list(&tmp_list);
>  
> -	WARN_ON(test_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags));
> -
>  	lrp = kzalloc(sizeof(*lrp), GFP_KERNEL);
>  	if (unlikely(lrp == NULL)) {
>  		status = -ENOMEM;
> @@ -1460,7 +1481,6 @@ static void pnfs_ld_handle_write_error(struct nfs_write_data *data)
>  	dprintk("pnfs write error = %d\n", hdr->pnfs_error);
>  	if (NFS_SERVER(hdr->inode)->pnfs_curr_ld->flags &
>  	    PNFS_LAYOUTRET_ON_ERROR) {
> -		clear_bit(NFS_INO_LAYOUTCOMMIT, &NFS_I(hdr->inode)->flags);
>  		pnfs_return_layout(hdr->inode);
>  	}
>  	if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags))
> @@ -1615,7 +1635,6 @@ static void pnfs_ld_handle_read_error(struct nfs_read_data *data)
>  	dprintk("pnfs read error = %d\n", hdr->pnfs_error);
>  	if (NFS_SERVER(hdr->inode)->pnfs_curr_ld->flags &
>  	    PNFS_LAYOUTRET_ON_ERROR) {
> -		clear_bit(NFS_INO_LAYOUTCOMMIT, &NFS_I(hdr->inode)->flags);
>  		pnfs_return_layout(hdr->inode);
>  	}
>  	if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags))
> 

  parent reply	other threads:[~2013-03-21 11:25 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-20 17:39 [PATCH 1/3] NFSv4.1: Fix a race in pNFS layoutcommit Trond Myklebust
2013-03-20 17:39 ` [PATCH 2/3] NFSv4.1: Always clear the NFS_INO_LAYOUTCOMMIT in layoutreturn Trond Myklebust
2013-03-20 17:39   ` [PATCH 3/3] NFSv4.1: Add a helper pnfs_commit_and_return_layout Trond Myklebust
2013-03-21 11:25     ` Boaz Harrosh
2013-03-21 14:07       ` Myklebust, Trond
2013-03-21 11:27     ` Benny Halevy
2013-03-21 13:59       ` Myklebust, Trond
2013-03-21 11:25   ` Benny Halevy [this message]
2013-03-21 11:22 ` [PATCH 1/3] NFSv4.1: Fix a race in pNFS layoutcommit Benny Halevy

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=514AEE11.1030705@tonian.com \
    --to=bhalevy@tonian.com \
    --cc=Trond.Myklebust@netapp.com \
    --cc=bergwolf@gmail.com \
    --cc=bharrosh@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 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.