1 /*
2 * Copyright 2004-2024 the Pacemaker project contributors
3 *
4 * The version control history for this file may have further details.
5 *
6 * This source code is licensed under the GNU Lesser General Public License
7 * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8 */
9
10 #include <crm_internal.h>
11
12 #include <stdint.h> // uint32_t
13 #include <errno.h> // EINVAL
14 #include <glib.h> // gboolean, FALSE
15 #include <libxml/tree.h> // xmlNode
16
17 #include <crm/common/scheduler.h>
18
19 uint32_t pcmk__warnings = 0;
20
21 gboolean was_processing_error = FALSE;
22 gboolean was_processing_warning = FALSE;
23
24 /*!
25 * \internal
26 * \brief Get the Designated Controller node from scheduler data
27 *
28 * \param[in] scheduler Scheduler data
29 *
30 * \return Designated Controller node from scheduler data, or NULL if none
31 */
32 pcmk_node_t *
33 pcmk_get_dc(const pcmk_scheduler_t *scheduler)
/* ![[previous]](../icons/n_left.png)
![[next]](../icons/right.png)
![[first]](../icons/n_first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
34 {
35 return (scheduler == NULL)? NULL : scheduler->dc_node;
36 }
37
38 /*!
39 * \internal
40 * \brief Get the no quorum policy from scheduler data
41 *
42 * \param[in] scheduler Scheduler data
43 *
44 * \return No quorum policy from scheduler data
45 */
46 enum pe_quorum_policy
47 pcmk_get_no_quorum_policy(const pcmk_scheduler_t *scheduler)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
48 {
49 if (scheduler == NULL) {
50 return pcmk_no_quorum_stop; // The default
51 }
52 return scheduler->no_quorum_policy;
53 }
54
55 /*!
56 * \internal
57 * \brief Set CIB XML as scheduler input in scheduler data
58 *
59 * \param[out] scheduler Scheduler data
60 * \param[in] cib CIB XML to set as scheduler input
61 *
62 * \return Standard Pacemaker return code (EINVAL if \p scheduler is NULL,
63 * otherwise pcmk_rc_ok)
64 * \note This will not free any previously set scheduler CIB.
65 */
66 int
67 pcmk_set_scheduler_cib(pcmk_scheduler_t *scheduler, xmlNode *cib)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
68 {
69 if (scheduler == NULL) {
70 return EINVAL;
71 }
72 scheduler->input = cib;
73 return pcmk_rc_ok;
74 }
75
76 /*!
77 * \internal
78 * \brief Check whether cluster has quorum
79 *
80 * \param[in] scheduler Scheduler data
81 *
82 * \return true if cluster has quorum, otherwise false
83 */
84 bool
85 pcmk_has_quorum(const pcmk_scheduler_t *scheduler)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
86 {
87 if (scheduler == NULL) {
88 return false;
89 }
90 return pcmk_is_set(scheduler->flags, pcmk_sched_quorate);
91 }
92
93 /*!
94 * \brief Find a node by name in scheduler data
95 *
96 * \param[in] scheduler Scheduler data
97 * \param[in] node_name Name of node to find
98 *
99 * \return Node from scheduler data that matches \p node_name if any,
100 * otherwise NULL
101 */
102 pcmk_node_t *
103 pcmk_find_node(const pcmk_scheduler_t *scheduler, const char *node_name)
/* ![[previous]](../icons/left.png)
![[next]](../icons/n_right.png)
![[first]](../icons/first.png)
![[last]](../icons/n_last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
104 {
105 if ((scheduler == NULL) || (node_name == NULL)) {
106 return NULL;
107 }
108 return pcmk__find_node_in_list(scheduler->nodes, node_name);
109 }