summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Reitz <mreitz@redhat.com>2019-09-30 14:29:44 -0400
committerDarrick J. Wong <darrick.wong@oracle.com>2019-10-06 18:39:05 -0400
commite093c4be760ebf46c131ae0dd6138865a22f46fa (patch)
tree82261bab8e71e6c3fea87143beebfc9af97fb133
parentda0c9ea146cbe92b832f1b0f694840ea8eb33cce (diff)
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>
-rw-r--r--fs/xfs/xfs_bmap_util.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
index 0910cb75b65d..4f443703065e 100644
--- a/fs/xfs/xfs_bmap_util.c
+++ b/fs/xfs/xfs_bmap_util.c
@@ -864,6 +864,7 @@ xfs_alloc_file_space(
864 xfs_filblks_t allocatesize_fsb; 864 xfs_filblks_t allocatesize_fsb;
865 xfs_extlen_t extsz, temp; 865 xfs_extlen_t extsz, temp;
866 xfs_fileoff_t startoffset_fsb; 866 xfs_fileoff_t startoffset_fsb;
867 xfs_fileoff_t endoffset_fsb;
867 int nimaps; 868 int nimaps;
868 int quota_flag; 869 int quota_flag;
869 int rt; 870 int rt;
@@ -891,7 +892,8 @@ xfs_alloc_file_space(
891 imapp = &imaps[0]; 892 imapp = &imaps[0];
892 nimaps = 1; 893 nimaps = 1;
893 startoffset_fsb = XFS_B_TO_FSBT(mp, offset); 894 startoffset_fsb = XFS_B_TO_FSBT(mp, offset);
894 allocatesize_fsb = XFS_B_TO_FSB(mp, count); 895 endoffset_fsb = XFS_B_TO_FSB(mp, offset + count);
896 allocatesize_fsb = endoffset_fsb - startoffset_fsb;
895 897
896 /* 898 /*
897 * Allocate file space until done or until there is an error 899 * Allocate file space until done or until there is an error