1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

fix readonly activation override options

This fixes a problem in commit e6bb780d24, in which the
back compat handling for the old locking_type=4 was
incorrectly translated to mean the same thing as --readonly,
which prevented activation because activation uses an
exclusive vg lock.  Previously, locking_type=4 allowed
activation.

If we see locking_type 4 in an old config, translate it to
the new combination of --readonly and --sysinit, which we
now define to mean the --readonly behavior with an exception
to allow activation.
This commit is contained in:
David Teigland 2018-09-12 15:59:47 -05:00
parent 17bd91e33e
commit 0aeca60aaa
3 changed files with 41 additions and 11 deletions

View File

@ -86,9 +86,9 @@ static void _update_vg_lock_count(const char *resource, uint32_t flags)
/*
* A mess of options have been introduced over time to override
* or tweak the behavior of file locking. These options are
* allowed in different but overlapping sets of commands
* (see command-lines.in)
* or tweak the behavior of file locking, and indirectly other
* behaviors. These options are allowed in different but
* overlapping sets of commands (see command-lines.in)
*
* --nolocking
*
@ -98,7 +98,8 @@ static void _update_vg_lock_count(const char *resource, uint32_t flags)
*
* Command will grant any read lock request, without trying
* to acquire an actual file lock. Command will refuse any
* write lock request.
* write lock request. (Activation, which uses a write lock,
* is not allowed.)
*
* --ignorelockingfailure
*
@ -111,6 +112,12 @@ static void _update_vg_lock_count(const char *resource, uint32_t flags)
*
* The same as ignorelockingfailure.
*
* --sysinit --readonly
*
* The combination of these two flags acts like --readonly,
* refusing write lock requests, but makes an exception to
* allow activation.
*
* global/metadata_read_only
*
* The command acquires actual read locks and refuses
@ -214,7 +221,7 @@ int lock_vol(struct cmd_context *cmd, const char *vol, uint32_t flags, const str
* When --readonly is set, grant read lock requests without trying to
* acquire an actual lock, and refuse write lock requests.
*/
if (_file_locking_readonly) {
if (_file_locking_readonly && !_file_locking_sysinit) {
if (lck_type != LCK_WRITE)
goto out_hold;
@ -222,6 +229,24 @@ int lock_vol(struct cmd_context *cmd, const char *vol, uint32_t flags, const str
goto out_fail;
}
/*
* When --readonly and --sysinit are set, grant read lock requests without
* trying to acquire an actual lock, and refuse write lock requests except
* in the case of activation which is permitted.
*/
if (_file_locking_readonly && _file_locking_sysinit) {
if (lck_type != LCK_WRITE)
goto out_hold;
if (cmd->is_activating) {
log_warn("Allowing activation with --readonly --sysinit.");
goto out_hold;
}
log_error("Operation prohibited while --readonly is set.");
goto out_fail;
}
/*
* When global/metadata_read_only is set, acquire actual read locks and
* refuse write lock requests.

View File

@ -280,7 +280,7 @@ RULE: all not LV_raid0
lvchange --activate Active VG|LV|Tag|Select ...
OO: --activationmode ActivationMode, --partial, --poll Bool, --monitor Bool,
--ignoreactivationskip, --ignorelockingfailure, --sysinit, OO_LVCHANGE
--ignoreactivationskip, --ignorelockingfailure, --sysinit, --readonly, OO_LVCHANGE
IO: --ignoreskippedcluster
ID: lvchange_activate
DESC: Activate or deactivate an LV.
@ -1559,7 +1559,7 @@ DESC: Start or stop processing LV conversions.
vgchange --activate Active
OO: --activationmode ActivationMode, --ignoreactivationskip, --partial, --sysinit,
--ignorelockingfailure, --monitor Bool, --poll Bool, OO_VGCHANGE
--readonly, --ignorelockingfailure, --monitor Bool, --poll Bool, OO_VGCHANGE
OP: VG|Tag|Select ...
IO: --ignoreskippedcluster
ID: vgchange_activate

View File

@ -2743,6 +2743,7 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
int locking_type;
int nolocking = 0;
int readonly = 0;
int sysinit = 0;
int monitoring;
char *arg_new, *arg;
int i;
@ -2921,20 +2922,24 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
log_warn("WARNING: see lvmlockd(8) for information on using cluster/clvm VGs.");
if ((locking_type == 0) || (locking_type == 5)) {
log_warn("WARNING: locking_type is deprecated, using --nolocking.");
log_warn("WARNING: locking_type (%d) is deprecated, using --nolocking.", locking_type);
nolocking = 1;
} else if (locking_type == 4) {
log_warn("WARNING: locking_type is deprecated, using --readonly.");
log_warn("WARNING: locking_type (%d) is deprecated, using --sysinit --readonly.", locking_type);
sysinit = 1;
readonly = 1;
} else if (locking_type != 1) {
log_warn("WARNING: locking_type is deprecated, using file locking.");
log_warn("WARNING: locking_type (%d) is deprecated, using file locking.", locking_type);
}
if (arg_is_set(cmd, nolocking_ARG) || _cmd_no_meta_proc(cmd))
nolocking = 1;
if (arg_is_set(cmd, sysinit_ARG))
sysinit = 1;
if (arg_is_set(cmd, readonly_ARG))
readonly = 1;
@ -2942,7 +2947,7 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
if (!_cmd_no_meta_proc(cmd))
log_warn("WARNING: File locking is disabled.");
} else {
if (!init_locking(cmd, arg_is_set(cmd, sysinit_ARG), readonly, arg_is_set(cmd, ignorelockingfailure_ARG))) {
if (!init_locking(cmd, sysinit, readonly, arg_is_set(cmd, ignorelockingfailure_ARG))) {
ret = ECMD_FAILED;
goto_out;
}