diff options
author | Tony Asleson <tasleson@redhat.com> | 2013-09-03 18:07:43 -0500 |
---|---|---|
committer | Tony Asleson <tasleson@redhat.com> | 2013-11-19 14:40:30 -0600 |
commit | 5074dcc896681494309c59830803b54a84429fd0 (patch) | |
tree | b6784e553d968201de89da57aba757bb3f3fde4c | |
parent | fe474e1452866476b7f17175d92417d6d827ae4c (diff) | |
download | lvm2-5074dcc896681494309c59830803b54a84429fd0.tar.gz |
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>
-rw-r--r-- | lib/metadata/metadata-exported.h | 2 | ||||
-rw-r--r-- | lib/metadata/metadata.c | 35 | ||||
-rw-r--r-- | lib/metadata/vg.c | 37 | ||||
-rw-r--r-- | tools/vgreduce.c | 2 |
4 files changed, 30 insertions, 46 deletions
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h index cac5b3cfd..742924133 100644 --- a/lib/metadata/metadata-exported.h +++ b/lib/metadata/metadata-exported.h @@ -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, diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c index 398def68c..7177ff078 100644 --- a/lib/metadata/metadata.c +++ b/lib/metadata/metadata.c @@ -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 (!dev_get_size(pv_dev(pv), &pv->size)) { - log_error("%s: Couldn't get size.", pv_name); - goto bad; + if (vgreduce_single(vg->cmd, vg, pv, 0)) { + dm_list_add(&vg->removed_pvs, &pvl->list); + return 1; } - 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; } diff --git a/lib/metadata/vg.c b/lib/metadata/vg.c index 20b4b4df4..877371efe 100644 --- a/lib/metadata/vg.c +++ b/lib/metadata/vg.c @@ -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; - } + 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); + backup(vg); - log_print_unless_silent("Removed \"%s\" from volume group \"%s\"", name, vg->name); + 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; diff --git a/tools/vgreduce.c b/tools/vgreduce.c index 534a4fbbb..0ade4fad1 100644 --- a/tools/vgreduce.c +++ b/tools/vgreduce.c @@ -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; |