pacemaker 3.0.1-16e74fc4da
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
agents.c
Go to the documentation of this file.
1/*
2 * Copyright 2004-2024 the Pacemaker project contributors
3 *
4 * The version control history for this file may have further details.
5 *
6 * This source code is licensed under the GNU Lesser General Public License
7 * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8 */
9
10#include <crm_internal.h>
11
12#include <stdio.h>
13#include <string.h>
14#include <strings.h>
15
16#include <crm/crm.h>
17#include <crm/common/util.h>
18
26uint32_t
27pcmk_get_ra_caps(const char *standard)
28{
29 /* @COMPAT This should probably be case-sensitive, but isn't,
30 * for backward compatibility.
31 */
32 if (standard == NULL) {
33 return pcmk_ra_cap_none;
34
35 } else if (!strcasecmp(standard, PCMK_RESOURCE_CLASS_OCF)) {
39
40 } else if (!strcasecmp(standard, PCMK_RESOURCE_CLASS_STONITH)) {
41 /* @COMPAT Stonith resources can't really be unique clones, but we've
42 * allowed it in the past and have it in some scheduler regression tests
43 * (which were likely never used as real configurations).
44 *
45 * @TODO Remove pcmk_ra_cap_unique at the next major schema version
46 * bump, with a transform to remove PCMK_META_GLOBALLY_UNIQUE from the
47 * config.
48 */
51
52 } else if (!strcasecmp(standard, PCMK_RESOURCE_CLASS_LSB)) {
54
55 } else if (!strcasecmp(standard, PCMK_RESOURCE_CLASS_SYSTEMD)
56 || !strcasecmp(standard, PCMK_RESOURCE_CLASS_SERVICE)) {
57 return pcmk_ra_cap_status;
58 }
59 return pcmk_ra_cap_none;
60}
61
62int
64{
65 int remapped_rc = rc;
66
67 switch (rc) {
69 remapped_rc = PCMK_OCF_OK;
70 break;
71
73 remapped_rc = PCMK_OCF_RUNNING_PROMOTED;
74 break;
75
76 default:
77 break;
78 }
79
80 return remapped_rc;
81}
82
83char *
84crm_generate_ra_key(const char *standard, const char *provider,
85 const char *type)
86{
87 bool std_empty = pcmk__str_empty(standard);
88 bool prov_empty = pcmk__str_empty(provider);
89 bool ty_empty = pcmk__str_empty(type);
90
91 if (std_empty || ty_empty) {
92 return NULL;
93 }
94
95 return crm_strdup_printf("%s%s%s:%s",
96 standard,
97 (prov_empty ? "" : ":"), (prov_empty ? "" : provider),
98 type);
99}
100
115int
116crm_parse_agent_spec(const char *spec, char **standard, char **provider,
117 char **type)
118{
119 char *colon;
120
121 CRM_CHECK(spec && standard && provider && type, return -EINVAL);
122 *standard = NULL;
123 *provider = NULL;
124 *type = NULL;
125
126 colon = strchr(spec, ':');
127 if ((colon == NULL) || (colon == spec)) {
128 return -EINVAL;
129 }
130
131 *standard = strndup(spec, colon - spec);
132 spec = colon + 1;
133
135 colon = strchr(spec, ':');
136 if ((colon == NULL) || (colon == spec)) {
137 free(*standard);
138 return -EINVAL;
139 }
140 *provider = strndup(spec, colon - spec);
141 spec = colon + 1;
142 }
143
144 if (*spec == '\0') {
145 free(*standard);
146 free(*provider);
147 return -EINVAL;
148 }
149
150 *type = strdup(spec);
151 return pcmk_ok;
152}
153
165bool
166pcmk_stonith_param(const char *param)
167{
168 if (param == NULL) {
169 return false;
170 }
173 return true;
174 }
175 if (!pcmk__starts_with(param, "pcmk_")) { // Short-circuit common case
176 return false;
177 }
178 if (pcmk__str_any_of(param,
186 NULL)) {
187 return true;
188 }
189 param = strchr(param + 5, '_'); // Skip past "pcmk_ACTION"
190 return pcmk__str_any_of(param, "_action", "_timeout", "_retries", NULL);
191}
int crm_parse_agent_spec(const char *spec, char **standard, char **provider, char **type)
Parse a "standard[:provider]:type" agent specification.
Definition agents.c:116
uint32_t pcmk_get_ra_caps(const char *standard)
Get capabilities of a resource agent standard.
Definition agents.c:27
bool pcmk_stonith_param(const char *param)
Check whether a given stonith parameter is handled by Pacemaker.
Definition agents.c:166
int pcmk__effective_rc(int rc)
Definition agents.c:63
char * crm_generate_ra_key(const char *standard, const char *provider, const char *type)
Definition agents.c:84
#define PCMK_RESOURCE_CLASS_SYSTEMD
Definition agents.h:30
#define PCMK_STONITH_HOST_LIST
Definition agents.h:42
#define PCMK_STONITH_STONITH_TIMEOUT
Definition agents.h:45
#define PCMK_STONITH_HOST_ARGUMENT
Definition agents.h:40
#define PCMK_RESOURCE_CLASS_SERVICE
Definition agents.h:28
#define PCMK_RESOURCE_CLASS_STONITH
Definition agents.h:31
#define PCMK_STONITH_HOST_MAP
Definition agents.h:43
#define PCMK_RESOURCE_CLASS_OCF
Definition agents.h:27
@ pcmk_ra_cap_status
Definition agents.h:56
@ pcmk_ra_cap_cli_exec
Definition agents.h:62
@ pcmk_ra_cap_none
Definition agents.h:54
@ pcmk_ra_cap_unique
Definition agents.h:58
@ pcmk_ra_cap_params
Definition agents.h:57
@ pcmk_ra_cap_promotable
Definition agents.h:59
@ pcmk_ra_cap_provider
Definition agents.h:55
@ pcmk_ra_cap_fence_params
Definition agents.h:61
@ pcmk_ra_cap_stdin
Definition agents.h:60
#define PCMK_STONITH_DELAY_BASE
Definition agents.h:38
#define PCMK_STONITH_ACTION_LIMIT
Definition agents.h:37
#define PCMK_STONITH_HOST_CHECK
Definition agents.h:41
#define PCMK_STONITH_PROVIDES
Definition agents.h:44
#define PCMK_STONITH_DELAY_MAX
Definition agents.h:39
#define PCMK_RESOURCE_CLASS_LSB
Definition agents.h:29
Utility functions.
#define pcmk_is_set(g, f)
Convenience alias for pcmk_all_flags_set(), to check single flag.
Definition util.h:80
enum pcmk_ipc_server type
Definition cpg.c:3
A dumping ground.
#define CRM_CHECK(expr, failure_action)
Definition logging.h:213
@ PCMK_OCF_RUNNING_PROMOTED
Service active and promoted.
Definition results.h:188
@ PCMK_OCF_DEGRADED_PROMOTED
Service promoted but more likely to fail soon.
Definition results.h:191
@ PCMK_OCF_DEGRADED
Service active but more likely to fail soon.
Definition results.h:190
@ PCMK_OCF_OK
Success.
Definition results.h:174
#define pcmk_ok
Definition results.h:65
API for strings.
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
bool pcmk__starts_with(const char *str, const char *prefix)
Check whether a string starts with a certain sequence.
Definition strings.c:558
bool pcmk__str_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
Definition strings.c:1053