[Devel] [PATCH vz9 v1 24/63] dm-ploop: submit all postponed metadata on REQ_OP_FLUSH
Alexander Atanasov
alexander.atanasov at virtuozzo.com
Fri Jan 24 18:35:58 MSK 2025
From: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
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 | 42 +++++++++++++++++++++++++++++++++++++++
drivers/md/dm-ploop.h | 3 +++
2 files changed, 45 insertions(+)
diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c
index 92844d032810..fdbf20145223 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)
@@ -873,6 +874,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;
@@ -911,6 +913,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().
@@ -1972,6 +1980,35 @@ int ploop_worker(void *data)
return 0;
}
+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)
+ ploop_schedule_work(ploop);
+ 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;
@@ -1994,6 +2031,11 @@ 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;
+ }
+
if (pio->queue_list_id == PLOOP_LIST_FLUSH) {
/* Let the FLUSH go last from the queue , do not run here to preserve ordering */
llist_add((struct llist_node *)(&pio->list), &ploop->pios[PLOOP_LIST_PREPARE]);
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index 8bfc5e87a24e..c08acb1a3cc9 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 */
@@ -300,6 +301,8 @@ struct pio {
int ret; /* iocb result */
void (*complete)(struct pio *me);
void *data;
+
+ atomic_t md_inflight;
};
/* Delta COW private */
--
2.43.0
More information about the Devel
mailing list