pacemaker  1.1.17-b36b869ca8
Scalable High-Availability cluster resource manager
status.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2004 Andrew Beekhof <andrew@beekhof.net>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include <crm_internal.h>
20 
21 #include <sys/param.h>
22 
23 #include <crm/crm.h>
24 #include <crm/msg_xml.h>
25 #include <crm/common/xml.h>
26 
27 #include <glib.h>
28 
29 #include <crm/pengine/internal.h>
30 #include <unpack.h>
31 
32 #define MEMCHECK_STAGE_0 0
33 
34 #define check_and_exit(stage) cleanup_calculations(data_set); \
35  crm_mem_stats(NULL); \
36  crm_err("Exiting: stage %d", stage); \
37  crm_exit(pcmk_err_generic);
38 
39 /*
40  * Unpack everything
41  * At the end you'll have:
42  * - A list of nodes
43  * - A list of resources (each with any dependencies on other resources)
44  * - A list of constraints between resources and nodes
45  * - A list of constraints between start/stop actions
46  * - A list of nodes that need to be stonith'd
47  * - A list of nodes that need to be shutdown
48  * - A list of the possible stop/start actions (without dependencies)
49  */
50 gboolean
52 {
53  xmlNode *config = get_xpath_object("//"XML_CIB_TAG_CRMCONFIG, data_set->input, LOG_TRACE);
54  xmlNode *cib_nodes = get_xpath_object("//"XML_CIB_TAG_NODES, data_set->input, LOG_TRACE);
55  xmlNode *cib_resources = get_xpath_object("//"XML_CIB_TAG_RESOURCES, data_set->input, LOG_TRACE);
56  xmlNode *cib_status = get_xpath_object("//"XML_CIB_TAG_STATUS, data_set->input, LOG_TRACE);
57  xmlNode *cib_tags = get_xpath_object("//"XML_CIB_TAG_TAGS, data_set->input, LOG_TRACE);
58  const char *value = crm_element_value(data_set->input, XML_ATTR_HAVE_QUORUM);
59 
60  crm_trace("Beginning unpack");
61  pe_dataset = data_set;
62 
63  /* reset remaining global variables */
64  data_set->failed = create_xml_node(NULL, "failed-ops");
65 
66  if (data_set->input == NULL) {
67  return FALSE;
68  }
69 
70  if (data_set->now == NULL) {
71  data_set->now = crm_time_new(NULL);
72  }
73 
74  if (data_set->dc_uuid == NULL
75  && data_set->input != NULL
76  && crm_element_value(data_set->input, XML_ATTR_DC_UUID) != NULL) {
77  /* this should always be present */
78  data_set->dc_uuid = crm_element_value_copy(data_set->input, XML_ATTR_DC_UUID);
79  }
80 
82  if (crm_is_true(value)) {
83  set_bit(data_set->flags, pe_flag_have_quorum);
84  }
85 
88 
89  unpack_config(config, data_set);
90 
91  if (is_not_set(data_set->flags, pe_flag_quick_location)
92  && is_not_set(data_set->flags, pe_flag_have_quorum)
93  && data_set->no_quorum_policy != no_quorum_ignore) {
94  crm_warn("Fencing and resource management disabled due to lack of quorum");
95  }
96 
97  unpack_nodes(cib_nodes, data_set);
98 
99  if(is_not_set(data_set->flags, pe_flag_quick_location)) {
100  unpack_remote_nodes(cib_resources, data_set);
101  }
102 
103  unpack_resources(cib_resources, data_set);
104  unpack_tags(cib_tags, data_set);
105 
106  if(is_not_set(data_set->flags, pe_flag_quick_location)) {
107  unpack_status(cib_status, data_set);
108  }
109 
110  set_bit(data_set->flags, pe_flag_have_status);
111  return TRUE;
112 }
113 
114 static void
115 pe_free_resources(GListPtr resources)
116 {
117  resource_t *rsc = NULL;
118  GListPtr iterator = resources;
119 
120  while (iterator != NULL) {
121  rsc = (resource_t *) iterator->data;
122  iterator = iterator->next;
123  rsc->fns->free(rsc);
124  }
125  if (resources != NULL) {
126  g_list_free(resources);
127  }
128 }
129 
130 static void
131 pe_free_actions(GListPtr actions)
132 {
133  GListPtr iterator = actions;
134 
135  while (iterator != NULL) {
136  pe_free_action(iterator->data);
137  iterator = iterator->next;
138  }
139  if (actions != NULL) {
140  g_list_free(actions);
141  }
142 }
143 
144 static void
145 pe_free_nodes(GListPtr nodes)
146 {
147  GListPtr iterator = nodes;
148 
149  while (iterator != NULL) {
150  node_t *node = (node_t *) iterator->data;
151  struct node_shared_s *details = node->details;
152 
153  iterator = iterator->next;
154 
155  crm_trace("deleting node");
156  print_node("delete", node, FALSE);
157 
158  if (details != NULL) {
159  crm_trace("%s is being deleted", details->uname);
160  if (details->attrs != NULL) {
161  g_hash_table_destroy(details->attrs);
162  }
163  if (details->utilization != NULL) {
164  g_hash_table_destroy(details->utilization);
165  }
166  if (details->digest_cache != NULL) {
167  g_hash_table_destroy(details->digest_cache);
168  }
169  g_list_free(details->running_rsc);
170  g_list_free(details->allocated_rsc);
171  free(details);
172  }
173  free(node);
174  }
175  if (nodes != NULL) {
176  g_list_free(nodes);
177  }
178 }
179 
180 void
182 {
183  pe_dataset = NULL;
184  if (data_set == NULL) {
185  return;
186  }
187 
188  clear_bit(data_set->flags, pe_flag_have_status);
189  if (data_set->config_hash != NULL) {
190  g_hash_table_destroy(data_set->config_hash);
191  }
192 
193  if (data_set->singletons != NULL) {
194  g_hash_table_destroy(data_set->singletons);
195  }
196 
197  if (data_set->tickets) {
198  g_hash_table_destroy(data_set->tickets);
199  }
200 
201  if (data_set->template_rsc_sets) {
202  g_hash_table_destroy(data_set->template_rsc_sets);
203  }
204 
205  if (data_set->tags) {
206  g_hash_table_destroy(data_set->tags);
207  }
208 
209  free(data_set->dc_uuid);
210 
211  crm_trace("deleting resources");
212  pe_free_resources(data_set->resources);
213 
214  crm_trace("deleting actions");
215  pe_free_actions(data_set->actions);
216 
217  crm_trace("deleting nodes");
218  pe_free_nodes(data_set->nodes);
219 
220  free_xml(data_set->graph);
221  crm_time_free(data_set->now);
222  free_xml(data_set->input);
223  free_xml(data_set->failed);
224 
225  set_working_set_defaults(data_set);
226 
227  CRM_CHECK(data_set->ordering_constraints == NULL,;
228  );
229  CRM_CHECK(data_set->placement_constraints == NULL,;
230  );
231 }
232 
233 void
235 {
236  pe_dataset = data_set;
237  memset(data_set, 0, sizeof(pe_working_set_t));
238 
239  data_set->dc_uuid = NULL;
240  data_set->order_id = 1;
241  data_set->action_id = 1;
243 
244  data_set->flags = 0x0ULL;
249 }
250 
251 resource_t *
252 pe_find_resource(GListPtr rsc_list, const char *id)
253 {
254  GListPtr rIter = NULL;
255 
256  for (rIter = rsc_list; id && rIter; rIter = rIter->next) {
257  resource_t *parent = rIter->data;
258 
259  resource_t *match =
260  parent->fns->find_rsc(parent, id, NULL, pe_find_renamed | pe_find_current);
261  if (match != NULL) {
262  return match;
263  }
264  }
265  crm_trace("No match for %s", id);
266  return NULL;
267 }
268 
269 node_t *
270 pe_find_node_any(GListPtr nodes, const char *id, const char *uname)
271 {
272  node_t *match = pe_find_node_id(nodes, id);
273 
274  if (match) {
275  return match;
276  }
277  crm_trace("Looking up %s via its uname instead", uname);
278  return pe_find_node(nodes, uname);
279 }
280 
281 node_t *
282 pe_find_node_id(GListPtr nodes, const char *id)
283 {
284  GListPtr gIter = nodes;
285 
286  for (; gIter != NULL; gIter = gIter->next) {
287  node_t *node = (node_t *) gIter->data;
288 
289  if (node && safe_str_eq(node->details->id, id)) {
290  return node;
291  }
292  }
293  /* error */
294  return NULL;
295 }
296 
297 node_t *
298 pe_find_node(GListPtr nodes, const char *uname)
299 {
300  GListPtr gIter = nodes;
301 
302  for (; gIter != NULL; gIter = gIter->next) {
303  node_t *node = (node_t *) gIter->data;
304 
305  if (node && safe_str_eq(node->details->uname, uname)) {
306  return node;
307  }
308  }
309  /* error */
310  return NULL;
311 }
GHashTable * tags
Definition: status.h:125
#define LOG_TRACE
Definition: logging.h:29
gboolean unpack_config(xmlNode *config, pe_working_set_t *data_set)
Definition: unpack.c:141
#define CRM_CHECK(expr, failure_action)
Definition: logging.h:164
GListPtr nodes
Definition: status.h:102
const char * uname
Definition: status.h:134
A dumping ground.
xmlNode * failed
Definition: status.h:110
void set_working_set_defaults(pe_working_set_t *data_set)
Definition: status.c:234
const char * id
Definition: status.h:133
void(* free)(resource_t *)
Definition: complex.h:51
xmlNode * op_defaults
Definition: status.h:111
#define pe_flag_stop_rsc_orphans
Definition: status.h:68
node_t * pe_find_node_any(GListPtr nodes, const char *id, const char *uname)
Definition: status.c:270
char * crm_element_value_copy(xmlNode *data, const char *name)
Definition: xml.c:3893
void print_node(const char *pre_text, node_t *node, gboolean details)
Definition: utils.c:1047
GListPtr resources
Definition: status.h:103
#define XML_ATTR_DC_UUID
Definition: msg_xml.h:111
no_quorum_policy_t no_quorum_policy
Definition: status.h:96
void cleanup_calculations(pe_working_set_t *data_set)
Definition: status.c:181
#define clear_bit(word, bit)
Definition: crm_internal.h:193
GHashTable * tickets
Definition: status.h:99
#define XML_CIB_TAG_NODES
Definition: msg_xml.h:159
xmlNode * get_xpath_object(const char *xpath, xmlNode *xml_obj, int error_level)
Definition: xpath.c:224
char * dc_uuid
Definition: status.h:87
gboolean unpack_resources(xmlNode *xml_resources, pe_working_set_t *data_set)
Definition: unpack.c:782
GListPtr placement_constraints
Definition: status.h:104
#define XML_CIB_TAG_RESOURCES
Definition: msg_xml.h:158
char uname[MAX_NAME]
Definition: internal.h:53
struct node_shared_s * details
Definition: status.h:173
gboolean unpack_status(xmlNode *status, pe_working_set_t *data_set)
Definition: unpack.c:1179
#define crm_warn(fmt, args...)
Definition: logging.h:249
#define set_bit(word, bit)
Definition: crm_internal.h:192
gboolean unpack_nodes(xmlNode *xml_nodes, pe_working_set_t *data_set)
Definition: unpack.c:584
xmlNode * rsc_defaults
Definition: status.h:112
resource_object_functions_t * fns
Definition: status.h:261
pe_working_set_t * pe_dataset
Definition: utils.c:29
#define crm_trace(fmt, args...)
Definition: logging.h:254
gboolean unpack_remote_nodes(xmlNode *xml_resources, pe_working_set_t *data_set)
Definition: unpack.c:669
#define XML_ATTR_HAVE_QUORUM
Definition: msg_xml.h:89
GListPtr actions
Definition: status.h:109
Wrappers for and extensions to libxml2.
GHashTable * config_hash
Definition: status.h:98
xmlNode * create_xml_node(xmlNode *parent, const char *name)
Definition: xml.c:2587
const char * crm_element_value(xmlNode *data, const char *name)
Definition: xml.c:5134
node_t * pe_find_node(GListPtr nodes, const char *uname)
Definition: status.c:298
void free_xml(xmlNode *child)
Definition: xml.c:2705
xmlNode * input
Definition: status.h:83
GListPtr ordering_constraints
Definition: status.h:105
resource_t * pe_find_resource(GListPtr rsc_list, const char *id)
Definition: status.c:252
node_t * pe_find_node_id(GListPtr nodes, const char *id)
Definition: status.c:282
gboolean cluster_status(pe_working_set_t *data_set)
Definition: status.c:51
#define pe_flag_have_status
Definition: status.h:76
#define pe_flag_quick_location
Definition: status.h:79
resource_t *(* find_rsc)(resource_t *parent, const char *search, node_t *node, int flags)
Definition: complex.h:44
crm_time_t * crm_time_new(const char *string)
Definition: iso8601.c:99
#define XML_CIB_TAG_CRMCONFIG
Definition: msg_xml.h:162
#define XML_CIB_TAG_RSCCONFIG
Definition: msg_xml.h:164
void pe_free_action(action_t *action)
Definition: utils.c:1107
#define pe_flag_have_quorum
Definition: status.h:58
#define XML_CIB_TAG_STATUS
Definition: msg_xml.h:157
#define XML_CIB_TAG_TAGS
Definition: msg_xml.h:404
#define pe_flag_is_managed_default
Definition: status.h:60
Definition: status.h:169
#define pe_flag_stop_action_orphans
Definition: status.h:69
gboolean crm_is_true(const char *s)
Definition: strings.c:165
#define pe_flag_symmetric_cluster
Definition: status.h:59
GHashTable * singletons
Definition: status.h:100
unsigned long long flags
Definition: status.h:92
gboolean unpack_tags(xmlNode *xml_tags, pe_working_set_t *data_set)
Definition: unpack.c:842
#define safe_str_eq(a, b)
Definition: util.h:64
#define XML_CIB_TAG_OPCONFIG
Definition: msg_xml.h:163
GList * GListPtr
Definition: crm.h:202
crm_time_t * now
Definition: status.h:84
GHashTable * template_rsc_sets
Definition: status.h:123
xmlNode * graph
Definition: status.h:121
void crm_time_free(crm_time_t *dt)
Definition: iso8601.c:116