• M
    dm writecache: fix incorrect flush sequence when doing SSD mode commit · d1ed69bf
    Mikulas Patocka 提交于
    stable inclusion
    from linux-4.19.103
    commit a999296636fbbec86aa2af5025b89493532e907d
    
    --------------------------------
    
    commit aa950920 upstream.
    
    When committing state, the function writecache_flush does the following:
    1. write metadata (writecache_commit_flushed)
    2. flush disk cache (writecache_commit_flushed)
    3. wait for data writes to complete (writecache_wait_for_ios)
    4. increase superblock seq_count
    5. write the superblock
    6. flush disk cache
    
    It may happen that at step 3, when we wait for some write to finish, the
    disk may report the write as finished, but the write only hit the disk
    cache and it is not yet stored in persistent storage. At step 5 we write
    the superblock - it may happen that the superblock is written before the
    write that we waited for in step 3. If the machine crashes, it may result
    in incorrect data being returned after reboot.
    
    In order to fix the bug, we must swap steps 2 and 3 in the above sequence,
    so that we first wait for writes to complete and then flush the disk
    cache.
    
    Fixes: 48debafe ("dm: add writecache target")
    Cc: stable@vger.kernel.org # 4.18+
    Signed-off-by: NMikulas Patocka <mpatocka@redhat.com>
    Signed-off-by: NMike Snitzer <snitzer@redhat.com>
    Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
    d1ed69bf
dm-writecache.c 56.8 KB