[Devel] [PATCH RHEL8 COMMIT] ploop: Refactor ploop_add_delta()

Konstantin Khorenko khorenko at virtuozzo.com
Tue May 4 16:59:26 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 24d849592468814e626cba6842fe2cf5e2350cd4
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date:   Tue May 4 16:59:26 2021 +0300

    ploop: Refactor ploop_add_delta()
    
    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    | 17 +++--------------
 drivers/md/dm-ploop-target.c | 21 +++++++++++++++++----
 drivers/md/dm-ploop.h        |  2 +-
 3 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/drivers/md/dm-ploop-cmd.c b/drivers/md/dm-ploop-cmd.c
index 85ba713749cf..01e6ba5153dc 100644
--- a/drivers/md/dm-ploop-cmd.c
+++ b/drivers/md/dm-ploop-cmd.c
@@ -651,28 +651,17 @@ static int ploop_check_raw_delta(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, const char *arg)
+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;
-	bool is_raw = false;
 	unsigned int size;
 	struct file *file;
-	int fd, ret;
+	int ret;
 
-	if (ploop->maintaince)
-		return -EBUSY;
-	if (strncmp(arg, "raw@", 4) == 0) {
-		is_raw = true;
-		arg += 4;
-	}
-	/* Only ploop->deltas[0] may be raw */
-	if (level == BAT_LEVEL_TOP || (is_raw && level))
+	if (level == BAT_LEVEL_TOP)
 		return -EMFILE;
-	if (kstrtos32(arg, 10, &fd) < 0)
-		return -EINVAL;
-
 	file = fget(fd);
 	if (!file)
 		return -ENOENT;
diff --git a/drivers/md/dm-ploop-target.c b/drivers/md/dm-ploop-target.c
index 7b5f81955abe..9b94f5f21c6c 100644
--- a/drivers/md/dm-ploop-target.c
+++ b/drivers/md/dm-ploop-target.c
@@ -115,8 +115,10 @@ static int ploop_check_origin_dev(struct dm_target *ti, struct ploop *ploop)
 static int ploop_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 {
 	percpu_ref_func_t *release;
+	int i, delta_fd, ret;
 	struct ploop *ploop;
-	int i, ret;
+	bool is_raw;
+	char *arg;
 
 	if (argc < 2)
 		return -EINVAL;
@@ -138,6 +140,8 @@ static int ploop_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 	bio_list_init(&ploop->delta_cow_action_list);
 	atomic_set(&ploop->nr_discard_bios, 0);
 	ploop->bat_entries = RB_ROOT;
+	ploop->exclusive_bios_rbtree = RB_ROOT;
+	ploop->inflight_bios_rbtree = RB_ROOT;
 
 	INIT_WORK(&ploop->worker, do_ploop_work);
 	init_completion(&ploop->inflight_bios_ref_comp);
@@ -192,11 +196,20 @@ static int ploop_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 		goto err;
 	}
 
-	ploop->exclusive_bios_rbtree = RB_ROOT;
-	ploop->inflight_bios_rbtree = RB_ROOT;
 	ret = -EINVAL;
 	for (i = 2; i < argc; i++) {
-		ret = ploop_add_delta(ploop, argv[i]);
+		arg = argv[i];
+		is_raw = false;
+		if (strncmp(arg, "raw@", 4) == 0) {
+			if (i != 2)
+				goto err;
+			arg += 4;
+			is_raw = true;
+		}
+		if (kstrtos32(arg, 10, &delta_fd) < 0)
+			goto err;
+
+		ret = ploop_add_delta(ploop, delta_fd, is_raw);
 		if (ret < 0)
 			goto err;
 	}
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index a025df4bf328..5f22e95575b5 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -493,7 +493,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, const char *arg);
+extern int ploop_add_delta(struct ploop *ploop, 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