• Dave Chinner's avatar
    xfs: add log item precommit operation · fad743d7
    Dave Chinner authored
    For inodes that are dirty, we have an attached cluster buffer that
    we want to use to track the dirty inode through the AIL.
    Unfortunately, locking the cluster buffer and adding it to the
    transaction when the inode is first logged in a transaction leads to
    buffer lock ordering inversions.
    
    The specific problem is ordering against the AGI buffer. When
    modifying unlinked lists, the buffer lock order is AGI -> inode
    cluster buffer as the AGI buffer lock serialises all access to the
    unlinked lists. Unfortunately, functionality like xfs_droplink()
    logs the inode before calling xfs_iunlink(), as do various directory
    manipulation functions. The inode can be logged way down in the
    stack as far as the bmapi routines and hence, without a major
    rewrite of lots of APIs there's no way we can avoid the inode being
    logged by something until after the AGI has been logged.
    
    As we are going to be using ordered buffers for inode AIL tracking,
    there isn't a need to actually lock that buffer against modification
    as all the modifications are captured by logging the inode item
    itself. Hence we don't actually need to join the cluster buffer into
    the transaction until just before it is committed. This means we do
    not perturb any of the existing buffer lock orders in transactions,
    and the inode cluster buffer is always locked last in a transaction
    that doesn't otherwise touch inode cluster buffers.
    
    We do this by introducing a precommit log item method.  This commit
    just introduces the mechanism; the inode item implementation is in
    followup commits.
    
    The precommit items need to be sorted into consistent order as we
    may be locking multiple items here. Hence if we have two dirty
    inodes in cluster buffers A and B, and some other transaction has
    two separate dirty inodes in the same cluster buffers, locking them
    in different orders opens us up to ABBA deadlocks. Hence we sort the
    items on the transaction based on the presence of a sort log item
    method.
    Signed-off-by: default avatarDave Chinner <dchinner@redhat.com>
    Reviewed-by: default avatarDarrick J. Wong <djwong@kernel.org>
    Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
    fad743d7
xfs_icache.c 55.2 KB