pacemaker  1.1.18-7fdfbbe
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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->dc_uuid = crm_element_value_copy(data_set->input,
77  }
78 
80  if (crm_is_true(value)) {
81  set_bit(data_set->flags, pe_flag_have_quorum);
82  }
83 
86 
87  unpack_config(config, data_set);
88 
89  if (is_not_set(data_set->flags, pe_flag_quick_location)
90  && is_not_set(data_set->flags, pe_flag_have_quorum)
91  && data_set->no_quorum_policy != no_quorum_ignore) {
92  crm_warn("Fencing and resource management disabled due to lack of quorum");
93  }
94 
95  unpack_nodes(cib_nodes, data_set);
96 
97  if(is_not_set(data_set->flags, pe_flag_quick_location)) {
98  unpack_remote_nodes(cib_resources, data_set);
99  }
100 
101  unpack_resources(cib_resources, data_set);
102  unpack_tags(cib_tags, data_set);
103 
104  if(is_not_set(data_set->flags, pe_flag_quick_location)) {
105  unpack_status(cib_status, data_set);
106  }
107 
108  set_bit(data_set->flags, pe_flag_have_status);
109  return TRUE;
110 }
111 
112 static void
113 pe_free_resources(GListPtr resources)
114 {
115  resource_t *rsc = NULL;
116  GListPtr iterator = resources;
117 
118  while (iterator != NULL) {
119  rsc = (resource_t *) iterator->data;
120  iterator = iterator->next;
121  rsc->fns->free(rsc);
122  }
123  if (resources != NULL) {
124  g_list_free(resources);
125  }
126 }
127 
128 static void
129 pe_free_actions(GListPtr actions)
130 {
131  GListPtr iterator = actions;
132 
133  while (iterator != NULL) {
134  pe_free_action(iterator->data);
135  iterator = iterator->next;
136  }
137  if (actions != NULL) {
138  g_list_free(actions);
139  }
140 }
141 
142 static void
143 pe_free_nodes(GListPtr nodes)
144 {
145  GListPtr iterator = nodes;
146 
147  while (iterator != NULL) {
148  node_t *node = (node_t *) iterator->data;
149  struct node_shared_s *details = node->details;
150 
151  iterator = iterator->next;
152 
153  crm_trace("deleting node");
154  print_node("delete", node, FALSE);
155 
156  if (details != NULL) {
157  crm_trace("%s is being deleted", details->uname);
158  if (details->attrs != NULL) {
159  g_hash_table_destroy(details->attrs);
160  }
161  if (details->utilization != NULL) {
162  g_hash_table_destroy(details->utilization);
163  }
164  if (details->digest_cache != NULL) {
165  g_hash_table_destroy(details->digest_cache);
166  }
167  g_list_free(details->running_rsc);
168  g_list_free(details->allocated_rsc);
169  free(details);
170  }
171  free(node);
172  }
173  if (nodes != NULL) {
174  g_list_free(nodes);
175  }
176 }
177 
178 void
180 {
181  pe_dataset = NULL;
182  if (data_set == NULL) {
183  return;
184  }
185 
186  clear_bit(data_set->flags, pe_flag_have_status);
187  if (data_set->config_hash != NULL) {
188  g_hash_table_destroy(data_set->config_hash);
189  }
190 
191  if (data_set->singletons != NULL) {
192  g_hash_table_destroy(data_set->singletons);
193  }
194 
195  if (data_set->tickets) {
196  g_hash_table_destroy(data_set->tickets);
197  }
198 
199  if (data_set->template_rsc_sets) {
200  g_hash_table_destroy(data_set->template_rsc_sets);
201  }
202 
203  if (data_set->tags) {
204  g_hash_table_destroy(data_set->tags);
205  }
206 
207  free(data_set->dc_uuid);
208 
209  crm_trace("deleting resources");
210  pe_free_resources(data_set->resources);
211 
212  crm_trace("deleting actions");
213  pe_free_actions(data_set->actions);
214 
215  crm_trace("deleting nodes");
216  pe_free_nodes(data_set->nodes);
217 
218  free_xml(data_set->graph);
219  crm_time_free(data_set->now);
220  free_xml(data_set->input);
221  free_xml(data_set->failed);
222 
223  set_working_set_defaults(data_set);
224 
225  CRM_CHECK(data_set->ordering_constraints == NULL,;
226  );
227  CRM_CHECK(data_set->placement_constraints == NULL,;
228  );
229 }
230 
231 void
233 {
234  pe_dataset = data_set;
235  memset(data_set, 0, sizeof(pe_working_set_t));
236 
237  data_set->order_id = 1;
238  data_set->action_id = 1;
240 
241  data_set->flags = 0x0ULL;
246 }
247 
248 resource_t *
249 pe_find_resource(GListPtr rsc_list, const char *id)
250 {
251  return pe_find_resource_with_flags(rsc_list, id, pe_find_renamed);
252 }
253 
254 resource_t *
255 pe_find_resource_with_flags(GListPtr rsc_list, const char *id, enum pe_find flags)
256 {
257  GListPtr rIter = NULL;
258 
259  for (rIter = rsc_list; id && rIter; rIter = rIter->next) {
260  resource_t *parent = rIter->data;
261 
262  resource_t *match =
263  parent->fns->find_rsc(parent, id, NULL, flags);
264  if (match != NULL) {
265  return match;
266  }
267  }
268  crm_trace("No match for %s", id);
269  return NULL;
270 }
271 
272 node_t *
273 pe_find_node_any(GListPtr nodes, const char *id, const char *uname)
274 {
275  node_t *match = pe_find_node_id(nodes, id);
276 
277  if (match) {
278  return match;
279  }
280  crm_trace("Looking up %s via its uname instead", uname);
281  return pe_find_node(nodes, uname);
282 }
283 
284 node_t *
285 pe_find_node_id(GListPtr nodes, const char *id)
286 {
287  GListPtr gIter = nodes;
288 
289  for (; gIter != NULL; gIter = gIter->next) {
290  node_t *node = (node_t *) gIter->data;
291 
292  if (node && safe_str_eq(node->details->id, id)) {
293  return node;
294  }
295  }
296  /* error */
297  return NULL;
298 }
299 
300 node_t *
301 pe_find_node(GListPtr nodes, const char *uname)
302 {
303  GListPtr gIter = nodes;
304 
305  for (; gIter != NULL; gIter = gIter->next) {
306  node_t *node = (node_t *) gIter->data;
307 
308  if (node && safe_str_eq(node->details->uname, uname)) {
309  return node;
310  }
311  }
312  /* error */
313  return NULL;
314 }
GHashTable * tags
Definition: status.h:130
#define LOG_TRACE
Definition: logging.h:29
gboolean unpack_config(xmlNode *config, pe_working_set_t *data_set)
Definition: unpack.c:176
#define CRM_CHECK(expr, failure_action)
Definition: logging.h:164
GListPtr nodes
Definition: status.h:107
const char * uname
Definition: status.h:139
A dumping ground.
xmlNode * failed
Definition: status.h:115
const char * id
Definition: status.h:138
xmlNode * op_defaults
Definition: status.h:116
void(* free)(resource_t *)
Definition: complex.h:51
#define pe_flag_stop_rsc_orphans
Definition: status.h:70
char * crm_element_value_copy(xmlNode *data, const char *name)
Definition: xml.c:3869
void print_node(const char *pre_text, node_t *node, gboolean details)
Definition: utils.c:1240
GListPtr resources
Definition: status.h:108
#define XML_ATTR_DC_UUID
Definition: msg_xml.h:112
node_t * pe_find_node(GListPtr node_list, const char *uname)
Definition: status.c:301
no_quorum_policy_t no_quorum_policy
Definition: status.h:99
#define clear_bit(word, bit)
Definition: crm_internal.h:191
GHashTable * tickets
Definition: status.h:102
resource_t *(* find_rsc)(resource_t *parent, const char *search, node_t *node, int flags)
Definition: complex.h:44
#define XML_CIB_TAG_NODES
Definition: msg_xml.h:160
xmlNode * get_xpath_object(const char *xpath, xmlNode *xml_obj, int error_level)
Definition: xpath.c:224
char * dc_uuid
Definition: status.h:90
gboolean unpack_resources(xmlNode *xml_resources, pe_working_set_t *data_set)
Definition: unpack.c:737
GListPtr placement_constraints
Definition: status.h:109
#define XML_CIB_TAG_RESOURCES
Definition: msg_xml.h:159
char uname[MAX_NAME]
Definition: internal.h:53
struct node_shared_s * details
Definition: status.h:178
gboolean unpack_status(xmlNode *status, pe_working_set_t *data_set)
Definition: unpack.c:1157
#define crm_warn(fmt, args...)
Definition: logging.h:249
void cleanup_calculations(pe_working_set_t *data_set)
Definition: status.c:179
#define set_bit(word, bit)
Definition: crm_internal.h:190
gboolean unpack_nodes(xmlNode *xml_nodes, pe_working_set_t *data_set)
Definition: unpack.c:525
xmlNode * rsc_defaults
Definition: status.h:117
resource_object_functions_t * fns
Definition: status.h:266
pe_working_set_t * pe_dataset
Definition: utils.c:31
#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:611
void set_working_set_defaults(pe_working_set_t *data_set)
Definition: status.c:232
pe_find
Definition: status.h:51
#define XML_ATTR_HAVE_QUORUM
Definition: msg_xml.h:90
GListPtr actions
Definition: status.h:114
Wrappers for and extensions to libxml2.
GHashTable * config_hash
Definition: status.h:101
xmlNode * create_xml_node(xmlNode *parent, const char *name)
Definition: xml.c:2588
const char * crm_element_value(xmlNode *data, const char *name)
Definition: xml.c:5165
void free_xml(xmlNode *child)
Definition: xml.c:2706
xmlNode * input
Definition: status.h:86
GListPtr ordering_constraints
Definition: status.h:110
node_t * pe_find_node_any(GListPtr node_list, const char *id, const char *uname)
Definition: status.c:273
#define pe_flag_have_status
Definition: status.h:79
#define pe_flag_quick_location
Definition: status.h:82
gboolean cluster_status(pe_working_set_t *data_set)
Definition: status.c:51
crm_time_t * crm_time_new(const char *string)
Definition: iso8601.c:99
#define XML_CIB_TAG_CRMCONFIG
Definition: msg_xml.h:163
#define XML_CIB_TAG_RSCCONFIG
Definition: msg_xml.h:165
resource_t * pe_find_resource_with_flags(GListPtr rsc_list, const char *id, enum pe_find flags)
Definition: status.c:255
node_t * pe_find_node_id(GListPtr node_list, const char *id)
Definition: status.c:285
void pe_free_action(action_t *action)
Definition: utils.c:1300
#define pe_flag_have_quorum
Definition: status.h:60
#define XML_CIB_TAG_STATUS
Definition: msg_xml.h:158
#define XML_CIB_TAG_TAGS
Definition: msg_xml.h:416
#define pe_flag_is_managed_default
Definition: status.h:62
Definition: status.h:174
#define pe_flag_stop_action_orphans
Definition: status.h:71
gboolean crm_is_true(const char *s)
Definition: strings.c:165
#define pe_flag_symmetric_cluster
Definition: status.h:61
GHashTable * singletons
Definition: status.h:105
unsigned long long flags
Definition: status.h:95
gboolean unpack_tags(xmlNode *xml_tags, pe_working_set_t *data_set)
Definition: unpack.c:797
resource_t * pe_find_resource(GListPtr rsc_list, const char *id_rh)
Definition: status.c:249
#define safe_str_eq(a, b)
Definition: util.h:72
#define XML_CIB_TAG_OPCONFIG
Definition: msg_xml.h:164
GList * GListPtr
Definition: crm.h:218
crm_time_t * now
Definition: status.h:87
GHashTable * template_rsc_sets
Definition: status.h:128
uint64_t flags
Definition: remote.c:156
xmlNode * graph
Definition: status.h:126
void crm_time_free(crm_time_t *dt)
Definition: iso8601.c:116