[Devel] [PATCH RHEL8 COMMIT] dm-qcow2: Remap qio before submitting

Konstantin Khorenko khorenko at virtuozzo.com
Fri Aug 13 15:26:51 MSK 2021


The commit is pushed to "branch-rh8-4.18.0-305.3.1.vz8.7.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-305.3.1.vz8.7.6
------>
commit 2ab6147a9596e5c9599add3c1abe1431b500235c
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date:   Fri Aug 13 15:26:51 2021 +0300

    dm-qcow2: Remap qio before submitting
    
    Write related file sector to bi_sector before call_rw_iter().
    This allows to resubmit partially completed IO in next patches.
    
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
    
    ====================
    It's a preparation for https://jira.sw.ru/browse/PSBM-132049
---
 drivers/md/dm-qcow2-map.c | 16 ++++++++++++----
 drivers/md/dm-qcow2.h     |  5 +++++
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index d6ae382c1b9e..a7b801166546 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -2716,7 +2716,7 @@ static void data_rw_complete(struct qio *qio)
 		complete_wbd(qcow2, wbd);
 }
 
-static void submit_rw_mapped(struct qcow2 *qcow2, loff_t clu_pos, struct qio *qio)
+static void submit_rw_mapped(struct qcow2 *qcow2, struct qio *qio)
 {
 	unsigned int rw, nr_segs;
 	struct bio_vec *bvec;
@@ -2726,14 +2726,22 @@ static void submit_rw_mapped(struct qcow2 *qcow2, loff_t clu_pos, struct qio *qi
 	rw = (op_is_write(qio->bi_op) ? WRITE : READ);
 	nr_segs = qio_nr_segs(qio);
 	bvec = __bvec_iter_bvec(qio->bi_io_vec, qio->bi_iter);
+	pos = to_bytes(qio->bi_iter.bi_sector);
 
 	iov_iter_bvec(&iter, rw, bvec, nr_segs, qio->bi_iter.bi_size);
 	iter.iov_offset = qio->bi_iter.bi_bvec_done;
 
-	pos = clu_pos + bytes_off_in_cluster(qcow2, qio);
 	call_rw_iter(qcow2->file, pos, rw, &iter, qio);
 }
 
+static void map_and_submit_rw(struct qcow2 *qcow2, loff_t clu_pos, struct qio *qio)
+{
+	WARN_ON_ONCE(qio->qcow2 != qcow2);
+	remap_to_clu(qcow2, qio, clu_pos);
+
+	submit_rw_mapped(qcow2, qio);
+}
+
 static void perform_rw_mapped(struct qcow2_map *map, struct qio *qio)
 {
 	struct qcow2 *qcow2 = map->qcow2;
@@ -2765,7 +2773,7 @@ static void perform_rw_mapped(struct qcow2_map *map, struct qio *qio)
 		spin_unlock_irqrestore(&qcow2->md_pages_lock, flags);
 	}
 
-	submit_rw_mapped(qcow2, map->data_clu_pos, qio);
+	map_and_submit_rw(qcow2, map->data_clu_pos, qio);
 }
 
 static void cow_read_complete(struct qio *qio)
@@ -3685,7 +3693,7 @@ static void submit_sliced_cow_data_write(struct qcow2 *qcow2, struct qio *qio, l
 	while ((write_qio = qio_list_pop(&list)) != NULL) {
 		write_qio->complete = data_rw_complete;
 		write_qio->data = NULL;
-		submit_rw_mapped(qcow2, clu_pos, write_qio);
+		map_and_submit_rw(qcow2, clu_pos, write_qio);
 	}
 }
 
diff --git a/drivers/md/dm-qcow2.h b/drivers/md/dm-qcow2.h
index 817a39356018..58c6fe48fef0 100644
--- a/drivers/md/dm-qcow2.h
+++ b/drivers/md/dm-qcow2.h
@@ -357,4 +357,9 @@ static inline bool qcow2_wants_check(struct qcow2_target *tgt)
 	return !!(tgt->md_writeback_error|tgt->truncate_error);
 }
 
+static inline void remap_to_clu(struct qcow2 *qcow2, struct qio *qio, loff_t clu_pos)
+{
+	qio->bi_iter.bi_sector &= (to_sector(qcow2->clu_size) - 1);
+	qio->bi_iter.bi_sector |= (to_sector(clu_pos));
+}
 #endif


More information about the Devel mailing list