• Stefan Behrens's avatar
    Btrfs: remove superblock writing after fatal error · 68ce9682
    Stefan Behrens authored
    With commit acce952b, btrfs was changed to flag the filesystem with
    BTRFS_SUPER_FLAG_ERROR and switch to read-only mode after a fatal
    error happened like a write I/O errors of all mirrors.
    In such situations, on unmount, the superblock is written in
    btrfs_error_commit_super(). This is done with the intention to be able
    to evaluate the error flag on the next mount. A warning is printed
    in this case during the next mount and the log tree is ignored.
    
    The issue is that it is possible that the superblock points to a root
    that was not written (due to write I/O errors).
    The result is that the filesystem cannot be mounted. btrfsck also does
    not start and all the other btrfs-progs tools fail to start as well.
    However, mount -o recovery is working well and does the right things
    to recover the filesystem (i.e., don't use the log root, clear the
    free space cache and use the next mountable root that is stored in the
    root backup array).
    
    This patch removes the writing of the superblock when
    BTRFS_SUPER_FLAG_ERROR is set, and removes the handling of the error
    flag in the mount function.
    
    These lines can be used to reproduce the issue (using /dev/sdm):
    SCRATCH_DEV=/dev/sdm
    SCRATCH_MNT=/mnt
    echo 0 25165824 linear $SCRATCH_DEV 0 | dmsetup create foo
    ls -alLF /dev/mapper/foo
    mkfs.btrfs /dev/mapper/foo
    mount /dev/mapper/foo $SCRATCH_MNT
    echo bar > $SCRATCH_MNT/foo
    sync
    echo 0 25165824 error | dmsetup reload foo
    dmsetup resume foo
    ls -alF $SCRATCH_MNT
    touch $SCRATCH_MNT/1
    ls -alF $SCRATCH_MNT
    sleep 35
    echo 0 25165824 linear $SCRATCH_DEV 0 | dmsetup reload foo
    dmsetup resume foo
    sleep 1
    umount $SCRATCH_MNT
    btrfsck /dev/mapper/foo
    dmsetup remove foo
    Signed-off-by: default avatarStefan Behrens <sbehrens@giantdisaster.de>
    Signed-off-by: default avatarJan Schmidt <list.btrfs@jan-o-sch.net>
    68ce9682
disk-io.c 103 KB