linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] xfs: flush posteof zeroing before reflink truncation
@ 2018-11-16 19:07 Darrick J. Wong
  2018-11-16 19:31 ` Brian Foster
  2018-11-16 20:37 ` Dave Chinner
  0 siblings, 2 replies; 8+ messages in thread
From: Darrick J. Wong @ 2018-11-16 19:07 UTC (permalink / raw)
  To: Brian Foster, Dave Chinner; +Cc: xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

If we're remapping into a range that starts beyond EOF, we have to zero
the memory between EOF and the start of the target range, as established
in 410fdc72b05af.  However, in 4918ef4ea008, we extended the pagecache
truncation range downwards to a page boundary to guarantee that
pagecache pages are removed and that there's no possibility that we end
up zeroing subpage blocks within a page.  Unfortunately, we never commit
the posteof zeroing to disk, so on a filesystem where page size > block
size the truncation partially undoes the zeroing and we end up with
stale disk contents.

Brian and I reproduced this problem by running generic/091 on a 1k block
xfs filesystem, assuming fsx in fstests supports clone/dedupe/copyrange.

Fixes: 410fdc72b05a ("xfs: zero posteof blocks when cloning above eof")
Fixes: 4918ef4ea008 ("xfs: fix pagecache truncation prior to reflink")
Simultaneously-diagnosed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
Note: I haven't tested this thoroughly but wanted to push this out for
everyone to look at ASAP.
---
 fs/xfs/xfs_reflink.c |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c
index c56bdbfcf7ae..8ea09a7e550c 100644
--- a/fs/xfs/xfs_reflink.c
+++ b/fs/xfs/xfs_reflink.c
@@ -1255,13 +1255,19 @@ xfs_reflink_zero_posteof(
 	loff_t			pos)
 {
 	loff_t			isize = i_size_read(VFS_I(ip));
+	int			error;
 
 	if (pos <= isize)
 		return 0;
 
 	trace_xfs_zero_eof(ip, isize, pos - isize);
-	return iomap_zero_range(VFS_I(ip), isize, pos - isize, NULL,
+	error = iomap_zero_range(VFS_I(ip), isize, pos - isize, NULL,
 			&xfs_iomap_ops);
+	if (error)
+		return error;
+
+	return filemap_write_and_wait_range(VFS_I(ip)->i_mapping,
+			isize, pos - 1);
 }
 
 /*

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-11-20  8:33 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-16 19:07 [RFC PATCH] xfs: flush posteof zeroing before reflink truncation Darrick J. Wong
2018-11-16 19:31 ` Brian Foster
2018-11-16 20:37 ` Dave Chinner
2018-11-18 14:12   ` Brian Foster
2018-11-19  0:26     ` Dave Chinner
2018-11-19 19:05       ` Brian Foster
2018-11-19 22:04         ` Dave Chinner
2018-11-19 22:07           ` Dave Chinner

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).