diff --git a/crm/cib/callbacks.c b/crm/cib/callbacks.c index 64d1010582..33fac5e0ef 100644 --- a/crm/cib/callbacks.c +++ b/crm/cib/callbacks.c @@ -1,1025 +1,1027 @@ -/* $Id: callbacks.c,v 1.22 2005/02/19 15:06:07 alan Exp $ */ +/* $Id: callbacks.c,v 1.23 2005/02/19 18:11:03 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 #include #include #include #include #include #include #include #include gint cib_GCompareFunc(gconstpointer a, gconstpointer b); gboolean cib_msg_timeout(gpointer data); void cib_GHFunc(gpointer key, gpointer value, gpointer user_data); GHashTable *peer_hash = NULL; int next_client_id = 0; gboolean cib_is_master = FALSE; gboolean cib_have_quorum = FALSE; GHashTable *client_list = NULL; extern const char *cib_our_uname; extern ll_cluster_t *hb_conn; /* technically bump does modify the cib... * but we want to split the "bump" from the "sync" */ cib_operation_t cib_server_ops[] = { {NULL, FALSE, FALSE, FALSE, FALSE, cib_process_default}, {CRM_OP_NOOP, FALSE, FALSE, FALSE, FALSE, cib_process_default}, {CRM_OP_RETRIVE_CIB, FALSE, FALSE, FALSE, FALSE, cib_process_query}, {CRM_OP_CIB_SLAVE, FALSE, TRUE, FALSE, FALSE, cib_process_readwrite}, {CRM_OP_CIB_SLAVEALL,TRUE, TRUE, FALSE, FALSE, cib_process_readwrite}, {CRM_OP_CIB_MASTER, FALSE, TRUE, FALSE, FALSE, cib_process_readwrite}, {CRM_OP_CIB_ISMASTER,FALSE, TRUE, FALSE, FALSE, cib_process_readwrite}, {CRM_OP_CIB_BUMP, FALSE, TRUE, TRUE, FALSE, cib_process_bump}, {CRM_OP_CIB_REPLACE, TRUE, TRUE, TRUE, TRUE, cib_process_replace}, {CRM_OP_CIB_CREATE, TRUE, TRUE, TRUE, TRUE, cib_process_modify}, {CRM_OP_CIB_UPDATE, TRUE, TRUE, TRUE, TRUE, cib_process_modify}, {CRM_OP_JOINACK, TRUE, TRUE, TRUE, TRUE, cib_process_modify}, {CRM_OP_SHUTDOWN_REQ,TRUE, TRUE, TRUE, TRUE, cib_process_modify}, {CRM_OP_CIB_DELETE, TRUE, TRUE, TRUE, TRUE, cib_process_modify}, {CRM_OP_CIB_QUERY, FALSE, FALSE, TRUE, FALSE, cib_process_query}, {CRM_OP_QUIT, FALSE, TRUE, FALSE, FALSE, cib_process_quit}, {CRM_OP_PING, FALSE, FALSE, FALSE, FALSE, cib_process_ping}, {CRM_OP_CIB_ERASE, TRUE, TRUE, TRUE, FALSE, cib_process_erase} }; int send_via_callback_channel(HA_Message *msg, const char *token); enum cib_errors cib_process_command( const HA_Message *request, HA_Message **reply, gboolean privileged); gboolean cib_common_callback( IPC_Channel *channel, gpointer user_data, gboolean privileged); enum cib_errors cib_get_operation_id(const HA_Message * msg, int *operation); gboolean cib_process_disconnect(IPC_Channel *channel, cib_client_t *cib_client); gboolean cib_client_connect(IPC_Channel *channel, gpointer user_data) { gboolean auth_failed = FALSE; gboolean can_connect = TRUE; gboolean (*client_callback)(IPC_Channel *channel, gpointer user_data) = NULL; cib_client_t *new_client = NULL; - crm_debug("Connecting channel"); + crm_devel("Connecting channel"); if (channel == NULL) { crm_err("Channel was NULL"); can_connect = FALSE; } else if (channel->ch_status == IPC_DISCONNECT) { crm_err("Channel was disconnected"); can_connect = FALSE; } else if(user_data == NULL) { crm_err("user_data must contain channel name"); can_connect = FALSE; } else { crm_malloc(new_client, sizeof(cib_client_t)); new_client->id = NULL; new_client->callback_id = NULL; new_client->source = NULL; new_client->channel = channel; new_client->channel_name = user_data; new_client->delegated_calls = NULL; - crm_debug("Created channel %p for channel %s", + crm_devel("Created channel %p for channel %s", new_client, new_client->channel_name); client_callback = NULL; /* choose callback and do auth based on channel_name */ if(safe_str_eq(new_client->channel_name, cib_channel_callback)) { client_callback = cib_null_callback; } else { uuid_t client_id; uuid_generate(client_id); crm_malloc(new_client->id, sizeof(char)*36); uuid_unparse(client_id, new_client->id); new_client->id[35] = EOS; uuid_generate(client_id); crm_malloc(new_client->callback_id, sizeof(char)*36); uuid_unparse(client_id, new_client->callback_id); new_client->callback_id[35] = EOS; client_callback = cib_ro_callback; if(safe_str_eq(new_client->channel_name, cib_channel_rw)) { client_callback = cib_rw_callback; } } } if(auth_failed) { crm_err("Connection to %s channel failed authentication", (char *)user_data); can_connect = FALSE; } if(can_connect == FALSE) { if(new_client) { crm_free(new_client->id); crm_free(new_client->callback_id); } crm_free(new_client); return FALSE; } channel->ops->set_recv_qlen(channel, 100); channel->ops->set_send_qlen(channel, 100); if(client_callback != NULL) { new_client->source = G_main_add_IPC_Channel( G_PRIORITY_LOW, channel, FALSE, client_callback, new_client, default_ipc_connection_destroy); } if(client_callback != cib_null_callback) { /* send msg to client with uuid to use when signing up for * callback channel */ HA_Message *reg_msg = ha_msg_new(3); ha_msg_add(reg_msg, F_CIB_OPERATION, CRM_OP_REGISTER); ha_msg_add(reg_msg, F_CIB_CLIENTID, new_client->id); ha_msg_add( reg_msg, F_CIB_CALLBACK_TOKEN, new_client->callback_id); msg2ipcchan(reg_msg, channel); crm_msg_del(reg_msg); /* make sure we can find ourselves later for sync calls * redirected to the master instance */ g_hash_table_insert(client_list, new_client->id, new_client); } - crm_debug("Channel %s connected for client %s", + crm_devel("Channel %s connected for client %s", new_client->channel_name, new_client->id); return TRUE; } gboolean cib_rw_callback(IPC_Channel *channel, gpointer user_data) { return cib_common_callback(channel, user_data, TRUE); } gboolean cib_ro_callback(IPC_Channel *channel, gpointer user_data) { return cib_common_callback(channel, user_data, FALSE); } gboolean cib_null_callback(IPC_Channel *channel, gpointer user_data) { gboolean did_disconnect = TRUE; HA_Message *op_request = NULL; cib_client_t *cib_client = user_data; cib_client_t *hash_client = NULL; const char *type = NULL; const char *uuid_ticket = NULL; if(cib_client == NULL) { crm_err("Discarding IPC message from unknown source" " on callback channel."); return FALSE; } while(channel->ops->is_message_pending(channel)) { if (channel->ch_status == IPC_DISCONNECT) { /* The message which was pending for us is that * the IPC status is now IPC_DISCONNECT */ break; } op_request = msgfromIPC_noauth(channel); type = cl_get_string(op_request, F_CIB_OPERATION); if(safe_str_neq(type, CRM_OP_REGISTER) ) { crm_warn("Discarding IPC message from %s on callback channel", cib_client->id); crm_msg_del(op_request); continue; } uuid_ticket = cl_get_string(op_request, F_CIB_CALLBACK_TOKEN); hash_client = g_hash_table_lookup(client_list, uuid_ticket); if(hash_client != NULL) { crm_err("Duplicate registration request... disconnecting"); crm_msg_del(op_request); return FALSE; } cib_client->id = crm_strdup(uuid_ticket); g_hash_table_insert(client_list, cib_client->id, cib_client); crm_info("Registered %s on %s channel", cib_client->id, cib_client->channel_name); crm_msg_del(op_request); op_request = ha_msg_new(2); ha_msg_add(op_request, F_CIB_OPERATION, CRM_OP_REGISTER); ha_msg_add(op_request, F_CIB_CLIENTID, cib_client->id); msg2ipcchan(op_request, channel); crm_msg_del(op_request); } did_disconnect = cib_process_disconnect(channel, cib_client); if(did_disconnect) { crm_info("Client disconnected"); } return did_disconnect; } gboolean cib_common_callback( IPC_Channel *channel, gpointer user_data, gboolean privileged) { int rc = cib_ok; int lpc = 0; int call_type = 0; int call_options = 0; const char *op = NULL; const char *host = NULL; HA_Message *op_request = NULL; HA_Message *op_reply = NULL; gboolean needs_processing = FALSE; cib_client_t *cib_client = user_data; if(cib_client == NULL) { crm_err("Receieved call from unknown source. Discarding."); return FALSE; } crm_verbose("Callback for %s on %s channel", cib_client->id, cib_client->channel_name); while(channel->ops->is_message_pending(channel)) { if (channel->ch_status == IPC_DISCONNECT) { /* The message which was pending for us is that * the IPC status is now IPC_DISCONNECT */ break; } op_request = msgfromIPC(channel); if (op_request == NULL) { perror("Receive failure:"); break; } crm_verbose("Processing IPC message from %s on %s channel", cib_client->id, cib_client->channel_name); crm_log_message(LOG_MSG, op_request); - crm_log_message_adv(LOG_DEBUG, "cib.client-in.log", op_request); + crm_log_message_adv(LOG_DEV, "cib.client-in.log", op_request); lpc++; rc = cib_ok; if(HA_OK != ha_msg_add( op_request, F_CIB_CLIENTID, cib_client->id)) { crm_err("Couldnt add F_CIB_CLIENTID to message"); rc = cib_msg_field_add; } if(rc == cib_ok) { ha_msg_value_int( op_request, F_CIB_CALLOPTS, &call_options); - crm_debug("Call options: %.8lx", (long)call_options); + crm_devel("Call options: %.8lx", (long)call_options); host = cl_get_string(op_request, F_CIB_HOST); op = cl_get_string(op_request, F_CIB_OPERATION); rc = cib_get_operation_id(op_request, &call_type); } if(rc == cib_ok && cib_server_ops[call_type].needs_privileges && privileged == FALSE) { rc = cib_not_authorized; } needs_processing = FALSE; if(rc != cib_ok) { /* TODO: construct error reply */ crm_err("Pre-processing of command failed: %s", cib_error2string(rc)); } else if(host == NULL && cib_is_master && !(call_options & cib_scope_local)) { - crm_debug("Processing master %s op locally", op); + crm_devel("Processing master %s op locally", op); needs_processing = TRUE; } else if( (host == NULL && (call_options & cib_scope_local)) || safe_str_eq(host, cib_our_uname)) { - crm_debug("Processing %s op locally", op); + crm_devel("Processing %s op locally", op); needs_processing = TRUE; } else { /* send via HA to other nodes */ ha_msg_add(op_request, F_CIB_DELEGATED, cib_our_uname); crm_log_message(LOG_MSG, op_request); if(host != NULL) { - crm_debug("Forwarding %s op to %s", op, host); + crm_devel("Forwarding %s op to %s", op, host); hb_conn->llc_ops->send_ordered_nodemsg( hb_conn, op_request, host); } else { crm_info("Forwarding %s op to master instance", op); hb_conn->llc_ops->sendclustermsg( hb_conn, op_request); } if(call_options & cib_discard_reply) { crm_trace("Client not interested in reply"); } else if(call_options & cib_sync_call) { /* keep track of the request so we can time it * out if required */ HA_Message *saved = ha_msg_copy(op_request); - crm_debug("Registering delegated call from %s", + crm_devel("Registering delegated call from %s", cib_client->id); cib_client->delegated_calls = g_list_append( cib_client->delegated_calls, saved); } crm_msg_del(op_request); op_request = NULL; continue; } if(needs_processing) { crm_verbose("Processing %s op", op); rc = cib_process_command( op_request, &op_reply, privileged); - crm_debug("Performing local processing: op=%s origin=%s/%s,%s (update=%s)", + crm_devel("Performing local processing: op=%s origin=%s/%s,%s (update=%s)", op, cib_our_uname, cib_client->id, cl_get_string(op_request, F_CIB_CALLID), (rc==cib_ok && cib_server_ops[call_type].modifies_cib)?"true":"false"); - crm_debug("Processing complete"); + crm_devel("Processing complete"); } - crm_debug("processing response cases"); + crm_devel("processing response cases"); if(rc != cib_ok) { crm_err("Input message"); crm_log_message(LOG_ERR, op_request); crm_err("Output message"); crm_log_message(LOG_ERR, op_reply); crm_log_message_adv(LOG_ERR, DEVEL_DIR"/cib.out.log", op_reply); } if(op_reply == NULL) { crm_trace("No reply is required for op %s", crm_str(op)); } else if(call_options & cib_sync_call) { - crm_debug("Sending sync reply to %s op", crm_str(op)); + crm_devel("Sending sync reply to %s op", crm_str(op)); crm_log_message(LOG_MSG, op_reply); if(msg2ipcchan(op_reply, channel) != HA_OK) { crm_err("Sync reply failed: %s", cib_error2string(cib_reply_failed)); if(rc == cib_ok) { rc = cib_reply_failed; } } } else { enum cib_errors local_rc = cib_ok; /* send reply via client's callback channel */ - crm_debug("Sending async reply %p to %s op", + crm_devel("Sending async reply %p to %s op", op_reply, crm_str(op)); crm_log_message(LOG_MSG, op_reply); local_rc = send_via_callback_channel( op_reply, cib_client->callback_id); if(local_rc != cib_ok) { crm_err("ASync reply failed: %s", cib_error2string(local_rc)); if(rc != cib_ok) { local_rc = cib_reply_failed; } } } - crm_debug("Cleaning up reply"); + crm_devel("Cleaning up reply"); crm_msg_del(op_reply); op_reply = NULL; - crm_debug("Processing forward cases"); + crm_devel("Processing forward cases"); if(rc == cib_ok && cib_server_ops[call_type].modifies_cib && !(call_options & cib_scope_local)) { /* send via HA to other nodes */ crm_info("Forwarding %s op to all instances", op); ha_msg_add(op_request, F_CIB_GLOBAL_UPDATE, XML_BOOLEAN_TRUE); - cl_log_message(LOG_DEBUG, op_request); + cl_log_message(LOG_DEV, op_request); CRM_DEV_ASSERT(hb_conn->llc_ops->sendclustermsg( hb_conn, op_request) == HA_OK); } else { if(call_options & cib_scope_local ) { - crm_debug("Request not broadcast : local scope"); + crm_devel("Request not broadcast : local scope"); } if(cib_server_ops[call_type].modifies_cib == FALSE) { - crm_debug("Request not broadcast : R/O call"); + crm_devel("Request not broadcast : R/O call"); } if(rc != cib_ok) { - crm_debug("Request not broadcast : call failed : %s", + crm_devel("Request not broadcast : call failed : %s", cib_error2string(rc)); } } - crm_debug("Cleaning up request"); + crm_devel("Cleaning up request"); crm_msg_del(op_request); op_request = NULL; } crm_verbose("Processed %d messages", lpc); return cib_process_disconnect(channel, cib_client); } enum cib_errors cib_process_command( const HA_Message *request, HA_Message **reply, gboolean privileged) { crm_data_t *output = NULL; crm_data_t *input = NULL; int call_type = 0; int call_options = 0; enum cib_errors rc = cib_ok; const char *op = NULL; const char *call_id = NULL; const char *section = NULL; const char *tmp = NULL; if(reply) { *reply = NULL; } /* Start processing the request... */ op = cl_get_string(request, F_CIB_OPERATION); call_id = cl_get_string(request, F_CIB_CALLID); ha_msg_value_int(request, F_CIB_CALLOPTS, &call_options); crm_trace("Processing call id: %s", call_id); rc = cib_get_operation_id(request, &call_type); if(rc == cib_ok && cib_server_ops[call_type].needs_privileges && privileged == FALSE) { /* abort */ rc = cib_not_authorized; } if(rc == cib_ok && cib_server_ops[call_type].needs_section) { section = cl_get_string(request, F_CIB_SECTION); crm_trace("Unpacked section as: %s", section); } if(rc == cib_ok && cib_server_ops[call_type].needs_data) { crm_trace("Unpacking data in %s", F_CIB_CALLDATA); input = get_message_xml(request, F_CIB_CALLDATA); } if(rc == cib_ok) { rc = cib_server_ops[call_type].fn( op, call_options, section, input, &output); } - crm_debug("Processing reply cases"); + crm_devel("Processing reply cases"); if((call_options & cib_discard_reply) || reply == NULL) { return rc; } - crm_debug("Creating the reply"); + crm_devel("Creating the reply"); /* make the basic reply */ *reply = ha_msg_new(8); ha_msg_add(*reply, F_TYPE, T_CIB); ha_msg_add(*reply, F_CIB_OPERATION, op); ha_msg_add(*reply, F_CIB_CALLID, call_id); ha_msg_add_int(*reply, F_CIB_RC, rc); tmp = cl_get_string(request, F_CIB_CLIENTID); ha_msg_add(*reply, F_CIB_CLIENTID, tmp); tmp = cl_get_string(request, F_CIB_CALLOPTS); ha_msg_add(*reply, F_CIB_CALLOPTS, tmp); /* attach the output if necessary */ if(output != NULL) { add_message_xml(*reply, F_CIB_CALLDATA, output); } - crm_debug("Cleaning up"); + crm_devel("Cleaning up"); free_xml(output); free_xml(input); return rc; } int send_via_callback_channel(HA_Message *msg, const char *token) { cib_client_t *hash_client = NULL; GList *list_item = NULL; - crm_debug("Delivering msg %p to client %s", msg, token); + crm_devel("Delivering msg %p to client %s", msg, token); if(msg == NULL) { crm_err("No message to send"); return cib_reply_failed; } else if(token == NULL) { crm_err("No client id token, cant send message"); return cib_missing; } hash_client = g_hash_table_lookup(client_list, token); if(hash_client == NULL) { crm_err("Cannot find client for token %s", token); return cib_client_gone; } else if(hash_client->channel == NULL) { crm_err("Cannot find channel for client %s", token); return cib_client_corrupt; } list_item = g_list_find_custom( hash_client->delegated_calls, msg, cib_GCompareFunc); if(list_item != NULL) { /* remove it - no need to time it out */ HA_Message *orig_msg = list_item->data; - crm_debug("Removing msg from delegated list"); + crm_devel("Removing msg from delegated list"); hash_client->delegated_calls = g_list_remove( hash_client->delegated_calls, orig_msg); CRM_DEV_ASSERT(orig_msg != msg); crm_msg_del(orig_msg); } - crm_debug("Delivering reply to client %s", token); - cl_log_message(LOG_DEBUG, msg); + crm_devel("Delivering reply to client %s", token); + cl_log_message(LOG_DEV, msg); if(msg2ipcchan(msg, hash_client->channel) != HA_OK) { crm_err("Delivery of reply to client %s failed", token); return cib_reply_failed; } return cib_ok; } gint cib_GCompareFunc(gconstpointer a, gconstpointer b) { const HA_Message *a_msg = a; const HA_Message *b_msg = b; int msg_a_id = 0; int msg_b_id = 0; ha_msg_value_int(a_msg, F_CIB_CALLID, &msg_a_id); ha_msg_value_int(b_msg, F_CIB_CALLID, &msg_b_id); if(msg_a_id == msg_b_id) { return 0; } else if(msg_a_id < msg_b_id) { return -1; } return 1; } gboolean cib_msg_timeout(gpointer data) { crm_trace("Checking if any clients have timed out messages"); g_hash_table_foreach(client_list, cib_GHFunc, NULL); return TRUE; } void cib_GHFunc(gpointer key, gpointer value, gpointer user_data) { cib_client_t *client = value; GListPtr list = client->delegated_calls; HA_Message *msg = NULL; while(list != NULL) { int seen = 0; int timeout = 5; /* 1 iteration == 1 seconds */ HA_Message *reply = NULL; msg = list->data; ha_msg_value_int(msg, F_CIB_SEENCOUNT, &seen); ha_msg_value_int(msg, F_CIB_TIMEOUT, &timeout); crm_trace("Timeout %d, seen %d", timeout, seen); if(timeout > 0 && seen < timeout) { int seen2 = 0; crm_trace("Updating seen count for msg from client %s", client->id); seen++; ha_msg_mod_int(msg, F_CIB_SEENCOUNT, seen); ha_msg_value_int(msg, F_CIB_SEENCOUNT, &seen2); list = list->next; continue; } crm_warn("Sending operation timeout msg to client %s", client->id); reply = ha_msg_new(4); ha_msg_add(reply, F_TYPE, T_CIB); ha_msg_add(reply, F_CIB_OPERATION, cl_get_string(msg, F_CIB_OPERATION)); ha_msg_add(reply, F_CIB_CALLID, cl_get_string(msg, F_CIB_CALLID)); ha_msg_add_int(reply, F_CIB_RC, cib_master_timeout); msg2ipcchan(reply, client->channel); list = list->next; client->delegated_calls = g_list_remove( client->delegated_calls, msg); crm_msg_del(reply); crm_msg_del(msg); } } gboolean cib_process_disconnect(IPC_Channel *channel, cib_client_t *cib_client) { if (channel->ch_status == IPC_DISCONNECT && cib_client != NULL) { crm_info("Cleaning up after %s channel disconnect from client (%p) %s", cib_client->channel_name, cib_client, crm_str(cib_client->id)); if(cib_client->id != NULL) { g_hash_table_remove(client_list, cib_client->id); } if(cib_client->source != NULL) { - crm_debug("deleting the IPC Channel"); + crm_devel("deleting the IPC Channel"); G_main_del_IPC_Channel(cib_client->source); cib_client->source = NULL; } - crm_debug("Freeing the cib client %s", - crm_str(cib_client->id)); -/* crm_free(cib_client->callback_id); */ -/* crm_free(cib_client->id); */ + crm_devel("Freeing the cib client %s", crm_str(cib_client->id)); +#if 0 + /* todo - put this back in once i recheck its safe */ + crm_free(cib_client->callback_id); + crm_free(cib_client->id); +#endif crm_free(cib_client); - crm_debug("Freed the cib client"); + crm_devel("Freed the cib client"); return FALSE; } else if (channel->ch_status == IPC_DISCONNECT) { crm_warn("Unknown client disconnected"); return FALSE; } return TRUE; } gboolean cib_ha_dispatch(IPC_Channel *channel, gpointer user_data) { int lpc = 0; ll_cluster_t *hb_cluster = (ll_cluster_t*)user_data; while(hb_cluster->llc_ops->msgready(hb_cluster)) { lpc++; /* invoke the callbacks but dont block */ hb_cluster->llc_ops->rcvmsg(hb_cluster, 0); } crm_trace("%d HA messages dispatched", lpc); if (channel && (channel->ch_status == IPC_DISCONNECT)) { crm_crit("Lost connection to heartbeat service... exiting"); exit(100); return FALSE; } return TRUE; } void cib_peer_callback(const HA_Message * msg, void* private_data) { int is_done = 1; int call_type = 0; int call_options = 0; gboolean process = TRUE; gboolean needs_reply = TRUE; gboolean local_notify = FALSE; enum cib_errors rc = cib_ok; HA_Message *op_reply = NULL; const char *originator = cl_get_string(msg, F_ORIG); const char *request_to = cl_get_string(msg, F_CIB_HOST); const char *reply_to = cl_get_string(msg, F_CIB_ISREPLY); const char *update = cl_get_string(msg, F_CIB_GLOBAL_UPDATE); const char *delegated = cl_get_string(msg, F_CIB_DELEGATED); const char *client_id = NULL; if(safe_str_eq(originator, cib_our_uname)) { - crm_debug("Discarding message %s from ourselves", + crm_devel("Discarding message %s from ourselves", cl_get_string(msg, F_SEQ)); return; } if(cib_get_operation_id(msg, &call_type) != cib_ok) { crm_err("Invalid operation... discarding msg %s", cl_get_string(msg, F_SEQ)); return; } crm_trace("%s Processing msg %s", cib_our_uname, cl_get_string(msg, F_SEQ)); if(request_to != NULL && strlen(request_to) == 0) { request_to = NULL; } if(cib_server_ops[call_type].modifies_cib || (reply_to == NULL && cib_is_master) || request_to != NULL) { is_done = 0; } crm_info("Processing message from peer to %s...", request_to); - crm_log_message(LOG_DEBUG, msg); + crm_log_message(LOG_DEV, msg); if(safe_str_eq(update, XML_BOOLEAN_TRUE) && safe_str_eq(reply_to, cib_our_uname)) { - crm_debug("Processing global update that originated from us"); + crm_devel("Processing global update that originated from us"); needs_reply = FALSE; local_notify = TRUE; } else if(safe_str_eq(update, XML_BOOLEAN_TRUE)) { - crm_debug("Processing global update"); + crm_devel("Processing global update"); needs_reply = FALSE; } else if(request_to != NULL && safe_str_eq(request_to, cib_our_uname)) { - crm_debug("Processing request sent to us"); + crm_devel("Processing request sent to us"); } else if(delegated != NULL && cib_is_master == TRUE) { - crm_debug("Processing request sent to master instance"); + crm_devel("Processing request sent to master instance"); } else if(reply_to != NULL && safe_str_eq(reply_to, cib_our_uname)) { - crm_debug("Forward reply sent from %s to local clients", + crm_devel("Forward reply sent from %s to local clients", originator); process = FALSE; needs_reply = FALSE; local_notify = TRUE; } else if(delegated != NULL) { - crm_debug("Ignoring msg for master instance"); + crm_devel("Ignoring msg for master instance"); return; } else if(request_to != NULL) { /* this is for a specific instance and we're not it */ - crm_debug("Ignoring msg for instance on %s", + crm_devel("Ignoring msg for instance on %s", crm_str(request_to)); return; } else if(reply_to == NULL && cib_is_master == FALSE) { /* this is for the master instance and we're not it */ - crm_debug("Ignoring reply to %s", crm_str(reply_to)); + crm_devel("Ignoring reply to %s", crm_str(reply_to)); return; } else { crm_warn("Nothing for us to do?"); return; } - crm_debug("Finished determining processing actions"); + crm_devel("Finished determining processing actions"); ha_msg_value_int(msg, F_CIB_CALLOPTS, &call_options); crm_trace("Retrieved call options: %d", call_options); if(process) { - crm_debug("Performing local processing: op=%s origin=%s/%s,%s (update=%s)", + crm_devel("Performing local processing: op=%s origin=%s/%s,%s (update=%s)", cl_get_string(msg, F_CIB_OPERATION), originator, cl_get_string(msg, F_CIB_CLIENTID), cl_get_string(msg, F_CIB_CALLID), update); rc = cib_process_command(msg, &op_reply, TRUE); } if(local_notify) { /* send callback to originating child */ cib_client_t *client_obj = NULL; HA_Message *client_reply = NULL; crm_trace("find the client"); if(process == FALSE) { client_reply = ha_msg_copy(msg); } else { client_reply = ha_msg_copy(op_reply); } client_id = cl_get_string(msg, F_CIB_CLIENTID); if(client_id != NULL) { client_obj = g_hash_table_lookup( client_list, client_id); } else { crm_err("No client to sent the response to." " F_CIB_CLIENTID not set."); } - crm_debug("Sending callback to originator of delegated request"); + crm_devel("Sending callback to originator of delegated request"); if(client_obj != NULL) { if(is_done == 0) { - crm_debug("Sending local modify response"); + crm_devel("Sending local modify response"); } else { - crm_debug("Sending master response"); + crm_devel("Sending master response"); } if(call_options & cib_sync_call) { - crm_debug("Sending sync response: %d", + crm_devel("Sending sync response: %d", call_options); send_via_callback_channel( client_reply, client_obj->id); } else { - crm_debug("Sending async response"); + crm_devel("Sending async response"); send_via_callback_channel( client_reply, client_obj->callback_id); } } else { crm_warn("Client %s may have left us", crm_str(client_id)); } crm_msg_del(client_reply); } if(needs_reply == FALSE) { /* nothing more to do... * this was a non-originating slave update */ - crm_debug("Completed slave update"); + crm_devel("Completed slave update"); crm_msg_del(op_reply); return; } crm_trace("add the originator to message"); /* from now on we are the server */ if(rc == cib_ok && cib_server_ops[call_type].modifies_cib && !(call_options & cib_scope_local)) { /* this (successful) call modified the CIB _and_ the * change needs to be broadcast... * send via HA to other nodes */ HA_Message *op_bcast = ha_msg_copy(msg); - crm_debug("Sending update request to everyone"); + crm_devel("Sending update request to everyone"); ha_msg_add(op_bcast, F_CIB_ISREPLY, originator); ha_msg_add(op_bcast, F_CIB_GLOBAL_UPDATE, XML_BOOLEAN_TRUE); - crm_log_message(LOG_DEBUG, op_bcast); + crm_log_message(LOG_DEV, op_bcast); hb_conn->llc_ops->sendclustermsg(hb_conn, op_bcast); crm_msg_del(op_bcast); } else { /* send reply via HA to originating node */ - crm_debug("Sending request result to originator only"); + crm_devel("Sending request result to originator only"); ha_msg_add(op_reply, F_CIB_ISREPLY, originator); - crm_log_message(LOG_DEBUG, op_reply); + crm_log_message(LOG_DEV, op_reply); hb_conn->llc_ops->send_ordered_nodemsg( hb_conn, op_reply, originator); } crm_msg_del(op_reply); return; } enum cib_errors cib_get_operation_id(const HA_Message * msg, int *operation) { int lpc = 0; int max_msg_types = DIMOF(cib_server_ops); const char *op = cl_get_string(msg, F_CIB_OPERATION); for (lpc = 0; lpc < max_msg_types; lpc++) { if (safe_str_eq(op, cib_server_ops[lpc].operation)) { *operation = lpc; return cib_ok; } } crm_err("Operation %s is not valid", op); *operation = -1; return cib_operation; } void cib_client_status_callback(const char * node, const char * client, const char * status, void * private) { crm_notice("Status update: Client %s/%s now has status [%s]\n", node, client, status); g_hash_table_replace(peer_hash, crm_strdup(node), crm_strdup(status)); return; } gboolean cib_ccm_dispatch(int fd, gpointer user_data) { int rc = 0; oc_ev_t *ccm_token = (oc_ev_t*)user_data; - crm_debug("received callback"); + crm_devel("received callback"); rc = oc_ev_handle_event(ccm_token); if(0 == rc) { return TRUE; } else { crm_err("CCM connection appears to have failed: rc=%d.", rc); return FALSE; } } void cib_ccm_msg_callback( oc_ed_t event, void *cookie, size_t size, const void *data) { - crm_debug("received callback"); + crm_devel("received callback"); crm_info("event=%s", event==OC_EV_MS_NEW_MEMBERSHIP?"NEW MEMBERSHIP": event==OC_EV_MS_NOT_PRIMARY?"NOT PRIMARY": event==OC_EV_MS_PRIMARY_RESTORED?"PRIMARY RESTORED": event==OC_EV_MS_EVICTED?"EVICTED": "NO QUORUM MEMBERSHIP"); if(event==OC_EV_MS_NEW_MEMBERSHIP || event==OC_EV_MS_NOT_PRIMARY || event==OC_EV_MS_PRIMARY_RESTORED) { cib_have_quorum = TRUE; } else { cib_have_quorum = FALSE; } oc_ev_callback_done(cookie); return; } diff --git a/crm/cib/cibmon.c b/crm/cib/cibmon.c index 331923ea11..14f99314ee 100644 --- a/crm/cib/cibmon.c +++ b/crm/cib/cibmon.c @@ -1,459 +1,459 @@ -/* $Id: cibmon.c,v 1.13 2005/02/16 18:01:41 andrew Exp $ */ +/* $Id: cibmon.c,v 1.14 2005/02/19 18:11:03 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 #include #include #include #include #include #include #include /* someone complaining about _ha_msg_mod not being found */ #include #define UPDATE_PREFIX "cib.updates:" int exit_code = cib_ok; GMainLoop *mainloop = NULL; const char *crm_system_name = "cibmon"; void usage(const char *cmd, int exit_status); void cib_connection_destroy(gpointer user_data); void cibmon_pre_notify(const char *event, HA_Message *msg); void cibmon_post_notify(const char *event, HA_Message *msg); void cibmon_update_confirm(const char *event, HA_Message *msg); cib_t *the_cib = NULL; #define OPTARGS "V?pPUam:i" gboolean intermediate_changes = FALSE; gboolean pre_notify = FALSE; gboolean post_notify = FALSE; gboolean update_notify = FALSE; int max_failures = 30; int main(int argc, char **argv) { int option_index = 0; int argerr = 0; int flag; int level = 0; int attempts = 0; static struct option long_options[] = { /* Top-level Options */ {"verbose", 0, 0, 'V'}, {"help", 0, 0, '?'}, {"pre", 0, 0, 'p'}, {"post", 0, 0, 'P'}, {"update", 0, 0, 'U'}, {"all", 0, 0, 'a'}, {"intermediate", 0, 0, 'i'}, {"max-conn-fail",1, 0, 'm'}, {0, 0, 0, 0} }; crm_log_init(crm_system_name); cl_set_corerootdir(HA_COREDIR); cl_cdtocoredir(); #ifdef USE_LIBXML /* docs say only do this once, but in their code they do it every time! */ xmlInitParser(); #endif while (1) { flag = getopt_long(argc, argv, OPTARGS, long_options, &option_index); if (flag == -1) break; switch(flag) { case 0: printf("option %s", long_options[option_index].name); if (optarg) { printf(" with arg %s", optarg); } printf("\n"); printf("Long option (--%s) is not" " (yet?) properly supported\n", long_options[option_index].name); ++argerr; break; case 'V': level = get_crm_log_level(); cl_log_enable_stderr(TRUE); set_crm_log_level(level+1); break; case '?': usage(crm_system_name, LSB_EXIT_OK); break; case 'm': max_failures = crm_atoi(optarg, "30"); break; case 'a': pre_notify = TRUE; post_notify = TRUE; update_notify = TRUE; break; case 'p': pre_notify = TRUE; break; case 'P': post_notify = TRUE; break; case 'U': update_notify = TRUE; break; case 'i': intermediate_changes = TRUE; break; default: printf("Argument code 0%o (%c)" " is not (?yet?) supported\n", flag, 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) { usage(crm_system_name, LSB_EXIT_GENERIC); } the_cib = cib_new(); do { if(attempts != 0) { sleep(1); } exit_code = the_cib->cmds->signon(the_cib, cib_query); } while(exit_code == cib_connection && attempts++ < max_failures); if(exit_code != cib_ok) { crm_err("Signon to CIB failed: %s", cib_error2string(exit_code)); } if(exit_code == cib_ok) { exit_code = the_cib->cmds->set_connection_dnotify( the_cib, cib_connection_destroy); } if(exit_code == cib_ok && pre_notify) { exit_code = the_cib->cmds->add_notify_callback( the_cib, T_CIB_PRE_NOTIFY, cibmon_pre_notify); if(exit_code != cib_ok) { crm_err("Failed to set %s callback: %s", T_CIB_PRE_NOTIFY, cib_error2string(exit_code)); } } if(exit_code == cib_ok && post_notify) { exit_code = the_cib->cmds->add_notify_callback( the_cib, T_CIB_POST_NOTIFY, cibmon_post_notify); if(exit_code != cib_ok) { crm_err("Failed to set %s callback: %s", T_CIB_POST_NOTIFY, cib_error2string(exit_code)); } } if(exit_code == cib_ok && update_notify) { exit_code = the_cib->cmds->add_notify_callback( the_cib, T_CIB_UPDATE_CONFIRM, cibmon_update_confirm); if(exit_code != cib_ok) { crm_err("Failed to set %s callback: %s", T_CIB_UPDATE_CONFIRM, cib_error2string(exit_code)); } } if(exit_code != cib_ok) { crm_err("Setup failed, could not monitor CIB actions"); return -exit_code; } mainloop = g_main_new(FALSE); crm_info("Starting mainloop"); g_main_run(mainloop); - crm_debug("%s exiting normally", crm_system_name); + crm_devel("%s exiting normally", crm_system_name); fflush(stderr); return -exit_code; } void usage(const char *cmd, int exit_status) { FILE *stream; stream = exit_status != 0 ? stderr : stdout; #if 0 fprintf(stream, "usage: %s [-?Vio] command\n" "\twhere necessary, XML data will be expected using -X" " or on STDIN if -X isnt specified\n", cmd); fprintf(stream, "Options\n"); fprintf(stream, "\t--%s (-%c) \tid of the object being operated on\n", XML_ATTR_ID, 'i'); fprintf(stream, "\t--%s (-%c) \tobject type being operated on\n", "obj_type", 'o'); fprintf(stream, "\t--%s (-%c)\tturn on debug info." " additional instance increase verbosity\n", "verbose", 'V'); fprintf(stream, "\t--%s (-%c)\tthis help message\n", "help", '?'); fprintf(stream, "\nCommands\n"); fprintf(stream, "\t--%s (-%c)\t\n", CRM_OP_CIB_ERASE, 'E'); fprintf(stream, "\t--%s (-%c)\t\n", CRM_OP_CIB_QUERY, 'Q'); fprintf(stream, "\t--%s (-%c)\t\n", CRM_OP_CIB_CREATE, 'C'); fprintf(stream, "\t--%s (-%c)\t\n", CRM_OP_CIB_REPLACE,'R'); fprintf(stream, "\t--%s (-%c)\t\n", CRM_OP_CIB_UPDATE, 'U'); fprintf(stream, "\t--%s (-%c)\t\n", CRM_OP_CIB_DELETE, 'D'); fprintf(stream, "\t--%s (-%c)\t\n", CRM_OP_CIB_BUMP, 'B'); fprintf(stream, "\t--%s (-%c)\t\n", CRM_OP_CIB_ISMASTER,'M'); fprintf(stream, "\t--%s (-%c)\t\n", CRM_OP_CIB_SYNC, 'S'); fprintf(stream, "\nXML data\n"); fprintf(stream, "\t--%s (-%c) \t\n", F_CRM_DATA, 'X'); fprintf(stream, "\nAdvanced Options\n"); fprintf(stream, "\t--%s (-%c)\tsend command to specified host." " Applies to %s and %s commands only\n", "host", 'h', CRM_OP_CIB_QUERY, CRM_OP_CIB_SYNC); fprintf(stream, "\t--%s (-%c)\tcommand only takes effect locally" " on the specified host\n", "local", 'l'); fprintf(stream, "\t--%s (-%c)\twait for call to complete before" " returning\n", "sync-call", 's'); #endif fflush(stream); exit(exit_status); } void cib_connection_destroy(gpointer user_data) { crm_err("Connection to the CIB terminated... exiting"); g_main_quit(mainloop); return; } int update_depth = 0; gboolean last_notify_pre = TRUE; void cibmon_pre_notify(const char *event, HA_Message *msg) { int rc = -1; const char *op = NULL; const char *id = NULL; const char *type = NULL; crm_data_t *update = NULL; crm_data_t *pre_update = NULL; if(msg == NULL) { crm_err("NULL update"); return; } op = cl_get_string(msg, F_CIB_OPERATION); id = cl_get_string(msg, F_CIB_OBJID); type = cl_get_string(msg, F_CIB_OBJTYPE); update = get_message_xml(msg, F_CIB_UPDATE); pre_update = get_message_xml(msg, F_CIB_EXISTING); ha_msg_value_int(msg, F_CIB_RC, &rc); update_depth++; last_notify_pre = TRUE; if(update_depth > 1 && intermediate_changes == FALSE) { crm_trace("[%s] Ignoring intermediate update", event); return; } if(update != NULL) { - crm_debug(UPDATE_PREFIX"[%s] Performing %s on <%s%s%s>", + crm_devel(UPDATE_PREFIX"[%s] Performing %s on <%s%s%s>", event, op, type, id?" id=":"", id?id:""); print_xml_formatted(LOG_INSANE, UPDATE_PREFIX, update, "Update"); } else if(update == NULL) { crm_info(UPDATE_PREFIX"[%s] Performing operation %s (on section=%s)", event, op, crm_str(type)); } - print_xml_formatted(LOG_DEBUG, UPDATE_PREFIX, + print_xml_formatted(LOG_DEV, UPDATE_PREFIX, pre_update, "Existing Object"); } void cibmon_post_notify(const char *event, HA_Message *msg) { int rc = -1; const char *op = NULL; const char *id = NULL; const char *type = NULL; crm_data_t *update = NULL; crm_data_t *output = NULL; crm_data_t *generation = NULL; if(msg == NULL) { crm_err("NULL update"); return; } op = cl_get_string(msg, F_CIB_OPERATION); id = cl_get_string(msg, F_CIB_OBJID); type = cl_get_string(msg, F_CIB_OBJTYPE); update = get_message_xml(msg, F_CIB_UPDATE); output = get_message_xml(msg, F_CIB_UPDATE_RESULT); generation = get_message_xml(msg, "cib_generation"); update_depth--; if(last_notify_pre == FALSE && update_depth > 0 && intermediate_changes == FALSE) { crm_trace("Ignoring intermediate update"); return; } last_notify_pre = FALSE; ha_msg_value_int(msg, F_CIB_RC, &rc); if(update == NULL) { if(rc == cib_ok) { crm_verbose(UPDATE_PREFIX"[%s] %s (to %s) completed", event, op, crm_str(type)); } else { crm_warn(UPDATE_PREFIX"[%s] %s (to %s) FAILED: (%d) %s", event, op, crm_str(type), rc, cib_error2string(rc)); } } else { if(rc == cib_ok) { crm_verbose(UPDATE_PREFIX"[%s] Operation %s to <%s%s%s> completed.", event, op, crm_str(type), id?" id=":"", id?id:""); } else { crm_warn(UPDATE_PREFIX"[%s] Operation %s to <%s %s%s> FAILED: (%d) %s", event, op, crm_str(type), id?" id=":"", id?id:"", rc, cib_error2string(rc)); } } if(update == NULL) { print_xml_formatted( rc==cib_ok?LOG_DEBUG:LOG_WARNING, UPDATE_PREFIX, update, "Update"); } print_xml_formatted( - rc==cib_ok?LOG_DEBUG:LOG_WARNING, UPDATE_PREFIX, + rc==cib_ok?LOG_DEV:LOG_WARNING, UPDATE_PREFIX, output, "Resulting Object"); if(update_depth == 0) { print_xml_formatted( rc==cib_ok?LOG_DEBUG:LOG_WARNING, UPDATE_PREFIX, generation, "CIB Generation"); } } void cibmon_update_confirm(const char *event, HA_Message *msg) { int rc = -1; const char *op = NULL; const char *id = NULL; const char *type = NULL; if(msg == NULL) { crm_err("NULL update"); return; } op = cl_get_string(msg, F_CIB_OPERATION); id = cl_get_string(msg, F_CIB_OBJID); type = cl_get_string(msg, F_CIB_OBJTYPE); ha_msg_value_int(msg, F_CIB_RC, &rc); if(id == NULL) { if(rc == cib_ok) { crm_info(UPDATE_PREFIX"[%s] %s (to section=%s) confirmed.\n", event, op, crm_str(type)); } else { crm_warn(UPDATE_PREFIX"[%s] %s (to section=%s) ABORTED: (%d) %s\n", event, op, crm_str(type), rc, cib_error2string(rc)); } } else { if(rc == cib_ok) { crm_info(UPDATE_PREFIX"[%s] %s (to <%s%s%s>) confirmed\n", event, op, crm_str(type), id?" id=":"", id?id:""); } else { crm_warn(UPDATE_PREFIX"[%s] %s (to <%s%s%s>) ABORTED: (%d) %s\n", event, op, crm_str(type), id?" id=":"", id?id:"", rc, cib_error2string(rc)); } } - crm_debug(UPDATE_PREFIX"================================="); + crm_devel(UPDATE_PREFIX"================================="); } diff --git a/crm/cib/io.c b/crm/cib/io.c index c409f03360..a3dc49bcb2 100644 --- a/crm/cib/io.c +++ b/crm/cib/io.c @@ -1,389 +1,389 @@ -/* $Id: io.c,v 1.11 2005/02/18 10:36:10 andrew Exp $ */ +/* $Id: io.c,v 1.12 2005/02/19 18:11:03 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 #include #include #include #include gboolean cib_writes_enabled = TRUE; const char * local_resource_path[] = { XML_CIB_TAG_STATUS, }; const char * resource_path[] = { XML_CIB_TAG_RESOURCES, }; const char * node_path[] = { XML_CIB_TAG_NODES, }; const char * constraint_path[] = { XML_CIB_TAG_CONSTRAINTS, }; gboolean initialized = FALSE; crm_data_t *the_cib = NULL; crm_data_t *node_search = NULL; crm_data_t *resource_search = NULL; crm_data_t *constraint_search = NULL; crm_data_t *status_search = NULL; /* * It is the callers responsibility to free the output of this function */ crm_data_t* readCibXml(char *buffer) { crm_data_t *root = string2xml(buffer); if (verifyCibXml(root) == FALSE) { free_xml(root); return createEmptyCib(); } return root; } /* * It is the callers responsibility to free the output of this function */ crm_data_t* readCibXmlFile(const char *filename) { int s_res = -1; struct stat buf; crm_data_t *root = NULL; if(filename != NULL) { s_res = stat(filename, &buf); } if (s_res == 0) { FILE *cib_file = fopen(filename, "r"); root = file2xml(cib_file); set_xml_property_copy(root, "generated", XML_BOOLEAN_FALSE); fclose(cib_file); } else { crm_warn("Stat of (%s) failed, file does not exist.", CIB_FILENAME); } if (verifyCibXml(root) == FALSE) { free_xml(root); /* return createEmptyCib(); */ root = NULL; } return root; } /* * The caller should never free the return value */ crm_data_t* get_the_CIB(void) { return the_cib; } gboolean uninitializeCib(void) { crm_data_t *tmp_cib = the_cib; if(tmp_cib == NULL) { crm_err("The CIB has already been deallocated."); return FALSE; } initialized = FALSE; the_cib = NULL; node_search = NULL; resource_search = NULL; constraint_search = NULL; status_search = NULL; crm_err("Deallocating the CIB."); free_xml(tmp_cib); crm_err("The CIB has been deallocated."); return TRUE; } /* * This method will not free the old CIB pointer or the new one. * We rely on the caller to have saved a pointer to the old CIB * and to free the old/bad one depending on what is appropriate. */ gboolean initializeCib(crm_data_t *new_cib) { #if 0 if(new_cib != NULL) { crm_set_element_parent(new_cib, NULL); } #endif if (verifyCibXml(new_cib)) { initialized = FALSE; the_cib = new_cib; /* update search paths */ /* not used yet... node_search = get_object_root(XML_CIB_TAG_NODES, new_cib); resource_search = get_object_root(XML_CIB_TAG_RESOURCES, new_cib); constraint_search = get_object_root(XML_CIB_TAG_CONSTRAINTS, new_cib); status_search = get_object_root(XML_CIB_TAG_STATUS, new_cib); */ initialized = TRUE; crm_trace("CIB initialized"); return TRUE; } if(initialized == FALSE) { crm_warn("CIB Verification failed"); } else { const char *option = "suppress_cib_writes"; const char *value = NULL; crm_data_t *config = get_object_root( XML_CIB_TAG_CRMCONFIG, new_cib); crm_data_t * a_default = find_entity( config, XML_CIB_TAG_NVPAIR, option, FALSE); if(a_default != NULL) { value = crm_element_value( a_default, XML_NVPAIR_ATTR_VALUE); } cib_writes_enabled = TRUE; if(value == NULL) { crm_warn("Option %s not set", option); } else if(safe_str_eq(value, XML_BOOLEAN_TRUE)) { cib_writes_enabled = FALSE; } if(cib_writes_enabled) { crm_info("CIB disk writes to %s enabled", CIB_FILENAME); } else { crm_notice("Disabling CIB disk writes"); } } return initialized; } int moveFile(const char *oldname, const char *newname, gboolean backup, char *ext) { /* move 'oldname' to 'newname' by creating a hard link to it * and then removing the original hard link */ int res = 0; struct stat tmp; int s_res = stat(newname, &tmp); if (s_res >= 0) { if (backup == TRUE) { char backname[1024]; static const char *back_ext = "bak"; if (ext != NULL) { back_ext = (char*)ext; } snprintf(backname, sizeof(backname)-1, "%s.%s", newname, back_ext); moveFile(newname, backname, FALSE, NULL); } else { res = unlink(newname); if (res < 0) { perror("Could not remove the current backup of Cib"); return -1; } } } s_res = stat(oldname, &tmp); if (s_res >= 0) { res = link(oldname, newname); if (res < 0) { perror("Could not create backup of current Cib"); return -2; } res = unlink(oldname); if (res < 0) { perror("Could not unlink the current Cib"); return -3; } } return 0; } int activateCibBuffer(char *buffer, const char *filename) { int result = -1; crm_data_t *local_cib = NULL; local_cib = readCibXml(buffer); result = activateCibXml(local_cib, filename); return result; } /* * This method will free the old CIB pointer on success and the new one * on failure. */ int activateCibXml(crm_data_t *new_cib, const char *filename) { int error_code = cib_ok; crm_data_t *saved_cib = get_the_CIB(); const char *filename_bak = CIB_BACKUP; /* calculate */ - crm_xml_debug(new_cib, "Attempting to activate CIB"); + crm_xml_devel(new_cib, "Attempting to activate CIB"); CRM_ASSERT(new_cib != saved_cib); crm_validate_data(new_cib); if(saved_cib != NULL) { crm_validate_data(saved_cib); } if (initializeCib(new_cib) == FALSE) { crm_warn("Ignoring invalid or NULL Cib"); error_code = -5; } else if(cib_writes_enabled) { if(saved_cib != NULL) { CRM_DEV_ASSERT(0 >= moveFile(filename, filename_bak, FALSE, NULL)); if (crm_assert_failed) { crm_warn("Could not make backup of the current" " Cib... aborting update."); error_code = -1; } } if(error_code == cib_ok) { - crm_debug("Writing CIB out to %s", CIB_FILENAME); + crm_devel("Writing CIB out to %s", CIB_FILENAME); CRM_DEV_ASSERT(write_xml_file( new_cib, CIB_FILENAME) >= 0); if (crm_assert_failed) { error_code = -4; } } if(error_code == -4 && saved_cib != NULL) { CRM_DEV_ASSERT(moveFile(filename_bak, filename, FALSE, NULL) >= 0); if (crm_assert_failed){ crm_crit("Could not restore the backup of the " " current Cib... panic!"); error_code = -2; /* should probably exit here */ } } CRM_DEV_ASSERT(saved_cib != NULL || error_code == cib_ok); if(crm_assert_failed) { /* oh we are so dead */ crm_crit("Could not write out new CIB and no saved" " version to revert to"); error_code = -3; } else if(error_code != cib_ok) { crm_crit("Update of Cib failed (%d)... reverting" " to last known valid version", error_code); CRM_DEV_ASSERT(initializeCib(saved_cib)); if (crm_assert_failed) { /* oh we are so dead */ crm_crit("Could not re-initialize with the old" " CIB. Can anyone say corruption?"); error_code = -3; } } } /* Make sure memory is cleaned up appropriately */ if (error_code != cib_ok) { crm_trace("Freeing new CIB %p", new_cib); free_xml(new_cib); } else if(saved_cib != NULL) { crm_trace("Freeing saved CIB %p", saved_cib); crm_validate_data(saved_cib); free_xml(saved_cib); } return error_code; } diff --git a/crm/cib/main.c b/crm/cib/main.c index a8c2b91c8b..c5d845bcfe 100644 --- a/crm/cib/main.c +++ b/crm/cib/main.c @@ -1,343 +1,343 @@ -/* $Id: main.c,v 1.14 2005/02/17 16:22:11 andrew Exp $ */ +/* $Id: main.c,v 1.15 2005/02/19 18:11:03 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 /* #include */ #include /* #include */ #include #include #include #include #include #include #include #include #include #include extern void oc_ev_special(const oc_ev_t *, oc_ev_class_t , int ); GMainLoop* mainloop = NULL; const char* crm_system_name = CRM_SYSTEM_CIB; char *cib_our_uname = NULL; oc_ev_t *cib_ev_token; void usage(const char* cmd, int exit_status); int init_start(void); gboolean cib_register_ha(ll_cluster_t *hb_cluster, const char *client_name); gboolean cib_shutdown(int nsig, gpointer unused); void cib_ha_connection_destroy(gpointer user_data); gboolean startCib(const char *filename); extern gboolean cib_msg_timeout(gpointer data); ll_cluster_t *hb_conn = NULL; #define OPTARGS "hV" int main(int argc, char ** argv) { int argerr = 0; int flag; crm_log_init(crm_system_name); set_crm_log_level(LOG_VERBOSE); G_main_add_SignalHandler( G_PRIORITY_HIGH, SIGTERM, cib_shutdown, NULL, NULL); client_list = g_hash_table_new(g_str_hash, g_str_equal); peer_hash = g_hash_table_new(g_str_hash, g_str_equal); while ((flag = getopt(argc, argv, OPTARGS)) != EOF) { switch(flag) { case 'V': alter_debug(DEBUG_INC); break; case 'h': /* Help message */ usage(crm_system_name, LSB_EXIT_OK); break; default: ++argerr; break; } } if (optind > argc) { ++argerr; } if (argerr) { usage(crm_system_name,LSB_EXIT_GENERIC); } /* read local config file */ return init_start(); } int init_start(void) { gboolean was_error = FALSE; hb_conn = ll_cluster_new("heartbeat"); cib_register_ha(hb_conn, CRM_SYSTEM_CIB); if(startCib(CIB_FILENAME) == FALSE){ crm_crit("Cannot start CIB... terminating"); exit(1); } was_error = init_server_ipc_comms( crm_strdup(cib_channel_callback), cib_client_connect, default_ipc_connection_destroy); was_error = was_error || init_server_ipc_comms( crm_strdup(cib_channel_ro), cib_client_connect, default_ipc_connection_destroy); was_error = was_error || init_server_ipc_comms( crm_strdup(cib_channel_rw), cib_client_connect, default_ipc_connection_destroy); if(was_error == FALSE) { - crm_debug("Be informed of CRM Client Status changes"); + crm_devel("Be informed of CRM Client Status changes"); if (HA_OK != hb_conn->llc_ops->set_cstatus_callback( hb_conn, cib_client_status_callback, hb_conn)) { crm_err("Cannot set cstatus callback: %s\n", hb_conn->llc_ops->errmsg(hb_conn)); was_error = TRUE; } else { - crm_debug("Client Status callback set"); + crm_devel("Client Status callback set"); } } if(was_error == FALSE) { gboolean did_fail = TRUE; int num_ccm_fails = 0; int max_ccm_fails = 30; int ret; int cib_ev_fd; while(did_fail && was_error == FALSE) { did_fail = FALSE; - crm_debug("Registering with CCM"); + crm_devel("Registering with CCM"); ret = oc_ev_register(&cib_ev_token); if (ret != 0) { crm_warn("CCM registration failed"); did_fail = TRUE; } if(did_fail == FALSE) { - crm_debug("Setting up CCM callbacks"); + crm_devel("Setting up CCM callbacks"); ret = oc_ev_set_callback( cib_ev_token, OC_EV_MEMB_CLASS, cib_ccm_msg_callback, NULL); if (ret != 0) { crm_warn("CCM callback not set"); did_fail = TRUE; } } if(did_fail == FALSE) { oc_ev_special(cib_ev_token, OC_EV_MEMB_CLASS, 0); - crm_debug("Activating CCM token"); + crm_devel("Activating CCM token"); ret = oc_ev_activate(cib_ev_token, &cib_ev_fd); if (ret != 0){ crm_warn("CCM Activation failed"); did_fail = TRUE; } } if(did_fail) { num_ccm_fails++; oc_ev_unregister(cib_ev_token); if(num_ccm_fails < max_ccm_fails){ crm_warn("CCM Connection failed" " %d times (%d max)", num_ccm_fails, max_ccm_fails); sleep(1); } else { crm_err("CCM Activation failed %d (max) times", num_ccm_fails); was_error = TRUE; } } } - crm_debug("CCM Activation passed... all set to go!"); + crm_devel("CCM Activation passed... all set to go!"); G_main_add_fd(G_PRIORITY_LOW, cib_ev_fd, FALSE, cib_ccm_dispatch, cib_ev_token, default_ipc_connection_destroy); } if(was_error == FALSE) { /* Async get client status information in the cluster */ - crm_debug("Requesting an initial dump of CRMD client_status"); + crm_devel("Requesting an initial dump of CRMD client_status"); hb_conn->llc_ops->client_status( hb_conn, NULL, CRM_SYSTEM_CRMD, -1); /* Create the mainloop and run it... */ mainloop = g_main_new(FALSE); crm_info("Starting %s mainloop", crm_system_name); Gmain_timeout_add(1000, cib_msg_timeout, NULL); g_main_run(mainloop); return_to_orig_privs(); } else { crm_err("Couldnt start all communication channels, exiting."); } return 0; } void usage(const char* cmd, int exit_status) { FILE* stream; stream = exit_status ? stderr : stdout; fprintf(stream, "usage: %s [-srkh]" "[-c configure file]\n", cmd); /* fprintf(stream, "\t-d\tsets debug level\n"); */ /* fprintf(stream, "\t-s\tgets daemon status\n"); */ /* fprintf(stream, "\t-r\trestarts daemon\n"); */ /* fprintf(stream, "\t-k\tstops daemon\n"); */ /* fprintf(stream, "\t-h\thelp message\n"); */ fflush(stream); exit(exit_status); } gboolean cib_register_ha(ll_cluster_t *hb_cluster, const char *client_name) { int facility; const char *uname = NULL; if(safe_val3(NULL, hb_cluster, llc_ops, errmsg) == NULL) { crm_crit("cluster errmsg function unavailable"); } crm_info("Signing in with Heartbeat"); if (hb_cluster->llc_ops->signon(hb_cluster, client_name)!= HA_OK) { crm_err("Cannot sign on with heartbeat: %s", hb_cluster->llc_ops->errmsg(hb_cluster)); return FALSE; } /* change the logging facility to the one used by heartbeat daemon */ crm_info("Switching to Heartbeat logger"); if (( facility = hb_cluster->llc_ops->get_logfacility(hb_cluster)) > 0) { cl_log_set_facility(facility); } crm_verbose("Facility: %d", facility); - crm_debug("Be informed of CIB messages"); + crm_devel("Be informed of CIB messages"); if (HA_OK != hb_cluster->llc_ops->set_msg_callback( hb_cluster, T_CIB, cib_peer_callback, hb_cluster)){ crm_err("Cannot set msg callback: %s", hb_cluster->llc_ops->errmsg(hb_cluster)); return FALSE; } - crm_debug("Finding our node name"); + crm_devel("Finding our node name"); if ((uname = hb_cluster->llc_ops->get_mynodeid(hb_cluster)) == NULL) { crm_err("get_mynodeid() failed"); return FALSE; } cib_our_uname = crm_strdup(uname); crm_info("FSA Hostname: %s", cib_our_uname); - crm_debug("Adding channel to mainloop"); + crm_devel("Adding channel to mainloop"); G_main_add_IPC_Channel( G_PRIORITY_HIGH, hb_cluster->llc_ops->ipcchan(hb_cluster), FALSE, cib_ha_dispatch, hb_cluster /* userdata */, cib_ha_connection_destroy); return TRUE; } void cib_ha_connection_destroy(gpointer user_data) { } gboolean cib_shutdown(int nsig, gpointer unused) { static int shuttingdown = 0; if (!shuttingdown) { shuttingdown = 1; } if (mainloop != NULL && g_main_is_running(mainloop)) { g_main_quit(mainloop); } else { exit(LSB_EXIT_OK); } return TRUE; } gboolean startCib(const char *filename) { crm_data_t *cib = readCibXmlFile(filename); if (initializeCib(cib)) { crm_info("CIB Initialization completed successfully"); } else { /* free_xml(cib); */ crm_warn("CIB Initialization failed, " "starting with an empty default."); activateCibXml(createEmptyCib(), filename); } return TRUE; } diff --git a/crm/cib/messages.c b/crm/cib/messages.c index d70cf819b4..f98fc0c8b9 100644 --- a/crm/cib/messages.c +++ b/crm/cib/messages.c @@ -1,760 +1,760 @@ -/* $Id: messages.c,v 1.26 2005/02/18 10:36:10 andrew Exp $ */ +/* $Id: messages.c,v 1.27 2005/02/19 18:11:03 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 #include #include #include #include #include #include #include #include #include extern const char *cib_our_uname; enum cib_errors revision_check(crm_data_t *cib_update, crm_data_t *cib_copy, int flags); int get_revision(crm_data_t *xml_obj, int cur_revision); enum cib_errors updateList( crm_data_t *local_cib, crm_data_t *update_command, crm_data_t *failed, int operation, const char *section); crm_data_t *createCibFragmentAnswer(const char *section, crm_data_t *failed); gboolean replace_section( const char *section, crm_data_t *tmpCib, crm_data_t *command); gboolean check_generation(crm_data_t *newCib, crm_data_t *oldCib); gboolean update_results( crm_data_t *failed, crm_data_t *target, int operation, int return_code); enum cib_errors cib_update_counter( crm_data_t *xml_obj, const char *field, gboolean reset); int set_connected_peers(crm_data_t *xml_obj); void GHFunc_count_peers(gpointer key, gpointer value, gpointer user_data); int set_connected_peers(crm_data_t *xml_obj) { int active = 0; char *peers_s = NULL; g_hash_table_foreach(peer_hash, GHFunc_count_peers, &active); peers_s = crm_itoa(active); set_xml_property_copy(xml_obj, XML_ATTR_NUMPEERS, peers_s); crm_free(peers_s); return active; } void GHFunc_count_peers(gpointer key, gpointer value, gpointer user_data) { int *active = user_data; if(safe_str_eq(value, ONLINESTATUS)) { (*active)++; } else if(safe_str_eq(value, JOINSTATUS)) { (*active)++; } } enum cib_errors cib_process_default( const char *op, int options, const char *section, crm_data_t *input, crm_data_t **answer) { enum cib_errors result = cib_ok; crm_debug("Processing \"%s\" event", op); if(answer != NULL) { *answer = NULL; } if(op == NULL) { result = cib_operation; crm_err("No operation specified\n"); } else if(strcmp(CRM_OP_NOOP, op) == 0) { ; } else { result = cib_NOTSUPPORTED; crm_err("Action [%s] is not supported by the CIB", op); } return result; } enum cib_errors cib_process_quit( const char *op, int options, const char *section, crm_data_t *input, crm_data_t **answer) { enum cib_errors result = cib_ok; crm_debug("Processing \"%s\" event", op); cib_pre_notify(op, get_the_CIB(), NULL); crm_warn("The CRMd has asked us to exit... complying"); exit(0); return result; } enum cib_errors cib_process_readwrite( const char *op, int options, const char *section, crm_data_t *input, crm_data_t **answer) { enum cib_errors result = cib_ok; crm_debug("Processing \"%s\" event", op); if(safe_str_eq(op, CRM_OP_CIB_ISMASTER)) { if(cib_is_master == TRUE) { result = cib_ok; } else { result = cib_not_master; } return result; } cib_pre_notify(op, get_the_CIB(), NULL); if(safe_str_eq(op, CRM_OP_CIB_MASTER)) { crm_info("We are now in R/W mode"); cib_is_master = TRUE; } else { crm_info("We are now in R/O mode"); cib_is_master = FALSE; } cib_post_notify(op, NULL, result, NULL); return result; } enum cib_errors cib_process_ping( const char *op, int options, const char *section, crm_data_t *input, crm_data_t **answer) { enum cib_errors result = cib_ok; crm_debug("Processing \"%s\" event", op); if(answer != NULL) { *answer = createPingAnswerFragment(CRM_SYSTEM_CIB, "ok"); } return result; } enum cib_errors cib_process_query( const char *op, int options, const char *section, crm_data_t *input, crm_data_t **answer) { crm_data_t *obj_root = NULL; enum cib_errors result = cib_ok; crm_debug("Processing \"%s\" event for section=%s", op, crm_str(section)); if(answer != NULL) { *answer = NULL; } else { return cib_ok; } #if 0 if (safe_str_eq(XML_CIB_TAG_SECTION_ALL, section)) { section = NULL; } #else if (section == NULL) { section = XML_CIB_TAG_SECTION_ALL; } #endif *answer = create_xml_node(NULL, XML_TAG_FRAGMENT); /* set_xml_property_copy(*answer, XML_ATTR_SECTION, section); */ set_xml_property_copy(*answer, "generated_on", cib_our_uname); obj_root = get_object_root(section, get_the_CIB()); if(obj_root == NULL) { result = cib_NOTEXISTS; } else if(obj_root == get_the_CIB()) { add_node_copy(*answer, obj_root); } else { crm_data_t *cib = createEmptyCib(); crm_data_t *query_obj_root = get_object_root(section, cib); copy_in_properties(cib, get_the_CIB()); xml_child_iter( obj_root, an_obj, NULL, add_node_copy(query_obj_root, an_obj); ); add_node_copy(*answer, cib); free_xml(cib); } return result; } enum cib_errors cib_process_erase( const char *op, int options, const char *section, crm_data_t *input, crm_data_t **answer) { crm_data_t *tmpCib = NULL; enum cib_errors result = cib_ok; crm_debug("Processing \"%s\" event", op); if(answer != NULL) { *answer = NULL; } tmpCib = createEmptyCib(); result = revision_check(get_the_CIB(), tmpCib, options); copy_in_properties(tmpCib, get_the_CIB()); cib_pre_notify(op, the_cib, tmpCib); cib_update_counter(tmpCib, XML_ATTR_NUMUPDATES, TRUE); if(result == cib_ok && activateCibXml(tmpCib, CIB_FILENAME) < 0) { result = cib_ACTIVATION; } cib_post_notify(op, NULL, result, the_cib); if(answer != NULL) { *answer = createCibFragmentAnswer(NULL, NULL); } return result; } enum cib_errors cib_process_bump( const char *op, int options, const char *section, crm_data_t *input, crm_data_t **answer) { crm_data_t *tmpCib = NULL; enum cib_errors result = cib_ok; crm_debug("Processing \"%s\" event for epoche=%s", op, crm_str(crm_element_value(the_cib, XML_ATTR_GENERATION))); if(answer != NULL) { *answer = NULL; } cib_pre_notify(op, get_the_CIB(), NULL); tmpCib = copy_xml_node_recursive(the_cib); cib_update_counter(tmpCib, XML_ATTR_GENERATION, FALSE); cib_update_counter(tmpCib, XML_ATTR_NUMUPDATES, FALSE); if(activateCibXml(tmpCib, CIB_FILENAME) < 0) { result = cib_ACTIVATION; } cib_post_notify(op, NULL, result, get_the_CIB()); if(answer != NULL) { *answer = createCibFragmentAnswer(NULL, NULL); } return result; } enum cib_errors cib_update_counter(crm_data_t *xml_obj, const char *field, gboolean reset) { char *new_value = NULL; char *old_value = NULL; int int_value = -1; /* modify the timestamp */ set_node_tstamp(xml_obj); if(reset == FALSE && crm_element_value(xml_obj, field) != NULL) { old_value = crm_element_value_copy(xml_obj, field); } if(old_value != NULL) { crm_malloc(new_value, 128*(sizeof(char))); int_value = atoi(old_value); sprintf(new_value, "%d", ++int_value); } else { new_value = crm_strdup("1"); } crm_trace("%s %d(%s)->%s", field, int_value, crm_str(old_value), crm_str(new_value)); set_xml_property_copy(xml_obj, field, new_value); crm_free(new_value); if(safe_str_eq(field, XML_ATTR_NUMUPDATES)) { set_connected_peers(xml_obj); if(cib_have_quorum) { set_xml_property_copy( xml_obj, XML_ATTR_HAVE_QUORUM, XML_BOOLEAN_TRUE); } else { set_xml_property_copy( xml_obj, XML_ATTR_HAVE_QUORUM, XML_BOOLEAN_FALSE); } } crm_free(old_value); return cib_ok; } enum cib_errors cib_process_replace( const char *op, int options, const char *section, crm_data_t *input, crm_data_t **answer) { gboolean verbose = FALSE; crm_data_t *tmpCib = NULL; crm_data_t *cib_update = NULL; crm_data_t *the_update = NULL; char *section_name = NULL; enum cib_errors result = cib_ok; crm_debug("Processing \"%s\" event for section=%s", op, crm_str(section)); if(answer != NULL) { *answer = NULL; } if (options & cib_verbose) { verbose = TRUE; } if(safe_str_eq(XML_CIB_TAG_SECTION_ALL, section)) { section = NULL; } cib_update = find_xml_node(input, XML_TAG_CIB, TRUE); if (cib_update == NULL) { result = cib_NOOBJECT; } else if (section == NULL) { tmpCib = copy_xml_node_recursive(cib_update); the_update = cib_update; section_name = crm_strdup(crm_element_name(tmpCib)); } else { tmpCib = copy_xml_node_recursive(get_the_CIB()); section_name = crm_strdup(section); replace_section(section_name, tmpCib, input); the_update = get_object_root(section_name, cib_update); } cib_pre_notify( op, get_object_root(section_name, get_the_CIB()), the_update); cib_update_counter(tmpCib, XML_ATTR_NUMUPDATES, FALSE); result = revision_check(the_update, tmpCib, options); copy_in_properties(tmpCib, cib_update); if (result == cib_ok && activateCibXml(tmpCib, CIB_FILENAME) < 0) { crm_warn("Replacment of section=%s failed", section); result = cib_ACTIVATION; } if (verbose || result != cib_ok) { if(answer != NULL) { *answer = createCibFragmentAnswer(section_name, NULL); } } cib_post_notify(op, the_update, result, get_object_root(section_name, get_the_CIB())); crm_free(section_name); return result; } /* FILE *msg_cibup_strm = NULL; */ enum cib_errors cib_process_modify( const char *op, int options, const char *section, crm_data_t *input, crm_data_t **answer) { gboolean verbose = FALSE; enum cib_errors result = cib_ok; char *section_name = NULL; crm_data_t *failed = NULL; crm_data_t *cib_update = NULL; crm_data_t *the_update = NULL; int cib_update_op = CIB_OP_NONE; crm_data_t *tmpCib = NULL; crm_debug("Processing \"%s\" event for section=%s", op, crm_str(section)); failed = create_xml_node(NULL, XML_TAG_FAILED); if (strcmp(CRM_OP_CIB_CREATE, op) == 0) { cib_update_op = CIB_OP_ADD; } else if (strcmp(CRM_OP_CIB_UPDATE, op) == 0 || strcmp(CRM_OP_JOINACK, op) == 0 || strcmp(CRM_OP_SHUTDOWN_REQ, op) == 0) { cib_update_op = CIB_OP_MODIFY; } else if (strcmp(CRM_OP_CIB_DELETE, op) == 0) { cib_update_op = CIB_OP_DELETE; } else { crm_err("Incorrect request handler invoked for \"%s\" op", crm_str(op)); return cib_operation; } result = cib_ok; if (options & cib_verbose) { verbose = TRUE; } if(safe_str_eq(XML_CIB_TAG_SECTION_ALL, section)) { section = NULL; } if(input == NULL) { crm_err("Cannot perform modification with no data"); return cib_NOOBJECT; } tmpCib = copy_xml_node_recursive(get_the_CIB()); cib_update = find_xml_node(input, XML_TAG_CIB, TRUE); /* do logging */ the_update = get_object_root(section, cib_update); crm_validate_data(the_update); crm_validate_data(tmpCib); cib_pre_notify(op, get_object_root(section, tmpCib), the_update); crm_validate_data(the_update); crm_validate_data(tmpCib); result = revision_check(cib_update, tmpCib, options); copy_in_properties(tmpCib, cib_update); /* make changes to a temp copy then activate */ if(section == NULL) { /* order is no longer important here */ section_name = crm_strdup(crm_element_name(tmpCib)); if(result == cib_ok) { result = updateList( tmpCib, input, failed, cib_update_op, XML_CIB_TAG_NODES); } if(result == cib_ok) { result = updateList( tmpCib, input, failed, cib_update_op, XML_CIB_TAG_RESOURCES); } if(result == cib_ok) { result = updateList( tmpCib, input, failed, cib_update_op, XML_CIB_TAG_CONSTRAINTS); } if(result == cib_ok) { result = updateList(tmpCib, input, failed, cib_update_op, XML_CIB_TAG_STATUS); } } else { section_name = crm_strdup(section); result = updateList(tmpCib, input, failed, cib_update_op, section); } crm_trace("Activating temporary CIB"); cib_update_counter(tmpCib, XML_ATTR_NUMUPDATES, FALSE); if (result == cib_ok && activateCibXml(tmpCib, CIB_FILENAME) < 0) { result = cib_ACTIVATION; } else if (result != cib_ok || xml_has_children(failed)) { if(result == cib_ok) { result = cib_unknown; } crm_xml_err(failed, "CIB Update failures"); } if (verbose || xml_has_children(failed) || result != cib_ok) { *answer = createCibFragmentAnswer(section_name, failed); } cib_post_notify(op, the_update, result, get_object_root(section_name, get_the_CIB())); free_xml(failed); crm_free(section_name); return result; } gboolean replace_section(const char *section, crm_data_t *tmpCib, crm_data_t *fragment) { crm_data_t *parent = NULL, *cib_updates = NULL, *new_section = NULL, *old_section = NULL; cib_updates = find_xml_node(fragment, XML_TAG_CIB, TRUE); /* find the old and new versions of the section */ new_section = get_object_root(section, cib_updates); old_section = get_object_root(section, tmpCib); if(old_section == NULL) { crm_err("The CIB is corrupt, cannot replace missing section %s", section); return FALSE; } else if(new_section == NULL) { crm_err("The CIB is corrupt, cannot set section %s to nothing", section); return FALSE; } parent = crm_element_parent(old_section); /* unlink and free the old one */ unlink_xml_node(old_section); free_xml(old_section); /* add the new copy */ add_node_copy(parent, new_section); return TRUE; } enum cib_errors updateList(crm_data_t *local_cib, crm_data_t *update_fragment, crm_data_t *failed, int operation, const char *section) { int rc = cib_ok; crm_data_t *this_section = get_object_root(section, local_cib); crm_data_t *cib_updates = NULL; crm_data_t *xml_section = NULL; cib_updates = find_xml_node(update_fragment, XML_TAG_CIB, TRUE); xml_section = get_object_root(section, cib_updates); if (section == NULL || xml_section == NULL) { crm_err("Section %s not found in message." " CIB update is corrupt, ignoring.", crm_str(section)); return cib_NOSECTION; } if(CIB_OP_NONE > operation > CIB_OP_MAX) { crm_err("Invalid operation on section %s", crm_str(section)); return cib_operation; } set_node_tstamp(this_section); xml_child_iter( xml_section, a_child, NULL, rc = cib_ok; if(operation == CIB_OP_DELETE) { rc = delete_cib_object(this_section, a_child); update_results(failed, a_child, operation, rc); } else if(operation == CIB_OP_MODIFY) { rc = update_cib_object(this_section, a_child, FALSE); update_results(failed, a_child, operation, rc); } else { rc = add_cib_object(this_section, a_child); update_results(failed, a_child, operation, rc); } ); if(rc == cib_ok && xml_has_children(failed)) { rc = cib_unknown; } return rc; } crm_data_t* createCibFragmentAnswer(const char *section, crm_data_t *failed) { crm_data_t *cib = NULL; crm_data_t *fragment = NULL; fragment = create_xml_node(NULL, XML_TAG_FRAGMENT); if (section == NULL || strlen(section) == 0 || strcmp(XML_CIB_TAG_SECTION_ALL, section) == 0) { cib = get_the_CIB(); if(cib != NULL) { add_node_copy(fragment, get_the_CIB()); } } else { crm_data_t *obj_root = get_object_root(section, get_the_CIB()); if(obj_root != NULL) { cib = create_xml_node(fragment, XML_TAG_CIB); add_node_copy(cib, obj_root); copy_in_properties(cib, get_the_CIB()); } } if (failed != NULL && xml_has_children(failed)) { add_node_copy(fragment, failed); } set_xml_property_copy(fragment, XML_ATTR_SECTION, section); set_xml_property_copy(fragment, "generated_on", cib_our_uname); return fragment; } gboolean check_generation(crm_data_t *newCib, crm_data_t *oldCib) { if(cib_compare_generation(newCib, oldCib) >= 0) { return TRUE; } crm_warn("Generation from update is older than the existing one"); return FALSE; } gboolean update_results( crm_data_t *failed, crm_data_t *target, int operation, int return_code) { gboolean was_error = FALSE; const char *error_msg = NULL; const char *operation_msg = NULL; crm_data_t *xml_node = NULL; operation_msg = cib_op2string(operation); if (return_code != cib_ok) { error_msg = cib_error2string(return_code); xml_node = create_xml_node(failed, XML_FAIL_TAG_CIB); was_error = TRUE; add_node_copy(xml_node, target); set_xml_property_copy( xml_node, XML_FAILCIB_ATTR_ID, ID(target)); set_xml_property_copy( xml_node, XML_FAILCIB_ATTR_OBJTYPE, TYPE(target)); set_xml_property_copy( xml_node, XML_FAILCIB_ATTR_OP, operation_msg); set_xml_property_copy( xml_node, XML_FAILCIB_ATTR_REASON, error_msg); - crm_debug("Action %s failed: %s (cde=%d)", + crm_warn("Action %s failed: %s (cde=%d)", operation_msg, error_msg, return_code); } else { - crm_debug("CIB %s passed", operation_msg); + crm_devel("CIB %s passed", operation_msg); } return was_error; } enum cib_errors revision_check(crm_data_t *cib_update, crm_data_t *cib_copy, int flags) { enum cib_errors rc = cib_ok; char *revision = crm_element_value_copy( cib_update, XML_ATTR_CIB_REVISION); const char *cur_revision = crm_element_value( cib_copy, XML_ATTR_CIB_REVISION); crm_validate_data(cib_update); crm_validate_data(cib_copy); if(revision == NULL) { return cib_ok; } else if(cur_revision == NULL || strcmp(revision, cur_revision) > 0) { crm_info("Updating CIB revision to %s", revision); set_xml_property_copy( cib_copy, XML_ATTR_CIB_REVISION, revision); } else { /* make sure we end up with the right value in the end */ set_xml_property_copy( cib_update, XML_ATTR_CIB_REVISION, cur_revision); } if(strcmp(revision, cib_feature_revision_s) > 0) { CRM_DEV_ASSERT(cib_is_master == FALSE); CRM_DEV_ASSERT((flags & cib_scope_local) == 0); if(cib_is_master) { crm_err("Update uses an unsupported tag/feature:" " %s vs %s", revision, cib_feature_revision_s); rc = cib_revision_unsupported; } else if(flags & cib_scope_local) { /* an admin has forced a local change using a tag we * dont understand... ERROR */ crm_err("Local update uses an unsupported tag/feature:" " %s vs %s", revision, cib_feature_revision_s); rc = cib_revision_unsupported; } } crm_free(revision); return rc; } diff --git a/crm/cib/notify.c b/crm/cib/notify.c index dd6525878e..0fc70edb46 100644 --- a/crm/cib/notify.c +++ b/crm/cib/notify.c @@ -1,223 +1,223 @@ -/* $Id: notify.c,v 1.12 2005/02/16 18:03:48 andrew Exp $ */ +/* $Id: notify.c,v 1.13 2005/02/19 18:11:03 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 #include #include #include #include #include #include extern GHashTable *client_list; int pending_updates = 0; void cib_notify_client(gpointer key, gpointer value, gpointer user_data); void attach_cib_generation(HA_Message *msg, const char *field, crm_data_t *a_cib); void cib_notify_client(gpointer key, gpointer value, gpointer user_data) { HA_Message *update_msg = user_data; cib_client_t *client = value; CRM_DEV_ASSERT(client != NULL); CRM_DEV_ASSERT(update_msg != NULL); if(client != NULL && safe_str_eq(client->channel_name, cib_channel_callback)) { crm_trace("Notifying client %s of update", client->id); if(client->channel->should_send_blocking == FALSE) { crm_warn("Client channel %s was not set to \"send blocking\"", client->id); client->channel->should_send_blocking = TRUE; } if(msg2ipcchan(update_msg, client->channel) != HA_OK) { crm_err("Notification of client %s failed", client->id); } } } void cib_pre_notify( const char *op, crm_data_t *existing, crm_data_t *update) { HA_Message *update_msg = ha_msg_new(6); const char *type = NULL; const char *id = NULL; if(update != NULL) { id = crm_element_value(update, XML_ATTR_ID); } ha_msg_add(update_msg, F_TYPE, T_CIB_NOTIFY); ha_msg_add(update_msg, F_SUBTYPE, T_CIB_PRE_NOTIFY); ha_msg_add(update_msg, F_CIB_OPERATION, op); if(id != NULL) { ha_msg_add(update_msg, F_CIB_OBJID, id); } if(update != NULL) { ha_msg_add(update_msg, F_CIB_OBJTYPE, crm_element_name(update)); } else if(existing != NULL) { ha_msg_add(update_msg, F_CIB_OBJTYPE, crm_element_name(existing)); } type = cl_get_string(update_msg, F_CIB_OBJTYPE); attach_cib_generation(update_msg, "cib_generation", the_cib); if(existing != NULL) { add_message_xml(update_msg, F_CIB_EXISTING, existing); } if(update != NULL) { add_message_xml(update_msg, F_CIB_UPDATE, update); } g_hash_table_foreach(client_list, cib_notify_client, update_msg); pending_updates++; if(update == NULL) { crm_verbose("Performing operation %s (on section=%s)", op, type); } else { crm_verbose("Performing %s on <%s%s%s>", op, type, id?" id=":"", id?id:""); } crm_msg_del(update_msg); } void cib_post_notify( const char *op, crm_data_t *update, enum cib_errors result, crm_data_t *new_obj) { HA_Message *update_msg = ha_msg_new(8); char *type = NULL; char *id = NULL; if(update != NULL && crm_element_value(new_obj, XML_ATTR_ID) != NULL){ id = crm_element_value_copy(new_obj, XML_ATTR_ID); } ha_msg_add(update_msg, F_TYPE, T_CIB_NOTIFY); ha_msg_add(update_msg, F_SUBTYPE, T_CIB_POST_NOTIFY); ha_msg_add(update_msg, F_CIB_OPERATION, op); ha_msg_add_int(update_msg, F_CIB_RC, result); if(id != NULL) { ha_msg_add(update_msg, F_CIB_OBJID, id); } - crm_debug("beekhof"); + if(update != NULL) { crm_trace("Setting type to update->name: %s", crm_element_name(update)); ha_msg_add(update_msg, F_CIB_OBJTYPE, crm_element_name(update)); type = crm_strdup(crm_element_name(update)); } else if(new_obj != NULL) { crm_trace("Setting type to new_obj->name: %s", crm_element_name(new_obj)); ha_msg_add(update_msg, F_CIB_OBJTYPE, crm_element_name(new_obj)); type = crm_strdup(crm_element_name(new_obj)); } else { crm_trace("Not Setting type"); } attach_cib_generation(update_msg, "cib_generation", the_cib); if(update != NULL) { add_message_xml(update_msg, F_CIB_UPDATE, update); } if(new_obj != NULL) { add_message_xml(update_msg, F_CIB_UPDATE_RESULT, new_obj); } - crm_debug("Notifying clients"); + crm_devel("Notifying clients"); g_hash_table_foreach(client_list, cib_notify_client, update_msg); pending_updates--; if(pending_updates == 0) { ha_msg_mod(update_msg, F_SUBTYPE, T_CIB_UPDATE_CONFIRM); - crm_debug("Sending confirmation to clients"); + crm_devel("Sending confirmation to clients"); g_hash_table_foreach(client_list, cib_notify_client, update_msg); } if(update == NULL) { if(result == cib_ok) { crm_verbose("Operation %s (on section=%s) completed", op, crm_str(type)); } else { crm_warn("Operation %s (on section=%s) FAILED: (%d) %s", op, crm_str(type), result, cib_error2string(result)); } } else { if(result == cib_ok) { crm_verbose("Completed %s of <%s %s%s>", op, crm_str(type), id?"id=":"", id?id:""); } else { crm_warn("%s of <%s %s%s> FAILED: %s", op,crm_str(type), id?"id=":"", id?id:"", cib_error2string(result)); } } crm_free(id); crm_free(type); crm_msg_del(update_msg); - crm_debug("Notify complete"); + crm_devel("Notify complete"); } void attach_cib_generation(HA_Message *msg, const char *field, crm_data_t *a_cib) { crm_data_t *generation = create_xml_node( NULL, XML_CIB_TAG_GENERATION_TUPPLE); if(the_cib != NULL) { copy_in_properties(generation, a_cib); } add_message_xml(msg, field, a_cib); free_xml(generation); } diff --git a/crm/cib/primatives.c b/crm/cib/primatives.c index 4547888213..e631cc278d 100644 --- a/crm/cib/primatives.c +++ b/crm/cib/primatives.c @@ -1,593 +1,593 @@ -/* $Id: primatives.c,v 1.12 2005/02/17 16:27:56 andrew Exp $ */ +/* $Id: primatives.c,v 1.13 2005/02/19 18:11:03 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 #include #include #include /* * In case of confusion, this is the memory management policy for * all functions in this file. * * All add/modify functions use copies of supplied data. * It is therefore appropriate that the callers free the supplied data * at some point after the function has finished. * * All delete functions will handle the freeing of deleted data * but not the function arguments. */ void update_node_state(crm_data_t *existing_node, crm_data_t *update); /* --- Resource */ int addResource(crm_data_t *cib, crm_data_t *anXmlNode) { const char *id = ID(anXmlNode); crm_data_t *root; if (id == NULL || strlen(id) < 1) { return CIBRES_MISSING_ID; } crm_verbose("Adding " XML_CIB_TAG_RESOURCE " (%s)...", id); root = get_object_root(XML_CIB_TAG_RESOURCES, cib); return add_cib_object(root, anXmlNode); } crm_data_t* findResource(crm_data_t *cib, const char *id) { crm_data_t *root = NULL, *ret = NULL; root = get_object_root(XML_CIB_TAG_RESOURCES, cib); ret = find_entity(root, XML_CIB_TAG_RESOURCE, id, FALSE); return ret; } int updateResource(crm_data_t *cib, crm_data_t *anXmlNode) { const char *id = ID(anXmlNode); crm_data_t *root = NULL; if (id == NULL || strlen(id) < 1) { return CIBRES_MISSING_ID; } crm_verbose("Updating " XML_CIB_TAG_RESOURCE " (%s)...", id); root = get_object_root(XML_CIB_TAG_RESOURCES, cib); return update_cib_object(root, anXmlNode, FALSE); } int delResource(crm_data_t *cib, crm_data_t *delete_spec) { const char *id = ID(delete_spec); crm_data_t *root; if(id == NULL || strlen(id) == 0) { return CIBRES_MISSING_ID; } crm_verbose("Deleting " XML_CIB_TAG_RESOURCE " (%s)...", id); root = get_object_root(XML_CIB_TAG_RESOURCES, cib); return delete_cib_object(root, delete_spec); } /* --- Constraint */ int addConstraint(crm_data_t *cib, crm_data_t *anXmlNode) { const char *id = ID(anXmlNode); crm_data_t *root; if (id == NULL || strlen(id) < 1) { return CIBRES_MISSING_ID; } crm_verbose("Adding " XML_CIB_TAG_CONSTRAINT " (%s)...", id); root = get_object_root(XML_CIB_TAG_CONSTRAINTS, cib); return add_cib_object(root, anXmlNode); } crm_data_t* findConstraint(crm_data_t *cib, const char *id) { crm_data_t *root = NULL, *ret = NULL; root = get_object_root(XML_CIB_TAG_CONSTRAINTS, cib); ret = find_entity(root, XML_CIB_TAG_CONSTRAINT, id, FALSE); return ret; } int updateConstraint(crm_data_t *cib, crm_data_t *anXmlNode) { const char *id = ID(anXmlNode); crm_data_t *root; if (id == NULL || strlen(id) < 1) { return CIBRES_MISSING_ID; } crm_verbose("Updating " XML_CIB_TAG_CONSTRAINT " (%s)...", id); root = get_object_root(XML_CIB_TAG_CONSTRAINTS, cib); return update_cib_object(root, anXmlNode, FALSE); } int delConstraint(crm_data_t *cib, crm_data_t *delete_spec) { const char *id = ID(delete_spec); crm_data_t *root; if(id == NULL || strlen(id) == 0) { return CIBRES_MISSING_ID; } crm_verbose("Deleting " XML_CIB_TAG_CONSTRAINT " (%s)...", id); root = get_object_root(XML_CIB_TAG_CONSTRAINTS, cib); return delete_cib_object(root, delete_spec); } /* --- HaNode */ int addHaNode(crm_data_t *cib, crm_data_t *anXmlNode) { const char *id = ID(anXmlNode); crm_data_t *root; if (id == NULL || strlen(id) < 1) { return CIBRES_MISSING_ID; } crm_verbose("Adding " XML_CIB_TAG_NODE " (%s)...", id); root = get_object_root(XML_CIB_TAG_NODES, cib); return add_cib_object(root, anXmlNode); } crm_data_t* findHaNode(crm_data_t *cib, const char *id) { crm_data_t *root = NULL, *ret = NULL; root = get_object_root(XML_CIB_TAG_NODES, cib); ret = find_entity(root, XML_CIB_TAG_NODE, id, FALSE); return ret; } int updateHaNode(crm_data_t *cib, cibHaNode *anXmlNode) { const char *id = ID(anXmlNode); crm_data_t *root; if (id == NULL || strlen(id) < 1) { return CIBRES_MISSING_ID; } crm_verbose("Updating " XML_CIB_TAG_NODE " (%s)...", id); root = get_object_root(XML_CIB_TAG_NODES, cib); return update_cib_object(root, anXmlNode, FALSE); } int delHaNode(crm_data_t *cib, crm_data_t *delete_spec) { const char *id = ID(delete_spec); crm_data_t *root; if(id == NULL || strlen(id) == 0) { return CIBRES_MISSING_ID; } crm_verbose("Deleting " XML_CIB_TAG_NODE " (%s)...", id); root = get_object_root(XML_CIB_TAG_CONSTRAINTS, cib); return delete_cib_object(root, delete_spec); } /* --- Status */ int addStatus(crm_data_t *cib, crm_data_t *anXmlNode) { const char *id = ID(anXmlNode); crm_data_t *root; if (id == NULL || strlen(id) < 1) { return CIBRES_MISSING_ID; } crm_verbose("Adding " XML_CIB_TAG_NODE " (%s)...", id); root = get_object_root(XML_CIB_TAG_STATUS, cib); return add_cib_object(root, anXmlNode); } crm_data_t* findStatus(crm_data_t *cib, const char *id) { crm_data_t *root = NULL, *ret = NULL; root = get_object_root(XML_CIB_TAG_STATUS, cib); ret = find_entity(root, XML_CIB_TAG_STATE, id, FALSE); return ret; } int updateStatus(crm_data_t *cib, crm_data_t *anXmlNode) { const char *id = ID(anXmlNode); crm_data_t *root; if (id == NULL || strlen(id) < 1) { return CIBRES_MISSING_ID; } crm_verbose("Updating " XML_CIB_TAG_NODE " (%s)...", id); root = get_object_root(XML_CIB_TAG_STATUS, cib); return update_cib_object(root, anXmlNode, FALSE); } int delStatus(crm_data_t *cib, crm_data_t *delete_spec) { const char *id = ID(delete_spec); crm_data_t *root; if(id == NULL || strlen(id) == 0) { return CIBRES_MISSING_ID; } crm_verbose("Deleting " XML_CIB_TAG_STATE " (%s)...", id); root = get_object_root(XML_CIB_TAG_STATUS, cib); return delete_cib_object(root, delete_spec); } int delete_cib_object(crm_data_t *parent, crm_data_t *delete_spec) { const char *object_name = NULL; const char *object_id = NULL; crm_data_t *equiv_node = NULL; int result = cib_ok; if(delete_spec != NULL) { object_name = crm_element_name(delete_spec); } object_id = crm_element_value(delete_spec, XML_ATTR_ID); if(delete_spec == NULL) { result = cib_NOOBJECT; } else if(parent == NULL) { result = cib_NOPARENT; } else if(object_id == NULL) { /* placeholder object */ equiv_node = find_xml_node(parent, object_name, FALSE); } else { equiv_node = find_entity( parent, object_name, object_id, FALSE); } cib_pre_notify(CRM_OP_CIB_DELETE, equiv_node, delete_spec); if(result != cib_ok) { ; /* nothing */ } else if(equiv_node == NULL) { result = cib_NOTEXISTS; } else if(xml_has_children(delete_spec)) { /* only leaves are deleted */ #ifdef USE_LIBXML unlink_xml_node(equiv_node); #endif free_xml(equiv_node); equiv_node = NULL; } else { xml_child_iter( delete_spec, child, NULL, int tmp_result = delete_cib_object(equiv_node, child); /* only the first error is likely to be interesting */ if(tmp_result != cib_ok && result == cib_ok) { result = tmp_result; } ); } cib_post_notify(CRM_OP_CIB_DELETE, delete_spec, result, equiv_node); return result; } int add_cib_object(crm_data_t *parent, crm_data_t *new_obj) { enum cib_errors result = cib_ok; const char *object_name = NULL; const char *object_id = NULL; crm_data_t *equiv_node = NULL; if(new_obj != NULL) { object_name = crm_element_name(new_obj); } object_id = crm_element_value(new_obj, XML_ATTR_ID); if(new_obj == NULL) { result = cib_NOOBJECT; } else if(parent == NULL) { result = cib_NOPARENT; } else if(object_id == NULL) { /* placeholder object */ equiv_node = find_xml_node(parent, object_name, FALSE); } else { equiv_node = find_entity( parent, object_name, object_id, FALSE); } cib_pre_notify(CRM_OP_CIB_CREATE, equiv_node, new_obj); if(result != cib_ok) { ; /* do nothing */ } else if(equiv_node != NULL) { result = cib_EXISTS; } else if(add_node_copy(parent, new_obj) == NULL) { result = cib_NODECOPY; } cib_post_notify(CRM_OP_CIB_CREATE, new_obj, result, new_obj); return result; } int update_cib_object(crm_data_t *parent, crm_data_t *new_obj, gboolean force) { const char *replace = NULL; const char *object_name = NULL; char *object_id = NULL; crm_data_t *equiv_node = NULL; int result = cib_ok; if(new_obj != NULL) { object_name = crm_element_name(new_obj); if(crm_element_value(new_obj, XML_ATTR_ID) != NULL){ object_id = crm_element_value_copy(new_obj,XML_ATTR_ID); } } if(new_obj == NULL) { result = cib_NOOBJECT; } else if(parent == NULL) { result = cib_NOPARENT; } else if(object_id == NULL) { /* placeholder object */ equiv_node = find_xml_node(parent, object_name, FALSE); } else { equiv_node = find_entity(parent, object_name, object_id, FALSE); } cib_pre_notify(CRM_OP_CIB_UPDATE, equiv_node, new_obj); if(result != cib_ok) { ; /* nothing */ } else if(equiv_node == NULL) { - crm_debug("No node to update, creating %s instead", crm_element_name(new_obj)); + crm_devel("No node to update, creating %s instead", crm_element_name(new_obj)); if(parent == NULL) { crm_warn("Failed to add <%s id=%s> (NULL parent)", object_name, object_id); result = cib_NODECOPY; } else if(add_node_copy(parent, new_obj) == NULL) { crm_warn("Failed to add <%s id=%s>", crm_str(object_name), crm_str(object_id)); result = cib_NODECOPY; } else { - crm_debug("Added <%s id=%s>", + crm_devel("Added <%s id=%s>", crm_str(object_name), crm_str(object_id)); if(object_id == NULL) { /* placeholder object */ equiv_node = find_xml_node( parent, object_name, TRUE); } else { equiv_node = find_entity( parent, object_name, object_id, FALSE); } } } else { crm_verbose("Found node <%s id=%s> to update", crm_str(object_name), crm_str(object_id)); replace = crm_element_value(new_obj, XML_CIB_ATTR_REPLACE); if(replace != NULL) { crm_data_t *remove = find_xml_node( equiv_node, replace, FALSE); if(remove != NULL) { - crm_debug("Replacing node <%s> in <%s>", + crm_devel("Replacing node <%s> in <%s>", replace, crm_element_name(equiv_node)); #ifdef USE_LIBXML unlink_xml_node(remove); #endif free_xml(remove); } xml_remove_prop(new_obj, XML_CIB_ATTR_REPLACE); xml_remove_prop(equiv_node, XML_CIB_ATTR_REPLACE); } if(safe_str_eq(XML_CIB_TAG_STATE, object_name)){ update_node_state(equiv_node, new_obj); } else { copy_in_properties(equiv_node, new_obj); } - crm_debug("Processing children of <%s id=%s>", + crm_devel("Processing children of <%s id=%s>", crm_str(object_name), crm_str(object_id)); xml_child_iter( new_obj, a_child, NULL, int tmp_result = 0; - crm_debug("Updating child <%s id=%s>", + crm_devel("Updating child <%s id=%s>", crm_element_name(a_child), crm_element_value(a_child, XML_ATTR_ID)); tmp_result = update_cib_object(equiv_node, a_child, force); /* only the first error is likely to be interesting */ if(tmp_result != cib_ok) { crm_err("Error updating child <%s id=%s>", crm_element_name(a_child), crm_element_value(a_child, XML_ATTR_ID)); if(result == cib_ok) { result = tmp_result; } } ); } - crm_debug("Finished with <%s id=%s>", + crm_devel("Finished with <%s id=%s>", crm_str(object_name), crm_str(object_id)); cib_post_notify(CRM_OP_CIB_UPDATE, new_obj, result, equiv_node); crm_free(object_id); return result; } void update_node_state(crm_data_t *target, crm_data_t *update) { const char *source = NULL; gboolean any_updates = FALSE; gboolean clear_stonith = FALSE; gboolean clear_shutdown = FALSE; xml_prop_iter( update, local_prop_name, local_prop_value, if(local_prop_name == NULL) { /* error */ } else if(strcmp(local_prop_name, XML_ATTR_ID) == 0) { } else if(strcmp(local_prop_name, XML_ATTR_TSTAMP) == 0) { } else if(strcmp(local_prop_name, XML_CIB_ATTR_CLEAR_SHUTDOWN) == 0) { clear_shutdown = TRUE; } else if(strcmp(local_prop_name, XML_CIB_ATTR_CLEAR_STONITH) == 0) { clear_stonith = TRUE; clear_shutdown = TRUE; } else if(strcmp(local_prop_name, XML_CIB_ATTR_SOURCE) == 0) { source = local_prop_value; } else { any_updates = TRUE; set_xml_property_copy( target, local_prop_name, local_prop_value); } ); xml_remove_prop(target, XML_CIB_ATTR_CLEAR_SHUTDOWN); if(clear_shutdown) { /* unset XML_CIB_ATTR_SHUTDOWN */ crm_verbose("Clearing %s", XML_CIB_ATTR_SHUTDOWN); xml_remove_prop(target, XML_CIB_ATTR_SHUTDOWN); any_updates = TRUE; } xml_remove_prop(target, XML_CIB_ATTR_CLEAR_STONITH); if(clear_stonith) { /* unset XML_CIB_ATTR_STONITH */ crm_verbose("Clearing %s", XML_CIB_ATTR_STONITH); xml_remove_prop(target, XML_CIB_ATTR_STONITH); any_updates = TRUE; } if(any_updates) { set_node_tstamp(target); set_xml_property_copy(target, XML_CIB_ATTR_SOURCE, source); } } diff --git a/crm/common/ctrl.c b/crm/common/ctrl.c index ea8255b3d8..644cba7175 100644 --- a/crm/common/ctrl.c +++ b/crm/common/ctrl.c @@ -1,98 +1,98 @@ -/* $Id: ctrl.c,v 1.7 2005/02/17 16:28:30 andrew Exp $ */ +/* $Id: ctrl.c,v 1.8 2005/02/19 18:11:03 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 #include #include #include static int wdt_interval_ms = 10000; void register_with_apphb(const char *client_name, gboolean(*tickle_fn)(gpointer data)) { char app_instance[APPNAME_LEN]; int hb_intvl_ms = wdt_interval_ms * 2; int rc = 0; /* Register with apphb */ crm_info("Signing in with AppHb"); sprintf(app_instance, "%s_%ld", client_name, (long)getpid()); crm_info("Client %s registering with apphb", app_instance); rc = apphb_register(client_name, app_instance); if (rc < 0) { cl_perror("%s registration failure", app_instance); exit(1); } - crm_debug("Client %s registered with apphb", app_instance); + crm_devel("Client %s registered with apphb", app_instance); crm_info("Client %s setting %d ms apphb heartbeat interval", app_instance, hb_intvl_ms); rc = apphb_setinterval(hb_intvl_ms); if (rc < 0) { cl_perror("%s setinterval failure", app_instance); exit(2); } /* regularly tell apphb that we are alive */ crm_info("Setting up AppHb Heartbeat"); Gmain_timeout_add(wdt_interval_ms, tickle_fn, NULL); } gboolean tickle_apphb_template(gpointer data) { char app_instance[APPNAME_LEN]; int rc = 0; sprintf(app_instance, "%s_%ld", "our_system_name", (long)getpid()); rc = apphb_hb(); if (rc < 0) { cl_perror("%s apphb_hb failure", app_instance); exit(3); } return TRUE; } diff --git a/crm/common/ipc.c b/crm/common/ipc.c index 6a023d444e..b27c040b28 100644 --- a/crm/common/ipc.c +++ b/crm/common/ipc.c @@ -1,335 +1,335 @@ -/* $Id: ipc.c,v 1.20 2005/02/18 15:17:59 andrew Exp $ */ +/* $Id: ipc.c,v 1.21 2005/02/19 18:11:03 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 #include #include #include #include #include #ifdef USE_LIBXML # include # include # include #endif #include #include #include #include /* frees msg */ gboolean send_ipc_message(IPC_Channel *ipc_client, HA_Message *msg) { gboolean all_is_good = TRUE; if (msg == NULL) { crm_err("cant send NULL message"); all_is_good = FALSE; } else if (ipc_client == NULL) { crm_err("cant send message without an IPC Channel"); all_is_good = FALSE; } else if(ipc_client->ch_status != IPC_CONNECT) { crm_err("IPC Channel is not connected"); all_is_good = FALSE; } else if(ipc_client->should_send_blocking == FALSE) { crm_verbose("Setting IPC Channel to blocking..." " least some messages get lost"); ipc_client->should_send_blocking = TRUE; } if(all_is_good && msg2ipcchan(msg, ipc_client) != HA_OK) { crm_err("Could not send IPC, message"); all_is_good = FALSE; if(ipc_client->ch_status != IPC_CONNECT) { crm_err("IPC Channel is no longer connected"); } } - crm_log_message(all_is_good?LOG_DEBUG:LOG_ERR, msg); + crm_log_message(all_is_good?LOG_DEV:LOG_ERR, msg); #ifdef MSG_LOG - crm_log_message_adv(all_is_good?LOG_DEBUG:LOG_ERR, + crm_log_message_adv(all_is_good?LOG_DEV:LOG_ERR, DEVEL_DIR"/outbound.ipc.log", msg); #endif crm_msg_del(msg); return all_is_good; } void default_ipc_connection_destroy(gpointer user_data) { return; } int init_server_ipc_comms( char *channel_name, gboolean (*channel_client_connect)(IPC_Channel *newclient,gpointer user_data), void (*channel_connection_destroy)(gpointer user_data)) { /* the clients wait channel is the other source of events. * This source delivers the clients connection events. * listen to this source at a relatively lower priority. */ char commpath[SOCKET_LEN]; IPC_WaitConnection *wait_ch; sprintf(commpath, WORKING_DIR "/%s", channel_name); wait_ch = wait_channel_init(commpath); if (wait_ch == NULL) { return 1; } G_main_add_IPC_WaitConnection( G_PRIORITY_LOW, wait_ch, NULL, FALSE, channel_client_connect, channel_name, channel_connection_destroy); - crm_debug("Listening on: %s", commpath); + crm_devel("Listening on: %s", commpath); return 0; } GCHSource* init_client_ipc_comms(const char *channel_name, gboolean (*dispatch)( IPC_Channel* source_data, gpointer user_data), void *client_data, IPC_Channel **ch) { IPC_Channel *a_ch = NULL; GCHSource *the_source = NULL; void *callback_data = client_data; a_ch = init_client_ipc_comms_nodispatch(channel_name); if(ch != NULL) { *ch = a_ch; if(callback_data == NULL) { callback_data = a_ch; } } if(a_ch == NULL) { crm_err("Setup of client connection failed," " not adding channel to mainloop"); return NULL; } if(dispatch == NULL) { crm_warn("No dispatch method specified..." "maybe you meant init_client_ipc_comms_nodispatch()?"); } else { - crm_debug("Adding dispatch method to channel"); + crm_devel("Adding dispatch method to channel"); the_source = G_main_add_IPC_Channel( G_PRIORITY_LOW, a_ch, FALSE, dispatch, callback_data, default_ipc_connection_destroy); } return the_source; } IPC_Channel * init_client_ipc_comms_nodispatch(const char *channel_name) { IPC_Channel *ch; GHashTable *attrs; static char path[] = IPC_PATH_ATTR; char *commpath = NULL; int local_socket_len = 2; /* 2 = '/' + '\0' */ local_socket_len += strlen(channel_name); local_socket_len += strlen(WORKING_DIR); crm_malloc(commpath, sizeof(char)*local_socket_len); if(commpath != NULL) { sprintf(commpath, WORKING_DIR "/%s", channel_name); commpath[local_socket_len - 1] = '\0'; - crm_debug("Attempting to talk on: %s", commpath); + crm_devel("Attempting to talk on: %s", commpath); } attrs = g_hash_table_new(g_str_hash,g_str_equal); g_hash_table_insert(attrs, path, commpath); ch = ipc_channel_constructor(IPC_ANYTYPE, attrs); g_hash_table_destroy(attrs); if (ch == NULL) { crm_err("Could not access channel on: %s", commpath); return NULL; } else if (ch->ops->initiate_connection(ch) != IPC_OK) { crm_debug("Could not init comms on: %s", commpath); return NULL; } ch->ops->set_recv_qlen(ch, 100); ch->ops->set_send_qlen(ch, 100); ch->should_send_blocking = TRUE; - crm_debug("Processing of %s complete", commpath); + crm_devel("Processing of %s complete", commpath); return ch; } IPC_WaitConnection * wait_channel_init(char daemonsocket[]) { IPC_WaitConnection *wait_ch; mode_t mask; char path[] = IPC_PATH_ATTR; GHashTable * attrs; attrs = g_hash_table_new(g_str_hash,g_str_equal); g_hash_table_insert(attrs, path, daemonsocket); mask = umask(0); wait_ch = ipc_wait_conn_constructor(IPC_ANYTYPE, attrs); if (wait_ch == NULL) { cl_perror("Can't create wait channel of type %s", IPC_ANYTYPE); exit(1); } mask = umask(mask); g_hash_table_destroy(attrs); return wait_ch; } gboolean subsystem_msg_dispatch(IPC_Channel *sender, void *user_data) { int lpc = 0; IPC_Message *msg = NULL; ha_msg_input_t *new_input = NULL; gboolean all_is_well = TRUE; const char *sys_to; const char *task; while(sender->ops->is_message_pending(sender)) { gboolean process = FALSE; if (sender->ch_status == IPC_DISCONNECT) { /* The message which was pending for us is that * the IPC status is now IPC_DISCONNECT */ break; } if (sender->ops->recv(sender, &msg) != IPC_OK) { perror("Receive failure:"); return !all_is_well; } if (msg == NULL) { crm_err("No message this time"); continue; } lpc++; new_input = new_ipc_msg_input(msg); msg->msg_done(msg); crm_log_message(LOG_MSG, new_input->msg); sys_to = cl_get_string(new_input->msg, F_CRM_SYS_TO); task = cl_get_string(new_input->msg, F_CRM_TASK); if(safe_str_eq(task, CRM_OP_HELLO)) { process = TRUE; } else if(sys_to == NULL) { crm_err("Value of %s was NULL!!", F_CRM_SYS_TO); } else if(task == NULL) { crm_err("Value of %s was NULL!!", F_CRM_TASK); } else { process = TRUE; } if(process){ gboolean (*process_function) (HA_Message *msg, crm_data_t *data, IPC_Channel *sender) = NULL; process_function = user_data; #ifdef MSG_LOG crm_log_message_adv( LOG_MSG, NULL, new_input->msg); #endif if(FALSE == process_function( new_input->msg, new_input->xml, sender)) { crm_warn("Received a message destined for %s" " by mistake", sys_to); } } else { #ifdef MSG_LOG crm_log_message_adv( LOG_ERR, NULL, new_input->msg); #endif } delete_ha_msg_input(new_input); msg = NULL; } /* clean up after a break */ if(msg != NULL) msg->msg_done(msg); crm_verbose("Processed %d messages", lpc); if (sender->ch_status == IPC_DISCONNECT) { crm_err("The server has left us: Shutting down...NOW"); exit(1); /* shutdown properly later */ return !all_is_well; } return all_is_well; } diff --git a/crm/common/msg.c b/crm/common/msg.c index 2c590647ff..d2479f43ed 100644 --- a/crm/common/msg.c +++ b/crm/common/msg.c @@ -1,356 +1,356 @@ -/* $Id: msg.c,v 1.14 2005/02/17 16:29:38 andrew Exp $ */ +/* $Id: msg.c,v 1.15 2005/02/19 18:11:03 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 #include #include HA_Message *create_common_message( HA_Message *original_request, crm_data_t *xml_response_data); crm_data_t* createPingAnswerFragment(const char *from, const char *status) { crm_data_t *ping = NULL; ping = create_xml_node(NULL, XML_CRM_TAG_PING); set_xml_property_copy(ping, XML_PING_ATTR_STATUS, status); set_xml_property_copy(ping, XML_PING_ATTR_SYSFROM, from); return ping; } HA_Message * validate_crm_message( HA_Message *msg, const char *sys, const char *uuid, const char *msg_type) { const char *from = NULL; const char *to = NULL; const char *type = NULL; const char *crm_msg_reference = NULL; HA_Message *action = NULL; const char *true_sys; if (msg == NULL) { return NULL; } from = cl_get_string(msg, F_CRM_SYS_FROM); to = cl_get_string(msg, F_CRM_SYS_TO); type = cl_get_string(msg, F_CRM_MSG_TYPE); crm_msg_reference = cl_get_string(msg, XML_ATTR_REFERENCE); action = msg; true_sys = sys; if (uuid != NULL) { true_sys = generate_hash_key(sys, uuid); } if (to == NULL) { crm_info("No sub-system defined."); action = NULL; } else if (true_sys != NULL && strcmp(to, true_sys) != 0) { - crm_debug("The message is not for this sub-system (%s != %s).", + crm_devel("The message is not for this sub-system (%s != %s).", to, true_sys); action = NULL; } if (type == NULL) { crm_info("No message type defined."); return NULL; } else if (msg_type != NULL && strcmp(msg_type, type) != 0) { crm_info("Expecting a (%s) message but received a (%s).", msg_type, type); action = NULL; } if (crm_msg_reference == NULL) { crm_info("No message crm_msg_reference defined."); action = NULL; } /* if(action != NULL) - crm_debug( + crm_devel( "XML is valid and node with message type (%s) found.", type); - crm_debug("Returning node (%s)", xmlGetNodePath(action)); + crm_devel("Returning node (%s)", xmlGetNodePath(action)); */ return action; } void send_hello_message(IPC_Channel *ipc_client, const char *uuid, const char *client_name, const char *major_version, const char *minor_version) { crm_data_t *hello_node = NULL; HA_Message *hello = NULL; if (uuid == NULL || strlen(uuid) == 0 || client_name == NULL || strlen(client_name) == 0 || major_version == NULL || strlen(major_version) == 0 || minor_version == NULL || strlen(minor_version) == 0) { crm_err("Missing fields, Hello message will not be valid."); return; } hello_node = create_xml_node(NULL, XML_TAG_OPTIONS); set_xml_property_copy(hello_node, "major_version", major_version); set_xml_property_copy(hello_node, "minor_version", minor_version); set_xml_property_copy(hello_node, "client_name", client_name); set_xml_property_copy(hello_node, "client_uuid", uuid); crm_trace("creating hello message"); hello = create_request( CRM_OP_HELLO, hello_node, NULL, NULL, client_name, uuid); send_ipc_message(ipc_client, hello); crm_trace("hello message sent"); free_xml(hello_node); } gboolean process_hello_message(crm_data_t *hello, char **uuid, char **client_name, char **major_version, char **minor_version) { const char *local_uuid; const char *local_client_name; const char *local_major_version; const char *local_minor_version; *uuid = NULL; *client_name = NULL; *major_version = NULL; *minor_version = NULL; if(hello == NULL) { return FALSE; } local_uuid = crm_element_value(hello, "client_uuid"); local_client_name = crm_element_value(hello, "client_name"); local_major_version = crm_element_value(hello, "major_version"); local_minor_version = crm_element_value(hello, "minor_version"); if (local_uuid == NULL || strlen(local_uuid) == 0) { crm_err("Hello message was not valid (field %s not found)", "uuid"); return FALSE; } else if (local_client_name==NULL || strlen(local_client_name)==0){ crm_err("Hello message was not valid (field %s not found)", "client name"); return FALSE; } else if(local_major_version == NULL || strlen(local_major_version) == 0){ crm_err("Hello message was not valid (field %s not found)", "major version"); return FALSE; } else if (local_minor_version == NULL || strlen(local_minor_version) == 0){ crm_err("Hello message was not valid (field %s not found)", "minor version"); return FALSE; } *uuid = crm_strdup(local_uuid); *client_name = crm_strdup(local_client_name); *major_version = crm_strdup(local_major_version); *minor_version = crm_strdup(local_minor_version); - crm_debug("Hello message ok"); + crm_devel("Hello message ok"); return TRUE; } HA_Message * create_request_adv(const char *task, crm_data_t *msg_data, const char *host_to, const char *sys_to, const char *sys_from, const char *uuid_from, const char *origin) { char *true_from = NULL; HA_Message *request = NULL; char *reference = generateReference(task, sys_from); if (uuid_from != NULL) { true_from = generate_hash_key(sys_from, uuid_from); } else if(sys_from != NULL) { true_from = crm_strdup(sys_from); } else { crm_err("No sys from specified"); } /* host_from will get set for us if necessary by CRMd when routed */ request = ha_msg_new(11); ha_msg_add(request, F_CRM_ORIGIN, origin); ha_msg_add(request, F_TYPE, T_CRM); ha_msg_add(request, F_CRM_VERSION, CRM_VERSION); ha_msg_add(request, F_CRM_MSG_TYPE, XML_ATTR_REQUEST); ha_msg_add(request, XML_ATTR_REFERENCE, reference); ha_msg_add(request, F_CRM_TASK, task); ha_msg_add(request, F_CRM_SYS_TO, sys_to); ha_msg_add(request, F_CRM_SYS_FROM, true_from); /* HOSTTO will be ignored if it is to the DC anyway. */ if(host_to != NULL && strlen(host_to) > 0) { ha_msg_add(request, F_CRM_HOST_TO, host_to); } if (msg_data != NULL) { add_message_xml(request, F_CRM_DATA, msg_data); } crm_free(reference); crm_free(true_from); return request; } /* * This method adds a copy of xml_response_data */ HA_Message * create_reply_adv(HA_Message *original_request, crm_data_t *xml_response_data, const char *origin) { HA_Message *reply = NULL; const char *host_from= cl_get_string(original_request, F_CRM_HOST_FROM); const char *sys_from = cl_get_string(original_request, F_CRM_SYS_FROM); const char *sys_to = cl_get_string(original_request, F_CRM_SYS_TO); const char *type = cl_get_string(original_request, F_CRM_MSG_TYPE); const char *operation= cl_get_string(original_request, F_CRM_TASK); const char *crm_msg_reference = cl_get_string( original_request, XML_ATTR_REFERENCE); if (type == NULL) { crm_err("Cannot create new_message," " no message type in original message"); return NULL; #if 0 } else if (strcmp(XML_ATTR_REQUEST, type) != 0) { crm_err("Cannot create new_message," " original message was not a request"); return NULL; #endif } reply = ha_msg_new(10); ha_msg_add(reply, F_CRM_ORIGIN, origin); ha_msg_add(reply, F_TYPE, T_CRM); ha_msg_add(reply, F_CRM_VERSION, CRM_VERSION); ha_msg_add(reply, F_CRM_MSG_TYPE, XML_ATTR_RESPONSE); ha_msg_add(reply, XML_ATTR_REFERENCE, crm_msg_reference); ha_msg_add(reply, F_CRM_TASK, operation); /* since this is a reply, we reverse the from and to */ ha_msg_add(reply, F_CRM_SYS_TO, sys_from); ha_msg_add(reply, F_CRM_SYS_FROM, sys_to); /* HOSTTO will be ignored if it is to the DC anyway. */ if(host_from != NULL && strlen(host_from) > 0) { ha_msg_add(reply, F_CRM_HOST_TO, host_from); } if (xml_response_data != NULL) { add_message_xml(reply, F_CRM_DATA, xml_response_data); } return reply; } /* * This method adds a copy of xml_response_data */ gboolean send_ipc_reply(IPC_Channel *ipc_channel, HA_Message *request, crm_data_t *xml_response_data) { gboolean was_sent = FALSE; HA_Message *reply = NULL; reply = create_reply(request, xml_response_data); if (reply != NULL) { was_sent = send_ipc_message(ipc_channel, reply); } return was_sent; } ha_msg_input_t * new_ha_msg_input(const HA_Message *orig) { ha_msg_input_t *input_copy = NULL; crm_malloc(input_copy, sizeof(ha_msg_input_t)); input_copy->msg = ha_msg_copy(orig); input_copy->xml = get_message_xml(input_copy->msg, F_CRM_DATA); return input_copy; } ha_msg_input_t * new_ipc_msg_input(IPC_Message *orig) { ha_msg_input_t *input_copy = NULL; crm_malloc(input_copy, sizeof(ha_msg_input_t)); input_copy->msg = ipcmsg2hamsg(orig); input_copy->xml = get_message_xml(input_copy->msg, F_CRM_DATA); return input_copy; } void delete_ha_msg_input(ha_msg_input_t *orig) { if(orig == NULL) { return; } crm_msg_del(orig->msg); free_xml(orig->xml); crm_free(orig); } diff --git a/crm/common/utils.c b/crm/common/utils.c index fbfdbb8d98..b694f54432 100644 --- a/crm/common/utils.c +++ b/crm/common/utils.c @@ -1,523 +1,523 @@ -/* $Id: utils.c,v 1.32 2005/02/18 10:40:24 andrew Exp $ */ +/* $Id: utils.c,v 1.33 2005/02/19 18:11:03 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 */ #ifndef _GNU_SOURCE # define _GNU_SOURCE #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define MAXLINE 512 static uint ref_counter = 0; gboolean crm_assert_failed = FALSE; char * generateReference(const char *custom1, const char *custom2) { const char *local_cust1 = custom1; const char *local_cust2 = custom2; int reference_len = 4; char *since_epoch = NULL; reference_len += 20; /* too big */ reference_len += 40; /* too big */ if(local_cust1 == NULL) { local_cust1 = "_empty_"; } reference_len += strlen(local_cust1); if(local_cust2 == NULL) { local_cust2 = "_empty_"; } reference_len += strlen(local_cust2); crm_malloc(since_epoch, reference_len*(sizeof(char))); if(since_epoch != NULL) { sprintf(since_epoch, "%s-%s-%ld-%u", local_cust1, local_cust2, (unsigned long)time(NULL), ref_counter++); } return since_epoch; } gboolean decodeNVpair(const char *srcstring, char separator, char **name, char **value) { int lpc = 0; int len = 0; const char *temp = NULL; crm_trace("Attempting to decode: [%s]", srcstring); if (srcstring != NULL) { len = strlen(srcstring); while(lpc <= len) { if (srcstring[lpc] == separator || srcstring[lpc] == '\0') { crm_malloc(*name, sizeof(char)*lpc+1); if(*name == NULL) { break; /* and return FALSE */ } strncpy(*name, srcstring, lpc); (*name)[lpc] = '\0'; /* this sucks but as the strtok manpage says.. * it *is* a bug */ len = len-lpc; len--; if(len <= 0) { *value = NULL; } else { crm_malloc(*value, sizeof(char)*len+1); if(*value == NULL) { crm_free(*name); break; /* and return FALSE */ } temp = srcstring+lpc+1; strncpy(*value, temp, len); (*value)[len] = '\0'; } return TRUE; } lpc++; } } *name = NULL; *value = NULL; return FALSE; } char * generate_hash_key(const char *crm_msg_reference, const char *sys) { int ref_len = strlen(sys?sys:"none") + strlen(crm_msg_reference) + 2; char *hash_key = NULL; crm_malloc(hash_key, sizeof(char)*(ref_len)); if(hash_key != NULL) { sprintf(hash_key, "%s_%s", sys?sys:"none", crm_msg_reference); hash_key[ref_len-1] = '\0'; - crm_debug("created hash key: (%s)", hash_key); + crm_devel("created hash key: (%s)", hash_key); } return hash_key; } char * generate_hash_value(const char *src_node, const char *src_subsys) { int ref_len; char *hash_value; if (src_node == NULL || src_subsys == NULL) { return NULL; } if (strcmp(CRM_SYSTEM_DC, src_subsys) == 0) { hash_value = crm_strdup(src_subsys); if (!hash_value) { crm_err("memory allocation failed in " "generate_hash_value()\n"); return NULL; } return hash_value; } ref_len = strlen(src_subsys) + strlen(src_node) + 2; crm_malloc(hash_value, sizeof(char)*(ref_len)); if (!hash_value) { crm_err("memory allocation failed in " "generate_hash_value()\n"); return NULL; } snprintf(hash_value, ref_len-1, "%s_%s", src_node, src_subsys); hash_value[ref_len-1] = '\0';/* make sure it is null terminated */ crm_info("created hash value: (%s)", hash_value); return hash_value; } gboolean decode_hash_value(gpointer value, char **node, char **subsys) { char *char_value = (char*)value; int value_len = strlen(char_value); crm_info("Decoding hash value: (%s:%d)", char_value, value_len); if (strcmp(CRM_SYSTEM_DC, (char*)value) == 0) { *node = NULL; *subsys = (char*)crm_strdup(char_value); if (*subsys == NULL) { crm_err("memory allocation failed in " "decode_hash_value()\n"); return FALSE; } crm_info("Decoded value: (%s:%d)", *subsys, (int)strlen(*subsys)); return TRUE; } else if (char_value != NULL) { if (decodeNVpair(char_value, '_', node, subsys)) { return TRUE; } else { *node = NULL; *subsys = NULL; return FALSE; } } return FALSE; } char * crm_itoa(int an_int) { int len = 32; char *buffer = NULL; crm_malloc(buffer, sizeof(char)*(len+1)); if(buffer != NULL) { snprintf(buffer, len, "%d", an_int); } return buffer; } unsigned int crm_log_level = LOG_INFO; extern int LogToLoggingDaemon(int priority, const char * buf, int bstrlen, gboolean use_pri_str); gboolean crm_log_init(const char *entity) { const char *test = "Testing log daemon connection"; /* Redirect messages from glib functions to our handler */ /* cl_malloc_forced_for_glib(); */ g_log_set_handler(NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG | G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL, cl_glib_msg_handler, NULL); /* and for good measure... */ g_log_set_always_fatal((GLogLevelFlags)0); cl_log_set_entity(entity); cl_log_set_facility(LOG_LOCAL7); cl_set_corerootdir(HA_COREDIR); cl_cdtocoredir(); cl_log_send_to_logging_daemon(FALSE); if(HA_FAIL == LogToLoggingDaemon(LOG_INFO, test, strlen(test), TRUE)) { crm_warn("Not using log daemon"); } else { cl_log_send_to_logging_daemon(TRUE); crm_info("Enabled log daemon"); } CL_SIGNAL(DEBUG_INC, alter_debug); CL_SIGNAL(DEBUG_DEC, alter_debug); return TRUE; } /* returns the old value */ unsigned int set_crm_log_level(unsigned int level) { unsigned int old = crm_log_level; while(crm_log_level < level) { alter_debug(DEBUG_INC); } while(crm_log_level > level) { alter_debug(DEBUG_DEC); } return old; } unsigned int get_crm_log_level(void) { return crm_log_level; } void crm_log_message_adv(int level, const char *prefix, const HA_Message *msg) { if(crm_log_level >= level) { do_crm_log(level, NULL, NULL, "#========= %s message start ==========#", prefix?prefix:""); if(level > LOG_DEBUG) { cl_log_message(LOG_DEBUG, msg); } else { cl_log_message(level, msg); } } } void do_crm_log(int log_level, const char *function, const char *alt_debugfile, const char *fmt, ...) { int log_as = log_level; gboolean do_log = FALSE; if(log_level <= crm_log_level) { do_log = TRUE; if(log_level > LOG_INFO) { log_as = LOG_DEBUG; } } if(do_log) { va_list ap; char *buf = NULL; int nbytes; va_start(ap, fmt); nbytes=vasprintf(&buf, fmt, ap); va_end(ap); log_level -= LOG_DEBUG; if(log_level > 0) { if(function == NULL) { cl_log(log_as, "[%d] %s", log_level, buf); } else { cl_log(log_as, "fn(%s [%d]): %s", function, log_level, buf); } } else { if(function == NULL) { cl_log(log_as, "%s", buf); } else { cl_log(log_as, "fn(%s): %s", function, buf); } } if(nbytes > MAXLINE) { cl_log(LOG_WARNING, "Log from %s() was truncated", crm_str(function)); } free(buf); } } int compare_version(const char *version1, const char *version2) { int lpc = 0; char *step1 = NULL, *step2 = NULL; char *rest1 = NULL, *rest2 = NULL; if(version1 != NULL) { rest1 = crm_strdup(version1); } else { version1 = ""; } if(version2 != NULL) { rest2 = crm_strdup(version2); } else { version2 = ""; } while(1) { int cmp = 0; int step1_i = 0; int step2_i = 0; char *tmp1 = NULL, *tmp2 = NULL; decodeNVpair(rest1, '.', &step1, &tmp1); decodeNVpair(rest2, '.', &step2, &tmp2); if(step1 != NULL) { step1_i = atoi(step1); } if(step2 != NULL) { step2_i = atoi(step2); } if(step1_i < step2_i){ cmp = -1; } else if (step1_i > step2_i){ cmp = 1; } crm_trace("compare[%d (%d)]: %d(%s) %d(%s)", lpc++, cmp, step1_i, crm_str(step1), step2_i, crm_str(step2)); crm_free(rest1); crm_free(rest2); rest1 = tmp1; rest2 = tmp2; if(step1 == NULL && step2 == NULL) { break; } crm_free(step1); crm_free(step2); if(cmp < 0) { crm_verbose("%s < %s", version1, version2); return -1; } else if(cmp > 0) { crm_verbose("%s > %s", version1, version2); return 1; } } crm_verbose("%s == %s", version1, version2); return 0; } gboolean do_stderr = FALSE; void alter_debug(int nsig) { CL_SIGNAL(DEBUG_INC, alter_debug); CL_SIGNAL(DEBUG_DEC, alter_debug); switch(nsig) { case DEBUG_INC: crm_log_level++; cl_log(LOG_DEBUG, "Upped log level to %d\n", crm_log_level); break; case DEBUG_DEC: crm_log_level--; cl_log(LOG_DEBUG, "Reduced log level to %d\n", crm_log_level); break; default: fprintf(stderr, "Unknown signal %d\n", nsig); cl_log(LOG_ERR, "Unknown signal %d\n", nsig); break; } } void g_hash_destroy_str(gpointer data) { crm_free(data); } gboolean safe_str_eq(const char *a, const char *b) { if(a == b) { return TRUE; } else if(a == NULL || b == NULL) { return FALSE; } else if(strcmp(a, b) == 0) { return TRUE; } return FALSE; } gboolean safe_str_neq(const char *a, const char *b) { if(a == b) { return FALSE; } else if(a==NULL || b==NULL) { return TRUE; } else if(strcmp(a, b) == 0) { return FALSE; } return TRUE; } char * crm_strdup(const char *a) { char *ret = NULL; CRM_DEV_ASSERT(a != NULL); if(a != NULL) { ret = cl_strdup(a); } else { crm_warn("Cannot dup NULL string"); } return ret; } void set_uuid(ll_cluster_t *hb,crm_data_t *node,const char *attr,const char *uname) { char *uuid_calc = NULL; crm_malloc(uuid_calc, sizeof(char)*50); if(uuid_calc != NULL) { uuid_t uuid_raw; if(hb->llc_ops->get_uuid_by_name( hb, uname, uuid_raw) == HA_FAIL) { crm_err("Could not calculate UUID for %s", uname); crm_free(uuid_calc); uuid_calc = crm_strdup(uname); } else { uuid_unparse(uuid_raw, uuid_calc); } set_xml_property_copy(node, attr, uuid_calc); } crm_free(uuid_calc); }/*memory leak*/ /* BEAM BUG - this is not a memory leak */ diff --git a/crm/common/xml.c b/crm/common/xml.c index c40d48c783..0845ec3213 100644 --- a/crm/common/xml.c +++ b/crm/common/xml.c @@ -1,1594 +1,1594 @@ -/* $Id: xml.c,v 1.35 2005/02/18 10:36:44 andrew Exp $ */ +/* $Id: xml.c,v 1.36 2005/02/19 18:11:03 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 #include #include #include void dump_array( int log_level, const char *message, const char **array, int depth); int print_spaces(char *buffer, int spaces); int log_data_element( const char *function, int log_level, int depth, crm_data_t *data, gboolean formatted); int dump_data_element( int depth, char **buffer, crm_data_t *data, gboolean formatted); #ifndef USE_LIBXML crm_data_t *parse_xml(const char *input, int *offset); int get_tag_name(const char *input); int get_attr_name(const char *input); int get_attr_value(const char *input); #endif crm_data_t * find_xml_node(crm_data_t *root, const char * search_path, gboolean must_find) { if(must_find || root != NULL) { crm_validate_data(root); } if(search_path == NULL) { crm_warn("Will never find "); return NULL; } xml_child_iter( root, a_child, search_path, /* crm_insane("returning node (%s).", xmlGetNodePath(a_child)); */ crm_xml_insane(a_child, "contents\t%s"); crm_xml_insane(root, "found in\t%s"); crm_validate_data(a_child); return a_child; ); if(must_find) { crm_warn("Could not find %s in %s.", search_path, xmlGetNodePath(root)); } else if(root != NULL) { - crm_debug("Could not find %s in %s.", search_path, xmlGetNodePath(root)); + crm_devel("Could not find %s in %s.", search_path, xmlGetNodePath(root)); } else { - crm_debug("Could not find %s in .", search_path); + crm_devel("Could not find %s in .", search_path); } return NULL; } crm_data_t* find_xml_node_nested(crm_data_t *root, const char **search_path, int len) { int j; gboolean is_found = TRUE; crm_data_t *match = NULL; crm_data_t *lastMatch = root; crm_validate_data(root); if(search_path == NULL || search_path[0] == NULL) { crm_warn("Will never find NULL"); return NULL; } dump_array(LOG_INSANE, "Looking for.", search_path, len); for (j=0; j < len; ++j) { if (search_path[j] == NULL) { /* a NULL also means stop searching */ break; } match = find_xml_node(lastMatch, search_path[j], FALSE); if(match == NULL) { is_found = FALSE; break; } else { lastMatch = match; } } if (is_found) { crm_insane("returning node (%s).", xmlGetNodePath(lastMatch)); crm_xml_insane(lastMatch, "found\t%s"); crm_xml_insane(root, "in \t%s"); crm_validate_data(lastMatch); return lastMatch; } dump_array(LOG_WARNING, "Could not find the full path to the node you specified.", search_path, len); crm_warn("Closest point was node (%s) starting from %s.", xmlGetNodePath(lastMatch), crm_element_name(root)); return NULL; } const char * get_xml_attr_nested(crm_data_t *parent, const char **node_path, int length, const char *attr_name, gboolean error) { const char *attr_value = NULL; crm_data_t *attr_parent = NULL; if(error || parent != NULL) { crm_validate_data(parent); } if(parent == NULL) { - crm_debug("Can not find attribute %s in NULL parent",attr_name); + crm_devel("Can not find attribute %s in NULL parent",attr_name); return NULL; } if(attr_name == NULL || strlen(attr_name) == 0) { crm_err("Can not find attribute with no name in %s", xmlGetNodePath(parent)); return NULL; } if(length == 0) { attr_parent = parent; } else { attr_parent = find_xml_node_nested(parent, node_path, length); if(attr_parent == NULL && error) { crm_err("No node at the path you specified."); return NULL; } } attr_value = crm_element_value(attr_parent, attr_name); if((attr_value == NULL || strlen(attr_value) == 0) && error) { crm_err( "No value present for %s at %s", attr_name, xmlGetNodePath(attr_parent)); return NULL; } return attr_value; } crm_data_t* find_entity(crm_data_t *parent, const char *node_name, const char *id, gboolean siblings) { crm_validate_data(parent); xml_child_iter( parent, a_child, node_name, if(id == NULL || safe_str_eq(id,crm_element_value(a_child,XML_ATTR_ID))){ - crm_debug("returning node (%s).", + crm_devel("returning node (%s).", xmlGetNodePath(a_child)); return a_child; } ); if(siblings) { abort(); } crm_warn("node <%s id=%s> not found in %s.", node_name, id, xmlGetNodePath(parent)); return NULL; } void copy_in_properties(crm_data_t* target, crm_data_t *src) { crm_validate_data(src); crm_validate_data(target); if(src == NULL) { crm_warn("No node to copy properties from"); } else if (target == NULL) { crm_err("No node to copy properties into"); } else { xml_prop_iter( src, local_prop_name, local_prop_value, set_xml_property_copy( target, local_prop_name, local_prop_value); ); crm_validate_data(target); } return; } crm_data_t* add_node_copy(crm_data_t *new_parent, crm_data_t *xml_node) { crm_data_t *node_copy = NULL; crm_validate_data(new_parent); crm_validate_data(xml_node); if(xml_node != NULL && new_parent != NULL) { #ifdef USE_LIBXML node_copy = copy_xml_node_recursive(xml_node); xmlAddChild(new_parent, node_copy); #else const char *name = crm_element_name(xml_node); CRM_DEV_ASSERT(HA_OK == ha_msg_addstruct( new_parent, name, xml_node)); node_copy = find_entity(new_parent, crm_element_name(xml_node), ID(xml_node), FALSE); crm_validate_data(node_copy); crm_update_parents(new_parent); crm_validate_data(new_parent); #endif } else if(xml_node == NULL) { crm_err("Could not add copy of NULL node"); } else { crm_err("Could not add copy of node to NULL parent"); } crm_validate_data(node_copy); return node_copy; } const char * set_xml_property_copy(crm_data_t* node, const char *name, const char *value) { const char *parent_name = NULL; if(node != NULL) { parent_name = crm_element_name(node); } crm_insane("[%s] Setting %s to %s", crm_str(parent_name), name, value); if (name == NULL || strlen(name) <= 0) { } else if(node == NULL) { } else if(parent_name == NULL && strcmp(name, F_XML_TAGNAME) != 0) { } else if (value == NULL || strlen(value) <= 0) { xml_remove_prop(node, name); return NULL; } else { #ifdef USE_LIBXML const char *local_name = NULL; const char *local_value = NULL; local_value = crm_strdup(value); local_name = crm_strdup(name); xmlUnsetProp(node, local_name); xmlSetProp(node, local_name, local_value); return xmlGetProp(node, local_name); #else crm_validate_data(node); ha_msg_mod(node, name, value); return crm_element_value(node, name); #endif } return NULL; } crm_data_t* create_xml_node(crm_data_t *parent, const char *name) { const char *local_name = NULL; const char *parent_name = NULL; crm_data_t *ret_value = NULL; if (name == NULL || strlen(name) < 1) { ret_value = NULL; } else { #ifdef USE_LIBXML local_name = crm_strdup(name); if(parent == NULL) ret_value = xmlNewNode(NULL, local_name); else { parent_name = parent->name; ret_value = xmlNewChild(parent, NULL, local_name, NULL); } #else local_name = name; ret_value = ha_msg_new(1); CRM_DEV_ASSERT(ret_value != NULL); set_xml_property_copy(ret_value, XML_ATTR_TAGNAME, name); crm_validate_data(ret_value); if(parent) { crm_validate_data(parent); parent_name = crm_element_name(parent); crm_insane("Attaching %s to parent %s", local_name, parent_name); CRM_DEV_ASSERT(HA_OK == ha_msg_addstruct( parent, name, ret_value)); crm_msg_del(ret_value); crm_update_parents(parent); crm_validate_data(parent); ret_value = parent->values[parent->nfields-1]; crm_validate_data(ret_value); } #endif } crm_insane("Created node [%s [%s]]", crm_str(parent_name), crm_str(local_name)); /* set_node_tstamp(ret_value); */ return ret_value; } void unlink_xml_node(crm_data_t *node) { #ifdef USE_LIBXML xmlUnlinkNode(node); /* this helps us with frees and really should be being done by * the library call */ node->doc = NULL; #else abort(); #endif } void free_xml_fn(crm_data_t *a_node) { if(a_node == NULL) { ; /* nothing to do */ #ifdef USE_LIBXML } else if (a_node->doc != NULL) { xmlFreeDoc(a_node->doc); } else { /* make sure the node is unlinked first */ xmlUnlinkNode(a_node); xmlFreeNode(a_node); #else } else { crm_data_t *parent = NULL; crm_validate_data(a_node); parent = crm_element_parent(a_node); if(parent != NULL) { /* delete it from the parent */ crm_validate_data(parent); cl_msg_remove_value(parent, a_node); crm_validate_data(parent); } else { crm_validate_data(a_node); crm_msg_del(a_node); } #endif } return; } void set_node_tstamp(crm_data_t *a_node) { char *since_epoch = NULL; time_t a_time = time(NULL); crm_validate_data(a_node); if(a_time == (time_t)-1) { cl_perror("set_node_tstamp(): Invalid time returned"); return; } crm_malloc(since_epoch, 128*(sizeof(char))); if(since_epoch != NULL) { sprintf(since_epoch, "%ld", (unsigned long)a_time); #ifdef USE_LIBXML xmlUnsetProp(a_node, XML_ATTR_TSTAMP); xmlSetProp(a_node, XML_ATTR_TSTAMP, since_epoch); #else ha_msg_mod(a_node, XML_ATTR_TSTAMP, since_epoch); crm_validate_data(a_node); crm_free(since_epoch); #endif } } crm_data_t* copy_xml_node_recursive(crm_data_t *src_node) { crm_data_t *new_xml = NULL; #ifdef USE_LIBXML # if 1 return xmlCopyNode(src_node, 1); # else xmlNodePtr local_node = NULL, local_child = NULL; if(src_node == NULL || src_node->name == NULL) { return NULL; } local_node = create_xml_node(NULL, src_node->name); copy_in_properties(local_node, src_node); xml_child_iter( src_node, node_iter, NULL, local_child = copy_xml_node_recursive(node_iter); if(local_child != NULL) { xmlAddChild(local_node, local_child); crm_insane("Copied node [%s [%s]", local_node->name, local_child->name); } ); crm_insane("Returning [%s]", local_node->name); return local_node; # endif #else CRM_DEV_ASSERT(src_node != NULL); CRM_DEV_ASSERT(crm_element_name(src_node) != NULL); if(src_node == NULL) { crm_warn("Attempt to dup NULL XML"); return NULL; } else if(crm_element_name(src_node) == NULL) { crm_xml_err(src_node, "Attempt to dup XML with no name"); return NULL; } new_xml = ha_msg_copy(src_node); crm_set_element_parent(new_xml, NULL); crm_update_parents(new_xml); crm_validate_data(new_xml); #endif return new_xml; } crm_data_t* string2xml(const char *input) { #ifdef USE_LIBXML int lpc = 0; char ch = 0; int input_len = 0; gboolean more = TRUE; gboolean inTag = FALSE; crm_data_t *xml_object = NULL; const char *the_xml; xmlDocPtr doc; xmlBufferPtr xml_buffer = NULL; if(input == NULL || (input_len = strlen(input)) < 0) { return NULL; } xml_buffer = xmlBufferCreate(); for(lpc = 0; (lpc < input_len) && more; lpc++) { ch = input[lpc]; switch(ch) { case EOF: case 0: ch = 0; more = FALSE; xmlBufferAdd(xml_buffer, &ch, 1); break; case '>': case '<': inTag = TRUE; if(ch == '>') inTag = FALSE; xmlBufferAdd(xml_buffer, &ch, 1); break; case '\n': case '\t': case ' ': ch = ' '; if(inTag) { xmlBufferAdd(xml_buffer, &ch, 1); } break; default: xmlBufferAdd(xml_buffer, &ch, 1); break; } } xmlInitParser(); the_xml = xmlBufferContent(xml_buffer); doc = xmlParseMemory(the_xml, strlen(the_xml)); xmlCleanupParser(); if (doc == NULL) { crm_err("Malformed XML [xml=%s]", the_xml); xmlBufferFree(xml_buffer); return NULL; } xmlBufferFree(xml_buffer); xml_object = xmlDocGetRootElement(doc); return xml_object; #else crm_data_t *output = parse_xml(input, NULL); if(output != NULL) { crm_update_parents(output); crm_validate_data(output); } return output; #endif } crm_data_t* file2xml(FILE *input) { #ifdef USE_LIBXML char ch = 0; gboolean more = TRUE; gboolean inTag = FALSE; crm_data_t *xml_object = NULL; xmlBufferPtr xml_buffer = xmlBufferCreate(); const char *the_xml; xmlDocPtr doc; if(input == NULL) { crm_err("File pointer was NULL"); return NULL; } while (more) { ch = fgetc(input); -/* crm_debug("Got [%c]", ch); */ +/* crm_devel("Got [%c]", ch); */ switch(ch) { case EOF: case 0: ch = 0; more = FALSE; xmlBufferAdd(xml_buffer, &ch, 1); break; case '>': case '<': inTag = TRUE; if(ch == '>') inTag = FALSE; xmlBufferAdd(xml_buffer, &ch, 1); break; case '\n': case '\t': case ' ': ch = ' '; if(inTag) { xmlBufferAdd(xml_buffer, &ch, 1); } break; default: xmlBufferAdd(xml_buffer, &ch, 1); break; } } xmlInitParser(); the_xml = xmlBufferContent(xml_buffer); doc = xmlParseMemory(the_xml, strlen(the_xml)); xmlCleanupParser(); if (doc == NULL) { crm_err("Malformed XML [xml=%s]", the_xml); xmlBufferFree(xml_buffer); return NULL; } xmlBufferFree(xml_buffer); xml_object = xmlDocGetRootElement(doc); crm_xml_devel(xml_object, "Created fragment"); return xml_object; #else char *buffer = NULL; crm_data_t *new_obj = NULL; int start = 0, length = 0, read_len = 0; /* see how big the file is */ start = ftell(input); fseek(input, 0L, SEEK_END); length = ftell(input); fseek(input, 0L, start); if(start != ftell(input)) { crm_err("fseek not behaving"); return NULL; } - crm_debug("Reading %d bytes from file", length); + crm_devel("Reading %d bytes from file", length); crm_malloc(buffer, sizeof(char) * (length+1)); read_len = fread(buffer, sizeof(char), length, input); if(read_len != length) { crm_err("Calculated and read bytes differ: %d vs. %d", length, read_len); } else if(length > 0) { new_obj = string2xml(buffer); } else { crm_warn("File contained no XML"); } crm_free(buffer); return new_obj; #endif } void dump_array(int log_level, const char *message, const char **array, int depth) { int j; if(message != NULL) { do_crm_log(log_level, __FUNCTION__, NULL, "%s", message); } do_crm_log(log_level, __FUNCTION__, NULL, "Contents of the array:"); if(array == NULL || array[0] == NULL || depth == 0) { do_crm_log(log_level, __FUNCTION__, NULL, "\t"); return; } for (j=0; j < depth && array[j] != NULL; j++) { if (array[j] == NULL) { break; } do_crm_log(log_level, __FUNCTION__, NULL, "\t--> (%s).", array[j]); } } int write_xml_file(crm_data_t *xml_node, const char *filename) { int res = 0; char now_str[30]; time_t now; - crm_debug("Writing XML out to %s", filename); + crm_devel("Writing XML out to %s", filename); crm_validate_data(xml_node); if (xml_node == NULL) { return -1; } crm_validate_data(xml_node); - crm_xml_debug(xml_node, "Writing out"); + crm_xml_devel(xml_node, "Writing out"); crm_validate_data(xml_node); now = time(NULL); ctime_r(&now, now_str); now_str[24] = EOS; /* replace the newline */ set_xml_property_copy(xml_node, "last_written", now_str); crm_validate_data(xml_node); #ifdef USE_LIBXML if (xml_node->doc == NULL) { xmlDocPtr foo = NULL; crm_insane("Creating doc pointer for %s", xml_node->name); foo = xmlNewDoc("1.0"); xmlDocSetRootElement(foo, xml_node); xmlSetTreeDoc(xml_node, foo); } /* save it. * set arg 3 to 0 to disable line breaks,1 to enable * res == num bytes saved */ res = xmlSaveFormatFile(filename, xml_node->doc, 1); /* for some reason, reading back after saving with * line-breaks doesnt go real well */ #else { FILE *file_output_strm = fopen(filename, "w"); char *buffer = dump_xml_formatted(xml_node); CRM_DEV_ASSERT(buffer != NULL && strlen(buffer) > 0); if(buffer != NULL && strlen(buffer) > 0) { res = fprintf(file_output_strm, "%s", buffer); fflush(file_output_strm); } fclose(file_output_strm); crm_free(buffer); } #endif - crm_debug("Saved %d bytes to the Cib as XML", res); + crm_devel("Saved %d bytes to the Cib as XML", res); return res; } void print_xml_formatted(int log_level, const char *function, crm_data_t *msg, const char *text) { if(msg == NULL) { do_crm_log(log_level, function, NULL, "%s: %s", crm_str(text), ""); return; } crm_validate_data(msg); do_crm_log(log_level, function, NULL, "%s:", crm_str(text)); log_data_element(function, log_level, 0, msg, TRUE); return; } crm_data_t * get_message_xml(const HA_Message *msg, const char *field) { crm_data_t *xml_node = NULL; #ifdef USE_LIBXML const char *xml_text = cl_get_string(msg, field); xml_node = string2xml(xml_text); #else crm_data_t *tmp_node = NULL; crm_validate_data(msg); tmp_node = cl_get_struct(msg, field); if(tmp_node != NULL) { xml_node = copy_xml_node_recursive(tmp_node); } #endif return xml_node; } gboolean add_message_xml(HA_Message *msg, const char *field, crm_data_t *xml) { crm_validate_data(xml); #ifdef USE_LIBXML char *buffer = dump_xml_unformatted(xml); CRM_DEV_ASSERT(buffer != NULL); if(buffer != NULL) { CRM_DEV_ASSERT(cl_is_allocated(buffer)); ha_msg_add(msg, field, buffer); - crm_debug("Added XML to message"); + crm_devel("Added XML to message"); CRM_DEV_ASSERT(cl_is_allocated(buffer)); crm_free(buffer); } #else crm_validate_data(msg); ha_msg_addstruct(msg, field, xml); crm_update_parents(msg); #endif return TRUE; } char * dump_xml_formatted(crm_data_t *an_xml_node) { char *buffer = NULL; #if 0 int len = 0; xmlChar *xml_buffer = NULL; xmlDocPtr foo = NULL; crm_data_t* xml_node = NULL; xml_node = copy_xml_node_recursive(an_xml_node); if (xml_node == NULL) { return NULL; } else { /* reset the doc pointer */ crm_insane("Creating doc pointer for %s", xml_node->name); foo = xmlNewDoc("1.0"); xmlDocSetRootElement(foo, xml_node); xmlSetTreeDoc(xml_node, foo); crm_insane("Doc pointer set for %s", xml_node->name); } crm_insane("Initializing Parser"); xmlInitParser(); crm_insane("Dumping data"); xmlDocDumpFormatMemory(xml_node->doc, &xml_buffer, &len, 1); crm_insane("Cleaning up parser"); xmlCleanupParser(); crm_insane("Copying memory into crm_ space"); if(xml_buffer != NULL && len > 0) { /* copy the text into crm_ memory */ buffer = crm_strdup(xml_buffer); xmlFree(xml_buffer); } crm_insane("Buffer coppied"); free_xml(xml_node); #else char *mutable_ptr = NULL; /* crm_malloc(buffer, 2*(an_xml_node->stringlen)); */ crm_malloc(buffer, sizeof(char)*30000); mutable_ptr = buffer; crm_validate_data(an_xml_node); CRM_DEV_ASSERT(dump_data_element( 0, &mutable_ptr, an_xml_node, TRUE) >= 0); if(crm_assert_failed) { crm_crit("Could not dump the whole message"); } crm_trace("Dumped: %s", buffer); #endif return buffer; } char * dump_xml_unformatted(crm_data_t *an_xml_node) { char *buffer = NULL; #if 0 int lpc = 0; int len = 0; xmlChar *xml_buffer = NULL; xmlDocPtr foo = NULL; crm_data_t* xml_node = NULL; xml_node = copy_xml_node_recursive(an_xml_node); if (xml_node == NULL) { return NULL; } else { /* reset the doc pointer */ crm_insane("Creating doc pointer for %s", xml_node->name); foo = xmlNewDoc("1.0"); xmlDocSetRootElement(foo, xml_node); xmlSetTreeDoc(xml_node, foo); crm_insane("Doc pointer set for %s", xml_node->name); } crm_insane("Initializing Parser"); xmlInitParser(); crm_insane("Dumping data"); xmlDocDumpFormatMemory(xml_node->doc, &xml_buffer, &len, 0); crm_insane("Cleaning up parser"); xmlCleanupParser(); crm_insane("Copying memory into crm_ space"); if(xml_buffer != NULL && len > 0) { /* copy the text into crm_ memory */ buffer = crm_strdup(xml_buffer); xmlFree(xml_buffer); } crm_insane("Buffer coppied"); free_xml(xml_node); /* remove and the newline */ /* for(lpc = 0; lpc < len; lpc++) { */ /* if(buffer[lpc] == '\n') { */ /* buffer[lpc] = ' '; */ /* break; */ /* } else { */ /* buffer[lpc] = ' '; */ /* } */ /* } */ /* for(lpc = len - 2; lpc > 0 && lpc < len; lpc++) { */ for(lpc = 0; lpc < len; lpc++) { if(buffer[lpc] == '\n') { - crm_debug("Reset newline at %d", lpc); + crm_devel("Reset newline at %d", lpc); buffer[lpc] = ' '; } } - crm_debug("Processed %d chars for newlines", lpc); + crm_devel("Processed %d chars for newlines", lpc); #else char *mutable_ptr = NULL; /* crm_malloc(buffer, 2*(an_xml_node->stringlen)); */ crm_malloc(buffer, sizeof(char)*20000); mutable_ptr = buffer; crm_validate_data(an_xml_node); CRM_DEV_ASSERT(dump_data_element( 0, &mutable_ptr, an_xml_node, TRUE) >= 0); if(crm_assert_failed) { crm_crit("Could not dump the whole message"); } crm_trace("Dumped: %s", buffer); #endif return buffer; } #define update_buffer_head(buffer, len) if(len < 0) { \ (*buffer) = EOS; return -1; \ } else { \ buffer += len; \ } int print_spaces(char *buffer, int depth) { int lpc = 0; int spaces = 2*depth; /* <= so that we always print 1 space - prevents problems with syslog */ for(lpc = 0; lpc <= spaces; lpc++) { if(sprintf(buffer, "%c", ' ') < 1) { return -1; } buffer += 1; } return lpc; } int log_data_element( const char *function, int log_level, int depth, crm_data_t *data, gboolean formatted) { int printed = 0; int child_result = 0; int has_children = 0; char print_buffer[1000]; char *buffer = print_buffer; const char *name = crm_element_name(data); crm_insane("Dumping %s...", name); crm_validate_data(data); if(data == NULL) { crm_warn("No data to dump as XML"); return 0; } else if(name == NULL && depth == 0) { xml_child_iter( data, a_child, NULL, child_result = log_data_element( function, log_level, depth, a_child, formatted); if(child_result < 0) { return child_result; } ); return 0; } else if(name == NULL) { crm_err("Cannot dump NULL element at depth %d", depth); return -1; } if(formatted) { printed = print_spaces(buffer, depth); update_buffer_head(buffer, printed); } printed = sprintf(buffer, "<%s", name); update_buffer_head(buffer, printed); xml_prop_iter( data, prop_name, prop_value, if(safe_str_eq(XML_ATTR_TAGNAME, prop_name)) { continue; } else if(safe_str_eq(XML_ATTR_PARENT, prop_name)) { continue; } crm_insane("Dumping <%s %s=\"%s\"...", name, prop_name, prop_value); printed = sprintf(buffer, " %s=\"%s\"", prop_name, prop_value); update_buffer_head(buffer, printed); ); xml_child_iter( data, child, NULL, if(child != NULL) { has_children++; break; } ); printed = sprintf(buffer, "%s>", has_children==0?"/":""); update_buffer_head(buffer, printed); do_crm_log(log_level, function, NULL, "%s", print_buffer); buffer = print_buffer; if(has_children == 0) { return 0; } xml_child_iter( data, a_child, NULL, child_result = log_data_element( function, log_level, depth+1, a_child, formatted); if(child_result < 0) { return -1; } ); if(formatted) { printed = print_spaces(buffer, depth); update_buffer_head(buffer, printed); } do_crm_log(log_level, function, NULL, "%s", print_buffer, name); crm_insane("Dumped %s...", name); return has_children; } int dump_data_element( int depth, char **buffer, crm_data_t *data, gboolean formatted) { int printed = 0; int child_result = 0; int has_children = 0; const char *name = crm_element_name(data); crm_insane("Dumping %s...", name); crm_validate_data(data); if(buffer == NULL || *buffer == NULL) { crm_err("No buffer supplied to dump XML into"); return -1; } else if(data == NULL) { crm_warn("No data to dump as XML"); (*buffer)[0] = EOS; return 0; } else if(name == NULL && depth == 0) { xml_child_iter( data, a_child, NULL, child_result = dump_data_element( depth, buffer, a_child, formatted); if(child_result < 0) { return child_result; } ); return 0; } else if(name == NULL) { crm_err("Cannot dump NULL element at depth %d", depth); return -1; } if(formatted) { printed = print_spaces(*buffer, depth); update_buffer_head(*buffer, printed); } printed = sprintf(*buffer, "<%s", name); update_buffer_head(*buffer, printed); xml_prop_iter(data, prop_name, prop_value, if(safe_str_eq(XML_ATTR_TAGNAME, prop_name)) { continue; } else if(safe_str_eq(XML_ATTR_PARENT, prop_name)) { continue; } crm_insane("Dumping <%s %s=\"%s\"...", name, prop_name, prop_value); printed = sprintf(*buffer, " %s=\"%s\"", prop_name, prop_value); update_buffer_head(*buffer, printed); ); xml_child_iter( data, child, NULL, if(child != NULL) { has_children++; break; } ); printed = sprintf(*buffer, "%s>%s", has_children==0?"/":"", formatted?"\n":""); update_buffer_head(*buffer, printed); if(has_children == 0) { return 0; } xml_child_iter( data, child, NULL, child_result = dump_data_element( depth+1, buffer, child, formatted); if(child_result < 0) { return -1; } ); if(formatted) { printed = print_spaces(*buffer, depth); update_buffer_head(*buffer, printed); } printed = sprintf(*buffer, "%s", name, formatted?"\n":""); update_buffer_head(*buffer, printed); crm_insane("Dumped %s...", name); return has_children; } gboolean xml_has_children(crm_data_t *xml_root) { crm_validate_data(xml_root); #ifdef USE_LIBXML if(xml_root != NULL && xml_root->children != NULL) { return TRUE; } #else xml_child_iter( xml_root, a_child, NULL, return TRUE; ); #endif return FALSE; } void crm_validate_data(const crm_data_t *xml_root) { #ifdef USE_LIBXML CRM_DEV_ASSERT(xml_root != NULL); #else # ifndef XML_PARANOIA_CHECKS CRM_DEV_ASSERT(xml_root != NULL); # else int lpc = 0; CRM_ASSERT(xml_root != NULL); CRM_ASSERT(cl_is_allocated(xml_root) == 1); CRM_ASSERT(xml_root->nfields < 500); for (lpc = 0; lpc < xml_root->nfields; lpc++) { void *child = xml_root->values[lpc]; CRM_ASSERT(cl_is_allocated(xml_root->names[lpc]) == 1); if(child == NULL) { } else if(xml_root->types[lpc] == FT_STRUCT) { crm_validate_data(child); } else if(xml_root->types[lpc] == FT_STRING) { CRM_ASSERT(cl_is_allocated(child) == 1); /* } else { */ /* CRM_DEV_ASSERT(FALSE); */ } } # endif #endif } crm_data_t * crm_element_parent(crm_data_t *data) { #ifdef USE_LIBXML return (data?data->parent:NULL); #else crm_data_t *parent = NULL; ha_msg_value_int(data, XML_ATTR_PARENT, (int*)&parent); return parent; #endif } /* FIXME!! This whole function is evil!! */ void crm_set_element_parent(crm_data_t *data, crm_data_t *parent) { #ifdef USE_LIBXML if(data != NULL) { data->parent = parent; } #else crm_validate_data(data); if(parent != NULL) { ha_msg_mod_int(data, XML_ATTR_PARENT, GPOINTER_TO_INT(parent)); } else if(cl_get_string(data, XML_ATTR_PARENT) != NULL) { cl_msg_remove(data, XML_ATTR_PARENT); } #endif } const char * crm_element_value(crm_data_t *data, const char *name) { #ifdef USE_LIBXML return xmlGetProp(data, name); #else const char *value = NULL; crm_validate_data(data); value = cl_get_string(data, name); if(value != NULL) { cl_is_allocated(value); } return value; #endif } char * crm_element_value_copy(crm_data_t *data, const char *name) { const char *value = NULL; char *value_copy = NULL; #ifdef USE_LIBXML value = xmlGetProp(data, name); #else crm_validate_data(data); value = cl_get_string(data, name); if(value != NULL) { cl_is_allocated(value); } #endif CRM_DEV_ASSERT(value != NULL); if(value != NULL) { value_copy = crm_strdup(value); } return value_copy; } const char * crm_element_name(crm_data_t *data) { #ifdef USE_LIBXML return (data ? data->name : NULL); #else crm_validate_data(data); return cl_get_string(data, XML_ATTR_TAGNAME); #endif } void xml_remove_prop(crm_data_t *obj, const char *name) { #ifdef USE_LIBXML xmlUnsetProp(obj, name); #else if(crm_element_value(obj, name) != NULL) { cl_msg_remove(obj, name); } #endif } void crm_update_parents(crm_data_t *xml_root) { #ifndef USE_LIBXML crm_validate_data(xml_root); xml_child_iter( xml_root, a_child, NULL, crm_set_element_parent(a_child, xml_root); crm_update_parents(a_child); ); #endif } #ifndef USE_LIBXML int get_tag_name(const char *input) { int lpc = 0; char ch = 0; const char *error = NULL; gboolean do_special = FALSE; for(lpc = 0; error == NULL && lpc < strlen(input); lpc++) { ch = input[lpc]; crm_insane("Processing char %c [%d]", ch, lpc); switch(ch) { case EOF: case 0: error = "unexpected EOS"; break; case '?': if(lpc == 0) { /* weird xml tag that we dont care about */ do_special = TRUE; } else { return lpc; } break; case '/': case '>': case '\t': case '\n': case ' ': if(!do_special) { return lpc; } break; default: if(do_special) { } else if('a' <= ch && ch <= 'z') { } else if('A' <= ch && ch <= 'Z') { } else if(ch == '_') { } else { error = "bad character, not in [a-zA-Z_]"; } break; } } crm_err("Error parsing token near %.15s: %s", input, crm_str(error)); return -1; } int get_attr_name(const char *input) { int lpc = 0; char ch = 0; const char *error = NULL; for(lpc = 0; error == NULL && lpc < strlen(input); lpc++) { ch = input[lpc]; crm_insane("Processing char %c[%d]", ch, lpc); switch(ch) { case EOF: case 0: error = "unexpected EOS"; break; case '\t': case '\n': case ' ': error = "unexpected whitespace"; break; case '=': return lpc; default: if('a' <= ch && ch <= 'z') { } else if('A' <= ch && ch <= 'Z') { } else if(ch == '_') { } else { error = "bad character, not in [a-zA-Z_]"; } break; } } crm_err("Error parsing token near %.15s: %s", input, crm_str(error)); return -1; } int get_attr_value(const char *input) { int lpc = 0; char ch = 0; const char *error = NULL; for(lpc = 0; error == NULL && lpc < strlen(input); lpc++) { ch = input[lpc]; crm_insane("Processing char %c [%d]", ch, lpc); switch(ch) { case EOF: case 0: error = "unexpected EOS"; break; case '\\': if(input[lpc+1] == '"') { /* skip over the next char */ lpc++; break; } /*fall through*/ case '"': return lpc; default: break; } } crm_err("Error parsing token near %.15s: %s", input, crm_str(error)); return -1; } crm_data_t* parse_xml(const char *input, int *offset) { int len = 0, lpc = 0; char ch = 0; char *tag_name = NULL; char *attr_name = NULL; char *attr_value = NULL; gboolean more = TRUE; const char *error = NULL; const char *our_input = input; crm_data_t *new_obj = NULL; if(offset != NULL) { our_input = input + (*offset); } len = strlen(our_input); while(lpc < len) { if(our_input[lpc] != '<') { } else if(our_input[lpc+1] == '!') { crm_err("XML Comments are not supported"); crm_insane("Skipping char %c", our_input[lpc]); lpc++; } else if(our_input[lpc+1] == '?') { crm_insane("Skipping char %c", our_input[lpc]); lpc++; } else { lpc++; our_input += lpc; break; } crm_insane("Skipping char %c", our_input[lpc]); lpc++; } len = get_tag_name(our_input); if(len < 0) { return NULL; } crm_malloc(tag_name, len+1); strncpy(tag_name, our_input, len+1); tag_name[len] = EOS; - crm_debug("Processing tag %s", tag_name); + crm_devel("Processing tag %s", tag_name); new_obj = ha_msg_new(1); CRM_DEV_ASSERT(cl_is_allocated(new_obj) == 1); ha_msg_add(new_obj, XML_ATTR_TAGNAME, tag_name); lpc = len; for(; more && error == NULL && lpc < strlen(input); lpc++) { ch = our_input[lpc]; crm_insane("Processing char %c[%d]", ch, lpc); switch(ch) { case EOF: case 0: error = "unexpected EOS"; break; case '/': if(our_input[lpc+1] == '>') { more = FALSE; } break; case '<': if(our_input[lpc+1] != '/') { crm_data_t *child = NULL; - crm_debug("Start parsing child..."); + crm_devel("Start parsing child..."); child = parse_xml(our_input, &lpc); if(child == NULL) { error = "error parsing child"; } else { CRM_DEV_ASSERT(cl_is_allocated(child) == 1); ha_msg_addstruct( new_obj, crm_element_name(child), child); - crm_debug("Finished parsing child: %s", + crm_devel("Finished parsing child: %s", crm_element_name(child)); /* lpc++; /\* > *\/ */ } } else { lpc += 2; /* *\/ */ if(our_input[lpc] != '>') { error = "clase tag cannot contain attrs"; } - crm_debug("Finished parsing ourselves: %s", + crm_devel("Finished parsing ourselves: %s", crm_element_name(new_obj)); } else { error = "Mismatching close tag"; crm_err("Expected: %s", tag_name); } } break; case '=': lpc++; /* = */ /*fall through*/ case '"': lpc++; /* " */ len = get_attr_value(our_input+lpc); if(len < 0) { error = "couldnt find attr_value"; } else { crm_malloc(attr_value, len+1); strncpy(attr_value, our_input+lpc, len+1); attr_value[len] = EOS; lpc += len; /* lpc++; /\* " *\/ */ - crm_debug("creating nvpair: <%s %s=\"%s\"...", + crm_devel("creating nvpair: <%s %s=\"%s\"...", tag_name, crm_str(attr_name), crm_str(attr_value)); ha_msg_add(new_obj, attr_name, attr_value); crm_free(attr_name); crm_free(attr_value); } break; case '>': case ' ': case '\t': case '\n': break; default: len = get_attr_name(our_input+lpc); if(len < 0) { error = "couldnt find attr_name"; } else { crm_malloc(attr_name, len+1); strncpy(attr_name, our_input+lpc, len+1); attr_name[len] = EOS; lpc += len; crm_trace("found attr name: %s", attr_name); lpc--; /* make sure the '=' is seen next time around */ } break; } } if(error) { crm_err("Error parsing token: %s", error); crm_err("Error at or before: %s", our_input+lpc-3); return NULL; } - crm_debug("Finished processing %s tag", tag_name); + crm_devel("Finished processing %s tag", tag_name); crm_free(tag_name); if(offset != NULL) { (*offset) += lpc; } CRM_DEV_ASSERT(cl_is_allocated(new_obj) == 1); return new_obj; } #endif diff --git a/crm/crmd/callbacks.c b/crm/crmd/callbacks.c index 522fade705..68c310cc68 100644 --- a/crm/crmd/callbacks.c +++ b/crm/crmd/callbacks.c @@ -1,464 +1,464 @@ /* * 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 #include #include crm_data_t *find_xml_in_hamessage(const HA_Message * msg); void crmd_ha_connection_destroy(gpointer user_data); void crmd_ha_msg_callback(const HA_Message * msg, void* private_data) { ha_msg_input_t *new_input = NULL; const char *from = ha_msg_value(msg, F_ORIG); const char *seq = ha_msg_value(msg, F_SEQ); const char *op = ha_msg_value(msg, F_CRM_TASK); const char *sys_to = ha_msg_value(msg, F_CRM_SYS_TO); const char *sys_from = ha_msg_value(msg, F_CRM_SYS_FROM); CRM_DEV_ASSERT(from != NULL); if(AM_I_DC && safe_str_eq(sys_from, CRM_SYSTEM_DC) && safe_str_neq(from, fsa_our_uname)) { crm_err("Another DC detected"); crm_log_message_adv(LOG_ERR, "inbound.ha.log", msg); new_input = new_ha_msg_input(msg); register_fsa_input(C_HA_MESSAGE, I_ELECTION, new_input); #if 0 /* still thinking about this one... * could create a timing issue if we dont notice the * election before a new DC is elected. */ } else if(fsa_our_dc != NULL && safe_str_eq(sys_from, CRM_SYSTEM_DC) && safe_str_neq(from, fsa_our_dc)) { crm_warn("Ignoring message from wrong DC: %s vs. %s ", from, fsa_our_dc); crm_log_message_adv(LOG_WARNING, "inbound.ha.log", msg); #endif } else if(safe_str_eq(sys_to, CRM_SYSTEM_DC) && AM_I_DC == FALSE) { crm_verbose("Ignoring message for the DC [F_SEQ=%s]", seq); crm_log_message_adv(LOG_TRACE, "inbound.ha.log", msg); return; } else if(safe_str_eq(from, fsa_our_uname) && safe_str_eq(op, CRM_OP_VOTE)) { crm_log_message_adv(LOG_TRACE, "inbound.ha.log", msg); crm_verbose("Ignoring our own vote [F_SEQ=%s]", seq); return; } else if(AM_I_DC && safe_str_eq(op, CRM_OP_HBEAT)) { crm_verbose("Ignoring our own heartbeat [F_SEQ=%s]", seq); crm_log_message_adv(LOG_MSG, "inbound.ha.log", msg); return; } else { - crm_debug("Processing message"); + crm_devel("Processing message"); crm_log_message_adv(LOG_MSG, "inbound.ha.log", msg); new_input = new_ha_msg_input(msg); register_fsa_input(C_HA_MESSAGE, I_ROUTER, new_input); } #if 0 if(ha_msg_value(msg, XML_ATTR_REFERENCE) == NULL) { ha_msg_add(new_input->msg, XML_ATTR_REFERENCE, seq); } #endif delete_ha_msg_input(new_input); s_crmd_fsa(C_HA_MESSAGE); return; } /* * Apparently returning TRUE means "stay connected, keep doing stuff". * Returning FALSE means "we're all done, close the connection" */ gboolean crmd_ipc_msg_callback(IPC_Channel *client, gpointer user_data) { int lpc = 0; IPC_Message *msg = NULL; ha_msg_input_t *new_input = NULL; gboolean hack_return_good = TRUE; crmd_client_t *curr_client = (crmd_client_t*)user_data; crm_verbose("Processing IPC message from %s", curr_client->table_key); while(client->ops->is_message_pending(client)) { if (client->ch_status == IPC_DISCONNECT) { /* The message which was pending for us is that * the IPC status is now IPC_DISCONNECT */ break; } if (client->ops->recv(client, &msg) != IPC_OK) { perror("Receive failure:"); crm_err("[%s] [receive failure]\n", curr_client->table_key); return !hack_return_good; } else if (msg == NULL) { crm_err("No message from %s this time", curr_client->table_key); continue; } lpc++; new_input = new_ipc_msg_input(msg); msg->msg_done(msg); crm_verbose("Processing msg from %s", curr_client->table_key); crm_log_message_adv(LOG_MSG, "inbound.ipc.log", new_input->msg); crmd_authorize_message(new_input, curr_client); delete_ha_msg_input(new_input); msg = NULL; new_input = NULL; } crm_verbose("Processed %d messages", lpc); if (client->ch_status == IPC_DISCONNECT) { crm_info("received HUP from %s", curr_client->table_key); if (curr_client != NULL) { struct crm_subsystem_s *the_subsystem = NULL; if (curr_client->sub_sys == NULL) { crm_warn("Client hadn't registered with us yet"); } else if (strcmp(CRM_SYSTEM_PENGINE, curr_client->sub_sys) == 0) { the_subsystem = pe_subsystem; } else if (strcmp(CRM_SYSTEM_TENGINE, curr_client->sub_sys) == 0) { the_subsystem = te_subsystem; } else if (strcmp(CRM_SYSTEM_CIB, curr_client->sub_sys) == 0){ the_subsystem = cib_subsystem; } if(the_subsystem != NULL) { cleanup_subsystem(the_subsystem); s_crmd_fsa(C_FSA_INTERNAL); } /* else that was a transient client */ if (curr_client->table_key != NULL) { /* * Key is destroyed below: * curr_client->table_key * Value is cleaned up by: * G_main_del_IPC_Channel */ g_hash_table_remove( ipc_clients, curr_client->table_key); } if(curr_client->client_source != NULL) { gboolean det = G_main_del_IPC_Channel( curr_client->client_source); crm_verbose("crm_client was %s detached", det?"successfully":"not"); } crm_free(curr_client->table_key); crm_free(curr_client->sub_sys); crm_free(curr_client->uuid); crm_free(curr_client); } return !hack_return_good; } return hack_return_good; } void lrm_op_callback(lrm_op_t* op) { /* todo: free op->rsc */ - crm_debug("received callback"); + crm_devel("received callback"); register_fsa_input(C_LRM_OP_CALLBACK, I_LRM_EVENT, op); s_crmd_fsa(C_LRM_OP_CALLBACK); } void crmd_ha_status_callback( const char *node, const char * status, void* private_data) { crm_data_t *update = NULL; - crm_debug("received callback"); + crm_devel("received callback"); crm_notice("Status update: Node %s now has status [%s]\n",node,status); if(AM_I_DC == FALSE) { - crm_debug("Got nstatus callback in non-DC mode"); + crm_devel("Got nstatus callback in non-DC mode"); return; } else if(safe_str_neq(status, DEADSTATUS)) { - crm_debug("nstatus callback was not for a dead node"); + crm_devel("nstatus callback was not for a dead node"); return; } /* this node is taost */ update = create_node_state( node, node, status, NULL, NULL, NULL, NULL); set_xml_property_copy( update, XML_CIB_ATTR_CLEAR_SHUTDOWN, XML_BOOLEAN_TRUE); update_local_cib(create_cib_fragment(update, NULL)); s_crmd_fsa(C_FSA_INTERNAL); free_xml(update); } void crmd_client_status_callback(const char * node, const char * client, const char * status, void * private) { const char *join = NULL; const char *extra = NULL; crm_data_t * update = NULL; - crm_debug("received callback"); + crm_devel("received callback"); set_bit_inplace(fsa_input_register, R_PEER_DATA); if(safe_str_eq(status, JOINSTATUS)){ status = ONLINESTATUS; extra = XML_CIB_ATTR_CLEAR_SHUTDOWN; } else if(safe_str_eq(status, LEAVESTATUS)){ status = OFFLINESTATUS; join = CRMD_JOINSTATE_DOWN; extra = XML_CIB_ATTR_CLEAR_SHUTDOWN; } crm_notice("Status update: Client %s/%s now has status [%s]\n", node, client, status); if(safe_str_eq(node, fsa_our_dc) && status == OFFLINESTATUS) { /* did our DC leave us */ crm_info("Got client status callback - our DC is dead"); register_fsa_input(C_CRMD_STATUS_CALLBACK, I_ELECTION, NULL); } else if(AM_I_DC == FALSE) { - crm_debug("Got client status callback in non-DC mode"); + crm_devel("Got client status callback in non-DC mode"); return; } else { - crm_debug("Got client status callback in DC mode"); + crm_devel("Got client status callback in DC mode"); update = create_node_state( node, node, NULL, NULL, status, join, NULL); set_xml_property_copy(update, extra, XML_BOOLEAN_TRUE); update_local_cib(create_cib_fragment(update, NULL)); free_xml(update); } s_crmd_fsa(C_CRMD_STATUS_CALLBACK); } gboolean lrm_dispatch(int fd, gpointer user_data) { int num_msgs = 0; ll_lrm_t *lrm = (ll_lrm_t*)user_data; - crm_debug("received callback"); + crm_devel("received callback"); num_msgs = lrm->lrm_ops->rcvmsg(lrm, FALSE); if(num_msgs < 1) { crm_err("lrm->lrm_ops->rcvmsg() failed, connection lost?"); clear_bit_inplace(fsa_input_register, R_LRM_CONNECTED); register_fsa_input(C_FSA_INTERNAL, I_ERROR, NULL); s_crmd_fsa(C_FSA_INTERNAL); return FALSE; } return TRUE; } /* #define MAX_EMPTY_CALLBACKS 20 */ /* int empty_callbacks = 0; */ gboolean crmd_ha_msg_dispatch(IPC_Channel *channel, gpointer user_data) { int lpc = 0; ll_cluster_t *hb_cluster = (ll_cluster_t*)user_data; if(hb_cluster->llc_ops->msgready(hb_cluster)) { lpc++; /* invoke the callbacks but dont block */ hb_cluster->llc_ops->rcvmsg(hb_cluster, 0); } - crm_debug("%d HA messages dispatched", lpc); + crm_devel("%d HA messages dispatched", lpc); if (channel && (channel->ch_status == IPC_DISCONNECT)) { crm_crit("Lost connection to heartbeat service."); return FALSE; } return TRUE; } void crmd_ha_connection_destroy(gpointer user_data) { crm_crit("Heartbeat has left us"); /* this is always an error */ /* feed this back into the FSA */ register_fsa_input(C_HA_DISCONNECT, I_ERROR, NULL); s_crmd_fsa(C_HA_DISCONNECT); } gboolean crmd_client_connect(IPC_Channel *client_channel, gpointer user_data) { if (client_channel == NULL) { crm_err("Channel was NULL"); } else if (client_channel->ch_status == IPC_DISCONNECT) { crm_err("Channel was disconnected"); } else { crmd_client_t *blank_client = NULL; - crm_debug("Channel connected"); + crm_devel("Channel connected"); crm_malloc(blank_client, sizeof(crmd_client_t)); if (blank_client == NULL) { return FALSE; } client_channel->ops->set_recv_qlen(client_channel, 100); client_channel->ops->set_send_qlen(client_channel, 100); blank_client->client_channel = client_channel; blank_client->sub_sys = NULL; blank_client->uuid = NULL; blank_client->table_key = NULL; blank_client->client_source = G_main_add_IPC_Channel( G_PRIORITY_LOW, client_channel, FALSE, crmd_ipc_msg_callback, blank_client, default_ipc_connection_destroy); } return TRUE; } gboolean ccm_dispatch(int fd, gpointer user_data) { int rc = 0; oc_ev_t *ccm_token = (oc_ev_t*)user_data; - crm_debug("received callback"); + crm_devel("received callback"); rc = oc_ev_handle_event(ccm_token); if(0 == rc) { return TRUE; } else { crm_err("CCM connection appears to have failed: rc=%d.", rc); register_fsa_input(C_CCM_CALLBACK, I_ERROR, NULL); s_crmd_fsa(C_CCM_CALLBACK); return FALSE; } } void crmd_ccm_msg_callback( oc_ed_t event, void *cookie, size_t size, const void *data) { struct crmd_ccm_data_s *event_data = NULL; - crm_debug("received callback"); + crm_devel("received callback"); if(data != NULL) { crm_malloc(event_data, sizeof(struct crmd_ccm_data_s)); if(event_data != NULL) { event_data->event = &event; event_data->oc = copy_ccm_oc_data( (const oc_ev_membership_t *)data); - crm_debug("Sending callback to the FSA"); + crm_devel("Sending callback to the FSA"); register_fsa_input( C_CCM_CALLBACK, I_CCM_EVENT, (void*)event_data); s_crmd_fsa(C_CCM_CALLBACK); event_data->event = NULL; event_data->oc = NULL; crm_free(event_data); } } else { crm_info("CCM Callback with NULL data... " "I dont /think/ this is bad"); } oc_ev_callback_done(cookie); return; } void crmd_cib_connection_destroy(gpointer user_data) { if(is_set(fsa_input_register, R_SHUTDOWN)) { crm_info("Connection to the CIB terminated..."); return; } /* eventually this will trigger a reconnect, not a shutdown */ crm_err("Connection to the CIB terminated..."); register_fsa_input(C_FSA_INTERNAL, I_ERROR, NULL); clear_bit_inplace(fsa_input_register, R_CIB_CONNECTED); s_crmd_fsa(C_FSA_INTERNAL); return; } diff --git a/crm/crmd/ccm.c b/crm/crmd/ccm.c index db4cc7d76f..2c78830c1b 100644 --- a/crm/crmd/ccm.c +++ b/crm/crmd/ccm.c @@ -1,646 +1,646 @@ -/* $Id: ccm.c,v 1.54 2005/02/18 15:19:17 andrew Exp $ */ +/* $Id: ccm.c,v 1.55 2005/02/19 18:11:04 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 */ /* put these first so that uuid_t is defined without conflicts */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include void oc_ev_special(const oc_ev_t *, oc_ev_class_t , int ); int register_with_ccm(ll_cluster_t *hb_cluster); void msg_ccm_join(const HA_Message *msg, void *foo); void crmd_ccm_msg_callback(oc_ed_t event, void *cookie, size_t size, const void *data); gboolean ghash_node_clfree(gpointer key, gpointer value, gpointer user_data); void ghash_update_cib_node(gpointer key, gpointer value, gpointer user_data); #define CCM_EVENT_DETAIL 1 oc_ev_t *fsa_ev_token; int num_ccm_register_fails = 0; int max_ccm_register_fails = 30; /* A_CCM_CONNECT */ enum crmd_fsa_input do_ccm_control(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { int ret; int fsa_ev_fd; gboolean did_fail = FALSE; if(action & A_CCM_DISCONNECT){ oc_ev_unregister(fsa_ev_token); } if(action & A_CCM_CONNECT) { crm_info("Registering with CCM"); ret = oc_ev_register(&fsa_ev_token); if (ret != 0) { crm_warn("CCM registration failed"); did_fail = TRUE; } if(did_fail == FALSE) { crm_info("Setting up CCM callbacks"); ret = oc_ev_set_callback(fsa_ev_token, OC_EV_MEMB_CLASS, crmd_ccm_msg_callback, NULL); if (ret != 0) { crm_warn("CCM callback not set"); did_fail = TRUE; } } if(did_fail == FALSE) { oc_ev_special(fsa_ev_token, OC_EV_MEMB_CLASS, 0/*don't care*/); crm_info("Activating CCM token"); ret = oc_ev_activate(fsa_ev_token, &fsa_ev_fd); if (ret != 0){ crm_warn("CCM Activation failed"); did_fail = TRUE; } } if(did_fail) { num_ccm_register_fails++; oc_ev_unregister(fsa_ev_token); if(num_ccm_register_fails < max_ccm_register_fails) { crm_warn("CCM Connection failed" " %d times (%d max)", num_ccm_register_fails, max_ccm_register_fails); startTimer(wait_timer); crmd_fsa_stall(); return I_NULL; } else { crm_err("CCM Activation failed %d (max) times", num_ccm_register_fails); register_fsa_error(C_FSA_INTERNAL, I_FAIL, NULL); return I_NULL; } } crm_info("CCM Activation passed... all set to go!"); /* GFDSource* */ G_main_add_fd(G_PRIORITY_LOW, fsa_ev_fd, FALSE, ccm_dispatch, fsa_ev_token, default_ipc_connection_destroy); } if(action & ~(A_CCM_CONNECT|A_CCM_DISCONNECT)) { crm_err("Unexpected action %s in %s", fsa_action2string(action), __FUNCTION__); } return I_NULL; } /* A_CCM_EVENT */ enum crmd_fsa_input do_ccm_event(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { enum crmd_fsa_input return_input = I_NULL; oc_ed_t *event = NULL; const oc_ev_membership_t *oc = NULL; struct crmd_ccm_data_s *ccm_data = fsa_typed_data(fsa_dt_ccm); if(ccm_data == NULL) { crm_err("No data provided to FSA function"); register_fsa_error(C_FSA_INTERNAL, I_FAIL, NULL); return I_NULL; } else if(msg_data->fsa_cause != C_CCM_CALLBACK) { crm_err("FSA function called in response to incorect input"); register_fsa_error(C_FSA_INTERNAL, I_FAIL, NULL); return I_NULL; } event = ccm_data->event; oc = ccm_data->oc; crm_info("event=%s", *event==OC_EV_MS_NEW_MEMBERSHIP?"NEW MEMBERSHIP": *event==OC_EV_MS_NOT_PRIMARY?"NOT PRIMARY": *event==OC_EV_MS_PRIMARY_RESTORED?"PRIMARY RESTORED": *event==OC_EV_MS_EVICTED?"EVICTED": "NO QUORUM MEMBERSHIP"); if(CCM_EVENT_DETAIL) { ccm_event_detail(oc, *event); } if (OC_EV_MS_EVICTED == *event) { /* todo: drop back to S_PENDING instead */ /* get out... NOW! * * go via the error recovery process so that HA will * restart us if required */ register_fsa_error(cause, I_ERROR, msg_data->data); return I_NULL; } /* My understanding is that we will never get both * node leaving *and* node joining callbacks at the * same time. * * This logic would need to change if this is not * the case */ if(oc->m_n_out != 0) { int lpc = 0; int offset = oc->m_out_idx; for(lpc=0; lpc < oc->m_n_out; lpc++) { crm_data_t *node_state = NULL; const char *uname = oc->m_array[offset+lpc].node_uname; crm_info("Node %s has left the cluster," " updating the CIB.", uname); if(uname == NULL) { crm_err("CCM node had no name"); continue; } else if(safe_str_eq(uname, fsa_our_dc)) { /* did our DC leave us */ register_fsa_input(cause, I_ELECTION, NULL); } else if(AM_I_DC) { node_state = create_node_state( NULL, uname, NULL, XML_BOOLEAN_NO, NULL, NULL, NULL); update_local_cib( create_cib_fragment(node_state, NULL)); free_xml(node_state); } } } else if(oc->m_n_in !=0) { /* delay the I_NODE_JOIN until they acknowledge our * DC status and send us their CIB */ } else { CRM_DEV_ASSERT(oc->m_n_in != 0 || oc->m_n_out != 0); crm_warn("So why are we here? What CCM event happened?"); } return return_input; } /* A_CCM_UPDATE_CACHE */ /* * Take the opportunity to update the node status in the CIB as well * (but only if we are the DC) */ enum crmd_fsa_input do_ccm_update_cache(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { enum crmd_fsa_input next_input = I_NULL; int lpc, offset; GHashTable *members = NULL; oc_ed_t *event = NULL; const oc_ev_membership_t *oc = NULL; oc_node_list_t *tmp = NULL, *membership_copy = NULL; struct crmd_ccm_data_s *ccm_data = fsa_typed_data(fsa_dt_ccm); if(ccm_data == NULL) { crm_err("No data provided to FSA function"); register_fsa_error(C_FSA_INTERNAL, I_FAIL, NULL); return I_NULL; } event = ccm_data->event; oc = ccm_data->oc; crm_info("Updating CCM cache after a \"%s\" event.", *event==OC_EV_MS_NEW_MEMBERSHIP?"NEW MEMBERSHIP": *event==OC_EV_MS_NOT_PRIMARY?"NOT PRIMARY": *event==OC_EV_MS_PRIMARY_RESTORED?"PRIMARY RESTORED": *event==OC_EV_MS_EVICTED?"EVICTED": "NO QUORUM MEMBERSHIP"); crm_debug("instace=%d, nodes=%d, new=%d, lost=%d n_idx=%d, " "new_idx=%d, old_idx=%d", oc->m_instance, oc->m_n_member, oc->m_n_in, oc->m_n_out, oc->m_memb_idx, oc->m_in_idx, oc->m_out_idx); crm_malloc(membership_copy, sizeof(oc_node_list_t)); if(membership_copy == NULL) { crm_crit("Couldnt create membership copy - out of memory"); register_fsa_error(C_FSA_INTERNAL, I_ERROR, NULL); return I_NULL; } - crm_debug("Copying members"); + crm_devel("Copying members"); /*--*-- All Member Nodes --*--*/ offset = oc->m_memb_idx; membership_copy->members_size = oc->m_n_member; if(membership_copy->members_size > 0) { membership_copy->members = g_hash_table_new(g_str_hash, g_str_equal); members = membership_copy->members; for(lpc=0; lpc < membership_copy->members_size; lpc++) { oc_node_t *member = NULL; - crm_debug("Copying member %d", lpc); + crm_devel("Copying member %d", lpc); crm_malloc(member, sizeof(oc_node_t)); if(member == NULL) { continue; } member->node_id = oc->m_array[offset+lpc].node_id; member->node_born_on = oc->m_array[offset+lpc].node_born_on; member->node_uname = NULL; if(oc->m_array[offset+lpc].node_uname != NULL) { member->node_uname = crm_strdup(oc->m_array[offset+lpc].node_uname); } else { crm_err("Node %d had a NULL uname", member->node_id); } g_hash_table_insert( members, member->node_uname, member); } } else { membership_copy->members = NULL; } - crm_debug("Copying new members"); + crm_devel("Copying new members"); /*--*-- New Member Nodes --*--*/ offset = oc->m_in_idx; membership_copy->new_members_size = oc->m_n_in; if(membership_copy->new_members_size > 0) { membership_copy->new_members = g_hash_table_new(g_str_hash, g_str_equal); members = membership_copy->new_members; for(lpc=0; lpc < membership_copy->new_members_size; lpc++) { oc_node_t *member = NULL; crm_malloc(member, sizeof(oc_node_t)); if(member == NULL) { continue; } member->node_uname = NULL; member->node_id = oc->m_array[offset+lpc].node_id; member->node_born_on = oc->m_array[offset+lpc].node_born_on; if(oc->m_array[offset+lpc].node_uname != NULL) { member->node_uname = crm_strdup(oc->m_array[offset+lpc].node_uname); } else { crm_err("Node %d had a NULL uname", member->node_id); } g_hash_table_insert( members, member->node_uname, member); g_hash_table_insert(members, member->node_uname, member); } } else { membership_copy->new_members = NULL; } - crm_debug("Copying dead members"); + crm_devel("Copying dead members"); /*--*-- Recently Dead Member Nodes --*--*/ offset = oc->m_out_idx; membership_copy->dead_members_size = oc->m_n_out; if(membership_copy->dead_members_size > 0) { membership_copy->dead_members = g_hash_table_new(g_str_hash, g_str_equal); members = membership_copy->dead_members; for(lpc=0; lpc < membership_copy->dead_members_size; lpc++) { oc_node_t *member = NULL; crm_malloc(member, sizeof(oc_node_t)); if(member == NULL) { continue; } member->node_id = oc->m_array[offset+lpc].node_id; member->node_born_on = oc->m_array[offset+lpc].node_born_on; member->node_uname = NULL; if(oc->m_array[offset+lpc].node_uname != NULL) { member->node_uname = crm_strdup(oc->m_array[offset+lpc].node_uname); } else { crm_err("Node %d had a NULL uname", member->node_id); } g_hash_table_insert( members, member->node_uname, member); g_hash_table_insert(members, member->node_uname, member); } } else { membership_copy->dead_members = NULL; } - crm_debug("Replacing old copies"); + crm_devel("Replacing old copies"); tmp = fsa_membership_copy; fsa_membership_copy = membership_copy; /* Free the old copy */ if(tmp != NULL) { if(tmp->members != NULL) g_hash_table_foreach_remove( tmp->members, ghash_node_clfree, NULL); if(tmp->new_members != NULL) g_hash_table_foreach_remove( tmp->new_members, ghash_node_clfree, NULL); if(tmp->dead_members != NULL) g_hash_table_foreach_remove( tmp->dead_members, ghash_node_clfree, NULL); crm_free(tmp); } - crm_debug("Free'd old copies"); + crm_devel("Free'd old copies"); if(AM_I_DC) { /* should be sufficient for only the DC to do this */ crm_data_t *foo = NULL; - crm_debug("Updating the CIB"); + crm_devel("Updating the CIB"); foo = do_update_cib_nodes(NULL, FALSE); free_xml(foo); } set_bit_inplace(fsa_input_register, R_CCM_DATA); return next_input; } void ccm_event_detail(const oc_ev_membership_t *oc, oc_ed_t event) { int member_id = -1; gboolean member = FALSE; int lpc; int node_list_size; crm_info("-----------------------"); crm_debug("trans=%d, nodes=%d, new=%d, lost=%d n_idx=%d, " "new_idx=%d, old_idx=%d", oc->m_instance, oc->m_n_member, oc->m_n_in, oc->m_n_out, oc->m_memb_idx, oc->m_in_idx, oc->m_out_idx); node_list_size = oc->m_n_member; for(lpc=0; lpcm_array[oc->m_memb_idx+lpc].node_uname, oc->m_array[oc->m_memb_idx+lpc].node_id, oc->m_array[oc->m_memb_idx+lpc].node_born_on); if(safe_str_eq(fsa_our_uname, oc->m_array[oc->m_memb_idx+lpc].node_uname)) { member = TRUE; member_id = oc->m_array[oc->m_memb_idx+lpc].node_id; } } if (member == FALSE) { crm_warn("MY NODE IS NOT IN CCM THE MEMBERSHIP LIST"); } for(lpc=0; lpcm_n_in; lpc++) { crm_info("\tNEW: %s [nodeid=%d, born=%d]", oc->m_array[oc->m_in_idx+lpc].node_uname, oc->m_array[oc->m_in_idx+lpc].node_id, oc->m_array[oc->m_in_idx+lpc].node_born_on); } for(lpc=0; lpcm_n_out; lpc++) { crm_info("\tLOST: %s [nodeid=%d, born=%d]", oc->m_array[oc->m_out_idx+lpc].node_uname, oc->m_array[oc->m_out_idx+lpc].node_id, oc->m_array[oc->m_out_idx+lpc].node_born_on); if(fsa_our_uname != NULL && 0 == strcmp(fsa_our_uname, oc->m_array[oc->m_out_idx+lpc].node_uname)) { crm_err("We're not part of the cluster anymore"); } } crm_info("-----------------------"); } int register_with_ccm(ll_cluster_t *hb_cluster) { return 0; } void msg_ccm_join(const HA_Message *msg, void *foo) { crm_verbose("\n###### Recieved ccm_join message..."); if (msg != NULL) { crm_verbose("[type=%s]", ha_msg_value(msg, F_TYPE)); crm_verbose("[orig=%s]", ha_msg_value(msg, F_ORIG)); crm_verbose("[to=%s]", ha_msg_value(msg, F_TO)); crm_verbose("[status=%s]", ha_msg_value(msg, F_STATUS)); crm_verbose("[info=%s]", ha_msg_value(msg, F_COMMENT)); crm_verbose("[rsc_hold=%s]", ha_msg_value(msg, F_RESOURCES)); crm_verbose("[stable=%s]", ha_msg_value(msg, F_ISSTABLE)); crm_verbose("[rtype=%s]", ha_msg_value(msg, F_RTYPE)); crm_verbose("[ts=%s]", ha_msg_value(msg, F_TIME)); crm_verbose("[seq=%s]", ha_msg_value(msg, F_SEQ)); crm_verbose("[generation=%s]", ha_msg_value(msg, F_HBGENERATION)); /* crm_verbose("[=%s]", ha_msg_value(msg, F_)); */ } return; } struct update_data_s { crm_data_t *updates; const char *state; const char *join; }; crm_data_t* do_update_cib_nodes(crm_data_t *updates, gboolean overwrite) { struct update_data_s update_data; crm_data_t *fragment = updates; crm_data_t *tmp = NULL; if(updates == NULL) { fragment = create_cib_fragment(NULL, NULL); } tmp = find_xml_node(fragment, XML_TAG_CIB, TRUE); tmp = get_object_root(XML_CIB_TAG_STATUS, tmp); CRM_DEV_ASSERT(tmp != NULL); update_data.updates = tmp; update_data.state = XML_BOOLEAN_NO; update_data.join = CRMD_JOINSTATE_DOWN; if(fsa_membership_copy->dead_members != NULL) { g_hash_table_foreach(fsa_membership_copy->dead_members, ghash_update_cib_node, &update_data); } update_data.state = XML_BOOLEAN_YES; update_data.join = NULL; if(overwrite) { update_data.join = CRMD_JOINSTATE_PENDING; } if(fsa_membership_copy->members != NULL) { g_hash_table_foreach(fsa_membership_copy->members, ghash_update_cib_node, &update_data); } /* this is most likely overkill... * * make *sure* that the join status of nodes entering the ccm list * is reset * update_data.join = CRMD_JOINSTATE_PENDING; if(fsa_membership_copy->new_members != NULL) { g_hash_table_foreach(fsa_membership_copy->new_members, ghash_update_cib_node, &update_data); } */ if(update_data.updates != NULL) { update_local_cib(fragment); } /* so it can be freed */ return update_data.updates; } void ghash_update_cib_node(gpointer key, gpointer value, gpointer user_data) { crm_data_t *tmp1 = NULL; const char *node_uname = (const char*)key; struct update_data_s* data = (struct update_data_s*)user_data; const char *state = data->join; crm_verbose("%s processing %s (%s)", __FUNCTION__, node_uname, data->state); tmp1 = create_node_state(node_uname, node_uname, NULL, data->state, NULL, state, NULL); add_node_copy(data->updates, tmp1); free_xml(tmp1); } gboolean ghash_node_clfree(gpointer key, gpointer value, gpointer user_data) { /* value->node_uname is free'd as "key" */ if(key != NULL) { crm_free(key); } if(value != NULL) { crm_free(value); } return TRUE; } diff --git a/crm/crmd/cib.c b/crm/crmd/cib.c index 24aaa8c88c..c6485c82a2 100644 --- a/crm/crmd/cib.c +++ b/crm/crmd/cib.c @@ -1,285 +1,285 @@ /* * 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 /* for access */ #include #include #include /* for calls to open */ #include /* for calls to open */ #include /* for calls to open */ #include /* for getpwuid */ #include /* for initgroups */ #include /* for getrlimit */ #include /* for getrlimit */ #include #include #include #include #include #include #include #include struct crm_subsystem_s *cib_subsystem = NULL; void crmd_update_confirm(const char *event, HA_Message *msg); int cib_retries = 0; /* A_CIB_STOP, A_CIB_START, A_CIB_RESTART, */ enum crmd_fsa_input do_cib_control(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { enum crmd_fsa_input result = I_NULL; struct crm_subsystem_s *this_subsys = cib_subsystem; long long stop_actions = A_CIB_STOP; long long start_actions = A_CIB_START; if(action & stop_actions) { if(fsa_cib_conn != NULL && fsa_cib_conn->state != cib_disconnected) { fsa_cib_conn->cmds->signoff(fsa_cib_conn); } } if(action & start_actions) { if(cur_state != S_STOPPING) { if(fsa_cib_conn == NULL) { fsa_cib_conn = cib_new(); } if(fsa_cib_conn->cmds->signon( fsa_cib_conn, cib_command) != cib_ok) { crm_warn("Could not connect to the CIB service"); } else if(fsa_cib_conn->cmds->add_notify_callback( fsa_cib_conn, T_CIB_UPDATE_CONFIRM, crmd_update_confirm) != cib_ok) { crm_err("Could not set notify callback"); } else if(fsa_cib_conn->cmds->set_connection_dnotify( fsa_cib_conn, crmd_cib_connection_destroy)!=cib_ok){ crm_err("Could not set dnotify callback"); } else { set_bit_inplace( fsa_input_register, R_CIB_CONNECTED); } if(is_set(fsa_input_register, R_CIB_CONNECTED) == FALSE) { crm_warn("Could complete CIB registration %d" " time... retry", cib_retries); if(++cib_retries < 30) { startTimer(wait_timer); crmd_fsa_stall(); } else { crm_err("Could complete CIB" " registration %d times..." " hard error", cib_retries); register_fsa_error( C_FSA_INTERNAL, I_ERROR, NULL); } } else { cib_retries = 0; } } else { crm_info("Ignoring request to start %s after shutdown", this_subsys->name); } } return result; } /* A_CIB_INVOKE, A_CIB_BUMPGEN, A_UPDATE_NODESTATUS */ enum crmd_fsa_input do_cib_invoke(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { HA_Message *answer = NULL; enum crmd_fsa_input result = I_NULL; ha_msg_input_t *cib_msg = fsa_typed_data(fsa_dt_ha_msg); const char *sys_from = cl_get_string(cib_msg->msg, F_CRM_SYS_FROM); if(action & A_CIB_INVOKE) { if(safe_str_eq(sys_from, CRM_SYSTEM_CRMD)) { action = A_CIB_INVOKE_LOCAL; } else if(safe_str_eq(sys_from, CRM_SYSTEM_DC)) { action = A_CIB_INVOKE_LOCAL; } } if(action & A_CIB_INVOKE || action & A_CIB_INVOKE_LOCAL) { int call_options = 0; enum cib_errors rc = cib_ok; crm_data_t *cib_frag = NULL; const char *section = NULL; const char *op = cl_get_string(cib_msg->msg, F_CRM_TASK); section = cl_get_string(cib_msg->msg, F_CIB_SECTION); ha_msg_value_int(cib_msg->msg, F_CIB_CALLOPTS, &call_options); crm_log_message(LOG_MSG, cib_msg->msg); crm_xml_devel(cib_msg->xml, "[CIB update]"); if(op == NULL) { crm_err("Invalid CIB Message"); register_fsa_error(C_FSA_INTERNAL, I_ERROR, NULL); return I_NULL; } cib_frag = NULL; rc = fsa_cib_conn->cmds->variant_op( fsa_cib_conn, op, NULL, section, cib_msg->xml, &cib_frag, call_options); if(rc != cib_ok || (action & A_CIB_INVOKE)) { answer = create_reply(cib_msg->msg, cib_frag); ha_msg_add(answer,XML_ATTR_RESULT,cib_error2string(rc)); } if(action & A_CIB_INVOKE) { if(relay_message(answer, TRUE) == FALSE) { crm_err("Confused what to do with cib result"); crm_log_message(LOG_ERR, answer); crm_msg_del(answer); result = I_ERROR; } } else if(rc != cib_ok) { ha_msg_input_t *input = NULL; crm_err("Internal CRM/CIB command from %s() failed: %s", msg_data->origin, cib_error2string(rc)); crm_log_message_adv(LOG_ERR, "CIB Input", cib_msg->msg); crm_log_message_adv(LOG_ERR, "CIB Reply", answer); input = new_ha_msg_input(answer); register_fsa_input(C_FSA_INTERNAL, I_ERROR, input); crm_msg_del(answer); delete_ha_msg_input(input); } return result; } else { crm_err("Unexpected action %s in %s", fsa_action2string(action), __FUNCTION__); } return I_NULL; } /* frees fragment as part of delete_ha_msg_input() */ void update_local_cib_adv( crm_data_t *msg_data, gboolean do_now, const char *raised_from) { HA_Message *msg = NULL; ha_msg_input_t *fsa_input = NULL; int call_options = cib_sync_call; CRM_DEV_ASSERT(msg_data != NULL); crm_malloc(fsa_input, sizeof(ha_msg_input_t)); msg = create_request(CRM_OP_CIB_UPDATE, msg_data, NULL, CRM_SYSTEM_CIB, CRM_SYSTEM_CRMD, NULL); ha_msg_add(msg, F_CIB_SECTION, crm_element_value(msg_data, XML_ATTR_SECTION)); ha_msg_add_int(msg, F_CIB_CALLOPTS, call_options); ha_msg_add(msg, "call_origin", raised_from); fsa_input->msg = msg; fsa_input->xml = msg_data; CRM_DEV_ASSERT(cib_ok == fsa_cib_conn->cmds->is_master(fsa_cib_conn)); if(do_now == FALSE) { - crm_debug("Registering event with FSA"); + crm_devel("Registering event with FSA"); register_fsa_input_adv(C_FSA_INTERNAL, I_CIB_OP, fsa_input, 0, FALSE, raised_from); } else { fsa_data_t *op_data = NULL; - crm_debug("Invoking CIB handler directly"); + crm_devel("Invoking CIB handler directly"); crm_malloc(op_data, sizeof(fsa_data_t)); op_data->fsa_cause = C_FSA_INTERNAL; op_data->fsa_input = I_CIB_OP; op_data->origin = raised_from; op_data->data = fsa_input; op_data->data_type = fsa_dt_ha_msg; do_cib_invoke(A_CIB_INVOKE_LOCAL, C_FSA_INTERNAL, fsa_state, I_CIB_OP, op_data); crm_free(op_data); - crm_debug("CIB handler completed"); + crm_devel("CIB handler completed"); } - crm_debug("deleting input"); + crm_devel("deleting input"); #if 0 delete_ha_msg_input(fsa_input); #else crm_msg_del(fsa_input->msg); crm_free(fsa_input); /* BUG: it should be possible to free this but for some reason I cant */ /* free_xml(fsa_input->xml); */ #endif - crm_debug("deleted input"); + crm_devel("deleted input"); } void crmd_update_confirm(const char *event, HA_Message *msg) { int rc = -1; const char *op = cl_get_string(msg, F_CIB_OPERATION); ha_msg_value_int(msg, F_CIB_RC, &rc); if(rc != cib_ok) { crm_trace("Ignoring failed CIB update"); return; } if(safe_str_eq(op, CRM_OP_CIB_ERASE)) { /* regenerate everyone's state and our node entry */ register_fsa_input(C_UNKNOWN, I_ELECTION_DC, NULL); } } diff --git a/crm/crmd/control.c b/crm/crmd/control.c index dd55af7d03..b1d6664163 100644 --- a/crm/crmd/control.c +++ b/crm/crmd/control.c @@ -1,617 +1,617 @@ /* * 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 #include extern void crmd_ha_connection_destroy(gpointer user_data); extern gboolean stop_all_resources(void); gboolean crm_shutdown(int nsig, gpointer unused); gboolean register_with_ha(ll_cluster_t *hb_cluster, const char *client_name); GHashTable *ipc_clients = NULL; /* A_HA_CONNECT */ enum crmd_fsa_input do_ha_control(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { gboolean registered = FALSE; if(action & A_HA_DISCONNECT) { if(fsa_cluster_conn != NULL) { fsa_cluster_conn->llc_ops->signoff(fsa_cluster_conn); } } if(action & A_HA_CONNECT) { if(fsa_cluster_conn == NULL) fsa_cluster_conn = ll_cluster_new("heartbeat"); /* make sure we are disconnected first */ fsa_cluster_conn->llc_ops->signoff(fsa_cluster_conn); registered = register_with_ha( fsa_cluster_conn, crm_system_name); if(registered == FALSE) { register_fsa_error(C_FSA_INTERNAL, I_FAIL, NULL); return I_NULL; } } if(action & ~(A_HA_CONNECT|A_HA_DISCONNECT)) { crm_err("Unexpected action %s in %s", fsa_action2string(action), __FUNCTION__); } return I_NULL; } /* A_SHUTDOWN */ enum crmd_fsa_input do_shutdown(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { enum crmd_fsa_input next_input = I_NULL; enum crmd_fsa_input tmp = I_NULL; /* just in case */ set_bit_inplace(fsa_input_register, R_SHUTDOWN); /* last attempt to shut these down */ if(is_set(fsa_input_register, R_PE_CONNECTED)) { crm_warn("Last attempt to shutdown the PolicyEngine"); tmp = do_pe_control(A_PE_STOP, cause, cur_state, current_input, msg_data); if(tmp != I_NULL) { next_input = I_ERROR; crm_err("Failed to shutdown the PolicyEngine"); } } if(is_set(fsa_input_register, R_TE_CONNECTED)) { crm_warn("Last attempt to shutdown the Transitioner"); tmp = do_pe_control(A_TE_STOP, cause, cur_state, current_input, msg_data); if(tmp != I_NULL) { next_input = I_ERROR; crm_err("Failed to shutdown the Transitioner"); } } crm_info("Stopping all remaining local resources"); stop_all_resources(); return next_input; } /* A_SHUTDOWN_REQ */ enum crmd_fsa_input do_shutdown_req(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { enum crmd_fsa_input next_input = I_NULL; HA_Message *msg = NULL; - crm_debug("Sending shutdown request to DC"); + crm_info("Sending shutdown request to DC"); msg = create_request( CRM_OP_SHUTDOWN_REQ, NULL, NULL, CRM_SYSTEM_DC, CRM_SYSTEM_CRMD, NULL); set_bit_inplace(fsa_input_register, R_STAYDOWN); if(send_request(msg, NULL) == FALSE) { next_input = I_ERROR; } return next_input; } /* A_EXIT_0, A_EXIT_1 */ enum crmd_fsa_input do_exit(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { int exit_code = 0; gboolean do_exit = FALSE; if(action & A_EXIT_0) { do_exit = TRUE; crm_info("Performing %s - gracefully exiting the CRMd", fsa_action2string(action)); } else { do_exit = TRUE; exit_code = 1; crm_warn("Performing %s - forcefully exiting the CRMd... now!", fsa_action2string(action)); } if(is_set(fsa_input_register, R_STAYDOWN)) { crm_info("Inhibiting respawn by Heartbeat"); exit_code = 100; } if(do_exit) { crm_info("[%s] stopped (%d)", crm_system_name, exit_code); exit(exit_code); } return I_NULL; } /* A_STARTUP */ enum crmd_fsa_input do_startup(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { int was_error = 0; int interval = 1; /* seconds between DC heartbeats */ crm_info("Register Signal Handler"); G_main_add_SignalHandler( G_PRIORITY_HIGH, SIGTERM, crm_shutdown, NULL, NULL); ipc_clients = g_hash_table_new(g_str_hash, g_str_equal); if(was_error == 0) { crm_info("Init server comms"); was_error = init_server_ipc_comms( crm_strdup(CRM_SYSTEM_CRMD), crmd_client_connect, default_ipc_connection_destroy); } if(was_error == 0) { crm_info("Creating CIB object"); fsa_cib_conn = cib_new(); } /* set up the timers */ crm_malloc(dc_heartbeat, sizeof(fsa_timer_t)); crm_malloc(integration_timer, sizeof(fsa_timer_t)); crm_malloc(finalization_timer, sizeof(fsa_timer_t)); crm_malloc(election_trigger, sizeof(fsa_timer_t)); crm_malloc(election_timeout, sizeof(fsa_timer_t)); crm_malloc(shutdown_escalation_timer, sizeof(fsa_timer_t)); crm_malloc(wait_timer, sizeof(fsa_timer_t)); interval = interval * 1000; if(election_trigger != NULL) { election_trigger->source_id = -1; election_trigger->period_ms = -1; election_trigger->fsa_input = I_DC_TIMEOUT; election_trigger->callback = timer_popped; } else { was_error = TRUE; } if(dc_heartbeat != NULL) { dc_heartbeat->source_id = -1; dc_heartbeat->period_ms = -1; dc_heartbeat->fsa_input = I_NULL; dc_heartbeat->callback = do_dc_heartbeat; } else { was_error = TRUE; } if(election_timeout != NULL) { election_timeout->source_id = -1; election_timeout->period_ms = -1; election_timeout->fsa_input = I_ELECTION_DC; election_timeout->callback = timer_popped; } else { was_error = TRUE; } if(integration_timer != NULL) { integration_timer->source_id = -1; integration_timer->period_ms = -1; integration_timer->fsa_input = I_INTEGRATED; integration_timer->callback = timer_popped; } else { was_error = TRUE; } if(finalization_timer != NULL) { finalization_timer->source_id = -1; finalization_timer->period_ms = -1; finalization_timer->fsa_input = I_FINALIZED; finalization_timer->callback = timer_popped; } else { was_error = TRUE; } if(shutdown_escalation_timer != NULL) { shutdown_escalation_timer->source_id = -1; shutdown_escalation_timer->period_ms = -1; shutdown_escalation_timer->fsa_input = I_TERMINATE; shutdown_escalation_timer->callback = timer_popped; } else { was_error = TRUE; } if(wait_timer != NULL) { wait_timer->source_id = -1; wait_timer->period_ms = 3*1000; wait_timer->fsa_input = I_NULL; wait_timer->callback = timer_popped; } else { was_error = TRUE; } /* set up the sub systems */ crm_malloc(cib_subsystem, sizeof(struct crm_subsystem_s)); crm_malloc(te_subsystem, sizeof(struct crm_subsystem_s)); crm_malloc(pe_subsystem, sizeof(struct crm_subsystem_s)); if(cib_subsystem != NULL) { cib_subsystem->pid = -1; cib_subsystem->path = BIN_DIR; cib_subsystem->name = CRM_SYSTEM_CIB; cib_subsystem->command = BIN_DIR"/"CRM_SYSTEM_CIB; cib_subsystem->args = "-VVc"; cib_subsystem->flag_connected = R_CIB_CONNECTED; cib_subsystem->flag_required = R_CIB_REQUIRED; } else { was_error = TRUE; } if(te_subsystem != NULL) { te_subsystem->pid = -1; te_subsystem->path = BIN_DIR; te_subsystem->name = CRM_SYSTEM_TENGINE; te_subsystem->command = BIN_DIR"/"CRM_SYSTEM_TENGINE; te_subsystem->args = "-VVc"; te_subsystem->flag_connected = R_TE_CONNECTED; te_subsystem->flag_required = R_TE_REQUIRED; } else { was_error = TRUE; } if(pe_subsystem != NULL) { pe_subsystem->pid = -1; pe_subsystem->path = BIN_DIR; pe_subsystem->name = CRM_SYSTEM_PENGINE; pe_subsystem->command = BIN_DIR"/"CRM_SYSTEM_PENGINE; pe_subsystem->args = "-VVc"; pe_subsystem->flag_connected = R_PE_CONNECTED; pe_subsystem->flag_required = R_PE_REQUIRED; } else { was_error = TRUE; } if(was_error) { register_fsa_error(C_FSA_INTERNAL, I_ERROR, NULL); } return I_NULL; } /* A_STOP */ enum crmd_fsa_input do_stop(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { /* nothing to do yet */ /* todo: shut down any remaining CRM resources */ return I_NULL; } /* A_STARTED */ enum crmd_fsa_input do_started(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { if(is_set(fsa_input_register, R_CCM_DATA) == FALSE) { crm_info("Delaying start, CCM (%.16llx) not connected", R_CCM_DATA); crmd_fsa_stall(); return I_NULL; } else if(is_set(fsa_input_register, R_LRM_CONNECTED) == FALSE) { crm_info("Delaying start, LRM (%.16llx) not connected", R_LRM_CONNECTED); crmd_fsa_stall(); return I_NULL; } else if(is_set(fsa_input_register, R_CIB_CONNECTED) == FALSE) { crm_info("Delaying start, CIB (%.16llx) not connected", R_CIB_CONNECTED); crmd_fsa_stall(); return I_NULL; } else if(is_set(fsa_input_register, R_PEER_DATA) == FALSE) { HA_Message * msg = NULL; /* try reading from HA */ crm_info("Delaying start, Peer data (%.16llx) not recieved", R_PEER_DATA); - crm_debug("Looking for a HA message"); + crm_devel("Looking for a HA message"); msg = fsa_cluster_conn->llc_ops->readmsg(fsa_cluster_conn, 0); if(msg != NULL) { - crm_debug("There was a HA message"); + crm_devel("There was a HA message"); crm_msg_del(msg); } startTimer(wait_timer); crmd_fsa_stall(); return I_NULL; } crm_info("The local CRM is operational"); clear_bit_inplace(fsa_input_register, R_STARTING); register_fsa_input(msg_data->fsa_cause, I_PENDING, NULL); return I_NULL; } /* A_RECOVER */ enum crmd_fsa_input do_recover(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { crm_err("Action %s (%.16llx) not supported\n", fsa_action2string(action), action); register_fsa_input(C_FSA_INTERNAL, I_SHUTDOWN, NULL); return I_NULL; } /* A_READCONFIG */ enum crmd_fsa_input do_read_config(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { crm_data_t *cib_copy = get_cib_copy(fsa_cib_conn); crm_data_t *config = get_object_root(XML_CIB_TAG_CRMCONFIG, cib_copy); xml_child_iter( config, iter, XML_CIB_TAG_NVPAIR, const char *name = crm_element_value(iter, XML_NVPAIR_ATTR_NAME); const char *value = crm_element_value(iter, XML_NVPAIR_ATTR_VALUE); if(name == NULL || value == NULL) { continue; } else if(safe_str_eq(name, XML_CONFIG_ATTR_DC_BEAT)) { dc_heartbeat->period_ms = atoi(value); } else if(safe_str_eq(name, XML_CONFIG_ATTR_DC_DEADTIME)) { election_trigger->period_ms = atoi(value); } else if(safe_str_eq(name, XML_CONFIG_ATTR_FORCE_QUIT)) { shutdown_escalation_timer->period_ms = atoi(value); } else if(safe_str_eq(name, XML_CONFIG_ATTR_REANNOUNCE)) { fsa_join_reannouce = atoi(value); } ); if(dc_heartbeat->period_ms < 1) { /* sensible default */ dc_heartbeat->period_ms = 1000; } if(fsa_join_reannouce < 0) { fsa_join_reannouce = 100; /* how many times should we let * go by before reannoucning * ourselves to the DC */ } election_timeout->period_ms = dc_heartbeat->period_ms * 6; integration_timer->period_ms = dc_heartbeat->period_ms * 6; finalization_timer->period_ms = dc_heartbeat->period_ms * 6; if(election_trigger->period_ms < 1 || election_trigger->period_ms > election_timeout->period_ms) { /* sensible default */ election_trigger->period_ms = election_timeout->period_ms * 2; } if(shutdown_escalation_timer->period_ms < 1 || election_timeout->period_ms > shutdown_escalation_timer->period_ms) { /* sensible default */ shutdown_escalation_timer->period_ms = election_timeout->period_ms * 3 * 100; } return I_NULL; } gboolean crm_shutdown(int nsig, gpointer unused) { if (crmd_mainloop != NULL && g_main_is_running(crmd_mainloop)) { if(is_set(fsa_input_register, R_SHUTDOWN)) { crm_err("Escalating the shutdown"); register_fsa_input_before(C_SHUTDOWN, I_ERROR, NULL); s_crmd_fsa(C_SHUTDOWN); } else { set_bit_inplace(fsa_input_register, R_SHUTDOWN); set_bit_inplace(fsa_input_register, R_STAYDOWN); /* fast track the case where no-one else is out there */ if(AM_I_DC) { election_timeout->fsa_input = I_TERMINATE; } if(is_set(fsa_input_register, R_SHUTDOWN)) { /* cant rely on this... */ startTimer(shutdown_escalation_timer); register_fsa_input(C_SHUTDOWN, I_SHUTDOWN, NULL); s_crmd_fsa(C_SHUTDOWN); } else { crm_err("Could not set R_SHUTDOWN"); exit(LSB_EXIT_ENOTSUPPORTED); } } } else { crm_info("exit from shutdown"); exit(LSB_EXIT_OK); } return TRUE; } gboolean register_with_ha(ll_cluster_t *hb_cluster, const char *client_name) { int facility; if(safe_val3(NULL, hb_cluster, llc_ops, errmsg) == NULL) { crm_crit("cluster errmsg function unavailable"); } crm_info("Signing in with Heartbeat"); if (hb_cluster->llc_ops->signon(hb_cluster, client_name)!= HA_OK) { crm_err("Cannot sign on with heartbeat: %s", hb_cluster->llc_ops->errmsg(hb_cluster)); return FALSE; } /* change the logging facility to the one used by heartbeat daemon */ crm_info("Switching to Heartbeat logger"); if (( facility = hb_cluster->llc_ops->get_logfacility(hb_cluster)) > 0) { cl_log_set_facility(facility); } crm_verbose("Facility: %d", facility); - crm_debug("Be informed of CRM messages"); + crm_devel("Be informed of CRM messages"); if (HA_OK != hb_cluster->llc_ops->set_msg_callback( hb_cluster, T_CRM, crmd_ha_msg_callback, hb_cluster)){ crm_err("Cannot set msg callback: %s", hb_cluster->llc_ops->errmsg(hb_cluster)); return FALSE; } #if 0 - crm_debug("Be informed of Node Status changes"); + crm_devel("Be informed of Node Status changes"); if (HA_OK != hb_cluster->llc_ops->set_nstatus_callback( hb_cluster, crmd_ha_status_callback, hb_cluster)){ crm_err("Cannot set nstatus callback: %s", hb_cluster->llc_ops->errmsg(hb_cluster)); return FALSE; } #endif - crm_debug("Be informed of CRM Client Status changes"); + crm_devel("Be informed of CRM Client Status changes"); if (HA_OK != hb_cluster->llc_ops->set_cstatus_callback( hb_cluster, crmd_client_status_callback, hb_cluster)) { crm_err("Cannot set cstatus callback: %s\n", hb_cluster->llc_ops->errmsg(hb_cluster)); return FALSE; } crm_info("beekhof: Client Status callback set"); - crm_debug("Adding channel to mainloop"); + crm_devel("Adding channel to mainloop"); G_main_add_IPC_Channel( G_PRIORITY_HIGH, hb_cluster->llc_ops->ipcchan(hb_cluster), FALSE, crmd_ha_msg_dispatch, hb_cluster /* userdata */, crmd_ha_connection_destroy); - crm_debug("Finding our node name"); + crm_devel("Finding our node name"); if ((fsa_our_uname = hb_cluster->llc_ops->get_mynodeid(hb_cluster)) == NULL) { crm_err("get_mynodeid() failed"); return FALSE; } crm_info("FSA Hostname: %s", fsa_our_uname); /* Async get client status information in the cluster */ - crm_debug("Requesting an initial dump of CRMD client_status"); + crm_devel("Requesting an initial dump of CRMD client_status"); crm_info("beekhof: Requesting Client Status"); fsa_cluster_conn->llc_ops->client_status( fsa_cluster_conn, NULL, CRM_SYSTEM_CRMD, -1); return TRUE; } diff --git a/crm/crmd/election.c b/crm/crmd/election.c index d5f9e8bb6f..b1ecb4e3f0 100644 --- a/crm/crmd/election.c +++ b/crm/crmd/election.c @@ -1,406 +1,406 @@ /* * 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 void ghash_count_vote(gpointer key, gpointer value, gpointer user_data); /* A_ELECTION_VOTE */ enum crmd_fsa_input do_election_vote(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { gboolean not_voting = FALSE; HA_Message *vote = NULL; /* dont vote if we're in one of these states or wanting to shut down */ switch(cur_state) { case S_RECOVERY: case S_STOPPING: case S_RELEASE_DC: case S_TERMINATE: crm_warn("Not voting in election, we're in state %s", fsa_state2string(cur_state)); not_voting = TRUE; break; default: if(is_set(fsa_input_register, R_SHUTDOWN)) { crm_warn("Not voting in election," " we're shutting down"); not_voting = TRUE; } break; } if(not_voting == FALSE) { if(is_set(fsa_input_register, R_STARTING)) { not_voting = TRUE; } } vote = create_request( CRM_OP_VOTE, NULL, NULL, CRM_SYSTEM_CRMD, CRM_SYSTEM_CRMD, NULL); if(action & A_ELECTION_START) { /* leaving out our version number, no other node out there * will think we should win the election... * which is what we want if we are the DC and want to shutdown */ ha_msg_mod(vote, XML_ATTR_VERSION, "0"); } else if(not_voting) { fsa_cib_conn->cmds->set_slave(fsa_cib_conn, cib_scope_local); if(AM_I_DC) { register_fsa_input(C_FSA_INTERNAL, I_RELEASE_DC, NULL); } else { register_fsa_input(C_FSA_INTERNAL, I_NOT_DC, NULL); } } send_request(vote, NULL); startTimer(election_timeout); return I_NULL; } char *dc_hb_msg = NULL; int beat_num = 0; gboolean do_dc_heartbeat(gpointer data) { #if 0 fsa_timer_t *timer = (fsa_timer_t *)data; - crm_debug("Sending DC Heartbeat %d", beat_num); + crm_devel("Sending DC Heartbeat %d", beat_num); HA_Message *msg = ha_msg_new(5); ha_msg_add(msg, F_TYPE, T_CRM); ha_msg_add(msg, F_SUBTYPE, XML_ATTR_REQUEST); ha_msg_add(msg, F_CRM_SYS_TO, CRM_SYSTEM_CRMD); ha_msg_add(msg, F_CRM_SYS_FROM, CRM_SYSTEM_DC); ha_msg_add(msg, F_CRM_TASK, CRM_OP_HBEAT); ha_msg_add_int(msg, "dc_beat_seq", beat_num); beat_num++; if(send_msg_via_ha(fsa_cluster_conn, msg) == FALSE) { /* this is bad */ stopTimer(timer); /* make it not go off again */ register_fsa_input(C_HEARTBEAT_FAILED, I_SHUTDOWN, NULL); s_crmd_fsa(C_HEARTBEAT_FAILED); return FALSE; } #endif return TRUE; } struct election_data_s { const char *winning_uname; unsigned int winning_bornon; }; /* A_ELECTION_COUNT */ enum crmd_fsa_input do_election_count_vote(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { gboolean we_loose = FALSE; ha_msg_input_t *vote = fsa_typed_data(fsa_dt_ha_msg); enum crmd_fsa_input election_result = I_NULL; const char *vote_from = cl_get_string(vote->msg, F_CRM_HOST_FROM); const char *your_version = cl_get_string(vote->msg, F_CRM_VERSION); oc_node_t *our_node = NULL, * your_node = NULL; if(vote_from == NULL || strcmp(vote_from, fsa_our_uname) == 0) { /* dont count our own vote */ return election_result; } if(fsa_membership_copy == NULL) { /* if the membership copy is NULL we REALLY shouldnt be voting * the question is how we managed to get here. */ crm_err("Membership copy was NULL"); return I_NULL; } else if(fsa_membership_copy->members_size < 1) { /* if even we are not in the cluster then we should not vote */ return I_NULL; } our_node = (oc_node_t*) g_hash_table_lookup(fsa_membership_copy->members, fsa_our_uname); your_node = (oc_node_t*) g_hash_table_lookup(fsa_membership_copy->members, vote_from); if(is_set(fsa_input_register, R_SHUTDOWN)) { - crm_debug("Election fail: we are shutting down"); + crm_devel("Election fail: we are shutting down"); we_loose = TRUE; } else if(our_node == NULL) { - crm_debug("Election fail: we dont exist in the CCM list"); + crm_devel("Election fail: we dont exist in the CCM list"); we_loose = TRUE; } else if(your_node == NULL) { crm_err("The other side doesnt exist in the CCM list"); } else if(compare_version(your_version, CRM_VERSION) > 0) { - crm_debug("Election fail: version"); + crm_devel("Election fail: version"); we_loose = TRUE; } else if(compare_version(your_version, CRM_VERSION) < 0) { - crm_debug("Election pass: version"); + crm_devel("Election pass: version"); } else if(your_node->node_born_on < our_node->node_born_on) { - crm_debug("Election fail: born_on"); + crm_devel("Election fail: born_on"); we_loose = TRUE; } else if(your_node->node_born_on < our_node->node_born_on) { - crm_debug("Election pass: born_on"); + crm_devel("Election pass: born_on"); } else if(strcmp(fsa_our_uname, vote_from) > 0) { - crm_debug("Election fail: uname"); + crm_devel("Election fail: uname"); we_loose = TRUE; } else if(strcmp(fsa_our_uname, vote_from) == 0) { - crm_debug("Election ??pass??: dup uname"); + crm_devel("Election ??pass??: dup uname"); CRM_DEV_ASSERT(strcmp(fsa_our_uname, vote_from) != 0); } if(we_loose) { stopTimer(election_timeout); fsa_cib_conn->cmds->set_slave(fsa_cib_conn, cib_scope_local); if(fsa_input_register & R_THE_DC) { - crm_debug("Give up the DC"); + crm_devel("Give up the DC"); election_result = I_RELEASE_DC; } else { - crm_debug("We werent the DC anyway"); + crm_devel("We werent the DC anyway"); election_result = I_PENDING; } } else { crm_verbose("We might win... we should vote (possibly again)"); election_result = I_ELECTION; /* new "default" */ } register_fsa_input(C_FSA_INTERNAL, election_result, NULL); return I_NULL; } /* A_ELECT_TIMER_START, A_ELECTION_TIMEOUT */ /* we won */ enum crmd_fsa_input do_election_timer_ctrl(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { return I_NULL; } /* A_DC_TAKEOVER */ enum crmd_fsa_input do_dc_takeover(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { enum crmd_fsa_input result = I_NULL; crm_data_t *cib = createEmptyCib(); crm_data_t *update = NULL; crm_data_t *output = NULL; int rc = cib_ok; crm_trace("################## Taking over the DC ##################"); set_bit_inplace(fsa_input_register, R_THE_DC); crm_verbose("Am I the DC? %s", AM_I_DC?XML_BOOLEAN_YES:XML_BOOLEAN_NO); crm_free(fsa_our_dc); fsa_our_dc = crm_strdup(fsa_our_uname); set_bit_inplace(fsa_input_register, R_JOIN_OK); set_bit_inplace(fsa_input_register, R_INVOKE_PE); clear_bit_inplace(fsa_input_register, R_CIB_DONE); clear_bit_inplace(fsa_input_register, R_HAVE_CIB); if(dc_heartbeat->source_id == (guint)-1 || dc_heartbeat->source_id == (guint)-2) { - crm_debug("Starting DC Heartbeat timer"); + crm_devel("Starting DC Heartbeat timer"); dc_heartbeat->source_id = Gmain_timeout_add_full( G_PRIORITY_HIGH, dc_heartbeat->period_ms, dc_heartbeat->callback, dc_heartbeat, NULL); } else { - crm_debug("DC Heartbeat timer already active"); + crm_devel("DC Heartbeat timer already active"); } /* fsa_cib_conn->cmds->set_slave_all(fsa_cib_conn, cib_none); */ fsa_cib_conn->cmds->set_master(fsa_cib_conn, cib_none); CRM_DEV_ASSERT(cib_ok == fsa_cib_conn->cmds->is_master(fsa_cib_conn)); - crm_debug("Update %s in the CIB to our uuid: %s", + crm_devel("Update %s in the CIB to our uuid: %s", XML_ATTR_DC_UUID, crm_element_value(cib, XML_ATTR_DC_UUID)); set_uuid(fsa_cluster_conn, cib, XML_ATTR_DC_UUID, fsa_our_uname); update = create_cib_fragment(cib, NULL); free_xml(cib); rc = fsa_cib_conn->cmds->modify( fsa_cib_conn, NULL, update, &output, cib_sync_call|cib_verbose); if(rc == cib_ok) { int revision_i = -1; const char *revision = NULL; - crm_debug("Checking our feature revision is allowed: %d", + crm_devel("Checking our feature revision is allowed: %d", cib_feature_revision); cib = find_xml_node(output, XML_TAG_CIB, TRUE); revision = crm_element_value(cib, XML_ATTR_CIB_REVISION); revision_i = atoi(revision?revision:"0"); if(revision_i > cib_feature_revision) { crm_err("Feature revision not permitted"); /* go into a stall state */ result = I_HALT; } } else if(rc == cib_revision_unsupported) { crm_err("Feature revision not permitted"); /* go into a stall state */ result = I_HALT; } else if(rc != cib_ok) { crm_err("DC UUID update failed: %s", cib_error2string(rc)); register_fsa_error(C_FSA_INTERNAL, I_FAIL, NULL); return I_NULL; } free_xml(update); - crm_debug("Requesting an initial dump of CRMD client_status"); + crm_devel("Requesting an initial dump of CRMD client_status"); fsa_cluster_conn->llc_ops->client_status( fsa_cluster_conn, NULL, CRM_SYSTEM_CRMD, -1); return result; } /* A_DC_RELEASE */ enum crmd_fsa_input do_dc_release(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { enum crmd_fsa_input result = I_NULL; crm_trace("################## Releasing the DC ##################"); stopTimer(dc_heartbeat); if(action & A_DC_RELEASE) { clear_bit_inplace(fsa_input_register, R_THE_DC); /* get a new CIB from the new DC */ clear_bit_inplace(fsa_input_register, R_HAVE_CIB); } else if (action & A_DC_RELEASED) { fsa_cib_conn->cmds->set_slave(fsa_cib_conn, cib_scope_local); if(cur_state == S_STOPPING) { register_fsa_input(C_FSA_INTERNAL, I_RELEASE_SUCCESS, NULL); } #if 0 else if( are there errors ) { /* we cant stay up if not healthy */ /* or perhaps I_ERROR and go to S_RECOVER? */ result = I_SHUTDOWN; } #endif else { register_fsa_input(C_FSA_INTERNAL, I_RELEASE_SUCCESS, NULL); } } else { crm_err("Warning, do_dc_release invoked for action %s", fsa_action2string(action)); } crm_verbose("Am I still the DC? %s", AM_I_DC?XML_BOOLEAN_YES:XML_BOOLEAN_NO); return result; } void ghash_count_vote(gpointer key, gpointer value, gpointer user_data) { struct election_data_s *election_data = (struct election_data_s *)user_data; oc_node_t *cur_node = (oc_node_t*)value; const char *node_uname = (const char*)key; if(election_data->winning_bornon > cur_node->node_born_on) { election_data->winning_uname = node_uname; election_data->winning_bornon = cur_node->node_born_on; } else if(election_data->winning_bornon == cur_node->node_born_on && (election_data->winning_uname == NULL || strcmp(election_data->winning_uname, node_uname) > 0)) { election_data->winning_uname = node_uname; election_data->winning_bornon = cur_node->node_born_on; } } diff --git a/crm/crmd/fsa.c b/crm/crmd/fsa.c index 04c9d93d88..8651da8522 100644 --- a/crm/crmd/fsa.c +++ b/crm/crmd/fsa.c @@ -1,694 +1,694 @@ /* * 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 #include #include #include extern int num_join_invites; extern GHashTable *join_requests; extern GHashTable *confirmed_nodes; extern void initialize_join(gboolean before); long long do_state_transition(long long actions, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_state next_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data); long long clear_flags(long long actions, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input cur_input); void dump_rsc_info(void); #define DOT_PREFIX "live.dot: " #ifdef DOT_FSA_ACTIONS # define IF_FSA_ACTION(x,y) \ if(is_set(fsa_actions,x)) { \ last_action = x; \ fsa_actions = clear_bit(fsa_actions, x); \ crm_verbose("Invoking action %s (%.16llx)", \ fsa_action2string(x), x); \ next_input = y(x, cause, fsa_state, last_input, fsa_data); \ crm_verbose("Action complete: %s (%.16llx)", \ fsa_action2string(x), x); \ CRM_DEV_ASSERT(next_input == I_NULL); \ crm_debug(DOT_PREFIX"\t// %s\n", fsa_action2string(x)); \ } #else # define IF_FSA_ACTION(x,y) \ if(is_set(fsa_actions,x)) { \ last_action = x; \ fsa_actions = clear_bit(fsa_actions, x); \ crm_verbose("Invoking action %s (%.16llx)", \ fsa_action2string(x), x); \ next_input = y(x, cause, fsa_state, last_input, fsa_data); \ crm_verbose("Action complete: %s (%.16llx)", \ fsa_action2string(x), x); \ CRM_DEV_ASSERT(next_input == I_NULL); \ } #endif /* #define ELSEIF_FSA_ACTION(x,y) else IF_FSA_ACTION(x,y) */ void init_dotfile(void); void init_dotfile(void) { crm_debug(DOT_PREFIX"digraph \"g\" {"); crm_debug(DOT_PREFIX" size = \"30,30\""); crm_debug(DOT_PREFIX" graph ["); crm_debug(DOT_PREFIX" fontsize = \"12\""); crm_debug(DOT_PREFIX" fontname = \"Times-Roman\""); crm_debug(DOT_PREFIX" fontcolor = \"black\""); crm_debug(DOT_PREFIX" bb = \"0,0,398.922306,478.927856\""); crm_debug(DOT_PREFIX" color = \"black\""); crm_debug(DOT_PREFIX" ]"); crm_debug(DOT_PREFIX" node ["); crm_debug(DOT_PREFIX" fontsize = \"12\""); crm_debug(DOT_PREFIX" fontname = \"Times-Roman\""); crm_debug(DOT_PREFIX" fontcolor = \"black\""); crm_debug(DOT_PREFIX" shape = \"ellipse\""); crm_debug(DOT_PREFIX" color = \"black\""); crm_debug(DOT_PREFIX" ]"); crm_debug(DOT_PREFIX" edge ["); crm_debug(DOT_PREFIX" fontsize = \"12\""); crm_debug(DOT_PREFIX" fontname = \"Times-Roman\""); crm_debug(DOT_PREFIX" fontcolor = \"black\""); crm_debug(DOT_PREFIX" color = \"black\""); crm_debug(DOT_PREFIX" ]"); crm_debug(DOT_PREFIX"// special nodes"); crm_debug(DOT_PREFIX" \"S_PENDING\" "); crm_debug(DOT_PREFIX" ["); crm_debug(DOT_PREFIX" color = \"blue\""); crm_debug(DOT_PREFIX" fontcolor = \"blue\""); crm_debug(DOT_PREFIX" ]"); crm_debug(DOT_PREFIX" \"S_TERMINATE\" "); crm_debug(DOT_PREFIX" ["); crm_debug(DOT_PREFIX" color = \"red\""); crm_debug(DOT_PREFIX" fontcolor = \"red\""); crm_debug(DOT_PREFIX" ]"); crm_debug(DOT_PREFIX"// DC only nodes"); crm_debug(DOT_PREFIX" \"S_INTEGRATION\" [ fontcolor = \"green\" ]"); crm_debug(DOT_PREFIX" \"S_POLICY_ENGINE\" [ fontcolor = \"green\" ]"); crm_debug(DOT_PREFIX" \"S_TRANSITION_ENGINE\" [ fontcolor = \"green\" ]"); crm_debug(DOT_PREFIX" \"S_RELEASE_DC\" [ fontcolor = \"green\" ]"); crm_debug(DOT_PREFIX" \"S_IDLE\" [ fontcolor = \"green\" ]"); } volatile enum crmd_fsa_state fsa_state = S_STARTING; oc_node_list_t *fsa_membership_copy; ll_cluster_t *fsa_cluster_conn; ll_lrm_t *fsa_lrm_conn; volatile long long fsa_input_register; volatile long long fsa_actions = A_NOTHING; const char *fsa_our_uname; char *fsa_our_dc; cib_t *fsa_cib_conn = NULL; fsa_timer_t *election_trigger = NULL; /* */ fsa_timer_t *election_timeout = NULL; /* */ fsa_timer_t *shutdown_escalation_timer = NULL; /* */ fsa_timer_t *integration_timer = NULL; fsa_timer_t *finalization_timer = NULL; fsa_timer_t *dc_heartbeat = NULL; fsa_timer_t *wait_timer = NULL; int fsa_join_reannouce = 0; volatile gboolean do_fsa_stall = FALSE; enum crmd_fsa_state s_crmd_fsa(enum crmd_fsa_cause cause) { time_t now; fsa_data_t *fsa_data = NULL; long long new_actions = A_NOTHING; long long last_action = A_NOTHING; enum crmd_fsa_input last_input = I_NULL; enum crmd_fsa_input cur_input = I_NULL; enum crmd_fsa_input next_input = I_NULL; enum crmd_fsa_state starting_state = fsa_state; enum crmd_fsa_state last_state = starting_state; enum crmd_fsa_state next_state = starting_state; crm_debug("FSA invoked with Cause: %s\tState: %s", fsa_cause2string(cause), fsa_state2string(fsa_state)); /* * Process actions in order of priority but do only one * action at a time to avoid complicating the ordering. * * Actions may result in a new I_ event, these are added to * (not replace) existing actions before the next iteration. * */ do_fsa_stall = FALSE; while(next_input != I_NULL || fsa_actions != A_NOTHING || is_message()) { if(do_fsa_stall) { /* we may be waiting for an a-sync task to "happen" * and until it does, we cant do anything else */ crm_info("Wait until something else happens"); break; } else if((is_message() && fsa_data == NULL) || (is_message() && fsa_actions == A_NOTHING && next_input == I_NULL)) { fsa_data_t *stored_msg = NULL; - crm_debug("Finished with current input..." + crm_devel("Finished with current input..." " Checking messages (%d remaining)", g_list_length(fsa_message_queue)); next_input = I_NULL; stored_msg = get_message(); if(stored_msg == NULL) { crm_crit("Invalid stored message"); exit(1); } delete_fsa_input(fsa_data); if(stored_msg->fsa_cause == C_CCM_CALLBACK) { crm_devel("FSA processing CCM callback from %s", stored_msg->origin); } else if(stored_msg->fsa_cause == C_LRM_OP_CALLBACK) { crm_devel("FSA processing LRM callback from %s", stored_msg->origin); } else if(stored_msg->data == NULL) { crm_devel("FSA processing input from %s", stored_msg->origin); } else { ha_msg_input_t *ha_input = fsa_typed_data_adv( stored_msg, fsa_dt_ha_msg, __FUNCTION__); crm_devel("FSA processing XML message from %s", stored_msg->origin); crm_log_message(LOG_MSG, ha_input->msg); crm_xml_devel(ha_input->xml, "FSA message data"); } fsa_data = stored_msg; /* set up the input */ next_input = fsa_data->fsa_input; /* add any actions back to the queue */ fsa_actions |= fsa_data->actions; /* update the cause */ cause = fsa_data->fsa_cause; fsa_dump_actions(fsa_data->actions, "\tadded back"); crm_debug(DOT_PREFIX"\t// FSA input: State=%s \tCause=%s" " \tInput=%s \tOrigin=%s()", fsa_state2string(fsa_state), fsa_cause2string(fsa_data->fsa_cause), fsa_input2string(fsa_data->fsa_input), fsa_data->origin); } else if(fsa_data == NULL) { crm_malloc(fsa_data, sizeof(fsa_data_t)); fsa_data->fsa_input = I_NULL; fsa_data->fsa_cause = cause; fsa_data->actions = A_NOTHING; fsa_data->origin = "s_crmd_fsa (enter)"; fsa_data->data = NULL; fsa_data->data_type = fsa_dt_none; if(fsa_data->origin == NULL) { crm_crit("Out of memory"); exit(1); } } /* update input variables */ cur_input = next_input; if(cur_input != I_NULL) { /* record the most recent non I_NULL input */ crm_devel("Updating last_input to %s", fsa_input2string(cur_input)); last_input = cur_input; } /* get the next batch of actions */ new_actions = crmd_fsa_actions[cur_input][fsa_state]; if(new_actions != A_NOTHING) { #ifdef FSA_TRACE crm_verbose("Adding actions %.16llx for %s/%s", new_actions, fsa_input2string(cur_input), fsa_state2string(fsa_state)); fsa_dump_actions(new_actions, "\tscheduled"); #endif fsa_actions |= new_actions; } if(fsa_data == NULL) { crm_err("No input for FSA.... terminating"); exit(1); } #ifdef FSA_TRACE crm_verbose("FSA while loop:\tState: %s, Cause: %s," " Input: %s, Origin=%s", fsa_state2string(crmd_fsa_state[cur_input][fsa_state]), fsa_cause2string(fsa_data->fsa_cause), fsa_input2string(cur_input), fsa_data->origin); #endif /* logging : *before* the state is changed */ IF_FSA_ACTION(A_ERROR, do_log) else IF_FSA_ACTION(A_WARN, do_log) else IF_FSA_ACTION(A_LOG, do_log) /* this is always run, some inputs/states may make various * actions irrelevant/invalid */ fsa_actions = clear_flags(fsa_actions, cause, fsa_state, cur_input); /* update state variables */ next_state = crmd_fsa_state[cur_input][fsa_state]; last_state = fsa_state; fsa_state = next_state; /* start doing things... */ /* * Hook for change of state. * Allows actions to be added or removed when entering a state */ if(last_state != fsa_state){ fsa_actions = do_state_transition( fsa_actions, cause, last_state, fsa_state, cur_input, fsa_data); } /* regular action processing in order of action priority * * Make sure all actions that connect to required systems * are performed first */ /* get out of here NOW! before anything worse happens */ IF_FSA_ACTION(A_EXIT_1, do_exit) /* essential start tasks */ else IF_FSA_ACTION(A_HA_CONNECT, do_ha_control) else IF_FSA_ACTION(A_STARTUP, do_startup) else IF_FSA_ACTION(A_CIB_START, do_cib_control) else IF_FSA_ACTION(A_READCONFIG, do_read_config) /* sub-system start/connect */ else IF_FSA_ACTION(A_LRM_CONNECT, do_lrm_control) else IF_FSA_ACTION(A_CCM_CONNECT, do_ccm_control) else IF_FSA_ACTION(A_TE_START, do_te_control) else IF_FSA_ACTION(A_PE_START, do_pe_control) /* sub-system restart */ else IF_FSA_ACTION(O_CIB_RESTART, do_cib_control) else IF_FSA_ACTION(O_PE_RESTART, do_pe_control) else IF_FSA_ACTION(O_TE_RESTART, do_te_control) /* Timers */ /* else IF_FSA_ACTION(O_DC_TIMER_RESTART, do_timer_control) */ else IF_FSA_ACTION(A_DC_TIMER_STOP, do_timer_control) else IF_FSA_ACTION(A_INTEGRATE_TIMER_STOP, do_timer_control) else IF_FSA_ACTION(A_INTEGRATE_TIMER_START, do_timer_control) else IF_FSA_ACTION(A_FINALIZE_TIMER_STOP, do_timer_control) else IF_FSA_ACTION(A_FINALIZE_TIMER_START, do_timer_control) /* * Highest priority actions */ else IF_FSA_ACTION(A_CIB_BUMPGEN, do_cib_invoke) else IF_FSA_ACTION(A_MSG_ROUTE, do_msg_route) else IF_FSA_ACTION(A_RECOVER, do_recover) else IF_FSA_ACTION(A_CL_JOIN_REQUEST, do_cl_join_request) else IF_FSA_ACTION(A_CL_JOIN_RESULT, do_cl_join_result) else IF_FSA_ACTION(A_SHUTDOWN_REQ, do_shutdown_req) else IF_FSA_ACTION(A_ELECTION_START, do_election_vote) else IF_FSA_ACTION(A_ELECTION_VOTE, do_election_vote) else IF_FSA_ACTION(A_ELECTION_COUNT, do_election_count_vote) /* * High priority actions * Update the cache first */ else IF_FSA_ACTION(A_CCM_UPDATE_CACHE, do_ccm_update_cache) else IF_FSA_ACTION(A_CCM_EVENT, do_ccm_event) else IF_FSA_ACTION(A_STARTED, do_started) else IF_FSA_ACTION(A_CL_JOIN_QUERY, do_cl_join_query) else IF_FSA_ACTION(A_DC_TIMER_START, do_timer_control) /* * Medium priority actions */ else IF_FSA_ACTION(A_DC_TAKEOVER, do_dc_takeover) else IF_FSA_ACTION(A_DC_RELEASE, do_dc_release) else IF_FSA_ACTION(A_DC_JOIN_OFFER_ALL, do_dc_join_offer_all) else IF_FSA_ACTION(A_DC_JOIN_OFFER_ONE, do_dc_join_offer_one) else IF_FSA_ACTION(A_DC_JOIN_PROCESS_REQ,do_dc_join_req) else IF_FSA_ACTION(A_DC_JOIN_PROCESS_ACK,do_dc_join_ack) /* * Low(er) priority actions * Make sure the CIB is always updated before invoking the * PE, and the PE before the TE */ else IF_FSA_ACTION(A_CIB_INVOKE_LOCAL, do_cib_invoke) else IF_FSA_ACTION(A_CIB_INVOKE, do_cib_invoke) else IF_FSA_ACTION(A_DC_JOIN_FINALIZE, do_dc_join_finalize) else IF_FSA_ACTION(A_LRM_INVOKE, do_lrm_invoke) else IF_FSA_ACTION(A_LRM_EVENT, do_lrm_event) else IF_FSA_ACTION(A_TE_CANCEL, do_te_invoke) else IF_FSA_ACTION(A_PE_INVOKE, do_pe_invoke) else IF_FSA_ACTION(A_TE_INVOKE, do_te_invoke) else IF_FSA_ACTION(A_CL_JOIN_ANNOUNCE, do_cl_join_announce) /* sub-system stop */ else IF_FSA_ACTION(A_DC_RELEASED, do_dc_release) else IF_FSA_ACTION(A_PE_STOP, do_pe_control) else IF_FSA_ACTION(A_TE_STOP, do_te_control) else IF_FSA_ACTION(A_CCM_DISCONNECT, do_ccm_control) else IF_FSA_ACTION(A_SHUTDOWN, do_shutdown) else IF_FSA_ACTION(A_LRM_DISCONNECT, do_lrm_control) else IF_FSA_ACTION(A_HA_DISCONNECT, do_ha_control) else IF_FSA_ACTION(A_CIB_STOP, do_cib_control) else IF_FSA_ACTION(A_STOP, do_stop) /* exit gracefully */ else IF_FSA_ACTION(A_EXIT_0, do_exit) /* else IF_FSA_ACTION(A_, do_) */ /* Error checking and reporting */ else if(cur_input != I_NULL && fsa_actions == A_NOTHING) { crm_warn( "No action specified for input,state (%s,%s)", fsa_input2string(cur_input), fsa_state2string(fsa_state)); next_input = I_NULL; } else if(cur_input == I_NULL && fsa_actions == A_NOTHING) { #ifdef FSA_TRACE crm_info("Nothing left to do..."); fsa_dump_actions(fsa_actions, "still here"); #endif break; } else { crm_err("Action %s (0x%llx) not supported ", fsa_action2string(fsa_actions), fsa_actions); next_input = I_ERROR; } } now = time(NULL); crm_debug(DOT_PREFIX"\t// ### Exiting the FSA (%s%s): %s\n", fsa_state2string(fsa_state), do_fsa_stall?": paused":"", asctime(localtime(&now))); /* cleanup inputs? */ delete_fsa_input(fsa_data); crm_debug("Register contents (0x%llx)", fsa_input_register); fsa_dump_queue(LOG_DEBUG); return fsa_state; } long long do_state_transition(long long actions, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_state next_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { gboolean clear_recovery_bit = TRUE; long long tmp = actions; const char *state_from = fsa_state2string(cur_state); const char *state_to = fsa_state2string(next_state); const char *input = fsa_input2string(current_input); time_t now = time(NULL); if(cur_state == next_state) { crm_err("%s called in state %s with no transtion", __FUNCTION__, state_from); return A_NOTHING; } crm_debug(DOT_PREFIX"\t%s -> %s [ label=%s cause=%s origin=%s ] // %s", state_from, state_to, input, fsa_cause2string(cause), msg_data->origin, asctime(localtime(&now))); crm_info("State transition %s -> %s [ input=%s cause=%s origin=%s %s ]", state_from, state_to, input, fsa_cause2string(cause), msg_data->origin, asctime(localtime(&now))); /* the last two clauses might cause trouble later */ if(election_timeout != NULL && next_state != S_ELECTION && next_state != S_RELEASE_DC && next_state != S_PENDING) { stopTimer(election_timeout); /* } else { */ /* startTimer(election_timeout); */ } if(is_set(fsa_input_register, R_SHUTDOWN)){ set_bit_inplace(tmp, A_DC_TIMER_STOP); } switch(next_state) { case S_PENDING: set_bit_inplace(tmp, A_DC_TIMER_START); /*fall through*/ case S_ELECTION: crm_info("Resetting our DC to NULL on election"); crm_free(fsa_our_dc); fsa_our_dc = NULL; /*fall through*/ case S_RELEASE_DC: set_bit_inplace(tmp, A_INTEGRATE_TIMER_STOP); set_bit_inplace(tmp, A_FINALIZE_TIMER_STOP); break; case S_NOT_DC: set_bit_inplace(tmp, A_DC_TIMER_STOP); if(is_set(fsa_input_register, R_SHUTDOWN)){ crm_info("(Re)Issuing shutdown request now" " that we have a new DC"); set_bit_inplace(tmp, A_SHUTDOWN_REQ); } CRM_DEV_ASSERT(fsa_our_dc != NULL); if(fsa_our_dc == NULL) { crm_err("Reached S_NOT_DC without a DC" " being recorded"); } break; case S_RECOVERY: set_bit_inplace(tmp, A_DC_TIMER_STOP); clear_recovery_bit = FALSE; break; case S_INTEGRATION: set_bit_inplace(tmp, A_DC_TIMER_STOP); set_bit_inplace(tmp, A_INTEGRATE_TIMER_START); set_bit_inplace(tmp, A_FINALIZE_TIMER_STOP); break; case S_FINALIZE_JOIN: set_bit_inplace(tmp, A_INTEGRATE_TIMER_STOP); set_bit_inplace(tmp, A_FINALIZE_TIMER_START); if(cause != C_FSA_INTERNAL) { crm_warn("Progressed to state %s after %s", fsa_state2string(cur_state), fsa_cause2string(cause)); } if(g_hash_table_size(join_requests) != fsa_membership_copy->members_size) { crm_warn("Only %d (of %d) cluster nodes " "responded to the join offer.", g_hash_table_size(join_requests), fsa_membership_copy->members_size); } else { crm_info("All %d clusters nodes " "responded to the join offer.", fsa_membership_copy->members_size); } break; case S_POLICY_ENGINE: set_bit_inplace(tmp, A_FINALIZE_TIMER_STOP); if(cause != C_FSA_INTERNAL) { crm_warn("Progressed to state %s after %s", fsa_state2string(cur_state), fsa_cause2string(cause)); } if(g_hash_table_size(confirmed_nodes) == fsa_membership_copy->members_size) { crm_info("All %d clusters nodes are" " eligable to run resources.", fsa_membership_copy->members_size); } else if(g_hash_table_size(confirmed_nodes) == num_join_invites) { crm_warn("All %d (%d total) cluster " "nodes are eligable to run resources", g_hash_table_size(confirmed_nodes), fsa_membership_copy->members_size); } else { crm_warn("Only %d of %d (%d total) cluster " "nodes are eligable to run resources", g_hash_table_size(confirmed_nodes), num_join_invites, fsa_membership_copy->members_size); } /* initialize_join(FALSE); */ break; case S_IDLE: dump_rsc_info(); break; default: set_bit_inplace(tmp, A_DC_TIMER_STOP); break; } if(clear_recovery_bit && next_state != S_PENDING) { tmp = clear_bit(tmp, A_RECOVER); } else if(clear_recovery_bit == FALSE) { tmp = set_bit(tmp, A_RECOVER); } if(tmp != actions) { fsa_dump_actions(actions ^ tmp, "New actions"); actions = tmp; } return actions; } long long clear_flags(long long actions, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input cur_input) { long long saved_actions = actions; if(is_set(fsa_input_register, R_SHUTDOWN) && cur_state == S_STARTING) { clear_bit_inplace( actions, A_STARTUP|A_CIB_START|A_LRM_CONNECT|A_CCM_CONNECT|A_HA_CONNECT|A_READCONFIG|A_STARTED|A_CL_JOIN_QUERY|A_DC_TIMER_START); } fsa_dump_actions(actions ^ saved_actions, "Cleared Actions"); return actions; } void dump_rsc_info(void) { crm_data_t *local_cib = get_cib_copy(fsa_cib_conn); crm_data_t *root = get_object_root(XML_CIB_TAG_STATUS, local_cib); crm_data_t *resources = NULL; const char *rsc_id = NULL; const char *node_id = NULL; const char *rsc_state = NULL; const char *op_status = NULL; const char *last_rc = NULL; const char *last_op = NULL; const char *path[] = { XML_CIB_TAG_LRM, XML_LRM_TAG_RESOURCES }; xml_child_iter( root, node, XML_CIB_TAG_STATE, resources = find_xml_node_nested(node, path, DIMOF(path)); xml_child_iter( resources, rsc, XML_LRM_TAG_RESOURCE, rsc_id = crm_element_value(rsc, XML_ATTR_ID); node_id = crm_element_value(rsc, XML_LRM_ATTR_TARGET); rsc_state = crm_element_value(rsc, XML_LRM_ATTR_RSCSTATE); op_status = crm_element_value(rsc, XML_LRM_ATTR_OPSTATUS); last_rc = crm_element_value(rsc, XML_LRM_ATTR_RC); last_op = crm_element_value(rsc, XML_LRM_ATTR_LASTOP); /* if(safe_str_eq(rsc_state, "stopped")) { */ /* continue; */ /* } */ if(safe_str_neq(op_status, "-1")) { crm_info("Resource state: %s %s " "[%s (rc=%s) after %s] on %s", rsc_id, rsc_state, op_status, last_rc, last_op, node_id); } else { crm_warn("Resource state: %s %s " "[pending %s] on %s", rsc_id, rsc_state, last_op, node_id); } ); ); } diff --git a/crm/crmd/join_client.c b/crm/crmd/join_client.c index 158ac32af5..fdaaac1c7a 100644 --- a/crm/crmd/join_client.c +++ b/crm/crmd/join_client.c @@ -1,243 +1,243 @@ /* * 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 int reannounce_count = 0; /* A_CL_JOIN_QUERY */ /* is there a DC out there? */ enum crmd_fsa_input do_cl_join_query(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { HA_Message *req = create_request(CRM_OP_ANNOUNCE, NULL, NULL, CRM_SYSTEM_DC, CRM_SYSTEM_CRMD, NULL); send_msg_via_ha(fsa_cluster_conn, req); return I_NULL; } /* A_CL_JOIN_ANNOUNCE */ /* this is kind of a workaround for the the fact that we may not be around * or are otherwise unable to reply when the DC sends out A_WELCOME_ALL */ enum crmd_fsa_input do_cl_join_announce(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { ha_msg_input_t *input = fsa_typed_data(fsa_dt_ha_msg); /* Once we hear from the DC, we can stop the timer * * This timer was started either on startup or when a node * left the CCM list */ /* dont announce if we're in one of these states */ if(cur_state != S_PENDING) { crm_warn("Do not announce ourselves in state %s", fsa_state2string(cur_state)); return I_NULL; } if(AM_I_OPERATIONAL) { const char *hb_from = cl_get_string( input->msg, F_CRM_HOST_FROM); if(hb_from == NULL) { crm_err("Failed to determin origin of hb message"); register_fsa_error(C_FSA_INTERNAL, I_FAIL, NULL); return I_NULL; } if(fsa_our_dc == NULL) { crm_info("Set DC to %s", hb_from); fsa_our_dc = crm_strdup(hb_from); } else if(safe_str_eq(hb_from, fsa_our_dc)) { reannounce_count++; if(fsa_join_reannouce > 0 && reannounce_count < fsa_join_reannouce) { crm_warn("Already announced to %s", hb_from); return I_NULL; } crm_warn("Re-announcing ourselves to %s (%d times)", hb_from, reannounce_count); } else { crm_warn("We announced ourselves to %s, but are" " now receiving DC Heartbeats from %s", fsa_our_dc, hb_from); /* reset the fsa_our_dc to NULL */ crm_warn("Resetting our DC to NULL after DC_HB" " from unrecognised node."); crm_free(fsa_our_dc); fsa_our_dc = NULL; return I_NULL; /* for now, wait for the DC's * to settle down */ } reannounce_count = 0; /* send as a broadcast */ { HA_Message *req = create_request( CRM_OP_ANNOUNCE, NULL, NULL, CRM_SYSTEM_DC, CRM_SYSTEM_CRMD, NULL); send_msg_via_ha(fsa_cluster_conn, req); } } else { /* Delay announce until we have finished local startup */ crm_warn("Delaying announce until local startup is complete"); return I_NULL; } return I_NULL; } /* A_CL_JOIN_REQUEST */ /* aka. accept the welcome offer */ enum crmd_fsa_input do_cl_join_request(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { crm_data_t *tmp1; ha_msg_input_t *input = fsa_typed_data(fsa_dt_ha_msg); const char *welcome_from = cl_get_string(input->msg, F_CRM_HOST_FROM); HA_Message *reply = NULL; #if 0 if(we are sick) { log error ; /* save the request for later? */ return I_NULL; } #endif if(fsa_our_dc == NULL) { crm_info("Set DC to %s", welcome_from); fsa_our_dc = crm_strdup(welcome_from); } else if(safe_str_neq(welcome_from, fsa_our_dc)) { /* dont do anything until DC's sort themselves out */ crm_err("Expected a welcome from %s, but %s replied", fsa_our_dc, welcome_from); return I_NULL; } /* include our CIB generation tuple */ tmp1 = cib_get_generation(fsa_cib_conn); if(tmp1 != NULL) { reply = create_reply(input->msg, tmp1); send_msg_via_ha(fsa_cluster_conn, reply); free_xml(tmp1); return I_NULL; } register_fsa_error(C_FSA_INTERNAL, I_FAIL, NULL); return I_NULL; } /* A_CL_JOIN_RESULT */ /* aka. this is notification that we have (or have not) been accepted */ enum crmd_fsa_input do_cl_join_result(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { gboolean was_nack = TRUE; crm_data_t *tmp1 = NULL; ha_msg_input_t *input = fsa_typed_data(fsa_dt_ha_msg); const char *ack_nack = cl_get_string(input->msg, CRM_OP_JOINACK); const char *welcome_from = cl_get_string(input->msg, F_CRM_HOST_FROM); const char *type = cl_get_string(input->msg, F_SUBTYPE); if(safe_str_eq(type, XML_ATTR_RESPONSE)) { crm_verbose("Ignoring result."); crm_log_message(LOG_VERBOSE, input->msg); return I_NULL; } /* calculate if it was an ack or a nack */ if(safe_str_eq(ack_nack, XML_BOOLEAN_TRUE)) { was_nack = FALSE; } if(was_nack) { crm_err("Join with %s failed. NACK'd", welcome_from); register_fsa_error(C_FSA_INTERNAL, I_ERROR, NULL); return I_NULL; } if(fsa_our_dc == NULL) { crm_info("Set DC to %s", welcome_from); fsa_our_dc = crm_strdup(welcome_from); } /* send our status section to the DC */ - crm_debug("Discovering local LRM status"); + crm_devel("Discovering local LRM status"); tmp1 = do_lrm_query(TRUE); if(tmp1 != NULL) { HA_Message *reply = create_reply(input->msg, tmp1); - crm_debug("Sending local LRM status"); + crm_devel("Sending local LRM status"); send_msg_via_ha(fsa_cluster_conn, reply); free_xml(tmp1); if(AM_I_DC == FALSE) { register_fsa_input(cause, I_NOT_DC, NULL); } } else { crm_err("Could send our LRM state to the DC"); register_fsa_error(C_FSA_INTERNAL, I_FAIL, NULL); } return I_NULL; } diff --git a/crm/crmd/join_dc.c b/crm/crmd/join_dc.c index 0c8b402b23..9ae1a74767 100644 --- a/crm/crmd/join_dc.c +++ b/crm/crmd/join_dc.c @@ -1,516 +1,516 @@ /* * 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 int num_join_invites = 0; GHashTable *join_offers = NULL; GHashTable *join_requests = NULL; GHashTable *confirmed_nodes = NULL; char *max_generation_from = NULL; void initialize_join(gboolean before); void finalize_join_for(gpointer key, gpointer value, gpointer user_data); void join_send_offer(gpointer key, gpointer value, gpointer user_data); /* A_DC_JOIN_OFFER_ALL */ enum crmd_fsa_input do_dc_join_offer_all(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { /* reset everyones status back to down or in_ccm in the CIB */ crm_data_t *cib_copy = get_cib_copy(fsa_cib_conn); crm_data_t *fragment = create_cib_fragment(NULL, NULL); crm_data_t *update = find_xml_node(fragment, XML_TAG_CIB, TRUE); crm_data_t *tmp1 = get_object_root(XML_CIB_TAG_STATUS, cib_copy); crm_data_t *tmp2 = NULL; initialize_join(TRUE); /* catch any nodes that are active in the CIB but not in the CCM list*/ update = get_object_root(XML_CIB_TAG_STATUS, update); CRM_DEV_ASSERT(update != NULL); xml_child_iter( tmp1, node_entry, XML_CIB_TAG_STATE, const char *node_id = crm_element_value(node_entry, XML_ATTR_UNAME); gpointer a_node = g_hash_table_lookup( fsa_membership_copy->members, node_id); if(a_node != NULL || (safe_str_eq(fsa_our_uname, node_id))) { /* handled by do_update_cib_node() */ continue; } tmp2 = create_node_state( node_id, node_id, NULL, XML_BOOLEAN_NO, NULL, CRMD_JOINSTATE_PENDING, NULL); add_node_copy(update, tmp2); free_xml(tmp2); ); /* now process the CCM data */ do_update_cib_nodes(fragment, TRUE); free_xml(cib_copy); /* free_xml(fragment); */ /* BUG! This should be able to be freed. * I cant find any reason why it shouldnt be able to be, * but libxml still corrupts memory */ #if 0 /* Avoid ordered message delays caused when the CRMd proc * isnt running yet (ie. send as a broadcast msg which are never * sent ordered. */ send_request(NULL, NULL, CRM_OP_WELCOME, NULL, CRM_SYSTEM_CRMD, NULL); #else crm_debug("Offering membership to %d clients", fsa_membership_copy->members_size); g_hash_table_foreach(fsa_membership_copy->members, join_send_offer, NULL); #endif /* No point hanging around in S_INTEGRATION if we're the only ones here! */ if(g_hash_table_size(join_requests) >= fsa_membership_copy->members_size) { crm_info("Not expecting any join acks"); register_fsa_input(C_FSA_INTERNAL, I_INTEGRATED, NULL); return I_NULL; } /* dont waste time by invoking the pe yet; */ crm_debug("Still waiting on %d outstanding join acks", fsa_membership_copy->members_size - g_hash_table_size(join_requests)); return I_NULL; } /* A_DC_JOIN_OFFER_ONE */ enum crmd_fsa_input do_dc_join_offer_one(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { gpointer a_node = NULL; ha_msg_input_t *welcome = fsa_typed_data(fsa_dt_ha_msg); const char *join_to = NULL; if(welcome == NULL) { crm_err("Attempt to send welcome message " "without a message to reply to!"); return I_NULL; } join_to = cl_get_string(welcome->msg, F_CRM_HOST_FROM); a_node = g_hash_table_lookup(join_requests, join_to); if(a_node != NULL && (cur_state == S_INTEGRATION || cur_state == S_FINALIZE_JOIN)) { /* note: it _is_ possible that a node will have been * sick or starting up when the original offer was made. * however, it will either re-announce itself in due course * _or_ we can re-store the original offer on the client. */ crm_warn("Already offered membership to %s... discarding", join_to); /* Make sure we end up in the correct state again */ if(g_hash_table_size(join_requests) >= fsa_membership_copy->members_size) { crm_info("False alarm, returning to %s", fsa_state2string(S_FINALIZE_JOIN)); register_fsa_input(C_FSA_INTERNAL, I_INTEGRATED, NULL); return I_NULL; } crm_debug("Still waiting on %d outstanding join acks", fsa_membership_copy->members_size - g_hash_table_size(join_requests)); } else { oc_node_t member; crm_debug("Processing annouce request from %s in state %s", join_to, fsa_state2string(cur_state)); member.node_uname = crm_strdup(join_to); join_send_offer(NULL, &member, NULL); crm_free(member.node_uname); /* this was a genuine join request, cancel any existing * transition and invoke the PE */ register_fsa_input_w_actions( msg_data->fsa_cause, I_NULL, NULL, A_TE_CANCEL); } return I_NULL; } /* A_DC_JOIN_PROCESS_REQ */ enum crmd_fsa_input do_dc_join_req(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { crm_data_t *generation = NULL; crm_data_t *our_generation = NULL; gboolean is_a_member = FALSE; const char *ack_nack = CRMD_JOINSTATE_MEMBER; ha_msg_input_t *join_ack = fsa_typed_data(fsa_dt_ha_msg); const char *join_from = cl_get_string(join_ack->msg,F_CRM_HOST_FROM); const char *ref = cl_get_string(join_ack->msg,XML_ATTR_REFERENCE); const char *op = cl_get_string(join_ack->msg, F_CRM_TASK); gpointer join_node = g_hash_table_lookup(fsa_membership_copy->members, join_from); if(safe_str_neq(op, CRM_OP_WELCOME)) { crm_warn("Ignoring op=%s message", op); return I_NULL; } - crm_debug("Processing req from %s", join_from); + crm_devel("Processing req from %s", join_from); if(join_node != NULL) { is_a_member = TRUE; } generation = join_ack->xml; our_generation = cib_get_generation(fsa_cib_conn); CRM_ASSERT(our_generation != NULL); /* what to do here? */ if(cib_compare_generation(our_generation, generation) <= 0) { clear_bit_inplace(fsa_input_register, R_HAVE_CIB); - crm_debug("%s has a better generation number than us", + crm_devel("%s has a better generation number than us", join_from); - crm_xml_debug(our_generation, "Our generation"); - crm_xml_debug(generation, "Their generation"); + crm_xml_devel(our_generation, "Our generation"); + crm_xml_devel(generation, "Their generation"); max_generation_from = crm_strdup(join_from); } free_xml(our_generation); - crm_debug("Welcoming node %s after ACK (ref %s)", join_from, ref); + crm_devel("Welcoming node %s after ACK (ref %s)", join_from, ref); if(is_a_member == FALSE) { /* nack them now so they are not counted towards the * expected responses */ char *local_from = crm_strdup(join_from); char *local_down = crm_strdup(CRMD_JOINSTATE_DOWN); crm_err("Node %s is not known to us (ref %s)", join_from, ref); finalize_join_for(local_from, local_down, NULL); crm_free(local_from); crm_free(local_down); register_fsa_error(C_FSA_INTERNAL, I_FAIL, NULL); return I_NULL; } else if(/* some reason */ 0) { /* NACK this client */ ack_nack = CRMD_JOINSTATE_DOWN; } /* add them to our list of CRMD_STATE_ACTIVE nodes TODO: check its not already there */ g_hash_table_insert( join_requests, crm_strdup(join_from), crm_strdup(ack_nack)); if(g_hash_table_size(join_requests) >= fsa_membership_copy->members_size) { crm_info("That was the last outstanding join ack"); register_fsa_input(C_FSA_INTERNAL, I_INTEGRATED, NULL); return I_NULL; } /* dont waste time by invoking the PE yet; */ crm_debug("Still waiting on %d (of %d) outstanding join acks", fsa_membership_copy->members_size - g_hash_table_size(join_requests), fsa_membership_copy->members_size); return I_NULL; } /* A_DC_JOIN_FINALIZE */ enum crmd_fsa_input do_dc_join_finalize(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { if(max_generation_from == NULL) { crm_warn("There is no CIB to get..." " how did R_HAVE_CIB get unset?"); set_bit_inplace(fsa_input_register, R_HAVE_CIB); } if(! is_set(fsa_input_register, R_HAVE_CIB)) { /* ask for the agreed best CIB */ enum cib_errors rc = cib_ok; crm_info("Asking %s for its copy of the CIB", crm_str(max_generation_from)); CRM_DEV_ASSERT(cib_ok == fsa_cib_conn->cmds->is_master(fsa_cib_conn)); rc = fsa_cib_conn->cmds->sync_from( fsa_cib_conn, max_generation_from, NULL, cib_sync_call); if(rc != cib_ok) { crm_err("Sync from %s resulted in an error: %s", max_generation_from, cib_error2string(rc)); register_fsa_error(C_FSA_INTERNAL, I_FAIL, NULL); return I_NULL; } } - crm_debug("Bumping the epoche and syncing to %d clients", + crm_devel("Bumping the epoche and syncing to %d clients", g_hash_table_size(join_requests)); fsa_cib_conn->cmds->bump_epoch( fsa_cib_conn, cib_scope_local|cib_sync_call); CRM_DEV_ASSERT(cib_ok == fsa_cib_conn->cmds->sync( fsa_cib_conn, NULL, cib_sync_call)); num_join_invites = 0; crm_debug("Notifying %d clients of join results", g_hash_table_size(join_requests)); g_hash_table_foreach(join_requests, finalize_join_for, NULL); if(num_join_invites <= g_hash_table_size(confirmed_nodes)) { crm_info("Not expecting any join confirmations"); register_fsa_input(C_FSA_INTERNAL, I_FINALIZED, NULL); return I_NULL; } /* dont waste time by invoking the PE yet; */ crm_debug("Still waiting on %d outstanding join confirmations", num_join_invites - g_hash_table_size(confirmed_nodes)); return I_NULL; } /* A_DC_JOIN_PROCESS_ACK */ enum crmd_fsa_input do_dc_join_ack(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { /* now update them to "member" */ crm_data_t *update = NULL; ha_msg_input_t *join_ack = fsa_typed_data(fsa_dt_ha_msg); const char *join_from = cl_get_string(join_ack->msg, F_CRM_HOST_FROM); const char *op = cl_get_string(join_ack->msg, F_CRM_TASK); const char *type = cl_get_string(join_ack->msg, F_SUBTYPE); const char *join_state = NULL; if(safe_str_neq(op, CRM_OP_JOINACK)) { crm_warn("Ignoring op=%s message", op); return I_NULL; } else if(safe_str_eq(type, XML_ATTR_REQUEST)) { crm_verbose("Ignoring request"); crm_log_message(LOG_VERBOSE, join_ack->msg); return I_NULL; } crm_debug("Processing ack from %s", join_from); join_state = (const char *) g_hash_table_lookup(join_requests, join_from); if(join_state == NULL) { crm_err("Join not in progress: ignoring join from %s", join_from); register_fsa_error(C_FSA_INTERNAL, I_FAIL, NULL); return I_NULL; } else if(safe_str_neq(join_state, CRMD_JOINSTATE_MEMBER)) { crm_err("Node %s wasnt invited to join the cluster",join_from); return I_NULL; } g_hash_table_insert(confirmed_nodes, crm_strdup(join_from), crm_strdup(CRMD_JOINSTATE_MEMBER)); /* the updates will actually occur in reverse order because of * the LIFO nature of the fsa input queue */ /* update CIB with the current LRM status from the node */ update_local_cib(copy_xml_node_recursive(join_ack->xml)); /* update node entry in the status section */ crm_info("Updating node state to %s for %s", join_state, join_from); update = create_node_state( join_from, join_from, ACTIVESTATUS, NULL, ONLINESTATUS, join_state, join_state); set_xml_property_copy(update,XML_CIB_ATTR_EXPSTATE, CRMD_STATE_ACTIVE); update_local_cib(create_cib_fragment(update, NULL)); if(num_join_invites <= g_hash_table_size(confirmed_nodes)) { crm_info("That was the last outstanding join confirmation"); register_fsa_input_later(C_FSA_INTERNAL, I_FINALIZED, NULL); return I_NULL; } /* dont waste time by invoking the pe yet; */ crm_debug("Still waiting on %d outstanding join confirmations", num_join_invites - g_hash_table_size(confirmed_nodes)); return I_NULL; } void finalize_join_for(gpointer key, gpointer value, gpointer user_data) { const char *join_to = NULL; const char *join_state = NULL; HA_Message *acknak = NULL; if(key == NULL || value == NULL) { return; } join_to = (const char *)key; join_state = (const char *)value; /* make sure the node exists in the config section */ create_node_entry(join_to, join_to, CRMD_JOINSTATE_MEMBER); /* send the ack/nack to the node */ acknak = create_request( CRM_OP_JOINACK, NULL, join_to, CRM_SYSTEM_CRMD, CRM_SYSTEM_DC, NULL); /* set the ack/nack */ if(safe_str_eq(join_state, CRMD_JOINSTATE_MEMBER)) { crm_info("ACK'ing join request from %s, state %s", join_to, join_state); num_join_invites++; ha_msg_add(acknak, CRM_OP_JOINACK, XML_BOOLEAN_TRUE); } else { crm_warn("NACK'ing join request from %s, state %s", join_to, join_state); ha_msg_add(acknak, CRM_OP_JOINACK, XML_BOOLEAN_FALSE); } send_msg_via_ha(fsa_cluster_conn, acknak); } void initialize_join(gboolean before) { /* clear out/reset a bunch of stuff */ if(join_offers != NULL) { g_hash_table_destroy(join_offers); } if(join_requests != NULL) { g_hash_table_destroy(join_requests); } if(confirmed_nodes != NULL) { g_hash_table_destroy(confirmed_nodes); } if(before) { if(max_generation_from != NULL) { crm_free(max_generation_from); max_generation_from = NULL; } set_bit_inplace(fsa_input_register, R_HAVE_CIB); clear_bit_inplace(fsa_input_register, R_CIB_ASKED); } join_offers = g_hash_table_new(g_str_hash, g_str_equal); join_requests = g_hash_table_new(g_str_hash, g_str_equal); confirmed_nodes = g_hash_table_new(g_str_hash, g_str_equal); } void join_send_offer(gpointer key, gpointer value, gpointer user_data) { const char *join_to = NULL; const oc_node_t *member = (const oc_node_t*)value; - crm_debug("Sending %s offer", CRM_OP_WELCOME); + crm_devel("Sending %s offer", CRM_OP_WELCOME); if(member != NULL) { join_to = member->node_uname; } if(join_to == NULL) { crm_err("No recipient for welcome message"); } else { HA_Message *offer = create_request( CRM_OP_WELCOME, NULL, join_to, CRM_SYSTEM_CRMD, CRM_SYSTEM_DC, NULL); /* send the welcome */ - crm_debug("Sending %s to %s", CRM_OP_WELCOME, join_to); + crm_devel("Sending %s to %s", CRM_OP_WELCOME, join_to); send_msg_via_ha(fsa_cluster_conn, offer); g_hash_table_insert(join_offers, crm_strdup(join_to), crm_strdup(CRMD_JOINSTATE_PENDING)); } } diff --git a/crm/crmd/lrm.c b/crm/crmd/lrm.c index 6c8f742bec..ecb59f8e3b 100644 --- a/crm/crmd/lrm.c +++ b/crm/crmd/lrm.c @@ -1,849 +1,849 @@ /* * 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 /* for access */ #include #include #include #include #include #include #include #include #include #include gboolean stop_all_resources(void); gboolean build_suppported_RAs( crm_data_t *metadata_list, crm_data_t *xml_agent_list); gboolean build_active_RAs(crm_data_t *rsc_list); void do_update_resource(lrm_rsc_t *rsc, lrm_op_t *op); enum crmd_fsa_input do_lrm_rsc_op( lrm_rsc_t *rsc, char *rid, const char *operation, crm_data_t *msg); enum crmd_fsa_input do_fake_lrm_op(gpointer data); GHashTable *xml2list(crm_data_t *parent, const char **attr_path, int depth); GHashTable *monitors = NULL; int num_lrm_register_fails = 0; int max_lrm_register_fails = 30; const char *rsc_path[] = { /* XML_GRAPH_TAG_RSC_OP, */ XML_CIB_TAG_RESOURCE, "instance_attributes", "rsc_parameters" }; enum crmd_rscstate { crmd_rscstate_NULL, crmd_rscstate_START, crmd_rscstate_START_PENDING, crmd_rscstate_START_OK, crmd_rscstate_START_FAIL, crmd_rscstate_STOP, crmd_rscstate_STOP_PENDING, crmd_rscstate_STOP_OK, crmd_rscstate_STOP_FAIL, crmd_rscstate_MON, crmd_rscstate_MON_PENDING, crmd_rscstate_MON_OK, crmd_rscstate_MON_FAIL, crmd_rscstate_GENERIC_PENDING, crmd_rscstate_GENERIC_OK, crmd_rscstate_GENERIC_FAIL }; void free_lrm_op(lrm_op_t *op); const char *crmd_rscstate2string(enum crmd_rscstate state); const char * crmd_rscstate2string(enum crmd_rscstate state) { switch(state) { case crmd_rscstate_NULL: return NULL; case crmd_rscstate_START: return CRMD_RSCSTATE_START; case crmd_rscstate_START_PENDING: return CRMD_RSCSTATE_START_PENDING; case crmd_rscstate_START_OK: return CRMD_RSCSTATE_START_OK; case crmd_rscstate_START_FAIL: return CRMD_RSCSTATE_START_FAIL; case crmd_rscstate_STOP: return CRMD_RSCSTATE_STOP; case crmd_rscstate_STOP_PENDING: return CRMD_RSCSTATE_STOP_PENDING; case crmd_rscstate_STOP_OK: return CRMD_RSCSTATE_STOP_OK; case crmd_rscstate_STOP_FAIL: return CRMD_RSCSTATE_STOP_FAIL; case crmd_rscstate_MON: return CRMD_RSCSTATE_MON; case crmd_rscstate_MON_PENDING: return CRMD_RSCSTATE_MON_PENDING; case crmd_rscstate_MON_OK: return CRMD_RSCSTATE_MON_OK; case crmd_rscstate_MON_FAIL: return CRMD_RSCSTATE_MON_FAIL; case crmd_rscstate_GENERIC_PENDING: return CRMD_RSCSTATE_GENERIC_PENDING; case crmd_rscstate_GENERIC_OK: return CRMD_RSCSTATE_GENERIC_OK; case crmd_rscstate_GENERIC_FAIL: return CRMD_RSCSTATE_GENERIC_FAIL; } return ""; } /* A_LRM_CONNECT */ enum crmd_fsa_input do_lrm_control(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { int ret = HA_OK; if(action & A_LRM_DISCONNECT) { if(fsa_lrm_conn) { fsa_lrm_conn->lrm_ops->signoff(fsa_lrm_conn); } /* TODO: Clean up the hashtable */ } if(action & A_LRM_CONNECT) { crm_trace("LRM: connect..."); ret = HA_OK; monitors = g_hash_table_new(g_str_hash, g_str_equal); fsa_lrm_conn = ll_lrm_new(XML_CIB_TAG_LRM); if(NULL == fsa_lrm_conn) { register_fsa_error(C_FSA_INTERNAL, I_ERROR, NULL); ret = HA_FAIL; } if(ret == HA_OK) { crm_trace("LRM: sigon..."); ret = fsa_lrm_conn->lrm_ops->signon( fsa_lrm_conn, CRM_SYSTEM_CRMD); } if(ret != HA_OK) { if(++num_lrm_register_fails < max_lrm_register_fails) { crm_warn("Failed to sign on to the LRM %d" " (%d max) times", num_lrm_register_fails, max_lrm_register_fails); startTimer(wait_timer); crmd_fsa_stall(); return I_NULL; } } if(ret == HA_OK) { crm_trace("LRM: set_lrm_callback..."); ret = fsa_lrm_conn->lrm_ops->set_lrm_callback( fsa_lrm_conn, lrm_op_callback); if(ret != HA_OK) { crm_err("Failed to set LRM callbacks"); } } if(ret != HA_OK) { crm_err("Failed to sign on to the LRM %d" " (max) times", num_lrm_register_fails); register_fsa_error(C_FSA_INTERNAL, I_ERROR, NULL); return I_NULL; } /* TODO: create a destroy handler that causes * some recovery to happen */ G_main_add_fd(G_PRIORITY_LOW, fsa_lrm_conn->lrm_ops->inputfd(fsa_lrm_conn), FALSE, lrm_dispatch, fsa_lrm_conn, default_ipc_connection_destroy); set_bit_inplace(fsa_input_register, R_LRM_CONNECTED); } if(action & ~(A_LRM_CONNECT|A_LRM_DISCONNECT)) { crm_err("Unexpected action %s in %s", fsa_action2string(action), __FUNCTION__); } return I_NULL; } gboolean build_suppported_RAs(crm_data_t *metadata_list, crm_data_t *xml_agent_list) { GList *types = NULL; GList *classes = NULL; const char *version = NULL; crm_data_t *xml_agent = NULL; /* return TRUE; */ if(fsa_lrm_conn == NULL) { return FALSE; } classes = fsa_lrm_conn->lrm_ops->get_rsc_class_supported(fsa_lrm_conn); slist_iter( class, char, classes, lpc, types = fsa_lrm_conn->lrm_ops->get_rsc_type_supported( fsa_lrm_conn, class); slist_iter( type, char, types, llpc, version = "1"; xml_agent = create_xml_node( xml_agent_list, XML_LRM_TAG_AGENT); set_xml_property_copy( xml_agent, XML_AGENT_ATTR_CLASS, class); set_xml_property_copy(xml_agent, XML_ATTR_TYPE, type); set_xml_property_copy( xml_agent, XML_ATTR_VERSION, version); ) g_list_free(types); ); g_list_free(classes); return TRUE; } gboolean stop_all_resources(void) { GList *op_list = NULL; GList *lrm_list = NULL; state_flag_t cur_state = 0; const char *this_op = NULL; if(fsa_lrm_conn == NULL) { return TRUE; } lrm_list = fsa_lrm_conn->lrm_ops->get_all_rscs(fsa_lrm_conn); slist_iter( rid, char, lrm_list, lpc, /* GHashTable* params; */ lrm_rsc_t *the_rsc = fsa_lrm_conn->lrm_ops->get_rsc(fsa_lrm_conn, rid); crm_info("Processing lrm_rsc_t entry %s", rid); if(the_rsc == NULL) { crm_err("NULL resource returned from the LRM"); continue; } op_list = the_rsc->ops->get_cur_state(the_rsc, &cur_state); crm_verbose("\tcurrent state:%s\n", cur_state==LRM_RSC_IDLE?"Idle":"Busy"); slist_iter( op, lrm_op_t, op_list, llpc, this_op = op->op_type; crm_debug("Processing op %s for %s (status=%d, rc=%d)", op->op_type, the_rsc->id, op->op_status, op->rc); if(safe_str_neq(this_op, CRMD_RSCSTATE_STOP)){ do_lrm_rsc_op(the_rsc, the_rsc->id, CRMD_RSCSTATE_STOP, NULL); } break; ); ); return TRUE; } gboolean build_active_RAs(crm_data_t *rsc_list) { GList *op_list = NULL; GList *lrm_list = NULL; gboolean found_op = FALSE; state_flag_t cur_state = 0; const char *this_op = NULL; char *tmp = NULL; if(fsa_lrm_conn == NULL) { return FALSE; } lrm_list = fsa_lrm_conn->lrm_ops->get_all_rscs(fsa_lrm_conn); slist_iter( rid, char, lrm_list, lpc, /* GHashTable* params; */ lrm_rsc_t *the_rsc = fsa_lrm_conn->lrm_ops->get_rsc(fsa_lrm_conn, rid); crm_data_t *xml_rsc = create_xml_node( rsc_list, XML_LRM_TAG_RESOURCE); crm_info("Processing lrm_rsc_t entry %s", rid); if(the_rsc == NULL) { crm_err("NULL resource returned from the LRM"); continue; } set_xml_property_copy(xml_rsc, XML_ATTR_ID, the_rsc->id); set_xml_property_copy( xml_rsc, XML_LRM_ATTR_TARGET, fsa_our_uname); op_list = the_rsc->ops->get_cur_state(the_rsc, &cur_state); crm_verbose("\tcurrent state:%s\n", cur_state==LRM_RSC_IDLE?"Idle":"Busy"); slist_iter( op, lrm_op_t, op_list, llpc, this_op = op->op_type; crm_debug("Processing op %s for %s (status=%d, rc=%d)", op->op_type, the_rsc->id, op->op_status, op->rc); if(op->rc != 0 || safe_str_neq(this_op, CRMD_RSCSTATE_MON)){ set_xml_property_copy( xml_rsc, XML_LRM_ATTR_RSCSTATE, op->user_data); set_xml_property_copy( xml_rsc, XML_LRM_ATTR_LASTOP, this_op); tmp = crm_itoa(op->rc); set_xml_property_copy( xml_rsc, XML_LRM_ATTR_RC, tmp); crm_free(tmp); tmp = crm_itoa(op->op_status); set_xml_property_copy( xml_rsc, XML_LRM_ATTR_OPSTATUS, tmp); crm_free(tmp); /* we only want the last one */ found_op = TRUE; break; } else { set_xml_property_copy( xml_rsc, XML_LRM_ATTR_RSCSTATE, CRMD_RSCSTATE_START_OK); set_xml_property_copy( xml_rsc, XML_LRM_ATTR_LASTOP, CRMD_RSCSTATE_START); tmp = crm_itoa(op->rc); set_xml_property_copy( xml_rsc, XML_LRM_ATTR_RC, tmp); crm_free(tmp); set_xml_property_copy( xml_rsc, XML_LRM_ATTR_OPSTATUS, "0"); /* we only want the last one */ found_op = TRUE; break; } ); if(found_op == FALSE) { crm_err("Could not properly determin last op" " for %s from %d entries", the_rsc->id, g_list_length(op_list)); } g_list_free(op_list); ); g_list_free(lrm_list); return TRUE; } crm_data_t* do_lrm_query(gboolean is_replace) { crm_data_t *xml_result= NULL; crm_data_t *xml_state = create_xml_node(NULL, XML_CIB_TAG_STATE); crm_data_t *xml_data = create_xml_node(xml_state, XML_CIB_TAG_LRM); crm_data_t *rsc_list = create_xml_node(xml_data,XML_LRM_TAG_RESOURCES); #if 0 /* Build a list of supported agents and metadata */ crm_data_t *xml_agent_list = create_xml_node(xml_data, XML_LRM_TAG_AGENTS); crm_data_t *xml_metadata_list = create_xml_node(xml_data, "metatdata"); build_suppported_RAs(xml_metadata_list, xml_agent_list); #endif /* Build a list of active (not always running) resources */ build_active_RAs(rsc_list); if(is_replace) { set_xml_property_copy( xml_state, XML_CIB_ATTR_REPLACE, XML_CIB_TAG_LRM); } set_uuid(fsa_cluster_conn, xml_state, XML_ATTR_UUID, fsa_our_uname); set_xml_property_copy(xml_state, XML_ATTR_UNAME, fsa_our_uname); xml_result = create_cib_fragment(xml_state, NULL); - crm_xml_debug(xml_state, "Current state of the LRM"); + crm_xml_devel(xml_state, "Current state of the LRM"); return xml_result; } /* A_LRM_INVOKE */ enum crmd_fsa_input do_lrm_invoke(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { const char *crm_op = NULL; const char *operation = NULL; enum crmd_fsa_input next_input = I_NULL; ha_msg_input_t *input = fsa_typed_data(fsa_dt_ha_msg); crm_op = cl_get_string(input->msg, F_CRM_TASK); operation = get_xml_attr_nested( input->xml, rsc_path, DIMOF(rsc_path) -3, XML_LRM_ATTR_TASK, FALSE); if(crm_op != NULL && safe_str_eq(crm_op, "lrm_query")) { crm_data_t *data = do_lrm_query(FALSE); HA_Message *reply = create_reply(input->msg, data); if(relay_message(reply, TRUE) == FALSE) { crm_err("Unable to route reply"); crm_log_message(LOG_ERR, reply); crm_msg_del(reply); } free_xml(data); } else if(operation != NULL) { char rid[64]; const char *id_from_cib = NULL; lrm_rsc_t *rsc = NULL; id_from_cib = get_xml_attr_nested( input->xml, rsc_path, DIMOF(rsc_path) -2, XML_ATTR_ID, TRUE); if(id_from_cib == NULL) { crm_err("No value for %s in message at level %d.", XML_ATTR_ID, DIMOF(rsc_path) -2); return I_NULL; } /* only the first 16 chars are used by the LRM */ strncpy(rid, id_from_cib, 64); rid[63] = 0; rsc = fsa_lrm_conn->lrm_ops->get_rsc(fsa_lrm_conn, rid); next_input = do_lrm_rsc_op(rsc, rid, operation, input->xml); } else { crm_err("Operation was neither a lrm_query, nor a rsc op. %s", crm_str(crm_op)); next_input = I_ERROR; } return next_input; } enum crmd_fsa_input do_lrm_rsc_op( lrm_rsc_t *rsc, char *rid, const char *operation, crm_data_t *msg) { lrm_op_t* op = NULL; int call_id = 0; int action_timeout = 0; fsa_data_t *msg_data = NULL; const char *type = NULL; const char *class = NULL; const char *timeout = NULL; if(rsc != NULL) { class = rsc->class; type = rsc->type; } else if(msg != NULL) { class = get_xml_attr_nested( msg, rsc_path, DIMOF(rsc_path) -2, XML_AGENT_ATTR_CLASS, TRUE); type = get_xml_attr_nested( msg, rsc_path, DIMOF(rsc_path) -2, XML_ATTR_TYPE, TRUE); timeout = get_xml_attr_nested( msg, rsc_path, DIMOF(rsc_path) -2, XML_ATTR_TIMEOUT, FALSE); } if(rsc == NULL) { /* add it to the list */ crm_verbose("adding rsc %s before operation", rid); fsa_lrm_conn->lrm_ops->add_rsc( fsa_lrm_conn, rid, class, type, NULL, NULL); rsc = fsa_lrm_conn->lrm_ops->get_rsc(fsa_lrm_conn, rid); } if(rsc == NULL) { crm_err("Could not add resource to LRM"); register_fsa_error(C_FSA_INTERNAL, I_FAIL, NULL); return I_NULL; } if(timeout) { action_timeout = atoi(timeout); if(action_timeout < 0) { action_timeout = 0; } } /* stop the monitor before stopping the resource */ if(safe_str_eq(operation, CRMD_RSCSTATE_STOP)) { gpointer foo = g_hash_table_lookup(monitors, rsc->id); call_id = GPOINTER_TO_INT(foo); if(call_id > 0) { crm_debug("Stopping status op for %s", rsc->id); rsc->ops->cancel_op(rsc, call_id); g_hash_table_remove(monitors, rsc->id); /* TODO: Clean up key */ } else { crm_warn("No monitor operation found for %s", rsc->id); /* TODO: we probably need to look up the LRM to find it */ } } /* now do the op */ crm_info("Performing op %s on %s", operation, rid); crm_malloc(op, sizeof(lrm_op_t)); op->op_type = crm_strdup(operation); op->timeout = action_timeout; op->interval = 0; op->user_data = NULL; op->target_rc = EVERYTIME; if(msg != NULL) { op->params = xml2list(msg, rsc_path, DIMOF(rsc_path)); } else { CRM_DEV_ASSERT(safe_str_eq(CRMD_RSCSTATE_STOP, operation)); } if(safe_str_eq(CRMD_RSCSTATE_START, operation)) { op->user_data = crm_strdup(CRMD_RSCSTATE_START_OK); } else if(safe_str_eq(CRMD_RSCSTATE_STOP, operation)) { op->user_data = crm_strdup(CRMD_RSCSTATE_STOP_OK); } else { crm_warn("Using status \"complete\" for op \"%s\"" "... this is still in the experimental stage.", operation); op->user_data = crm_strdup(CRMD_RSCSTATE_GENERIC_OK); } op->user_data_len = 1+strlen(op->user_data); call_id = rsc->ops->perform_op(rsc, op); free_lrm_op(op); if(call_id <= 0) { crm_err("Operation %s on %s failed", operation, rid); register_fsa_error(C_FSA_INTERNAL, I_FAIL, NULL); return I_NULL; } if(safe_str_eq(operation, CRMD_RSCSTATE_START)) { /* initiate the monitor action */ crm_malloc(op, sizeof(lrm_op_t)); op->op_type = crm_strdup(CRMD_RSCSTATE_MON); op->params = NULL; op->user_data = crm_strdup(CRMD_RSCSTATE_MON_OK); op->timeout = 0; op->interval = 9000; op->target_rc = CHANGED; op->user_data_len = 1+strlen(op->user_data); call_id = rsc->ops->perform_op(rsc, op); free_lrm_op(op); if (call_id > 0) { crm_debug("Adding monitor op for %s", rsc->id); g_hash_table_insert( monitors, strdup(rsc->id), GINT_TO_POINTER(call_id)); } else { crm_err("Monitor op for %s did not have a call id", rsc->id); } } return I_NULL; } void free_lrm_op(lrm_op_t *op) { crm_free(op->user_data); crm_free(op->op_type); crm_free(op); } GHashTable * xml2list(crm_data_t *parent, const char**attr_path, int depth) { crm_data_t *nvpair_list = NULL; GHashTable *nvpair_hash = g_hash_table_new(g_str_hash, g_str_equal); CRM_DEV_ASSERT(parent != NULL); if(parent != NULL) { nvpair_list = find_xml_node_nested(parent, attr_path, depth); if(nvpair_list == NULL) { - crm_xml_debug(parent, "No attributes for resource op"); + crm_xml_devel(parent, "No attributes for resource op"); } } xml_child_iter( nvpair_list, node_iter, XML_CIB_TAG_NVPAIR, const char *key = crm_element_value( node_iter, XML_NVPAIR_ATTR_NAME); const char *value = crm_element_value( node_iter, XML_NVPAIR_ATTR_VALUE); crm_verbose("Added %s=%s", key, value); g_hash_table_insert( nvpair_hash,crm_strdup(key), crm_strdup(value)); ); return nvpair_hash; } void do_update_resource(lrm_rsc_t *rsc, lrm_op_t* op) { /* */ crm_data_t *update, *iter; char *tmp = NULL; crm_data_t *fragment; int len = 0; char *fail_state = NULL; if(op == NULL || rsc == NULL) { crm_err("Either resouce or op was not specified"); return; } crm_info("Updating resouce %s after op %s", rsc->id, op->op_type); update = create_xml_node(NULL, XML_CIB_TAG_STATE); set_uuid(fsa_cluster_conn, update, XML_ATTR_UUID, fsa_our_uname); set_xml_property_copy(update, XML_ATTR_UNAME, fsa_our_uname); iter = create_xml_node(update, XML_CIB_TAG_LRM); iter = create_xml_node(iter, XML_LRM_TAG_RESOURCES); iter = create_xml_node(iter, XML_LRM_TAG_RESOURCE); set_xml_property_copy(iter, XML_ATTR_ID, rsc->id); set_xml_property_copy(iter, XML_LRM_ATTR_LASTOP, op->op_type); len = strlen(op->op_type); len += strlen("_failed_"); crm_malloc(fail_state, sizeof(char)*len); if(fail_state != NULL) { sprintf(fail_state, "%s_failed", op->op_type); } switch(op->op_status) { case LRM_OP_CANCELLED: break; case LRM_OP_ERROR: case LRM_OP_TIMEOUT: case LRM_OP_NOTSUPPORTED: crm_err("An LRM operation failed" " or was aborted"); set_xml_property_copy( iter, XML_LRM_ATTR_RSCSTATE, fail_state); break; case LRM_OP_DONE: set_xml_property_copy( iter, XML_LRM_ATTR_RSCSTATE, op->user_data); break; } crm_free(fail_state); tmp = crm_itoa(op->rc); set_xml_property_copy(iter, XML_LRM_ATTR_RC, tmp); crm_free(tmp); tmp = crm_itoa(op->op_status); set_xml_property_copy(iter, XML_LRM_ATTR_OPSTATUS, tmp); crm_free(tmp); set_xml_property_copy(iter, XML_LRM_ATTR_TARGET, fsa_our_uname); fragment = create_cib_fragment(update, NULL); { int rc = cib_ok; rc = fsa_cib_conn->cmds->modify( fsa_cib_conn, XML_CIB_TAG_STATUS, fragment, NULL, cib_sync_call); CRM_DEV_ASSERT(rc == cib_ok); if(rc != cib_ok) { crm_err("Resource state update failed: %s", cib_error2string(rc)); } } free_xml(fragment); free_xml(update); } enum crmd_fsa_input do_lrm_event(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input cur_input, fsa_data_t *msg_data) { lrm_op_t* op = NULL; lrm_rsc_t* rsc = NULL; if(msg_data->fsa_cause != C_LRM_OP_CALLBACK) { register_fsa_error(C_FSA_INTERNAL, I_FAIL, NULL); return I_NULL; } op = fsa_typed_data(fsa_dt_lrm); rsc = op->rsc; CRM_DEV_ASSERT(rsc != NULL); crm_info("Processing %d event for %s/%s", op->op_status, op->op_type, crm_str(rsc?rsc->id:NULL)); switch(op->op_status) { case LRM_OP_ERROR: case LRM_OP_CANCELLED: case LRM_OP_TIMEOUT: case LRM_OP_NOTSUPPORTED: crm_err("An LRM operation failed" " or was aborted"); /* fall through */ case LRM_OP_DONE: do_update_resource(rsc, op); break; } return I_NULL; } diff --git a/crm/crmd/messages.c b/crm/crmd/messages.c index 3f24c16b63..0529685b8c 100644 --- a/crm/crmd/messages.c +++ b/crm/crmd/messages.c @@ -1,1129 +1,1129 @@ /* * 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 #include FILE *msg_out_strm = NULL; FILE *router_strm = NULL; GListPtr fsa_message_queue = NULL; extern void crm_shutdown(int nsig); gboolean send_ha_message(ll_cluster_t *hb_fd, crm_data_t *root); enum crmd_fsa_input handle_request(ha_msg_input_t *stored_msg); enum crmd_fsa_input handle_response(ha_msg_input_t *stored_msg); enum crmd_fsa_input handle_shutdown_request(HA_Message *stored_msg); ha_msg_input_t *copy_ha_msg_input(ha_msg_input_t *orig); #ifdef MSG_LOG # define ROUTER_RESULT(x) \ - do_crm_log(LOG_DEBUG, __FUNCTION__, DEVEL_DIR"/router.log", x); \ + do_crm_log(LOG_DEV, __FUNCTION__, DEVEL_DIR"/router.log", x); \ crm_log_message_adv(LOG_MSG, DEVEL_DIR"/router.log", relay_message); \ crm_devel(x); \ crm_log_message(LOG_MSG, relay_message); #else # define ROUTER_RESULT(x) crm_devel("Router result: %s", x); \ crm_log_message(LOG_MSG, relay_message); #endif /* debug only, can wrap all it likes */ int last_data_id = 0; void register_fsa_error_adv( enum crmd_fsa_cause cause, enum crmd_fsa_input input, fsa_data_t *cur_data, void *new_data, const char *raised_from) { /* save the current actions */ register_fsa_input_adv(cur_data?cur_data->fsa_cause:C_FSA_INTERNAL, I_NULL, cur_data?cur_data->data:NULL, fsa_actions, FALSE, __FUNCTION__); /* reset the action list */ fsa_actions = A_NOTHING; /* register the error */ register_fsa_input_adv( cause, input, new_data, A_NOTHING, FALSE, raised_from); } void register_fsa_input_adv( enum crmd_fsa_cause cause, enum crmd_fsa_input input, void *data, long long with_actions, gboolean after, const char *raised_from) { int old_len = g_list_length(fsa_message_queue); fsa_data_t *fsa_data = NULL; crm_debug("%s raised FSA input %s (cause=%s) %s data", raised_from,fsa_input2string(input), fsa_cause2string(cause), data?"with":"without"); if(input == I_WAIT_FOR_EVENT) { do_fsa_stall = TRUE; set_bit_inplace(fsa_actions, with_actions); with_actions = A_NOTHING; crm_debug("Stalling the FSA pending further input"); } if(input == I_NULL && with_actions == A_NOTHING /* && data == NULL */){ /* no point doing anything */ return; } crm_malloc(fsa_data, sizeof(fsa_data_t)); fsa_data->id = ++last_data_id; fsa_data->fsa_input = input; fsa_data->fsa_cause = cause; fsa_data->origin = raised_from; fsa_data->data = NULL; fsa_data->data_type = fsa_dt_none; fsa_data->actions = with_actions; if(with_actions != A_NOTHING) { - crm_debug("Adding actions %.16llx to input", with_actions); + crm_devel("Adding actions %.16llx to input", with_actions); } if(data != NULL) { switch(cause) { case C_FSA_INTERNAL: case C_CRMD_STATUS_CALLBACK: case C_IPC_MESSAGE: case C_HA_MESSAGE: - crm_debug("Copying %s data from %s as a HA msg", + crm_devel("Copying %s data from %s as a HA msg", fsa_cause2string(cause), raised_from); fsa_data->data = copy_ha_msg_input(data); fsa_data->data_type = fsa_dt_ha_msg; break; case C_LRM_OP_CALLBACK: - crm_debug("Copying %s data from %s as lrm_op_t", + crm_devel("Copying %s data from %s as lrm_op_t", fsa_cause2string(cause), raised_from); fsa_data->data = copy_lrm_op((lrm_op_t*)data); fsa_data->data_type = fsa_dt_lrm; break; case C_CCM_CALLBACK: - crm_debug("Copying %s data from %s as CCM data", + crm_devel("Copying %s data from %s as CCM data", fsa_cause2string(cause), raised_from); fsa_data->data = copy_ccm_data(data); fsa_data->data_type = fsa_dt_ccm; break; case C_SUBSYSTEM_CONNECT: case C_LRM_MONITOR_CALLBACK: case C_TIMER_POPPED: case C_SHUTDOWN: case C_HEARTBEAT_FAILED: case C_HA_DISCONNECT: case C_ILLEGAL: case C_UNKNOWN: case C_STARTUP: crm_err("Copying %s data (from %s)" " not yet implemented", fsa_cause2string(cause), raised_from); exit(1); break; } crm_trace("%s data copied", fsa_cause2string(fsa_data->fsa_cause)); } /* make sure to free it properly later */ if(after) { crm_trace("Appending input"); fsa_message_queue = g_list_append(fsa_message_queue, fsa_data); } else { crm_trace("Prepending input"); fsa_message_queue = g_list_prepend(fsa_message_queue, fsa_data); } crm_verbose("Queue len: %d -> %d", old_len, g_list_length(fsa_message_queue)); fsa_dump_queue(LOG_VERBOSE); if(old_len == g_list_length(fsa_message_queue)){ crm_err("Couldnt add message to the queue"); } } void fsa_dump_queue(int log_level) { if(log_level < crm_log_level) { return; } slist_iter( data, fsa_data_t, fsa_message_queue, lpc, do_crm_log(log_level, __FUNCTION__, NULL, "queue[%d(%d)]: input %s raised by %s()\t(cause=%s)", lpc, data->id, fsa_input2string(data->fsa_input), data->origin, fsa_cause2string(data->fsa_cause)); ); } ha_msg_input_t * copy_ha_msg_input(ha_msg_input_t *orig) { ha_msg_input_t *input_copy = NULL; crm_malloc(input_copy, sizeof(ha_msg_input_t)); if(orig != NULL) { crm_trace("Copy msg"); input_copy->msg = ha_msg_copy(orig->msg); if(orig->xml != NULL) { crm_trace("Copy xml"); input_copy->xml = copy_xml_node_recursive(orig->xml); } } else { - crm_debug("No message to copy"); + crm_devel("No message to copy"); } return input_copy; } void delete_fsa_input(fsa_data_t *fsa_data) { lrm_op_t *op = NULL; crm_data_t *foo = NULL; struct crmd_ccm_data_s *ccm_input = NULL; if(fsa_data == NULL) { return; } crm_trace("About to free %s data", fsa_cause2string(fsa_data->fsa_cause)); if(fsa_data->data != NULL) { switch(fsa_data->data_type) { case fsa_dt_ha_msg: delete_ha_msg_input(fsa_data->data); break; case fsa_dt_xml: foo = fsa_data->data; free_xml(foo); break; case fsa_dt_lrm: op = (lrm_op_t*)fsa_data->data; crm_free(op->rsc->id); crm_free(op->rsc->type); crm_free(op->rsc->class); crm_free(op->rsc->provider); crm_free(op->rsc); crm_free(op->user_data); crm_free(op->output); crm_free(op->rsc_id); crm_free(op->app_name); crm_free(op); break; case fsa_dt_ccm: ccm_input = (struct crmd_ccm_data_s *) fsa_data->data; crm_free(ccm_input->oc); crm_free(ccm_input); break; case fsa_dt_none: if(fsa_data->data != NULL) { crm_err("Dont know how to free %s data from %s", fsa_cause2string(fsa_data->fsa_cause), fsa_data->origin); exit(1); } break; } crm_trace("%s data freed", fsa_cause2string(fsa_data->fsa_cause)); } crm_free(fsa_data); } /* returns the next message */ fsa_data_t * get_message(void) { fsa_data_t* message = g_list_nth_data(fsa_message_queue, 0); fsa_message_queue = g_list_remove(fsa_message_queue, message); return message; } /* returns the current head of the FIFO queue */ gboolean is_message(void) { return (g_list_length(fsa_message_queue) > 0); } void * fsa_typed_data_adv( fsa_data_t *fsa_data, enum fsa_data_type a_type, const char *caller) { void *ret_val = NULL; if(fsa_data == NULL) { do_crm_log(LOG_ERR, caller, NULL, "No FSA data available"); } else if(fsa_data->data == NULL) { do_crm_log(LOG_ERR, caller, NULL, "No message data available"); } else if(fsa_data->data_type != a_type) { do_crm_log(LOG_CRIT, caller, NULL, "Message data was the wrong type! %d vs. requested=%d." " Origin: %s", fsa_data->data_type, a_type, fsa_data->origin); CRM_ASSERT(fsa_data->data_type == a_type); } else { ret_val = fsa_data->data; } return ret_val; } /* A_MSG_ROUTE */ enum crmd_fsa_input do_msg_route(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { enum crmd_fsa_input result = I_NULL; ha_msg_input_t *input = fsa_typed_data(fsa_dt_ha_msg); gboolean routed = FALSE; if(msg_data->fsa_cause != C_IPC_MESSAGE && msg_data->fsa_cause != C_HA_MESSAGE) { /* dont try and route these */ crm_warn("Can only process HA and IPC messages"); return I_NULL; } /* try passing the buck first */ crm_trace("Attempting to route message"); routed = relay_message(input->msg, cause==C_IPC_MESSAGE); if(routed == FALSE) { crm_trace("Message wasn't routed... try handling locally"); /* calculate defer */ result = handle_message(input); switch(result) { case I_NULL: break; case I_DC_HEARTBEAT: break; case I_CIB_OP: break; /* what else should go here? */ default: crm_trace("Defering local processing of message"); register_fsa_input_later( cause, result, msg_data->data); result = I_NULL; break; } if(result == I_NULL) { crm_trace("Message processed"); } else { register_fsa_input(cause, result, msg_data->data); } } else { crm_trace("Message routed..."); input->msg = NULL; } return I_NULL; } /* * This method frees msg */ gboolean send_request(HA_Message *msg, char **msg_reference) { gboolean was_sent = FALSE; /* crm_xml_devel(request, "Final request..."); */ if(msg_reference != NULL) { *msg_reference = crm_strdup( cl_get_string(msg, XML_ATTR_REFERENCE)); } was_sent = relay_message(msg, TRUE); if(was_sent == FALSE) { ha_msg_input_t *fsa_input = new_ha_msg_input(msg); register_fsa_input(C_IPC_MESSAGE, I_ROUTER, fsa_input); delete_ha_msg_input(fsa_input); crm_msg_del(msg); } return was_sent; } /* unless more processing is required, relay_message is freed */ gboolean relay_message(HA_Message *relay_message, gboolean originated_locally) { int is_for_dc = 0; int is_for_dcib = 0; int is_for_crm = 0; int is_for_cib = 0; int is_local = 0; gboolean processing_complete = FALSE; const char *host_to = cl_get_string(relay_message, F_CRM_HOST_TO); const char *sys_to = cl_get_string(relay_message, F_CRM_SYS_TO); const char *type = cl_get_string(relay_message, F_TYPE); const char *msg_error = NULL; - crm_debug("Routing message %s", + crm_devel("Routing message %s", cl_get_string(relay_message, XML_ATTR_REFERENCE)); if(relay_message == NULL) { msg_error = "Cannot route empty message"; } else if(safe_str_eq(CRM_OP_HELLO, cl_get_string(relay_message, F_CRM_TASK))){ /* quietly ignore */ processing_complete = TRUE; } else if(safe_str_neq(type, T_CRM)) { msg_error = "Bad message type"; } else if(sys_to == NULL) { msg_error = "Bad message destination: no subsystem"; } if(msg_error != NULL) { processing_complete = TRUE; crm_err("%s", msg_error); crm_log_message(LOG_ERR, relay_message); } if(processing_complete) { crm_msg_del(relay_message); return TRUE; } processing_complete = TRUE; is_for_dc = (strcmp(CRM_SYSTEM_DC, sys_to) == 0); is_for_dcib = (strcmp(CRM_SYSTEM_DCIB, sys_to) == 0); is_for_cib = (strcmp(CRM_SYSTEM_CIB, sys_to) == 0); is_for_crm = (strcmp(CRM_SYSTEM_CRMD, sys_to) == 0); is_local = 0; if(host_to == NULL || strlen(host_to) == 0) { if(is_for_dc) { is_local = 0; } else if(is_for_crm && originated_locally) { is_local = 0; } else { is_local = 1; } } else if(strcmp(fsa_our_uname, host_to) == 0) { is_local=1; } if(is_for_dc || is_for_dcib) { if(AM_I_DC) { ROUTER_RESULT("Message result: DC/CRMd process"); processing_complete = FALSE; /* more to be done by caller */ } else if(originated_locally) { ROUTER_RESULT("Message result: External relay to DC"); send_msg_via_ha(fsa_cluster_conn, relay_message); } else { /* discard */ ROUTER_RESULT("Message result: Discard, not DC"); crm_msg_del(relay_message); } } else if(is_local && (is_for_crm || is_for_cib)) { ROUTER_RESULT("Message result: CRMd process"); processing_complete = FALSE; /* more to be done by caller */ } else if(is_local) { ROUTER_RESULT("Message result: Local relay"); send_msg_via_ipc(relay_message, sys_to); } else { ROUTER_RESULT("Message result: External relay"); send_msg_via_ha(fsa_cluster_conn, relay_message); } return processing_complete; } gboolean crmd_authorize_message(ha_msg_input_t *client_msg, crmd_client_t *curr_client) { /* check the best case first */ const char *sys_from = cl_get_string(client_msg->msg, F_CRM_SYS_FROM); char *uuid = NULL; char *client_name = NULL; char *major_version = NULL; char *minor_version = NULL; const char *filtered_from; gpointer table_key = NULL; gboolean auth_result = FALSE; struct crm_subsystem_s *the_subsystem = NULL; gboolean can_reply = FALSE; /* no-one has registered with this id */ const char *op = cl_get_string(client_msg->msg, F_CRM_TASK); if (safe_str_neq(CRM_OP_HELLO, op)) { if(sys_from == NULL) { crm_warn("Message [%s] was had no value for %s... discarding", cl_get_string(client_msg->msg, XML_ATTR_REFERENCE), F_CRM_SYS_FROM); return FALSE; } filtered_from = sys_from; /* The CIB can have two names on the DC */ if(strcmp(sys_from, CRM_SYSTEM_DCIB) == 0) filtered_from = CRM_SYSTEM_CIB; if (g_hash_table_lookup (ipc_clients, filtered_from) != NULL) { can_reply = TRUE; /* reply can be routed */ } crm_verbose("Message reply can%s be routed from %s.", can_reply?"":" not", sys_from); if(can_reply == FALSE) { crm_warn("Message [%s] not authorized", cl_get_string(client_msg->msg, XML_ATTR_REFERENCE)); } #if 0 if(ha_msg_value(msg, XML_ATTR_REFERENCE) == NULL) { ha_msg_add(new_input->msg, XML_ATTR_REFERENCE, seq); } #endif register_fsa_input(C_IPC_MESSAGE, I_ROUTER, client_msg); s_crmd_fsa(C_IPC_MESSAGE); return can_reply; } - crm_debug("received client join msg"); + crm_devel("received client join msg"); crm_log_message(LOG_MSG, client_msg->msg); auth_result = process_hello_message( client_msg->xml, &uuid, &client_name, &major_version, &minor_version); if (auth_result == TRUE) { if(client_name == NULL || uuid == NULL) { crm_err("Bad client details (client_name=%s, uuid=%s)", crm_str(client_name), crm_str(uuid)); auth_result = FALSE; } } if (auth_result == TRUE) { /* check version */ int mav = atoi(major_version); int miv = atoi(minor_version); - crm_debug("Checking client version number"); + crm_devel("Checking client version number"); if (mav < 0 || miv < 0) { crm_err("Client version (%d:%d) is not acceptable", mav, miv); auth_result = FALSE; } crm_free(major_version); crm_free(minor_version); } if (auth_result == TRUE) { /* if we already have one of those clients * only applies to te, pe etc. not admin clients */ if (strcmp(CRM_SYSTEM_PENGINE, client_name) == 0) { the_subsystem = pe_subsystem; } else if (strcmp(CRM_SYSTEM_TENGINE, client_name) == 0) { the_subsystem = te_subsystem; } if (the_subsystem != NULL) { /* do we already have one? */ - crm_debug("Checking if %s is required/already connected", + crm_devel("Checking if %s is required/already connected", client_name); if(is_set(fsa_input_register, the_subsystem->flag_connected)) { auth_result = FALSE; crm_err("Bit\t%.16llx set in %.16llx", the_subsystem->flag_connected, fsa_input_register); crm_err("Client %s is already connected", client_name); } else if(FALSE == is_set(fsa_input_register, the_subsystem->flag_required)) { auth_result = FALSE; crm_err("Bit\t%.16llx not set in %.16llx", the_subsystem->flag_connected, fsa_input_register); crm_err("Client %s joined without us asking", client_name); } else { the_subsystem->ipc = curr_client->client_channel; } } else { table_key = (gpointer) generate_hash_key(client_name, uuid); } } if (auth_result == TRUE) { if(table_key == NULL) { table_key = (gpointer)crm_strdup(client_name); } crm_info("Accepted client %s", crm_str(table_key)); curr_client->table_key = table_key; curr_client->sub_sys = crm_strdup(client_name); curr_client->uuid = crm_strdup(uuid); g_hash_table_insert (ipc_clients, table_key, curr_client->client_channel); send_hello_message(curr_client->client_channel, "n/a", CRM_SYSTEM_CRMD, "0", "1"); crm_debug("Updated client list with %s", crm_str(table_key)); if(the_subsystem != NULL) { set_bit_inplace( fsa_input_register, the_subsystem->flag_connected); } s_crmd_fsa(C_SUBSYSTEM_CONNECT); } else { crm_err("Rejected client logon request"); curr_client->client_channel->ch_status = IPC_DISC_PENDING; } if(uuid != NULL) crm_free(uuid); if(minor_version != NULL) crm_free(minor_version); if(major_version != NULL) crm_free(major_version); if(client_name != NULL) crm_free(client_name); /* hello messages should never be processed further */ return FALSE; } enum crmd_fsa_input handle_message(ha_msg_input_t *stored_msg) { enum crmd_fsa_input next_input = I_NULL; const char *type = NULL; if(stored_msg == NULL || stored_msg->msg == NULL) { crm_err("No message to handle"); return I_NULL; } type = cl_get_string(stored_msg->msg, F_CRM_MSG_TYPE); if(safe_str_eq(type, XML_ATTR_REQUEST)) { next_input = handle_request(stored_msg); } else if(safe_str_eq(type, XML_ATTR_RESPONSE)) { next_input = handle_response(stored_msg); } else { crm_err("Unknown message type: %s", type); } /* crm_verbose("%s: Next input is %s", __FUNCTION__, */ /* fsa_input2string(next_input)); */ return next_input; } enum crmd_fsa_input handle_request(ha_msg_input_t *stored_msg) { HA_Message *msg = NULL; enum crmd_fsa_input next_input = I_NULL; const char *op = cl_get_string(stored_msg->msg, F_CRM_TASK); const char *sys_to = cl_get_string(stored_msg->msg, F_CRM_SYS_TO); const char *host_from = cl_get_string(stored_msg->msg, F_CRM_HOST_FROM); crm_verbose("Received %s in state %s", op, fsa_state2string(fsa_state)); if(op == NULL) { crm_err("Bad message"); crm_log_message(LOG_ERR, stored_msg->msg); /*========== common actions ==========*/ } else if(strcmp(op, CRM_OP_VOTE) == 0) { /* count the vote and decide what to do after that */ register_fsa_input_w_actions( C_HA_MESSAGE, I_NULL, stored_msg, A_ELECTION_COUNT); /* Sometimes we _must_ go into S_ELECTION */ if(fsa_state == S_HALT) { crm_debug("Forcing an election from S_HALT"); next_input = I_ELECTION; #if 0 } else if(AM_I_DC) { /* This is the old way of doing things but what is gained? */ next_input = I_ELECTION; #endif } } else if(strcmp(op, CRM_OP_LOCAL_SHUTDOWN) == 0) { crm_shutdown(SIGTERM); /*next_input = I_SHUTDOWN; */ next_input = I_NULL; } else if(strcmp(op, CRM_OP_PING) == 0) { /* eventually do some stuff to figure out * if we /are/ ok */ crm_data_t *ping = createPingAnswerFragment(sys_to, "ok"); set_xml_property_copy(ping, "crmd_state", fsa_state2string(fsa_state)); msg = create_reply(stored_msg->msg, ping); if(relay_message(msg, TRUE) == FALSE) { crm_msg_del(msg); } /* probably better to do this via signals on the * local node */ } else if(strcmp(op, CRM_OP_DEBUG_UP) == 0) { int level = get_crm_log_level(); set_crm_log_level(level+1); crm_info("Debug set to %d (was %d)", get_crm_log_level(), level); } else if(strcmp(op, CRM_OP_DEBUG_DOWN) == 0) { int level = get_crm_log_level(); set_crm_log_level(level-1); crm_info("Debug set to %d (was %d)", get_crm_log_level(), level); } else if(strcmp(op, CRM_OP_WELCOME) == 0) { next_input = I_JOIN_OFFER; } else if(strcmp(op, CRM_OP_JOINACK) == 0) { next_input = I_JOIN_RESULT; /* this functionality should only be enabled if this is a development build */ } else if(CRM_DEV_BUILD && strcmp(op, CRM_OP_DIE) == 0/*constant condition*/) { crm_warn("Test-only code: Killing the CRM without mercy"); crm_warn("Inhibiting respawns"); exit(100); /*========== (NOT_DC)-Only Actions ==========*/ } else if(AM_I_DC == FALSE){ gboolean dc_match = safe_str_eq(host_from, fsa_our_dc); if(dc_match || fsa_our_dc == NULL) { if(strcmp(op, CRM_OP_HBEAT) == 0) { - crm_debug("Received DC heartbeat from %s", + crm_devel("Received DC heartbeat from %s", host_from); next_input = I_DC_HEARTBEAT; } else if(fsa_our_dc == NULL) { crm_warn("CRMd discarding request: %s" " (DC: %s, from: %s)", op, crm_str(fsa_our_dc), host_from); crm_warn("Ignored Request"); crm_log_message(LOG_WARNING, stored_msg->msg); } else if(strcmp(op, CRM_OP_SHUTDOWN) == 0) { next_input = I_TERMINATE; } else { crm_err("CRMd didnt expect request: %s", op); crm_log_message(LOG_ERR, stored_msg->msg); } } else { crm_warn("Discarding %s op from %s", op, host_from); } /*========== DC-Only Actions ==========*/ } else if(AM_I_DC){ if(strcmp(op, CRM_OP_TEABORT) == 0) { if(fsa_state != S_INTEGRATION) { next_input = I_PE_CALC; } else { - crm_debug("Ignoring %s in state %s." + crm_devel("Ignoring %s in state %s." " Waiting for the integration to" " complete first.", op, fsa_state2string(fsa_state)); } } else if(strcmp(op, CRM_OP_TECOMPLETE) == 0) { /* if(fsa_state == S_TRANSITION_ENGINE) { */ next_input = I_TE_SUCCESS; /* } else { */ /* crm_warn("Op %s is only valid in state %s..." */ /* "We are in (%s)", */ /* op, */ /* fsa_state2string(S_TRANSITION_ENGINE), */ /* fsa_state2string(fsa_state)); */ /* } */ } else if(strcmp(op, CRM_OP_ANNOUNCE) == 0) { next_input = I_NODE_JOIN; } else if(strcmp(op, CRM_OP_SHUTDOWN) == 0) { gboolean dc_match = safe_str_eq(host_from, fsa_our_dc); if(dc_match) { crm_err("We didnt ask to be shut down yet our" " TE is telling us too." " Better get out now!"); next_input = I_TERMINATE; } else if(is_set(fsa_input_register, R_SHUTDOWN)) { crm_err("We asked to be shut down, " " are still the DC, yet another node" " is askin us to shutdown!"); next_input = I_TERMINATE; } else if(fsa_state != S_STOPPING) { crm_warn("Another node is asking us to shutdown" " but we think we're ok."); next_input = I_ELECTION; } } else if(strcmp(op, CRM_OP_SHUTDOWN_REQ) == 0) { /* a slave wants to shut down */ /* create cib fragment and add to message */ next_input = handle_shutdown_request(stored_msg->msg); } else { crm_err("Unexpected request (%s) sent to the DC", op); crm_log_message(LOG_ERR, stored_msg->msg); } } return next_input; } enum crmd_fsa_input handle_response(ha_msg_input_t *stored_msg) { enum crmd_fsa_input next_input = I_NULL; const char *op = cl_get_string(stored_msg->msg, F_CRM_TASK); const char *sys_from = cl_get_string(stored_msg->msg, F_CRM_SYS_FROM); const char *msg_ref = cl_get_string(stored_msg->msg, XML_ATTR_REFERENCE); crm_verbose("Received %s %s in state %s", op, XML_ATTR_RESPONSE, fsa_state2string(fsa_state)); if(op == NULL) { crm_err("Bad message"); crm_log_message(LOG_ERR, stored_msg->msg); } else if(AM_I_DC && strcmp(op, CRM_OP_WELCOME) == 0) { next_input = I_JOIN_REQUEST; } else if(AM_I_DC && strcmp(op, CRM_OP_JOINACK) == 0) { next_input = I_JOIN_RESULT; } else if(AM_I_DC && strcmp(op, CRM_OP_PECALC) == 0) { if(safe_str_eq(msg_ref, fsa_pe_ref)) { next_input = I_PE_SUCCESS; } else { crm_verbose("Skipping superceeded reply from %s", sys_from); } } else if(strcmp(op, CRM_OP_VOTE) == 0 || strcmp(op, CRM_OP_HBEAT) == 0 || strcmp(op, CRM_OP_WELCOME) == 0 || strcmp(op, CRM_OP_SHUTDOWN_REQ) == 0 || strcmp(op, CRM_OP_SHUTDOWN) == 0 || strcmp(op, CRM_OP_ANNOUNCE) == 0) { next_input = I_NULL; } else if(strcmp(op, CRM_OP_CIB_CREATE) == 0 || strcmp(op, CRM_OP_CIB_UPDATE) == 0 || strcmp(op, CRM_OP_CIB_DELETE) == 0 || strcmp(op, CRM_OP_CIB_REPLACE) == 0 || strcmp(op, CRM_OP_CIB_ERASE) == 0) { /* perhaps we should do somethign with these replies, * especially check that the actions passed */ /* fprintf(router_strm, "Message result: CIB Reply\n"); */ } else { crm_err("Unexpected response (op=%s) sent to the %s", op, AM_I_DC?"DC":"CRMd"); next_input = I_NULL; } return next_input; } enum crmd_fsa_input handle_shutdown_request(HA_Message *stored_msg) { /* handle here to avoid potential version issues * where the shutdown message/proceedure may have * been changed in later versions. * * This way the DC is always in control of the shutdown */ crm_data_t *frag = NULL; time_t now = time(NULL); char *now_s = crm_itoa((int)now); crm_data_t *node_state = create_xml_node(NULL, XML_CIB_TAG_STATE); const char *host_from= cl_get_string(stored_msg, F_CRM_HOST_FROM); crm_info("Creating shutdown request for %s",host_from); crm_info("stored msg"); crm_log_message(LOG_MSG, stored_msg); set_uuid(fsa_cluster_conn, node_state, XML_ATTR_UUID, host_from); set_xml_property_copy(node_state, XML_ATTR_UNAME, host_from); set_xml_property_copy(node_state, XML_CIB_ATTR_SHUTDOWN, now_s); set_xml_property_copy( node_state, XML_CIB_ATTR_EXPSTATE, CRMD_STATE_INACTIVE); frag = create_cib_fragment(node_state, NULL); /* cleanup intermediate steps */ free_xml(node_state); crm_free(now_s); fsa_cib_conn->cmds->modify( fsa_cib_conn, XML_CIB_TAG_STATUS, frag, NULL, cib_sync_call); free_xml(frag); /* will be picked up by the TE as long as its running */ if(! is_set(fsa_input_register, R_TE_CONNECTED) ) { register_fsa_input(C_HA_MESSAGE, I_PE_CALC, NULL); } return I_NULL; } /* frees msg upon completion */ gboolean send_msg_via_ha(ll_cluster_t *hb_fd, HA_Message *msg) { - int log_level = LOG_DEBUG; + int log_level = LOG_DEV; int send_result = HA_OK; gboolean broadcast = FALSE; gboolean all_is_good = TRUE; const char *op = cl_get_string(msg, F_CRM_TASK); const char *sys_to = cl_get_string(msg, F_CRM_SYS_TO); const char *host_to = cl_get_string(msg, F_CRM_HOST_TO); if (msg == NULL) { crm_err("Attempt to send NULL Message via HA failed."); all_is_good = FALSE; } else { crm_trace("Relaying message to (%s) via HA", host_to); } if (all_is_good) { if (sys_to == NULL || strlen(sys_to) == 0) { crm_err("You did not specify a destination sub-system" " for this message."); all_is_good = FALSE; } } /* There are a number of messages may not need to be ordered. * At a later point perhaps we should detect them and send them * as unordered messages. */ if (all_is_good) { if (host_to == NULL || strlen(host_to) == 0 || safe_str_eq(sys_to, CRM_SYSTEM_DC)) { broadcast = TRUE; send_result=hb_fd->llc_ops->sendclustermsg(hb_fd, msg); } else { send_result = hb_fd->llc_ops->send_ordered_nodemsg( hb_fd, msg, host_to); } if(send_result != HA_OK) all_is_good = FALSE; } if(all_is_good == FALSE) { log_level = LOG_ERR; } if(log_level == LOG_ERR || (safe_str_neq(op, CRM_OP_HBEAT))) { do_crm_log(log_level, __FUNCTION__, NULL, "Sending %sHA message (ref=%s) to %s@%s %s.", broadcast?"broadcast ":"directed ", cl_get_string(msg, XML_ATTR_REFERENCE), crm_str(sys_to), host_to==NULL?"":host_to, all_is_good?"succeeded":"failed"); } #ifdef MSG_LOG crm_log_message_adv(log_level, "outbound.log", msg); #endif crm_msg_del(msg); return all_is_good; } /* msg is deleted by the time this returns */ gboolean send_msg_via_ipc(HA_Message *msg, const char *sys) { gboolean send_ok = TRUE; IPC_Channel *client_channel; enum crmd_fsa_input next_input; crm_trace("relaying msg to sub_sys=%s via IPC", sys); client_channel = (IPC_Channel*)g_hash_table_lookup(ipc_clients, sys); if(cl_get_string(msg, F_CRM_HOST_FROM) == NULL) { ha_msg_add(msg, F_CRM_HOST_FROM, fsa_our_uname); } if (client_channel != NULL) { - crm_debug("Sending message via channel %s.", sys); + crm_devel("Sending message via channel %s.", sys); send_ok = send_ipc_message(client_channel, msg); msg = NULL; /* so the crm_msg_del() below doesnt fail */ } else if(sys != NULL && strcmp(sys, CRM_SYSTEM_CIB) == 0) { crm_err("Sub-system (%s) has been incorporated into the CRMd.", sys); crm_err("Change the way we handle this CIB message"); crm_log_message(LOG_ERR, msg); send_ok = FALSE; } else if(sys != NULL && strcmp(sys, CRM_SYSTEM_LRMD) == 0) { fsa_data_t *fsa_data = NULL; ha_msg_input_t *msg_copy = new_ha_msg_input(msg); crm_malloc(fsa_data, sizeof(fsa_data_t)); fsa_data->fsa_input = I_MESSAGE; fsa_data->fsa_cause = C_IPC_MESSAGE; fsa_data->data = msg_copy; fsa_data->origin = __FUNCTION__; fsa_data->data_type = fsa_dt_ha_msg; #ifdef FSA_TRACE crm_verbose("Invoking action %s (%.16llx)", fsa_action2string(A_LRM_INVOKE), A_LRM_INVOKE); #endif next_input = do_lrm_invoke(A_LRM_INVOKE, C_IPC_MESSAGE, fsa_state, I_MESSAGE, fsa_data); delete_ha_msg_input(msg_copy); crm_free(fsa_data); /* todo: feed this back in for anything != I_NULL */ #ifdef FSA_TRACE crm_verbose("Result of action %s was %s", fsa_action2string(A_LRM_INVOKE), fsa_input2string(next_input)); #endif } else { crm_err("Unknown Sub-system (%s)... discarding message.", sys); send_ok = FALSE; } crm_msg_del(msg); return send_ok; } diff --git a/crm/crmd/misc.c b/crm/crmd/misc.c index 18c06b8328..fa496a7ad6 100644 --- a/crm/crmd/misc.c +++ b/crm/crmd/misc.c @@ -1,91 +1,90 @@ /* * 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 /* A_LOG, A_WARN, A_ERROR */ enum crmd_fsa_input do_log(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { int log_type = LOG_DEBUG; if(action & A_LOG) { log_type = LOG_INFO; } else if(action & A_WARN) { log_type = LOG_WARNING; } else if(action & A_ERROR) { log_type = LOG_ERR; } do_crm_log(log_type, __FUNCTION__, NULL, "[[FSA]] Input %s from %s() received in state (%s)", fsa_input2string(msg_data->fsa_input), msg_data->origin, fsa_state2string(cur_state)); if(msg_data->data_type == fsa_dt_ha_msg) { -#if 0 ha_msg_input_t *input = fsa_typed_data(msg_data->data_type); crm_log_message(log_type, input->msg); -#endif + } else if(msg_data->data_type == fsa_dt_xml) { crm_data_t *input = fsa_typed_data(msg_data->data_type); if(crm_log_level >= log_type) { print_xml_formatted( log_type, __FUNCTION__, input, NULL); } } else if(msg_data->data_type == fsa_dt_lrm) { lrm_op_t *input = fsa_typed_data(msg_data->data_type); do_crm_log(log_type, __FUNCTION__, NULL, "Resource %s: Call ID %d returned %d (%d)." " New status if rc=0: %s", input->rsc_id, input->call_id, input->rc, input->op_status, (char*)input->user_data); } else if(msg_data->data_type == fsa_dt_ccm) { struct crmd_ccm_data_s *input = fsa_typed_data( msg_data->data_type); int event = *(input->event); do_crm_log(log_type, __FUNCTION__, NULL, "Received \"%s\" event from the CCM.", event==OC_EV_MS_NEW_MEMBERSHIP?"NEW MEMBERSHIP": event==OC_EV_MS_NOT_PRIMARY?"NOT PRIMARY": event==OC_EV_MS_PRIMARY_RESTORED?"PRIMARY RESTORED": event==OC_EV_MS_EVICTED?"EVICTED": "NO QUORUM MEMBERSHIP"); } return I_NULL; } diff --git a/crm/crmd/utils.c b/crm/crmd/utils.c index 8a10cb8541..a8fdb6841a 100644 --- a/crm/crmd/utils.c +++ b/crm/crmd/utils.c @@ -1,1136 +1,1194 @@ /* * 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 #include #include #include void copy_ccm_node(oc_node_t a_node, oc_node_t *a_node_copy); /* A_DC_TIMER_STOP, A_DC_TIMER_START, * A_FINALIZE_TIMER_STOP, A_FINALIZE_TIMER_START * A_INTEGRATE_TIMER_STOP, A_INTEGRATE_TIMER_START */ enum crmd_fsa_input do_timer_control(long long action, enum crmd_fsa_cause cause, enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t *msg_data) { gboolean timer_op_ok = TRUE; enum crmd_fsa_input result = I_NULL; if(action & A_DC_TIMER_STOP) { timer_op_ok = stopTimer(election_trigger); } else if(action & A_FINALIZE_TIMER_STOP) { timer_op_ok = stopTimer(finalization_timer); } else if(action & A_INTEGRATE_TIMER_STOP) { timer_op_ok = stopTimer(integration_timer); /* } else if(action & A_ELECTION_TIMEOUT_STOP) { */ /* timer_op_ok = stopTimer(election_timeout); */ } /* dont start a timer that wasnt already running */ if(action & A_DC_TIMER_START && timer_op_ok) { startTimer(election_trigger); if(AM_I_DC) { /* there can be only one */ result = I_ELECTION; } } else if(action & A_FINALIZE_TIMER_START) { startTimer(finalization_timer); } else if(action & A_INTEGRATE_TIMER_START) { startTimer(integration_timer); /* } else if(action & A_ELECTION_TIMEOUT_START) { */ /* startTimer(election_timeout); */ } return I_NULL; } gboolean timer_popped(gpointer data) { fsa_timer_t *timer = (fsa_timer_t *)data; if(timer == election_trigger) { crm_info("Election Trigger (%s) just popped!", fsa_input2string(timer->fsa_input)); } else if(timer == election_timeout) { crm_info("Election Timeout (%s) just popped!", fsa_input2string(timer->fsa_input)); } else { crm_info("Timer %s just popped!", fsa_input2string(timer->fsa_input)); } stopTimer(timer); /* make it _not_ go off again */ if(timer->fsa_input != I_NULL) { register_fsa_input_before( C_TIMER_POPPED, timer->fsa_input, NULL); } s_crmd_fsa(C_TIMER_POPPED); return TRUE; } gboolean startTimer(fsa_timer_t *timer) { if((timer->source_id == (guint)-1 || timer->source_id == (guint)-2) && timer->period_ms > 0) { timer->source_id = Gmain_timeout_add( timer->period_ms, timer->callback, (void*)timer); - crm_debug("Started %s timer (%d), period=%dms", + crm_devel("Started %s timer (%d), period=%dms", fsa_input2string(timer->fsa_input), timer->source_id, timer->period_ms); } else if(timer->period_ms < 0) { crm_err("Tried to start timer %s with -ve period", fsa_input2string(timer->fsa_input)); } else { - crm_debug("Timer %s (period=%dms) already running (%d)", + crm_devel("Timer %s (period=%dms) already running (%d)", fsa_input2string(timer->fsa_input), timer->period_ms, timer->source_id); return FALSE; } return TRUE; } gboolean stopTimer(fsa_timer_t *timer) { if(timer == NULL) { crm_err("Attempted to stop NULL timer"); return FALSE; } else if(timer->source_id != (guint)-1 && timer->source_id != (guint)-2) { - crm_debug("Stopping %s timer (period=%dms, src=%d)", + crm_devel("Stopping %s timer (period=%dms, src=%d)", fsa_input2string(timer->fsa_input), timer->period_ms, timer->source_id); g_source_remove(timer->source_id); timer->source_id = -2; } else { - crm_debug("Timer %s (period=%dms) already stopped (src=%d)", + crm_devel("Timer %s (period=%dms) already stopped (src=%d)", fsa_input2string(timer->fsa_input), timer->period_ms, timer->source_id); timer->source_id = -2; return FALSE; } return TRUE; } long long toggle_bit(long long action_list, long long action) { crm_insane("Toggling bit %.16llx", action); action_list ^= action; crm_insane("Result %.16llx", action_list & action); return action_list; } long long clear_bit(long long action_list, long long action) { crm_insane("Clearing bit\t%.16llx", action); /* ensure its set */ action_list |= action; /* then toggle */ action_list = action_list ^ action; return action_list; } long long set_bit(long long action_list, long long action) { crm_insane("Setting bit\t%.16llx", action); action_list |= action; return action_list; } gboolean is_set(long long action_list, long long action) { crm_insane("Checking bit\t%.16llx in %.16llx", action, action_list); return ((action_list & action) == action); } gboolean is_set_any(long long action_list, long long action) { crm_insane("Checking bit\t%.16llx in %.16llx", action, action_list); return ((action_list & action) != 0); } const char * fsa_input2string(enum crmd_fsa_input input) { const char *inputAsText = NULL; switch(input){ case I_NULL: inputAsText = "I_NULL"; break; case I_CCM_EVENT: inputAsText = "I_CCM_EVENT"; break; case I_CIB_OP: inputAsText = "I_CIB_OP"; break; case I_CIB_UPDATE: inputAsText = "I_CIB_UPDATE"; break; case I_DC_TIMEOUT: inputAsText = "I_DC_TIMEOUT"; break; case I_ELECTION: inputAsText = "I_ELECTION"; break; case I_PE_CALC: inputAsText = "I_PE_CALC"; break; case I_RELEASE_DC: inputAsText = "I_RELEASE_DC"; break; case I_ELECTION_DC: inputAsText = "I_ELECTION_DC"; break; case I_ERROR: inputAsText = "I_ERROR"; break; case I_FAIL: inputAsText = "I_FAIL"; break; case I_INTEGRATED: inputAsText = "I_INTEGRATED"; break; case I_FINALIZED: inputAsText = "I_FINALIZED"; break; case I_NODE_JOIN: inputAsText = "I_NODE_JOIN"; break; case I_JOIN_OFFER: inputAsText = "I_JOIN_OFFER"; break; case I_JOIN_REQUEST: inputAsText = "I_JOIN_REQUEST"; break; case I_JOIN_RESULT: inputAsText = "I_JOIN_RESULT"; break; case I_NOT_DC: inputAsText = "I_NOT_DC"; break; case I_RECOVERED: inputAsText = "I_RECOVERED"; break; case I_RELEASE_FAIL: inputAsText = "I_RELEASE_FAIL"; break; case I_RELEASE_SUCCESS: inputAsText = "I_RELEASE_SUCCESS"; break; case I_RESTART: inputAsText = "I_RESTART"; break; case I_PE_SUCCESS: inputAsText = "I_PE_SUCCESS"; break; case I_ROUTER: inputAsText = "I_ROUTER"; break; case I_SHUTDOWN: inputAsText = "I_SHUTDOWN"; break; case I_STARTUP: inputAsText = "I_STARTUP"; break; case I_TE_SUCCESS: inputAsText = "I_TE_SUCCESS"; break; case I_TERMINATE: inputAsText = "I_TERMINATE"; break; case I_DC_HEARTBEAT: inputAsText = "I_DC_HEARTBEAT"; break; case I_WAIT_FOR_EVENT: inputAsText = "I_WAIT_FOR_EVENT"; break; case I_LRM_EVENT: inputAsText = "I_LRM_EVENT"; break; case I_PENDING: inputAsText = "I_PENDING"; break; case I_HALT: inputAsText = "I_HALT"; break; case I_ILLEGAL: inputAsText = "I_ILLEGAL"; break; } if(inputAsText == NULL) { crm_err("Input %d is unknown", input); inputAsText = ""; } return inputAsText; } const char * fsa_state2string(enum crmd_fsa_state state) { const char *stateAsText = NULL; switch(state){ case S_IDLE: stateAsText = "S_IDLE"; break; case S_ELECTION: stateAsText = "S_ELECTION"; break; case S_INTEGRATION: stateAsText = "S_INTEGRATION"; break; case S_FINALIZE_JOIN: stateAsText = "S_FINALIZE_JOIN"; break; case S_NOT_DC: stateAsText = "S_NOT_DC"; break; case S_POLICY_ENGINE: stateAsText = "S_POLICY_ENGINE"; break; case S_RECOVERY: stateAsText = "S_RECOVERY"; break; case S_RELEASE_DC: stateAsText = "S_RELEASE_DC"; break; case S_PENDING: stateAsText = "S_PENDING"; break; case S_STOPPING: stateAsText = "S_STOPPING"; break; case S_TERMINATE: stateAsText = "S_TERMINATE"; break; case S_TRANSITION_ENGINE: stateAsText = "S_TRANSITION_ENGINE"; break; case S_STARTING: stateAsText = "S_STARTING"; break; case S_HALT: stateAsText = "S_HALT"; break; case S_ILLEGAL: stateAsText = "S_ILLEGAL"; break; } if(stateAsText == NULL) { crm_err("State %d is unknown", state); stateAsText = ""; } return stateAsText; } const char * fsa_cause2string(enum crmd_fsa_cause cause) { const char *causeAsText = NULL; switch(cause){ case C_UNKNOWN: causeAsText = "C_UNKNOWN"; break; case C_STARTUP: causeAsText = "C_STARTUP"; break; case C_IPC_MESSAGE: causeAsText = "C_IPC_MESSAGE"; break; case C_HA_MESSAGE: causeAsText = "C_HA_MESSAGE"; break; case C_CCM_CALLBACK: causeAsText = "C_CCM_CALLBACK"; break; case C_TIMER_POPPED: causeAsText = "C_TIMER_POPPED"; break; case C_SHUTDOWN: causeAsText = "C_SHUTDOWN"; break; case C_HEARTBEAT_FAILED: causeAsText = "C_HEARTBEAT_FAILED"; break; case C_SUBSYSTEM_CONNECT: causeAsText = "C_SUBSYSTEM_CONNECT"; break; case C_LRM_OP_CALLBACK: causeAsText = "C_LRM_OP_CALLBACK"; break; case C_LRM_MONITOR_CALLBACK: causeAsText = "C_LRM_MONITOR_CALLBACK"; break; case C_CRMD_STATUS_CALLBACK: causeAsText = "C_CRMD_STATUS_CALLBACK"; break; case C_HA_DISCONNECT: causeAsText = "C_HA_DISCONNECT"; break; case C_FSA_INTERNAL: causeAsText = "C_FSA_INTERNAL"; break; case C_ILLEGAL: causeAsText = "C_ILLEGAL"; break; } if(causeAsText == NULL) { crm_err("Cause %d is unknown", cause); causeAsText = ""; } return causeAsText; } const char * fsa_action2string(long long action) { const char *actionAsText = NULL; switch(action){ case A_NOTHING: actionAsText = "A_NOTHING"; break; case A_ELECTION_START: actionAsText = "A_ELECTION_START"; break; case A_READCONFIG: actionAsText = "A_READCONFIG"; break; case O_SHUTDOWN: actionAsText = "O_SHUTDOWN"; break; case O_RELEASE: actionAsText = "O_RELEASE"; break; case A_STARTUP: actionAsText = "A_STARTUP"; break; case A_STARTED: actionAsText = "A_STARTED"; break; case A_HA_CONNECT: actionAsText = "A_HA_CONNECT"; break; case A_HA_DISCONNECT: actionAsText = "A_HA_DISCONNECT"; break; case A_LRM_CONNECT: actionAsText = "A_LRM_CONNECT"; break; case A_LRM_EVENT: actionAsText = "A_LRM_EVENT"; break; case A_LRM_INVOKE: actionAsText = "A_LRM_INVOKE"; break; case A_LRM_DISCONNECT: actionAsText = "A_LRM_DISCONNECT"; break; case A_CL_JOIN_QUERY: actionAsText = "A_CL_JOIN_QUERY"; break; case A_DC_TIMER_STOP: actionAsText = "A_DC_TIMER_STOP"; break; case A_DC_TIMER_START: actionAsText = "A_DC_TIMER_START"; break; case A_INTEGRATE_TIMER_START: actionAsText = "A_INTEGRATE_TIMER_START"; break; case A_INTEGRATE_TIMER_STOP: actionAsText = "A_INTEGRATE_TIMER_STOP"; break; case A_FINALIZE_TIMER_START: actionAsText = "A_FINALIZE_TIMER_START"; break; case A_FINALIZE_TIMER_STOP: actionAsText = "A_FINALIZE_TIMER_STOP"; break; case A_ELECTION_COUNT: actionAsText = "A_ELECTION_COUNT"; break; case A_ELECTION_VOTE: actionAsText = "A_ELECTION_VOTE"; break; case A_CL_JOIN_ANNOUNCE: actionAsText = "A_CL_JOIN_ANNOUNCE"; break; case A_CL_JOIN_REQUEST: actionAsText = "A_CL_JOIN_REQUEST"; break; case A_CL_JOIN_RESULT: actionAsText = "A_CL_JOIN_RESULT"; break; case A_DC_JOIN_OFFER_ALL: actionAsText = "A_DC_JOIN_OFFER_ALL"; break; case A_DC_JOIN_OFFER_ONE: actionAsText = "A_DC_JOIN_OFFER_ONE"; break; case A_DC_JOIN_PROCESS_REQ: actionAsText = "A_DC_JOIN_PROCESS_REQ"; break; case A_DC_JOIN_PROCESS_ACK: actionAsText = "A_DC_JOIN_PROCESS_ACK"; break; case A_DC_JOIN_FINALIZE: actionAsText = "A_DC_JOIN_FINALIZE"; break; case A_MSG_PROCESS: actionAsText = "A_MSG_PROCESS"; break; case A_MSG_ROUTE: actionAsText = "A_MSG_ROUTE"; break; case A_RECOVER: actionAsText = "A_RECOVER"; break; case A_DC_RELEASE: actionAsText = "A_DC_RELEASE"; break; case A_DC_RELEASED: actionAsText = "A_DC_RELEASED"; break; case A_DC_TAKEOVER: actionAsText = "A_DC_TAKEOVER"; break; case A_SHUTDOWN: actionAsText = "A_SHUTDOWN"; break; case A_SHUTDOWN_REQ: actionAsText = "A_SHUTDOWN_REQ"; break; case A_STOP: actionAsText = "A_STOP "; break; case A_EXIT_0: actionAsText = "A_EXIT_0"; break; case A_EXIT_1: actionAsText = "A_EXIT_1"; break; case A_CCM_CONNECT: actionAsText = "A_CCM_CONNECT"; break; case A_CCM_DISCONNECT: actionAsText = "A_CCM_DISCONNECT"; break; case A_CCM_EVENT: actionAsText = "A_CCM_EVENT"; break; case A_CCM_UPDATE_CACHE: actionAsText = "A_CCM_UPDATE_CACHE"; break; case A_CIB_BUMPGEN: actionAsText = "A_CIB_BUMPGEN"; break; case A_CIB_INVOKE: actionAsText = "A_CIB_INVOKE"; break; case O_CIB_RESTART: actionAsText = "O_CIB_RESTART"; break; case A_CIB_START: actionAsText = "A_CIB_START"; break; case A_CIB_STOP: actionAsText = "A_CIB_STOP"; break; case A_TE_INVOKE: actionAsText = "A_TE_INVOKE"; break; case O_TE_RESTART: actionAsText = "O_TE_RESTART"; break; case A_TE_START: actionAsText = "A_TE_START"; break; case A_TE_STOP: actionAsText = "A_TE_STOP"; break; case A_TE_CANCEL: actionAsText = "A_TE_CANCEL"; break; case A_PE_INVOKE: actionAsText = "A_PE_INVOKE"; break; case O_PE_RESTART: actionAsText = "O_PE_RESTART"; break; case A_PE_START: actionAsText = "A_PE_START"; break; case A_PE_STOP: actionAsText = "A_PE_STOP"; break; case A_NODE_BLOCK: actionAsText = "A_NODE_BLOCK"; break; case A_UPDATE_NODESTATUS: actionAsText = "A_UPDATE_NODESTATUS"; break; case A_LOG: actionAsText = "A_LOG "; break; case A_ERROR: actionAsText = "A_ERROR "; break; case A_WARN: actionAsText = "A_WARN "; break; } if(actionAsText == NULL) { crm_err("Action %.16llx is unknown", action); actionAsText = ""; } return actionAsText; } void fsa_dump_actions(long long action, const char *text) { + int log_level = LOG_DEV; + if(is_set(action, A_READCONFIG)) { - crm_debug("Action %.16llx (A_READCONFIG) %s", A_READCONFIG, text); + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_READCONFIG) %s", A_READCONFIG, text); } if(is_set(action, A_STARTUP)) { - crm_debug("Action %.16llx (A_STARTUP) %s", A_STARTUP, text); + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_STARTUP) %s", A_STARTUP, text); } if(is_set(action, A_STARTED)) { - crm_debug("Action %.16llx (A_STARTED) %s", A_STARTED, text); + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_STARTED) %s", A_STARTED, text); } if(is_set(action, A_HA_CONNECT)) { - crm_debug("Action %.16llx (A_CONNECT) %s", A_HA_CONNECT, text); + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_CONNECT) %s", A_HA_CONNECT, text); } if(is_set(action, A_HA_DISCONNECT)) { - crm_debug("Action %.16llx (A_DISCONNECT) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_DISCONNECT) %s", A_HA_DISCONNECT, text); } if(is_set(action, A_LRM_CONNECT)) { - crm_debug("Action %.16llx (A_LRM_CONNECT) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_LRM_CONNECT) %s", A_LRM_CONNECT, text); } if(is_set(action, A_LRM_EVENT)) { - crm_debug("Action %.16llx (A_LRM_EVENT) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_LRM_EVENT) %s", A_LRM_EVENT, text); } if(is_set(action, A_LRM_INVOKE)) { - crm_debug("Action %.16llx (A_LRM_INVOKE) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_LRM_INVOKE) %s", A_LRM_INVOKE, text); } if(is_set(action, A_LRM_DISCONNECT)) { - crm_debug("Action %.16llx (A_LRM_DISCONNECT) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_LRM_DISCONNECT) %s", A_LRM_DISCONNECT, text); } if(is_set(action, A_DC_TIMER_STOP)) { - crm_debug("Action %.16llx (A_DC_TIMER_STOP) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_DC_TIMER_STOP) %s", A_DC_TIMER_STOP, text); } if(is_set(action, A_DC_TIMER_START)) { - crm_debug("Action %.16llx (A_DC_TIMER_START) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_DC_TIMER_START) %s", A_DC_TIMER_START, text); } if(is_set(action, A_INTEGRATE_TIMER_START)) { - crm_debug("Action %.16llx (A_INTEGRATE_TIMER_START) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_INTEGRATE_TIMER_START) %s", A_INTEGRATE_TIMER_START, text); } if(is_set(action, A_INTEGRATE_TIMER_STOP)) { - crm_debug("Action %.16llx (A_INTEGRATE_TIMER_STOP) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_INTEGRATE_TIMER_STOP) %s", A_INTEGRATE_TIMER_STOP, text); } if(is_set(action, A_FINALIZE_TIMER_START)) { - crm_debug("Action %.16llx (A_FINALIZE_TIMER_START) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_FINALIZE_TIMER_START) %s", A_FINALIZE_TIMER_START, text); } if(is_set(action, A_FINALIZE_TIMER_STOP)) { - crm_debug("Action %.16llx (A_FINALIZE_TIMER_STOP) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_FINALIZE_TIMER_STOP) %s", A_FINALIZE_TIMER_STOP, text); } if(is_set(action, A_ELECTION_COUNT)) { - crm_debug("Action %.16llx (A_ELECTION_COUNT) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_ELECTION_COUNT) %s", A_ELECTION_COUNT, text); } if(is_set(action, A_ELECTION_VOTE)) { - crm_debug("Action %.16llx (A_ELECTION_VOTE) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_ELECTION_VOTE) %s", A_ELECTION_VOTE, text); } if(is_set(action, A_CL_JOIN_ANNOUNCE)) { - crm_debug("Action %.16llx (A_CL_JOIN_ANNOUNCE) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_CL_JOIN_ANNOUNCE) %s", A_CL_JOIN_ANNOUNCE, text); } if(is_set(action, A_CL_JOIN_REQUEST)) { - crm_debug("Action %.16llx (A_CL_JOIN_REQUEST) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_CL_JOIN_REQUEST) %s", A_CL_JOIN_REQUEST, text); } if(is_set(action, A_CL_JOIN_RESULT)) { - crm_debug("Action %.16llx (A_CL_JOIN_RESULT) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_CL_JOIN_RESULT) %s", A_CL_JOIN_RESULT, text); } if(is_set(action, A_DC_JOIN_OFFER_ALL)) { - crm_debug("Action %.16llx (A_DC_JOIN_OFFER_ALL) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_DC_JOIN_OFFER_ALL) %s", A_DC_JOIN_OFFER_ALL, text); } if(is_set(action, A_DC_JOIN_OFFER_ONE)) { - crm_debug("Action %.16llx (A_DC_JOIN_OFFER_ONE) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_DC_JOIN_OFFER_ONE) %s", A_DC_JOIN_OFFER_ONE, text); } if(is_set(action, A_DC_JOIN_PROCESS_REQ)) { - crm_debug("Action %.16llx (A_DC_JOIN_PROCESS_REQ) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_DC_JOIN_PROCESS_REQ) %s", A_DC_JOIN_PROCESS_REQ, text); } if(is_set(action, A_DC_JOIN_PROCESS_ACK)) { - crm_debug("Action %.16llx (A_DC_JOIN_PROCESS_ACK) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_DC_JOIN_PROCESS_ACK) %s", A_DC_JOIN_PROCESS_ACK, text); } if(is_set(action, A_DC_JOIN_FINALIZE)) { - crm_debug("Action %.16llx (A_DC_JOIN_FINALIZE) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_DC_JOIN_FINALIZE) %s", A_DC_JOIN_FINALIZE, text); } if(is_set(action, A_MSG_PROCESS)) { - crm_debug("Action %.16llx (A_MSG_PROCESS) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_MSG_PROCESS) %s", A_MSG_PROCESS, text); } if(is_set(action, A_MSG_ROUTE)) { - crm_debug("Action %.16llx (A_MSG_ROUTE) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_MSG_ROUTE) %s", A_MSG_ROUTE, text); } if(is_set(action, A_RECOVER)) { - crm_debug("Action %.16llx (A_RECOVER) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_RECOVER) %s", A_RECOVER, text); } if(is_set(action, A_DC_RELEASE)) { - crm_debug("Action %.16llx (A_DC_RELEASE) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_DC_RELEASE) %s", A_DC_RELEASE, text); } if(is_set(action, A_DC_RELEASED)) { - crm_debug("Action %.16llx (A_DC_RELEASED) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_DC_RELEASED) %s", A_DC_RELEASED, text); } if(is_set(action, A_DC_TAKEOVER)) { - crm_debug("Action %.16llx (A_DC_TAKEOVER) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_DC_TAKEOVER) %s", A_DC_TAKEOVER, text); } if(is_set(action, A_SHUTDOWN)) { - crm_debug("Action %.16llx (A_SHUTDOWN) %s", A_SHUTDOWN, text); + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_SHUTDOWN) %s", A_SHUTDOWN, text); } if(is_set(action, A_SHUTDOWN_REQ)) { - crm_debug("Action %.16llx (A_SHUTDOWN_REQ) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_SHUTDOWN_REQ) %s", A_SHUTDOWN_REQ, text); } if(is_set(action, A_STOP)) { - crm_debug("Action %.16llx (A_STOP ) %s", A_STOP , text); + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_STOP ) %s", A_STOP , text); } if(is_set(action, A_EXIT_0)) { - crm_debug("Action %.16llx (A_EXIT_0) %s", A_EXIT_0, text); + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_EXIT_0) %s", A_EXIT_0, text); } if(is_set(action, A_EXIT_1)) { - crm_debug("Action %.16llx (A_EXIT_1) %s", A_EXIT_1, text); + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_EXIT_1) %s", A_EXIT_1, text); } if(is_set(action, A_CCM_CONNECT)) { - crm_debug("Action %.16llx (A_CCM_CONNECT) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_CCM_CONNECT) %s", A_CCM_CONNECT, text); } if(is_set(action, A_CCM_DISCONNECT)) { - crm_debug("Action %.16llx (A_CCM_DISCONNECT) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_CCM_DISCONNECT) %s", A_CCM_DISCONNECT, text); } if(is_set(action, A_CCM_EVENT)) { - crm_debug("Action %.16llx (A_CCM_EVENT) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_CCM_EVENT) %s", A_CCM_EVENT, text); } if(is_set(action, A_CCM_UPDATE_CACHE)) { - crm_debug("Action %.16llx (A_CCM_UPDATE_CACHE) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_CCM_UPDATE_CACHE) %s", A_CCM_UPDATE_CACHE, text); } if(is_set(action, A_CIB_BUMPGEN)) { - crm_debug("Action %.16llx (A_CIB_BUMPGEN) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_CIB_BUMPGEN) %s", A_CIB_BUMPGEN, text); } if(is_set(action, A_CIB_INVOKE)) { - crm_debug("Action %.16llx (A_CIB_INVOKE) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_CIB_INVOKE) %s", A_CIB_INVOKE, text); } if(is_set(action, A_CIB_START)) { - crm_debug("Action %.16llx (A_CIB_START) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_CIB_START) %s", A_CIB_START, text); } if(is_set(action, A_CIB_STOP)) { - crm_debug("Action %.16llx (A_CIB_STOP) %s", A_CIB_STOP, text); + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_CIB_STOP) %s", A_CIB_STOP, text); } if(is_set(action, A_TE_INVOKE)) { - crm_debug("Action %.16llx (A_TE_INVOKE) %s", A_TE_INVOKE, text); + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_TE_INVOKE) %s", A_TE_INVOKE, text); } if(is_set(action, A_TE_START)) { - crm_debug("Action %.16llx (A_TE_START) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_TE_START) %s", A_TE_START, text); } if(is_set(action, A_TE_STOP)) { - crm_debug("Action %.16llx (A_TE_STOP) %s", A_TE_STOP, text); + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_TE_STOP) %s", A_TE_STOP, text); } if(is_set(action, A_TE_CANCEL)) { - crm_debug("Action %.16llx (A_TE_CANCEL) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_TE_CANCEL) %s", A_TE_CANCEL, text); } if(is_set(action, A_PE_INVOKE)) { - crm_debug("Action %.16llx (A_PE_INVOKE) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_PE_INVOKE) %s", A_PE_INVOKE, text); } if(is_set(action, A_PE_START)) { - crm_debug("Action %.16llx (A_PE_START) %s", A_PE_START, text); + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_PE_START) %s", A_PE_START, text); } if(is_set(action, A_PE_STOP)) { - crm_debug("Action %.16llx (A_PE_STOP) %s", A_PE_STOP, text); + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_PE_STOP) %s", A_PE_STOP, text); } if(is_set(action, A_NODE_BLOCK)) { - crm_debug("Action %.16llx (A_NODE_BLOCK) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_NODE_BLOCK) %s", A_NODE_BLOCK, text); } if(is_set(action, A_UPDATE_NODESTATUS)) { - crm_debug("Action %.16llx (A_UPDATE_NODESTATUS) %s", + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_UPDATE_NODESTATUS) %s", A_UPDATE_NODESTATUS, text); } if(is_set(action, A_LOG)) { - crm_debug("Action %.16llx (A_LOG ) %s", A_LOG, text); + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_LOG ) %s", A_LOG, text); } if(is_set(action, A_ERROR)) { - crm_debug("Action %.16llx (A_ERROR ) %s", A_ERROR, text); + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_ERROR ) %s", A_ERROR, text); } if(is_set(action, A_WARN)) { - crm_debug("Action %.16llx (A_WARN ) %s", A_WARN, text); + do_crm_log(log_level, __FUNCTION__, NULL, + "Action %.16llx (A_WARN ) %s", A_WARN, text); } } void create_node_entry(const char *uuid, const char *uname, const char *type) { /* make sure a node entry exists for the new node * * this will add anyone except the first ever node in the cluster * since it will also be the DC which doesnt go through the * join process (with itself). We can include a special case * later if desired. */ crm_data_t *tmp1 = create_xml_node(NULL, XML_CIB_TAG_NODE); - crm_debug("Creating node entry for %s", uname); + crm_devel("Creating node entry for %s", uname); set_uuid(fsa_cluster_conn, tmp1, XML_ATTR_UUID, uname); set_xml_property_copy(tmp1, XML_ATTR_UNAME, uname); set_xml_property_copy(tmp1, XML_ATTR_TYPE, type); update_local_cib(create_cib_fragment(tmp1, NULL)); free_xml(tmp1); } struct crmd_ccm_data_s * copy_ccm_data(const struct crmd_ccm_data_s *ccm_input) { const oc_ev_membership_t *oc_in = (const oc_ev_membership_t *)ccm_input->oc; struct crmd_ccm_data_s *ccm_input_copy = NULL; crm_malloc(ccm_input_copy, sizeof(struct crmd_ccm_data_s)); ccm_input_copy->oc = copy_ccm_oc_data(oc_in); ccm_input_copy->event = ccm_input->event; return ccm_input_copy; } oc_ev_membership_t * copy_ccm_oc_data(const oc_ev_membership_t *oc_in) { int lpc = 0; int size = 0; int offset = 0; int num_nodes = 0; oc_ev_membership_t *oc_copy = NULL; if(oc_in->m_n_member > 0 && num_nodes < oc_in->m_n_member + oc_in->m_memb_idx) { num_nodes = oc_in->m_n_member + oc_in->m_memb_idx; crm_devel("Updated ccm nodes to %d - 1", num_nodes); } if(oc_in->m_n_in > 0 && num_nodes < oc_in->m_n_in + oc_in->m_in_idx) { num_nodes = oc_in->m_n_in + oc_in->m_in_idx; crm_devel("Updated ccm nodes to %d - 2", num_nodes); } if(oc_in->m_n_out > 0 && num_nodes < oc_in->m_n_out + oc_in->m_out_idx) { num_nodes = oc_in->m_n_out + oc_in->m_out_idx; crm_devel("Updated ccm nodes to %d - 3", num_nodes); } /* why 2*?? * ccm code does it like this so i guess its right... */ size = sizeof(oc_ev_membership_t) + sizeof(int) + 2*num_nodes*sizeof(oc_node_t); crm_devel("Copying %d ccm nodes", num_nodes); crm_malloc(oc_copy, size); oc_copy->m_instance = oc_in->m_instance; oc_copy->m_n_member = oc_in->m_n_member; oc_copy->m_memb_idx = oc_in->m_memb_idx; oc_copy->m_n_out = oc_in->m_n_out; oc_copy->m_out_idx = oc_in->m_out_idx; oc_copy->m_n_in = oc_in->m_n_in; oc_copy->m_in_idx = oc_in->m_in_idx; - crm_debug("instance=%d, nodes=%d (idx=%d), new=%d (idx=%d), lost=%d (idx=%d)", + crm_devel("instance=%d, nodes=%d (idx=%d), new=%d (idx=%d), lost=%d (idx=%d)", oc_in->m_instance, oc_in->m_n_member, oc_in->m_memb_idx, oc_in->m_n_in, oc_in->m_in_idx, oc_in->m_n_out, oc_in->m_out_idx); offset = oc_in->m_memb_idx; for(lpc = 0; lpc < oc_in->m_n_member; lpc++) { oc_node_t a_node = oc_in->m_array[lpc+offset]; oc_node_t *a_node_copy = &(oc_copy->m_array[lpc+offset]); crm_devel("Copying ccm member node %d", lpc); copy_ccm_node(a_node, a_node_copy); } offset = oc_in->m_in_idx; for(lpc = 0; lpc < oc_in->m_n_in; lpc++) { oc_node_t a_node = oc_in->m_array[lpc+offset]; oc_node_t *a_node_copy = &(oc_copy->m_array[lpc+offset]); crm_devel("Copying ccm new node %d", lpc); copy_ccm_node(a_node, a_node_copy); } offset = oc_in->m_out_idx; for(lpc = 0; lpc < oc_in->m_n_out; lpc++) { oc_node_t a_node = oc_in->m_array[lpc+offset]; oc_node_t *a_node_copy = &(oc_copy->m_array[lpc+offset]); crm_devel("Copying ccm lost node %d", lpc); copy_ccm_node(a_node, a_node_copy); } return oc_copy; } void copy_ccm_node(oc_node_t a_node, oc_node_t *a_node_copy) { crm_devel("Copying ccm node: id=%d, born=%d, uname=%s", a_node.node_id, a_node.node_born_on, a_node.node_uname); a_node_copy->node_id = a_node.node_id; a_node_copy->node_born_on = a_node.node_born_on; a_node_copy->node_uname = NULL; if(a_node.node_uname != NULL) { a_node_copy->node_uname = crm_strdup(a_node.node_uname); } else { crm_err("Node Id %d had a NULL uname!", a_node.node_id); } crm_devel("Copied ccm node: id=%d, born=%d, uname=%s", a_node_copy->node_id, a_node_copy->node_born_on, a_node_copy->node_uname); } lrm_op_t * copy_lrm_op(const lrm_op_t *op) { lrm_op_t *op_copy = NULL; crm_malloc(op_copy, sizeof(lrm_op_t)); op_copy->op_type = crm_strdup(op->op_type); /* input fields */ /* GHashTable* params; */ op_copy->params = NULL; op_copy->timeout = op->timeout; op_copy->interval = op->interval; op_copy->target_rc = op->target_rc; /* in the CRM, this is always an int */ if(op->user_data != NULL) { op_copy->user_data = crm_strdup(op->user_data); } /* output fields */ op_copy->op_status = op->op_status; op_copy->rc = op->rc; op_copy->call_id = op->call_id; op_copy->output = NULL; if(op->output!= NULL) { op_copy->output = crm_strdup(op->output); } op_copy->rsc_id = crm_strdup(op->rsc_id); op_copy->app_name = crm_strdup(op->app_name); /*please notice the client needs release the memory of rsc.*/ CRM_DEV_ASSERT(op->rsc != NULL); op_copy->rsc = copy_lrm_rsc(op->rsc); if(op_copy->rsc == NULL) { crm_err("Op callback for %s did not contain a resource", crm_str(op_copy->rsc_id)); } else { - crm_debug("Copied op callback for %s",crm_str(op_copy->rsc_id)); + crm_devel("Copied op callback for %s",crm_str(op_copy->rsc_id)); } return op_copy; } lrm_rsc_t * copy_lrm_rsc(const lrm_rsc_t *rsc) { lrm_rsc_t *rsc_copy = NULL; if(rsc == NULL) { return NULL; } crm_malloc(rsc_copy, sizeof(lrm_rsc_t)); rsc_copy->id = crm_strdup(rsc->id); rsc_copy->type = crm_strdup(rsc->type); rsc_copy->class = NULL; rsc_copy->provider = NULL; if(rsc->class != NULL) { rsc_copy->class = crm_strdup(rsc->class); } if(rsc->provider != NULL) { rsc_copy->provider = crm_strdup(rsc->provider); } /* GHashTable* params; */ rsc_copy->params = NULL; rsc_copy->ops = NULL; return rsc_copy; } crm_data_t* create_node_state(const char *uuid, const char *uname, const char *ha_state, const char *ccm_state, const char *crmd_state, const char *join_state, const char *exp_state) { crm_data_t *node_state = create_xml_node(NULL, XML_CIB_TAG_STATE); - crm_debug("Creating node state entry for %s", uname); + crm_devel("Creating node state entry for %s", uname); set_uuid(fsa_cluster_conn, node_state, XML_ATTR_UUID, uname); set_xml_property_copy(node_state, XML_ATTR_UNAME, uname); set_xml_property_copy( node_state, XML_CIB_ATTR_HASTATE, ha_state); set_xml_property_copy( node_state, XML_CIB_ATTR_INCCM, ccm_state); set_xml_property_copy( node_state, XML_CIB_ATTR_CRMDSTATE, crmd_state); set_xml_property_copy( node_state, XML_CIB_ATTR_JOINSTATE, join_state); set_xml_property_copy( node_state, XML_CIB_ATTR_EXPSTATE, exp_state); crm_xml_devel(node_state, "created"); return node_state; } diff --git a/crm/pengine/color.c b/crm/pengine/color.c index d66722b811..a38b68584a 100644 --- a/crm/pengine/color.c +++ b/crm/pengine/color.c @@ -1,136 +1,136 @@ -/* $Id: color.c,v 1.23 2005/01/26 13:30:59 andrew Exp $ */ +/* $Id: color.c,v 1.24 2005/02/19 18:11:04 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 color_t *no_color = NULL; color_t *add_color(resource_t *rh_resource, color_t *color); gboolean apply_placement_constraints(GListPtr constraints, GListPtr nodes) { crm_verbose("Applying constraints..."); slist_iter( cons, rsc_to_node_t, constraints, lpc, cons->rsc_lh->fns->rsc_location(cons->rsc_lh, cons); ); return TRUE; } gboolean apply_agent_constraints(GListPtr resources) { slist_iter( rsc, resource_t, resources, lpc, rsc->fns->agent_constraints(rsc); ); crm_trace("Finished applying RA restrictions"); return TRUE; } color_t * add_color(resource_t *resource, color_t *color) { color_t *local_color = NULL; if(color == NULL) { crm_err("Cannot add NULL color"); return NULL; } local_color = find_color(resource->candidate_colors, color); if(local_color == NULL) { - crm_debug("Adding color %d", color->id); + crm_devel("Adding color %d", color->id); local_color = copy_color(color); resource->candidate_colors = g_list_append(resource->candidate_colors, local_color); } else { - crm_debug("Color %d already present", color->id); + crm_devel("Color %d already present", color->id); } return local_color; } void color_resource(resource_t *rsc, GListPtr *colors, GListPtr resources) { - crm_debug_action(print_resource("Coloring", rsc, FALSE)); + crm_devel_action(print_resource("Coloring", rsc, FALSE)); if(rsc->provisional == FALSE) { /* already processed this resource */ return; } rsc->rsc_cons = g_list_sort( rsc->rsc_cons, sort_cons_strength); - crm_debug_action( + crm_devel_action( print_resource("Pre-processing", rsc, FALSE)); /*------ Pre-processing */ slist_iter( constraint, rsc_dependancy_t, rsc->rsc_cons, lpc, - crm_debug_action( + crm_devel_action( print_rsc_dependancy( "Pre-Processing constraint", constraint,FALSE)); rsc->fns->rsc_dependancy_lh(constraint); ); /* avoid looping through lists when we know this resource * cant be started */ rsc->fns->color(rsc, colors); - crm_debug_action( + crm_devel_action( print_resource("Post-processing", rsc, TRUE)); /*------ Post-processing */ slist_iter( constraint, rsc_dependancy_t, rsc->rsc_cons, lpc, - crm_debug_action( + crm_devel_action( print_rsc_dependancy( "Post-Processing constraint",constraint,FALSE)); rsc->fns->rsc_dependancy_lh(constraint); ); - crm_debug_action(print_resource("Colored", rsc, TRUE)); + crm_devel_action(print_resource("Colored", rsc, TRUE)); } diff --git a/crm/pengine/complex.c b/crm/pengine/complex.c index b6d34c6207..4343bf33f2 100644 --- a/crm/pengine/complex.c +++ b/crm/pengine/complex.c @@ -1,328 +1,328 @@ -/* $Id: complex.c,v 1.13 2005/02/14 22:36:12 andrew Exp $ */ +/* $Id: complex.c,v 1.14 2005/02/19 18:11:04 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 gboolean update_node_weight(rsc_to_node_t *cons,const char *id,GListPtr nodes); gboolean is_active(rsc_to_node_t *cons); gboolean constraint_violated( resource_t *rsc_lh, resource_t *rsc_rh, rsc_dependancy_t *constraint); void order_actions(action_t *lh, action_t *rh, order_constraint_t *order); gboolean has_agent(node_t *a_node, lrm_agent_t *an_agent); resource_object_functions_t resource_class_functions[] = { { native_unpack, native_find_child, native_num_allowed_nodes, native_color, native_create_actions, native_internal_constraints, native_agent_constraints, native_rsc_dependancy_lh, native_rsc_dependancy_rh, native_rsc_order_lh, native_rsc_order_rh, native_rsc_location, native_expand, native_dump, native_free }, { group_unpack, group_find_child, group_num_allowed_nodes, group_color, group_create_actions, group_internal_constraints, group_agent_constraints, group_rsc_dependancy_lh, group_rsc_dependancy_rh, group_rsc_order_lh, group_rsc_order_rh, group_rsc_location, group_expand, group_dump, group_free }, { incarnation_unpack, incarnation_find_child, incarnation_num_allowed_nodes, incarnation_color, incarnation_create_actions, incarnation_internal_constraints, incarnation_agent_constraints, incarnation_rsc_dependancy_lh, incarnation_rsc_dependancy_rh, incarnation_rsc_order_lh, incarnation_rsc_order_rh, incarnation_rsc_location, incarnation_expand, incarnation_dump, incarnation_free } }; /* resource_object_functions_t resource_variants[] = resource_class_functions; */ int get_resource_type(const char *name) { if(safe_str_eq(name, "resource")) { return pe_native; } else if(safe_str_eq(name, "resource_group")) { return pe_group; } else if(safe_str_eq(name, XML_RSC_ATTR_INCARNATION)) { return pe_incarnation; } return pe_unknown; } gboolean is_active(rsc_to_node_t *cons) { /* todo: check constraint lifetime */ return TRUE; } gboolean common_unpack(crm_data_t * xml_obj, resource_t **rsc) { const char *id = crm_element_value(xml_obj, XML_ATTR_ID); const char *stopfail = crm_element_value(xml_obj, XML_RSC_ATTR_STOPFAIL); const char *restart = crm_element_value(xml_obj, XML_RSC_ATTR_RESTART); const char *def_timeout = crm_element_value(xml_obj, XML_ATTR_TIMEOUT); const char *start_timeout = crm_element_value(xml_obj, XML_RSC_ATTR_START_TIMEOUT); const char *stop_timeout = crm_element_value(xml_obj, XML_RSC_ATTR_STOP_TIMEOUT); const char *priority = crm_element_value(xml_obj, XML_CIB_ATTR_PRIORITY); crm_xml_verbose(xml_obj, "Processing resource input..."); if(id == NULL) { crm_err("Must specify id tag in "); return FALSE; } else if(rsc == NULL) { crm_err("Nowhere to unpack resource into"); return FALSE; } crm_malloc(*rsc, sizeof(resource_t)); if(*rsc == NULL) { return FALSE; } (*rsc)->id = id; (*rsc)->xml = xml_obj; (*rsc)->variant = get_resource_type(crm_element_name(xml_obj)); if((*rsc)->variant == pe_unknown) { crm_err("Unknown resource type: %s", crm_element_name(xml_obj)); crm_free(*rsc); return FALSE; } (*rsc)->fns = &resource_class_functions[(*rsc)->variant]; crm_verbose("Unpacking resource..."); (*rsc)->priority = atoi(priority?priority:"0"); (*rsc)->effective_priority = (*rsc)->priority; (*rsc)->recovery_type = recovery_stop_start; (*rsc)->runnable = TRUE; (*rsc)->provisional = TRUE; (*rsc)->starting = FALSE; (*rsc)->stopping = FALSE; (*rsc)->start_timeout = start_timeout; (*rsc)->stop_timeout = stop_timeout; (*rsc)->def_timeout = def_timeout; (*rsc)->candidate_colors = NULL; (*rsc)->rsc_cons = NULL; (*rsc)->actions = NULL; (*rsc)->extra_attrs = create_xml_node(NULL, "extra"); if(safe_str_eq(stopfail, "ignore")) { (*rsc)->stopfail_type = pesf_ignore; } else if(safe_str_eq(stopfail, XML_CIB_ATTR_STONITH)) { (*rsc)->stopfail_type = pesf_stonith; } else { (*rsc)->stopfail_type = pesf_block; } if(safe_str_eq(restart, "restart")) { (*rsc)->restart_type = pe_restart_restart; } else if(safe_str_eq(restart, "recover")) { (*rsc)->restart_type = pe_restart_recover; } else { (*rsc)->restart_type = pe_restart_ignore; } (*rsc)->fns->unpack(*rsc); return TRUE; } void order_actions(action_t *lh_action, action_t *rh_action, order_constraint_t *order) { action_wrapper_t *wrapper = NULL; GListPtr list = NULL; crm_verbose("%d Processing %d -> %d", order->id, lh_action->id, rh_action->id); - crm_debug_action( + crm_devel_action( print_action("LH (order_actions)", lh_action, FALSE)); - crm_debug_action( + crm_devel_action( print_action("RH (order_actions)", rh_action, FALSE)); crm_malloc(wrapper, sizeof(action_wrapper_t)); if(wrapper != NULL) { wrapper->action = rh_action; wrapper->strength = order->strength; list = lh_action->actions_after; list = g_list_append(list, wrapper); lh_action->actions_after = list; } crm_malloc(wrapper, sizeof(action_wrapper_t)); if(wrapper != NULL) { wrapper->action = lh_action; wrapper->strength = order->strength; list = rh_action->actions_before; list = g_list_append(list, wrapper); rh_action->actions_before = list; } } void common_dump(resource_t *rsc, const char *pre_text, gboolean details) { - crm_debug("%s%s%s%sResource %s: (variant=%s, priority=%f)", + crm_devel("%s%s%s%sResource %s: (variant=%s, priority=%f)", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", rsc->provisional?"Provisional ":"", rsc->runnable?"":"(Non-Startable) ", rsc->id, crm_element_name(rsc->xml), (double)rsc->priority); } void common_free(resource_t *rsc) { if(rsc == NULL) { return; } crm_trace("Freeing %s", rsc->id); while(rsc->rsc_cons) { pe_free_rsc_dependancy( (rsc_dependancy_t*)rsc->rsc_cons->data); rsc->rsc_cons = rsc->rsc_cons->next; } crm_trace("Freeing constraint list"); if(rsc->rsc_cons != NULL) { g_list_free(rsc->rsc_cons); } crm_trace("Freeing opaque data"); crm_free(rsc->variant_opaque); crm_trace("Freeing resource"); crm_free(rsc); crm_trace("Resource freed"); } void common_agent_constraints( GListPtr node_list, lrm_agent_t *agent, const char *id) { #if 0 slist_iter( node, node_t, node_list, lpc, crm_trace("Checking if %s supports %s/%s (%s)", node->details->uname, agent->class, agent->type, agent->version); if(has_agent(node, agent) == FALSE) { /* remove node from contention */ crm_trace("Marking node %s unavailable for %s", node->details->uname, id); node->weight = -1.0; node->fixed = TRUE; } ); #endif } gboolean has_agent(node_t *a_node, lrm_agent_t *an_agent) { if(a_node == NULL || an_agent == NULL || an_agent->type == NULL) { crm_warn("Invalid inputs"); return FALSE; } crm_devel("Checking %d agents on %s", g_list_length(a_node->details->agents), a_node->details->uname); slist_iter( agent, lrm_agent_t, a_node->details->agents, lpc, crm_trace("Checking against %s/%s (%s)", agent->class, agent->type, agent->version); if(safe_str_eq(an_agent->type, agent->type)){ if(an_agent->class == NULL) { return TRUE; } else if(safe_str_eq(an_agent->class, agent->class)) { if(compare_version( an_agent->version, agent->version) <= 0) { return TRUE; } } } ); crm_verbose("%s doesnt support version %s of %s/%s", a_node->details->uname, an_agent->version, an_agent->class, an_agent->type); return FALSE; } diff --git a/crm/pengine/graph.c b/crm/pengine/graph.c index 9f3943ad49..13d257e6f8 100644 --- a/crm/pengine/graph.c +++ b/crm/pengine/graph.c @@ -1,352 +1,352 @@ -/* $Id: graph.c,v 1.26 2005/01/26 13:31:00 andrew Exp $ */ +/* $Id: graph.c,v 1.27 2005/02/19 18:11:04 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 gboolean update_action(action_t *action); gboolean update_action_states(GListPtr actions) { slist_iter( action, action_t, actions, lpc, update_action(action); ); return TRUE; } gboolean update_action(action_t *action) { gboolean change = FALSE; if(action->optional && action->runnable) { return FALSE; } slist_iter( other, action_wrapper_t, action->actions_after, lpc, if(action->runnable == FALSE && action->optional == FALSE) { if(other->action->runnable == FALSE) { continue; } else if (other->strength == pecs_must) { change = TRUE; other->action->runnable =FALSE; - crm_debug_action( + crm_devel_action( print_action("Marking unrunnable", other->action, FALSE); print_action("Reason", action, FALSE); ); } } if(action->optional == FALSE && other->action->optional) { switch(action->rsc->restart_type) { case pe_restart_ignore: break; case pe_restart_recover: crm_err("Recover after dependancy " "restart not supported... " "forcing a restart"); /* keep going */ case pe_restart_restart: change = TRUE; other->action->optional = FALSE; - crm_debug_action( + crm_devel_action( print_action("Marking manditory", other->action, FALSE)); } } if(change) { update_action(other->action); } ); return change; } gboolean shutdown_constraints( node_t *node, action_t *shutdown_op, GListPtr *ordering_constraints) { /* add the stop to the before lists so it counts as a pre-req * for the shutdown */ slist_iter( rsc, resource_t, node->details->running_rsc, lpc, order_new(rsc, stop_rsc, NULL, NULL, shutdown_crm, shutdown_op, pecs_must, ordering_constraints); ); return TRUE; } gboolean stonith_constraints(node_t *node, action_t *stonith_op, action_t *shutdown_op, GListPtr *ordering_constraints) { GListPtr stop_actions = NULL; if(shutdown_op != NULL) { /* shutdown before stonith */ /* add the shutdown OP to the before lists so it counts as a pre-req */ - crm_debug("Adding shutdown (%d) as an input to stonith (%d)", + crm_devel("Adding shutdown (%d) as an input to stonith (%d)", shutdown_op->id, stonith_op->id); order_new(NULL, shutdown_crm, shutdown_op, NULL, stonith_node, stonith_op, pecs_must, ordering_constraints); } /* add the stonith OP to the before lists so it counts as a pre-req */ slist_iter( rsc, resource_t, node->details->running_rsc, lpc, /* make use of timeouts in the TE for cases such * as this. * ie. the node may be cactus and unable to receive the * stop let alone reply with failed. */ stop_actions = find_actions(rsc->actions, stop_rsc, node); slist_iter( action, action_t, stop_actions, lpc2, action->discard = TRUE; ); if(rsc->stopfail_type == pesf_block) { /* depend on the stop action which will fail */ crm_warn("SHARED RESOURCE %s WILL REMAIN BLOCKED" " UNTIL CLEANED UP MANUALLY ON NODE %s", rsc->id, node->details->uname); continue; } else if(rsc->stopfail_type == pesf_ignore) { /* nothing to do here */ crm_warn("SHARED RESOURCE %s IS NOT PROTECTED", rsc->id); continue; } /* case pesf_stonith: */ /* remedial action: * shutdown (so all other resources are * stopped gracefully) and then STONITH node */ if(stonith_enabled == FALSE) { /* depend on an action that will never complete */ crm_err("STONITH is not enabled in this" " cluster but is required for " "resource %s after a failed stop", rsc->id); } - crm_debug("Adding stonith (%d) as an input to start", + crm_devel("Adding stonith (%d) as an input to start", stonith_op->id); /* stonith before start */ order_new(NULL, stonith_node, stonith_op, rsc, start_rsc, NULL, pecs_must, ordering_constraints); /* a pointless optimization? probably */ /* if(shutdown_op != NULL) { */ /* /\* the next rule is implied *\/ */ /* continue; */ /* } */ /* stop before stonith */ order_new(rsc, stop_rsc, NULL, NULL, stonith_node, stonith_op, pecs_must, ordering_constraints); ); return TRUE; } crm_data_t * action2xml(action_t *action, gboolean as_input) { crm_data_t * action_xml = NULL; if(action == NULL) { return NULL; } - crm_debug("Dumping action%d as XML", action->id); + crm_devel("Dumping action%d as XML", action->id); switch(action->task) { case stonith_node: case shutdown_crm: action_xml = create_xml_node(NULL, XML_GRAPH_TAG_CRM_EVENT); set_xml_property_copy( action_xml, XML_ATTR_ID, crm_itoa(action->id)); set_xml_property_copy(action_xml, XML_LRM_ATTR_TASK, task2text(action->task)); break; default: if(action->pseudo) { action_xml = create_xml_node(NULL,XML_GRAPH_TAG_PSEUDO_EVENT); } else { action_xml = create_xml_node(NULL, XML_GRAPH_TAG_RSC_OP); } if(!as_input) { add_node_copy( action_xml, safe_val3(NULL, action, rsc, xml)); } set_xml_property_copy( action_xml, XML_ATTR_ID, crm_itoa(action->id)); set_xml_property_copy( action_xml, XML_LRM_ATTR_RSCID, safe_val3("__no_rsc__", action, rsc, id)); set_xml_property_copy(action_xml, XML_LRM_ATTR_TASK, task2text(action->task)); break; } if(action->task != stonith_node && (action->pseudo == FALSE || action->node != NULL)) { set_xml_property_copy( action_xml, XML_LRM_ATTR_TARGET, safe_val4("__no_node__", action, node, details,uname)); set_xml_property_copy( action_xml, XML_LRM_ATTR_TARGET_UUID, safe_val4("__no_uuid__", action, node, details, id)); } set_xml_property_copy( action_xml, "allow_fail", action->failure_is_fatal?XML_BOOLEAN_FALSE:XML_BOOLEAN_TRUE); set_xml_property_copy( action_xml, XML_ATTR_TIMEOUT, action->timeout); if(as_input) { return action_xml; } - crm_xml_debug(action->extra_attrs, "copying in extra attributes"); + crm_xml_devel(action->extra_attrs, "copying in extra attributes"); if(action->extra_attrs) { copy_in_properties(action->args, action->extra_attrs); } add_node_copy(action_xml, action->args); return action_xml; } void graph_element_from_action(action_t *action, crm_data_t * *graph) { char *syn_id = NULL; crm_data_t * syn = NULL; crm_data_t * set = NULL; crm_data_t * in = NULL; crm_data_t * input = NULL; crm_data_t * xml_action = NULL; if(action == NULL) { crm_err("Cannot dump NULL action"); return; } else if(action->optional) { crm_trace("action %d was optional", action->id); return; } else if(action->runnable == FALSE) { crm_trace("action %d was not runnable", action->id); return; } else if(action->dumped) { crm_trace("action %d was already dumped", action->id); return; } else if(action->discard) { crm_trace("action %d was discarded", action->id); return; } action->dumped = TRUE; syn = create_xml_node(*graph, "synapse"); set = create_xml_node(syn, "action_set"); in = create_xml_node(syn, "inputs"); syn_id = crm_itoa(num_synapse++); set_xml_property_copy(syn, XML_ATTR_ID, syn_id); crm_free(syn_id); xml_action = action2xml(action, FALSE); add_node_copy(set, xml_action); slist_iter(wrapper,action_wrapper_t,action->actions_before,lpc, if(wrapper->action->optional == TRUE) { continue; } else if(wrapper->action->discard == TRUE) { continue; } switch(wrapper->strength) { case pecs_must_not: case pecs_ignore: /* ignore both */ break; case pecs_startstop: if(wrapper->action->runnable == FALSE){ break; } /* keep going */ case pecs_must: input = create_xml_node(in, "trigger"); xml_action = action2xml( wrapper->action, TRUE); add_node_copy(input, xml_action); break; } ); free_xml(xml_action); } diff --git a/crm/pengine/group.c b/crm/pengine/group.c index 085c3d1021..94deefa56b 100644 --- a/crm/pengine/group.c +++ b/crm/pengine/group.c @@ -1,407 +1,407 @@ -/* $Id: group.c,v 1.8 2005/02/17 16:39:26 andrew Exp $ */ +/* $Id: group.c,v 1.9 2005/02/19 18:11:04 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 extern gboolean rsc_dependancy_new( const char *id, enum con_strength strength, resource_t *rsc_lh, resource_t *rsc_rh); typedef struct group_variant_data_s { int num_children; GListPtr child_list; /* resource_t* */ resource_t *self; resource_t *first_child; resource_t *last_child; } group_variant_data_t; #define get_group_variant_data(data, rsc) \ CRM_ASSERT(rsc->variant == pe_group); \ CRM_ASSERT(rsc->variant_opaque != NULL); \ data = (group_variant_data_t *)rsc->variant_opaque; \ void group_unpack(resource_t *rsc) { crm_data_t * xml_obj = rsc->xml; crm_data_t * xml_self = create_xml_node(NULL, XML_CIB_TAG_RESOURCE); group_variant_data_t *group_data = NULL; resource_t *self = NULL; crm_verbose("Processing resource %s...", rsc->id); crm_malloc(group_data, sizeof(group_variant_data_t)); group_data->num_children = 0; group_data->self = NULL; group_data->child_list = NULL; group_data->first_child = NULL; group_data->last_child = NULL; /* this is a bit of a hack - but simplifies everything else */ copy_in_properties(xml_self, xml_obj); if(common_unpack(xml_self, &self)) { group_data->self = self; self->restart_type = pe_restart_restart; } else { crm_xml_err(xml_self, "Couldnt unpack dummy child"); return; } xml_child_iter( xml_obj, xml_native_rsc, XML_CIB_TAG_RESOURCE, resource_t *new_rsc = NULL; set_id(xml_native_rsc, rsc->id, -1); if(common_unpack(xml_native_rsc, &new_rsc)) { group_data->num_children++; group_data->child_list = g_list_append( group_data->child_list, new_rsc); group_data->last_child = new_rsc; if(group_data->first_child == NULL) { group_data->first_child = new_rsc; } - crm_debug_action( + crm_devel_action( print_resource("Added", new_rsc, FALSE)); } else { crm_err("Failed unpacking resource %s", crm_element_value(xml_obj, XML_ATTR_ID)); } ); crm_verbose("Added %d children to resource %s...", group_data->num_children, rsc->id); rsc->variant_opaque = group_data; } resource_t * group_find_child(resource_t *rsc, const char *id) { group_variant_data_t *group_data = NULL; if(rsc->variant == pe_group) { group_data = (group_variant_data_t *)rsc->variant_opaque; } else { crm_err("Resource %s was not a \"group\" variant", rsc->id); return NULL; } return pe_find_resource(group_data->child_list, id); } int group_num_allowed_nodes(resource_t *rsc) { group_variant_data_t *group_data = NULL; if(rsc->variant == pe_native) { group_data = (group_variant_data_t *)rsc->variant_opaque; } else { crm_err("Resource %s was not a \"native\" variant", rsc->id); return 0; } if(group_data->self == NULL) { return 0; } return group_data->self->fns->num_allowed_nodes(group_data->self); } void group_color(resource_t *rsc, GListPtr *colors) { group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); if(group_data->self == NULL) { return; } group_data->self->fns->color(group_data->self, colors); slist_iter( child_rsc, resource_t, group_data->child_list, lpc, child_rsc->fns->color(child_rsc, colors); ); } void group_create_actions(resource_t *rsc) { gboolean child_starting = FALSE; gboolean child_stopping = FALSE; group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); slist_iter( child_rsc, resource_t, group_data->child_list, lpc, child_rsc->fns->create_actions(child_rsc); child_starting = child_starting || child_rsc->starting; child_stopping = child_stopping || child_rsc->stopping; ); if(child_starting) { rsc->starting = TRUE; action_new(group_data->self, start_rsc, NULL); action_new(group_data->self, started_rsc, NULL); } if(child_stopping) { rsc->stopping = TRUE; action_new(group_data->self, stop_rsc, NULL); action_new(group_data->self, stopped_rsc, NULL); } if(group_data->self != NULL) { slist_iter( action, action_t, group_data->self->actions, lpc, action->pseudo = TRUE; ); } } void group_internal_constraints(resource_t *rsc, GListPtr *ordering_constraints) { resource_t *last_rsc = NULL; group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); order_new(group_data->self, stop_rsc, NULL, group_data->self, start_rsc, NULL, pecs_startstop, ordering_constraints); slist_iter( child_rsc, resource_t, group_data->child_list, lpc, order_new(child_rsc, stop_rsc, NULL, child_rsc, start_rsc, NULL, pecs_startstop, ordering_constraints); if(last_rsc != NULL) { order_new(last_rsc, start_rsc, NULL, child_rsc, start_rsc, NULL, pecs_startstop, ordering_constraints); order_new(child_rsc, stop_rsc, NULL, last_rsc, stop_rsc, NULL, pecs_startstop, ordering_constraints); } else { order_new(child_rsc, stop_rsc, NULL, group_data->self, stopped_rsc, NULL, pecs_startstop, ordering_constraints); order_new(group_data->self, start_rsc, NULL, child_rsc, start_rsc, NULL, pecs_startstop, ordering_constraints); } rsc_dependancy_new("pe_group_internal", pecs_must, group_data->self, child_rsc); last_rsc = child_rsc; ); if(last_rsc != NULL) { order_new(last_rsc, start_rsc, NULL, group_data->self, started_rsc, NULL, pecs_startstop, ordering_constraints); order_new(group_data->self, stop_rsc, NULL, last_rsc, stop_rsc, NULL, pecs_startstop, ordering_constraints); } } void group_rsc_dependancy_lh(rsc_dependancy_t *constraint) { resource_t *rsc = constraint->rsc_lh; group_variant_data_t *group_data = NULL; if(rsc == NULL) { crm_err("rsc_lh was NULL for %s", constraint->id); return; } else if(constraint->rsc_rh == NULL) { crm_err("rsc_rh was NULL for %s", constraint->id); return; } else { - crm_debug("Processing constraints from %s", rsc->id); + crm_devel("Processing constraints from %s", rsc->id); } get_group_variant_data(group_data, rsc); if(group_data->self == NULL) { return; } group_data->self->fns->rsc_dependancy_rh(group_data->self, constraint); } void group_rsc_dependancy_rh(resource_t *rsc, rsc_dependancy_t *constraint) { resource_t *rsc_lh = rsc; group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); crm_verbose("Processing RH of constraint %s", constraint->id); - crm_debug_action(print_resource("LHS", rsc_lh, TRUE)); + crm_devel_action(print_resource("LHS", rsc_lh, TRUE)); if(group_data->self == NULL) { return; } group_data->self->fns->rsc_dependancy_rh(group_data->self, constraint); } void group_rsc_order_lh(resource_t *rsc, order_constraint_t *order) { group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); crm_verbose("Processing LH of ordering constraint %d", order->id); if(group_data->self == NULL) { return; } else if(order->lh_action_task == start_rsc) { order->lh_action_task = started_rsc; } else if(order->lh_action_task == stop_rsc) { order->lh_action_task = stopped_rsc; } group_data->self->fns->rsc_order_lh(group_data->self, order); } void group_rsc_order_rh( action_t *lh_action, resource_t *rsc, order_constraint_t *order) { group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); crm_verbose("Processing RH of ordering constraint %d", order->id); if(group_data->self == NULL) { return; } group_data->self->fns->rsc_order_rh(lh_action, group_data->self, order); } void group_rsc_location(resource_t *rsc, rsc_to_node_t *constraint) { group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); crm_verbose("Processing actions from %s", rsc->id); if(group_data->self != NULL) { group_data->self->fns->rsc_location(group_data->self, constraint); } slist_iter( child_rsc, resource_t, group_data->child_list, lpc, child_rsc->fns->rsc_location(child_rsc, constraint); ); } void group_expand(resource_t *rsc, crm_data_t * *graph) { group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); crm_verbose("Processing actions from %s", rsc->id); group_data->self->fns->expand(group_data->self, graph); if(group_data->self == NULL) { return; } slist_iter( child_rsc, resource_t, group_data->child_list, lpc, child_rsc->fns->expand(child_rsc, graph); ); } void group_dump(resource_t *rsc, const char *pre_text, gboolean details) { group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); if(group_data->self == NULL) { return; } common_dump(rsc, pre_text, details); group_data->self->fns->dump(group_data->self, pre_text, details); slist_iter( child_rsc, resource_t, group_data->child_list, lpc, child_rsc->fns->dump(child_rsc, pre_text, details); ); } void group_free(resource_t *rsc) { group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); crm_verbose("Freeing %s", rsc->id); slist_iter( child_rsc, resource_t, group_data->child_list, lpc, crm_verbose("Freeing child %s", child_rsc->id); child_rsc->fns->free(child_rsc); ); crm_verbose("Freeing child list"); pe_free_shallow_adv(group_data->child_list, FALSE); if(group_data->self != NULL) { group_data->self->fns->free(group_data->self); } common_free(rsc); } void group_agent_constraints(resource_t *rsc) { group_variant_data_t *group_data = NULL; get_group_variant_data(group_data, rsc); slist_iter( child_rsc, resource_t, group_data->child_list, lpc, child_rsc->fns->agent_constraints(child_rsc); ); } diff --git a/crm/pengine/incarnation.c b/crm/pengine/incarnation.c index 8cae2b0bde..ba85bc947e 100644 --- a/crm/pengine/incarnation.c +++ b/crm/pengine/incarnation.c @@ -1,561 +1,561 @@ -/* $Id: incarnation.c,v 1.7 2005/02/01 22:46:41 andrew Exp $ */ +/* $Id: incarnation.c,v 1.8 2005/02/19 18:11:04 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 extern gboolean rsc_dependancy_new( const char *id, enum con_strength strength, resource_t *rsc_lh, resource_t *rsc_rh); typedef struct incarnation_variant_data_s { resource_t *self; int incarnation_max; int incarnation_max_node; int active_incarnation; gboolean interleave; gboolean ordered; GListPtr child_list; /* resource_t* */ } incarnation_variant_data_t; #define get_incarnation_variant_data(data, rsc) \ if(rsc->variant == pe_incarnation) { \ data = (incarnation_variant_data_t *)rsc->variant_opaque; \ } else { \ crm_err("Resource %s was not an \"incarnation\" variant", \ rsc->id); \ return; \ } void incarnation_unpack(resource_t *rsc) { int lpc = 0; crm_data_t * xml_obj = rsc->xml; crm_data_t * xml_self = create_xml_node(NULL, XML_CIB_TAG_RESOURCE); incarnation_variant_data_t *incarnation_data = NULL; resource_t *self = NULL; const char *ordered = crm_element_value( xml_obj, XML_RSC_ATTR_ORDERED); const char *interleave = crm_element_value( xml_obj, XML_RSC_ATTR_INTERLEAVE); const char *max_incarn = crm_element_value( xml_obj, XML_RSC_ATTR_INCARNATION_MAX); const char *max_incarn_node = crm_element_value( xml_obj, XML_RSC_ATTR_INCARNATION_NODEMAX); crm_verbose("Processing resource %s...", rsc->id); crm_malloc(incarnation_data, sizeof(incarnation_variant_data_t)); incarnation_data->child_list = NULL; incarnation_data->interleave = FALSE; incarnation_data->ordered = FALSE; incarnation_data->active_incarnation = 0; incarnation_data->incarnation_max = crm_atoi(max_incarn, "1"); incarnation_data->incarnation_max_node = crm_atoi(max_incarn_node,"1"); /* this is a bit of a hack - but simplifies everything else */ copy_in_properties(xml_self, xml_obj); if(common_unpack(xml_self, &self)) { incarnation_data->self = self; self->restart_type = pe_restart_restart; } else { crm_xml_err(xml_self, "Couldnt unpack dummy child"); return; } if(safe_str_eq(interleave, XML_BOOLEAN_TRUE)) { incarnation_data->interleave = TRUE; } if(safe_str_eq(ordered, XML_BOOLEAN_TRUE)) { incarnation_data->ordered = TRUE; } xml_child_iter( xml_obj, xml_obj_child, XML_CIB_TAG_RESOURCE, char *inc_max = crm_itoa(incarnation_data->incarnation_max); for(lpc = 0; lpc < incarnation_data->incarnation_max; lpc++) { resource_t *child_rsc = NULL; crm_data_t * child_copy = copy_xml_node_recursive( xml_obj_child); set_id(child_copy, rsc->id, lpc); if(common_unpack(child_copy, &child_rsc)) { char *inc_num = crm_itoa(lpc); incarnation_data->child_list = g_list_append( incarnation_data->child_list, child_rsc); set_xml_property_copy( child_rsc->extra_attrs, XML_RSC_ATTR_INCARNATION, inc_num); set_xml_property_copy( child_rsc->extra_attrs, XML_RSC_ATTR_INCARNATION_MAX, inc_max); - crm_xml_debug(child_rsc->extra_attrs, + crm_xml_devel(child_rsc->extra_attrs, "creating extra attributes"); - crm_debug_action( + crm_devel_action( print_resource("Added", child_rsc, FALSE)); crm_free(inc_num); } else { crm_err("Failed unpacking resource %s", crm_element_value(child_copy, XML_ATTR_ID)); } } crm_free(inc_max); /* only count the first one */ break; ); crm_verbose("Added %d children to resource %s...", incarnation_data->incarnation_max, rsc->id); rsc->variant_opaque = incarnation_data; } resource_t * incarnation_find_child(resource_t *rsc, const char *id) { incarnation_variant_data_t *incarnation_data = NULL; if(rsc->variant == pe_incarnation) { incarnation_data = (incarnation_variant_data_t *)rsc->variant_opaque; } else { crm_err("Resource %s was not a \"incarnation\" variant", rsc->id); return NULL; } return pe_find_resource(incarnation_data->child_list, id); } int incarnation_num_allowed_nodes(resource_t *rsc) { int num_nodes = 0; incarnation_variant_data_t *incarnation_data = NULL; if(rsc->variant == pe_incarnation) { incarnation_data = (incarnation_variant_data_t *)rsc->variant_opaque; } else { crm_err("Resource %s was not an \"incarnation\" variant", rsc->id); return 0; } /* what *should* we return here? */ slist_iter( child_rsc, resource_t, incarnation_data->child_list, lpc, int tmp_num_nodes = child_rsc->fns->num_allowed_nodes(child_rsc); if(tmp_num_nodes > num_nodes) { num_nodes = tmp_num_nodes; } ); return num_nodes; } void incarnation_color(resource_t *rsc, GListPtr *colors) { int lpc = 0, lpc2 = 0, max_nodes = 0; resource_t *child_0 = NULL; resource_t *child_lh = NULL; resource_t *child_rh = NULL; incarnation_variant_data_t *incarnation_data = NULL; get_incarnation_variant_data(incarnation_data, rsc); child_0 = g_list_nth_data(incarnation_data->child_list, 0); max_nodes = rsc->fns->num_allowed_nodes(rsc); /* generate up to max_nodes * incarnation_node_max constraints */ lpc = 0; crm_info("Distributing %d incarnations over %d nodes", incarnation_data->incarnation_max, max_nodes); for(; lpc < max_nodes && lpc < incarnation_data->incarnation_max; lpc++) { child_lh = child_0; incarnation_data->active_incarnation++; if(lpc != 0) { child_rh = g_list_nth_data(incarnation_data->child_list, lpc); - crm_debug("Incarnation %d will run on a differnt node to 0", + crm_devel("Incarnation %d will run on a differnt node to 0", lpc); rsc_dependancy_new("pe_incarnation_internal_must_not", pecs_must_not, child_lh, child_rh); } else { child_rh = child_0; } child_lh = child_rh; for(lpc2 = 1; lpc2 < incarnation_data->incarnation_max_node; lpc2++) { int offset = lpc + (lpc2 * max_nodes); if(offset >= incarnation_data->incarnation_max) { break; } - crm_debug("Incarnation %d will run on the same node as %d", + crm_devel("Incarnation %d will run on the same node as %d", offset, lpc); incarnation_data->active_incarnation++; child_rh = g_list_nth_data( incarnation_data->child_list, offset); rsc_dependancy_new("pe_incarnation_internal_must", pecs_must, child_lh, child_rh); } } slist_iter( child_rsc, resource_t, incarnation_data->child_list, lpc, if(lpc < incarnation_data->active_incarnation) { - crm_debug("Coloring Incarnation %d", lpc); + crm_devel("Coloring Incarnation %d", lpc); child_rsc->fns->color(child_rsc, colors); } else { /* TODO: assign "no color"? Doesnt seem to need it */ crm_warn("Incarnation %d cannot be started", lpc); } ); crm_info("%d Incarnations are active", incarnation_data->active_incarnation); } void incarnation_create_actions(resource_t *rsc) { gboolean child_starting = FALSE; gboolean child_stopping = FALSE; incarnation_variant_data_t *incarnation_data = NULL; get_incarnation_variant_data(incarnation_data, rsc); slist_iter( child_rsc, resource_t, incarnation_data->child_list, lpc, child_rsc->fns->create_actions(child_rsc); child_starting = child_starting || child_rsc->starting; child_stopping = child_stopping || child_rsc->stopping; ); if(child_starting) { rsc->starting = TRUE; action_new(incarnation_data->self, start_rsc, NULL); action_new(incarnation_data->self, started_rsc, NULL); } if(child_stopping) { rsc->stopping = TRUE; action_new(incarnation_data->self, stop_rsc, NULL); action_new(incarnation_data->self, stopped_rsc, NULL); } slist_iter( action, action_t, incarnation_data->self->actions, lpc, action->pseudo = TRUE; ); } void incarnation_internal_constraints(resource_t *rsc, GListPtr *ordering_constraints) { resource_t *last_rsc = NULL; incarnation_variant_data_t *incarnation_data = NULL; get_incarnation_variant_data(incarnation_data, rsc); /* global stop before start */ order_new(incarnation_data->self, stop_rsc, NULL, incarnation_data->self, start_rsc, NULL, pecs_startstop, ordering_constraints); slist_iter( child_rsc, resource_t, incarnation_data->child_list, lpc, /* child stop before start */ order_new(child_rsc, stop_rsc, NULL, child_rsc, start_rsc, NULL, pecs_startstop, ordering_constraints); if(incarnation_data->ordered && last_rsc != NULL) { - crm_debug("Ordered version"); + crm_devel("Ordered version"); if(lpc < incarnation_data->active_incarnation) { /* child/child relative start */ order_new(last_rsc, start_rsc, NULL, child_rsc, start_rsc, NULL, pecs_startstop, ordering_constraints); } /* child/child relative stop */ order_new(child_rsc, stop_rsc, NULL, last_rsc, stop_rsc, NULL, pecs_startstop, ordering_constraints); } else if(incarnation_data->ordered) { - crm_debug("Ordered version (1st node)"); + crm_devel("Ordered version (1st node)"); /* child start before global started */ order_new(child_rsc, start_rsc, NULL, incarnation_data->self, started_rsc, NULL, pecs_startstop, ordering_constraints); /* first child stop before global stopped */ order_new(child_rsc, stop_rsc, NULL, incarnation_data->self, stopped_rsc, NULL, pecs_startstop, ordering_constraints); /* global start before first child start */ order_new(incarnation_data->self, start_rsc, NULL, child_rsc, start_rsc, NULL, pecs_startstop, ordering_constraints); } else { - crm_debug("Un-ordered version"); + crm_devel("Un-ordered version"); if(lpc < incarnation_data->active_incarnation) { /* child start before global started */ order_new(child_rsc, start_rsc, NULL, incarnation_data->self, started_rsc, NULL, pecs_startstop, ordering_constraints); } /* global start before child start */ order_new(incarnation_data->self, start_rsc, NULL, child_rsc, start_rsc, NULL, pecs_startstop, ordering_constraints); /* child stop before global stopped */ order_new(child_rsc, stop_rsc, NULL, incarnation_data->self, stopped_rsc, NULL, pecs_startstop, ordering_constraints); /* global stop before child stop */ order_new(incarnation_data->self, stop_rsc, NULL, child_rsc, stop_rsc, NULL, pecs_startstop, ordering_constraints); } if(lpc < incarnation_data->active_incarnation) { last_rsc = child_rsc; } ); if(incarnation_data->ordered && last_rsc != NULL) { - crm_debug("Ordered version (last node)"); + crm_devel("Ordered version (last node)"); /* last child start before global started */ order_new(last_rsc, start_rsc, NULL, incarnation_data->self, started_rsc, NULL, pecs_startstop, ordering_constraints); /* global stop before first child stop */ order_new(incarnation_data->self, stop_rsc, NULL, last_rsc, stop_rsc, NULL, pecs_startstop, ordering_constraints); } } void incarnation_rsc_dependancy_lh(rsc_dependancy_t *constraint) { resource_t *rsc = constraint->rsc_lh; incarnation_variant_data_t *incarnation_data = NULL; if(rsc == NULL) { crm_err("rsc_lh was NULL for %s", constraint->id); return; } else if(constraint->rsc_rh == NULL) { crm_err("rsc_rh was NULL for %s", constraint->id); return; } else if(constraint->strength != pecs_must_not) { crm_warn("rsc_dependancies other than \"must_not\" " "are not supported for incarnation resources"); return; } else { - crm_debug("Processing constraints from %s", rsc->id); + crm_devel("Processing constraints from %s", rsc->id); } get_incarnation_variant_data(incarnation_data, rsc); slist_iter( child_rsc, resource_t, incarnation_data->child_list, lpc, - crm_debug_action(print_resource("LHS", child_rsc, TRUE)); + crm_devel_action(print_resource("LHS", child_rsc, TRUE)); child_rsc->fns->rsc_dependancy_rh(child_rsc, constraint); ); } void incarnation_rsc_dependancy_rh(resource_t *rsc, rsc_dependancy_t *constraint) { incarnation_variant_data_t *incarnation_data = NULL; crm_verbose("Processing RH of constraint %s", constraint->id); if(rsc == NULL) { crm_err("rsc_lh was NULL for %s", constraint->id); return; } else if(constraint->rsc_rh == NULL) { crm_err("rsc_rh was NULL for %s", constraint->id); return; } else if(constraint->strength != pecs_must_not) { crm_warn("rsc_dependancies other than \"must_not\" " "are not supported for incarnation resources"); return; } else { - crm_debug_action(print_resource("LHS", rsc, FALSE)); + crm_devel_action(print_resource("LHS", rsc, FALSE)); } get_incarnation_variant_data(incarnation_data, rsc); slist_iter( child_rsc, resource_t, incarnation_data->child_list, lpc, - crm_debug_action(print_resource("RHS", child_rsc, FALSE)); + crm_devel_action(print_resource("RHS", child_rsc, FALSE)); child_rsc->fns->rsc_dependancy_rh(child_rsc, constraint); ); } void incarnation_rsc_order_lh(resource_t *rsc, order_constraint_t *order) { incarnation_variant_data_t *incarnation_data = NULL; get_incarnation_variant_data(incarnation_data, rsc); crm_verbose("Processing LH of ordering constraint %d", order->id); if(order->lh_action_task == start_rsc) { order->lh_action_task = started_rsc; } else if(order->lh_action_task == stop_rsc) { order->lh_action_task = stopped_rsc; } incarnation_data->self->fns->rsc_order_lh(incarnation_data->self, order); } void incarnation_rsc_order_rh( action_t *lh_action, resource_t *rsc, order_constraint_t *order) { incarnation_variant_data_t *incarnation_data = NULL; get_incarnation_variant_data(incarnation_data, rsc); crm_verbose("Processing RH of ordering constraint %d", order->id); incarnation_data->self->fns->rsc_order_rh(lh_action, incarnation_data->self, order); } void incarnation_rsc_location(resource_t *rsc, rsc_to_node_t *constraint) { incarnation_variant_data_t *incarnation_data = NULL; get_incarnation_variant_data(incarnation_data, rsc); crm_verbose("Processing actions from %s", rsc->id); incarnation_data->self->fns->rsc_location(incarnation_data->self, constraint); slist_iter( child_rsc, resource_t, incarnation_data->child_list, lpc, child_rsc->fns->rsc_location(child_rsc, constraint); ); } void incarnation_expand(resource_t *rsc, crm_data_t * *graph) { incarnation_variant_data_t *incarnation_data = NULL; get_incarnation_variant_data(incarnation_data, rsc); crm_verbose("Processing actions from %s", rsc->id); incarnation_data->self->fns->expand(incarnation_data->self, graph); slist_iter( child_rsc, resource_t, incarnation_data->child_list, lpc, child_rsc->fns->expand(child_rsc, graph); ); } void incarnation_dump(resource_t *rsc, const char *pre_text, gboolean details) { incarnation_variant_data_t *incarnation_data = NULL; get_incarnation_variant_data(incarnation_data, rsc); common_dump(rsc, pre_text, details); incarnation_data->self->fns->dump( incarnation_data->self, pre_text, details); slist_iter( child_rsc, resource_t, incarnation_data->child_list, lpc, child_rsc->fns->dump(child_rsc, pre_text, details); ); } void incarnation_free(resource_t *rsc) { incarnation_variant_data_t *incarnation_data = NULL; get_incarnation_variant_data(incarnation_data, rsc); crm_verbose("Freeing %s", rsc->id); slist_iter( child_rsc, resource_t, incarnation_data->child_list, lpc, crm_verbose("Freeing child %s", child_rsc->id); child_rsc->fns->free(child_rsc); ); crm_verbose("Freeing child list"); pe_free_shallow_adv(incarnation_data->child_list, FALSE); incarnation_data->self->fns->free(incarnation_data->self); common_free(rsc); } void incarnation_agent_constraints(resource_t *rsc) { incarnation_variant_data_t *incarnation_data = NULL; get_incarnation_variant_data(incarnation_data, rsc); slist_iter( child_rsc, resource_t, incarnation_data->child_list, lpc, child_rsc->fns->agent_constraints(child_rsc); ); } diff --git a/crm/pengine/native.c b/crm/pengine/native.c index ceaf7d90b8..b82900152a 100644 --- a/crm/pengine/native.c +++ b/crm/pengine/native.c @@ -1,1103 +1,1103 @@ -/* $Id: native.c,v 1.14 2005/02/18 10:59:02 andrew Exp $ */ +/* $Id: native.c,v 1.15 2005/02/19 18:11:04 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 extern color_t *add_color(resource_t *rh_resource, color_t *color); gboolean native_choose_color(resource_t *lh_resource); void native_assign_color(resource_t *rsc, color_t *color); void native_update_node_weight(resource_t *rsc, rsc_to_node_t *cons, const char *id, GListPtr nodes); void native_rsc_dependancy_rh_must(resource_t *rsc_lh, gboolean update_lh, resource_t *rsc_rh, gboolean update_rh); void native_rsc_dependancy_rh_mustnot(resource_t *rsc_lh, gboolean update_lh, resource_t *rsc_rh, gboolean update_rh); void filter_nodes(resource_t *rsc); int num_allowed_nodes4color(color_t *color); typedef struct native_variant_data_s { lrm_agent_t *agent; GListPtr running_on; /* node_t* */ color_t *color; GListPtr node_cons; /* rsc_to_node_t* */ GListPtr allowed_nodes; /* node_t* */ } native_variant_data_t; #define get_native_variant_data(data, rsc) \ CRM_ASSERT(rsc->variant == pe_native); \ CRM_ASSERT(rsc->variant_opaque != NULL); \ data = (native_variant_data_t *)rsc->variant_opaque; void native_add_running(resource_t *rsc, node_t *node) { native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); native_data->running_on = g_list_append(native_data->running_on, node); if(g_list_length(native_data->running_on) > 1) { crm_warn("Resource %s is (potentially) active on %d nodes." " Latest: %s", rsc->id, g_list_length(native_data->running_on), node->details->id); } } void native_unpack(resource_t *rsc) { crm_data_t * xml_obj = rsc->xml; native_variant_data_t *native_data = NULL; const char *version = crm_element_value(xml_obj, XML_ATTR_VERSION); crm_verbose("Processing resource %s...", rsc->id); crm_malloc(native_data, sizeof(native_variant_data_t)); crm_malloc(native_data->agent, sizeof(lrm_agent_t)); native_data->agent->class = crm_element_value(xml_obj, "class"); native_data->agent->type = crm_element_value(xml_obj, "type"); native_data->agent->version = version?version:"0.0"; native_data->color = NULL; native_data->allowed_nodes = NULL; native_data->node_cons = NULL; native_data->running_on = NULL; rsc->variant_opaque = native_data; } resource_t * native_find_child(resource_t *rsc, const char *id) { return NULL; } int native_num_allowed_nodes(resource_t *rsc) { int num_nodes = 0; native_variant_data_t *native_data = NULL; if(rsc->variant == pe_native) { native_data = (native_variant_data_t *)rsc->variant_opaque; } else { crm_err("Resource %s was not a \"native\" variant", rsc->id); return 0; } if(native_data->color) { return num_allowed_nodes4color(native_data->color); } else if(rsc->candidate_colors) { /* TODO: sort colors first */ color_t *color = g_list_nth_data(rsc->candidate_colors, 0); return num_allowed_nodes4color(color); } else { slist_iter( this_node, node_t, native_data->allowed_nodes, lpc, if(this_node->weight < 0) { continue; } num_nodes++; ); } return num_nodes; } int num_allowed_nodes4color(color_t *color) { int num_nodes = 0; if(color->details->pending == FALSE) { if(color->details->chosen_node) { return 1; } return 0; } slist_iter( this_node, node_t, color->details->candidate_nodes, lpc, if(this_node->weight < 0) { continue; } num_nodes++; ); return num_nodes; } void native_color(resource_t *rsc, GListPtr *colors) { color_t *new_color = NULL; native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); if( native_choose_color(rsc) ) { crm_verbose("Colored resource %s with color %d", rsc->id, native_data->color->id); } else { if(native_data->allowed_nodes != NULL) { /* filter out nodes with a negative weight */ filter_nodes(rsc); new_color = create_color( colors, rsc, native_data->allowed_nodes); native_assign_color(rsc, new_color); } if(new_color == NULL) { crm_err("Could not color resource %s", rsc->id); print_resource("ERROR: No color", rsc, FALSE); native_assign_color(rsc, no_color); } } rsc->provisional = FALSE; } void native_create_actions(resource_t *rsc) { action_t *start_op = NULL; gboolean can_start = FALSE; node_t *chosen = NULL; native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); if(native_data->color != NULL) { chosen = native_data->color->details->chosen_node; } if(chosen != NULL) { can_start = TRUE; } if(can_start && g_list_length(native_data->running_on) == 0) { /* create start action */ crm_info("Start resource %s (%s)", rsc->id, safe_val3(NULL, chosen, details, uname)); start_op = action_new(rsc, start_rsc, chosen); } else if(g_list_length(native_data->running_on) > 1) { crm_info("Attempting recovery of resource %s", rsc->id); if(rsc->recovery_type == recovery_stop_start || rsc->recovery_type == recovery_stop_only) { slist_iter( node, node_t, native_data->running_on, lpc, crm_info("Stop resource %s (%s)", rsc->id, safe_val3(NULL, node, details, uname)); action_new(rsc, stop_rsc, node); ); } if(rsc->recovery_type == recovery_stop_start && can_start) { crm_info("Start resource %s (%s)", rsc->id, safe_val3(NULL, chosen, details, uname)); start_op = action_new( rsc, start_rsc, chosen); } } else { crm_debug("Stop and possible restart of %s", rsc->id); slist_iter( node, node_t, native_data->running_on, lpc, if(chosen != NULL && safe_str_eq( node->details->id, chosen->details->id)) { /* restart */ crm_info("Leave resource %s alone (%s)", rsc->id, safe_val3(NULL, chosen, details, uname)); /* in case the actions already exist */ slist_iter( action, action_t, rsc->actions, lpc2, if(action->task == start_rsc || action->task == stop_rsc){ action->optional = TRUE; } ); continue; } else if(chosen != NULL) { /* move */ crm_info("Move resource %s (%s -> %s)", rsc->id, safe_val3(NULL, node, details, uname), safe_val3(NULL, chosen, details, uname)); action_new(rsc, stop_rsc, node); action_new(rsc, start_rsc, chosen); } else { crm_info("Stop resource %s (%s)", rsc->id, safe_val3(NULL, node, details, uname)); action_new(rsc, stop_rsc, node); } ); } slist_iter( action, action_t, rsc->actions, lpc, if(action->extra_attrs == NULL) { action->extra_attrs = create_xml_node(NULL, "extra"); } - crm_xml_debug(rsc->extra_attrs, "copying in extra attributes"); + crm_xml_devel(rsc->extra_attrs, "copying in extra attributes"); copy_in_properties(action->extra_attrs, rsc->extra_attrs); ); } void native_internal_constraints(resource_t *rsc, GListPtr *ordering_constraints) { order_new(rsc, stop_rsc, NULL, rsc, start_rsc, NULL, pecs_startstop, ordering_constraints); } void native_rsc_dependancy_lh(rsc_dependancy_t *constraint) { resource_t *rsc = constraint->rsc_lh; if(rsc == NULL) { crm_err("rsc_lh was NULL for %s", constraint->id); return; } else if(constraint->rsc_rh == NULL) { crm_err("rsc_rh was NULL for %s", constraint->id); return; } else { - crm_debug("Processing constraints from %s", rsc->id); + crm_devel("Processing constraints from %s", rsc->id); } constraint->rsc_rh->fns->rsc_dependancy_rh(rsc, constraint); } void native_rsc_dependancy_rh(resource_t *rsc, rsc_dependancy_t *constraint) { gboolean do_check = FALSE; gboolean update_lh = FALSE; gboolean update_rh = FALSE; resource_t *rsc_lh = rsc; resource_t *rsc_rh = constraint->rsc_rh; native_variant_data_t *native_data_lh = NULL; native_variant_data_t *native_data_rh = NULL; get_native_variant_data(native_data_lh, rsc_lh); get_native_variant_data(native_data_rh, rsc_rh); crm_verbose("Processing RH of constraint %s", constraint->id); - crm_debug_action(print_resource("LHS", rsc_lh, TRUE)); - crm_debug_action(print_resource("RHS", rsc_rh, TRUE)); + crm_devel_action(print_resource("LHS", rsc_lh, TRUE)); + crm_devel_action(print_resource("RHS", rsc_rh, TRUE)); if(constraint->strength == pecs_ignore || constraint->strength == pecs_startstop){ - crm_debug("Skipping constraint type %d", constraint->strength); + crm_devel("Skipping constraint type %d", constraint->strength); return; } if(rsc_lh->provisional && rsc_rh->provisional) { if(constraint->strength == pecs_must) { /* update effective_priorities */ native_rsc_dependancy_rh_must( rsc_lh, update_lh,rsc_rh, update_rh); } else { /* nothing */ - crm_debug( + crm_devel( "Skipping constraint, both sides provisional"); } return; } else if( (!rsc_lh->provisional) && (!rsc_rh->provisional) && (!native_data_lh->color->details->pending) && (!native_data_rh->color->details->pending) ) { /* error check */ do_check = TRUE; if(rsc_lh->effective_priority < rsc_rh->effective_priority) { update_lh = TRUE; } else if(rsc_lh->effective_priority > rsc_rh->effective_priority) { update_rh = TRUE; } else { update_lh = TRUE; update_rh = TRUE; } } else if(rsc_lh->provisional == FALSE && native_data_lh->color->details->pending == FALSE) { /* update _us_ : postproc color version */ update_rh = TRUE; } else if(rsc_rh->provisional == FALSE && native_data_rh->color->details->pending == FALSE) { /* update _them_ : postproc color alt version */ update_lh = TRUE; } else if(rsc_lh->provisional == FALSE) { /* update _us_ : preproc version */ update_rh = TRUE; } else if(rsc_rh->provisional == FALSE) { /* update _them_ : postproc version */ update_lh = TRUE; } else { crm_warn("Un-expected combination of inputs"); return; } if(update_lh) { - crm_debug("Updating LHS"); + crm_devel("Updating LHS"); } if(update_rh) { - crm_debug("Updating RHS"); + crm_devel("Updating RHS"); } if(do_check) { if(native_constraint_violated( rsc_lh, rsc_rh, constraint) == FALSE) { - crm_debug("Constraint satisfied"); + crm_devel("Constraint satisfied"); return; } /* else constraint cant be satisified */ crm_warn("Constraint %s could not be satisfied", constraint->id); if(update_lh) { crm_warn("Marking resource %s unrunnable as a result", rsc_lh->id); rsc_lh->runnable = FALSE; } if(update_rh) { crm_warn("Marking resource %s unrunnable as a result", rsc_rh->id); rsc_rh->runnable = FALSE; } } if(constraint->strength == pecs_must) { native_rsc_dependancy_rh_must( rsc_lh, update_lh,rsc_rh, update_rh); return; } else if(constraint->strength != pecs_must_not) { /* unknown type */ crm_err("Unknown constraint type %d", constraint->strength); return; } native_rsc_dependancy_rh_mustnot(rsc_lh, update_lh,rsc_rh, update_rh); } void native_rsc_order_lh(resource_t *lh_rsc, order_constraint_t *order) { GListPtr lh_actions = NULL; action_t *lh_action = order->lh_action; crm_verbose("Processing LH of ordering constraint %d", order->id); switch(order->lh_action_task) { case start_rsc: case started_rsc: case stop_rsc: case stopped_rsc: break; default: crm_err("Task \"%s\" from ordering %d isnt a resource action", task2text(order->lh_action_task), order->id); return; } if(lh_action != NULL) { lh_actions = g_list_append(NULL, lh_action); } else if(lh_action == NULL && lh_rsc != NULL) { if(order->strength == pecs_must) { - crm_debug("No LH-Side (%s/%s) found for constraint..." + crm_devel("No LH-Side (%s/%s) found for constraint..." " creating", lh_rsc->id, task2text(order->lh_action_task)); action_new(lh_rsc, order->lh_action_task, NULL); } lh_actions = find_actions( lh_rsc->actions, order->lh_action_task, NULL); if(lh_actions == NULL) { - crm_debug("No LH-Side (%s/%s) found for constraint", + crm_devel("No LH-Side (%s/%s) found for constraint", lh_rsc->id, task2text(order->lh_action_task)); - crm_debug("RH-Side was: (%s/%s)", + crm_devel("RH-Side was: (%s/%s)", order->rh_rsc?order->rh_rsc->id:order->rh_action?order->rh_action->rsc->id:"", task2text(order->rh_action_task)); return; } } else { crm_warn("No LH-Side (%s) specified for constraint", task2text(order->lh_action_task)); - crm_debug("RH-Side was: (%s/%s)", + crm_devel("RH-Side was: (%s/%s)", order->rh_rsc?order->rh_rsc->id:order->rh_action?order->rh_action->rsc->id:"", task2text(order->rh_action_task)); return; } slist_iter( lh_action_iter, action_t, lh_actions, lpc, resource_t *rh_rsc = order->rh_rsc; if(rh_rsc == NULL && order->rh_action) { rh_rsc = order->rh_action->rsc; } if(rh_rsc) { rh_rsc->fns->rsc_order_rh( lh_action_iter, rh_rsc, order); } else if(order->rh_action) { order_actions(lh_action_iter, order->rh_action, order); } ); pe_free_shallow_adv(lh_actions, FALSE); } void native_rsc_order_rh( action_t *lh_action, resource_t *rsc, order_constraint_t *order) { GListPtr rh_actions = NULL; action_t *rh_action = order->rh_action; crm_verbose("Processing RH of ordering constraint %d", order->id); switch(order->rh_action_task) { case start_rsc: case started_rsc: case stop_rsc: case stopped_rsc: break; default: crm_err("Task \"%s\" from ordering %d isnt a resource action", task2text(order->rh_action_task), order->id); return; } if(rh_action != NULL) { rh_actions = g_list_append(NULL, rh_action); } else if(rh_action == NULL && rsc != NULL) { rh_actions = find_actions( rsc->actions, order->rh_action_task, NULL); if(rh_actions == NULL) { - crm_debug("No RH-Side (%s/%s) found for constraint..." + crm_devel("No RH-Side (%s/%s) found for constraint..." " ignoring", rsc->id, task2text(order->rh_action_task)); - crm_debug("LH-Side was: (%s/%s)", + crm_devel("LH-Side was: (%s/%s)", order->lh_rsc?order->lh_rsc->id:order->lh_action?order->lh_action->rsc->id:"", task2text(order->lh_action_task)); return; } } else if(rh_action == NULL) { - crm_debug("No RH-Side (%s) specified for constraint..." + crm_devel("No RH-Side (%s) specified for constraint..." " ignoring", task2text(order->rh_action_task)); - crm_debug("LH-Side was: (%s/%s)", + crm_devel("LH-Side was: (%s/%s)", order->lh_rsc?order->lh_rsc->id:order->lh_action?order->lh_action->rsc->id:"", task2text(order->lh_action_task)); return; } slist_iter( rh_action_iter, action_t, rh_actions, lpc, order_actions(lh_action, rh_action_iter, order); ); pe_free_shallow_adv(rh_actions, FALSE); } void native_rsc_location(resource_t *rsc, rsc_to_node_t *constraint) { GListPtr or_list; native_variant_data_t *native_data = NULL; - crm_debug_action(print_rsc_to_node("Applying", constraint, FALSE)); + crm_devel_action(print_rsc_to_node("Applying", constraint, FALSE)); /* take "lifetime" into account */ if(constraint == NULL) { crm_err("Constraint is NULL"); return; } else if(is_active(constraint) == FALSE) { crm_debug("Constraint (%s) is not active", constraint->id); return; } else if(rsc == NULL) { crm_err("LHS of rsc_to_node (%s) is NULL", constraint->id); return; } get_native_variant_data(native_data, rsc); native_data->node_cons = g_list_append(native_data->node_cons, constraint); if(constraint->node_list_rh == NULL) { crm_warn("RHS of constraint %s is NULL", constraint->id); return; } - crm_debug_action(print_resource("before update", rsc,TRUE)); + crm_devel_action(print_resource("before update", rsc,TRUE)); or_list = node_list_or( native_data->allowed_nodes, constraint->node_list_rh, FALSE); pe_free_shallow(native_data->allowed_nodes); native_data->allowed_nodes = or_list; slist_iter(node_rh, node_t, constraint->node_list_rh, lpc, native_update_node_weight( rsc, constraint, node_rh->details->uname, native_data->allowed_nodes)); - crm_debug_action(print_resource("after update", rsc, TRUE)); + crm_devel_action(print_resource("after update", rsc, TRUE)); } void native_expand(resource_t *rsc, crm_data_t * *graph) { slist_iter( action, action_t, rsc->actions, lpc, - crm_debug("processing action %d for rsc=%s", + crm_devel("processing action %d for rsc=%s", action->id, rsc->id); graph_element_from_action(action, graph); ); } void native_dump(resource_t *rsc, const char *pre_text, gboolean details) { native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); common_dump(rsc, pre_text, details); - crm_debug("\t%d candidate colors, %d allowed nodes," + crm_devel("\t%d candidate colors, %d allowed nodes," " %d rsc_cons and %d node_cons", g_list_length(rsc->candidate_colors), g_list_length(native_data->allowed_nodes), g_list_length(rsc->rsc_cons), g_list_length(native_data->node_cons)); if(details) { - crm_debug("\t=== Actions"); + crm_devel("\t=== Actions"); slist_iter( action, action_t, rsc->actions, lpc, print_action("\trsc action: ", action, FALSE); ); - crm_debug("\t=== Colors"); + crm_devel("\t=== Colors"); slist_iter( color, color_t, rsc->candidate_colors, lpc, print_color("\t", color, FALSE) ); - crm_debug("\t=== Allowed Nodes"); + crm_devel("\t=== Allowed Nodes"); slist_iter( node, node_t, native_data->allowed_nodes, lpc, print_node("\t", node, FALSE); ); } } void native_free(resource_t *rsc) { native_variant_data_t *native_data = (native_variant_data_t *)rsc->variant_opaque; - crm_debug("Freeing Allowed Nodes"); + crm_devel("Freeing Allowed Nodes"); pe_free_shallow(native_data->allowed_nodes); common_free(rsc); } void native_rsc_dependancy_rh_must(resource_t *rsc_lh, gboolean update_lh, resource_t *rsc_rh, gboolean update_rh) { native_variant_data_t *native_data_lh = NULL; native_variant_data_t *native_data_rh = NULL; gboolean do_merge = FALSE; GListPtr old_list = NULL; GListPtr merged_node_list = NULL; float max_pri = rsc_lh->effective_priority; if(max_pri < rsc_rh->effective_priority) { max_pri = rsc_rh->effective_priority; } rsc_lh->effective_priority = max_pri; rsc_rh->effective_priority = max_pri; get_native_variant_data(native_data_lh, rsc_lh); get_native_variant_data(native_data_rh, rsc_rh); if(native_data_lh->color && native_data_rh->color) { do_merge = TRUE; merged_node_list = node_list_and( native_data_lh->color->details->candidate_nodes, native_data_rh->color->details->candidate_nodes, TRUE); } else if(native_data_lh->color) { do_merge = TRUE; merged_node_list = node_list_and( native_data_lh->color->details->candidate_nodes, native_data_rh->allowed_nodes, TRUE); } else if(native_data_rh->color) { do_merge = TRUE; merged_node_list = node_list_and( native_data_lh->allowed_nodes, native_data_rh->color->details->candidate_nodes, TRUE); } if(update_lh) { crm_free(native_data_lh->color); rsc_lh->runnable = rsc_rh->runnable; native_data_lh->color = copy_color(native_data_rh->color); } if(update_rh) { crm_free(native_data_rh->color); rsc_rh->runnable = rsc_lh->runnable; native_data_rh->color = copy_color(native_data_lh->color); } CRM_DEV_ASSERT(update_rh || update_lh); if(crm_assert_failed == FALSE && do_merge) { - crm_debug("Merging candidate nodes"); + crm_devel("Merging candidate nodes"); old_list = native_data_rh->color->details->candidate_nodes; native_data_rh->color->details->candidate_nodes = merged_node_list; pe_free_shallow(old_list); } - crm_debug("Finished processing pecs_must constraint"); + crm_devel("Finished processing pecs_must constraint"); } void native_rsc_dependancy_rh_mustnot(resource_t *rsc_lh, gboolean update_lh, resource_t *rsc_rh, gboolean update_rh) { color_t *color_lh = NULL; color_t *color_rh = NULL; native_variant_data_t *native_data_lh = NULL; native_variant_data_t *native_data_rh = NULL; get_native_variant_data(native_data_lh, rsc_lh); get_native_variant_data(native_data_rh, rsc_rh); - crm_debug("Processing pecs_must_not constraint"); + crm_devel("Processing pecs_must_not constraint"); /* pecs_must_not */ if(update_lh) { color_rh = native_data_rh->color; if(rsc_lh->provisional) { color_lh = find_color( rsc_lh->candidate_colors, color_rh); rsc_lh->candidate_colors = g_list_remove( rsc_lh->candidate_colors, color_lh); - crm_debug_action( + crm_devel_action( print_color("Removed LH", color_lh, FALSE)); - crm_debug_action( + crm_devel_action( print_resource("Modified LH", rsc_lh, TRUE)); crm_free(color_lh); } else if(native_data_lh->color && native_data_lh->color->details->pending) { node_t *node_lh = NULL; color_lh = native_data_lh->color; node_lh = pe_find_node( color_lh->details->candidate_nodes, safe_val5(NULL, color_rh, details, chosen_node, details, uname)); color_lh->details->candidate_nodes = g_list_remove( color_lh->details->candidate_nodes, node_lh); - crm_debug_action( + crm_devel_action( print_node("Removed LH", node_lh, FALSE)); - crm_debug_action( + crm_devel_action( print_color("Modified LH", color_lh, FALSE)); crm_free(node_lh); } else { /* error, rsc marked as unrunnable above */ crm_warn("lh else"); } } if(update_rh) { color_lh = native_data_lh->color; if(rsc_rh->provisional) { color_rh = find_color( rsc_rh->candidate_colors, color_lh); rsc_rh->candidate_colors = g_list_remove( rsc_rh->candidate_colors, color_rh); - crm_debug_action( + crm_devel_action( print_color("Removed RH", color_rh, FALSE)); - crm_debug_action( + crm_devel_action( print_resource("Modified RH", rsc_rh, TRUE)); crm_free(color_rh); } else if(native_data_rh->color && native_data_rh->color->details->pending) { node_t *node_rh = NULL; color_rh = native_data_rh->color; node_rh = pe_find_node( color_rh->details->candidate_nodes, safe_val5(NULL, color_lh, details, chosen_node, details, uname)); color_rh->details->candidate_nodes = g_list_remove( color_rh->details->candidate_nodes, node_rh); - crm_debug_action( + crm_devel_action( print_node("Removed RH", node_rh, FALSE)); - crm_debug_action( + crm_devel_action( print_color("Modified RH", color_rh, FALSE)); crm_free(node_rh); } else { /* error, rsc marked as unrunnable above */ crm_warn("rh else"); } } } void native_agent_constraints(resource_t *rsc) { native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); crm_trace("Applying RA restrictions to %s", rsc->id); common_agent_constraints( native_data->allowed_nodes, native_data->agent, rsc->id); } gboolean native_choose_color(resource_t *rsc) { GListPtr sorted_colors = NULL; native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); if(rsc->runnable == FALSE) { native_assign_color(rsc, no_color); } if(rsc->provisional == FALSE) { return !rsc->provisional; } sorted_colors = g_list_sort( rsc->candidate_colors, sort_color_weight); rsc->candidate_colors = sorted_colors; crm_verbose("Choose a color from %d possibilities", g_list_length(sorted_colors)); slist_iter( this_color, color_t, rsc->candidate_colors, lpc, GListPtr intersection = NULL; GListPtr minus = NULL; int len = 0; if(this_color == NULL) { crm_err("color was NULL"); continue; } else if(rsc->effective_priority < this_color->details->highest_priority) { minus = node_list_minus( this_color->details->candidate_nodes, native_data->allowed_nodes, TRUE); len = g_list_length(minus); pe_free_shallow(minus); if(len > 0) { native_assign_color(rsc, this_color); break; } } else { intersection = node_list_and( this_color->details->candidate_nodes, native_data->allowed_nodes, TRUE); len = g_list_length(intersection); pe_free_shallow(intersection); if(len != 0) { native_assign_color(rsc, this_color); break; } } ); return !rsc->provisional; } void native_assign_color(resource_t *rsc, color_t *color) { color_t *local_color = add_color(rsc, color); GListPtr intersection = NULL; GListPtr old_list = NULL; native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); native_data->color = local_color; rsc->provisional = FALSE; if(local_color != NULL) { local_color->details->allocated_resources = g_list_append( local_color->details->allocated_resources,rsc); intersection = node_list_and( local_color->details->candidate_nodes, native_data->allowed_nodes, TRUE); old_list = local_color->details->candidate_nodes; pe_free_shallow(old_list); local_color->details->candidate_nodes = intersection; crm_verbose("Colored resource %s with new color %d", rsc->id, native_data->color->id); - crm_debug_action( + crm_devel_action( print_resource("Colored Resource", rsc, TRUE)); } else { crm_err("local color was NULL"); } return; } void native_update_node_weight(resource_t *rsc, rsc_to_node_t *cons, const char *id, GListPtr nodes) { node_t *node_rh = NULL; native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); node_rh = pe_find_node(native_data->allowed_nodes, id); if(node_rh == NULL) { crm_err("Node not found - cant update"); return; } if(node_rh->fixed) { /* warning */ crm_warn("Constraint %s is irrelevant as the" " weight of node %s is fixed as %f.", cons->id, node_rh->details->uname, node_rh->weight); return; } crm_verbose("Constraint %s (%s): node %s weight %f.", cons->id, cons->can?"can":"cannot", node_rh->details->uname, node_rh->weight); if(cons->can == FALSE) { node_rh->weight = -1; } else { node_rh->weight += cons->weight; } if(node_rh->weight < 0) { node_rh->fixed = TRUE; } - crm_debug_action(print_node("Updated", node_rh, FALSE)); + crm_devel_action(print_node("Updated", node_rh, FALSE)); return; } gboolean native_constraint_violated( resource_t *rsc_lh, resource_t *rsc_rh, rsc_dependancy_t *constraint) { native_variant_data_t *native_data_lh = NULL; native_variant_data_t *native_data_rh = NULL; GListPtr result = NULL; color_t *color_lh = NULL; color_t *color_rh = NULL; GListPtr candidate_nodes_lh = NULL; GListPtr candidate_nodes_rh = NULL; gboolean matched = FALSE; get_native_variant_data(native_data_lh, rsc_lh); get_native_variant_data(native_data_rh, rsc_rh); color_lh = native_data_lh->color; color_rh = native_data_rh->color; if(constraint->strength == pecs_must_not) { matched = TRUE; } if(rsc_lh->provisional || rsc_rh->provisional) { return FALSE; } if(color_lh->details->pending && color_rh->details->pending) { candidate_nodes_lh = color_lh->details->candidate_nodes; candidate_nodes_rh = color_rh->details->candidate_nodes; } else if(color_lh->details->pending == FALSE && color_rh->details->pending == FALSE) { if(color_lh == NULL && color_rh == NULL) { return matched; } else if(color_lh == NULL || color_rh == NULL) { return !matched; } else if(color_lh->details->chosen_node == NULL && color_rh->details->chosen_node == NULL) { return matched; } else if(color_lh->details->chosen_node == NULL || color_rh->details->chosen_node == NULL) { return !matched; } else if(safe_str_eq( color_lh->details->chosen_node->details->id, color_rh->details->chosen_node->details->id)) { return matched; } return !matched; } else if(color_lh->details->pending) { candidate_nodes_lh = color_lh->details->candidate_nodes; candidate_nodes_rh = g_list_append( NULL, color_rh->details->chosen_node); } else if(color_rh->details->pending) { candidate_nodes_rh = color_rh->details->candidate_nodes; candidate_nodes_lh = g_list_append( NULL, color_lh->details->chosen_node); } result = node_list_and(candidate_nodes_lh, candidate_nodes_rh, TRUE); if(g_list_length(result) == 0 && constraint->strength == pecs_must) { /* free result */ return TRUE; } return FALSE; } /* * Remove any nodes with a -ve weight */ void filter_nodes(resource_t *rsc) { native_variant_data_t *native_data = NULL; get_native_variant_data(native_data, rsc); - crm_debug_action(print_resource("Filtering nodes for", rsc, FALSE)); + crm_devel_action(print_resource("Filtering nodes for", rsc, FALSE)); slist_iter( node, node_t, native_data->allowed_nodes, lpc, if(node == NULL) { crm_err("Invalid NULL node"); } else if(node->weight < 0.0 || node->details->online == FALSE || node->details->type == node_ping) { - crm_debug_action(print_node("Removing", node, FALSE)); + crm_devel_action(print_node("Removing", node, FALSE)); native_data->allowed_nodes = g_list_remove(native_data->allowed_nodes, node); crm_free(node); lpc = -1; /* restart the loop */ } ); } diff --git a/crm/pengine/pengine.c b/crm/pengine/pengine.c index 7584b2e8e9..f4c6eb65d2 100755 --- a/crm/pengine/pengine.c +++ b/crm/pengine/pengine.c @@ -1,234 +1,234 @@ -/* $Id: pengine.c,v 1.56 2005/02/11 22:11:29 andrew Exp $ */ +/* $Id: pengine.c,v 1.57 2005/02/19 18:11:04 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 crm_data_t * do_calculations(crm_data_t *cib_object); int num_synapse = 0; 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_verbose("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_verbose("Bad sys-to %s", crm_str(sys_to)); return FALSE; } else if(strcmp(op, CRM_OP_PECALC) == 0) { crm_data_t * output = NULL; crm_xml_info(xml_data, "[in ]"); output = do_calculations(xml_data); crm_xml_debug(output, "[out]"); if (send_ipc_reply(sender, msg, output) ==FALSE) { crm_warn("Answer could not be sent"); } free_xml(output); } else if(strcmp(op, CRM_OP_QUIT) == 0) { crm_warn("Received quit message, terminating"); exit(0); } return TRUE; } crm_data_t * do_calculations(crm_data_t * cib_object) { GListPtr resources = NULL; GListPtr nodes = NULL; GListPtr placement_constraints = NULL; GListPtr actions = NULL; GListPtr ordering_constraints = NULL; GListPtr stonith_list = NULL; GListPtr shutdown_list = NULL; GListPtr colors = NULL; GListPtr action_sets = NULL; crm_data_t * graph = NULL; /* pe_debug_on(); */ crm_verbose("=#=#=#=#= Stage 0 =#=#=#=#="); stage0(cib_object, &resources, &nodes, &placement_constraints, &actions, &ordering_constraints, &stonith_list, &shutdown_list); crm_verbose("=#=#=#=#= Stage 1 =#=#=#=#="); stage1(placement_constraints, nodes, resources); crm_verbose("=#=#=#=#= Stage 2 =#=#=#=#="); stage2(resources, nodes, &colors); crm_verbose("========= Nodes ========="); - crm_debug_action( + crm_devel_action( slist_iter(node, node_t, nodes, lpc, print_node(NULL, node, TRUE) ) ); crm_verbose("========= Resources ========="); - crm_debug_action( + crm_devel_action( slist_iter(resource, resource_t, resources, lpc, print_resource(NULL, resource, TRUE) ) ); crm_verbose("=#=#=#=#= Stage 3 =#=#=#=#="); stage3(colors); crm_verbose("=#=#=#=#= Stage 4 =#=#=#=#="); stage4(colors); crm_verbose("========= Colors ========="); - crm_debug_action( + crm_devel_action( slist_iter(color, color_t, colors, lpc, print_color(NULL, color, FALSE) ) ); crm_verbose("=#=#=#=#= Stage 5 =#=#=#=#="); stage5(resources, &ordering_constraints); crm_verbose("=#=#=#=#= Stage 6 =#=#=#=#="); stage6(&actions, &ordering_constraints, nodes, resources); crm_verbose("========= Action List ========="); - crm_debug_action( + crm_devel_action( slist_iter(action, action_t, actions, lpc, print_action(NULL, action, TRUE) ) ); crm_verbose("=#=#=#=#= Stage 7 =#=#=#=#="); stage7(resources, actions, ordering_constraints); crm_verbose("========= Action Sets ========="); crm_verbose("\t========= Set %d (Un-runnable) =========", -1); - crm_debug_action( + crm_devel_action( slist_iter(action, action_t, actions, lpc, if(action->optional == FALSE && action->runnable == FALSE) { print_action("\t", action, TRUE); } ) ); - crm_debug_action( + crm_devel_action( slist_iter(action_set, GList, action_sets, lpc, crm_verbose("\t========= Set %d =========", lpc); slist_iter(action, action_t, action_set, lpc2, print_action("\t", action, TRUE); ) ) ); crm_verbose("========= Stonith List ========="); - crm_debug_action( + crm_devel_action( slist_iter(node, node_t, stonith_list, lpc, print_node(NULL, node, FALSE); ) ); crm_verbose("========= Shutdown List ========="); - crm_debug_action( + crm_devel_action( slist_iter(node, node_t, shutdown_list, lpc, print_node(NULL, node, FALSE); ) ); crm_verbose("=#=#=#=#= Stage 8 =#=#=#=#="); stage8(resources, actions, &graph); crm_verbose("=#=#=#=#= Cleanup =#=#=#=#="); crm_verbose("deleting node cons"); while(placement_constraints) { pe_free_rsc_to_node((rsc_to_node_t*)placement_constraints->data); placement_constraints = placement_constraints->next; } if(placement_constraints != NULL) { g_list_free(placement_constraints); } crm_verbose("deleting order cons"); pe_free_shallow(ordering_constraints); crm_verbose("deleting action sets"); slist_iter(action_set, GList, action_sets, lpc, pe_free_shallow_adv(action_set, FALSE); ); pe_free_shallow_adv(action_sets, FALSE); crm_verbose("deleting actions"); pe_free_actions(actions); crm_verbose("deleting resources"); pe_free_resources(resources); crm_verbose("deleting colors"); pe_free_colors(colors); crm_verbose("deleting nodes"); pe_free_nodes(nodes); if(shutdown_list != NULL) { g_list_free(shutdown_list); } if(stonith_list != NULL) { g_list_free(stonith_list); } return graph; } diff --git a/crm/pengine/stages.c b/crm/pengine/stages.c index d446784c57..87f9962e57 100644 --- a/crm/pengine/stages.c +++ b/crm/pengine/stages.c @@ -1,415 +1,414 @@ -/* $Id: stages.c,v 1.35 2005/02/15 08:07:34 andrew Exp $ */ +/* $Id: stages.c,v 1.36 2005/02/19 18:11:04 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 node_t *choose_fencer(action_t *stonith, node_t *node, GListPtr resources); void order_actions(action_t *lh, action_t *rh, order_constraint_t *order); char *dc_uuid = NULL; /* * Unpack everything * At the end you'll have: * - A list of nodes * - A list of resources (each with any dependancies on other resources) * - A list of constraints between resources and nodes * - A list of constraints between start/stop actions * - A list of nodes that need to be stonith'd * - A list of nodes that need to be shutdown * - A list of the possible stop/start actions (without dependancies) */ gboolean stage0(crm_data_t * cib, GListPtr *resources, GListPtr *nodes, GListPtr *placement_constraints, GListPtr *actions, GListPtr *ordering_constraints, GListPtr *stonith_list, GListPtr *shutdown_list) { /* int lpc; */ crm_data_t * cib_nodes = get_object_root( XML_CIB_TAG_NODES, cib); crm_data_t * cib_status = get_object_root( XML_CIB_TAG_STATUS, cib); crm_data_t * cib_resources = get_object_root( XML_CIB_TAG_RESOURCES, cib); crm_data_t * cib_constraints = get_object_root( XML_CIB_TAG_CONSTRAINTS, cib); crm_data_t * config = get_object_root( XML_CIB_TAG_CRMCONFIG, cib); crm_data_t * agent_defaults = NULL; /*get_object_root(XML_CIB_TAG_RA_DEFAULTS, cib); */ crm_free(dc_uuid); dc_uuid = NULL; if(cib != NULL) { dc_uuid = crm_element_value_copy(cib, XML_ATTR_DC_UUID); } /* reset remaining global variables */ num_synapse = 0; max_valid_nodes = 0; order_id = 1; action_id = 1; unpack_config(config); unpack_global_defaults(agent_defaults); unpack_nodes(cib_nodes, nodes); unpack_resources(cib_resources, resources, actions, ordering_constraints, *nodes); unpack_status(cib_status, *nodes, *resources, actions, placement_constraints); unpack_constraints(cib_constraints, *nodes, *resources, placement_constraints, ordering_constraints); return TRUE; } /* * Count how many valid nodes we have (so we know the maximum number of * colors we can resolve). * * Apply node constraints (ie. filter the "allowed_nodes" part of resources */ gboolean stage1(GListPtr placement_constraints, GListPtr nodes, GListPtr resources) { - crm_debug("Processing stage 1"); + crm_devel("Processing stage 1"); slist_iter( node, node_t, nodes, lpc, if(node == NULL) { /* error */ } else if(node->weight >= 0.0 /* global weight */ && node->details->online && node->details->type == node_member) { max_valid_nodes++; } ); apply_placement_constraints(placement_constraints, nodes); /* will also filter -ve "final" weighted nodes from resources' * allowed lists while we are there */ apply_agent_constraints(resources); return TRUE; } /* * Choose a color for all resources from highest priority and XML_STRENGTH_VAL_MUST * dependancies to lowest, creating new colors as necessary (returned * as "colors"). * * Some nodes may be colored as a "no_color" meaning that it was unresolvable * given the current node stati and constraints. */ gboolean stage2(GListPtr sorted_rscs, GListPtr sorted_nodes, GListPtr *colors) { - crm_debug("Processing stage 2"); + crm_devel("Processing stage 2"); if(no_color != NULL) { crm_free(no_color->details); crm_free(no_color); } crm_trace("create \"no color\""); no_color = create_color(NULL, NULL, NULL); /* Take (next) highest resource */ slist_iter( lh_resource, resource_t, sorted_rscs, lpc, /* if resource.provisional == FALSE, repeat */ if(lh_resource->provisional == FALSE) { /* already processed this resource */ continue; } color_resource(lh_resource, colors, sorted_rscs); /* next resource */ ); return TRUE; } /* * not sure if this is a good idea or not, but eventually we might like * to utilize as many nodes as possible... and this might be a convienient * hook */ gboolean stage3(GListPtr colors) { - crm_debug("Processing stage 3"); + crm_devel("Processing stage 3"); /* not sure if this is a good idea or not */ if(g_list_length(colors) > max_valid_nodes) { /* we need to consolidate some */ } else if(g_list_length(colors) < max_valid_nodes) { /* we can create a few more */ } return TRUE; } /* * Choose a node for each (if possible) color */ gboolean stage4(GListPtr colors) { - crm_debug("Processing stage 4"); + crm_devel("Processing stage 4"); slist_iter( color, color_t, colors, lpc, - crm_debug("assigning node to color %d", color->id); + crm_devel("assigning node to color %d", color->id); if(color == NULL) { crm_err("NULL color detected"); continue; } else if(color->details->pending == FALSE) { continue; } choose_node_from_list(color); - crm_debug("assigned %s to color %d", + crm_devel("assigned %s to color %d", safe_val5(NULL, color, details, chosen_node, details, uname), color->id); slist_iter( rsc, resource_t, color->details->allocated_resources, lpc2, slist_iter( constraint, rsc_dependancy_t, rsc->rsc_cons, lpc, rsc->fns->rsc_dependancy_lh(constraint); ); ); ); crm_verbose("done"); return TRUE; } /* * Attach nodes to the actions that need to be taken * * Mark actions XML_LRM_ATTR_OPTIONAL if possible (Ie. if the start and stop are * for the same node) * * Mark unrunnable actions */ gboolean stage5(GListPtr resources, GListPtr *ordering_constraints) { slist_iter( rsc, resource_t, resources, lpc, rsc->fns->create_actions(rsc); rsc->fns->internal_constraints(rsc, ordering_constraints); ); return TRUE; } /* * Create dependacies for stonith and shutdown operations */ gboolean stage6(GListPtr *actions, GListPtr *ordering_constraints, GListPtr nodes, GListPtr resources) { action_t *down_op = NULL; action_t *stonith_op = NULL; - crm_debug("Processing stage 6"); + crm_devel("Processing stage 6"); slist_iter( node, node_t, nodes, lpc, if(node->details->shutdown) { crm_info("Scheduling Node %s for shutdown", node->details->uname); down_op = action_new(NULL, shutdown_crm, node); down_op->runnable = TRUE; *actions = g_list_append(*actions, down_op); shutdown_constraints( node, down_op, ordering_constraints); } if(node->details->unclean && stonith_enabled) { crm_warn("Scheduling Node %s for STONITH", node->details->uname); stonith_op = action_new(NULL, stonith_node, NULL); stonith_op->runnable = TRUE; set_xml_property_copy(stonith_op->args, "target", node->details->uname); set_xml_property_copy(stonith_op->args, "target_uuid", node->details->id); if(down_op != NULL) { down_op->failure_is_fatal = FALSE; } *actions = g_list_append(*actions, stonith_op); stonith_constraints(node, stonith_op, down_op, ordering_constraints); } ); return TRUE; } /* * Determin the sets of independant actions and the correct order for the * actions in each set. * * Mark dependancies of un-runnable actions un-runnable * */ gboolean stage7(GListPtr resources, GListPtr actions, GListPtr ordering_constraints) { - crm_debug("Processing stage 7"); + crm_devel("Processing stage 7"); slist_iter( order, order_constraint_t, ordering_constraints, lpc, /* try rsc_action-to-rsc_action */ resource_t *rsc = order->lh_rsc; if(rsc == NULL && order->lh_action) { rsc = order->lh_action->rsc; } if(rsc != NULL) { rsc->fns->rsc_order_lh(rsc, order); continue; } /* try action-to-rsc_action */ /* que off the rh resource */ rsc = order->rh_rsc; if(rsc == NULL && order->rh_action) { rsc = order->rh_action->rsc; } if(rsc != NULL) { rsc->fns->rsc_order_rh(order->lh_action, rsc, order); } else { /* fall back to action-to-action */ order_actions( order->lh_action, order->rh_action, order); } ); update_action_states(actions); return TRUE; } /* * Create a dependancy graph to send to the transitioner (via the CRMd) */ gboolean stage8(GListPtr resources, GListPtr actions, crm_data_t * *graph) { - crm_debug("Processing stage 8"); + crm_devel("Processing stage 8"); *graph = create_xml_node(NULL, XML_TAG_GRAPH); set_xml_property_copy( *graph, "global_timeout", transition_timeout); /* errors... slist_iter(action, action_t, action_list, lpc, if(action->optional == FALSE && action->runnable == FALSE) { print_action("Ignoring", action, TRUE); } ); */ slist_iter( rsc, resource_t, resources, lpc, - crm_debug("processing actions for rsc=%s", rsc->id); + crm_devel("processing actions for rsc=%s", rsc->id); rsc->fns->expand(rsc, graph); ); crm_xml_devel(*graph, "created resource-driven action list"); /* catch any non-resource specific actions */ - crm_debug("processing non-resource actions"); + crm_devel("processing non-resource actions"); slist_iter( action, action_t, actions, lpc, graph_element_from_action(action, graph); ); crm_xml_devel(*graph, "created generic action list"); return TRUE; } gboolean choose_node_from_list(color_t *color) { /* 1. Sort by weight 2. color.chosen_node = highest wieghted node 3. remove color.chosen_node from all other colors */ GListPtr nodes = color->details->candidate_nodes; nodes = g_list_sort(nodes, sort_node_weight); color->details->chosen_node = node_copy((node_t*)g_list_nth_data(nodes, 0)); color->details->pending = FALSE; if(color->details->chosen_node == NULL) { - crm_err("Could not allocate a node for color %d", - color->id); + crm_err("Could not allocate a node for color %d", color->id); return FALSE; } return TRUE; } diff --git a/crm/pengine/unpack.c b/crm/pengine/unpack.c index 3c92eb4f27..d6ea5585f5 100644 --- a/crm/pengine/unpack.c +++ b/crm/pengine/unpack.c @@ -1,1291 +1,1291 @@ -/* $Id: unpack.c,v 1.54 2005/02/15 08:10:37 andrew Exp $ */ +/* $Id: unpack.c,v 1.55 2005/02/19 18:11:04 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 /* for ONLINESTATUS */ #include #include int max_valid_nodes = 0; int order_id = 1; GListPtr agent_defaults = NULL; gboolean stonith_enabled = FALSE; const char* transition_timeout = "60000"; /* 1 minute */ extern const char *dc_uuid; GListPtr match_attrs(const char *attr, const char *op, const char *value, const char *type, GListPtr node_list); gboolean unpack_rsc_to_attr(crm_data_t * xml_obj, GListPtr rsc_list, GListPtr node_list, GListPtr *placement_constraints); gboolean unpack_rsc_to_node(crm_data_t * xml_obj, GListPtr rsc_list, GListPtr node_list, GListPtr *placement_constraints); gboolean unpack_rsc_order( crm_data_t * xml_obj, GListPtr rsc_list, GListPtr *ordering_constraints); gboolean unpack_rsc_dependancy( crm_data_t * xml_obj, GListPtr rsc_list, GListPtr *ordering_constraints); gboolean unpack_rsc_location( crm_data_t * xml_obj, GListPtr rsc_list, GListPtr node_list, GListPtr *ordering_constraints); gboolean unpack_lrm_rsc_state( node_t *node, crm_data_t * lrm_state, GListPtr rsc_list, GListPtr nodes, GListPtr *actions, GListPtr *placement_constraints); gboolean add_node_attrs(crm_data_t * attrs, node_t *node); gboolean unpack_healthy_resource(GListPtr *placement_constraints, GListPtr *actions, crm_data_t * rsc_entry, resource_t *rsc_lh, node_t *node); gboolean unpack_failed_resource(GListPtr *placement_constraints, crm_data_t * rsc_entry, resource_t *rsc_lh, node_t *node); gboolean determine_online_status(crm_data_t * node_state, node_t *this_node); gboolean unpack_lrm_agents(node_t *node, crm_data_t * agent_list); gboolean is_node_unclean(crm_data_t * node_state); gboolean rsc_dependancy_new( const char *id, enum con_strength strength, resource_t *rsc_lh, resource_t *rsc_rh); gboolean create_ordering( const char *id, enum con_strength strength, resource_t *rsc_lh, resource_t *rsc_rh, GListPtr *ordering_constraints); rsc_to_node_t *rsc2node_new( const char *id, resource_t *rsc, double weight, gboolean can_run, node_t *node, GListPtr *placement_constraints); const char *get_agent_param(resource_t *rsc, const char *param); const char *get_agent_param_rsc(resource_t *rsc, const char *param); const void *get_agent_param_metadata(resource_t *rsc, const char *param); const char *get_agent_param_global(resource_t *rsc, const char *param); const char *param_value(crm_data_t * parent, const char *name); gboolean unpack_config(crm_data_t * config) { const char *value = NULL; value = param_value(config, "failed_nodes"); if(safe_str_eq(value, XML_CIB_ATTR_STONITH)) { crm_debug("Enabling STONITH of failed nodes"); stonith_enabled = TRUE; } else { stonith_enabled = FALSE; } value = param_value(config, "transition_timeout"); if(value != NULL) { int tmp = atoi(value); if(tmp > 0) { transition_timeout = value; } else { crm_warn("Invalid value for %s: %s", "transition_timeout", value); } } - crm_debug("%s set to: %s", + crm_devel("%s set to: %s", "transition_timeout", transition_timeout); return TRUE; } const char * param_value(crm_data_t * parent, const char *name) { crm_data_t * a_default = find_entity( parent, XML_CIB_TAG_NVPAIR, name, FALSE); if(a_default == NULL) { crm_warn("Option %s not set", name); return NULL; } return crm_element_value(a_default, XML_NVPAIR_ATTR_VALUE); } const char * get_agent_param(resource_t *rsc, const char *param) { const char *value = NULL; if(param == NULL) { return NULL; } value = get_agent_param_rsc(rsc, param); if(value == NULL) { value = get_agent_param_metadata(rsc, param); } if(value == NULL) { value = get_agent_param_global(rsc, param); } return value; } const char * get_agent_param_rsc(resource_t *rsc, const char *param) { crm_data_t * xml_rsc = rsc->xml; return crm_element_value(xml_rsc, param); } const void * get_agent_param_metadata(resource_t *rsc, const char *param) { return NULL; } const char * get_agent_param_global(resource_t *rsc, const char *param) { const char * value = NULL;/*g_hashtable_lookup(agent_global_defaults, param); */ if(value == NULL) { crm_err("No global value default for %s", param); } return value; } gboolean unpack_global_defaults(crm_data_t * defaults) { return TRUE; } gboolean unpack_nodes(crm_data_t * xml_nodes, GListPtr *nodes) { node_t *new_node = NULL; crm_data_t * attrs = NULL; const char *id = NULL; const char *uname = NULL; const char *type = NULL; crm_verbose("Begining unpack..."); xml_child_iter( xml_nodes, xml_obj, XML_CIB_TAG_NODE, id = crm_element_value(xml_obj, XML_ATTR_ID); uname = crm_element_value(xml_obj, XML_ATTR_UNAME); type = crm_element_value(xml_obj, XML_ATTR_TYPE); crm_verbose("Processing node %s/%s", uname, id); attrs = find_xml_node(xml_obj, "attributes", FALSE); if(id == NULL) { crm_err("Must specify id tag in "); continue; } if(type == NULL) { crm_err("Must specify type tag in "); continue; } crm_malloc(new_node, sizeof(node_t)); if(new_node == NULL) { return FALSE; } new_node->weight = 1.0; new_node->fixed = FALSE; crm_malloc(new_node->details, sizeof(struct node_shared_s)); if(new_node->details == NULL) { crm_free(new_node); return FALSE; } crm_verbose("Creaing node for entry %s/%s", uname, id); new_node->details->id = id; new_node->details->uname = uname; new_node->details->type = node_ping; new_node->details->online = FALSE; new_node->details->unclean = TRUE; /* all nodes are unclean until we've seen their status entry */ new_node->details->shutdown = FALSE; new_node->details->running_rsc = NULL; new_node->details->agents = NULL; new_node->details->attrs = g_hash_table_new( g_str_hash, g_str_equal); if(safe_str_eq(type, "member")) { new_node->details->type = node_member; } add_node_attrs(attrs, new_node); *nodes = g_list_append(*nodes, new_node); crm_verbose("Done with node %s", crm_element_value(xml_obj, XML_ATTR_UNAME)); - crm_debug_action(print_node("Added", new_node, FALSE)); + crm_devel_action(print_node("Added", new_node, FALSE)); ); *nodes = g_list_sort(*nodes, sort_node_weight); return TRUE; } gboolean unpack_resources(crm_data_t * xml_resources, GListPtr *resources, GListPtr *actions, GListPtr *ordering_constraints, GListPtr all_nodes) { crm_verbose("Begining unpack..."); xml_child_iter( xml_resources, xml_obj, NULL, resource_t *new_rsc = NULL; if(common_unpack(xml_obj, &new_rsc)) { *resources = g_list_append(*resources, new_rsc); - crm_debug_action( + crm_devel_action( print_resource("Added", new_rsc, FALSE)); } else { crm_err("Failed unpacking resource %s", crm_element_value(xml_obj, XML_ATTR_ID)); } ); *resources = g_list_sort(*resources, sort_rsc_priority); return TRUE; } gboolean unpack_constraints(crm_data_t * xml_constraints, GListPtr nodes, GListPtr resources, GListPtr *placement_constraints, GListPtr *ordering_constraints) { crm_verbose("Begining unpack..."); xml_child_iter( xml_constraints, xml_obj, NULL, const char *id = crm_element_value(xml_obj, XML_ATTR_ID); if(id == NULL) { crm_err("Constraint <%s...> must have an id", crm_element_name(xml_obj)); continue; } crm_verbose("Processing constraint %s %s", crm_element_name(xml_obj),id); if(safe_str_eq(XML_CONS_TAG_RSC_ORDER, crm_element_name(xml_obj))) { unpack_rsc_order( xml_obj, resources, ordering_constraints); } else if(safe_str_eq(XML_CONS_TAG_RSC_DEPEND, crm_element_name(xml_obj))) { unpack_rsc_dependancy( xml_obj, resources, ordering_constraints); } else if(safe_str_eq(XML_CONS_TAG_RSC_LOCATION, crm_element_name(xml_obj))) { unpack_rsc_location( xml_obj, resources, nodes, placement_constraints); } else { crm_err("Unsupported constraint type: %s", crm_element_name(xml_obj)); } ); return TRUE; } rsc_to_node_t * rsc2node_new(const char *id, resource_t *rsc, double weight, gboolean can, node_t *node, GListPtr *placement_constraints) { rsc_to_node_t *new_con = NULL; if(rsc == NULL || id == NULL) { crm_err("Invalid constraint %s for rsc=%p", crm_str(id), rsc); return NULL; } crm_malloc(new_con, sizeof(rsc_to_node_t)); if(new_con != NULL) { new_con->id = id; new_con->rsc_lh = rsc; new_con->node_list_rh = NULL; new_con->can = can; if(can) { new_con->weight = weight; } else { new_con->weight = -1; } if(node != NULL) { new_con->node_list_rh = g_list_append(NULL, node); } *placement_constraints = g_list_append(*placement_constraints, new_con); } return new_con; } /* remove nodes that are down, stopping */ /* create +ve rsc_to_node constraints between resources and the nodes they are running on */ /* anything else? */ gboolean unpack_status(crm_data_t * status, GListPtr nodes, GListPtr rsc_list, GListPtr *actions, GListPtr *placement_constraints) { const char *uname = NULL; crm_data_t * lrm_rsc = NULL; crm_data_t * lrm_agents = NULL; crm_data_t * attrs = NULL; node_t *this_node = NULL; crm_verbose("Begining unpack"); xml_child_iter( status, node_state, XML_CIB_TAG_STATE, /* id = crm_element_value(node_state, XML_ATTR_ID); */ uname = crm_element_value(node_state, XML_ATTR_UNAME); attrs = find_xml_node(node_state, XML_LRM_TAG_ATTRIBUTES,FALSE); lrm_rsc = find_xml_node(node_state, XML_CIB_TAG_LRM, FALSE); lrm_agents = find_xml_node(lrm_rsc, XML_LRM_TAG_AGENTS, FALSE); lrm_rsc = find_xml_node(lrm_rsc, XML_LRM_TAG_RESOURCES, FALSE); crm_verbose("Processing node %s", uname); this_node = pe_find_node(nodes, uname); if(uname == NULL) { /* error */ continue; } else if(this_node == NULL) { crm_err("Node %s in status section no longer exists", uname); continue; } /* Mark the node as provisionally clean * - at least we have seen it in the current cluster's lifetime */ this_node->details->unclean = FALSE; crm_verbose("Adding runtime node attrs"); add_node_attrs(attrs, this_node); crm_verbose("determining node state"); determine_online_status(node_state, this_node); crm_verbose("Processing lrm resource entries"); unpack_lrm_rsc_state(this_node, lrm_rsc, rsc_list, nodes, actions, placement_constraints); crm_verbose("Processing lrm agents"); unpack_lrm_agents(this_node, lrm_agents); ); return TRUE; } gboolean determine_online_status(crm_data_t * node_state, node_t *this_node) { gboolean online = FALSE; const char *uname = crm_element_value(node_state,XML_ATTR_UNAME); /* const char *state = crm_element_value(node_state,XML_NODE_ATTR_STATE); */ const char *exp_state = crm_element_value(node_state,XML_CIB_ATTR_EXPSTATE); const char *join_state = crm_element_value(node_state,XML_CIB_ATTR_JOINSTATE); const char *crm_state = crm_element_value(node_state,XML_CIB_ATTR_CRMDSTATE); const char *ccm_state = crm_element_value(node_state,XML_CIB_ATTR_INCCM); const char *ha_state = crm_element_value(node_state,XML_CIB_ATTR_HASTATE); const char *shutdown = crm_element_value(node_state,XML_CIB_ATTR_SHUTDOWN); const char *unclean = NULL;/*crm_element_value(node_state,XML_CIB_ATTR_STONITH); */ if(safe_str_eq(join_state, CRMD_JOINSTATE_MEMBER) && safe_str_eq(ccm_state, XML_BOOLEAN_YES) && (ha_state == NULL || safe_str_eq(ha_state, ACTIVESTATUS)) && safe_str_eq(crm_state, ONLINESTATUS) && shutdown == NULL) { if(this_node != NULL) { this_node->details->online = TRUE; } crm_debug("Node %s is online", uname); online = TRUE; } else if(this_node != NULL) { /* remove node from contention */ this_node->weight = -1; this_node->fixed = TRUE; crm_verbose("join_state=%s, expected=%s, shutdown=%s", crm_str(join_state), crm_str(exp_state), crm_str(shutdown)); if(unclean != NULL) { this_node->details->unclean = TRUE; } else if(is_node_unclean(node_state)) { /* report and or take remedial action */ this_node->details->unclean = TRUE; } if(shutdown != NULL) { this_node->details->shutdown = TRUE; } if(this_node->details->unclean) { crm_warn("Node %s is unclean", uname); } if(this_node->details->shutdown) { crm_debug("Node %s is due for shutdown", uname); } } return online; } gboolean is_node_unclean(crm_data_t * node_state) { /* const char *state = crm_element_value(node_state,XML_NODE_ATTR_STATE); */ const char *uname = crm_element_value(node_state,XML_ATTR_UNAME); const char *exp_state = crm_element_value(node_state,XML_CIB_ATTR_EXPSTATE); const char *join_state = crm_element_value(node_state,XML_CIB_ATTR_JOINSTATE); const char *crm_state = crm_element_value(node_state,XML_CIB_ATTR_CRMDSTATE); const char *ha_state = crm_element_value(node_state,XML_CIB_ATTR_HASTATE); const char *ccm_state = crm_element_value(node_state,XML_CIB_ATTR_INCCM); if(safe_str_eq(exp_state, CRMD_STATE_INACTIVE)) { crm_debug("Node %s is safely inactive", uname); return FALSE; /* do an actual calculation once STONITH is available */ } else if(safe_str_neq(exp_state, CRMD_JOINSTATE_DOWN)) { if(safe_str_eq(crm_state, OFFLINESTATUS) || (ha_state != NULL && safe_str_eq(ha_state, DEADSTATUS)) || safe_str_eq(join_state, CRMD_JOINSTATE_DOWN) || safe_str_eq(ccm_state, XML_BOOLEAN_NO)) { crm_warn("Node %s is un-expectedly down", uname); return TRUE; } crm_debug("Node %s: ha=%s, join=%s, crm=%s, ccm=%s", uname, crm_str(ha_state), crm_str(join_state), crm_str(crm_state), crm_str(ccm_state)); } else { crm_debug("Node %s was expected to be down", uname); } return FALSE; } gboolean unpack_lrm_agents(node_t *node, crm_data_t * agent_list) { /* if the agent is not listed, remove the node from * the resource's list of allowed_nodes */ lrm_agent_t *agent = NULL; const char *version = NULL; if(agent_list == NULL) { return FALSE; } xml_child_iter( agent_list, xml_agent, XML_LRM_TAG_AGENT, crm_malloc(agent, sizeof(lrm_agent_t)); if(agent == NULL) { continue; } agent->class = crm_element_value(xml_agent, XML_AGENT_ATTR_CLASS); agent->type = crm_element_value(xml_agent, XML_ATTR_TYPE); version = crm_element_value(xml_agent, XML_ATTR_VERSION); agent->version = version?version:"0.0"; crm_trace("Adding agent %s/%s v%s to node %s", agent->class, agent->type, agent->version, node->details->uname); node->details->agents = g_list_append( node->details->agents, agent); ); return TRUE; } gboolean unpack_lrm_rsc_state(node_t *node, crm_data_t * lrm_rsc, GListPtr rsc_list, GListPtr nodes, GListPtr *actions, GListPtr *placement_constraints) { const char *rsc_id = NULL; const char *node_id = NULL; const char *rsc_state = NULL; const char *op_status = NULL; const char *last_rc = NULL; const char *last_op = NULL; resource_t *rsc_lh = NULL; op_status_t action_status_i = LRM_OP_ERROR; xml_child_iter( lrm_rsc, rsc_entry, XML_LRM_TAG_RESOURCE, rsc_id = crm_element_value(rsc_entry, XML_ATTR_ID); node_id = crm_element_value(rsc_entry, XML_LRM_ATTR_TARGET); rsc_state = crm_element_value(rsc_entry, XML_LRM_ATTR_RSCSTATE); op_status = crm_element_value(rsc_entry, XML_LRM_ATTR_OPSTATUS); last_rc = crm_element_value(rsc_entry, XML_LRM_ATTR_RC); last_op = crm_element_value(rsc_entry, XML_LRM_ATTR_LASTOP); rsc_lh = pe_find_resource(rsc_list, rsc_id); crm_verbose("[%s] Processing %s on %s (%s)", crm_element_name(rsc_entry), rsc_id, node_id, rsc_state); if(rsc_lh == NULL) { crm_err("Could not find a match for resource" " %s in %s's status section", rsc_id, node_id); continue; } else if(op_status == NULL) { crm_err("Invalid resource status entry for %s in %s", rsc_id, node_id); continue; } action_status_i = atoi(op_status); if(node->details->unclean) { crm_info("Node %s (where %s is running) is unclean." "Further action depends on the value of %s", node->details->uname, rsc_lh->id, XML_RSC_ATTR_STOPFAIL); /* map the status to an error and then handle as a * failed resource. */ action_status_i = LRM_OP_ERROR; } else if(action_status_i == -1) { /* * TODO: this may need some more thought * Some cases: * - PE reinvoked with pending action that will succeed * - PE reinvoked with pending action that will fail * - After DC election * - After startup * * pending start - required start * pending stop - required stop * pending on unavailable node - stonith * * For now this should do */ if(safe_str_eq(last_op, "stop")) { /* map this to a timeout so it is re-issued */ action_status_i = LRM_OP_TIMEOUT; } else { /* map this to a "done" so it is not marked * as failed, then make sure it is re-issued */ action_new(rsc_lh, start_rsc, NULL); action_status_i = LRM_OP_DONE; } } switch(action_status_i) { case LRM_OP_DONE: unpack_healthy_resource( placement_constraints, actions, rsc_entry, rsc_lh,node); break; case LRM_OP_ERROR: case LRM_OP_TIMEOUT: case LRM_OP_NOTSUPPORTED: unpack_failed_resource(placement_constraints, rsc_entry, rsc_lh,node); break; case LRM_OP_CANCELLED: /* do nothing?? */ crm_warn("Dont know what to do for cancelled ops yet"); break; } ); return TRUE; } gboolean unpack_failed_resource(GListPtr *placement_constraints, crm_data_t * rsc_entry, resource_t *rsc_lh, node_t *node) { const char *last_op = crm_element_value(rsc_entry, XML_LRM_ATTR_LASTOP); - crm_debug("Unpacking failed action %s on %s", last_op, rsc_lh->id); + crm_devel("Unpacking failed action %s on %s", last_op, rsc_lh->id); /* make sure we dont allocate the resource here again*/ rsc2node_new("dont_run__generated", rsc_lh, -1.0, FALSE, node, placement_constraints); if(safe_str_eq(last_op, "start")) { /* the resource is not actually running... nothing more to do*/ return TRUE; } switch(rsc_lh->stopfail_type) { case pesf_stonith: /* treat it as if it is still running * but also mark the node as unclean */ native_add_running(rsc_lh, node); node->details->running_rsc = g_list_append( node->details->running_rsc, rsc_lh); if(node->details->online) { node->details->shutdown = TRUE; } node->details->unclean = TRUE; break; case pesf_block: /* let this depend on the stop action which will fail * but make sure the transition continues... */ native_add_running(rsc_lh, node); node->details->running_rsc = g_list_append( node->details->running_rsc, rsc_lh); /* rsc_lh->stop->timeout = NULL; /\* wait forever *\/ */ break; case pesf_ignore: /* pretend nothing happened */ break; } return TRUE; } gboolean unpack_healthy_resource(GListPtr *placement_constraints, GListPtr *actions, crm_data_t * rsc_entry, resource_t *rsc_lh, node_t *node) { const char *last_op = crm_element_value(rsc_entry, XML_LRM_ATTR_LASTOP); - crm_debug("Unpacking healthy action %s on %s", last_op, rsc_lh->id); + crm_devel("Unpacking healthy action %s on %s", last_op, rsc_lh->id); if(safe_str_neq(last_op, "stop")) { /* create the link between this node and the rsc */ crm_verbose("Setting cur_node = %s for rsc = %s", node->details->uname, rsc_lh->id); native_add_running(rsc_lh, node); node->details->running_rsc = g_list_append( node->details->running_rsc, rsc_lh); } return TRUE; } gboolean rsc_dependancy_new(const char *id, enum con_strength strength, resource_t *rsc_lh, resource_t *rsc_rh) { rsc_dependancy_t *new_con = NULL; rsc_dependancy_t *inverted_con = NULL; if(rsc_lh == NULL || rsc_rh == NULL){ /* error */ return FALSE; } crm_malloc(new_con, sizeof(rsc_dependancy_t)); if(new_con != NULL) { new_con->id = id; new_con->rsc_lh = rsc_lh; new_con->rsc_rh = rsc_rh; new_con->strength = strength; inverted_con = invert_constraint(new_con); - crm_debug("Adding constraint %s (%p) to %s", + crm_devel("Adding constraint %s (%p) to %s", new_con->id, new_con, rsc_lh->id); rsc_lh->rsc_cons = g_list_insert_sorted( rsc_lh->rsc_cons, new_con, sort_cons_strength); - crm_debug("Adding constraint %s (%p) to %s", + crm_devel("Adding constraint %s (%p) to %s", inverted_con->id, inverted_con, rsc_rh->id); rsc_rh->rsc_cons = g_list_insert_sorted( rsc_rh->rsc_cons, inverted_con, sort_cons_strength); } else { return FALSE; } return TRUE; } gboolean order_new(resource_t *lh_rsc, enum action_tasks lh_action_task, action_t *lh_action, resource_t *rh_rsc, enum action_tasks rh_action_task, action_t *rh_action, enum con_strength strength, GListPtr *ordering_constraints) { order_constraint_t *order = NULL; if((lh_action == NULL && lh_rsc == NULL) || (rh_action == NULL && rh_rsc == NULL) || ordering_constraints == NULL){ crm_err("Invalid inputs lh_rsc=%p, lh_a=%p," " rh_rsc=%p, rh_a=%p, l=%p", lh_rsc, lh_action, rh_rsc, rh_action, ordering_constraints); return FALSE; } crm_malloc(order, sizeof(order_constraint_t)); if(order == NULL) { return FALSE; } order->id = order_id++; order->strength = strength; order->lh_rsc = lh_rsc; order->rh_rsc = rh_rsc; order->lh_action = lh_action; order->rh_action = rh_action; order->lh_action_task = lh_action_task; order->rh_action_task = rh_action_task; *ordering_constraints = g_list_append( *ordering_constraints, order); if(lh_rsc != NULL && rh_rsc != NULL) { - crm_debug("Created ordering constraint %d (%s):" + crm_devel("Created ordering constraint %d (%s):" " %s/%s before %s/%s", order->id, strength2text(order->strength), lh_rsc->id, task2text(lh_action_task), rh_rsc->id, task2text(rh_action_task)); } else if(lh_rsc != NULL) { - crm_debug("Created ordering constraint %d (%s):" + crm_devel("Created ordering constraint %d (%s):" " %s/%s before action %d (%s)", order->id, strength2text(order->strength), lh_rsc->id, task2text(lh_action_task), rh_action->id, task2text(rh_action_task)); } else if(rh_rsc != NULL) { - crm_debug("Created ordering constraint %d (%s):" + crm_devel("Created ordering constraint %d (%s):" " action %d (%s) before %s/%s", order->id, strength2text(order->strength), lh_action->id, task2text(lh_action_task), rh_rsc->id, task2text(rh_action_task)); } else { - crm_debug("Created ordering constraint %d (%s):" + crm_devel("Created ordering constraint %d (%s):" " action %d (%s) before action %d (%s)", order->id, strength2text(order->strength), lh_action->id, task2text(lh_action_task), rh_action->id, task2text(rh_action_task)); } return TRUE; } gboolean unpack_rsc_dependancy(crm_data_t * xml_obj, GListPtr rsc_list, GListPtr *ordering_constraints) { enum con_strength strength_e = pecs_ignore; const char *id_lh = crm_element_value(xml_obj, XML_CONS_ATTR_FROM); const char *id = crm_element_value(xml_obj, XML_ATTR_ID); const char *id_rh = crm_element_value(xml_obj, XML_CONS_ATTR_TO); const char *type = crm_element_value(xml_obj, XML_ATTR_TYPE); resource_t *rsc_lh = pe_find_resource(rsc_list, id_lh); resource_t *rsc_rh = pe_find_resource(rsc_list, id_rh); if(rsc_lh == NULL) { crm_err("No resource (con=%s, rsc=%s)", id, id_lh); return FALSE; } else if(rsc_rh == NULL) { crm_err("No resource (con=%s, rsc=%s)", id, id_rh); return FALSE; } if(safe_str_eq(type, XML_STRENGTH_VAL_MUST)) { strength_e = pecs_must; } else if(safe_str_eq(type, XML_STRENGTH_VAL_SHOULD)) { crm_err("Type %s is no longer supported", type); strength_e = pecs_must; } else if(safe_str_eq(type, XML_STRENGTH_VAL_SHOULDNOT)) { crm_err("Type %s is no longer supported", type); strength_e = pecs_must_not; } else if(safe_str_eq(type, XML_STRENGTH_VAL_MUSTNOT)) { strength_e = pecs_must_not; } else { crm_err("Unknown value for %s: %s", XML_ATTR_TYPE, type); return FALSE; } return rsc_dependancy_new(id, strength_e, rsc_lh, rsc_rh); } gboolean unpack_rsc_order( crm_data_t * xml_obj, GListPtr rsc_list, GListPtr *ordering_constraints) { gboolean symetrical_bool = TRUE; gboolean action_is_start = TRUE; gboolean type_is_after = TRUE; const char *id = crm_element_value(xml_obj, XML_ATTR_ID); const char *id_lh = crm_element_value(xml_obj, XML_CONS_ATTR_FROM); const char *id_rh = crm_element_value(xml_obj, XML_CONS_ATTR_TO); const char *action = crm_element_value(xml_obj, XML_CONS_ATTR_ACTION); const char *symetrical = crm_element_value(xml_obj, XML_CONS_ATTR_SYMETRICAL); const char *type = crm_element_value(xml_obj, XML_ATTR_TYPE); resource_t *rsc_lh = pe_find_resource(rsc_list, id_lh); resource_t *rsc_rh = pe_find_resource(rsc_list, id_rh); if(xml_obj == NULL) { crm_err("No constraint object to process."); return FALSE; } else if(id == NULL) { crm_err("%s constraint must have an id", crm_element_name(xml_obj)); return FALSE; } else if(rsc_lh == NULL || rsc_rh == NULL) { crm_err("Constraint %s needs two sides lh: %p rh: %p" " (NULL indicates missing side)", id, rsc_lh, rsc_rh); return FALSE; } if(safe_str_eq(symetrical, XML_BOOLEAN_FALSE)) { symetrical_bool = FALSE; } if(safe_str_eq(type, "before")) { type_is_after = FALSE; } if(safe_str_eq(action, CRMD_RSCSTATE_STOP)) { action_is_start = FALSE; } #if 1 if((type_is_after && action_is_start) || (type_is_after == FALSE && action_is_start == FALSE)){ if(symetrical_bool || action_is_start == FALSE) { order_new(rsc_lh, stop_rsc, NULL, rsc_rh, stop_rsc, NULL, pecs_startstop, ordering_constraints); } if(symetrical_bool || action_is_start) { order_new(rsc_rh, start_rsc, NULL, rsc_lh, start_rsc, NULL, pecs_startstop, ordering_constraints); } } else { if(symetrical_bool || action_is_start == FALSE) { order_new(rsc_rh, stop_rsc, NULL, rsc_lh, stop_rsc, NULL, pecs_startstop, ordering_constraints); } if(symetrical_bool || action_is_start) { order_new(rsc_lh, start_rsc, NULL, rsc_rh, start_rsc, NULL, pecs_startstop, ordering_constraints); } } #else if(type_is_after) { order_new(rsc_lh, stop_rsc, NULL, rsc_rh, stop_rsc, NULL, pecs_startstop, ordering_constraints); order_new(rsc_rh, start_rsc, NULL, rsc_lh, start_rsc, NULL, pecs_startstop, ordering_constraints); } else { order_new(rsc_rh, stop_rsc, NULL, rsc_lh, stop_rsc, NULL, pecs_startstop, ordering_constraints); order_new(rsc_lh, start_rsc, NULL, rsc_rh, start_rsc, NULL, pecs_startstop, ordering_constraints); } #endif return TRUE; } /* do NOT free the nodes returned here */ GListPtr match_attrs(const char *attr, const char *op, const char *value, const char *type, GListPtr node_list) { GListPtr result = NULL; if(attr == NULL || op == NULL) { crm_err("Invlaid attribute or operation in expression" " (\'%s\' \'%s\' \'%s\')", crm_str(attr), crm_str(op), crm_str(value)); return NULL; } slist_iter( node, node_t, node_list, lpc, gboolean accept = FALSE; int cmp = 0; const char *h_val = (const char*)g_hash_table_lookup( node->details->attrs, attr); if(value != NULL && h_val != NULL) { if(type == NULL || (safe_str_eq(type, "string"))) { cmp = strcmp(h_val, value); } else if(safe_str_eq(type, "number")) { float h_val_f = atof(h_val); float value_f = atof(value); if(h_val_f < value_f) { cmp = -1; } else if(h_val_f > value_f) { cmp = 1; } else { cmp = 0; } } else if(safe_str_eq(type, "version")) { cmp = compare_version(h_val, value); } } else if(value == NULL && h_val == NULL) { cmp = 0; } else if(value == NULL) { cmp = 1; } else { cmp = -1; } if(safe_str_eq(op, "exists")) { if(h_val != NULL) accept = TRUE; } else if(safe_str_eq(op, "not_exists")) { if(h_val == NULL) accept = TRUE; } else if(safe_str_eq(op, "running")) { GListPtr rsc_list = node->details->running_rsc; slist_iter( rsc, resource_t, rsc_list, lpc2, if(safe_str_eq(rsc->id, attr)) { accept = TRUE; } ); } else if(safe_str_eq(op, "not_running")) { GListPtr rsc_list = node->details->running_rsc; accept = TRUE; slist_iter( rsc, resource_t, rsc_list, lpc2, if(safe_str_eq(rsc->id, attr)) { accept = FALSE; break; } ); } else if(safe_str_eq(op, "eq")) { if((h_val == value) || cmp == 0) accept = TRUE; } else if(safe_str_eq(op, "ne")) { if((h_val == NULL && value != NULL) || (h_val != NULL && value == NULL) || cmp != 0) accept = TRUE; } else if(value == NULL || h_val == NULL) { /* the comparision is meaningless from this point on */ accept = FALSE; } else if(safe_str_eq(op, "lt")) { if(cmp < 0) accept = TRUE; } else if(safe_str_eq(op, "lte")) { if(cmp <= 0) accept = TRUE; } else if(safe_str_eq(op, "gt")) { if(cmp > 0) accept = TRUE; } else if(safe_str_eq(op, "gte")) { if(cmp >= 0) accept = TRUE; } if(accept) { crm_trace("node %s matched", node->details->uname); result = g_list_append(result, node); } else { crm_trace("node %s did not match", node->details->uname); } ); return result; } gboolean add_node_attrs(crm_data_t * attrs, node_t *node) { const char *name = NULL; const char *value = NULL; xml_child_iter( attrs, attr, NULL, name = crm_element_value(attr, XML_NVPAIR_ATTR_NAME); value = crm_element_value(attr, XML_NVPAIR_ATTR_VALUE); if(name != NULL && value != NULL && safe_val(NULL, node, details) != NULL) { crm_verbose("Adding %s => %s", name, value); /* this is frustrating... no way to pass in const * keys or values yet docs say: * Note: If keys and/or values are dynamically * allocated, you should free them first. */ g_hash_table_insert(node->details->attrs, crm_strdup(name), crm_strdup(value)); } ); g_hash_table_insert(node->details->attrs, crm_strdup(XML_ATTR_UNAME), crm_strdup(node->details->uname)); g_hash_table_insert(node->details->attrs, crm_strdup(XML_ATTR_ID), crm_strdup(node->details->id)); if(safe_str_eq(node->details->id, dc_uuid)) { node->details->is_dc = TRUE; g_hash_table_insert(node->details->attrs, crm_strdup(XML_ATTR_DC), crm_strdup(XML_BOOLEAN_TRUE)); } else { g_hash_table_insert(node->details->attrs, crm_strdup(XML_ATTR_DC), crm_strdup(XML_BOOLEAN_FALSE)); } return TRUE; } gboolean unpack_rsc_location( crm_data_t * xml_obj, GListPtr rsc_list, GListPtr node_list, GListPtr *placement_constraints) { /* ... Translation: Further translation: */ gboolean were_rules = FALSE; const char *id_lh = crm_element_value(xml_obj, "rsc"); const char *id = crm_element_value(xml_obj, XML_ATTR_ID); resource_t *rsc_lh = pe_find_resource(rsc_list, id_lh); if(rsc_lh == NULL) { crm_warn("No resource (con=%s, rsc=%s)", id, id_lh); return FALSE; } xml_child_iter( xml_obj, rule, XML_TAG_RULE, gboolean first_expr = TRUE; gboolean can_run = FALSE; gboolean do_and = TRUE; gboolean rule_has_expressions; const char *rule_id = crm_element_value(rule, XML_ATTR_ID); const char *score = crm_element_value(rule, XML_RULE_ATTR_SCORE); const char *result = crm_element_value(rule, XML_RULE_ATTR_RESULT); const char *boolean = crm_element_value(rule, XML_RULE_ATTR_BOOLEAN_OP); GListPtr match_L = NULL; GListPtr old_list = NULL; float score_f = atof(score?score:"0.0"); rsc_to_node_t *new_con = NULL; were_rules = TRUE; if(safe_str_eq(boolean, "or")) { do_and = FALSE; } if(result == NULL || (safe_str_eq(result, "can"))) { can_run = TRUE; } new_con = rsc2node_new(rule_id, rsc_lh, score_f, can_run, NULL, placement_constraints); if(new_con == NULL) { continue; } rule_has_expressions = FALSE; xml_child_iter( rule, expr, XML_TAG_EXPRESSION, const char *attr = crm_element_value( expr, XML_EXPR_ATTR_ATTRIBUTE); const char *op = crm_element_value( expr, XML_EXPR_ATTR_OPERATION); const char *value = crm_element_value( expr, XML_EXPR_ATTR_VALUE); const char *type = crm_element_value( expr, XML_EXPR_ATTR_TYPE); rule_has_expressions = TRUE; crm_trace("processing expression: %s", crm_element_value(expr, XML_ATTR_ID)); match_L = match_attrs( attr, op, value, type, node_list); if(first_expr) { new_con->node_list_rh = node_list_dup( match_L, FALSE); first_expr = FALSE; continue; } old_list = new_con->node_list_rh; if(do_and) { crm_trace("do_and"); new_con->node_list_rh = node_list_and( old_list, match_L, FALSE); } else { crm_trace("do_or"); new_con->node_list_rh = node_list_or( old_list, match_L, FALSE); } pe_free_shallow_adv(match_L, FALSE); pe_free_shallow_adv(old_list, TRUE); ); if(rule_has_expressions == FALSE) { /* feels like a hack */ - crm_debug("Rule %s had no expressions," + crm_devel("Rule %s had no expressions," " adding all nodes", crm_element_value(rule, XML_ATTR_ID)); new_con->node_list_rh = node_list_dup(node_list,FALSE); } if(new_con->node_list_rh == NULL) { crm_warn("No matching nodes for constraint/rule %s/%s", id, crm_element_value(rule, XML_ATTR_ID)); } - crm_debug_action(print_rsc_to_node("Added", new_con, FALSE)); + crm_devel_action(print_rsc_to_node("Added", new_con, FALSE)); ); if(were_rules == FALSE) { crm_err("no rules for constraint %s", id); } return TRUE; } diff --git a/crm/pengine/utils.c b/crm/pengine/utils.c index 8efca1f75d..8965c707b5 100644 --- a/crm/pengine/utils.c +++ b/crm/pengine/utils.c @@ -1,1139 +1,1142 @@ -/* $Id: utils.c,v 1.54 2005/02/18 10:32:37 andrew Exp $ */ +/* $Id: utils.c,v 1.55 2005/02/19 18:11:04 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 int action_id = 1; void print_str_str(gpointer key, gpointer value, gpointer user_data); gboolean ghash_free_str_str(gpointer key, gpointer value, gpointer user_data); gboolean node_merge_weights(node_t *node, node_t *with); /* only for rsc_dependancy constraints */ rsc_dependancy_t * invert_constraint(rsc_dependancy_t *constraint) { rsc_dependancy_t *inverted_con = NULL; crm_verbose("Inverting constraint"); if(constraint == NULL) { crm_err("Cannot invert NULL constraint"); return NULL; } crm_malloc(inverted_con, sizeof(rsc_dependancy_t)); if(inverted_con == NULL) { return NULL; } inverted_con->id = crm_strdup(constraint->id); inverted_con->strength = constraint->strength; /* swap the direction */ inverted_con->rsc_lh = constraint->rsc_rh; inverted_con->rsc_rh = constraint->rsc_lh; - crm_debug_action( + crm_devel_action( print_rsc_dependancy("Inverted constraint", inverted_con, FALSE)); return inverted_con; } /* are the contents of list1 and list2 equal * nodes with weight < 0 are ignored if filter == TRUE * * slow but linear * */ gboolean node_list_eq(GListPtr list1, GListPtr list2, gboolean filter) { node_t *other_node; GListPtr lhs = list1; GListPtr rhs = list2; slist_iter( node, node_t, lhs, lpc, if(node == NULL || (filter && node->weight < 0)) { continue; } other_node = (node_t*) pe_find_node(rhs, node->details->uname); if(other_node == NULL || other_node->weight < 0) { return FALSE; } ); lhs = list2; rhs = list1; slist_iter( node, node_t, lhs, lpc, if(node == NULL || (filter && node->weight < 0)) { continue; } other_node = (node_t*) pe_find_node(rhs, node->details->uname); if(other_node == NULL || other_node->weight < 0) { return FALSE; } ); return TRUE; } /* the intersection of list1 and list2 */ GListPtr node_list_and(GListPtr list1, GListPtr list2, gboolean filter) { GListPtr result = NULL; int lpc = 0; for(lpc = 0; lpc < g_list_length(list1); lpc++) { node_t *node = (node_t*)g_list_nth_data(list1, lpc); node_t *new_node = node_copy(node); node_t *other_node = pe_find_node(list2, node->details->uname); if(node_merge_weights(new_node, other_node) == FALSE) { crm_free(new_node); } else if(filter && new_node->weight < 0) { crm_free(new_node); } else { result = g_list_append(result, new_node); } } return result; } gboolean node_merge_weights(node_t *node, node_t *with) { if(node == NULL || with == NULL) { return FALSE; } else if(node->weight < 0 || with->weight < 0) { node->weight = -1; } else if(node->weight < with->weight) { node->weight = with->weight; } return TRUE; } /* list1 - list2 */ GListPtr node_list_minus(GListPtr list1, GListPtr list2, gboolean filter) { GListPtr result = NULL; slist_iter( node, node_t, list1, lpc, node_t *other_node = pe_find_node(list2, node->details->uname); node_t *new_node = NULL; if(node == NULL || other_node != NULL || (filter && node->weight < 0)) { continue; } new_node = node_copy(node); result = g_list_append(result, new_node); ); crm_verbose("Minus result len: %d", g_list_length(result)); return result; } /* list1 + list2 - (intersection of list1 and list2) */ GListPtr node_list_xor(GListPtr list1, GListPtr list2, gboolean filter) { GListPtr result = NULL; slist_iter( node, node_t, list1, lpc, node_t *new_node = NULL; node_t *other_node = (node_t*) pe_find_node(list2, node->details->uname); if(node == NULL || other_node != NULL || (filter && node->weight < 0)) { continue; } new_node = node_copy(node); result = g_list_append(result, new_node); ); slist_iter( node, node_t, list2, lpc, node_t *new_node = NULL; node_t *other_node = (node_t*) pe_find_node(list1, node->details->uname); if(node == NULL || other_node != NULL || (filter && node->weight < 0)) { continue; } new_node = node_copy(node); result = g_list_append(result, new_node); ); crm_verbose("Xor result len: %d", g_list_length(result)); return result; } GListPtr node_list_or(GListPtr list1, GListPtr list2, gboolean filter) { node_t *other_node = NULL; GListPtr result = NULL; result = node_list_dup(list1, filter); slist_iter( node, node_t, list2, lpc, if(node == NULL) { continue; } other_node = (node_t*)pe_find_node( result, node->details->uname); if(other_node != NULL) { node_merge_weights(other_node, node); if(filter && node->weight < 0) { /* TODO: remove and free other_node */ } } else if(filter && node->weight < 0) { } else { node_t *new_node = node_copy(node); result = g_list_append(result, new_node); } ); return result; } GListPtr node_list_dup(GListPtr list1, gboolean filter) { GListPtr result = NULL; slist_iter( this_node, node_t, list1, lpc, node_t *new_node = NULL; if(filter && this_node->weight < 0) { continue; } new_node = node_copy(this_node); if(new_node != NULL) { result = g_list_append(result, new_node); } ); return result; } node_t * node_copy(node_t *this_node) { node_t *new_node = NULL; + CRM_DEV_ASSERT(this_node != NULL); if(this_node == NULL) { crm_err("Failed copy of node."); return NULL; } crm_malloc(new_node, sizeof(node_t)); + CRM_DEV_ASSERT(new_node != NULL); if(new_node == NULL) { return NULL; } crm_trace("Copying %p (%s) to %p", this_node, this_node->details->uname, new_node); new_node->weight = this_node->weight; new_node->fixed = this_node->fixed; new_node->details = this_node->details; return new_node; } static int color_id = 0; /* * Create a new color with the contents of "nodes" as the list of * possible nodes that resources with this color can be run on. * * Typically, when creating a color you will provide the node list from * the resource you will first assign the color to. * * If "colors" != NULL, it will be added to that list * If "resources" != NULL, it will be added to every provisional resource * in that list */ color_t * create_color(GListPtr *colors, resource_t *resource, GListPtr node_list) { color_t *new_color = NULL; crm_trace("Creating color"); crm_malloc(new_color, sizeof(color_t)); if(new_color == NULL) { return NULL; } new_color->id = color_id++; new_color->local_weight = 1.0; crm_trace("Creating color details"); crm_malloc(new_color->details, sizeof(struct color_shared_s)); if(new_color->details == NULL) { crm_free(new_color); return NULL; } new_color->details->id = new_color->id; new_color->details->highest_priority = -1; new_color->details->chosen_node = NULL; new_color->details->candidate_nodes = NULL; new_color->details->allocated_resources = NULL; new_color->details->pending = TRUE; if(resource != NULL) { crm_trace("populating node list"); new_color->details->highest_priority = resource->priority; new_color->details->candidate_nodes = node_list_dup(node_list, TRUE); } - crm_debug_action(print_color("Created color", new_color, TRUE)); + crm_devel_action(print_color("Created color", new_color, TRUE)); if(colors != NULL) { *colors = g_list_append(*colors, new_color); } return new_color; } color_t * copy_color(color_t *a_color) { color_t *color_copy = NULL; if(a_color == NULL) { crm_err("Cannot copy NULL"); return NULL; } crm_malloc(color_copy, sizeof(color_t)); if(color_copy != NULL) { color_copy->id = a_color->id; color_copy->details = a_color->details; color_copy->local_weight = 1.0; } return color_copy; } resource_t * pe_find_resource(GListPtr rsc_list, const char *id) { int lpc = 0; resource_t *rsc = NULL; resource_t *child_rsc = NULL; + crm_devel("Looking for %s in %d objects", id, g_list_length(rsc_list)); for(lpc = 0; lpc < g_list_length(rsc_list); lpc++) { rsc = g_list_nth_data(rsc_list, lpc); if(rsc != NULL && safe_str_eq(rsc->id, id)){ - crm_debug("Found a match for %s", id); + crm_devel("Found a match for %s", id); return rsc; } } for(lpc = 0; lpc < g_list_length(rsc_list); lpc++) { rsc = g_list_nth_data(rsc_list, lpc); child_rsc = rsc->fns->find_child(rsc, id); if(child_rsc != NULL) { - crm_debug("Found a match for %s in %s", + crm_devel("Found a match for %s in %s", id, rsc->id); return child_rsc; } } /* error */ return NULL; } node_t * pe_find_node(GListPtr nodes, const char *uname) { int lpc = 0; node_t *node = NULL; for(lpc = 0; lpc < g_list_length(nodes); lpc++) { node = g_list_nth_data(nodes, lpc); if(node != NULL && safe_str_eq(node->details->uname, uname)) { return node; } } /* error */ return NULL; } node_t * pe_find_node_id(GListPtr nodes, const char *id) { int lpc = 0; node_t *node = NULL; for(lpc = 0; lpc < g_list_length(nodes); lpc++) { node = g_list_nth_data(nodes, lpc); if(safe_str_eq(node->details->id, id)) { return node; } } /* error */ return NULL; } gint gslist_color_compare(gconstpointer a, gconstpointer b); color_t * find_color(GListPtr candidate_colors, color_t *other_color) { GListPtr tmp = g_list_find_custom(candidate_colors, other_color, gslist_color_compare); if(tmp != NULL) { return (color_t *)tmp->data; } return NULL; } gint gslist_color_compare(gconstpointer a, gconstpointer b) { const color_t *color_a = (const color_t*)a; const color_t *color_b = (const color_t*)b; /* crm_trace("%d vs. %d", a?color_a->id:-2, b?color_b->id:-2); */ if(a == b) { return 0; } else if(a == NULL || b == NULL) { return 1; } else if(color_a->id == color_b->id) { return 0; } return 1; } gint sort_rsc_priority(gconstpointer a, gconstpointer b) { const resource_t *resource1 = (const resource_t*)a; const resource_t *resource2 = (const resource_t*)b; if(a == NULL) { return 1; } if(b == NULL) { return -1; } if(resource1->priority > resource2->priority) { return -1; } if(resource1->priority < resource2->priority) { return 1; } return 0; } gint sort_cons_strength(gconstpointer a, gconstpointer b) { const rsc_dependancy_t *rsc_constraint1 = (const rsc_dependancy_t*)a; const rsc_dependancy_t *rsc_constraint2 = (const rsc_dependancy_t*)b; if(a == NULL) { return 1; } if(b == NULL) { return -1; } if(rsc_constraint1->strength > rsc_constraint2->strength) { return 1; } if(rsc_constraint1->strength < rsc_constraint2->strength) { return -1; } return 0; } gint sort_color_weight(gconstpointer a, gconstpointer b) { const color_t *color1 = (const color_t*)a; const color_t *color2 = (const color_t*)b; if(a == NULL) { return 1; } if(b == NULL) { return -1; } if(color1->local_weight > color2->local_weight) { return -1; } if(color1->local_weight < color2->local_weight) { return 1; } return 0; } gint sort_node_weight(gconstpointer a, gconstpointer b) { const node_t *node1 = (const node_t*)a; const node_t *node2 = (const node_t*)b; if(a == NULL) { return 1; } if(b == NULL) { return -1; } if(node1->weight > node2->weight) { return -1; } if(node1->weight < node2->weight) { return 1; } return 0; } action_t * action_new(resource_t *rsc, enum action_tasks task, node_t *on_node) { action_t *action = NULL; GListPtr possible_matches = NULL; if(rsc != NULL) { possible_matches = find_actions(rsc->actions, task, on_node); } if(on_node != NULL && on_node->details->unclean) { crm_warn("Not creating action %s for %s because %s is unclean", task2text(task), rsc?rsc->id:"", on_node->details->id); } if(on_node != NULL && on_node->details->unclean) { crm_warn("Not creating action %s for %s because %s is unclean", task2text(task), rsc?rsc->id:"", on_node->details->id); } if(possible_matches != NULL) { if(g_list_length(possible_matches) > 1) { - crm_err("Action %s for %s on %s exists %d times", + crm_warn("Action %s for %s on %s exists %d times", task2text(task), rsc?rsc->id:"", on_node?on_node->details->id:"", g_list_length(possible_matches)); } action = g_list_nth_data(possible_matches, 0); - crm_debug("Returning existing action (%d) %s for %s on %s", + crm_devel("Returning existing action (%d) %s for %s on %s", action->id, task2text(task), rsc?rsc->id:"", on_node?on_node->details->id:""); /* todo: free possible_matches */ return action; } - crm_debug("Creating action %s for %s on %s", + crm_devel("Creating action %s for %s on %s", task2text(task), rsc?rsc->id:"", on_node?on_node->details->id:""); crm_malloc(action, sizeof(action_t)); if(action != NULL) { action->id = action_id++; action->rsc = rsc; action->task = task; action->node = on_node; action->actions_before = NULL; action->actions_after = NULL; action->failure_is_fatal = TRUE; action->pseudo = FALSE; action->dumped = FALSE; action->discard = FALSE; action->runnable = TRUE; action->processed = FALSE; action->optional = FALSE; action->seen_count = 0; action->timeout = NULL; action->args = create_xml_node(NULL, "args"); if(rsc != NULL) { - crm_debug("Adding created action to its resource"); + crm_devel("Adding created action to its resource"); rsc->actions = g_list_append(rsc->actions, action); if(task == start_rsc) { rsc->starting = TRUE; action->timeout = rsc->start_timeout; } else if(task == stop_rsc) { rsc->stopping = TRUE; action->timeout = rsc->stop_timeout; } else { action->timeout = rsc->def_timeout; } } } - crm_debug("Action %d created", action->id); + crm_devel("Action %d created", action->id); return action; } const char * strength2text(enum con_strength strength) { const char *result = ""; switch(strength) { case pecs_ignore: result = "ignore"; break; case pecs_must: result = XML_STRENGTH_VAL_MUST; break; case pecs_must_not: result = XML_STRENGTH_VAL_MUSTNOT; break; case pecs_startstop: result = "start/stop"; break; } return result; } const char * task2text(enum action_tasks task) { const char *result = ""; switch(task) { case no_action: result = "no_action"; break; case stop_rsc: result = CRMD_RSCSTATE_STOP; break; case stopped_rsc: result = CRMD_RSCSTATE_STOP_OK; break; case start_rsc: result = CRMD_RSCSTATE_START; break; case started_rsc: result = CRMD_RSCSTATE_START_OK; break; case shutdown_crm: result = CRM_OP_SHUTDOWN; break; case stonith_node: result = XML_CIB_ATTR_STONITH; break; } return result; } void print_node(const char *pre_text, node_t *node, gboolean details) { if(node == NULL) { - crm_debug("%s%s: ", + crm_devel("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } - crm_debug("%s%s%sNode %s: (weight=%f, fixed=%s)", + crm_devel("%s%s%sNode %s: (weight=%f, fixed=%s)", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", node->details==NULL?"error ":node->details->online?"":"Unavailable/Unclean ", node->details->uname, node->weight, node->fixed?"True":"False"); if(details && node->details != NULL) { char *pe_mutable = crm_strdup("\t\t"); - crm_debug("\t\t===Node Attributes"); + crm_devel("\t\t===Node Attributes"); g_hash_table_foreach(node->details->attrs, print_str_str, pe_mutable); crm_free(pe_mutable); } if(details) { - crm_debug("\t\t===Node Attributes"); + crm_devel("\t\t===Node Attributes"); slist_iter( rsc, resource_t, node->details->running_rsc, lpc, print_resource("\t\t", rsc, FALSE); ); } } /* * Used by the HashTable for-loop */ void print_str_str(gpointer key, gpointer value, gpointer user_data) { - crm_debug("%s%s %s ==> %s", + crm_devel("%s%s %s ==> %s", user_data==NULL?"":(char*)user_data, user_data==NULL?"":": ", (char*)key, (char*)value); } void print_color_details(const char *pre_text, struct color_shared_s *color, gboolean details) { if(color == NULL) { - crm_debug("%s%s: ", + crm_devel("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } - crm_debug("%s%sColor %d: node=%s (from %d candidates)", + crm_devel("%s%sColor %d: node=%s (from %d candidates)", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", color->id, color->chosen_node==NULL?"":color->chosen_node->details->uname, g_list_length(color->candidate_nodes)); if(details) { slist_iter(node, node_t, color->candidate_nodes, lpc, print_node("\t", node, FALSE)); } } void print_color(const char *pre_text, color_t *color, gboolean details) { if(color == NULL) { - crm_debug("%s%s: ", + crm_devel("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } - crm_debug("%s%sColor %d: (weight=%f, node=%s, possible=%d)", + crm_devel("%s%sColor %d: (weight=%f, node=%s, possible=%d)", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", color->id, color->local_weight, safe_val5("",color,details,chosen_node,details,uname), g_list_length(color->details->candidate_nodes)); if(details) { print_color_details("\t", color->details, details); } } void print_rsc_to_node(const char *pre_text, rsc_to_node_t *cons, gboolean details) { if(cons == NULL) { - crm_debug("%s%s: ", + crm_devel("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } - crm_debug("%s%s%s Constraint %s (%p) - %d nodes:", + crm_devel("%s%s%s Constraint %s (%p) - %d nodes:", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", "rsc_to_node", cons->id, cons, g_list_length(cons->node_list_rh)); if(details == FALSE) { - crm_debug("\t%s %s run (score=%f : node placement rule)", + crm_devel("\t%s %s run (score=%f : node placement rule)", safe_val3(NULL, cons, rsc_lh, id), cons->can?"Can":"Cannot", cons->weight); slist_iter( node, node_t, cons->node_list_rh, lpc, print_node("\t\t-->", node, FALSE) ); } } void print_rsc_dependancy(const char *pre_text, rsc_dependancy_t *cons, gboolean details) { if(cons == NULL) { - crm_debug("%s%s: ", + crm_devel("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } - crm_debug("%s%s%s Constraint %s (%p):", + crm_devel("%s%s%s Constraint %s (%p):", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", XML_CONS_TAG_RSC_DEPEND, cons->id, cons); if(details == FALSE) { - crm_debug("\t%s --> %s, %s", + crm_devel("\t%s --> %s, %s", safe_val3(NULL, cons, rsc_lh, id), safe_val3(NULL, cons, rsc_rh, id), strength2text(cons->strength)); } } void print_resource(const char *pre_text, resource_t *rsc, gboolean details) { if(rsc == NULL) { - crm_debug("%s%s: ", + crm_devel("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } rsc->fns->dump(rsc, pre_text, details); } void print_action(const char *pre_text, action_t *action, gboolean details) { if(action == NULL) { - crm_debug("%s%s: ", + crm_devel("%s%s: ", pre_text==NULL?"":pre_text, pre_text==NULL?"":": "); return; } switch(action->task) { case stonith_node: case shutdown_crm: - crm_debug("%s%s%sAction %d: %s @ %s", + crm_devel("%s%s%sAction %d: %s @ %s", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", action->discard?"Discarded ":action->optional?"Optional ":action->runnable?action->processed?"":"(Provisional) ":"!!Non-Startable!! ", action->id, task2text(action->task), safe_val4(NULL, action, node, details, uname)); break; default: - crm_debug("%s%s%sAction %d: %s %s @ %s", + crm_devel("%s%s%sAction %d: %s %s @ %s", pre_text==NULL?"":pre_text, pre_text==NULL?"":": ", action->optional?"Optional ":action->runnable?action->processed?"":"(Provisional) ":"!!Non-Startable!! ", action->id, task2text(action->task), safe_val3(NULL, action, rsc, id), safe_val4(NULL, action, node, details, uname)); break; } if(details) { #if 1 - crm_debug("\t\t====== Preceeding Actions"); + crm_devel("\t\t====== Preceeding Actions"); slist_iter( other, action_wrapper_t, action->actions_before, lpc, print_action("\t\t", other->action, FALSE); ); - crm_debug("\t\t====== Subsequent Actions"); + crm_devel("\t\t====== Subsequent Actions"); slist_iter( other, action_wrapper_t, action->actions_after, lpc, print_action("\t\t", other->action, FALSE); ); #else - crm_debug("\t\t====== Subsequent Actions"); + crm_devel("\t\t====== Subsequent Actions"); slist_iter( other, action_wrapper_t, action->actions_after, lpc, print_action("\t\t", other->action, FALSE); ); #endif - crm_debug("\t\t====== End"); + crm_devel("\t\t====== End"); } else { - crm_debug("\t\t(seen=%d, before=%d, after=%d)", + crm_devel("\t\t(seen=%d, before=%d, after=%d)", action->seen_count, g_list_length(action->actions_before), g_list_length(action->actions_after)); } } void pe_free_nodes(GListPtr nodes) { while(nodes != NULL) { GListPtr list_item = nodes; node_t *node = (node_t*)list_item->data; struct node_shared_s *details = node->details; nodes = nodes->next; crm_trace("deleting node"); crm_trace("%s is being deleted", details->uname); print_node("delete", node, FALSE); if(details != NULL) { if(details->attrs != NULL) { g_hash_table_foreach_remove(details->attrs, ghash_free_str_str, NULL); g_hash_table_destroy(details->attrs); } } } if(nodes != NULL) { g_list_free(nodes); } } gboolean ghash_free_str_str(gpointer key, gpointer value, gpointer user_data) { crm_free(key); crm_free(value); return TRUE; } void pe_free_colors(GListPtr colors) { while(colors != NULL) { GListPtr list_item = colors; color_t *color = (color_t *)list_item->data; struct color_shared_s *details = color->details; colors = colors->next; if(details != NULL) { pe_free_shallow(details->candidate_nodes); pe_free_shallow_adv(details->allocated_resources, FALSE); crm_free(details->chosen_node); crm_free(details); } crm_free(color); } if(colors != NULL) { g_list_free(colors); } } void pe_free_shallow(GListPtr alist) { pe_free_shallow_adv(alist, TRUE); } void pe_free_shallow_adv(GListPtr alist, gboolean with_data) { GListPtr item; GListPtr item_next = alist; while(item_next != NULL) { item = item_next; item_next = item_next->next; if(with_data) { /* crm_trace("freeing %p", item->data); */ crm_free(item->data); } item->data = NULL; item->next = NULL; g_list_free(item); } } void pe_free_resources(GListPtr resources) { volatile GListPtr list_item = NULL; resource_t *rsc = NULL; while(resources != NULL) { list_item = resources; rsc = (resource_t *)list_item->data; resources = resources->next; pe_free_shallow_adv(rsc->candidate_colors, TRUE); rsc->fns->free(rsc); } if(resources != NULL) { g_list_free(resources); } } void pe_free_actions(GListPtr actions) { while(actions != NULL) { GListPtr list_item = actions; action_t *action = (action_t *)list_item->data; actions = actions->next; pe_free_shallow(action->actions_before);/* action_warpper_t* */ pe_free_shallow(action->actions_after); /* action_warpper_t* */ action->actions_before = NULL; action->actions_after = NULL; free_xml(action->args); crm_free(action); } if(actions != NULL) { g_list_free(actions); } } void pe_free_rsc_dependancy(rsc_dependancy_t *cons) { if(cons != NULL) { - crm_debug("Freeing constraint %s (%p)", cons->id, cons); + crm_devel("Freeing constraint %s (%p)", cons->id, cons); crm_free(cons); } } void pe_free_rsc_to_node(rsc_to_node_t *cons) { if(cons != NULL) { /* right now we dont make copies so this isnt required */ /* pe_free_shallow(cons->node_list_rh); */ /* node_t* */ crm_free(cons); } } GListPtr find_actions(GListPtr input, enum action_tasks task, node_t *on_node) { GListPtr result = NULL; slist_iter( action, action_t, input, lpc, if(action->task == task) { if(on_node == NULL) { result = g_list_append(result, action); } else if(action->node == NULL) { /* skip */ crm_warn("While looking for %s action on %s, " "found an unallocated one. " "This could end up creating dups..", task2text(task), on_node->details->id); } else if(safe_str_eq(on_node->details->id, action->node->details->id)) { result = g_list_append(result, action); } } ); return result; } void set_id(crm_data_t * xml_obj, const char *prefix, int child) { int id_len = 0; gboolean use_prefix = TRUE; gboolean use_child = TRUE; char *new_id = NULL; const char *id = crm_element_value(xml_obj, XML_ATTR_ID); id_len = 1 + strlen(id); if(child > 999) { crm_err("Are you insane?!?" " The CRM does not support > 1000 children per resource"); return; } else if(child < 0) { use_child = FALSE; } else { id_len += 4; /* child */ } if(prefix == NULL || safe_str_eq(id, prefix)) { use_prefix = FALSE; } else { id_len += (1 + strlen(prefix)); } crm_malloc(new_id, id_len); if(use_child) { snprintf(new_id, id_len, "%s%s%s:%d", use_prefix?prefix:"", use_prefix?":":"", id, child); } else { snprintf(new_id, id_len, "%s%s%s", use_prefix?prefix:"", use_prefix?":":"", id); } set_xml_property_copy(xml_obj, XML_ATTR_ID, new_id); crm_free(new_id); } diff --git a/crm/tengine/callbacks.c b/crm/tengine/callbacks.c index 7fb99635b0..5c0e2e5432 100644 --- a/crm/tengine/callbacks.c +++ b/crm/tengine/callbacks.c @@ -1,264 +1,264 @@ -/* $Id: callbacks.c,v 1.11 2005/02/18 10:32:07 andrew Exp $ */ +/* $Id: callbacks.c,v 1.12 2005/02/19 18:11:04 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 void te_update_confirm(const char *event, HA_Message *msg); void te_update_confirm(const char *event, HA_Message *msg) { int rc = -1; gboolean done = FALSE; const char *op = cl_get_string(msg, F_CIB_OPERATION); const char *type = cl_get_string(msg, F_CIB_OBJTYPE); crm_data_t *update = get_message_xml(msg, F_CIB_UPDATE); ha_msg_value_int(msg, F_CIB_RC, &rc); crm_debug("Processing %s...", event); crm_xml_debug(update, "Processing update"); if (MSG_LOG) { struct stat buf; if(stat(DEVEL_DIR, &buf) != 0) { cl_perror("Stat of %s failed... exiting", DEVEL_DIR); exit(100); } } if(op == NULL) { crm_err( "Illegal CIB update, the operation must be specified"); send_abort("Illegal update", update); done = TRUE; } else if(strcmp(op, CRM_OP_CIB_CREATE) == 0 || strcmp(op, CRM_OP_CIB_DELETE) == 0 || strcmp(op, CRM_OP_CIB_REPLACE) == 0 || strcmp(op, CRM_OP_SHUTDOWN_REQ) == 0 || strcmp(op, CRM_OP_CIB_ERASE) == 0) { /* these are always unexpected, trigger the PE */ send_abort("Non-update change", update); done = TRUE; } else if(strcmp(op, CRM_OP_CIB_UPDATE) != 0) { crm_verbose("Ignoring %s op confirmation", op); done = TRUE; } if(done) { free_xml(update); return; } if(safe_str_eq(type, XML_CIB_TAG_CRMCONFIG)) { /* ignore - for the moment */ - crm_debug("Ignoring changes to the %s section", type); + crm_devel("Ignoring changes to the %s section", type); } else if(safe_str_eq(type, XML_CIB_TAG_STATUS)) { /* this _may_ not be un-expected */ if(extract_event(update) == FALSE) { send_abort("Unexpected status update", update); } } else if(safe_str_eq(type, XML_CIB_TAG_NODES) || safe_str_eq(type, XML_CIB_TAG_RESOURCES) || safe_str_eq(type, XML_CIB_TAG_CONSTRAINTS)) { /* these are never expected */ crm_debug("Aborting on changes to the %s section", type); send_abort("Non-status update", update); } else { crm_warn("Ignoring update confirmation for %s object", type); } free_xml(update); } gboolean process_te_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 *ref = cl_get_string(msg, XML_ATTR_REFERENCE); const char *op = cl_get_string(msg, F_CRM_TASK); crm_log_message(LOG_VERBOSE, msg); if(safe_str_eq(cl_get_string(msg, F_CRM_MSG_TYPE), XML_ATTR_RESPONSE) && safe_str_neq(op, CRM_OP_EVENTCC)) { crm_info("Message was a response not a request. Discarding"); return TRUE; } - crm_debug("Processing %s (%s) message", op, ref); + crm_devel("Processing %s (%s) message", op, ref); if(op == NULL){ /* error */ } else if(strcmp(op, CRM_OP_HELLO) == 0) { /* ignore */ } else if(sys_to == NULL || strcmp(sys_to, CRM_SYSTEM_TENGINE) != 0) { crm_verbose("Bad sys-to %s", crm_str(sys_to)); return FALSE; } else if(strcmp(op, CRM_OP_TRANSITION) == 0) { crm_trace("Initializing graph..."); initialize_graph(); crm_trace("Unpacking graph..."); unpack_graph(xml_data); crm_trace("Initiating transition..."); in_transition = TRUE; if(initiate_transition() == FALSE) { /* nothing to be done.. means we're done. */ crm_info("No actions to be taken..." " transition compelte."); } crm_trace("Processing complete..."); } else if(strcmp(op, CRM_OP_TEABORT) == 0) { initialize_graph(); } else if(strcmp(op, CRM_OP_QUIT) == 0) { crm_info("Received quit message, terminating"); exit(0); } else if(in_transition == FALSE) { crm_info("Received event_cc while not in a transition..." " Poking the Policy Engine"); send_abort("Initiate a transition", NULL); } - crm_debug("finished processing message"); - print_state(LOG_DEBUG); + crm_devel("finished processing message"); + print_state(LOG_DEV); return TRUE; } void tengine_stonith_callback(stonith_ops_t * op, void * private_data) { action_t *te_action = private_data; if(op == NULL) { crm_err("Called with a NULL op!"); return; } crm_info("optype=%d, node_name=%s, result=%d, node_list=%s\n", op->optype, op->node_name, op->op_result, (char *)op->node_list); if(op->op_result == STONITH_SUCCEEDED) { enum cib_errors rc = cib_ok; crm_data_t *action_args = find_xml_node( te_action->xml, "args", TRUE); const char *target = crm_element_value(action_args, "target"); const char *uuid = crm_element_value(action_args,"target_uuid"); /* zero out the node-status & remove all LRM status info */ crm_data_t *update = NULL; crm_data_t *node_state = create_xml_node( NULL, XML_CIB_TAG_STATE); set_xml_property_copy(node_state, XML_ATTR_UUID, uuid); set_xml_property_copy(node_state, XML_ATTR_UNAME, target); set_xml_property_copy( node_state, XML_CIB_ATTR_HASTATE, DEADSTATUS); set_xml_property_copy( node_state, XML_CIB_ATTR_INCCM, XML_BOOLEAN_NO); set_xml_property_copy( node_state, XML_CIB_ATTR_CRMDSTATE, OFFLINESTATUS); set_xml_property_copy( node_state, XML_CIB_ATTR_JOINSTATE,CRMD_JOINSTATE_DOWN); set_xml_property_copy( node_state, XML_CIB_ATTR_EXPSTATE, CRMD_JOINSTATE_DOWN); set_xml_property_copy( node_state, XML_CIB_ATTR_REPLACE, XML_CIB_TAG_LRM); create_xml_node(node_state, XML_CIB_TAG_LRM); update = create_cib_fragment(node_state, NULL); free_xml(node_state); rc = te_cib_conn->cmds->modify( te_cib_conn, XML_CIB_TAG_STATUS,update,NULL,cib_none); if(rc == cib_ok) { /* mark the action complete */ te_action->complete = TRUE; process_trigger(te_action->id); check_for_completion(); } else { send_abort("Couldnt update CIB after stonith", update); } free_xml(update); } else { send_abort("Fencing op failed", NULL); } } void tengine_stonith_connection_destroy(gpointer user_data) { crm_err("Fencing daemon has left us: Shutting down...NOW"); abort(); /* shutdown properly later */ return; } gboolean tengine_stonith_dispatch(IPC_Channel *sender, void *user_data) { int lpc = 0; while(stonithd_op_result_ready()) { if (sender->ch_status == IPC_DISCONNECT) { /* The message which was pending for us is that * the IPC status is now IPC_DISCONNECT */ break; } if(ST_FAIL == stonithd_receive_ops_result(FALSE)) { crm_err("stonithd_receive_ops_result() failed"); } else { lpc++; } } crm_verbose("Processed %d messages", lpc); if (sender->ch_status == IPC_DISCONNECT) { return FALSE; } return TRUE; } diff --git a/crm/tengine/main.c b/crm/tengine/main.c index 75e49ec4ad..28818ba3ca 100644 --- a/crm/tengine/main.c +++ b/crm/tengine/main.c @@ -1,228 +1,228 @@ -/* $Id: main.c,v 1.17 2005/02/17 16:22:12 andrew Exp $ */ +/* $Id: main.c,v 1.18 2005/02/19 18:11:04 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 #include #include #include #include #define SYS_NAME CRM_SYSTEM_TENGINE #define OPTARGS "hVc" GMainLoop* mainloop = NULL; const char* crm_system_name = SYS_NAME; extern cib_t *te_cib_conn; void usage(const char* cmd, int exit_status); int init_start(void); gboolean tengine_shutdown(int nsig, gpointer unused); extern void te_update_confirm(const char *event, HA_Message *msg); int main(int argc, char ** argv) { gboolean allow_cores = TRUE; int argerr = 0; int flag; crm_log_init(crm_system_name); set_crm_log_level(LOG_VERBOSE); G_main_add_SignalHandler( G_PRIORITY_HIGH, SIGTERM, tengine_shutdown, NULL, NULL); - crm_debug("Begining option processing"); + crm_devel("Begining option processing"); while ((flag = getopt(argc, argv, OPTARGS)) != EOF) { switch(flag) { case 'V': alter_debug(DEBUG_INC); break; case 'h': /* Help message */ usage(crm_system_name, LSB_EXIT_OK); break; case 'c': allow_cores = TRUE; break; default: ++argerr; break; } } - crm_debug("Option processing complete"); + crm_devel("Option processing complete"); if (optind > argc) { ++argerr; } if (argerr) { usage(crm_system_name,LSB_EXIT_GENERIC); } /* read local config file */ - crm_debug("Starting..."); + crm_devel("Starting..."); return init_start(); } int init_start(void) { int init_ok = TRUE; init_client_ipc_comms( CRM_SYSTEM_CRMD, subsystem_msg_dispatch, (void*)process_te_message, &crm_ch); if(crm_ch != NULL) { send_hello_message(crm_ch, "1234", CRM_SYSTEM_TENGINE, "0", "1"); } else { init_ok = FALSE; crm_err("Could not connect to the CRMd"); } if(init_ok) { crm_trace("Creating CIB connection"); te_cib_conn = cib_new(); if(te_cib_conn == NULL) { init_ok = FALSE; } } if(init_ok) { crm_trace("Connecting to the CIB"); if(te_cib_conn->cmds->signon( te_cib_conn, cib_command) != cib_ok) { init_ok = FALSE; } } if(init_ok) { crm_trace("Setting CIB notification callback"); if(te_cib_conn->cmds->add_notify_callback( te_cib_conn, T_CIB_UPDATE_CONFIRM, te_update_confirm) != cib_ok) { crm_err("Could not set CIB notification callback"); init_ok = FALSE; } } if(init_ok && ST_OK != stonithd_signon(crm_system_name)) { crm_err("Could not sign up to stonithd"); /* init_ok = FALSE; */ } if(init_ok && ST_OK != stonithd_set_stonith_ops_callback( tengine_stonith_callback, NULL)) { crm_err("Could not set stonith callback"); stonithd_signoff(); /* init_ok = FALSE; */ } if(init_ok) { IPC_Channel *fence_ch = stonithd_input_IPC_channel(); if(fence_ch == NULL) { } else if(NULL == G_main_add_IPC_Channel( G_PRIORITY_LOW, fence_ch, FALSE, tengine_stonith_dispatch, NULL, tengine_stonith_connection_destroy)) { crm_err("Failed to add Fencing channel to our mainloop"); init_ok = FALSE; } } if(init_ok) { /* Create the mainloop and run it... */ crm_info("Starting %s", crm_system_name); mainloop = g_main_new(FALSE); g_main_run(mainloop); return_to_orig_privs(); crm_info("Exiting %s", crm_system_name); } else { crm_warn("Initialization errors, %s not starting.", crm_system_name); } if(init_ok) { return 0; } return 1; } void usage(const char* cmd, int exit_status) { FILE* stream; stream = exit_status ? stderr : stdout; fprintf(stream, "usage: %s [-srkh]" "[-c configure file]\n", cmd); /* fprintf(stream, "\t-d\tsets debug level\n"); */ /* fprintf(stream, "\t-s\tgets daemon status\n"); */ /* fprintf(stream, "\t-r\trestarts daemon\n"); */ /* fprintf(stream, "\t-k\tstops daemon\n"); */ /* fprintf(stream, "\t-h\thelp message\n"); */ fflush(stream); exit(exit_status); } gboolean tengine_shutdown(int nsig, gpointer unused) { static int shuttingdown = 0; if (!shuttingdown) { shuttingdown = 1; } if (mainloop != NULL && g_main_is_running(mainloop)) { g_main_quit(mainloop); }else{ exit(LSB_EXIT_OK); } return TRUE; } diff --git a/crm/tengine/tengine.c b/crm/tengine/tengine.c index 0abe73146d..24a9819d8c 100644 --- a/crm/tengine/tengine.c +++ b/crm/tengine/tengine.c @@ -1,605 +1,605 @@ -/* $Id: tengine.c,v 1.45 2005/02/10 10:48:08 andrew Exp $ */ +/* $Id: tengine.c,v 1.46 2005/02/19 18:11:04 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 gboolean graph_complete = FALSE; GListPtr graph = NULL; IPC_Channel *crm_ch = NULL; uint transition_timeout = 30*1000; /* 30 seconds */ uint transition_fuzz_timeout = 0; uint default_transition_timeout = 30*1000; /* 30 seconds */ uint next_transition_timeout = 30*1000; /* 30 seconds */ void fire_synapse(synapse_t *synapse); gboolean initiate_action(action_t *action); gboolean confirm_synapse(synapse_t *synapse, int action_id); void check_synapse_triggers(synapse_t *synapse, int action_id); gboolean in_transition = FALSE; te_timer_t *transition_timer = NULL; te_timer_t *transition_fuzz_timer = NULL; int transition_counter = 1; gboolean initialize_graph(void) { if(transition_timer == NULL) { crm_malloc(transition_timer, sizeof(te_timer_t)); transition_timer->timeout = 10; transition_timer->source_id = -1; transition_timer->reason = timeout_timeout; transition_timer->action = NULL; } else { stop_te_timer(transition_timer); } if(transition_fuzz_timer == NULL) { crm_malloc(transition_fuzz_timer, sizeof(te_timer_t)); transition_fuzz_timer->timeout = 10; transition_fuzz_timer->source_id = -1; transition_fuzz_timer->reason = timeout_fuzz; transition_fuzz_timer->action = NULL; } else { stop_te_timer(transition_fuzz_timer); } while(g_list_length(graph) > 0) { synapse_t *synapse = g_list_nth_data(graph, 0); while(g_list_length(synapse->actions) > 0) { action_t *action = g_list_nth_data(synapse->actions,0); synapse->actions = g_list_remove( synapse->actions, action); if(action->timer->source_id > 0) { - crm_debug("Removing timer for action: %d", + crm_devel("Removing timer for action: %d", action->id); g_source_remove(action->timer->source_id); } free_xml(action->xml); crm_free(action->timer); crm_free(action); } while(g_list_length(synapse->inputs) > 0) { action_t *action = g_list_nth_data(synapse->inputs, 0); synapse->inputs = g_list_remove(synapse->inputs, action); free_xml(action->xml); crm_free(action); } graph = g_list_remove(graph, synapse); crm_free(synapse); } graph = NULL; return TRUE; } /* * returns the ID of the action if a match is found * returns -1 if a match was not found * returns -2 if a match was found but the action failed (and was * not allowed to) */ int match_graph_event(action_t *action, crm_data_t *event) { const char *allow_fail = NULL; const char *this_action = NULL; const char *this_node = NULL; const char *this_rsc = NULL; const char *event_node; const char *event_rsc; const char *rsc_state; const char *event_action; const char *event_rc; const char *op_status; action_t *match = NULL; int op_status_i = -3; if(event == NULL) { crm_trace("Ignoring NULL event"); return -1; } event_node = crm_element_value(event, XML_LRM_ATTR_TARGET); event_action = crm_element_value(event, XML_LRM_ATTR_LASTOP); event_rsc = crm_element_value(event, XML_ATTR_ID); event_rc = crm_element_value(event, XML_LRM_ATTR_RC); rsc_state = crm_element_value(event, XML_LRM_ATTR_RSCSTATE); op_status = crm_element_value(event, XML_LRM_ATTR_OPSTATUS); if(op_status != NULL) { op_status_i = atoi(op_status); } this_action = crm_element_value(action->xml, XML_LRM_ATTR_TASK); this_node = crm_element_value(action->xml, XML_LRM_ATTR_TARGET); this_rsc = crm_element_value(action->xml, XML_LRM_ATTR_RSCID); crm_devel("matching against: <%s task=%s node=%s rsc_id=%s/>", crm_element_name(action->xml), this_action, this_node, this_rsc); if(safe_str_neq(this_node, event_node)) { crm_devel("node mismatch: %s", event_node); } else if(safe_str_neq(this_action, event_action)) { crm_devel("action mismatch: %s", event_action); } else if(safe_str_eq(crm_element_name(action->xml), XML_GRAPH_TAG_RSC_OP)) { crm_devel(XML_GRAPH_TAG_RSC_OP); if(safe_str_eq(this_rsc, event_rsc)) { match = action; } else { crm_devel("bad rsc (%s) != (%s)", this_rsc, event_rsc); } } else if(safe_str_eq(crm_element_name(action->xml), XML_GRAPH_TAG_CRM_EVENT)) { crm_devel(XML_GRAPH_TAG_CRM_EVENT); match = action; } else { crm_devel("no match"); } if(match == NULL) { - crm_debug("didnt match current action"); + crm_devel("didnt match current action"); return -1; } - crm_debug("matched"); + crm_devel("matched"); /* stop this event's timer if it had one */ stop_te_timer(match->timer); /* Process OP status */ allow_fail = crm_element_value(match->xml, "allow_fail"); switch(op_status_i) { case LRM_OP_DONE: break; case LRM_OP_ERROR: case LRM_OP_TIMEOUT: case LRM_OP_NOTSUPPORTED: if(safe_str_neq(allow_fail, XML_BOOLEAN_TRUE)) { crm_err("Action %s to %s on %s resulted in" " failure... aborting transition.", event_action, event_rsc, event_node); send_abort("Action failed", match->xml); return -2; } break; case LRM_OP_CANCELLED: /* do nothing?? */ crm_warn("Dont know what to do for cancelled ops yet"); break; default: crm_err("Unsupported action result: %d", op_status_i); send_abort("Unsupport action result", match->xml); return -2; } crm_devel("Action %d was successful, looking for next action", match->id); match->complete = TRUE; return match->id; } gboolean process_graph_event(crm_data_t *event) { int action_id = -1; int op_status_i = 0; const char *op_status = NULL; if(event != NULL) { op_status = crm_element_value(event, XML_LRM_ATTR_OPSTATUS); } next_transition_timeout = transition_timeout; if(op_status != NULL) { op_status_i = atoi(op_status); } if(op_status_i == -1) { /* just information that the action was sent */ crm_trace("Ignoring TE initiated updates"); return TRUE; } slist_iter( synapse, synapse_t, graph, lpc, /* lookup event */ slist_iter( action, action_t, synapse->actions, lpc2, action_id = match_graph_event(action, event); if(action_id != -1) { break; } ); if(action_id != -1) { break; } ); if(event == NULL) { crm_debug("a transition is starting"); } else if(action_id > -1) { crm_xml_devel(event, "Event found"); } else if(action_id == -2) { crm_xml_info(event, "Event found but failed"); } else { /* unexpected event, trigger a pe-recompute */ /* possibly do this only for certain types of actions */ send_abort("Event not matched", event); return FALSE; } process_trigger(action_id); check_for_completion(); return TRUE; } void check_for_completion(void) { if(graph_complete) { /* allow some slack until we are pretty sure nothing * else is happening */ crm_info("Transition complete"); if(transition_fuzz_timer->timeout > 0) { crm_info("Allowing the system to stabilize for %d ms" " before S_IDLE transition", transition_fuzz_timer->timeout); start_te_timer(transition_fuzz_timer); } else { send_success("complete"); } } else { /* restart the transition timer again */ - crm_debug("Transition not yet complete"); - print_state(LOG_DEBUG); + crm_devel("Transition not yet complete"); + print_state(LOG_DEV); transition_timer->timeout = next_transition_timeout; start_te_timer(transition_timer); } } gboolean initiate_action(action_t *action) { gboolean ret = FALSE; const char *on_node = NULL; const char *id = NULL; const char *task = NULL; const char *timeout = NULL; const char *destination = NULL; const char *msg_task = XML_GRAPH_TAG_RSC_OP; crm_data_t *rsc_op = NULL; on_node = crm_element_value(action->xml, XML_LRM_ATTR_TARGET); id = crm_element_value(action->xml, XML_ATTR_ID); task = crm_element_value(action->xml, XML_LRM_ATTR_TASK); timeout = crm_element_value(action->xml, XML_ATTR_TIMEOUT); if(id == NULL || strlen(id) == 0 || task == NULL || strlen(task) == 0) { /* error */ crm_err("Failed on corrupted command: %s (id=%s) %s", crm_element_name(action->xml), crm_str(id), crm_str(task)); } else if(action->type == action_type_pseudo){ crm_info("Executing pseudo-event (%d): " "%s on %s", action->id, task, on_node); action->complete = TRUE; process_trigger(action->id); ret = TRUE; } else if(action->type == action_type_crm && safe_str_eq(task, XML_CIB_ATTR_STONITH)){ /* */ stonith_ops_t * st_op = NULL; crm_data_t *action_args = find_xml_node( action->xml, "args", TRUE); const char *target = crm_element_value(action_args, "target"); crm_malloc(st_op, sizeof(stonith_ops_t)); st_op->optype = RESET; st_op->timeout = crm_atoi(timeout, "10"); /* one second */ st_op->node_name = crm_strdup(target); #ifdef TESTING ret = TRUE; #else if (ST_OK == stonithd_node_fence( st_op )) { ret = TRUE; } #endif } else if(on_node == NULL || strlen(on_node) == 0) { /* error */ crm_err("Failed on corrupted command: %s (id=%s) %s on %s", crm_element_name(action->xml), crm_str(id), crm_str(task), crm_str(on_node)); } else if(action->type == action_type_crm){ /* */ crm_info("Executing crm-event (%s): %s on %s", id, task, on_node); action->complete = TRUE; destination = CRM_SYSTEM_CRMD; msg_task = task; ret = TRUE; } else if(action->type == action_type_rsc){ crm_data_t *rsc = find_xml_node( action->xml, XML_CIB_TAG_RESOURCE, TRUE); crm_info("Executing rsc-op (%s): %s %s on %s", id, task, crm_element_value(rsc, XML_ATTR_ID), on_node); /* let everyone know this was invoked */ do_update_cib(action->xml, -1); /* ... */ rsc_op = create_xml_node(NULL, XML_GRAPH_TAG_RSC_OP); set_xml_property_copy(rsc_op, XML_ATTR_ID, id); set_xml_property_copy(rsc_op, XML_LRM_ATTR_TASK, task); set_xml_property_copy(rsc_op, XML_LRM_ATTR_TARGET, on_node); add_node_copy(rsc_op, rsc); destination = CRM_SYSTEM_LRMD; ret = TRUE; } else { crm_err("Failed on unsupported command type: " "%s, %s (id=%s) on %s", crm_element_name(action->xml), task, id, on_node); } if(ret) { HA_Message *cmd = NULL; char *counter = crm_itoa(transition_counter); if(rsc_op != NULL) { crm_xml_debug(rsc_op, "Performing"); } cmd = create_request(msg_task, rsc_op, on_node, destination, CRM_SYSTEM_TENGINE, NULL); ha_msg_add(cmd, "transition_id", crm_str(counter)); #ifndef TESTING send_ipc_message(crm_ch, cmd); #else cl_log_message(LOG_DEBUG, cmd); #endif crm_free(counter); if(action->timeout > 0) { - crm_debug("Setting timer for action %d",action->id); + crm_devel("Setting timer for action %d",action->id); start_te_timer(action->timer); } } free_xml(rsc_op); return ret; } gboolean initiate_transition(void) { crm_info("Initating transition"); process_graph_event(NULL); return TRUE; } void check_synapse_triggers(synapse_t *synapse, int action_id) { synapse->triggers_complete = TRUE; if(synapse->confirmed) { - crm_debug("Skipping confirmed synapse %d", synapse->id); + crm_devel("Skipping confirmed synapse %d", synapse->id); return; } else if(synapse->complete == FALSE) { - crm_debug("Checking pre-reqs for %d", synapse->id); + crm_devel("Checking pre-reqs for %d", synapse->id); /* lookup prereqs */ slist_iter( prereq, action_t, synapse->inputs, lpc, crm_devel("Processing input %d", prereq->id); if(prereq->id == action_id) { crm_devel("Marking input %d complete", action_id); prereq->complete = TRUE; } else if(prereq->complete == FALSE) { crm_devel("Inputs for synapse %d not satisfied", synapse->id); synapse->triggers_complete = FALSE; } ); } } void fire_synapse(synapse_t *synapse) { if(synapse == NULL) { crm_err("Synapse was NULL!"); return; } - crm_debug("Checking if synapse %d needs to be fired", synapse->id); + crm_devel("Checking if synapse %d needs to be fired", synapse->id); if(synapse->complete) { - crm_debug("Skipping complete synapse %d", synapse->id); + crm_devel("Skipping complete synapse %d", synapse->id); return; } else if(synapse->triggers_complete == FALSE) { - crm_debug("Synapse %d not yet satisfied", synapse->id); + crm_devel("Synapse %d not yet satisfied", synapse->id); return; } crm_devel("All inputs for synapse %d satisfied... invoking actions", synapse->id); synapse->complete = TRUE; slist_iter( action, action_t, synapse->actions, lpc, /* allow some leway */ int tmp_time = 2 * action->timeout; gboolean passed = FALSE; action->invoked = TRUE; /* Invoke the action and start the timer */ passed = initiate_action(action); if(passed == FALSE) { crm_err("Failed initiating <%s id=%d> in synapse %d", crm_element_name(action->xml), action->id, synapse->id); send_abort("Action init failed", action->xml); return; } if(tmp_time > next_transition_timeout) { next_transition_timeout = tmp_time; } ); crm_debug("Synapse %d complete", synapse->id); } gboolean confirm_synapse(synapse_t *synapse, int action_id) { gboolean complete = TRUE; synapse->confirmed = TRUE; slist_iter( action, action_t, synapse->actions, lpc, if(action->type == action_type_rsc && action->complete == FALSE) { complete = FALSE; synapse->confirmed = FALSE; - crm_debug("Found an incomplete action" + crm_devel("Found an incomplete action" " - transition not complete"); break; } ); return complete; } void process_trigger(int action_id) { graph_complete = TRUE; - crm_debug("Processing trigger from action %d", action_id); + crm_devel("Processing trigger from action %d", action_id); /* something happened, stop the timer and start it again at the end */ stop_te_timer(transition_timer); slist_iter( synapse, synapse_t, graph, lpc, if(synapse->confirmed) { - crm_debug("Skipping confirmed synapse %d", synapse->id); + crm_devel("Skipping confirmed synapse %d", synapse->id); continue; } check_synapse_triggers(synapse, action_id); fire_synapse(synapse); if(graph == NULL) { crm_err("Trigger processing aborted after failed synapse"); break; } - crm_debug("Checking if %d is confirmed", synapse->id); + crm_devel("Checking if %d is confirmed", synapse->id); if(synapse->complete == FALSE) { - crm_debug("Found an incomplete synapse" + crm_devel("Found an incomplete synapse" " - transition not complete"); /* indicate that the transition is not yet complete */ graph_complete = FALSE; } else if(synapse->confirmed == FALSE) { graph_complete = graph_complete && confirm_synapse(synapse, action_id); } - crm_debug("%d is %s", synapse->id, + crm_devel("%d is %s", synapse->id, synapse->confirmed?"confirmed":synapse->complete?"complete":"pending"); ); } diff --git a/crm/tengine/unpack.c b/crm/tengine/unpack.c index 8f29b43355..c0740b1221 100644 --- a/crm/tengine/unpack.c +++ b/crm/tengine/unpack.c @@ -1,358 +1,358 @@ -/* $Id: unpack.c,v 1.21 2005/02/17 20:35:50 andrew Exp $ */ +/* $Id: unpack.c,v 1.22 2005/02/19 18:11:04 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 cib_t *te_cib_conn = NULL; action_t* unpack_action(crm_data_t *xml_action); crm_data_t *create_shutdown_event(const char *node, int op_status); void set_timer_value(te_timer_t *timer, const char *time, int time_default); extern int transition_counter; void set_timer_value(te_timer_t *timer, const char *time, int time_default) { if(timer == NULL) { return; } timer->timeout = time_default; if(time != NULL) { int tmp_time = atoi(time); if(tmp_time > 0) { timer->timeout = tmp_time; } } } gboolean unpack_graph(crm_data_t *xml_graph) { /* timeout; time = crm_element_value(xml_graph, "transition_fuzz"); set_timer_value(transition_fuzz_timer, time, transition_fuzz_timeout); transition_counter++; crm_info("Beginning transition %d - timeout set to %d", transition_counter, transition_timer->timeout); xml_child_iter( xml_graph, synapse, "synapse", synapse_t *new_synapse = NULL; - crm_debug("looking in synapse %s", crm_element_value(synapse, XML_ATTR_ID)); + crm_devel("looking in synapse %s", crm_element_value(synapse, XML_ATTR_ID)); crm_malloc(new_synapse, sizeof(synapse_t)); new_synapse->id = num_synapses++; new_synapse->complete = FALSE; new_synapse->confirmed = FALSE; new_synapse->actions = NULL; new_synapse->inputs = NULL; graph = g_list_append(graph, new_synapse); - crm_debug("look for actions in synapse %s", crm_element_value(synapse, XML_ATTR_ID)); + crm_devel("look for actions in synapse %s", crm_element_value(synapse, XML_ATTR_ID)); xml_child_iter( synapse, actions, "action_set", xml_child_iter( actions, action, NULL, action_t *new_action = unpack_action(action); num_actions++; if(new_action == NULL) { continue; } - crm_debug("Adding action %d to synapse %d", + crm_devel("Adding action %d to synapse %d", new_action->id, new_synapse->id); new_synapse->actions = g_list_append( new_synapse->actions, new_action); ); ); - crm_debug("look for inputs in synapse %s", crm_element_value(synapse, XML_ATTR_ID)); + crm_devel("look for inputs in synapse %s", crm_element_value(synapse, XML_ATTR_ID)); xml_child_iter( synapse, inputs, "inputs", xml_child_iter( inputs, trigger, NULL, xml_child_iter( trigger, input, NULL, action_t *new_input = unpack_action(input); if(new_input == NULL) { continue; } - crm_debug("Adding input %d to synapse %d", + crm_devel("Adding input %d to synapse %d", new_input->id, new_synapse->id); new_synapse->inputs = g_list_append( new_synapse->inputs, new_input); ); ); ); ); crm_info("Unpacked %d actions in %d synapses", num_actions, num_synapses); if(num_actions > 0) { return TRUE; } else { /* indicate to caller that there's nothing to do */ return FALSE; } } action_t* unpack_action(crm_data_t *xml_action) { const char *tmp = crm_element_value(xml_action, XML_ATTR_ID); action_t *action = NULL; crm_data_t *action_copy = NULL; if(tmp == NULL) { crm_err("Actions must have an id!"); crm_xml_devel(xml_action, "Action with missing id"); return NULL; } action_copy = copy_xml_node_recursive(xml_action); crm_malloc(action, sizeof(action_t)); if(action == NULL) { return NULL; } action->id = atoi(tmp); action->timeout = 0; action->timer = NULL; action->invoked = FALSE; action->complete = FALSE; action->can_fail = FALSE; action->type = action_type_rsc; action->xml = action_copy; if(safe_str_eq(crm_element_name(action_copy), XML_GRAPH_TAG_RSC_OP)) { action->type = action_type_rsc; } else if(safe_str_eq(crm_element_name(action_copy), XML_GRAPH_TAG_PSEUDO_EVENT)) { action->type = action_type_pseudo; } else if(safe_str_eq(crm_element_name(action_copy), XML_GRAPH_TAG_CRM_EVENT)) { action->type = action_type_crm; } tmp = crm_element_value(action_copy, XML_ATTR_TIMEOUT); if(tmp != NULL) { action->timeout = atoi(tmp); } - crm_debug("Action %d has timer set to %d", + crm_devel("Action %d has timer set to %d", action->id, action->timeout); crm_malloc(action->timer, sizeof(te_timer_t)); action->timer->timeout = action->timeout; action->timer->source_id = -1; action->timer->reason = timeout_action; action->timer->action = action; tmp = crm_element_value(action_copy, "can_fail"); if(safe_str_eq(tmp, XML_BOOLEAN_TRUE)) { action->can_fail = TRUE; } return action; } gboolean extract_event(crm_data_t *msg) { gboolean abort = FALSE; const char *event_node = NULL; /* [cib fragment] ... */ crm_trace("Extracting event"); xml_child_iter( msg, iter, XML_CIB_TAG_STATE, crm_data_t *shutdown = NULL; crm_data_t *resources = NULL; crm_data_t *node_state = iter; const char *ccm_state = crm_element_value( node_state, XML_CIB_ATTR_INCCM); const char *crmd_state = crm_element_value( node_state, XML_CIB_ATTR_CRMDSTATE); const char *join_state = crm_element_value( node_state, XML_CIB_ATTR_JOINSTATE); crm_xml_devel(node_state,"Processing"); if(crm_element_value(node_state, XML_CIB_ATTR_SHUTDOWN) != NULL) { crm_devel("Aborting on %s attribute", XML_CIB_ATTR_SHUTDOWN); abort = TRUE; break; } else if(crm_element_value(node_state, XML_CIB_ATTR_STONITH) != NULL) { /* node marked for STONITH * possibly by us when a shutdown timmed out */ crm_devel("Checking for STONITH"); event_node = crm_element_value(node_state, XML_ATTR_UNAME); shutdown = create_shutdown_event( event_node, LRM_OP_TIMEOUT); process_graph_event(shutdown); free_xml(shutdown); continue; } resources = find_xml_node(node_state, XML_CIB_TAG_LRM, FALSE); resources = find_xml_node( resources, XML_LRM_TAG_RESOURCES, FALSE); if(crmd_state != NULL || ccm_state != NULL || join_state != NULL) { /* simple node state update... * possibly from a shutdown we requested */ crm_devel("Processing state update"); if(crmd_state != NULL && safe_str_neq(crmd_state, OFFLINESTATUS)) { /* always recompute */ crm_devel("Abort - crmd not offline"); abort = TRUE; } else if(join_state != NULL && safe_str_neq(join_state, CRMD_JOINSTATE_DOWN)) { crm_devel("Abort - new CRMD node"); abort = TRUE; } else { /* this may be called more than once per shutdown * ie. once per update of each field */ crm_devel("Checking if this was a known shutdown"); event_node = crm_element_value(node_state, XML_ATTR_UNAME); shutdown = create_shutdown_event(event_node, LRM_OP_DONE); abort = !process_graph_event(shutdown); free_xml(shutdown); } if(abort) { - crm_xml_debug( + crm_xml_devel( node_state, "Update resulted in state-based abort"); } else if(ccm_state != NULL && safe_str_eq(ccm_state, XML_BOOLEAN_YES)) { crm_devel("Ignore - new CCM node"); } } if(abort == FALSE && resources != NULL) { /* LRM resource update... */ xml_child_iter( resources, child, NULL, crm_xml_devel(child, "Processing LRM resource update"); abort = !process_graph_event(child); if(abort) { break; } ); } if(abort) { break; } ); return !abort; } crm_data_t* create_shutdown_event(const char *node, int op_status) { crm_data_t *event = create_xml_node(NULL, XML_CIB_TAG_STATE); char *code = crm_itoa(op_status); set_xml_property_copy(event, XML_LRM_ATTR_TARGET, node); /* event_rsc = set_xml_property_copy(event, XML_ATTR_ID); */ set_xml_property_copy(event, XML_LRM_ATTR_RC, "0"); set_xml_property_copy( event, XML_LRM_ATTR_LASTOP, XML_CIB_ATTR_SHUTDOWN); set_xml_property_copy( event, XML_LRM_ATTR_RSCSTATE, CRMD_RSCSTATE_GENERIC_OK); set_xml_property_copy(event, XML_LRM_ATTR_OPSTATUS, code); crm_free(code); return event; } diff --git a/crm/tengine/utils.c b/crm/tengine/utils.c index d30d77b713..86999d27df 100644 --- a/crm/tengine/utils.c +++ b/crm/tengine/utils.c @@ -1,381 +1,381 @@ -/* $Id: utils.c,v 1.15 2005/02/15 08:13:09 andrew Exp $ */ +/* $Id: utils.c,v 1.16 2005/02/19 18:11:04 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 extern cib_t *te_cib_conn; extern int global_transition_timer; void print_input(const char *prefix, action_t *input, gboolean to_file); void print_action(const char *prefix, action_t *action, gboolean to_file); gboolean timer_callback(gpointer data); void /* send_abort(const char *text, HA_Message *msg) */ send_abort(const char *text, crm_data_t *msg) { HA_Message *cmd = NULL; if(msg != NULL) { crm_info("Sending \"abort\" message... details follow"); crm_xml_info(msg, text); } else { crm_info("Sending \"abort\" message... %s", text); } print_state(LOG_WARNING); initialize_graph(); cmd = create_request(CRM_OP_TEABORT, NULL, NULL, CRM_SYSTEM_DC, CRM_SYSTEM_TENGINE, NULL); ha_msg_add(cmd, "message", text); #ifdef TESTING crm_log_message(LOG_ERR, cmd); g_main_quit(mainloop); return; #else send_ipc_message(crm_ch, cmd); #endif } void send_success(const char *text) { HA_Message *cmd = NULL; if(in_transition == FALSE) { crm_warn("Not in transition, not sending message"); return; } in_transition = FALSE; crm_info("Transition \"complete\": %s", text); print_state(LOG_INFO); initialize_graph(); cmd = create_request(CRM_OP_TECOMPLETE, NULL, NULL, CRM_SYSTEM_DC, CRM_SYSTEM_TENGINE, NULL); ha_msg_add(cmd, "message", text); #ifdef TESTING crm_log_message(LOG_INFO, cmd); g_main_quit(mainloop); return; #else send_ipc_message(crm_ch, cmd); #endif } void print_state(int log_level) { do_crm_log(log_level, __FUNCTION__, NULL, "###########"); if(graph == NULL) { do_crm_log(log_level, __FUNCTION__, NULL, "\tEmpty transition graph"); do_crm_log(log_level, __FUNCTION__, NULL, "###########"); return; } slist_iter( synapse, synapse_t, graph, lpc, do_crm_log(log_level, __FUNCTION__, NULL, "Synapse %d %s", synapse->id, synapse->complete?"has completed":"is pending"); if(synapse->complete == FALSE) { slist_iter( input, action_t, synapse->inputs, lpc2, print_input("\t", input, log_level+1); ); } slist_iter( action, action_t, synapse->actions, lpc2, print_action("\t", action, log_level); ); ); do_crm_log(log_level, __FUNCTION__, NULL, "###########"); } void print_input(const char *prefix, action_t *input, int log_level) { do_crm_log(log_level, __FUNCTION__, NULL, "%s[Input %d] %s (%s)", prefix, input->id, input->complete?"Satisfied":"Pending", actiontype2text(input->type)); if(input->complete == FALSE) { crm_log_xml(log_level, "\t Raw input", input->xml); } } void print_action(const char *prefix, action_t *action, int log_level) { do_crm_log(log_level, __FUNCTION__, NULL, "%s[Action %d] %s (%d - %s fail)", prefix, action->id, action->complete?"Completed": action->invoked?"In-flight":"Pending", action->type, action->can_fail?"can":"cannot"); do_crm_log(log_level, __FUNCTION__, NULL, "%s timeout=%d, timer=%d", prefix, action->timeout, action->timer->source_id); if(action->complete == FALSE) { crm_log_xml(log_level, "\t Raw action", action->xml); } } gboolean do_update_cib(crm_data_t *xml_action, int status) { char *code; char since_epoch[64]; crm_data_t *fragment = NULL; crm_data_t *state = NULL; crm_data_t *rsc = NULL; enum cib_errors rc = cib_ok; const char *task = crm_element_value(xml_action, XML_LRM_ATTR_TASK); const char *rsc_id = crm_element_value(xml_action, XML_LRM_ATTR_RSCID); const char *target = crm_element_value(xml_action, XML_LRM_ATTR_TARGET); const char *target_uuid = crm_element_value(xml_action, XML_LRM_ATTR_TARGET_UUID); int call_options = cib_scope_local|cib_discard_reply|cib_sync_call; call_options |= cib_inhibit_notify; if(status == LRM_OP_TIMEOUT) { if(crm_element_value(xml_action, XML_LRM_ATTR_RSCID) != NULL) { crm_warn("%s: %s %s on %s timed out", crm_element_name(xml_action), task, rsc_id, target); } else { crm_warn("%s: %s on %s timed out", crm_element_name(xml_action), task, target); } } /* update the CIB */ fragment = NULL; state = create_xml_node(NULL, XML_CIB_TAG_STATE); #ifdef TESTING /* turn the "pending" notification into a "op completed" notification * when testing... exercises more code this way. */ if(status == -1) { status = 0; } #endif set_xml_property_copy(state, XML_ATTR_UUID, target_uuid); set_xml_property_copy(state, XML_ATTR_UNAME, target); if(status != -1 && (safe_str_eq(task, CRM_OP_SHUTDOWN))) { sprintf(since_epoch, "%ld", (unsigned long)time(NULL)); set_xml_property_copy(rsc, XML_CIB_ATTR_STONITH, since_epoch); } else { code = crm_itoa(status); rsc = create_xml_node(state, XML_CIB_TAG_LRM); rsc = create_xml_node(rsc, XML_LRM_TAG_RESOURCES); rsc = create_xml_node(rsc, XML_LRM_TAG_RESOURCE); set_xml_property_copy(rsc, XML_ATTR_ID, rsc_id); set_xml_property_copy(rsc, XML_LRM_ATTR_TARGET, target); set_xml_property_copy( rsc, XML_LRM_ATTR_TARGET_UUID, target_uuid); if(safe_str_eq(CRMD_RSCSTATE_START, task)) { set_xml_property_copy( rsc, XML_LRM_ATTR_RSCSTATE, CRMD_RSCSTATE_START_PENDING); } else if(safe_str_eq(CRMD_RSCSTATE_STOP, task)) { set_xml_property_copy( rsc, XML_LRM_ATTR_RSCSTATE, CRMD_RSCSTATE_STOP_PENDING); } else { crm_warn("Using status \"pending\" for op \"%s\"..." " this is still in the experimental stage.", crm_str(task)); set_xml_property_copy( rsc, XML_LRM_ATTR_RSCSTATE, CRMD_RSCSTATE_GENERIC_PENDING); } set_xml_property_copy(rsc, XML_LRM_ATTR_OPSTATUS, code); set_xml_property_copy(rsc, XML_LRM_ATTR_RC, code); set_xml_property_copy(rsc, XML_LRM_ATTR_LASTOP, task); crm_free(code); } fragment = create_cib_fragment(state, NULL); - do_crm_log(LOG_DEBUG, __FUNCTION__, NULL, + do_crm_log(LOG_DEV, __FUNCTION__, NULL, "Updating CIB with \"%s\" (%s): %s %s on %s", status<0?"new action":XML_ATTR_TIMEOUT, crm_element_name(xml_action), crm_str(task), rsc_id, target); rc = te_cib_conn->cmds->modify( te_cib_conn, XML_CIB_TAG_STATUS, fragment, NULL, call_options); free_xml(fragment); free_xml(state); if(rc != cib_ok) { return FALSE; } return TRUE; } gboolean timer_callback(gpointer data) { te_timer_t *timer = NULL; if(data == NULL) { crm_err("Timer popped with no data"); return FALSE; } timer = (te_timer_t*)data; if(timer->source_id > 0) { g_source_remove(timer->source_id); } timer->source_id = -1; if(timer->reason == timeout_fuzz) { crm_warn("Transition timeout reached..." " marking transition complete."); send_success("success"); return TRUE; } else if(timer->reason == timeout_timeout) { /* global timeout - abort the transition */ crm_warn("Transition timeout reached..." " marking transition complete."); crm_warn("Some actions may not have been executed."); send_success(XML_ATTR_TIMEOUT); return TRUE; } else if(timer->action == NULL) { crm_err("Action not present!"); return FALSE; } else { /* fail the action * - which may or may not abort the transition */ /* TODO: send a cancel notice to the LRM */ /* TODO: use the ack from above to update the CIB */ return do_update_cib(timer->action->xml, LRM_OP_TIMEOUT); } } gboolean start_te_timer(te_timer_t *timer) { if(((int)timer->source_id) < 0 && timer->timeout > 0) { timer->source_id = Gmain_timeout_add( timer->timeout, timer_callback, (void*)timer); return TRUE; } else if(timer->timeout < 0) { crm_err("Tried to start timer with -ve period"); } else { - crm_debug("#!!#!!# Timer already running (%d)", + crm_devel("#!!#!!# Timer already running (%d)", timer->source_id); } return FALSE; } gboolean stop_te_timer(te_timer_t *timer) { if(timer == NULL) { return FALSE; } if(((int)timer->source_id) > 0) { g_source_remove(timer->source_id); timer->source_id = -2; } else { return FALSE; } return TRUE; } const char * actiontype2text(action_type_e type) { switch(type) { case action_type_pseudo: return "pseduo"; case action_type_rsc: return "rsc"; case action_type_crm: return "crm"; } return ""; } diff --git a/include/crm/crm.h b/include/crm/crm.h index 91bdd8617d..80acbaa5ad 100644 --- a/include/crm/crm.h +++ b/include/crm/crm.h @@ -1,259 +1,255 @@ -/* $Id: crm.h,v 1.45 2005/02/18 10:30:47 andrew Exp $ */ +/* $Id: crm.h,v 1.46 2005/02/19 18:11:04 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 */ #ifndef CRM__H #define CRM__H #include #include #include #include #include #include #ifdef MCHECK #include #endif #include #ifndef CRM_DEV_BUILD # define CRM_DEV_BUILD 0 #endif #define CRM_ASSERT(expr) if((expr) == FALSE) { \ do_crm_log(LOG_CRIT, __PRETTY_FUNCTION__, NULL, \ "Triggered dev assert at %s:%d : %s", \ __FILE__, __LINE__, #expr); \ abort(); \ } extern gboolean crm_assert_failed; #define CRM_DEV_ASSERT(expr) crm_assert_failed = FALSE; \ if((expr) == FALSE) { \ crm_assert_failed = TRUE; \ do_crm_log(CRM_DEV_BUILD?LOG_CRIT:LOG_ERR, \ __PRETTY_FUNCTION__, NULL, \ "Triggered dev assert at %s:%d : %s", \ __FILE__, __LINE__, #expr); \ if(CRM_DEV_BUILD) { \ abort(); \ } \ } /* Clean these up at some point, some probably should be runtime options */ #define WORKING_DIR HA_VARLIBDIR"/heartbeat/crm" #define BIN_DIR "/usr/lib/heartbeat" #define MAXDATASIZE 65535 /* ipc comms */ #define SOCKET_LEN 1024 #define APPNAME_LEN 256 #define LOG_DIR "/var/log" #define MAX_IPC_FAIL 5 #define CIB_FILENAME WORKING_DIR"/cib.xml" #define CIB_BACKUP WORKING_DIR"/cib_backup.xml" #define DEVEL_CIB_COPY 1 #define DEVEL_DIR "/tmp/crm" #define CRM_VERSION "0.7" #define MSG_LOG 1 #define DOT_FSA_ACTIONS 1 #define DOT_ALL_FSA_INPUTS 1 #define FSA_TRACE 1 /* #define USE_FAKE_LRM 1 */ /* Sub-systems */ #define CRM_SYSTEM_DC "dc" #define CRM_SYSTEM_DCIB "dcib" /* The master CIB */ #define CRM_SYSTEM_CIB "cib" #define CRM_SYSTEM_CRMD "crmd" #define CRM_SYSTEM_LRMD "lrmd" #define CRM_SYSTEM_PENGINE "pengine" #define CRM_SYSTEM_TENGINE "tengine" /* Valid operations */ #define CRM_OP_NOOP "noop" /* soon to be moved to cib.h */ #define CRM_OP_CIB_SLAVE "cib_slave" #define CRM_OP_CIB_SLAVEALL "cib_slave_all" #define CRM_OP_CIB_MASTER "cib_master" #define CRM_OP_CIB_SYNC "cib_sync" #define CRM_OP_CIB_ISMASTER "cib_ismaster" #define CRM_OP_CIB_BUMP "cib_bump" #define CRM_OP_CIB_QUERY "cib_query" #define CRM_OP_CIB_CREATE "cib_create" #define CRM_OP_CIB_UPDATE "cib_update" #define CRM_OP_CIB_DELETE "cib_delete" #define CRM_OP_CIB_ERASE "cib_erase" #define CRM_OP_CIB_REPLACE "cib_replace" #define CRM_OP_DIE "die_no_respawn" #define CRM_OP_RETRIVE_CIB "retrieve_cib" #define CRM_OP_JOINACK "join_ack_nack" #define CRM_OP_WELCOME "welcome" #define CRM_OP_PING "ping" #define CRM_OP_VOTE "vote" #define CRM_OP_HELLO "hello" #define CRM_OP_ANNOUNCE "announce" #define CRM_OP_HBEAT "dc_beat" #define CRM_OP_PECALC "pe_calc" #define CRM_OP_ABORT "abort" #define CRM_OP_QUIT "quit" #define CRM_OP_LOCAL_SHUTDOWN "start_shutdown" #define CRM_OP_SHUTDOWN_REQ "req_shutdown" #define CRM_OP_SHUTDOWN "do_shutdown" #define CRM_OP_EVENTCC "event_cc" #define CRM_OP_TEABORT "te_abort" #define CRM_OP_TRANSITION "transition" #define CRM_OP_TECOMPLETE "te_complete" #define CRM_OP_REGISTER "register" #define CRM_OP_DEBUG_UP "debug_inc" #define CRM_OP_DEBUG_DOWN "debug_dec" #define CRMD_STATE_ACTIVE "member" #define CRMD_STATE_INACTIVE "down" #define CRMD_JOINSTATE_DOWN "down" #define CRMD_JOINSTATE_PENDING "pending" #define CRMD_JOINSTATE_MEMBER "member" #define CRMD_RSCSTATE_START "start" #define CRMD_RSCSTATE_START_PENDING "starting" #define CRMD_RSCSTATE_START_OK "running" #define CRMD_RSCSTATE_START_FAIL "start_failed" #define CRMD_RSCSTATE_STOP "stop" #define CRMD_RSCSTATE_STOP_PENDING "stopping" #define CRMD_RSCSTATE_STOP_OK "stopped" #define CRMD_RSCSTATE_STOP_FAIL "stop_failed" #define CRMD_RSCSTATE_MON "status" #define CRMD_RSCSTATE_MON_PENDING CRMD_RSCSTATE_START_OK #define CRMD_RSCSTATE_MON_OK CRMD_RSCSTATE_START_OK #define CRMD_RSCSTATE_MON_FAIL "status_failed" /* #define CRMD_RSCSTATE_GENERIC "pending" */ #define CRMD_RSCSTATE_GENERIC_PENDING "pending" #define CRMD_RSCSTATE_GENERIC_OK "complete" #define CRMD_RSCSTATE_GENERIC_FAIL "pending_failed" typedef GList* GListPtr; #define crm_atoi(text, default) atoi(text?text:default) extern gboolean safe_str_eq(const char *a, const char *b); extern gboolean safe_str_neq(const char *a, const char *b); #define slist_iter(w, x, y, z, a) \ { \ GListPtr __crm_iter_head = y; \ x *w = NULL; \ int z = 0; \ for(; __crm_iter_head != NULL; z++) { \ w = __crm_iter_head->data; \ __crm_iter_head = __crm_iter_head->next; \ { a; } \ } \ } #define safe_val3(def, t,u,v) (t?t->u?t->u->v:def:def) /* Developmental debug stuff */ #define LOG_VERBOSE LOG_DEBUG+1 #define LOG_DEV LOG_DEBUG+2 #define LOG_TRACE LOG_DEBUG+3 #define LOG_INSANE LOG_DEBUG+5 #define LOG_MSG LOG_TRACE -#if 1 # define crm_crit(w...) do_crm_log(LOG_CRIT, __FUNCTION__, NULL, w) # define crm_err(w...) do_crm_log(LOG_ERR, __FUNCTION__, NULL, w) # define crm_warn(w...) do_crm_log(LOG_WARNING, __FUNCTION__, NULL, w) # define crm_notice(w...) do_crm_log(LOG_NOTICE, __FUNCTION__, NULL, w) # define crm_info(w...) do_crm_log(LOG_INFO, __FUNCTION__, NULL, w) +#if 1 # define crm_debug(w...) do_crm_log(LOG_DEBUG, __FUNCTION__, NULL, w) # define crm_devel(w...) do_crm_log(LOG_DEV, __FUNCTION__, NULL, w) # define crm_verbose(w...) do_crm_log(LOG_VERBOSE, __FUNCTION__, NULL, w) # define crm_trace(w...) do_crm_log(LOG_TRACE, __FUNCTION__, NULL, w) # define crm_insane(w...) do_crm_log(LOG_INSANE, __FUNCTION__, NULL, w) #else -# define crm_crit(w...) cl_log(LOG_CRIT, w) -# define crm_err(w...) cl_log(LOG_ERR, w) -# define crm_warn(w...) cl_log(LOG_WARNING, w) -# define crm_notice(w...) cl_log(LOG_NOTICE, w) -# define crm_info(w...) cl_log(LOG_INFO, w) -# define crm_debug(w...) cl_log(LOG_DEBUG, w) -# define crm_devel(w...) cl_log(LOG_DEV, w) -# define crm_verbose(w...) cl_log(LOG_VERBOSE, w) -# define crm_trace(w...) cl_log(LOG_TRACE, w) -# define crm_insane(w...) cl_log(LOG_INSANE, w) +# define crm_debug(w...) if(0) { do_crm_log(LOG_DEBUG, NULL, NULL, w); } +# define crm_devel(w...) if(0) { do_crm_log(LOG_DEV, NULL, NULL, w); } +# define crm_verbose(w...) if(0) { do_crm_log(LOG_VERBOSE, NULL, NULL, w); } +# define crm_trace(w...) if(0) { do_crm_log(LOG_TRACE, NULL, NULL, w); } +# define crm_insane(w...) if(0) { do_crm_log(LOG_INSANE, NULL, NULL, w); } #endif extern void crm_log_message_adv(int level, const char *alt_debugfile, const HA_Message *msg); #define crm_log_message(level, msg) crm_log_message_adv(level, NULL, msg) #define crm_do_action(level, actions) if(crm_log_level >= level) { \ actions; \ } -#define crm_debug_action(x) crm_do_action(LOG_DEBUG, x) #define crm_info_action(x) crm_do_action(LOG_INFO, x) +#define crm_debug_action(x) crm_do_action(LOG_DEBUG, x) +#define crm_devel_action(x) crm_do_action(LOG_DEV, x) #define crm_log_xml(level, text, xml) if(crm_log_level >= level) { \ print_xml_formatted(level, __FUNCTION__, xml, text); \ } #define crm_xml_crit(xml, text) crm_log_xml(LOG_CRIT, text, xml) #define crm_xml_err(xml, text) crm_log_xml(LOG_ERR, text, xml) #define crm_xml_warn(xml, text) crm_log_xml(LOG_WARNING, text, xml) #define crm_xml_notice(xml, text) crm_log_xml(LOG_NOTICE, text, xml) #define crm_xml_info(xml, text) crm_log_xml(LOG_INFO, text, xml) #define crm_xml_debug(xml, text) crm_log_xml(LOG_DEBUG, text, xml) #define crm_xml_devel(xml, text) crm_log_xml(LOG_DEV, text, xml) #define crm_xml_verbose(xml, text) crm_log_xml(LOG_VERBOSE, text, xml) #define crm_xml_trace(xml, text) crm_log_xml(LOG_TRACE, text, xml) #define crm_xml_insane(xml, text) crm_log_xml(LOG_INSANE, text, xml) #define crm_malloc(new_obj,length) \ { \ new_obj = cl_malloc(length); \ if(new_obj == NULL) { \ crm_crit("Out of memory... exiting"); \ exit(1); \ } else { \ memset(new_obj, 0, length); \ } \ } #if 1 # define crm_free(x) if(x) { \ CRM_ASSERT(cl_is_allocated(x) == 1); \ cl_free(x); \ x=NULL; \ } #else # define crm_free(x) x=NULL #endif #define crm_str(x) (const char*)(x?x:"") #if 1 # define crm_msg_del(msg) if(msg != NULL) { ha_msg_del(msg); } #else # define crm_msg_del(msg) msg = NULL #endif #endif diff --git a/lib/crm/cib/cib_client.c b/lib/crm/cib/cib_client.c index 06f34c004a..d83b4c1167 100755 --- a/lib/crm/cib/cib_client.c +++ b/lib/crm/cib/cib_client.c @@ -1,1189 +1,1189 @@ /* * Copyright (c) 2004 International Business Machines * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser 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 library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser 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 #include gboolean verify_cib_cmds(cib_t *cib); int cib_client_set_op_callback( cib_t *cib, void (*callback)(const struct ha_msg *msg, int call_id, int rc, crm_data_t *output)); int cib_client_noop(cib_t *cib, int call_options); int cib_client_ping(cib_t *cib, crm_data_t **output_data, int call_options); int cib_client_query(cib_t *cib, const char *section, crm_data_t **output_data, int call_options); int cib_client_query_from(cib_t *cib, const char *host, const char *section, crm_data_t **output_data, int call_options); int cib_client_sync(cib_t *cib, const char *section, int call_options); int cib_client_sync_from( cib_t *cib, const char *host, const char *section, int call_options); int cib_client_is_master(cib_t *cib); int cib_client_set_slave(cib_t *cib, int call_options); int cib_client_set_slave_all(cib_t *cib, int call_options); int cib_client_set_master(cib_t *cib, int call_options); int cib_client_bump_epoch(cib_t *cib, int call_options); int cib_client_create(cib_t *cib, const char *section, crm_data_t *data, crm_data_t **output_data, int call_options) ; int cib_client_modify(cib_t *cib, const char *section, crm_data_t *data, crm_data_t **output_data, int call_options) ; int cib_client_replace(cib_t *cib, const char *section, crm_data_t *data, crm_data_t **output_data, int call_options) ; int cib_client_delete(cib_t *cib, const char *section, crm_data_t *data, crm_data_t **output_data, int call_options) ; int cib_client_erase( cib_t *cib, crm_data_t **output_data, int call_options); int cib_client_quit(cib_t *cib, int call_options); int cib_client_add_notify_callback( cib_t *cib, const char *event, void (*callback)( const char *event, struct ha_msg *msg)); int cib_client_del_notify_callback( cib_t *cib, const char *event, void (*callback)( const char *event, struct ha_msg *msg)); gint ciblib_GCompareFunc(gconstpointer a, gconstpointer b); extern cib_t *cib_native_new(cib_t *cib); static enum cib_variant configured_variant = cib_native; /* define of the api functions*/ cib_t* cib_new(void) { cib_t* new_cib = NULL; if(configured_variant != cib_native) { crm_err("Only the native CIB type is currently implemented"); return NULL; } crm_malloc(new_cib, sizeof(cib_t)); new_cib->call_id = 1; new_cib->type = cib_none; new_cib->state = cib_disconnected; new_cib->op_callback = NULL; new_cib->variant_opaque = NULL; new_cib->notify_list = NULL; /* the rest will get filled in by the variant constructor */ crm_malloc(new_cib->cmds, sizeof(cib_api_operations_t)); memset(new_cib->cmds, 0, sizeof(cib_api_operations_t)); new_cib->cmds->set_op_callback = cib_client_set_op_callback; new_cib->cmds->add_notify_callback = cib_client_add_notify_callback; new_cib->cmds->del_notify_callback = cib_client_del_notify_callback; new_cib->cmds->noop = cib_client_noop; new_cib->cmds->ping = cib_client_ping; new_cib->cmds->query = cib_client_query; new_cib->cmds->sync = cib_client_sync; new_cib->cmds->query_from = cib_client_query_from; new_cib->cmds->sync_from = cib_client_sync_from; new_cib->cmds->is_master = cib_client_is_master; new_cib->cmds->set_master = cib_client_set_master; new_cib->cmds->set_slave = cib_client_set_slave; new_cib->cmds->set_slave_all = cib_client_set_slave_all; new_cib->cmds->bump_epoch = cib_client_bump_epoch; new_cib->cmds->create = cib_client_create; new_cib->cmds->modify = cib_client_modify; new_cib->cmds->replace = cib_client_replace; new_cib->cmds->delete = cib_client_delete; new_cib->cmds->erase = cib_client_erase; new_cib->cmds->quit = cib_client_quit; cib_native_new(new_cib); if(verify_cib_cmds(new_cib) == FALSE) { return NULL; } return new_cib; } int cib_client_set_op_callback( cib_t *cib, void (*callback)(const struct ha_msg *msg, int call_id, int rc, crm_data_t *output)) { if(callback == NULL) { crm_info("Un-Setting operation callback"); } else { - crm_debug("Setting operation callback"); + crm_devel("Setting operation callback"); } cib->op_callback = callback; return cib_ok; } int cib_client_noop(cib_t *cib, int call_options) { if(cib == NULL) { return cib_missing; } else if(cib->state == cib_disconnected) { return cib_not_connected; } else if(cib->cmds->variant_op == NULL) { return cib_variant; } return cib->cmds->variant_op( cib, CRM_OP_NOOP, NULL, NULL, NULL, NULL, call_options); } int cib_client_ping(cib_t *cib, crm_data_t **output_data, int call_options) { if(cib == NULL) { return cib_missing; } else if(cib->state == cib_disconnected) { return cib_not_connected; } else if(cib->cmds->variant_op == NULL) { return cib_variant; } return cib->cmds->variant_op( cib, CRM_OP_PING, NULL,NULL,NULL, output_data, call_options); } int cib_client_query(cib_t *cib, const char *section, crm_data_t **output_data, int call_options) { return cib->cmds->query_from( cib, NULL, section, output_data, call_options); } int cib_client_query_from(cib_t *cib, const char *host, const char *section, crm_data_t **output_data, int call_options) { if(cib == NULL) { return cib_missing; } else if(cib->state == cib_disconnected) { return cib_not_connected; } else if(cib->cmds->variant_op == NULL) { return cib_variant; } return cib->cmds->variant_op(cib, CRM_OP_CIB_QUERY, host, section, NULL, output_data, call_options); } int cib_client_is_master(cib_t *cib) { if(cib == NULL) { return cib_missing; } else if(cib->state == cib_disconnected) { return cib_not_connected; } else if(cib->cmds->variant_op == NULL) { return cib_variant; } return cib->cmds->variant_op( cib, CRM_OP_CIB_ISMASTER, NULL, NULL,NULL,NULL, cib_scope_local|cib_sync_call); } int cib_client_set_slave(cib_t *cib, int call_options) { if(cib == NULL) { return cib_missing; } else if(cib->state == cib_disconnected) { return cib_not_connected; } else if(cib->cmds->variant_op == NULL) { return cib_variant; } return cib->cmds->variant_op( cib, CRM_OP_CIB_SLAVE, NULL,NULL,NULL,NULL, call_options); } int cib_client_set_slave_all(cib_t *cib, int call_options) { if(cib == NULL) { return cib_missing; } else if(cib->state == cib_disconnected) { return cib_not_connected; } else if(cib->cmds->variant_op == NULL) { return cib_variant; } return cib->cmds->variant_op( cib, CRM_OP_CIB_SLAVEALL, NULL,NULL,NULL,NULL, call_options); } int cib_client_set_master(cib_t *cib, int call_options) { if(cib == NULL) { return cib_missing; } else if(cib->state == cib_disconnected) { return cib_not_connected; } else if(cib->cmds->variant_op == NULL) { return cib_variant; } - crm_debug("Adding cib_scope_local to options"); + crm_devel("Adding cib_scope_local to options"); return cib->cmds->variant_op( cib, CRM_OP_CIB_MASTER, NULL,NULL,NULL,NULL, call_options|cib_scope_local); } int cib_client_bump_epoch(cib_t *cib, int call_options) { if(cib == NULL) { return cib_missing; } else if(cib->state == cib_disconnected) { return cib_not_connected; } else if(cib->cmds->variant_op == NULL) { return cib_variant; } return cib->cmds->variant_op( cib, CRM_OP_CIB_BUMP, NULL, NULL, NULL, NULL, call_options); } int cib_client_sync(cib_t *cib, const char *section, int call_options) { return cib->cmds->sync_from(cib, NULL, section, call_options); } int cib_client_sync_from( cib_t *cib, const char *host, const char *section, int call_options) { enum cib_errors rc = cib_ok; crm_data_t *stored_cib = NULL; crm_data_t *current_cib = NULL; if(cib == NULL) { return cib_missing; } else if(cib->state == cib_disconnected) { return cib_not_connected; } else if(cib->cmds->variant_op == NULL) { return cib_variant; } - crm_debug("Retrieving current CIB from %s", host); + crm_devel("Retrieving current CIB from %s", host); rc = cib->cmds->query_from( cib, host, section, ¤t_cib, call_options|cib_sync_call); if(current_cib == NULL) { crm_err("Could not retrive current CIB."); } else if(rc == cib_ok) { if(call_options & cib_scope_local) { /* having scope == local makes no sense from here on */ call_options ^= cib_scope_local; } - crm_debug("Storing current CIB (should trigger a store everywhere)"); -/* crm_xml_debug(current_cib, "XML to store"); */ + crm_devel("Storing current CIB (should trigger a store everywhere)"); +/* crm_xml_devel(current_cib, "XML to store"); */ rc = cib->cmds->replace( cib, section, current_cib, &stored_cib, call_options); } free_xml(current_cib); free_xml(stored_cib); return rc; } int cib_client_create(cib_t *cib, const char *section, crm_data_t *data, crm_data_t **output_data, int call_options) { if(cib == NULL) { return cib_missing; } else if(cib->state == cib_disconnected) { return cib_not_connected; } else if(cib->cmds->variant_op == NULL) { return cib_variant; } return cib->cmds->variant_op(cib, CRM_OP_CIB_CREATE, NULL, section, data, output_data, call_options); } int cib_client_modify(cib_t *cib, const char *section, crm_data_t *data, crm_data_t **output_data, int call_options) { if(cib == NULL) { return cib_missing; } else if(cib->state == cib_disconnected) { return cib_not_connected; } else if(cib->cmds->variant_op == NULL) { return cib_variant; } return cib->cmds->variant_op(cib, CRM_OP_CIB_UPDATE, NULL, section, data, output_data, call_options); } int cib_client_replace(cib_t *cib, const char *section, crm_data_t *data, crm_data_t **output_data, int call_options) { if(cib == NULL) { return cib_missing; } else if(cib->state == cib_disconnected) { return cib_not_connected; } else if(cib->cmds->variant_op == NULL) { return cib_variant; } else if(data == NULL) { return cib_missing_data; } return cib->cmds->variant_op(cib, CRM_OP_CIB_REPLACE, NULL, section, data, output_data, call_options); } int cib_client_delete(cib_t *cib, const char *section, crm_data_t *data, crm_data_t **output_data, int call_options) { if(cib == NULL) { return cib_missing; } else if(cib->state == cib_disconnected) { return cib_not_connected; } else if(cib->cmds->variant_op == NULL) { return cib_variant; } return cib->cmds->variant_op(cib, CRM_OP_CIB_DELETE, NULL, section, data, output_data, call_options); } int cib_client_erase( cib_t *cib, crm_data_t **output_data, int call_options) { if(cib == NULL) { return cib_missing; } else if(cib->state == cib_disconnected) { return cib_not_connected; } else if(cib->cmds->variant_op == NULL) { return cib_variant; } return cib->cmds->variant_op(cib, CRM_OP_CIB_ERASE, NULL, NULL, NULL, output_data, call_options); } int cib_client_quit(cib_t *cib, int call_options) { if(cib == NULL) { return cib_missing; } else if(cib->state == cib_disconnected) { return cib_not_connected; } else if(cib->cmds->variant_op == NULL) { return cib_variant; } return cib->cmds->variant_op( cib, CRM_OP_QUIT, NULL, NULL, NULL, NULL, call_options); } int cib_client_add_notify_callback( cib_t *cib, const char *event, void (*callback)( const char *event, struct ha_msg *msg)) { GList *list_item = NULL; cib_notify_client_t *new_client = NULL; crm_debug("Adding callback for %s events (%d)", event, g_list_length(cib->notify_list)); crm_malloc(new_client, sizeof(cib_notify_client_t)); new_client->event = event; new_client->callback = callback; list_item = g_list_find_custom( cib->notify_list, new_client, ciblib_GCompareFunc); if(list_item != NULL) { crm_warn("Callback already present"); } else { cib->notify_list = g_list_append( cib->notify_list, new_client); - crm_debug("Callback added (%d)", g_list_length(cib->notify_list)); + crm_devel("Callback added (%d)", g_list_length(cib->notify_list)); } return cib_ok; } int cib_client_del_notify_callback( cib_t *cib, const char *event, void (*callback)( const char *event, struct ha_msg *msg)) { GList *list_item = NULL; cib_notify_client_t *new_client = NULL; crm_debug("Removing callback for %s events", event); crm_malloc(new_client, sizeof(cib_notify_client_t)); new_client->event = event; new_client->callback = callback; list_item = g_list_find_custom( cib->notify_list, new_client, ciblib_GCompareFunc); if(list_item != NULL) { cib_notify_client_t *list_client = list_item->data; cib->notify_list = g_list_remove(cib->notify_list, list_client); crm_free(list_client); - crm_debug("Removed callback"); + crm_devel("Removed callback"); } else { - crm_debug("Callback not present"); + crm_devel("Callback not present"); } crm_free(new_client); return cib_ok; } gint ciblib_GCompareFunc(gconstpointer a, gconstpointer b) { const cib_notify_client_t *a_client = a; const cib_notify_client_t *b_client = b; if(a_client->callback == b_client->callback && safe_str_neq(a_client->event, b_client->event)) { return 0; } else if(((long)a_client->callback) < ((long)b_client->callback)) { return -1; } return 1; } char * cib_pluralSection(const char *a_section) { char *a_section_parent = NULL; if (a_section == NULL) { a_section_parent = crm_strdup("all"); } else if(strcmp(a_section, XML_TAG_CIB) == 0) { a_section_parent = crm_strdup("all"); } else if(strcmp(a_section, XML_CIB_TAG_NODE) == 0) { a_section_parent = crm_strdup(XML_CIB_TAG_NODES); } else if(strcmp(a_section, XML_CIB_TAG_STATE) == 0) { a_section_parent = crm_strdup(XML_CIB_TAG_STATUS); } else if(strcmp(a_section, XML_CIB_TAG_CONSTRAINT) == 0) { a_section_parent = crm_strdup(XML_CIB_TAG_CONSTRAINTS); } else if(strcmp(a_section, "rsc_location") == 0) { a_section_parent = crm_strdup(XML_CIB_TAG_CONSTRAINTS); } else if(strcmp(a_section, "rsc_dependancy") == 0) { a_section_parent = crm_strdup(XML_CIB_TAG_CONSTRAINTS); } else if(strcmp(a_section, "rsc_order") == 0) { a_section_parent = crm_strdup(XML_CIB_TAG_CONSTRAINTS); } else if(strcmp(a_section, XML_CIB_TAG_RESOURCE) == 0) { a_section_parent = crm_strdup(XML_CIB_TAG_RESOURCES); } else if(strcmp(a_section, XML_CIB_TAG_NVPAIR) == 0) { a_section_parent = crm_strdup(XML_CIB_TAG_CRMCONFIG); } else { crm_err("Unknown section %s", a_section); a_section_parent = crm_strdup("all"); } crm_verbose("Plural of %s is %s", crm_str(a_section), a_section_parent); return a_section_parent; } const char * cib_error2string(enum cib_errors return_code) { const char *error_msg = NULL; switch(return_code) { case cib_msg_field_add: error_msg = "failed adding field to cib message"; break; case cib_operation: error_msg = "invalid operation"; break; case cib_create_msg: error_msg = "couldnt create cib message"; break; case cib_client_gone: error_msg = "client left before we could send reply"; break; case cib_not_connected: error_msg = "not connected"; break; case cib_not_authorized: error_msg = "not authorized"; break; case cib_send_failed: error_msg = "send failed"; break; case cib_reply_failed: error_msg = "reply failed"; break; case cib_return_code: error_msg = "no return code"; break; case cib_output_ptr: error_msg = "nowhere to store output"; break; case cib_output_data: error_msg = "corrupt output data"; break; case cib_connection: error_msg = "connection failed"; break; case cib_callback_register: error_msg = "couldnt register callback channel"; break; case cib_authentication: error_msg = ""; break; case cib_registration_msg: error_msg = "invalid registration msg"; break; case cib_callback_token: error_msg = "callback token not found"; break; case cib_missing: error_msg = "cib object missing"; break; case cib_variant: error_msg = "unknown/corrupt cib variant"; break; case CIBRES_MISSING_ID: error_msg = "The id field is missing"; break; case CIBRES_MISSING_TYPE: error_msg = "The type field is missing"; break; case CIBRES_MISSING_FIELD: error_msg = "A required field is missing"; break; case CIBRES_OBJTYPE_MISMATCH: error_msg = "CIBRES_OBJTYPE_MISMATCH"; break; case cib_EXISTS: error_msg = "The object already exists"; break; case cib_NOTEXISTS: error_msg = "The object does not exist"; break; case CIBRES_CORRUPT: error_msg = "The CIB is corrupt"; break; case cib_NOOBJECT: error_msg = "The update was empty"; break; case cib_NOPARENT: error_msg = "The parent object does not exist"; break; case cib_NODECOPY: error_msg = "Failed while copying update"; break; case CIBRES_OTHER: error_msg = "CIBRES_OTHER"; break; case cib_ok: error_msg = "ok"; break; case cib_unknown: error_msg = "Unknown error"; break; case cib_STALE: error_msg = "Discarded old update"; break; case cib_ACTIVATION: error_msg = "Activation Failed"; break; case cib_NOSECTION: error_msg = "Required section was missing"; break; case cib_NOTSUPPORTED: error_msg = "Supplied information is not supported"; break; case cib_not_master: error_msg = "Local service is not the master instance"; break; case cib_client_corrupt: error_msg = "Service client not valid"; break; case cib_master_timeout: error_msg = "No master service is currently active"; break; case cib_revision_unsupported: error_msg = "The required CIB revision number is not supported"; break; case cib_revision_unknown: error_msg = "The CIB revision number could not be determined"; break; case cib_missing_data: error_msg = "Required data for this CIB API call not found"; break; } if(error_msg == NULL) { crm_err("Unknown CIB Error Code: %d", return_code); error_msg = ""; } return error_msg; } const char * cib_op2string(enum cib_op operation) { const char *operation_msg = NULL; switch(operation) { case 0: operation_msg = "none"; break; case 1: operation_msg = "add"; break; case 2: operation_msg = "modify"; break; case 3: operation_msg = "delete"; break; case CIB_OP_MAX: operation_msg = "invalid operation"; break; } if(operation_msg == NULL) { crm_err("Unknown CIB operation %d", operation); operation_msg = ""; } return operation_msg; } int cib_section2enum(const char *a_section) { if(a_section == NULL || strcmp(a_section, "all") == 0) { return cib_section_all; } else if(strcmp(a_section, XML_CIB_TAG_NODES) == 0) { return cib_section_nodes; } else if(strcmp(a_section, XML_CIB_TAG_STATUS) == 0) { return cib_section_status; } else if(strcmp(a_section, XML_CIB_TAG_CONSTRAINTS) == 0) { return cib_section_constraints; } else if(strcmp(a_section, XML_CIB_TAG_RESOURCES) == 0) { return cib_section_resources; } else if(strcmp(a_section, XML_CIB_TAG_CRMCONFIG) == 0) { return cib_section_crmconfig; } crm_err("Unknown CIB section: %s", a_section); return cib_section_none; } int cib_compare_generation(crm_data_t *left, crm_data_t *right) { int int_elem_l = -1; int int_elem_r = -1; const char *elem_l = crm_element_value(left, XML_ATTR_GENERATION); const char *elem_r = NULL; crm_xml_trace(left, "left"); if(right != NULL) { elem_r = crm_element_value(right, XML_ATTR_GENERATION); crm_xml_trace(right, "right"); } if(elem_l != NULL) { int_elem_l = atoi(elem_l); } if(elem_r != NULL) { int_elem_r = atoi(elem_r); } if(int_elem_l < int_elem_r) { crm_verbose("lt - XML_ATTR_GENERATION"); return -1; } else if(int_elem_l > int_elem_r) { crm_verbose("gt - XML_ATTR_GENERATION"); return 1; } int_elem_l = -1; int_elem_r = -1; elem_l = crm_element_value(left, XML_ATTR_NUMUPDATES); if(right != NULL) { elem_r = crm_element_value(right, XML_ATTR_NUMUPDATES); } if(elem_l != NULL) { int_elem_l = atoi(elem_l); } if(elem_r != NULL) { int_elem_r = atoi(elem_r); } crm_xml_trace(left, "left"); crm_xml_trace(left, "right"); if(int_elem_l < int_elem_r) { crm_verbose("lt - XML_ATTR_NUMUPDATES"); return -1; } else if(int_elem_l > int_elem_r) { crm_verbose("gt - XML_ATTR_NUMUPDATES"); return 1; } crm_verbose("eq - XML_ATTR_NUMUPDATES"); int_elem_l = -1; int_elem_r = -1; elem_l = crm_element_value(left, XML_ATTR_NUMPEERS); if(right != NULL) { elem_r = crm_element_value(right, XML_ATTR_NUMPEERS); } if(elem_l != NULL) { int_elem_l = atoi(elem_l); } if(elem_r != NULL) { int_elem_r = atoi(elem_r); } if(int_elem_l < int_elem_r) { crm_verbose("lt - XML_ATTR_NUMPEERS"); return -1; } else if(int_elem_l > int_elem_r) { crm_verbose("gt - XML_ATTR_NUMPEERS"); return 1; } crm_verbose("eq - XML_ATTR_NUMPEERS"); elem_l = crm_element_value(left, XML_ATTR_NUMPEERS); if(right != NULL) { elem_r = crm_element_value(right, XML_ATTR_NUMPEERS); } if(elem_l == NULL && elem_r == NULL) { } else if(elem_l == NULL) { crm_verbose("lt - XML_ATTR_NUMPEERS"); return -1; } else if(elem_r == NULL) { crm_verbose("gt - XML_ATTR_NUMPEERS"); return 1; } else if(safe_str_neq(elem_l, elem_r)) { if(safe_str_eq(elem_l, XML_BOOLEAN_TRUE)) { crm_verbose("gt - XML_ATTR_NUMPEERS"); return 1; } else if(safe_str_eq(elem_r, XML_BOOLEAN_TRUE)) { crm_verbose("lt - XML_ATTR_NUMPEERS"); return -1; } } crm_verbose("eq - XML_ATTR_NUMPEERS"); return 0; } crm_data_t* get_cib_copy(cib_t *cib) { crm_data_t *xml_cib; int options = cib_scope_local|cib_sync_call; if(cib->cmds->query(cib, NULL, &xml_cib, options) != cib_ok) { crm_err("Couldnt retrieve the CIB"); return NULL; } else if(xml_cib == NULL) { crm_err("The CIB result was empty"); return NULL; } return find_xml_node(xml_cib, XML_TAG_CIB, TRUE); } crm_data_t* cib_get_generation(cib_t *cib) { crm_data_t *the_cib = get_cib_copy(cib); crm_data_t *generation = create_xml_node( NULL, XML_CIB_TAG_GENERATION_TUPPLE); if(the_cib != NULL) { copy_in_properties(generation, the_cib); free_xml(the_cib); } return generation; } /* * The caller should never free the return value */ crm_data_t* get_object_root(const char *object_type, crm_data_t *the_root) { const char *node_stack[2]; crm_data_t *tmp_node = NULL; if(the_root == NULL) { crm_err("CIB root object was NULL"); return NULL; } node_stack[0] = XML_CIB_TAG_CONFIGURATION; node_stack[1] = object_type; if(object_type == NULL || strlen(object_type) == 0 || safe_str_eq("all", object_type) || safe_str_eq(XML_TAG_CIB, object_type)) { /* get the whole cib */ return the_root; } else if(strcmp(object_type, XML_CIB_TAG_STATUS) == 0) { /* these live in a different place */ tmp_node = find_xml_node(the_root, XML_CIB_TAG_STATUS, TRUE); node_stack[0] = XML_CIB_TAG_STATUS; node_stack[1] = NULL; } else { tmp_node = find_xml_node_nested(the_root, node_stack, 2); } if (tmp_node == NULL) { crm_err("Section [%s [%s]] not present in %s", node_stack[0], node_stack[1]?node_stack[1]:"", crm_element_name(the_root)); } return tmp_node; } crm_data_t* create_cib_fragment_adv( crm_data_t *update, const char *section, const char *source) { crm_data_t *cib = NULL; gboolean whole_cib = FALSE; crm_data_t *fragment = create_xml_node(NULL, XML_TAG_FRAGMENT); crm_data_t *object_root = NULL; char *auto_section = NULL; const char *update_name = NULL; if(update != NULL) { update_name = crm_element_name(update); } auto_section = cib_pluralSection(update_name); if(update == NULL && section == NULL) { - crm_debug("Creating a blank fragment"); + crm_devel("Creating a blank fragment"); update = createEmptyCib(); section = auto_section; } else if(update == NULL) { crm_err("No update to create a fragment for"); cib = createEmptyCib(); return NULL; } else if(section == NULL) { section = auto_section; } else if(strcmp(auto_section, section) != 0) { crm_err("Values for update (tag=%s) and section (%s)" " were not consistent", crm_element_name(update), section); crm_free(auto_section); return NULL; } if(safe_str_eq(section, "all") && safe_str_eq(crm_element_name(update), XML_TAG_CIB)) { whole_cib = TRUE; } set_xml_property_copy(fragment, XML_ATTR_SECTION, section); if(whole_cib == FALSE) { cib = createEmptyCib(); set_xml_property_copy(cib, "debug_source", source); object_root = get_object_root(section, cib); add_node_copy(object_root, update); add_node_copy(fragment, cib); free_xml(cib); cib = find_xml_node(fragment, XML_TAG_CIB, TRUE); } else { add_node_copy(fragment, update); cib = find_xml_node(fragment, XML_TAG_CIB, TRUE); set_xml_property_copy(cib, "debug_source", source); } crm_free(auto_section); - crm_debug("Verifying created fragment"); + crm_devel("Verifying created fragment"); if(verifyCibXml(cib) == FALSE) { crm_err("Fragment creation failed"); crm_xml_err(update, "[src]"); crm_xml_err(fragment, "[created]"); free_xml(fragment); fragment = NULL; } return fragment; } /* * It is the callers responsibility to free both the new CIB (output) * and the new CIB (input) */ crm_data_t* createEmptyCib(void) { crm_data_t *cib_root = NULL, *config = NULL, *status = NULL; cib_root = create_xml_node(NULL, XML_TAG_CIB); config = create_xml_node(cib_root, XML_CIB_TAG_CONFIGURATION); status = create_xml_node(cib_root, XML_CIB_TAG_STATUS); set_node_tstamp(cib_root); set_node_tstamp(config); set_node_tstamp(status); /* set_xml_property_copy(cib_root, "version", "1"); */ set_xml_property_copy(cib_root, "generated", XML_BOOLEAN_TRUE); set_xml_property_copy( cib_root, XML_ATTR_CIB_REVISION, cib_feature_revision_s); create_xml_node(config, XML_CIB_TAG_CRMCONFIG); create_xml_node(config, XML_CIB_TAG_NODES); create_xml_node(config, XML_CIB_TAG_RESOURCES); create_xml_node(config, XML_CIB_TAG_CONSTRAINTS); if (verifyCibXml(cib_root)) { return cib_root; } free_xml(cib_root); crm_crit("The generated CIB did not pass integrity testing!!" " All hope is lost."); return NULL; } gboolean verifyCibXml(crm_data_t *cib) { gboolean is_valid = TRUE; crm_data_t *tmp_node = NULL; if (cib == NULL) { crm_warn("CIB was empty."); return FALSE; } tmp_node = get_object_root(XML_CIB_TAG_NODES, cib); if (tmp_node == NULL) { is_valid = FALSE; } tmp_node = get_object_root(XML_CIB_TAG_RESOURCES, cib); if (tmp_node == NULL) { is_valid = FALSE; } tmp_node = get_object_root(XML_CIB_TAG_CONSTRAINTS, cib); if (tmp_node == NULL) { is_valid = FALSE; } tmp_node = get_object_root(XML_CIB_TAG_STATUS, cib); if (tmp_node == NULL) { is_valid = FALSE; } tmp_node = get_object_root(XML_CIB_TAG_CRMCONFIG, cib); if (tmp_node == NULL) { is_valid = FALSE; } /* more integrity tests */ return is_valid; } gboolean verify_cib_cmds(cib_t *cib) { gboolean valid = TRUE; if(cib->cmds->variant_op == NULL) { crm_err("Operation variant_op not set"); valid = FALSE; } if(cib->cmds->signon == NULL) { crm_err("Operation signon not set"); valid = FALSE; } if(cib->cmds->signoff == NULL) { crm_err("Operation signoff not set"); valid = FALSE; } if(cib->cmds->free == NULL) { crm_err("Operation free not set"); valid = FALSE; } if(cib->cmds->set_op_callback == NULL) { crm_err("Operation set_op_callback not set"); valid = FALSE; } if(cib->cmds->add_notify_callback == NULL) { crm_err("Operation add_notify_callback not set"); valid = FALSE; } if(cib->cmds->del_notify_callback == NULL) { crm_err("Operation del_notify_callback not set"); valid = FALSE; } if(cib->cmds->set_connection_dnotify == NULL) { crm_err("Operation set_connection_dnotify not set"); valid = FALSE; } if(cib->cmds->channel == NULL) { crm_err("Operation channel not set"); valid = FALSE; } if(cib->cmds->inputfd == NULL) { crm_err("Operation inputfd not set"); valid = FALSE; } if(cib->cmds->noop == NULL) { crm_err("Operation noop not set"); valid = FALSE; } if(cib->cmds->ping == NULL) { crm_err("Operation ping not set"); valid = FALSE; } if(cib->cmds->query == NULL) { crm_err("Operation query not set"); valid = FALSE; } if(cib->cmds->query_from == NULL) { crm_err("Operation query_from not set"); valid = FALSE; } if(cib->cmds->is_master == NULL) { crm_err("Operation is_master not set"); valid = FALSE; } if(cib->cmds->set_master == NULL) { crm_err("Operation set_master not set"); valid = FALSE; } if(cib->cmds->set_slave == NULL) { crm_err("Operation set_slave not set"); valid = FALSE; } if(cib->cmds->set_slave_all == NULL) { crm_err("Operation set_slave_all not set"); valid = FALSE; } if(cib->cmds->sync == NULL) { crm_err("Operation sync not set"); valid = FALSE; } if(cib->cmds->sync_from == NULL) { crm_err("Operation sync_from not set"); valid = FALSE; } if(cib->cmds->bump_epoch == NULL) { crm_err("Operation bump_epoch not set"); valid = FALSE; } if(cib->cmds->create == NULL) { crm_err("Operation create not set"); valid = FALSE; } if(cib->cmds->modify == NULL) { crm_err("Operation modify not set"); valid = FALSE; } if(cib->cmds->replace == NULL) { crm_err("Operation replace not set"); valid = FALSE; } if(cib->cmds->delete == NULL) { crm_err("Operation delete not set"); valid = FALSE; } if(cib->cmds->erase == NULL) { crm_err("Operation erase not set"); valid = FALSE; } if(cib->cmds->quit == NULL) { crm_err("Operation quit not set"); valid = FALSE; } if(cib->cmds->msgready == NULL) { crm_err("Operation msgready not set"); valid = FALSE; } if(cib->cmds->rcvmsg == NULL) { crm_err("Operation rcvmsg not set"); valid = FALSE; } if(cib->cmds->dispatch == NULL) { crm_err("Operation dispatch not set"); valid = FALSE; } return valid; } diff --git a/lib/crm/cib/cib_native.c b/lib/crm/cib/cib_native.c index f13ec85af8..7b5f02db17 100755 --- a/lib/crm/cib/cib_native.c +++ b/lib/crm/cib/cib_native.c @@ -1,586 +1,586 @@ /* * Copyright (c) 2004 International Business Machines * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser 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 library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser 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 #include typedef struct cib_native_opaque_s { IPC_Channel *command_channel; IPC_Channel *callback_channel; GCHSource *callback_source; } cib_native_opaque_t; int cib_native_perform_op( cib_t *cib, const char *op, const char *host, const char *section, crm_data_t *data, crm_data_t **output_data, int call_options); int cib_native_signon(cib_t* cib, enum cib_conn_type type); int cib_native_signoff(cib_t* cib); int cib_native_free(cib_t* cib); IPC_Channel *cib_native_channel(cib_t* cib); int cib_native_inputfd(cib_t* cib); gboolean cib_native_msgready(cib_t* cib); int cib_native_rcvmsg(cib_t* cib, int blocking); gboolean cib_native_dispatch(IPC_Channel *channel, gpointer user_data); cib_t *cib_native_new (cib_t *cib); int cib_native_set_connection_dnotify( cib_t *cib, void (*dnotify)(gpointer user_data)); void cib_native_notify(gpointer data, gpointer user_data); void cib_native_callback(cib_t *cib, struct ha_msg *msg); cib_t* cib_native_new (cib_t *cib) { cib_native_opaque_t *native = NULL; crm_malloc(cib->variant_opaque, sizeof(cib_native_opaque_t)); native = cib->variant_opaque; native->command_channel = NULL; native->callback_channel = NULL; /* assign variant specific ops*/ cib->cmds->variant_op = cib_native_perform_op; cib->cmds->signon = cib_native_signon; cib->cmds->signoff = cib_native_signoff; cib->cmds->free = cib_native_free; cib->cmds->channel = cib_native_channel; cib->cmds->inputfd = cib_native_inputfd; cib->cmds->msgready = cib_native_msgready; cib->cmds->rcvmsg = cib_native_rcvmsg; cib->cmds->dispatch = cib_native_dispatch; cib->cmds->set_connection_dnotify = cib_native_set_connection_dnotify; return cib; } int cib_native_signon(cib_t* cib, enum cib_conn_type type) { int rc = cib_ok; char *uuid_ticket = NULL; struct ha_msg *reg_msg = NULL; cib_native_opaque_t *native = cib->variant_opaque; crm_trace("Connecting command channel"); if(type == cib_command) { cib->state = cib_connected_command; native->command_channel = init_client_ipc_comms_nodispatch( cib_channel_rw); } else { cib->state = cib_connected_query; native->command_channel = init_client_ipc_comms_nodispatch( cib_channel_ro); } if(native->command_channel == NULL) { crm_debug("Connection to command channel failed"); rc = cib_connection; } else if(native->command_channel->ch_status != IPC_CONNECT) { crm_err("Connection may have succeeded," " but authentication to command channel failed"); rc = cib_authentication; } if(rc == cib_ok) { crm_trace("Connecting callback channel"); native->callback_source = init_client_ipc_comms( cib_channel_callback, cib_native_dispatch, cib, &(native->callback_channel)); if(native->callback_channel == NULL) { crm_debug("Connection to callback channel failed"); rc = cib_connection; } else if(native->callback_source == NULL) { crm_err("Callback source not recorded"); rc = cib_connection; } } else if(rc == cib_ok && native->callback_channel->ch_status != IPC_CONNECT) { crm_err("Connection may have succeeded," " but authentication to callback channel failed"); rc = cib_authentication; } if(rc == cib_ok) { const char *msg_type = NULL; crm_trace("Waiting for msg on command channel"); reg_msg = msgfromIPC_noauth(native->command_channel); msg_type = cl_get_string(reg_msg, F_CIB_OPERATION); if(safe_str_neq(msg_type, CRM_OP_REGISTER) ) { crm_err("Invalid registration message: %s", msg_type); rc = cib_registration_msg; } else { const char *tmp_ticket = NULL; crm_trace("Retrieving callback channel ticket"); tmp_ticket = cl_get_string( reg_msg, F_CIB_CALLBACK_TOKEN); if(tmp_ticket == NULL) { rc = cib_callback_token; } else { uuid_ticket = crm_strdup(tmp_ticket); } } crm_msg_del(reg_msg); reg_msg = NULL; } if(rc == cib_ok) { crm_trace("Registering callback channel with ticket %s", crm_str(uuid_ticket)); reg_msg = ha_msg_new(2); ha_msg_add(reg_msg, F_CIB_OPERATION, CRM_OP_REGISTER); ha_msg_add(reg_msg, F_CIB_CALLBACK_TOKEN, uuid_ticket); CRM_DEV_ASSERT(native->command_channel->should_send_blocking); if(msg2ipcchan(reg_msg, native->callback_channel) != HA_OK) { rc = cib_callback_register; } crm_free(uuid_ticket); crm_msg_del(reg_msg); } if(rc == cib_ok) { crm_trace("wait for the callback channel setup to complete"); reg_msg = msgfromIPC_noauth(native->callback_channel); if(reg_msg == NULL) { crm_err("Connection to callback channel not maintined"); rc = cib_connection; } crm_msg_del(reg_msg); } if(rc == cib_ok) { crm_info("Connection to CIB successful"); return cib_ok; } crm_warn("Connection to CIB failed: %s", cib_error2string(rc)); cib_native_signoff(cib); return rc; } int cib_native_signoff(cib_t* cib) { cib_native_opaque_t *native = cib->variant_opaque; crm_info("Signing out of the CIB Service"); /* close channels */ if (native->command_channel != NULL) { native->command_channel->ops->destroy( native->command_channel); native->command_channel = NULL; } if (native->callback_channel != NULL) { G_main_del_IPC_Channel(native->callback_source); #ifdef BUG native->callback_channel->ops->destroy( native->callback_channel); #endif native->callback_channel = NULL; } cib->state = cib_disconnected; cib->type = cib_none; return cib_ok; } int cib_native_free (cib_t* cib) { int rc = cib_ok; crm_warn("Freeing CIB"); if(cib->state != cib_disconnected) { rc = cib_native_signoff(cib); if(rc == cib_ok) { crm_free(cib); } } return rc; } IPC_Channel * cib_native_channel(cib_t* cib) { cib_native_opaque_t *native = NULL; if(cib == NULL) { crm_err("Missing cib object"); return NULL; } native = cib->variant_opaque; if(native != NULL) { return native->callback_channel; } crm_err("couldnt find variant specific data in %p", cib); return NULL; } int cib_native_inputfd(cib_t* cib) { IPC_Channel *ch = cib_native_channel(cib); return ch->ops->get_recv_select_fd(ch); } int cib_native_perform_op( cib_t *cib, const char *op, const char *host, const char *section, crm_data_t *data, crm_data_t **output_data, int call_options) { int rc = HA_OK; struct ha_msg *op_msg = NULL; struct ha_msg *op_reply = NULL; cib_native_opaque_t *native = cib->variant_opaque; if(cib->state == cib_disconnected) { return cib_not_connected; } if(output_data != NULL) { *output_data = NULL; } if(op == NULL) { crm_err("No operation specified"); rc = cib_operation; } op_msg = ha_msg_new(7); if (op_msg == NULL) { crm_err("No memory to create HA_Message"); return cib_create_msg; } if(rc == HA_OK) { rc = ha_msg_add(op_msg, F_TYPE, "cib"); } if(rc == HA_OK) { rc = ha_msg_add(op_msg, F_CIB_OPERATION, op); } if(rc == HA_OK && host != NULL) { CRM_DEV_ASSERT(cl_is_allocated(host) == 1); rc = ha_msg_add(op_msg, F_CIB_HOST, host); } if(rc == HA_OK && section != NULL) { rc = ha_msg_add(op_msg, F_CIB_SECTION, section); } if(rc == HA_OK) { rc = ha_msg_add_int(op_msg, F_CIB_CALLID, cib->call_id); } if(rc == HA_OK) { crm_trace("Sending call options: %.8lx, %d", (long)call_options, call_options); rc = ha_msg_add_int(op_msg, F_CIB_CALLOPTS, call_options); } if(rc == HA_OK && data != NULL) { add_message_xml(op_msg, F_CIB_CALLDATA, data); } if (rc != HA_OK) { crm_err("Failed to create CIB operation message"); crm_log_message(LOG_ERR, op_msg); crm_msg_del(op_msg); return cib_create_msg; } cib->call_id++; crm_debug("Sending %s message to CIB service", op); crm_log_message(LOG_MSG, op_msg); rc = msg2ipcchan(op_msg, native->command_channel); if (rc != HA_OK) { crm_err("Sending message to CIB service FAILED: %d", rc); CRM_DEV_ASSERT(native->command_channel->should_send_blocking); crm_log_message(LOG_ERR, op_msg); crm_msg_del(op_msg); return cib_send_failed; } else { - crm_debug("Message sent"); + crm_devel("Message sent"); } crm_msg_del(op_msg); op_msg = NULL; if((call_options & cib_discard_reply)) { - crm_debug("Discarding reply"); + crm_devel("Discarding reply"); return cib_ok; } else if(!(call_options & cib_sync_call)) { - crm_debug("Async call, returning"); + crm_devel("Async call, returning"); return cib->call_id - 1; } - crm_debug("Waiting for a syncronous reply"); + crm_devel("Waiting for a syncronous reply"); op_reply = msgfromIPC_noauth(native->command_channel); if (op_reply == NULL) { crm_err("No reply message"); return cib_reply_failed; } - crm_debug("Syncronous reply recieved"); + crm_devel("Syncronous reply recieved"); crm_log_message(LOG_MSG, op_reply); rc = cib_ok; /* Start processing the reply... */ if(ha_msg_value_int(op_reply, F_CIB_RC, &rc) != HA_OK) { rc = cib_return_code; } if(output_data == NULL) { /* do nothing more */ } else if(!(call_options & cib_discard_reply)) { *output_data = get_message_xml(op_reply, F_CIB_CALLDATA); if(*output_data == NULL) { crm_debug("No output in reply to \"%s\" command %d", op, cib->call_id - 1); } } crm_msg_del(op_reply); return rc; } gboolean cib_native_msgready(cib_t* cib) { IPC_Channel *ch = NULL; cib_native_opaque_t *native = NULL; if (cib == NULL) { crm_err("No CIB!"); return FALSE; } native = cib->variant_opaque; ch = cib_native_channel(cib); if (ch == NULL) { crm_err("No channel"); return FALSE; } if(native->command_channel->ops->is_message_pending( native->command_channel)) { crm_verbose("Message pending on command channel"); } if(native->callback_channel->ops->is_message_pending( native->callback_channel)) { crm_trace("Message pending on callback channel"); return TRUE; } crm_verbose("No message pending"); return FALSE; } int cib_native_rcvmsg(cib_t* cib, int blocking) { const char *type = NULL; struct ha_msg* msg = NULL; IPC_Channel *ch = cib_native_channel(cib); /* if it is not blocking mode and no message in the channel, return */ if (blocking == 0 && cib_native_msgready(cib) == FALSE) { - crm_debug("No message ready and non-blocking..."); + crm_devel("No message ready and non-blocking..."); return 0; } else if (cib_native_msgready(cib) == FALSE) { - crm_debug("Waiting for message from CIB service..."); + crm_devel("Waiting for message from CIB service..."); ch->ops->waitin(ch); } /* get the message */ msg = msgfromIPC_noauth(ch); if (msg == NULL) { crm_warn("Received a NULL msg from CIB service."); return 0; } /* do callbacks */ type = cl_get_string(msg, F_TYPE); crm_trace("Activating %s callbacks...", type); if(safe_str_eq(type, T_CIB)) { cib_native_callback(cib, msg); } else if(safe_str_eq(type, T_CIB_NOTIFY)) { g_list_foreach(cib->notify_list, cib_native_notify, msg); } else { crm_err("Unknown message type: %s", type); } crm_msg_del(msg); return 1; } void cib_native_callback(cib_t *cib, struct ha_msg *msg) { int rc = 0; int call_id = 0; crm_data_t *output = NULL; if(cib->op_callback == NULL) { - crm_debug("No OP callback set, ignoring reply"); + crm_devel("No OP callback set, ignoring reply"); return; } ha_msg_value_int(msg, F_CIB_CALLID, &call_id); ha_msg_value_int(msg, F_CIB_RC, &rc); output = get_message_xml(msg, F_CIB_CALLDATA); cib->op_callback(msg, call_id, rc, output); crm_trace("OP callback activated."); } void cib_native_notify(gpointer data, gpointer user_data) { struct ha_msg *msg = user_data; cib_notify_client_t *entry = data; const char *event = NULL; if(msg == NULL) { crm_warn("Skipping callback - NULL message"); return; } event = cl_get_string(msg, F_SUBTYPE); if(entry == NULL) { crm_warn("Skipping callback - NULL callback client"); return; } else if(entry->callback == NULL) { crm_warn("Skipping callback - NULL callback"); return; } else if(safe_str_neq(entry->event, event)) { crm_trace("Skipping callback - event mismatch %p/%s vs. %s", entry, entry->event, event); return; } crm_trace("Invoking callback for %p/%s event...", entry, event); entry->callback(event, msg); crm_trace("Callback invoked..."); } gboolean cib_native_dispatch(IPC_Channel *channel, gpointer user_data) { int lpc = 0; cib_t *cib = user_data; - crm_debug("Received callback"); + crm_devel("Received callback"); if(user_data == NULL){ crm_err("user_data field must contain the CIB struct"); return FALSE; } while(cib_native_msgready(cib)) { lpc++; /* invoke the callbacks but dont block */ if(cib_native_rcvmsg(cib, 0) < 1) { break; } } - crm_debug("%d CIB messages dispatched", lpc); + crm_devel("%d CIB messages dispatched", lpc); if (channel && (channel->ch_status == IPC_DISCONNECT)) { crm_crit("Lost connection to the CIB service."); return FALSE; } return TRUE; } int cib_native_set_connection_dnotify( cib_t *cib, void (*dnotify)(gpointer user_data)) { cib_native_opaque_t *native = NULL; if (cib == NULL) { crm_err("No CIB!"); return FALSE; } native = cib->variant_opaque; if(dnotify == NULL) { crm_warn("Setting dnotify back to default value"); set_IPC_Channel_dnotify(native->callback_source, default_ipc_connection_destroy); } else { - crm_debug("Setting dnotify"); + crm_devel("Setting dnotify"); set_IPC_Channel_dnotify(native->callback_source, dnotify); } return cib_ok; }