1
2
3
4
5
6
7
8
9
10 #ifndef PACEMAKER_ATTRD__H
11 # define PACEMAKER_ATTRD__H
12
13 #include <regex.h>
14 #include <glib.h>
15 #include <crm/crm.h>
16 #include <crm/cluster.h>
17 #include <crm/cluster/election_internal.h>
18 #include <crm/common/messages_internal.h>
19 #include <crm/cib/cib_types.h>
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 #define ATTRD_PROTOCOL_VERSION "7"
48
49 #define ATTRD_SUPPORTS_MULTI_MESSAGE(x) ((x) >= 4)
50 #define ATTRD_SUPPORTS_CONFIRMATION(x) ((x) >= 5)
51
52 #define attrd_send_ack(client, id, flags) \
53 pcmk__ipc_send_ack((client), (id), (flags), PCMK__XE_ACK, \
54 ATTRD_PROTOCOL_VERSION, CRM_EX_INDETERMINATE)
55
56 void attrd_init_mainloop(void);
57 void attrd_run_mainloop(void);
58
59 void attrd_set_requesting_shutdown(void);
60 void attrd_clear_requesting_shutdown(void);
61 void attrd_free_waitlist(void);
62 bool attrd_shutting_down(bool if_requested);
63 void attrd_shutdown(int nsig);
64 void attrd_init_ipc(void);
65 void attrd_ipc_fini(void);
66
67 int attrd_cib_connect(int max_retry);
68 void attrd_cib_disconnect(void);
69 void attrd_cib_init(void);
70 void attrd_cib_erase_transient_attrs(const char *node);
71
72 bool attrd_value_needs_expansion(const char *value);
73 int attrd_expand_value(const char *value, const char *old_value);
74
75
76 #define ATTRD_RE_CLEAR_ALL \
77 "^(" PCMK__FAIL_COUNT_PREFIX "|" PCMK__LAST_FAILURE_PREFIX ")-"
78
79
80
81
82 #define ATTRD_RE_CLEAR_ONE ATTRD_RE_CLEAR_ALL "%s#.+_[0-9]+$"
83
84
85
86
87 #define ATTRD_RE_CLEAR_OP ATTRD_RE_CLEAR_ALL "%s#%s_%u$"
88
89 int attrd_failure_regex(regex_t *regex, const char *rsc, const char *op,
90 guint interval_ms);
91
92 extern cib_t *the_cib;
93 extern crm_exit_t attrd_exit_status;
94
95
96
97 extern lrmd_t *the_lrmd;
98 extern crm_trigger_t *attrd_config_read;
99
100 void attrd_lrmd_disconnect(void);
101 gboolean attrd_read_options(gpointer user_data);
102 int attrd_send_attribute_alert(const char *node, int nodeid,
103 const char *attr, const char *value);
104
105
106 void attrd_election_init(void);
107 void attrd_start_election_if_needed(void);
108 bool attrd_election_won(void);
109 void attrd_handle_election_op(const pcmk__node_status_t *peer, xmlNode *xml);
110 bool attrd_check_for_new_writer(const pcmk__node_status_t *peer,
111 const xmlNode *xml);
112 void attrd_declare_winner(void);
113 void attrd_remove_voter(const pcmk__node_status_t *peer);
114 void attrd_xml_add_writer(xmlNode *xml);
115
116 enum attrd_attr_flags {
117 attrd_attr_none = 0U,
118 attrd_attr_changed = (1U << 0),
119 attrd_attr_uuid_missing = (1U << 1),
120 attrd_attr_is_private = (1U << 2),
121 attrd_attr_force_write = (1U << 3),
122 };
123
124 typedef struct attribute_s {
125 char *id;
126 char *set_type;
127 char *set_id;
128 char *user;
129 int update;
130 int timeout_ms;
131 uint32_t flags;
132 GHashTable *values;
133 mainloop_timer_t *timer;
134 } attribute_t;
135
136 #define attrd_set_attr_flags(attr, flags_to_set) do { \
137 (attr)->flags = pcmk__set_flags_as(__func__, __LINE__, \
138 LOG_TRACE, "Value for attribute", (attr)->id, \
139 (attr)->flags, (flags_to_set), #flags_to_set); \
140 } while (0)
141
142 #define attrd_clear_attr_flags(attr, flags_to_clear) do { \
143 (attr)->flags = pcmk__clear_flags_as(__func__, __LINE__, \
144 LOG_TRACE, "Value for attribute", (attr)->id, \
145 (attr)->flags, (flags_to_clear), #flags_to_clear); \
146 } while (0)
147
148 enum attrd_value_flags {
149 attrd_value_none = 0U,
150 attrd_value_remote = (1U << 0),
151 attrd_value_from_peer = (1U << 1),
152 };
153
154 typedef struct attribute_value_s {
155 char *nodename;
156 char *current;
157 char *requested;
158 uint32_t nodeid;
159 uint32_t flags;
160 } attribute_value_t;
161
162 #define attrd_set_value_flags(attr_value, flags_to_set) do { \
163 (attr_value)->flags = pcmk__set_flags_as(__func__, __LINE__, \
164 LOG_TRACE, "Value for node", (attr_value)->nodename, \
165 (attr_value)->flags, (flags_to_set), #flags_to_set); \
166 } while (0)
167
168 #define attrd_clear_value_flags(attr_value, flags_to_clear) do { \
169 (attr_value)->flags = pcmk__clear_flags_as(__func__, __LINE__, \
170 LOG_TRACE, "Value for node", (attr_value)->nodename, \
171 (attr_value)->flags, (flags_to_clear), #flags_to_clear); \
172 } while (0)
173
174 extern pcmk_cluster_t *attrd_cluster;
175 extern GHashTable *attributes;
176 extern GHashTable *peer_protocol_vers;
177
178 #define CIB_OP_TIMEOUT_S 120
179
180 int attrd_cluster_connect(void);
181 void attrd_broadcast_value(const attribute_t *a, const attribute_value_t *v);
182 void attrd_peer_update(const pcmk__node_status_t *peer, xmlNode *xml,
183 const char *host, bool filter);
184 void attrd_peer_sync(pcmk__node_status_t *peer);
185 void attrd_peer_remove(const char *host, bool uncache, const char *source);
186 void attrd_peer_clear_failure(pcmk__request_t *request);
187 void attrd_peer_sync_response(const pcmk__node_status_t *peer, bool peer_won,
188 xmlNode *xml);
189
190 void attrd_broadcast_protocol(void);
191 xmlNode *attrd_client_peer_remove(pcmk__request_t *request);
192 xmlNode *attrd_client_clear_failure(pcmk__request_t *request);
193 xmlNode *attrd_client_update(pcmk__request_t *request);
194 xmlNode *attrd_client_refresh(pcmk__request_t *request);
195 xmlNode *attrd_client_query(pcmk__request_t *request);
196 gboolean attrd_send_message(pcmk__node_status_t *node, xmlNode *data,
197 bool confirm);
198
199 xmlNode *attrd_add_value_xml(xmlNode *parent, const attribute_t *a,
200 const attribute_value_t *v, bool force_write);
201 void attrd_clear_value_seen(void);
202 void attrd_free_attribute(gpointer data);
203 void attrd_free_attribute_value(gpointer data);
204 attribute_t *attrd_populate_attribute(xmlNode *xml, const char *attr);
205 char *attrd_set_id(const attribute_t *attr, const char *node_state_id);
206 char *attrd_nvpair_id(const attribute_t *attr, const char *node_state_id);
207
208 enum attrd_write_options {
209 attrd_write_changed = 0,
210 attrd_write_all = (1 << 0),
211 attrd_write_no_delay = (1 << 1),
212 };
213
214 void attrd_write_attributes(uint32_t options);
215 void attrd_write_or_elect_attribute(attribute_t *a);
216
217 extern int minimum_protocol_version;
218 void attrd_remove_peer_protocol_ver(const char *host);
219 void attrd_update_minimum_protocol_ver(const char *host, const char *value);
220
221 mainloop_timer_t *attrd_add_timer(const char *id, int timeout_ms, attribute_t *attr);
222
223 void attrd_unregister_handlers(void);
224 void attrd_handle_request(pcmk__request_t *request);
225
226 enum attrd_sync_point {
227 attrd_sync_point_local,
228 attrd_sync_point_cluster,
229 };
230
231 typedef int (*attrd_confirmation_action_fn)(xmlNode *);
232
233 void attrd_add_client_to_waitlist(pcmk__request_t *request);
234 void attrd_ack_waitlist_clients(enum attrd_sync_point sync_point, const xmlNode *xml);
235 int attrd_cluster_sync_point_update(xmlNode *xml);
236 void attrd_do_not_expect_from_peer(const char *host);
237 void attrd_do_not_wait_for_client(pcmk__client_t *client);
238 void attrd_expect_confirmations(pcmk__request_t *request, attrd_confirmation_action_fn fn);
239 void attrd_free_confirmations(void);
240 void attrd_handle_confirmation(int callid, const char *host);
241 void attrd_remove_client_from_waitlist(pcmk__client_t *client);
242 const char *attrd_request_sync_point(xmlNode *xml);
243 bool attrd_request_has_sync_point(xmlNode *xml);
244
245 extern gboolean stand_alone;
246
247 #endif