From 4f629c3bbafc7b2c27bd973a636bfc3fff9709ac Mon Sep 17 00:00:00 2001 From: Dave Wysochanski Date: Mon, 23 Jul 2007 21:03:42 +0000 Subject: [PATCH] Add CORRECT_INCONSISTENT and FAIL_INCONSISTENT flags to vg_lock_and_read --- lib/metadata/metadata-exported.h | 7 ++++++- lib/metadata/metadata.c | 12 +++++++++--- tools/pvmove.c | 3 ++- tools/vgextend.c | 3 ++- tools/vgmerge.c | 6 ++++-- tools/vgsplit.c | 3 ++- 6 files changed, 25 insertions(+), 9 deletions(-) diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h index 24f8bdfb9..7cfec7bf7 100644 --- a/lib/metadata/metadata-exported.h +++ b/lib/metadata/metadata-exported.h @@ -83,6 +83,10 @@ struct pv_segment; #define FMT_RESIZE_PV 0x00000080U /* Supports pvresize? */ #define FMT_UNLIMITED_STRIPESIZE 0x00000100U /* Unlimited stripe size? */ +/* LVM2 external library flags */ +#define CORRECT_INCONSISTENT 0x00000001U /* Correct inconsistent metadata */ +#define FAIL_INCONSISTENT 0x00000002U /* Fail if metadata inconsistent */ + /* Ordered list - see lv_manip.c */ typedef enum { ALLOC_INVALID, @@ -293,7 +297,8 @@ int pv_write(struct cmd_context *cmd, struct physical_volume *pv, struct list *mdas, int64_t label_sector); int is_orphan(pv_t *pv); vg_t *vg_lock_and_read(struct cmd_context *cmd, const char *vg_name, - uint32_t lock_flags, uint32_t status_flags); + uint32_t lock_flags, uint32_t status_flags, + uint32_t misc_flags); /* pe_start and pe_end relate to any existing data so that new metadata * areas can avoid overlap */ diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c index 29940c232..de42ed39a 100644 --- a/lib/metadata/metadata.c +++ b/lib/metadata/metadata.c @@ -1798,23 +1798,29 @@ int vg_check_status(struct volume_group *vg, uint32_t status) * @vg_name - name of the volume group to lock and read * @lock_flags - locking flags to use * @status_flags - status flags to check + * @misc_flags - function modifier flags * * Returns: * NULL - failure * non-NULL - success; volume group handle */ vg_t *vg_lock_and_read(struct cmd_context *cmd, const char *vg_name, - uint32_t lock_flags, uint32_t status_flags) + uint32_t lock_flags, uint32_t status_flags, + uint32_t misc_flags) { struct volume_group *vg; int consistent = 1; - + + if (!(misc_flags & CORRECT_INCONSISTENT)) + consistent = 0; + if (!lock_vol(cmd, vg_name, lock_flags)) { log_error("Can't get lock for %s", vg_name); return NULL; } - if (!(vg = vg_read(cmd, vg_name, NULL, &consistent)) || !consistent) { + if (!(vg = vg_read(cmd, vg_name, NULL, &consistent)) || + ((misc_flags & FAIL_INCONSISTENT) && !consistent)) { log_error("Volume group \"%s\" not found", vg_name); unlock_vg(cmd, vg_name); return NULL; diff --git a/tools/pvmove.c b/tools/pvmove.c index 33d1c42b4..4b6fdc2ef 100644 --- a/tools/pvmove.c +++ b/tools/pvmove.c @@ -55,7 +55,8 @@ static struct volume_group *_get_vg(struct cmd_context *cmd, const char *vgname) dev_close_all(); if (!(vg = vg_lock_and_read(cmd, vgname, LCK_VG_WRITE, - CLUSTERED | EXPORTED_VG | LVM_WRITE))) + CLUSTERED | EXPORTED_VG | LVM_WRITE, + CORRECT_INCONSISTENT | FAIL_INCONSISTENT))) return NULL; return vg; diff --git a/tools/vgextend.c b/tools/vgextend.c index 8f8009588..9ac98e2b0 100644 --- a/tools/vgextend.c +++ b/tools/vgextend.c @@ -49,7 +49,8 @@ int vgextend(struct cmd_context *cmd, int argc, char **argv) log_verbose("Checking for volume group \"%s\"", vg_name); if (!(vg = vg_lock_and_read(cmd, vg_name, LCK_VG_WRITE | LCK_NONBLOCK, CLUSTERED | EXPORTED_VG | - LVM_WRITE | RESIZEABLE_VG))) { + LVM_WRITE | RESIZEABLE_VG, + CORRECT_INCONSISTENT | FAIL_INCONSISTENT))) { unlock_vg(cmd, ORPHAN); return ECMD_FAILED; } diff --git a/tools/vgmerge.c b/tools/vgmerge.c index e44f05ead..218e38dec 100644 --- a/tools/vgmerge.c +++ b/tools/vgmerge.c @@ -30,13 +30,15 @@ static int _vgmerge_single(struct cmd_context *cmd, const char *vg_name_to, log_verbose("Checking for volume group \"%s\"", vg_name_to); if (!(vg_to = vg_lock_and_read(cmd, vg_name_to, LCK_VG_WRITE, - CLUSTERED | EXPORTED_VG | LVM_WRITE))) + CLUSTERED | EXPORTED_VG | LVM_WRITE, + CORRECT_INCONSISTENT | FAIL_INCONSISTENT))) return ECMD_FAILED; log_verbose("Checking for volume group \"%s\"", vg_name_from); if (!(vg_from = vg_lock_and_read(cmd, vg_name_from, LCK_VG_WRITE | LCK_NONBLOCK, - CLUSTERED | EXPORTED_VG | LVM_WRITE))) { + CLUSTERED | EXPORTED_VG | LVM_WRITE, + CORRECT_INCONSISTENT | FAIL_INCONSISTENT))) { unlock_vg(cmd, vg_name_to); return ECMD_FAILED; } diff --git a/tools/vgsplit.c b/tools/vgsplit.c index 805f5f212..ccc9dc3fe 100644 --- a/tools/vgsplit.c +++ b/tools/vgsplit.c @@ -242,7 +242,8 @@ int vgsplit(struct cmd_context *cmd, int argc, char **argv) log_verbose("Checking for volume group \"%s\"", vg_name_from); if (!(vg_to = vg_lock_and_read(cmd, vg_name_from, LCK_VG_WRITE, CLUSTERED | EXPORTED_VG | - RESIZEABLE_VG | LVM_WRITE))) + RESIZEABLE_VG | LVM_WRITE, + CORRECT_INCONSISTENT | FAIL_INCONSISTENT))) return ECMD_FAILED; log_verbose("Checking for volume group \"%s\"", vg_name_to);