pacemaker  2.0.4-2deceaa
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 gboolean
18 {
19  pe_node_t *node;
20 
21  if (rsc == NULL) {
22  return FALSE;
23  } else if (rsc->is_remote_node == FALSE) {
24  return FALSE;
25  }
26 
27  node = pe_find_node(data_set->nodes, rsc->id);
28  if (node == NULL) {
29  return FALSE;
30  }
31 
32  return pe__is_remote_node(node);
33 }
34 
35 gboolean
37 {
39  && ((node->details->remote_rsc == NULL)
40  || (node->details->remote_rsc->container == NULL))) {
41  return TRUE;
42  }
43  return FALSE;
44 }
45 
46 gboolean
48 {
50  && node->details->remote_rsc
51  && node->details->remote_rsc->container) {
52  return TRUE;
53  }
54  return FALSE;
55 }
56 
57 gboolean
59 {
60  return (node != NULL) && (node->details->type == node_remote);
61 }
62 
63 bool
65 {
66  return pe__is_guest_node(node)
67  && pe_rsc_is_bundled(node->details->remote_rsc);
68 }
69 
84  const pe_resource_t *rsc)
85 {
86  if (rsc && data_set && is_set(data_set->flags, pe_flag_have_remote_nodes)) {
87  for (GList *gIter = rsc->fillers; gIter != NULL; gIter = gIter->next) {
88  pe_resource_t *filler = gIter->data;
89 
90  if (filler->is_remote_node) {
91  return filler;
92  }
93  }
94  }
95  return NULL;
96 }
97 
98 gboolean
100 {
101  const char *class = crm_element_value(xml, XML_AGENT_ATTR_CLASS);
102  const char *provider = crm_element_value(xml, XML_AGENT_ATTR_PROVIDER);
103  const char *agent = crm_element_value(xml, XML_ATTR_TYPE);
104 
105  if (safe_str_eq(agent, "remote") && safe_str_eq(provider, "pacemaker")
107  return TRUE;
108  }
109  return FALSE;
110 }
111 
121 void
123  void (*helper)(const pe_node_t*, void*), void *user_data)
124 {
125  GListPtr iter;
126 
127  CRM_CHECK(data_set && host && host->details && helper, return);
128  if (!is_set(data_set->flags, pe_flag_have_remote_nodes)) {
129  return;
130  }
131  for (iter = host->details->running_rsc; iter != NULL; iter = iter->next) {
132  pe_resource_t *rsc = (pe_resource_t *) iter->data;
133 
134  if (rsc->is_remote_node && (rsc->container != NULL)) {
135  pe_node_t *guest_node = pe_find_node(data_set->nodes, rsc->id);
136 
137  if (guest_node) {
138  (*helper)(guest_node, user_data);
139  }
140  }
141  }
142 }
143 
157 xmlNode *
158 pe_create_remote_xml(xmlNode *parent, const char *uname,
159  const char *container_id, const char *migrateable,
160  const char *is_managed, const char *start_timeout,
161  const char *server, const char *port)
162 {
163  xmlNode *remote;
164  xmlNode *xml_sub;
165 
166  remote = create_xml_node(parent, XML_CIB_TAG_RESOURCE);
167 
168  // Add identity
169  crm_xml_add(remote, XML_ATTR_ID, uname);
171  crm_xml_add(remote, XML_AGENT_ATTR_PROVIDER, "pacemaker");
172  crm_xml_add(remote, XML_ATTR_TYPE, "remote");
173 
174  // Add meta-attributes
175  xml_sub = create_xml_node(remote, XML_TAG_META_SETS);
176  crm_xml_set_id(xml_sub, "%s-%s", uname, XML_TAG_META_SETS);
177  crm_create_nvpair_xml(xml_sub, NULL,
179  if (container_id) {
180  crm_create_nvpair_xml(xml_sub, NULL,
181  XML_RSC_ATTR_CONTAINER, container_id);
182  }
183  if (migrateable) {
184  crm_create_nvpair_xml(xml_sub, NULL,
185  XML_OP_ATTR_ALLOW_MIGRATE, migrateable);
186  }
187  if (is_managed) {
188  crm_create_nvpair_xml(xml_sub, NULL, XML_RSC_ATTR_MANAGED, is_managed);
189  }
190 
191  // Add instance attributes
192  if (port || server) {
193  xml_sub = create_xml_node(remote, XML_TAG_ATTR_SETS);
194  crm_xml_set_id(xml_sub, "%s-%s", uname, XML_TAG_ATTR_SETS);
195  if (server) {
197  server);
198  }
199  if (port) {
200  crm_create_nvpair_xml(xml_sub, NULL, "port", port);
201  }
202  }
203 
204  // Add operations
205  xml_sub = create_xml_node(remote, "operations");
206  crm_create_op_xml(xml_sub, uname, "monitor", "30s", "30s");
207  if (start_timeout) {
208  crm_create_op_xml(xml_sub, uname, "start", "0", start_timeout);
209  }
210  return remote;
211 }
212 
213 // History entry to be checked for fail count clearing
214 struct check_op {
215  xmlNode *rsc_op; // History entry XML
216  pe_resource_t *rsc; // Known resource corresponding to history entry
217  pe_node_t *node; // Known node corresponding to history entry
218  enum pe_check_parameters check_type; // What needs checking
219 };
220 
221 void
222 pe__add_param_check(xmlNode *rsc_op, pe_resource_t *rsc, pe_node_t *node,
223  enum pe_check_parameters flag, pe_working_set_t *data_set)
224 {
225  struct check_op *check_op = NULL;
226 
227  CRM_CHECK(data_set && rsc_op && rsc && node, return);
228 
229  check_op = calloc(1, sizeof(struct check_op));
230  CRM_ASSERT(check_op != NULL);
231 
232  crm_trace("Deferring checks of %s until after allocation", ID(rsc_op));
233  check_op->rsc_op = rsc_op;
234  check_op->rsc = rsc;
235  check_op->node = node;
236  check_op->check_type = flag;
237  data_set->param_check = g_list_prepend(data_set->param_check, check_op);
238 }
239 
247 void
249  void (*cb)(pe_resource_t*, pe_node_t*, xmlNode*,
251 {
252  CRM_CHECK(data_set && cb, return);
253 
254  for (GList *item = data_set->param_check; item != NULL; item = item->next) {
255  struct check_op *check_op = item->data;
256 
257  cb(check_op->rsc, check_op->node, check_op->rsc_op,
258  check_op->check_type, data_set);
259  }
260 }
261 
262 void
264 {
265  if (data_set && data_set->param_check) {
266  g_list_free_full(data_set->param_check, free);
267  data_set->param_check = NULL;
268  }
269 }
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:248
#define CRM_CHECK(expr, failure_action)
Definition: logging.h:233
char uname[MAX_NAME]
Definition: internal.h:85
GListPtr nodes
Definition: pe_types.h:146
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:377
pe_check_parameters
Definition: pe_types.h:182
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:222
pe_resource_t * container
Definition: pe_types.h:364
#define XML_ATTR_TYPE
Definition: msg_xml.h:99
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:122
pe_resource_t * remote_rsc
Definition: pe_types.h:217
gboolean pe__is_guest_or_remote_node(pe_node_t *node)
Definition: remote.c:58
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:316
GListPtr fillers
Definition: pe_types.h:365
gboolean xml_contains_remote_node(xmlNode *xml)
Definition: remote.c:99
AIS_Host host
Definition: internal.h:84
pe_node_t * pe_find_node(GListPtr node_list, const char *uname)
Definition: status.c:427
#define XML_RSC_ATTR_REMOTE_RA_ADDR
Definition: msg_xml.h:211
bool pe__is_bundle_node(pe_node_t *node)
Definition: remote.c:64
gboolean pe__is_remote_node(pe_node_t *node)
Definition: remote.c:36
#define XML_TAG_ATTR_SETS
Definition: msg_xml.h:163
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:158
#define pe_flag_have_remote_nodes
Definition: pe_types.h:111
#define PCMK_RESOURCE_CLASS_OCF
Definition: services.h:43
gboolean pe__resource_is_remote_conn(pe_resource_t *rsc, pe_working_set_t *data_set)
Definition: remote.c:17
pe_resource_t * pe__resource_contains_guest_node(const pe_working_set_t *data_set, const pe_resource_t *rsc)
Definition: remote.c:83
#define XML_RSC_ATTR_CONTAINER
Definition: msg_xml.h:205
#define XML_ATTR_ID
Definition: msg_xml.h:96
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
Definition: nvpair.c:522
#define XML_CIB_TAG_RESOURCE
Definition: msg_xml.h:174
#define XML_BOOLEAN_TRUE
Definition: msg_xml.h:107
#define crm_trace(fmt, args...)
Definition: logging.h:369
struct pe_node_shared_s * details
Definition: pe_types.h:231
#define XML_AGENT_ATTR_PROVIDER
Definition: msg_xml.h:230
#define XML_TAG_META_SETS
Definition: msg_xml.h:164
Wrappers for and extensions to libxml2.
#define XML_RSC_ATTR_MANAGED
Definition: msg_xml.h:195
xmlNode * create_xml_node(xmlNode *parent, const char *name)
Definition: xml.c:1976
void pe__free_param_checks(pe_working_set_t *data_set)
Definition: remote.c:263
GListPtr running_rsc
Definition: pe_types.h:218
gboolean pe__is_guest_node(pe_node_t *node)
Definition: remote.c:47
gboolean is_remote_node
Definition: pe_types.h:335
GList * param_check
Definition: pe_types.h:174
#define CRM_ASSERT(expr)
Definition: results.h:42
void crm_xml_set_id(xmlNode *xml, const char *format,...) __attribute__((__format__(__printf__
#define XML_RSC_ATTR_INTERNAL_RSC
Definition: msg_xml.h:206
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:847
#define ID(x)
Definition: msg_xml.h:418
unsigned long long flags
Definition: pe_types.h:135
#define safe_str_eq(a, b)
Definition: util.h:65
GList * GListPtr
Definition: crm.h:214
enum node_type type
Definition: pe_types.h:197
#define XML_OP_ATTR_ALLOW_MIGRATE
Definition: msg_xml.h:219
#define XML_AGENT_ATTR_CLASS
Definition: msg_xml.h:229
char * id
Definition: pe_types.h:305