File: | xlators/mgmt/glusterd/src/glusterd-sm.c |
Location: | line 378, column 20 |
Description: | Access to field 'peerinfo' results in a dereference of a null pointer (loaded from variable 'event') |
1 | /* | |||||
2 | Copyright (c) 2006-2012 Red Hat, Inc. <http://www.redhat.com> | |||||
3 | This file is part of GlusterFS. | |||||
4 | ||||||
5 | This file is licensed to you under your choice of the GNU Lesser | |||||
6 | General Public License, version 3 or any later version (LGPLv3 or | |||||
7 | later), or the GNU General Public License, version 2 (GPLv2), in all | |||||
8 | cases as published by the Free Software Foundation. | |||||
9 | */ | |||||
10 | ||||||
11 | #ifndef _CONFIG_H | |||||
12 | #define _CONFIG_H | |||||
13 | #include "config.h" | |||||
14 | #endif | |||||
15 | #include <time.h> | |||||
16 | #include <sys/uio.h> | |||||
17 | #include <sys/resource.h> | |||||
18 | ||||||
19 | #include <libgen.h> | |||||
20 | #include "uuid.h" | |||||
21 | ||||||
22 | #include "fnmatch.h" | |||||
23 | #include "xlator.h" | |||||
24 | #include "protocol-common.h" | |||||
25 | #include "glusterd.h" | |||||
26 | #include "call-stub.h" | |||||
27 | #include "defaults.h" | |||||
28 | #include "list.h" | |||||
29 | #include "dict.h" | |||||
30 | #include "compat.h" | |||||
31 | #include "compat-errno.h" | |||||
32 | #include "statedump.h" | |||||
33 | #include "glusterd-sm.h" | |||||
34 | #include "glusterd-op-sm.h" | |||||
35 | #include "glusterd-utils.h" | |||||
36 | #include "glusterd-store.h" | |||||
37 | ||||||
38 | static struct list_head gd_friend_sm_queue; | |||||
39 | ||||||
40 | static char *glusterd_friend_sm_state_names[] = { | |||||
41 | "Establishing Connection", | |||||
42 | "Probe Sent to Peer", | |||||
43 | "Probe Received from Peer", | |||||
44 | "Peer in Cluster", | |||||
45 | "Accepted peer request", | |||||
46 | "Sent and Received peer request", | |||||
47 | "Peer Rejected", | |||||
48 | "Peer detach in progress", | |||||
49 | "Probe Received from peer", | |||||
50 | "Connected to Peer", | |||||
51 | "Peer is connected and Accepted", | |||||
52 | "Invalid State" | |||||
53 | }; | |||||
54 | ||||||
55 | static char *glusterd_friend_sm_event_names[] = { | |||||
56 | "GD_FRIEND_EVENT_NONE", | |||||
57 | "GD_FRIEND_EVENT_PROBE", | |||||
58 | "GD_FRIEND_EVENT_INIT_FRIEND_REQ", | |||||
59 | "GD_FRIEND_EVENT_RCVD_ACC", | |||||
60 | "GD_FRIEND_EVENT_LOCAL_ACC", | |||||
61 | "GD_FRIEND_EVENT_RCVD_RJT", | |||||
62 | "GD_FRIEND_EVENT_LOCAL_RJT", | |||||
63 | "GD_FRIEND_EVENT_RCVD_FRIEND_REQ", | |||||
64 | "GD_FRIEND_EVENT_INIT_REMOVE_FRIEND", | |||||
65 | "GD_FRIEND_EVENT_RCVD_REMOVE_FRIEND", | |||||
66 | "GD_FRIEND_EVENT_REMOVE_FRIEND", | |||||
67 | "GD_FRIEND_EVENT_CONNECTED", | |||||
68 | "GD_FRIEND_EVENT_MAX" | |||||
69 | }; | |||||
70 | ||||||
71 | char* | |||||
72 | glusterd_friend_sm_state_name_get (int state) | |||||
73 | { | |||||
74 | if (state < 0 || state >= GD_FRIEND_STATE_MAX) | |||||
75 | return glusterd_friend_sm_state_names[GD_FRIEND_STATE_MAX]; | |||||
76 | return glusterd_friend_sm_state_names[state]; | |||||
77 | } | |||||
78 | ||||||
79 | char* | |||||
80 | glusterd_friend_sm_event_name_get (int event) | |||||
81 | { | |||||
82 | if (event < 0 || event >= GD_FRIEND_EVENT_MAX) | |||||
83 | return glusterd_friend_sm_event_names[GD_FRIEND_EVENT_MAX]; | |||||
84 | return glusterd_friend_sm_event_names[event]; | |||||
85 | } | |||||
86 | ||||||
87 | void | |||||
88 | glusterd_destroy_probe_ctx (glusterd_probe_ctx_t *ctx) | |||||
89 | { | |||||
90 | if (!ctx) | |||||
91 | return; | |||||
92 | ||||||
93 | GF_FREE (ctx->hostname)__gf_free (ctx->hostname); | |||||
94 | GF_FREE (ctx)__gf_free (ctx); | |||||
95 | } | |||||
96 | ||||||
97 | void | |||||
98 | glusterd_destroy_friend_req_ctx (glusterd_friend_req_ctx_t *ctx) | |||||
99 | { | |||||
100 | if (!ctx) | |||||
101 | return; | |||||
102 | ||||||
103 | if (ctx->vols) | |||||
104 | dict_unref (ctx->vols); | |||||
105 | GF_FREE (ctx->hostname)__gf_free (ctx->hostname); | |||||
106 | GF_FREE (ctx)__gf_free (ctx); | |||||
107 | } | |||||
108 | ||||||
109 | void | |||||
110 | glusterd_destroy_friend_update_ctx (glusterd_friend_update_ctx_t *ctx) | |||||
111 | { | |||||
112 | if (!ctx) | |||||
113 | return; | |||||
114 | GF_FREE (ctx->hostname)__gf_free (ctx->hostname); | |||||
115 | GF_FREE (ctx)__gf_free (ctx); | |||||
116 | } | |||||
117 | ||||||
118 | int | |||||
119 | glusterd_broadcast_friend_delete (char *hostname, uuid_t uuid) | |||||
120 | { | |||||
121 | int ret = 0; | |||||
122 | rpc_clnt_procedure_t *proc = NULL((void*)0); | |||||
123 | xlator_t *this = NULL((void*)0); | |||||
124 | glusterd_friend_update_ctx_t ctx = {{0},}; | |||||
125 | glusterd_peerinfo_t *peerinfo = NULL((void*)0); | |||||
126 | glusterd_conf_t *priv = NULL((void*)0); | |||||
127 | dict_t *friends = NULL((void*)0); | |||||
128 | char key[100] = {0,}; | |||||
129 | int32_t count = 0; | |||||
130 | ||||||
131 | this = THIS(*__glusterfs_this_location()); | |||||
132 | priv = this->private; | |||||
133 | ||||||
134 | GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: " "priv"); } while (0); _gf_log_callingfn ("", "glusterd-sm.c" , __FUNCTION__, 134, GF_LOG_ERROR, "Assertion failed: " "priv" ); } while (0); } } while (0); | |||||
135 | ||||||
136 | ctx.hostname = hostname; | |||||
137 | ctx.op = GD_FRIEND_UPDATE_DEL; | |||||
138 | ||||||
139 | friends = dict_new (); | |||||
140 | if (!friends) | |||||
141 | goto out; | |||||
142 | ||||||
143 | snprintf (key, sizeof (key), "op"); | |||||
144 | ret = dict_set_int32 (friends, key, ctx.op); | |||||
145 | if (ret) | |||||
146 | goto out; | |||||
147 | ||||||
148 | snprintf (key, sizeof (key), "hostname"); | |||||
149 | ret = dict_set_str (friends, key, hostname); | |||||
150 | if (ret) | |||||
151 | goto out; | |||||
152 | ||||||
153 | ret = dict_set_int32 (friends, "count", count); | |||||
154 | if (ret) | |||||
155 | goto out; | |||||
156 | ||||||
157 | list_for_each_entry (peerinfo, &priv->peers, uuid_list)for (peerinfo = ((typeof(*peerinfo) *)((char *)((&priv-> peers)->next)-(unsigned long)(&((typeof(*peerinfo) *)0 )->uuid_list))); &peerinfo->uuid_list != (&priv ->peers); peerinfo = ((typeof(*peerinfo) *)((char *)(peerinfo ->uuid_list.next)-(unsigned long)(&((typeof(*peerinfo) *)0)->uuid_list)))) { | |||||
158 | if (!peerinfo->connected || !peerinfo->peer) | |||||
159 | continue; | |||||
160 | ||||||
161 | ret = dict_set_static_ptr (friends, "peerinfo", peerinfo); | |||||
162 | if (ret) { | |||||
163 | gf_log ("", GF_LOG_ERROR, "failed to set peerinfo")do { do { if (0) printf ("failed to set peerinfo"); } while ( 0); _gf_log ("", "glusterd-sm.c", __FUNCTION__, 163, GF_LOG_ERROR , "failed to set peerinfo"); } while (0); | |||||
164 | goto out; | |||||
165 | } | |||||
166 | ||||||
167 | proc = &peerinfo->peer->proctable[GLUSTERD_FRIEND_UPDATE]; | |||||
168 | if (proc->fn) { | |||||
169 | ret = proc->fn (NULL((void*)0), this, friends); | |||||
170 | } | |||||
171 | } | |||||
172 | ||||||
173 | gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while ( 0); _gf_log ("", "glusterd-sm.c", __FUNCTION__, 173, GF_LOG_DEBUG , "Returning with %d", ret); } while (0); | |||||
174 | ||||||
175 | out: | |||||
176 | if (friends) | |||||
177 | dict_unref (friends); | |||||
178 | ||||||
179 | return ret; | |||||
180 | } | |||||
181 | ||||||
182 | ||||||
183 | static int | |||||
184 | glusterd_ac_none (glusterd_friend_sm_event_t *event, void *ctx) | |||||
185 | { | |||||
186 | int ret = 0; | |||||
187 | ||||||
188 | gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while ( 0); _gf_log ("", "glusterd-sm.c", __FUNCTION__, 188, GF_LOG_DEBUG , "Returning with %d", ret); } while (0); | |||||
189 | ||||||
190 | return ret; | |||||
191 | } | |||||
192 | ||||||
193 | static int | |||||
194 | glusterd_ac_error (glusterd_friend_sm_event_t *event, void *ctx) | |||||
195 | { | |||||
196 | int ret = 0; | |||||
197 | ||||||
198 | gf_log ("", GF_LOG_ERROR, "Received event %d ", event->event)do { do { if (0) printf ("Received event %d ", event->event ); } while (0); _gf_log ("", "glusterd-sm.c", __FUNCTION__, 198 , GF_LOG_ERROR, "Received event %d ", event->event); } while (0); | |||||
199 | ||||||
200 | return ret; | |||||
201 | } | |||||
202 | ||||||
203 | static int | |||||
204 | glusterd_ac_reverse_probe_begin (glusterd_friend_sm_event_t *event, void *ctx) | |||||
205 | { | |||||
206 | int ret = 0; | |||||
207 | glusterd_peerinfo_t *peerinfo = NULL((void*)0); | |||||
208 | glusterd_friend_sm_event_t *new_event = NULL((void*)0); | |||||
209 | glusterd_probe_ctx_t *new_ev_ctx = NULL((void*)0); | |||||
210 | ||||||
211 | GF_ASSERT (event)do { if (!(event)) { do { do { if (0) printf ("Assertion failed: " "event"); } while (0); _gf_log_callingfn ("", "glusterd-sm.c" , __FUNCTION__, 211, GF_LOG_ERROR, "Assertion failed: " "event" ); } while (0); } } while (0); | |||||
212 | GF_ASSERT (ctx)do { if (!(ctx)) { do { do { if (0) printf ("Assertion failed: " "ctx"); } while (0); _gf_log_callingfn ("", "glusterd-sm.c", __FUNCTION__, 212, GF_LOG_ERROR, "Assertion failed: " "ctx") ; } while (0); } } while (0); | |||||
213 | ||||||
214 | peerinfo = event->peerinfo; | |||||
215 | ret = glusterd_friend_sm_new_event | |||||
216 | (GD_FRIEND_EVENT_PROBE, &new_event); | |||||
217 | ||||||
218 | if (ret) { | |||||
219 | gf_log ("glusterd", GF_LOG_ERROR, "Unable to get new new_event")do { do { if (0) printf ("Unable to get new new_event"); } while (0); _gf_log ("glusterd", "glusterd-sm.c", __FUNCTION__, 219 , GF_LOG_ERROR, "Unable to get new new_event"); } while (0); | |||||
220 | ret = -1; | |||||
221 | goto out; | |||||
222 | } | |||||
223 | ||||||
224 | new_ev_ctx = GF_CALLOC (1, sizeof(*new_ev_ctx), gf_gld_mt_probe_ctx_t)__gf_calloc (1, sizeof(*new_ev_ctx), gf_gld_mt_probe_ctx_t); | |||||
225 | ||||||
226 | if (!new_ev_ctx) { | |||||
227 | ret = -1; | |||||
228 | goto out; | |||||
229 | } | |||||
230 | ||||||
231 | new_ev_ctx->hostname = gf_strdup (peerinfo->hostname); | |||||
232 | new_ev_ctx->port = peerinfo->port; | |||||
233 | new_ev_ctx->req = NULL((void*)0); | |||||
234 | ||||||
235 | new_event->peerinfo = peerinfo; | |||||
236 | new_event->ctx = new_ev_ctx; | |||||
237 | ||||||
238 | ret = glusterd_friend_sm_inject_event (new_event); | |||||
239 | ||||||
240 | if (ret) { | |||||
241 | gf_log ("glusterd", GF_LOG_ERROR, "Unable to inject new_event %d, "do { do { if (0) printf ("Unable to inject new_event %d, " "ret = %d" , new_event->event, ret); } while (0); _gf_log ("glusterd" , "glusterd-sm.c", __FUNCTION__, 242, GF_LOG_ERROR, "Unable to inject new_event %d, " "ret = %d", new_event->event, ret); } while (0) | |||||
242 | "ret = %d", new_event->event, ret)do { do { if (0) printf ("Unable to inject new_event %d, " "ret = %d" , new_event->event, ret); } while (0); _gf_log ("glusterd" , "glusterd-sm.c", __FUNCTION__, 242, GF_LOG_ERROR, "Unable to inject new_event %d, " "ret = %d", new_event->event, ret); } while (0); | |||||
243 | } | |||||
244 | ||||||
245 | out: | |||||
246 | if (ret) { | |||||
247 | GF_FREE (new_event)__gf_free (new_event); | |||||
248 | GF_FREE (new_ev_ctx->hostname)__gf_free (new_ev_ctx->hostname); | |||||
249 | GF_FREE (new_ev_ctx)__gf_free (new_ev_ctx); | |||||
250 | } | |||||
251 | gf_log ("", GF_LOG_DEBUG, "returning with %d", ret)do { do { if (0) printf ("returning with %d", ret); } while ( 0); _gf_log ("", "glusterd-sm.c", __FUNCTION__, 251, GF_LOG_DEBUG , "returning with %d", ret); } while (0); | |||||
252 | return ret; | |||||
253 | } | |||||
254 | ||||||
255 | static int | |||||
256 | glusterd_ac_friend_add (glusterd_friend_sm_event_t *event, void *ctx) | |||||
257 | { | |||||
258 | int ret = 0; | |||||
259 | glusterd_peerinfo_t *peerinfo = NULL((void*)0); | |||||
260 | rpc_clnt_procedure_t *proc = NULL((void*)0); | |||||
261 | call_frame_t *frame = NULL((void*)0); | |||||
262 | glusterd_conf_t *conf = NULL((void*)0); | |||||
263 | xlator_t *this = NULL((void*)0); | |||||
264 | ||||||
265 | GF_ASSERT (event)do { if (!(event)) { do { do { if (0) printf ("Assertion failed: " "event"); } while (0); _gf_log_callingfn ("", "glusterd-sm.c" , __FUNCTION__, 265, GF_LOG_ERROR, "Assertion failed: " "event" ); } while (0); } } while (0); | |||||
266 | peerinfo = event->peerinfo; | |||||
267 | ||||||
268 | this = THIS(*__glusterfs_this_location()); | |||||
269 | conf = this->private; | |||||
270 | ||||||
271 | GF_ASSERT (conf)do { if (!(conf)) { do { do { if (0) printf ("Assertion failed: " "conf"); } while (0); _gf_log_callingfn ("", "glusterd-sm.c" , __FUNCTION__, 271, GF_LOG_ERROR, "Assertion failed: " "conf" ); } while (0); } } while (0); | |||||
272 | ||||||
273 | if (!peerinfo->peer) | |||||
274 | goto out; | |||||
275 | proc = &peerinfo->peer->proctable[GLUSTERD_FRIEND_ADD]; | |||||
276 | if (proc->fn) { | |||||
277 | frame = create_frame (this, this->ctx->pool); | |||||
278 | if (!frame) { | |||||
279 | goto out; | |||||
280 | } | |||||
281 | frame->local = ctx; | |||||
282 | ret = proc->fn (frame, this, event); | |||||
283 | } | |||||
284 | ||||||
285 | out: | |||||
286 | gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while ( 0); _gf_log ("", "glusterd-sm.c", __FUNCTION__, 286, GF_LOG_DEBUG , "Returning with %d", ret); } while (0); | |||||
287 | ||||||
288 | return ret; | |||||
289 | } | |||||
290 | ||||||
291 | static int | |||||
292 | glusterd_ac_friend_probe (glusterd_friend_sm_event_t *event, void *ctx) | |||||
293 | { | |||||
294 | int ret = -1; | |||||
295 | rpc_clnt_procedure_t *proc = NULL((void*)0); | |||||
296 | call_frame_t *frame = NULL((void*)0); | |||||
297 | glusterd_conf_t *conf = NULL((void*)0); | |||||
298 | xlator_t *this = NULL((void*)0); | |||||
299 | glusterd_probe_ctx_t *probe_ctx = NULL((void*)0); | |||||
300 | glusterd_peerinfo_t *peerinfo = NULL((void*)0); | |||||
301 | dict_t *dict = NULL((void*)0); | |||||
302 | ||||||
303 | GF_ASSERT (ctx)do { if (!(ctx)) { do { do { if (0) printf ("Assertion failed: " "ctx"); } while (0); _gf_log_callingfn ("", "glusterd-sm.c", __FUNCTION__, 303, GF_LOG_ERROR, "Assertion failed: " "ctx") ; } while (0); } } while (0); | |||||
304 | ||||||
305 | probe_ctx = ctx; | |||||
306 | ||||||
307 | this = THIS(*__glusterfs_this_location()); | |||||
308 | ||||||
309 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-sm.c" , __FUNCTION__, 309, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
310 | ||||||
311 | conf = this->private; | |||||
312 | ||||||
313 | GF_ASSERT (conf)do { if (!(conf)) { do { do { if (0) printf ("Assertion failed: " "conf"); } while (0); _gf_log_callingfn ("", "glusterd-sm.c" , __FUNCTION__, 313, GF_LOG_ERROR, "Assertion failed: " "conf" ); } while (0); } } while (0); | |||||
314 | ||||||
315 | ret = glusterd_friend_find (NULL((void*)0), probe_ctx->hostname, &peerinfo); | |||||
316 | if (ret) { | |||||
317 | //We should not reach this state ideally | |||||
318 | GF_ASSERT (0)do { if (!(0)) { do { do { if (0) printf ("Assertion failed: " "0"); } while (0); _gf_log_callingfn ("", "glusterd-sm.c", __FUNCTION__ , 318, GF_LOG_ERROR, "Assertion failed: " "0"); } while (0); } } while (0); | |||||
319 | goto out; | |||||
320 | } | |||||
321 | ||||||
322 | if (!peerinfo->peer) | |||||
323 | goto out; | |||||
324 | proc = &peerinfo->peer->proctable[GLUSTERD_PROBE_QUERY]; | |||||
325 | if (proc->fn) { | |||||
326 | frame = create_frame (this, this->ctx->pool); | |||||
327 | if (!frame) { | |||||
328 | goto out; | |||||
329 | } | |||||
330 | frame->local = ctx; | |||||
331 | dict = dict_new (); | |||||
332 | if (!dict) | |||||
333 | goto out; | |||||
334 | ret = dict_set_str (dict, "hostname", probe_ctx->hostname); | |||||
335 | if (ret) | |||||
336 | goto out; | |||||
337 | ||||||
338 | ret = dict_set_int32 (dict, "port", probe_ctx->port); | |||||
339 | if (ret) | |||||
340 | goto out; | |||||
341 | ||||||
342 | ret = dict_set_static_ptr (dict, "peerinfo", peerinfo); | |||||
343 | if (ret) { | |||||
344 | gf_log ("", GF_LOG_ERROR, "failed to set peerinfo")do { do { if (0) printf ("failed to set peerinfo"); } while ( 0); _gf_log ("", "glusterd-sm.c", __FUNCTION__, 344, GF_LOG_ERROR , "failed to set peerinfo"); } while (0); | |||||
345 | goto out; | |||||
346 | } | |||||
347 | ||||||
348 | ret = proc->fn (frame, this, dict); | |||||
349 | if (ret) | |||||
350 | goto out; | |||||
351 | ||||||
352 | } | |||||
353 | ||||||
354 | ||||||
355 | out: | |||||
356 | if (dict) | |||||
357 | dict_unref (dict); | |||||
358 | gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while ( 0); _gf_log ("", "glusterd-sm.c", __FUNCTION__, 358, GF_LOG_DEBUG , "Returning with %d", ret); } while (0); | |||||
359 | ||||||
360 | return ret; | |||||
361 | } | |||||
362 | ||||||
363 | static int | |||||
364 | glusterd_ac_send_friend_remove_req (glusterd_friend_sm_event_t *event, | |||||
365 | void *data) | |||||
366 | { | |||||
367 | int ret = 0; | |||||
368 | glusterd_peerinfo_t *peerinfo = NULL((void*)0); | |||||
369 | rpc_clnt_procedure_t *proc = NULL((void*)0); | |||||
370 | call_frame_t *frame = NULL((void*)0); | |||||
371 | glusterd_conf_t *conf = NULL((void*)0); | |||||
372 | xlator_t *this = NULL((void*)0); | |||||
373 | glusterd_friend_sm_event_type_t event_type = GD_FRIEND_EVENT_NONE; | |||||
374 | glusterd_probe_ctx_t *ctx = NULL((void*)0); | |||||
375 | glusterd_friend_sm_event_t *new_event = NULL((void*)0); | |||||
376 | ||||||
377 | GF_ASSERT (event)do { if (!(event)) { do { do { if (0) printf ("Assertion failed: " "event"); } while (0); _gf_log_callingfn ("", "glusterd-sm.c" , __FUNCTION__, 377, GF_LOG_ERROR, "Assertion failed: " "event" ); } while (0); } } while (0); | |||||
| ||||||
378 | peerinfo = event->peerinfo; | |||||
| ||||||
379 | ||||||
380 | this = THIS(*__glusterfs_this_location()); | |||||
381 | conf = this->private; | |||||
382 | ||||||
383 | GF_ASSERT (conf)do { if (!(conf)) { do { do { if (0) printf ("Assertion failed: " "conf"); } while (0); _gf_log_callingfn ("", "glusterd-sm.c" , __FUNCTION__, 383, GF_LOG_ERROR, "Assertion failed: " "conf" ); } while (0); } } while (0); | |||||
384 | ||||||
385 | ctx = event->ctx; | |||||
386 | ||||||
387 | if (!peerinfo->connected) { | |||||
388 | event_type = GD_FRIEND_EVENT_REMOVE_FRIEND; | |||||
389 | ||||||
390 | ret = glusterd_friend_sm_new_event (event_type, &new_event); | |||||
391 | ||||||
392 | if (!ret) { | |||||
393 | new_event->peerinfo = peerinfo; | |||||
394 | ret = glusterd_friend_sm_inject_event (new_event); | |||||
395 | } else { | |||||
396 | gf_log ("glusterd", GF_LOG_ERROR,do { do { if (0) printf ("Unable to get event"); } while (0); _gf_log ("glusterd", "glusterd-sm.c", __FUNCTION__, 397, GF_LOG_ERROR , "Unable to get event"); } while (0) | |||||
397 | "Unable to get event")do { do { if (0) printf ("Unable to get event"); } while (0); _gf_log ("glusterd", "glusterd-sm.c", __FUNCTION__, 397, GF_LOG_ERROR , "Unable to get event"); } while (0); | |||||
398 | } | |||||
399 | ||||||
400 | if (ctx) | |||||
401 | ret = glusterd_xfer_cli_deprobe_resp (ctx->req, ret, 0, | |||||
402 | NULL((void*)0), | |||||
403 | ctx->hostname); | |||||
404 | glusterd_friend_sm (); | |||||
405 | glusterd_op_sm (); | |||||
406 | ||||||
407 | if (ctx) { | |||||
408 | glusterd_broadcast_friend_delete (ctx->hostname, NULL((void*)0)); | |||||
409 | glusterd_destroy_probe_ctx (ctx); | |||||
410 | } | |||||
411 | goto out; | |||||
412 | } | |||||
413 | ||||||
414 | if (!peerinfo->peer) | |||||
415 | goto out; | |||||
416 | proc = &peerinfo->peer->proctable[GLUSTERD_FRIEND_REMOVE]; | |||||
417 | if (proc->fn) { | |||||
418 | frame = create_frame (this, this->ctx->pool); | |||||
419 | if (!frame) { | |||||
420 | goto out; | |||||
421 | } | |||||
422 | frame->local = data; | |||||
423 | ret = proc->fn (frame, this, event); | |||||
424 | } | |||||
425 | ||||||
426 | out: | |||||
427 | gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while ( 0); _gf_log ("", "glusterd-sm.c", __FUNCTION__, 427, GF_LOG_DEBUG , "Returning with %d", ret); } while (0); | |||||
428 | ||||||
429 | return ret; | |||||
430 | } | |||||
431 | ||||||
432 | static gf_boolean_t | |||||
433 | glusterd_should_update_peer (glusterd_peerinfo_t *peerinfo, | |||||
434 | glusterd_peerinfo_t *cur_peerinfo) | |||||
435 | { | |||||
436 | gf_boolean_t is_valid = _gf_false; | |||||
437 | ||||||
438 | if ((peerinfo == cur_peerinfo) || | |||||
439 | (peerinfo->state.state == GD_FRIEND_STATE_BEFRIENDED)) | |||||
440 | is_valid = _gf_true; | |||||
441 | ||||||
442 | return is_valid; | |||||
443 | } | |||||
444 | ||||||
445 | static int | |||||
446 | glusterd_ac_send_friend_update (glusterd_friend_sm_event_t *event, void *ctx) | |||||
447 | { | |||||
448 | int ret = 0; | |||||
449 | glusterd_peerinfo_t *cur_peerinfo = NULL((void*)0); | |||||
450 | glusterd_peerinfo_t *peerinfo = NULL((void*)0); | |||||
451 | rpc_clnt_procedure_t *proc = NULL((void*)0); | |||||
452 | xlator_t *this = NULL((void*)0); | |||||
453 | glusterd_friend_update_ctx_t ev_ctx = {{0}}; | |||||
454 | glusterd_conf_t *priv = NULL((void*)0); | |||||
455 | dict_t *friends = NULL((void*)0); | |||||
456 | char key[100] = {0,}; | |||||
457 | char *dup_buf = NULL((void*)0); | |||||
458 | int32_t count = 0; | |||||
459 | ||||||
460 | GF_ASSERT (event)do { if (!(event)) { do { do { if (0) printf ("Assertion failed: " "event"); } while (0); _gf_log_callingfn ("", "glusterd-sm.c" , __FUNCTION__, 460, GF_LOG_ERROR, "Assertion failed: " "event" ); } while (0); } } while (0); | |||||
461 | cur_peerinfo = event->peerinfo; | |||||
462 | ||||||
463 | this = THIS(*__glusterfs_this_location()); | |||||
464 | priv = this->private; | |||||
465 | ||||||
466 | GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: " "priv"); } while (0); _gf_log_callingfn ("", "glusterd-sm.c" , __FUNCTION__, 466, GF_LOG_ERROR, "Assertion failed: " "priv" ); } while (0); } } while (0); | |||||
467 | ||||||
468 | ev_ctx.op = GD_FRIEND_UPDATE_ADD; | |||||
469 | ||||||
470 | friends = dict_new (); | |||||
471 | if (!friends) | |||||
472 | goto out; | |||||
473 | ||||||
474 | snprintf (key, sizeof (key), "op"); | |||||
475 | ret = dict_set_int32 (friends, key, ev_ctx.op); | |||||
476 | if (ret) | |||||
477 | goto out; | |||||
478 | ||||||
479 | list_for_each_entry (peerinfo, &priv->peers, uuid_list)for (peerinfo = ((typeof(*peerinfo) *)((char *)((&priv-> peers)->next)-(unsigned long)(&((typeof(*peerinfo) *)0 )->uuid_list))); &peerinfo->uuid_list != (&priv ->peers); peerinfo = ((typeof(*peerinfo) *)((char *)(peerinfo ->uuid_list.next)-(unsigned long)(&((typeof(*peerinfo) *)0)->uuid_list)))) { | |||||
480 | if (!glusterd_should_update_peer (peerinfo, cur_peerinfo)) | |||||
481 | continue; | |||||
482 | ||||||
483 | count++; | |||||
484 | snprintf (key, sizeof (key), "friend%d.uuid", count); | |||||
485 | dup_buf = gf_strdup (uuid_utoa (peerinfo->uuid)); | |||||
486 | ret = dict_set_dynstr (friends, key, dup_buf); | |||||
487 | if (ret) | |||||
488 | goto out; | |||||
489 | snprintf (key, sizeof (key), "friend%d.hostname", count); | |||||
490 | ret = dict_set_str (friends, key, peerinfo->hostname); | |||||
491 | if (ret) | |||||
492 | goto out; | |||||
493 | gf_log ("", GF_LOG_INFO, "Added uuid: %s, host: %s",do { do { if (0) printf ("Added uuid: %s, host: %s", dup_buf, peerinfo->hostname); } while (0); _gf_log ("", "glusterd-sm.c" , __FUNCTION__, 494, GF_LOG_INFO, "Added uuid: %s, host: %s", dup_buf, peerinfo->hostname); } while (0) | |||||
494 | dup_buf, peerinfo->hostname)do { do { if (0) printf ("Added uuid: %s, host: %s", dup_buf, peerinfo->hostname); } while (0); _gf_log ("", "glusterd-sm.c" , __FUNCTION__, 494, GF_LOG_INFO, "Added uuid: %s, host: %s", dup_buf, peerinfo->hostname); } while (0); | |||||
495 | } | |||||
496 | ||||||
497 | ret = dict_set_int32 (friends, "count", count); | |||||
498 | if (ret) | |||||
499 | goto out; | |||||
500 | ||||||
501 | list_for_each_entry (peerinfo, &priv->peers, uuid_list)for (peerinfo = ((typeof(*peerinfo) *)((char *)((&priv-> peers)->next)-(unsigned long)(&((typeof(*peerinfo) *)0 )->uuid_list))); &peerinfo->uuid_list != (&priv ->peers); peerinfo = ((typeof(*peerinfo) *)((char *)(peerinfo ->uuid_list.next)-(unsigned long)(&((typeof(*peerinfo) *)0)->uuid_list)))) { | |||||
502 | if (!peerinfo->connected || !peerinfo->peer) | |||||
503 | continue; | |||||
504 | ||||||
505 | if (!glusterd_should_update_peer (peerinfo, cur_peerinfo)) | |||||
506 | continue; | |||||
507 | ||||||
508 | ret = dict_set_static_ptr (friends, "peerinfo", peerinfo); | |||||
509 | if (ret) { | |||||
510 | gf_log ("", GF_LOG_ERROR, "failed to set peerinfo")do { do { if (0) printf ("failed to set peerinfo"); } while ( 0); _gf_log ("", "glusterd-sm.c", __FUNCTION__, 510, GF_LOG_ERROR , "failed to set peerinfo"); } while (0); | |||||
511 | goto out; | |||||
512 | } | |||||
513 | ||||||
514 | proc = &peerinfo->peer->proctable[GLUSTERD_FRIEND_UPDATE]; | |||||
515 | if (proc->fn) { | |||||
516 | ret = proc->fn (NULL((void*)0), this, friends); | |||||
517 | } | |||||
518 | } | |||||
519 | ||||||
520 | gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while ( 0); _gf_log ("", "glusterd-sm.c", __FUNCTION__, 520, GF_LOG_DEBUG , "Returning with %d", ret); } while (0); | |||||
521 | ||||||
522 | out: | |||||
523 | if (friends) | |||||
524 | dict_unref (friends); | |||||
525 | ||||||
526 | return ret; | |||||
527 | } | |||||
528 | ||||||
529 | static int | |||||
530 | glusterd_peer_detach_cleanup (glusterd_conf_t *priv) | |||||
531 | { | |||||
532 | int ret = -1; | |||||
533 | glusterd_volinfo_t *volinfo = NULL((void*)0); | |||||
534 | glusterd_volinfo_t *tmp_volinfo = NULL((void*)0); | |||||
535 | ||||||
536 | GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: " "priv"); } while (0); _gf_log_callingfn ("", "glusterd-sm.c" , __FUNCTION__, 536, GF_LOG_ERROR, "Assertion failed: " "priv" ); } while (0); } } while (0); | |||||
537 | ||||||
538 | list_for_each_entry_safe (volinfo,tmp_volinfo,for (volinfo = ((typeof(*volinfo) *)((char *)((&priv-> volumes)->next)-(unsigned long)(&((typeof(*volinfo) *) 0)->vol_list))), tmp_volinfo = ((typeof(*volinfo) *)((char *)(volinfo->vol_list.next)-(unsigned long)(&((typeof( *volinfo) *)0)->vol_list))); &volinfo->vol_list != ( &priv->volumes); volinfo = tmp_volinfo, tmp_volinfo = ( (typeof(*tmp_volinfo) *)((char *)(tmp_volinfo->vol_list.next )-(unsigned long)(&((typeof(*tmp_volinfo) *)0)->vol_list )))) | |||||
539 | &priv->volumes, vol_list)for (volinfo = ((typeof(*volinfo) *)((char *)((&priv-> volumes)->next)-(unsigned long)(&((typeof(*volinfo) *) 0)->vol_list))), tmp_volinfo = ((typeof(*volinfo) *)((char *)(volinfo->vol_list.next)-(unsigned long)(&((typeof( *volinfo) *)0)->vol_list))); &volinfo->vol_list != ( &priv->volumes); volinfo = tmp_volinfo, tmp_volinfo = ( (typeof(*tmp_volinfo) *)((char *)(tmp_volinfo->vol_list.next )-(unsigned long)(&((typeof(*tmp_volinfo) *)0)->vol_list )))) { | |||||
540 | if (!glusterd_friend_contains_vol_bricks (volinfo, | |||||
541 | MY_UUID(__glusterd_uuid()))) { | |||||
542 | gf_log (THIS->name, GF_LOG_INFO,do { do { if (0) printf ("Deleting stale volume %s", volinfo-> volname); } while (0); _gf_log ((*__glusterfs_this_location() )->name, "glusterd-sm.c", __FUNCTION__, 543, GF_LOG_INFO, "Deleting stale volume %s" , volinfo->volname); } while (0) | |||||
543 | "Deleting stale volume %s", volinfo->volname)do { do { if (0) printf ("Deleting stale volume %s", volinfo-> volname); } while (0); _gf_log ((*__glusterfs_this_location() )->name, "glusterd-sm.c", __FUNCTION__, 543, GF_LOG_INFO, "Deleting stale volume %s" , volinfo->volname); } while (0); | |||||
544 | ret = glusterd_delete_volume (volinfo); | |||||
545 | if (ret) { | |||||
546 | gf_log (THIS->name, GF_LOG_ERROR,do { do { if (0) printf ("Error deleting stale volume"); } while (0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-sm.c" , __FUNCTION__, 547, GF_LOG_ERROR, "Error deleting stale volume" ); } while (0) | |||||
547 | "Error deleting stale volume")do { do { if (0) printf ("Error deleting stale volume"); } while (0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-sm.c" , __FUNCTION__, 547, GF_LOG_ERROR, "Error deleting stale volume" ); } while (0); | |||||
548 | goto out; | |||||
549 | } | |||||
550 | } | |||||
551 | } | |||||
552 | ret = 0; | |||||
553 | out: | |||||
554 | gf_log (THIS->name, GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-sm.c", __FUNCTION__ , 554, GF_LOG_DEBUG, "Returning %d", ret); } while (0); | |||||
555 | return ret; | |||||
556 | } | |||||
557 | ||||||
558 | static int | |||||
559 | glusterd_ac_handle_friend_remove_req (glusterd_friend_sm_event_t *event, | |||||
560 | void *ctx) | |||||
561 | { | |||||
562 | int ret = 0; | |||||
563 | glusterd_peerinfo_t *peerinfo = NULL((void*)0); | |||||
564 | glusterd_friend_req_ctx_t *ev_ctx = NULL((void*)0); | |||||
565 | glusterd_friend_sm_event_t *new_event = NULL((void*)0); | |||||
566 | glusterd_conf_t *priv = NULL((void*)0); | |||||
567 | ||||||
568 | GF_ASSERT (ctx)do { if (!(ctx)) { do { do { if (0) printf ("Assertion failed: " "ctx"); } while (0); _gf_log_callingfn ("", "glusterd-sm.c", __FUNCTION__, 568, GF_LOG_ERROR, "Assertion failed: " "ctx") ; } while (0); } } while (0); | |||||
569 | ev_ctx = ctx; | |||||
570 | peerinfo = event->peerinfo; | |||||
571 | GF_ASSERT (peerinfo)do { if (!(peerinfo)) { do { do { if (0) printf ("Assertion failed: " "peerinfo"); } while (0); _gf_log_callingfn ("", "glusterd-sm.c" , __FUNCTION__, 571, GF_LOG_ERROR, "Assertion failed: " "peerinfo" ); } while (0); } } while (0); | |||||
572 | ||||||
573 | priv = THIS(*__glusterfs_this_location())->private; | |||||
574 | GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: " "priv"); } while (0); _gf_log_callingfn ("", "glusterd-sm.c" , __FUNCTION__, 574, GF_LOG_ERROR, "Assertion failed: " "priv" ); } while (0); } } while (0); | |||||
575 | ||||||
576 | ret = glusterd_xfer_friend_remove_resp (ev_ctx->req, ev_ctx->hostname, | |||||
577 | ev_ctx->port); | |||||
578 | ||||||
579 | list_for_each_entry (peerinfo, &priv->peers, uuid_list)for (peerinfo = ((typeof(*peerinfo) *)((char *)((&priv-> peers)->next)-(unsigned long)(&((typeof(*peerinfo) *)0 )->uuid_list))); &peerinfo->uuid_list != (&priv ->peers); peerinfo = ((typeof(*peerinfo) *)((char *)(peerinfo ->uuid_list.next)-(unsigned long)(&((typeof(*peerinfo) *)0)->uuid_list)))) { | |||||
580 | ||||||
581 | ret = glusterd_friend_sm_new_event (GD_FRIEND_EVENT_REMOVE_FRIEND, | |||||
582 | &new_event); | |||||
583 | if (ret) | |||||
584 | goto out; | |||||
585 | ||||||
586 | new_event->peerinfo = peerinfo; | |||||
587 | ||||||
588 | ret = glusterd_friend_sm_inject_event (new_event); | |||||
589 | if (ret) | |||||
590 | goto out; | |||||
591 | } | |||||
592 | ret = glusterd_peer_detach_cleanup (priv); | |||||
593 | if (ret) { | |||||
594 | gf_log (THIS->name, GF_LOG_WARNING,do { do { if (0) printf ("Peer detach cleanup was not successful" ); } while (0); _gf_log ((*__glusterfs_this_location())->name , "glusterd-sm.c", __FUNCTION__, 595, GF_LOG_WARNING, "Peer detach cleanup was not successful" ); } while (0) | |||||
595 | "Peer detach cleanup was not successful")do { do { if (0) printf ("Peer detach cleanup was not successful" ); } while (0); _gf_log ((*__glusterfs_this_location())->name , "glusterd-sm.c", __FUNCTION__, 595, GF_LOG_WARNING, "Peer detach cleanup was not successful" ); } while (0); | |||||
596 | ret = 0; | |||||
597 | } | |||||
598 | out: | |||||
599 | gf_log (THIS->name, GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while ( 0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-sm.c" , __FUNCTION__, 599, GF_LOG_DEBUG, "Returning with %d", ret); } while (0); | |||||
600 | ||||||
601 | return ret; | |||||
602 | } | |||||
603 | ||||||
604 | static int | |||||
605 | glusterd_ac_friend_remove (glusterd_friend_sm_event_t *event, void *ctx) | |||||
606 | { | |||||
607 | int ret = -1; | |||||
608 | ||||||
609 | ret = glusterd_friend_remove_cleanup_vols (event->peerinfo->uuid); | |||||
610 | if (ret) | |||||
611 | gf_log (THIS->name, GF_LOG_WARNING, "Volumes cleanup failed")do { do { if (0) printf ("Volumes cleanup failed"); } while ( 0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-sm.c" , __FUNCTION__, 611, GF_LOG_WARNING, "Volumes cleanup failed" ); } while (0); | |||||
612 | ||||||
613 | ret = glusterd_friend_cleanup (event->peerinfo); | |||||
614 | if (ret) { | |||||
615 | gf_log (THIS->name, GF_LOG_ERROR, "Cleanup returned: %d", ret)do { do { if (0) printf ("Cleanup returned: %d", ret); } while (0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-sm.c" , __FUNCTION__, 615, GF_LOG_ERROR, "Cleanup returned: %d", ret ); } while (0); | |||||
616 | } | |||||
617 | ||||||
618 | return 0; | |||||
619 | } | |||||
620 | ||||||
621 | /*static int | |||||
622 | glusterd_ac_none (void *ctx) | |||||
623 | { | |||||
624 | int ret = 0; | |||||
625 | ||||||
626 | gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret); | |||||
627 | ||||||
628 | return ret; | |||||
629 | }*/ | |||||
630 | ||||||
631 | static int | |||||
632 | glusterd_ac_handle_friend_add_req (glusterd_friend_sm_event_t *event, void *ctx) | |||||
633 | { | |||||
634 | int ret = 0; | |||||
635 | uuid_t uuid; | |||||
636 | glusterd_peerinfo_t *peerinfo = NULL((void*)0); | |||||
637 | glusterd_friend_req_ctx_t *ev_ctx = NULL((void*)0); | |||||
638 | glusterd_friend_update_ctx_t *new_ev_ctx = NULL((void*)0); | |||||
639 | glusterd_friend_sm_event_t *new_event = NULL((void*)0); | |||||
640 | glusterd_friend_sm_event_type_t event_type = GD_FRIEND_EVENT_NONE; | |||||
641 | int status = 0; | |||||
642 | int32_t op_ret = -1; | |||||
643 | int32_t op_errno = 0; | |||||
644 | ||||||
645 | GF_ASSERT (ctx)do { if (!(ctx)) { do { do { if (0) printf ("Assertion failed: " "ctx"); } while (0); _gf_log_callingfn ("", "glusterd-sm.c", __FUNCTION__, 645, GF_LOG_ERROR, "Assertion failed: " "ctx") ; } while (0); } } while (0); | |||||
646 | ev_ctx = ctx; | |||||
647 | uuid_copy (uuid, ev_ctx->uuid); | |||||
648 | peerinfo = event->peerinfo; | |||||
649 | GF_ASSERT (peerinfo)do { if (!(peerinfo)) { do { do { if (0) printf ("Assertion failed: " "peerinfo"); } while (0); _gf_log_callingfn ("", "glusterd-sm.c" , __FUNCTION__, 649, GF_LOG_ERROR, "Assertion failed: " "peerinfo" ); } while (0); } } while (0); | |||||
650 | uuid_copy (peerinfo->uuid, ev_ctx->uuid); | |||||
651 | ||||||
652 | //Build comparison logic here. | |||||
653 | ret = glusterd_compare_friend_data (ev_ctx->vols, &status, | |||||
654 | peerinfo->hostname); | |||||
655 | if (ret) | |||||
656 | goto out; | |||||
657 | ||||||
658 | if (GLUSTERD_VOL_COMP_RJT != status) { | |||||
659 | event_type = GD_FRIEND_EVENT_LOCAL_ACC; | |||||
660 | op_ret = 0; | |||||
661 | } else { | |||||
662 | event_type = GD_FRIEND_EVENT_LOCAL_RJT; | |||||
663 | op_errno = GF_PROBE_VOLUME_CONFLICT; | |||||
664 | op_ret = -1; | |||||
665 | } | |||||
666 | ||||||
667 | ret = glusterd_friend_sm_new_event (event_type, &new_event); | |||||
668 | ||||||
669 | if (ret) { | |||||
670 | gf_log ("", GF_LOG_ERROR, "Out of Memory")do { do { if (0) printf ("Out of Memory"); } while (0); _gf_log ("", "glusterd-sm.c", __FUNCTION__, 670, GF_LOG_ERROR, "Out of Memory" ); } while (0); | |||||
671 | } | |||||
672 | ||||||
673 | new_event->peerinfo = peerinfo; | |||||
674 | ||||||
675 | new_ev_ctx = GF_CALLOC (1, sizeof (*new_ev_ctx),__gf_calloc (1, sizeof (*new_ev_ctx), gf_gld_mt_friend_update_ctx_t ) | |||||
676 | gf_gld_mt_friend_update_ctx_t)__gf_calloc (1, sizeof (*new_ev_ctx), gf_gld_mt_friend_update_ctx_t ); | |||||
677 | if (!new_ev_ctx) { | |||||
678 | ret = -1; | |||||
679 | goto out; | |||||
680 | } | |||||
681 | ||||||
682 | uuid_copy (new_ev_ctx->uuid, ev_ctx->uuid); | |||||
683 | new_ev_ctx->hostname = gf_strdup (ev_ctx->hostname); | |||||
684 | new_ev_ctx->op = GD_FRIEND_UPDATE_ADD; | |||||
685 | ||||||
686 | new_event->ctx = new_ev_ctx; | |||||
687 | ||||||
688 | glusterd_friend_sm_inject_event (new_event); | |||||
689 | ||||||
690 | ret = glusterd_xfer_friend_add_resp (ev_ctx->req, ev_ctx->hostname, | |||||
691 | ev_ctx->port, op_ret, op_errno); | |||||
692 | ||||||
693 | out: | |||||
694 | gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while ( 0); _gf_log ("", "glusterd-sm.c", __FUNCTION__, 694, GF_LOG_DEBUG , "Returning with %d", ret); } while (0); | |||||
695 | ||||||
696 | return ret; | |||||
697 | } | |||||
698 | ||||||
699 | static int | |||||
700 | glusterd_friend_sm_transition_state (glusterd_peerinfo_t *peerinfo, | |||||
701 | glusterd_sm_t *state, | |||||
702 | glusterd_friend_sm_event_type_t event_type) | |||||
703 | { | |||||
704 | ||||||
705 | GF_ASSERT (state)do { if (!(state)) { do { do { if (0) printf ("Assertion failed: " "state"); } while (0); _gf_log_callingfn ("", "glusterd-sm.c" , __FUNCTION__, 705, GF_LOG_ERROR, "Assertion failed: " "state" ); } while (0); } } while (0); | |||||
706 | GF_ASSERT (peerinfo)do { if (!(peerinfo)) { do { do { if (0) printf ("Assertion failed: " "peerinfo"); } while (0); _gf_log_callingfn ("", "glusterd-sm.c" , __FUNCTION__, 706, GF_LOG_ERROR, "Assertion failed: " "peerinfo" ); } while (0); } } while (0); | |||||
707 | ||||||
708 | (void) glusterd_sm_tr_log_transition_add (&peerinfo->sm_log, | |||||
709 | peerinfo->state.state, | |||||
710 | state[event_type].next_state, | |||||
711 | event_type); | |||||
712 | ||||||
713 | peerinfo->state.state = state[event_type].next_state; | |||||
714 | return 0; | |||||
715 | } | |||||
716 | ||||||
717 | ||||||
718 | glusterd_sm_t glusterd_state_default [] = { | |||||
719 | {GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, | |||||
720 | {GD_FRIEND_STATE_DEFAULT, glusterd_ac_friend_probe},//EV_PROBE | |||||
721 | {GD_FRIEND_STATE_REQ_SENT, glusterd_ac_friend_add}, //EV_INIT_FRIEND_REQ | |||||
722 | {GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, //EVENT_RCVD_ACC | |||||
723 | {GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, //EVENT_RCVD_LOCAL_ACC | |||||
724 | {GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, //EVENT_RCVD_RJT | |||||
725 | {GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, //EVENT_RCVD_LOCAL_RJT | |||||
726 | {GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_handle_friend_add_req}, //EVENT_RCV_FRIEND_REQ | |||||
727 | {GD_FRIEND_STATE_DEFAULT, glusterd_ac_send_friend_remove_req}, //EV_INIT_REMOVE_FRIEND | |||||
728 | {GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, //EVENT_RCVD_REMOVE_FRIEND | |||||
729 | {GD_FRIEND_STATE_DEFAULT, glusterd_ac_friend_remove}, //EVENT_REMOVE_FRIEND | |||||
730 | {GD_FRIEND_STATE_DEFAULT, glusterd_ac_friend_probe}, //EVENT_CONNECTED | |||||
731 | {GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, //EVENT_MAX | |||||
732 | }; | |||||
733 | ||||||
734 | glusterd_sm_t glusterd_state_probe_rcvd [] = { | |||||
735 | {GD_FRIEND_STATE_PROBE_RCVD, glusterd_ac_none}, | |||||
736 | {GD_FRIEND_STATE_PROBE_RCVD, glusterd_ac_none}, //EV_PROBE | |||||
737 | {GD_FRIEND_STATE_PROBE_RCVD, glusterd_ac_none}, //EV_INIT_FRIEND_REQ | |||||
738 | {GD_FRIEND_STATE_PROBE_RCVD, glusterd_ac_none}, //EVENT_RCVD_ACC | |||||
739 | {GD_FRIEND_STATE_PROBE_RCVD, glusterd_ac_none}, //EVENT_RCVD_LOCAL_ACC | |||||
740 | {GD_FRIEND_STATE_PROBE_RCVD, glusterd_ac_none}, //EVENT_RCVD_RJT | |||||
741 | {GD_FRIEND_STATE_PROBE_RCVD, glusterd_ac_none}, //EVENT_RCVD_LOCAL_RJT | |||||
742 | {GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_handle_friend_add_req}, //EVENT_RCV_FRIEND_REQ | |||||
743 | {GD_FRIEND_STATE_DEFAULT, glusterd_ac_send_friend_remove_req}, //EV_INIT_REMOVE_FRIEND | |||||
744 | {GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, //EVENT_RCVD_REMOVE_FRIEND | |||||
745 | {GD_FRIEND_STATE_DEFAULT, glusterd_ac_friend_remove}, //EVENT_REMOVE_FRIEND | |||||
746 | {GD_FRIEND_STATE_CONNECTED_RCVD, glusterd_ac_none}, //EVENT_CONNECTED | |||||
747 | {GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, //EVENT_MAX | |||||
748 | }; | |||||
749 | ||||||
750 | glusterd_sm_t glusterd_state_connected_rcvd [] = { | |||||
751 | {GD_FRIEND_STATE_CONNECTED_RCVD, glusterd_ac_none}, | |||||
752 | {GD_FRIEND_STATE_CONNECTED_RCVD, glusterd_ac_none}, //EV_PROBE | |||||
753 | {GD_FRIEND_STATE_CONNECTED_RCVD, glusterd_ac_none}, //EV_INIT_FRIEND_REQ | |||||
754 | {GD_FRIEND_STATE_CONNECTED_RCVD, glusterd_ac_none}, //EVENT_RCVD_ACC | |||||
755 | {GD_FRIEND_STATE_CONNECTED_ACCEPTED, glusterd_ac_reverse_probe_begin}, //EVENT_RCVD_LOCAL_ACC | |||||
756 | {GD_FRIEND_STATE_CONNECTED_RCVD, glusterd_ac_none}, //EVENT_RCVD_RJT | |||||
757 | {GD_FRIEND_STATE_REJECTED, glusterd_ac_none}, //EVENT_RCVD_LOCAL_RJT | |||||
758 | {GD_FRIEND_STATE_CONNECTED_RCVD, glusterd_ac_handle_friend_add_req}, //EVENT_RCV_FRIEND_REQ | |||||
759 | {GD_FRIEND_STATE_DEFAULT, glusterd_ac_send_friend_remove_req}, //EV_INIT_REMOVE_FRIEND | |||||
760 | {GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, //EVENT_RCVD_REMOVE_FRIEND | |||||
761 | {GD_FRIEND_STATE_DEFAULT, glusterd_ac_friend_remove}, //EVENT_REMOVE_FRIEND | |||||
762 | {GD_FRIEND_STATE_CONNECTED_RCVD, glusterd_ac_none}, //EVENT_CONNECTED | |||||
763 | {GD_FRIEND_STATE_CONNECTED_RCVD, glusterd_ac_none}, //EVENT_MAX | |||||
764 | }; | |||||
765 | ||||||
766 | glusterd_sm_t glusterd_state_connected_accepted [] = { | |||||
767 | {GD_FRIEND_STATE_CONNECTED_ACCEPTED, glusterd_ac_none}, | |||||
768 | {GD_FRIEND_STATE_CONNECTED_ACCEPTED, glusterd_ac_friend_probe}, //EV_PROBE | |||||
769 | {GD_FRIEND_STATE_REQ_SENT_RCVD, glusterd_ac_friend_add}, //EV_INIT_FRIEND_REQ | |||||
770 | {GD_FRIEND_STATE_CONNECTED_ACCEPTED, glusterd_ac_none}, //EVENT_RCVD_ACC | |||||
771 | {GD_FRIEND_STATE_CONNECTED_ACCEPTED, glusterd_ac_none}, //EVENT_RCVD_LOCAL_ACC | |||||
772 | {GD_FRIEND_STATE_CONNECTED_ACCEPTED, glusterd_ac_none}, //EVENT_RCVD_RJT | |||||
773 | {GD_FRIEND_STATE_CONNECTED_ACCEPTED, glusterd_ac_none}, //EVENT_RCVD_LOCAL_RJT | |||||
774 | {GD_FRIEND_STATE_CONNECTED_ACCEPTED, glusterd_ac_none}, //EVENT_RCV_FRIEND_REQ | |||||
775 | {GD_FRIEND_STATE_DEFAULT, glusterd_ac_send_friend_remove_req}, //EV_INIT_REMOVE_FRIEND | |||||
776 | {GD_FRIEND_STATE_DEFAULT, glusterd_ac_none}, //EVENT_RCVD_REMOVE_FRIEND | |||||
777 | {GD_FRIEND_STATE_DEFAULT, glusterd_ac_friend_remove}, //EVENT_REMOVE_FRIEND | |||||
778 | {GD_FRIEND_STATE_CONNECTED_ACCEPTED, glusterd_ac_none}, //EVENT_CONNECTED | |||||
779 | {GD_FRIEND_STATE_CONNECTED_ACCEPTED, glusterd_ac_none}, //EVENT_MAX | |||||
780 | }; | |||||
781 | ||||||
782 | glusterd_sm_t glusterd_state_req_sent [] = { | |||||
783 | {GD_FRIEND_STATE_REQ_SENT, glusterd_ac_none}, //EVENT_NONE, | |||||
784 | {GD_FRIEND_STATE_REQ_SENT, glusterd_ac_none}, //EVENT_PROBE, | |||||
785 | {GD_FRIEND_STATE_REQ_SENT, glusterd_ac_none}, //EVENT_INIT_FRIEND_REQ, | |||||
786 | {GD_FRIEND_STATE_REQ_ACCEPTED, glusterd_ac_none}, //EVENT_RCVD_ACC | |||||
787 | {GD_FRIEND_STATE_REQ_SENT, glusterd_ac_none}, //EVENT_RCVD_LOCAL_ACC | |||||
788 | {GD_FRIEND_STATE_REJECTED, glusterd_ac_none}, //EVENT_RCVD_RJT | |||||
789 | {GD_FRIEND_STATE_REQ_SENT, glusterd_ac_none}, //EVENT_RCVD_LOCAL_RJT | |||||
790 | {GD_FRIEND_STATE_REQ_SENT_RCVD, glusterd_ac_handle_friend_add_req}, //EVENT_RCV_FRIEND_REQ | |||||
791 | {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_send_friend_remove_req}, //EVENT_INIT_REMOVE_FRIEND, | |||||
792 | {GD_FRIEND_STATE_REQ_SENT, glusterd_ac_none}, //EVENT_RCVD_REMOVE_FRIEND | |||||
793 | {GD_FRIEND_STATE_DEFAULT, glusterd_ac_friend_remove}, //EVENT_REMOVE_FRIEND | |||||
794 | {GD_FRIEND_STATE_REQ_SENT, glusterd_ac_none},//EVENT_CONNECTED | |||||
795 | {GD_FRIEND_STATE_REQ_SENT, glusterd_ac_none},//EVENT_MAX | |||||
796 | }; | |||||
797 | ||||||
798 | glusterd_sm_t glusterd_state_req_rcvd [] = { | |||||
799 | {GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_none}, //EVENT_NONE, | |||||
800 | {GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_none}, //EVENT_PROBE, | |||||
801 | {GD_FRIEND_STATE_REQ_SENT_RCVD, glusterd_ac_none}, //EVENT_INIT_FRIEND_REQ, | |||||
802 | {GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_none}, //EVENT_RCVD_ACC | |||||
803 | {GD_FRIEND_STATE_REQ_ACCEPTED, glusterd_ac_none}, //EVENT_RCVD_LOCAL_ACC | |||||
804 | {GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_none}, //EVENT_RCVD_RJT | |||||
805 | {GD_FRIEND_STATE_REJECTED, glusterd_ac_none}, //EVENT_RCVD_LOCAL_RJT | |||||
806 | {GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_none}, //EVENT_RCV_FRIEND_REQ | |||||
807 | {GD_FRIEND_STATE_DEFAULT, glusterd_ac_send_friend_remove_req}, //EVENT_INIT_REMOVE_FRIEND, | |||||
808 | {GD_FRIEND_STATE_DEFAULT, glusterd_ac_handle_friend_remove_req}, //EVENT_RCVD_REMOVE_FRIEND | |||||
809 | {GD_FRIEND_STATE_DEFAULT, glusterd_ac_friend_remove}, //EVENT_REMOVE_FRIEND | |||||
810 | {GD_FRIEND_STATE_CONNECTED_RCVD, glusterd_ac_none},//EVENT_CONNECTED | |||||
811 | {GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_none},//EVENT_MAX | |||||
812 | }; | |||||
813 | ||||||
814 | glusterd_sm_t glusterd_state_befriended [] = { | |||||
815 | {GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_none}, //EVENT_NONE, | |||||
816 | {GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_none}, //EVENT_PROBE, | |||||
817 | {GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_none}, //EVENT_INIT_FRIEND_REQ, | |||||
818 | {GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_none}, //EVENT_RCVD_ACC | |||||
819 | {GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_send_friend_update}, //EVENT_RCVD_LOCAL_ACC | |||||
820 | {GD_FRIEND_STATE_REJECTED, glusterd_ac_none}, //EVENT_RCVD_RJT | |||||
821 | {GD_FRIEND_STATE_REJECTED, glusterd_ac_none}, //EVENT_RCVD_LOCAL_RJT | |||||
822 | {GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_handle_friend_add_req}, //EVENT_RCV_FRIEND_REQ | |||||
823 | {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_send_friend_remove_req}, //EVENT_INIT_REMOVE_FRIEND, | |||||
824 | {GD_FRIEND_STATE_DEFAULT, glusterd_ac_handle_friend_remove_req}, //EVENT_RCVD_REMOVE_FRIEND | |||||
825 | {GD_FRIEND_STATE_DEFAULT, glusterd_ac_friend_remove}, //EVENT_REMOVE_FRIEND | |||||
826 | {GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_friend_add},//EVENT_CONNECTED | |||||
827 | {GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_none},//EVENT_MAX | |||||
828 | }; | |||||
829 | ||||||
830 | glusterd_sm_t glusterd_state_req_sent_rcvd [] = { | |||||
831 | {GD_FRIEND_STATE_REQ_SENT_RCVD, glusterd_ac_none}, //EVENT_NONE, | |||||
832 | {GD_FRIEND_STATE_REQ_SENT_RCVD, glusterd_ac_none}, //EVENT_PROBE, | |||||
833 | {GD_FRIEND_STATE_REQ_SENT_RCVD, glusterd_ac_none}, //EVENT_INIT_FRIEND_REQ, | |||||
834 | {GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_send_friend_update}, //EVENT_RCVD_ACC | |||||
835 | {GD_FRIEND_STATE_REQ_SENT_RCVD, glusterd_ac_none}, //EVENT_RCVD_LOCAL_ACC | |||||
836 | {GD_FRIEND_STATE_REJECTED, glusterd_ac_none}, //EVENT_RCVD_RJT | |||||
837 | {GD_FRIEND_STATE_REQ_SENT_RCVD, glusterd_ac_none}, //EVENT_RCVD_LOCAL_RJT | |||||
838 | {GD_FRIEND_STATE_REQ_SENT_RCVD, glusterd_ac_none}, //EVENT_RCV_FRIEND_REQ | |||||
839 | {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_send_friend_remove_req}, //EVENT_INIT_REMOVE_FRIEND, | |||||
840 | {GD_FRIEND_STATE_DEFAULT, glusterd_ac_handle_friend_remove_req}, //EVENT_RCVD_REMOVE_FRIEND | |||||
841 | {GD_FRIEND_STATE_DEFAULT, glusterd_ac_friend_remove}, //EVENT_REMOVE_FRIEND | |||||
842 | {GD_FRIEND_STATE_REQ_SENT_RCVD, glusterd_ac_none},//EVENT_CONNECTED | |||||
843 | {GD_FRIEND_STATE_REQ_SENT_RCVD, glusterd_ac_none},//EVENT_MAX | |||||
844 | }; | |||||
845 | ||||||
846 | glusterd_sm_t glusterd_state_rejected [] = { | |||||
847 | {GD_FRIEND_STATE_REJECTED, glusterd_ac_none}, //EVENT_NONE, | |||||
848 | {GD_FRIEND_STATE_REJECTED, glusterd_ac_friend_probe}, //EVENT_PROBE, | |||||
849 | {GD_FRIEND_STATE_REQ_SENT, glusterd_ac_friend_add}, //EVENT_INIT_FRIEND_REQ, | |||||
850 | {GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_none}, //EVENT_RCVD_ACC | |||||
851 | {GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_none}, //EVENT_RCVD_LOCAL_ACC | |||||
852 | {GD_FRIEND_STATE_REJECTED, glusterd_ac_none}, //EVENT_RCVD_RJT | |||||
853 | {GD_FRIEND_STATE_REJECTED, glusterd_ac_none}, //EVENT_RCVD_LOCAL_RJT | |||||
854 | {GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_handle_friend_add_req}, //EVENT_RCV_FRIEND_REQ | |||||
855 | {GD_FRIEND_STATE_DEFAULT, glusterd_ac_send_friend_remove_req}, //EVENT_INIT_REMOVE_FRIEND | |||||
856 | {GD_FRIEND_STATE_DEFAULT, glusterd_ac_handle_friend_remove_req}, //EVENT_RCVD_REMOVE_FRIEND | |||||
857 | {GD_FRIEND_STATE_DEFAULT, glusterd_ac_friend_remove}, //EVENT_REMOVE_FRIEND | |||||
858 | {GD_FRIEND_STATE_REJECTED, glusterd_ac_friend_add},//EVENT_CONNECTED | |||||
859 | {GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_none},//EVENT_MAX | |||||
860 | }; | |||||
861 | ||||||
862 | glusterd_sm_t glusterd_state_req_accepted [] = { | |||||
863 | {GD_FRIEND_STATE_REQ_ACCEPTED, glusterd_ac_none}, //EVENT_NONE, | |||||
864 | {GD_FRIEND_STATE_REQ_ACCEPTED, glusterd_ac_none}, //EVENT_PROBE, | |||||
865 | {GD_FRIEND_STATE_REQ_ACCEPTED, glusterd_ac_none}, //EVENT_INIT_FRIEND_REQ, | |||||
866 | {GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_send_friend_update}, //EVENT_RCVD_ACC | |||||
867 | {GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_send_friend_update}, //EVENT_RCVD_LOCAL_ACC | |||||
868 | {GD_FRIEND_STATE_REJECTED, glusterd_ac_none}, //EVENT_RCVD_RJT | |||||
869 | {GD_FRIEND_STATE_REJECTED, glusterd_ac_none}, //EVENT_RCVD_LOCAL_RJT | |||||
870 | {GD_FRIEND_STATE_REQ_ACCEPTED, glusterd_ac_handle_friend_add_req}, //EVENT_RCV_FRIEND_REQ | |||||
871 | {GD_FRIEND_STATE_REQ_ACCEPTED, glusterd_ac_send_friend_remove_req}, //EVENT_INIT_REMOVE_FRIEND | |||||
872 | {GD_FRIEND_STATE_DEFAULT, glusterd_ac_handle_friend_remove_req}, //EVENT_RCVD_REMOVE_FRIEND | |||||
873 | {GD_FRIEND_STATE_DEFAULT, glusterd_ac_friend_remove}, //EVENT_REMOVE_FRIEND | |||||
874 | {GD_FRIEND_STATE_CONNECTED_ACCEPTED, glusterd_ac_reverse_probe_begin},//EVENT_CONNECTED | |||||
875 | {GD_FRIEND_STATE_REQ_SENT, glusterd_ac_none},//EVENT_MAX | |||||
876 | }; | |||||
877 | ||||||
878 | glusterd_sm_t glusterd_state_unfriend_sent [] = { | |||||
879 | {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_none}, //EVENT_NONE, | |||||
880 | {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_error}, //EVENT_PROBE, | |||||
881 | {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_none}, //EVENT_INIT_FRIEND_REQ, | |||||
882 | {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_none}, //EVENT_RCVD_ACC | |||||
883 | {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_none}, //EVENT_RCVD_LOCAL_ACC | |||||
884 | {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_error}, //EVENT_RCVD_RJT | |||||
885 | {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_error}, //EVENT_RCVD_LOCAL_RJT | |||||
886 | {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_error}, //EVENT_RCV_FRIEND_REQ | |||||
887 | {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_none}, //EVENT_INIT_REMOVE_FRIEND | |||||
888 | {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_none}, //EVENT_RCVD_REMOVE_FRIEND | |||||
889 | {GD_FRIEND_STATE_DEFAULT, glusterd_ac_friend_remove}, //EVENT_REMOVE_FRIEND | |||||
890 | {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_none},//EVENT_CONNECTED | |||||
891 | {GD_FRIEND_STATE_UNFRIEND_SENT, glusterd_ac_none},//EVENT_MAX | |||||
892 | }; | |||||
893 | ||||||
894 | glusterd_sm_t *glusterd_friend_state_table [] = { | |||||
895 | glusterd_state_default, | |||||
896 | glusterd_state_req_sent, | |||||
897 | glusterd_state_req_rcvd, | |||||
898 | glusterd_state_befriended, | |||||
899 | glusterd_state_req_accepted, | |||||
900 | glusterd_state_req_sent_rcvd, | |||||
901 | glusterd_state_rejected, | |||||
902 | glusterd_state_unfriend_sent, | |||||
903 | glusterd_state_probe_rcvd, | |||||
904 | glusterd_state_connected_rcvd, | |||||
905 | glusterd_state_connected_accepted | |||||
906 | }; | |||||
907 | ||||||
908 | int | |||||
909 | glusterd_friend_sm_new_event (glusterd_friend_sm_event_type_t event_type, | |||||
910 | glusterd_friend_sm_event_t **new_event) | |||||
911 | { | |||||
912 | glusterd_friend_sm_event_t *event = NULL((void*)0); | |||||
913 | ||||||
914 | GF_ASSERT (new_event)do { if (!(new_event)) { do { do { if (0) printf ("Assertion failed: " "new_event"); } while (0); _gf_log_callingfn ("", "glusterd-sm.c" , __FUNCTION__, 914, GF_LOG_ERROR, "Assertion failed: " "new_event" ); } while (0); } } while (0); | |||||
915 | GF_ASSERT (GD_FRIEND_EVENT_NONE <= event_type &&do { if (!(GD_FRIEND_EVENT_NONE <= event_type && GD_FRIEND_EVENT_MAX > event_type)) { do { do { if (0) printf ("Assertion failed: " "GD_FRIEND_EVENT_NONE <= event_type && GD_FRIEND_EVENT_MAX > event_type" ); } while (0); _gf_log_callingfn ("", "glusterd-sm.c", __FUNCTION__ , 916, GF_LOG_ERROR, "Assertion failed: " "GD_FRIEND_EVENT_NONE <= event_type && GD_FRIEND_EVENT_MAX > event_type" ); } while (0); } } while (0) | |||||
916 | GD_FRIEND_EVENT_MAX > event_type)do { if (!(GD_FRIEND_EVENT_NONE <= event_type && GD_FRIEND_EVENT_MAX > event_type)) { do { do { if (0) printf ("Assertion failed: " "GD_FRIEND_EVENT_NONE <= event_type && GD_FRIEND_EVENT_MAX > event_type" ); } while (0); _gf_log_callingfn ("", "glusterd-sm.c", __FUNCTION__ , 916, GF_LOG_ERROR, "Assertion failed: " "GD_FRIEND_EVENT_NONE <= event_type && GD_FRIEND_EVENT_MAX > event_type" ); } while (0); } } while (0); | |||||
917 | ||||||
918 | event = GF_CALLOC (1, sizeof (*event), gf_gld_mt_friend_sm_event_t)__gf_calloc (1, sizeof (*event), gf_gld_mt_friend_sm_event_t); | |||||
919 | ||||||
920 | if (!event) | |||||
921 | return -1; | |||||
922 | ||||||
923 | *new_event = event; | |||||
924 | event->event = event_type; | |||||
925 | INIT_LIST_HEAD (&event->list)do { (&event->list)->next = (&event->list)-> prev = &event->list; } while (0); | |||||
926 | ||||||
927 | return 0; | |||||
928 | } | |||||
929 | ||||||
930 | int | |||||
931 | glusterd_friend_sm_inject_event (glusterd_friend_sm_event_t *event) | |||||
932 | { | |||||
933 | GF_ASSERT (event)do { if (!(event)) { do { do { if (0) printf ("Assertion failed: " "event"); } while (0); _gf_log_callingfn ("", "glusterd-sm.c" , __FUNCTION__, 933, GF_LOG_ERROR, "Assertion failed: " "event" ); } while (0); } } while (0); | |||||
934 | gf_log ("glusterd", GF_LOG_DEBUG, "Enqueue event: '%s'",do { do { if (0) printf ("Enqueue event: '%s'", glusterd_friend_sm_event_name_get (event->event)); } while (0); _gf_log ("glusterd", "glusterd-sm.c" , __FUNCTION__, 935, GF_LOG_DEBUG, "Enqueue event: '%s'", glusterd_friend_sm_event_name_get (event->event)); } while (0) | |||||
935 | glusterd_friend_sm_event_name_get (event->event))do { do { if (0) printf ("Enqueue event: '%s'", glusterd_friend_sm_event_name_get (event->event)); } while (0); _gf_log ("glusterd", "glusterd-sm.c" , __FUNCTION__, 935, GF_LOG_DEBUG, "Enqueue event: '%s'", glusterd_friend_sm_event_name_get (event->event)); } while (0); | |||||
936 | list_add_tail (&event->list, &gd_friend_sm_queue); | |||||
937 | ||||||
938 | return 0; | |||||
939 | } | |||||
940 | ||||||
941 | void | |||||
942 | glusterd_destroy_friend_event_context (glusterd_friend_sm_event_t *event) | |||||
943 | { | |||||
944 | if (!event) | |||||
945 | return; | |||||
946 | ||||||
947 | switch (event->event) { | |||||
948 | case GD_FRIEND_EVENT_RCVD_FRIEND_REQ: | |||||
949 | case GD_FRIEND_EVENT_RCVD_REMOVE_FRIEND: | |||||
950 | glusterd_destroy_friend_req_ctx (event->ctx); | |||||
951 | break; | |||||
952 | case GD_FRIEND_EVENT_LOCAL_ACC: | |||||
953 | case GD_FRIEND_EVENT_LOCAL_RJT: | |||||
954 | case GD_FRIEND_EVENT_RCVD_ACC: | |||||
955 | case GD_FRIEND_EVENT_RCVD_RJT: | |||||
956 | glusterd_destroy_friend_update_ctx (event->ctx); | |||||
957 | break; | |||||
958 | default: | |||||
959 | break; | |||||
960 | } | |||||
961 | } | |||||
962 | ||||||
963 | gf_boolean_t | |||||
964 | gd_does_peer_affect_quorum (glusterd_friend_sm_state_t old_state, | |||||
965 | glusterd_friend_sm_event_type_t event_type, | |||||
966 | glusterd_peerinfo_t *peerinfo) | |||||
967 | { | |||||
968 | gf_boolean_t affects = _gf_false; | |||||
969 | ||||||
970 | //When glusterd comes up with friends in BEFRIENDED state in store, | |||||
971 | //wait until compare-data happens. | |||||
972 | if ((old_state == GD_FRIEND_STATE_BEFRIENDED) && | |||||
973 | (event_type != GD_FRIEND_EVENT_RCVD_ACC) && | |||||
974 | (event_type != GD_FRIEND_EVENT_LOCAL_ACC)) | |||||
975 | goto out; | |||||
976 | if ((peerinfo->state.state == GD_FRIEND_STATE_BEFRIENDED) | |||||
977 | && peerinfo->connected) { | |||||
978 | affects = _gf_true; | |||||
979 | } | |||||
980 | out: | |||||
981 | return affects; | |||||
982 | } | |||||
983 | ||||||
984 | int | |||||
985 | glusterd_friend_sm () | |||||
986 | { | |||||
987 | glusterd_friend_sm_event_t *event = NULL((void*)0); | |||||
988 | glusterd_friend_sm_event_t *tmp = NULL((void*)0); | |||||
989 | int ret = -1; | |||||
990 | glusterd_friend_sm_ac_fn handler = NULL((void*)0); | |||||
991 | glusterd_sm_t *state = NULL((void*)0); | |||||
992 | glusterd_peerinfo_t *peerinfo = NULL((void*)0); | |||||
993 | glusterd_friend_sm_event_type_t event_type = 0; | |||||
994 | gf_boolean_t is_await_conn = _gf_false; | |||||
995 | gf_boolean_t quorum_action = _gf_false; | |||||
996 | glusterd_friend_sm_state_t old_state = GD_FRIEND_STATE_DEFAULT; | |||||
997 | ||||||
998 | while (!list_empty (&gd_friend_sm_queue)) { | |||||
999 | list_for_each_entry_safe (event, tmp, &gd_friend_sm_queue, list)for (event = ((typeof(*event) *)((char *)((&gd_friend_sm_queue )->next)-(unsigned long)(&((typeof(*event) *)0)->list ))), tmp = ((typeof(*event) *)((char *)(event->list.next)- (unsigned long)(&((typeof(*event) *)0)->list))); & event->list != (&gd_friend_sm_queue); event = tmp, tmp = ((typeof(*tmp) *)((char *)(tmp->list.next)-(unsigned long )(&((typeof(*tmp) *)0)->list)))) { | |||||
1000 | ||||||
1001 | list_del_init (&event->list); | |||||
1002 | event_type = event->event; | |||||
1003 | peerinfo = event->peerinfo; | |||||
1004 | if (!peerinfo) { | |||||
1005 | gf_log ("glusterd", GF_LOG_CRITICAL, "Received"do { do { if (0) printf ("Received" " event %s with empty peer info" , glusterd_friend_sm_event_name_get (event_type)); } while (0 ); _gf_log ("glusterd", "glusterd-sm.c", __FUNCTION__, 1007, GF_LOG_CRITICAL , "Received" " event %s with empty peer info", glusterd_friend_sm_event_name_get (event_type)); } while (0) | |||||
1006 | " event %s with empty peer info",do { do { if (0) printf ("Received" " event %s with empty peer info" , glusterd_friend_sm_event_name_get (event_type)); } while (0 ); _gf_log ("glusterd", "glusterd-sm.c", __FUNCTION__, 1007, GF_LOG_CRITICAL , "Received" " event %s with empty peer info", glusterd_friend_sm_event_name_get (event_type)); } while (0) | |||||
1007 | glusterd_friend_sm_event_name_get (event_type))do { do { if (0) printf ("Received" " event %s with empty peer info" , glusterd_friend_sm_event_name_get (event_type)); } while (0 ); _gf_log ("glusterd", "glusterd-sm.c", __FUNCTION__, 1007, GF_LOG_CRITICAL , "Received" " event %s with empty peer info", glusterd_friend_sm_event_name_get (event_type)); } while (0); | |||||
1008 | ||||||
1009 | GF_FREE (event)__gf_free (event); | |||||
1010 | continue; | |||||
1011 | } | |||||
1012 | gf_log ("", GF_LOG_DEBUG, "Dequeued event of type: '%s'",do { do { if (0) printf ("Dequeued event of type: '%s'", glusterd_friend_sm_event_name_get (event_type)); } while (0); _gf_log ("", "glusterd-sm.c", __FUNCTION__ , 1013, GF_LOG_DEBUG, "Dequeued event of type: '%s'", glusterd_friend_sm_event_name_get (event_type)); } while (0) | |||||
1013 | glusterd_friend_sm_event_name_get (event_type))do { do { if (0) printf ("Dequeued event of type: '%s'", glusterd_friend_sm_event_name_get (event_type)); } while (0); _gf_log ("", "glusterd-sm.c", __FUNCTION__ , 1013, GF_LOG_DEBUG, "Dequeued event of type: '%s'", glusterd_friend_sm_event_name_get (event_type)); } while (0); | |||||
1014 | ||||||
1015 | ||||||
1016 | old_state = peerinfo->state.state; | |||||
1017 | state = glusterd_friend_state_table[peerinfo->state.state]; | |||||
1018 | ||||||
1019 | GF_ASSERT (state)do { if (!(state)) { do { do { if (0) printf ("Assertion failed: " "state"); } while (0); _gf_log_callingfn ("", "glusterd-sm.c" , __FUNCTION__, 1019, GF_LOG_ERROR, "Assertion failed: " "state" ); } while (0); } } while (0); | |||||
1020 | ||||||
1021 | handler = state[event_type].handler; | |||||
1022 | GF_ASSERT (handler)do { if (!(handler)) { do { do { if (0) printf ("Assertion failed: " "handler"); } while (0); _gf_log_callingfn ("", "glusterd-sm.c" , __FUNCTION__, 1022, GF_LOG_ERROR, "Assertion failed: " "handler" ); } while (0); } } while (0); | |||||
1023 | ||||||
1024 | ret = handler (event, event->ctx); | |||||
1025 | if (ret == GLUSTERD_CONNECTION_AWAITED) { | |||||
1026 | is_await_conn = _gf_true; | |||||
1027 | ret = 0; | |||||
1028 | } | |||||
1029 | ||||||
1030 | if (ret) { | |||||
1031 | gf_log ("glusterd", GF_LOG_ERROR, "handler returned: "do { do { if (0) printf ("handler returned: " "%d", ret); } while (0); _gf_log ("glusterd", "glusterd-sm.c", __FUNCTION__, 1032 , GF_LOG_ERROR, "handler returned: " "%d", ret); } while (0) | |||||
1032 | "%d", ret)do { do { if (0) printf ("handler returned: " "%d", ret); } while (0); _gf_log ("glusterd", "glusterd-sm.c", __FUNCTION__, 1032 , GF_LOG_ERROR, "handler returned: " "%d", ret); } while (0); | |||||
1033 | glusterd_destroy_friend_event_context (event); | |||||
1034 | GF_FREE (event)__gf_free (event); | |||||
1035 | continue; | |||||
1036 | } | |||||
1037 | ||||||
1038 | if ((GD_FRIEND_EVENT_REMOVE_FRIEND == event_type) || | |||||
1039 | (GD_FRIEND_EVENT_INIT_REMOVE_FRIEND == event_type)){ | |||||
1040 | glusterd_destroy_friend_event_context (event); | |||||
1041 | GF_FREE (event)__gf_free (event); | |||||
1042 | continue; | |||||
1043 | } | |||||
1044 | ||||||
1045 | ret = glusterd_friend_sm_transition_state (peerinfo, | |||||
1046 | state, event_type); | |||||
1047 | ||||||
1048 | if (ret) { | |||||
1049 | gf_log ("glusterd", GF_LOG_ERROR, "Unable to transition"do { do { if (0) printf ("Unable to transition" " state from '%s' to '%s' for event '%s'" , glusterd_friend_sm_state_name_get(peerinfo->state.state) , glusterd_friend_sm_state_name_get(state[event_type].next_state ), glusterd_friend_sm_event_name_get(event_type)); } while (0 ); _gf_log ("glusterd", "glusterd-sm.c", __FUNCTION__, 1053, GF_LOG_ERROR , "Unable to transition" " state from '%s' to '%s' for event '%s'" , glusterd_friend_sm_state_name_get(peerinfo->state.state) , glusterd_friend_sm_state_name_get(state[event_type].next_state ), glusterd_friend_sm_event_name_get(event_type)); } while (0 ) | |||||
1050 | " state from '%s' to '%s' for event '%s'",do { do { if (0) printf ("Unable to transition" " state from '%s' to '%s' for event '%s'" , glusterd_friend_sm_state_name_get(peerinfo->state.state) , glusterd_friend_sm_state_name_get(state[event_type].next_state ), glusterd_friend_sm_event_name_get(event_type)); } while (0 ); _gf_log ("glusterd", "glusterd-sm.c", __FUNCTION__, 1053, GF_LOG_ERROR , "Unable to transition" " state from '%s' to '%s' for event '%s'" , glusterd_friend_sm_state_name_get(peerinfo->state.state) , glusterd_friend_sm_state_name_get(state[event_type].next_state ), glusterd_friend_sm_event_name_get(event_type)); } while (0 ) | |||||
1051 | glusterd_friend_sm_state_name_get(peerinfo->state.state),do { do { if (0) printf ("Unable to transition" " state from '%s' to '%s' for event '%s'" , glusterd_friend_sm_state_name_get(peerinfo->state.state) , glusterd_friend_sm_state_name_get(state[event_type].next_state ), glusterd_friend_sm_event_name_get(event_type)); } while (0 ); _gf_log ("glusterd", "glusterd-sm.c", __FUNCTION__, 1053, GF_LOG_ERROR , "Unable to transition" " state from '%s' to '%s' for event '%s'" , glusterd_friend_sm_state_name_get(peerinfo->state.state) , glusterd_friend_sm_state_name_get(state[event_type].next_state ), glusterd_friend_sm_event_name_get(event_type)); } while (0 ) | |||||
1052 | glusterd_friend_sm_state_name_get(state[event_type].next_state),do { do { if (0) printf ("Unable to transition" " state from '%s' to '%s' for event '%s'" , glusterd_friend_sm_state_name_get(peerinfo->state.state) , glusterd_friend_sm_state_name_get(state[event_type].next_state ), glusterd_friend_sm_event_name_get(event_type)); } while (0 ); _gf_log ("glusterd", "glusterd-sm.c", __FUNCTION__, 1053, GF_LOG_ERROR , "Unable to transition" " state from '%s' to '%s' for event '%s'" , glusterd_friend_sm_state_name_get(peerinfo->state.state) , glusterd_friend_sm_state_name_get(state[event_type].next_state ), glusterd_friend_sm_event_name_get(event_type)); } while (0 ) | |||||
1053 | glusterd_friend_sm_event_name_get(event_type))do { do { if (0) printf ("Unable to transition" " state from '%s' to '%s' for event '%s'" , glusterd_friend_sm_state_name_get(peerinfo->state.state) , glusterd_friend_sm_state_name_get(state[event_type].next_state ), glusterd_friend_sm_event_name_get(event_type)); } while (0 ); _gf_log ("glusterd", "glusterd-sm.c", __FUNCTION__, 1053, GF_LOG_ERROR , "Unable to transition" " state from '%s' to '%s' for event '%s'" , glusterd_friend_sm_state_name_get(peerinfo->state.state) , glusterd_friend_sm_state_name_get(state[event_type].next_state ), glusterd_friend_sm_event_name_get(event_type)); } while (0 ); | |||||
1054 | goto out; | |||||
1055 | } | |||||
1056 | ||||||
1057 | if (gd_does_peer_affect_quorum (old_state, event_type, | |||||
1058 | peerinfo)) { | |||||
1059 | peerinfo->quorum_contrib = QUORUM_UP; | |||||
1060 | if (peerinfo->quorum_action) { | |||||
1061 | peerinfo->quorum_action = _gf_false; | |||||
1062 | quorum_action = _gf_true; | |||||
1063 | } | |||||
1064 | } | |||||
1065 | ||||||
1066 | ret = glusterd_store_peerinfo (peerinfo); | |||||
1067 | ||||||
1068 | glusterd_destroy_friend_event_context (event); | |||||
1069 | GF_FREE (event)__gf_free (event); | |||||
1070 | if (is_await_conn) | |||||
1071 | break; | |||||
1072 | } | |||||
1073 | if (is_await_conn) | |||||
1074 | break; | |||||
1075 | } | |||||
1076 | ||||||
1077 | ret = 0; | |||||
1078 | out: | |||||
1079 | if (quorum_action) { | |||||
1080 | /* When glusterd is restarted, it needs to wait until the 'friends' view | |||||
1081 | * of the volumes settle, before it starts any of the internal daemons. | |||||
1082 | * | |||||
1083 | * Every friend that was part of the cluster, would send its | |||||
1084 | * cluster-view, 'our' way. For every friend, who belongs to | |||||
1085 | * a partition which has a different cluster-view from our | |||||
1086 | * partition, we may update our cluster-view. For subsequent | |||||
1087 | * friends from that partition would agree with us, if the first | |||||
1088 | * friend wasn't rejected. For every first friend, whom we agreed with, | |||||
1089 | * we would need to start internal daemons/bricks belonging to the | |||||
1090 | * new volumes. | |||||
1091 | * glusterd_spawn_daemons calls functions that are idempotent. ie, | |||||
1092 | * the functions spawn process(es) only if they are not started yet. | |||||
1093 | * | |||||
1094 | * */ | |||||
1095 | glusterd_spawn_daemons ((void*) _gf_false); | |||||
1096 | glusterd_do_quorum_action (); | |||||
1097 | } | |||||
1098 | return ret; | |||||
1099 | } | |||||
1100 | ||||||
1101 | ||||||
1102 | int | |||||
1103 | glusterd_friend_sm_init () | |||||
1104 | { | |||||
1105 | INIT_LIST_HEAD (&gd_friend_sm_queue)do { (&gd_friend_sm_queue)->next = (&gd_friend_sm_queue )->prev = &gd_friend_sm_queue; } while (0); | |||||
1106 | return 0; | |||||
1107 | } |