mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
Add vg_check_status to consolidate vg status flags checks and error messages.
This commit is contained in:
parent
7da954d191
commit
c221b0bc21
@ -1,5 +1,6 @@
|
||||
Version 2.02.26 -
|
||||
=================================
|
||||
Add vg_check_status to consolidate vg status checks and error messages.
|
||||
Add pvdisplay --maps implementation.
|
||||
Fix vgcfgrestore man pg to show mandatory VG name and remove LVM1 options.
|
||||
Fix vgrename man page to include UUID and be consistent with lvrename.
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "pv_alloc.h"
|
||||
#include "activate.h"
|
||||
#include "display.h"
|
||||
#include "locking.h"
|
||||
|
||||
#include <sys/param.h>
|
||||
|
||||
@ -1593,3 +1594,44 @@ int pv_analyze(struct cmd_context *cmd, const char *pv_name,
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* vg_check_status - check volume group status flags and log error
|
||||
*
|
||||
* @vg - volume group to check status flags
|
||||
* @status_flags - specific status flags to check (e.g. EXPORTED_VG)
|
||||
*
|
||||
* Returns:
|
||||
* 0 - fail
|
||||
* 1 - success
|
||||
*/
|
||||
int vg_check_status(struct volume_group *vg, uint32_t status_flags)
|
||||
{
|
||||
if ((status_flags & CLUSTERED) &&
|
||||
(vg->status & CLUSTERED) && !locking_is_clustered() &&
|
||||
!lockingfailed()) {
|
||||
log_error("Skipping clustered volume group %s", vg->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((status_flags & EXPORTED_VG) &&
|
||||
(vg->status & EXPORTED_VG)) {
|
||||
log_error("Volume group %s is exported", vg->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((status_flags & LVM_WRITE) &&
|
||||
!(vg->status & LVM_WRITE)) {
|
||||
log_error("Volume group %s is read-only", vg->name);
|
||||
return 0;
|
||||
}
|
||||
if ((status_flags & RESIZEABLE_VG) &&
|
||||
!(vg->status & RESIZEABLE_VG)) {
|
||||
log_error("Volume group %s is not resizeable.", vg->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -578,6 +578,8 @@ int vg_add_snapshot(struct format_instance *fid, const char *name,
|
||||
|
||||
int vg_remove_snapshot(struct logical_volume *cow);
|
||||
|
||||
int vg_check_status(struct volume_group *vg, uint32_t status_flags);
|
||||
|
||||
/*
|
||||
* Mirroring functions
|
||||
*/
|
||||
|
@ -557,21 +557,8 @@ int lvconvert(struct cmd_context * cmd, int argc, char **argv)
|
||||
goto error;
|
||||
}
|
||||
|
||||
if ((vg->status & CLUSTERED) && !locking_is_clustered() &&
|
||||
!lockingfailed()) {
|
||||
log_error("Skipping clustered volume group %s", lp.vg_name);
|
||||
if (!vg_check_status(vg, CLUSTERED | EXPORTED_VG | LVM_WRITE))
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (vg->status & EXPORTED_VG) {
|
||||
log_error("Volume group \"%s\" is exported", lp.vg_name);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!(vg->status & LVM_WRITE)) {
|
||||
log_error("Volume group \"%s\" is read-only", lp.vg_name);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!(lvl = find_lv_in_vg(vg, lp.lv_name))) {
|
||||
log_error("Logical volume \"%s\" not found in "
|
||||
|
@ -493,21 +493,8 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((vg->status & CLUSTERED) && !locking_is_clustered() &&
|
||||
!lockingfailed()) {
|
||||
log_error("Skipping clustered volume group %s", lp->vg_name);
|
||||
if (!vg_check_status(vg, CLUSTERED | EXPORTED_VG | LVM_WRITE))
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (vg->status & EXPORTED_VG) {
|
||||
log_error("Volume group \"%s\" is exported", lp->vg_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(vg->status & LVM_WRITE)) {
|
||||
log_error("Volume group \"%s\" is read-only", lp->vg_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (lp->lv_name && find_lv_in_vg(vg, lp->lv_name)) {
|
||||
log_error("Logical volume \"%s\" already exists in "
|
||||
|
@ -109,21 +109,8 @@ int lvrename(struct cmd_context *cmd, int argc, char **argv)
|
||||
goto error;
|
||||
}
|
||||
|
||||
if ((vg->status & CLUSTERED) && !locking_is_clustered() &&
|
||||
!lockingfailed()) {
|
||||
log_error("Skipping clustered volume group %s", vg->name);
|
||||
if (!vg_check_status(vg, CLUSTERED | EXPORTED_VG | LVM_WRITE))
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (vg->status & EXPORTED_VG) {
|
||||
log_error("Volume group \"%s\" is exported", vg->name);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!(vg->status & LVM_WRITE)) {
|
||||
log_error("Volume group \"%s\" is read-only", vg_name);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (find_lv_in_vg(vg, lv_name_new)) {
|
||||
log_error("Logical volume \"%s\" already exists in "
|
||||
|
@ -141,21 +141,8 @@ static int _lvresize(struct cmd_context *cmd, struct lvresize_params *lp)
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
if ((vg->status & CLUSTERED) && !locking_is_clustered() &&
|
||||
!lockingfailed()) {
|
||||
log_error("Skipping clustered volume group %s", vg->name);
|
||||
if (!vg_check_status(vg, CLUSTERED | EXPORTED_VG | LVM_WRITE))
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
if (vg->status & EXPORTED_VG) {
|
||||
log_error("Volume group %s is exported", vg->name);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
if (!(vg->status & LVM_WRITE)) {
|
||||
log_error("Volume group %s is read-only", lp->vg_name);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
/* does LV exist? */
|
||||
if (!(lvl = find_lv_in_vg(vg, lp->lv_name))) {
|
||||
|
@ -67,21 +67,9 @@ static int _pvchange_single(struct cmd_context *cmd, struct physical_volume *pv,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((vg->status & CLUSTERED) && !locking_is_clustered() &&
|
||||
!lockingfailed()) {
|
||||
log_error("Skipping clustered volume group %s", vg->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (vg->status & EXPORTED_VG) {
|
||||
if (!vg_check_status(vg,
|
||||
CLUSTERED | EXPORTED_VG | LVM_WRITE)) {
|
||||
unlock_vg(cmd, pv->vg_name);
|
||||
log_error("Volume group \"%s\" is exported", vg->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(vg->status & LVM_WRITE)) {
|
||||
unlock_vg(cmd, pv->vg_name);
|
||||
log_error("Volume group \"%s\" is read-only", vg->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -37,10 +37,7 @@ static int _pvdisplay_single(struct cmd_context *cmd,
|
||||
goto out;
|
||||
}
|
||||
|
||||
if ((vg->status & CLUSTERED) && !locking_is_clustered() &&
|
||||
!lockingfailed()) {
|
||||
log_error("Skipping clustered volume group %s",
|
||||
vg->name);
|
||||
if (!vg_check_status(vg, CLUSTERED)) {
|
||||
ret = ECMD_FAILED;
|
||||
goto out;
|
||||
}
|
||||
|
@ -66,20 +66,7 @@ static struct volume_group *_get_vg(struct cmd_context *cmd, const char *vgname)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((vg->status & CLUSTERED) && !locking_is_clustered() &&
|
||||
!lockingfailed()) {
|
||||
log_error("Skipping clustered volume group %s", vgname);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (vg->status & EXPORTED_VG) {
|
||||
log_error("Volume group \"%s\" is exported", vgname);
|
||||
unlock_vg(cmd, vgname);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(vg->status & LVM_WRITE)) {
|
||||
log_error("Volume group \"%s\" is read-only", vgname);
|
||||
if (!vg_check_status(vg, CLUSTERED | EXPORTED_VG | LVM_WRITE)) {
|
||||
unlock_vg(cmd, vgname);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -77,22 +77,8 @@ static int _pvresize_single(struct cmd_context *cmd,
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
if ((vg->status & CLUSTERED) && !locking_is_clustered() &&
|
||||
!lockingfailed()) {
|
||||
if (!vg_check_status(vg, CLUSTERED | EXPORTED_VG | LVM_WRITE)) {
|
||||
unlock_vg(cmd, vg_name);
|
||||
log_error("Skipping clustered volume group %s", vg->name);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
if (vg->status & EXPORTED_VG) {
|
||||
unlock_vg(cmd, vg_name);
|
||||
log_error("Volume group \"%s\" is exported", vg->name);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
if (!(vg->status & LVM_WRITE)) {
|
||||
unlock_vg(cmd, pv->vg_name);
|
||||
log_error("Volume group \"%s\" is read-only", vg->name);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
|
@ -71,9 +71,7 @@ static int _pvsegs_sub_single(struct cmd_context *cmd, struct volume_group *vg,
|
||||
goto out;
|
||||
}
|
||||
|
||||
if ((vg->status & CLUSTERED) && !locking_is_clustered() &&
|
||||
!lockingfailed()) {
|
||||
log_error("Skipping clustered volume group %s", vg->name);
|
||||
if (!vg_check_status(vg, CLUSTERED)) {
|
||||
ret = ECMD_FAILED;
|
||||
goto out;
|
||||
}
|
||||
@ -119,10 +117,7 @@ static int _pvs_single(struct cmd_context *cmd, struct volume_group *vg,
|
||||
goto out;
|
||||
}
|
||||
|
||||
if ((vg->status & CLUSTERED) && !locking_is_clustered() &&
|
||||
!lockingfailed()) {
|
||||
log_error("Skipping clustered volume group %s",
|
||||
vg->name);
|
||||
if (!vg_check_status(vg, CLUSTERED)) {
|
||||
ret = ECMD_FAILED;
|
||||
goto out;
|
||||
}
|
||||
|
@ -357,11 +357,7 @@ int process_each_lv(struct cmd_context *cmd, int argc, char **argv,
|
||||
log_error("Volume group \"%s\" "
|
||||
"not found", vgname);
|
||||
else {
|
||||
if ((vg->status & CLUSTERED) &&
|
||||
!locking_is_clustered() &&
|
||||
!lockingfailed()) {
|
||||
log_error("Skipping clustered volume "
|
||||
"group %s", vgname);
|
||||
if (!vg_check_status(vg, CLUSTERED)) {
|
||||
if (ret_max < ECMD_FAILED)
|
||||
ret_max = ECMD_FAILED;
|
||||
continue;
|
||||
@ -377,10 +373,8 @@ int process_each_lv(struct cmd_context *cmd, int argc, char **argv,
|
||||
}
|
||||
}
|
||||
|
||||
if ((vg->status & CLUSTERED) && !locking_is_clustered() &&
|
||||
!lockingfailed()) {
|
||||
if (!vg_check_status(vg, CLUSTERED)) {
|
||||
unlock_vg(cmd, vgname);
|
||||
log_error("Skipping clustered volume group %s", vgname);
|
||||
if (ret_max < ECMD_FAILED)
|
||||
ret_max = ECMD_FAILED;
|
||||
continue;
|
||||
@ -485,9 +479,7 @@ static int _process_one_vg(struct cmd_context *cmd, const char *vg_name,
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
if ((vg->status & CLUSTERED) && !locking_is_clustered() &&
|
||||
!lockingfailed()) {
|
||||
log_error("Skipping clustered volume group %s", vg_name);
|
||||
if (!vg_check_status(vg, CLUSTERED)) {
|
||||
unlock_vg(cmd, vg_name);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
@ -735,13 +727,8 @@ int process_each_pv(struct cmd_context *cmd, int argc, char **argv,
|
||||
if (!consistent)
|
||||
continue;
|
||||
|
||||
if ((vg->status & CLUSTERED) &&
|
||||
!locking_is_clustered() &&
|
||||
!lockingfailed()) {
|
||||
log_error("Skipping clustered volume "
|
||||
"group %s", sll->str);
|
||||
if (!vg_check_status(vg, CLUSTERED))
|
||||
continue;
|
||||
}
|
||||
|
||||
ret = process_each_pv_in_vg(cmd, vg, &tags,
|
||||
handle,
|
||||
|
@ -59,26 +59,9 @@ int vgextend(struct cmd_context *cmd, int argc, char **argv)
|
||||
goto error;
|
||||
}
|
||||
|
||||
if ((vg->status & CLUSTERED) && !locking_is_clustered() &&
|
||||
!lockingfailed()) {
|
||||
log_error("Skipping clustered volume group %s", vg->name);
|
||||
if (!vg_check_status(vg, CLUSTERED | EXPORTED_VG |
|
||||
LVM_WRITE | RESIZEABLE_VG))
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (vg->status & EXPORTED_VG) {
|
||||
log_error("Volume group \"%s\" is exported", vg->name);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!(vg->status & LVM_WRITE)) {
|
||||
log_error("Volume group \"%s\" is read-only", vg_name);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!(vg->status & RESIZEABLE_VG)) {
|
||||
log_error("Volume group \"%s\" is not resizeable.", vg_name);
|
||||
goto error;
|
||||
}
|
||||
|
||||
/********** FIXME
|
||||
log_print("maximum logical volume size is %s",
|
||||
|
@ -41,21 +41,7 @@ static int _vgmerge_single(struct cmd_context *cmd, const char *vg_name_to,
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
if ((vg_to->status & CLUSTERED) && !locking_is_clustered() &&
|
||||
!lockingfailed()) {
|
||||
log_error("Skipping clustered volume group %s", vg_name_to);
|
||||
unlock_vg(cmd, vg_name_to);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
if (vg_to->status & EXPORTED_VG) {
|
||||
log_error("Volume group \"%s\" is exported", vg_to->name);
|
||||
unlock_vg(cmd, vg_name_to);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
if (!(vg_to->status & LVM_WRITE)) {
|
||||
log_error("Volume group \"%s\" is read-only", vg_to->name);
|
||||
if (!vg_check_status(vg_to, CLUSTERED | EXPORTED_VG | LVM_WRITE)) {
|
||||
unlock_vg(cmd, vg_name_to);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
@ -73,21 +59,8 @@ static int _vgmerge_single(struct cmd_context *cmd, const char *vg_name_to,
|
||||
goto error;
|
||||
}
|
||||
|
||||
if ((vg_from->status & CLUSTERED) && !locking_is_clustered() &&
|
||||
!lockingfailed()) {
|
||||
log_error("Skipping clustered volume group %s", vg_name_from);
|
||||
if (!vg_check_status(vg_from, CLUSTERED | EXPORTED_VG | LVM_WRITE))
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (vg_from->status & EXPORTED_VG) {
|
||||
log_error("Volume group \"%s\" is exported", vg_from->name);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!(vg_from->status & LVM_WRITE)) {
|
||||
log_error("Volume group \"%s\" is read-only", vg_from->name);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if ((active = lvs_in_vg_activated(vg_from))) {
|
||||
log_error("Logical volumes in \"%s\" must be inactive",
|
||||
|
@ -484,9 +484,7 @@ int vgreduce(struct cmd_context *cmd, int argc, char **argv)
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
if (vg && (vg->status & CLUSTERED) && !locking_is_clustered() &&
|
||||
!lockingfailed()) {
|
||||
log_error("Skipping clustered volume group %s", vg->name);
|
||||
if (vg && !vg_check_status(vg, CLUSTERED)) {
|
||||
unlock_vg(cmd, vg_name);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
@ -506,10 +504,7 @@ int vgreduce(struct cmd_context *cmd, int argc, char **argv)
|
||||
unlock_vg(cmd, vg_name);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
if ((vg->status & CLUSTERED) && !locking_is_clustered() &&
|
||||
!lockingfailed()) {
|
||||
log_error("Skipping clustered volume group %s",
|
||||
vg->name);
|
||||
if (!vg_check_status(vg, CLUSTERED)) {
|
||||
unlock_vg(cmd, vg_name);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
@ -102,21 +102,13 @@ int vgrename(struct cmd_context *cmd, int argc, char **argv)
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
if ((vg_old->status & CLUSTERED) && !locking_is_clustered() &&
|
||||
!lockingfailed()) {
|
||||
log_error("Skipping clustered volume group %s", vg_old->name);
|
||||
if (!vg_check_status(vg_old, CLUSTERED | LVM_WRITE)) {
|
||||
unlock_vg(cmd, vg_name_old);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
if (vg_old->status & EXPORTED_VG)
|
||||
log_info("Volume group \"%s\" is exported", vg_old->name);
|
||||
|
||||
if (!(vg_old->status & LVM_WRITE)) {
|
||||
unlock_vg(cmd, vg_name_old);
|
||||
log_error("Volume group \"%s\" is read-only", vg_old->name);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
/* Don't return failure for EXPORTED_VG */
|
||||
vg_check_status(vg_old, EXPORTED_VG);
|
||||
|
||||
if (lvs_in_vg_activated_by_uuid_only(vg_old)) {
|
||||
unlock_vg(cmd, vg_name_old);
|
||||
|
@ -251,27 +251,8 @@ int vgsplit(struct cmd_context *cmd, int argc, char **argv)
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
if ((vg_from->status & CLUSTERED) && !locking_is_clustered() &&
|
||||
!lockingfailed()) {
|
||||
log_error("Skipping clustered volume group %s", vg_from->name);
|
||||
unlock_vg(cmd, vg_name_from);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
if (vg_from->status & EXPORTED_VG) {
|
||||
log_error("Volume group \"%s\" is exported", vg_from->name);
|
||||
unlock_vg(cmd, vg_name_from);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
if (!(vg_from->status & RESIZEABLE_VG)) {
|
||||
log_error("Volume group \"%s\" is not resizeable", vg_from->name);
|
||||
unlock_vg(cmd, vg_name_from);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
if (!(vg_from->status & LVM_WRITE)) {
|
||||
log_error("Volume group \"%s\" is read-only", vg_from->name);
|
||||
if (!vg_check_status(vg_from, CLUSTERED | EXPORTED_VG |
|
||||
RESIZEABLE_VG | LVM_WRITE)) {
|
||||
unlock_vg(cmd, vg_name_from);
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user