diff --git a/include/crm/cluster.h b/include/crm/cluster.h index 81fc3d0e11..546ab9623f 100644 --- a/include/crm/cluster.h +++ b/include/crm/cluster.h @@ -1,228 +1,150 @@ /* * 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 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef CRM_COMMON_CLUSTER__H # define CRM_COMMON_CLUSTER__H # include # include # if SUPPORT_HEARTBEAT # include # include # endif extern gboolean crm_have_quorum; extern GHashTable *crm_peer_cache; extern GHashTable *crm_peer_id_cache; extern unsigned long long crm_peer_seq; # ifndef CRM_SERVICE # define CRM_SERVICE PCMK_SERVICE_ID # endif /* *INDENT-OFF* */ #define CRM_NODE_LOST "lost" #define CRM_NODE_MEMBER "member" #define CRM_NODE_ACTIVE CRM_NODE_MEMBER #define CRM_NODE_EVICTED "evicted" -enum crm_proc_flag { - crm_proc_none = 0x00000001, - /* These values are sent over the network by the legacy plugin - * Therefor changing any of these values is going to break compatability - * - * So don't - */ - - /* 3 messaging types */ - crm_proc_heartbeat = 0x01000000, - crm_proc_plugin = 0x00000002, - crm_proc_cpg = 0x04000000, - - crm_proc_lrmd = 0x00000010, - crm_proc_cib = 0x00000100, - crm_proc_crmd = 0x00000200, - crm_proc_attrd = 0x00001000, - - crm_proc_stonithd = 0x00002000, - crm_proc_stonith_ng= 0x00100000, - - crm_proc_pe = 0x00010000, - crm_proc_te = 0x00020000, - - crm_proc_mgmtd = 0x00040000, -}; /* *INDENT-ON* */ typedef struct crm_peer_node_s { uint32_t id; /* Only used by corosync derivatives */ uint64_t born; /* Only used by heartbeat and the legacy plugin */ uint64_t last_seen; int32_t votes; /* Only used by the legacy plugin */ uint32_t processes; char *uname; char *uuid; char *state; char *expected; char *addr; /* Only used by the legacy plugin */ char *version;/* Unused */ } crm_node_t; -static inline const char * -peer2text(enum crm_proc_flag proc) -{ - const char *text = "unknown"; - if( proc == (crm_proc_cpg|crm_proc_crmd) ) { - return "peer"; - } - - switch (proc) { - case crm_proc_none: - text = "none"; - break; - case crm_proc_plugin: - text = "ais"; - break; - case crm_proc_heartbeat: - text = "heartbeat"; - break; - case crm_proc_cib: - text = "cib"; - break; - case crm_proc_crmd: - text = "crmd"; - break; - case crm_proc_pe: - text = "pengine"; - break; - case crm_proc_te: - text = "tengine"; - break; - case crm_proc_lrmd: - text = "lrmd"; - break; - case crm_proc_attrd: - text = "attrd"; - break; - case crm_proc_stonithd: - text = "stonithd"; - break; - case crm_proc_stonith_ng: - text = "stonith-ng"; - break; - case crm_proc_mgmtd: - text = "mgmtd"; - break; - case crm_proc_cpg: - text = "corosync-cpg"; - break; - } - return text; -} - void crm_peer_init(void); void crm_peer_destroy(void); char *get_corosync_uuid(uint32_t id, const char *uname); const char *get_node_uuid(uint32_t id, const char *uname); int get_corosync_id(int id, const char *uuid); typedef struct crm_cluster_s { char *uuid; char *uname; uint32_t nodeid; #if SUPPORT_HEARTBEAT ll_cluster_t *hb_conn; void (*hb_dispatch)(HA_Message *msg, void *private); #endif gboolean (*cs_dispatch) (int kind, const char *from, const char *data); void (*destroy) (gpointer); } crm_cluster_t; gboolean crm_cluster_connect(crm_cluster_t *cluster); enum crm_ais_msg_types; gboolean send_cluster_message(const char *node, enum crm_ais_msg_types service, xmlNode * data, gboolean ordered); void destroy_crm_node(gpointer/* crm_node_t* */ data); crm_node_t *crm_get_peer(unsigned int id, const char *uname); guint crm_active_peers(void); gboolean crm_is_peer_active(const crm_node_t * node); guint reap_crm_member(uint32_t id); int crm_terminate_member(int nodeid, const char *uname, void* unused); int crm_terminate_member_no_mainloop(int nodeid, const char *uname, int *connection); gboolean crm_get_cluster_name(char **cname); # if SUPPORT_HEARTBEAT gboolean crm_is_heartbeat_peer_active(const crm_node_t * node); # endif # if SUPPORT_COROSYNC extern int ais_fd_sync; gboolean crm_is_corosync_peer_active(const crm_node_t * node); gboolean send_ais_text(int class, const char *data, gboolean local, const char *node, enum crm_ais_msg_types dest); gboolean get_ais_nodeid(uint32_t * id, char **uname); # endif void empty_uuid_cache(void); const char *get_uuid(const char *uname); const char *get_uname(const char *uuid); void set_uuid(xmlNode * node, const char *attr, const char *uname); void unget_uuid(const char *uname); enum crm_status_type { crm_status_uname, crm_status_nstate, crm_status_processes, }; enum crm_ais_msg_types text2msg_type(const char *text); void crm_set_status_callback(void (*dispatch) (enum crm_status_type, crm_node_t *, const void *)); /* *INDENT-OFF* */ enum cluster_type_e { pcmk_cluster_unknown = 0x0001, pcmk_cluster_invalid = 0x0002, pcmk_cluster_heartbeat = 0x0004, pcmk_cluster_classic_ais = 0x0010, pcmk_cluster_corosync = 0x0020, pcmk_cluster_cman = 0x0040, }; /* *INDENT-ON* */ enum cluster_type_e get_cluster_type(void); const char *name_for_cluster_type(enum cluster_type_e type); gboolean is_corosync_cluster(void); gboolean is_cman_cluster(void); gboolean is_openais_cluster(void); gboolean is_classic_ais_cluster(void); gboolean is_heartbeat_cluster(void); #endif diff --git a/include/crm/cluster/internal.h b/include/crm/cluster/internal.h index 0044d97c89..14afa04fc1 100644 --- a/include/crm/cluster/internal.h +++ b/include/crm/cluster/internal.h @@ -1,328 +1,407 @@ /* * 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 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef CRM_CLUSTER_INTERNAL__H # define CRM_CLUSTER_INTERNAL__H # include # define AIS_IPC_NAME "ais-crm-ipc" # define AIS_IPC_MESSAGE_SIZE 8192*128 # define CRM_MESSAGE_IPC_ACK 0 typedef struct crm_ais_host_s AIS_Host; typedef struct crm_ais_msg_s AIS_Message; enum crm_ais_msg_class { crm_class_cluster = 0, crm_class_members = 1, crm_class_notify = 2, crm_class_nodeid = 3, crm_class_rmpeer = 4, crm_class_quorum = 5, }; /* order here matters - its used to index into the crm_children array */ enum crm_ais_msg_types { crm_msg_none = 0, crm_msg_ais = 1, crm_msg_lrmd = 2, crm_msg_cib = 3, crm_msg_crmd = 4, crm_msg_attrd = 5, crm_msg_stonithd = 6, crm_msg_te = 7, crm_msg_pe = 8, crm_msg_stonith_ng = 9, }; struct crm_ais_host_s { uint32_t id; uint32_t pid; gboolean local; enum crm_ais_msg_types type; uint32_t size; char uname[MAX_NAME]; } __attribute__ ((packed)); struct crm_ais_msg_s { cs_ipc_header_response_t header __attribute__ ((aligned(8))); uint32_t id; gboolean is_compressed; AIS_Host host; AIS_Host sender; uint32_t size; uint32_t compressed_size; /* 584 bytes */ char data[0]; } __attribute__ ((packed)); struct crm_ais_nodeid_resp_s { cs_ipc_header_response_t header __attribute__ ((aligned(8))); uint32_t id; uint32_t counter; char uname[MAX_NAME]; char cname[MAX_NAME]; } __attribute__ ((packed)); struct crm_ais_quorum_resp_s { cs_ipc_header_response_t header __attribute__ ((aligned(8))); uint64_t id; uint32_t votes; uint32_t expected_votes; uint32_t quorate; } __attribute__ ((packed)); +enum crm_proc_flag { + crm_proc_none = 0x00000001, + /* These values are sent over the network by the legacy plugin + * Therefor changing any of these values is going to break compatability + * + * So don't + */ + + /* 3 messaging types */ + crm_proc_heartbeat = 0x01000000, + crm_proc_plugin = 0x00000002, + crm_proc_cpg = 0x04000000, + + crm_proc_lrmd = 0x00000010, + crm_proc_cib = 0x00000100, + crm_proc_crmd = 0x00000200, + crm_proc_attrd = 0x00001000, + + crm_proc_stonithd = 0x00002000, + crm_proc_stonith_ng= 0x00100000, + + crm_proc_pe = 0x00010000, + crm_proc_te = 0x00020000, + + crm_proc_mgmtd = 0x00040000, +}; + +static inline const char * +peer2text(enum crm_proc_flag proc) +{ + const char *text = "unknown"; + if( proc == (crm_proc_cpg|crm_proc_crmd) ) { + return "peer"; + } + + switch (proc) { + case crm_proc_none: + text = "none"; + break; + case crm_proc_plugin: + text = "ais"; + break; + case crm_proc_heartbeat: + text = "heartbeat"; + break; + case crm_proc_cib: + text = "cib"; + break; + case crm_proc_crmd: + text = "crmd"; + break; + case crm_proc_pe: + text = "pengine"; + break; + case crm_proc_te: + text = "tengine"; + break; + case crm_proc_lrmd: + text = "lrmd"; + break; + case crm_proc_attrd: + text = "attrd"; + break; + case crm_proc_stonithd: + text = "stonithd"; + break; + case crm_proc_stonith_ng: + text = "stonith-ng"; + break; + case crm_proc_mgmtd: + text = "mgmtd"; + break; + case crm_proc_cpg: + text = "corosync-cpg"; + break; + } + return text; +} + static inline enum crm_proc_flag text2proc(const char *proc) { /* We only care about these two so far */ if(proc && strcmp(proc, "cib") == 0) { return crm_proc_cib; } else if(proc && strcmp(proc, "crmd") == 0) { return crm_proc_crmd; } return crm_proc_none; } static inline const char * ais_dest(const struct crm_ais_host_s *host) { if (host->local) { return "local"; } else if (host->size > 0) { return host->uname; } else { return ""; } } # define ais_data_len(msg) (msg->is_compressed?msg->compressed_size:msg->size) static inline AIS_Message * ais_msg_copy(const AIS_Message * source) { AIS_Message *target = malloc(sizeof(AIS_Message) + ais_data_len(source)); memcpy(target, source, sizeof(AIS_Message)); memcpy(target->data, source->data, ais_data_len(target)); return target; } static inline const char * ais_error2text(int error) { const char *text = "unknown"; # if SUPPORT_COROSYNC switch (error) { case CS_OK: text = "None"; break; case CS_ERR_LIBRARY: text = "Library error"; break; case CS_ERR_VERSION: text = "Version error"; break; case CS_ERR_INIT: text = "Initialization error"; break; case CS_ERR_TIMEOUT: text = "Timeout"; break; case CS_ERR_TRY_AGAIN: text = "Try again"; break; case CS_ERR_INVALID_PARAM: text = "Invalid parameter"; break; case CS_ERR_NO_MEMORY: text = "No memory"; break; case CS_ERR_BAD_HANDLE: text = "Bad handle"; break; case CS_ERR_BUSY: text = "Busy"; break; case CS_ERR_ACCESS: text = "Access error"; break; case CS_ERR_NOT_EXIST: text = "Doesn't exist"; break; case CS_ERR_NAME_TOO_LONG: text = "Name too long"; break; case CS_ERR_EXIST: text = "Exists"; break; case CS_ERR_NO_SPACE: text = "No space"; break; case CS_ERR_INTERRUPT: text = "Interrupt"; break; case CS_ERR_NAME_NOT_FOUND: text = "Name not found"; break; case CS_ERR_NO_RESOURCES: text = "No resources"; break; case CS_ERR_NOT_SUPPORTED: text = "Not supported"; break; case CS_ERR_BAD_OPERATION: text = "Bad operation"; break; case CS_ERR_FAILED_OPERATION: text = "Failed operation"; break; case CS_ERR_MESSAGE_ERROR: text = "Message error"; break; case CS_ERR_QUEUE_FULL: text = "Queue full"; break; case CS_ERR_QUEUE_NOT_AVAILABLE: text = "Queue not available"; break; case CS_ERR_BAD_FLAGS: text = "Bad flags"; break; case CS_ERR_TOO_BIG: text = "To big"; break; case CS_ERR_NO_SECTIONS: text = "No sections"; break; } # endif return text; } static inline const char * msg_type2text(enum crm_ais_msg_types type) { const char *text = "unknown"; switch (type) { case crm_msg_none: text = "unknown"; break; case crm_msg_ais: text = "ais"; break; case crm_msg_cib: text = "cib"; break; case crm_msg_crmd: text = "crmd"; break; case crm_msg_pe: text = "pengine"; break; case crm_msg_te: text = "tengine"; break; case crm_msg_lrmd: text = "lrmd"; break; case crm_msg_attrd: text = "attrd"; break; case crm_msg_stonithd: text = "stonithd"; break; case crm_msg_stonith_ng: text = "stonith-ng"; break; } return text; } enum crm_ais_msg_types text2msg_type(const char *text); char *get_ais_data(const AIS_Message * msg); gboolean check_message_sanity(const AIS_Message * msg, const char *data); # if SUPPORT_HEARTBEAT extern ll_cluster_t *heartbeat_cluster; gboolean send_ha_message(ll_cluster_t * hb_conn, xmlNode * msg, const char *node, gboolean force_ordered); gboolean ha_msg_dispatch(ll_cluster_t * cluster_conn, gpointer user_data); gboolean register_heartbeat_conn(crm_cluster_t *cluster); xmlNode *convert_ha_message(xmlNode * parent, HA_Message *msg, const char *field); gboolean ccm_have_quorum(oc_ed_t event); const char *ccm_event_name(oc_ed_t event); crm_node_t *crm_update_ccm_node(const oc_ev_membership_t * oc, int offset, const char *state, uint64_t seq); gboolean heartbeat_initialize_nodelist(void *cluster, gboolean force_member, xmlNode *xml_parent); # endif # if SUPPORT_COROSYNC gboolean corosync_initialize_nodelist(void *cluster, gboolean force_member, xmlNode *xml_parent); gboolean send_ais_message(xmlNode * msg, gboolean local, const char *node, enum crm_ais_msg_types dest); enum cluster_type_e find_corosync_variant(void); void terminate_cs_connection(void); gboolean init_cs_connection(crm_cluster_t *cluster); gboolean init_cs_connection_once(crm_cluster_t *cluster); # endif enum crm_quorum_source { crm_quorum_cman, crm_quorum_corosync, crm_quorum_pacemaker, }; enum crm_quorum_source get_quorum_source(void); void crm_update_peer_proc(const char *source, crm_node_t *peer, uint32_t flag, const char *status); crm_node_t *crm_update_peer( const char *source, unsigned int id, uint64_t born, uint64_t seen, int32_t votes, uint32_t children, const char *uuid, const char *uname, const char *addr, const char *state); void crm_update_peer_expected(const char *source, crm_node_t *node, const char *expected); void crm_update_peer_state(const char *source, crm_node_t *node, const char *state, int membership); gboolean init_cman_connection( gboolean(*dispatch) (unsigned long long, gboolean), void (*destroy) (gpointer)); gboolean init_quorum_connection( gboolean(*dispatch) (unsigned long long, gboolean), void (*destroy) (gpointer)); void set_node_uuid(const char *uname, const char *uuid); #endif