pacemaker  2.1.0-7c3f660
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
remote.c
Go to the documentation of this file.
1 /*
2  * Copyright 2013-2019 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>
13 #include <crm/pengine/internal.h>
14 #include <glib.h>
15 
16 bool
18  const pe_working_set_t *data_set)
19 {
20  return (rsc != NULL) && rsc->is_remote_node
21  && pe__is_remote_node(pe_find_node(data_set->nodes, rsc->id));
22 }
23 
24 bool
26 {
27  return (node != NULL) && (node->details->type == node_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 == node_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 == node_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 pe_resource_t *rsc)
68 {
69  if ((rsc != NULL) && (data_set != NULL)
71 
72  for (GList *gIter = rsc->fillers; gIter != NULL; gIter = gIter->next) {
73  pe_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  void (*helper)(const pe_node_t*, void*), void *user_data)
122 {
123  GList *iter;
124 
125  CRM_CHECK(data_set && host && host->details && helper, return);
126  if (!pcmk_is_set(data_set->flags, pe_flag_have_remote_nodes)) {
127  return;
128  }
129  for (iter = host->details->running_rsc; iter != NULL; iter = iter->next) {
130  pe_resource_t *rsc = (pe_resource_t *) iter->data;
131 
132  if (rsc->is_remote_node && (rsc->container != NULL)) {
133  pe_node_t *guest_node = pe_find_node(data_set->nodes, rsc->id);
134 
135  if (guest_node) {
136  (*helper)(guest_node, user_data);
137  }
138  }
139  }
140 }
141 
155 xmlNode *
156 pe_create_remote_xml(xmlNode *parent, const char *uname,
157  const char *container_id, const char *migrateable,
158  const char *is_managed, const char *start_timeout,
159  const char *server, const char *port)
160 {
161  xmlNode *remote;
162  xmlNode *xml_sub;
163 
164  remote = create_xml_node(parent, XML_CIB_TAG_RESOURCE);
165 
166  // Add identity
167  crm_xml_add(remote, XML_ATTR_ID, uname);
169  crm_xml_add(remote, XML_AGENT_ATTR_PROVIDER, "pacemaker");
170  crm_xml_add(remote, XML_ATTR_TYPE, "remote");
171 
172  // Add meta-attributes
173  xml_sub = create_xml_node(remote, XML_TAG_META_SETS);
174  crm_xml_set_id(xml_sub, "%s-%s", uname, XML_TAG_META_SETS);
175  crm_create_nvpair_xml(xml_sub, NULL,
177  if (container_id) {
178  crm_create_nvpair_xml(xml_sub, NULL,
179  XML_RSC_ATTR_CONTAINER, container_id);
180  }
181  if (migrateable) {
182  crm_create_nvpair_xml(xml_sub, NULL,
183  XML_OP_ATTR_ALLOW_MIGRATE, migrateable);
184  }
185  if (is_managed) {
186  crm_create_nvpair_xml(xml_sub, NULL, XML_RSC_ATTR_MANAGED, is_managed);
187  }
188 
189  // Add instance attributes
190  if (port || server) {
191  xml_sub = create_xml_node(remote, XML_TAG_ATTR_SETS);
192  crm_xml_set_id(xml_sub, "%s-%s", uname, XML_TAG_ATTR_SETS);
193  if (server) {
195  server);
196  }
197  if (port) {
198  crm_create_nvpair_xml(xml_sub, NULL, "port", port);
199  }
200  }
201 
202  // Add operations
203  xml_sub = create_xml_node(remote, "operations");
204  crm_create_op_xml(xml_sub, uname, "monitor", "30s", "30s");
205  if (start_timeout) {
206  crm_create_op_xml(xml_sub, uname, "start", "0", start_timeout);
207  }
208  return remote;
209 }
210 
211 // History entry to be checked for fail count clearing
212 struct check_op {
213  xmlNode *rsc_op; // History entry XML
214  pe_resource_t *rsc; // Known resource corresponding to history entry
215  pe_node_t *node; // Known node corresponding to history entry
216  enum pe_check_parameters check_type; // What needs checking
217 };
218 
219 void
220 pe__add_param_check(xmlNode *rsc_op, pe_resource_t *rsc, pe_node_t *node,
221  enum pe_check_parameters flag, pe_working_set_t *data_set)
222 {
223  struct check_op *check_op = NULL;
224 
225  CRM_CHECK(data_set && rsc_op && rsc && node, return);
226 
227  check_op = calloc(1, sizeof(struct check_op));
228  CRM_ASSERT(check_op != NULL);
229 
230  crm_trace("Deferring checks of %s until after allocation", ID(rsc_op));
231  check_op->rsc_op = rsc_op;
232  check_op->rsc = rsc;
233  check_op->node = node;
234  check_op->check_type = flag;
235  data_set->param_check = g_list_prepend(data_set->param_check, check_op);
236 }
237 
245 void
247  void (*cb)(pe_resource_t*, pe_node_t*, xmlNode*,
249 {
250  CRM_CHECK(data_set && cb, return);
251 
252  for (GList *item = data_set->param_check; item != NULL; item = item->next) {
253  struct check_op *check_op = item->data;
254 
255  cb(check_op->rsc, check_op->node, check_op->rsc_op,
256  check_op->check_type, data_set);
257  }
258 }
259 
260 void
262 {
263  if (data_set && data_set->param_check) {
264  g_list_free_full(data_set->param_check, free);
265  data_set->param_check = NULL;
266  }
267 }
void pe__foreach_param_check(pe_working_set_t *data_set, void(*cb)(pe_resource_t *, pe_node_t *, xmlNode *, enum pe_check_parameters, pe_working_set_t *))
Definition: remote.c:246
pcmk__cpg_host_t host
Definition: cpg.c:49
#define CRM_CHECK(expr, failure_action)
Definition: logging.h:218
pe_node_t * pe_find_node(GList *node_list, const char *uname)
Definition: status.c:434
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: operations.c:472
bool pe__is_guest_or_remote_node(const pe_node_t *node)
Definition: remote.c:41
pe_check_parameters
Definition: pe_types.h:195
void pe__add_param_check(xmlNode *rsc_op, pe_resource_t *rsc, pe_node_t *node, enum pe_check_parameters, pe_working_set_t *data_set)
Definition: remote.c:220
pe_resource_t * container
Definition: pe_types.h:379
#define XML_ATTR_TYPE
Definition: msg_xml.h:132
bool pe__is_bundle_node(const pe_node_t *node)
Definition: remote.c:47
void pe_foreach_guest_node(const pe_working_set_t *data_set, const pe_node_t *host, void(*helper)(const pe_node_t *, void *), void *user_data)
Definition: remote.c:120
pe_resource_t * remote_rsc
Definition: pe_types.h:230
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:324
#define XML_RSC_ATTR_REMOTE_RA_ADDR
Definition: msg_xml.h:247
GList * nodes
Definition: pe_types.h:157
bool pe__is_remote_node(const pe_node_t *node)
Definition: remote.c:25
#define XML_TAG_ATTR_SETS
Definition: msg_xml.h:203
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:156
#define pe_flag_have_remote_nodes
Definition: pe_types.h:117
#define PCMK_RESOURCE_CLASS_OCF
Definition: services.h:43
pe_resource_t * pe__resource_contains_guest_node(const pe_working_set_t *data_set, const pe_resource_t *rsc)
Definition: remote.c:66
#define XML_RSC_ATTR_CONTAINER
Definition: msg_xml.h:241
#define XML_ATTR_ID
Definition: msg_xml.h:129
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
Definition: nvpair.c:530
#define XML_CIB_TAG_RESOURCE
Definition: msg_xml.h:214
#define XML_BOOLEAN_TRUE
Definition: msg_xml.h:140
bool pe__is_guest_node(const pe_node_t *node)
Definition: remote.c:33
#define crm_trace(fmt, args...)
Definition: logging.h:356
bool xml_contains_remote_node(xmlNode *xml)
Definition: remote.c:84
#define pcmk_is_set(g, f)
Convenience alias for pcmk_all_flags_set(), to check single flag.
Definition: util.h:114
void crm_xml_set_id(xmlNode *xml, const char *format,...) G_GNUC_PRINTF(2
struct pe_node_shared_s * details
Definition: pe_types.h:244
#define XML_AGENT_ATTR_PROVIDER
Definition: msg_xml.h:267
#define XML_TAG_META_SETS
Definition: msg_xml.h:204
Wrappers for and extensions to libxml2.
#define XML_RSC_ATTR_MANAGED
Definition: msg_xml.h:232
xmlNode * create_xml_node(xmlNode *parent, const char *name)
Definition: xml.c:696
void pe__free_param_checks(pe_working_set_t *data_set)
Definition: remote.c:261
GList * fillers
Definition: pe_types.h:380
GList * running_rsc
Definition: pe_types.h:231
gboolean is_remote_node
Definition: pe_types.h:350
GList * param_check
Definition: pe_types.h:185
#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:242
bool pe__resource_is_remote_conn(const pe_resource_t *rsc, const pe_working_set_t *data_set)
Definition: remote.c:17
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:849
#define ID(x)
Definition: msg_xml.h:456
unsigned long long flags
Definition: pe_types.h:146
enum node_type type
Definition: pe_types.h:210
#define XML_OP_ATTR_ALLOW_MIGRATE
Definition: msg_xml.h:256
#define XML_AGENT_ATTR_CLASS
Definition: msg_xml.h:266
char * id
Definition: pe_types.h:320