root/lib/pengine/status.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. cluster_status
  2. pe_free_resources
  3. pe_free_actions
  4. pe_free_nodes
  5. cleanup_calculations
  6. set_working_set_defaults
  7. pe_find_resource
  8. pe_find_resource_with_flags
  9. pe_find_node_any
  10. pe_find_node_id
  11. pe_find_node

   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
  51 cluster_status(pe_working_set_t * data_set)
     /* [previous][next][first][last][top][bottom][index][help] */
  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,
  76                                                    XML_ATTR_DC_UUID);
  77     }
  78 
  79     clear_bit(data_set->flags, pe_flag_have_quorum);
  80     if (crm_is_true(value)) {
  81         set_bit(data_set->flags, pe_flag_have_quorum);
  82     }
  83 
  84     data_set->op_defaults = get_xpath_object("//"XML_CIB_TAG_OPCONFIG, data_set->input, LOG_TRACE);
  85     data_set->rsc_defaults = get_xpath_object("//"XML_CIB_TAG_RSCCONFIG, data_set->input, LOG_TRACE);
  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)
     /* [previous][next][first][last][top][bottom][index][help] */
 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)
     /* [previous][next][first][last][top][bottom][index][help] */
 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)
     /* [previous][next][first][last][top][bottom][index][help] */
 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
 179 cleanup_calculations(pe_working_set_t * data_set)
     /* [previous][next][first][last][top][bottom][index][help] */
 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
 232 set_working_set_defaults(pe_working_set_t * data_set)
     /* [previous][next][first][last][top][bottom][index][help] */
 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;
 239     data_set->no_quorum_policy = no_quorum_freeze;
 240 
 241     data_set->flags = 0x0ULL;
 242     set_bit(data_set->flags, pe_flag_stop_rsc_orphans);
 243     set_bit(data_set->flags, pe_flag_symmetric_cluster);
 244     set_bit(data_set->flags, pe_flag_is_managed_default);
 245     set_bit(data_set->flags, pe_flag_stop_action_orphans);
 246 }
 247 
 248 resource_t *
 249 pe_find_resource(GListPtr rsc_list, const char *id)
     /* [previous][next][first][last][top][bottom][index][help] */
 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)
     /* [previous][next][first][last][top][bottom][index][help] */
 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)
     /* [previous][next][first][last][top][bottom][index][help] */
 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)
     /* [previous][next][first][last][top][bottom][index][help] */
 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)
     /* [previous][next][first][last][top][bottom][index][help] */
 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 }

/* [previous][next][first][last][top][bottom][index][help] */