1 /*
2 * Copyright 2019-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 #ifndef PCMK__PCMKI_PCMKI_FENCE__H
10 #define PCMK__PCMKI_PCMKI_FENCE__H
11
12 #include <crm/stonith-ng.h>
13 #include <crm/common/output_internal.h>
14
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18
19 /*!
20 * \brief Control how much of the fencing history is output.
21 */
22 enum pcmk__fence_history {
23 pcmk__fence_history_none,
24 pcmk__fence_history_reduced,
25 pcmk__fence_history_full
26 };
27
28 /*!
29 * \brief Ask the cluster to perform fencing
30 *
31 * \note This is the internal version of pcmk_request_fencing(). External users
32 * of the pacemaker API should use that function instead.
33 *
34 * \param[in,out] st A connection to the fencer API
35 * \param[in] target The node that should be fenced
36 * \param[in] action The fencing action (on, off, reboot) to perform
37 * \param[in] name Who requested the fence action?
38 * \param[in] timeout How long to wait for operation to complete (in ms)
39 * \param[in] tolerance If a successful action for \p target happened within
40 * this many milliseconds, return success without
41 * performing the action again
42 * \param[in] delay Apply this delay (in milliseconds) before initiating
43 * fencing action (a value of -1 applies no delay and
44 * disables any fencing delay from pcmk_delay_base and
45 * pcmk_delay_max)
46 * \param[out] reason If not NULL, where to put descriptive failure reason
47 *
48 * \return Standard Pacemaker return code
49 * \note If \p reason is not NULL, the caller is responsible for freeing its
50 * returned value.
51 * \todo delay is eventually used with pcmk__create_timer() and should be guint
52 */
53 int pcmk__request_fencing(stonith_t *st, const char *target, const char *action,
54 const char *name, unsigned int timeout,
55 unsigned int tolerance, int delay, char **reason);
56
57 /*!
58 * \brief List the fencing operations that have occurred for a specific node
59 *
60 * \note This is the internal version of pcmk_fence_history(). External users
61 * of the pacemaker API should use that function instead.
62 *
63 * \note \p out should be initialized with pcmk__output_new() before calling this
64 * function and destroyed with out->finish and pcmk__output_free() before
65 * reusing it with any other functions in this library.
66 *
67 * \param[in,out] out The output functions structure
68 * \param[in,out] st A connection to the fencer API
69 * \param[in] target The node to get history for
70 * \param[in] timeout How long to wait for operation to complete (in ms)
71 * \param[in] verbose Include additional output
72 * \param[in] broadcast Gather fencing history from all nodes
73 * \param[in] cleanup Clean up fencing history after listing
74 *
75 * \return Standard Pacemaker return code
76 */
77 int pcmk__fence_history(pcmk__output_t *out, stonith_t *st, const char *target,
78 unsigned int timeout, int verbose, bool broadcast,
79 bool cleanup);
80
81 /*!
82 * \brief List all installed fence agents
83 *
84 * \note This is the internal version of pcmk_fence_installed(). External users
85 * of the pacemaker API should use that function instead.
86 *
87 * \note \p out should be initialized with pcmk__output_new() before calling this
88 * function and destroyed with out->finish and pcmk__output_free() before
89 * reusing it with any other functions in this library.
90 *
91 * \param[in,out] out The output functions structure
92 * \param[in,out] st A connection to the fencer API
93 *
94 * \return Standard Pacemaker return code
95 */
96 int pcmk__fence_installed(pcmk__output_t *out, stonith_t *st);
97
98 /*!
99 * \brief When was a device last fenced?
100 *
101 * \note This is the internal version of pcmk_fence_last(). External users
102 * of the pacemaker API should use that function instead.
103 *
104 * \note \p out should be initialized with pcmk__output_new() before calling this
105 * function and destroyed with out->finish and pcmk__output_free() before
106 * reusing it with any other functions in this library.
107 *
108 * \param[in,out] out The output functions structure.
109 * \param[in] target The node that was fenced.
110 * \param[in] as_nodeid
111 *
112 * \return Standard Pacemaker return code
113 */
114 int pcmk__fence_last(pcmk__output_t *out, const char *target, bool as_nodeid);
115
116 /*!
117 * \brief List nodes that can be fenced
118 *
119 * \note This is the internal version of pcmk_fence_list_targets(). External users
120 * of the pacemaker API should use that function instead.
121 *
122 * \note \p out should be initialized with pcmk__output_new() before calling this
123 * function and destroyed with out->finish and pcmk__output_free() before
124 * reusing it with any other functions in this library.
125 *
126 * \param[in,out] out The output functions structure
127 * \param[in,out] st A connection to the fencer API
128 * \param[in] device_id Resource ID of fence device to check
129 * \param[in] timeout How long to wait for operation to complete (in ms)
130 *
131 * \return Standard Pacemaker return code
132 */
133 int pcmk__fence_list_targets(pcmk__output_t *out, stonith_t *st,
134 const char *device_id, unsigned int timeout);
135
136 /*!
137 * \brief Get metadata for a fence agent
138 *
139 * \note This is the internal version of pcmk_fence_metadata(). External users
140 * of the pacemaker API should use that function instead.
141 *
142 * \note \p out should be initialized with pcmk__output_new() before calling this
143 * function and destroyed with out->finish and pcmk__output_free() before
144 * reusing it with any other functions in this library.
145 *
146 * \param[in,out] out The output functions structure
147 * \param[in,out] st A connection to the fencer API
148 * \param[in] agent The fence agent to get metadata for
149 * \param[in] timeout How long to wait for the operation to complete (in ms)
150 *
151 * \return Standard Pacemaker return code
152 */
153 int pcmk__fence_metadata(pcmk__output_t *out, stonith_t *st, const char *agent,
154 unsigned int timeout);
155
156 /*!
157 * \brief List registered fence devices
158 *
159 * \note This is the internal version of pcmk_fence_metadata(). External users
160 * of the pacemaker API should use that function instead.
161 *
162 * \note \p out should be initialized with pcmk__output_new() before calling this
163 * function and destroyed with out->finish and pcmk__output_free() before
164 * reusing it with any other functions in this library.
165 *
166 * \param[in,out] out The output functions structure
167 * \param[in,out] st A connection to the fencer API
168 * \param[in] target If not NULL, return only devices that can fence this
169 * \param[in] timeout How long to wait for the operation to complete (in ms)
170 *
171 * \return Standard Pacemaker return code
172 */
173 int pcmk__fence_registered(pcmk__output_t *out, stonith_t *st,
174 const char *target, unsigned int timeout);
175
176 /*!
177 * \brief Register a fencing level for a specific node, node regex, or attribute
178 *
179 * \note This is the internal version of pcmk_fence_register_level(). External users
180 * of the pacemaker API should use that function instead.
181 *
182 * \p target can take three different forms:
183 * - name=value, in which case \p target is an attribute.
184 * - @pattern, in which case \p target is a node regex.
185 * - Otherwise, \p target is a node name.
186 *
187 * \param[in,out] st A connection to the fencer API
188 * \param[in] target The object to register a fencing level for
189 * \param[in] fence_level Index number of level to add
190 * \param[in] devices Devices to use in level as a list of char *
191 *
192 * \return Standard Pacemaker return code
193 */
194 int pcmk__fence_register_level(stonith_t *st, const char *target,
195 int fence_level, GList *devices);
196
197 /*!
198 * \brief Unregister a fencing level for specific node, node regex, or attribute
199 *
200 * \note This is the internal version of pcmk_fence_unregister_level(). External users
201 * of the pacemaker API should use that function instead.
202 *
203 * \p target can take three different forms:
204 * - name=value, in which case \p target is an attribute.
205 * - @pattern, in which case \p target is a node regex.
206 * - Otherwise, \p target is a node name.
207 *
208 * \param[in,out] st A connection to the fencer API
209 * \param[in] target The object to unregister a fencing level for
210 * \param[in] fence_level Index number of level to remove
211 *
212 * \return Standard Pacemaker return code
213 */
214 int pcmk__fence_unregister_level(stonith_t *st, const char *target,
215 int fence_level);
216
217 /*!
218 * \brief Validate a fence device configuration
219 *
220 * \note This is the internal version of pcmk_stonith_validate(). External users
221 * of the pacemaker API should use that function instead.
222 *
223 * \note \p out should be initialized with pcmk__output_new() before calling this
224 * function and destroyed with out->finish and pcmk__output_free() before
225 * reusing it with any other functions in this library.
226 *
227 * \param[in,out] out The output functions structure
228 * \param[in,out] st A connection to the fencer API
229 * \param[in] agent The agent to validate (for example, "fence_xvm")
230 * \param[in] id Fence device ID (may be NULL)
231 * \param[in] params Fence device configuration parameters
232 * \param[in] timeout How long to wait for the operation to complete (in ms)
233 *
234 * \return Standard Pacemaker return code
235 */
236 int pcmk__fence_validate(pcmk__output_t *out, stonith_t *st, const char *agent,
237 const char *id, GHashTable *params, unsigned int timeout);
238
239 /*!
240 * \brief Fetch fencing history, optionally reducing it
241 *
242 * \param[in,out] st A connection to the fencer API
243 * \param[out] stonith_history Destination for storing the history
244 * \param[in] fence_history How much of the fencing history to display
245 *
246 * \return Standard Pacemaker return code
247 */
248 int
249 pcmk__get_fencing_history(stonith_t *st, stonith_history_t **stonith_history,
250 enum pcmk__fence_history fence_history);
251
252 #ifdef __cplusplus
253 }
254 #endif
255
256 #endif // PCMK__PCMKI_PCMKI_FENCE__H