[Devel] [PATCH hci-8.2 v2 8/8] dm-qcow2: flush the backward merge work before freeing the target

Denis V. Lunev den at openvz.org
Mon Nov 23 18:36:40 MSK 2026


From: Denis V. Lunev <den at openvz.org>

qcow2_merge_backward_work() runs on the system workqueue and ends by
setting the merge state under ctl_mutex and unlocking it. A
qcow2_merge_backward_cancel() that sees BACKWARD_MERGE_STOPPED, or
turns BACKWARD_MERGE_WAIT_COMPLETION into it, returns without
flush_work(), so it can take ctl_mutex while the work is still inside
mutex_unlock(). qcow2_tgt_destroy() then frees the target, and the
mutex in it, under that unlock.

Flush the merge work in qcow2_tgt_destroy() after the cancel,
whatever state the merge is in.

https://virtuozzo.atlassian.net/browse/VSTOR-156036

Fixes: 7d2cf9a7c178 ("dm-qcow2: make merge_backward command asyncronous")
Feature: dm-qcow2: block device over QCOW2 files driver
Signed-off-by: Denis V. Lunev <den at openvz.org>
---
 drivers/md/dm-qcow2-target.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
index 9c173e1dce87..5a18738d5b89 100644
--- a/drivers/md/dm-qcow2-target.c
+++ b/drivers/md/dm-qcow2-target.c
@@ -245,6 +245,7 @@ static void qcow2_tgt_destroy(struct qcow2_target *tgt)
 	unsigned int i;
 
 	qcow2_merge_backward_cancel(tgt);
+	flush_work(&tgt->backward_merge.work);
 	timer_shutdown_sync(&tgt->enospc_timer);
 
 	/*
-- 
2.55.0



More information about the Devel mailing list