• J
    btrfs: fix possible free space tree corruption with online conversion · 348ec0f4
    Josef Bacik 提交于
    stable inclusion
    from stable-5.10.13
    commit 2175bf57dc9522c58d93dcd474758434a3f05c57
    bugzilla: 47995
    
    --------------------------------
    
    commit 2f96e402 upstream.
    
    While running btrfs/011 in a loop I would often ASSERT() while trying to
    add a new free space entry that already existed, or get an EEXIST while
    adding a new block to the extent tree, which is another indication of
    double allocation.
    
    This occurs because when we do the free space tree population, we create
    the new root and then populate the tree and commit the transaction.
    The problem is when you create a new root, the root node and commit root
    node are the same.  During this initial transaction commit we will run
    all of the delayed refs that were paused during the free space tree
    generation, and thus begin to cache block groups.  While caching block
    groups the caching thread will be reading from the main root for the
    free space tree, so as we make allocations we'll be changing the free
    space tree, which can cause us to add the same range twice which results
    in either the ASSERT(ret != -EEXIST); in __btrfs_add_free_space, or in a
    variety of different errors when running delayed refs because of a
    double allocation.
    
    Fix this by marking the fs_info as unsafe to load the free space tree,
    and fall back on the old slow method.  We could be smarter than this,
    for example caching the block group while we're populating the free
    space tree, but since this is a serious problem I've opted for the
    simplest solution.
    
    CC: stable@vger.kernel.org # 4.9+
    Fixes: a5ed9182 ("Btrfs: implement the free space B-tree")
    Reviewed-by: NFilipe Manana <fdmanana@suse.com>
    Signed-off-by: NJosef Bacik <josef@toxicpanda.com>
    Signed-off-by: NDavid Sterba <dsterba@suse.com>
    Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
    Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
    348ec0f4
block-group.c 96.6 KB