[Devel] [PATCH vz9] dm-qcow2: use bio inline vecs in case bi_io_vec is not initiallized

Alexander Atanasov alexander.atanasov at virtuozzo.com
Thu Jul 11 11:16:53 MSK 2024


In some cases bi_io_vec ptr is not initiallized, which can happen after
bio reset and qcow2 can try to use the ptr before it is reinitiallized
with bi_inline_vecs. in that case fallback to use bi_inline_vecs ptr.
bi_inline_vecs are used when there are less than 4 io vecs.

Add some warnings to trace the problem further if it happens again.

https://virtuozzo.atlassian.net/browse/PSBM-157238
Signed-off-by: Alexander Atanasov <alexander.atanasov at virtuozzo.com>
---
 drivers/md/dm-qcow2-map.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index 8f871c0522aac..53bed6c0a30ae 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -1245,6 +1245,7 @@ static void __submit_rw_mapped(struct qcow2 *qcow2, struct qio *qio, u32 nr_segs
 
 	rw = (op_is_write(qio->bi_op) ? WRITE : READ);
 	bvec = __bvec_iter_bvec(qio->bi_io_vec, qio->bi_iter);
+	WARN_ON_ONCE(!bvec);
 	pos = to_bytes(qio->bi_iter.bi_sector);
 
 	iov_iter_bvec(&iter, rw, bvec, nr_segs, qio->bi_iter.bi_size);
@@ -3509,7 +3510,15 @@ static void prepare_one_embedded_qio(struct qcow2 *qcow2, struct qio *qio,
 	} else {
 		/* Single bio already provides bvec array */
 		bvec = rq->bio->bi_io_vec;
-
+		WARN_ON_ONCE(!bvec);
+		if (!bvec) {
+			bvec = rq->bio->bi_inline_vecs;
+			if (unlikely(!bvec)) {
+				printk(KERN_ERR "Expecting inline bvec\n");
+				WARN_ON_ONCE(1);
+				goto err;
+			}
+		}
 		qio->bi_iter = rq->bio->bi_iter;
 	}
 
@@ -3706,6 +3715,7 @@ static int prepare_sliced_data_write(struct qcow2 *qcow2, struct qio *qio,
 	}
 
 	write_qio->bi_io_vec = qvec->bvec;
+	WARN_ON_ONCE(!write_qio->bi_io_vec);
 	write_qio->bi_iter.bi_idx = 0;
 	write_qio->bi_iter.bi_bvec_done = 0;
 
@@ -4162,6 +4172,7 @@ void qcow2_submit_embedded_qio(struct qcow2_target *tgt, struct qio *qio)
 	qcow2 = qcow2_ref_inc(tgt, &ref_index);
 
 	if (blk_rq_bytes(rq)) {
+		WARN_ON_ONCE(rq->bio && !rq->bio->bi_io_vec);
 		queue_list_id = QLIST_EMBEDDED;
 		worker = &qcow2->worker;
 	} else {
-- 
2.43.0



More information about the Devel mailing list