1 /* 2 * Copyright 2004-2025 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 Lesser General Public License 7 * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. 8 */ 9 10 #ifndef PCMK__CRM_STONITH_NG__H 11 # define PCMK__CRM_STONITH_NG__H 12 13 #ifdef __cplusplus 14 extern "C" { 15 #endif 16 17 /** 18 * \file 19 * \brief Fencing aka. STONITH 20 * \ingroup fencing 21 */ 22 23 /* IMPORTANT: dlm source code includes this file directly. Until dlm v4.2.0 24 * (commit 5afd9fdc), dlm did not have access to other Pacemaker headers on its 25 * include path. This file should *not* include any other Pacemaker headers 26 * until we decide that we no longer need to support dlm versions older than 27 * v4.2.0. 28 * 29 * @COMPAT Remove this restriction and take any opportunities to simplify code 30 * when possible. 31 */ 32 33 # include <dlfcn.h> 34 # include <errno.h> 35 # include <stdbool.h> // bool 36 # include <stdint.h> // uint32_t 37 # include <time.h> // time_t 38 39 // @TODO Keep this definition but make it internal 40 /*! 41 * \brief Fencer API connection state 42 * \deprecated Do not use 43 */ 44 enum stonith_state { 45 stonith_connected_command, 46 stonith_connected_query, 47 stonith_disconnected, 48 }; 49 50 // @TODO Keep this definition but make it internal 51 /*! 52 * \brief Flags that can be set in call options for API requests 53 * 54 * \deprecated Do not use 55 */ 56 enum stonith_call_options { 57 // No options 58 //! \deprecated Do not use 59 st_opt_none = 0, 60 61 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1) 62 //! \deprecated Do not use 63 st_opt_verbose = (1 << 0), 64 #endif 65 66 // The fencing target is allowed to execute the request 67 //! \deprecated Do not use 68 st_opt_allow_self_fencing = (1 << 1), 69 70 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1) 71 //! \deprecated Do not use 72 st_opt_allow_suicide = st_opt_allow_self_fencing, 73 #endif 74 75 // Used internally to indicate that request is manual fence confirmation 76 // \internal Do not use 77 //! \deprecated Do not use 78 st_opt_manual_ack = (1 << 3), 79 80 // Do not return any reply from server 81 //! \deprecated Do not use 82 st_opt_discard_reply = (1 << 4), 83 84 // Used internally to indicate that request requires a fencing topology 85 // \internal Do not use 86 //! \deprecated Do not use 87 st_opt_topology = (1 << 6), 88 89 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1) 90 //! \deprecated Do not use 91 st_opt_scope_local = (1 << 8), 92 #endif 93 94 // Interpret target as node cluster layer ID instead of name 95 //! \deprecated Do not use 96 st_opt_cs_nodeid = (1 << 9), 97 98 // Wait for request to be completed before returning 99 //! \deprecated Do not use 100 st_opt_sync_call = (1 << 12), 101 102 // Request that server send an update with optimal callback timeout 103 //! \deprecated Do not use 104 st_opt_timeout_updates = (1 << 13), 105 106 // Invoke callback only if request succeeded 107 //! \deprecated Do not use 108 st_opt_report_only_success = (1 << 14), 109 110 // For a fence history request, request that the history be cleared 111 //! \deprecated Do not use 112 st_opt_cleanup = (1 << 19), 113 114 // For a fence history request, broadcast the request to all nodes 115 //! \deprecated Do not use 116 st_opt_broadcast = (1 << 20), 117 }; 118 119 // Order matters here, do not change values 120 // @TODO Keep this definition but make it internal 121 /*! 122 * \brief Fencing operation states 123 * \deprecated Do not use 124 */ 125 enum op_state { 126 st_query, //! \deprecated Do not use 127 st_exec, //! \deprecated Do not use 128 st_done, //! \deprecated Do not use 129 st_duplicate, //! \deprecated Do not use 130 st_failed, //! \deprecated Do not use 131 }; 132 133 // @TODO Keep this definition but make it internal 134 /*! 135 * \brief Supported fence agent interface standards 136 * \deprecated Do not use 137 */ 138 enum stonith_namespace { 139 st_namespace_invalid, //! \deprecated Do not use 140 st_namespace_any, //! \deprecated Do not use 141 142 // Implemented internally by Pacemaker 143 st_namespace_internal, //! \deprecated Do not use 144 145 /* Neither of these projects are active any longer, but the fence agent 146 * interfaces they created are still in use and supported by Pacemaker. 147 */ 148 // Red Hat Cluster Suite compatible 149 st_namespace_rhcs, //! \deprecated Do not use 150 151 // Linux-HA compatible 152 st_namespace_lha, //! \deprecated Do not use 153 }; 154 155 /* @COMPAT Drop this and use a GList/GSList of pcmk_nvpair_t or a GHashtable as 156 * appropriate 157 */ 158 /*! 159 * \brief Key-value pair list node 160 * \deprecated Do not use 161 */ 162 typedef struct stonith_key_value_s { 163 char *key; 164 char *value; 165 struct stonith_key_value_s *next; 166 } stonith_key_value_t; 167 168 // @TODO Keep this definition but make it internal 169 /*! 170 * \brief Fencing history entry 171 * \deprecated Do not use 172 */ 173 typedef struct stonith_history_s { 174 char *target; 175 char *action; 176 char *origin; 177 char *delegate; 178 char *client; 179 int state; 180 time_t completed; 181 struct stonith_history_s *next; 182 long completed_nsec; 183 char *exit_reason; 184 } stonith_history_t; 185 186 // @TODO Keep this typedef but rename it and make it internal 187 typedef struct stonith_s stonith_t; 188 189 // @TODO Keep this definition but make it internal 190 /*! 191 * \brief Fencing event 192 * \deprecated Do not use 193 */ 194 typedef struct stonith_event_s { 195 char *id; 196 char *operation; 197 int result; 198 char *origin; 199 char *target; 200 char *action; 201 char *executioner; 202 203 char *device; 204 205 // Name of the client that initiated the action 206 char *client_origin; 207 208 void *opaque; 209 } stonith_event_t; 210 211 // @TODO Keep this definition but make it internal 212 /*! 213 * \brief Data for an asynchronous fencing request callback 214 * \deprecated Do not use 215 */ 216 typedef struct stonith_callback_data_s { 217 int rc; 218 int call_id; 219 void *userdata; 220 221 //! \internal This field should be treated as internal to Pacemaker 222 void *opaque; 223 } stonith_callback_data_t; 224 225 // @TODO Keep this object but make it internal 226 /*! 227 * \brief Fencer API operations 228 * \deprecated Use appropriate functions in libpacemaker instead 229 */ 230 typedef struct stonith_api_operations_s { 231 /*! 232 * \brief Destroy a fencer connection 233 * 234 * \param[in,out] st Fencer connection to destroy 235 * \deprecated \c stonith_api_operations_t is deprecated for external use 236 */ 237 int (*free) (stonith_t *st); 238 239 /*! 240 * \brief Connect to the local fencer 241 * 242 * \param[in,out] st Fencer connection to connect 243 * \param[in] name Client name to use 244 * \param[out] stonith_fd If NULL, use a main loop, otherwise 245 * store IPC file descriptor here 246 * 247 * \return Legacy Pacemaker return code 248 * \deprecated \c stonith_api_operations_t is deprecated for external use 249 */ 250 int (*connect) (stonith_t *st, const char *name, int *stonith_fd); 251 252 /*! 253 * \brief Disconnect from the local stonith daemon. 254 * 255 * \param[in,out] st Fencer connection to disconnect 256 * 257 * \return Legacy Pacemaker return code 258 * \deprecated \c stonith_api_operations_t is deprecated for external use 259 */ 260 int (*disconnect)(stonith_t *st); 261 262 /*! 263 * \brief Unregister a fence device with the local fencer 264 * 265 * \param[in,out] st Fencer connection to disconnect 266 * \param[in] options Group of enum stonith_call_options 267 * \param[in] name ID of fence device to unregister 268 * 269 * \return pcmk_ok (if synchronous) or positive call ID (if asynchronous) 270 * on success, otherwise a negative legacy Pacemaker return code 271 * \deprecated \c stonith_api_operations_t is deprecated for external use 272 */ 273 int (*remove_device)(stonith_t *st, int options, const char *name); 274 275 /*! 276 * \brief Register a fence device with the local fencer 277 * 278 * \param[in,out] st Fencer connection to use 279 * \param[in] options Group of enum stonith_call_options 280 * \param[in] id ID of fence device to register 281 * \param[in] namespace_s Type of fence agent to search for ("redhat" 282 * or "stonith-ng" for RHCS-style, "internal" 283 * for Pacemaker-internal devices, "heartbeat" 284 * for LHA-style, or "any" or NULL for any) 285 * \param[in] agent Name of fence agent for device 286 * \param[in] params Fence agent parameters for device 287 * 288 * \return pcmk_ok (if synchronous) or positive call ID (if asynchronous) 289 * on success, otherwise a negative legacy Pacemaker return code 290 * \deprecated \c stonith_api_operations_t is deprecated for external use 291 */ 292 int (*register_device)(stonith_t *st, int options, const char *id, 293 const char *namespace_s, const char *agent, 294 const stonith_key_value_t *params); 295 296 /*! 297 * \brief Unregister a fencing level for specified node with local fencer 298 * 299 * \param[in,out] st Fencer connection to use 300 * \param[in] options Group of enum stonith_call_options 301 * \param[in] node Target node to unregister level for 302 * \param[in] level Topology level number to unregister 303 * 304 * \return pcmk_ok (if synchronous) or positive call ID (if asynchronous) 305 * on success, otherwise a negative legacy Pacemaker return code 306 * \note Not used internally 307 * \deprecated \c stonith_api_operations_t is deprecated for external use 308 */ 309 int (*remove_level)(stonith_t *st, int options, const char *node, 310 int level); 311 312 /*! 313 * \brief Register a fencing level for specified node with local fencer 314 * 315 * \param[in,out] st Fencer connection to use 316 * \param[in] options Group of enum stonith_call_options 317 * \param[in] node Target node to register level for 318 * \param[in] level Topology level number to register 319 * \param[in] device_list Devices to register in level 320 * 321 * \return pcmk_ok (if synchronous) or positive call ID (if asynchronous) 322 * on success, otherwise a negative legacy Pacemaker return code 323 * \note Used only by cts-fence-helper.c internally 324 * \deprecated \c stonith_api_operations_t is deprecated for external use 325 */ 326 int (*register_level)(stonith_t *st, int options, const char *node, 327 int level, const stonith_key_value_t *device_list); 328 329 /*! 330 * \brief Retrieve a fence agent's metadata 331 * 332 * \param[in,out] stonith Fencer connection 333 * \param[in] call_options Group of enum stonith_call_options 334 * (currently ignored) 335 * \param[in] agent Fence agent to query 336 * \param[in] namespace_s Ignored 337 * \param[out] output Where to store metadata 338 * \param[in] timeout_sec Error if not complete within this time 339 * 340 * \return Legacy Pacemaker return code 341 * \note The caller is responsible for freeing *output using free(). 342 * \deprecated \c stonith_api_operations_t is deprecated for external use 343 */ 344 int (*metadata)(stonith_t *stonith, int call_options, const char *agent, 345 const char *namespace_s, char **output, int timeout_sec); 346 347 /*! 348 * \brief Retrieve a list of installed fence agents 349 * 350 * \param[in,out] stonith Fencer connection to use 351 * \param[in] call_options Group of enum stonith_call_options 352 * (currently ignored) 353 * \param[in] namespace_s Type of fence agents to list ("redhat" 354 * or "stonith-ng" for RHCS-style, "internal" for 355 * Pacemaker-internal devices, "heartbeat" for 356 * LHA-style, or "any" or NULL for all) 357 * \param[out] devices Where to store agent list 358 * \param[in] timeout Ignored 359 * 360 * \return Number of items in list on success, or negative errno otherwise 361 * \note The caller is responsible for freeing the returned list with 362 * \c stonith__key_value_freeall(). 363 * \deprecated \c stonith_api_operations_t is deprecated for external use 364 */ 365 int (*list_agents)(stonith_t *stonith, int call_options, 366 const char *namespace_s, stonith_key_value_t **devices, 367 int timeout); 368 369 /*! 370 * \brief Get the output of a fence device's list action 371 * 372 * \param[in,out] stonith Fencer connection to use 373 * \param[in] call_options Group of enum stonith_call_options 374 * \param[in] id Fence device ID to run list for 375 * \param[out] list_info Where to store list output 376 * \param[in] timeout Error if unable to complete within this 377 * 378 * \return pcmk_ok (if synchronous) or positive call ID (if asynchronous) 379 * on success, otherwise a negative legacy Pacemaker return code 380 * \deprecated \c stonith_api_operations_t is deprecated for external use 381 */ 382 int (*list)(stonith_t *stonith, int call_options, const char *id, 383 char **list_info, int timeout); 384 385 /*! 386 * \brief Check whether a fence device is reachable by monitor action 387 * 388 * \param[in,out] stonith Fencer connection to use 389 * \param[in] call_options Group of enum stonith_call_options 390 * \param[in] id Fence device ID to run monitor for 391 * \param[in] timeout Error if unable to complete within this 392 * 393 * \return pcmk_ok (if synchronous) or positive call ID (if asynchronous) 394 * on success, otherwise a negative legacy Pacemaker return code 395 * \deprecated \c stonith_api_operations_t is deprecated for external use 396 */ 397 int (*monitor)(stonith_t *stonith, int call_options, const char *id, 398 int timeout); 399 400 /*! 401 * \brief Check whether a fence device target is reachable by status action 402 * 403 * \param[in,out] stonith Fencer connection to use 404 * \param[in] call_options Group of enum stonith_call_options 405 * \param[in] id Fence device ID to run status for 406 * \param[in] port Fence target to run status for 407 * \param[in] timeout Error if unable to complete within this 408 * 409 * \return pcmk_ok (if synchronous) or positive call ID (if asynchronous) 410 * on success, otherwise a negative legacy Pacemaker return code 411 * \note Used only by cts-fence-helper.c internally 412 * \deprecated \c stonith_api_operations_t is deprecated for external use 413 */ 414 int (*status)(stonith_t *stonith, int call_options, const char *id, 415 const char *port, int timeout); 416 417 /*! 418 * \brief List registered fence devices 419 * 420 * \param[in,out] stonith Fencer connection to use 421 * \param[in] call_options Group of enum stonith_call_options 422 * \param[in] target Fence target to run status for 423 * \param[out] devices Where to store list of fence devices 424 * \param[in] timeout Error if unable to complete within this 425 * 426 * \note If node is provided, only devices that can fence the node id 427 * will be returned. 428 * 429 * \return Number of items in list on success, or negative errno otherwise 430 * \deprecated \c stonith_api_operations_t is deprecated for external use 431 */ 432 int (*query)(stonith_t *stonith, int call_options, const char *target, 433 stonith_key_value_t **devices, int timeout); 434 435 /*! 436 * \brief Request that a target get fenced 437 * 438 * \param[in,out] stonith Fencer connection to use 439 * \param[in] call_options Group of enum stonith_call_options 440 * \param[in] node Fence target 441 * \param[in] action "on", "off", or "reboot" 442 * \param[in] timeout Default per-device timeout to use with 443 * each executed device 444 * \param[in] tolerance Accept result of identical fence action 445 * completed within this time 446 * 447 * \return pcmk_ok (if synchronous) or positive call ID (if asynchronous) 448 * on success, otherwise a negative legacy Pacemaker return code 449 * \note Used only by cts-fence-helper.c and \c stonith_api_kick() 450 * internally. The latter might go away eventually if dlm starts using 451 * \c pcmk_request_fencing(). 452 * \deprecated \c stonith_api_operations_t is deprecated for external use 453 */ 454 int (*fence)(stonith_t *stonith, int call_options, const char *node, 455 const char *action, int timeout, int tolerance); 456 457 /*! 458 * \brief Manually confirm that a node has been fenced 459 * 460 * \param[in,out] stonith Fencer connection to use 461 * \param[in] call_options Group of enum stonith_call_options 462 * \param[in] target Fence target 463 * 464 * \return pcmk_ok (if synchronous) or positive call ID (if asynchronous) 465 * on success, otherwise a negative legacy Pacemaker return code 466 * \deprecated \c stonith_api_operations_t is deprecated for external use 467 */ 468 int (*confirm)(stonith_t *stonith, int call_options, const char *target); 469 470 /*! 471 * \brief List fencing actions that have occurred for a target 472 * 473 * \param[in,out] stonith Fencer connection to use 474 * \param[in] call_options Group of enum stonith_call_options 475 * \param[in] node Fence target 476 * \param[out] history Where to store list of fencing actions 477 * \param[in] timeout Error if unable to complete within this 478 * 479 * \return Legacy Pacemaker return code 480 * \deprecated \c stonith_api_operations_t is deprecated for external use 481 */ 482 int (*history)(stonith_t *stonith, int call_options, const char *node, 483 stonith_history_t **history, int timeout); 484 485 /*! 486 * \brief Register a callback for fence notifications 487 * 488 * \param[in,out] stonith Fencer connection to use 489 * \param[in] event Event to register for 490 * \param[in] callback Callback to register 491 * 492 * \return Legacy Pacemaker return code 493 * \deprecated \c stonith_api_operations_t is deprecated for external use 494 */ 495 int (*register_notification)(stonith_t *stonith, const char *event, 496 void (*callback)(stonith_t *st, 497 stonith_event_t *e)); 498 499 /*! 500 * \brief Unregister callbacks for fence notifications 501 * 502 * \param[in,out] stonith Fencer connection to use 503 * \param[in] event Event to unregister callbacks for (NULL for all) 504 * 505 * \return Legacy Pacemaker return code 506 * \deprecated \c stonith_api_operations_t is deprecated for external use 507 */ 508 int (*remove_notification)(stonith_t *stonith, const char *event); 509 510 /*! 511 * \brief Register a callback for an asynchronous fencing result 512 * 513 * \param[in,out] stonith Fencer connection to use 514 * \param[in] call_id Call ID to register callback for 515 * \param[in] timeout Error if result not received in this time 516 * \param[in] options Group of enum stonith_call_options 517 * (respects \c st_opt_timeout_updates and 518 * \c st_opt_report_only_success) 519 * \param[in,out] user_data Pointer to pass to callback 520 * \param[in] callback_name Unique identifier for callback 521 * \param[in] callback Callback to register (may be called 522 * immediately if \p call_id indicates error) 523 * 524 * \return \c TRUE on success, \c FALSE if call_id indicates error, 525 * or -EINVAL if \p stonith is not valid 526 * \deprecated \c stonith_api_operations_t is deprecated for external use 527 */ 528 int (*register_callback)(stonith_t *stonith, int call_id, int timeout, 529 int options, void *user_data, 530 const char *callback_name, 531 void (*callback)(stonith_t *st, 532 stonith_callback_data_t *data)); 533 534 /*! 535 * \brief Unregister callbacks for asynchronous fencing results 536 * 537 * \param[in,out] stonith Fencer connection to use 538 * \param[in] call_id If \p all_callbacks is false, call ID 539 * to unregister callback for 540 * \param[in] all_callbacks If true, unregister all callbacks 541 * 542 * \return pcmk_ok 543 * \note Not used internally (but perhaps it should be) 544 * \deprecated \c stonith_api_operations_t is deprecated for external use 545 */ 546 int (*remove_callback)(stonith_t *stonith, int call_id, bool all_callbacks); 547 548 /*! 549 * \brief Unregister fencing level for specified node, pattern or attribute 550 * 551 * \param[in,out] st Fencer connection to use 552 * \param[in] options Group of enum stonith_call_options 553 * \param[in] node If not NULL, unregister level targeting this node 554 * \param[in] pattern If not NULL, unregister level targeting nodes 555 * whose names match this regular expression 556 * \param[in] attr If this and \p value are not NULL, unregister 557 * level targeting nodes with this node attribute 558 * set to \p value 559 * \param[in] value If this and \p attr are not NULL, unregister 560 * level targeting nodes with node attribute \p attr 561 * set to this 562 * \param[in] level Topology level number to remove 563 * 564 * \return pcmk_ok (if synchronous) or positive call ID (if asynchronous) 565 * on success, otherwise a negative legacy Pacemaker return code 566 * \note The caller should set only one of \p node, \p pattern, or \p attr 567 * and \p value. 568 * \deprecated \c stonith_api_operations_t is deprecated for external use 569 */ 570 int (*remove_level_full)(stonith_t *st, int options, 571 const char *node, const char *pattern, 572 const char *attr, const char *value, int level); 573 574 /*! 575 * \brief Register fencing level for specified node, pattern or attribute 576 * 577 * \param[in,out] st Fencer connection to use 578 * \param[in] options Group of enum stonith_call_options 579 * \param[in] node If not NULL, register level targeting this 580 * node by name 581 * \param[in] pattern If not NULL, register level targeting nodes 582 * whose names match this regular expression 583 * \param[in] attr If this and \p value are not NULL, register 584 * level targeting nodes with this node 585 * attribute set to \p value 586 * \param[in] value If this and \p attr are not NULL, register 587 * level targeting nodes with node attribute 588 * \p attr set to this 589 * \param[in] level Topology level number to remove 590 * \param[in] device_list Devices to use in level 591 * 592 * \return pcmk_ok (if synchronous) or positive call ID (if asynchronous) 593 * on success, otherwise a negative legacy Pacemaker return code 594 * 595 * \note The caller should set only one of node, pattern or attr/value. 596 * \deprecated \c stonith_api_operations_t is deprecated for external use 597 */ 598 int (*register_level_full)(stonith_t *st, int options, 599 const char *node, const char *pattern, 600 const char *attr, const char *value, int level, 601 const stonith_key_value_t *device_list); 602 603 /*! 604 * \brief Validate an arbitrary stonith device configuration 605 * 606 * \param[in,out] st Fencer connection to use 607 * \param[in] call_options Group of enum stonith_call_options 608 * \param[in] rsc_id ID used to replace CIB secrets in \p params 609 * \param[in] namespace_s Ignored 610 * \param[in] agent Fence agent to validate 611 * \param[in] params Configuration parameters to pass to agent 612 * \param[in] timeout Fail if no response within this many seconds 613 * \param[out] output If non-NULL, where to store any agent output 614 * \param[out] error_output If non-NULL, where to store agent error output 615 * 616 * \return pcmk_ok if validation succeeds, -errno otherwise 617 * \note If pcmk_ok is returned, the caller is responsible for freeing 618 * the output (if requested) with free(). 619 * \note Not used internally 620 * \deprecated \c stonith_api_operations_t is deprecated for external use 621 */ 622 int (*validate)(stonith_t *st, int call_options, const char *rsc_id, 623 const char *namespace_s, const char *agent, 624 const stonith_key_value_t *params, int timeout, 625 char **output, char **error_output); 626 627 /*! 628 * \brief Request delayed fencing of a target 629 * 630 * \param[in,out] stonith Fencer connection to use 631 * \param[in] call_options Group of enum stonith_call_options 632 * \param[in] node Fence target 633 * \param[in] action "on", "off", or "reboot" 634 * \param[in] timeout Default per-device timeout to use with 635 * each executed device 636 * \param[in] tolerance Accept result of identical fence action 637 * completed within this time 638 * \param[in] delay Execute fencing after this delay (-1 639 * disables any delay from pcmk_delay_base 640 * and pcmk_delay_max) 641 * 642 * \return pcmk_ok (if synchronous) or positive call ID (if asynchronous) 643 * on success, otherwise a negative legacy Pacemaker return code 644 * \deprecated \c stonith_api_operations_t is deprecated for external use 645 */ 646 int (*fence_with_delay)(stonith_t *stonith, int call_options, 647 const char *node, const char *action, int timeout, 648 int tolerance, int delay); 649 650 } stonith_api_operations_t; 651 652 // @TODO Keep this object but make it internal 653 /*! 654 * \brief Fencer API connection object 655 * \deprecated Use appropriate functions in libpacemaker instead 656 */ 657 struct stonith_s { 658 enum stonith_state state; 659 int call_id; 660 void *st_private; 661 stonith_api_operations_t *cmds; 662 }; 663 664 /* Basic helpers that allows nodes to be fenced and the history to be 665 * queried without mainloop or the caller understanding the full API 666 * 667 * At least one of nodeid and uname are required 668 * 669 * NOTE: dlm (as of at least 4.3.0) uses these (via the helper functions below) 670 */ 671 int stonith_api_kick(uint32_t nodeid, const char *uname, int timeout, bool off); 672 time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress); 673 674 /* 675 * Helpers for using the above functions without install-time dependencies 676 * 677 * Usage: 678 * #include <crm/stonith-ng.h> 679 * 680 * To turn a node off by corosync nodeid: 681 * stonith_api_kick_helper(nodeid, 120, 1); 682 * 683 * To check the last fence date/time (also by nodeid): 684 * last = stonith_api_time_helper(nodeid, 0); 685 * 686 * To check if fencing is in progress: 687 * if(stonith_api_time_helper(nodeid, 1) > 0) { ... } 688 * 689 * eg. 690 691 #include <stdio.h> 692 #include <time.h> 693 #include <crm/stonith-ng.h> 694 int 695 main(int argc, char ** argv) 696 { 697 int rc = 0; 698 int nodeid = 102; 699 700 rc = stonith_api_time_helper(nodeid, 0); 701 printf("%d last fenced at %s\n", nodeid, ctime(rc)); 702 703 rc = stonith_api_kick_helper(nodeid, 120, 1); 704 printf("%d fence result: %d\n", nodeid, rc); 705 706 rc = stonith_api_time_helper(nodeid, 0); 707 printf("%d last fenced at %s\n", nodeid, ctime(rc)); 708 709 return 0; 710 } 711 712 */ 713 714 #define STONITH_LIBRARY "libstonithd.so.56" 715 716 // NOTE: dlm (as of at least 4.3.0) uses these (via the helper functions below) 717 typedef int (*st_api_kick_fn) (int nodeid, const char *uname, int timeout, bool off); 718 typedef time_t (*st_api_time_fn) (int nodeid, const char *uname, bool in_progress); 719 720 // NOTE: dlm (as of at least 4.3.0) uses this 721 static inline int 722 stonith_api_kick_helper(uint32_t nodeid, int timeout, bool off) /**/ 723 { 724 static void *st_library = NULL; 725 static st_api_kick_fn st_kick_fn; 726 727 if (st_library == NULL) { 728 st_library = dlopen(STONITH_LIBRARY, RTLD_LAZY); 729 } 730 if (st_library && st_kick_fn == NULL) { 731 st_kick_fn = (st_api_kick_fn) dlsym(st_library, "stonith_api_kick"); 732 } 733 if (st_kick_fn == NULL) { 734 #ifdef ELIBACC 735 return -ELIBACC; 736 #else 737 return -ENOSYS; 738 #endif 739 } 740 741 return (*st_kick_fn) (nodeid, NULL, timeout, off); 742 } 743 744 // NOTE: dlm (as of at least 4.3.0) uses this 745 static inline time_t 746 stonith_api_time_helper(uint32_t nodeid, bool in_progress) /*
*/ 747 { 748 static void *st_library = NULL; 749 static st_api_time_fn st_time_fn; 750 751 if (st_library == NULL) { 752 st_library = dlopen(STONITH_LIBRARY, RTLD_LAZY); 753 } 754 if (st_library && st_time_fn == NULL) { 755 st_time_fn = (st_api_time_fn) dlsym(st_library, "stonith_api_time"); 756 } 757 if (st_time_fn == NULL) { 758 return 0; 759 } 760 761 return (*st_time_fn) (nodeid, NULL, in_progress); 762 } 763 764 #if !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1) 765 766 /* Normally we'd put this section in a separate file (crm/fencing/compat.h), but 767 * we can't do that for the reason noted at the top of this file. That does mean 768 * we have to duplicate these declarations where they're implemented. 769 */ 770 771 //! \deprecated Use appropriate functions in libpacemaker 772 stonith_t *stonith_api_new(void); 773 774 //! \deprecated Use appropriate functions in libpacemaker 775 void stonith_api_delete(stonith_t *stonith); 776 777 //! \deprecated Do not use 778 void stonith_dump_pending_callbacks(stonith_t *stonith); 779 780 //! \deprecated Do not use 781 bool stonith_dispatch(stonith_t *stonith_api); 782 783 //! \deprecated Do not use 784 stonith_key_value_t *stonith_key_value_add(stonith_key_value_t *kvp, 785 const char *key, const char *value); 786 787 //! \deprecated Do not use 788 void stonith_key_value_freeall(stonith_key_value_t *head, int keys, int values); 789 790 //! \deprecated Do not use 791 void stonith_history_free(stonith_history_t *head); 792 793 //! \deprecated Do not use 794 int stonith_api_connect_retry(stonith_t *st, const char *name, 795 int max_attempts); 796 797 //! \deprecated Do not use 798 const char *stonith_op_state_str(enum op_state state); 799 800 //! \deprecated Do not use 801 bool stonith_agent_exists(const char *agent, int timeout); 802 803 //! \deprecated Do not use 804 const char *stonith_action_str(const char *action); 805 806 //! \deprecated Do not use 807 enum stonith_namespace stonith_text2namespace(const char *namespace_s); 808 809 //! \deprecated Do not use 810 const char *stonith_namespace2text(enum stonith_namespace st_namespace); 811 812 //! \deprecated Do not use 813 enum stonith_namespace stonith_get_namespace(const char *agent, 814 const char *namespace_s); 815 816 #endif // !defined(PCMK_ALLOW_DEPRECATED) || (PCMK_ALLOW_DEPRECATED == 1) 817 818 #ifdef __cplusplus 819 } 820 #endif 821 822 #endif