1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-10 05:18:36 +03:00

Slightly refactor the config code to allow better reuse (no functional change).

This commit is contained in:
Petr Rockai 2011-07-18 13:26:08 +00:00
parent 4ac59193ee
commit 8e1761a804
4 changed files with 54 additions and 14 deletions

View File

@ -671,8 +671,7 @@ struct volume_group *lvmcache_get_vg(const char *vgid, unsigned precommitted)
/* Build config tree from vgmetadata, if not yet cached */
if (!vginfo->cft &&
!(vginfo->cft =
create_config_tree_from_string(fid->fmt->cmd,
vginfo->vgmetadata)))
create_config_tree_from_string(vginfo->vgmetadata)))
goto_bad;
if (!(vg = import_vg_from_config_tree(vginfo->cft, fid)))

View File

@ -2,7 +2,6 @@
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
* Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved.
*
*
* This file is part of LVM2.
*
* This copyrighted material is made available to anyone wishing to use,
@ -160,8 +159,7 @@ static int _parse_config_file(struct parser *p, struct config_tree *cft)
return 1;
}
struct config_tree *create_config_tree_from_string(struct cmd_context *cmd __attribute__((unused)),
const char *config_settings)
struct config_tree *create_config_tree_from_string(const char *config_settings)
{
struct cs *c;
struct config_tree *cft;
@ -192,7 +190,7 @@ struct config_tree *create_config_tree_from_string(struct cmd_context *cmd __att
int override_config_tree_from_string(struct cmd_context *cmd,
const char *config_settings)
{
if (!(cmd->cft_override = create_config_tree_from_string(cmd,config_settings))) {
if (!(cmd->cft_override = create_config_tree_from_string(config_settings))) {
log_error("Failed to set overridden configuration entries.");
return 1;
}
@ -1365,8 +1363,8 @@ static struct config_value *_clone_config_value(struct dm_pool *mem, const struc
return new_cv;
}
struct config_node *clone_config_node(struct dm_pool *mem, const struct config_node *cn,
int siblings)
struct config_node *clone_config_node_with_mem(struct dm_pool *mem, const struct config_node *cn,
int siblings)
{
struct config_node *new_cn;
@ -1384,9 +1382,45 @@ struct config_node *clone_config_node(struct dm_pool *mem, const struct config_n
}
if ((cn->v && !(new_cn->v = _clone_config_value(mem, cn->v))) ||
(cn->child && !(new_cn->child = clone_config_node(mem, cn->child, 1))) ||
(siblings && cn->sib && !(new_cn->sib = clone_config_node(mem, cn->sib, siblings))))
(cn->child && !(new_cn->child = clone_config_node_with_mem(mem, cn->child, 1))) ||
(siblings && cn->sib && !(new_cn->sib = clone_config_node_with_mem(mem, cn->sib, siblings))))
return_NULL; /* 'new_cn' released with mem pool */
return new_cn;
}
struct config_node *clone_config_node(struct config_tree *cft, const struct config_node *node, int sib)
{
struct cs *c = (struct cs *) cft;
return clone_config_node_with_mem(c->mem, node, sib);
}
struct config_node *create_config_node(struct config_tree *cft, const char *key)
{
struct cs *c = (struct cs *) cft;
struct config_node *cn;
if (!(cn = _create_node(c->mem))) {
log_error("Failed to create config node.");
return NULL;
}
if (!(cn->key = dm_pool_strdup(c->mem, key))) {
log_error("Failed to create config node's key.");
return NULL;
}
if (!(cn->v = _create_value(c->mem))) {
log_error("Failed to create config node's value.");
return NULL;
}
cn->parent = NULL;
cn->v->type = CFG_INT;
cn->v->v.i = 0;
cn->v->next = NULL;
return cn;
}
struct dm_pool *config_tree_memory(struct config_tree *cft)
{
struct cs *c = (struct cs *) cft;
return c->mem;
}

View File

@ -54,8 +54,8 @@ struct config_tree_list {
};
struct config_tree *create_config_tree(const char *filename, int keep_open);
struct config_tree *create_config_tree_from_string(struct cmd_context *cmd,
const char *config_settings);
struct config_tree *create_config_tree_from_string(const char *config_settings);
int override_config_tree_from_string(struct cmd_context *cmd,
const char *config_settings);
void destroy_config_tree(struct config_tree *cft);
@ -120,6 +120,13 @@ unsigned maybe_config_section(const char *str, unsigned len);
const char *config_parent_name(const struct config_node *n);
struct config_node *clone_config_node(struct dm_pool *mem, const struct config_node *cn,
struct config_node *clone_config_node_with_mem(struct dm_pool *mem,
const struct config_node *node,
int siblings);
struct config_node *create_config_node(struct config_tree *cft, const char *key);
struct config_node *clone_config_node(struct config_tree *cft, const struct config_node *cn,
int siblings);
struct dm_pool *config_tree_memory(struct config_tree *cft);
#endif

View File

@ -42,7 +42,7 @@ static int _unknown_text_import(struct lv_segment *seg, const struct config_node
if (!strcmp(current->key, "type") || !strcmp(current->key, "start_extent") ||
!strcmp(current->key, "tags") || !strcmp(current->key, "extent_count"))
continue;
new = clone_config_node(seg->lv->vg->vgmem, current, 0);
new = clone_config_node_with_mem(seg->lv->vg->vgmem, current, 0);
if (!new)
return_0;
if (last)