pacemaker  2.1.7-0f7f88312f
Scalable High-Availability cluster resource manager
remote.c
Go to the documentation of this file.
1 /*
2  * Copyright 2013-2023 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/msg_xml.h>
12 #include <crm/common/xml.h>
14 #include <crm/pengine/internal.h>
15 #include <glib.h>
16 
17 bool
19 {
20  return (rsc != NULL) && rsc->is_remote_node
22 }
23 
24 bool
26 {
27  return (node != NULL) && (node->details->type == pcmk_node_variant_remote)
28  && ((node->details->remote_rsc == NULL)
29  || (node->details->remote_rsc->container == NULL));
30 }
31 
32 bool
34 {
35  return (node != NULL) && (node->details->type == pcmk_node_variant_remote)
36  && (node->details->remote_rsc != NULL)
37  && (node->details->remote_rsc->container != NULL);
38 }
39 
40 bool
42 {
43  return (node != NULL) && (node->details->type == pcmk_node_variant_remote);
44 }
45 
46 bool
48 {
49  return pe__is_guest_node(node)
50  && pe_rsc_is_bundled(node->details->remote_rsc);
51 }
52 
67  const pcmk_resource_t *rsc)
68 {
69  if ((rsc != NULL) && (scheduler != NULL)
71 
72  for (GList *gIter = rsc->fillers; gIter != NULL; gIter = gIter->next) {
73  pcmk_resource_t *filler = gIter->data;
74 
75  if (filler->is_remote_node) {
76  return filler;
77  }
78  }
79  }
80  return NULL;
81 }
82 
83 bool
85 {
86  const char *value = NULL;
87 
88  if (xml == NULL) {
89  return false;
90  }
91 
92  value = crm_element_value(xml, XML_ATTR_TYPE);
93  if (!pcmk__str_eq(value, "remote", pcmk__str_casei)) {
94  return false;
95  }
96 
98  if (!pcmk__str_eq(value, PCMK_RESOURCE_CLASS_OCF, pcmk__str_casei)) {
99  return false;
100  }
101 
103  if (!pcmk__str_eq(value, "pacemaker", pcmk__str_casei)) {
104  return false;
105  }
106 
107  return true;
108 }
109 
119 void
121  const pcmk_node_t *host,
122  void (*helper)(const pcmk_node_t*, void*),
123  void *user_data)
124 {
125  GList *iter;
126 
127  CRM_CHECK(scheduler && host && host->details && helper, return);
129  return;
130  }
131  for (iter = host->details->running_rsc; iter != NULL; iter = iter->next) {
132  pcmk_resource_t *rsc = (pcmk_resource_t *) iter->data;
133 
134  if (rsc->is_remote_node && (rsc->container != NULL)) {
135  pcmk_node_t *guest_node = pe_find_node(scheduler->nodes, rsc->id);
136 
137  if (guest_node) {
138  (*helper)(guest_node, user_data);
139  }
140  }
141  }
142 }
143 
159 xmlNode *
160 pe_create_remote_xml(xmlNode *parent, const char *uname,
161  const char *container_id, const char *migrateable,
162  const char *is_managed, const char *start_timeout,
163  const char *server, const char *port)
164 {
165  xmlNode *remote;
166  xmlNode *xml_sub;
167 
169 
170  // Add identity
171  crm_xml_add(remote, XML_ATTR_ID, uname);
173  crm_xml_add(remote, XML_AGENT_ATTR_PROVIDER, "pacemaker");
174  crm_xml_add(remote, XML_ATTR_TYPE, "remote");
175 
176  // Add meta-attributes
177  xml_sub = create_xml_node(remote, XML_TAG_META_SETS);
178  crm_xml_set_id(xml_sub, "%s-%s", uname, XML_TAG_META_SETS);
179  crm_create_nvpair_xml(xml_sub, NULL,
181  if (container_id) {
182  crm_create_nvpair_xml(xml_sub, NULL,
183  XML_RSC_ATTR_CONTAINER, container_id);
184  }
185  if (migrateable) {
186  crm_create_nvpair_xml(xml_sub, NULL,
187  XML_OP_ATTR_ALLOW_MIGRATE, migrateable);
188  }
189  if (is_managed) {
190  crm_create_nvpair_xml(xml_sub, NULL, XML_RSC_ATTR_MANAGED, is_managed);
191  }
192 
193  // Add instance attributes
194  if (port || server) {
195  xml_sub = create_xml_node(remote, XML_TAG_ATTR_SETS);
196  crm_xml_set_id(xml_sub, "%s-%s", uname, XML_TAG_ATTR_SETS);
197  if (server) {
199  server);
200  }
201  if (port) {
202  crm_create_nvpair_xml(xml_sub, NULL, "port", port);
203  }
204  }
205 
206  // Add operations
207  xml_sub = create_xml_node(remote, "operations");
208  crm_create_op_xml(xml_sub, uname, PCMK_ACTION_MONITOR, "30s", "30s");
209  if (start_timeout) {
211  start_timeout);
212  }
213  return remote;
214 }
215 
216 // History entry to be checked for fail count clearing
217 struct check_op {
218  const xmlNode *rsc_op; // History entry XML
219  pcmk_resource_t *rsc; // Known resource corresponding to history entry
220  pcmk_node_t *node; // Known node corresponding to history entry
221  enum pcmk__check_parameters check_type; // What needs checking
222 };
223 
224 void
225 pe__add_param_check(const xmlNode *rsc_op, pcmk_resource_t *rsc,
226  pcmk_node_t *node, enum pcmk__check_parameters flag,
228 {
229  struct check_op *check_op = NULL;
230 
231  CRM_CHECK(scheduler && rsc_op && rsc && node, return);
232 
233  check_op = calloc(1, sizeof(struct check_op));
234  CRM_ASSERT(check_op != NULL);
235 
236  crm_trace("Deferring checks of %s until after allocation", ID(rsc_op));
237  check_op->rsc_op = rsc_op;
238  check_op->rsc = rsc;
239  check_op->node = node;
240  check_op->check_type = flag;
241  scheduler->param_check = g_list_prepend(scheduler->param_check, check_op);
242 }
243 
251 void
253  void (*cb)(pcmk_resource_t*, pcmk_node_t*,
254  const xmlNode*, enum pcmk__check_parameters))
255 {
256  CRM_CHECK(scheduler && cb, return);
257 
258  for (GList *item = scheduler->param_check;
259  item != NULL; item = item->next) {
260  struct check_op *check_op = item->data;
261 
262  cb(check_op->rsc, check_op->node, check_op->rsc_op,
263  check_op->check_type);
264  }
265 }
266 
267 void
269 {
270  if (scheduler && scheduler->param_check) {
271  g_list_free_full(scheduler->param_check, free);
272  scheduler->param_check = NULL;
273  }
274 }
pcmk__cpg_host_t host
Definition: cpg.c:49
#define CRM_CHECK(expr, failure_action)
Definition: logging.h:238
pcmk_scheduler_t * cluster
Cluster that resource is part of.
Definition: resources.h:412
#define XML_ATTR_TYPE
Definition: msg_xml.h:160
bool pe__is_bundle_node(const pcmk_node_t *node)
Definition: remote.c:47
#define PCMK_ACTION_MONITOR
Definition: actions.h:59
bool xml_contains_remote_node(xmlNode *xml)
Definition: remote.c:84
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:302
pcmk_resource_t * pe__resource_contains_guest_node(const pcmk_scheduler_t *scheduler, const pcmk_resource_t *rsc)
Definition: remote.c:66
#define PCMK_RESOURCE_CLASS_OCF
Definition: agents.h:27
pcmk_resource_t * container
Resource containing this one, if any.
Definition: resources.h:480
bool pe__is_remote_node(const pcmk_node_t *node)
Definition: remote.c:25
Implementation of pcmk_scheduler_t.
Definition: scheduler.h:172
#define XML_RSC_ATTR_REMOTE_RA_ADDR
Definition: msg_xml.h:261
bool pe__is_guest_or_remote_node(const pcmk_node_t *node)
Definition: remote.c:41
GList * nodes
Nodes in cluster.
Definition: scheduler.h:195
#define XML_TAG_ATTR_SETS
Definition: msg_xml.h:227
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:252
Implementation of pcmk_resource_t.
Definition: resources.h:399
#define XML_RSC_ATTR_CONTAINER
Definition: msg_xml.h:255
#define XML_ATTR_ID
Definition: msg_xml.h:156
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
Definition: nvpair.c:447
#define XML_CIB_TAG_RESOURCE
Definition: msg_xml.h:235
#define XML_BOOLEAN_TRUE
Definition: msg_xml.h:167
Whether the cluster includes any Pacemaker Remote nodes (via CIB)
Definition: scheduler.h:134
#define crm_trace(fmt, args...)
Definition: logging.h:387
pcmk_node_t * pe_find_node(const GList *node_list, const char *node_name)
Find a node by name in a list of nodes.
Definition: status.c:473
#define pcmk_is_set(g, f)
Convenience alias for pcmk_all_flags_set(), to check single flag.
Definition: util.h:99
void crm_xml_set_id(xmlNode *xml, const char *format,...) G_GNUC_PRINTF(2
struct pe_node_shared_s * details
Basic node information.
Definition: nodes.h:134
void pe__free_param_checks(pcmk_scheduler_t *scheduler)
Definition: remote.c:268
#define PCMK_ACTION_START
Definition: actions.h:71
#define XML_AGENT_ATTR_PROVIDER
Definition: msg_xml.h:281
#define XML_TAG_META_SETS
Definition: msg_xml.h:228
Wrappers for and extensions to libxml2.
#define XML_RSC_ATTR_MANAGED
Definition: msg_xml.h:248
xmlNode * create_xml_node(xmlNode *parent, const char *name)
Definition: xml.c:638
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:225
Implementation of pcmk_node_t.
Definition: nodes.h:130
GList * fillers
Resources contained by this one, if any.
Definition: resources.h:481
bool pe__is_guest_node(const pcmk_node_t *node)
Definition: remote.c:33
Pacemaker Remote node.
Definition: nodes.h:35
pcmk__check_parameters
gboolean is_remote_node
Whether this is a remote connection.
Definition: resources.h:432
pcmk_scheduler_t * scheduler
GList * param_check
History entries that need to be checked.
Definition: scheduler.h:221
#define CRM_ASSERT(expr)
Definition: results.h:42
char uname[MAX_NAME]
Definition: cpg.c:50
#define XML_RSC_ATTR_INTERNAL_RSC
Definition: msg_xml.h:256
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:120
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:428
bool pe__resource_is_remote_conn(const pcmk_resource_t *rsc)
Definition: remote.c:18
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:763
#define ID(x)
Definition: msg_xml.h:474
unsigned long long flags
Group of enum pcmk_scheduler_flags.
Definition: scheduler.h:183
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:160
enum node_type type
Node variant.
Definition: nodes.h:69
#define XML_OP_ATTR_ALLOW_MIGRATE
Definition: msg_xml.h:270
pcmk_resource_t * remote_rsc
Remote connection resource for node, if it is a Pacemaker Remote node.
Definition: nodes.h:111
#define XML_AGENT_ATTR_CLASS
Definition: msg_xml.h:280
char * id
Resource ID in configuration.
Definition: resources.h:400