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 /*!
22 * \internal
23 * \brief Get the Designated Controller node from scheduler data
24 *
25 * \param[in] scheduler Scheduler data
26 *
27 * \return Designated Controller node from scheduler data, or NULL if none
28 */
29 pcmk_node_t *
30 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)
*/
31 {
32 return (scheduler == NULL)? NULL : scheduler->dc_node;
33 }
34
35 /*!
36 * \internal
37 * \brief Get the no quorum policy from scheduler data
38 *
39 * \param[in] scheduler Scheduler data
40 *
41 * \return No quorum policy from scheduler data
42 */
43 enum pe_quorum_policy
44 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)
*/
45 {
46 if (scheduler == NULL) {
47 return pcmk_no_quorum_stop; // The default
48 }
49 return scheduler->no_quorum_policy;
50 }
51
52 /*!
53 * \internal
54 * \brief Set CIB XML as scheduler input in scheduler data
55 *
56 * \param[out] scheduler Scheduler data
57 * \param[in] cib CIB XML to set as scheduler input
58 *
59 * \return Standard Pacemaker return code (EINVAL if \p scheduler is NULL,
60 * otherwise pcmk_rc_ok)
61 * \note This will not free any previously set scheduler CIB.
62 */
63 int
64 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)
*/
65 {
66 if (scheduler == NULL) {
67 return EINVAL;
68 }
69 scheduler->input = cib;
70 return pcmk_rc_ok;
71 }
72
73 /*!
74 * \internal
75 * \brief Check whether cluster has quorum
76 *
77 * \param[in] scheduler Scheduler data
78 *
79 * \return true if cluster has quorum, otherwise false
80 */
81 bool
82 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)
*/
83 {
84 if (scheduler == NULL) {
85 return false;
86 }
87 return pcmk_is_set(scheduler->flags, pcmk__sched_quorate);
88 }
89
90 /*!
91 * \brief Find a node by name in scheduler data
92 *
93 * \param[in] scheduler Scheduler data
94 * \param[in] node_name Name of node to find
95 *
96 * \return Node from scheduler data that matches \p node_name if any,
97 * otherwise NULL
98 */
99 pcmk_node_t *
100 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)
*/
101 {
102 if ((scheduler == NULL) || (node_name == NULL)) {
103 return NULL;
104 }
105 return pcmk__find_node_in_list(scheduler->nodes, node_name);
106 }