• Mikulas Patocka's avatar
    dm: report suspended device during destroy · adc0daad
    Mikulas Patocka authored
    The function dm_suspended returns true if the target is suspended.
    However, when the target is being suspended during unload, it returns
    false.
    
    An example where this is a problem: the test "!dm_suspended(wc->ti)" in
    writecache_writeback is not sufficient, because dm_suspended returns
    zero while writecache_suspend is in progress.  As is, without an
    enhanced dm_suspended, simply switching from flush_workqueue to
    drain_workqueue still emits warnings:
    workqueue writecache-writeback: drain_workqueue() isn't complete after 10 tries
    workqueue writecache-writeback: drain_workqueue() isn't complete after 100 tries
    workqueue writecache-writeback: drain_workqueue() isn't complete after 200 tries
    workqueue writecache-writeback: drain_workqueue() isn't complete after 300 tries
    workqueue writecache-writeback: drain_workqueue() isn't complete after 400 tries
    
    writecache_suspend calls flush_workqueue(wc->writeback_wq) - this function
    flushes the current work. However, the workqueue may re-queue itself and
    flush_workqueue doesn't wait for re-queued works to finish. Because of
    this - the function writecache_writeback continues execution after the
    device was suspended and then concurrently with writecache_dtr, causing
    a crash in writecache_writeback.
    
    We must use drain_workqueue - that waits until the work and all re-queued
    works finish.
    
    As a prereq for switching to drain_workqueue, this commit fixes
    dm_suspended to return true after the presuspend hook and before the
    postsuspend hook - just like during a normal suspend. It allows
    simplifying the dm-integrity and dm-writecache targets so that they
    don't have to maintain suspended flags on their own.
    
    With this change use of drain_workqueue() can be used effectively.  This
    change was tested with the lvm2 testsuite and cryptsetup testsuite and
    the are no regressions.
    
    Fixes: 48debafe ("dm: add writecache target")
    Cc: stable@vger.kernel.org # 4.18+
    Reported-by: default avatarCorey Marthaler <cmarthal@redhat.com>
    Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
    Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
    adc0daad
dm.c 73.7 KB