• Miao Xie's avatar
    Btrfs: fix the race between bio and btrfs_stop_workers · 2b8195bb
    Miao Xie authored
    open_ctree() need read the metadata to initialize the global information
    of btrfs. But it may fail after it submit some bio, and then it will jump
    to the error path. Unfortunately, it doesn't check if there are some bios
    in flight, and just stop all the worker threads. As a result, when the
    submitted bios end, they can not find any worker thread which can deal with
    subsequent work, then oops happen.
    
    kernel BUG at fs/btrfs/async-thread.c:605!
    
    Fix this problem by invoking invalidate_inode_pages2() before we stop the
    worker threads. This function will wait until the bio end because it need
    lock the pages which are going to be invalidated, and if a page is under
    disk read IO, it must be locked. invalidate_inode_pages2() need wait until
    end bio handler to unlocked it.
    Reported-and-Tested-by: default avatarTsutomu Itoh <t-itoh@jp.fujitsu.com>
    Signed-off-by: default avatarEric Sandeen <sandeen@redhat.com>
    Signed-off-by: default avatarMiao Xie <miaox@cn.fujitsu.com>
    Signed-off-by: default avatarJosef Bacik <jbacik@fusionio.com>
    2b8195bb
disk-io.c 106 KB