[Devel] [PATCH RHEL8 COMMIT] ploop: Move prealloc_pages()

Konstantin Khorenko khorenko at virtuozzo.com
Thu May 6 00:32:31 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 f667724ce7136493e86699b613c9ac9368cf9874
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date:   Thu May 6 00:32:31 2021 +0300

    ploop: Move prealloc_pages()
    
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
    
    =====================
    Patchset description:
    
    ploop: Preparation to kill-loop from dm-ploop (series 3)
    
    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 #3 for further series.
    Let's this goes to testing earlier.
    
    Kirill Tkhai (3):
          ploop: Move fget() code to separate function
          ploop: Move prealloc_pages()
          ploop: Use prealloc_md_pages on ctr.
    
    https://jira.sw.ru/browse/PSBM-123654
    
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 drivers/md/dm-ploop-bat.c | 34 +++++++++++++++++++++++++++++++---
 drivers/md/dm-ploop-cmd.c | 26 --------------------------
 drivers/md/dm-ploop.h     |  8 +++++++-
 3 files changed, 38 insertions(+), 30 deletions(-)

diff --git a/drivers/md/dm-ploop-bat.c b/drivers/md/dm-ploop-bat.c
index ba912001dca9..6ef8ec177670 100644
--- a/drivers/md/dm-ploop-bat.c
+++ b/drivers/md/dm-ploop-bat.c
@@ -24,9 +24,8 @@ struct md_page * md_page_find(struct ploop *ploop, unsigned int id)
 	return NULL;
 }
 
-void md_page_insert(struct ploop *ploop, struct md_page *new_md)
+static void __md_page_insert(struct rb_root *root, struct md_page *new_md)
 {
-	struct rb_root *root = &ploop->bat_entries;
 	unsigned int new_id = new_md->id;
 	struct rb_node *parent, **node;
 	struct md_page *md;
@@ -49,7 +48,12 @@ void md_page_insert(struct ploop *ploop, struct md_page *new_md)
 	rb_insert_color(&new_md->node, root);
 }
 
-struct md_page * alloc_md_page(unsigned int id)
+void md_page_insert(struct ploop *ploop, struct md_page *new_md)
+{
+	__md_page_insert(&ploop->bat_entries, new_md);
+}
+
+static struct md_page * alloc_md_page(unsigned int id)
 {
 	struct md_page *md;
 	struct page *page;
@@ -86,6 +90,30 @@ void free_md_page(struct md_page *md)
 	kfree(md);
 }
 
+int prealloc_md_pages(struct rb_root *root, unsigned int nr_bat_entries,
+		      unsigned int new_nr_bat_entries)
+{
+	unsigned int i, nr_pages, new_nr_pages;
+	struct md_page *md;
+	void *addr;
+
+	new_nr_pages = bat_clu_to_page_nr(new_nr_bat_entries - 1) + 1;
+	nr_pages = bat_clu_to_page_nr(nr_bat_entries - 1) + 1;
+
+	for (i = nr_pages; i < new_nr_pages; i++) {
+		md = alloc_md_page(i);
+		if (!md)
+			return -ENOMEM;
+		addr = kmap_atomic(md->page);
+		memset(addr, 0, PAGE_SIZE);
+		kunmap_atomic(addr);
+
+		__md_page_insert(root, md);
+	}
+
+	return 0;
+}
+
 bool try_update_bat_entry(struct ploop *ploop, unsigned int cluster,
 			  u8 level, unsigned int dst_cluster)
 {
diff --git a/drivers/md/dm-ploop-cmd.c b/drivers/md/dm-ploop-cmd.c
index 8485236e3460..0b8ef1382717 100644
--- a/drivers/md/dm-ploop-cmd.c
+++ b/drivers/md/dm-ploop-cmd.c
@@ -456,32 +456,6 @@ void free_bio_with_pages(struct ploop *ploop, struct bio *bio)
 	bio_put(bio);
 }
 
-static int prealloc_md_pages(struct rb_root *root, unsigned int nr_bat_entries,
-			     unsigned int new_nr_bat_entries)
-{
-	unsigned int i, nr_pages, new_nr_pages;
-	struct md_page *md;
-	void *addr;
-
-	new_nr_pages = bat_clu_to_page_nr(new_nr_bat_entries - 1) + 1;
-	nr_pages = bat_clu_to_page_nr(nr_bat_entries - 1) + 1;
-
-	for (i = nr_pages; i < new_nr_pages; i++) {
-		md = alloc_md_page(i); /* Any id is OK */
-		if (!md)
-			return -ENOMEM;
-		addr = kmap_atomic(md->page);
-		memset(addr, 0, PAGE_SIZE);
-		kunmap_atomic(addr);
-
-		/* No order */
-		rb_link_node(&md->node, NULL, &root->rb_node);
-		rb_insert_color(&md->node, root);
-	}
-
-	return 0;
-}
-
 /* @new_size is in sectors */
 static int ploop_resize(struct ploop *ploop, u64 new_size)
 {
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index d0c613b743b8..040e798fdbe7 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -481,7 +481,13 @@ static inline struct dm_ploop_endio_hook *find_endio_hook(struct ploop *ploop,
 	return find_endio_hook_range(ploop, root, cluster, cluster);
 }
 
-extern struct md_page * alloc_md_page(unsigned int id);
+static inline struct pio *bio_to_endio_hook(struct bio *bio)
+{
+	return dm_per_bio_data(bio, sizeof(struct pio));
+}
+
+extern int prealloc_md_pages(struct rb_root *root, unsigned int nr_bat_entries,
+			     unsigned int new_nr_bat_entries);
 extern void md_page_insert(struct ploop *ploop, struct md_page *md);
 extern void free_md_page(struct md_page *md);
 extern void free_md_pages_tree(struct rb_root *root);


More information about the Devel mailing list