[Devel] [PATCH hci-8.2 v2 6/8] dm-qcow2: stop slow_wb_timer and flush the workers before freeing an image
Denis V. Lunev
den at openvz.org
Mon Nov 23 18:36:38 MSK 2026
From: Denis V. Lunev <den at openvz.org>
qcow2_flush_deferred_activity() ends with an inflight reference switch
that waits for the metadata writeback it started. Those qios are ended
by the image's fsync_worker, and each completion queues that worker
before the qio is taken, so one run can end the last qio while another
run stays queued. qcow2_merge_backward_complete() then frees the merged
image with that work still pending, and it runs on freed memory.
Shut slow_wb_timer down and flush both workers of the merged image
before truncating and freeing it. The timer is not expected to be armed
after the final flush pass, which writes without retrying on ENOSPC,
but qcow2_destroy() only warns about a pending one. In
qcow2_tgt_destroy(), shut down the timer of every image before
destroy_workqueue() drains the remaining work, for the same reason.
https://virtuozzo.atlassian.net/browse/VSTOR-156036
Fixes: 222b6f1291c1 ("dm-qcow2: Introduce driver to create block devices over QCOW2 files")
Feature: dm-qcow2: block device over QCOW2 files driver
Signed-off-by: Denis V. Lunev <den at openvz.org>
---
drivers/md/dm-qcow2-cmd.c | 3 +++
drivers/md/dm-qcow2-target.c | 3 +++
2 files changed, 6 insertions(+)
diff --git a/drivers/md/dm-qcow2-cmd.c b/drivers/md/dm-qcow2-cmd.c
index fb3d1e014046..783159b0161c 100644
--- a/drivers/md/dm-qcow2-cmd.c
+++ b/drivers/md/dm-qcow2-cmd.c
@@ -392,6 +392,9 @@ static int qcow2_merge_backward_complete(struct qcow2_target *tgt)
smp_wmb(); /* Pairs with qcow2_ref_inc() */
qcow2_inflight_ref_switch(tgt); /* Pending qios */
qcow2_flush_deferred_activity(tgt, qcow2); /* Delayed md pages */
+ timer_shutdown_sync(&qcow2->slow_wb_timer);
+ flush_work(&qcow2->worker);
+ flush_work(&qcow2->fsync_worker);
qcow2->lower = NULL;
if (qcow2_file_is_writable(qcow2)) {
diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
index 2a51beaebcab..d5e94753ddbb 100644
--- a/drivers/md/dm-qcow2-target.c
+++ b/drivers/md/dm-qcow2-target.c
@@ -252,6 +252,8 @@ static void qcow2_tgt_destroy(struct qcow2_target *tgt)
* since DM waits them. Complete our deferred:
*/
qcow2_flush_deferred_activity_all(tgt);
+ for (qcow2 = tgt->top; qcow2; qcow2 = qcow2->lower)
+ timer_shutdown_sync(&qcow2->slow_wb_timer);
/* Now kill the queue */
destroy_workqueue(tgt->wq);
}
@@ -264,6 +266,7 @@ static void qcow2_tgt_destroy(struct qcow2_target *tgt)
for (i = 0; i < 2; i++)
percpu_ref_exit(&tgt->inflight_ref[i]);
+ qcow2 = tgt->top;
while (qcow2) {
lower = qcow2->lower;
qcow2_destroy(qcow2);
--
2.55.0
More information about the Devel
mailing list