• Christoph Hellwig's avatar
    xfs: fix xfs_bmap_add_extent_delay_real for partial conversions · d69bee6a
    Christoph Hellwig authored
    xfs_bmap_add_extent_delay_real takes parts or all of a delalloc extent
    and converts them to a real extent.  It is written to deal with any
    potential overlap of the to be converted range with the delalloc extent,
    but it turns out that currently only converting the entire extents, or a
    part starting at the beginning is actually exercised, as the only caller
    always tries to convert the entire delalloc extent, and either succeeds
    or at least progresses partially from the start.
    
    If it only converts a tiny part of a delalloc extent, the indirect block
    calculation for the new delalloc extent (da_new) might be equivalent to that
    of the existing delalloc extent (da_old).  If this extent conversion now
    requires allocating an indirect block that gets accounted into da_new,
    leading to the assert that da_new must be smaller or equal to da_new
    unless we split the extent to trigger.
    
    Except for the assert that case is actually handled by just trying to
    allocate more space, as that already handled for the split case (which
    currently can't be reached at all), so just reusing it should be fine.
    Except that without dipping into the reserved block pool that would make
    it a bit too easy to trigger a fs shutdown due to ENOSPC.  So in addition
    to adjusting the assert, also dip into the reserved block pool.
    
    Note that I could only reproduce the assert with a change to only convert
    the actually asked range instead of the full delalloc extent from
    xfs_bmapi_write.
    Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
    Reviewed-by: default avatar"Darrick J. Wong" <djwong@kernel.org>
    Signed-off-by: default avatarChandan Babu R <chandanbabu@kernel.org>
    d69bee6a
xfs_bmap.c 171 KB