pacemaker  1.1.24-3850484742
Scalable High-Availability cluster resource manager
remote.c
Go to the documentation of this file.
1 /*
2  * Copyright 2013-2018 Andrew Beekhof <andrew@beekhof.net>
3  *
4  * This source code is licensed under the GNU Lesser General Public License
5  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
6  */
7 
8 #include <crm_internal.h>
9 #include <crm/msg_xml.h>
10 #include <crm/common/xml.h>
11 #include <crm/pengine/internal.h>
12 #include <glib.h>
13 
14 gboolean
16 {
17  node_t *node;
18 
19  if (rsc == NULL) {
20  return FALSE;
21  } else if (rsc->is_remote_node == FALSE) {
22  return FALSE;
23  }
24 
25  node = pe_find_node(data_set->nodes, rsc->id);
26  if (node == NULL) {
27  return FALSE;
28  }
29 
30  return is_baremetal_remote_node(node);
31 }
32 
33 gboolean
35 {
36  if (is_remote_node(node) && (node->details->remote_rsc == NULL || node->details->remote_rsc->container == FALSE)) {
37  return TRUE;
38  }
39  return FALSE;
40 }
41 
42 gboolean
44 {
45  if (is_remote_node(node) && (node->details->remote_rsc && node->details->remote_rsc->container)) {
46  return TRUE;
47  }
48  return FALSE;
49 }
50 
51 gboolean
53 {
54  if (node && node->details->type == node_remote) {
55  return TRUE;
56  }
57  return FALSE;
58 }
59 
60 resource_t *
62 {
63  if (is_set(data_set->flags, pe_flag_have_remote_nodes) == FALSE) {
64  return NULL;
65  }
66 
67  if (rsc->fillers) {
68  GListPtr gIter = NULL;
69  for (gIter = rsc->fillers; gIter != NULL; gIter = gIter->next) {
70  resource_t *filler = (resource_t *) gIter->data;
71 
72  if (filler->is_remote_node) {
73  return filler;
74  }
75  }
76  }
77  return NULL;
78 }
79 
80 gboolean
82 {
83  const char *class = crm_element_value(xml, XML_AGENT_ATTR_CLASS);
84  const char *provider = crm_element_value(xml, XML_AGENT_ATTR_PROVIDER);
85  const char *agent = crm_element_value(xml, XML_ATTR_TYPE);
86 
87  if (safe_str_eq(agent, "remote") && safe_str_eq(provider, "pacemaker")
89  return TRUE;
90  }
91  return FALSE;
92 }
93 
103 void
105  void (*helper)(const node_t*, void*), void *user_data)
106 {
107  GListPtr iter;
108 
109  CRM_CHECK(data_set && host && host->details && helper, return);
110  if (!is_set(data_set->flags, pe_flag_have_remote_nodes)) {
111  return;
112  }
113  for (iter = host->details->running_rsc; iter != NULL; iter = iter->next) {
114  resource_t *rsc = (resource_t *) iter->data;
115 
116  if (rsc->is_remote_node && (rsc->container != NULL)) {
117  node_t *guest_node = pe_find_node(data_set->nodes, rsc->id);
118 
119  if (guest_node) {
120  (*helper)(guest_node, user_data);
121  }
122  }
123  }
124 }
125 
147 xmlNode *
148 pe_create_remote_xml(xmlNode *parent, const char *uname,
149  const char *container_id, const char *migrateable,
150  const char *is_managed, const char *interval,
151  const char *monitor_timeout, const char *start_timeout,
152  const char *server, const char *port)
153 {
154  xmlNode *remote;
155  xmlNode *xml_sub;
156 
157  remote = create_xml_node(parent, XML_CIB_TAG_RESOURCE);
158 
159  // Add identity
160  crm_xml_add(remote, XML_ATTR_ID, uname);
162  crm_xml_add(remote, XML_AGENT_ATTR_PROVIDER, "pacemaker");
163  crm_xml_add(remote, XML_ATTR_TYPE, "remote");
164 
165  // Add meta-attributes
166  xml_sub = create_xml_node(remote, XML_TAG_META_SETS);
167  crm_xml_set_id(xml_sub, "%s-%s", uname, XML_TAG_META_SETS);
168  crm_create_nvpair_xml(xml_sub, NULL,
170  if (container_id) {
171  crm_create_nvpair_xml(xml_sub, NULL,
172  XML_RSC_ATTR_CONTAINER, container_id);
173  }
174  if (migrateable) {
175  crm_create_nvpair_xml(xml_sub, NULL,
176  XML_OP_ATTR_ALLOW_MIGRATE, migrateable);
177  }
178  if (is_managed) {
179  crm_create_nvpair_xml(xml_sub, NULL, XML_RSC_ATTR_MANAGED, is_managed);
180  }
181 
182  // Add instance attributes
183  if (port || server) {
184  xml_sub = create_xml_node(remote, XML_TAG_ATTR_SETS);
185  crm_xml_set_id(xml_sub, "%s-%s", uname, XML_TAG_ATTR_SETS);
186  if (server) {
187  crm_create_nvpair_xml(xml_sub, NULL, "addr", server);
188  }
189  if (port) {
190  crm_create_nvpair_xml(xml_sub, NULL, "port", port);
191  }
192  }
193 
194  // Add operations
195  if (interval || start_timeout) {
196  xml_sub = create_xml_node(remote, "operations");
197  if (interval) {
198  crm_create_op_xml(xml_sub, uname, "monitor", interval,
199  monitor_timeout);
200  }
201  if (start_timeout) {
202  crm_create_op_xml(xml_sub, uname, "start", "0", start_timeout);
203  }
204  }
205  return remote;
206 }
207 
208 // History entry to be checked for fail count clearing
209 struct check_op {
210  xmlNode *rsc_op; // History entry XML
211  pe_resource_t *rsc; // Known resource corresponding to history entry
212  pe_node_t *node; // Known node corresponding to history entry
213  enum pe_check_parameters check_type; // What needs checking
214 };
215 
216 void
217 pe__add_param_check(xmlNode *rsc_op, pe_resource_t *rsc, pe_node_t *node,
218  enum pe_check_parameters flag, pe_working_set_t *data_set)
219 {
220  struct check_op *check_op = NULL;
221 
222  CRM_CHECK(data_set && rsc_op && rsc && node, return);
223 
224  check_op = calloc(1, sizeof(struct check_op));
225  CRM_ASSERT(check_op != NULL);
226 
227  crm_trace("Deferring checks of %s until after allocation", ID(rsc_op));
228  check_op->rsc_op = rsc_op;
229  check_op->rsc = rsc;
230  check_op->node = node;
231  check_op->check_type = flag;
232  data_set->param_check = g_list_prepend(data_set->param_check, check_op);
233 }
234 
242 void
244  void (*cb)(pe_resource_t*, pe_node_t*, xmlNode*,
246 {
247  CRM_CHECK(data_set && cb, return);
248 
249  for (GList *item = data_set->param_check; item != NULL; item = item->next) {
250  struct check_op *check_op = item->data;
251 
252  cb(check_op->rsc, check_op->node, check_op->rsc_op,
253  check_op->check_type, data_set);
254  }
255 }
256 
257 void
259 {
260  if (data_set && data_set->param_check) {
261  g_list_free_full(data_set->param_check, free);
262  data_set->param_check = NULL;
263  }
264 }
#define CRM_CHECK(expr, failure_action)
Definition: logging.h:190
GListPtr nodes
Definition: status.h:125
void pe__free_param_checks(pe_working_set_t *data_set)
Definition: remote.c:258
gboolean is_container_remote_node(node_t *node)
Definition: remote.c:43
#define XML_ATTR_TYPE
Definition: msg_xml.h:105
#define pe_flag_have_remote_nodes
Definition: status.h:89
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:104
GListPtr running_rsc
Definition: status.h:187
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:216
xmlNode * pe_create_remote_xml(xmlNode *parent, const char *uname, const char *container_id, const char *migrateable, const char *is_managed, const char *interval, const char *monitor_timeout, const char *start_timeout, const char *server, const char *port)
Definition: remote.c:148
node_t * pe_find_node(GListPtr node_list, const char *uname)
Definition: status.c:444
AIS_Host host
Definition: internal.h:80
resource_t * remote_rsc
Definition: status.h:190
gboolean is_remote_node
Definition: status.h:314
char * id
Definition: status.h:292
#define XML_TAG_ATTR_SETS
Definition: msg_xml.h:185
resource_t * rsc_contains_remote_node(pe_working_set_t *data_set, resource_t *rsc)
Definition: remote.c:61
char uname[MAX_NAME]
Definition: internal.h:81
struct node_shared_s * details
Definition: status.h:213
#define PCMK_RESOURCE_CLASS_OCF
Definition: services.h:57
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:243
#define XML_RSC_ATTR_CONTAINER
Definition: msg_xml.h:230
#define XML_ATTR_ID
Definition: msg_xml.h:102
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
Definition: nvpair.c:393
#define XML_CIB_TAG_RESOURCE
Definition: msg_xml.h:196
#define XML_BOOLEAN_TRUE
Definition: msg_xml.h:117
resource_t * container
Definition: status.h:343
#define crm_trace(fmt, args...)
Definition: logging.h:280
xmlNode * crm_create_op_xml(xmlNode *parent, const char *prefix, const char *task, const char *interval, const char *timeout)
Create a CIB XML element for an operation.
Definition: operations.c:455
#define XML_AGENT_ATTR_PROVIDER
Definition: msg_xml.h:258
#define XML_TAG_META_SETS
Definition: msg_xml.h:186
Wrappers for and extensions to libxml2.
#define XML_RSC_ATTR_MANAGED
Definition: msg_xml.h:219
xmlNode * create_xml_node(xmlNode *parent, const char *name)
Definition: xml.c:1977
gboolean is_remote_node(node_t *node)
Definition: remote.c:52
GListPtr fillers
Definition: status.h:344
void pe__add_param_check(xmlNode *rsc_op, pe_resource_t *rsc, pe_node_t *node, enum pe_check_parameters flag, pe_working_set_t *data_set)
Definition: remote.c:217
gboolean is_baremetal_remote_node(node_t *node)
Definition: remote.c:34
GList * param_check
Definition: status.h:153
void crm_xml_set_id(xmlNode *xml, const char *format,...) __attribute__((__format__(__printf__
#define XML_RSC_ATTR_INTERNAL_RSC
Definition: msg_xml.h:231
#define CRM_ASSERT(expr)
Definition: error.h:20
enum node_type type
Definition: status.h:193
Definition: status.h:209
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:692
gboolean xml_contains_remote_node(xmlNode *xml)
Definition: remote.c:81
#define ID(x)
Definition: msg_xml.h:452
unsigned long long flags
Definition: status.h:113
#define safe_str_eq(a, b)
Definition: util.h:74
GList * GListPtr
Definition: crm.h:210
#define XML_OP_ATTR_ALLOW_MIGRATE
Definition: msg_xml.h:244
pe_check_parameters
Definition: status.h:159
gboolean is_rsc_baremetal_remote_node(resource_t *rsc, pe_working_set_t *data_set)
Definition: remote.c:15
#define XML_AGENT_ATTR_CLASS
Definition: msg_xml.h:257