• Josef Bacik's avatar
    btrfs: fix error handling in commit_fs_roots · 4f4317c1
    Josef Bacik authored
    While doing error injection I would sometimes get a corrupt file system.
    This is because I was injecting errors at btrfs_search_slot, but would
    only do it one time per stack.  This uncovered a problem in
    commit_fs_roots, where if we get an error we would just break.  However
    we're in a nested loop, the first loop being a loop to find all the
    dirty fs roots, and then subsequent root updates would succeed clearing
    the error value.
    
    This isn't likely to happen in real scenarios, however we could
    potentially get a random ENOMEM once and then not again, and we'd end up
    with a corrupted file system.  Fix this by moving the error checking
    around a bit to the main loop, as this is the only place where something
    will fail, and return the error as soon as it occurs.
    
    With this patch my reproducer no longer corrupts the file system.
    Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
    Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    4f4317c1
transaction.c 69 KB