diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 07:45:40 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 07:45:40 +0000 |
commit | 07d7f4cfa4b10de87a31b68191036ff446add675 (patch) | |
tree | 7162524d8aaf1aef62d2f4fa51f595ed113981ff /tools/crm_resource_ban.c | |
parent | Adding upstream version 2.1.6. (diff) | |
download | pacemaker-07d7f4cfa4b10de87a31b68191036ff446add675.tar.xz pacemaker-07d7f4cfa4b10de87a31b68191036ff446add675.zip |
Adding upstream version 2.1.7.upstream/2.1.7
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tools/crm_resource_ban.c')
-rw-r--r-- | tools/crm_resource_ban.c | 75 |
1 files changed, 35 insertions, 40 deletions
diff --git a/tools/crm_resource_ban.c b/tools/crm_resource_ban.c index b1edac8..3b0e4a1 100644 --- a/tools/crm_resource_ban.c +++ b/tools/crm_resource_ban.c @@ -1,5 +1,5 @@ /* - * Copyright 2004-2021 the Pacemaker project contributors + * Copyright 2004-2023 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -56,42 +56,17 @@ parse_cli_lifetime(pcmk__output_t *out, const char *move_lifetime) return later_s; } -static const char * -promoted_role_name(void) -{ - /* This is a judgment call for what string to use. @TODO Ideally we'd - * use the legacy string if the DC only supports that, and the new one - * otherwise. Basing it on --enable-compat-2.0 is a decent guess. - */ -#ifdef PCMK__COMPAT_2_0 - return RSC_ROLE_PROMOTED_LEGACY_S; -#else - return RSC_ROLE_PROMOTED_S; -#endif -} - // \return Standard Pacemaker return code int cli_resource_ban(pcmk__output_t *out, const char *rsc_id, const char *host, - const char *move_lifetime, GList *allnodes, cib_t * cib_conn, - int cib_options, gboolean promoted_role_only) + const char *move_lifetime, cib_t * cib_conn, int cib_options, + gboolean promoted_role_only, const char *promoted_role) { char *later_s = NULL; int rc = pcmk_rc_ok; xmlNode *fragment = NULL; xmlNode *location = NULL; - if(host == NULL) { - GList *n = allnodes; - for(; n && rc == pcmk_rc_ok; n = n->next) { - pe_node_t *target = n->data; - - rc = cli_resource_ban(out, rsc_id, target->details->uname, move_lifetime, - NULL, cib_conn, cib_options, promoted_role_only); - } - return rc; - } - later_s = parse_cli_lifetime(out, move_lifetime); if(move_lifetime && later_s == NULL) { return EINVAL; @@ -114,9 +89,9 @@ cli_resource_ban(pcmk__output_t *out, const char *rsc_id, const char *host, crm_xml_add(location, XML_LOC_ATTR_SOURCE, rsc_id); if(promoted_role_only) { - crm_xml_add(location, XML_RULE_ATTR_ROLE, promoted_role_name()); + crm_xml_add(location, XML_RULE_ATTR_ROLE, promoted_role); } else { - crm_xml_add(location, XML_RULE_ATTR_ROLE, RSC_ROLE_STARTED_S); + crm_xml_add(location, XML_RULE_ATTR_ROLE, PCMK__ROLE_STARTED); } if (later_s == NULL) { @@ -151,14 +126,24 @@ cli_resource_ban(pcmk__output_t *out, const char *rsc_id, const char *host, free_xml(fragment); free(later_s); + + if (rc != pcmk_rc_ok && promoted_role_only && strcmp(promoted_role, PCMK__ROLE_PROMOTED) == 0) { + int banrc = cli_resource_ban(out, rsc_id, host, move_lifetime, + cib_conn, cib_options, promoted_role_only, + PCMK__ROLE_PROMOTED_LEGACY); + if (banrc == pcmk_rc_ok) { + rc = banrc; + } + } + return rc; } // \return Standard Pacemaker return code int cli_resource_prefer(pcmk__output_t *out,const char *rsc_id, const char *host, - const char *move_lifetime, cib_t * cib_conn, int cib_options, - gboolean promoted_role_only) + const char *move_lifetime, cib_t *cib_conn, int cib_options, + gboolean promoted_role_only, const char *promoted_role) { char *later_s = parse_cli_lifetime(out, move_lifetime); int rc = pcmk_rc_ok; @@ -181,9 +166,9 @@ cli_resource_prefer(pcmk__output_t *out,const char *rsc_id, const char *host, crm_xml_add(location, XML_LOC_ATTR_SOURCE, rsc_id); if(promoted_role_only) { - crm_xml_add(location, XML_RULE_ATTR_ROLE, promoted_role_name()); + crm_xml_add(location, XML_RULE_ATTR_ROLE, promoted_role); } else { - crm_xml_add(location, XML_RULE_ATTR_ROLE, RSC_ROLE_STARTED_S); + crm_xml_add(location, XML_RULE_ATTR_ROLE, PCMK__ROLE_STARTED); } if (later_s == NULL) { @@ -218,6 +203,16 @@ cli_resource_prefer(pcmk__output_t *out,const char *rsc_id, const char *host, free_xml(fragment); free(later_s); + + if (rc != pcmk_rc_ok && promoted_role_only && strcmp(promoted_role, PCMK__ROLE_PROMOTED) == 0) { + int preferrc = cli_resource_prefer(out, rsc_id, host, move_lifetime, + cib_conn, cib_options, promoted_role_only, + PCMK__ROLE_PROMOTED_LEGACY); + if (preferrc == pcmk_rc_ok) { + rc = preferrc; + } + } + return rc; } @@ -335,7 +330,7 @@ cli_resource_clear(const char *rsc_id, const char *host, GList *allnodes, cib_t * On the first error, abort. */ for(; n; n = n->next) { - pe_node_t *target = n->data; + pcmk_node_t *target = n->data; rc = cli_resource_clear(rsc_id, target->details->uname, NULL, cib_conn, cib_options, clear_ban_constraints, @@ -358,6 +353,9 @@ build_clear_xpath_string(GString *buf, const xmlNode *constraint_node, const char *cons_rsc = crm_element_value(constraint_node, XML_LOC_ATTR_SOURCE); GString *rsc_role_substr = NULL; + const char *promoted_role_rule = "@" XML_RULE_ATTR_ROLE "='" PCMK__ROLE_PROMOTED + "' or @" XML_RULE_ATTR_ROLE "='" + PCMK__ROLE_PROMOTED_LEGACY "'"; CRM_ASSERT(buf != NULL); g_string_truncate(buf, 0); @@ -384,8 +382,7 @@ build_clear_xpath_string(GString *buf, const xmlNode *constraint_node, rsc_role_substr = g_string_sized_new(64); pcmk__g_strcat(rsc_role_substr, "@" XML_LOC_ATTR_SOURCE "='", rsc, "' " - "and @" XML_RULE_ATTR_ROLE "='", - promoted_role_name(), "'", NULL); + "and (" , promoted_role_rule, ")", NULL); } else if (rsc != NULL) { rsc_role_substr = g_string_sized_new(64); @@ -394,9 +391,7 @@ build_clear_xpath_string(GString *buf, const xmlNode *constraint_node, } else if (promoted_role_only) { rsc_role_substr = g_string_sized_new(64); - pcmk__g_strcat(rsc_role_substr, - "@" XML_RULE_ATTR_ROLE "='", promoted_role_name(), - "'", NULL); + g_string_append(rsc_role_substr, promoted_role_rule); } if (rsc_role_substr != NULL) { |