From c221b0bc2197f8b5233c53698d760a8eb755344d Mon Sep 17 00:00:00 2001 From: Dave Wysochanski Date: Wed, 6 Jun 2007 19:40:28 +0000 Subject: [PATCH] Add vg_check_status to consolidate vg status flags checks and error messages. --- WHATS_NEW | 1 + lib/metadata/metadata.c | 42 +++++++++++++++++++++++++++++++++++++++++ lib/metadata/metadata.h | 2 ++ tools/lvconvert.c | 15 +-------------- tools/lvcreate.c | 15 +-------------- tools/lvrename.c | 15 +-------------- tools/lvresize.c | 15 +-------------- tools/pvchange.c | 16 ++-------------- tools/pvdisplay.c | 5 +---- tools/pvmove.c | 15 +-------------- tools/pvresize.c | 16 +--------------- tools/reporter.c | 9 ++------- tools/toollib.c | 21 ++++----------------- tools/vgextend.c | 21 ++------------------- tools/vgmerge.c | 31 ++---------------------------- tools/vgreduce.c | 9 ++------- tools/vgrename.c | 14 +++----------- tools/vgsplit.c | 23 ++-------------------- 18 files changed, 71 insertions(+), 214 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index 27da3e7a3..f74610dc9 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -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. diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c index e75a6cd7d..042bbf53d 100644 --- a/lib/metadata/metadata.c +++ b/lib/metadata/metadata.c @@ -24,6 +24,7 @@ #include "pv_alloc.h" #include "activate.h" #include "display.h" +#include "locking.h" #include @@ -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; +} diff --git a/lib/metadata/metadata.h b/lib/metadata/metadata.h index 024a82b0a..f03afc32a 100644 --- a/lib/metadata/metadata.h +++ b/lib/metadata/metadata.h @@ -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 */ diff --git a/tools/lvconvert.c b/tools/lvconvert.c index 8b28bfb9d..ccc8b1761 100644 --- a/tools/lvconvert.c +++ b/tools/lvconvert.c @@ -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 " diff --git a/tools/lvcreate.c b/tools/lvcreate.c index c5504d240..c94843e7f 100644 --- a/tools/lvcreate.c +++ b/tools/lvcreate.c @@ -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 " diff --git a/tools/lvrename.c b/tools/lvrename.c index a63f3a561..211930733 100644 --- a/tools/lvrename.c +++ b/tools/lvrename.c @@ -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 " diff --git a/tools/lvresize.c b/tools/lvresize.c index f4a90459d..b77fc7219 100644 --- a/tools/lvresize.c +++ b/tools/lvresize.c @@ -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))) { diff --git a/tools/pvchange.c b/tools/pvchange.c index a3a0717c9..1aa4c8670 100644 --- a/tools/pvchange.c +++ b/tools/pvchange.c @@ -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) { - unlock_vg(cmd, pv->vg_name); - log_error("Volume group \"%s\" is exported", vg->name); - return 0; - } - - if (!(vg->status & LVM_WRITE)) { + if (!vg_check_status(vg, + CLUSTERED | EXPORTED_VG | LVM_WRITE)) { unlock_vg(cmd, pv->vg_name); - log_error("Volume group \"%s\" is read-only", vg->name); return 0; } diff --git a/tools/pvdisplay.c b/tools/pvdisplay.c index 2e7643f25..eb7df5c26 100644 --- a/tools/pvdisplay.c +++ b/tools/pvdisplay.c @@ -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; } diff --git a/tools/pvmove.c b/tools/pvmove.c index b98014ef9..841d89ab6 100644 --- a/tools/pvmove.c +++ b/tools/pvmove.c @@ -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; } diff --git a/tools/pvresize.c b/tools/pvresize.c index 3de3ab945..5f44d6d5d 100644 --- a/tools/pvresize.c +++ b/tools/pvresize.c @@ -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; } diff --git a/tools/reporter.c b/tools/reporter.c index bdf4adfad..f906b5ad4 100644 --- a/tools/reporter.c +++ b/tools/reporter.c @@ -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; } diff --git a/tools/toollib.c b/tools/toollib.c index e461efb03..b286446b0 100644 --- a/tools/toollib.c +++ b/tools/toollib.c @@ -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, diff --git a/tools/vgextend.c b/tools/vgextend.c index 8c967a4cf..6fd079f71 100644 --- a/tools/vgextend.c +++ b/tools/vgextend.c @@ -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", diff --git a/tools/vgmerge.c b/tools/vgmerge.c index e7361e44f..4a74a09aa 100644 --- a/tools/vgmerge.c +++ b/tools/vgmerge.c @@ -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", diff --git a/tools/vgreduce.c b/tools/vgreduce.c index c7ce77466..92dd21eb4 100644 --- a/tools/vgreduce.c +++ b/tools/vgreduce.c @@ -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; } diff --git a/tools/vgrename.c b/tools/vgrename.c index 2adf71796..bd42be17e 100644 --- a/tools/vgrename.c +++ b/tools/vgrename.c @@ -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); diff --git a/tools/vgsplit.c b/tools/vgsplit.c index 24ac534f7..f6d4c96d1 100644 --- a/tools/vgsplit.c +++ b/tools/vgsplit.c @@ -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; } -- 2.43.5