From c5e634d2e0986e56b64347ee2ba3390cf766c7ce Mon Sep 17 00:00:00 2001 From: Ken Gaillot Date: Mar 09 2021 06:18:36 +0000 Subject: Refactor: libcrmcommon,libstonithd: add API for detecting special stonith params This includes a slight behavioral change. Previously, the stonith API validate method would strip out all parameters starting with "pcmk_" (which could be an issue if a fence agent named one of its own parameters like that); now, it only strips the specific parameters that Pacemaker handles directly. --- diff --git a/include/crm/common/agents.h b/include/crm/common/agents.h index e9089ae..b185977 100644 --- a/include/crm/common/agents.h +++ b/include/crm/common/agents.h @@ -53,6 +53,7 @@ char *crm_generate_ra_key(const char *standard, const char *provider, const char *type); int crm_parse_agent_spec(const char *spec, char **standard, char **provider, char **type); +bool pcmk_stonith_param(const char *param); #ifndef PCMK__NO_COMPAT /* Everything here is deprecated and kept only for public API backward diff --git a/lib/common/agents.c b/lib/common/agents.c index 1ee55ac..0291b0b 100644 --- a/lib/common/agents.c +++ b/lib/common/agents.c @@ -171,3 +171,42 @@ crm_provider_required(const char *standard) { return pcmk_is_set(pcmk_get_ra_caps(standard), pcmk_ra_cap_provider); } + +/*! + * \brief Check whether a given stonith parameter is handled by Pacemaker + * + * Return true if a given string is the name of one of the special resource + * instance attributes interpreted directly by Pacemaker for stonith-class + * resources. + * + * \param[in] param Parameter name to check + * + * \return true if \p param is a special fencing parameter + */ +bool +pcmk_stonith_param(const char *param) +{ + if (param == NULL) { + return false; + } + if (pcmk__str_any_of(param, PCMK_STONITH_PROVIDES, + PCMK_STONITH_STONITH_TIMEOUT, NULL)) { + return true; + } + if (!pcmk__starts_with(param, "pcmk_")) { // Short-circuit common case + return false; + } + if (pcmk__str_any_of(param, + PCMK_STONITH_ACTION_LIMIT, + PCMK_STONITH_DELAY_BASE, + PCMK_STONITH_DELAY_MAX, + PCMK_STONITH_HOST_ARGUMENT, + PCMK_STONITH_HOST_CHECK, + PCMK_STONITH_HOST_LIST, + PCMK_STONITH_HOST_MAP, + NULL)) { + return true; + } + param = strchr(param + 5, '_'); // Skip past "pcmk_ACTION" + return pcmk__str_any_of(param, "_action", "_timeout", "_retries", NULL); +} diff --git a/lib/fencing/st_client.c b/lib/fencing/st_client.c index 21ea9c7..c0d1e3d 100644 --- a/lib/fencing/st_client.c +++ b/lib/fencing/st_client.c @@ -2052,11 +2052,7 @@ stonith_api_validate(stonith_t *st, int call_options, const char *rsc_id, pcmk__str_casei)) { host_arg = params->value; } - - // Strip out Pacemaker-implemented parameters - if (!pcmk__starts_with(params->key, "pcmk_") - && strcmp(params->key, PCMK_STONITH_PROVIDES) - && strcmp(params->key, PCMK_STONITH_STONITH_TIMEOUT)) { + if (!pcmk_stonith_param(params->key)) { g_hash_table_insert(params_table, strdup(params->key), strdup(params->value)); }