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/format_pool | |
parent | 9cfdf8031eeb459b2de373d630e6cd9be23476f8 (diff) | |
download | lvm2-3019419e955a212e83e7a6b7e8d1791cd866f0dd.tar.gz |
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/format_pool')
-rw-r--r-- | lib/format_pool/format_pool.c | 94 |
1 files changed, 33 insertions, 61 deletions
diff --git a/lib/format_pool/format_pool.c b/lib/format_pool/format_pool.c index 4252dad0d..a14bf8c7a 100644 --- a/lib/format_pool/format_pool.c +++ b/lib/format_pool/format_pool.c @@ -98,93 +98,65 @@ static int _check_usp(const char *vgname, struct user_subpool *usp, int sp_count return 1; } -static struct volume_group *_build_vg_from_pds(struct format_instance - *fid, struct dm_pool *mem, - struct dm_list *pds) +static struct volume_group *_pool_vg_read(struct format_instance *fid, + const char *vg_name, + struct metadata_area *mda __attribute__((unused))) { - struct dm_pool *smem = fid->fmt->cmd->mem; - struct volume_group *vg = NULL; - struct user_subpool *usp = NULL; + struct volume_group *vg; + struct user_subpool *usp; int sp_count; + DM_LIST_INIT(pds); - if (!(vg = dm_pool_zalloc(smem, sizeof(*vg)))) { - log_error("Unable to allocate volume group structure"); - return NULL; - } + /* We can safely ignore the mda passed in */ + + /* Strip dev_dir if present */ + vg_name = strip_dir(vg_name, fid->fmt->cmd->dev_dir); + + /* Set vg_name through read_pool_pds() */ + if (!(vg = alloc_vg("pool_vg_read", fid->fmt->cmd, NULL))) + return_NULL; + + /* Read all the pvs in the vg */ + if (!read_pool_pds(fid->fmt, vg_name, vg->vgmem, &pds)) + goto_bad; - vg->cmd = fid->fmt->cmd; - vg->vgmem = mem; vg->fid = fid; - vg->name = NULL; - vg->status = 0; - vg->extent_count = 0; - vg->pv_count = 0; + /* Setting pool seqno to 1 because the code always did this, + * although we don't think it's needed. */ vg->seqno = 1; - vg->system_id = NULL; - dm_list_init(&vg->pvs); - dm_list_init(&vg->lvs); - dm_list_init(&vg->tags); - dm_list_init(&vg->removed_pvs); - if (!import_pool_vg(vg, smem, pds)) - return_NULL; + if (!import_pool_vg(vg, vg->vgmem, &pds)) + goto_bad; - if (!import_pool_pvs(fid->fmt, vg, smem, pds)) - return_NULL; + if (!import_pool_pvs(fid->fmt, vg, vg->vgmem, &pds)) + goto_bad; - if (!import_pool_lvs(vg, smem, pds)) - return_NULL; + if (!import_pool_lvs(vg, vg->vgmem, &pds)) + goto_bad; /* * I need an intermediate subpool structure that contains all the * relevant info for this. Then i can iterate through the subpool * structures for checking, and create the segments */ - if (!(usp = _build_usp(pds, mem, &sp_count))) - return_NULL; + if (!(usp = _build_usp(&pds, vg->vgmem, &sp_count))) + goto_bad; /* * check the subpool structures - we can't handle partial VGs in * the pool format, so this will error out if we're missing PVs */ if (!_check_usp(vg->name, usp, sp_count)) - return_NULL; + goto_bad; - if (!import_pool_segments(&vg->lvs, smem, usp, sp_count)) - return_NULL; + if (!import_pool_segments(&vg->lvs, vg->vgmem, usp, sp_count)) + goto_bad; return vg; -} -static struct volume_group *_pool_vg_read(struct format_instance *fid, - const char *vg_name, - struct metadata_area *mda __attribute__((unused))) -{ - struct dm_pool *mem = dm_pool_create("pool vg_read", VG_MEMPOOL_CHUNK); - struct dm_list pds; - struct volume_group *vg = NULL; - - dm_list_init(&pds); - - /* We can safely ignore the mda passed in */ - - if (!mem) - return_NULL; - - /* Strip dev_dir if present */ - vg_name = strip_dir(vg_name, fid->fmt->cmd->dev_dir); - - /* Read all the pvs in the vg */ - if (!read_pool_pds(fid->fmt, vg_name, mem, &pds)) - goto_out; +bad: + free_vg(vg); - /* Do the rest of the vg stuff */ - if (!(vg = _build_vg_from_pds(fid, mem, &pds))) - goto_out; - - return vg; -out: - dm_pool_destroy(mem); return NULL; } |