diff options
author | Zdenek Kabelac <zkabelac@redhat.com> | 2011-03-10 12:43:29 +0000 |
---|---|---|
committer | Zdenek Kabelac <zkabelac@redhat.com> | 2011-03-10 12:43:29 +0000 |
commit | 3019419e955a212e83e7a6b7e8d1791cd866f0dd (patch) | |
tree | ea23ad764b804ac3c76b364e761297a87b10f17c /lib/metadata/vg.c | |
parent | 9cfdf8031eeb459b2de373d630e6cd9be23476f8 (diff) | |
download | lvm2-3019419e955a212e83e7a6b7e8d1791cd866f0dd.tar.gz lvm2-3019419e955a212e83e7a6b7e8d1791cd866f0dd.tar.xz lvm2-3019419e955a212e83e7a6b7e8d1791cd866f0dd.zip |
Refactor vg allocation code
Create new function alloc_vg() to allocate VG structure.
It takes pool_name (for easier debugging).
and also take vg_name to futher simplify code.
Move remainder of _build_vg_from_pds to _pool_vg_read
and use vg memory pool for import functions.
(it's been using smem -> fid mempool -> cmd mempool)
(FIXME: remove mempool parameter for import functions and use vg).
Move remainder of the _build_vg to _format1_vg_read
Diffstat (limited to 'lib/metadata/vg.c')
-rw-r--r-- | lib/metadata/vg.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/metadata/vg.c b/lib/metadata/vg.c index 9d0d5dd7..5bd00aee 100644 --- a/lib/metadata/vg.c +++ b/lib/metadata/vg.c @@ -18,6 +18,38 @@ #include "display.h" #include "activate.h" +struct volume_group *alloc_vg(const char *pool_name, struct cmd_context *cmd, + const char *vg_name) +{ + struct dm_pool *vgmem; + struct volume_group *vg; + + if (!(vgmem = dm_pool_create(pool_name, VG_MEMPOOL_CHUNK)) || + !(vg = dm_pool_zalloc(vgmem, sizeof(*vg)))) { + log_error("Failed to allocate volume group structure"); + if (vgmem) + dm_pool_destroy(vgmem); + return NULL; + } + + if (vg_name && !(vg->name = dm_pool_strdup(vgmem, vg_name))) { + log_error("Failed to allocate VG name."); + dm_pool_destroy(vgmem); + return NULL; + } + + vg->cmd = cmd; + vg->vgmem = vgmem; + vg->alloc = ALLOC_NORMAL; + + dm_list_init(&vg->pvs); + dm_list_init(&vg->lvs); + dm_list_init(&vg->tags); + dm_list_init(&vg->removed_pvs); + + return vg; +} + char *vg_fmt_dup(const struct volume_group *vg) { if (!vg->fid || !vg->fid->fmt) |