[Devel] [PATCH RHEL8 COMMIT] ploop: Call add_delta directly

Konstantin Khorenko khorenko at virtuozzo.com
Tue May 4 16:59:27 MSK 2021


The commit is pushed to "branch-rh8-4.18.0-240.1.1.vz8.5.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-240.1.1.vz8.5.25
------>
commit a237b3653e990589cba6648e69dfb1cc96286278
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date:   Tue May 4 16:59:27 2021 +0300

    ploop: Call add_delta directly
    
    There is no a possiblily to add delta to starting device.
    So, calling that functionality from work is overkill.
    
    To_merge: 3e892fb36c57 ("dm: Interpreter of ploop1 format (ploop driver)")
    
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
    
    =====================
    Patchset description:
    
    ploop: Preparation to kill-loop from dm-ploop (series 1)
    
    Currently, ploop requires underlining loop for top delta. This is overkill,
    since we may submit bios directly to fs, without using it.
    
    Initially there was a possibility, we may use device-mapper format snapshots
    instead of ploop-based. But we don't do that, so we have to use loop for top
    delta and directly submit bios to the rest of deltas. So, these two ways to do
    the same actions are wrong.
    
    This is preparations#1 for further series.
    Let's this goes to testing earlier.
    
    Kirill Tkhai (7):
          ploop: Kill "add_delta" interface
          ploop: Refactor ploop_add_delta()
          ploop: Move check in ploop_ctr()
          ploop: Call add_delta directly
          ploop: Move add_delta iterating code to separate function
          ploop: Allocate deltas in only place
          ploop: Add ignore_signature_disk_in_use parameter
    
    https://jira.sw.ru/browse/PSBM-123654
    
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 drivers/md/dm-ploop-cmd.c | 62 +++++++++++++++++------------------------------
 drivers/md/dm-ploop.h     |  7 ------
 2 files changed, 22 insertions(+), 47 deletions(-)

diff --git a/drivers/md/dm-ploop-cmd.c b/drivers/md/dm-ploop-cmd.c
index 01e6ba5153dc..1626cd1b881a 100644
--- a/drivers/md/dm-ploop-cmd.c
+++ b/drivers/md/dm-ploop-cmd.c
@@ -571,8 +571,8 @@ static int ploop_resize(struct ploop *ploop, u64 new_size)
 	return ret;
 }
 
-/* FIXME: this must not be called on running device */
-static void process_add_delta_cmd(struct ploop *ploop, struct ploop_cmd *cmd)
+static int apply_delta_mappings(struct ploop *ploop, struct ploop_delta *deltas,
+				void *hdr, u64 size_in_clus)
 {
 	map_index_t *bat_entries, *delta_bat_entries;
 	unsigned int i, end, level, dst_cluster;
@@ -580,16 +580,10 @@ static void process_add_delta_cmd(struct ploop *ploop, struct ploop_cmd *cmd)
 	struct md_page *md;
 	bool is_raw;
 
-	if (unlikely(ploop->force_link_inflight_bios)) {
-		cmd->retval = -EBUSY;
-		pr_err("ploop: adding delta on running device\n");
-		goto out;
-	}
-
 	level = ploop->nr_deltas;
 	/* Points to hdr since md_page[0] also contains hdr. */
-	delta_bat_entries = (map_index_t *)cmd->add_delta.hdr;
-	is_raw = cmd->add_delta.deltas[level].is_raw;
+	delta_bat_entries = (map_index_t *)hdr;
+	is_raw = deltas[level].is_raw;
 
 	write_lock_irq(&ploop->bat_rwlock);
 
@@ -604,7 +598,7 @@ static void process_add_delta_cmd(struct ploop *ploop, struct ploop_cmd *cmd)
 				dst_cluster = delta_bat_entries[i];
 			else {
 				dst_cluster = page_clu_idx_to_bat_clu(md->id, i);
-				if (dst_cluster >= cmd->add_delta.raw_clusters)
+				if (dst_cluster >= size_in_clus)
 					dst_cluster = BAT_ENTRY_NONE;
 			}
 			if (dst_cluster == BAT_ENTRY_NONE)
@@ -626,24 +620,24 @@ static void process_add_delta_cmd(struct ploop *ploop, struct ploop_cmd *cmd)
 		delta_bat_entries += PAGE_SIZE / sizeof(map_index_t);
 	}
 
-	swap(ploop->deltas, cmd->add_delta.deltas);
+	swap(ploop->deltas, deltas);
 	ploop->nr_deltas++;
 	write_unlock_irq(&ploop->bat_rwlock);
+
+	kfree(deltas);
 	get_file(ploop->deltas[level].file);
-	cmd->retval = 0;
-out:
-	complete(&cmd->comp); /* Last touch of cmd memory */
+	return 0;
 }
 
-static int ploop_check_raw_delta(struct ploop *ploop, struct file *file,
-				 struct ploop_cmd *cmd)
+static int ploop_check_delta_length(struct ploop *ploop, struct file *file,
+				    u64 *size_in_clus)
 {
 	loff_t loff = i_size_read(file->f_mapping->host);
 	unsigned int cluster_log = ploop->cluster_log;
 
 	if (loff & ((1 << (cluster_log + SECTOR_SHIFT)) - 1))
 		return -EPROTO;
-	cmd->add_delta.raw_clusters = loff >> (cluster_log + SECTOR_SHIFT);
+	*size_in_clus = loff >> (cluster_log + SECTOR_SHIFT);
 	return 0;
 }
 
@@ -654,10 +648,11 @@ static int ploop_check_raw_delta(struct ploop *ploop, struct file *file,
 int ploop_add_delta(struct ploop *ploop, int fd, bool is_raw)
 {
 	unsigned int level = ploop->nr_deltas;
-	struct ploop_cmd cmd = { {0} };
 	struct ploop_delta *deltas;
 	unsigned int size;
 	struct file *file;
+	u64 size_in_clus;
+	void *hdr = NULL;
 	int ret;
 
 	if (level == BAT_LEVEL_TOP)
@@ -677,30 +672,19 @@ int ploop_add_delta(struct ploop *ploop, int fd, bool is_raw)
 	memcpy(deltas, ploop->deltas, size);
 	deltas[level].file = file;
 	deltas[level].is_raw = is_raw;
-	/*
-	 * BAT update in general is driven by the kwork
-	 * (see comment in process_one_deferred_bio()),
-	 * so we delegate the cmd to it.
-	 */
-	cmd.add_delta.deltas = deltas;
-	cmd.type = PLOOP_CMD_ADD_DELTA;
-	cmd.ploop = ploop;
 
-	if (is_raw)
-		ret = ploop_check_raw_delta(ploop, file, &cmd);
-	else
-		ret = ploop_read_delta_metadata(ploop, file,
-						&cmd.add_delta.hdr);
+	ret = ploop_check_delta_length(ploop, file, &size_in_clus);
 	if (ret)
 		goto out;
 
-	init_completion(&cmd.comp);
-	ploop_queue_deferred_cmd(ploop, &cmd);
-	wait_for_completion(&cmd.comp);
-	ret = cmd.retval;
+	if (!is_raw)
+		ret = ploop_read_delta_metadata(ploop, file, &hdr);
+	if (ret)
+		goto out;
+
+	ret = apply_delta_mappings(ploop, deltas, hdr, size_in_clus);
 out:
-	vfree(cmd.add_delta.hdr);
-	kfree(cmd.add_delta.deltas);
+	vfree(hdr);
 	fput(file);
 	return ret;
 }
@@ -1774,8 +1758,6 @@ void process_deferred_cmd(struct ploop *ploop, struct ploop_index_wb *piwb)
 
 	if (cmd->type == PLOOP_CMD_RESIZE) {
 		process_resize_cmd(ploop, piwb, cmd);
-	} else if (cmd->type == PLOOP_CMD_ADD_DELTA) {
-		process_add_delta_cmd(ploop, cmd);
 	} else if (cmd->type == PLOOP_CMD_MERGE_SNAPSHOT) {
 		process_merge_latest_snapshot_cmd(ploop, cmd);
 	} else if (cmd->type == PLOOP_CMD_NOTIFY_DELTA_MERGED) {
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index 5f22e95575b5..1741a2075fb2 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -39,7 +39,6 @@ struct ploop_delta {
 
 struct ploop_cmd {
 #define PLOOP_CMD_RESIZE		1
-#define PLOOP_CMD_ADD_DELTA		2
 #define PLOOP_CMD_MERGE_SNAPSHOT	3
 #define PLOOP_CMD_NOTIFY_DELTA_MERGED	4
 #define PLOOP_CMD_SWITCH_TOP_DELTA	5
@@ -68,12 +67,6 @@ struct ploop_cmd {
 			struct bio *bio;
 		} resize;
 		struct {
-			struct file *file;
-			struct ploop_delta *deltas;
-			void *hdr; /* hdr and bat_entries consequentially */
-			unsigned int raw_clusters;
-		} add_delta;
-		struct {
 #define NR_MERGE_BIOS			64
 			atomic_t nr_available;
 			unsigned int cluster; /* Currently iterated cluster */


More information about the Devel mailing list