[Devel] [PATCH RH8 04/61] ploop: Add flush_worker
Kirill Tkhai
ktkhai at virtuozzo.com
Fri May 14 18:54:56 MSK 2021
This is preparation for flushing in separate thread.
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
drivers/md/dm-ploop-map.c | 28 ++++++++++++++++++++++++++--
drivers/md/dm-ploop-target.c | 2 ++
drivers/md/dm-ploop.h | 3 +++
3 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c
index dd209f2a0a8c..6f1b602117c8 100644
--- a/drivers/md/dm-ploop-map.c
+++ b/drivers/md/dm-ploop-map.c
@@ -1590,6 +1590,23 @@ void do_ploop_work(struct work_struct *ws)
check_services_timeout(ploop);
}
+void do_ploop_fsync_work(struct work_struct *ws)
+{
+ struct ploop *ploop = container_of(ws, struct ploop, fsync_worker);
+ struct bio_list flush_bios = BIO_EMPTY_LIST;
+ struct bio *bio;
+
+ spin_lock_irq(&ploop->deferred_lock);
+ bio_list_merge(&flush_bios, &ploop->flush_bios);
+ bio_list_init(&ploop->flush_bios);
+ spin_unlock_irq(&ploop->deferred_lock);
+
+ /* FIXME: issue flush */
+
+ while ((bio = bio_list_pop(&flush_bios)) != NULL)
+ bio_endio(bio);
+}
+
/*
* ploop_map() tries to map bio to origins or delays it.
* It never modifies ploop->bat_entries and other cached
@@ -1599,6 +1616,7 @@ int ploop_map(struct dm_target *ti, struct bio *bio)
{
struct ploop *ploop = ti->private;
unsigned int cluster;
+ unsigned long flags;
ploop_init_end_io(ploop, bio);
@@ -1612,9 +1630,15 @@ int ploop_map(struct dm_target *ti, struct bio *bio)
return DM_MAPIO_SUBMITTED;
}
- remap_to_origin(ploop, bio);
+ if (WARN_ON_ONCE(!op_is_flush(bio->bi_opf)))
+ return DM_MAPIO_KILL;
- return DM_MAPIO_REMAPPED;
+ spin_lock_irqsave(&ploop->deferred_lock, flags);
+ bio_list_add(&ploop->flush_bios, bio);
+ spin_unlock_irqrestore(&ploop->deferred_lock, flags);
+ queue_work(ploop->wq, &ploop->fsync_worker);
+
+ return DM_MAPIO_SUBMITTED;
}
int ploop_endio(struct dm_target *ti, struct bio *bio, blk_status_t *err)
diff --git a/drivers/md/dm-ploop-target.c b/drivers/md/dm-ploop-target.c
index 8a2a5312195e..f8d471581ac0 100644
--- a/drivers/md/dm-ploop-target.c
+++ b/drivers/md/dm-ploop-target.c
@@ -206,6 +206,7 @@ static int ploop_ctr(struct dm_target *ti, unsigned int argc, char **argv)
spin_lock_init(&ploop->pb_lock);
bio_list_init(&ploop->deferred_bios);
+ bio_list_init(&ploop->flush_bios);
bio_list_init(&ploop->discard_bios);
INIT_LIST_HEAD(&ploop->cluster_lk_list);
bio_list_init(&ploop->delta_cow_action_list);
@@ -215,6 +216,7 @@ static int ploop_ctr(struct dm_target *ti, unsigned int argc, char **argv)
ploop->inflight_bios_rbtree = RB_ROOT;
INIT_WORK(&ploop->worker, do_ploop_work);
+ INIT_WORK(&ploop->fsync_worker, do_ploop_fsync_work);
init_completion(&ploop->inflight_bios_ref_comp);
for (i = 0; i < 2; i++) {
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index 0eb313d4c412..1dfe3dc7df60 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -194,6 +194,7 @@ struct ploop {
struct workqueue_struct *wq;
struct work_struct worker;
+ struct work_struct fsync_worker;
struct completion inflight_bios_ref_comp;
struct percpu_ref inflight_bios_ref[2];
@@ -202,6 +203,7 @@ struct ploop {
spinlock_t deferred_lock;
struct bio_list deferred_bios;
+ struct bio_list flush_bios;
struct bio_list discard_bios;
struct rw_semaphore ctl_rwsem;
@@ -474,6 +476,7 @@ extern bool try_update_bat_entry(struct ploop *ploop, unsigned int cluster,
extern int ploop_add_delta(struct ploop *ploop, u32 level, struct file *file, bool is_raw);
extern void defer_bios(struct ploop *ploop, struct bio *bio, struct bio_list *bio_list);
extern void do_ploop_work(struct work_struct *ws);
+extern void do_ploop_fsync_work(struct work_struct *ws);
extern void process_deferred_cmd(struct ploop *ploop,
struct ploop_index_wb *piwb);
extern int ploop_map(struct dm_target *ti, struct bio *bio);
More information about the Devel
mailing list