root/crmd/corosync.c

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

DEFINITIONS

This source file includes following definitions.
  1. crmd_cs_dispatch
  2. crmd_cman_dispatch
  3. crmd_quorum_destroy
  4. crmd_cs_destroy
  5. crmd_cman_destroy
  6. crm_connect_corosync

   1 /*
   2  * Copyright (C) 2004 Andrew Beekhof <andrew@beekhof.net>
   3  *
   4  * This program is free software; you can redistribute it and/or
   5  * modify it under the terms of the GNU General Public
   6  * License as published by the Free Software Foundation; either
   7  * version 2 of the License, or (at your option) any later version.
   8  *
   9  * This software is distributed in the hope that it will be useful,
  10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12  * General Public License for more details.
  13  *
  14  * You should have received a copy of the GNU General Public
  15  * License along with this library; if not, write to the Free Software
  16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  17  */
  18 
  19 #include <crm_internal.h>
  20 
  21 #include <sys/param.h>
  22 
  23 #include <crm/crm.h>
  24 #include <crm/cluster/internal.h>
  25 #include <crm/common/xml.h>
  26 
  27 #include <crmd.h>
  28 #include <crmd_fsa.h>
  29 #include <fsa_proto.h>
  30 #include <crmd_messages.h>
  31 #include <crmd_callbacks.h>
  32 #include <crmd_lrm.h>
  33 #include <tengine.h>
  34 
  35 #include <sys/types.h>
  36 #include <sys/stat.h>
  37 
  38 extern void post_cache_update(int seq);
  39 extern void crmd_ha_connection_destroy(gpointer user_data);
  40 
  41 /*       A_HA_CONNECT   */
  42 #if SUPPORT_COROSYNC
  43 
  44 static void
  45 crmd_cs_dispatch(cpg_handle_t handle,
     /* [previous][next][first][last][top][bottom][index][help] */
  46                          const struct cpg_name *groupName,
  47                          uint32_t nodeid, uint32_t pid, void *msg, size_t msg_len)
  48 {
  49     int seq = 0;
  50     xmlNode *xml = NULL;
  51     const char *seq_s = NULL;
  52     crm_node_t *peer = NULL;
  53     enum crm_proc_flag flag = crm_proc_cpg;
  54 
  55     uint32_t kind = 0;
  56     const char *from = NULL;
  57     char *data = pcmk_message_common_cs(handle, nodeid, pid, msg, &kind, &from);
  58 
  59     if(data == NULL) {
  60         return;
  61     }
  62     xml = string2xml(data);
  63     if (xml == NULL) {
  64         crm_err("Could not parse message content (%d): %.100s", kind, data);
  65         free(data);
  66         return;
  67     }
  68 
  69     switch (kind) {
  70         case crm_class_members:
  71             seq_s = crm_element_value(xml, "id");
  72             seq = crm_int_helper(seq_s, NULL);
  73             set_bit(fsa_input_register, R_PEER_DATA);
  74             post_cache_update(seq);
  75 
  76             /* fall through */
  77         case crm_class_quorum:
  78             crm_update_quorum(crm_have_quorum, FALSE);
  79             if (AM_I_DC) {
  80                 const char *votes = crm_element_value(xml, "expected");
  81 
  82                 if (votes == NULL || check_number(votes) == FALSE) {
  83                     crm_log_xml_err(xml, "Invalid quorum/membership update");
  84 
  85                 } else {
  86                     int rc = update_attr_delegate(fsa_cib_conn,
  87                                                   cib_quorum_override | cib_scope_local |
  88                                                   cib_inhibit_notify,
  89                                                   XML_CIB_TAG_CRMCONFIG, NULL, NULL, NULL, NULL,
  90                                                   XML_ATTR_EXPECTED_VOTES, votes, FALSE, NULL, NULL);
  91 
  92                     crm_info("Setting expected votes to %s", votes);
  93                     if (pcmk_ok > rc) {
  94                         crm_err("Quorum update failed: %s", pcmk_strerror(rc));
  95                     }
  96                 }
  97             }
  98             break;
  99 
 100         case crm_class_cluster:
 101             crm_xml_add(xml, F_ORIG, from);
 102             /* crm_xml_add_int(xml, F_SEQ, wrapper->id); Fake? */
 103 
 104             if (is_heartbeat_cluster()) {
 105                 flag = crm_proc_heartbeat;
 106 
 107             } else if (is_classic_ais_cluster()) {
 108                 flag = crm_proc_plugin;
 109             }
 110 
 111             peer = crm_get_peer(0, from);
 112             if (is_not_set(peer->processes, flag)) {
 113                 /* If we can still talk to our peer process on that node,
 114                  * then its also part of the corosync membership
 115                  */
 116                 crm_warn("Receiving messages from a node we think is dead: %s[%d]", peer->uname,
 117                          peer->id);
 118                 crm_update_peer_proc(__FUNCTION__, peer, flag, ONLINESTATUS);
 119             }
 120             crmd_ha_msg_filter(xml);
 121             break;
 122 
 123         case crm_class_rmpeer:
 124             /* Ignore */
 125             break;
 126 
 127         case crm_class_notify:
 128         case crm_class_nodeid:
 129             crm_err("Unexpected message class (%d): %.100s", kind, data);
 130             break;
 131 
 132         default:
 133             crm_err("Invalid message class (%d): %.100s", kind, data);
 134     }
 135 
 136     free(data);
 137     free_xml(xml);
 138 }
 139 
 140 static gboolean
 141 crmd_cman_dispatch(unsigned long long seq, gboolean quorate)
     /* [previous][next][first][last][top][bottom][index][help] */
 142 {
 143     crm_update_quorum(quorate, FALSE);
 144     post_cache_update(seq);
 145     return TRUE;
 146 }
 147 
 148 static void
 149 crmd_quorum_destroy(gpointer user_data)
     /* [previous][next][first][last][top][bottom][index][help] */
 150 {
 151     if (is_not_set(fsa_input_register, R_HA_DISCONNECTED)) {
 152         crm_err("connection terminated");
 153         crmd_exit(ENOLINK);
 154 
 155     } else {
 156         crm_info("connection closed");
 157     }
 158 }
 159 
 160 static void
 161 crmd_cs_destroy(gpointer user_data)
     /* [previous][next][first][last][top][bottom][index][help] */
 162 {
 163     if (is_not_set(fsa_input_register, R_HA_DISCONNECTED)) {
 164         crm_err("connection terminated");
 165         crmd_exit(ENOLINK);
 166 
 167     } else {
 168         crm_info("connection closed");
 169     }
 170 }
 171 
 172 #  if SUPPORT_CMAN
 173 static void
 174 crmd_cman_destroy(gpointer user_data)
     /* [previous][next][first][last][top][bottom][index][help] */
 175 {
 176     if (is_not_set(fsa_input_register, R_HA_DISCONNECTED)) {
 177         crm_err("connection terminated");
 178         crmd_exit(ENOLINK);
 179 
 180     } else {
 181         crm_info("connection closed");
 182     }
 183 }
 184 #  endif
 185 
 186 extern gboolean crm_connect_corosync(crm_cluster_t * cluster);
 187 
 188 gboolean
 189 crm_connect_corosync(crm_cluster_t * cluster)
     /* [previous][next][first][last][top][bottom][index][help] */
 190 {
 191     gboolean rc = FALSE;
 192 
 193     if (is_openais_cluster()) {
 194         crm_set_status_callback(&peer_update_callback);
 195         cluster->cpg.cpg_deliver_fn = crmd_cs_dispatch;
 196         cluster->cpg.cpg_confchg_fn = pcmk_cpg_membership;
 197         cluster->destroy = crmd_cs_destroy;
 198 
 199         rc = crm_cluster_connect(cluster);
 200     }
 201 
 202     if (rc && is_corosync_cluster()) {
 203         cluster_connect_quorum(crmd_cman_dispatch, crmd_quorum_destroy);
 204     }
 205 #  if SUPPORT_CMAN
 206     if (rc && is_cman_cluster()) {
 207         init_cman_connection(crmd_cman_dispatch, crmd_cman_destroy);
 208         set_bit(fsa_input_register, R_MEMBERSHIP);
 209     }
 210 #  endif
 211     return rc;
 212 }
 213 
 214 #endif

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