root/daemons/controld/controld_messages.c

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

DEFINITIONS

This source file includes following definitions.
  1. register_fsa_error_adv
  2. register_fsa_input_adv
  3. fsa_dump_queue
  4. copy_ha_msg_input
  5. delete_fsa_input
  6. get_message
  7. fsa_typed_data_adv
  8. do_msg_route
  9. route_message
  10. relay_message
  11. authorize_version
  12. controld_authorize_ipc_message
  13. handle_message
  14. handle_failcount_op
  15. handle_lrm_delete
  16. handle_remote_state
  17. create_ping_reply
  18. handle_ping
  19. handle_node_list
  20. handle_node_info_request
  21. verify_feature_set
  22. handle_shutdown_self_ack
  23. handle_shutdown_ack
  24. handle_request
  25. handle_response
  26. handle_shutdown_request
  27. send_msg_via_ipc
  28. delete_ha_msg_input
  29. broadcast_remote_state_message

   1 /*
   2  * Copyright 2004-2024 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 #include <time.h>
  15 
  16 #include <crm/crm.h>
  17 #include <crm/common/xml.h>
  18 #include <crm/cluster/internal.h>
  19 #include <crm/cib.h>
  20 #include <crm/common/ipc_internal.h>
  21 
  22 #include <pacemaker-controld.h>
  23 
  24 static enum crmd_fsa_input handle_message(xmlNode *msg,
  25                                           enum crmd_fsa_cause cause);
  26 static xmlNode* create_ping_reply(const xmlNode *msg);
  27 static void handle_response(xmlNode *stored_msg);
  28 static enum crmd_fsa_input handle_request(xmlNode *stored_msg,
  29                                           enum crmd_fsa_cause cause);
  30 static enum crmd_fsa_input handle_shutdown_request(xmlNode *stored_msg);
  31 static void send_msg_via_ipc(xmlNode * msg, const char *sys, const char *src);
  32 
  33 /* debug only, can wrap all it likes */
  34 static int last_data_id = 0;
  35 
  36 void
  37 register_fsa_error_adv(enum crmd_fsa_cause cause, enum crmd_fsa_input input,
     /* [previous][next][first][last][top][bottom][index][help] */
  38                        fsa_data_t * cur_data, void *new_data, const char *raised_from)
  39 {
  40     /* save the current actions if any */
  41     if (controld_globals.fsa_actions != A_NOTHING) {
  42         register_fsa_input_adv(cur_data ? cur_data->fsa_cause : C_FSA_INTERNAL,
  43                                I_NULL, cur_data ? cur_data->data : NULL,
  44                                controld_globals.fsa_actions, TRUE, __func__);
  45     }
  46 
  47     /* reset the action list */
  48     crm_info("Resetting the current action list");
  49     fsa_dump_actions(controld_globals.fsa_actions, "Drop");
  50     controld_globals.fsa_actions = A_NOTHING;
  51 
  52     /* register the error */
  53     register_fsa_input_adv(cause, input, new_data, A_NOTHING, TRUE, raised_from);
  54 }
  55 
  56 void
  57 register_fsa_input_adv(enum crmd_fsa_cause cause, enum crmd_fsa_input input,
     /* [previous][next][first][last][top][bottom][index][help] */
  58                        void *data, uint64_t with_actions,
  59                        gboolean prepend, const char *raised_from)
  60 {
  61     unsigned old_len = g_list_length(controld_globals.fsa_message_queue);
  62     fsa_data_t *fsa_data = NULL;
  63 
  64     if (raised_from == NULL) {
  65         raised_from = "<unknown>";
  66     }
  67 
  68     if (input == I_NULL && with_actions == A_NOTHING /* && data == NULL */ ) {
  69         /* no point doing anything */
  70         crm_err("Cannot add entry to queue: no input and no action");
  71         return;
  72     }
  73 
  74     if (input == I_WAIT_FOR_EVENT) {
  75         controld_set_global_flags(controld_fsa_is_stalled);
  76         crm_debug("Stalling the FSA pending further input: source=%s cause=%s data=%p queue=%d",
  77                   raised_from, fsa_cause2string(cause), data, old_len);
  78 
  79         if (old_len > 0) {
  80             fsa_dump_queue(LOG_TRACE);
  81             prepend = FALSE;
  82         }
  83 
  84         if (data == NULL) {
  85             controld_set_fsa_action_flags(with_actions);
  86             fsa_dump_actions(with_actions, "Restored");
  87             return;
  88         }
  89 
  90         /* Store everything in the new event and reset
  91          * controld_globals.fsa_actions
  92          */
  93         with_actions |= controld_globals.fsa_actions;
  94         controld_globals.fsa_actions = A_NOTHING;
  95     }
  96 
  97     last_data_id++;
  98     crm_trace("%s %s FSA input %d (%s) due to %s, %s data",
  99               raised_from, (prepend? "prepended" : "appended"), last_data_id,
 100               fsa_input2string(input), fsa_cause2string(cause),
 101               (data? "with" : "without"));
 102 
 103     fsa_data = pcmk__assert_alloc(1, sizeof(fsa_data_t));
 104     fsa_data->id = last_data_id;
 105     fsa_data->fsa_input = input;
 106     fsa_data->fsa_cause = cause;
 107     fsa_data->origin = raised_from;
 108     fsa_data->data = NULL;
 109     fsa_data->data_type = fsa_dt_none;
 110     fsa_data->actions = with_actions;
 111 
 112     if (with_actions != A_NOTHING) {
 113         crm_trace("Adding actions %.16llx to input",
 114                   (unsigned long long) with_actions);
 115     }
 116 
 117     if (data != NULL) {
 118         switch (cause) {
 119             case C_FSA_INTERNAL:
 120             case C_CRMD_STATUS_CALLBACK:
 121             case C_IPC_MESSAGE:
 122             case C_HA_MESSAGE:
 123                 CRM_CHECK(((ha_msg_input_t *) data)->msg != NULL,
 124                           crm_err("Bogus data from %s", raised_from));
 125                 crm_trace("Copying %s data from %s as cluster message data",
 126                           fsa_cause2string(cause), raised_from);
 127                 fsa_data->data = copy_ha_msg_input(data);
 128                 fsa_data->data_type = fsa_dt_ha_msg;
 129                 break;
 130 
 131             case C_LRM_OP_CALLBACK:
 132                 crm_trace("Copying %s data from %s as lrmd_event_data_t",
 133                           fsa_cause2string(cause), raised_from);
 134                 fsa_data->data = lrmd_copy_event((lrmd_event_data_t *) data);
 135                 fsa_data->data_type = fsa_dt_lrm;
 136                 break;
 137 
 138             case C_TIMER_POPPED:
 139             case C_SHUTDOWN:
 140             case C_UNKNOWN:
 141             case C_STARTUP:
 142                 crm_crit("Copying %s data (from %s) is not yet implemented",
 143                          fsa_cause2string(cause), raised_from);
 144                 crmd_exit(CRM_EX_SOFTWARE);
 145                 break;
 146         }
 147     }
 148 
 149     /* make sure to free it properly later */
 150     if (prepend) {
 151         controld_globals.fsa_message_queue
 152             = g_list_prepend(controld_globals.fsa_message_queue, fsa_data);
 153     } else {
 154         controld_globals.fsa_message_queue
 155             = g_list_append(controld_globals.fsa_message_queue, fsa_data);
 156     }
 157 
 158     crm_trace("FSA message queue length is %d",
 159               g_list_length(controld_globals.fsa_message_queue));
 160 
 161     /* fsa_dump_queue(LOG_TRACE); */
 162 
 163     if (old_len == g_list_length(controld_globals.fsa_message_queue)) {
 164         crm_err("Couldn't add message to the queue");
 165     }
 166 
 167     if (input != I_WAIT_FOR_EVENT) {
 168         controld_trigger_fsa();
 169     }
 170 }
 171 
 172 void
 173 fsa_dump_queue(int log_level)
     /* [previous][next][first][last][top][bottom][index][help] */
 174 {
 175     int offset = 0;
 176 
 177     for (GList *iter = controld_globals.fsa_message_queue; iter != NULL;
 178          iter = iter->next) {
 179         fsa_data_t *data = (fsa_data_t *) iter->data;
 180 
 181         do_crm_log_unlikely(log_level,
 182                             "queue[%d.%d]: input %s raised by %s(%p.%d)\t(cause=%s)",
 183                             offset++, data->id, fsa_input2string(data->fsa_input),
 184                             data->origin, data->data, data->data_type,
 185                             fsa_cause2string(data->fsa_cause));
 186     }
 187 }
 188 
 189 ha_msg_input_t *
 190 copy_ha_msg_input(ha_msg_input_t * orig)
     /* [previous][next][first][last][top][bottom][index][help] */
 191 {
 192     xmlNode *wrapper = NULL;
 193 
 194     ha_msg_input_t *copy = pcmk__assert_alloc(1, sizeof(ha_msg_input_t));
 195 
 196     copy->msg = (orig != NULL)? pcmk__xml_copy(NULL, orig->msg) : NULL;
 197 
 198     wrapper = pcmk__xe_first_child(copy->msg, PCMK__XE_CRM_XML, NULL, NULL);
 199     copy->xml = pcmk__xe_first_child(wrapper, NULL, NULL, NULL);
 200     return copy;
 201 }
 202 
 203 void
 204 delete_fsa_input(fsa_data_t * fsa_data)
     /* [previous][next][first][last][top][bottom][index][help] */
 205 {
 206     lrmd_event_data_t *op = NULL;
 207     xmlNode *foo = NULL;
 208 
 209     if (fsa_data == NULL) {
 210         return;
 211     }
 212     crm_trace("About to free %s data", fsa_cause2string(fsa_data->fsa_cause));
 213 
 214     if (fsa_data->data != NULL) {
 215         switch (fsa_data->data_type) {
 216             case fsa_dt_ha_msg:
 217                 delete_ha_msg_input(fsa_data->data);
 218                 break;
 219 
 220             case fsa_dt_xml:
 221                 foo = fsa_data->data;
 222                 free_xml(foo);
 223                 break;
 224 
 225             case fsa_dt_lrm:
 226                 op = (lrmd_event_data_t *) fsa_data->data;
 227                 lrmd_free_event(op);
 228                 break;
 229 
 230             case fsa_dt_none:
 231                 if (fsa_data->data != NULL) {
 232                     crm_err("Don't know how to free %s data from %s",
 233                             fsa_cause2string(fsa_data->fsa_cause), fsa_data->origin);
 234                     crmd_exit(CRM_EX_SOFTWARE);
 235                 }
 236                 break;
 237         }
 238         crm_trace("%s data freed", fsa_cause2string(fsa_data->fsa_cause));
 239     }
 240 
 241     free(fsa_data);
 242 }
 243 
 244 /* returns the next message */
 245 fsa_data_t *
 246 get_message(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 247 {
 248     fsa_data_t *message
 249         = (fsa_data_t *) controld_globals.fsa_message_queue->data;
 250 
 251     controld_globals.fsa_message_queue
 252         = g_list_remove(controld_globals.fsa_message_queue, message);
 253     crm_trace("Processing input %d", message->id);
 254     return message;
 255 }
 256 
 257 void *
 258 fsa_typed_data_adv(fsa_data_t * fsa_data, enum fsa_data_type a_type, const char *caller)
     /* [previous][next][first][last][top][bottom][index][help] */
 259 {
 260     void *ret_val = NULL;
 261 
 262     if (fsa_data == NULL) {
 263         crm_err("%s: No FSA data available", caller);
 264 
 265     } else if (fsa_data->data == NULL) {
 266         crm_err("%s: No message data available. Origin: %s", caller, fsa_data->origin);
 267 
 268     } else if (fsa_data->data_type != a_type) {
 269         crm_crit("%s: Message data was the wrong type! %d vs. requested=%d.  Origin: %s",
 270                  caller, fsa_data->data_type, a_type, fsa_data->origin);
 271         pcmk__assert(fsa_data->data_type == a_type);
 272     } else {
 273         ret_val = fsa_data->data;
 274     }
 275 
 276     return ret_val;
 277 }
 278 
 279 /*      A_MSG_ROUTE     */
 280 void
 281 do_msg_route(long long action,
     /* [previous][next][first][last][top][bottom][index][help] */
 282              enum crmd_fsa_cause cause,
 283              enum crmd_fsa_state cur_state,
 284              enum crmd_fsa_input current_input, fsa_data_t * msg_data)
 285 {
 286     ha_msg_input_t *input = fsa_typed_data(fsa_dt_ha_msg);
 287 
 288     route_message(msg_data->fsa_cause, input->msg);
 289 }
 290 
 291 void
 292 route_message(enum crmd_fsa_cause cause, xmlNode * input)
     /* [previous][next][first][last][top][bottom][index][help] */
 293 {
 294     ha_msg_input_t fsa_input;
 295     enum crmd_fsa_input result = I_NULL;
 296 
 297     fsa_input.msg = input;
 298     CRM_CHECK(cause == C_IPC_MESSAGE || cause == C_HA_MESSAGE, return);
 299 
 300     /* try passing the buck first */
 301     if (relay_message(input, cause == C_IPC_MESSAGE)) {
 302         return;
 303     }
 304 
 305     /* handle locally */
 306     result = handle_message(input, cause);
 307 
 308     /* done or process later? */
 309     switch (result) {
 310         case I_NULL:
 311         case I_CIB_OP:
 312         case I_ROUTER:
 313         case I_NODE_JOIN:
 314         case I_JOIN_REQUEST:
 315         case I_JOIN_RESULT:
 316             break;
 317         default:
 318             /* Defering local processing of message */
 319             register_fsa_input_later(cause, result, &fsa_input);
 320             return;
 321     }
 322 
 323     if (result != I_NULL) {
 324         /* add to the front of the queue */
 325         register_fsa_input(cause, result, &fsa_input);
 326     }
 327 }
 328 
 329 gboolean
 330 relay_message(xmlNode * msg, gboolean originated_locally)
     /* [previous][next][first][last][top][bottom][index][help] */
 331 {
 332     enum crm_ais_msg_types dest = crm_msg_none;
 333     bool is_for_dc = false;
 334     bool is_for_dcib = false;
 335     bool is_for_te = false;
 336     bool is_for_crm = false;
 337     bool is_for_cib = false;
 338     bool is_local = false;
 339     bool broadcast = false;
 340     const char *host_to = NULL;
 341     const char *sys_to = NULL;
 342     const char *sys_from = NULL;
 343     const char *type = NULL;
 344     const char *task = NULL;
 345     const char *ref = NULL;
 346     crm_node_t *node_to = NULL;
 347 
 348     CRM_CHECK(msg != NULL, return TRUE);
 349 
 350     host_to = crm_element_value(msg, PCMK__XA_CRM_HOST_TO);
 351     sys_to = crm_element_value(msg, PCMK__XA_CRM_SYS_TO);
 352     sys_from = crm_element_value(msg, PCMK__XA_CRM_SYS_FROM);
 353     type = crm_element_value(msg, PCMK__XA_T);
 354     task = crm_element_value(msg, PCMK__XA_CRM_TASK);
 355     ref = crm_element_value(msg, PCMK_XA_REFERENCE);
 356 
 357     broadcast = pcmk__str_empty(host_to);
 358 
 359     if (ref == NULL) {
 360         ref = "without reference ID";
 361     }
 362 
 363     if (pcmk__str_eq(task, CRM_OP_HELLO, pcmk__str_casei)) {
 364         crm_trace("Received hello %s from %s (no processing needed)",
 365                   ref, pcmk__s(sys_from, "unidentified source"));
 366         crm_log_xml_trace(msg, "hello");
 367         return TRUE;
 368     }
 369 
 370     // Require message type (set by create_request())
 371     if (!pcmk__str_eq(type, PCMK__VALUE_CRMD, pcmk__str_none)) {
 372         crm_warn("Ignoring invalid message %s with type '%s' "
 373                  "(not '" PCMK__VALUE_CRMD "')",
 374                  ref, pcmk__s(type, ""));
 375         crm_log_xml_trace(msg, "ignored");
 376         return TRUE;
 377     }
 378 
 379     // Require a destination subsystem (also set by create_request())
 380     if (sys_to == NULL) {
 381         crm_warn("Ignoring invalid message %s with no " PCMK__XA_CRM_SYS_TO,
 382                  ref);
 383         crm_log_xml_trace(msg, "ignored");
 384         return TRUE;
 385     }
 386 
 387     // Get the message type appropriate to the destination subsystem
 388     if (pcmk_get_cluster_layer() == pcmk_cluster_layer_corosync) {
 389         dest = pcmk__cluster_parse_msg_type(sys_to);
 390         if (dest == crm_msg_none) {
 391             /* Unrecognized value, use a sane default
 392              *
 393              * @TODO Maybe we should bail instead
 394              */
 395             dest = crm_msg_crmd;
 396         }
 397     }
 398 
 399     is_for_dc = (strcasecmp(CRM_SYSTEM_DC, sys_to) == 0);
 400     is_for_dcib = (strcasecmp(CRM_SYSTEM_DCIB, sys_to) == 0);
 401     is_for_te = (strcasecmp(CRM_SYSTEM_TENGINE, sys_to) == 0);
 402     is_for_cib = (strcasecmp(CRM_SYSTEM_CIB, sys_to) == 0);
 403     is_for_crm = (strcasecmp(CRM_SYSTEM_CRMD, sys_to) == 0);
 404 
 405     // Check whether message should be processed locally
 406     is_local = false;
 407     if (broadcast) {
 408         if (is_for_dc || is_for_te) {
 409             is_local = false;
 410 
 411         } else if (is_for_crm) {
 412             if (pcmk__strcase_any_of(task, CRM_OP_NODE_INFO,
 413                                      PCMK__CONTROLD_CMD_NODES, NULL)) {
 414                 /* Node info requests do not specify a host, which is normally
 415                  * treated as "all hosts", because the whole point is that the
 416                  * client may not know the local node name. Always handle these
 417                  * requests locally.
 418                  */
 419                 is_local = true;
 420             } else {
 421                 is_local = !originated_locally;
 422             }
 423 
 424         } else {
 425             is_local = true;
 426         }
 427 
 428     } else if (pcmk__str_eq(controld_globals.our_nodename, host_to,
 429                             pcmk__str_casei)) {
 430         is_local = true;
 431 
 432     } else if (is_for_crm && pcmk__str_eq(task, CRM_OP_LRM_DELETE, pcmk__str_casei)) {
 433         xmlNode *wrapper = pcmk__xe_first_child(msg, PCMK__XE_CRM_XML, NULL,
 434                                                 NULL);
 435         xmlNode *msg_data = pcmk__xe_first_child(wrapper, NULL, NULL, NULL);
 436         const char *mode = crm_element_value(msg_data, PCMK__XA_MODE);
 437 
 438         if (pcmk__str_eq(mode, PCMK__VALUE_CIB, pcmk__str_none)) {
 439             // Local delete of an offline node's resource history
 440             is_local = true;
 441         }
 442     }
 443 
 444     // If is for DC and DC is not yet selected
 445     if (is_for_dc && pcmk__str_eq(task, CRM_OP_PING, pcmk__str_casei)
 446         && (controld_globals.dc_name == NULL)) {
 447 
 448         xmlNode *reply = create_ping_reply(msg);
 449         sys_to = crm_element_value(reply, PCMK__XA_CRM_SYS_TO);
 450         // Explicitly leave src empty. It indicates that dc is "not yet selected"
 451         send_msg_via_ipc(reply, sys_to, NULL);
 452         free_xml(reply);
 453         return TRUE;
 454     }
 455 
 456     // Check whether message should be relayed
 457 
 458     if (is_for_dc || is_for_dcib || is_for_te) {
 459         if (AM_I_DC) {
 460             if (is_for_te) {
 461                 crm_trace("Route message %s locally as transition request",
 462                           ref);
 463                 crm_log_xml_trace(msg, sys_to);
 464                 send_msg_via_ipc(msg, sys_to, controld_globals.our_nodename);
 465                 return TRUE; // No further processing of message is needed
 466             }
 467             crm_trace("Route message %s locally as DC request", ref);
 468             return FALSE; // More to be done by caller
 469         }
 470 
 471         if (originated_locally
 472             && !pcmk__strcase_any_of(sys_from, CRM_SYSTEM_PENGINE,
 473                                      CRM_SYSTEM_TENGINE, NULL)) {
 474             crm_trace("Relay message %s to DC (via %s)",
 475                       ref, pcmk__s(host_to, "broadcast"));
 476             crm_log_xml_trace(msg, "relayed");
 477             if (!broadcast) {
 478                 node_to = pcmk__get_node(0, host_to, NULL,
 479                                          pcmk__node_search_cluster_member);
 480             }
 481             pcmk__cluster_send_message(node_to, dest, msg);
 482             return TRUE;
 483         }
 484 
 485         /* Transition engine and scheduler messages are sent only to the DC on
 486          * the same node. If we are no longer the DC, discard this message.
 487          */
 488         crm_trace("Ignoring message %s because we are no longer DC", ref);
 489         crm_log_xml_trace(msg, "ignored");
 490         return TRUE; // No further processing of message is needed
 491     }
 492 
 493     if (is_local) {
 494         if (is_for_crm || is_for_cib) {
 495             crm_trace("Route message %s locally as controller request", ref);
 496             return FALSE; // More to be done by caller
 497         }
 498         crm_trace("Relay message %s locally to %s", ref, sys_to);
 499         crm_log_xml_trace(msg, "IPC-relay");
 500         send_msg_via_ipc(msg, sys_to, controld_globals.our_nodename);
 501         return TRUE;
 502     }
 503 
 504     if (!broadcast) {
 505         node_to = pcmk__search_node_caches(0, host_to,
 506                                            pcmk__node_search_cluster_member);
 507         if (node_to == NULL) {
 508             crm_warn("Ignoring message %s because node %s is unknown",
 509                      ref, host_to);
 510             crm_log_xml_trace(msg, "ignored");
 511             return TRUE;
 512         }
 513     }
 514 
 515     crm_trace("Relay message %s to %s",
 516               ref, pcmk__s(host_to, "all peers"));
 517     crm_log_xml_trace(msg, "relayed");
 518     pcmk__cluster_send_message(node_to, dest, msg);
 519     return TRUE;
 520 }
 521 
 522 // Return true if field contains a positive integer
 523 static bool
 524 authorize_version(xmlNode *message_data, const char *field,
     /* [previous][next][first][last][top][bottom][index][help] */
 525                   const char *client_name, const char *ref, const char *uuid)
 526 {
 527     const char *version = crm_element_value(message_data, field);
 528     long long version_num;
 529 
 530     if ((pcmk__scan_ll(version, &version_num, -1LL) != pcmk_rc_ok)
 531         || (version_num < 0LL)) {
 532 
 533         crm_warn("Rejected IPC hello from %s: '%s' is not a valid protocol %s "
 534                  CRM_XS " ref=%s uuid=%s",
 535                  client_name, ((version == NULL)? "" : version),
 536                  field, (ref? ref : "none"), uuid);
 537         return false;
 538     }
 539     return true;
 540 }
 541 
 542 /*!
 543  * \internal
 544  * \brief Check whether a client IPC message is acceptable
 545  *
 546  * If a given client IPC message is a hello, "authorize" it by ensuring it has
 547  * valid information such as a protocol version, and return false indicating
 548  * that nothing further needs to be done with the message. If the message is not
 549  * a hello, just return true to indicate it needs further processing.
 550  *
 551  * \param[in]     client_msg     XML of IPC message
 552  * \param[in,out] curr_client    If IPC is not proxied, client that sent message
 553  * \param[in]     proxy_session  If IPC is proxied, the session ID
 554  *
 555  * \return true if message needs further processing, false if it doesn't
 556  */
 557 bool
 558 controld_authorize_ipc_message(const xmlNode *client_msg, pcmk__client_t *curr_client,
     /* [previous][next][first][last][top][bottom][index][help] */
 559                                const char *proxy_session)
 560 {
 561     xmlNode *wrapper = NULL;
 562     xmlNode *message_data = NULL;
 563     const char *client_name = NULL;
 564     const char *op = crm_element_value(client_msg, PCMK__XA_CRM_TASK);
 565     const char *ref = crm_element_value(client_msg, PCMK_XA_REFERENCE);
 566     const char *uuid = (curr_client? curr_client->id : proxy_session);
 567 
 568     if (uuid == NULL) {
 569         crm_warn("IPC message from client rejected: No client identifier "
 570                  CRM_XS " ref=%s", (ref? ref : "none"));
 571         goto rejected;
 572     }
 573 
 574     if (!pcmk__str_eq(CRM_OP_HELLO, op, pcmk__str_casei)) {
 575         // Only hello messages need to be authorized
 576         return true;
 577     }
 578 
 579     wrapper = pcmk__xe_first_child(client_msg, PCMK__XE_CRM_XML, NULL, NULL);
 580     message_data = pcmk__xe_first_child(wrapper, NULL, NULL, NULL);
 581 
 582     client_name = crm_element_value(message_data, PCMK__XA_CLIENT_NAME);
 583     if (pcmk__str_empty(client_name)) {
 584         crm_warn("IPC hello from client rejected: No client name",
 585                  CRM_XS " ref=%s uuid=%s", (ref? ref : "none"), uuid);
 586         goto rejected;
 587     }
 588     if (!authorize_version(message_data, PCMK__XA_MAJOR_VERSION, client_name,
 589                            ref, uuid)) {
 590         goto rejected;
 591     }
 592     if (!authorize_version(message_data, PCMK__XA_MINOR_VERSION, client_name,
 593                            ref, uuid)) {
 594         goto rejected;
 595     }
 596 
 597     crm_trace("Validated IPC hello from client %s", client_name);
 598     crm_log_xml_trace(client_msg, "hello");
 599     if (curr_client) {
 600         curr_client->userdata = pcmk__str_copy(client_name);
 601     }
 602     controld_trigger_fsa();
 603     return false;
 604 
 605 rejected:
 606     crm_log_xml_trace(client_msg, "rejected");
 607     if (curr_client) {
 608         qb_ipcs_disconnect(curr_client->ipcs);
 609     }
 610     return false;
 611 }
 612 
 613 static enum crmd_fsa_input
 614 handle_message(xmlNode *msg, enum crmd_fsa_cause cause)
     /* [previous][next][first][last][top][bottom][index][help] */
 615 {
 616     const char *type = NULL;
 617 
 618     CRM_CHECK(msg != NULL, return I_NULL);
 619 
 620     type = crm_element_value(msg, PCMK__XA_SUBT);
 621     if (pcmk__str_eq(type, PCMK__VALUE_REQUEST, pcmk__str_none)) {
 622         return handle_request(msg, cause);
 623     }
 624 
 625     if (pcmk__str_eq(type, PCMK__VALUE_RESPONSE, pcmk__str_none)) {
 626         handle_response(msg);
 627         return I_NULL;
 628     }
 629 
 630     crm_warn("Ignoring message with unknown " PCMK__XA_SUBT" '%s'",
 631              pcmk__s(type, ""));
 632     crm_log_xml_trace(msg, "bad");
 633     return I_NULL;
 634 }
 635 
 636 static enum crmd_fsa_input
 637 handle_failcount_op(xmlNode * stored_msg)
     /* [previous][next][first][last][top][bottom][index][help] */
 638 {
 639     const char *rsc = NULL;
 640     const char *uname = NULL;
 641     const char *op = NULL;
 642     char *interval_spec = NULL;
 643     guint interval_ms = 0;
 644     gboolean is_remote_node = FALSE;
 645 
 646     xmlNode *wrapper = pcmk__xe_first_child(stored_msg, PCMK__XE_CRM_XML, NULL,
 647                                             NULL);
 648     xmlNode *xml_op = pcmk__xe_first_child(wrapper, NULL, NULL, NULL);
 649 
 650     if (xml_op) {
 651         xmlNode *xml_rsc = pcmk__xe_first_child(xml_op, PCMK_XE_PRIMITIVE, NULL,
 652                                                 NULL);
 653         xmlNode *xml_attrs = pcmk__xe_first_child(xml_op, PCMK__XE_ATTRIBUTES,
 654                                                   NULL, NULL);
 655 
 656         if (xml_rsc) {
 657             rsc = pcmk__xe_id(xml_rsc);
 658         }
 659         if (xml_attrs) {
 660             op = crm_element_value(xml_attrs,
 661                                    CRM_META "_" PCMK__META_CLEAR_FAILURE_OP);
 662             crm_element_value_ms(xml_attrs,
 663                                  CRM_META "_" PCMK__META_CLEAR_FAILURE_INTERVAL,
 664                                  &interval_ms);
 665         }
 666     }
 667     uname = crm_element_value(xml_op, PCMK__META_ON_NODE);
 668 
 669     if ((rsc == NULL) || (uname == NULL)) {
 670         crm_log_xml_warn(stored_msg, "invalid failcount op");
 671         return I_NULL;
 672     }
 673 
 674     if (crm_element_value(xml_op, PCMK__XA_ROUTER_NODE)) {
 675         is_remote_node = TRUE;
 676     }
 677 
 678     crm_debug("Clearing failures for %s-interval %s on %s "
 679               "from attribute manager, CIB, and executor state",
 680               pcmk__readable_interval(interval_ms), rsc, uname);
 681 
 682     if (interval_ms) {
 683         interval_spec = crm_strdup_printf("%ums", interval_ms);
 684     }
 685     update_attrd_clear_failures(uname, rsc, op, interval_spec, is_remote_node);
 686     free(interval_spec);
 687 
 688     controld_cib_delete_last_failure(rsc, uname, op, interval_ms);
 689 
 690     lrm_clear_last_failure(rsc, uname, op, interval_ms);
 691 
 692     return I_NULL;
 693 }
 694 
 695 static enum crmd_fsa_input
 696 handle_lrm_delete(xmlNode *stored_msg)
     /* [previous][next][first][last][top][bottom][index][help] */
 697 {
 698     const char *mode = NULL;
 699     xmlNode *wrapper = pcmk__xe_first_child(stored_msg, PCMK__XE_CRM_XML, NULL,
 700                                             NULL);
 701     xmlNode *msg_data = pcmk__xe_first_child(wrapper, NULL, NULL, NULL);
 702 
 703     CRM_CHECK(msg_data != NULL, return I_NULL);
 704 
 705     /* CRM_OP_LRM_DELETE has two distinct modes. The default behavior is to
 706      * relay the operation to the affected node, which will unregister the
 707      * resource from the local executor, clear the resource's history from the
 708      * CIB, and do some bookkeeping in the controller.
 709      *
 710      * However, if the affected node is offline, the client will specify
 711      * mode=PCMK__VALUE_CIB which means the controller receiving the operation
 712      * should clear the resource's history from the CIB and nothing else. This
 713      * is used to clear shutdown locks.
 714      */
 715     mode = crm_element_value(msg_data, PCMK__XA_MODE);
 716     if (!pcmk__str_eq(mode, PCMK__VALUE_CIB, pcmk__str_none)) {
 717         // Relay to affected node
 718         crm_xml_add(stored_msg, PCMK__XA_CRM_SYS_TO, CRM_SYSTEM_LRMD);
 719         return I_ROUTER;
 720 
 721     } else {
 722         // Delete CIB history locally (compare with do_lrm_delete())
 723         const char *from_sys = NULL;
 724         const char *user_name = NULL;
 725         const char *rsc_id = NULL;
 726         const char *node = NULL;
 727         xmlNode *rsc_xml = NULL;
 728         int rc = pcmk_rc_ok;
 729 
 730         rsc_xml = pcmk__xe_first_child(msg_data, PCMK_XE_PRIMITIVE, NULL, NULL);
 731         CRM_CHECK(rsc_xml != NULL, return I_NULL);
 732 
 733         rsc_id = pcmk__xe_id(rsc_xml);
 734         from_sys = crm_element_value(stored_msg, PCMK__XA_CRM_SYS_FROM);
 735         node = crm_element_value(msg_data, PCMK__META_ON_NODE);
 736         user_name = pcmk__update_acl_user(stored_msg, PCMK__XA_CRM_USER, NULL);
 737         crm_debug("Handling " CRM_OP_LRM_DELETE " for %s on %s locally%s%s "
 738                   "(clearing CIB resource history only)", rsc_id, node,
 739                   (user_name? " for user " : ""), (user_name? user_name : ""));
 740         rc = controld_delete_resource_history(rsc_id, node, user_name,
 741                                               cib_dryrun|cib_sync_call);
 742         if (rc == pcmk_rc_ok) {
 743             rc = controld_delete_resource_history(rsc_id, node, user_name,
 744                                                   crmd_cib_smart_opt());
 745         }
 746 
 747         /* Notify client. Also notify tengine if mode=PCMK__VALUE_CIB and
 748          * op=CRM_OP_LRM_DELETE.
 749          */
 750         if (from_sys) {
 751             lrmd_event_data_t *op = NULL;
 752             const char *from_host = crm_element_value(stored_msg, PCMK__XA_SRC);
 753             const char *transition;
 754 
 755             if (strcmp(from_sys, CRM_SYSTEM_TENGINE)) {
 756                 transition = crm_element_value(msg_data,
 757                                                PCMK__XA_TRANSITION_KEY);
 758             } else {
 759                 transition = crm_element_value(stored_msg,
 760                                                PCMK__XA_TRANSITION_KEY);
 761             }
 762 
 763             crm_info("Notifying %s on %s that %s was%s deleted",
 764                      from_sys, (from_host? from_host : "local node"), rsc_id,
 765                      ((rc == pcmk_rc_ok)? "" : " not"));
 766             op = lrmd_new_event(rsc_id, PCMK_ACTION_DELETE, 0);
 767             op->type = lrmd_event_exec_complete;
 768             op->user_data = pcmk__str_copy(pcmk__s(transition, FAKE_TE_ID));
 769             op->params = pcmk__strkey_table(free, free);
 770             pcmk__insert_dup(op->params, PCMK_XA_CRM_FEATURE_SET,
 771                              CRM_FEATURE_SET);
 772             controld_rc2event(op, rc);
 773             controld_ack_event_directly(from_host, from_sys, NULL, op, rsc_id);
 774             lrmd_free_event(op);
 775             controld_trigger_delete_refresh(from_sys, rsc_id);
 776         }
 777         return I_NULL;
 778     }
 779 }
 780 
 781 /*!
 782  * \brief Handle a CRM_OP_REMOTE_STATE message by updating remote peer cache
 783  *
 784  * \param[in] msg  Message XML
 785  *
 786  * \return Next FSA input
 787  */
 788 static enum crmd_fsa_input
 789 handle_remote_state(const xmlNode *msg)
     /* [previous][next][first][last][top][bottom][index][help] */
 790 {
 791     const char *conn_host = NULL;
 792     const char *remote_uname = pcmk__xe_id(msg);
 793     crm_node_t *remote_peer;
 794     bool remote_is_up = false;
 795     int rc = pcmk_rc_ok;
 796 
 797     rc = pcmk__xe_get_bool_attr(msg, PCMK__XA_IN_CCM, &remote_is_up);
 798 
 799     CRM_CHECK(remote_uname && rc == pcmk_rc_ok, return I_NULL);
 800 
 801     remote_peer = pcmk__cluster_lookup_remote_node(remote_uname);
 802     CRM_CHECK(remote_peer, return I_NULL);
 803 
 804     pcmk__update_peer_state(__func__, remote_peer,
 805                             remote_is_up ? CRM_NODE_MEMBER : CRM_NODE_LOST,
 806                             0);
 807 
 808     conn_host = crm_element_value(msg, PCMK__XA_CONNECTION_HOST);
 809     if (conn_host) {
 810         pcmk__str_update(&remote_peer->conn_host, conn_host);
 811     } else if (remote_peer->conn_host) {
 812         free(remote_peer->conn_host);
 813         remote_peer->conn_host = NULL;
 814     }
 815 
 816     return I_NULL;
 817 }
 818 
 819 /*!
 820  * \brief Handle a CRM_OP_PING message
 821  *
 822  * \param[in] msg  Message XML
 823  *
 824  * \return Next FSA input
 825  */
 826 static xmlNode*
 827 create_ping_reply(const xmlNode *msg)
     /* [previous][next][first][last][top][bottom][index][help] */
 828 {
 829     const char *value = NULL;
 830     xmlNode *ping = NULL;
 831     xmlNode *reply = NULL;
 832 
 833     // Build reply
 834 
 835     ping = pcmk__xe_create(NULL, PCMK__XE_PING_RESPONSE);
 836     value = crm_element_value(msg, PCMK__XA_CRM_SYS_TO);
 837     crm_xml_add(ping, PCMK__XA_CRM_SUBSYSTEM, value);
 838 
 839     // Add controller state
 840     value = fsa_state2string(controld_globals.fsa_state);
 841     crm_xml_add(ping, PCMK__XA_CRMD_STATE, value);
 842     crm_notice("Current ping state: %s", value); // CTS needs this
 843 
 844     // Add controller health
 845     // @TODO maybe do some checks to determine meaningful status
 846     crm_xml_add(ping, PCMK_XA_RESULT, "ok");
 847 
 848     reply = create_reply(msg, ping);
 849     free_xml(ping);
 850     return reply;
 851 }
 852 
 853 static enum crmd_fsa_input
 854 handle_ping(const xmlNode *msg)
     /* [previous][next][first][last][top][bottom][index][help] */
 855 {
 856     xmlNode *reply = create_ping_reply(msg);
 857     if (reply != NULL) {
 858         (void) relay_message(reply, TRUE);
 859         free_xml(reply);
 860     }
 861 
 862     // Nothing further to do
 863     return I_NULL;
 864 }
 865 
 866 /*!
 867  * \brief Handle a PCMK__CONTROLD_CMD_NODES message
 868  *
 869  * \param[in] request  Message XML
 870  *
 871  * \return Next FSA input
 872  */
 873 static enum crmd_fsa_input
 874 handle_node_list(const xmlNode *request)
     /* [previous][next][first][last][top][bottom][index][help] */
 875 {
 876     GHashTableIter iter;
 877     crm_node_t *node = NULL;
 878     xmlNode *reply = NULL;
 879     xmlNode *reply_data = NULL;
 880 
 881     // Create message data for reply
 882     reply_data = pcmk__xe_create(NULL, PCMK_XE_NODES);
 883     g_hash_table_iter_init(&iter, crm_peer_cache);
 884     while (g_hash_table_iter_next(&iter, NULL, (gpointer *) & node)) {
 885         xmlNode *xml = pcmk__xe_create(reply_data, PCMK_XE_NODE);
 886 
 887         crm_xml_add_ll(xml, PCMK_XA_ID, (long long) node->id); // uint32_t
 888         crm_xml_add(xml, PCMK_XA_UNAME, node->uname);
 889         crm_xml_add(xml, PCMK__XA_IN_CCM, node->state);
 890     }
 891 
 892     // Create and send reply
 893     reply = create_reply(request, reply_data);
 894     free_xml(reply_data);
 895     if (reply) {
 896         (void) relay_message(reply, TRUE);
 897         free_xml(reply);
 898     }
 899 
 900     // Nothing further to do
 901     return I_NULL;
 902 }
 903 
 904 /*!
 905  * \brief Handle a CRM_OP_NODE_INFO request
 906  *
 907  * \param[in] msg  Message XML
 908  *
 909  * \return Next FSA input
 910  */
 911 static enum crmd_fsa_input
 912 handle_node_info_request(const xmlNode *msg)
     /* [previous][next][first][last][top][bottom][index][help] */
 913 {
 914     const char *value = NULL;
 915     crm_node_t *node = NULL;
 916     int node_id = 0;
 917     xmlNode *reply = NULL;
 918     xmlNode *reply_data = NULL;
 919 
 920     // Build reply
 921 
 922     reply_data = pcmk__xe_create(NULL, PCMK_XE_NODE);
 923     crm_xml_add(reply_data, PCMK__XA_CRM_SUBSYSTEM, CRM_SYSTEM_CRMD);
 924 
 925     // Add whether current partition has quorum
 926     pcmk__xe_set_bool_attr(reply_data, PCMK_XA_HAVE_QUORUM,
 927                            pcmk_is_set(controld_globals.flags,
 928                                        controld_has_quorum));
 929 
 930     /* Check whether client requested node info by ID and/or name
 931      *
 932      * @TODO A Corosync-layer node ID is of type uint32_t. We should be able to
 933      * handle legitimate node IDs greater than INT_MAX, but currently we do not.
 934      */
 935     crm_element_value_int(msg, PCMK_XA_ID, &node_id);
 936     if (node_id < 0) {
 937         node_id = 0;
 938     }
 939     value = crm_element_value(msg, PCMK_XA_UNAME);
 940 
 941     // Default to local node if none given
 942     if ((node_id == 0) && (value == NULL)) {
 943         value = controld_globals.our_nodename;
 944     }
 945 
 946     node = pcmk__search_node_caches(node_id, value, pcmk__node_search_any);
 947     if (node) {
 948         crm_xml_add(reply_data, PCMK_XA_ID, node->uuid);
 949         crm_xml_add(reply_data, PCMK_XA_UNAME, node->uname);
 950         crm_xml_add(reply_data, PCMK_XA_CRMD, node->state);
 951         pcmk__xe_set_bool_attr(reply_data, PCMK_XA_REMOTE_NODE,
 952                                pcmk_is_set(node->flags, crm_remote_node));
 953     }
 954 
 955     // Send reply
 956     reply = create_reply(msg, reply_data);
 957     free_xml(reply_data);
 958     if (reply != NULL) {
 959         (void) relay_message(reply, TRUE);
 960         free_xml(reply);
 961     }
 962 
 963     // Nothing further to do
 964     return I_NULL;
 965 }
 966 
 967 static void
 968 verify_feature_set(xmlNode *msg)
     /* [previous][next][first][last][top][bottom][index][help] */
 969 {
 970     const char *dc_version = crm_element_value(msg, PCMK_XA_CRM_FEATURE_SET);
 971 
 972     if (dc_version == NULL) {
 973         /* All we really know is that the DC feature set is older than 3.1.0,
 974          * but that's also all that really matters.
 975          */
 976         dc_version = "3.0.14";
 977     }
 978 
 979     if (feature_set_compatible(dc_version, CRM_FEATURE_SET)) {
 980         crm_trace("Local feature set (%s) is compatible with DC's (%s)",
 981                   CRM_FEATURE_SET, dc_version);
 982     } else {
 983         crm_err("Local feature set (%s) is incompatible with DC's (%s)",
 984                 CRM_FEATURE_SET, dc_version);
 985 
 986         // Nothing is likely to improve without administrator involvement
 987         controld_set_fsa_input_flags(R_STAYDOWN);
 988         crmd_exit(CRM_EX_FATAL);
 989     }
 990 }
 991 
 992 // DC gets own shutdown all-clear
 993 static enum crmd_fsa_input
 994 handle_shutdown_self_ack(xmlNode *stored_msg)
     /* [previous][next][first][last][top][bottom][index][help] */
 995 {
 996     const char *host_from = crm_element_value(stored_msg, PCMK__XA_SRC);
 997 
 998     if (pcmk_is_set(controld_globals.fsa_input_register, R_SHUTDOWN)) {
 999         // The expected case -- we initiated own shutdown sequence
1000         crm_info("Shutting down controller");
1001         return I_STOP;
1002     }
1003 
1004     if (pcmk__str_eq(host_from, controld_globals.dc_name, pcmk__str_casei)) {
1005         // Must be logic error -- DC confirming its own unrequested shutdown
1006         crm_err("Shutting down controller immediately due to "
1007                 "unexpected shutdown confirmation");
1008         return I_TERMINATE;
1009     }
1010 
1011     if (controld_globals.fsa_state != S_STOPPING) {
1012         // Shouldn't happen -- non-DC confirming unrequested shutdown
1013         crm_err("Starting new DC election because %s is "
1014                 "confirming shutdown we did not request",
1015                 (host_from? host_from : "another node"));
1016         return I_ELECTION;
1017     }
1018 
1019     // Shouldn't happen, but we are already stopping anyway
1020     crm_debug("Ignoring unexpected shutdown confirmation from %s",
1021               (host_from? host_from : "another node"));
1022     return I_NULL;
1023 }
1024 
1025 // Non-DC gets shutdown all-clear from DC
1026 static enum crmd_fsa_input
1027 handle_shutdown_ack(xmlNode *stored_msg)
     /* [previous][next][first][last][top][bottom][index][help] */
1028 {
1029     const char *host_from = crm_element_value(stored_msg, PCMK__XA_SRC);
1030 
1031     if (host_from == NULL) {
1032         crm_warn("Ignoring shutdown request without origin specified");
1033         return I_NULL;
1034     }
1035 
1036     if (pcmk__str_eq(host_from, controld_globals.dc_name,
1037                      pcmk__str_null_matches|pcmk__str_casei)) {
1038 
1039         if (pcmk_is_set(controld_globals.fsa_input_register, R_SHUTDOWN)) {
1040             crm_info("Shutting down controller after confirmation from %s",
1041                      host_from);
1042         } else {
1043             crm_err("Shutting down controller after unexpected "
1044                     "shutdown request from %s", host_from);
1045             controld_set_fsa_input_flags(R_STAYDOWN);
1046         }
1047         return I_STOP;
1048     }
1049 
1050     crm_warn("Ignoring shutdown request from %s because DC is %s",
1051              host_from, controld_globals.dc_name);
1052     return I_NULL;
1053 }
1054 
1055 static enum crmd_fsa_input
1056 handle_request(xmlNode *stored_msg, enum crmd_fsa_cause cause)
     /* [previous][next][first][last][top][bottom][index][help] */
1057 {
1058     xmlNode *msg = NULL;
1059     const char *op = crm_element_value(stored_msg, PCMK__XA_CRM_TASK);
1060 
1061     /* Optimize this for the DC - it has the most to do */
1062 
1063     crm_log_xml_trace(stored_msg, "request");
1064     if (op == NULL) {
1065         crm_warn("Ignoring request without " PCMK__XA_CRM_TASK);
1066         return I_NULL;
1067     }
1068 
1069     if (strcmp(op, CRM_OP_SHUTDOWN_REQ) == 0) {
1070         const char *from = crm_element_value(stored_msg, PCMK__XA_SRC);
1071         crm_node_t *node =
1072             pcmk__search_node_caches(0, from, pcmk__node_search_cluster_member);
1073 
1074         pcmk__update_peer_expected(__func__, node, CRMD_JOINSTATE_DOWN);
1075         if(AM_I_DC == FALSE) {
1076             return I_NULL; /* Done */
1077         }
1078     }
1079 
1080     /*========== DC-Only Actions ==========*/
1081     if (AM_I_DC) {
1082         if (strcmp(op, CRM_OP_JOIN_ANNOUNCE) == 0) {
1083             return I_NODE_JOIN;
1084 
1085         } else if (strcmp(op, CRM_OP_JOIN_REQUEST) == 0) {
1086             return I_JOIN_REQUEST;
1087 
1088         } else if (strcmp(op, CRM_OP_JOIN_CONFIRM) == 0) {
1089             return I_JOIN_RESULT;
1090 
1091         } else if (strcmp(op, CRM_OP_SHUTDOWN) == 0) {
1092             return handle_shutdown_self_ack(stored_msg);
1093 
1094         } else if (strcmp(op, CRM_OP_SHUTDOWN_REQ) == 0) {
1095             // Another controller wants to shut down its node
1096             return handle_shutdown_request(stored_msg);
1097         }
1098     }
1099 
1100     /*========== common actions ==========*/
1101     if (strcmp(op, CRM_OP_NOVOTE) == 0) {
1102         ha_msg_input_t fsa_input;
1103 
1104         fsa_input.msg = stored_msg;
1105         register_fsa_input_adv(C_HA_MESSAGE, I_NULL, &fsa_input,
1106                                A_ELECTION_COUNT | A_ELECTION_CHECK, FALSE,
1107                                __func__);
1108 
1109     } else if (strcmp(op, CRM_OP_REMOTE_STATE) == 0) {
1110         /* a remote connection host is letting us know the node state */
1111         return handle_remote_state(stored_msg);
1112 
1113     } else if (strcmp(op, CRM_OP_THROTTLE) == 0) {
1114         throttle_update(stored_msg);
1115         if (AM_I_DC && (controld_globals.transition_graph != NULL)
1116             && !controld_globals.transition_graph->complete) {
1117 
1118             crm_debug("The throttle changed. Trigger a graph.");
1119             trigger_graph();
1120         }
1121         return I_NULL;
1122 
1123     } else if (strcmp(op, CRM_OP_CLEAR_FAILCOUNT) == 0) {
1124         return handle_failcount_op(stored_msg);
1125 
1126     } else if (strcmp(op, CRM_OP_VOTE) == 0) {
1127         /* count the vote and decide what to do after that */
1128         ha_msg_input_t fsa_input;
1129 
1130         fsa_input.msg = stored_msg;
1131         register_fsa_input_adv(C_HA_MESSAGE, I_NULL, &fsa_input,
1132                                A_ELECTION_COUNT | A_ELECTION_CHECK, FALSE,
1133                                __func__);
1134 
1135         /* Sometimes we _must_ go into S_ELECTION */
1136         if (controld_globals.fsa_state == S_HALT) {
1137             crm_debug("Forcing an election from S_HALT");
1138             return I_ELECTION;
1139         }
1140 
1141     } else if (strcmp(op, CRM_OP_JOIN_OFFER) == 0) {
1142         verify_feature_set(stored_msg);
1143         crm_debug("Raising I_JOIN_OFFER: join-%s",
1144                   crm_element_value(stored_msg, PCMK__XA_JOIN_ID));
1145         return I_JOIN_OFFER;
1146 
1147     } else if (strcmp(op, CRM_OP_JOIN_ACKNAK) == 0) {
1148         crm_debug("Raising I_JOIN_RESULT: join-%s",
1149                   crm_element_value(stored_msg, PCMK__XA_JOIN_ID));
1150         return I_JOIN_RESULT;
1151 
1152     } else if (strcmp(op, CRM_OP_LRM_DELETE) == 0) {
1153         return handle_lrm_delete(stored_msg);
1154 
1155     } else if ((strcmp(op, CRM_OP_LRM_FAIL) == 0)
1156                || (strcmp(op, CRM_OP_LRM_REFRESH) == 0) // @COMPAT
1157                || (strcmp(op, CRM_OP_REPROBE) == 0)) {
1158 
1159         crm_xml_add(stored_msg, PCMK__XA_CRM_SYS_TO, CRM_SYSTEM_LRMD);
1160         return I_ROUTER;
1161 
1162     } else if (strcmp(op, CRM_OP_NOOP) == 0) {
1163         return I_NULL;
1164 
1165     } else if (strcmp(op, CRM_OP_PING) == 0) {
1166         return handle_ping(stored_msg);
1167 
1168     } else if (strcmp(op, CRM_OP_NODE_INFO) == 0) {
1169         return handle_node_info_request(stored_msg);
1170 
1171     } else if (strcmp(op, CRM_OP_RM_NODE_CACHE) == 0) {
1172         int id = 0;
1173         const char *name = NULL;
1174 
1175         crm_element_value_int(stored_msg, PCMK_XA_ID, &id);
1176         name = crm_element_value(stored_msg, PCMK_XA_UNAME);
1177 
1178         if(cause == C_IPC_MESSAGE) {
1179             msg = create_request(CRM_OP_RM_NODE_CACHE, NULL, NULL, CRM_SYSTEM_CRMD, CRM_SYSTEM_CRMD, NULL);
1180             if (!pcmk__cluster_send_message(NULL, crm_msg_crmd, msg)) {
1181                 crm_err("Could not instruct peers to remove references to node %s/%u", name, id);
1182             } else {
1183                 crm_notice("Instructing peers to remove references to node %s/%u", name, id);
1184             }
1185             free_xml(msg);
1186 
1187         } else {
1188             pcmk__cluster_forget_cluster_node(id, name);
1189 
1190             /* If we're forgetting this node, also forget any failures to fence
1191              * it, so we don't carry that over to any node added later with the
1192              * same name.
1193              */
1194             st_fail_count_reset(name);
1195         }
1196 
1197     } else if (strcmp(op, CRM_OP_MAINTENANCE_NODES) == 0) {
1198         xmlNode *wrapper = pcmk__xe_first_child(stored_msg, PCMK__XE_CRM_XML,
1199                                                 NULL, NULL);
1200         xmlNode *xml = pcmk__xe_first_child(wrapper, NULL, NULL, NULL);
1201 
1202         remote_ra_process_maintenance_nodes(xml);
1203 
1204     } else if (strcmp(op, PCMK__CONTROLD_CMD_NODES) == 0) {
1205         return handle_node_list(stored_msg);
1206 
1207         /*========== (NOT_DC)-Only Actions ==========*/
1208     } else if (!AM_I_DC) {
1209 
1210         if (strcmp(op, CRM_OP_SHUTDOWN) == 0) {
1211             return handle_shutdown_ack(stored_msg);
1212         }
1213 
1214     } else {
1215         crm_err("Unexpected request (%s) sent to %s", op, AM_I_DC ? "the DC" : "non-DC node");
1216         crm_log_xml_err(stored_msg, "Unexpected");
1217     }
1218 
1219     return I_NULL;
1220 }
1221 
1222 static void
1223 handle_response(xmlNode *stored_msg)
     /* [previous][next][first][last][top][bottom][index][help] */
1224 {
1225     const char *op = crm_element_value(stored_msg, PCMK__XA_CRM_TASK);
1226 
1227     crm_log_xml_trace(stored_msg, "reply");
1228     if (op == NULL) {
1229         crm_warn("Ignoring reply without " PCMK__XA_CRM_TASK);
1230 
1231     } else if (AM_I_DC && strcmp(op, CRM_OP_PECALC) == 0) {
1232         // Check whether scheduler answer been superseded by subsequent request
1233         const char *msg_ref = crm_element_value(stored_msg, PCMK_XA_REFERENCE);
1234 
1235         if (msg_ref == NULL) {
1236             crm_err("%s - Ignoring calculation with no reference", op);
1237 
1238         } else if (pcmk__str_eq(msg_ref, controld_globals.fsa_pe_ref,
1239                                 pcmk__str_none)) {
1240             ha_msg_input_t fsa_input;
1241 
1242             controld_stop_sched_timer();
1243             fsa_input.msg = stored_msg;
1244             register_fsa_input_later(C_IPC_MESSAGE, I_PE_SUCCESS, &fsa_input);
1245 
1246         } else {
1247             crm_info("%s calculation %s is obsolete", op, msg_ref);
1248         }
1249 
1250     } else if (strcmp(op, CRM_OP_VOTE) == 0
1251                || strcmp(op, CRM_OP_SHUTDOWN_REQ) == 0 || strcmp(op, CRM_OP_SHUTDOWN) == 0) {
1252 
1253     } else {
1254         const char *host_from = crm_element_value(stored_msg, PCMK__XA_SRC);
1255 
1256         crm_err("Unexpected response (op=%s, src=%s) sent to the %s",
1257                 op, host_from, AM_I_DC ? "DC" : "controller");
1258     }
1259 }
1260 
1261 static enum crmd_fsa_input
1262 handle_shutdown_request(xmlNode * stored_msg)
     /* [previous][next][first][last][top][bottom][index][help] */
1263 {
1264     /* handle here to avoid potential version issues
1265      *   where the shutdown message/procedure may have
1266      *   been changed in later versions.
1267      *
1268      * This way the DC is always in control of the shutdown
1269      */
1270 
1271     char *now_s = NULL;
1272     const char *host_from = crm_element_value(stored_msg, PCMK__XA_SRC);
1273 
1274     if (host_from == NULL) {
1275         /* we're shutting down and the DC */
1276         host_from = controld_globals.our_nodename;
1277     }
1278 
1279     crm_info("Creating shutdown request for %s (state=%s)", host_from,
1280              fsa_state2string(controld_globals.fsa_state));
1281     crm_log_xml_trace(stored_msg, "message");
1282 
1283     now_s = pcmk__ttoa(time(NULL));
1284     update_attrd(host_from, PCMK__NODE_ATTR_SHUTDOWN, now_s, NULL, FALSE);
1285     free(now_s);
1286 
1287     /* will be picked up by the TE as long as its running */
1288     return I_NULL;
1289 }
1290 
1291 static void
1292 send_msg_via_ipc(xmlNode * msg, const char *sys, const char *src)
     /* [previous][next][first][last][top][bottom][index][help] */
1293 {
1294     pcmk__client_t *client_channel = NULL;
1295 
1296     CRM_CHECK(sys != NULL, return);
1297 
1298     client_channel = pcmk__find_client_by_id(sys);
1299 
1300     if (crm_element_value(msg, PCMK__XA_SRC) == NULL) {
1301         crm_xml_add(msg, PCMK__XA_SRC, src);
1302     }
1303 
1304     if (client_channel != NULL) {
1305         /* Transient clients such as crmadmin */
1306         pcmk__ipc_send_xml(client_channel, 0, msg, crm_ipc_server_event);
1307 
1308     } else if (pcmk__str_eq(sys, CRM_SYSTEM_TENGINE, pcmk__str_none)) {
1309         xmlNode *wrapper = pcmk__xe_first_child(msg, PCMK__XE_CRM_XML, NULL,
1310                                                 NULL);
1311         xmlNode *data = pcmk__xe_first_child(wrapper, NULL, NULL, NULL);
1312 
1313         process_te_message(msg, data);
1314 
1315     } else if (pcmk__str_eq(sys, CRM_SYSTEM_LRMD, pcmk__str_none)) {
1316         fsa_data_t fsa_data;
1317         ha_msg_input_t fsa_input;
1318         xmlNode *wrapper = NULL;
1319 
1320         fsa_input.msg = msg;
1321 
1322         wrapper = pcmk__xe_first_child(msg, PCMK__XE_CRM_XML, NULL, NULL);
1323         fsa_input.xml = pcmk__xe_first_child(wrapper, NULL, NULL, NULL);
1324 
1325         fsa_data.id = 0;
1326         fsa_data.actions = 0;
1327         fsa_data.data = &fsa_input;
1328         fsa_data.fsa_input = I_MESSAGE;
1329         fsa_data.fsa_cause = C_IPC_MESSAGE;
1330         fsa_data.origin = __func__;
1331         fsa_data.data_type = fsa_dt_ha_msg;
1332 
1333         do_lrm_invoke(A_LRM_INVOKE, C_IPC_MESSAGE, controld_globals.fsa_state,
1334                       I_MESSAGE, &fsa_data);
1335 
1336     } else if (crmd_is_proxy_session(sys)) {
1337         crmd_proxy_send(sys, msg);
1338 
1339     } else {
1340         crm_info("Received invalid request: unknown subsystem '%s'", sys);
1341     }
1342 }
1343 
1344 void
1345 delete_ha_msg_input(ha_msg_input_t * orig)
     /* [previous][next][first][last][top][bottom][index][help] */
1346 {
1347     if (orig == NULL) {
1348         return;
1349     }
1350     free_xml(orig->msg);
1351     free(orig);
1352 }
1353 
1354 /*!
1355  * \internal
1356  * \brief Notify the cluster of a remote node state change
1357  *
1358  * \param[in] node_name  Node's name
1359  * \param[in] node_up    true if node is up, false if down
1360  */
1361 void
1362 broadcast_remote_state_message(const char *node_name, bool node_up)
     /* [previous][next][first][last][top][bottom][index][help] */
1363 {
1364     xmlNode *msg = create_request(CRM_OP_REMOTE_STATE, NULL, NULL,
1365                                   CRM_SYSTEM_CRMD, CRM_SYSTEM_CRMD, NULL);
1366 
1367     crm_info("Notifying cluster of Pacemaker Remote node %s %s",
1368              node_name, node_up? "coming up" : "going down");
1369 
1370     crm_xml_add(msg, PCMK_XA_ID, node_name);
1371     pcmk__xe_set_bool_attr(msg, PCMK__XA_IN_CCM, node_up);
1372 
1373     if (node_up) {
1374         crm_xml_add(msg, PCMK__XA_CONNECTION_HOST,
1375                     controld_globals.our_nodename);
1376     }
1377 
1378     pcmk__cluster_send_message(NULL, crm_msg_crmd, msg);
1379     free_xml(msg);
1380 }
1381 

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