public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Dave Chinner <david@fromorbit.com>
To: xfs@oss.sgi.com
Subject: [PATCH 6/7] xfs: xfs_file_collapse_range is delalloc challenged
Date: Thu, 28 Aug 2014 21:49:10 +1000	[thread overview]
Message-ID: <1409226551-16570-7-git-send-email-david@fromorbit.com> (raw)
In-Reply-To: <1409226551-16570-1-git-send-email-david@fromorbit.com>

From: Dave Chinner <dchinner@redhat.com>

If we have delalloc extents on a file before we run a collapse range
opertaion, we sync the range that we are going to collapse to
convert delalloc extents in that region to real extents to simplify
the shift operation.

However, the shift operation then assumes that the extent list is
not going to change as it iterates over the extent list moving
things about. Unfortunately, this isn't true because we can't hold
the ILOCK over all the operations. We can prevent new IO from
modifying the extent list by holding the IOLOCK, but that doesn't
prevent writeback from running....

And when writeback runs, it can convert delalloc extents is the
range of the file prior to the region being collapsed, and this
changes the indexes of all the extents in the file. That causes the
collapse range operation to Go Bad.

The right fix is to rewrite the extent shift operation not to be
dependent on the extent list not changing across the entire
operation, but this is a fairly significant piece of work to do.
Hence, as a short-term workaround for the problem, sync the entire
file before starting a collapse operation to remove all delalloc
ranges from the file and so avoid the problem of concurrent
writeback changing the extent list.

Diagnosed-and-Reported-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
---
 fs/xfs/xfs_bmap_util.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
index aa70620..283e20c 100644
--- a/fs/xfs/xfs_bmap_util.c
+++ b/fs/xfs/xfs_bmap_util.c
@@ -1444,6 +1444,19 @@ xfs_collapse_file_space(
 	start_fsb = XFS_B_TO_FSB(mp, offset + len);
 	shift_fsb = XFS_B_TO_FSB(mp, len);
 
+	/*
+	 * writeback the entire file to prevent concurrent writeback of ranges
+	 * outside the collapsing region from changing the extent list.
+	 *
+	 * XXX: This is a temporary fix until the extent shift loop below is
+	 * converted to use offsets and lookups within the ILOCK rather than
+	 * carrying around the index into the extent list for the next
+	 * iteration.
+	 */
+	error = filemap_write_and_wait(VFS_I(ip)->i_mapping);
+	if (error)
+		return error;
+
 	error = xfs_free_file_space(ip, offset, len);
 	if (error)
 		return error;
-- 
2.0.0

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

  parent reply	other threads:[~2014-08-28 11:49 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-28 11:49 [PATCH v2 0/7] xfs: invalidation and related fixes for v3.17-rc3 Dave Chinner
2014-08-28 11:49 ` [PATCH 1/7] xfs: don't dirty buffers beyond EOF Dave Chinner
2014-08-28 13:34   ` Brian Foster
2014-08-28 22:37     ` Dave Chinner
2014-08-28 23:49       ` [PATCH 1/7 v2] " Dave Chinner
2014-08-29 12:13         ` Brian Foster
2014-08-29  0:39   ` [PATCH 1/7] " Christoph Hellwig
2014-08-29  0:53     ` Dave Chinner
2014-08-28 11:49 ` [PATCH 2/7] xfs: don't zero partial page cache pages during O_DIRECT writes Dave Chinner
2014-08-29  0:39   ` Christoph Hellwig
2014-08-28 11:49 ` [PATCH 3/7] " Dave Chinner
2014-08-29  0:39   ` Christoph Hellwig
2014-08-28 11:49 ` [PATCH 4/7] xfs: use ranged writeback and invalidation for direct IO Dave Chinner
2014-08-29  0:40   ` Christoph Hellwig
2014-08-28 11:49 ` [PATCH 5/7] xfs: don't log inode unless extent shift makes extent modifications Dave Chinner
2014-08-29  0:41   ` Christoph Hellwig
2014-08-28 11:49 ` Dave Chinner [this message]
2014-08-29  0:41   ` [PATCH 6/7] xfs: xfs_file_collapse_range is delalloc challenged Christoph Hellwig
2014-08-28 11:49 ` [PATCH 7/7] xfs: trim eofblocks before collapse range Dave Chinner
2014-08-29  0:42   ` 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=1409226551-16570-7-git-send-email-david@fromorbit.com \
    --to=david@fromorbit.com \
    --cc=xfs@oss.sgi.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