mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-17 06:04:23 +03:00
Slightly refactor the config code to allow better reuse (no functional change).
This commit is contained in:
parent
9c1f6bc985
commit
2710477deb
3
lib/cache/lvmcache.c
vendored
3
lib/cache/lvmcache.c
vendored
@ -671,8 +671,7 @@ struct volume_group *lvmcache_get_vg(const char *vgid, unsigned precommitted)
|
|||||||
/* Build config tree from vgmetadata, if not yet cached */
|
/* Build config tree from vgmetadata, if not yet cached */
|
||||||
if (!vginfo->cft &&
|
if (!vginfo->cft &&
|
||||||
!(vginfo->cft =
|
!(vginfo->cft =
|
||||||
create_config_tree_from_string(fid->fmt->cmd,
|
create_config_tree_from_string(vginfo->vgmetadata)))
|
||||||
vginfo->vgmetadata)))
|
|
||||||
goto_bad;
|
goto_bad;
|
||||||
|
|
||||||
if (!(vg = import_vg_from_config_tree(vginfo->cft, fid)))
|
if (!(vg = import_vg_from_config_tree(vginfo->cft, fid)))
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
|
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
|
||||||
* Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved.
|
* Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* This file is part of LVM2.
|
* This file is part of LVM2.
|
||||||
*
|
*
|
||||||
* This copyrighted material is made available to anyone wishing to use,
|
* 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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct config_tree *create_config_tree_from_string(struct cmd_context *cmd __attribute__((unused)),
|
struct config_tree *create_config_tree_from_string(const char *config_settings)
|
||||||
const char *config_settings)
|
|
||||||
{
|
{
|
||||||
struct cs *c;
|
struct cs *c;
|
||||||
struct config_tree *cft;
|
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,
|
int override_config_tree_from_string(struct cmd_context *cmd,
|
||||||
const char *config_settings)
|
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.");
|
log_error("Failed to set overridden configuration entries.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -1365,8 +1363,8 @@ static struct config_value *_clone_config_value(struct dm_pool *mem, const struc
|
|||||||
return new_cv;
|
return new_cv;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 *cn,
|
||||||
int siblings)
|
int siblings)
|
||||||
{
|
{
|
||||||
struct config_node *new_cn;
|
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))) ||
|
if ((cn->v && !(new_cn->v = _clone_config_value(mem, cn->v))) ||
|
||||||
(cn->child && !(new_cn->child = clone_config_node(mem, cn->child, 1))) ||
|
(cn->child && !(new_cn->child = clone_config_node_with_mem(mem, cn->child, 1))) ||
|
||||||
(siblings && cn->sib && !(new_cn->sib = clone_config_node(mem, cn->sib, siblings))))
|
(siblings && cn->sib && !(new_cn->sib = clone_config_node_with_mem(mem, cn->sib, siblings))))
|
||||||
return_NULL; /* 'new_cn' released with mem pool */
|
return_NULL; /* 'new_cn' released with mem pool */
|
||||||
|
|
||||||
return new_cn;
|
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;
|
||||||
|
}
|
||||||
|
@ -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(const char *filename, int keep_open);
|
||||||
struct config_tree *create_config_tree_from_string(struct cmd_context *cmd,
|
struct config_tree *create_config_tree_from_string(const char *config_settings);
|
||||||
const char *config_settings);
|
|
||||||
int override_config_tree_from_string(struct cmd_context *cmd,
|
int override_config_tree_from_string(struct cmd_context *cmd,
|
||||||
const char *config_settings);
|
const char *config_settings);
|
||||||
void destroy_config_tree(struct config_tree *cft);
|
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);
|
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);
|
int siblings);
|
||||||
|
|
||||||
|
struct dm_pool *config_tree_memory(struct config_tree *cft);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -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") ||
|
if (!strcmp(current->key, "type") || !strcmp(current->key, "start_extent") ||
|
||||||
!strcmp(current->key, "tags") || !strcmp(current->key, "extent_count"))
|
!strcmp(current->key, "tags") || !strcmp(current->key, "extent_count"))
|
||||||
continue;
|
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)
|
if (!new)
|
||||||
return_0;
|
return_0;
|
||||||
if (last)
|
if (last)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user