root/daemons/controld/controld_control.c

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

DEFINITIONS

This source file includes following definitions.
  1. do_ha_control
  2. do_shutdown
  3. do_shutdown_req
  4. crmd_fast_exit
  5. crmd_exit
  6. do_exit
  7. sigpipe_ignore
  8. do_startup
  9. accept_controller_client
  10. dispatch_controller_ipc
  11. crmd_ipc_closed
  12. crmd_ipc_destroy
  13. do_stop
  14. do_started
  15. do_recover
  16. crmd_metadata
  17. verify_crmd_options
  18. crmd_pref
  19. config_query_callback
  20. crm_read_options
  21. do_read_config
  22. crm_shutdown

   1 /*
   2  * Copyright 2004-2021 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 <sys/types.h>
  14 #include <sys/stat.h>
  15 
  16 #include <crm/crm.h>
  17 #include <crm/msg_xml.h>
  18 #include <crm/pengine/rules.h>
  19 #include <crm/cluster/internal.h>
  20 #include <crm/cluster/election_internal.h>
  21 #include <crm/common/ipc_internal.h>
  22 
  23 #include <pacemaker-controld.h>
  24 
  25 qb_ipcs_service_t *ipcs = NULL;
  26 
  27 #if SUPPORT_COROSYNC
  28 extern gboolean crm_connect_corosync(crm_cluster_t * cluster);
  29 #endif
  30 
  31 void crm_shutdown(int nsig);
  32 gboolean crm_read_options(gpointer user_data);
  33 
  34 gboolean fsa_has_quorum = FALSE;
  35 crm_trigger_t *fsa_source = NULL;
  36 crm_trigger_t *config_read = NULL;
  37 bool no_quorum_suicide_escalation = FALSE;
  38 bool controld_shutdown_lock_enabled = false;
  39 
  40 /*       A_HA_CONNECT   */
  41 void
  42 do_ha_control(long long action,
     /* [previous][next][first][last][top][bottom][index][help] */
  43               enum crmd_fsa_cause cause,
  44               enum crmd_fsa_state cur_state,
  45               enum crmd_fsa_input current_input, fsa_data_t * msg_data)
  46 {
  47     gboolean registered = FALSE;
  48     static crm_cluster_t *cluster = NULL;
  49 
  50     if (cluster == NULL) {
  51         cluster = calloc(1, sizeof(crm_cluster_t));
  52     }
  53 
  54     if (action & A_HA_DISCONNECT) {
  55         crm_cluster_disconnect(cluster);
  56         crm_info("Disconnected from the cluster");
  57 
  58         controld_set_fsa_input_flags(R_HA_DISCONNECTED);
  59     }
  60 
  61     if (action & A_HA_CONNECT) {
  62         crm_set_status_callback(&peer_update_callback);
  63         crm_set_autoreap(FALSE);
  64 
  65         if (is_corosync_cluster()) {
  66 #if SUPPORT_COROSYNC
  67             registered = crm_connect_corosync(cluster);
  68 #endif
  69         }
  70 
  71         if (registered == TRUE) {
  72             controld_election_init(cluster->uname);
  73             fsa_our_uname = cluster->uname;
  74             fsa_our_uuid = cluster->uuid;
  75             if(cluster->uuid == NULL) {
  76                 crm_err("Could not obtain local uuid");
  77                 registered = FALSE;
  78             }
  79         }
  80 
  81         if (registered == FALSE) {
  82             controld_set_fsa_input_flags(R_HA_DISCONNECTED);
  83             register_fsa_error(C_FSA_INTERNAL, I_ERROR, NULL);
  84             return;
  85         }
  86 
  87         populate_cib_nodes(node_update_none, __func__);
  88         controld_clear_fsa_input_flags(R_HA_DISCONNECTED);
  89         crm_info("Connected to the cluster");
  90     }
  91 
  92     if (action & ~(A_HA_CONNECT | A_HA_DISCONNECT)) {
  93         crm_err("Unexpected action %s in %s", fsa_action2string(action),
  94                 __func__);
  95     }
  96 }
  97 
  98 /*       A_SHUTDOWN     */
  99 void
 100 do_shutdown(long long action,
     /* [previous][next][first][last][top][bottom][index][help] */
 101             enum crmd_fsa_cause cause,
 102             enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t * msg_data)
 103 {
 104     /* just in case */
 105     controld_set_fsa_input_flags(R_SHUTDOWN);
 106     controld_disconnect_fencer(FALSE);
 107 }
 108 
 109 /*       A_SHUTDOWN_REQ */
 110 void
 111 do_shutdown_req(long long action,
     /* [previous][next][first][last][top][bottom][index][help] */
 112                 enum crmd_fsa_cause cause,
 113                 enum crmd_fsa_state cur_state,
 114                 enum crmd_fsa_input current_input, fsa_data_t * msg_data)
 115 {
 116     xmlNode *msg = NULL;
 117 
 118     controld_set_fsa_input_flags(R_SHUTDOWN);
 119     //controld_set_fsa_input_flags(R_STAYDOWN);
 120     crm_info("Sending shutdown request to all peers (DC is %s)",
 121              (fsa_our_dc? fsa_our_dc : "not set"));
 122     msg = create_request(CRM_OP_SHUTDOWN_REQ, NULL, NULL, CRM_SYSTEM_CRMD, CRM_SYSTEM_CRMD, NULL);
 123 
 124     if (send_cluster_message(NULL, crm_msg_crmd, msg, TRUE) == FALSE) {
 125         register_fsa_error(C_FSA_INTERNAL, I_ERROR, NULL);
 126     }
 127     free_xml(msg);
 128 }
 129 
 130 extern char *max_generation_from;
 131 extern xmlNode *max_generation_xml;
 132 extern GHashTable *resource_history;
 133 extern GHashTable *voted;
 134 
 135 void
 136 crmd_fast_exit(crm_exit_t exit_code)
     /* [previous][next][first][last][top][bottom][index][help] */
 137 {
 138     if (pcmk_is_set(fsa_input_register, R_STAYDOWN)) {
 139         crm_warn("Inhibiting respawn "CRM_XS" remapping exit code %d to %d",
 140                  exit_code, CRM_EX_FATAL);
 141         exit_code = CRM_EX_FATAL;
 142 
 143     } else if ((exit_code == CRM_EX_OK)
 144                && pcmk_is_set(fsa_input_register, R_IN_RECOVERY)) {
 145         crm_err("Could not recover from internal error");
 146         exit_code = CRM_EX_ERROR;
 147     }
 148     crm_exit(exit_code);
 149 }
 150 
 151 crm_exit_t
 152 crmd_exit(crm_exit_t exit_code)
     /* [previous][next][first][last][top][bottom][index][help] */
 153 {
 154     GList *gIter = NULL;
 155     GMainLoop *mloop = crmd_mainloop;
 156 
 157     static bool in_progress = FALSE;
 158 
 159     if (in_progress && (exit_code == CRM_EX_OK)) {
 160         crm_debug("Exit is already in progress");
 161         return exit_code;
 162 
 163     } else if(in_progress) {
 164         crm_notice("Error during shutdown process, exiting now with status %d (%s)",
 165                    exit_code, crm_exit_str(exit_code));
 166         crm_write_blackbox(SIGTRAP, NULL);
 167         crmd_fast_exit(exit_code);
 168     }
 169 
 170     in_progress = TRUE;
 171     crm_trace("Preparing to exit with status %d (%s)",
 172               exit_code, crm_exit_str(exit_code));
 173 
 174     /* Suppress secondary errors resulting from us disconnecting everything */
 175     controld_set_fsa_input_flags(R_HA_DISCONNECTED);
 176 
 177 /* Close all IPC servers and clients to ensure any and all shared memory files are cleaned up */
 178 
 179     if(ipcs) {
 180         crm_trace("Closing IPC server");
 181         mainloop_del_ipc_server(ipcs);
 182         ipcs = NULL;
 183     }
 184 
 185     controld_close_attrd_ipc();
 186     pe_subsystem_free();
 187     controld_disconnect_fencer(TRUE);
 188 
 189     if ((exit_code == CRM_EX_OK) && (crmd_mainloop == NULL)) {
 190         crm_debug("No mainloop detected");
 191         exit_code = CRM_EX_ERROR;
 192     }
 193 
 194     /* On an error, just get out.
 195      *
 196      * Otherwise, make the effort to have mainloop exit gracefully so
 197      * that it (mostly) cleans up after itself and valgrind has less
 198      * to report on - allowing real errors stand out
 199      */
 200     if (exit_code != CRM_EX_OK) {
 201         crm_notice("Forcing immediate exit with status %d (%s)",
 202                    exit_code, crm_exit_str(exit_code));
 203         crm_write_blackbox(SIGTRAP, NULL);
 204         crmd_fast_exit(exit_code);
 205     }
 206 
 207 /* Clean up as much memory as possible for valgrind */
 208 
 209     for (gIter = fsa_message_queue; gIter != NULL; gIter = gIter->next) {
 210         fsa_data_t *fsa_data = gIter->data;
 211 
 212         crm_info("Dropping %s: [ state=%s cause=%s origin=%s ]",
 213                  fsa_input2string(fsa_data->fsa_input),
 214                  fsa_state2string(fsa_state),
 215                  fsa_cause2string(fsa_data->fsa_cause), fsa_data->origin);
 216         delete_fsa_input(fsa_data);
 217     }
 218 
 219     controld_clear_fsa_input_flags(R_MEMBERSHIP);
 220     g_list_free(fsa_message_queue); fsa_message_queue = NULL;
 221 
 222     metadata_cache_fini();
 223     controld_election_fini();
 224 
 225     /* Tear down the CIB manager connection, but don't free it yet -- it could
 226      * be used when we drain the mainloop later.
 227      */
 228 
 229     controld_disconnect_cib_manager();
 230 
 231     verify_stopped(fsa_state, LOG_WARNING);
 232     controld_clear_fsa_input_flags(R_LRM_CONNECTED);
 233     lrm_state_destroy_all();
 234 
 235     /* This basically will not work, since mainloop has a reference to it */
 236     mainloop_destroy_trigger(fsa_source); fsa_source = NULL;
 237 
 238     mainloop_destroy_trigger(config_read); config_read = NULL;
 239     mainloop_destroy_trigger(transition_trigger); transition_trigger = NULL;
 240 
 241     pcmk__client_cleanup();
 242     crm_peer_destroy();
 243 
 244     controld_free_fsa_timers();
 245     te_cleanup_stonith_history_sync(NULL, TRUE);
 246     controld_free_sched_timer();
 247 
 248     free(fsa_our_dc_version); fsa_our_dc_version = NULL;
 249     free(fsa_our_uname); fsa_our_uname = NULL;
 250     free(fsa_our_uuid); fsa_our_uuid = NULL;
 251     free(fsa_our_dc); fsa_our_dc = NULL;
 252 
 253     free(fsa_cluster_name); fsa_cluster_name = NULL;
 254 
 255     free(te_uuid); te_uuid = NULL;
 256     free(failed_stop_offset); failed_stop_offset = NULL;
 257     free(failed_start_offset); failed_start_offset = NULL;
 258 
 259     free(max_generation_from); max_generation_from = NULL;
 260     free_xml(max_generation_xml); max_generation_xml = NULL;
 261 
 262     mainloop_destroy_signal(SIGPIPE);
 263     mainloop_destroy_signal(SIGUSR1);
 264     mainloop_destroy_signal(SIGTERM);
 265     mainloop_destroy_signal(SIGTRAP);
 266     /* leave SIGCHLD engaged as we might still want to drain some service-actions */
 267 
 268     if (mloop) {
 269         GMainContext *ctx = g_main_loop_get_context(crmd_mainloop);
 270 
 271         /* Don't re-enter this block */
 272         crmd_mainloop = NULL;
 273 
 274         /* no signals on final draining anymore */
 275         mainloop_destroy_signal(SIGCHLD);
 276 
 277         crm_trace("Draining mainloop %d %d", g_main_loop_is_running(mloop), g_main_context_pending(ctx));
 278 
 279         {
 280             int lpc = 0;
 281 
 282             while((g_main_context_pending(ctx) && lpc < 10)) {
 283                 lpc++;
 284                 crm_trace("Iteration %d", lpc);
 285                 g_main_context_dispatch(ctx);
 286             }
 287         }
 288 
 289         crm_trace("Closing mainloop %d %d", g_main_loop_is_running(mloop), g_main_context_pending(ctx));
 290         g_main_loop_quit(mloop);
 291 
 292         /* Won't do anything yet, since we're inside it now */
 293         g_main_loop_unref(mloop);
 294     } else {
 295         mainloop_destroy_signal(SIGCHLD);
 296     }
 297 
 298     cib_delete(fsa_cib_conn);
 299     fsa_cib_conn = NULL;
 300 
 301     throttle_fini();
 302 
 303     /* Graceful */
 304     crm_trace("Done preparing for exit with status %d (%s)",
 305               exit_code, crm_exit_str(exit_code));
 306     return exit_code;
 307 }
 308 
 309 /*       A_EXIT_0, A_EXIT_1     */
 310 void
 311 do_exit(long long action,
     /* [previous][next][first][last][top][bottom][index][help] */
 312         enum crmd_fsa_cause cause,
 313         enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t * msg_data)
 314 {
 315     crm_exit_t exit_code = CRM_EX_OK;
 316     int log_level = LOG_INFO;
 317     const char *exit_type = "gracefully";
 318 
 319     if (action & A_EXIT_1) {
 320         log_level = LOG_ERR;
 321         exit_type = "forcefully";
 322         exit_code = CRM_EX_ERROR;
 323     }
 324 
 325     verify_stopped(cur_state, LOG_ERR);
 326     do_crm_log(log_level, "Performing %s - %s exiting the controller",
 327                fsa_action2string(action), exit_type);
 328 
 329     crm_info("[%s] stopped (%d)", crm_system_name, exit_code);
 330     crmd_exit(exit_code);
 331 }
 332 
 333 static void sigpipe_ignore(int nsig) { return; }
     /* [previous][next][first][last][top][bottom][index][help] */
 334 
 335 /*       A_STARTUP      */
 336 void
 337 do_startup(long long action,
     /* [previous][next][first][last][top][bottom][index][help] */
 338            enum crmd_fsa_cause cause,
 339            enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t * msg_data)
 340 {
 341     crm_debug("Registering Signal Handlers");
 342     mainloop_add_signal(SIGTERM, crm_shutdown);
 343     mainloop_add_signal(SIGPIPE, sigpipe_ignore);
 344 
 345     fsa_source = mainloop_add_trigger(G_PRIORITY_HIGH, crm_fsa_trigger, NULL);
 346     config_read = mainloop_add_trigger(G_PRIORITY_HIGH, crm_read_options, NULL);
 347     transition_trigger = mainloop_add_trigger(G_PRIORITY_LOW, te_graph_trigger, NULL);
 348 
 349     crm_debug("Creating CIB manager and executor objects");
 350     fsa_cib_conn = cib_new();
 351 
 352     lrm_state_init_local();
 353     if (controld_init_fsa_timers() == FALSE) {
 354         register_fsa_error(C_FSA_INTERNAL, I_ERROR, NULL);
 355     }
 356 }
 357 
 358 // \return libqb error code (0 on success, -errno on error)
 359 static int32_t
 360 accept_controller_client(qb_ipcs_connection_t *c, uid_t uid, gid_t gid)
     /* [previous][next][first][last][top][bottom][index][help] */
 361 {
 362     crm_trace("Accepting new IPC client connection");
 363     if (pcmk__new_client(c, uid, gid) == NULL) {
 364         return -EIO;
 365     }
 366     return 0;
 367 }
 368 
 369 // \return libqb error code (0 on success, -errno on error)
 370 static int32_t
 371 dispatch_controller_ipc(qb_ipcs_connection_t * c, void *data, size_t size)
     /* [previous][next][first][last][top][bottom][index][help] */
 372 {
 373     uint32_t id = 0;
 374     uint32_t flags = 0;
 375     pcmk__client_t *client = pcmk__find_client(c);
 376 
 377     xmlNode *msg = pcmk__client_data2xml(client, data, &id, &flags);
 378 
 379     if (msg == NULL) {
 380         pcmk__ipc_send_ack(client, id, flags, "ack", CRM_EX_PROTOCOL);
 381         return 0;
 382     }
 383     pcmk__ipc_send_ack(client, id, flags, "ack", CRM_EX_INDETERMINATE);
 384 
 385     CRM_ASSERT(client->user != NULL);
 386     pcmk__update_acl_user(msg, F_CRM_USER, client->user);
 387 
 388     crm_xml_add(msg, F_CRM_SYS_FROM, client->id);
 389     if (controld_authorize_ipc_message(msg, client, NULL)) {
 390         crm_trace("Processing IPC message from client %s",
 391                   pcmk__client_name(client));
 392         route_message(C_IPC_MESSAGE, msg);
 393     }
 394 
 395     trigger_fsa();
 396     free_xml(msg);
 397     return 0;
 398 }
 399 
 400 static int32_t
 401 crmd_ipc_closed(qb_ipcs_connection_t * c)
     /* [previous][next][first][last][top][bottom][index][help] */
 402 {
 403     pcmk__client_t *client = pcmk__find_client(c);
 404 
 405     if (client) {
 406         crm_trace("Disconnecting %sregistered client %s (%p/%p)",
 407                   (client->userdata? "" : "un"), pcmk__client_name(client),
 408                   c, client);
 409         free(client->userdata);
 410         pcmk__free_client(client);
 411         trigger_fsa();
 412     }
 413     return 0;
 414 }
 415 
 416 static void
 417 crmd_ipc_destroy(qb_ipcs_connection_t * c)
     /* [previous][next][first][last][top][bottom][index][help] */
 418 {
 419     crm_trace("Connection %p", c);
 420     crmd_ipc_closed(c);
 421 }
 422 
 423 /*       A_STOP */
 424 void
 425 do_stop(long long action,
     /* [previous][next][first][last][top][bottom][index][help] */
 426         enum crmd_fsa_cause cause,
 427         enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t * msg_data)
 428 {
 429     crm_trace("Closing IPC server");
 430     mainloop_del_ipc_server(ipcs); ipcs = NULL;
 431     register_fsa_input(C_FSA_INTERNAL, I_TERMINATE, NULL);
 432 }
 433 
 434 /*       A_STARTED      */
 435 void
 436 do_started(long long action,
     /* [previous][next][first][last][top][bottom][index][help] */
 437            enum crmd_fsa_cause cause,
 438            enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t * msg_data)
 439 {
 440     static struct qb_ipcs_service_handlers crmd_callbacks = {
 441         .connection_accept = accept_controller_client,
 442         .connection_created = NULL,
 443         .msg_process = dispatch_controller_ipc,
 444         .connection_closed = crmd_ipc_closed,
 445         .connection_destroyed = crmd_ipc_destroy
 446     };
 447 
 448     if (cur_state != S_STARTING) {
 449         crm_err("Start cancelled... %s", fsa_state2string(cur_state));
 450         return;
 451 
 452     } else if (!pcmk_is_set(fsa_input_register, R_MEMBERSHIP)) {
 453         crm_info("Delaying start, no membership data (%.16llx)", R_MEMBERSHIP);
 454 
 455         crmd_fsa_stall(TRUE);
 456         return;
 457 
 458     } else if (!pcmk_is_set(fsa_input_register, R_LRM_CONNECTED)) {
 459         crm_info("Delaying start, not connected to executor (%.16llx)", R_LRM_CONNECTED);
 460 
 461         crmd_fsa_stall(TRUE);
 462         return;
 463 
 464     } else if (!pcmk_is_set(fsa_input_register, R_CIB_CONNECTED)) {
 465         crm_info("Delaying start, CIB not connected (%.16llx)", R_CIB_CONNECTED);
 466 
 467         crmd_fsa_stall(TRUE);
 468         return;
 469 
 470     } else if (!pcmk_is_set(fsa_input_register, R_READ_CONFIG)) {
 471         crm_info("Delaying start, Config not read (%.16llx)", R_READ_CONFIG);
 472 
 473         crmd_fsa_stall(TRUE);
 474         return;
 475 
 476     } else if (!pcmk_is_set(fsa_input_register, R_PEER_DATA)) {
 477 
 478         crm_info("Delaying start, No peer data (%.16llx)", R_PEER_DATA);
 479         crmd_fsa_stall(TRUE);
 480         return;
 481     }
 482 
 483     crm_debug("Init server comms");
 484     ipcs = pcmk__serve_controld_ipc(&crmd_callbacks);
 485     if (ipcs == NULL) {
 486         crm_err("Failed to create IPC server: shutting down and inhibiting respawn");
 487         register_fsa_error(C_FSA_INTERNAL, I_ERROR, NULL);
 488     } else {
 489         crm_notice("Pacemaker controller successfully started and accepting connections");
 490     }
 491     controld_trigger_fencer_connect();
 492 
 493     controld_clear_fsa_input_flags(R_STARTING);
 494     register_fsa_input(msg_data->fsa_cause, I_PENDING, NULL);
 495 }
 496 
 497 /*       A_RECOVER      */
 498 void
 499 do_recover(long long action,
     /* [previous][next][first][last][top][bottom][index][help] */
 500            enum crmd_fsa_cause cause,
 501            enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t * msg_data)
 502 {
 503     controld_set_fsa_input_flags(R_IN_RECOVERY);
 504     crm_warn("Fast-tracking shutdown in response to errors");
 505 
 506     register_fsa_input(C_FSA_INTERNAL, I_TERMINATE, NULL);
 507 }
 508 
 509 static pcmk__cluster_option_t crmd_opts[] = {
 510     /* name, old name, type, allowed values,
 511      * default value, validator,
 512      * short description,
 513      * long description
 514      */
 515     {
 516         "dc-version", NULL, "string", NULL, "none", NULL,
 517         "Pacemaker version on cluster node elected Designated Controller (DC)",
 518         "Includes a hash which identifies the exact changeset the code was "
 519             "built from. Used for diagnostic purposes."
 520     },
 521     {
 522         "cluster-infrastructure", NULL, "string", NULL, "corosync", NULL,
 523         "The messaging stack on which Pacemaker is currently running",
 524         "Used for informational and diagnostic purposes."
 525     },
 526     {
 527         "cluster-name", NULL, "string", NULL, NULL, NULL,
 528         "An arbitrary name for the cluster",
 529         "This optional value is mostly for users' convenience as desired "
 530             "in administration, but may also be used in Pacemaker "
 531             "configuration rules via the #cluster-name node attribute, and "
 532             "by higher-level tools and resource agents."
 533     },
 534     {
 535         XML_CONFIG_ATTR_DC_DEADTIME, NULL, "time",
 536         NULL, "20s", pcmk__valid_interval_spec,
 537         "How long to wait for a response from other nodes during start-up",
 538         "The optimal value will depend on the speed and load of your network "
 539             "and the type of switches used."
 540     },
 541     {
 542         XML_CONFIG_ATTR_RECHECK, NULL, "time",
 543         "Zero disables polling, while positive values are an interval in seconds"
 544             "(unless other units are specified, for example \"5min\")",
 545         "15min", pcmk__valid_interval_spec,
 546         "Polling interval to recheck cluster state and evaluate rules "
 547             "with date specifications",
 548         "Pacemaker is primarily event-driven, and looks ahead to know when to "
 549             "recheck cluster state for failure timeouts and most time-based "
 550             "rules. However, it will also recheck the cluster after this "
 551             "amount of inactivity, to evaluate rules with date specifications "
 552             "and serve as a fail-safe for certain types of scheduler bugs."
 553     },
 554     {
 555         "load-threshold", NULL, "percentage", NULL,
 556         "80%", pcmk__valid_utilization,
 557         "Maximum amount of system load that should be used by cluster nodes",
 558         "The cluster will slow down its recovery process when the amount of "
 559             "system resources used (currently CPU) approaches this limit",
 560     },
 561     {
 562         "node-action-limit", NULL, "integer", NULL,
 563         "0", pcmk__valid_number,
 564         "Maximum number of jobs that can be scheduled per node "
 565             "(defaults to 2x cores)"
 566     },
 567     { XML_CONFIG_ATTR_FENCE_REACTION, NULL, "string", NULL, "stop", NULL,
 568         "How a cluster node should react if notified of its own fencing",
 569         "A cluster node may receive notification of its own fencing if fencing "
 570         "is misconfigured, or if fabric fencing is in use that doesn't cut "
 571         "cluster communication. Allowed values are \"stop\" to attempt to "
 572         "immediately stop Pacemaker and stay stopped, or \"panic\" to attempt "
 573         "to immediately reboot the local node, falling back to stop on failure."
 574     },
 575     {
 576         XML_CONFIG_ATTR_ELECTION_FAIL, NULL, "time", NULL,
 577         "2min", pcmk__valid_interval_spec,
 578         "*** Advanced Use Only ***",
 579         "Declare an election failed if it is not decided within this much "
 580             "time. If you need to adjust this value, it probably indicates "
 581             "the presence of a bug."
 582     },
 583     {
 584         XML_CONFIG_ATTR_FORCE_QUIT, NULL, "time", NULL,
 585         "20min", pcmk__valid_interval_spec,
 586         "*** Advanced Use Only ***",
 587         "Exit immediately if shutdown does not complete within this much "
 588             "time. If you need to adjust this value, it probably indicates "
 589             "the presence of a bug."
 590     },
 591     {
 592         "join-integration-timeout", "crmd-integration-timeout", "time", NULL,
 593         "3min", pcmk__valid_interval_spec,
 594         "*** Advanced Use Only ***",
 595         "If you need to adjust this value, it probably indicates "
 596             "the presence of a bug."
 597     },
 598     {
 599         "join-finalization-timeout", "crmd-finalization-timeout", "time", NULL,
 600         "30min", pcmk__valid_interval_spec,
 601         "*** Advanced Use Only ***",
 602         "If you need to adjust this value, it probably indicates "
 603             "the presence of a bug."
 604     },
 605     {
 606         "transition-delay", "crmd-transition-delay", "time", NULL,
 607         "0s", pcmk__valid_interval_spec,
 608         "*** Advanced Use Only *** Enabling this option will slow down "
 609             "cluster recovery under all conditions",
 610         "Delay cluster recovery for this much time to allow for additional "
 611             "events to occur. Useful if your configuration is sensitive to "
 612             "the order in which ping updates arrive."
 613     },
 614     {
 615         "stonith-watchdog-timeout", NULL, "time", NULL,
 616         "0", controld_verify_stonith_watchdog_timeout,
 617         "How long to wait before we can assume nodes are safely down "
 618             "when watchdog-based self-fencing via SBD is in use",
 619         "If nonzero, along with `have-watchdog=true` automatically set by the "
 620             "cluster, when fencing is required, watchdog-based self-fencing "
 621             "will be performed via SBD without requiring a fencing resource "
 622             "explicitly configured. "
 623             "If `stonith-watchdog-timeout` is set to a positive value, unseen "
 624             "nodes are assumed to self-fence within this much time. +WARNING:+ "
 625             "It must be ensured that this value is larger than the "
 626             "`SBD_WATCHDOG_TIMEOUT` environment variable on all nodes. "
 627             "Pacemaker verifies the settings individually on all nodes and "
 628             "prevents startup or shuts down if configured wrongly on the fly. "
 629             "It's strongly recommended that `SBD_WATCHDOG_TIMEOUT` is set to "
 630             "the same value on all nodes. "
 631             "If `stonith-watchdog-timeout` is set to a negative value, and "
 632             "`SBD_WATCHDOG_TIMEOUT` is set, twice that value will be used. "
 633             "+WARNING:+ In this case, it's essential (currently not verified by "
 634             "Pacemaker) that `SBD_WATCHDOG_TIMEOUT` is set to the same value on "
 635             "all nodes."
 636     },
 637     {
 638         "stonith-max-attempts", NULL, "integer", NULL,
 639         "10", pcmk__valid_positive_number,
 640         "How many times fencing can fail before it will no longer be "
 641             "immediately re-attempted on a target"
 642     },
 643 
 644     // Already documented in libpe_status (other values must be kept identical)
 645     {
 646         "no-quorum-policy", NULL, "select", "stop, freeze, ignore, demote, suicide",
 647         "stop", pcmk__valid_quorum, NULL, NULL
 648     },
 649     {
 650         XML_CONFIG_ATTR_SHUTDOWN_LOCK, NULL, "boolean", NULL,
 651         "false", pcmk__valid_boolean, NULL, NULL
 652     },
 653 };
 654 
 655 void
 656 crmd_metadata(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 657 {
 658     pcmk__print_option_metadata("pacemaker-controld",
 659                                 "Pacemaker controller options",
 660                                 "Cluster options used by Pacemaker's "
 661                                     "controller (formerly called crmd)",
 662                                 crmd_opts, PCMK__NELEM(crmd_opts));
 663 }
 664 
 665 static void
 666 verify_crmd_options(GHashTable * options)
     /* [previous][next][first][last][top][bottom][index][help] */
 667 {
 668     pcmk__validate_cluster_options(options, crmd_opts, PCMK__NELEM(crmd_opts));
 669 }
 670 
 671 static const char *
 672 crmd_pref(GHashTable * options, const char *name)
     /* [previous][next][first][last][top][bottom][index][help] */
 673 {
 674     return pcmk__cluster_option(options, crmd_opts, PCMK__NELEM(crmd_opts),
 675                                 name);
 676 }
 677 
 678 static void
 679 config_query_callback(xmlNode * msg, int call_id, int rc, xmlNode * output, void *user_data)
     /* [previous][next][first][last][top][bottom][index][help] */
 680 {
 681     const char *value = NULL;
 682     GHashTable *config_hash = NULL;
 683     crm_time_t *now = crm_time_new(NULL);
 684     xmlNode *crmconfig = NULL;
 685     xmlNode *alerts = NULL;
 686 
 687     if (rc != pcmk_ok) {
 688         fsa_data_t *msg_data = NULL;
 689 
 690         crm_err("Local CIB query resulted in an error: %s", pcmk_strerror(rc));
 691         register_fsa_error(C_FSA_INTERNAL, I_ERROR, NULL);
 692 
 693         if (rc == -EACCES || rc == -pcmk_err_schema_validation) {
 694             crm_err("The cluster is mis-configured - shutting down and staying down");
 695             controld_set_fsa_input_flags(R_STAYDOWN);
 696         }
 697         goto bail;
 698     }
 699 
 700     crmconfig = output;
 701     if ((crmconfig) &&
 702         (crm_element_name(crmconfig)) &&
 703         (strcmp(crm_element_name(crmconfig), XML_CIB_TAG_CRMCONFIG) != 0)) {
 704         crmconfig = first_named_child(crmconfig, XML_CIB_TAG_CRMCONFIG);
 705     }
 706     if (!crmconfig) {
 707         fsa_data_t *msg_data = NULL;
 708 
 709         crm_err("Local CIB query for " XML_CIB_TAG_CRMCONFIG " section failed");
 710         register_fsa_error(C_FSA_INTERNAL, I_ERROR, NULL);
 711         goto bail;
 712     }
 713 
 714     crm_debug("Call %d : Parsing CIB options", call_id);
 715     config_hash = pcmk__strkey_table(free, free);
 716     pe_unpack_nvpairs(crmconfig, crmconfig, XML_CIB_TAG_PROPSET, NULL,
 717                       config_hash, CIB_OPTIONS_FIRST, FALSE, now, NULL);
 718 
 719     verify_crmd_options(config_hash);
 720 
 721     value = crmd_pref(config_hash, XML_CONFIG_ATTR_DC_DEADTIME);
 722     election_trigger->period_ms = crm_parse_interval_spec(value);
 723 
 724     value = crmd_pref(config_hash, "node-action-limit"); /* Also checks migration-limit */
 725     throttle_update_job_max(value);
 726 
 727     value = crmd_pref(config_hash, "load-threshold");
 728     if(value) {
 729         throttle_set_load_target(strtof(value, NULL) / 100.0);
 730     }
 731 
 732     value = crmd_pref(config_hash, "no-quorum-policy");
 733     if (pcmk__str_eq(value, "suicide", pcmk__str_casei) && pcmk__locate_sbd()) {
 734         no_quorum_suicide_escalation = TRUE;
 735     }
 736 
 737     set_fence_reaction(crmd_pref(config_hash, XML_CONFIG_ATTR_FENCE_REACTION));
 738 
 739     value = crmd_pref(config_hash,"stonith-max-attempts");
 740     update_stonith_max_attempts(value);
 741 
 742     value = crmd_pref(config_hash, XML_CONFIG_ATTR_FORCE_QUIT);
 743     shutdown_escalation_timer->period_ms = crm_parse_interval_spec(value);
 744     crm_debug("Shutdown escalation occurs if DC has not responded to request in %ums",
 745               shutdown_escalation_timer->period_ms);
 746 
 747     value = crmd_pref(config_hash, XML_CONFIG_ATTR_ELECTION_FAIL);
 748     controld_set_election_period(value);
 749 
 750     value = crmd_pref(config_hash, XML_CONFIG_ATTR_RECHECK);
 751     recheck_interval_ms = crm_parse_interval_spec(value);
 752     crm_debug("Re-run scheduler after %dms of inactivity", recheck_interval_ms);
 753 
 754     value = crmd_pref(config_hash, "transition-delay");
 755     transition_timer->period_ms = crm_parse_interval_spec(value);
 756 
 757     value = crmd_pref(config_hash, "join-integration-timeout");
 758     integration_timer->period_ms = crm_parse_interval_spec(value);
 759 
 760     value = crmd_pref(config_hash, "join-finalization-timeout");
 761     finalization_timer->period_ms = crm_parse_interval_spec(value);
 762 
 763     value = crmd_pref(config_hash, XML_CONFIG_ATTR_SHUTDOWN_LOCK);
 764     controld_shutdown_lock_enabled = crm_is_true(value);
 765 
 766     free(fsa_cluster_name);
 767     fsa_cluster_name = NULL;
 768 
 769     value = g_hash_table_lookup(config_hash, "cluster-name");
 770     if (value) {
 771         fsa_cluster_name = strdup(value);
 772     }
 773 
 774     alerts = first_named_child(output, XML_CIB_TAG_ALERTS);
 775     crmd_unpack_alerts(alerts);
 776 
 777     controld_set_fsa_input_flags(R_READ_CONFIG);
 778     crm_trace("Triggering FSA: %s", __func__);
 779     mainloop_set_trigger(fsa_source);
 780 
 781     g_hash_table_destroy(config_hash);
 782   bail:
 783     crm_time_free(now);
 784 }
 785 
 786 gboolean
 787 crm_read_options(gpointer user_data)
     /* [previous][next][first][last][top][bottom][index][help] */
 788 {
 789     int call_id =
 790         fsa_cib_conn->cmds->query(fsa_cib_conn,
 791             "//" XML_CIB_TAG_CRMCONFIG " | //" XML_CIB_TAG_ALERTS,
 792             NULL, cib_xpath | cib_scope_local);
 793 
 794     fsa_register_cib_callback(call_id, FALSE, NULL, config_query_callback);
 795     crm_trace("Querying the CIB... call %d", call_id);
 796     return TRUE;
 797 }
 798 
 799 /*       A_READCONFIG   */
 800 void
 801 do_read_config(long long action,
     /* [previous][next][first][last][top][bottom][index][help] */
 802                enum crmd_fsa_cause cause,
 803                enum crmd_fsa_state cur_state,
 804                enum crmd_fsa_input current_input, fsa_data_t * msg_data)
 805 {
 806     throttle_init();
 807     mainloop_set_trigger(config_read);
 808 }
 809 
 810 void
 811 crm_shutdown(int nsig)
     /* [previous][next][first][last][top][bottom][index][help] */
 812 {
 813     if ((crmd_mainloop == NULL) || !g_main_loop_is_running(crmd_mainloop)) {
 814         crmd_exit(CRM_EX_OK);
 815         return;
 816     }
 817 
 818     if (pcmk_is_set(fsa_input_register, R_SHUTDOWN)) {
 819         crm_err("Escalating shutdown");
 820         register_fsa_input_before(C_SHUTDOWN, I_ERROR, NULL);
 821         return;
 822     }
 823 
 824     controld_set_fsa_input_flags(R_SHUTDOWN);
 825     register_fsa_input(C_SHUTDOWN, I_SHUTDOWN, NULL);
 826 
 827     if (shutdown_escalation_timer->period_ms == 0) {
 828         const char *value = crmd_pref(NULL, XML_CONFIG_ATTR_FORCE_QUIT);
 829 
 830         shutdown_escalation_timer->period_ms = crm_parse_interval_spec(value);
 831     }
 832 
 833     crm_notice("Initiating controller shutdown sequence " CRM_XS
 834                " limit=%ums", shutdown_escalation_timer->period_ms);
 835     controld_start_timer(shutdown_escalation_timer);
 836 }

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