• Filipe Manana's avatar
    btrfs: avoid tree mod log ENOMEM failures when we don't need to log · 8793ed87
    Filipe Manana authored
    When logging tree mod log operations we start by checking, in a lockless
    manner, if we need to log - if we don't, we just return and do nothing,
    otherwise we will allocate one or more tree mod log operations and then
    check again if we need to log. This second check will take the tree mod
    log lock in write mode if we need to log, otherwise it will do nothing
    and we just free the allocated memory and return success.
    
    We can improve on this by not returning an error in case the memory
    allocations fail, unless the second check tells us that we actually need
    to log. That is, if we fail to allocate memory and the second check tells
    use that we don't need to log, we can just return success and avoid
    returning -ENOMEM to the caller. Currently tree mod log failures are
    dealt with either a BUG_ON() or a transaction abort, as tree mod log
    operations are logged in code paths that modify a b+tree.
    
    So just avoid failing with -ENOMEM if we fail to allocate a tree mod log
    operation unless we actually need to log the operations, that is, if
    tree_mod_dont_log() returns true.
    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>
    8793ed87
tree-mod-log.c 28.1 KB