[Devel] [PATCH RH8 2/3] ploop: Do not use work on resize

Kirill Tkhai ktkhai at virtuozzo.com
Wed Jun 23 18:12:39 MSK 2021


Resize is made when there is no inflight reqs,
work is not needed.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 drivers/md/dm-ploop-cmd.c |   38 +++++++++-----------------------------
 drivers/md/dm-ploop-map.c |    2 --
 drivers/md/dm-ploop.h     |    1 -
 3 files changed, 9 insertions(+), 32 deletions(-)

diff --git a/drivers/md/dm-ploop-cmd.c b/drivers/md/dm-ploop-cmd.c
index 7a971be34e65..b36bb158a3ac 100644
--- a/drivers/md/dm-ploop-cmd.c
+++ b/drivers/md/dm-ploop-cmd.c
@@ -394,11 +394,8 @@ static void ploop_add_md_pages(struct ploop *ploop, struct rb_root *from)
  * of disk after resize. For user they look as already written to disk,
  * so be careful(!) and protective. Update indexes only after cluster
  * data is written to disk.
- *
- * This is called from deferred work -- the only place we alloc clusters.
- * So, nobody can reallocate clusters updated in ploop_grow_relocate_cluster().
  */
-static void process_resize_cmd(struct ploop *ploop, struct ploop_cmd *cmd)
+static int process_resize_cmd(struct ploop *ploop, struct ploop_cmd *cmd)
 {
 	struct ploop_index_wb piwb;
 	unsigned int dst_cluster;
@@ -406,25 +403,17 @@ static void process_resize_cmd(struct ploop *ploop, struct ploop_cmd *cmd)
 
 	ploop_index_wb_init(&piwb, ploop);
 
-	/*
-	 *  Update memory arrays and hb_nr, but do not update nr_bat_entries.
-	 *  This is noop except first enter to this function.
-	 */
+	/* Update memory arrays and hb_nr, but do not update nr_bat_entries. */
 	ploop_advance_holes_bitmap(ploop, cmd);
 
-	if (cmd->resize.dst_cluster <= cmd->resize.end_dst_cluster) {
+	while (cmd->resize.dst_cluster <= cmd->resize.end_dst_cluster) {
 		ret = ploop_grow_relocate_cluster(ploop, &piwb, cmd);
 		if (ret)
 			goto out;
-
-		/* Move one cluster per cmd to allow other requests. */
-		ploop_queue_deferred_cmd(ploop, cmd);
-		return;
-	} else {
-		/* Update header metadata */
-		ret = ploop_grow_update_header(ploop, &piwb, cmd);
 	}
 
+	/* Update header metadata */
+	ret = ploop_grow_update_header(ploop, &piwb, cmd);
 out:
 	write_lock_irq(&ploop->bat_rwlock);
 	if (ret) {
@@ -442,8 +431,7 @@ static void process_resize_cmd(struct ploop *ploop, struct ploop_cmd *cmd)
 	}
 	write_unlock_irq(&ploop->bat_rwlock);
 
-	cmd->retval = ret;
-	complete(&cmd->comp); /* Last touch of cmd memory */
+	return ret;
 }
 
 struct pio *alloc_pio_with_pages(struct ploop *ploop)
@@ -497,6 +485,7 @@ void free_pio_with_pages(struct ploop *ploop, struct pio *pio)
 }
 
 /* @new_size is in sectors */
+/* TODO: we may delegate this to userspace */
 static int ploop_resize(struct ploop *ploop, sector_t new_sectors)
 {
 	unsigned int nr_bat_entries, nr_old_bat_clusters, nr_bat_clusters;
@@ -569,18 +558,11 @@ static int ploop_resize(struct ploop *ploop, sector_t new_sectors)
 	cmd.resize.new_sectors = new_sectors;
 	cmd.resize.md0 = md0;
 	cmd.retval = 0;
-	cmd.type = PLOOP_CMD_RESIZE;
 	cmd.ploop = ploop;
 
 	ploop_suspend_submitting_pios(ploop);
-	/* FIXME: Avoid using work */
-	init_completion(&cmd.comp);
-	ploop_queue_deferred_cmd(ploop, &cmd);
-	wait_for_completion(&cmd.comp);
-
+	ret = process_resize_cmd(ploop, &cmd);
 	ploop_resume_submitting_pios(ploop);
-
-	ret = cmd.retval;
 err:
 	if (cmd.resize.pio)
 		free_pio_with_pages(ploop, cmd.resize.pio);
@@ -1185,9 +1167,7 @@ void process_deferred_cmd(struct ploop *ploop)
 	ploop->deferred_cmd = NULL;
 	spin_unlock_irq(&ploop->deferred_lock);
 
-	if (cmd->type == PLOOP_CMD_RESIZE) {
-		process_resize_cmd(ploop, cmd);
-	} else if (cmd->type == PLOOP_CMD_MERGE_SNAPSHOT) {
+	if (cmd->type == PLOOP_CMD_MERGE_SNAPSHOT) {
 		process_merge_latest_snapshot_cmd(ploop, cmd);
 	} else {
 		cmd->retval = -EINVAL;
diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c
index 05b93f98adb8..bcdc63a1d5c9 100644
--- a/drivers/md/dm-ploop-map.c
+++ b/drivers/md/dm-ploop-map.c
@@ -819,8 +819,6 @@ static int find_dst_cluster_bit(struct ploop *ploop,
 {
 	unsigned int dst_cluster;
 
-	WARN_ON_ONCE(!(current->flags & PF_WQ_WORKER));
-
 	/* Find empty cluster */
 	dst_cluster = find_first_bit(ploop->holes_bitmap, ploop->hb_nr);
 	if (dst_cluster >= ploop->hb_nr)
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index f518278c8be3..2a474e5d3cb6 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -41,7 +41,6 @@ struct ploop_delta {
 };
 
 struct ploop_cmd {
-#define PLOOP_CMD_RESIZE		1
 #define PLOOP_CMD_MERGE_SNAPSHOT	3
 	struct completion comp;
 	struct ploop *ploop;




More information about the Devel mailing list