diff --git a/lib/locking/lvmlockd.c b/lib/locking/lvmlockd.c index 99fc047e6..a0dff8ab1 100644 --- a/lib/locking/lvmlockd.c +++ b/lib/locking/lvmlockd.c @@ -1346,6 +1346,14 @@ int lockd_gl(struct cmd_context *cmd, const char *def_mode, uint32_t flags) if (!_use_lvmlockd) return 1; + /* + * Verify that when --readonly is used, no ex locks should be used. + */ + if (cmd->metadata_read_only && def_mode && !strcmp(def_mode, "ex")) { + log_error("Exclusive locks are not allowed with readonly option."); + return 0; + } + if (cmd->lockd_gl_disable) return 1; @@ -1528,6 +1536,16 @@ int lockd_vg(struct cmd_context *cmd, const char *vg_name, const char *def_mode, if (!is_real_vg(vg_name)) return 1; + /* + * Verify that when --readonly is used, no ex locks should be used. + */ + if (cmd->metadata_read_only && + ((def_mode && !strcmp(def_mode, "ex")) || + (!def_mode && !cmd->lockd_vg_default_sh))) { + log_error("Exclusive locks are not allowed with readonly option."); + return 0; + } + /* * Some special cases need to disable the vg lock. */ @@ -1799,6 +1817,14 @@ int lockd_lv_name(struct cmd_context *cmd, struct volume_group *vg, int refreshed = 0; int result; + /* + * Verify that when --readonly is used, no LVs should be activated or used. + */ + if (cmd->metadata_read_only) { + log_error("LV locks are not allowed with readonly option."); + return 0; + } + if (cmd->lockd_lv_disable) return 1; diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c index c4a78b0c2..6dbc1894a 100644 --- a/tools/lvmcmdline.c +++ b/tools/lvmcmdline.c @@ -1435,6 +1435,14 @@ static int _init_lvmlockd(struct cmd_context *cmd) const char *lvmlockd_socket; int use_lvmlockd = find_config_tree_bool(cmd, global_use_lvmlockd_CFG, NULL); + if (use_lvmlockd && arg_count(cmd, nolocking_ARG)) { + /* --nolocking is only allowed with vgs/lvs/pvs commands */ + cmd->lockd_gl_disable = 1; + cmd->lockd_vg_disable = 1; + cmd->lockd_lv_disable = 1; + return 1; + } + if (use_lvmlockd && locking_is_clustered()) { log_error("ERROR: configuration setting use_lvmlockd cannot be used with clustered locking_type 3."); return 0; @@ -1567,7 +1575,19 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv) } if (arg_count(cmd, readonly_ARG)) { - locking_type = 5; + if (find_config_tree_bool(cmd, global_use_lvmlockd_CFG, NULL)) { + /* + * FIXME: we could use locking_type 5 here if that didn't + * cause CLUSTERED to be set, which conflicts with using lvmlockd. + */ + locking_type = 1; + cmd->lockd_gl_disable = 1; + cmd->lockd_vg_disable = 1; + cmd->lockd_lv_disable = 1; + } else { + locking_type = 5; + } + if (lvmetad_used()) { lvmetad_set_active(cmd, 0); log_verbose("Disabling use of lvmetad because read-only is set.");