1 /*
2 * Copyright 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 #include <crm/cib/internal.h>
12 #include <crm/common/output.h>
13 #include <crm/common/results.h>
14 #include <crm/common/scheduler.h>
15 #include <pacemaker-internal.h>
16 #include <pacemaker.h>
17
18 #include "libpacemaker_private.h"
19
20 /*!
21 * \internal
22 * \brief Set up a pcmk__output_t, (optionally) cib_t, and
23 * (optionally) pcmk_scheduler_t for use in implementing
24 * public/private API function pairs
25 *
26 * \param[in,out] out Where to store a \c pcmk__output_t object
27 * \param[in,out] cib Where to store a \c cib_t object
28 * (may be \c NULL if a CIB is not needed)
29 * \param[in,out] scheduler Where to store a \c pcmk_scheduler_t object
30 * (may be \c NULL if a scheduler is not needed)
31 * \param[in,out] xml Where to write any result XML
32 *
33 * \note The \p cib and \p scheduler arguments will only be valid if there
34 * are no errors in this function. However, \p out will always be
35 * valid unless there are errors setting it up so that other errors
36 * may still be reported.
37 *
38 * \return Standard Pacemaker return code
39 */
40 int
41 pcmk__setup_output_cib_sched(pcmk__output_t **out, cib_t **cib,
/* ![[previous]](../icons/n_left.png)
![[next]](../icons/n_right.png)
![[first]](../icons/n_first.png)
![[last]](../icons/n_last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
42 pcmk_scheduler_t **scheduler, xmlNode **xml)
43 {
44 int rc = pcmk_rc_ok;
45
46 rc = pcmk__xml_output_new(out, xml);
47 if (rc != pcmk_rc_ok) {
48 return rc;
49 }
50
51 if (cib != NULL) {
52 *cib = cib_new();
53 if (*cib == NULL) {
54 return pcmk_rc_cib_corrupt;
55 }
56
57 rc = (*cib)->cmds->signon(*cib, crm_system_name, cib_command);
58 rc = pcmk_legacy2rc(rc);
59
60 if (rc != pcmk_rc_ok) {
61 cib__clean_up_connection(cib);
62 return rc;
63 }
64 }
65
66 if (scheduler != NULL) {
67 rc = pcmk__init_scheduler(*out, NULL, NULL, scheduler);
68 if (rc != pcmk_rc_ok && cib != NULL) {
69 cib__clean_up_connection(cib);
70 return rc;
71 }
72
73 pcmk__unpack_constraints(*scheduler);
74 }
75
76 pcmk__register_lib_messages(*out);
77 return rc;
78 }