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

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