pacemaker  2.1.9-49aab99839
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->fillers; gIter != NULL; gIter = gIter->next) {
36  pcmk_resource_t *filler = gIter->data;
37 
38  if (filler->is_remote_node) {
39  return filler;
40  }
41  }
42  }
43  return NULL;
44 }
45 
46 bool
48 {
49  const char *value = NULL;
50 
51  if (xml == NULL) {
52  return false;
53  }
54 
55  value = crm_element_value(xml, PCMK_XA_TYPE);
56  if (!pcmk__str_eq(value, "remote", pcmk__str_casei)) {
57  return false;
58  }
59 
60  value = crm_element_value(xml, PCMK_XA_CLASS);
61  if (!pcmk__str_eq(value, PCMK_RESOURCE_CLASS_OCF, pcmk__str_casei)) {
62  return false;
63  }
64 
65  value = crm_element_value(xml, PCMK_XA_PROVIDER);
66  if (!pcmk__str_eq(value, "pacemaker", pcmk__str_casei)) {
67  return false;
68  }
69 
70  return true;
71 }
72 
82 void
84  const pcmk_node_t *host,
85  void (*helper)(const pcmk_node_t*, void*),
86  void *user_data)
87 {
88  GList *iter;
89 
90  CRM_CHECK(scheduler && host && host->details && helper, return);
92  return;
93  }
94  for (iter = host->details->running_rsc; iter != NULL; iter = iter->next) {
95  pcmk_resource_t *rsc = (pcmk_resource_t *) iter->data;
96 
97  if (rsc->is_remote_node && (rsc->container != NULL)) {
98  pcmk_node_t *guest_node = pcmk_find_node(scheduler, rsc->id);
99 
100  if (guest_node) {
101  (*helper)(guest_node, user_data);
102  }
103  }
104  }
105 }
106 
124 xmlNode *
125 pe_create_remote_xml(xmlNode *parent, const char *uname,
126  const char *container_id, const char *migrateable,
127  const char *is_managed, const char *start_timeout,
128  const char *server, const char *port)
129 {
130  xmlNode *remote;
131  xmlNode *xml_sub;
132 
134 
135  // Add identity
136  crm_xml_add(remote, PCMK_XA_ID, uname);
138  crm_xml_add(remote, PCMK_XA_PROVIDER, "pacemaker");
139  crm_xml_add(remote, PCMK_XA_TYPE, "remote");
140 
141  // Add meta-attributes
142  xml_sub = pcmk__xe_create(remote, PCMK_XE_META_ATTRIBUTES);
143  crm_xml_set_id(xml_sub, "%s-%s", uname, PCMK_XE_META_ATTRIBUTES);
144  crm_create_nvpair_xml(xml_sub, NULL,
146  if (container_id) {
147  crm_create_nvpair_xml(xml_sub, NULL,
148  PCMK__META_CONTAINER, container_id);
149  }
150  if (migrateable) {
151  crm_create_nvpair_xml(xml_sub, NULL,
152  PCMK_META_ALLOW_MIGRATE, migrateable);
153  }
154  if (is_managed) {
155  crm_create_nvpair_xml(xml_sub, NULL, PCMK_META_IS_MANAGED, is_managed);
156  }
157 
158  // Add instance attributes
159  if (port || server) {
160  xml_sub = pcmk__xe_create(remote, PCMK_XE_INSTANCE_ATTRIBUTES);
162  if (server) {
163  crm_create_nvpair_xml(xml_sub, NULL, PCMK_REMOTE_RA_ADDR, server);
164  }
165  if (port) {
166  crm_create_nvpair_xml(xml_sub, NULL, PCMK_REMOTE_RA_PORT, port);
167  }
168  }
169 
170  // Add operations
171  xml_sub = pcmk__xe_create(remote, PCMK_XE_OPERATIONS);
172  crm_create_op_xml(xml_sub, uname, PCMK_ACTION_MONITOR, "30s", "30s");
173  if (start_timeout) {
175  start_timeout);
176  }
177  return remote;
178 }
179 
180 // History entry to be checked for fail count clearing
181 struct check_op {
182  const xmlNode *rsc_op; // History entry XML
183  pcmk_resource_t *rsc; // Known resource corresponding to history entry
184  pcmk_node_t *node; // Known node corresponding to history entry
185  enum pcmk__check_parameters check_type; // What needs checking
186 };
187 
188 void
189 pe__add_param_check(const xmlNode *rsc_op, pcmk_resource_t *rsc,
190  pcmk_node_t *node, enum pcmk__check_parameters flag,
192 {
193  struct check_op *check_op = NULL;
194 
195  CRM_CHECK(scheduler && rsc_op && rsc && node, return);
196 
197  check_op = pcmk__assert_alloc(1, sizeof(struct check_op));
198 
199  crm_trace("Deferring checks of %s until after allocation",
200  pcmk__xe_id(rsc_op));
201  check_op->rsc_op = rsc_op;
202  check_op->rsc = rsc;
203  check_op->node = node;
204  check_op->check_type = flag;
205  scheduler->param_check = g_list_prepend(scheduler->param_check, check_op);
206 }
207 
215 void
217  void (*cb)(pcmk_resource_t*, pcmk_node_t*,
218  const xmlNode*, enum pcmk__check_parameters))
219 {
220  CRM_CHECK(scheduler && cb, return);
221 
222  for (GList *item = scheduler->param_check;
223  item != NULL; item = item->next) {
224  struct check_op *check_op = item->data;
225 
226  cb(check_op->rsc, check_op->node, check_op->rsc_op,
227  check_op->check_type);
228  }
229 }
230 
231 void
233 {
234  if (scheduler && scheduler->param_check) {
235  g_list_free_full(scheduler->param_check, free);
236  scheduler->param_check = NULL;
237  }
238 }
pcmk__cpg_host_t host
Definition: cpg.c:52
#define CRM_CHECK(expr, failure_action)
Definition: logging.h:245
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:103
#define PCMK_XE_PRIMITIVE
Definition: xml_names.h:164
#define PCMK_ACTION_MONITOR
Definition: actions.h:60
#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:47
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
Definition: nvpair.c:313
#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
#define PCMK_RESOURCE_CLASS_OCF
Definition: agents.h:27
pcmk_resource_t * container
Definition: resources.h:476
#define PCMK_XA_TYPE
Definition: xml_names.h:430
#define PCMK_META_IS_MANAGED
Definition: options.h:92
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:216
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
Definition: nvpair.c:458
#define crm_trace(fmt, args...)
Definition: logging.h:404
#define pcmk_is_set(g, f)
Convenience alias for pcmk_all_flags_set(), to check single flag.
Definition: util.h:94
void crm_xml_set_id(xmlNode *xml, const char *format,...) G_GNUC_PRINTF(2
void pe__free_param_checks(pcmk_scheduler_t *scheduler)
Definition: remote.c:232
#define PCMK_ACTION_START
Definition: actions.h:72
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:189
#define PCMK_VALUE_TRUE
Definition: options.h:215
#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
GList * fillers
Definition: resources.h:477
pcmk__check_parameters
#define PCMK_XA_CLASS
Definition: xml_names.h:246
gboolean is_remote_node
Definition: resources.h:431
pcmk_scheduler_t * scheduler
GList * param_check
Definition: scheduler.h:256
char uname[MAX_NAME]
Definition: cpg.c:53
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:83
#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:520
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:883
unsigned long long flags
Definition: scheduler.h:211
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:125
xmlNode * pcmk__xe_create(xmlNode *parent, const char *name)
Definition: xml.c:770
#define pcmk__assert_alloc(nmemb, size)
Definition: internal.h:297
#define PCMK_XE_INSTANCE_ATTRIBUTES
Definition: xml_names.h:122
#define PCMK_META_ALLOW_MIGRATE
Definition: options.h:80