[Devel] [PATCH VZ9 v3 12/13] dm-ploop: submit all postponed metadata on REQ_OP_FLUSH

Andrey Zhadchenko andrey.zhadchenko at virtuozzo.com
Thu Oct 24 20:23:40 MSK 2024


On every flush request we should submit all accumulated metadata
changes, wait for their completion and only then do the flush.

https://virtuozzo.atlassian.net/browse/VSTOR-91817
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
---
 drivers/md/dm-ploop-map.c | 43 +++++++++++++++++++++++++++++++++++++++
 drivers/md/dm-ploop.h     |  3 +++
 2 files changed, 46 insertions(+)

diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c
index ca7439405168..22c97420262c 100644
--- a/drivers/md/dm-ploop-map.c
+++ b/drivers/md/dm-ploop-map.c
@@ -68,6 +68,7 @@ void ploop_index_wb_init(struct ploop_index_wb *piwb, struct ploop *ploop)
 	piwb->completed = false;
 	piwb->page_id = PAGE_NR_NONE;
 	piwb->type = PIWB_TYPE_ALLOC;
+	piwb->flush_pio = NULL;
 }
 
 void ploop_init_pio(struct ploop *ploop, unsigned int bi_op, struct pio *pio)
@@ -857,6 +858,7 @@ static void ploop_bat_write_complete(struct pio *pio, void *piwb_ptr,
 				     blk_status_t bi_status)
 {
 	struct ploop_index_wb *piwb = piwb_ptr;
+	struct pio *flush_pio = piwb->flush_pio;
 	struct ploop *ploop = piwb->ploop;
 	struct pio *aux_pio;
 	struct ploop_cow *cow;
@@ -895,6 +897,12 @@ static void ploop_bat_write_complete(struct pio *pio, void *piwb_ptr,
 		ploop_complete_cow(cow, bi_status);
 	}
 
+	if (flush_pio) {
+		if (atomic_dec_and_test(&flush_pio->md_inflight))
+			ploop_dispatch_pios(ploop, flush_pio, NULL);
+		piwb->flush_pio = NULL;
+	}
+
 	/*
 	 * In case of update BAT is failed, dst_clusters will be
 	 * set back to holes_bitmap on last put_piwb().
@@ -1917,6 +1925,35 @@ void do_ploop_work(struct work_struct *ws)
 	current->flags = old_flags;
 }
 
+static void ploop_prepare_flush(struct ploop *ploop, struct pio *pio)
+{
+	struct md_page *md, *n;
+	int md_inflight = 0;
+
+	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;
+	}
+
+	list_for_each_entry_safe(md, n, &ploop->wb_batch_list, wb_link) {
+		md_inflight++;
+		md->piwb->flush_pio = pio;
+		list_del(&md->wb_link);
+		list_add_tail(&md->wb_link, &ploop->wb_batch_list_prio);
+	}
+
+	atomic_set(&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);
+}
+
 static void ploop_submit_embedded_pio(struct ploop *ploop, struct pio *pio)
 {
 	struct ploop_rq *prq = pio->endio_cb_data;
@@ -1937,6 +1974,12 @@ 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) {
+		ploop_prepare_flush(ploop, pio);
+		return;
+	}
+
 	llist_add((struct llist_node *)(&pio->list), &ploop->pios[PLOOP_LIST_PREPARE]);
 
 out:
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index 8b12084e3223..82d058c925ef 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -109,6 +109,7 @@ struct ploop_index_wb {
 	blk_status_t bi_status;
 	u32 page_id;
 	struct bio_vec aux_bvec;
+	struct pio *flush_pio;
 };
 
 /* Metadata page */
@@ -294,6 +295,8 @@ struct pio {
 	int ret; /* iocb result */
 	void (*complete)(struct pio *me);
 	void *data;
+
+	atomic_t md_inflight;
 };
 
 /* Delta COW private */
-- 
2.39.3



More information about the Devel mailing list