mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
Add vg_reduce to metadata.c and metadata-exported.h
This function behaves a little bit different than vg_reduce_single, because it allowes to remove even the latest pv. This has been done to be consistent to lvm_vg_create, which creates an empty vg. removed_pvs has been added to the volume_group struct. vg_reduce adds remove pvs to this list to be able to commit the changes for the pvs in lvm_vg_comm in liblvm2app. Initialize removed_pvs list in format-specific volume_group constructors. Ideally, we should have a base constructor here that initializes the general non-format specific members of struct volume_group. But until then, there are multiple places to initialize these members. Maybe a better patch would be a base constructor patch for struct volume_group. That is more work though. Signed-off-by: Dave Wysochanski <dwysocha@redhat.com> Signed-off-by: Thomas Woerner <twoerner@redhat.com> Author: Dave Wysochanski <dwysocha@redhat.com>
This commit is contained in:
parent
0589e19fd7
commit
1bd72d90a4
@ -132,6 +132,7 @@ static struct volume_group *_build_vg(struct format_instance *fid,
|
||||
dm_list_init(&vg->pvs);
|
||||
dm_list_init(&vg->lvs);
|
||||
dm_list_init(&vg->tags);
|
||||
dm_list_init(&vg->removed_pvs);
|
||||
|
||||
if (!_check_vgs(pvs))
|
||||
goto_bad;
|
||||
|
@ -124,6 +124,7 @@ static struct volume_group *_build_vg_from_pds(struct format_instance
|
||||
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;
|
||||
|
@ -753,6 +753,7 @@ static struct volume_group *_read_vg(struct format_instance *fid,
|
||||
|
||||
dm_list_init(&vg->lvs);
|
||||
dm_list_init(&vg->tags);
|
||||
dm_list_init(&vg->removed_pvs);
|
||||
|
||||
/* Optional tags */
|
||||
if ((cn = find_config_node(vgn, "tags")) &&
|
||||
|
@ -242,6 +242,12 @@ struct volume_group {
|
||||
* FIXME: Split these out.
|
||||
*/
|
||||
|
||||
/*
|
||||
* List of removed physical volumes by pvreduce.
|
||||
* They have to get cleared on vg_commit.
|
||||
*/
|
||||
struct dm_list removed_pvs;
|
||||
|
||||
/*
|
||||
* Store result of the last vg_read().
|
||||
* 0 for success else appropriate FAILURE_* bits set.
|
||||
@ -437,6 +443,7 @@ int vg_remove_single(vg_t *vg);
|
||||
int vg_rename(struct cmd_context *cmd, struct volume_group *vg,
|
||||
const char *new_name);
|
||||
int vg_extend(struct volume_group *vg, int pv_count, char **pv_names);
|
||||
int vg_reduce(struct volume_group *vg, char *pv_name);
|
||||
int vg_set_extent_size(vg_t *vg, uint32_t new_extent_size);
|
||||
int vg_set_max_lv(vg_t *vg, uint32_t max_lv);
|
||||
int vg_set_max_pv(vg_t *vg, uint32_t max_pv);
|
||||
|
@ -532,6 +532,54 @@ int vg_extend(struct volume_group *vg, int pv_count, char **pv_names)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* FIXME: use this inside vgreduce_single? */
|
||||
int vg_reduce(struct volume_group *vg, char *pv_name)
|
||||
{
|
||||
struct physical_volume *pv;
|
||||
struct pv_list *pvl;
|
||||
|
||||
if (_vg_bad_status_bits(vg, RESIZEABLE_VG))
|
||||
return 0;
|
||||
|
||||
if (!archive(vg))
|
||||
goto bad;
|
||||
|
||||
/* remove each pv */
|
||||
if (!(pvl = find_pv_in_vg(vg, pv_name))) {
|
||||
log_error("Physical volume %s not in volume group %s.",
|
||||
pv_name, vg->name);
|
||||
goto bad;
|
||||
}
|
||||
|
||||
pv = pvl->pv;
|
||||
|
||||
if (pv_pe_alloc_count(pv)) {
|
||||
log_error("Physical volume %s still in use.",
|
||||
pv_name);
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if (!dev_get_size(pv_dev(pv), &pv->size)) {
|
||||
log_error("%s: Couldn't get size.", pv_name);
|
||||
goto bad;
|
||||
}
|
||||
|
||||
vg->pv_count--;
|
||||
vg->free_count -= pv_pe_count(pv) - pv_pe_alloc_count(pv);
|
||||
vg->extent_count -= pv_pe_count(pv);
|
||||
|
||||
/* add pv to the remove_pvs list */
|
||||
dm_list_del(&pvl->list);
|
||||
dm_list_add(&vg->removed_pvs, &pvl->list);
|
||||
|
||||
return 1;
|
||||
|
||||
bad:
|
||||
log_error("Unable to remove physical volume '%s' from "
|
||||
"volume group '%s'.", pv_name, vg->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *strip_dir(const char *vg_name, const char *dev_dir)
|
||||
{
|
||||
size_t len = strlen(dev_dir);
|
||||
@ -660,6 +708,9 @@ vg_t *vg_create(struct cmd_context *cmd, const char *vg_name)
|
||||
|
||||
dm_list_init(&vg->tags);
|
||||
|
||||
/* initialize removed_pvs list */
|
||||
dm_list_init(&vg->removed_pvs);
|
||||
|
||||
if (!(vg->fid = cmd->fmt->ops->create_instance(cmd->fmt, vg_name,
|
||||
NULL, NULL))) {
|
||||
log_error("Failed to create format instance");
|
||||
@ -2165,6 +2216,7 @@ static struct volume_group *_vg_read_orphans(struct cmd_context *cmd,
|
||||
dm_list_init(&vg->pvs);
|
||||
dm_list_init(&vg->lvs);
|
||||
dm_list_init(&vg->tags);
|
||||
dm_list_init(&vg->removed_pvs);
|
||||
vg->vgmem = mem;
|
||||
vg->cmd = cmd;
|
||||
if (!(vg->name = dm_pool_strdup(mem, orphan_vgname))) {
|
||||
|
Loading…
Reference in New Issue
Block a user