[Devel] [PATCH VZ9 v2 6/6] dm-ploop: handle REQ_PREFLUSH

Andrey Zhadchenko andrey.zhadchenko at virtuozzo.com
Wed Oct 9 15:17:26 MSK 2024


Create new flush pio when we see REQ_PREFLUSH flag. Call original
pio after the flush is done.

https://virtuozzo.atlassian.net/browse/VSTOR-91817
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
---
 drivers/md/dm-ploop-map.c | 39 ++++++++++++++++++++++++++++++++++-----
 1 file changed, 34 insertions(+), 5 deletions(-)

diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c
index 9ae6ffeed06a..134898bf7de5 100644
--- a/drivers/md/dm-ploop-map.c
+++ b/drivers/md/dm-ploop-map.c
@@ -1867,33 +1867,62 @@ void do_ploop_fsync_work(struct work_struct *ws)
 	}
 }
 
+static void ploop_preflush_endio(struct pio *pio, void *orig_pio_ptr,
+				 blk_status_t bi_status)
+{
+	struct pio *original = orig_pio_ptr;
+
+	if (bi_status) {
+		original->bi_status = bi_status;
+		ploop_pio_endio(original);
+	} else {
+		ploop_dispatch_pios(pio->ploop, original, NULL);
+	}
+}
+
 static void ploop_prepare_flush(struct ploop *ploop, struct pio *pio)
 {
+	struct pio *flush_pio = pio;
 	struct md_page *md, *n;
 	int md_inflight = 0;
 
+	if (pio->bi_op & REQ_PREFLUSH && (pio->bi_op & REQ_OP_MASK) != REQ_OP_FLUSH) {
+		flush_pio = ploop_alloc_pio(ploop, GFP_NOIO);
+		if (!flush_pio) {
+			pio->bi_status = BLK_STS_RESOURCE;
+			ploop_pio_endio(pio);
+			return;
+		}
+
+		ploop_init_pio(ploop, REQ_OP_FLUSH, flush_pio);
+		flush_pio->endio_cb = ploop_preflush_endio;
+		flush_pio->endio_cb_data = pio;
+		flush_pio->queue_list_id = PLOOP_LIST_FLUSH;
+		flush_pio->free_on_endio = true;
+	}
+
 	write_lock_irq(&ploop->bat_rwlock);
 
 	list_for_each_entry(md, &ploop->wb_batch_list_prio, wb_link) {
 		md_inflight++;
-		md->piwb->flush_pio = pio;
+		md->piwb->flush_pio = flush_pio;
 	}
 
 	list_for_each_entry_safe(md, n, &ploop->wb_batch_list, wb_link) {
 		md_inflight++;
-		md->piwb->flush_pio = pio;
+		md->piwb->flush_pio = flush_pio;
 		list_del(&md->wb_link);
 		list_add_tail(&md->wb_link, &ploop->wb_batch_list_prio);
 	}
 
-	atomic_set(&pio->md_inflight, md_inflight);
+	atomic_set(&flush_pio->md_inflight, md_inflight);
 
 	write_unlock_irq(&ploop->bat_rwlock);
 
 	if (md_inflight)
 		queue_work(ploop->wq, &ploop->worker);
 	else
-		ploop_dispatch_pios(ploop, pio, NULL);
+		ploop_dispatch_pios(ploop, flush_pio, NULL);
 }
 
 static void ploop_submit_embedded_pio(struct ploop *ploop, struct pio *pio)
@@ -1922,7 +1951,7 @@ static void ploop_submit_embedded_pio(struct ploop *ploop, struct pio *pio)
 
 	ploop_inc_nr_inflight(ploop, pio);
 
-	if ((pio->bi_op & REQ_OP_MASK) == REQ_OP_FLUSH) {
+	if ((pio->bi_op & REQ_OP_MASK) == REQ_OP_FLUSH || pio->bi_op & REQ_PREFLUSH) {
 		spin_unlock_irqrestore(&ploop->deferred_lock, flags);
 		ploop_prepare_flush(ploop, pio);
 		return;
-- 
2.39.3



More information about the Devel mailing list