[Devel] [PATCH hci-8.1 v3 4/5] dm-qcow2: fix SEEK_HOLE/SEEK_DATA hanging after a failed metadata read

Denis V. Lunev den at openvz.org
Wed Nov 4 21:01:04 MSK 2026


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

qcow2_llseek_hole_qio() parks its seek qio on an md page that is not
loaded yet and sleeps until the qio is dispatched to QLIST_SEEK, where
process_seek_qios() completes it. When the page read fails,
do_md_page_read_complete() ends the waiting qios instead. A seek qio
has no endio_cb, so nothing wakes the walk, and the lseek() caller
sleeps uninterruptibly forever while it holds seek_rwsem: the next
merge_backward complete and every target message after it hang under
ctl_mutex as well.

Complete the seek from an endio_cb and return the error the qio was
ended with.

Fixes: 412d5a4f7bf1 ("dm/dm-qcow2: add llseek_hole")
Reported-by: Konstantin Khorenko <khorenko at virtuozzo.com>
https://virtuozzo.atlassian.net/browse/VSTOR-153422
Feature: dm-qcow2: block device over QCOW2 files driver
Signed-off-by: Denis V. Lunev <den at openvz.org>
---
 drivers/md/dm-qcow2-map.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index fa535d7716da..eee865989ef7 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -4600,6 +4600,13 @@ static void seek_qio_set_sector(struct qio *qio, sector_t bi_sector)
 	qio->bi_iter.bi_size = end > pos ? end - pos : 0;
 }
 
+/* A failed md page read ends the qios waiting for it */
+static void seek_qio_endio(struct qcow2_target *tgt, struct qio *qio,
+			   void *data, blk_status_t bi_status)
+{
+	complete(&((struct qio_data_llseek_hole *)data)->compl);
+}
+
 static struct qio *alloc_seek_qio(struct qcow2 *qcow2, struct qio *parent, loff_t new_lim)
 {
 	struct qio_data_llseek_hole *data;
@@ -4619,6 +4626,8 @@ static struct qio *alloc_seek_qio(struct qcow2 *qcow2, struct qio *parent, loff_
 	}
 
 	qio->data = data;
+	qio->endio_cb = seek_qio_endio;
+	qio->endio_cb_data = data;
 	init_completion(&data->compl);
 	data->lim = new_lim;
 
@@ -4752,6 +4761,10 @@ static int qcow2_llseek_hole_qio(struct qio *qio, int whence, loff_t *result)
 			/* one of metadata pages is not loaded and qio is postponed*/
 			wait_for_completion(&SEEK_QIO_DATA(qio)->compl);
 			reinit_completion(&SEEK_QIO_DATA(qio)->compl);
+			if (qio->bi_status != BLK_STS_OK) {
+				ret = blk_status_to_errno(qio->bi_status);
+				break;
+			}
 			continue;
 		}
 
-- 
2.53.0



More information about the Devel mailing list