]> git.karo-electronics.de Git - linux-beck.git/commitdiff
xfs: flush the range before zero range conversion
authorBrian Foster <bfoster@redhat.com>
Wed, 1 Oct 2014 23:44:54 +0000 (09:44 +1000)
committerDave Chinner <david@fromorbit.com>
Wed, 1 Oct 2014 23:44:54 +0000 (09:44 +1000)
XFS currently discards delalloc blocks within the target range of a
zero range request. Unaligned start and end offsets are zeroed
through the page cache and the internal, aligned blocks are
converted to unwritten extents.

If EOF is page aligned and covered by a delayed allocation extent.
The inode size is not updated until I/O completion. If a zero range
request discards a delalloc range that covers page aligned EOF as
such, the inode size update never occurs. For example:

$ rm -f /mnt/file
$ xfs_io -fc "pwrite 0 64k" -c "zero 60k 4k" /mnt/file
$ stat -c "%s" /mnt/file
65536
$ umount /mnt
$ mount <dev> /mnt
$ stat -c "%s" /mnt/file
61440

Update xfs_zero_file_space() to flush the range rather than discard
delalloc blocks to ensure that inode size updates occur
appropriately.

[dchinner: Note that this is really a workaround to avoid the
underlying problems. More work is needed (and ongoing) to fix those
issues so this fix is being added as a temporary stop-gap measure. ]

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
fs/xfs/xfs_bmap_util.c

index 1cb345e7c1819936f9517dd76cc428077208a593..6f5cb63bed176ca31a580ccd062cc57d958d3e77 100644 (file)
@@ -1392,14 +1392,14 @@ xfs_zero_file_space(
 
        if (start_boundary < end_boundary - 1) {
                /*
-                * punch out delayed allocation blocks and the page cache over
-                * the conversion range
+                * Writeback the range to ensure any inode size updates due to
+                * appending writes make it to disk (otherwise we could just
+                * punch out the delalloc blocks).
                 */
-               xfs_ilock(ip, XFS_ILOCK_EXCL);
-               error = xfs_bmap_punch_delalloc_range(ip,
-                               XFS_B_TO_FSBT(mp, start_boundary),
-                               XFS_B_TO_FSB(mp, end_boundary - start_boundary));
-               xfs_iunlock(ip, XFS_ILOCK_EXCL);
+               error = filemap_write_and_wait_range(VFS_I(ip)->i_mapping,
+                               start_boundary, end_boundary - 1);
+               if (error)
+                       goto out;
                truncate_pagecache_range(VFS_I(ip), start_boundary,
                                         end_boundary - 1);