This source file includes following definitions.
- cib_notify_send_one
- cib_notify_send
- cib_diff_notify
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <sys/param.h>
13 #include <stdio.h>
14 #include <sys/types.h>
15 #include <unistd.h>
16 #include <inttypes.h>
17
18 #include <stdlib.h>
19 #include <errno.h>
20 #include <fcntl.h>
21
22 #include <time.h>
23
24 #include <glib.h>
25 #include <libxml/tree.h>
26
27 #include <crm/crm.h>
28 #include <crm/cib/internal.h>
29
30 #include <crm/common/xml.h>
31 #include <crm/common/remote_internal.h>
32 #include <pacemaker-based.h>
33
34 struct cib_notification_s {
35 const xmlNode *msg;
36 struct iovec *iov;
37 int32_t iov_size;
38 };
39
40 static void
41 cib_notify_send_one(gpointer key, gpointer value, gpointer user_data)
42 {
43 const char *type = NULL;
44 gboolean do_send = FALSE;
45 int rc = pcmk_rc_ok;
46
47 pcmk__client_t *client = value;
48 struct cib_notification_s *update = user_data;
49
50 if (client->ipcs == NULL && client->remote == NULL) {
51 crm_warn("Skipping client with NULL channel");
52 return;
53 }
54
55 type = crm_element_value(update->msg, PCMK__XA_SUBT);
56 CRM_LOG_ASSERT(type != NULL);
57
58 if (pcmk_is_set(client->flags, cib_notify_diff)
59 && pcmk__str_eq(type, PCMK__VALUE_CIB_DIFF_NOTIFY, pcmk__str_none)) {
60
61 do_send = TRUE;
62
63 } else if (pcmk_is_set(client->flags, cib_notify_confirm)
64 && pcmk__str_eq(type, PCMK__VALUE_CIB_UPDATE_CONFIRMATION,
65 pcmk__str_none)) {
66 do_send = TRUE;
67
68 } else if (pcmk_is_set(client->flags, cib_notify_pre)
69 && pcmk__str_eq(type, PCMK__VALUE_CIB_PRE_NOTIFY,
70 pcmk__str_none)) {
71 do_send = TRUE;
72
73 } else if (pcmk_is_set(client->flags, cib_notify_post)
74 && pcmk__str_eq(type, PCMK__VALUE_CIB_POST_NOTIFY,
75 pcmk__str_none)) {
76 do_send = TRUE;
77 }
78
79 if (do_send) {
80 switch (PCMK__CLIENT_TYPE(client)) {
81 case pcmk__client_ipc:
82 rc = pcmk__ipc_send_iov(client, update->iov,
83 crm_ipc_server_event);
84 if (rc != pcmk_rc_ok) {
85 crm_warn("Could not notify client %s: %s " QB_XS " id=%s",
86 pcmk__client_name(client), pcmk_rc_str(rc),
87 client->id);
88 }
89 break;
90 case pcmk__client_tls:
91 case pcmk__client_tcp:
92 crm_debug("Sent %s notification to client %s (id %s)",
93 type, pcmk__client_name(client), client->id);
94 pcmk__remote_send_xml(client->remote, update->msg);
95 break;
96 default:
97 crm_err("Unknown transport for client %s "
98 QB_XS " flags=%#016" PRIx64,
99 pcmk__client_name(client), client->flags);
100 }
101 }
102 }
103
104 static void
105 cib_notify_send(const xmlNode *xml)
106 {
107 struct iovec *iov;
108 struct cib_notification_s update;
109
110 ssize_t bytes = 0;
111 int rc = pcmk__ipc_prepare_iov(0, xml, 0, &iov, &bytes);
112
113 if (rc == pcmk_rc_ok) {
114 update.msg = xml;
115 update.iov = iov;
116 update.iov_size = bytes;
117 pcmk__foreach_ipc_client(cib_notify_send_one, &update);
118
119 } else {
120 crm_notice("Could not notify clients: %s " QB_XS " rc=%d",
121 pcmk_rc_str(rc), rc);
122 }
123 pcmk_free_ipc_event(iov);
124 }
125
126 void
127 cib_diff_notify(const char *op, int result, const char *call_id,
128 const char *client_id, const char *client_name,
129 const char *origin, xmlNode *update, xmlNode *diff)
130 {
131 int add_updates = 0;
132 int add_epoch = 0;
133 int add_admin_epoch = 0;
134
135 int del_updates = 0;
136 int del_epoch = 0;
137 int del_admin_epoch = 0;
138
139 uint8_t log_level = LOG_TRACE;
140
141 xmlNode *update_msg = NULL;
142 xmlNode *wrapper = NULL;
143
144 if (diff == NULL) {
145 return;
146 }
147
148 if (result != pcmk_ok) {
149 log_level = LOG_WARNING;
150 }
151
152 cib_diff_version_details(diff, &add_admin_epoch, &add_epoch, &add_updates,
153 &del_admin_epoch, &del_epoch, &del_updates);
154
155 if ((add_admin_epoch != del_admin_epoch)
156 || (add_epoch != del_epoch)
157 || (add_updates != del_updates)) {
158
159 do_crm_log(log_level,
160 "Updated CIB generation %d.%d.%d to %d.%d.%d from client "
161 "%s%s%s (%s) (%s)",
162 del_admin_epoch, del_epoch, del_updates,
163 add_admin_epoch, add_epoch, add_updates,
164 client_name,
165 ((call_id != NULL)? " call " : ""), pcmk__s(call_id, ""),
166 pcmk__s(origin, "unspecified peer"), pcmk_strerror(result));
167
168 } else if ((add_admin_epoch != 0)
169 || (add_epoch != 0)
170 || (add_updates != 0)) {
171
172 do_crm_log(log_level,
173 "Local-only change to CIB generation %d.%d.%d from client "
174 "%s%s%s (%s) (%s)",
175 add_admin_epoch, add_epoch, add_updates,
176 client_name,
177 ((call_id != NULL)? " call " : ""), pcmk__s(call_id, ""),
178 pcmk__s(origin, "unspecified peer"), pcmk_strerror(result));
179 }
180
181 update_msg = pcmk__xe_create(NULL, PCMK__XE_NOTIFY);
182
183 crm_xml_add(update_msg, PCMK__XA_T, PCMK__VALUE_CIB_NOTIFY);
184 crm_xml_add(update_msg, PCMK__XA_SUBT, PCMK__VALUE_CIB_DIFF_NOTIFY);
185 crm_xml_add(update_msg, PCMK__XA_CIB_OP, op);
186 crm_xml_add(update_msg, PCMK__XA_CIB_CLIENTID, client_id);
187 crm_xml_add(update_msg, PCMK__XA_CIB_CLIENTNAME, client_name);
188 crm_xml_add(update_msg, PCMK__XA_CIB_CALLID, call_id);
189 crm_xml_add(update_msg, PCMK__XA_SRC, origin);
190 crm_xml_add_int(update_msg, PCMK__XA_CIB_RC, result);
191
192 wrapper = pcmk__xe_create(update_msg, PCMK__XE_CIB_UPDATE_RESULT);
193 pcmk__xml_copy(wrapper, diff);
194
195 crm_log_xml_trace(update_msg, "diff-notify");
196 cib_notify_send(update_msg);
197 pcmk__xml_free(update_msg);
198 }