1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-07-17 00:58:59 +03:00

metadata.c: Call refactored vgreduce_single

Replace the code with the refactored vgreduce_single instead
of calling its own implementation.

Corrects bug: https://bugzilla.redhat.com/show_bug.cgi?id=989174

Signed-off-by: Tony Asleson <tasleson@redhat.com>
This commit is contained in:
Tony Asleson
2013-09-03 18:07:43 -05:00
parent fe474e1452
commit 5074dcc896
4 changed files with 32 additions and 48 deletions

View File

@ -594,7 +594,7 @@ int vg_extend(struct volume_group *vg, int pv_count, const char *const *pv_names
int vg_reduce(struct volume_group *vg, const char *pv_name);
int vgreduce_single(struct cmd_context *cmd, struct volume_group *vg,
struct physical_volume *pv);
struct physical_volume *pv, int commit);
int vg_change_tag(struct volume_group *vg, const char *tag, int add_tag);
int vg_split_mdas(struct cmd_context *cmd, struct volume_group *vg_from,

View File

@ -691,50 +691,27 @@ int vg_extend(struct volume_group *vg, int pv_count, const char *const *pv_names
return 1;
}
/* FIXME: use this inside vgreduce_single? */
int vg_reduce(struct volume_group *vg, const 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;
return 0;
}
pv = pvl->pv;
if (pv_pe_alloc_count(pv)) {
log_error("Physical volume %s still in use.",
pv_name);
goto bad;
if (vgreduce_single(vg->cmd, vg, pv, 0)) {
dm_list_add(&vg->removed_pvs, &pvl->list);
return 1;
}
if (!dev_get_size(pv_dev(pv), &pv->size)) {
log_error("%s: Couldn't get size.", pv_name);
goto bad;
}
vg->free_count -= pv_pe_count(pv) - pv_pe_alloc_count(pv);
vg->extent_count -= pv_pe_count(pv);
del_pvl_from_vgs(vg, pvl);
/* add pv to the remove_pvs 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);
"volume group '%s'.", pv_name, vg->name);
return 0;
}

View File

@ -576,7 +576,7 @@ char *vg_attr_dup(struct dm_pool *mem, const struct volume_group *vg)
}
int vgreduce_single(struct cmd_context *cmd, struct volume_group *vg,
struct physical_volume *pv)
struct physical_volume *pv, int commit)
{
struct pv_list *pvl;
struct volume_group *orphan_vg = NULL;
@ -637,25 +637,32 @@ int vgreduce_single(struct cmd_context *cmd, struct volume_group *vg,
goto bad;
}
if (!vg_write(vg) || !vg_commit(vg)) {
log_error("Removal of physical volume \"%s\" from "
"\"%s\" failed", name, vg->name);
goto bad;
/*
* Only write out the needed changes if so requested by caller.
*/
if (commit) {
if (!vg_write(vg) || !vg_commit(vg)) {
log_error("Removal of physical volume \"%s\" from "
"\"%s\" failed", name, vg->name);
goto bad;
}
if (!pv_write(cmd, pv, 0)) {
log_error("Failed to clear metadata from physical "
"volume \"%s\" "
"after removal from \"%s\"", name, vg->name);
goto bad;
}
backup(vg);
log_print_unless_silent("Removed \"%s\" from volume group \"%s\"",
name, vg->name);
}
if (!pv_write(cmd, pv, 0)) {
log_error("Failed to clear metadata from physical "
"volume \"%s\" "
"after removal from \"%s\"", name, vg->name);
goto bad;
}
backup(vg);
log_print_unless_silent("Removed \"%s\" from volume group \"%s\"", name, vg->name);
r = 1;
bad:
if (pvl)
/* If we are committing here or we had an error then we will free fid */
if (pvl && (commit || r != 1))
free_pv_fid(pvl->pv);
unlock_and_release_vg(cmd, orphan_vg, VG_ORPHANS);
return r;

View File

@ -125,7 +125,7 @@ static int _vgreduce_single(struct cmd_context *cmd, struct volume_group *vg,
struct physical_volume *pv,
void *handle __attribute__((unused)))
{
int r = vgreduce_single(cmd, vg, pv);
int r = vgreduce_single(cmd, vg, pv, 1);
if (!r)
return ECMD_FAILED;