[Devel] [PATCH RH8 2/7] ploop: Refactor ploop_add_delta()

Kirill Tkhai ktkhai at virtuozzo.com
Tue May 4 16:05:07 MSK 2021


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