crm_trace("Retrieved command: %s", op);
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;	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);				lpc++;		if(ha_msg_add(op_request, F_CIB_CLIENTID, cib_client->id) != HA_OK) {			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_trace("Call options: %.8lx", (long)call_options);						host = cl_get_string(op_request, F_CIB_HOST);			crm_trace("Destination host: %s", host);			op = cl_get_string(op_request, F_CIB_OPERATION);			crm_trace("Retrieved command: %s", op);			rc = cib_get_operation_id(op_request, &call_type);			crm_trace("Command offset: %d", call_type);		}				if(rc == cib_ok		   && cib_server_ops[call_type].needs_privileges		   && privileged == FALSE) {			rc = cib_not_authorized;		}		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);			rc = cib_process_command(				op_request, &op_reply, privileged);		} else if((host == NULL && (call_options & cib_scope_local))			  || safe_str_eq(host, cib_our_uname)) { 			crm_debug("Processing %s op locally", op);			rc = cib_process_command(				op_request, &op_reply, privileged);		} else if(host != NULL) { 			crm_debug("Forwarding %s op to %s", op, host);			ha_msg_add(op_request, F_CIB_DELEGATED, cib_our_uname);			crm_log_message(LOG_MSG, op_request);						hb_conn->llc_ops->send_ordered_nodemsg(				hb_conn, op_request, host);			if(call_options & cib_discard_reply) {				ha_msg_del(op_request);			} else if(call_options & cib_sync_call) {				/* keep track of the request so we can time it				 * out if required				 */				crm_debug("Registering call from %s as delegated", cib_client->id);				cib_client->delegated_calls = g_list_append(					cib_client->delegated_calls,					op_request);			} else {				ha_msg_del(op_request);			}			continue;		} else {			/* send via HA to other nodes */ 			crm_info("Forwarding %s op to master instance", op);			ha_msg_add(op_request, F_CIB_DELEGATED, cib_our_uname);			crm_log_message(LOG_MSG, op_request);						hb_conn->llc_ops->sendclustermsg(hb_conn, op_request);			if(call_options & cib_discard_reply) {				ha_msg_del(op_request);			} else if(call_options & cib_sync_call) {				/* keep track of the request so we can time it				 * out if required				 */				crm_debug("Registering call from %s as delegated", cib_client->id);				cib_client->delegated_calls = g_list_append(					cib_client->delegated_calls,					op_request);			} else {				ha_msg_del(op_request);			}			continue;		}		if(op_reply == NULL) {			crm_trace("No reply is required for op %s", op);					} else if(call_options & cib_sync_call) { 			crm_debug("Sending sync reply %p to %s op", op_reply,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", op_reply, 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;				}			}		}		ha_msg_del(op_reply);		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);			hb_conn->llc_ops->sendclustermsg(hb_conn, op_request);		} else {			if(call_options & cib_scope_local ) {				crm_debug("Request not broadcast : local scope");			}			if(cib_server_ops[call_type].modifies_cib == FALSE) {				crm_debug("Request not broadcast : R/O call");			}			if(rc != cib_ok) {				crm_debug("Request not broadcast : call failed : %s",					  cib_error2string(rc));			}		}		ha_msg_del(op_request);	}	crm_verbose("Processed %d messages", lpc);    	return cib_process_disconnect(channel, cib_client);}