This source file includes following definitions.
- controld_close_attrd_ipc
- node_type
- when
- handle_attr_error
- update_attrd
- update_attrd_list
- update_attrd_remote_node_removed
- update_attrd_clear_failures
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <crm/crm.h>
13 #include <crm/common/attrd_internal.h>
14 #include <crm/common/ipc.h>
15 #include <crm/common/ipc_attrd_internal.h>
16 #include <crm/msg_xml.h>
17
18 #include <pacemaker-controld.h>
19
20 static pcmk_ipc_api_t *attrd_api = NULL;
21
22 void
23 controld_close_attrd_ipc(void)
24 {
25 if (attrd_api != NULL) {
26 crm_trace("Closing connection to pacemaker-attrd");
27 pcmk_disconnect_ipc(attrd_api);
28 pcmk_free_ipc_api(attrd_api);
29 attrd_api = NULL;
30 }
31 }
32
33 static inline const char *
34 node_type(bool is_remote)
35 {
36 return is_remote? "Pacemaker Remote" : "cluster";
37 }
38
39 static inline const char *
40 when(void)
41 {
42 return pcmk_is_set(fsa_input_register, R_SHUTDOWN)? " at shutdown" : "";
43 }
44
45 static void
46 handle_attr_error(void)
47 {
48 if (AM_I_DC) {
49
50
51
52
53 crmd_exit(CRM_EX_FATAL);
54
55 } else if (pcmk_is_set(fsa_input_register, R_SHUTDOWN)) {
56
57 register_fsa_input(C_FSA_INTERNAL, I_FAIL, NULL);
58 }
59 }
60
61 void
62 update_attrd(const char *host, const char *name, const char *value,
63 const char *user_name, gboolean is_remote_node)
64 {
65 int rc = pcmk_rc_ok;
66
67 if (attrd_api == NULL) {
68 rc = pcmk_new_ipc_api(&attrd_api, pcmk_ipc_attrd);
69 }
70 if (rc == pcmk_rc_ok) {
71 uint32_t attrd_opts = pcmk__node_attr_value;
72
73 if (is_remote_node) {
74 pcmk__set_node_attr_flags(attrd_opts, pcmk__node_attr_remote);
75 }
76 rc = pcmk__attrd_api_update(attrd_api, host, name, value,
77 NULL, NULL, user_name, attrd_opts);
78 }
79 if (rc != pcmk_rc_ok) {
80 do_crm_log(AM_I_DC? LOG_CRIT : LOG_ERR,
81 "Could not update attribute %s=%s for %s node %s%s: %s "
82 CRM_XS " rc=%d", name, value, node_type(is_remote_node),
83 host, when(), pcmk_rc_str(rc), rc);
84 handle_attr_error();
85 }
86 }
87
88 void
89 update_attrd_list(GList *attrs, uint32_t opts)
90 {
91 int rc = pcmk_rc_ok;
92
93 if (attrd_api == NULL) {
94 rc = pcmk_new_ipc_api(&attrd_api, pcmk_ipc_attrd);
95 }
96 if (rc == pcmk_rc_ok) {
97 rc = pcmk__attrd_api_update_list(attrd_api, attrs, NULL, NULL, NULL,
98 opts | pcmk__node_attr_value);
99 }
100 if (rc != pcmk_rc_ok) {
101 do_crm_log(AM_I_DC? LOG_CRIT : LOG_ERR,
102 "Could not update multiple node attributes: %s "
103 CRM_XS " rc=%d", pcmk_rc_str(rc), rc);
104 handle_attr_error();
105 }
106 }
107
108 void
109 update_attrd_remote_node_removed(const char *host, const char *user_name)
110 {
111 int rc = pcmk_rc_ok;
112
113 if (attrd_api == NULL) {
114 rc = pcmk_new_ipc_api(&attrd_api, pcmk_ipc_attrd);
115 }
116 if (rc == pcmk_rc_ok) {
117 crm_trace("Asking attribute manager to purge Pacemaker Remote node %s",
118 host);
119 rc = pcmk__attrd_api_purge(attrd_api, host);
120 }
121 if (rc != pcmk_rc_ok) {
122 crm_err("Could not purge Pacemaker Remote node %s "
123 "in attribute manager%s: %s " CRM_XS " rc=%d",
124 host, when(), pcmk_rc_str(rc), rc);
125 }
126 }
127
128 void
129 update_attrd_clear_failures(const char *host, const char *rsc, const char *op,
130 const char *interval_spec, gboolean is_remote_node)
131 {
132 int rc = pcmk_rc_ok;
133
134 if (attrd_api == NULL) {
135 rc = pcmk_new_ipc_api(&attrd_api, pcmk_ipc_attrd);
136 }
137 if (rc == pcmk_rc_ok) {
138 const char *op_desc = pcmk__s(op, "operations");
139 const char *interval_desc = "all";
140 uint32_t attrd_opts = pcmk__node_attr_none;
141
142 if (op != NULL) {
143 interval_desc = pcmk__s(interval_spec, "nonrecurring");
144 }
145 if (is_remote_node) {
146 pcmk__set_node_attr_flags(attrd_opts, pcmk__node_attr_remote);
147 }
148 crm_info("Asking attribute manager to clear failure of %s %s for %s "
149 "on %s node %s", interval_desc, op_desc, rsc,
150 node_type(is_remote_node), host);
151 rc = pcmk__attrd_api_clear_failures(attrd_api, host, rsc, op,
152 interval_spec, NULL, attrd_opts);
153 }
154 if (rc != pcmk_rc_ok) {
155 crm_err("Could not clear failure attributes for %s on %s node %s%s: %s "
156 CRM_XS " rc=%d", pcmk__s(rsc, "all resources"),
157 node_type(is_remote_node), host, when(), pcmk_rc_str(rc), rc);
158 }
159 }