This source file includes following definitions.
- do_cib_updated
- do_cib_replaced
- controld_disconnect_cib_manager
- do_cib_control
- crmd_cib_smart_opt
- controld_action_is_recordable
- cib_delete_callback
- controld_delete_node_state
- controld_delete_resource_history
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <unistd.h>
13
14 #include <crm/common/alerts_internal.h>
15 #include <crm/common/xml.h>
16 #include <crm/crm.h>
17 #include <crm/msg_xml.h>
18
19 #include <pacemaker-controld.h>
20
21 int cib_retries = 0;
22
23 void
24 do_cib_updated(const char *event, xmlNode * msg)
25 {
26 if (pcmk__alert_in_patchset(msg, TRUE)) {
27 mainloop_set_trigger(config_read);
28 }
29 }
30
31 void
32 do_cib_replaced(const char *event, xmlNode * msg)
33 {
34 crm_debug("Updating the CIB after a replace: DC=%s", pcmk__btoa(AM_I_DC));
35 if (AM_I_DC == FALSE) {
36 return;
37
38 } else if ((fsa_state == S_FINALIZE_JOIN)
39 && pcmk_is_set(fsa_input_register, R_CIB_ASKED)) {
40
41 return;
42 }
43
44
45 populate_cib_nodes(node_update_quick|node_update_all, __func__);
46 register_fsa_input(C_FSA_INTERNAL, I_ELECTION, NULL);
47 }
48
49 void
50 controld_disconnect_cib_manager(void)
51 {
52 CRM_ASSERT(fsa_cib_conn != NULL);
53
54 crm_info("Disconnecting from the CIB manager");
55
56 controld_clear_fsa_input_flags(R_CIB_CONNECTED);
57
58 fsa_cib_conn->cmds->del_notify_callback(fsa_cib_conn, T_CIB_REPLACE_NOTIFY, do_cib_replaced);
59 fsa_cib_conn->cmds->del_notify_callback(fsa_cib_conn, T_CIB_DIFF_NOTIFY, do_cib_updated);
60 cib_free_callbacks(fsa_cib_conn);
61 if (fsa_cib_conn->state != cib_disconnected) {
62
63 fsa_cib_conn->cmds->set_slave(fsa_cib_conn, cib_scope_local | cib_discard_reply);
64 fsa_cib_conn->cmds->signoff(fsa_cib_conn);
65 }
66
67 crm_notice("Disconnected from the CIB manager");
68 }
69
70
71 void
72 do_cib_control(long long action,
73 enum crmd_fsa_cause cause,
74 enum crmd_fsa_state cur_state,
75 enum crmd_fsa_input current_input, fsa_data_t * msg_data)
76 {
77 CRM_ASSERT(fsa_cib_conn != NULL);
78
79 if (action & A_CIB_STOP) {
80
81 if (fsa_cib_conn->state != cib_disconnected && last_resource_update != 0) {
82 crm_info("Waiting for resource update %d to complete", last_resource_update);
83 crmd_fsa_stall(FALSE);
84 return;
85 }
86
87 controld_disconnect_cib_manager();
88
89 }
90
91 if (action & A_CIB_START) {
92 int rc = pcmk_ok;
93
94 if (cur_state == S_STOPPING) {
95 crm_err("Ignoring request to connect to the CIB manager after shutdown");
96 return;
97 }
98
99 rc = fsa_cib_conn->cmds->signon(fsa_cib_conn, CRM_SYSTEM_CRMD, cib_command_nonblocking);
100
101 if (rc != pcmk_ok) {
102
103 sleep(1);
104 rc = fsa_cib_conn->cmds->signon(fsa_cib_conn, CRM_SYSTEM_CRMD, cib_command_nonblocking);
105 }
106
107 if (rc != pcmk_ok) {
108 crm_info("Could not connect to the CIB manager: %s", pcmk_strerror(rc));
109
110 } else if (pcmk_ok !=
111 fsa_cib_conn->cmds->set_connection_dnotify(fsa_cib_conn,
112 crmd_cib_connection_destroy)) {
113 crm_err("Could not set dnotify callback");
114
115 } else if (pcmk_ok !=
116 fsa_cib_conn->cmds->add_notify_callback(fsa_cib_conn, T_CIB_REPLACE_NOTIFY,
117 do_cib_replaced)) {
118 crm_err("Could not set CIB notification callback (replace)");
119
120 } else if (pcmk_ok !=
121 fsa_cib_conn->cmds->add_notify_callback(fsa_cib_conn, T_CIB_DIFF_NOTIFY,
122 do_cib_updated)) {
123 crm_err("Could not set CIB notification callback (update)");
124
125 } else {
126 controld_set_fsa_input_flags(R_CIB_CONNECTED);
127 cib_retries = 0;
128 }
129
130 if (!pcmk_is_set(fsa_input_register, R_CIB_CONNECTED)) {
131
132 cib_retries++;
133 crm_warn("Couldn't complete CIB registration %d"
134 " times... pause and retry", cib_retries);
135
136 if (cib_retries < 30) {
137 controld_start_timer(wait_timer);
138 crmd_fsa_stall(FALSE);
139
140 } else {
141 crm_err("Could not complete CIB"
142 " registration %d times..." " hard error", cib_retries);
143 register_fsa_error(C_FSA_INTERNAL, I_ERROR, NULL);
144 }
145 }
146 }
147 }
148
149
150
151
152
153
154
155 int crmd_cib_smart_opt()
156 {
157 int call_opt = cib_quorum_override;
158
159 if (fsa_state == S_ELECTION || fsa_state == S_PENDING) {
160 crm_info("Sending update to local CIB in state: %s", fsa_state2string(fsa_state));
161 cib__set_call_options(call_opt, "update", cib_scope_local);
162 }
163 return call_opt;
164 }
165
166
167
168
169
170
171
172
173
174 bool
175 controld_action_is_recordable(const char *action)
176 {
177 return !pcmk__strcase_any_of(action, CRMD_ACTION_CANCEL, CRMD_ACTION_DELETE,
178 CRMD_ACTION_NOTIFY, CRMD_ACTION_METADATA, NULL);
179 }
180
181 static void
182 cib_delete_callback(xmlNode *msg, int call_id, int rc, xmlNode *output,
183 void *user_data)
184 {
185 char *desc = user_data;
186
187 if (rc == 0) {
188 crm_debug("Deletion of %s (via CIB call %d) succeeded", desc, call_id);
189 } else {
190 crm_warn("Deletion of %s (via CIB call %d) failed: %s " CRM_XS " rc=%d",
191 desc, call_id, pcmk_strerror(rc), rc);
192 }
193 }
194
195
196
197
198 #define XPATH_NODE_STATE "//" XML_CIB_TAG_STATE "[@" XML_ATTR_UNAME "='%s']"
199
200
201 #define XPATH_NODE_LRM XPATH_NODE_STATE "/" XML_CIB_TAG_LRM
202
203
204 #define XPATH_NODE_LRM_UNLOCKED XPATH_NODE_STATE "//" XML_LRM_TAG_RSC_OP \
205 "|" XPATH_NODE_STATE \
206 "//" XML_LRM_TAG_RESOURCE \
207 "[not(@" XML_CONFIG_ATTR_SHUTDOWN_LOCK ")]"
208
209
210 #define XPATH_NODE_ATTRS XPATH_NODE_STATE "/" XML_TAG_TRANSIENT_NODEATTRS
211
212
213 #define XPATH_NODE_ALL XPATH_NODE_STATE "/*"
214
215
216 #define XPATH_NODE_ALL_UNLOCKED XPATH_NODE_LRM_UNLOCKED "|" XPATH_NODE_ATTRS
217
218
219
220
221
222
223
224
225
226 void
227 controld_delete_node_state(const char *uname, enum controld_section_e section,
228 int options)
229 {
230 char *xpath = NULL;
231 char *desc = NULL;
232
233 CRM_CHECK(uname != NULL, return);
234 switch (section) {
235 case controld_section_lrm:
236 xpath = crm_strdup_printf(XPATH_NODE_LRM, uname);
237 desc = crm_strdup_printf("resource history for node %s", uname);
238 break;
239 case controld_section_lrm_unlocked:
240 xpath = crm_strdup_printf(XPATH_NODE_LRM_UNLOCKED, uname, uname);
241 desc = crm_strdup_printf("resource history (other than shutdown "
242 "locks) for node %s", uname);
243 break;
244 case controld_section_attrs:
245 xpath = crm_strdup_printf(XPATH_NODE_ATTRS, uname);
246 desc = crm_strdup_printf("transient attributes for node %s", uname);
247 break;
248 case controld_section_all:
249 xpath = crm_strdup_printf(XPATH_NODE_ALL, uname);
250 desc = crm_strdup_printf("all state for node %s", uname);
251 break;
252 case controld_section_all_unlocked:
253 xpath = crm_strdup_printf(XPATH_NODE_ALL_UNLOCKED,
254 uname, uname, uname);
255 desc = crm_strdup_printf("all state (other than shutdown locks) "
256 "for node %s", uname);
257 break;
258 }
259
260 if (fsa_cib_conn == NULL) {
261 crm_warn("Unable to delete %s: no CIB connection", desc);
262 free(desc);
263 } else {
264 int call_id;
265
266 cib__set_call_options(options, "node state deletion",
267 cib_quorum_override|cib_xpath|cib_multiple);
268 call_id = fsa_cib_conn->cmds->remove(fsa_cib_conn, xpath, NULL, options);
269 crm_info("Deleting %s (via CIB call %d) " CRM_XS " xpath=%s",
270 desc, call_id, xpath);
271 fsa_register_cib_callback(call_id, FALSE, desc, cib_delete_callback);
272
273 }
274 free(xpath);
275 }
276
277
278 #define XPATH_RESOURCE_HISTORY "//" XML_CIB_TAG_STATE \
279 "[@" XML_ATTR_UNAME "='%s']/" \
280 XML_CIB_TAG_LRM "/" XML_LRM_TAG_RESOURCES \
281 "/" XML_LRM_TAG_RESOURCE \
282 "[@" XML_ATTR_ID "='%s']"
283
284
285
286
287
288
289
290
291
292
293
294
295
296 int
297 controld_delete_resource_history(const char *rsc_id, const char *node,
298 const char *user_name, int call_options)
299 {
300 char *desc = NULL;
301 char *xpath = NULL;
302 int rc = pcmk_rc_ok;
303
304 CRM_CHECK((rsc_id != NULL) && (node != NULL), return EINVAL);
305
306 desc = crm_strdup_printf("resource history for %s on %s", rsc_id, node);
307 if (fsa_cib_conn == NULL) {
308 crm_err("Unable to clear %s: no CIB connection", desc);
309 free(desc);
310 return ENOTCONN;
311 }
312
313
314 xpath = crm_strdup_printf(XPATH_RESOURCE_HISTORY, node, rsc_id);
315 rc = cib_internal_op(fsa_cib_conn, CIB_OP_DELETE, NULL, xpath, NULL,
316 NULL, call_options|cib_xpath, user_name);
317
318 if (rc < 0) {
319 rc = pcmk_legacy2rc(rc);
320 crm_err("Could not delete resource status of %s on %s%s%s: %s "
321 CRM_XS " rc=%d", rsc_id, node,
322 (user_name? " for user " : ""), (user_name? user_name : ""),
323 pcmk_rc_str(rc), rc);
324 free(desc);
325 free(xpath);
326 return rc;
327 }
328
329 if (pcmk_is_set(call_options, cib_sync_call)) {
330 if (pcmk_is_set(call_options, cib_dryrun)) {
331 crm_debug("Deletion of %s would succeed", desc);
332 } else {
333 crm_debug("Deletion of %s succeeded", desc);
334 }
335 free(desc);
336
337 } else {
338 crm_info("Clearing %s (via CIB call %d) " CRM_XS " xpath=%s",
339 desc, rc, xpath);
340 fsa_register_cib_callback(rc, FALSE, desc, cib_delete_callback);
341
342 }
343
344 free(xpath);
345 return pcmk_rc_ok;
346 }