pacemaker  3.0.0-d8340737c4
Scalable High-Availability cluster resource manager
remote.c
Go to the documentation of this file.
1 /*
2  * Copyright 2013-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 #include <crm/common/xml.h>
13 #include <crm/pengine/internal.h>
14 #include <glib.h>
15 
30  const pcmk_resource_t *rsc)
31 {
32  if ((rsc != NULL) && (scheduler != NULL)
34 
35  for (GList *gIter = rsc->priv->launched;
36  gIter != NULL; gIter = gIter->next) {
37 
38  pcmk_resource_t *launched = gIter->data;
39 
41  return launched;
42  }
43  }
44  }
45  return NULL;
46 }
47 
48 bool
50 {
51  const char *value = NULL;
52 
53  if (xml == NULL) {
54  return false;
55  }
56 
57  value = crm_element_value(xml, PCMK_XA_TYPE);
58  if (!pcmk__str_eq(value, "remote", pcmk__str_casei)) {
59  return false;
60  }
61 
62  value = crm_element_value(xml, PCMK_XA_CLASS);
63  if (!pcmk__str_eq(value, PCMK_RESOURCE_CLASS_OCF, pcmk__str_casei)) {
64  return false;
65  }
66 
67  value = crm_element_value(xml, PCMK_XA_PROVIDER);
68  if (!pcmk__str_eq(value, "pacemaker", pcmk__str_casei)) {
69  return false;
70  }
71 
72  return true;
73 }
74 
84 void
86  const pcmk_node_t *host,
87  void (*helper)(const pcmk_node_t*, void*),
88  void *user_data)
89 {
90  GList *iter;
91 
92  CRM_CHECK(scheduler && host && host->details && helper, return);
94  return;
95  }
96  for (iter = host->details->running_rsc; iter != NULL; iter = iter->next) {
97  pcmk_resource_t *rsc = (pcmk_resource_t *) iter->data;
98 
100  && (rsc->priv->launcher != NULL)) {
101  pcmk_node_t *guest_node = pcmk_find_node(scheduler, rsc->id);
102 
103  if (guest_node) {
104  (*helper)(guest_node, user_data);
105  }
106  }
107  }
108 }
109 
127 xmlNode *
128 pe_create_remote_xml(xmlNode *parent, const char *uname,
129  const char *container_id, const char *migrateable,
130  const char *is_managed, const char *start_timeout,
131  const char *server, const char *port)
132 {
133  xmlNode *remote;
134  xmlNode *xml_sub;
135 
137 
138  // Add identity
139  crm_xml_add(remote, PCMK_XA_ID, uname);
141  crm_xml_add(remote, PCMK_XA_PROVIDER, "pacemaker");
142  crm_xml_add(remote, PCMK_XA_TYPE, "remote");
143 
144  // Add meta-attributes
145  xml_sub = pcmk__xe_create(remote, PCMK_XE_META_ATTRIBUTES);
146  pcmk__xe_set_id(xml_sub, "%s-%s", uname, PCMK_XE_META_ATTRIBUTES);
147  crm_create_nvpair_xml(xml_sub, NULL,
149  if (container_id) {
150  crm_create_nvpair_xml(xml_sub, NULL,
151  PCMK__META_CONTAINER, container_id);
152  }
153  if (migrateable) {
154  crm_create_nvpair_xml(xml_sub, NULL,
155  PCMK_META_ALLOW_MIGRATE, migrateable);
156  }
157  if (is_managed) {
158  crm_create_nvpair_xml(xml_sub, NULL, PCMK_META_IS_MANAGED, is_managed);
159  }
160 
161  // Add instance attributes
162  if (port || server) {
163  xml_sub = pcmk__xe_create(remote, PCMK_XE_INSTANCE_ATTRIBUTES);
165  if (server) {
166  crm_create_nvpair_xml(xml_sub, NULL, PCMK_REMOTE_RA_ADDR, server);
167  }
168  if (port) {
169  crm_create_nvpair_xml(xml_sub, NULL, PCMK_REMOTE_RA_PORT, port);
170  }
171  }
172 
173  // Add operations
174  xml_sub = pcmk__xe_create(remote, PCMK_XE_OPERATIONS);
175  crm_create_op_xml(xml_sub, uname, PCMK_ACTION_MONITOR, "30s", "30s");
176  if (start_timeout) {
178  start_timeout);
179  }
180  return remote;
181 }
182 
183 // History entry to be checked for fail count clearing
184 struct check_op {
185  const xmlNode *rsc_op; // History entry XML
186  pcmk_resource_t *rsc; // Known resource corresponding to history entry
187  pcmk_node_t *node; // Known node corresponding to history entry
188  enum pcmk__check_parameters check_type; // What needs checking
189 };
190 
191 void
192 pe__add_param_check(const xmlNode *rsc_op, pcmk_resource_t *rsc,
193  pcmk_node_t *node, enum pcmk__check_parameters flag,
195 {
196  struct check_op *check_op = NULL;
197 
198  CRM_CHECK(scheduler && rsc_op && rsc && node, return);
199 
200  check_op = pcmk__assert_alloc(1, sizeof(struct check_op));
201 
202  crm_trace("Deferring checks of %s until after allocation",
203  pcmk__xe_id(rsc_op));
204  check_op->rsc_op = rsc_op;
205  check_op->rsc = rsc;
206  check_op->node = node;
207  check_op->check_type = flag;
208  scheduler->priv->param_check = g_list_prepend(scheduler->priv->param_check,
209  check_op);
210 }
211 
219 void
221  void (*cb)(pcmk_resource_t*, pcmk_node_t*,
222  const xmlNode*, enum pcmk__check_parameters))
223 {
224  CRM_CHECK(scheduler && cb, return);
225 
226  for (GList *item = scheduler->priv->param_check;
227  item != NULL; item = item->next) {
228  struct check_op *check_op = item->data;
229 
230  cb(check_op->rsc, check_op->node, check_op->rsc_op,
231  check_op->check_type);
232  }
233 }
234 
235 void
237 {
238  if ((scheduler != NULL) && (scheduler->priv->param_check != NULL)) {
239  g_list_free_full(scheduler->priv->param_check, free);
240  scheduler->priv->param_check = NULL;
241  }
242 }
pcmk__cpg_host_t host
Definition: cpg.c:52
#define CRM_CHECK(expr, failure_action)
Definition: logging.h:213
pcmk_node_t * pcmk_find_node(const pcmk_scheduler_t *scheduler, const char *node_name)
Find a node by name in scheduler data.
Definition: scheduler.c:100
#define PCMK_XE_PRIMITIVE
Definition: xml_names.h:164
#define PCMK_ACTION_MONITOR
Definition: actions.h:51
#define PCMK_REMOTE_RA_ADDR
Definition: options.h:122
#define PCMK_REMOTE_RA_PORT
Definition: options.h:123
bool xml_contains_remote_node(xmlNode *xml)
Definition: remote.c:49
pcmk__scheduler_private_t * priv
Definition: scheduler.h:99
#define PCMK_XA_PROVIDER
Definition: xml_names.h:364
pcmk_resource_t * pe__resource_contains_guest_node(const pcmk_scheduler_t *scheduler, const pcmk_resource_t *rsc)
Definition: remote.c:29
uint64_t flags
Definition: scheduler.h:89
#define PCMK_RESOURCE_CLASS_OCF
Definition: agents.h:27
#define PCMK_XA_TYPE
Definition: xml_names.h:430
xmlNode * pcmk__xe_create(xmlNode *parent, const char *name)
Definition: xml_element.c:407
#define PCMK_META_IS_MANAGED
Definition: options.h:92
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
Definition: xml_element.c:1015
void pe__foreach_param_check(pcmk_scheduler_t *scheduler, void(*cb)(pcmk_resource_t *, pcmk_node_t *, const xmlNode *, enum pcmk__check_parameters))
Definition: remote.c:220
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
Definition: xml_element.c:1168
#define crm_trace(fmt, args...)
Definition: logging.h:372
#define pcmk_is_set(g, f)
Convenience alias for pcmk_all_flags_set(), to check single flag.
Definition: util.h:80
void pe__free_param_checks(pcmk_scheduler_t *scheduler)
Definition: remote.c:236
#define PCMK_ACTION_START
Definition: actions.h:63
pcmk__resource_private_t * priv
Definition: resources.h:61
Wrappers for and extensions to libxml2.
void pe__add_param_check(const xmlNode *rsc_op, pcmk_resource_t *rsc, pcmk_node_t *node, enum pcmk__check_parameters flag, pcmk_scheduler_t *scheduler)
Definition: remote.c:192
#define PCMK_VALUE_TRUE
Definition: options.h:218
#define PCMK_XA_ID
Definition: xml_names.h:301
#define PCMK_XE_OPERATIONS
Definition: xml_names.h:151
#define PCMK_XE_META_ATTRIBUTES
Definition: xml_names.h:130
pcmk__check_parameters
#define PCMK_XA_CLASS
Definition: xml_names.h:246
pcmk_scheduler_t * scheduler
pcmk_resource_t * launcher
char uname[MAX_NAME]
Definition: cpg.c:53
void pcmk__xe_set_id(xmlNode *xml, const char *format,...) G_GNUC_PRINTF(2
unsigned long long flags
Definition: resources.h:69
void pe_foreach_guest_node(const pcmk_scheduler_t *scheduler, const pcmk_node_t *host, void(*helper)(const pcmk_node_t *, void *), void *user_data)
Definition: remote.c:85
#define PCMK__META_INTERNAL_RSC
#define PCMK__META_CONTAINER
xmlNode * crm_create_op_xml(xmlNode *parent, const char *prefix, const char *task, const char *interval_spec, const char *timeout)
Create a CIB XML element for an operation.
Definition: actions.c:519
xmlNode * crm_create_nvpair_xml(xmlNode *parent, const char *id, const char *name, const char *value)
Create an XML name/value pair.
Definition: nvpair.c:312
const char * parent
Definition: cib.c:27
xmlNode * pe_create_remote_xml(xmlNode *parent, const char *uname, const char *container_id, const char *migrateable, const char *is_managed, const char *start_timeout, const char *server, const char *port)
Definition: remote.c:128
#define pcmk__assert_alloc(nmemb, size)
Definition: internal.h:257
#define PCMK_XE_INSTANCE_ATTRIBUTES
Definition: xml_names.h:122
#define PCMK_META_ALLOW_MIGRATE
Definition: options.h:80