From dc4d7417f743ea0766aa9b200aa861ef003400bb Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Sat, 2 Sep 2006 01:18:17 +0000 Subject: [PATCH] When using local file locking, skip clustered VGs. Add fallback_to_clustered_locking and fallback_to_local_locking parameters. --- WHATS_NEW | 2 ++ doc/example.conf | 17 ++++++++++++++++- lib/config/defaults.h | 2 ++ lib/locking/locking.c | 15 +++++++++++++++ tools/lvconvert.c | 6 ++++++ tools/lvcreate.c | 6 ++++++ tools/lvrename.c | 6 ++++++ tools/lvresize.c | 6 ++++++ tools/pvchange.c | 6 ++++++ tools/pvmove.c | 6 ++++++ tools/pvresize.c | 7 +++++++ tools/reporter.c | 23 +++++++++++++++++++---- tools/toollib.c | 42 +++++++++++++++++++++++++++++++++++++++++- tools/vgextend.c | 6 ++++++ tools/vgmerge.c | 13 +++++++++++++ tools/vgreduce.c | 14 ++++++++++++++ tools/vgrename.c | 7 +++++++ tools/vgsplit.c | 7 +++++++ 18 files changed, 185 insertions(+), 6 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index ee8e26361..a15ba6137 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,7 @@ Version 2.02.10 - ================================== + When using local file locking, skip clustered VGs. + Add fallback_to_clustered_locking and fallback_to_local_locking parameters. lvm.static uses built-in cluster locking instead of external locking. Don't attempt to load shared libraries if built statically. Change default locking_lib to liblvm2clusterlock.so. diff --git a/doc/example.conf b/doc/example.conf index c4c6a07a4..e7195afab 100644 --- a/doc/example.conf +++ b/doc/example.conf @@ -207,11 +207,26 @@ global { # Location of proc filesystem proc = "/proc" - # Type of locking to use. Defaults to file-based locking (1). + # Type of locking to use. Defaults to local file-based locking (1). # Turn locking off by setting to 0 (dangerous: risks metadata corruption # if LVM2 commands get run concurrently). + # Type 2 uses the external shared library locking_library. + # Type 3 uses built-in clustered locking. locking_type = 1 + # If using external locking (type 2) and initialisation fails, + # with this set to 1 an attempt will be made to use the built-in + # clustered locking. + # If you are using a customised locking_library you should set this to 0. + fallback_to_clustered_locking = 1 + + # If an attempt to initialise type 2 or type 3 locking failed, perhaps + # because cluster components such as clvmd are not running, with this set + # to 1 an attempt will be made to use local file-based locking (type 1). + # If this succeeds, only commands against local volume groups will proceed. + # Volume Groups marked as clustered will be ignored. + fallback_to_local_locking = 1 + # Local non-LV directory that holds file-based locks while commands are # in progress. A directory like /tmp that may get wiped on reboot is OK. locking_dir = "/var/lock/lvm" diff --git a/lib/config/defaults.h b/lib/config/defaults.h index 31686f227..45610464b 100644 --- a/lib/config/defaults.h +++ b/lib/config/defaults.h @@ -33,6 +33,8 @@ #define DEFAULT_LOCK_DIR "/var/lock/lvm" #define DEFAULT_LOCKING_LIB "liblvm2clusterlock.so" +#define DEFAULT_FALLBACK_TO_LOCAL_LOCKING 1 +#define DEFAULT_FALLBACK_TO_CLUSTERED_LOCKING 1 #define DEFAULT_MIRROR_LOG_FAULT_POLICY "allocate" #define DEFAULT_MIRROR_DEV_FAULT_POLICY "remove" diff --git a/lib/locking/locking.c b/lib/locking/locking.c index dfe6c6a95..25065d4d0 100644 --- a/lib/locking/locking.c +++ b/lib/locking/locking.c @@ -20,6 +20,7 @@ #include "activate.h" #include "toolcontext.h" #include "memlock.h" +#include "defaults.h" #include #include @@ -147,6 +148,10 @@ int init_locking(int type, struct cmd_context *cmd) break; return 1; } + if (!find_config_tree_int(cmd, "locking/fallback_to_clustered_locking", + DEFAULT_FALLBACK_TO_CLUSTERED_LOCKING)) + break; + log_very_verbose("Falling back to clustered locking."); /* Fall through */ #endif @@ -163,6 +168,16 @@ int init_locking(int type, struct cmd_context *cmd) return 0; } + if ((type == 2 || type == 3) && + find_config_tree_int(cmd, "locking/fallback_to_local_locking", + DEFAULT_FALLBACK_TO_LOCAL_LOCKING)) { + log_print("WARNING: Falling back to local file-based locking."); + log_print("Volume Groups with the clustered attribute will " + "be inaccessible."); + if (init_file_locking(&_locking, cmd)) + return 1; + } + if (!ignorelockingfailure()) return 0; diff --git a/tools/lvconvert.c b/tools/lvconvert.c index 0aa0c9084..03f4673a6 100644 --- a/tools/lvconvert.c +++ b/tools/lvconvert.c @@ -565,6 +565,12 @@ 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); + goto error; + } + if (vg->status & EXPORTED_VG) { log_error("Volume group \"%s\" is exported", lp.vg_name); goto error; diff --git a/tools/lvcreate.c b/tools/lvcreate.c index a7e1aac0f..a8964d215 100644 --- a/tools/lvcreate.c +++ b/tools/lvcreate.c @@ -486,6 +486,12 @@ 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); + return 0; + } + if (vg->status & EXPORTED_VG) { log_error("Volume group \"%s\" is exported", lp->vg_name); return 0; diff --git a/tools/lvrename.c b/tools/lvrename.c index 29683d794..f29b52b9f 100644 --- a/tools/lvrename.c +++ b/tools/lvrename.c @@ -109,6 +109,12 @@ 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); + goto error; + } + if (vg->status & EXPORTED_VG) { log_error("Volume group \"%s\" is exported", vg->name); goto error; diff --git a/tools/lvresize.c b/tools/lvresize.c index 52e059697..a226b9052 100644 --- a/tools/lvresize.c +++ b/tools/lvresize.c @@ -138,6 +138,12 @@ 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); + return ECMD_FAILED; + } + if (vg->status & EXPORTED_VG) { log_error("Volume group %s is exported", vg->name); return ECMD_FAILED; diff --git a/tools/pvchange.c b/tools/pvchange.c index 7056ddd21..a4c0aa453 100644 --- a/tools/pvchange.c +++ b/tools/pvchange.c @@ -67,6 +67,12 @@ 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); diff --git a/tools/pvmove.c b/tools/pvmove.c index 5e9d3cf00..7c3d94375 100644 --- a/tools/pvmove.c +++ b/tools/pvmove.c @@ -66,6 +66,12 @@ 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); diff --git a/tools/pvresize.c b/tools/pvresize.c index 5458426db..3de3ab945 100644 --- a/tools/pvresize.c +++ b/tools/pvresize.c @@ -77,6 +77,13 @@ static int _pvresize_single(struct cmd_context *cmd, return ECMD_FAILED; } + if ((vg->status & CLUSTERED) && !locking_is_clustered() && + !lockingfailed()) { + 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); diff --git a/tools/reporter.c b/tools/reporter.c index 5bfd50cb4..f1257d5a3 100644 --- a/tools/reporter.c +++ b/tools/reporter.c @@ -68,13 +68,20 @@ static int _pvsegs_sub_single(struct cmd_context *cmd, struct volume_group *vg, if (!(vg = vg_read(cmd, pv->vg_name, NULL, &consistent))) { log_error("Can't read %s: skipping", pv->vg_name); - unlock_vg(cmd, pv->vg_name); - return ECMD_FAILED; + goto out; + } + + if ((vg->status & CLUSTERED) && !locking_is_clustered() && + !lockingfailed()) { + log_error("Skipping clustered volume group %s", vg->name); + ret = ECMD_FAILED; + goto out; } if (!report_object(handle, vg, NULL, pv, NULL, pvseg)) ret = ECMD_FAILED; +out: unlock_vg(cmd, pv->vg_name); return ret; } @@ -109,14 +116,22 @@ static int _pvs_single(struct cmd_context *cmd, struct volume_group *vg, if (!(vg = vg_read(cmd, pv->vg_name, (char *)&pv->vgid, &consistent))) { log_error("Can't read %s: skipping", pv->vg_name); - unlock_vg(cmd, pv->vg_name); - return ECMD_FAILED; + goto out; + } + + if ((vg->status & CLUSTERED) && !locking_is_clustered() && + !lockingfailed()) { + log_error("Skipping clustered volume group %s", + vg->name); + ret = ECMD_FAILED; + goto out; } } if (!report_object(handle, vg, NULL, pv, NULL, NULL)) ret = ECMD_FAILED; +out: if (pv->vg_name) unlock_vg(cmd, pv->vg_name); diff --git a/tools/toollib.c b/tools/toollib.c index a9c924b91..91b335df8 100644 --- a/tools/toollib.c +++ b/tools/toollib.c @@ -329,9 +329,20 @@ int process_each_lv(struct cmd_context *cmd, int argc, char **argv, if (!vg) log_error("Volume group \"%s\" " "not found", vgname); - else + else { + if ((vg->status & CLUSTERED) && + !locking_is_clustered() && + !lockingfailed()) { + log_error("Skipping clustered volume " + "group %s", vgname); + if (ret_max < ECMD_FAILED) + ret_max = ECMD_FAILED; + continue; + } log_error("Volume group \"%s\" " "inconsistent", vgname); + } + if (!vg || !(vg = recover_vg(cmd, vgname, lock_type))) { if (ret_max < ECMD_FAILED) ret_max = ECMD_FAILED; @@ -339,6 +350,15 @@ int process_each_lv(struct cmd_context *cmd, int argc, char **argv, } } + if ((vg->status & CLUSTERED) && !locking_is_clustered() && + !lockingfailed()) { + unlock_vg(cmd, vgname); + log_error("Skipping clustered volume group %s", vgname); + if (ret_max < ECMD_FAILED) + ret_max = ECMD_FAILED; + continue; + } + tags_arg = &tags; list_init(&lvnames); /* LVs to be processed in this VG */ list_iterate_items(sll, &arg_lvnames) { @@ -438,6 +458,13 @@ 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); + unlock_vg(cmd, vg_name); + return ECMD_FAILED; + } + if (!list_empty(tags)) { /* Only process if a tag matches or it's on arg_vgnames */ if (!str_list_match_item(arg_vgnames, vg_name) && @@ -680,6 +707,15 @@ 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); + continue; + } + ret = process_each_pv_in_vg(cmd, vg, &tags, handle, process_single); @@ -1045,6 +1081,10 @@ struct volume_group *recover_vg(struct cmd_context *cmd, const char *vgname, { int consistent = 1; + /* Don't attempt automatic recovery without proper locking */ + if (lockingfailed()) + return NULL; + lock_type &= ~LCK_TYPE_MASK; lock_type |= LCK_WRITE; diff --git a/tools/vgextend.c b/tools/vgextend.c index a94c5788f..7ec7008ba 100644 --- a/tools/vgextend.c +++ b/tools/vgextend.c @@ -53,6 +53,12 @@ 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); + goto error; + } + if (vg->status & EXPORTED_VG) { log_error("Volume group \"%s\" is exported", vg->name); goto error; diff --git a/tools/vgmerge.c b/tools/vgmerge.c index 73b7fa813..761ef8837 100644 --- a/tools/vgmerge.c +++ b/tools/vgmerge.c @@ -41,6 +41,13 @@ 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); @@ -66,6 +73,12 @@ 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); + goto error; + } + if (vg_from->status & EXPORTED_VG) { log_error("Volume group \"%s\" is exported", vg_from->name); goto error; diff --git a/tools/vgreduce.c b/tools/vgreduce.c index 86ff7fde7..058908562 100644 --- a/tools/vgreduce.c +++ b/tools/vgreduce.c @@ -476,6 +476,13 @@ int vgreduce(struct cmd_context *cmd, int argc, char **argv) return ECMD_FAILED; } + if ((vg->status & CLUSTERED) && !locking_is_clustered() && + !lockingfailed()) { + log_error("Skipping clustered volume group %s", vg->name); + unlock_vg(cmd, vg_name); + return ECMD_FAILED; + } + if (arg_count(cmd, removemissing_ARG)) { if (vg && consistent) { log_error("Volume group \"%s\" is already consistent", @@ -491,6 +498,13 @@ 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); + unlock_vg(cmd, vg_name); + return ECMD_FAILED; + } if (!archive(vg)) { init_partial(0); unlock_vg(cmd, vg_name); diff --git a/tools/vgrename.c b/tools/vgrename.c index 95eec9514..7a724a593 100644 --- a/tools/vgrename.c +++ b/tools/vgrename.c @@ -102,6 +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); + 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); diff --git a/tools/vgsplit.c b/tools/vgsplit.c index 42cecf688..75dde7750 100644 --- a/tools/vgsplit.c +++ b/tools/vgsplit.c @@ -196,6 +196,13 @@ 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); -- 2.43.5