diff options
author | Peter Rajnoha <prajnoha@redhat.com> | 2016-09-15 14:37:58 +0200 |
---|---|---|
committer | Peter Rajnoha <prajnoha@redhat.com> | 2016-09-16 09:35:14 +0200 |
commit | e997f4818e8cdef0fdfe79fcd1f547c0f84b1097 (patch) | |
tree | 2683647c2d353b58e76574628f74176ffadca907 | |
parent | 9c8c8fb63abd1a36b9c448450c9cccfac4c0299e (diff) | |
download | lvm2-e997f4818e8cdef0fdfe79fcd1f547c0f84b1097.tar.gz |
libdm: config: add internal wrapper for dm_config_tree
Internal wrapper provides a way to store further internal information
and data related configuration tree. This part is then accessible only
in libdm, it's not exposed outside library directly which makes it more
robust for any future extensions.
-rw-r--r-- | libdm/libdm-config.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/libdm/libdm-config.c b/libdm/libdm-config.c index dcb7c3f81..f91288100 100644 --- a/libdm/libdm-config.c +++ b/libdm/libdm-config.c @@ -59,6 +59,13 @@ struct config_output { void *baton; }; +struct config_wrapper { + struct dm_config_tree cft; +}; + +#define get_config_wrapper(cfg_ptr) \ + ((struct config_wrapper *)((const char *)(cfg_ptr) - (const char *)&((struct config_wrapper *) 0)->cft)) + static void _get_token(struct parser *p, int tok_prev); static void _eat_space(struct parser *p); static struct dm_config_node *_file(struct parser *p); @@ -95,7 +102,7 @@ static int _tok_match(const char *str, const char *b, const char *e) struct dm_config_tree *dm_config_create(void) { - struct dm_config_tree *cft; + struct config_wrapper *cf_wrapper; struct dm_pool *mem = dm_pool_create("config", 10 * 1024); if (!mem) { @@ -103,14 +110,15 @@ struct dm_config_tree *dm_config_create(void) return 0; } - if (!(cft = dm_pool_zalloc(mem, sizeof(*cft)))) { - log_error("Failed to allocate config tree."); + if (!(cf_wrapper = dm_pool_zalloc(mem, sizeof(*cf_wrapper)))) { + log_error("Failed to allocate config wrapper."); dm_pool_destroy(mem); return 0; } - cft->mem = mem; - return cft; + cf_wrapper->cft.mem = mem; + + return &cf_wrapper->cft; } void dm_config_set_custom(struct dm_config_tree *cft, void *custom) |