]> git.baikalelectronics.ru Git - kernel.git/commit
xfs: Fix tail rounding in xfs_alloc_file_space()
authorMax Reitz <mreitz@redhat.com>
Mon, 30 Sep 2019 18:29:44 +0000 (11:29 -0700)
committerDarrick J. Wong <darrick.wong@oracle.com>
Sun, 6 Oct 2019 22:39:05 +0000 (15:39 -0700)
commitc7601c6bef0cb3912cd557b6ccb56dc262df995c
tree82261bab8e71e6c3fea87143beebfc9af97fb133
parent52b7759f73b03afc7cba59d3686ec69261291235
xfs: Fix tail rounding in xfs_alloc_file_space()

To ensure that all blocks touched by the range [offset, offset + count)
are allocated, we need to calculate the block count from the difference
of the range end (rounded up) and the range start (rounded down).

Before this patch, we just round up the byte count, which may lead to
unaligned ranges not being fully allocated:

$ touch test_file
$ block_size=$(stat -fc '%S' test_file)
$ fallocate -o $((block_size / 2)) -l $block_size test_file
$ xfs_bmap test_file
test_file:
        0: [0..7]: 1396264..1396271
        1: [8..15]: hole

There should not be a hole there.  Instead, the first two blocks should
be fully allocated.

With this patch applied, the result is something like this:

$ touch test_file
$ block_size=$(stat -fc '%S' test_file)
$ fallocate -o $((block_size / 2)) -l $block_size test_file
$ xfs_bmap test_file
test_file:
        0: [0..15]: 11024..11039

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
fs/xfs/xfs_bmap_util.c