From 0395dd225095708b708c87952a571c964edda266 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Fri, 14 Oct 2011 13:34:19 +0000 Subject: [PATCH] Use pool for dm_tree allocation Using the same pool allocation strategy as we use for vg, so dm_tree structure is part of the pool itself. --- WHATS_NEW_DM | 1 + libdm/libdm-deptree.c | 18 +++++++----------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM index 36ea7aca0..9de4a3d4f 100644 --- a/WHATS_NEW_DM +++ b/WHATS_NEW_DM @@ -1,5 +1,6 @@ Version 1.02.68 - ================================== + Allocate dm_tree structure from dm_tree pool. Update debug logging for _resume_node. Add functions to support thin provisioning target (API unstable). Improve libdm-config error path reporting. diff --git a/libdm/libdm-deptree.c b/libdm/libdm-deptree.c index 62d267143..af72c4aa7 100644 --- a/libdm/libdm-deptree.c +++ b/libdm/libdm-deptree.c @@ -248,10 +248,14 @@ struct dm_tree { struct dm_tree *dm_tree_create(void) { + struct dm_pool *dmem; struct dm_tree *dtree; - if (!(dtree = dm_zalloc(sizeof(*dtree)))) { - log_error("dm_tree_create malloc failed"); + if (!(dmem = dm_pool_create("dtree", 1024)) || + !(dtree = dm_pool_zalloc(dmem, sizeof(*dtree)))) { + log_error("Failed to allocate dtree."); + if (dmem) + dm_pool_destroy(dmem); return NULL; } @@ -260,17 +264,11 @@ struct dm_tree *dm_tree_create(void) dm_list_init(&dtree->root.used_by); dtree->skip_lockfs = 0; dtree->no_flush = 0; - - if (!(dtree->mem = dm_pool_create("dtree", 1024))) { - log_error("dtree pool creation failed"); - dm_free(dtree); - return NULL; - } + dtree->mem = dmem; if (!(dtree->devs = dm_hash_create(8))) { log_error("dtree hash creation failed"); dm_pool_destroy(dtree->mem); - dm_free(dtree); return NULL; } @@ -278,7 +276,6 @@ struct dm_tree *dm_tree_create(void) log_error("dtree uuid hash creation failed"); dm_hash_destroy(dtree->devs); dm_pool_destroy(dtree->mem); - dm_free(dtree); return NULL; } @@ -293,7 +290,6 @@ void dm_tree_free(struct dm_tree *dtree) dm_hash_destroy(dtree->uuids); dm_hash_destroy(dtree->devs); dm_pool_destroy(dtree->mem); - dm_free(dtree); } static int _nodes_are_linked(const struct dm_tree_node *parent,