[Devel] [PATCH RHEL8 COMMIT] ploop: Pass level directly in ploop_add_delta()

Konstantin Khorenko khorenko at virtuozzo.com
Thu May 6 00:30:45 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.26
------>
commit 05b87afc9969767f2b8d50ace44a5fd1852d35a2
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date:   Thu May 6 00:30:45 2021 +0300

    ploop: Pass level directly in ploop_add_delta()
    
    Do not manipulate nr_deltas in ploop_add_delta().
    
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
    
    =====================
    Patchset description:
    
    ploop: Preparation to kill-loop from dm-ploop (series 2)
    
    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 #2 for further series.
    Let's this goes to testing earlier.
    
    Kirill Tkhai (4):
          ploop: Move ploop_add_delta() to another file
          ploop: Pass level directly in ploop_add_delta()
          ploop: Add deltas in normal order
          ploop: Check next delta in stack not bigger then previous
    
    https://jira.sw.ru/browse/PSBM-123654
    
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 drivers/md/dm-ploop-bat.c    | 12 ++++--------
 drivers/md/dm-ploop-target.c |  5 ++++-
 drivers/md/dm-ploop.h        |  2 +-
 3 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/md/dm-ploop-bat.c b/drivers/md/dm-ploop-bat.c
index fd2b841e540c..135427c759dd 100644
--- a/drivers/md/dm-ploop-bat.c
+++ b/drivers/md/dm-ploop-bat.c
@@ -410,15 +410,14 @@ int ploop_read_delta_metadata(struct ploop *ploop, struct file *file,
 }
 
 static int apply_delta_mappings(struct ploop *ploop, struct ploop_delta *deltas,
-				void *hdr, u64 size_in_clus)
+				u32 level, void *hdr, u64 size_in_clus)
 {
 	map_index_t *bat_entries, *delta_bat_entries;
-	unsigned int i, end, level, dst_cluster;
+	unsigned int i, end, dst_cluster;
 	struct rb_node *node;
 	struct md_page *md;
 	bool is_raw;
 
-	level = ploop->nr_deltas;
 	/* Points to hdr since md_page[0] also contains hdr. */
 	delta_bat_entries = (map_index_t *)hdr;
 	is_raw = deltas[level].is_raw;
@@ -457,8 +456,6 @@ static int apply_delta_mappings(struct ploop *ploop, struct ploop_delta *deltas,
 		kunmap_atomic(bat_entries);
 		delta_bat_entries += PAGE_SIZE / sizeof(map_index_t);
 	}
-
-	ploop->nr_deltas++;
 	write_unlock_irq(&ploop->bat_rwlock);
 
 	get_file(ploop->deltas[level].file);
@@ -481,10 +478,9 @@ static int ploop_check_delta_length(struct ploop *ploop, struct file *file,
  * @fd refers to a new delta, which is placed right before top_delta.
  * So, userspace has to populate deltas stack from oldest to newest.
  */
-int ploop_add_delta(struct ploop *ploop, int fd, bool is_raw)
+int ploop_add_delta(struct ploop *ploop, u32 level, int fd, bool is_raw)
 {
 	struct ploop_delta *deltas = ploop->deltas;
-	unsigned int level = ploop->nr_deltas;
 	struct file *file;
 	u64 size_in_clus;
 	void *hdr = NULL;
@@ -509,7 +505,7 @@ int ploop_add_delta(struct ploop *ploop, int fd, bool is_raw)
 	if (ret)
 		goto out;
 
-	ret = apply_delta_mappings(ploop, deltas, hdr, size_in_clus);
+	ret = apply_delta_mappings(ploop, deltas, level, hdr, size_in_clus);
 out:
 	vfree(hdr);
 	fput(file);
diff --git a/drivers/md/dm-ploop-target.c b/drivers/md/dm-ploop-target.c
index 37e581f2997f..4e5f5adba40e 100644
--- a/drivers/md/dm-ploop-target.c
+++ b/drivers/md/dm-ploop-target.c
@@ -120,6 +120,7 @@ static int ploop_add_deltas_stack(struct ploop *ploop, char **argv, int argc)
 	int i, delta_fd, ret = 0;
 	const char *arg;
 	bool is_raw;
+	u32 level;
 
 	if (!argc)
 		goto out;
@@ -146,9 +147,11 @@ static int ploop_add_deltas_stack(struct ploop *ploop, char **argv, int argc)
 		if (kstrtos32(arg, 10, &delta_fd) < 0)
 			goto out;
 
-		ret = ploop_add_delta(ploop, delta_fd, is_raw);
+		level = ploop->nr_deltas;
+		ret = ploop_add_delta(ploop, level, delta_fd, is_raw);
 		if (ret < 0)
 			goto out;
+		ploop->nr_deltas++;
 	}
 
 	ret = 0;
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index 54baa1aa0229..1eeac9ca064d 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -487,7 +487,7 @@ extern void free_md_pages_tree(struct rb_root *root);
 extern bool try_update_bat_entry(struct ploop *ploop, unsigned int cluster,
 				 u8 level, unsigned int dst_cluster);
 
-extern int ploop_add_delta(struct ploop *ploop, int fd, bool is_raw);
+extern int ploop_add_delta(struct ploop *ploop, u32 level, int fd, 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 process_deferred_cmd(struct ploop *ploop,


More information about the Devel mailing list