[Devel] [PATCH RH8 2/3] ploop: Move prealloc_pages()
Kirill Tkhai
ktkhai at virtuozzo.com
Wed May 5 14:52:00 MSK 2021
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