diff --git a/WHATS_NEW b/WHATS_NEW index 4ea0927f1..9fb53cfe5 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.28 - ================================ + Move guts of vgremove into library. Fix inconsistent licence notices: executables are GPLv2; libraries LGPLv2.1. Move guts of lvremove into library. Allow clvmd debug to be turned on in a running daemon using clvmd -d diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h index 5b8030c08..a6fa49e50 100644 --- a/lib/metadata/metadata-exported.h +++ b/lib/metadata/metadata-exported.h @@ -330,6 +330,9 @@ struct volume_group *vg_create(struct cmd_context *cmd, const char *name, uint32_t max_lv, alloc_policy_t alloc, int pv_count, char **pv_names); int vg_remove(struct volume_group *vg); +int vg_remove_single(struct cmd_context *cmd, const char *vg_name, + struct volume_group *vg, int consistent, + force_t force); 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); diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c index 394b91903..c8b0e9f74 100644 --- a/lib/metadata/metadata.c +++ b/lib/metadata/metadata.c @@ -25,6 +25,7 @@ #include "activate.h" #include "display.h" #include "locking.h" +#include "archiver.h" #include @@ -248,6 +249,72 @@ int vg_rename(struct cmd_context *cmd, struct volume_group *vg, return 1; } +int vg_remove_single(struct cmd_context *cmd, const char *vg_name, + struct volume_group *vg, int consistent, + force_t force) +{ + struct physical_volume *pv; + struct pv_list *pvl; + int ret = 1; + + if (!vg || !consistent || (vg_status(vg) & PARTIAL_VG)) { + log_error("Volume group \"%s\" not found or inconsistent.", + vg_name); + log_error("Consider vgreduce --removemissing if metadata " + "is inconsistent."); + return 0; + } + + if (!vg_check_status(vg, EXPORTED_VG)) + return 0; + + if (vg->lv_count) { + log_error("Volume group \"%s\" still contains %d " + "logical volume(s)", vg_name, vg->lv_count); + return 0; + } + + if (!archive(vg)) + return 0; + + if (!vg_remove(vg)) { + log_error("vg_remove %s failed", vg_name); + return 0; + } + + /* init physical volumes */ + list_iterate_items(pvl, &vg->pvs) { + pv = pvl->pv; + log_verbose("Removing physical volume \"%s\" from " + "volume group \"%s\"", dev_name(pv_dev(pv)), vg_name); + pv->vg_name = ORPHAN; + pv->status = ALLOCATABLE_PV; + + if (!dev_get_size(pv_dev(pv), &pv->size)) { + log_error("%s: Couldn't get size.", dev_name(pv_dev(pv))); + ret = 0; + continue; + } + + /* FIXME Write to same sector label was read from */ + if (!pv_write(cmd, pv, NULL, INT64_C(-1))) { + log_error("Failed to remove physical volume \"%s\"" + " from volume group \"%s\"", + dev_name(pv_dev(pv)), vg_name); + ret = 0; + } + } + + backup_remove(cmd, vg_name); + + if (ret) + log_print("Volume group \"%s\" successfully removed", vg_name); + else + log_error("Volume group \"%s\" not properly removed", vg_name); + + return ret; +} + int vg_extend(struct volume_group *vg, int pv_count, char **pv_names) { int i; diff --git a/tools/vgremove.c b/tools/vgremove.c index 8076ae5ed..ca44e710d 100644 --- a/tools/vgremove.c +++ b/tools/vgremove.c @@ -15,71 +15,6 @@ #include "tools.h" -static int vg_remove_single(struct cmd_context *cmd, const char *vg_name, - struct volume_group *vg, int consistent, - force_t force) -{ - struct physical_volume *pv; - struct pv_list *pvl; - int ret = 1; - - if (!vg || !consistent || (vg_status(vg) & PARTIAL_VG)) { - log_error("Volume group \"%s\" not found or inconsistent.", - vg_name); - log_error("Consider vgreduce --removemissing if metadata " - "is inconsistent."); - return 0; - } - - if (!vg_check_status(vg, EXPORTED_VG)) - return 0; - - if (vg->lv_count) { - log_error("Volume group \"%s\" still contains %d " - "logical volume(s)", vg_name, vg->lv_count); - return 0; - } - - if (!archive(vg)) - return 0; - - if (!vg_remove(vg)) { - log_error("vg_remove %s failed", vg_name); - return 0; - } - - /* init physical volumes */ - list_iterate_items(pvl, &vg->pvs) { - pv = pvl->pv; - log_verbose("Removing physical volume \"%s\" from " - "volume group \"%s\"", dev_name(pv_dev(pv)), vg_name); - pv->vg_name = ORPHAN; - pv->status = ALLOCATABLE_PV; - - if (!dev_get_size(pv_dev(pv), &pv->size)) { - log_error("%s: Couldn't get size.", dev_name(pv_dev(pv))); - ret = 0; - continue; - } - - /* FIXME Write to same sector label was read from */ - if (!pv_write(cmd, pv, NULL, INT64_C(-1))) { - log_error("Failed to remove physical volume \"%s\"" - " from volume group \"%s\"", - dev_name(pv_dev(pv)), vg_name); - ret = 0; - } - } - - backup_remove(cmd, vg_name); - - if (ret) - log_print("Volume group \"%s\" successfully removed", vg_name); - else - log_error("Volume group \"%s\" not properly removed", vg_name); - - return ret; -} static int vgremove_single(struct cmd_context *cmd, const char *vg_name, struct volume_group *vg, int consistent, void *handle __attribute((unused)))