diff --git a/crm/pengine/pengine.c b/crm/pengine/pengine.c index 43b976d1f7..0f0c282d41 100755 --- a/crm/pengine/pengine.c +++ b/crm/pengine/pengine.c @@ -1,344 +1,344 @@ -/* $Id: pengine.c,v 1.94 2005/10/14 08:29:26 andrew Exp $ */ +/* $Id: pengine.c,v 1.95 2005/10/14 09:47:00 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include #include crm_data_t * do_calculations( pe_working_set_t *data_set, crm_data_t *xml_input, ha_time_t *now); gboolean was_processing_error = FALSE; gboolean was_processing_warning = FALSE; gboolean was_config_error = FALSE; gboolean was_config_warning = FALSE; gboolean process_pe_message(HA_Message *msg, crm_data_t * xml_data, IPC_Channel *sender) { const char *sys_to = cl_get_string(msg, F_CRM_SYS_TO); const char *op = cl_get_string(msg, F_CRM_TASK); const char *ref = cl_get_string(msg, XML_ATTR_REFERENCE); crm_debug_3("Processing %s op (ref=%s)...", op, ref); if(op == NULL){ /* error */ } else if(strcmp(op, CRM_OP_HELLO) == 0) { /* ignore */ } else if(safe_str_eq(cl_get_string(msg, F_CRM_MSG_TYPE), XML_ATTR_RESPONSE)) { /* ignore */ } else if(sys_to == NULL || strcmp(sys_to, CRM_SYSTEM_PENGINE) != 0) { crm_debug_3("Bad sys-to %s", crm_str(sys_to)); return FALSE; } else if(strcmp(op, CRM_OP_PECALC) == 0) { pe_working_set_t data_set; crm_data_t *generation = create_xml_node(NULL, XML_TAG_CIB); crm_data_t *status = get_object_root( XML_CIB_TAG_STATUS, xml_data); crm_data_t *log_input = status; log_input = xml_data; copy_in_properties(generation, xml_data); crm_log_xml_info(generation, "[generation]"); crm_log_xml_debug(status, "[status]"); #if 0 char *xml_buffer = NULL; char *xml_buffer_ptr = NULL; int max_xml = MAXLINE - 8; xml_buffer = dump_xml_unformatted(generation); LogToCircularBuffer(input_buffer, LOG_INFO, "Generation: %s", xml_buffer); crm_free(xml_buffer); xml_buffer = dump_xml_unformatted(status); xml_buffer_ptr = xml_buffer; while(xml_buffer_ptr != NULL) { LogToCircularBuffer(input_buffer, LOG_INFO, "PE xml: %s", xml_buffer_ptr); if(strlen(xml_buffer_ptr) > max_xml) { xml_buffer_ptr = xml_buffer_ptr + max_xml; } else { xml_buffer_ptr = NULL;; } } crm_free(xml_buffer); #endif was_processing_error = FALSE; was_processing_warning = FALSE; crm_zero_mem_stats(NULL); do_calculations(&data_set, xml_data, NULL); crm_log_xml_debug_3(data_set.graph, "[out]"); if (send_ipc_reply(sender, msg, data_set.graph) ==FALSE) { crm_err("Answer could not be sent"); } + data_set.input = NULL; cleanup_calculations(&data_set); if(is_ipc_empty(sender) && crm_mem_stats(NULL)) { pe_warn("Unfree'd memory"); } if(was_processing_error) { crm_info("ERRORs found during PE processing." " Input follows:"); crm_log_xml_info(log_input, "[input]"); } else if(was_processing_warning) { crm_debug("WARNINGs found during PE processing." " Input follows:"); crm_log_xml_debug(log_input, "[input]"); } else if(crm_log_level > LOG_DEBUG) { crm_log_xml_debug_2(log_input, "[input]"); } if(was_config_error) { crm_info("Configuration ERRORs found during PE processing." " Please run \"crm_verify -L\" to identify issues."); } else if(was_processing_warning) { crm_info("Configuration WARNINGs found during PE processing." " Please run \"crm_verify -L\" to identify issues."); } free_xml(generation); } else if(strcmp(op, CRM_OP_QUIT) == 0) { crm_warn("Received quit message, terminating"); exit(0); } return TRUE; } #define MEMCHECK_STAGE_0 0 #define check_and_exit(stage) cleanup_calculations(data_set); \ - free_xml(xml_input); \ crm_mem_stats(NULL); \ crm_err("Exiting: stage %d", stage); \ exit(1); crm_data_t * do_calculations(pe_working_set_t *data_set, crm_data_t *xml_input, ha_time_t *now) { /* pe_debug_on(); */ set_working_set_defaults(data_set); - data_set->input = copy_xml(xml_input); + data_set->input = xml_input; data_set->now = now; if(data_set->now == NULL) { data_set->now = new_ha_date(TRUE); } #if MEMCHECK_STAGE_SETUP check_and_exit(-1); #endif crm_debug_5("unpack"); stage0(data_set); #if MEMCHECK_STAGE_0 check_and_exit(0); #endif crm_debug_5("apply placement constraints"); stage1(data_set); #if MEMCHECK_STAGE_1 check_and_exit(1); #endif crm_debug_5("color resources"); stage2(data_set); #if MEMCHECK_STAGE_2 check_and_exit(2); #endif /* unused */ stage3(data_set); #if MEMCHECK_STAGE_3 check_and_exit(3); #endif crm_debug_5("assign nodes to colors"); stage4(data_set); #if MEMCHECK_STAGE_4 check_and_exit(4); #endif crm_debug_5("creating actions and internal ording constraints"); stage5(data_set); #if MEMCHECK_STAGE_5 check_and_exit(5); #endif crm_debug_5("processing fencing and shutdown cases"); stage6(data_set); #if MEMCHECK_STAGE_6 check_and_exit(6); #endif crm_debug_5("applying ordering constraints"); stage7(data_set); #if MEMCHECK_STAGE_7 check_and_exit(7); #endif crm_debug_5("creating transition graph"); stage8(data_set); #if MEMCHECK_STAGE_8 check_and_exit(8); #endif crm_debug_2("=#=#=#=#= Summary =#=#=#=#="); crm_debug_2("========= All Actions ========="); slist_iter(action, action_t, data_set->actions, lpc, log_action(LOG_DEBUG_2, "\t", action, TRUE) ); crm_debug_2("\t========= Set %d (Un-runnable) =========", -1); crm_action_debug_2( slist_iter(action, action_t, data_set->actions, lpc, if(action->optional == FALSE && action->runnable == FALSE && action->pseudo == FALSE) { log_action(LOG_DEBUG_2, "\t", action, TRUE); } ) ); return data_set->graph; } void cleanup_calculations(pe_working_set_t *data_set) { GListPtr iterator = NULL; if(data_set == NULL) { return; } if(data_set->config_hash != NULL) { g_hash_table_destroy(data_set->config_hash); } crm_free(data_set->dc_uuid); crm_free(data_set->transition_idle_timeout); crm_debug_3("deleting order cons"); pe_free_ordering(data_set->ordering_constraints); crm_debug_3("deleting actions"); pe_free_actions(data_set->actions); crm_debug_3("deleting resources"); pe_free_resources(data_set->resources); crm_debug_3("deleting nodes"); pe_free_nodes(data_set->nodes); crm_debug_3("deleting colors"); pe_free_colors(data_set->colors); crm_debug_3("deleting node cons"); iterator = data_set->placement_constraints; while(iterator) { pe_free_rsc_to_node(iterator->data); iterator = iterator->next; } if(data_set->placement_constraints != NULL) { g_list_free(data_set->placement_constraints); } free_xml(data_set->graph); free_ha_date(data_set->now); free_xml(data_set->input); } void set_working_set_defaults(pe_working_set_t *data_set) { data_set->input = NULL; data_set->now = NULL; data_set->graph = NULL; data_set->transition_idle_timeout = crm_strdup("60s"); data_set->dc_uuid = NULL; data_set->dc_node = NULL; data_set->have_quorum = FALSE; data_set->stonith_enabled = FALSE; data_set->symmetric_cluster = TRUE; data_set->no_quorum_policy = no_quorum_freeze; data_set->is_managed_default = TRUE; data_set->stop_action_orphans = TRUE; data_set->stop_rsc_orphans = FALSE; data_set->config_hash = NULL; data_set->nodes = NULL; data_set->resources = NULL; data_set->ordering_constraints = NULL; data_set->placement_constraints = NULL; data_set->no_color = NULL; data_set->colors = NULL; data_set->actions = NULL; data_set->num_synapse = 0; data_set->max_valid_nodes = 0; data_set->order_id = 1; data_set->action_id = 1; data_set->color_id = 0; } diff --git a/crm/pengine/ptest.c b/crm/pengine/ptest.c index beb88b4aaf..91a12a0035 100644 --- a/crm/pengine/ptest.c +++ b/crm/pengine/ptest.c @@ -1,318 +1,316 @@ -/* $Id: ptest.c,v 1.66 2005/09/30 13:01:16 andrew Exp $ */ +/* $Id: ptest.c,v 1.67 2005/10/14 09:47:00 andrew Exp $ */ /* * Copyright (C) 2004 Andrew Beekhof * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include #include #include #include #define OPTARGS "V?X:wD:" #ifdef HAVE_GETOPT_H # include #endif #include #include #include gboolean inhibit_exit = FALSE; extern crm_data_t * do_calculations( pe_working_set_t *data_set, crm_data_t *xml_input, ha_time_t *now); extern void cleanup_calculations(pe_working_set_t *data_set); FILE *dot_strm = NULL; #define DOT_PREFIX "PE_DOT: " /* #define DOT_PREFIX "" */ #define dot_write(fmt...) if(dot_strm != NULL) { \ fprintf(dot_strm, fmt); \ fprintf(dot_strm, "\n"); \ fflush(dot_strm); \ } else { \ crm_debug(DOT_PREFIX""fmt); \ } static void init_dotfile(void) { dot_write("digraph \"g\" {"); dot_write(" size = \"30,30\""); /* dot_write(" graph ["); */ /* dot_write(" fontsize = \"12\""); */ /* dot_write(" fontname = \"Times-Roman\""); */ /* dot_write(" fontcolor = \"black\""); */ /* dot_write(" bb = \"0,0,398.922306,478.927856\""); */ /* dot_write(" color = \"black\""); */ /* dot_write(" ]"); */ /* dot_write(" node ["); */ /* dot_write(" fontsize = \"12\""); */ /* dot_write(" fontname = \"Times-Roman\""); */ /* dot_write(" fontcolor = \"black\""); */ /* dot_write(" shape = \"ellipse\""); */ /* dot_write(" color = \"black\""); */ /* dot_write(" ]"); */ /* dot_write(" edge ["); */ /* dot_write(" fontsize = \"12\""); */ /* dot_write(" fontname = \"Times-Roman\""); */ /* dot_write(" fontcolor = \"black\""); */ /* dot_write(" color = \"black\""); */ /* dot_write(" ]"); */ } static char * create_action_name(action_t *action) { char *action_name = NULL; const char *action_host = NULL; if(action->node) { action_host = action->node->details->uname; action_name = crm_concat(action->uuid, action_host, ' '); } else if(action->pseudo) { action_name = crm_strdup(action->uuid); } else { action_host = ""; action_name = crm_concat(action->uuid, action_host, ' '); } return action_name; } int main(int argc, char **argv) { const char *fake_now = NULL; ha_time_t *a_date = NULL; crm_data_t * cib_object = NULL; int argerr = 0; int flag; char *msg_buffer = NULL; gboolean optional = FALSE; pe_working_set_t data_set; const char *xml_file = NULL; const char *dot_file = NULL; cl_log_set_entity("ptest"); cl_log_set_facility(LOG_USER); set_crm_log_level(LOG_CRIT-1); while (1) { #ifdef HAVE_GETOPT_H int option_index = 0; static struct option long_options[] = { /* Top-level Options */ {F_CRM_DATA, 1, 0, 'X'}, {"help", 0, 0, 0}, {0, 0, 0, 0} }; #endif #ifdef HAVE_GETOPT_H flag = getopt_long(argc, argv, OPTARGS, long_options, &option_index); #else flag = getopt(argc, argv, OPTARGS); #endif if (flag == -1) break; switch(flag) { #ifdef HAVE_GETOPT_H case 0: printf("option %s", long_options[option_index].name); if (optarg) printf(" with arg %s", optarg); printf("\n"); break; #endif case 'w': inhibit_exit = TRUE; break; case 'X': xml_file = crm_strdup(optarg); break; case 'D': dot_file = crm_strdup(optarg); break; case 'V': cl_log_enable_stderr(TRUE); alter_debug(DEBUG_INC); break; default: printf("?? getopt returned character code 0%o ??\n", flag); ++argerr; break; } } if (optind < argc) { printf("non-option ARGV-elements: "); while (optind < argc) { printf("%s ", argv[optind++]); } printf("\n"); } if (optind > argc) { ++argerr; } if (argerr) { crm_err("%d errors in option parsing", argerr); } crm_info("=#=#=#=#= Getting XML =#=#=#=#="); crm_zero_mem_stats(NULL); if(xml_file != NULL) { FILE *xml_strm = fopen(xml_file, "r"); cib_object = file2xml(xml_strm); } else { cib_object = stdin2xml(); } #ifdef MCHECK mtrace(); #endif CRM_DEV_ASSERT(cib_object != NULL); crm_notice("Required feature set: %s", feature_set(cib_object)); do_id_check(cib_object, NULL); fake_now = crm_element_value(cib_object, "fake_now"); if(fake_now != NULL) { char *fake_now_copy = crm_strdup(fake_now); char *fake_now_mutable = fake_now_copy; a_date = parse_date(&fake_now_mutable); log_date(LOG_WARNING, "Set fake 'now' to", a_date, ha_log_date|ha_log_time); log_date(LOG_WARNING, "Set fake 'now' to (localtime)", a_date, ha_log_date|ha_log_time|ha_log_local); crm_free(fake_now_copy); } do_calculations(&data_set, cib_object, a_date); msg_buffer = dump_xml_formatted(data_set.graph); fprintf(stdout, "%s\n", msg_buffer); fflush(stdout); crm_free(msg_buffer); dot_strm = fopen(dot_file, "w"); init_dotfile(); slist_iter( action, action_t, data_set.actions, lpc, char *action_name = create_action_name(action); crm_debug_3("Action %d: %p", action->id, action); if(action->dumped == FALSE) { if(action->rsc != NULL && action->rsc->is_managed == FALSE) { dot_write("\"%s\" [ font_color=black style=filled fillcolor=%s ]", action_name, "purple"); } else if(action->optional) { dot_write("\"%s\" [ style=\"dashed\" color=\"%s\" fontcolor=\"%s\" ]", action_name, "blue", action->pseudo?"orange":"black"); } else { dot_write("\"%s\" [ font_color=purple style=filled fillcolor=%s ]", action_name, "red"); CRM_DEV_ASSERT(action->runnable == FALSE); } } else { dot_write("\"%s\" [ style=bold color=\"%s\" fontcolor=\"%s\" ]", action_name, "green", action->pseudo?"orange":"black"); } crm_free(action_name); ); slist_iter( action, action_t, data_set.actions, lpc, int last_action = -1; slist_iter( before, action_wrapper_t, action->actions_before, lpc2, char *before_name = NULL; char *after_name = NULL; optional = FALSE; if(last_action == before->action->id) { continue; } last_action = before->action->id; if(action->dumped && before->action->dumped) { } else if(action->optional || before->action->optional) { optional = TRUE; } before_name = create_action_name(before->action); after_name = create_action_name(action); dot_write("\"%s\" -> \"%s\" [ style = %s]", before_name, after_name, optional?"dashed":"bold"); crm_free(before_name); crm_free(after_name); ); ); dot_write("}"); cleanup_calculations(&data_set); - free_xml(cib_object); - crm_mem_stats(NULL); CRM_DEV_ASSERT(crm_mem_stats(NULL) == FALSE); #ifdef MCHECK muntrace(); #endif /* required for MallocDebug.app */ if(inhibit_exit) { GMainLoop* mainloop = g_main_new(FALSE); g_main_run(mainloop); } return 0; }