• Filipe Manana's avatar
    btrfs: preallocate inodes xarray entry to avoid transaction abort · 061ea858
    Filipe Manana authored
    When creating a new inode, at btrfs_create_new_inode(), one of the very
    last steps is to add the inode to the root's inodes xarray. This often
    requires allocating memory which may fail (even though xarrays have a
    dedicated kmem_cache which make it less likely to fail), and at that point
    we are forced to abort the current transaction (as some, but not all, of
    the inode metadata was added to its subvolume btree).
    
    To avoid a transaction abort, preallocate memory for the xarray early at
    btrfs_create_new_inode(), so that if we fail we don't need to abort the
    transaction and the insertion into the xarray is guaranteed to succeed.
    Reviewed-by: default avatarQu Wenruo <wqu@suse.com>
    Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
    Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    061ea858
inode.c 313 KB