[Devel] [PATCH RHEL8 COMMIT] ploop: Allocate deltas in only place

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

    ploop: Allocate deltas in only place
    
    To_merge: 9de0f6efb0e5 ("ploop: Add ploop_delta type")
    
    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    | 13 +------------
 drivers/md/dm-ploop-target.c | 15 ++++++++++++++-
 2 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/drivers/md/dm-ploop-cmd.c b/drivers/md/dm-ploop-cmd.c
index 1626cd1b881a..ff696065fdb7 100644
--- a/drivers/md/dm-ploop-cmd.c
+++ b/drivers/md/dm-ploop-cmd.c
@@ -620,11 +620,9 @@ static int apply_delta_mappings(struct ploop *ploop, struct ploop_delta *deltas,
 		delta_bat_entries += PAGE_SIZE / sizeof(map_index_t);
 	}
 
-	swap(ploop->deltas, deltas);
 	ploop->nr_deltas++;
 	write_unlock_irq(&ploop->bat_rwlock);
 
-	kfree(deltas);
 	get_file(ploop->deltas[level].file);
 	return 0;
 }
@@ -647,16 +645,13 @@ static int ploop_check_delta_length(struct ploop *ploop, struct file *file,
  */
 int ploop_add_delta(struct ploop *ploop, int fd, bool is_raw)
 {
+	struct ploop_delta *deltas = ploop->deltas;
 	unsigned int level = ploop->nr_deltas;
-	struct ploop_delta *deltas;
-	unsigned int size;
 	struct file *file;
 	u64 size_in_clus;
 	void *hdr = NULL;
 	int ret;
 
-	if (level == BAT_LEVEL_TOP)
-		return -EMFILE;
 	file = fget(fd);
 	if (!file)
 		return -ENOENT;
@@ -664,12 +659,6 @@ int ploop_add_delta(struct ploop *ploop, int fd, bool is_raw)
 	if (!(file->f_mode & FMODE_READ))
 		goto out;
 
-	ret = -ENOMEM;
-	deltas = kcalloc(level + 1, sizeof(*deltas), GFP_KERNEL);
-	if (!deltas)
-		goto out;
-	size = level * sizeof(*deltas);
-	memcpy(deltas, ploop->deltas, size);
 	deltas[level].file = file;
 	deltas[level].is_raw = is_raw;
 
diff --git a/drivers/md/dm-ploop-target.c b/drivers/md/dm-ploop-target.c
index b4a21840fba7..5581e2722e0b 100644
--- a/drivers/md/dm-ploop-target.c
+++ b/drivers/md/dm-ploop-target.c
@@ -111,10 +111,23 @@ static int ploop_check_origin_dev(struct dm_target *ti, struct ploop *ploop)
 
 static int ploop_add_deltas_stack(struct ploop *ploop, char **argv, int argc)
 {
-	int i, delta_fd, ret;
+	struct ploop_delta *deltas;
+	int i, delta_fd, ret = 0;
 	const char *arg;
 	bool is_raw;
 
+	if (!argc)
+		goto out;
+	ret = -EINVAL;
+	if (argc > BAT_LEVEL_TOP - 1)
+		goto out;
+
+	ret = -ENOMEM;
+	deltas = kcalloc(argc, sizeof(*deltas), GFP_KERNEL);
+	if (!deltas)
+		goto out;
+	ploop->deltas = deltas;
+
 	ret = -EINVAL;
 	for (i = 0; i < argc; i++) {
 		arg = argv[i];


More information about the Devel mailing list