pacemaker  2.0.2-debe490
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  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 
77  const pe_resource_t *rsc)
78 {
79  if (rsc && data_set && is_set(data_set->flags, pe_flag_have_remote_nodes)) {
80  for (GList *gIter = rsc->fillers; gIter != NULL; gIter = gIter->next) {
81  pe_resource_t *filler = gIter->data;
82 
83  if (filler->is_remote_node) {
84  return filler;
85  }
86  }
87  }
88  return NULL;
89 }
90 
91 gboolean
93 {
94  const char *class = crm_element_value(xml, XML_AGENT_ATTR_CLASS);
95  const char *provider = crm_element_value(xml, XML_AGENT_ATTR_PROVIDER);
96  const char *agent = crm_element_value(xml, XML_ATTR_TYPE);
97 
98  if (safe_str_eq(agent, "remote") && safe_str_eq(provider, "pacemaker")
100  return TRUE;
101  }
102  return FALSE;
103 }
104 
114 void
116  void (*helper)(const node_t*, void*), void *user_data)
117 {
118  GListPtr iter;
119 
120  CRM_CHECK(data_set && host && host->details && helper, return);
121  if (!is_set(data_set->flags, pe_flag_have_remote_nodes)) {
122  return;
123  }
124  for (iter = host->details->running_rsc; iter != NULL; iter = iter->next) {
125  resource_t *rsc = (resource_t *) iter->data;
126 
127  if (rsc->is_remote_node && (rsc->container != NULL)) {
128  node_t *guest_node = pe_find_node(data_set->nodes, rsc->id);
129 
130  if (guest_node) {
131  (*helper)(guest_node, user_data);
132  }
133  }
134  }
135 }
136 
150 xmlNode *
151 pe_create_remote_xml(xmlNode *parent, const char *uname,
152  const char *container_id, const char *migrateable,
153  const char *is_managed, const char *start_timeout,
154  const char *server, const char *port)
155 {
156  xmlNode *remote;
157  xmlNode *xml_sub;
158 
159  remote = create_xml_node(parent, XML_CIB_TAG_RESOURCE);
160 
161  // Add identity
162  crm_xml_add(remote, XML_ATTR_ID, uname);
164  crm_xml_add(remote, XML_AGENT_ATTR_PROVIDER, "pacemaker");
165  crm_xml_add(remote, XML_ATTR_TYPE, "remote");
166 
167  // Add meta-attributes
168  xml_sub = create_xml_node(remote, XML_TAG_META_SETS);
169  crm_xml_set_id(xml_sub, "%s-%s", uname, XML_TAG_META_SETS);
170  crm_create_nvpair_xml(xml_sub, NULL,
172  if (container_id) {
173  crm_create_nvpair_xml(xml_sub, NULL,
174  XML_RSC_ATTR_CONTAINER, container_id);
175  }
176  if (migrateable) {
177  crm_create_nvpair_xml(xml_sub, NULL,
178  XML_OP_ATTR_ALLOW_MIGRATE, migrateable);
179  }
180  if (is_managed) {
181  crm_create_nvpair_xml(xml_sub, NULL, XML_RSC_ATTR_MANAGED, is_managed);
182  }
183 
184  // Add instance attributes
185  if (port || server) {
186  xml_sub = create_xml_node(remote, XML_TAG_ATTR_SETS);
187  crm_xml_set_id(xml_sub, "%s-%s", uname, XML_TAG_ATTR_SETS);
188  if (server) {
190  server);
191  }
192  if (port) {
193  crm_create_nvpair_xml(xml_sub, NULL, "port", port);
194  }
195  }
196 
197  // Add operations
198  xml_sub = create_xml_node(remote, "operations");
199  crm_create_op_xml(xml_sub, uname, "monitor", "30s", "30s");
200  if (start_timeout) {
201  crm_create_op_xml(xml_sub, uname, "start", "0", start_timeout);
202  }
203  return remote;
204 }
205 
206 // History entry to be checked for fail count clearing
207 struct check_op {
208  xmlNode *rsc_op; // History entry XML
209  pe_resource_t *rsc; // Known resource corresponding to history entry
210  pe_node_t *node; // Known node corresponding to history entry
211  enum pe_check_parameters check_type; // What needs checking
212 };
213 
214 void
215 pe__add_param_check(xmlNode *rsc_op, pe_resource_t *rsc, pe_node_t *node,
216  enum pe_check_parameters flag, pe_working_set_t *data_set)
217 {
218  struct check_op *check_op = NULL;
219 
220  CRM_CHECK(data_set && rsc_op && rsc && node, return);
221 
222  check_op = calloc(1, sizeof(struct check_op));
223  CRM_ASSERT(check_op != NULL);
224 
225  crm_trace("Deferring checks of %s until after allocation", ID(rsc_op));
226  check_op->rsc_op = rsc_op;
227  check_op->rsc = rsc;
228  check_op->node = node;
229  check_op->check_type = flag;
230  data_set->param_check = g_list_prepend(data_set->param_check, check_op);
231 }
232 
240 void
242  void (*cb)(pe_resource_t*, pe_node_t*, xmlNode*,
244 {
245  CRM_CHECK(data_set && cb, return);
246 
247  for (GList *item = data_set->param_check; item != NULL; item = item->next) {
248  struct check_op *check_op = item->data;
249 
250  cb(check_op->rsc, check_op->node, check_op->rsc_op,
251  check_op->check_type, data_set);
252  }
253 }
254 
255 void
257 {
258  if (data_set && data_set->param_check) {
259  g_list_free_full(data_set->param_check, free);
260  data_set->param_check = NULL;
261  }
262 }
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:241
#define CRM_CHECK(expr, failure_action)
Definition: logging.h:156
char uname[MAX_NAME]
Definition: internal.h:87
GListPtr nodes
Definition: pe_types.h:133
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:422
pe_check_parameters
Definition: pe_types.h:165
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:215
pe_resource_t * container
Definition: pe_types.h:343
#define XML_ATTR_TYPE
Definition: msg_xml.h:99
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:151
pe_resource_t * remote_rsc
Definition: pe_types.h:200
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:275
gboolean pe__is_guest_or_remote_node(pe_node_t *node)
Definition: remote.c:58
GListPtr fillers
Definition: pe_types.h:344
AIS_Host host
Definition: internal.h:86
pe_node_t * pe_find_node(GListPtr node_list, const char *uname)
Definition: status.c:412
#define XML_RSC_ATTR_REMOTE_RA_ADDR
Definition: msg_xml.h:211
#define XML_TAG_ATTR_SETS
Definition: msg_xml.h:163
void pe_foreach_guest_node(const pe_working_set_t *data_set, const node_t *host, void(*helper)(const node_t *, void *), void *user_data)
Definition: remote.c:115
#define pe_flag_have_remote_nodes
Definition: pe_types.h:106
#define PCMK_RESOURCE_CLASS_OCF
Definition: services.h:43
gboolean pe__is_guest_node(pe_node_t *node)
Definition: remote.c:47
#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:423
#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:246
pe_resource_t * pe__resource_contains_guest_node(const pe_working_set_t *data_set, const pe_resource_t *rsc)
Definition: remote.c:76
struct pe_node_shared_s * details
Definition: pe_types.h:213
#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:1890
void pe__free_param_checks(pe_working_set_t *data_set)
Definition: remote.c:256
GListPtr running_rsc
Definition: pe_types.h:201
gboolean xml_contains_remote_node(xmlNode *xml)
Definition: remote.c:92
gboolean is_remote_node
Definition: pe_types.h:314
GList * param_check
Definition: pe_types.h:161
#define CRM_ASSERT(expr)
Definition: results.h:42
void crm_xml_set_id(xmlNode *xml, const char *format,...) __attribute__((__format__(__printf__
gboolean pe__resource_is_remote_conn(pe_resource_t *rsc, pe_working_set_t *data_set)
Definition: remote.c:17
#define XML_RSC_ATTR_INTERNAL_RSC
Definition: msg_xml.h:206
gboolean pe__is_remote_node(pe_node_t *node)
Definition: remote.c:36
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:678
#define ID(x)
Definition: msg_xml.h:414
unsigned long long flags
Definition: pe_types.h:122
#define safe_str_eq(a, b)
Definition: util.h:59
GList * GListPtr
Definition: crm.h:192
enum node_type type
Definition: pe_types.h:180
#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:284