[Devel] [PATCH VZ9 v2 5/6] dm-ploop: submit all postponed metadata on REQ_OP_FLUSH

Andrey Zhadchenko andrey.zhadchenko at virtuozzo.com
Wed Oct 9 15:17:25 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 | 44 +++++++++++++++++++++++++++++++++++++++
 drivers/md/dm-ploop.h     |  2 ++
 2 files changed, 46 insertions(+)

diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c
index 5b0a5932b7a3..9ae6ffeed06a 100644
--- a/drivers/md/dm-ploop-map.c
+++ b/drivers/md/dm-ploop-map.c
@@ -67,6 +67,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)
@@ -869,6 +870,7 @@ static void ploop_bat_write_complete(struct pio *pio, void *piwb_ptr,
 	struct pio *aux_pio;
 	struct ploop_cow *cow;
 	struct pio *data_pio;
+	struct pio *flush_pio = piwb->flush_pio;
 	unsigned long flags;
 
 	if (!bi_status) {
@@ -903,6 +905,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().
@@ -1859,6 +1867,35 @@ void do_ploop_fsync_work(struct work_struct *ws)
 	}
 }
 
+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;
@@ -1884,6 +1921,13 @@ 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) {
+		spin_unlock_irqrestore(&ploop->deferred_lock, flags);
+		ploop_prepare_flush(ploop, pio);
+		return;
+	}
+
 	list_add_tail(&pio->list, &ploop->pios[pio->queue_list_id]);
 unlock:
 	spin_unlock_irqrestore(&ploop->deferred_lock, flags);
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index 675ddcc057a0..e0f926f5b04a 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -108,6 +108,7 @@ struct ploop_index_wb {
 	blk_status_t bi_status;
 	u32 page_id;
 	struct bio_vec aux_bvec;
+	struct pio *flush_pio;
 };
 
 /* Metadata page */
@@ -291,6 +292,7 @@ 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