[Devel] [PATCH hci-8.1 2/7] drivers/md/dm-qcow2: check MD_DIRTY and md->wbd under lock in perform_rw_mapped()

Andrey Zhadchenko andrey.zhadchenko at virtuozzo.com
Thu Oct 29 17:03:41 MSK 2026


Access to md fields was relying on dm-qcow2 sequential nature. Expand
md_pages_lock to also cover it so it can run in parallel.

https://virtuozzo.atlassian.net/browse/VSTOR-95494
Feature: dm-qcow2: block device over QCOW2 files driver
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
---
 drivers/md/dm-qcow2-map.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index fed6ce75e98ad..1023224484f5b 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -2908,14 +2908,18 @@ static void perform_rw_mapped(struct qcow2_map *map, struct qio *qio)
 	 * wait for md writeback completion.
 	 *
 	 * L1/L2 pages become set and unset dirty from main work only,
-	 * so lock is not needed for MD_DIRTY/changed_indexes visibility.
+	 * but this may be called from per-qio fast path in parallel
+	 * with main work submitting the writeback and with its completion
+	 * dropping md->wbd.
 	 */
 	index_in_page = map->l2.index_in_page + !!(qcow2->ext_l2);
-	if (rw == WRITE && (md->status & MD_DIRTY) &&
-	    test_bit(index_in_page, md->wbd->changed_indexes)) {
+	if (rw == WRITE) {
 		spin_lock_irqsave(&qcow2->md_pages_lock, flags);
-		md->wbd->nr_submitted++;
-		qio->data = md->wbd;
+		if ((md->status & MD_DIRTY) &&
+		    test_bit(index_in_page, md->wbd->changed_indexes)) {
+			md->wbd->nr_submitted++;
+			qio->data = md->wbd;
+		}
 		spin_unlock_irqrestore(&qcow2->md_pages_lock, flags);
 	}
 
-- 
2.43.5



More information about the Devel mailing list