1 /*
2 * Copyright 2022-2023 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_COMMON_IPC_ATTRD_INTERNAL__H
11 # define PCMK__CRM_COMMON_IPC_ATTRD_INTERNAL__H
12
13 #include <glib.h> // GList
14 #include <crm/common/ipc.h> // pcmk_ipc_api_t
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
20 //! Possible types of attribute manager replies
21 enum pcmk__attrd_api_reply {
22 pcmk__attrd_reply_unknown,
23 pcmk__attrd_reply_query,
24 };
25
26 // Information passed with pcmk__attrd_reply_query
27 typedef struct {
28 const char *node;
29 const char *name;
30 const char *value;
31 } pcmk__attrd_query_pair_t;
32
33 /*!
34 * Attribute manager reply passed to event callback
35 *
36 * \note The pointers in the reply are only guaranteed to be meaningful for the
37 * execution of the callback; if the values are needed for later, the
38 * callback should copy them.
39 */
40 typedef struct {
41 enum pcmk__attrd_api_reply reply_type;
42
43 union {
44 // pcmk__attrd_reply_query
45 GList *pairs;
46 } data;
47 } pcmk__attrd_api_reply_t;
48
49 /*!
50 * \internal
51 * \brief Send a request to pacemaker-attrd to clear resource failure
52 *
53 * \param[in,out] api pacemaker-attrd IPC object
54 * \param[in] node Affect only this node (or NULL for all nodes)
55 * \param[in] resource Name of resource to clear (or NULL for all)
56 * \param[in] operation Name of operation to clear (or NULL for all)
57 * \param[in] interval_spec If operation is not NULL, its interval
58 * \param[in] user_name ACL user to pass to pacemaker-attrd
59 * \param[in] options Bitmask of pcmk__node_attr_opts
60 *
61 * \note If \p api is NULL, a new temporary connection will be created
62 * just for this operation and destroyed afterwards. If \p api is
63 * not NULL but is not yet connected to pacemaker-attrd, the object
64 * will be connected for this operation and left connected afterwards.
65 * This allows for reusing an IPC connection.
66 *
67 * \return Standard Pacemaker return code
68 */
69 int pcmk__attrd_api_clear_failures(pcmk_ipc_api_t *api, const char *node,
70 const char *resource, const char *operation,
71 const char *interval_spec, const char *user_name,
72 uint32_t options);
73
74 /*!
75 * \internal
76 *
77 * \brief Delete a previously set attribute by setting its value to NULL
78 *
79 * \param[in,out] api Connection to pacemaker-attrd (or NULL to use
80 * a temporary new connection)
81 * \param[in] node Delete attribute for this node (or NULL for local)
82 * \param[in] name Attribute name
83 * \param[in] options Bitmask of pcmk__node_attr_opts
84 *
85 * \return Standard Pacemaker return code
86 */
87 int pcmk__attrd_api_delete(pcmk_ipc_api_t *api, const char *node, const char *name,
88 uint32_t options);
89
90 /*!
91 * \internal
92 * \brief Purge a node from pacemaker-attrd
93 *
94 * \param[in,out] api pacemaker-attrd IPC object
95 * \param[in] node Node to remove
96 *
97 * \note If \p api is NULL, a new temporary connection will be created
98 * just for this operation and destroyed afterwards. If \p api is
99 * not NULL but is not yet connected to pacemaker-attrd, the object
100 * will be connected for this operation and left connected afterwards.
101 * This allows for reusing an IPC connection.
102 *
103 * \return Standard Pacemaker return code
104 */
105 int pcmk__attrd_api_purge(pcmk_ipc_api_t *api, const char *node);
106
107 /*!
108 * \internal
109 * \brief Get the value of an attribute from pacemaker-attrd
110 *
111 * \param[in,out] api Connection to pacemaker-attrd
112 * \param[in] node Look up the attribute for this node
113 * (or NULL for the local node)
114 * \param[in] name Attribute name
115 * \param[in] options Bitmask of pcmk__node_attr_opts
116 *
117 * \note Passing pcmk__node_attr_query_all will cause the function to query
118 * the value of \p name on all nodes, regardless of the value of \p node.
119 *
120 * \return Standard Pacemaker return code
121 */
122 int pcmk__attrd_api_query(pcmk_ipc_api_t *api, const char *node, const char *name,
123 uint32_t options);
124
125 /*!
126 * \internal
127 * \brief Tell pacemaker-attrd to update the CIB with current values
128 *
129 * \param[in,out] api pacemaker-attrd IPC object
130 * \param[in] node Affect only this node (or NULL for all nodes)
131 *
132 * \note If \p api is NULL, a new temporary connection will be created
133 * just for this operation and destroyed afterwards. If \p api is
134 * not NULL but is not yet connected to pacemaker-attrd, the object
135 * will be connected for this operation and left connected afterwards.
136 * This allows for reusing an IPC connection.
137 *
138 * \return Standard Pacemaker return code
139 */
140 int pcmk__attrd_api_refresh(pcmk_ipc_api_t *api, const char *node);
141
142 /*!
143 * \internal
144 * \brief Update an attribute's value, time to wait, or both
145 *
146 * \param[in,out] api pacemaker-attrd IPC object
147 * \param[in] node Affect only this node (or NULL for current node)
148 * \param[in] name Attribute name
149 * \param[in] value The attribute's new value, or NULL to unset
150 * \param[in] dampen The new time to wait value, or NULL to unset
151 * \param[in] set ID of attribute set to use (or NULL for first)
152 * \param[in] user_name ACL user to pass to pacemaker-attrd
153 * \param[in] options Bitmask of pcmk__node_attr_opts
154 *
155 * \note If \p api is NULL, a new temporary connection will be created
156 * just for this operation and destroyed afterwards. If \p api is
157 * not NULL but is not yet connected to pacemaker-attrd, the object
158 * will be connected for this operation and left connected afterwards.
159 * This allows for reusing an IPC connection.
160 *
161 * \return Standard Pacemaker return code
162 */
163 int pcmk__attrd_api_update(pcmk_ipc_api_t *api, const char *node, const char *name,
164 const char *value, const char *dampen, const char *set,
165 const char *user_name, uint32_t options);
166
167 /*!
168 * \internal
169 * \brief Like pcmk__attrd_api_update, but for multiple attributes at once
170 *
171 * \param[in,out] api pacemaker-attrd IPC object
172 * \param[in,out] attrs A list of pcmk__attr_query_pair_t structs
173 * \param[in] dampen The new time to wait value, or NULL to unset
174 * \param[in] set ID of attribute set to use (or NULL for first)
175 * \param[in] user_name ACL user to pass to pacemaker-attrd
176 * \param[in] options Bitmask of pcmk__node_attr_opts
177 *
178 * \note If \p api is NULL, a new temporary connection will be created
179 * just for this operation and destroyed afterwards. If \p api is
180 * not NULL but is not yet connected to pacemaker-attrd, the object
181 * will be connected for this operation and left connected afterwards.
182 * This allows for reusing an IPC connection.
183 *
184 * \note Not all attrd versions support setting multiple attributes at once.
185 * For those servers that do not, this function will fall back to just
186 * sending a separate IPC request for each attribute.
187 *
188 * \return Standard Pacemaker return code
189 */
190 int pcmk__attrd_api_update_list(pcmk_ipc_api_t *api, GList *attrs,
191 const char *dampen, const char *set,
192 const char *user_name, uint32_t options);
193
194 #ifdef __cplusplus
195 }
196 #endif
197
198 #endif // PCMK__CRM_COMMON_IPC_ATTRD_INTERNAL__H