Skip to content

Commit 35dc55b

Browse files
Christoph HellwigChandan Babu R
authored andcommitted
xfs: handle nimaps=0 from xfs_bmapi_write in xfs_alloc_file_space
If xfs_bmapi_write finds a delalloc extent at the requested range, it tries to convert the entire delalloc extent to a real allocation. But if the allocator cannot find a single free extent large enough to cover the start block of the requested range, xfs_bmapi_write will return 0 but leave *nimaps set to 0. In that case we simply need to keep looping with the same startoffset_fsb so that one of the following allocations will eventually reach the requested range. Note that this could affect any caller of xfs_bmapi_write that covers an existing delayed allocation. As far as I can tell we do not have any other such caller, though - the regular writeback path uses xfs_bmapi_convert_delalloc to convert delayed allocations to real ones, and direct I/O invalidates the page cache first. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: "Darrick J. Wong" <[email protected]> Signed-off-by: Chandan Babu R <[email protected]>
1 parent 2b99e41 commit 35dc55b

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

fs/xfs/xfs_bmap_util.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -774,12 +774,10 @@ xfs_alloc_file_space(
774774
{
775775
xfs_mount_t *mp = ip->i_mount;
776776
xfs_off_t count;
777-
xfs_filblks_t allocated_fsb;
778777
xfs_filblks_t allocatesize_fsb;
779778
xfs_extlen_t extsz, temp;
780779
xfs_fileoff_t startoffset_fsb;
781780
xfs_fileoff_t endoffset_fsb;
782-
int nimaps;
783781
int rt;
784782
xfs_trans_t *tp;
785783
xfs_bmbt_irec_t imaps[1], *imapp;
@@ -802,7 +800,6 @@ xfs_alloc_file_space(
802800

803801
count = len;
804802
imapp = &imaps[0];
805-
nimaps = 1;
806803
startoffset_fsb = XFS_B_TO_FSBT(mp, offset);
807804
endoffset_fsb = XFS_B_TO_FSB(mp, offset + count);
808805
allocatesize_fsb = endoffset_fsb - startoffset_fsb;
@@ -813,6 +810,7 @@ xfs_alloc_file_space(
813810
while (allocatesize_fsb && !error) {
814811
xfs_fileoff_t s, e;
815812
unsigned int dblocks, rblocks, resblks;
813+
int nimaps = 1;
816814

817815
/*
818816
* Determine space reservations for data/realtime.
@@ -878,15 +876,19 @@ xfs_alloc_file_space(
878876
if (error)
879877
break;
880878

881-
allocated_fsb = imapp->br_blockcount;
882-
883-
if (nimaps == 0) {
884-
error = -ENOSPC;
885-
break;
879+
/*
880+
* If the allocator cannot find a single free extent large
881+
* enough to cover the start block of the requested range,
882+
* xfs_bmapi_write will return 0 but leave *nimaps set to 0.
883+
*
884+
* In that case we simply need to keep looping with the same
885+
* startoffset_fsb so that one of the following allocations
886+
* will eventually reach the requested range.
887+
*/
888+
if (nimaps) {
889+
startoffset_fsb += imapp->br_blockcount;
890+
allocatesize_fsb -= imapp->br_blockcount;
886891
}
887-
888-
startoffset_fsb += allocated_fsb;
889-
allocatesize_fsb -= allocated_fsb;
890892
}
891893

892894
return error;

0 commit comments

Comments
 (0)