diff options
author | David Teigland <teigland@redhat.com> | 2015-07-17 15:13:22 -0500 |
---|---|---|
committer | David Teigland <teigland@redhat.com> | 2015-07-17 15:35:34 -0500 |
commit | b4be988732e909d34ae7b4868bf30cf44c087518 (patch) | |
tree | 2a1ef841c3be5e30e92e00a19f6467fc759b76d7 | |
parent | b785a50da415cd8ee48e971f720640457514032d (diff) | |
download | lvm2-b4be988732e909d34ae7b4868bf30cf44c087518.tar.gz |
vgchange/lvchange: enforce the shared VG lock from lvmlockd
The vgchange/lvchange activation commands read the VG, and
don't write it, so they acquire a shared VG lock from lvmlockd.
When other commands fail to acquire a shared VG lock from
lvmlockd, a warning is printed and they continue without it.
(Without it, the VG metadata they display from lvmetad may
not be up to date.)
vgchange/lvchange -a shouldn't continue without the shared
lock for a couple reasons:
. Usually they will just continue on and fail to acquire the
LV locks for activation, so continuing is pointless.
. More importantly, without the sh VG lock, the VG metadata
used by the command may be stale, and the LV locks shown
in the VG metadata may no longer be current. In the
case of sanlock, this would result in odd, unpredictable
errors when lvmlockd doesn't find the expected lock on
disk. In the case of dlm, the invalid LV lock could be
granted for the non-existing LV.
The solution is to not continue after the shared lock fails,
in the same way that a command fails if an exclusive lock fails.
-rw-r--r-- | lib/commands/toolcontext.h | 1 | ||||
-rw-r--r-- | lib/metadata/metadata.c | 2 | ||||
-rw-r--r-- | tools/lvchange.c | 4 | ||||
-rw-r--r-- | tools/vgchange.c | 4 |
4 files changed, 8 insertions, 3 deletions
diff --git a/lib/commands/toolcontext.h b/lib/commands/toolcontext.h index 283783f5d..4e8998dc6 100644 --- a/lib/commands/toolcontext.h +++ b/lib/commands/toolcontext.h @@ -107,6 +107,7 @@ struct cmd_context { unsigned lockd_vg_disable:1; unsigned lockd_lv_disable:1; unsigned lockd_vg_default_sh:1; + unsigned lockd_vg_enforce_sh:1; struct dev_types *dev_types; diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c index 56ed3fb12..875733188 100644 --- a/lib/metadata/metadata.c +++ b/lib/metadata/metadata.c @@ -4803,7 +4803,7 @@ static int _access_vg_lock_type(struct cmd_context *cmd, struct volume_group *vg * no lock. */ if (lockd_state & LDST_FAIL) { - if (lockd_state & LDST_EX) { + if ((lockd_state & LDST_EX) || cmd->lockd_vg_enforce_sh) { log_error("Cannot access VG %s due to failed lock.", vg->name); *failure |= FAILED_LOCK_MODE; return 0; diff --git a/tools/lvchange.c b/tools/lvchange.c index 58e0fb222..823c36aab 100644 --- a/tools/lvchange.c +++ b/tools/lvchange.c @@ -1294,8 +1294,10 @@ int lvchange(struct cmd_context *cmd, int argc, char **argv) * are cases where lvchange does not modify the vg, so they can use * the sh lock mode. */ - if (arg_count(cmd, activate_ARG) || arg_count(cmd, refresh_ARG)) + if (arg_count(cmd, activate_ARG) || arg_count(cmd, refresh_ARG)) { cmd->lockd_vg_default_sh = 1; + cmd->lockd_vg_enforce_sh = 1; + } return process_each_lv(cmd, argc, argv, update ? READ_FOR_UPDATE : 0, NULL, diff --git a/tools/vgchange.c b/tools/vgchange.c index 961222206..824fd912e 100644 --- a/tools/vgchange.c +++ b/tools/vgchange.c @@ -1017,8 +1017,10 @@ static int _lockd_vgchange(struct cmd_context *cmd, int argc, char **argv) return 0; } - if (arg_is_set(cmd, activate_ARG) || arg_is_set(cmd, refresh_ARG)) + if (arg_is_set(cmd, activate_ARG) || arg_is_set(cmd, refresh_ARG)) { cmd->lockd_vg_default_sh = 1; + cmd->lockd_vg_enforce_sh = 1; + } /* Starting a vg lockspace means there are no locks available yet. */ |