This source file includes following definitions.
- log_attrd_error
- update_attrd_helper
- update_attrd
- update_attrd_remote_node_removed
- update_attrd_clear_failures
1
2
3
4
5
6
7
8 #include <crm_internal.h>
9
10 #include <crm/crm.h>
11 #include <crm/attrd.h>
12 #include <crm/msg_xml.h>
13
14 #include <crmd_fsa.h>
15 #include <crmd_utils.h>
16 #include <crmd_messages.h>
17
18 crm_ipc_t *attrd_ipc = NULL;
19
20 static void
21 log_attrd_error(const char *host, const char *name, const char *value,
22 gboolean is_remote, char command, int rc)
23 {
24 const char *display_command;
25 const char *node_type = (is_remote? "Pacemaker Remote" : "cluster");
26 gboolean shutting_down = is_set(fsa_input_register, R_SHUTDOWN);
27 const char *when = (shutting_down? " at shutdown" : "");
28
29 switch (command) {
30 case 'R':
31 display_command = "refresh";
32 break;
33 case 'C':
34 display_command = "purge";
35 break;
36 default:
37 display_command = NULL;
38 }
39
40 if (display_command) {
41 crm_err("Could not request %s of %s node %s%s: %s (%d)",
42 display_command, node_type, host, when, pcmk_strerror(rc), rc);
43 } else {
44 crm_err("Could not request update of %s=%s for %s node %s%s: %s (%d)",
45 name, value, node_type, host, when, pcmk_strerror(rc), rc);
46 }
47
48
49 if ((command == 'U') && shutting_down) {
50 register_fsa_input(C_FSA_INTERNAL, I_FAIL, NULL);
51 }
52 }
53
54 static void
55 update_attrd_helper(const char *host, const char *name, const char *value,
56 const char *interval, const char *user_name,
57 gboolean is_remote_node, char command)
58 {
59 int rc;
60 int max = 5;
61 int attrd_opts = attrd_opt_none;
62
63 if (is_remote_node) {
64 attrd_opts |= attrd_opt_remote;
65 }
66
67 if (attrd_ipc == NULL) {
68 attrd_ipc = crm_ipc_new(T_ATTRD, 0);
69 }
70
71 do {
72 if (crm_ipc_connected(attrd_ipc) == FALSE) {
73 crm_ipc_close(attrd_ipc);
74 crm_info("Connecting to attribute manager ... %d retries remaining",
75 max);
76 if (crm_ipc_connect(attrd_ipc) == FALSE) {
77 crm_perror(LOG_INFO, "Connection to attribute manager failed");
78 }
79 }
80
81 if (command) {
82 rc = attrd_update_delegate(attrd_ipc, command, host, name, value,
83 XML_CIB_TAG_STATUS, NULL, NULL,
84 user_name, attrd_opts);
85 } else {
86
87 rc = attrd_clear_delegate(attrd_ipc, host, name, value, interval,
88 user_name, attrd_opts);
89 }
90
91 if (rc == pcmk_ok) {
92 break;
93
94 } else if (rc != -EAGAIN && rc != -EALREADY) {
95 crm_info("Disconnecting from attribute manager: %s (%d)",
96 pcmk_strerror(rc), rc);
97 crm_ipc_close(attrd_ipc);
98 }
99
100 sleep(5 - max);
101
102 } while (max--);
103
104 if (rc != pcmk_ok) {
105 log_attrd_error(host, name, value, is_remote_node, command, rc);
106 }
107 }
108
109 void
110 update_attrd(const char *host, const char *name, const char *value,
111 const char *user_name, gboolean is_remote_node)
112 {
113 update_attrd_helper(host, name, value, NULL, user_name, is_remote_node,
114 'U');
115 }
116
117 void
118 update_attrd_remote_node_removed(const char *host, const char *user_name)
119 {
120 crm_trace("Asking attrd to purge Pacemaker Remote node %s", host);
121 update_attrd_helper(host, NULL, NULL, NULL, user_name, TRUE, 'C');
122 }
123
124 void
125 update_attrd_clear_failures(const char *host, const char *rsc, const char *op,
126 const char *interval, gboolean is_remote_node)
127 {
128 crm_info("Asking attrd to clear failure of %s %s for %s on %s node %s",
129 (op? op : "all operations"),
130 (interval? interval : "at all intervals"),
131 rsc, (is_remote_node? "Pacemaker Remote" : "cluster"), host);
132 update_attrd_helper(host, rsc, op, interval, NULL, is_remote_node, 0);
133 }