linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benjamin Coddington <bcodding@redhat.com>
To: linux-nfs@vger.kernel.org
Cc: Trond Myklebust <trond.myklebust@primarydata.com>,
	Anna Schumaker <anna.schumaker@netapp.com>,
	Christoph Hellwig <hch@lst.de>
Subject: [PATCH] pnfs/blocklayout: update last_write_offset atomically with extents
Date: Thu, 18 Aug 2016 11:55:53 -0400	[thread overview]
Message-ID: <a754067b5a8252a10a0bcfa23c4229cf3d7b1adf.1471535578.git.bcodding@redhat.com> (raw)

Block/SCSI layout write completion may add committable extents to the
extent tree before updating the layout's last-written byte under the inode
lock.  If a sync happens before this value is updated, then
prepare_layoutcommit may find and encode these extents which would produce
a LAYOUTCOMMIT request whose encoded extents are larger than the request's
loca_length.

Fix this by holding the i_lock while marking extents writeable and updating
the value of the last written byte.  Then extending the i_lock over
prepare_layoutcommit in pnfs_layoutcommit_inode() ensures we won't find
extents starting beyond the current last written byte.

Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
---
 fs/nfs/blocklayout/blocklayout.c | 3 +++
 fs/nfs/pnfs.c                    | 4 +---
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/fs/nfs/blocklayout/blocklayout.c b/fs/nfs/blocklayout/blocklayout.c
index 17a42e4eb872..36923b55f4f8 100644
--- a/fs/nfs/blocklayout/blocklayout.c
+++ b/fs/nfs/blocklayout/blocklayout.c
@@ -343,8 +343,11 @@ static void bl_write_cleanup(struct work_struct *work)
 		u64 end = (hdr->args.offset + hdr->args.count +
 			PAGE_SIZE - 1) & (loff_t)PAGE_MASK;
 
+		spin_lock(&hdr->inode->i_lock);
+		bl->bl_layout.plh_lwb = hdr->args.offset + hdr->res.count;
 		ext_tree_mark_written(bl, start >> SECTOR_SHIFT,
 					(end - start) >> SECTOR_SHIFT);
+		spin_unlock(&hdr->inode->i_lock);
 	}
 
 	pnfs_ld_write_done(hdr);
diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
index 4110c1dc8f68..978df68c498c 100644
--- a/fs/nfs/pnfs.c
+++ b/fs/nfs/pnfs.c
@@ -2386,7 +2386,6 @@ pnfs_layoutcommit_inode(struct inode *inode, bool sync)
 	end_pos = nfsi->layout->plh_lwb;
 
 	nfs4_stateid_copy(&data->args.stateid, &nfsi->layout->plh_stateid);
-	spin_unlock(&inode->i_lock);
 
 	data->args.inode = inode;
 	data->cred = get_rpccred(nfsi->layout->plh_lc_cred);
@@ -2403,14 +2402,13 @@ pnfs_layoutcommit_inode(struct inode *inode, bool sync)
 		status = ld->prepare_layoutcommit(&data->args);
 		if (status) {
 			put_rpccred(data->cred);
-			spin_lock(&inode->i_lock);
 			set_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags);
 			if (end_pos > nfsi->layout->plh_lwb)
 				nfsi->layout->plh_lwb = end_pos;
 			goto out_unlock;
 		}
 	}
-
+	spin_unlock(&inode->i_lock);
 
 	status = nfs4_proc_layoutcommit(data, sync);
 out:
-- 
2.5.5


             reply	other threads:[~2016-08-19  1:22 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-18 15:55 Benjamin Coddington [this message]
2016-08-18 18:19 ` [PATCH] pnfs/blocklayout: update last_write_offset atomically with extents Trond Myklebust
2016-08-18 18:46   ` Benjamin Coddington
2016-08-22 13:48 ` [PATCH v2] " Benjamin Coddington
2016-08-22 15:34   ` Trond Myklebust
2016-08-22 16:22     ` Benjamin Coddington
2016-08-22 18:11 ` [PATCH v3] " Benjamin Coddington
2016-09-19 14:58   ` Christoph Hellwig
2016-09-19 19:04     ` Benjamin Coddington
2016-09-19 19:06       ` Christoph Hellwig
2016-09-19 19:40         ` Benjamin Coddington
2016-09-20 12:22           ` [PATCH] pnfs/blocklayout: last_write_offset incorrectly set to end of extent Benjamin Coddington
2016-09-20 16:38             ` Christoph Hellwig

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=a754067b5a8252a10a0bcfa23c4229cf3d7b1adf.1471535578.git.bcodding@redhat.com \
    --to=bcodding@redhat.com \
    --cc=anna.schumaker@netapp.com \
    --cc=hch@lst.de \
    --cc=linux-nfs@vger.kernel.org \
    --cc=trond.myklebust@primarydata.com \
    /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).