• Darrick J. Wong's avatar
    xfs: automatic freeing of freshly allocated unwritten space · e3042be3
    Darrick J. Wong authored
    As mentioned in the previous commit, online repair wants to allocate
    space to write out a new metadata structure, and it also wants to hedge
    against system crashes during repairs by logging (and later cancelling)
    EFIs to free the space if we crash before committing the new data
    structure.
    
    Therefore, create a trio of functions to schedule automatic reaping of
    freshly allocated unwritten space.  xfs_alloc_schedule_autoreap creates
    a paused EFI representing the space we just allocated.  Once the
    allocations are made and the autoreaps scheduled, we can start writing
    to disk.
    
    If the writes succeed, xfs_alloc_cancel_autoreap marks the EFI work
    items as stale and unpauses the pending deferred work item.  Assuming
    that's done in the same transaction that commits the new structure into
    the filesystem, we guarantee that either the new object is fully
    visible, or that all the space gets reclaimed.
    
    If the writes succeed but only part of an extent was used, repair must
    call the same _cancel_autoreap function to kill the first EFI and then
    log a new EFI to free the unused space.  The first EFI is already
    committed, so it cannot be changed.
    
    For full extents that aren't used, xfs_alloc_commit_autoreap will
    unpause the EFI, which results in the space being freed during the next
    _defer_finish cycle.
    Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
    Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
    e3042be3
xfs_alloc.h 9.59 KB