root/daemons/controld/controld_callbacks.c

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

DEFINITIONS

This source file includes following definitions.
  1. crmd_ha_msg_filter
  2. node_alive
  3. peer_update_callback
  4. crmd_cib_connection_destroy
  5. crm_fsa_trigger

   1 /*
   2  * Copyright 2004-2020 the Pacemaker project contributors
   3  *
   4  * The version control history for this file may have further details.
   5  *
   6  * This source code is licensed under the GNU General Public License version 2
   7  * or later (GPLv2+) WITHOUT ANY WARRANTY.
   8  */
   9 
  10 #include <crm_internal.h>
  11 
  12 #include <sys/param.h>
  13 #include <string.h>
  14 
  15 #include <crm/crm.h>
  16 #include <crm/msg_xml.h>
  17 #include <crm/common/xml.h>
  18 #include <crm/cluster.h>
  19 #include <crm/cib.h>
  20 
  21 #include <pacemaker-controld.h>
  22 
  23 /* From join_dc... */
  24 extern gboolean check_join_state(enum crmd_fsa_state cur_state, const char *source);
  25 
  26 void
  27 crmd_ha_msg_filter(xmlNode * msg)
     /* [previous][next][first][last][top][bottom][index][help] */
  28 {
  29     if (AM_I_DC) {
  30         const char *sys_from = crm_element_value(msg, F_CRM_SYS_FROM);
  31 
  32         if (pcmk__str_eq(sys_from, CRM_SYSTEM_DC, pcmk__str_casei)) {
  33             const char *from = crm_element_value(msg, F_ORIG);
  34 
  35             if (!pcmk__str_eq(from, fsa_our_uname, pcmk__str_casei)) {
  36                 int level = LOG_INFO;
  37                 const char *op = crm_element_value(msg, F_CRM_TASK);
  38 
  39                 /* make sure the election happens NOW */
  40                 if (fsa_state != S_ELECTION) {
  41                     ha_msg_input_t new_input;
  42 
  43                     level = LOG_WARNING;
  44                     new_input.msg = msg;
  45                     register_fsa_error_adv(C_FSA_INTERNAL, I_ELECTION, NULL, &new_input,
  46                                            __func__);
  47                 }
  48 
  49                 do_crm_log(level, "Another DC detected: %s (op=%s)", from, op);
  50                 goto done;
  51             }
  52         }
  53 
  54     } else {
  55         const char *sys_to = crm_element_value(msg, F_CRM_SYS_TO);
  56 
  57         if (pcmk__str_eq(sys_to, CRM_SYSTEM_DC, pcmk__str_casei)) {
  58             return;
  59         }
  60     }
  61 
  62     /* crm_log_xml_trace("HA[inbound]", msg); */
  63     route_message(C_HA_MESSAGE, msg);
  64 
  65   done:
  66     trigger_fsa();
  67 }
  68 
  69 /*!
  70  * \internal
  71  * \brief Check whether a node is online
  72  *
  73  * \param[in] node  Node to check
  74  *
  75  * \retval -1 if completely dead
  76  * \retval  0 if partially alive
  77  * \retval  1 if completely alive
  78  */
  79 static int
  80 node_alive(const crm_node_t *node)
     /* [previous][next][first][last][top][bottom][index][help] */
  81 {
  82     if (pcmk_is_set(node->flags, crm_remote_node)) {
  83         // Pacemaker Remote nodes can't be partially alive
  84         return pcmk__str_eq(node->state, CRM_NODE_MEMBER, pcmk__str_casei) ? 1: -1;
  85 
  86     } else if (crm_is_peer_active(node)) {
  87         // Completely up cluster node: both cluster member and peer
  88         return 1;
  89 
  90     } else if (!pcmk_is_set(node->processes, crm_get_cluster_proc())
  91                && !pcmk__str_eq(node->state, CRM_NODE_MEMBER, pcmk__str_casei)) {
  92         // Completely down cluster node: neither cluster member nor peer
  93         return -1;
  94     }
  95 
  96     // Partially up cluster node: only cluster member or only peer
  97     return 0;
  98 }
  99 
 100 #define state_text(state) ((state)? (const char *)(state) : "in unknown state")
 101 
 102 bool controld_dc_left = false;
 103 
 104 void
 105 peer_update_callback(enum crm_status_type type, crm_node_t * node, const void *data)
     /* [previous][next][first][last][top][bottom][index][help] */
 106 {
 107     uint32_t old = 0;
 108     bool appeared = FALSE;
 109     bool is_remote = pcmk_is_set(node->flags, crm_remote_node);
 110 
 111     /* The controller waits to receive some information from the membership
 112      * layer before declaring itself operational. If this is being called for a
 113      * cluster node, indicate that we have it.
 114      */
 115     if (!is_remote) {
 116         controld_set_fsa_input_flags(R_PEER_DATA);
 117     }
 118 
 119     if (type == crm_status_processes
 120         && pcmk_is_set(node->processes, crm_get_cluster_proc())
 121         && !AM_I_DC
 122         && !is_remote) {
 123         /*
 124          * This is a hack until we can send to a nodeid and/or we fix node name lookups
 125          * These messages are ignored in crmd_ha_msg_filter()
 126          */
 127         xmlNode *query = create_request(CRM_OP_HELLO, NULL, NULL, CRM_SYSTEM_CRMD, CRM_SYSTEM_CRMD, NULL);
 128 
 129         crm_debug("Sending hello to node %u so that it learns our node name", node->id);
 130         send_cluster_message(node, crm_msg_crmd, query, FALSE);
 131 
 132         free_xml(query);
 133     }
 134 
 135     if (node->uname == NULL) {
 136         return;
 137     }
 138 
 139     switch (type) {
 140         case crm_status_uname:
 141             /* If we've never seen the node, then it also won't be in the status section */
 142             crm_info("%s node %s is now %s",
 143                      (is_remote? "Remote" : "Cluster"),
 144                      node->uname, state_text(node->state));
 145             return;
 146 
 147         case crm_status_nstate:
 148             /* This callback should not be called unless the state actually
 149              * changed, but here's a failsafe just in case.
 150              */
 151             CRM_CHECK(!pcmk__str_eq(data, node->state, pcmk__str_casei),
 152                       return);
 153 
 154             crm_info("%s node %s is now %s (was %s)",
 155                      (is_remote? "Remote" : "Cluster"),
 156                      node->uname, state_text(node->state), state_text(data));
 157 
 158             if (pcmk__str_eq(CRM_NODE_MEMBER, node->state, pcmk__str_casei)) {
 159                 appeared = TRUE;
 160                 if (!is_remote) {
 161                     remove_stonith_cleanup(node->uname);
 162                 }
 163             } else {
 164                 controld_remove_voter(node->uname);
 165             }
 166 
 167             crmd_alert_node_event(node);
 168             break;
 169 
 170         case crm_status_processes:
 171             CRM_CHECK(data != NULL, return);
 172             old = *(const uint32_t *)data;
 173             appeared = pcmk_is_set(node->processes, crm_get_cluster_proc());
 174 
 175             crm_info("Node %s is %s a peer " CRM_XS " DC=%s old=0x%07x new=0x%07x",
 176                      node->uname, (appeared? "now" : "no longer"),
 177                      (AM_I_DC? "true" : (fsa_our_dc? fsa_our_dc : "<none>")),
 178                      old, node->processes);
 179 
 180             if (!pcmk_is_set((node->processes ^ old), crm_get_cluster_proc())) {
 181                 /* Peer status did not change. This should not be possible,
 182                  * since we don't track process flags other than peer status.
 183                  */
 184                 crm_trace("Process flag 0x%7x did not change from 0x%7x to 0x%7x",
 185                           crm_get_cluster_proc(), old, node->processes);
 186                 return;
 187 
 188             }
 189 
 190             if (!appeared) {
 191                 controld_remove_voter(node->uname);
 192             }
 193 
 194             if (!pcmk_is_set(fsa_input_register, R_CIB_CONNECTED)) {
 195                 crm_trace("Ignoring peer status change because not connected to CIB");
 196                 return;
 197 
 198             } else if (fsa_state == S_STOPPING) {
 199                 crm_trace("Ignoring peer status change because stopping");
 200                 return;
 201             }
 202 
 203             if (pcmk__str_eq(node->uname, fsa_our_uname, pcmk__str_casei) && !appeared) {
 204                 /* Did we get evicted? */
 205                 crm_notice("Our peer connection failed");
 206                 register_fsa_input(C_CRMD_STATUS_CALLBACK, I_ERROR, NULL);
 207 
 208             } else if (pcmk__str_eq(node->uname, fsa_our_dc, pcmk__str_casei) && crm_is_peer_active(node) == FALSE) {
 209                 /* Did the DC leave us? */
 210                 crm_notice("Our peer on the DC (%s) is dead", fsa_our_dc);
 211                 register_fsa_input(C_CRMD_STATUS_CALLBACK, I_ELECTION, NULL);
 212 
 213                 /* @COMPAT DC < 1.1.13: If a DC shuts down normally, we don't
 214                  * want to fence it. Newer DCs will send their shutdown request
 215                  * to all peers, who will update the DC's expected state to
 216                  * down, thus avoiding fencing. We can safely erase the DC's
 217                  * transient attributes when it leaves in that case. However,
 218                  * the only way to avoid fencing older DCs is to leave the
 219                  * transient attributes intact until it rejoins.
 220                  */
 221                 if (compare_version(fsa_our_dc_version, "3.0.9") > 0) {
 222                     controld_delete_node_state(node->uname,
 223                                                controld_section_attrs,
 224                                                cib_scope_local);
 225                 }
 226 
 227             } else if (AM_I_DC || controld_dc_left || (fsa_our_dc == NULL)) {
 228                 /* This only needs to be done once, so normally the DC should do
 229                  * it. However if there is no DC, every node must do it, since
 230                  * there is no other way to ensure some one node does it.
 231                  */
 232                 if (appeared) {
 233                     te_trigger_stonith_history_sync(FALSE);
 234                 } else {
 235                     controld_delete_node_state(node->uname,
 236                                                controld_section_attrs,
 237                                                cib_scope_local);
 238                 }
 239             }
 240             break;
 241     }
 242 
 243     if (AM_I_DC) {
 244         xmlNode *update = NULL;
 245         int flags = node_update_peer;
 246         int alive = node_alive(node);
 247         crm_action_t *down = match_down_event(node->uuid);
 248 
 249         crm_trace("Alive=%d, appeared=%d, down=%d",
 250                   alive, appeared, (down? down->id : -1));
 251 
 252         if (appeared && (alive > 0) && !is_remote) {
 253             register_fsa_input_before(C_FSA_INTERNAL, I_NODE_JOIN, NULL);
 254         }
 255 
 256         if (down) {
 257             const char *task = crm_element_value(down->xml, XML_LRM_ATTR_TASK);
 258 
 259             if (pcmk__str_eq(task, CRM_OP_FENCE, pcmk__str_casei)) {
 260 
 261                 /* tengine_stonith_callback() confirms fence actions */
 262                 crm_trace("Updating CIB %s fencer reported fencing of %s complete",
 263                           (down->confirmed? "after" : "before"), node->uname);
 264 
 265             } else if (!appeared && pcmk__str_eq(task, CRM_OP_SHUTDOWN, pcmk__str_casei)) {
 266 
 267                 // Shutdown actions are immediately confirmed (i.e. no_wait)
 268                 if (!is_remote) {
 269                     flags |= node_update_join | node_update_expected;
 270                     crmd_peer_down(node, FALSE);
 271                     check_join_state(fsa_state, __func__);
 272                 }
 273                 if (alive >= 0) {
 274                     crm_info("%s of peer %s is in progress " CRM_XS " action=%d",
 275                              task, node->uname, down->id);
 276                 } else {
 277                     crm_notice("%s of peer %s is complete " CRM_XS " action=%d",
 278                                task, node->uname, down->id);
 279                     update_graph(transition_graph, down);
 280                     trigger_graph();
 281                 }
 282 
 283             } else {
 284                 crm_trace("Node %s is %s, was expected to %s (op %d)",
 285                           node->uname,
 286                           ((alive > 0)? "alive" :
 287                            ((alive < 0)? "dead" : "partially alive")),
 288                           task, down->id);
 289             }
 290 
 291         } else if (appeared == FALSE) {
 292             crm_warn("Stonith/shutdown of node %s was not expected",
 293                      node->uname);
 294             if (!is_remote) {
 295                 crm_update_peer_join(__func__, node, crm_join_none);
 296                 check_join_state(fsa_state, __func__);
 297             }
 298             abort_transition(INFINITY, tg_restart, "Node failure", NULL);
 299             fail_incompletable_actions(transition_graph, node->uuid);
 300 
 301         } else {
 302             crm_trace("Node %s came up, was not expected to be down",
 303                       node->uname);
 304         }
 305 
 306         if (is_remote) {
 307             /* A pacemaker_remote node won't have its cluster status updated
 308              * in the CIB by membership-layer callbacks, so do it here.
 309              */
 310             flags |= node_update_cluster;
 311 
 312             /* Trigger resource placement on newly integrated nodes */
 313             if (appeared) {
 314                 abort_transition(INFINITY, tg_restart,
 315                                  "pacemaker_remote node integrated", NULL);
 316             }
 317         }
 318 
 319         /* Update the CIB node state */
 320         update = create_node_state_update(node, flags, NULL, __func__);
 321         if (update == NULL) {
 322             crm_debug("Node state update not yet possible for %s", node->uname);
 323         } else {
 324             fsa_cib_anon_update(XML_CIB_TAG_STATUS, update);
 325         }
 326         free_xml(update);
 327     }
 328 
 329     trigger_fsa();
 330 }
 331 
 332 void
 333 crmd_cib_connection_destroy(gpointer user_data)
     /* [previous][next][first][last][top][bottom][index][help] */
 334 {
 335     CRM_CHECK(user_data == fsa_cib_conn,;);
 336 
 337     crm_trace("Invoked");
 338     trigger_fsa();
 339     fsa_cib_conn->state = cib_disconnected;
 340 
 341     if (!pcmk_is_set(fsa_input_register, R_CIB_CONNECTED)) {
 342         crm_info("Connection to the CIB manager terminated");
 343         return;
 344     }
 345 
 346     // @TODO This should trigger a reconnect, not a shutdown
 347     crm_crit("Lost connection to the CIB manager, shutting down");
 348     register_fsa_input(C_FSA_INTERNAL, I_ERROR, NULL);
 349     controld_clear_fsa_input_flags(R_CIB_CONNECTED);
 350 
 351     return;
 352 }
 353 
 354 gboolean
 355 crm_fsa_trigger(gpointer user_data)
     /* [previous][next][first][last][top][bottom][index][help] */
 356 {
 357     crm_trace("Invoked (queue len: %d)", g_list_length(fsa_message_queue));
 358     s_crmd_fsa(C_FSA_INTERNAL);
 359     crm_trace("Exited  (queue len: %d)", g_list_length(fsa_message_queue));
 360     return TRUE;
 361 }

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