From: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
To: khorenko@virtuozzo.com, alexander.ivanov@virtuozzo.com
Cc: devel@openvz.org
Subject: [Devel] [PATCH hci-8.1 v2 2/7] dm-qcow2: wait for L2 writeback in perform_rw_mapped()
Date: Tue, 10 Nov 2026 14:46:24 +0300 [thread overview]
Message-ID: <20261110114629.416695-3-andrey.zhadchenko@virtuozzo.com> (raw)
In-Reply-To: <20261110114629.416695-1-andrey.zhadchenko@virtuozzo.com>
perform_rw_mapped() reads md->status and md->wbd without
md_pages_lock, relying on dm-qcow2 sequential nature: L1/L2 pages
become dirty, go to writeback and drop md->wbd from main kwork only.
Expand md_pages_lock to also cover the check, so it can be called
from the per-qio fast path in parallel with main kwork.
The lock alone is not enough. parse_l2() does not delay a write to
a changed index of a DIRTY L2 page, as perform_rw_mapped() is going
to attach the write to md->wbd. Main kwork does parse, submit and the
DIRTY -> WRITEBACK switch in one do_qcow2_work() pass, so the page
is still DIRTY there. The fast path parses and submits under separate
lock holds, and main kwork may switch the page to WRITEBACK in
between:
main kwork fast worker
allocates cluster X,
L2 page DIRTY
parse_l2(): write to X, page DIRTY,
not delayed, unlock
submit_metadata_writeback():
DIRTY -> WRITEBACK
perform_rw_mapped(): no MD_DIRTY,
qio->data = NULL, submit
The write is then acked as soon as its data is written, before the
L2 entry mapping it is on disk. A FLUSH after it finds
QLIST_COMPLETED_WB empty and only calls vfs_fsync(), so it does not
wait for the L2 write in flight, and a crash loses a write that was
acked and flushed. If the L2 write fails instead, the entry is
reverted and X freed while the write already returned success.
So, when the page is under writeback and the index is changed, park
the qio on md->wait_list, as parse_l2() does. It is redispatched to
main kwork when the writeback ends and parsed again. Do not attach it
to the wbd under writeback: after a failed writeback complete_wbd()
reverts the indexes and frees the wbd.
This changes nothing for main kwork, where parse_l2() has already
delayed such writes in the same pass.
https://virtuozzo.atlassian.net/browse/VSTOR-95494
Feature: dm-qcow2: block device over QCOW2 files driver
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
---
v2: renamed from "check MD_DIRTY and md->wbd under lock in
perform_rw_mapped()"; park a write on md->wait_list if its L2 page
went to writeback after parse_l2(), instead of acking it before its
L2 entry is on disk; commit message describes the race
drivers/md/dm-qcow2-map.c | 24 +++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index 21d1c8975af99..49dc3e8119e76 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -2912,14 +2912,28 @@ 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.
+ *
+ * So md may have gone DIRTY -> WRITEBACK after parse_l2() decided
+ * the qio need not wait. Then the qio must wait for writeback end
+ * the way parse_l2() makes it. It can't be attached to wbd: after
+ * a failed writeback, complete_wbd() reverts the indexes and frees
+ * the wbd without looking at qios attached in the meantime.
*/
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 (__delay_if_writeback(qcow2, md, index_in_page, &qio, false)) {
+ spin_unlock_irqrestore(&qcow2->md_pages_lock, flags);
+ return;
+ }
+ 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
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
next prev parent reply other threads:[~2026-11-10 11:52 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 11:46 [Devel] [PATCH hci-8.1 v2 0/7] dm-qcow2: per-qio fast path Andrey Zhadchenko
2026-11-10 11:46 ` [Devel] [PATCH hci-8.1 v2 1/7] dm-qcow2: repeat md page lookup if it was inserted in parallel Andrey Zhadchenko
2026-11-10 11:55 ` no-reply
2026-11-10 17:56 ` Konstantin Khorenko
2026-11-10 11:46 ` Andrey Zhadchenko [this message]
2026-11-10 11:56 ` [Devel] [PATCH hci-8.1 v2 2/7] dm-qcow2: wait for L2 writeback in perform_rw_mapped() no-reply
2026-11-10 17:56 ` Konstantin Khorenko
2026-11-10 11:46 ` [Devel] [PATCH hci-8.1 v2 3/7] dm-qcow2: prepare process_one_qio() for fastpath Andrey Zhadchenko
2026-11-10 11:59 ` no-reply
2026-11-10 13:50 ` Andrey Zhadchenko
2026-11-10 17:56 ` Konstantin Khorenko
2026-11-11 14:36 ` Alexander Ivanov
2026-11-10 11:46 ` [Devel] [PATCH hci-8.1 v2 4/7] dm-qcow2: add per-qio work infrastructure Andrey Zhadchenko
2026-11-10 12:02 ` no-reply
2026-11-11 15:34 ` Andrey Zhadchenko
2026-11-10 17:56 ` Konstantin Khorenko
2026-11-10 11:46 ` [Devel] [PATCH hci-8.1 v2 5/7] dm-qcow2: implement per-qio fast processing Andrey Zhadchenko
2026-11-10 12:08 ` no-reply
2026-11-10 17:56 ` Konstantin Khorenko
2026-11-10 11:46 ` [Devel] [PATCH hci-8.1 v2 6/7] dm-qcow2: process fast path qios in per-cpu batches on a workqueue Andrey Zhadchenko
2026-11-10 12:06 ` no-reply
2026-11-10 17:56 ` Konstantin Khorenko
2026-11-11 15:00 ` Alexander Ivanov
2026-11-10 11:46 ` [Devel] [PATCH hci-8.1 v2 7/7] dm-qcow2: declare DM_TARGET_NOWAIT Andrey Zhadchenko
2026-11-10 12:06 ` no-reply
2026-11-10 17:56 ` [Devel] [PATCH hci-8.1 v2 0/7] dm-qcow2: per-qio fast path Konstantin Khorenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261110114629.416695-3-andrey.zhadchenko@virtuozzo.com \
--to=andrey.zhadchenko@virtuozzo.com \
--cc=alexander.ivanov@virtuozzo.com \
--cc=devel@openvz.org \
--cc=khorenko@virtuozzo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox