pacemaker  2.1.8-3980678f03
Scalable High-Availability cluster resource manager
agents.c
Go to the documentation of this file.
1 /*
2  * Copyright 2004-2021 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 #ifndef _GNU_SOURCE
13 # define _GNU_SOURCE
14 #endif
15 
16 #include <stdio.h>
17 #include <string.h>
18 #include <strings.h>
19 
20 #include <crm/crm.h>
21 #include <crm/common/util.h>
22 
30 uint32_t
31 pcmk_get_ra_caps(const char *standard)
32 {
33  /* @COMPAT This should probably be case-sensitive, but isn't,
34  * for backward compatibility.
35  */
36  if (standard == NULL) {
37  return pcmk_ra_cap_none;
38 
39  } else if (!strcasecmp(standard, PCMK_RESOURCE_CLASS_OCF)) {
42 
43  } else if (!strcasecmp(standard, PCMK_RESOURCE_CLASS_STONITH)) {
44  /* @COMPAT Stonith resources can't really be unique clones, but we've
45  * allowed it in the past and have it in some scheduler regression tests
46  * (which were likely never used as real configurations).
47  *
48  * @TODO Remove pcmk_ra_cap_unique at the next major schema version
49  * bump, with a transform to remove PCMK_META_GLOBALLY_UNIQUE from the
50  * config.
51  */
54 
55  } else if (!strcasecmp(standard, PCMK_RESOURCE_CLASS_SYSTEMD)
56  || !strcasecmp(standard, PCMK_RESOURCE_CLASS_SERVICE)
57  || !strcasecmp(standard, PCMK_RESOURCE_CLASS_LSB)
58  || !strcasecmp(standard, PCMK_RESOURCE_CLASS_UPSTART)) {
59 
60  /* Since service can map to LSB, systemd, or upstart, these should
61  * have identical capabilities
62  */
63  return pcmk_ra_cap_status;
64 
65  } else if (!strcasecmp(standard, PCMK_RESOURCE_CLASS_NAGIOS)) {
66  return pcmk_ra_cap_params;
67  }
68  return pcmk_ra_cap_none;
69 }
70 
71 int
73 {
74  int remapped_rc = rc;
75 
76  switch (rc) {
77  case PCMK_OCF_DEGRADED:
78  remapped_rc = PCMK_OCF_OK;
79  break;
80 
82  remapped_rc = PCMK_OCF_RUNNING_PROMOTED;
83  break;
84 
85  default:
86  break;
87  }
88 
89  return remapped_rc;
90 }
91 
92 char *
93 crm_generate_ra_key(const char *standard, const char *provider,
94  const char *type)
95 {
96  bool std_empty = pcmk__str_empty(standard);
97  bool prov_empty = pcmk__str_empty(provider);
98  bool ty_empty = pcmk__str_empty(type);
99 
100  if (std_empty || ty_empty) {
101  return NULL;
102  }
103 
104  return crm_strdup_printf("%s%s%s:%s",
105  standard,
106  (prov_empty ? "" : ":"), (prov_empty ? "" : provider),
107  type);
108 }
109 
124 int
125 crm_parse_agent_spec(const char *spec, char **standard, char **provider,
126  char **type)
127 {
128  char *colon;
129 
130  CRM_CHECK(spec && standard && provider && type, return -EINVAL);
131  *standard = NULL;
132  *provider = NULL;
133  *type = NULL;
134 
135  colon = strchr(spec, ':');
136  if ((colon == NULL) || (colon == spec)) {
137  return -EINVAL;
138  }
139 
140  *standard = strndup(spec, colon - spec);
141  spec = colon + 1;
142 
144  colon = strchr(spec, ':');
145  if ((colon == NULL) || (colon == spec)) {
146  free(*standard);
147  return -EINVAL;
148  }
149  *provider = strndup(spec, colon - spec);
150  spec = colon + 1;
151  }
152 
153  if (*spec == '\0') {
154  free(*standard);
155  free(*provider);
156  return -EINVAL;
157  }
158 
159  *type = strdup(spec);
160  return pcmk_ok;
161 }
162 
174 bool
175 pcmk_stonith_param(const char *param)
176 {
177  if (param == NULL) {
178  return false;
179  }
182  return true;
183  }
184  if (!pcmk__starts_with(param, "pcmk_")) { // Short-circuit common case
185  return false;
186  }
187  if (pcmk__str_any_of(param,
195  NULL)) {
196  return true;
197  }
198  param = strchr(param + 5, '_'); // Skip past "pcmk_ACTION"
199  return pcmk__str_any_of(param, "_action", "_timeout", "_retries", NULL);
200 }
201 
202 // Deprecated functions kept only for backward API compatibility
203 // LCOV_EXCL_START
204 
206 
207 bool
208 crm_provider_required(const char *standard)
209 {
211 }
212 
213 // LCOV_EXCL_STOP
214 // End deprecated API
#define CRM_CHECK(expr, failure_action)
Definition: logging.h:245
A dumping ground.
Service active and promoted.
Definition: results.h:192
#define PCMK_STONITH_HOST_CHECK
Definition: agents.h:45
#define PCMK_RESOURCE_CLASS_SERVICE
Definition: agents.h:28
#define PCMK_STONITH_PROVIDES
Definition: agents.h:48
#define PCMK_STONITH_HOST_MAP
Definition: agents.h:47
#define PCMK_RESOURCE_CLASS_OCF
Definition: agents.h:27
#define PCMK_STONITH_STONITH_TIMEOUT
Definition: agents.h:49
Service promoted but more likely to fail soon.
Definition: results.h:195
#define PCMK_RESOURCE_CLASS_SYSTEMD
Definition: agents.h:30
#define PCMK_STONITH_HOST_LIST
Definition: agents.h:46
enum crm_ais_msg_types type
Definition: cpg.c:51
bool pcmk_stonith_param(const char *param)
Check whether a given stonith parameter is handled by Pacemaker.
Definition: agents.c:175
#define PCMK_RESOURCE_CLASS_UPSTART
Definition: agents.h:36
Utility functions.
#define PCMK_RESOURCE_CLASS_STONITH
Definition: agents.h:31
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
#define pcmk_is_set(g, f)
Convenience alias for pcmk_all_flags_set(), to check single flag.
Definition: util.h:98
bool pcmk__str_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
Definition: strings.c:1050
#define PCMK_STONITH_ACTION_LIMIT
Definition: agents.h:41
int crm_parse_agent_spec(const char *spec, char **standard, char **provider, char **type)
Parse a "standard[:provider]:type" agent specification.
Definition: agents.c:125
Deprecated Pacemaker resource agent API.
uint32_t pcmk_get_ra_caps(const char *standard)
Get capabilities of a resource agent standard.
Definition: agents.c:31
bool crm_provider_required(const char *standard)
Definition: agents.c:208
#define PCMK_STONITH_HOST_ARGUMENT
Definition: agents.h:44
Service active but more likely to fail soon.
Definition: results.h:194
Success.
Definition: results.h:178
#define PCMK_RESOURCE_CLASS_LSB
Definition: agents.h:29
#define PCMK_STONITH_DELAY_BASE
Definition: agents.h:42
#define pcmk_ok
Definition: results.h:69
bool pcmk__starts_with(const char *str, const char *prefix)
Check whether a string starts with a certain sequence.
Definition: strings.c:556
char * crm_generate_ra_key(const char *standard, const char *provider, const char *type)
Definition: agents.c:93
#define PCMK_RESOURCE_CLASS_NAGIOS
Definition: agents.h:34
#define PCMK_STONITH_DELAY_MAX
Definition: agents.h:43
int pcmk__effective_rc(int rc)
Definition: agents.c:72