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