File: | xlators/mgmt/glusterd/src/glusterd-handler.c |
Location: | line 1327, column 30 |
Description: | Access to field 'rpc_err' results in a dereference of a null pointer (loaded from variable 'req') |
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 | #ifndef _CONFIG_H | |||||
11 | #define _CONFIG_H | |||||
12 | #include "config.h" | |||||
13 | #endif | |||||
14 | #include <inttypes.h> | |||||
15 | ||||||
16 | ||||||
17 | #include "globals.h" | |||||
18 | #include "glusterfs.h" | |||||
19 | #include "compat.h" | |||||
20 | #include "dict.h" | |||||
21 | #include "protocol-common.h" | |||||
22 | #include "xlator.h" | |||||
23 | #include "logging.h" | |||||
24 | #include "timer.h" | |||||
25 | #include "defaults.h" | |||||
26 | #include "compat.h" | |||||
27 | #include "compat-errno.h" | |||||
28 | #include "statedump.h" | |||||
29 | #include "run.h" | |||||
30 | #include "glusterd-mem-types.h" | |||||
31 | #include "glusterd.h" | |||||
32 | #include "glusterd-sm.h" | |||||
33 | #include "glusterd-op-sm.h" | |||||
34 | #include "glusterd-utils.h" | |||||
35 | #include "glusterd-store.h" | |||||
36 | ||||||
37 | #include "glusterd1-xdr.h" | |||||
38 | #include "cli1-xdr.h" | |||||
39 | #include "xdr-generic.h" | |||||
40 | #include "rpc-clnt.h" | |||||
41 | #include "glusterd-volgen.h" | |||||
42 | #include "glusterd-mountbroker.h" | |||||
43 | ||||||
44 | #include <sys/resource.h> | |||||
45 | #include <inttypes.h> | |||||
46 | ||||||
47 | #include "defaults.c" | |||||
48 | #include "common-utils.h" | |||||
49 | ||||||
50 | #include "globals.h" | |||||
51 | #include "glusterd-syncop.h" | |||||
52 | ||||||
53 | #ifdef HAVE_BD_XLATOR | |||||
54 | #include <lvm2app.h> | |||||
55 | #endif | |||||
56 | ||||||
57 | int glusterd_big_locked_notify (struct rpc_clnt *rpc, void *mydata, | |||||
58 | rpc_clnt_event_t event, | |||||
59 | void *data, rpc_clnt_notify_t notify_fn) | |||||
60 | { | |||||
61 | glusterd_conf_t *priv = THIS(*__glusterfs_this_location())->private; | |||||
62 | int ret = -1; | |||||
63 | synclock_lock (&priv->big_lock); | |||||
64 | ret = notify_fn (rpc, mydata, event, data); | |||||
65 | synclock_unlock (&priv->big_lock); | |||||
66 | return ret; | |||||
67 | } | |||||
68 | ||||||
69 | int glusterd_big_locked_handler (rpcsvc_request_t *req, rpcsvc_actor actor_fn) | |||||
70 | { | |||||
71 | glusterd_conf_t *priv = THIS(*__glusterfs_this_location())->private; | |||||
72 | int ret = -1; | |||||
73 | ||||||
74 | synclock_lock (&priv->big_lock); | |||||
75 | ret = actor_fn (req); | |||||
76 | synclock_unlock (&priv->big_lock); | |||||
77 | ||||||
78 | return ret; | |||||
79 | } | |||||
80 | ||||||
81 | static int | |||||
82 | glusterd_handle_friend_req (rpcsvc_request_t *req, uuid_t uuid, | |||||
83 | char *hostname, int port, | |||||
84 | gd1_mgmt_friend_req *friend_req) | |||||
85 | { | |||||
86 | int ret = -1; | |||||
87 | glusterd_peerinfo_t *peerinfo = NULL((void*)0); | |||||
88 | glusterd_friend_sm_event_t *event = NULL((void*)0); | |||||
89 | glusterd_friend_req_ctx_t *ctx = NULL((void*)0); | |||||
90 | char rhost[UNIX_PATH_MAX108 + 1] = {0}; | |||||
91 | uuid_t friend_uuid = {0}; | |||||
92 | dict_t *dict = NULL((void*)0); | |||||
93 | ||||||
94 | uuid_parse (uuid_utoa (uuid), friend_uuid); | |||||
95 | if (!port) | |||||
96 | port = GF_DEFAULT_BASE_PORT24007; | |||||
97 | ||||||
98 | ret = glusterd_remote_hostname_get (req, rhost, sizeof (rhost)); | |||||
99 | ret = glusterd_friend_find (uuid, rhost, &peerinfo); | |||||
100 | ||||||
101 | if (ret) { | |||||
102 | ret = glusterd_xfer_friend_add_resp (req, rhost, port, -1, | |||||
103 | GF_PROBE_UNKNOWN_PEER); | |||||
104 | if (friend_req->vols.vols_val) { | |||||
105 | free (friend_req->vols.vols_val); | |||||
106 | friend_req->vols.vols_val = NULL((void*)0); | |||||
107 | } | |||||
108 | goto out; | |||||
109 | } | |||||
110 | ||||||
111 | ret = glusterd_friend_sm_new_event | |||||
112 | (GD_FRIEND_EVENT_RCVD_FRIEND_REQ, &event); | |||||
113 | ||||||
114 | if (ret) { | |||||
115 | gf_log ("", GF_LOG_ERROR, "event generation failed: %d", ret)do { do { if (0) printf ("event generation failed: %d", ret); } while (0); _gf_log ("", "glusterd-handler.c", __FUNCTION__ , 115, GF_LOG_ERROR, "event generation failed: %d", ret); } while (0); | |||||
116 | return ret; | |||||
117 | } | |||||
118 | ||||||
119 | event->peerinfo = peerinfo; | |||||
120 | ||||||
121 | ctx = GF_CALLOC (1, sizeof (*ctx), gf_gld_mt_friend_req_ctx_t)__gf_calloc (1, sizeof (*ctx), gf_gld_mt_friend_req_ctx_t); | |||||
122 | ||||||
123 | if (!ctx) { | |||||
124 | gf_log ("", GF_LOG_ERROR, "Unable to allocate memory")do { do { if (0) printf ("Unable to allocate memory"); } while (0); _gf_log ("", "glusterd-handler.c", __FUNCTION__, 124, GF_LOG_ERROR , "Unable to allocate memory"); } while (0); | |||||
125 | ret = -1; | |||||
126 | goto out; | |||||
127 | } | |||||
128 | ||||||
129 | uuid_copy (ctx->uuid, uuid); | |||||
130 | if (hostname) | |||||
131 | ctx->hostname = gf_strdup (hostname); | |||||
132 | ctx->req = req; | |||||
133 | ||||||
134 | dict = dict_new (); | |||||
135 | if (!dict) { | |||||
136 | ret = -1; | |||||
137 | goto out; | |||||
138 | } | |||||
139 | ||||||
140 | ret = dict_unserialize (friend_req->vols.vols_val, | |||||
141 | friend_req->vols.vols_len, | |||||
142 | &dict); | |||||
143 | ||||||
144 | if (ret) | |||||
145 | goto out; | |||||
146 | else | |||||
147 | dict->extra_stdfree = friend_req->vols.vols_val; | |||||
148 | ||||||
149 | ctx->vols = dict; | |||||
150 | event->ctx = ctx; | |||||
151 | ||||||
152 | ret = glusterd_friend_sm_inject_event (event); | |||||
153 | if (ret) { | |||||
154 | gf_log ("glusterd", GF_LOG_ERROR, "Unable to inject event %d, "do { do { if (0) printf ("Unable to inject event %d, " "ret = %d" , event->event, ret); } while (0); _gf_log ("glusterd", "glusterd-handler.c" , __FUNCTION__, 155, GF_LOG_ERROR, "Unable to inject event %d, " "ret = %d", event->event, ret); } while (0) | |||||
155 | "ret = %d", event->event, ret)do { do { if (0) printf ("Unable to inject event %d, " "ret = %d" , event->event, ret); } while (0); _gf_log ("glusterd", "glusterd-handler.c" , __FUNCTION__, 155, GF_LOG_ERROR, "Unable to inject event %d, " "ret = %d", event->event, ret); } while (0); | |||||
156 | goto out; | |||||
157 | } | |||||
158 | ||||||
159 | ret = 0; | |||||
160 | ||||||
161 | out: | |||||
162 | if (0 != ret) { | |||||
163 | if (ctx && ctx->hostname) | |||||
164 | GF_FREE (ctx->hostname)__gf_free (ctx->hostname); | |||||
165 | GF_FREE (ctx)__gf_free (ctx); | |||||
166 | if (dict) { | |||||
167 | if ((!dict->extra_stdfree) && | |||||
168 | friend_req->vols.vols_val) | |||||
169 | free (friend_req->vols.vols_val); | |||||
170 | dict_unref (dict); | |||||
171 | } else { | |||||
172 | free (friend_req->vols.vols_val); | |||||
173 | } | |||||
174 | GF_FREE (event)__gf_free (event); | |||||
175 | } else { | |||||
176 | if (peerinfo && (0 == peerinfo->connected)) | |||||
177 | ret = GLUSTERD_CONNECTION_AWAITED; | |||||
178 | } | |||||
179 | return ret; | |||||
180 | } | |||||
181 | ||||||
182 | static int | |||||
183 | glusterd_handle_unfriend_req (rpcsvc_request_t *req, uuid_t uuid, | |||||
184 | char *hostname, int port) | |||||
185 | { | |||||
186 | int ret = -1; | |||||
187 | glusterd_peerinfo_t *peerinfo = NULL((void*)0); | |||||
188 | glusterd_friend_sm_event_t *event = NULL((void*)0); | |||||
189 | glusterd_friend_req_ctx_t *ctx = NULL((void*)0); | |||||
190 | ||||||
191 | if (!port) | |||||
192 | port = GF_DEFAULT_BASE_PORT24007; | |||||
193 | ||||||
194 | ret = glusterd_friend_find (uuid, hostname, &peerinfo); | |||||
195 | ||||||
196 | if (ret) { | |||||
197 | gf_log ("glusterd", GF_LOG_CRITICAL,do { do { if (0) printf ("Received remove-friend from unknown peer %s" , hostname); } while (0); _gf_log ("glusterd", "glusterd-handler.c" , __FUNCTION__, 199, GF_LOG_CRITICAL, "Received remove-friend from unknown peer %s" , hostname); } while (0) | |||||
198 | "Received remove-friend from unknown peer %s",do { do { if (0) printf ("Received remove-friend from unknown peer %s" , hostname); } while (0); _gf_log ("glusterd", "glusterd-handler.c" , __FUNCTION__, 199, GF_LOG_CRITICAL, "Received remove-friend from unknown peer %s" , hostname); } while (0) | |||||
199 | hostname)do { do { if (0) printf ("Received remove-friend from unknown peer %s" , hostname); } while (0); _gf_log ("glusterd", "glusterd-handler.c" , __FUNCTION__, 199, GF_LOG_CRITICAL, "Received remove-friend from unknown peer %s" , hostname); } while (0); | |||||
200 | ret = glusterd_xfer_friend_remove_resp (req, hostname, | |||||
201 | port); | |||||
202 | goto out; | |||||
203 | } | |||||
204 | ||||||
205 | ret = glusterd_friend_sm_new_event | |||||
206 | (GD_FRIEND_EVENT_RCVD_REMOVE_FRIEND, &event); | |||||
207 | ||||||
208 | if (ret) { | |||||
209 | gf_log ("", GF_LOG_ERROR, "event generation failed: %d", ret)do { do { if (0) printf ("event generation failed: %d", ret); } while (0); _gf_log ("", "glusterd-handler.c", __FUNCTION__ , 209, GF_LOG_ERROR, "event generation failed: %d", ret); } while (0); | |||||
210 | return ret; | |||||
211 | } | |||||
212 | ||||||
213 | event->peerinfo = peerinfo; | |||||
214 | ||||||
215 | ctx = GF_CALLOC (1, sizeof (*ctx), gf_gld_mt_friend_req_ctx_t)__gf_calloc (1, sizeof (*ctx), gf_gld_mt_friend_req_ctx_t); | |||||
216 | ||||||
217 | if (!ctx) { | |||||
218 | gf_log ("", GF_LOG_ERROR, "Unable to allocate memory")do { do { if (0) printf ("Unable to allocate memory"); } while (0); _gf_log ("", "glusterd-handler.c", __FUNCTION__, 218, GF_LOG_ERROR , "Unable to allocate memory"); } while (0); | |||||
219 | ret = -1; | |||||
220 | goto out; | |||||
221 | } | |||||
222 | ||||||
223 | uuid_copy (ctx->uuid, uuid); | |||||
224 | if (hostname) | |||||
225 | ctx->hostname = gf_strdup (hostname); | |||||
226 | ctx->req = req; | |||||
227 | ||||||
228 | event->ctx = ctx; | |||||
229 | ||||||
230 | ret = glusterd_friend_sm_inject_event (event); | |||||
231 | ||||||
232 | if (ret) { | |||||
233 | gf_log ("glusterd", GF_LOG_ERROR, "Unable to inject event %d, "do { do { if (0) printf ("Unable to inject event %d, " "ret = %d" , event->event, ret); } while (0); _gf_log ("glusterd", "glusterd-handler.c" , __FUNCTION__, 234, GF_LOG_ERROR, "Unable to inject event %d, " "ret = %d", event->event, ret); } while (0) | |||||
234 | "ret = %d", event->event, ret)do { do { if (0) printf ("Unable to inject event %d, " "ret = %d" , event->event, ret); } while (0); _gf_log ("glusterd", "glusterd-handler.c" , __FUNCTION__, 234, GF_LOG_ERROR, "Unable to inject event %d, " "ret = %d", event->event, ret); } while (0); | |||||
235 | goto out; | |||||
236 | } | |||||
237 | ||||||
238 | ret = 0; | |||||
239 | ||||||
240 | out: | |||||
241 | if (0 != ret) { | |||||
242 | if (ctx && ctx->hostname) | |||||
243 | GF_FREE (ctx->hostname)__gf_free (ctx->hostname); | |||||
244 | GF_FREE (ctx)__gf_free (ctx); | |||||
245 | } | |||||
246 | ||||||
247 | return ret; | |||||
248 | } | |||||
249 | ||||||
250 | static int | |||||
251 | glusterd_add_peer_detail_to_dict (glusterd_peerinfo_t *peerinfo, | |||||
252 | dict_t *friends, int count) | |||||
253 | { | |||||
254 | ||||||
255 | int ret = -1; | |||||
256 | char key[256] = {0, }; | |||||
257 | ||||||
258 | GF_ASSERT (peerinfo)do { if (!(peerinfo)) { do { do { if (0) printf ("Assertion failed: " "peerinfo"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 258, GF_LOG_ERROR, "Assertion failed: " "peerinfo" ); } while (0); } } while (0); | |||||
259 | GF_ASSERT (friends)do { if (!(friends)) { do { do { if (0) printf ("Assertion failed: " "friends"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 259, GF_LOG_ERROR, "Assertion failed: " "friends" ); } while (0); } } while (0); | |||||
260 | ||||||
261 | snprintf (key, 256, "friend%d.uuid", count); | |||||
262 | uuid_utoa_r (peerinfo->uuid, peerinfo->uuid_str); | |||||
263 | ret = dict_set_str (friends, key, peerinfo->uuid_str); | |||||
264 | if (ret) | |||||
265 | goto out; | |||||
266 | ||||||
267 | snprintf (key, 256, "friend%d.hostname", count); | |||||
268 | ret = dict_set_str (friends, key, peerinfo->hostname); | |||||
269 | if (ret) | |||||
270 | goto out; | |||||
271 | ||||||
272 | snprintf (key, 256, "friend%d.port", count); | |||||
273 | ret = dict_set_int32 (friends, key, peerinfo->port); | |||||
274 | if (ret) | |||||
275 | goto out; | |||||
276 | ||||||
277 | snprintf (key, 256, "friend%d.stateId", count); | |||||
278 | ret = dict_set_int32 (friends, key, peerinfo->state.state); | |||||
279 | if (ret) | |||||
280 | goto out; | |||||
281 | ||||||
282 | snprintf (key, 256, "friend%d.state", count); | |||||
283 | ret = dict_set_str (friends, key, | |||||
284 | glusterd_friend_sm_state_name_get(peerinfo->state.state)); | |||||
285 | if (ret) | |||||
286 | goto out; | |||||
287 | ||||||
288 | snprintf (key, 256, "friend%d.connected", count); | |||||
289 | ret = dict_set_int32 (friends, key, (int32_t)peerinfo->connected); | |||||
290 | if (ret) | |||||
291 | goto out; | |||||
292 | ||||||
293 | out: | |||||
294 | return ret; | |||||
295 | } | |||||
296 | ||||||
297 | struct args_pack { | |||||
298 | dict_t *dict; | |||||
299 | int vol_count; | |||||
300 | int opt_count; | |||||
301 | }; | |||||
302 | ||||||
303 | static int | |||||
304 | _build_option_key (dict_t *d, char *k, data_t *v, void *tmp) | |||||
305 | { | |||||
306 | char reconfig_key[256] = {0, }; | |||||
307 | struct args_pack *pack = NULL((void*)0); | |||||
308 | int ret = -1; | |||||
309 | ||||||
310 | pack = tmp; | |||||
311 | if (strcmp (k, GLUSTERD_GLOBAL_OPT_VERSION"global-option-version") == 0) | |||||
312 | return 0; | |||||
313 | snprintf (reconfig_key, 256, "volume%d.option.%s", | |||||
314 | pack->vol_count, k); | |||||
315 | ret = dict_set_str (pack->dict, reconfig_key, v->data); | |||||
316 | if (0 == ret) | |||||
317 | pack->opt_count++; | |||||
318 | ||||||
319 | return 0; | |||||
320 | } | |||||
321 | ||||||
322 | int | |||||
323 | glusterd_add_volume_detail_to_dict (glusterd_volinfo_t *volinfo, | |||||
324 | dict_t *volumes, int count) | |||||
325 | { | |||||
326 | ||||||
327 | int ret = -1; | |||||
328 | char key[256] = {0, }; | |||||
329 | glusterd_brickinfo_t *brickinfo = NULL((void*)0); | |||||
330 | char *buf = NULL((void*)0); | |||||
331 | int i = 1; | |||||
332 | dict_t *dict = NULL((void*)0); | |||||
333 | glusterd_conf_t *priv = NULL((void*)0); | |||||
334 | char *volume_id_str = NULL((void*)0); | |||||
335 | struct args_pack pack = {0,}; | |||||
336 | xlator_t *this = NULL((void*)0); | |||||
337 | ||||||
338 | ||||||
339 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 339, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); | |||||
340 | GF_ASSERT (volumes)do { if (!(volumes)) { do { do { if (0) printf ("Assertion failed: " "volumes"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 340, GF_LOG_ERROR, "Assertion failed: " "volumes" ); } while (0); } } while (0); | |||||
341 | ||||||
342 | this = THIS(*__glusterfs_this_location()); | |||||
343 | priv = this->private; | |||||
344 | ||||||
345 | GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: " "priv"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 345, GF_LOG_ERROR, "Assertion failed: " "priv" ); } while (0); } } while (0); | |||||
346 | ||||||
347 | snprintf (key, 256, "volume%d.name", count); | |||||
348 | ret = dict_set_str (volumes, key, volinfo->volname); | |||||
349 | if (ret) | |||||
350 | goto out; | |||||
351 | ||||||
352 | snprintf (key, 256, "volume%d.type", count); | |||||
353 | ret = dict_set_int32 (volumes, key, volinfo->type); | |||||
354 | if (ret) | |||||
355 | goto out; | |||||
356 | ||||||
357 | snprintf (key, 256, "volume%d.status", count); | |||||
358 | ret = dict_set_int32 (volumes, key, volinfo->status); | |||||
359 | if (ret) | |||||
360 | goto out; | |||||
361 | ||||||
362 | snprintf (key, 256, "volume%d.brick_count", count); | |||||
363 | ret = dict_set_int32 (volumes, key, volinfo->brick_count); | |||||
364 | if (ret) | |||||
365 | goto out; | |||||
366 | ||||||
367 | snprintf (key, 256, "volume%d.dist_count", count); | |||||
368 | ret = dict_set_int32 (volumes, key, volinfo->dist_leaf_count); | |||||
369 | if (ret) | |||||
370 | goto out; | |||||
371 | ||||||
372 | snprintf (key, 256, "volume%d.stripe_count", count); | |||||
373 | ret = dict_set_int32 (volumes, key, volinfo->stripe_count); | |||||
374 | if (ret) | |||||
375 | goto out; | |||||
376 | ||||||
377 | snprintf (key, 256, "volume%d.replica_count", count); | |||||
378 | ret = dict_set_int32 (volumes, key, volinfo->replica_count); | |||||
379 | if (ret) | |||||
380 | goto out; | |||||
381 | ||||||
382 | snprintf (key, 256, "volume%d.transport", count); | |||||
383 | ret = dict_set_int32 (volumes, key, volinfo->transport_type); | |||||
384 | if (ret) | |||||
385 | goto out; | |||||
386 | ||||||
387 | volume_id_str = gf_strdup (uuid_utoa (volinfo->volume_id)); | |||||
388 | if (!volume_id_str) | |||||
389 | goto out; | |||||
390 | ||||||
391 | snprintf (key, sizeof (key), "volume%d.volume_id", count); | |||||
392 | ret = dict_set_dynstr (volumes, key, volume_id_str); | |||||
393 | if (ret) | |||||
394 | goto out; | |||||
395 | ||||||
396 | snprintf (key, 256, "volume%d.rebalance", count); | |||||
397 | ret = dict_set_int32 (volumes, key, volinfo->rebal.defrag_cmd); | |||||
398 | if (ret) | |||||
399 | goto out; | |||||
400 | ||||||
401 | #ifdef HAVE_BD_XLATOR | |||||
402 | snprintf (key, 256, "volume%d.backend", count); | |||||
403 | ret = dict_set_int32 (volumes, key, volinfo->backend); | |||||
404 | if (ret) | |||||
405 | goto out; | |||||
406 | #endif | |||||
407 | ||||||
408 | list_for_each_entry (brickinfo, &volinfo->bricks, brick_list)for (brickinfo = ((typeof(*brickinfo) *)((char *)((&volinfo ->bricks)->next)-(unsigned long)(&((typeof(*brickinfo ) *)0)->brick_list))); &brickinfo->brick_list != (& volinfo->bricks); brickinfo = ((typeof(*brickinfo) *)((char *)(brickinfo->brick_list.next)-(unsigned long)(&((typeof (*brickinfo) *)0)->brick_list)))) { | |||||
409 | char brick[1024] = {0,}; | |||||
410 | snprintf (key, 256, "volume%d.brick%d", count, i); | |||||
411 | snprintf (brick, 1024, "%s:%s", brickinfo->hostname, | |||||
412 | brickinfo->path); | |||||
413 | buf = gf_strdup (brick); | |||||
414 | ret = dict_set_dynstr (volumes, key, buf); | |||||
415 | if (ret) | |||||
416 | goto out; | |||||
417 | i++; | |||||
418 | } | |||||
419 | ||||||
420 | dict = volinfo->dict; | |||||
421 | if (!dict) { | |||||
422 | ret = 0; | |||||
423 | goto out; | |||||
424 | } | |||||
425 | ||||||
426 | pack.dict = volumes; | |||||
427 | pack.vol_count = count; | |||||
428 | pack.opt_count = 0; | |||||
429 | dict_foreach (dict, _build_option_key, (void *) &pack); | |||||
430 | dict_foreach (priv->opts, _build_option_key, &pack); | |||||
431 | ||||||
432 | snprintf (key, 256, "volume%d.opt_count", pack.vol_count); | |||||
433 | ret = dict_set_int32 (volumes, key, pack.opt_count); | |||||
434 | out: | |||||
435 | return ret; | |||||
436 | } | |||||
437 | ||||||
438 | int | |||||
439 | glusterd_friend_find (uuid_t uuid, char *hostname, | |||||
440 | glusterd_peerinfo_t **peerinfo) | |||||
441 | { | |||||
442 | int ret = -1; | |||||
443 | xlator_t *this = NULL((void*)0); | |||||
444 | ||||||
445 | this = THIS(*__glusterfs_this_location()); | |||||
446 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 446, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
447 | ||||||
448 | if (uuid) { | |||||
449 | ret = glusterd_friend_find_by_uuid (uuid, peerinfo); | |||||
450 | ||||||
451 | if (ret) { | |||||
452 | gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("Unable to find peer by uuid: %s", uuid_utoa (uuid)); } while (0); _gf_log (this->name, "glusterd-handler.c" , __FUNCTION__, 454, GF_LOG_DEBUG, "Unable to find peer by uuid: %s" , uuid_utoa (uuid)); } while (0) | |||||
453 | "Unable to find peer by uuid: %s",do { do { if (0) printf ("Unable to find peer by uuid: %s", uuid_utoa (uuid)); } while (0); _gf_log (this->name, "glusterd-handler.c" , __FUNCTION__, 454, GF_LOG_DEBUG, "Unable to find peer by uuid: %s" , uuid_utoa (uuid)); } while (0) | |||||
454 | uuid_utoa (uuid))do { do { if (0) printf ("Unable to find peer by uuid: %s", uuid_utoa (uuid)); } while (0); _gf_log (this->name, "glusterd-handler.c" , __FUNCTION__, 454, GF_LOG_DEBUG, "Unable to find peer by uuid: %s" , uuid_utoa (uuid)); } while (0); | |||||
455 | } else { | |||||
456 | goto out; | |||||
457 | } | |||||
458 | ||||||
459 | } | |||||
460 | ||||||
461 | if (hostname) { | |||||
462 | ret = glusterd_friend_find_by_hostname (hostname, peerinfo); | |||||
463 | ||||||
464 | if (ret) { | |||||
465 | gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("Unable to find hostname: %s", hostname ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 466, GF_LOG_DEBUG, "Unable to find hostname: %s" , hostname); } while (0) | |||||
466 | "Unable to find hostname: %s", hostname)do { do { if (0) printf ("Unable to find hostname: %s", hostname ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 466, GF_LOG_DEBUG, "Unable to find hostname: %s" , hostname); } while (0); | |||||
467 | } else { | |||||
468 | goto out; | |||||
469 | } | |||||
470 | } | |||||
471 | ||||||
472 | out: | |||||
473 | return ret; | |||||
474 | } | |||||
475 | ||||||
476 | int32_t | |||||
477 | glusterd_op_txn_begin (rpcsvc_request_t *req, glusterd_op_t op, void *ctx, | |||||
478 | char *err_str, size_t err_len) | |||||
479 | { | |||||
480 | int32_t ret = -1; | |||||
481 | xlator_t *this = NULL((void*)0); | |||||
482 | glusterd_conf_t *priv = NULL((void*)0); | |||||
483 | int32_t locked = 0; | |||||
484 | ||||||
485 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 485, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
486 | GF_ASSERT ((op > GD_OP_NONE) && (op < GD_OP_MAX))do { if (!((op > GD_OP_NONE) && (op < GD_OP_MAX ))) { do { do { if (0) printf ("Assertion failed: " "(op > GD_OP_NONE) && (op < GD_OP_MAX)" ); } while (0); _gf_log_callingfn ("", "glusterd-handler.c", __FUNCTION__ , 486, GF_LOG_ERROR, "Assertion failed: " "(op > GD_OP_NONE) && (op < GD_OP_MAX)" ); } while (0); } } while (0); | |||||
487 | GF_ASSERT (NULL != ctx)do { if (!(((void*)0) != ctx)) { do { do { if (0) printf ("Assertion failed: " "NULL != ctx"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 487, GF_LOG_ERROR, "Assertion failed: " "NULL != ctx" ); } while (0); } } while (0); | |||||
488 | ||||||
489 | this = THIS(*__glusterfs_this_location()); | |||||
490 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 490, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
491 | priv = this->private; | |||||
492 | GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: " "priv"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 492, GF_LOG_ERROR, "Assertion failed: " "priv" ); } while (0); } } while (0); | |||||
493 | ||||||
494 | ret = glusterd_lock (MY_UUID(__glusterd_uuid())); | |||||
495 | if (ret) { | |||||
496 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("Unable to acquire lock on localhost, ret: %d" , ret); } while (0); _gf_log (this->name, "glusterd-handler.c" , __FUNCTION__, 497, GF_LOG_ERROR, "Unable to acquire lock on localhost, ret: %d" , ret); } while (0) | |||||
497 | "Unable to acquire lock on localhost, ret: %d", ret)do { do { if (0) printf ("Unable to acquire lock on localhost, ret: %d" , ret); } while (0); _gf_log (this->name, "glusterd-handler.c" , __FUNCTION__, 497, GF_LOG_ERROR, "Unable to acquire lock on localhost, ret: %d" , ret); } while (0); | |||||
498 | snprintf (err_str, err_len, "Another transaction is in progress. " | |||||
499 | "Please try again after sometime."); | |||||
500 | goto out; | |||||
501 | } | |||||
502 | ||||||
503 | locked = 1; | |||||
504 | gf_log (this->name, GF_LOG_DEBUG, "Acquired lock on localhost")do { do { if (0) printf ("Acquired lock on localhost"); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__ , 504, GF_LOG_DEBUG, "Acquired lock on localhost"); } while ( 0); | |||||
505 | ||||||
506 | ret = glusterd_op_sm_inject_event (GD_OP_EVENT_START_LOCK, NULL((void*)0)); | |||||
507 | if (ret) { | |||||
508 | gf_log (this->name, GF_LOG_ERROR, "Failed to acquire cluster"do { do { if (0) printf ("Failed to acquire cluster" " lock." ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 509, GF_LOG_ERROR, "Failed to acquire cluster" " lock."); } while (0) | |||||
509 | " lock.")do { do { if (0) printf ("Failed to acquire cluster" " lock." ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 509, GF_LOG_ERROR, "Failed to acquire cluster" " lock."); } while (0); | |||||
510 | goto out; | |||||
511 | } | |||||
512 | ||||||
513 | glusterd_op_set_op (op); | |||||
514 | glusterd_op_set_ctx (ctx); | |||||
515 | glusterd_op_set_req (req); | |||||
516 | ||||||
517 | ||||||
518 | out: | |||||
519 | if (locked && ret) | |||||
520 | glusterd_unlock (MY_UUID(__glusterd_uuid())); | |||||
521 | ||||||
522 | gf_log (this->name, GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 522, GF_LOG_DEBUG , "Returning %d", ret); } while (0); | |||||
523 | return ret; | |||||
524 | } | |||||
525 | ||||||
526 | int | |||||
527 | __glusterd_handle_cluster_lock (rpcsvc_request_t *req) | |||||
528 | { | |||||
529 | gd1_mgmt_cluster_lock_req lock_req = {{0},}; | |||||
530 | int32_t ret = -1; | |||||
531 | glusterd_op_lock_ctx_t *ctx = NULL((void*)0); | |||||
532 | glusterd_peerinfo_t *peerinfo = NULL((void*)0); | |||||
533 | xlator_t *this = NULL((void*)0); | |||||
534 | ||||||
535 | this = THIS(*__glusterfs_this_location()); | |||||
536 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 536, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
537 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 537, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
538 | ||||||
539 | ret = xdr_to_generic (req->msg[0], &lock_req, | |||||
540 | (xdrproc_t)xdr_gd1_mgmt_cluster_lock_req); | |||||
541 | if (ret < 0) { | |||||
542 | gf_log (this->name, GF_LOG_ERROR, "Failed to decode lock "do { do { if (0) printf ("Failed to decode lock " "request received from peer" ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 543, GF_LOG_ERROR, "Failed to decode lock " "request received from peer" ); } while (0) | |||||
543 | "request received from peer")do { do { if (0) printf ("Failed to decode lock " "request received from peer" ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 543, GF_LOG_ERROR, "Failed to decode lock " "request received from peer" ); } while (0); | |||||
544 | req->rpc_err = GARBAGE_ARGS; | |||||
545 | goto out; | |||||
546 | } | |||||
547 | ||||||
548 | gf_log (this->name, GF_LOG_DEBUG, "Received LOCK from uuid: %s",do { do { if (0) printf ("Received LOCK from uuid: %s", uuid_utoa (lock_req.uuid)); } while (0); _gf_log (this->name, "glusterd-handler.c" , __FUNCTION__, 549, GF_LOG_DEBUG, "Received LOCK from uuid: %s" , uuid_utoa (lock_req.uuid)); } while (0) | |||||
549 | uuid_utoa (lock_req.uuid))do { do { if (0) printf ("Received LOCK from uuid: %s", uuid_utoa (lock_req.uuid)); } while (0); _gf_log (this->name, "glusterd-handler.c" , __FUNCTION__, 549, GF_LOG_DEBUG, "Received LOCK from uuid: %s" , uuid_utoa (lock_req.uuid)); } while (0); | |||||
550 | ||||||
551 | if (glusterd_friend_find_by_uuid (lock_req.uuid, &peerinfo)) { | |||||
552 | gf_log (this->name, GF_LOG_WARNING, "%s doesn't "do { do { if (0) printf ("%s doesn't " "belong to the cluster. Ignoring request." , uuid_utoa (lock_req.uuid)); } while (0); _gf_log (this-> name, "glusterd-handler.c", __FUNCTION__, 554, GF_LOG_WARNING , "%s doesn't " "belong to the cluster. Ignoring request.", uuid_utoa (lock_req.uuid)); } while (0) | |||||
553 | "belong to the cluster. Ignoring request.",do { do { if (0) printf ("%s doesn't " "belong to the cluster. Ignoring request." , uuid_utoa (lock_req.uuid)); } while (0); _gf_log (this-> name, "glusterd-handler.c", __FUNCTION__, 554, GF_LOG_WARNING , "%s doesn't " "belong to the cluster. Ignoring request.", uuid_utoa (lock_req.uuid)); } while (0) | |||||
554 | uuid_utoa (lock_req.uuid))do { do { if (0) printf ("%s doesn't " "belong to the cluster. Ignoring request." , uuid_utoa (lock_req.uuid)); } while (0); _gf_log (this-> name, "glusterd-handler.c", __FUNCTION__, 554, GF_LOG_WARNING , "%s doesn't " "belong to the cluster. Ignoring request.", uuid_utoa (lock_req.uuid)); } while (0); | |||||
555 | ret = -1; | |||||
556 | goto out; | |||||
557 | } | |||||
558 | ||||||
559 | ctx = GF_CALLOC (1, sizeof (*ctx), gf_gld_mt_op_lock_ctx_t)__gf_calloc (1, sizeof (*ctx), gf_gld_mt_op_lock_ctx_t); | |||||
560 | ||||||
561 | if (!ctx) { | |||||
562 | //respond here | |||||
563 | return -1; | |||||
564 | } | |||||
565 | ||||||
566 | uuid_copy (ctx->uuid, lock_req.uuid); | |||||
567 | ctx->req = req; | |||||
568 | ||||||
569 | ret = glusterd_op_sm_inject_event (GD_OP_EVENT_LOCK, ctx); | |||||
570 | ||||||
571 | out: | |||||
572 | gf_log (this->name, GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 572, GF_LOG_DEBUG , "Returning %d", ret); } while (0); | |||||
573 | ||||||
574 | glusterd_friend_sm (); | |||||
575 | glusterd_op_sm (); | |||||
576 | ||||||
577 | return ret; | |||||
578 | } | |||||
579 | ||||||
580 | int | |||||
581 | glusterd_handle_cluster_lock (rpcsvc_request_t *req) | |||||
582 | { | |||||
583 | return glusterd_big_locked_handler (req, | |||||
584 | __glusterd_handle_cluster_lock); | |||||
585 | } | |||||
586 | ||||||
587 | int | |||||
588 | glusterd_req_ctx_create (rpcsvc_request_t *rpc_req, | |||||
589 | glusterd_op_t op, uuid_t uuid, | |||||
590 | char *buf_val, size_t buf_len, | |||||
591 | gf_gld_mem_types_t mem_type, | |||||
592 | glusterd_req_ctx_t **req_ctx_out) | |||||
593 | { | |||||
594 | int ret = -1; | |||||
595 | char str[50] = {0,}; | |||||
596 | glusterd_req_ctx_t *req_ctx = NULL((void*)0); | |||||
597 | dict_t *dict = NULL((void*)0); | |||||
598 | xlator_t *this = NULL((void*)0); | |||||
599 | ||||||
600 | this = THIS(*__glusterfs_this_location()); | |||||
601 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 601, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
602 | ||||||
603 | uuid_unparse (uuid, str); | |||||
604 | gf_log (this->name, GF_LOG_DEBUG, "Received op from uuid %s", str)do { do { if (0) printf ("Received op from uuid %s", str); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__ , 604, GF_LOG_DEBUG, "Received op from uuid %s", str); } while (0); | |||||
605 | ||||||
606 | dict = dict_new (); | |||||
607 | if (!dict) | |||||
608 | goto out; | |||||
609 | ||||||
610 | req_ctx = GF_CALLOC (1, sizeof (*req_ctx), mem_type)__gf_calloc (1, sizeof (*req_ctx), mem_type); | |||||
611 | if (!req_ctx) { | |||||
612 | goto out; | |||||
613 | } | |||||
614 | ||||||
615 | uuid_copy (req_ctx->uuid, uuid); | |||||
616 | req_ctx->op = op; | |||||
617 | ret = dict_unserialize (buf_val, buf_len, &dict); | |||||
618 | if (ret) { | |||||
619 | gf_log (this->name, GF_LOG_WARNING,do { do { if (0) printf ("failed to unserialize the dictionary" ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 620, GF_LOG_WARNING, "failed to unserialize the dictionary" ); } while (0) | |||||
620 | "failed to unserialize the dictionary")do { do { if (0) printf ("failed to unserialize the dictionary" ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 620, GF_LOG_WARNING, "failed to unserialize the dictionary" ); } while (0); | |||||
621 | goto out; | |||||
622 | } | |||||
623 | ||||||
624 | req_ctx->dict = dict; | |||||
625 | req_ctx->req = rpc_req; | |||||
626 | *req_ctx_out = req_ctx; | |||||
627 | ret = 0; | |||||
628 | out: | |||||
629 | if (ret) { | |||||
630 | if (dict) | |||||
631 | dict_unref (dict); | |||||
632 | GF_FREE (req_ctx)__gf_free (req_ctx); | |||||
633 | } | |||||
634 | return ret; | |||||
635 | } | |||||
636 | ||||||
637 | int | |||||
638 | __glusterd_handle_stage_op (rpcsvc_request_t *req) | |||||
639 | { | |||||
640 | int32_t ret = -1; | |||||
641 | glusterd_req_ctx_t *req_ctx = NULL((void*)0); | |||||
642 | gd1_mgmt_stage_op_req op_req = {{0},}; | |||||
643 | glusterd_peerinfo_t *peerinfo = NULL((void*)0); | |||||
644 | xlator_t *this = NULL((void*)0); | |||||
645 | ||||||
646 | this = THIS(*__glusterfs_this_location()); | |||||
647 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 647, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
648 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 648, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
649 | ||||||
650 | ret = xdr_to_generic (req->msg[0], &op_req, | |||||
651 | (xdrproc_t)xdr_gd1_mgmt_stage_op_req); | |||||
652 | if (ret < 0) { | |||||
653 | gf_log (this->name, GF_LOG_ERROR, "Failed to decode stage "do { do { if (0) printf ("Failed to decode stage " "request received from peer" ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 654, GF_LOG_ERROR, "Failed to decode stage " "request received from peer" ); } while (0) | |||||
654 | "request received from peer")do { do { if (0) printf ("Failed to decode stage " "request received from peer" ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 654, GF_LOG_ERROR, "Failed to decode stage " "request received from peer" ); } while (0); | |||||
655 | req->rpc_err = GARBAGE_ARGS; | |||||
656 | goto out; | |||||
657 | } | |||||
658 | ||||||
659 | if (glusterd_friend_find_by_uuid (op_req.uuid, &peerinfo)) { | |||||
660 | gf_log (this->name, GF_LOG_WARNING, "%s doesn't "do { do { if (0) printf ("%s doesn't " "belong to the cluster. Ignoring request." , uuid_utoa (op_req.uuid)); } while (0); _gf_log (this->name , "glusterd-handler.c", __FUNCTION__, 662, GF_LOG_WARNING, "%s doesn't " "belong to the cluster. Ignoring request.", uuid_utoa (op_req .uuid)); } while (0) | |||||
661 | "belong to the cluster. Ignoring request.",do { do { if (0) printf ("%s doesn't " "belong to the cluster. Ignoring request." , uuid_utoa (op_req.uuid)); } while (0); _gf_log (this->name , "glusterd-handler.c", __FUNCTION__, 662, GF_LOG_WARNING, "%s doesn't " "belong to the cluster. Ignoring request.", uuid_utoa (op_req .uuid)); } while (0) | |||||
662 | uuid_utoa (op_req.uuid))do { do { if (0) printf ("%s doesn't " "belong to the cluster. Ignoring request." , uuid_utoa (op_req.uuid)); } while (0); _gf_log (this->name , "glusterd-handler.c", __FUNCTION__, 662, GF_LOG_WARNING, "%s doesn't " "belong to the cluster. Ignoring request.", uuid_utoa (op_req .uuid)); } while (0); | |||||
663 | ret = -1; | |||||
664 | goto out; | |||||
665 | } | |||||
666 | ||||||
667 | ret = glusterd_req_ctx_create (req, op_req.op, op_req.uuid, | |||||
668 | op_req.buf.buf_val, op_req.buf.buf_len, | |||||
669 | gf_gld_mt_op_stage_ctx_t, &req_ctx); | |||||
670 | if (ret) | |||||
671 | goto out; | |||||
672 | ||||||
673 | ret = glusterd_op_sm_inject_event (GD_OP_EVENT_STAGE_OP, req_ctx); | |||||
674 | ||||||
675 | out: | |||||
676 | free (op_req.buf.buf_val);//malloced by xdr | |||||
677 | glusterd_friend_sm (); | |||||
678 | glusterd_op_sm (); | |||||
679 | return ret; | |||||
680 | } | |||||
681 | ||||||
682 | int | |||||
683 | glusterd_handle_stage_op (rpcsvc_request_t *req) | |||||
684 | { | |||||
685 | return glusterd_big_locked_handler (req, __glusterd_handle_stage_op); | |||||
686 | } | |||||
687 | ||||||
688 | ||||||
689 | int | |||||
690 | __glusterd_handle_commit_op (rpcsvc_request_t *req) | |||||
691 | { | |||||
692 | int32_t ret = -1; | |||||
693 | glusterd_req_ctx_t *req_ctx = NULL((void*)0); | |||||
694 | gd1_mgmt_commit_op_req op_req = {{0},}; | |||||
695 | glusterd_peerinfo_t *peerinfo = NULL((void*)0); | |||||
696 | xlator_t *this = NULL((void*)0); | |||||
697 | ||||||
698 | this = THIS(*__glusterfs_this_location()); | |||||
699 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 699, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
700 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 700, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
701 | ||||||
702 | ret = xdr_to_generic (req->msg[0], &op_req, | |||||
703 | (xdrproc_t)xdr_gd1_mgmt_commit_op_req); | |||||
704 | if (ret < 0) { | |||||
705 | gf_log (this->name, GF_LOG_ERROR, "Failed to decode commit "do { do { if (0) printf ("Failed to decode commit " "request received from peer" ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 706, GF_LOG_ERROR, "Failed to decode commit " "request received from peer" ); } while (0) | |||||
706 | "request received from peer")do { do { if (0) printf ("Failed to decode commit " "request received from peer" ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 706, GF_LOG_ERROR, "Failed to decode commit " "request received from peer" ); } while (0); | |||||
707 | req->rpc_err = GARBAGE_ARGS; | |||||
708 | goto out; | |||||
709 | } | |||||
710 | ||||||
711 | if (glusterd_friend_find_by_uuid (op_req.uuid, &peerinfo)) { | |||||
712 | gf_log (this->name, GF_LOG_WARNING, "%s doesn't "do { do { if (0) printf ("%s doesn't " "belong to the cluster. Ignoring request." , uuid_utoa (op_req.uuid)); } while (0); _gf_log (this->name , "glusterd-handler.c", __FUNCTION__, 714, GF_LOG_WARNING, "%s doesn't " "belong to the cluster. Ignoring request.", uuid_utoa (op_req .uuid)); } while (0) | |||||
713 | "belong to the cluster. Ignoring request.",do { do { if (0) printf ("%s doesn't " "belong to the cluster. Ignoring request." , uuid_utoa (op_req.uuid)); } while (0); _gf_log (this->name , "glusterd-handler.c", __FUNCTION__, 714, GF_LOG_WARNING, "%s doesn't " "belong to the cluster. Ignoring request.", uuid_utoa (op_req .uuid)); } while (0) | |||||
714 | uuid_utoa (op_req.uuid))do { do { if (0) printf ("%s doesn't " "belong to the cluster. Ignoring request." , uuid_utoa (op_req.uuid)); } while (0); _gf_log (this->name , "glusterd-handler.c", __FUNCTION__, 714, GF_LOG_WARNING, "%s doesn't " "belong to the cluster. Ignoring request.", uuid_utoa (op_req .uuid)); } while (0); | |||||
715 | ret = -1; | |||||
716 | goto out; | |||||
717 | } | |||||
718 | ||||||
719 | //the structures should always be equal | |||||
720 | GF_ASSERT (sizeof (gd1_mgmt_commit_op_req) == sizeof (gd1_mgmt_stage_op_req))do { if (!(sizeof (gd1_mgmt_commit_op_req) == sizeof (gd1_mgmt_stage_op_req ))) { do { do { if (0) printf ("Assertion failed: " "sizeof (gd1_mgmt_commit_op_req) == sizeof (gd1_mgmt_stage_op_req)" ); } while (0); _gf_log_callingfn ("", "glusterd-handler.c", __FUNCTION__ , 720, GF_LOG_ERROR, "Assertion failed: " "sizeof (gd1_mgmt_commit_op_req) == sizeof (gd1_mgmt_stage_op_req)" ); } while (0); } } while (0); | |||||
721 | ret = glusterd_req_ctx_create (req, op_req.op, op_req.uuid, | |||||
722 | op_req.buf.buf_val, op_req.buf.buf_len, | |||||
723 | gf_gld_mt_op_commit_ctx_t, &req_ctx); | |||||
724 | if (ret) | |||||
725 | goto out; | |||||
726 | ||||||
727 | ret = glusterd_op_init_ctx (op_req.op); | |||||
728 | if (ret) | |||||
729 | goto out; | |||||
730 | ||||||
731 | ret = glusterd_op_sm_inject_event (GD_OP_EVENT_COMMIT_OP, req_ctx); | |||||
732 | ||||||
733 | out: | |||||
734 | free (op_req.buf.buf_val);//malloced by xdr | |||||
735 | glusterd_friend_sm (); | |||||
736 | glusterd_op_sm (); | |||||
737 | return ret; | |||||
738 | } | |||||
739 | ||||||
740 | int | |||||
741 | glusterd_handle_commit_op (rpcsvc_request_t *req) | |||||
742 | { | |||||
743 | return glusterd_big_locked_handler (req, __glusterd_handle_commit_op); | |||||
744 | } | |||||
745 | ||||||
746 | int | |||||
747 | __glusterd_handle_cli_probe (rpcsvc_request_t *req) | |||||
748 | { | |||||
749 | int32_t ret = -1; | |||||
750 | gf1_cli_probe_req cli_req = {0,}; | |||||
751 | glusterd_peerinfo_t *peerinfo = NULL((void*)0); | |||||
752 | gf_boolean_t run_fsm = _gf_true; | |||||
753 | xlator_t *this = NULL((void*)0); | |||||
754 | char *bind_name = NULL((void*)0); | |||||
755 | ||||||
756 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 756, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
757 | this = THIS(*__glusterfs_this_location()); | |||||
758 | ||||||
759 | ret = xdr_to_generic (req->msg[0], &cli_req, | |||||
760 | (xdrproc_t)xdr_gf1_cli_probe_req); | |||||
761 | if (ret < 0) { | |||||
762 | //failed to decode msg; | |||||
763 | gf_log ("", GF_LOG_ERROR, "xdr decoding error")do { do { if (0) printf ("xdr decoding error"); } while (0); _gf_log ("", "glusterd-handler.c", __FUNCTION__, 763, GF_LOG_ERROR, "xdr decoding error" ); } while (0); | |||||
764 | req->rpc_err = GARBAGE_ARGS; | |||||
765 | goto out; | |||||
766 | } | |||||
767 | ||||||
768 | if (glusterd_is_any_volume_in_server_quorum (this) && | |||||
769 | !does_gd_meet_server_quorum (this)) { | |||||
770 | glusterd_xfer_cli_probe_resp (req, -1, GF_PROBE_QUORUM_NOT_MET, | |||||
771 | NULL((void*)0), | |||||
772 | cli_req.hostname, cli_req.port); | |||||
773 | gf_log (this->name, GF_LOG_ERROR, "Quorum does not meet, "do { do { if (0) printf ("Quorum does not meet, " "rejecting operation" ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 774, GF_LOG_ERROR, "Quorum does not meet, " "rejecting operation" ); } while (0) | |||||
774 | "rejecting operation")do { do { if (0) printf ("Quorum does not meet, " "rejecting operation" ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 774, GF_LOG_ERROR, "Quorum does not meet, " "rejecting operation" ); } while (0); | |||||
775 | ret = 0; | |||||
776 | goto out; | |||||
777 | } | |||||
778 | ||||||
779 | gf_cmd_log ("peer probe", " on host %s:%d", cli_req.hostname, | |||||
780 | cli_req.port); | |||||
781 | gf_log ("glusterd", GF_LOG_INFO, "Received CLI probe req %s %d",do { do { if (0) printf ("Received CLI probe req %s %d", cli_req .hostname, cli_req.port); } while (0); _gf_log ("glusterd", "glusterd-handler.c" , __FUNCTION__, 782, GF_LOG_INFO, "Received CLI probe req %s %d" , cli_req.hostname, cli_req.port); } while (0) | |||||
782 | cli_req.hostname, cli_req.port)do { do { if (0) printf ("Received CLI probe req %s %d", cli_req .hostname, cli_req.port); } while (0); _gf_log ("glusterd", "glusterd-handler.c" , __FUNCTION__, 782, GF_LOG_INFO, "Received CLI probe req %s %d" , cli_req.hostname, cli_req.port); } while (0); | |||||
783 | ||||||
784 | if (dict_get_str(this->options,"transport.socket.bind-address", | |||||
785 | &bind_name) == 0) { | |||||
786 | gf_log ("glusterd", GF_LOG_DEBUG,do { do { if (0) printf ("only checking probe address vs. bind address" ); } while (0); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__ , 787, GF_LOG_DEBUG, "only checking probe address vs. bind address" ); } while (0) | |||||
787 | "only checking probe address vs. bind address")do { do { if (0) printf ("only checking probe address vs. bind address" ); } while (0); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__ , 787, GF_LOG_DEBUG, "only checking probe address vs. bind address" ); } while (0); | |||||
788 | ret = glusterd_is_same_address(bind_name,cli_req.hostname); | |||||
789 | } | |||||
790 | else { | |||||
791 | ret = glusterd_is_local_addr(cli_req.hostname); | |||||
792 | } | |||||
793 | if (ret) { | |||||
794 | glusterd_xfer_cli_probe_resp (req, 0, GF_PROBE_LOCALHOST, NULL((void*)0), | |||||
795 | cli_req.hostname, cli_req.port); | |||||
796 | ret = 0; | |||||
797 | goto out; | |||||
798 | } | |||||
799 | ||||||
800 | if (!(ret = glusterd_friend_find_by_hostname(cli_req.hostname, | |||||
801 | &peerinfo))) { | |||||
802 | if (strcmp (peerinfo->hostname, cli_req.hostname) == 0) { | |||||
803 | ||||||
804 | gf_log ("glusterd", GF_LOG_DEBUG, "Probe host %s port "do { do { if (0) printf ("Probe host %s port " "%d already a peer" , cli_req.hostname, cli_req.port); } while (0); _gf_log ("glusterd" , "glusterd-handler.c", __FUNCTION__, 806, GF_LOG_DEBUG, "Probe host %s port " "%d already a peer", cli_req.hostname, cli_req.port); } while (0) | |||||
805 | "%d already a peer", cli_req.hostname,do { do { if (0) printf ("Probe host %s port " "%d already a peer" , cli_req.hostname, cli_req.port); } while (0); _gf_log ("glusterd" , "glusterd-handler.c", __FUNCTION__, 806, GF_LOG_DEBUG, "Probe host %s port " "%d already a peer", cli_req.hostname, cli_req.port); } while (0) | |||||
806 | cli_req.port)do { do { if (0) printf ("Probe host %s port " "%d already a peer" , cli_req.hostname, cli_req.port); } while (0); _gf_log ("glusterd" , "glusterd-handler.c", __FUNCTION__, 806, GF_LOG_DEBUG, "Probe host %s port " "%d already a peer", cli_req.hostname, cli_req.port); } while (0); | |||||
807 | glusterd_xfer_cli_probe_resp (req, 0, GF_PROBE_FRIEND, | |||||
808 | NULL((void*)0), cli_req.hostname, | |||||
809 | cli_req.port); | |||||
810 | goto out; | |||||
811 | } | |||||
812 | } | |||||
813 | ret = glusterd_probe_begin (req, cli_req.hostname, cli_req.port); | |||||
814 | ||||||
815 | gf_cmd_log ("peer probe","on host %s:%d %s",cli_req.hostname, | |||||
816 | cli_req.port, (ret) ? "FAILED" : "SUCCESS"); | |||||
817 | ||||||
818 | if (ret == GLUSTERD_CONNECTION_AWAITED) { | |||||
819 | //fsm should be run after connection establishes | |||||
820 | run_fsm = _gf_false; | |||||
821 | ret = 0; | |||||
822 | } | |||||
823 | out: | |||||
824 | free (cli_req.hostname);//its malloced by xdr | |||||
825 | ||||||
826 | if (run_fsm) { | |||||
827 | glusterd_friend_sm (); | |||||
828 | glusterd_op_sm (); | |||||
829 | } | |||||
830 | ||||||
831 | return ret; | |||||
832 | } | |||||
833 | ||||||
834 | int | |||||
835 | glusterd_handle_cli_probe (rpcsvc_request_t *req) | |||||
836 | { | |||||
837 | return glusterd_big_locked_handler (req, __glusterd_handle_cli_probe); | |||||
838 | } | |||||
839 | ||||||
840 | int | |||||
841 | __glusterd_handle_cli_deprobe (rpcsvc_request_t *req) | |||||
842 | { | |||||
843 | int32_t ret = -1; | |||||
844 | gf1_cli_deprobe_req cli_req = {0,}; | |||||
845 | uuid_t uuid = {0}; | |||||
846 | int op_errno = 0; | |||||
847 | xlator_t *this = NULL((void*)0); | |||||
848 | glusterd_conf_t *priv = NULL((void*)0); | |||||
849 | ||||||
850 | this = THIS(*__glusterfs_this_location()); | |||||
851 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 851, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
852 | priv = this->private; | |||||
853 | GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: " "priv"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 853, GF_LOG_ERROR, "Assertion failed: " "priv" ); } while (0); } } while (0); | |||||
854 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 854, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
855 | ||||||
856 | ret = xdr_to_generic (req->msg[0], &cli_req, | |||||
857 | (xdrproc_t)xdr_gf1_cli_deprobe_req); | |||||
858 | if (ret < 0) { | |||||
859 | //failed to decode msg; | |||||
860 | req->rpc_err = GARBAGE_ARGS; | |||||
861 | goto out; | |||||
862 | } | |||||
863 | ||||||
864 | gf_log ("glusterd", GF_LOG_INFO, "Received CLI deprobe req")do { do { if (0) printf ("Received CLI deprobe req"); } while (0); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__ , 864, GF_LOG_INFO, "Received CLI deprobe req"); } while (0); | |||||
865 | ||||||
866 | ret = glusterd_hostname_to_uuid (cli_req.hostname, uuid); | |||||
867 | if (ret) { | |||||
868 | op_errno = GF_DEPROBE_NOT_FRIEND; | |||||
869 | goto out; | |||||
870 | } | |||||
871 | ||||||
872 | if (!uuid_compare (uuid, MY_UUID(__glusterd_uuid()))) { | |||||
873 | op_errno = GF_DEPROBE_LOCALHOST; | |||||
874 | ret = -1; | |||||
875 | goto out; | |||||
876 | } | |||||
877 | ||||||
878 | if (!(cli_req.flags & GF_CLI_FLAG_OP_FORCE)) { | |||||
879 | if (!uuid_is_null (uuid)) { | |||||
880 | /* Check if peers are connected, except peer being detached*/ | |||||
881 | if (!glusterd_chk_peers_connected_befriended (uuid)) { | |||||
882 | ret = -1; | |||||
883 | op_errno = GF_DEPROBE_FRIEND_DOWN; | |||||
884 | goto out; | |||||
885 | } | |||||
886 | ret = glusterd_all_volume_cond_check ( | |||||
887 | glusterd_friend_brick_belongs, | |||||
888 | -1, &uuid); | |||||
889 | if (ret) { | |||||
890 | op_errno = GF_DEPROBE_BRICK_EXIST; | |||||
891 | goto out; | |||||
892 | } | |||||
893 | } | |||||
894 | ||||||
895 | if (glusterd_is_any_volume_in_server_quorum (this) && | |||||
896 | !does_gd_meet_server_quorum (this)) { | |||||
897 | gf_log (this->name, GF_LOG_ERROR, "Quorum does not "do { do { if (0) printf ("Quorum does not " "meet, rejecting operation" ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 898, GF_LOG_ERROR, "Quorum does not " "meet, rejecting operation" ); } while (0) | |||||
898 | "meet, rejecting operation")do { do { if (0) printf ("Quorum does not " "meet, rejecting operation" ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 898, GF_LOG_ERROR, "Quorum does not " "meet, rejecting operation" ); } while (0); | |||||
899 | ret = -1; | |||||
900 | op_errno = GF_DEPROBE_QUORUM_NOT_MET; | |||||
901 | goto out; | |||||
902 | } | |||||
903 | } | |||||
904 | ||||||
905 | if (!uuid_is_null (uuid)) { | |||||
906 | ret = glusterd_deprobe_begin (req, cli_req.hostname, | |||||
907 | cli_req.port, uuid); | |||||
908 | } else { | |||||
909 | ret = glusterd_deprobe_begin (req, cli_req.hostname, | |||||
910 | cli_req.port, NULL((void*)0)); | |||||
911 | } | |||||
912 | ||||||
913 | gf_cmd_log ("peer deprobe", "on host %s:%d %s", cli_req.hostname, | |||||
914 | cli_req.port, (ret) ? "FAILED" : "SUCCESS"); | |||||
915 | out: | |||||
916 | if (ret) { | |||||
917 | ret = glusterd_xfer_cli_deprobe_resp (req, ret, op_errno, NULL((void*)0), | |||||
918 | cli_req.hostname); | |||||
919 | } | |||||
920 | ||||||
921 | free (cli_req.hostname);//malloced by xdr | |||||
922 | ||||||
923 | glusterd_friend_sm (); | |||||
924 | glusterd_op_sm (); | |||||
925 | ||||||
926 | return ret; | |||||
927 | } | |||||
928 | ||||||
929 | int | |||||
930 | glusterd_handle_cli_deprobe (rpcsvc_request_t *req) | |||||
931 | { | |||||
932 | return glusterd_big_locked_handler (req, __glusterd_handle_cli_deprobe); | |||||
933 | } | |||||
934 | ||||||
935 | int | |||||
936 | __glusterd_handle_cli_list_friends (rpcsvc_request_t *req) | |||||
937 | { | |||||
938 | int32_t ret = -1; | |||||
939 | gf1_cli_peer_list_req cli_req = {0,}; | |||||
940 | dict_t *dict = NULL((void*)0); | |||||
941 | ||||||
942 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 942, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
943 | ||||||
944 | ret = xdr_to_generic (req->msg[0], &cli_req, | |||||
945 | (xdrproc_t)xdr_gf1_cli_peer_list_req); | |||||
946 | if (ret < 0) { | |||||
947 | //failed to decode msg; | |||||
948 | req->rpc_err = GARBAGE_ARGS; | |||||
949 | goto out; | |||||
950 | } | |||||
951 | ||||||
952 | gf_log ("glusterd", GF_LOG_INFO, "Received cli list req")do { do { if (0) printf ("Received cli list req"); } while (0 ); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__, 952 , GF_LOG_INFO, "Received cli list req"); } while (0); | |||||
953 | ||||||
954 | if (cli_req.dict.dict_len) { | |||||
955 | /* Unserialize the dictionary */ | |||||
956 | dict = dict_new (); | |||||
957 | ||||||
958 | ret = dict_unserialize (cli_req.dict.dict_val, | |||||
959 | cli_req.dict.dict_len, | |||||
960 | &dict); | |||||
961 | if (ret < 0) { | |||||
962 | gf_log ("glusterd", GF_LOG_ERROR,do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__ , 964, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0) | |||||
963 | "failed to "do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__ , 964, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0) | |||||
964 | "unserialize req-buffer to dictionary")do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__ , 964, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0); | |||||
965 | goto out; | |||||
966 | } else { | |||||
967 | dict->extra_stdfree = cli_req.dict.dict_val; | |||||
968 | } | |||||
969 | } | |||||
970 | ||||||
971 | ret = glusterd_list_friends (req, dict, cli_req.flags); | |||||
972 | ||||||
973 | out: | |||||
974 | if (dict) | |||||
975 | dict_unref (dict); | |||||
976 | ||||||
977 | glusterd_friend_sm (); | |||||
978 | glusterd_op_sm (); | |||||
979 | ||||||
980 | return ret; | |||||
981 | } | |||||
982 | ||||||
983 | int | |||||
984 | glusterd_handle_cli_list_friends (rpcsvc_request_t *req) | |||||
985 | { | |||||
986 | return glusterd_big_locked_handler (req, | |||||
987 | __glusterd_handle_cli_list_friends); | |||||
988 | } | |||||
989 | ||||||
990 | int | |||||
991 | __glusterd_handle_cli_get_volume (rpcsvc_request_t *req) | |||||
992 | { | |||||
993 | int32_t ret = -1; | |||||
994 | gf_cli_req cli_req = {{0,}}; | |||||
995 | dict_t *dict = NULL((void*)0); | |||||
996 | int32_t flags = 0; | |||||
997 | ||||||
998 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 998, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
999 | ||||||
1000 | ret = xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req); | |||||
1001 | if (ret < 0) { | |||||
1002 | //failed to decode msg; | |||||
1003 | req->rpc_err = GARBAGE_ARGS; | |||||
1004 | goto out; | |||||
1005 | } | |||||
1006 | ||||||
1007 | gf_log ("glusterd", GF_LOG_INFO, "Received get vol req")do { do { if (0) printf ("Received get vol req"); } while (0) ; _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__, 1007 , GF_LOG_INFO, "Received get vol req"); } while (0); | |||||
1008 | ||||||
1009 | if (cli_req.dict.dict_len) { | |||||
1010 | /* Unserialize the dictionary */ | |||||
1011 | dict = dict_new (); | |||||
1012 | ||||||
1013 | ret = dict_unserialize (cli_req.dict.dict_val, | |||||
1014 | cli_req.dict.dict_len, | |||||
1015 | &dict); | |||||
1016 | if (ret < 0) { | |||||
1017 | gf_log ("glusterd", GF_LOG_ERROR,do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__ , 1019, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0) | |||||
1018 | "failed to "do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__ , 1019, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0) | |||||
1019 | "unserialize req-buffer to dictionary")do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__ , 1019, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0); | |||||
1020 | goto out; | |||||
1021 | } else { | |||||
1022 | dict->extra_stdfree = cli_req.dict.dict_val; | |||||
1023 | } | |||||
1024 | } | |||||
1025 | ||||||
1026 | ret = dict_get_int32 (dict, "flags", &flags); | |||||
1027 | if (ret) { | |||||
1028 | gf_log (THIS->name, GF_LOG_ERROR, "failed to get flags")do { do { if (0) printf ("failed to get flags"); } while (0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-handler.c" , __FUNCTION__, 1028, GF_LOG_ERROR, "failed to get flags"); } while (0); | |||||
1029 | goto out; | |||||
1030 | } | |||||
1031 | ||||||
1032 | ret = glusterd_get_volumes (req, dict, flags); | |||||
1033 | ||||||
1034 | out: | |||||
1035 | if (dict) | |||||
1036 | dict_unref (dict); | |||||
1037 | ||||||
1038 | glusterd_friend_sm (); | |||||
1039 | glusterd_op_sm (); | |||||
1040 | ||||||
1041 | return ret; | |||||
1042 | } | |||||
1043 | ||||||
1044 | int | |||||
1045 | glusterd_handle_cli_get_volume (rpcsvc_request_t *req) | |||||
1046 | { | |||||
1047 | return glusterd_big_locked_handler (req, | |||||
1048 | __glusterd_handle_cli_get_volume); | |||||
1049 | } | |||||
1050 | ||||||
1051 | #ifdef HAVE_BD_XLATOR | |||||
1052 | int | |||||
1053 | __glusterd_handle_cli_bd_op (rpcsvc_request_t *req) | |||||
1054 | { | |||||
1055 | int32_t ret = -1; | |||||
1056 | gf_cli_req cli_req = { {0,} }; | |||||
1057 | dict_t *dict = NULL((void*)0); | |||||
1058 | char *volname = NULL((void*)0); | |||||
1059 | char op_errstr[2048] = {0,}; | |||||
1060 | glusterd_op_t cli_op = GD_OP_BD_OP; | |||||
1061 | ||||||
1062 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 1062, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
1063 | ||||||
1064 | ret = xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req); | |||||
1065 | if (ret < 0) { | |||||
1066 | /* failed to decode msg */ | |||||
1067 | req->rpc_err = GARBAGE_ARGS; | |||||
1068 | goto out; | |||||
1069 | } | |||||
1070 | ||||||
1071 | gf_log ("glusterd", GF_LOG_DEBUG, "Received bd op req")do { do { if (0) printf ("Received bd op req"); } while (0); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__, 1071, GF_LOG_DEBUG , "Received bd op req"); } while (0); | |||||
1072 | ||||||
1073 | if (cli_req.dict.dict_len) { | |||||
1074 | /* Unserialize the dictionary */ | |||||
1075 | dict = dict_new (); | |||||
1076 | ||||||
1077 | ret = dict_unserialize (cli_req.dict.dict_val, | |||||
1078 | cli_req.dict.dict_len, | |||||
1079 | &dict); | |||||
1080 | if (ret < 0) { | |||||
1081 | gf_log ("glusterd", GF_LOG_ERROR,do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__ , 1083, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0) | |||||
1082 | "failed to "do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__ , 1083, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0) | |||||
1083 | "unserialize req-buffer to dictionary")do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__ , 1083, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0); | |||||
1084 | goto out; | |||||
1085 | } else { | |||||
1086 | dict->extra_stdfree = cli_req.dict.dict_val; | |||||
1087 | } | |||||
1088 | } | |||||
1089 | ||||||
1090 | ret = dict_get_str (dict, "volname", &volname); | |||||
1091 | if (ret) { | |||||
1092 | gf_log (THIS->name, GF_LOG_ERROR,do { do { if (0) printf ("failed to get volname"); } while (0 ); _gf_log ((*__glusterfs_this_location())->name, "glusterd-handler.c" , __FUNCTION__, 1093, GF_LOG_ERROR, "failed to get volname"); } while (0) | |||||
1093 | "failed to get volname")do { do { if (0) printf ("failed to get volname"); } while (0 ); _gf_log ((*__glusterfs_this_location())->name, "glusterd-handler.c" , __FUNCTION__, 1093, GF_LOG_ERROR, "failed to get volname"); } while (0); | |||||
1094 | goto out; | |||||
1095 | } | |||||
1096 | ||||||
1097 | ret = glusterd_op_begin (req, GD_OP_BD_OP, dict, op_errstr, | |||||
1098 | sizeof (op_errstr)); | |||||
1099 | gf_cmd_log ("bd op: %s", ((ret == 0) ? "SUCCESS": "FAILED")); | |||||
1100 | out: | |||||
1101 | if (ret && dict) | |||||
1102 | dict_unref (dict); | |||||
1103 | ||||||
1104 | glusterd_friend_sm (); | |||||
1105 | glusterd_op_sm (); | |||||
1106 | ||||||
1107 | if (ret) { | |||||
1108 | if (op_errstr[0] == '\0') | |||||
1109 | snprintf (op_errstr, sizeof (op_errstr), | |||||
1110 | "Operation failed"); | |||||
1111 | ret = glusterd_op_send_cli_response (cli_op, ret, 0, | |||||
1112 | req, NULL((void*)0), op_errstr); | |||||
1113 | } | |||||
1114 | ||||||
1115 | return ret; | |||||
1116 | } | |||||
1117 | ||||||
1118 | int | |||||
1119 | glusterd_handle_cli_bd_op (rpcsvc_request_t *req) | |||||
1120 | { | |||||
1121 | return glusterd_big_locked_handler (req, __glusterd_handle_cli_bd_op); | |||||
1122 | } | |||||
1123 | #endif | |||||
1124 | ||||||
1125 | int | |||||
1126 | __glusterd_handle_cli_uuid_reset (rpcsvc_request_t *req) | |||||
1127 | { | |||||
1128 | int ret = -1; | |||||
1129 | dict_t *dict = NULL((void*)0); | |||||
1130 | xlator_t *this = NULL((void*)0); | |||||
1131 | glusterd_conf_t *priv = NULL((void*)0); | |||||
1132 | uuid_t uuid = {0}; | |||||
1133 | gf_cli_rsp rsp = {0,}; | |||||
1134 | gf_cli_req cli_req = {{0,}}; | |||||
1135 | char msg_str[2048] = {0,}; | |||||
1136 | ||||||
1137 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 1137, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
1138 | ||||||
1139 | this = THIS(*__glusterfs_this_location()); | |||||
1140 | priv = this->private; | |||||
1141 | GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: " "priv"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 1141, GF_LOG_ERROR, "Assertion failed: " "priv" ); } while (0); } } while (0); | |||||
1142 | ||||||
1143 | ret = xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req); | |||||
1144 | if (ret < 0) { | |||||
1145 | //failed to decode msg; | |||||
1146 | req->rpc_err = GARBAGE_ARGS; | |||||
1147 | goto out; | |||||
1148 | } | |||||
1149 | ||||||
1150 | gf_log ("glusterd", GF_LOG_DEBUG, "Received uuid reset req")do { do { if (0) printf ("Received uuid reset req"); } while ( 0); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__, 1150 , GF_LOG_DEBUG, "Received uuid reset req"); } while (0); | |||||
1151 | ||||||
1152 | if (cli_req.dict.dict_len) { | |||||
1153 | /* Unserialize the dictionary */ | |||||
1154 | dict = dict_new (); | |||||
1155 | ||||||
1156 | ret = dict_unserialize (cli_req.dict.dict_val, | |||||
1157 | cli_req.dict.dict_len, | |||||
1158 | &dict); | |||||
1159 | if (ret < 0) { | |||||
1160 | gf_log ("glusterd", GF_LOG_ERROR,do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__ , 1162, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0) | |||||
1161 | "failed to "do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__ , 1162, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0) | |||||
1162 | "unserialize req-buffer to dictionary")do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__ , 1162, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0); | |||||
1163 | snprintf (msg_str, sizeof (msg_str), "Unable to decode " | |||||
1164 | "the buffer"); | |||||
1165 | goto out; | |||||
1166 | } else { | |||||
1167 | dict->extra_stdfree = cli_req.dict.dict_val; | |||||
1168 | } | |||||
1169 | } | |||||
1170 | ||||||
1171 | /* In the above section if dict_unserialize is successful, ret is set | |||||
1172 | * to zero. | |||||
1173 | */ | |||||
1174 | ret = -1; | |||||
1175 | // Do not allow peer reset if there are any volumes in the cluster | |||||
1176 | if (!list_empty (&priv->volumes)) { | |||||
1177 | snprintf (msg_str, sizeof (msg_str), "volumes are already " | |||||
1178 | "present in the cluster. Resetting uuid is not " | |||||
1179 | "allowed"); | |||||
1180 | gf_log (this->name, GF_LOG_WARNING, "%s", msg_str)do { do { if (0) printf ("%s", msg_str); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 1180, GF_LOG_WARNING , "%s", msg_str); } while (0); | |||||
1181 | goto out; | |||||
1182 | } | |||||
1183 | ||||||
1184 | // Do not allow peer reset if trusted storage pool is already formed | |||||
1185 | if (!list_empty (&priv->peers)) { | |||||
1186 | snprintf (msg_str, sizeof (msg_str),"trusted storage pool " | |||||
1187 | "has been already formed. Please detach this peer " | |||||
1188 | "from the pool and reset its uuid."); | |||||
1189 | gf_log (this->name, GF_LOG_WARNING, "%s", msg_str)do { do { if (0) printf ("%s", msg_str); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 1189, GF_LOG_WARNING , "%s", msg_str); } while (0); | |||||
1190 | goto out; | |||||
1191 | } | |||||
1192 | ||||||
1193 | uuid_copy (uuid, priv->uuid); | |||||
1194 | ret = glusterd_uuid_generate_save (); | |||||
1195 | ||||||
1196 | if (!uuid_compare (uuid, MY_UUID(__glusterd_uuid()))) { | |||||
1197 | snprintf (msg_str, sizeof (msg_str), "old uuid and the new uuid" | |||||
1198 | " are same. Try gluster peer reset again"); | |||||
1199 | gf_log (this->name, GF_LOG_ERROR, "%s", msg_str)do { do { if (0) printf ("%s", msg_str); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 1199, GF_LOG_ERROR , "%s", msg_str); } while (0); | |||||
1200 | ret = -1; | |||||
1201 | goto out; | |||||
1202 | } | |||||
1203 | ||||||
1204 | out: | |||||
1205 | if (ret) { | |||||
1206 | rsp.op_ret = -1; | |||||
1207 | if (msg_str[0] == '\0') | |||||
1208 | snprintf (msg_str, sizeof (msg_str), "Operation " | |||||
1209 | "failed"); | |||||
1210 | rsp.op_errstr = msg_str; | |||||
1211 | ret = 0; | |||||
1212 | } else { | |||||
1213 | rsp.op_errstr = ""; | |||||
1214 | } | |||||
1215 | ||||||
1216 | glusterd_to_cli (req, &rsp, NULL((void*)0), 0, NULL((void*)0), | |||||
1217 | (xdrproc_t)xdr_gf_cli_rsp, dict); | |||||
1218 | ||||||
1219 | return ret; | |||||
1220 | } | |||||
1221 | ||||||
1222 | int | |||||
1223 | glusterd_handle_cli_uuid_reset (rpcsvc_request_t *req) | |||||
1224 | { | |||||
1225 | return glusterd_big_locked_handler (req, | |||||
1226 | __glusterd_handle_cli_uuid_reset); | |||||
1227 | } | |||||
1228 | ||||||
1229 | int | |||||
1230 | __glusterd_handle_cli_list_volume (rpcsvc_request_t *req) | |||||
1231 | { | |||||
1232 | int ret = -1; | |||||
1233 | dict_t *dict = NULL((void*)0); | |||||
1234 | glusterd_conf_t *priv = NULL((void*)0); | |||||
1235 | glusterd_volinfo_t *volinfo = NULL((void*)0); | |||||
1236 | int count = 0; | |||||
1237 | char key[1024] = {0,}; | |||||
1238 | gf_cli_rsp rsp = {0,}; | |||||
1239 | ||||||
1240 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 1240, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
1241 | ||||||
1242 | priv = THIS(*__glusterfs_this_location())->private; | |||||
1243 | GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: " "priv"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 1243, GF_LOG_ERROR, "Assertion failed: " "priv" ); } while (0); } } while (0); | |||||
1244 | ||||||
1245 | dict = dict_new (); | |||||
1246 | if (!dict) | |||||
1247 | goto out; | |||||
1248 | ||||||
1249 | list_for_each_entry (volinfo, &priv->volumes, vol_list)for (volinfo = ((typeof(*volinfo) *)((char *)((&priv-> volumes)->next)-(unsigned long)(&((typeof(*volinfo) *) 0)->vol_list))); &volinfo->vol_list != (&priv-> volumes); volinfo = ((typeof(*volinfo) *)((char *)(volinfo-> vol_list.next)-(unsigned long)(&((typeof(*volinfo) *)0)-> vol_list)))) { | |||||
1250 | memset (key, 0, sizeof (key)); | |||||
1251 | snprintf (key, sizeof (key), "volume%d", count); | |||||
1252 | ret = dict_set_str (dict, key, volinfo->volname); | |||||
1253 | if (ret) | |||||
1254 | goto out; | |||||
1255 | count++; | |||||
1256 | } | |||||
1257 | ||||||
1258 | ret = dict_set_int32 (dict, "count", count); | |||||
1259 | if (ret) | |||||
1260 | goto out; | |||||
1261 | ||||||
1262 | ret = dict_allocate_and_serialize (dict, &rsp.dict.dict_val, | |||||
1263 | &rsp.dict.dict_len); | |||||
1264 | if (ret) | |||||
1265 | goto out; | |||||
1266 | ||||||
1267 | ret = 0; | |||||
1268 | ||||||
1269 | out: | |||||
1270 | rsp.op_ret = ret; | |||||
1271 | if (ret) | |||||
1272 | rsp.op_errstr = "Error listing volumes"; | |||||
1273 | else | |||||
1274 | rsp.op_errstr = ""; | |||||
1275 | ||||||
1276 | glusterd_submit_reply (req, &rsp, NULL((void*)0), 0, NULL((void*)0), | |||||
1277 | (xdrproc_t)xdr_gf_cli_rsp); | |||||
1278 | ret = 0; | |||||
1279 | ||||||
1280 | if (dict) | |||||
1281 | dict_unref (dict); | |||||
1282 | ||||||
1283 | glusterd_friend_sm (); | |||||
1284 | glusterd_op_sm (); | |||||
1285 | ||||||
1286 | return ret; | |||||
1287 | } | |||||
1288 | ||||||
1289 | int | |||||
1290 | glusterd_handle_cli_list_volume (rpcsvc_request_t *req) | |||||
1291 | { | |||||
1292 | return glusterd_big_locked_handler (req, | |||||
1293 | __glusterd_handle_cli_list_volume); | |||||
1294 | } | |||||
1295 | ||||||
1296 | int32_t | |||||
1297 | glusterd_op_begin (rpcsvc_request_t *req, glusterd_op_t op, void *ctx, | |||||
1298 | char *err_str, size_t err_len) | |||||
1299 | { | |||||
1300 | int ret = -1; | |||||
1301 | ||||||
1302 | ret = glusterd_op_txn_begin (req, op, ctx, err_str, err_len); | |||||
1303 | ||||||
1304 | return ret; | |||||
1305 | } | |||||
1306 | ||||||
1307 | int | |||||
1308 | __glusterd_handle_reset_volume (rpcsvc_request_t *req) | |||||
1309 | { | |||||
1310 | int32_t ret = -1; | |||||
1311 | gf_cli_req cli_req = {{0,}}; | |||||
1312 | dict_t *dict = NULL((void*)0); | |||||
1313 | glusterd_op_t cli_op = GD_OP_RESET_VOLUME; | |||||
1314 | char *volname = NULL((void*)0); | |||||
1315 | char err_str[2048] = {0,}; | |||||
1316 | xlator_t *this = NULL((void*)0); | |||||
1317 | ||||||
1318 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 1318, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
| ||||||
1319 | this = THIS(*__glusterfs_this_location()); | |||||
1320 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 1320, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
1321 | ||||||
1322 | ret = xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req); | |||||
1323 | if (ret < 0) { | |||||
1324 | snprintf (err_str, sizeof (err_str), "Failed to decode request " | |||||
1325 | "received from cli"); | |||||
1326 | gf_log (this->name, GF_LOG_ERROR, "%s", err_str)do { do { if (0) printf ("%s", err_str); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 1326, GF_LOG_ERROR , "%s", err_str); } while (0); | |||||
1327 | req->rpc_err = GARBAGE_ARGS; | |||||
| ||||||
1328 | goto out; | |||||
1329 | } | |||||
1330 | ||||||
1331 | if (cli_req.dict.dict_len) { | |||||
1332 | /* Unserialize the dictionary */ | |||||
1333 | dict = dict_new (); | |||||
1334 | ||||||
1335 | ret = dict_unserialize (cli_req.dict.dict_val, | |||||
1336 | cli_req.dict.dict_len, | |||||
1337 | &dict); | |||||
1338 | if (ret < 0) { | |||||
1339 | gf_log (this->name, GF_LOG_ERROR, "failed to "do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 1340, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0) | |||||
1340 | "unserialize req-buffer to dictionary")do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 1340, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0); | |||||
1341 | snprintf (err_str, sizeof (err_str), "Unable to decode " | |||||
1342 | "the command"); | |||||
1343 | goto out; | |||||
1344 | } else { | |||||
1345 | dict->extra_stdfree = cli_req.dict.dict_val; | |||||
1346 | } | |||||
1347 | } | |||||
1348 | ||||||
1349 | ret = dict_get_str (dict, "volname", &volname); | |||||
1350 | if (ret) { | |||||
1351 | snprintf (err_str, sizeof (err_str), "Failed to get volume " | |||||
1352 | "name"); | |||||
1353 | gf_log (this->name, GF_LOG_ERROR, "%s", err_str)do { do { if (0) printf ("%s", err_str); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 1353, GF_LOG_ERROR , "%s", err_str); } while (0); | |||||
1354 | goto out; | |||||
1355 | } | |||||
1356 | gf_log (this->name, GF_LOG_DEBUG, "Received volume reset request for "do { do { if (0) printf ("Received volume reset request for " "volume %s", volname); } while (0); _gf_log (this->name, "glusterd-handler.c" , __FUNCTION__, 1357, GF_LOG_DEBUG, "Received volume reset request for " "volume %s", volname); } while (0) | |||||
1357 | "volume %s", volname)do { do { if (0) printf ("Received volume reset request for " "volume %s", volname); } while (0); _gf_log (this->name, "glusterd-handler.c" , __FUNCTION__, 1357, GF_LOG_DEBUG, "Received volume reset request for " "volume %s", volname); } while (0); | |||||
1358 | ||||||
1359 | ret = glusterd_op_begin_synctask (req, GD_OP_RESET_VOLUME, dict); | |||||
1360 | ||||||
1361 | out: | |||||
1362 | if (ret) { | |||||
1363 | if (err_str[0] == '\0') | |||||
1364 | snprintf (err_str, sizeof (err_str), | |||||
1365 | "Operation failed"); | |||||
1366 | ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, | |||||
1367 | dict, err_str); | |||||
1368 | } | |||||
1369 | ||||||
1370 | return ret; | |||||
1371 | } | |||||
1372 | ||||||
1373 | int | |||||
1374 | glusterd_handle_reset_volume (rpcsvc_request_t *req) | |||||
1375 | { | |||||
1376 | return glusterd_big_locked_handler (req, | |||||
1377 | __glusterd_handle_reset_volume); | |||||
1378 | } | |||||
1379 | ||||||
1380 | int | |||||
1381 | __glusterd_handle_set_volume (rpcsvc_request_t *req) | |||||
1382 | { | |||||
1383 | int32_t ret = -1; | |||||
1384 | gf_cli_req cli_req = {{0,}}; | |||||
1385 | dict_t *dict = NULL((void*)0); | |||||
1386 | glusterd_op_t cli_op = GD_OP_SET_VOLUME; | |||||
1387 | char *key = NULL((void*)0); | |||||
1388 | char *value = NULL((void*)0); | |||||
1389 | char *volname = NULL((void*)0); | |||||
1390 | char *op_errstr = NULL((void*)0); | |||||
1391 | gf_boolean_t help = _gf_false; | |||||
1392 | char err_str[2048] = {0,}; | |||||
1393 | xlator_t *this = NULL((void*)0); | |||||
1394 | ||||||
1395 | this = THIS(*__glusterfs_this_location()); | |||||
1396 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 1396, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
1397 | ||||||
1398 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 1398, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
1399 | ||||||
1400 | ret = xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req); | |||||
1401 | if (ret < 0) { | |||||
1402 | snprintf (err_str, sizeof (err_str), "Failed to decode " | |||||
1403 | "request received from cli"); | |||||
1404 | gf_log (this->name, GF_LOG_ERROR, "%s", err_str)do { do { if (0) printf ("%s", err_str); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 1404, GF_LOG_ERROR , "%s", err_str); } while (0); | |||||
1405 | req->rpc_err = GARBAGE_ARGS; | |||||
1406 | goto out; | |||||
1407 | } | |||||
1408 | ||||||
1409 | if (cli_req.dict.dict_len) { | |||||
1410 | /* Unserialize the dictionary */ | |||||
1411 | dict = dict_new (); | |||||
1412 | ||||||
1413 | ret = dict_unserialize (cli_req.dict.dict_val, | |||||
1414 | cli_req.dict.dict_len, | |||||
1415 | &dict); | |||||
1416 | if (ret < 0) { | |||||
1417 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 1419, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0) | |||||
1418 | "failed to "do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 1419, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0) | |||||
1419 | "unserialize req-buffer to dictionary")do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 1419, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0); | |||||
1420 | snprintf (err_str, sizeof (err_str), "Unable to decode " | |||||
1421 | "the command"); | |||||
1422 | goto out; | |||||
1423 | } else { | |||||
1424 | dict->extra_stdfree = cli_req.dict.dict_val; | |||||
1425 | } | |||||
1426 | } | |||||
1427 | ||||||
1428 | ret = dict_get_str (dict, "volname", &volname); | |||||
1429 | if (ret) { | |||||
1430 | snprintf (err_str, sizeof (err_str), "Failed to get volume " | |||||
1431 | "name while handling volume set command"); | |||||
1432 | gf_log (this->name, GF_LOG_ERROR, "%s", err_str)do { do { if (0) printf ("%s", err_str); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 1432, GF_LOG_ERROR , "%s", err_str); } while (0); | |||||
1433 | goto out; | |||||
1434 | } | |||||
1435 | ||||||
1436 | if (strcmp (volname, "help") == 0 || | |||||
1437 | strcmp (volname, "help-xml") == 0) { | |||||
1438 | ret = glusterd_volset_help (dict, &op_errstr); | |||||
1439 | help = _gf_true; | |||||
1440 | goto out; | |||||
1441 | } | |||||
1442 | ||||||
1443 | ret = dict_get_str (dict, "key1", &key); | |||||
1444 | if (ret) { | |||||
1445 | snprintf (err_str, sizeof (err_str), "Failed to get key while" | |||||
1446 | " handling volume set for %s", volname); | |||||
1447 | gf_log (this->name, GF_LOG_ERROR, "%s", err_str)do { do { if (0) printf ("%s", err_str); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 1447, GF_LOG_ERROR , "%s", err_str); } while (0); | |||||
1448 | goto out; | |||||
1449 | } | |||||
1450 | ||||||
1451 | ret = dict_get_str (dict, "value1", &value); | |||||
1452 | if (ret) { | |||||
1453 | snprintf (err_str, sizeof (err_str), "Failed to get value while" | |||||
1454 | " handling volume set for %s", volname); | |||||
1455 | gf_log (this->name, GF_LOG_ERROR, "%s", err_str)do { do { if (0) printf ("%s", err_str); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 1455, GF_LOG_ERROR , "%s", err_str); } while (0); | |||||
1456 | goto out; | |||||
1457 | } | |||||
1458 | gf_log (this->name, GF_LOG_DEBUG, "Received volume set request for "do { do { if (0) printf ("Received volume set request for " "volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-handler.c" , __FUNCTION__, 1459, GF_LOG_DEBUG, "Received volume set request for " "volume %s", volname); } while (0) | |||||
1459 | "volume %s", volname)do { do { if (0) printf ("Received volume set request for " "volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-handler.c" , __FUNCTION__, 1459, GF_LOG_DEBUG, "Received volume set request for " "volume %s", volname); } while (0); | |||||
1460 | ||||||
1461 | ret = glusterd_op_begin_synctask (req, GD_OP_SET_VOLUME, dict); | |||||
1462 | ||||||
1463 | out: | |||||
1464 | if (help) | |||||
1465 | ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, dict, | |||||
1466 | (op_errstr)? op_errstr:""); | |||||
1467 | else if (ret) { | |||||
1468 | if (err_str[0] == '\0') | |||||
1469 | snprintf (err_str, sizeof (err_str), | |||||
1470 | "Operation failed"); | |||||
1471 | ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, | |||||
1472 | dict, err_str); | |||||
1473 | } | |||||
1474 | if (op_errstr) | |||||
1475 | GF_FREE (op_errstr)__gf_free (op_errstr); | |||||
1476 | ||||||
1477 | return ret; | |||||
1478 | } | |||||
1479 | ||||||
1480 | int | |||||
1481 | glusterd_handle_set_volume (rpcsvc_request_t *req) | |||||
1482 | { | |||||
1483 | return glusterd_big_locked_handler (req, __glusterd_handle_set_volume); | |||||
1484 | } | |||||
1485 | ||||||
1486 | int | |||||
1487 | __glusterd_handle_sync_volume (rpcsvc_request_t *req) | |||||
1488 | { | |||||
1489 | int32_t ret = -1; | |||||
1490 | gf_cli_req cli_req = {{0,}}; | |||||
1491 | dict_t *dict = NULL((void*)0); | |||||
1492 | gf_cli_rsp cli_rsp = {0.}; | |||||
1493 | char msg[2048] = {0,}; | |||||
1494 | char *volname = NULL((void*)0); | |||||
1495 | gf1_cli_sync_volume flags = 0; | |||||
1496 | char *hostname = NULL((void*)0); | |||||
1497 | xlator_t *this = NULL((void*)0); | |||||
1498 | ||||||
1499 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 1499, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
1500 | this = THIS(*__glusterfs_this_location()); | |||||
1501 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 1501, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
1502 | ||||||
1503 | ret = xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req); | |||||
1504 | if (ret < 0) { | |||||
1505 | //failed to decode msg; | |||||
1506 | req->rpc_err = GARBAGE_ARGS; | |||||
1507 | goto out; | |||||
1508 | } | |||||
1509 | ||||||
1510 | if (cli_req.dict.dict_len) { | |||||
1511 | /* Unserialize the dictionary */ | |||||
1512 | dict = dict_new (); | |||||
1513 | ||||||
1514 | ret = dict_unserialize (cli_req.dict.dict_val, | |||||
1515 | cli_req.dict.dict_len, | |||||
1516 | &dict); | |||||
1517 | if (ret < 0) { | |||||
1518 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 1520, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0) | |||||
1519 | "failed to "do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 1520, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0) | |||||
1520 | "unserialize req-buffer to dictionary")do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 1520, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0); | |||||
1521 | snprintf (msg, sizeof (msg), "Unable to decode the " | |||||
1522 | "command"); | |||||
1523 | goto out; | |||||
1524 | } else { | |||||
1525 | dict->extra_stdfree = cli_req.dict.dict_val; | |||||
1526 | } | |||||
1527 | } | |||||
1528 | ||||||
1529 | ret = dict_get_str (dict, "hostname", &hostname); | |||||
1530 | if (ret) { | |||||
1531 | snprintf (msg, sizeof (msg), "Failed to get hostname"); | |||||
1532 | gf_log (this->name, GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log (this ->name, "glusterd-handler.c", __FUNCTION__, 1532, GF_LOG_ERROR , "%s", msg); } while (0); | |||||
1533 | goto out; | |||||
1534 | } | |||||
1535 | ||||||
1536 | ret = dict_get_str (dict, "volname", &volname); | |||||
1537 | if (ret) { | |||||
1538 | ret = dict_get_int32 (dict, "flags", (int32_t*)&flags); | |||||
1539 | if (ret) { | |||||
1540 | snprintf (msg, sizeof (msg), "Failed to get volume name" | |||||
1541 | " or flags"); | |||||
1542 | gf_log (this->name, GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log (this ->name, "glusterd-handler.c", __FUNCTION__, 1542, GF_LOG_ERROR , "%s", msg); } while (0); | |||||
1543 | goto out; | |||||
1544 | } | |||||
1545 | } | |||||
1546 | ||||||
1547 | gf_log (this->name, GF_LOG_INFO, "Received volume sync req "do { do { if (0) printf ("Received volume sync req " "for volume %s" , (flags & GF_CLI_SYNC_ALL) ? "all" : volname); } while ( 0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__ , 1548, GF_LOG_INFO, "Received volume sync req " "for volume %s" , (flags & GF_CLI_SYNC_ALL) ? "all" : volname); } while ( 0) | |||||
1548 | "for volume %s", (flags & GF_CLI_SYNC_ALL) ? "all" : volname)do { do { if (0) printf ("Received volume sync req " "for volume %s" , (flags & GF_CLI_SYNC_ALL) ? "all" : volname); } while ( 0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__ , 1548, GF_LOG_INFO, "Received volume sync req " "for volume %s" , (flags & GF_CLI_SYNC_ALL) ? "all" : volname); } while ( 0); | |||||
1549 | ||||||
1550 | if (glusterd_is_local_addr (hostname)) { | |||||
1551 | ret = -1; | |||||
1552 | snprintf (msg, sizeof (msg), "sync from localhost" | |||||
1553 | " not allowed"); | |||||
1554 | gf_log (this->name, GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log (this ->name, "glusterd-handler.c", __FUNCTION__, 1554, GF_LOG_ERROR , "%s", msg); } while (0); | |||||
1555 | goto out; | |||||
1556 | } | |||||
1557 | ||||||
1558 | ret = glusterd_op_begin_synctask (req, GD_OP_SYNC_VOLUME, dict); | |||||
1559 | ||||||
1560 | out: | |||||
1561 | if (ret) { | |||||
1562 | cli_rsp.op_ret = -1; | |||||
1563 | cli_rsp.op_errstr = msg; | |||||
1564 | if (msg[0] == '\0') | |||||
1565 | snprintf (msg, sizeof (msg), "Operation failed"); | |||||
1566 | glusterd_to_cli (req, &cli_rsp, NULL((void*)0), 0, NULL((void*)0), | |||||
1567 | (xdrproc_t)xdr_gf_cli_rsp, dict); | |||||
1568 | ||||||
1569 | ret = 0; //sent error to cli, prevent second reply | |||||
1570 | } | |||||
1571 | ||||||
1572 | return ret; | |||||
1573 | } | |||||
1574 | ||||||
1575 | int | |||||
1576 | glusterd_handle_sync_volume (rpcsvc_request_t *req) | |||||
1577 | { | |||||
1578 | return glusterd_big_locked_handler (req, __glusterd_handle_sync_volume); | |||||
1579 | } | |||||
1580 | ||||||
1581 | int | |||||
1582 | glusterd_fsm_log_send_resp (rpcsvc_request_t *req, int op_ret, | |||||
1583 | char *op_errstr, dict_t *dict) | |||||
1584 | { | |||||
1585 | ||||||
1586 | int ret = -1; | |||||
1587 | gf1_cli_fsm_log_rsp rsp = {0}; | |||||
1588 | ||||||
1589 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 1589, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
1590 | GF_ASSERT (op_errstr)do { if (!(op_errstr)) { do { do { if (0) printf ("Assertion failed: " "op_errstr"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 1590, GF_LOG_ERROR, "Assertion failed: " "op_errstr" ); } while (0); } } while (0); | |||||
1591 | ||||||
1592 | rsp.op_ret = op_ret; | |||||
1593 | rsp.op_errstr = op_errstr; | |||||
1594 | if (rsp.op_ret == 0) | |||||
1595 | ret = dict_allocate_and_serialize (dict, &rsp.fsm_log.fsm_log_val, | |||||
1596 | &rsp.fsm_log.fsm_log_len); | |||||
1597 | ||||||
1598 | ret = glusterd_submit_reply (req, &rsp, NULL((void*)0), 0, NULL((void*)0), | |||||
1599 | (xdrproc_t)xdr_gf1_cli_fsm_log_rsp); | |||||
1600 | GF_FREE (rsp.fsm_log.fsm_log_val)__gf_free (rsp.fsm_log.fsm_log_val); | |||||
1601 | ||||||
1602 | gf_log ("glusterd", GF_LOG_DEBUG, "Responded, ret: %d", ret)do { do { if (0) printf ("Responded, ret: %d", ret); } while ( 0); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__, 1602 , GF_LOG_DEBUG, "Responded, ret: %d", ret); } while (0); | |||||
1603 | ||||||
1604 | return 0; | |||||
1605 | } | |||||
1606 | ||||||
1607 | int | |||||
1608 | __glusterd_handle_fsm_log (rpcsvc_request_t *req) | |||||
1609 | { | |||||
1610 | int32_t ret = -1; | |||||
1611 | gf1_cli_fsm_log_req cli_req = {0,}; | |||||
1612 | dict_t *dict = NULL((void*)0); | |||||
1613 | glusterd_sm_tr_log_t *log = NULL((void*)0); | |||||
1614 | xlator_t *this = NULL((void*)0); | |||||
1615 | glusterd_conf_t *conf = NULL((void*)0); | |||||
1616 | char msg[2048] = {0}; | |||||
1617 | glusterd_peerinfo_t *peerinfo = NULL((void*)0); | |||||
1618 | ||||||
1619 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 1619, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
1620 | ||||||
1621 | ret = xdr_to_generic (req->msg[0], &cli_req, | |||||
1622 | (xdrproc_t)xdr_gf1_cli_fsm_log_req); | |||||
1623 | if (ret < 0) { | |||||
1624 | //failed to decode msg; | |||||
1625 | req->rpc_err = GARBAGE_ARGS; | |||||
1626 | snprintf (msg, sizeof (msg), "Garbage request"); | |||||
1627 | goto out; | |||||
1628 | } | |||||
1629 | ||||||
1630 | if (strcmp ("", cli_req.name) == 0) { | |||||
1631 | this = THIS(*__glusterfs_this_location()); | |||||
1632 | conf = this->private; | |||||
1633 | log = &conf->op_sm_log; | |||||
1634 | } else { | |||||
1635 | ret = glusterd_friend_find_by_hostname (cli_req.name, | |||||
1636 | &peerinfo); | |||||
1637 | if (ret) { | |||||
1638 | snprintf (msg, sizeof (msg), "%s is not a peer", | |||||
1639 | cli_req.name); | |||||
1640 | goto out; | |||||
1641 | } | |||||
1642 | log = &peerinfo->sm_log; | |||||
1643 | } | |||||
1644 | ||||||
1645 | dict = dict_new (); | |||||
1646 | if (!dict) { | |||||
1647 | ret = -1; | |||||
1648 | goto out; | |||||
1649 | } | |||||
1650 | ||||||
1651 | ret = glusterd_sm_tr_log_add_to_dict (dict, log); | |||||
1652 | out: | |||||
1653 | (void)glusterd_fsm_log_send_resp (req, ret, msg, dict); | |||||
1654 | free (cli_req.name);//malloced by xdr | |||||
1655 | if (dict) | |||||
1656 | dict_unref (dict); | |||||
1657 | ||||||
1658 | glusterd_friend_sm (); | |||||
1659 | glusterd_op_sm (); | |||||
1660 | ||||||
1661 | return 0;//send 0 to avoid double reply | |||||
1662 | } | |||||
1663 | ||||||
1664 | int | |||||
1665 | glusterd_handle_fsm_log (rpcsvc_request_t *req) | |||||
1666 | { | |||||
1667 | return glusterd_big_locked_handler (req, __glusterd_handle_fsm_log); | |||||
1668 | } | |||||
1669 | ||||||
1670 | int | |||||
1671 | glusterd_op_lock_send_resp (rpcsvc_request_t *req, int32_t status) | |||||
1672 | { | |||||
1673 | ||||||
1674 | gd1_mgmt_cluster_lock_rsp rsp = {{0},}; | |||||
1675 | int ret = -1; | |||||
1676 | ||||||
1677 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 1677, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
1678 | glusterd_get_uuid (&rsp.uuid); | |||||
1679 | rsp.op_ret = status; | |||||
1680 | ||||||
1681 | ret = glusterd_submit_reply (req, &rsp, NULL((void*)0), 0, NULL((void*)0), | |||||
1682 | (xdrproc_t)xdr_gd1_mgmt_cluster_lock_rsp); | |||||
1683 | ||||||
1684 | gf_log (THIS->name, GF_LOG_DEBUG, "Responded to lock, ret: %d", ret)do { do { if (0) printf ("Responded to lock, ret: %d", ret); } while (0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-handler.c", __FUNCTION__, 1684, GF_LOG_DEBUG, "Responded to lock, ret: %d" , ret); } while (0); | |||||
1685 | ||||||
1686 | return 0; | |||||
1687 | } | |||||
1688 | ||||||
1689 | int | |||||
1690 | glusterd_op_unlock_send_resp (rpcsvc_request_t *req, int32_t status) | |||||
1691 | { | |||||
1692 | ||||||
1693 | gd1_mgmt_cluster_unlock_rsp rsp = {{0},}; | |||||
1694 | int ret = -1; | |||||
1695 | ||||||
1696 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 1696, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
1697 | rsp.op_ret = status; | |||||
1698 | glusterd_get_uuid (&rsp.uuid); | |||||
1699 | ||||||
1700 | ret = glusterd_submit_reply (req, &rsp, NULL((void*)0), 0, NULL((void*)0), | |||||
1701 | (xdrproc_t)xdr_gd1_mgmt_cluster_unlock_rsp); | |||||
1702 | ||||||
1703 | gf_log (THIS->name, GF_LOG_DEBUG, "Responded to unlock, ret: %d", ret)do { do { if (0) printf ("Responded to unlock, ret: %d", ret) ; } while (0); _gf_log ((*__glusterfs_this_location())->name , "glusterd-handler.c", __FUNCTION__, 1703, GF_LOG_DEBUG, "Responded to unlock, ret: %d" , ret); } while (0); | |||||
1704 | ||||||
1705 | return ret; | |||||
1706 | } | |||||
1707 | ||||||
1708 | int | |||||
1709 | __glusterd_handle_cluster_unlock (rpcsvc_request_t *req) | |||||
1710 | { | |||||
1711 | gd1_mgmt_cluster_unlock_req unlock_req = {{0}, }; | |||||
1712 | int32_t ret = -1; | |||||
1713 | glusterd_op_lock_ctx_t *ctx = NULL((void*)0); | |||||
1714 | glusterd_peerinfo_t *peerinfo = NULL((void*)0); | |||||
1715 | xlator_t *this = NULL((void*)0); | |||||
1716 | ||||||
1717 | this = THIS(*__glusterfs_this_location()); | |||||
1718 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 1718, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
1719 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 1719, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
1720 | ||||||
1721 | ret = xdr_to_generic (req->msg[0], &unlock_req, | |||||
1722 | (xdrproc_t)xdr_gd1_mgmt_cluster_unlock_req); | |||||
1723 | if (ret < 0) { | |||||
1724 | gf_log (this->name, GF_LOG_ERROR, "Failed to decode unlock "do { do { if (0) printf ("Failed to decode unlock " "request received from peer" ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 1725, GF_LOG_ERROR, "Failed to decode unlock " "request received from peer"); } while (0) | |||||
1725 | "request received from peer")do { do { if (0) printf ("Failed to decode unlock " "request received from peer" ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 1725, GF_LOG_ERROR, "Failed to decode unlock " "request received from peer"); } while (0); | |||||
1726 | req->rpc_err = GARBAGE_ARGS; | |||||
1727 | goto out; | |||||
1728 | } | |||||
1729 | ||||||
1730 | ||||||
1731 | gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("Received UNLOCK from uuid: %s", uuid_utoa (unlock_req.uuid)); } while (0); _gf_log (this->name, "glusterd-handler.c" , __FUNCTION__, 1732, GF_LOG_DEBUG, "Received UNLOCK from uuid: %s" , uuid_utoa (unlock_req.uuid)); } while (0) | |||||
1732 | "Received UNLOCK from uuid: %s", uuid_utoa (unlock_req.uuid))do { do { if (0) printf ("Received UNLOCK from uuid: %s", uuid_utoa (unlock_req.uuid)); } while (0); _gf_log (this->name, "glusterd-handler.c" , __FUNCTION__, 1732, GF_LOG_DEBUG, "Received UNLOCK from uuid: %s" , uuid_utoa (unlock_req.uuid)); } while (0); | |||||
1733 | ||||||
1734 | if (glusterd_friend_find_by_uuid (unlock_req.uuid, &peerinfo)) { | |||||
1735 | gf_log (this->name, GF_LOG_WARNING, "%s doesn't "do { do { if (0) printf ("%s doesn't " "belong to the cluster. Ignoring request." , uuid_utoa (unlock_req.uuid)); } while (0); _gf_log (this-> name, "glusterd-handler.c", __FUNCTION__, 1737, GF_LOG_WARNING , "%s doesn't " "belong to the cluster. Ignoring request.", uuid_utoa (unlock_req.uuid)); } while (0) | |||||
1736 | "belong to the cluster. Ignoring request.",do { do { if (0) printf ("%s doesn't " "belong to the cluster. Ignoring request." , uuid_utoa (unlock_req.uuid)); } while (0); _gf_log (this-> name, "glusterd-handler.c", __FUNCTION__, 1737, GF_LOG_WARNING , "%s doesn't " "belong to the cluster. Ignoring request.", uuid_utoa (unlock_req.uuid)); } while (0) | |||||
1737 | uuid_utoa (unlock_req.uuid))do { do { if (0) printf ("%s doesn't " "belong to the cluster. Ignoring request." , uuid_utoa (unlock_req.uuid)); } while (0); _gf_log (this-> name, "glusterd-handler.c", __FUNCTION__, 1737, GF_LOG_WARNING , "%s doesn't " "belong to the cluster. Ignoring request.", uuid_utoa (unlock_req.uuid)); } while (0); | |||||
1738 | ret = -1; | |||||
1739 | goto out; | |||||
1740 | } | |||||
1741 | ||||||
1742 | ctx = GF_CALLOC (1, sizeof (*ctx), gf_gld_mt_op_lock_ctx_t)__gf_calloc (1, sizeof (*ctx), gf_gld_mt_op_lock_ctx_t); | |||||
1743 | ||||||
1744 | if (!ctx) { | |||||
1745 | //respond here | |||||
1746 | return -1; | |||||
1747 | } | |||||
1748 | uuid_copy (ctx->uuid, unlock_req.uuid); | |||||
1749 | ctx->req = req; | |||||
1750 | ||||||
1751 | ret = glusterd_op_sm_inject_event (GD_OP_EVENT_UNLOCK, ctx); | |||||
1752 | ||||||
1753 | out: | |||||
1754 | glusterd_friend_sm (); | |||||
1755 | glusterd_op_sm (); | |||||
1756 | ||||||
1757 | return ret; | |||||
1758 | } | |||||
1759 | ||||||
1760 | int | |||||
1761 | glusterd_handle_cluster_unlock (rpcsvc_request_t *req) | |||||
1762 | { | |||||
1763 | return glusterd_big_locked_handler (req, | |||||
1764 | __glusterd_handle_cluster_unlock); | |||||
1765 | } | |||||
1766 | ||||||
1767 | int | |||||
1768 | glusterd_op_stage_send_resp (rpcsvc_request_t *req, | |||||
1769 | int32_t op, int32_t status, | |||||
1770 | char *op_errstr, dict_t *rsp_dict) | |||||
1771 | { | |||||
1772 | gd1_mgmt_stage_op_rsp rsp = {{0},}; | |||||
1773 | int ret = -1; | |||||
1774 | xlator_t *this = NULL((void*)0); | |||||
1775 | ||||||
1776 | this = THIS(*__glusterfs_this_location()); | |||||
1777 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 1777, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
1778 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 1778, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
1779 | ||||||
1780 | rsp.op_ret = status; | |||||
1781 | glusterd_get_uuid (&rsp.uuid); | |||||
1782 | rsp.op = op; | |||||
1783 | if (op_errstr) | |||||
1784 | rsp.op_errstr = op_errstr; | |||||
1785 | else | |||||
1786 | rsp.op_errstr = ""; | |||||
1787 | ||||||
1788 | ret = dict_allocate_and_serialize (rsp_dict, &rsp.dict.dict_val, | |||||
1789 | &rsp.dict.dict_len); | |||||
1790 | if (ret < 0) { | |||||
1791 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("failed to get serialized length of dict" ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 1792, GF_LOG_ERROR, "failed to get serialized length of dict" ); } while (0) | |||||
1792 | "failed to get serialized length of dict")do { do { if (0) printf ("failed to get serialized length of dict" ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 1792, GF_LOG_ERROR, "failed to get serialized length of dict" ); } while (0); | |||||
1793 | return ret; | |||||
1794 | } | |||||
1795 | ||||||
1796 | ret = glusterd_submit_reply (req, &rsp, NULL((void*)0), 0, NULL((void*)0), | |||||
1797 | (xdrproc_t)xdr_gd1_mgmt_stage_op_rsp); | |||||
1798 | ||||||
1799 | gf_log (this->name, GF_LOG_DEBUG, "Responded to stage, ret: %d", ret)do { do { if (0) printf ("Responded to stage, ret: %d", ret); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__ , 1799, GF_LOG_DEBUG, "Responded to stage, ret: %d", ret); } while (0); | |||||
1800 | GF_FREE (rsp.dict.dict_val)__gf_free (rsp.dict.dict_val); | |||||
1801 | ||||||
1802 | return ret; | |||||
1803 | } | |||||
1804 | ||||||
1805 | int | |||||
1806 | glusterd_op_commit_send_resp (rpcsvc_request_t *req, | |||||
1807 | int32_t op, int32_t status, char *op_errstr, | |||||
1808 | dict_t *rsp_dict) | |||||
1809 | { | |||||
1810 | gd1_mgmt_commit_op_rsp rsp = {{0}, }; | |||||
1811 | int ret = -1; | |||||
1812 | xlator_t *this = NULL((void*)0); | |||||
1813 | ||||||
1814 | this = THIS(*__glusterfs_this_location()); | |||||
1815 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 1815, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
1816 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 1816, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
1817 | rsp.op_ret = status; | |||||
1818 | glusterd_get_uuid (&rsp.uuid); | |||||
1819 | rsp.op = op; | |||||
1820 | ||||||
1821 | if (op_errstr) | |||||
1822 | rsp.op_errstr = op_errstr; | |||||
1823 | else | |||||
1824 | rsp.op_errstr = ""; | |||||
1825 | ||||||
1826 | if (rsp_dict) { | |||||
1827 | ret = dict_allocate_and_serialize (rsp_dict, &rsp.dict.dict_val, | |||||
1828 | &rsp.dict.dict_len); | |||||
1829 | if (ret < 0) { | |||||
1830 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("failed to get serialized length of dict" ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 1831, GF_LOG_ERROR, "failed to get serialized length of dict" ); } while (0) | |||||
1831 | "failed to get serialized length of dict")do { do { if (0) printf ("failed to get serialized length of dict" ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 1831, GF_LOG_ERROR, "failed to get serialized length of dict" ); } while (0); | |||||
1832 | goto out; | |||||
1833 | } | |||||
1834 | } | |||||
1835 | ||||||
1836 | ||||||
1837 | ret = glusterd_submit_reply (req, &rsp, NULL((void*)0), 0, NULL((void*)0), | |||||
1838 | (xdrproc_t)xdr_gd1_mgmt_commit_op_rsp); | |||||
1839 | ||||||
1840 | gf_log (this->name, GF_LOG_DEBUG, "Responded to commit, ret: %d", ret)do { do { if (0) printf ("Responded to commit, ret: %d", ret) ; } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__ , 1840, GF_LOG_DEBUG, "Responded to commit, ret: %d", ret); } while (0); | |||||
1841 | ||||||
1842 | out: | |||||
1843 | GF_FREE (rsp.dict.dict_val)__gf_free (rsp.dict.dict_val); | |||||
1844 | return ret; | |||||
1845 | } | |||||
1846 | ||||||
1847 | int | |||||
1848 | __glusterd_handle_incoming_friend_req (rpcsvc_request_t *req) | |||||
1849 | { | |||||
1850 | int32_t ret = -1; | |||||
1851 | gd1_mgmt_friend_req friend_req = {{0},}; | |||||
1852 | gf_boolean_t run_fsm = _gf_true; | |||||
1853 | ||||||
1854 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 1854, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
1855 | ret = xdr_to_generic (req->msg[0], &friend_req, | |||||
1856 | (xdrproc_t)xdr_gd1_mgmt_friend_req); | |||||
1857 | if (ret < 0) { | |||||
1858 | //failed to decode msg; | |||||
1859 | req->rpc_err = GARBAGE_ARGS; | |||||
1860 | goto out; | |||||
1861 | } | |||||
1862 | ||||||
1863 | gf_log ("glusterd", GF_LOG_INFO,do { do { if (0) printf ("Received probe from uuid: %s", uuid_utoa (friend_req.uuid)); } while (0); _gf_log ("glusterd", "glusterd-handler.c" , __FUNCTION__, 1864, GF_LOG_INFO, "Received probe from uuid: %s" , uuid_utoa (friend_req.uuid)); } while (0) | |||||
1864 | "Received probe from uuid: %s", uuid_utoa (friend_req.uuid))do { do { if (0) printf ("Received probe from uuid: %s", uuid_utoa (friend_req.uuid)); } while (0); _gf_log ("glusterd", "glusterd-handler.c" , __FUNCTION__, 1864, GF_LOG_INFO, "Received probe from uuid: %s" , uuid_utoa (friend_req.uuid)); } while (0); | |||||
1865 | ret = glusterd_handle_friend_req (req, friend_req.uuid, | |||||
1866 | friend_req.hostname, friend_req.port, | |||||
1867 | &friend_req); | |||||
1868 | ||||||
1869 | if (ret == GLUSTERD_CONNECTION_AWAITED) { | |||||
1870 | //fsm should be run after connection establishes | |||||
1871 | run_fsm = _gf_false; | |||||
1872 | ret = 0; | |||||
1873 | } | |||||
1874 | ||||||
1875 | out: | |||||
1876 | free (friend_req.hostname);//malloced by xdr | |||||
1877 | ||||||
1878 | if (run_fsm) { | |||||
1879 | glusterd_friend_sm (); | |||||
1880 | glusterd_op_sm (); | |||||
1881 | } | |||||
1882 | ||||||
1883 | return ret; | |||||
1884 | } | |||||
1885 | ||||||
1886 | int | |||||
1887 | glusterd_handle_incoming_friend_req (rpcsvc_request_t *req) | |||||
1888 | { | |||||
1889 | return glusterd_big_locked_handler (req, | |||||
1890 | __glusterd_handle_incoming_friend_req); | |||||
1891 | } | |||||
1892 | ||||||
1893 | int | |||||
1894 | __glusterd_handle_incoming_unfriend_req (rpcsvc_request_t *req) | |||||
1895 | { | |||||
1896 | int32_t ret = -1; | |||||
1897 | gd1_mgmt_friend_req friend_req = {{0},}; | |||||
1898 | char remote_hostname[UNIX_PATH_MAX108 + 1] = {0,}; | |||||
1899 | ||||||
1900 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 1900, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
1901 | ret = xdr_to_generic (req->msg[0], &friend_req, | |||||
1902 | (xdrproc_t)xdr_gd1_mgmt_friend_req); | |||||
1903 | if (ret < 0) { | |||||
1904 | //failed to decode msg; | |||||
1905 | req->rpc_err = GARBAGE_ARGS; | |||||
1906 | goto out; | |||||
1907 | } | |||||
1908 | ||||||
1909 | gf_log ("glusterd", GF_LOG_INFO,do { do { if (0) printf ("Received unfriend from uuid: %s", uuid_utoa (friend_req.uuid)); } while (0); _gf_log ("glusterd", "glusterd-handler.c" , __FUNCTION__, 1910, GF_LOG_INFO, "Received unfriend from uuid: %s" , uuid_utoa (friend_req.uuid)); } while (0) | |||||
1910 | "Received unfriend from uuid: %s", uuid_utoa (friend_req.uuid))do { do { if (0) printf ("Received unfriend from uuid: %s", uuid_utoa (friend_req.uuid)); } while (0); _gf_log ("glusterd", "glusterd-handler.c" , __FUNCTION__, 1910, GF_LOG_INFO, "Received unfriend from uuid: %s" , uuid_utoa (friend_req.uuid)); } while (0); | |||||
1911 | ||||||
1912 | ret = glusterd_remote_hostname_get (req, remote_hostname, | |||||
1913 | sizeof (remote_hostname)); | |||||
1914 | if (ret) { | |||||
1915 | gf_log ("", GF_LOG_ERROR, "Unable to get the remote hostname")do { do { if (0) printf ("Unable to get the remote hostname") ; } while (0); _gf_log ("", "glusterd-handler.c", __FUNCTION__ , 1915, GF_LOG_ERROR, "Unable to get the remote hostname"); } while (0); | |||||
1916 | goto out; | |||||
1917 | } | |||||
1918 | ret = glusterd_handle_unfriend_req (req, friend_req.uuid, | |||||
1919 | remote_hostname, friend_req.port); | |||||
1920 | ||||||
1921 | out: | |||||
1922 | free (friend_req.hostname);//malloced by xdr | |||||
1923 | free (friend_req.vols.vols_val);//malloced by xdr | |||||
1924 | ||||||
1925 | glusterd_friend_sm (); | |||||
1926 | glusterd_op_sm (); | |||||
1927 | ||||||
1928 | return ret; | |||||
1929 | } | |||||
1930 | ||||||
1931 | int | |||||
1932 | glusterd_handle_incoming_unfriend_req (rpcsvc_request_t *req) | |||||
1933 | { | |||||
1934 | return glusterd_big_locked_handler (req, | |||||
1935 | __glusterd_handle_incoming_unfriend_req); | |||||
1936 | ||||||
1937 | } | |||||
1938 | ||||||
1939 | int | |||||
1940 | glusterd_handle_friend_update_delete (dict_t *dict) | |||||
1941 | { | |||||
1942 | char *hostname = NULL((void*)0); | |||||
1943 | int32_t ret = -1; | |||||
1944 | ||||||
1945 | GF_ASSERT (dict)do { if (!(dict)) { do { do { if (0) printf ("Assertion failed: " "dict"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 1945, GF_LOG_ERROR, "Assertion failed: " "dict" ); } while (0); } } while (0); | |||||
1946 | ||||||
1947 | ret = dict_get_str (dict, "hostname", &hostname); | |||||
1948 | if (ret) | |||||
1949 | goto out; | |||||
1950 | ||||||
1951 | ret = glusterd_friend_remove (NULL((void*)0), hostname); | |||||
1952 | ||||||
1953 | out: | |||||
1954 | gf_log ("", GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ("", "glusterd-handler.c", __FUNCTION__, 1954, GF_LOG_DEBUG, "Returning %d", ret); } while (0); | |||||
1955 | return ret; | |||||
1956 | } | |||||
1957 | ||||||
1958 | int | |||||
1959 | glusterd_friend_hostname_update (glusterd_peerinfo_t *peerinfo, | |||||
1960 | char *hostname, | |||||
1961 | gf_boolean_t store_update) | |||||
1962 | { | |||||
1963 | char *new_hostname = NULL((void*)0); | |||||
1964 | int ret = 0; | |||||
1965 | ||||||
1966 | GF_ASSERT (peerinfo)do { if (!(peerinfo)) { do { do { if (0) printf ("Assertion failed: " "peerinfo"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 1966, GF_LOG_ERROR, "Assertion failed: " "peerinfo" ); } while (0); } } while (0); | |||||
1967 | GF_ASSERT (hostname)do { if (!(hostname)) { do { do { if (0) printf ("Assertion failed: " "hostname"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 1967, GF_LOG_ERROR, "Assertion failed: " "hostname" ); } while (0); } } while (0); | |||||
1968 | ||||||
1969 | new_hostname = gf_strdup (hostname); | |||||
1970 | if (!new_hostname) { | |||||
1971 | ret = -1; | |||||
1972 | goto out; | |||||
1973 | } | |||||
1974 | ||||||
1975 | GF_FREE (peerinfo->hostname)__gf_free (peerinfo->hostname); | |||||
1976 | peerinfo->hostname = new_hostname; | |||||
1977 | if (store_update) | |||||
1978 | ret = glusterd_store_peerinfo (peerinfo); | |||||
1979 | out: | |||||
1980 | gf_log ("", GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ("", "glusterd-handler.c", __FUNCTION__, 1980, GF_LOG_DEBUG, "Returning %d", ret); } while (0); | |||||
1981 | return ret; | |||||
1982 | } | |||||
1983 | ||||||
1984 | int | |||||
1985 | __glusterd_handle_friend_update (rpcsvc_request_t *req) | |||||
1986 | { | |||||
1987 | int32_t ret = -1; | |||||
1988 | gd1_mgmt_friend_update friend_req = {{0},}; | |||||
1989 | glusterd_peerinfo_t *peerinfo = NULL((void*)0); | |||||
1990 | glusterd_conf_t *priv = NULL((void*)0); | |||||
1991 | xlator_t *this = NULL((void*)0); | |||||
1992 | glusterd_peerinfo_t *tmp = NULL((void*)0); | |||||
1993 | gd1_mgmt_friend_update_rsp rsp = {{0},}; | |||||
1994 | dict_t *dict = NULL((void*)0); | |||||
1995 | char key[100] = {0,}; | |||||
1996 | char *uuid_buf = NULL((void*)0); | |||||
1997 | char *hostname = NULL((void*)0); | |||||
1998 | int i = 1; | |||||
1999 | int count = 0; | |||||
2000 | uuid_t uuid = {0,}; | |||||
2001 | glusterd_peerctx_args_t args = {0}; | |||||
2002 | int32_t op = 0; | |||||
2003 | ||||||
2004 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 2004, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
2005 | ||||||
2006 | this = THIS(*__glusterfs_this_location()); | |||||
2007 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 2007, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
2008 | priv = this->private; | |||||
2009 | GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: " "priv"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 2009, GF_LOG_ERROR, "Assertion failed: " "priv" ); } while (0); } } while (0); | |||||
2010 | ||||||
2011 | ret = xdr_to_generic (req->msg[0], &friend_req, | |||||
2012 | (xdrproc_t)xdr_gd1_mgmt_friend_update); | |||||
2013 | if (ret < 0) { | |||||
2014 | //failed to decode msg; | |||||
2015 | req->rpc_err = GARBAGE_ARGS; | |||||
2016 | goto out; | |||||
2017 | } | |||||
2018 | ||||||
2019 | ret = glusterd_friend_find (friend_req.uuid, NULL((void*)0), &tmp); | |||||
2020 | if (ret) { | |||||
2021 | gf_log ("", GF_LOG_CRITICAL, "Received friend update request "do { do { if (0) printf ("Received friend update request " "from unknown peer %s" , uuid_utoa (friend_req.uuid)); } while (0); _gf_log ("", "glusterd-handler.c" , __FUNCTION__, 2022, GF_LOG_CRITICAL, "Received friend update request " "from unknown peer %s", uuid_utoa (friend_req.uuid)); } while (0) | |||||
2022 | "from unknown peer %s", uuid_utoa (friend_req.uuid))do { do { if (0) printf ("Received friend update request " "from unknown peer %s" , uuid_utoa (friend_req.uuid)); } while (0); _gf_log ("", "glusterd-handler.c" , __FUNCTION__, 2022, GF_LOG_CRITICAL, "Received friend update request " "from unknown peer %s", uuid_utoa (friend_req.uuid)); } while (0); | |||||
2023 | goto out; | |||||
2024 | } | |||||
2025 | gf_log ("glusterd", GF_LOG_INFO,do { do { if (0) printf ("Received friend update from uuid: %s" , uuid_utoa (friend_req.uuid)); } while (0); _gf_log ("glusterd" , "glusterd-handler.c", __FUNCTION__, 2026, GF_LOG_INFO, "Received friend update from uuid: %s" , uuid_utoa (friend_req.uuid)); } while (0) | |||||
2026 | "Received friend update from uuid: %s", uuid_utoa (friend_req.uuid))do { do { if (0) printf ("Received friend update from uuid: %s" , uuid_utoa (friend_req.uuid)); } while (0); _gf_log ("glusterd" , "glusterd-handler.c", __FUNCTION__, 2026, GF_LOG_INFO, "Received friend update from uuid: %s" , uuid_utoa (friend_req.uuid)); } while (0); | |||||
2027 | ||||||
2028 | if (friend_req.friends.friends_len) { | |||||
2029 | /* Unserialize the dictionary */ | |||||
2030 | dict = dict_new (); | |||||
2031 | ||||||
2032 | ret = dict_unserialize (friend_req.friends.friends_val, | |||||
2033 | friend_req.friends.friends_len, | |||||
2034 | &dict); | |||||
2035 | if (ret < 0) { | |||||
2036 | gf_log ("glusterd", GF_LOG_ERROR,do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__ , 2038, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0) | |||||
2037 | "failed to "do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__ , 2038, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0) | |||||
2038 | "unserialize req-buffer to dictionary")do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__ , 2038, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0); | |||||
2039 | goto out; | |||||
2040 | } else { | |||||
2041 | dict->extra_stdfree = friend_req.friends.friends_val; | |||||
2042 | } | |||||
2043 | } | |||||
2044 | ||||||
2045 | ret = dict_get_int32 (dict, "count", &count); | |||||
2046 | if (ret) | |||||
2047 | goto out; | |||||
2048 | ||||||
2049 | ret = dict_get_int32 (dict, "op", &op); | |||||
2050 | if (ret) | |||||
2051 | goto out; | |||||
2052 | ||||||
2053 | if (GD_FRIEND_UPDATE_DEL == op) { | |||||
2054 | ret = glusterd_handle_friend_update_delete (dict); | |||||
2055 | goto out; | |||||
2056 | } | |||||
2057 | ||||||
2058 | args.mode = GD_MODE_ON; | |||||
2059 | while ( i <= count) { | |||||
2060 | snprintf (key, sizeof (key), "friend%d.uuid", i); | |||||
2061 | ret = dict_get_str (dict, key, &uuid_buf); | |||||
2062 | if (ret) | |||||
2063 | goto out; | |||||
2064 | uuid_parse (uuid_buf, uuid); | |||||
2065 | snprintf (key, sizeof (key), "friend%d.hostname", i); | |||||
2066 | ret = dict_get_str (dict, key, &hostname); | |||||
2067 | if (ret) | |||||
2068 | goto out; | |||||
2069 | ||||||
2070 | gf_log ("", GF_LOG_INFO, "Received uuid: %s, hostname:%s",do { do { if (0) printf ("Received uuid: %s, hostname:%s", uuid_buf , hostname); } while (0); _gf_log ("", "glusterd-handler.c", __FUNCTION__ , 2071, GF_LOG_INFO, "Received uuid: %s, hostname:%s", uuid_buf , hostname); } while (0) | |||||
2071 | uuid_buf, hostname)do { do { if (0) printf ("Received uuid: %s, hostname:%s", uuid_buf , hostname); } while (0); _gf_log ("", "glusterd-handler.c", __FUNCTION__ , 2071, GF_LOG_INFO, "Received uuid: %s, hostname:%s", uuid_buf , hostname); } while (0); | |||||
2072 | ||||||
2073 | if (uuid_is_null (uuid)) { | |||||
2074 | gf_log (this->name, GF_LOG_WARNING, "Updates mustn't "do { do { if (0) printf ("Updates mustn't " "contain peer with 'null' uuid" ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 2075, GF_LOG_WARNING, "Updates mustn't " "contain peer with 'null' uuid" ); } while (0) | |||||
2075 | "contain peer with 'null' uuid")do { do { if (0) printf ("Updates mustn't " "contain peer with 'null' uuid" ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 2075, GF_LOG_WARNING, "Updates mustn't " "contain peer with 'null' uuid" ); } while (0); | |||||
2076 | continue; | |||||
2077 | } | |||||
2078 | ||||||
2079 | if (!uuid_compare (uuid, MY_UUID(__glusterd_uuid()))) { | |||||
2080 | gf_log ("", GF_LOG_INFO, "Received my uuid as Friend")do { do { if (0) printf ("Received my uuid as Friend"); } while (0); _gf_log ("", "glusterd-handler.c", __FUNCTION__, 2080, GF_LOG_INFO , "Received my uuid as Friend"); } while (0); | |||||
2081 | i++; | |||||
2082 | continue; | |||||
2083 | } | |||||
2084 | ||||||
2085 | ret = glusterd_friend_find (uuid, hostname, &tmp); | |||||
2086 | ||||||
2087 | if (!ret) { | |||||
2088 | if (strcmp (hostname, tmp->hostname) != 0) { | |||||
2089 | glusterd_friend_hostname_update (tmp, hostname, | |||||
2090 | _gf_true); | |||||
2091 | } | |||||
2092 | i++; | |||||
2093 | continue; | |||||
2094 | } | |||||
2095 | ||||||
2096 | ret = glusterd_friend_add (hostname, friend_req.port, | |||||
2097 | GD_FRIEND_STATE_BEFRIENDED, | |||||
2098 | &uuid, &peerinfo, 0, &args); | |||||
2099 | ||||||
2100 | i++; | |||||
2101 | } | |||||
2102 | ||||||
2103 | out: | |||||
2104 | uuid_copy (rsp.uuid, MY_UUID(__glusterd_uuid())); | |||||
2105 | ret = glusterd_submit_reply (req, &rsp, NULL((void*)0), 0, NULL((void*)0), | |||||
2106 | (xdrproc_t)xdr_gd1_mgmt_friend_update_rsp); | |||||
2107 | if (dict) { | |||||
2108 | if (!dict->extra_stdfree && friend_req.friends.friends_val) | |||||
2109 | free (friend_req.friends.friends_val);//malloced by xdr | |||||
2110 | dict_unref (dict); | |||||
2111 | } else { | |||||
2112 | free (friend_req.friends.friends_val);//malloced by xdr | |||||
2113 | } | |||||
2114 | ||||||
2115 | glusterd_friend_sm (); | |||||
2116 | glusterd_op_sm (); | |||||
2117 | ||||||
2118 | return ret; | |||||
2119 | } | |||||
2120 | ||||||
2121 | int | |||||
2122 | glusterd_handle_friend_update (rpcsvc_request_t *req) | |||||
2123 | { | |||||
2124 | return glusterd_big_locked_handler (req, | |||||
2125 | __glusterd_handle_friend_update); | |||||
2126 | } | |||||
2127 | ||||||
2128 | int | |||||
2129 | __glusterd_handle_probe_query (rpcsvc_request_t *req) | |||||
2130 | { | |||||
2131 | int32_t ret = -1; | |||||
2132 | xlator_t *this = NULL((void*)0); | |||||
2133 | glusterd_conf_t *conf = NULL((void*)0); | |||||
2134 | gd1_mgmt_probe_req probe_req = {{0},}; | |||||
2135 | gd1_mgmt_probe_rsp rsp = {{0},}; | |||||
2136 | glusterd_peerinfo_t *peerinfo = NULL((void*)0); | |||||
2137 | glusterd_peerctx_args_t args = {0}; | |||||
2138 | int port = 0; | |||||
2139 | char remote_hostname[UNIX_PATH_MAX108 + 1] = {0,}; | |||||
2140 | ||||||
2141 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 2141, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
2142 | ||||||
2143 | ret = xdr_to_generic (req->msg[0], &probe_req, | |||||
2144 | (xdrproc_t)xdr_gd1_mgmt_probe_req); | |||||
2145 | if (ret < 0) { | |||||
2146 | //failed to decode msg; | |||||
2147 | req->rpc_err = GARBAGE_ARGS; | |||||
2148 | goto out; | |||||
2149 | } | |||||
2150 | ||||||
2151 | this = THIS(*__glusterfs_this_location()); | |||||
2152 | ||||||
2153 | conf = this->private; | |||||
2154 | if (probe_req.port) | |||||
2155 | port = probe_req.port; | |||||
2156 | else | |||||
2157 | port = GF_DEFAULT_BASE_PORT24007; | |||||
2158 | ||||||
2159 | gf_log ("glusterd", GF_LOG_INFO,do { do { if (0) printf ("Received probe from uuid: %s", uuid_utoa (probe_req.uuid)); } while (0); _gf_log ("glusterd", "glusterd-handler.c" , __FUNCTION__, 2160, GF_LOG_INFO, "Received probe from uuid: %s" , uuid_utoa (probe_req.uuid)); } while (0) | |||||
2160 | "Received probe from uuid: %s", uuid_utoa (probe_req.uuid))do { do { if (0) printf ("Received probe from uuid: %s", uuid_utoa (probe_req.uuid)); } while (0); _gf_log ("glusterd", "glusterd-handler.c" , __FUNCTION__, 2160, GF_LOG_INFO, "Received probe from uuid: %s" , uuid_utoa (probe_req.uuid)); } while (0); | |||||
2161 | ||||||
2162 | /* Check for uuid collision and handle it in a user friendly way by | |||||
2163 | * sending the error. | |||||
2164 | */ | |||||
2165 | if (!uuid_compare (probe_req.uuid, MY_UUID(__glusterd_uuid()))) { | |||||
2166 | gf_log (THIS->name, GF_LOG_ERROR, "Peer uuid %s is same as "do { do { if (0) printf ("Peer uuid %s is same as " "local uuid. Please check the uuid of both the peers " "from %s/%s", uuid_utoa (probe_req.uuid), "/var/lib/glusterd" , "glusterd.info"); } while (0); _gf_log ((*__glusterfs_this_location ())->name, "glusterd-handler.c", __FUNCTION__, 2169, GF_LOG_ERROR , "Peer uuid %s is same as " "local uuid. Please check the uuid of both the peers " "from %s/%s", uuid_utoa (probe_req.uuid), "/var/lib/glusterd" , "glusterd.info"); } while (0) | |||||
2167 | "local uuid. Please check the uuid of both the peers "do { do { if (0) printf ("Peer uuid %s is same as " "local uuid. Please check the uuid of both the peers " "from %s/%s", uuid_utoa (probe_req.uuid), "/var/lib/glusterd" , "glusterd.info"); } while (0); _gf_log ((*__glusterfs_this_location ())->name, "glusterd-handler.c", __FUNCTION__, 2169, GF_LOG_ERROR , "Peer uuid %s is same as " "local uuid. Please check the uuid of both the peers " "from %s/%s", uuid_utoa (probe_req.uuid), "/var/lib/glusterd" , "glusterd.info"); } while (0) | |||||
2168 | "from %s/%s", uuid_utoa (probe_req.uuid),do { do { if (0) printf ("Peer uuid %s is same as " "local uuid. Please check the uuid of both the peers " "from %s/%s", uuid_utoa (probe_req.uuid), "/var/lib/glusterd" , "glusterd.info"); } while (0); _gf_log ((*__glusterfs_this_location ())->name, "glusterd-handler.c", __FUNCTION__, 2169, GF_LOG_ERROR , "Peer uuid %s is same as " "local uuid. Please check the uuid of both the peers " "from %s/%s", uuid_utoa (probe_req.uuid), "/var/lib/glusterd" , "glusterd.info"); } while (0) | |||||
2169 | GLUSTERD_DEFAULT_WORKDIR, GLUSTERD_INFO_FILE)do { do { if (0) printf ("Peer uuid %s is same as " "local uuid. Please check the uuid of both the peers " "from %s/%s", uuid_utoa (probe_req.uuid), "/var/lib/glusterd" , "glusterd.info"); } while (0); _gf_log ((*__glusterfs_this_location ())->name, "glusterd-handler.c", __FUNCTION__, 2169, GF_LOG_ERROR , "Peer uuid %s is same as " "local uuid. Please check the uuid of both the peers " "from %s/%s", uuid_utoa (probe_req.uuid), "/var/lib/glusterd" , "glusterd.info"); } while (0); | |||||
2170 | rsp.op_ret = -1; | |||||
2171 | rsp.op_errno = GF_PROBE_SAME_UUID; | |||||
2172 | rsp.port = port; | |||||
2173 | goto respond; | |||||
2174 | } | |||||
2175 | ||||||
2176 | ret = glusterd_remote_hostname_get (req, remote_hostname, | |||||
2177 | sizeof (remote_hostname)); | |||||
2178 | if (ret) { | |||||
2179 | gf_log ("", GF_LOG_ERROR, "Unable to get the remote hostname")do { do { if (0) printf ("Unable to get the remote hostname") ; } while (0); _gf_log ("", "glusterd-handler.c", __FUNCTION__ , 2179, GF_LOG_ERROR, "Unable to get the remote hostname"); } while (0); | |||||
2180 | goto out; | |||||
2181 | } | |||||
2182 | ret = glusterd_friend_find (probe_req.uuid, remote_hostname, &peerinfo); | |||||
2183 | if ((ret != 0 ) && (!list_empty (&conf->peers))) { | |||||
2184 | rsp.op_ret = -1; | |||||
2185 | rsp.op_errno = GF_PROBE_ANOTHER_CLUSTER; | |||||
2186 | } else if (ret) { | |||||
2187 | gf_log ("glusterd", GF_LOG_INFO, "Unable to find peerinfo"do { do { if (0) printf ("Unable to find peerinfo" " for host: %s (%d)" , remote_hostname, port); } while (0); _gf_log ("glusterd", "glusterd-handler.c" , __FUNCTION__, 2188, GF_LOG_INFO, "Unable to find peerinfo" " for host: %s (%d)" , remote_hostname, port); } while (0) | |||||
2188 | " for host: %s (%d)", remote_hostname, port)do { do { if (0) printf ("Unable to find peerinfo" " for host: %s (%d)" , remote_hostname, port); } while (0); _gf_log ("glusterd", "glusterd-handler.c" , __FUNCTION__, 2188, GF_LOG_INFO, "Unable to find peerinfo" " for host: %s (%d)" , remote_hostname, port); } while (0); | |||||
2189 | args.mode = GD_MODE_ON; | |||||
2190 | ret = glusterd_friend_add (remote_hostname, port, | |||||
2191 | GD_FRIEND_STATE_PROBE_RCVD, | |||||
2192 | NULL((void*)0), &peerinfo, 0, &args); | |||||
2193 | if (ret) { | |||||
2194 | gf_log ("", GF_LOG_ERROR, "Failed to add peer %s",do { do { if (0) printf ("Failed to add peer %s", remote_hostname ); } while (0); _gf_log ("", "glusterd-handler.c", __FUNCTION__ , 2195, GF_LOG_ERROR, "Failed to add peer %s", remote_hostname ); } while (0) | |||||
2195 | remote_hostname)do { do { if (0) printf ("Failed to add peer %s", remote_hostname ); } while (0); _gf_log ("", "glusterd-handler.c", __FUNCTION__ , 2195, GF_LOG_ERROR, "Failed to add peer %s", remote_hostname ); } while (0); | |||||
2196 | rsp.op_errno = GF_PROBE_ADD_FAILED; | |||||
2197 | } | |||||
2198 | } | |||||
2199 | ||||||
2200 | respond: | |||||
2201 | uuid_copy (rsp.uuid, MY_UUID(__glusterd_uuid())); | |||||
2202 | ||||||
2203 | rsp.hostname = probe_req.hostname; | |||||
2204 | rsp.op_errstr = ""; | |||||
2205 | ||||||
2206 | glusterd_submit_reply (req, &rsp, NULL((void*)0), 0, NULL((void*)0), | |||||
2207 | (xdrproc_t)xdr_gd1_mgmt_probe_rsp); | |||||
2208 | ret = 0; | |||||
2209 | ||||||
2210 | gf_log ("glusterd", GF_LOG_INFO, "Responded to %s, op_ret: %d, "do { do { if (0) printf ("Responded to %s, op_ret: %d, " "op_errno: %d, ret: %d" , remote_hostname, rsp.op_ret, rsp.op_errno, ret); } while (0 ); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__, 2212 , GF_LOG_INFO, "Responded to %s, op_ret: %d, " "op_errno: %d, ret: %d" , remote_hostname, rsp.op_ret, rsp.op_errno, ret); } while (0 ) | |||||
2211 | "op_errno: %d, ret: %d", remote_hostname,do { do { if (0) printf ("Responded to %s, op_ret: %d, " "op_errno: %d, ret: %d" , remote_hostname, rsp.op_ret, rsp.op_errno, ret); } while (0 ); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__, 2212 , GF_LOG_INFO, "Responded to %s, op_ret: %d, " "op_errno: %d, ret: %d" , remote_hostname, rsp.op_ret, rsp.op_errno, ret); } while (0 ) | |||||
2212 | rsp.op_ret, rsp.op_errno, ret)do { do { if (0) printf ("Responded to %s, op_ret: %d, " "op_errno: %d, ret: %d" , remote_hostname, rsp.op_ret, rsp.op_errno, ret); } while (0 ); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__, 2212 , GF_LOG_INFO, "Responded to %s, op_ret: %d, " "op_errno: %d, ret: %d" , remote_hostname, rsp.op_ret, rsp.op_errno, ret); } while (0 ); | |||||
2213 | ||||||
2214 | out: | |||||
2215 | free (probe_req.hostname);//malloced by xdr | |||||
2216 | ||||||
2217 | glusterd_friend_sm (); | |||||
2218 | glusterd_op_sm (); | |||||
2219 | ||||||
2220 | return ret; | |||||
2221 | } | |||||
2222 | ||||||
2223 | int glusterd_handle_probe_query (rpcsvc_request_t *req) | |||||
2224 | { | |||||
2225 | return glusterd_big_locked_handler (req, __glusterd_handle_probe_query); | |||||
2226 | } | |||||
2227 | ||||||
2228 | int | |||||
2229 | __glusterd_handle_cli_profile_volume (rpcsvc_request_t *req) | |||||
2230 | { | |||||
2231 | int32_t ret = -1; | |||||
2232 | gf_cli_req cli_req = {{0,}}; | |||||
2233 | dict_t *dict = NULL((void*)0); | |||||
2234 | glusterd_op_t cli_op = GD_OP_PROFILE_VOLUME; | |||||
2235 | char *volname = NULL((void*)0); | |||||
2236 | int32_t op = 0; | |||||
2237 | char err_str[2048] = {0,}; | |||||
2238 | xlator_t *this = NULL((void*)0); | |||||
2239 | ||||||
2240 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 2240, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
2241 | this = THIS(*__glusterfs_this_location()); | |||||
2242 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 2242, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
2243 | ||||||
2244 | ret = xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req); | |||||
2245 | if (ret < 0) { | |||||
2246 | //failed to decode msg; | |||||
2247 | req->rpc_err = GARBAGE_ARGS; | |||||
2248 | goto out; | |||||
2249 | } | |||||
2250 | ||||||
2251 | if (cli_req.dict.dict_len > 0) { | |||||
2252 | dict = dict_new(); | |||||
2253 | if (!dict) | |||||
2254 | goto out; | |||||
2255 | dict_unserialize (cli_req.dict.dict_val, | |||||
2256 | cli_req.dict.dict_len, &dict); | |||||
2257 | } | |||||
2258 | ||||||
2259 | ret = dict_get_str (dict, "volname", &volname); | |||||
2260 | if (ret) { | |||||
2261 | snprintf (err_str, sizeof (err_str), "Unable to get volume " | |||||
2262 | "name"); | |||||
2263 | gf_log (this->name, GF_LOG_ERROR, "%s", err_str)do { do { if (0) printf ("%s", err_str); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 2263, GF_LOG_ERROR , "%s", err_str); } while (0); | |||||
2264 | goto out; | |||||
2265 | } | |||||
2266 | ||||||
2267 | gf_log (this->name, GF_LOG_INFO, "Received volume profile req "do { do { if (0) printf ("Received volume profile req " "for volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-handler.c" , __FUNCTION__, 2268, GF_LOG_INFO, "Received volume profile req " "for volume %s", volname); } while (0) | |||||
2268 | "for volume %s", volname)do { do { if (0) printf ("Received volume profile req " "for volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-handler.c" , __FUNCTION__, 2268, GF_LOG_INFO, "Received volume profile req " "for volume %s", volname); } while (0); | |||||
2269 | ret = dict_get_int32 (dict, "op", &op); | |||||
2270 | if (ret) { | |||||
2271 | snprintf (err_str, sizeof (err_str), "Unable to get operation"); | |||||
2272 | gf_log (this->name, GF_LOG_ERROR, "%s", err_str)do { do { if (0) printf ("%s", err_str); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 2272, GF_LOG_ERROR , "%s", err_str); } while (0); | |||||
2273 | goto out; | |||||
2274 | } | |||||
2275 | ||||||
2276 | ret = glusterd_op_begin (req, cli_op, dict, err_str, sizeof (err_str)); | |||||
2277 | ||||||
2278 | out: | |||||
2279 | glusterd_friend_sm (); | |||||
2280 | glusterd_op_sm (); | |||||
2281 | ||||||
2282 | free (cli_req.dict.dict_val); | |||||
2283 | ||||||
2284 | if (ret) { | |||||
2285 | if (err_str[0] == '\0') | |||||
2286 | snprintf (err_str, sizeof (err_str), | |||||
2287 | "Operation failed"); | |||||
2288 | ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, | |||||
2289 | dict, err_str); | |||||
2290 | } | |||||
2291 | ||||||
2292 | gf_log (this->name, GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 2292, GF_LOG_DEBUG , "Returning %d", ret); } while (0); | |||||
2293 | return ret; | |||||
2294 | } | |||||
2295 | ||||||
2296 | int | |||||
2297 | glusterd_handle_cli_profile_volume (rpcsvc_request_t *req) | |||||
2298 | { | |||||
2299 | return glusterd_big_locked_handler (req, | |||||
2300 | __glusterd_handle_cli_profile_volume); | |||||
2301 | } | |||||
2302 | ||||||
2303 | int | |||||
2304 | __glusterd_handle_getwd (rpcsvc_request_t *req) | |||||
2305 | { | |||||
2306 | int32_t ret = -1; | |||||
2307 | gf1_cli_getwd_rsp rsp = {0,}; | |||||
2308 | glusterd_conf_t *priv = NULL((void*)0); | |||||
2309 | ||||||
2310 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 2310, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
2311 | ||||||
2312 | priv = THIS(*__glusterfs_this_location())->private; | |||||
2313 | GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: " "priv"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 2313, GF_LOG_ERROR, "Assertion failed: " "priv" ); } while (0); } } while (0); | |||||
2314 | ||||||
2315 | gf_log ("glusterd", GF_LOG_INFO, "Received getwd req")do { do { if (0) printf ("Received getwd req"); } while (0); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__, 2315, GF_LOG_INFO , "Received getwd req"); } while (0); | |||||
2316 | ||||||
2317 | rsp.wd = priv->workdir; | |||||
2318 | ||||||
2319 | glusterd_submit_reply (req, &rsp, NULL((void*)0), 0, NULL((void*)0), | |||||
2320 | (xdrproc_t)xdr_gf1_cli_getwd_rsp); | |||||
2321 | ret = 0; | |||||
2322 | ||||||
2323 | glusterd_friend_sm (); | |||||
2324 | glusterd_op_sm (); | |||||
2325 | ||||||
2326 | return ret; | |||||
2327 | } | |||||
2328 | ||||||
2329 | int | |||||
2330 | glusterd_handle_getwd (rpcsvc_request_t *req) | |||||
2331 | { | |||||
2332 | return glusterd_big_locked_handler (req, __glusterd_handle_getwd); | |||||
2333 | } | |||||
2334 | ||||||
2335 | int | |||||
2336 | __glusterd_handle_mount (rpcsvc_request_t *req) | |||||
2337 | { | |||||
2338 | gf1_cli_mount_req mnt_req = {0,}; | |||||
2339 | gf1_cli_mount_rsp rsp = {0,}; | |||||
2340 | dict_t *dict = NULL((void*)0); | |||||
2341 | int ret = 0; | |||||
2342 | ||||||
2343 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 2343, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
2344 | ||||||
2345 | ret = xdr_to_generic (req->msg[0], &mnt_req, | |||||
2346 | (xdrproc_t)xdr_gf1_cli_mount_req); | |||||
2347 | if (ret < 0) { | |||||
2348 | //failed to decode msg; | |||||
2349 | req->rpc_err = GARBAGE_ARGS; | |||||
2350 | rsp.op_ret = -1; | |||||
2351 | rsp.op_errno = EINVAL22; | |||||
2352 | goto out; | |||||
2353 | } | |||||
2354 | ||||||
2355 | gf_log ("glusterd", GF_LOG_INFO, "Received mount req")do { do { if (0) printf ("Received mount req"); } while (0); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__, 2355, GF_LOG_INFO , "Received mount req"); } while (0); | |||||
2356 | ||||||
2357 | if (mnt_req.dict.dict_len) { | |||||
2358 | /* Unserialize the dictionary */ | |||||
2359 | dict = dict_new (); | |||||
2360 | ||||||
2361 | ret = dict_unserialize (mnt_req.dict.dict_val, | |||||
2362 | mnt_req.dict.dict_len, | |||||
2363 | &dict); | |||||
2364 | if (ret < 0) { | |||||
2365 | gf_log ("glusterd", GF_LOG_ERROR,do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__ , 2367, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0) | |||||
2366 | "failed to "do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__ , 2367, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0) | |||||
2367 | "unserialize req-buffer to dictionary")do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__ , 2367, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0); | |||||
2368 | rsp.op_ret = -1; | |||||
2369 | rsp.op_errno = -EINVAL22; | |||||
2370 | goto out; | |||||
2371 | } else { | |||||
2372 | dict->extra_stdfree = mnt_req.dict.dict_val; | |||||
2373 | } | |||||
2374 | } | |||||
2375 | ||||||
2376 | rsp.op_ret = glusterd_do_mount (mnt_req.label, dict, | |||||
2377 | &rsp.path, &rsp.op_errno); | |||||
2378 | ||||||
2379 | out: | |||||
2380 | if (!rsp.path) | |||||
2381 | rsp.path = ""; | |||||
2382 | ||||||
2383 | glusterd_submit_reply (req, &rsp, NULL((void*)0), 0, NULL((void*)0), | |||||
2384 | (xdrproc_t)xdr_gf1_cli_mount_rsp); | |||||
2385 | ret = 0; | |||||
2386 | ||||||
2387 | if (dict) | |||||
2388 | dict_unref (dict); | |||||
2389 | if (*rsp.path) | |||||
2390 | GF_FREE (rsp.path)__gf_free (rsp.path); | |||||
2391 | ||||||
2392 | glusterd_friend_sm (); | |||||
2393 | glusterd_op_sm (); | |||||
2394 | ||||||
2395 | return ret; | |||||
2396 | } | |||||
2397 | ||||||
2398 | int | |||||
2399 | glusterd_handle_mount (rpcsvc_request_t *req) | |||||
2400 | { | |||||
2401 | return glusterd_big_locked_handler (req, __glusterd_handle_mount); | |||||
2402 | } | |||||
2403 | ||||||
2404 | int | |||||
2405 | __glusterd_handle_umount (rpcsvc_request_t *req) | |||||
2406 | { | |||||
2407 | gf1_cli_umount_req umnt_req = {0,}; | |||||
2408 | gf1_cli_umount_rsp rsp = {0,}; | |||||
2409 | char *mountbroker_root = NULL((void*)0); | |||||
2410 | char mntp[PATH_MAX4096] = {0,}; | |||||
2411 | char *path = NULL((void*)0); | |||||
2412 | runner_t runner = {0,}; | |||||
2413 | int ret = 0; | |||||
2414 | xlator_t *this = THIS(*__glusterfs_this_location()); | |||||
2415 | gf_boolean_t dir_ok = _gf_false; | |||||
2416 | char *pdir = NULL((void*)0); | |||||
2417 | char *t = NULL((void*)0); | |||||
2418 | glusterd_conf_t *priv = NULL((void*)0); | |||||
2419 | ||||||
2420 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 2420, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
2421 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 2421, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
2422 | priv = this->private; | |||||
2423 | ||||||
2424 | ret = xdr_to_generic (req->msg[0], &umnt_req, | |||||
2425 | (xdrproc_t)xdr_gf1_cli_umount_req); | |||||
2426 | if (ret < 0) { | |||||
2427 | //failed to decode msg; | |||||
2428 | req->rpc_err = GARBAGE_ARGS; | |||||
2429 | rsp.op_ret = -1; | |||||
2430 | goto out; | |||||
2431 | } | |||||
2432 | ||||||
2433 | gf_log ("glusterd", GF_LOG_INFO, "Received umount req")do { do { if (0) printf ("Received umount req"); } while (0); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__, 2433 , GF_LOG_INFO, "Received umount req"); } while (0); | |||||
2434 | ||||||
2435 | if (dict_get_str (this->options, "mountbroker-root", | |||||
2436 | &mountbroker_root) != 0) { | |||||
2437 | rsp.op_errno = ENOENT2; | |||||
2438 | goto out; | |||||
2439 | } | |||||
2440 | ||||||
2441 | /* check if it is allowed to umount path */ | |||||
2442 | path = gf_strdup (umnt_req.path); | |||||
2443 | if (!path) { | |||||
2444 | rsp.op_errno = ENOMEM12; | |||||
2445 | goto out; | |||||
2446 | } | |||||
2447 | dir_ok = _gf_false; | |||||
2448 | pdir = dirname (path); | |||||
2449 | t = strtail (pdir, mountbroker_root); | |||||
2450 | if (t && *t == '/') { | |||||
2451 | t = strtail(++t, MB_HIVE"mb_hive"); | |||||
2452 | if (t && !*t) | |||||
2453 | dir_ok = _gf_true; | |||||
2454 | } | |||||
2455 | GF_FREE (path)__gf_free (path); | |||||
2456 | if (!dir_ok) { | |||||
2457 | rsp.op_errno = EACCES13; | |||||
2458 | goto out; | |||||
2459 | } | |||||
2460 | ||||||
2461 | runinit (&runner); | |||||
2462 | runner_add_args (&runner, "umount", umnt_req.path, NULL((void*)0)); | |||||
2463 | if (umnt_req.lazy) | |||||
2464 | runner_add_arg (&runner, "-l"); | |||||
2465 | synclock_unlock (&priv->big_lock); | |||||
2466 | rsp.op_ret = runner_run (&runner); | |||||
2467 | synclock_lock (&priv->big_lock); | |||||
2468 | if (rsp.op_ret == 0) { | |||||
2469 | if (realpath (umnt_req.path, mntp)) | |||||
2470 | rmdir (mntp); | |||||
2471 | else { | |||||
2472 | rsp.op_ret = -1; | |||||
2473 | rsp.op_errno = errno(*__errno_location ()); | |||||
2474 | } | |||||
2475 | if (unlink (umnt_req.path) != 0) { | |||||
2476 | rsp.op_ret = -1; | |||||
2477 | rsp.op_errno = errno(*__errno_location ()); | |||||
2478 | } | |||||
2479 | } | |||||
2480 | ||||||
2481 | out: | |||||
2482 | if (rsp.op_errno) | |||||
2483 | rsp.op_ret = -1; | |||||
2484 | ||||||
2485 | glusterd_submit_reply (req, &rsp, NULL((void*)0), 0, NULL((void*)0), | |||||
2486 | (xdrproc_t)xdr_gf1_cli_umount_rsp); | |||||
2487 | ret = 0; | |||||
2488 | ||||||
2489 | glusterd_friend_sm (); | |||||
2490 | glusterd_op_sm (); | |||||
2491 | ||||||
2492 | return ret; | |||||
2493 | } | |||||
2494 | ||||||
2495 | int | |||||
2496 | glusterd_handle_umount (rpcsvc_request_t *req) | |||||
2497 | { | |||||
2498 | return glusterd_big_locked_handler (req, __glusterd_handle_umount); | |||||
2499 | } | |||||
2500 | ||||||
2501 | int | |||||
2502 | glusterd_friend_remove (uuid_t uuid, char *hostname) | |||||
2503 | { | |||||
2504 | int ret = 0; | |||||
2505 | glusterd_peerinfo_t *peerinfo = NULL((void*)0); | |||||
2506 | ||||||
2507 | ret = glusterd_friend_find (uuid, hostname, &peerinfo); | |||||
2508 | if (ret) | |||||
2509 | goto out; | |||||
2510 | ||||||
2511 | ret = glusterd_friend_remove_cleanup_vols (peerinfo->uuid); | |||||
2512 | if (ret) | |||||
2513 | 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-handler.c" , __FUNCTION__, 2513, GF_LOG_WARNING, "Volumes cleanup failed" ); } while (0); | |||||
2514 | ret = glusterd_friend_cleanup (peerinfo); | |||||
2515 | out: | |||||
2516 | gf_log ("", GF_LOG_DEBUG, "returning %d", ret)do { do { if (0) printf ("returning %d", ret); } while (0); _gf_log ("", "glusterd-handler.c", __FUNCTION__, 2516, GF_LOG_DEBUG, "returning %d", ret); } while (0); | |||||
2517 | return ret; | |||||
2518 | } | |||||
2519 | ||||||
2520 | int | |||||
2521 | glusterd_rpc_create (struct rpc_clnt **rpc, | |||||
2522 | dict_t *options, | |||||
2523 | rpc_clnt_notify_t notify_fn, | |||||
2524 | void *notify_data) | |||||
2525 | { | |||||
2526 | struct rpc_clnt *new_rpc = NULL((void*)0); | |||||
2527 | int ret = -1; | |||||
2528 | xlator_t *this = NULL((void*)0); | |||||
2529 | ||||||
2530 | this = THIS(*__glusterfs_this_location()); | |||||
2531 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 2531, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
2532 | ||||||
2533 | GF_ASSERT (options)do { if (!(options)) { do { do { if (0) printf ("Assertion failed: " "options"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 2533, GF_LOG_ERROR, "Assertion failed: " "options" ); } while (0); } } while (0); | |||||
2534 | ||||||
2535 | /* TODO: is 32 enough? or more ? */ | |||||
2536 | new_rpc = rpc_clnt_new (options, this->ctx, this->name, 16); | |||||
2537 | if (!new_rpc) | |||||
2538 | goto out; | |||||
2539 | ||||||
2540 | ret = rpc_clnt_register_notify (new_rpc, notify_fn, notify_data); | |||||
2541 | *rpc = new_rpc; | |||||
2542 | if (ret) | |||||
2543 | goto out; | |||||
2544 | ret = rpc_clnt_start (new_rpc); | |||||
2545 | out: | |||||
2546 | if (ret) { | |||||
2547 | if (new_rpc) { | |||||
2548 | (void) rpc_clnt_unref (new_rpc); | |||||
2549 | } | |||||
2550 | } | |||||
2551 | ||||||
2552 | gf_log (this->name, GF_LOG_DEBUG, "returning %d", ret)do { do { if (0) printf ("returning %d", ret); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 2552, GF_LOG_DEBUG , "returning %d", ret); } while (0); | |||||
2553 | return ret; | |||||
2554 | } | |||||
2555 | ||||||
2556 | int | |||||
2557 | glusterd_transport_keepalive_options_get (int *interval, int *time) | |||||
2558 | { | |||||
2559 | int ret = 0; | |||||
2560 | xlator_t *this = NULL((void*)0); | |||||
2561 | ||||||
2562 | this = THIS(*__glusterfs_this_location()); | |||||
2563 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 2563, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
2564 | ||||||
2565 | ret = dict_get_int32 (this->options, | |||||
2566 | "transport.socket.keepalive-interval", | |||||
2567 | interval); | |||||
2568 | ret = dict_get_int32 (this->options, | |||||
2569 | "transport.socket.keepalive-time", | |||||
2570 | time); | |||||
2571 | return 0; | |||||
2572 | } | |||||
2573 | ||||||
2574 | int | |||||
2575 | glusterd_transport_inet_options_build (dict_t **options, const char *hostname, | |||||
2576 | int port) | |||||
2577 | { | |||||
2578 | dict_t *dict = NULL((void*)0); | |||||
2579 | int32_t interval = -1; | |||||
2580 | int32_t time = -1; | |||||
2581 | int ret = 0; | |||||
2582 | ||||||
2583 | GF_ASSERT (options)do { if (!(options)) { do { do { if (0) printf ("Assertion failed: " "options"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 2583, GF_LOG_ERROR, "Assertion failed: " "options" ); } while (0); } } while (0); | |||||
2584 | GF_ASSERT (hostname)do { if (!(hostname)) { do { do { if (0) printf ("Assertion failed: " "hostname"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 2584, GF_LOG_ERROR, "Assertion failed: " "hostname" ); } while (0); } } while (0); | |||||
2585 | ||||||
2586 | if (!port) | |||||
2587 | port = GLUSTERD_DEFAULT_PORT24007; | |||||
2588 | ||||||
2589 | /* Build default transport options */ | |||||
2590 | ret = rpc_transport_inet_options_build (&dict, hostname, port); | |||||
2591 | if (ret) | |||||
2592 | goto out; | |||||
2593 | ||||||
2594 | /* Set frame-timeout to 10mins. Default timeout of 30 mins is too long | |||||
2595 | * when compared to 2 mins for cli timeout. This ensures users don't | |||||
2596 | * wait too long after cli timesout before being able to resume normal | |||||
2597 | * operations | |||||
2598 | */ | |||||
2599 | ret = dict_set_int32 (dict, "frame-timeout", 600); | |||||
2600 | if (ret) { | |||||
2601 | gf_log ("glusterd", GF_LOG_ERROR,do { do { if (0) printf ("Failed to set frame-timeout"); } while (0); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__ , 2602, GF_LOG_ERROR, "Failed to set frame-timeout"); } while (0) | |||||
2602 | "Failed to set frame-timeout")do { do { if (0) printf ("Failed to set frame-timeout"); } while (0); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__ , 2602, GF_LOG_ERROR, "Failed to set frame-timeout"); } while (0); | |||||
2603 | goto out; | |||||
2604 | } | |||||
2605 | ||||||
2606 | /* Set keepalive options */ | |||||
2607 | glusterd_transport_keepalive_options_get (&interval, &time); | |||||
2608 | ||||||
2609 | if ((interval > 0) || (time > 0)) | |||||
2610 | ret = rpc_transport_keepalive_options_set (dict, interval, time); | |||||
2611 | *options = dict; | |||||
2612 | out: | |||||
2613 | gf_log ("glusterd", GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__, 2613, GF_LOG_DEBUG , "Returning %d", ret); } while (0); | |||||
2614 | return ret; | |||||
2615 | } | |||||
2616 | ||||||
2617 | int | |||||
2618 | glusterd_friend_rpc_create (xlator_t *this, glusterd_peerinfo_t *peerinfo, | |||||
2619 | glusterd_peerctx_args_t *args) | |||||
2620 | { | |||||
2621 | dict_t *options = NULL((void*)0); | |||||
2622 | int ret = -1; | |||||
2623 | glusterd_peerctx_t *peerctx = NULL((void*)0); | |||||
2624 | data_t *data = NULL((void*)0); | |||||
2625 | ||||||
2626 | peerctx = GF_CALLOC (1, sizeof (*peerctx), gf_gld_mt_peerctx_t)__gf_calloc (1, sizeof (*peerctx), gf_gld_mt_peerctx_t); | |||||
2627 | if (!peerctx) | |||||
2628 | goto out; | |||||
2629 | ||||||
2630 | if (args) | |||||
2631 | peerctx->args = *args; | |||||
2632 | ||||||
2633 | peerctx->peerinfo = peerinfo; | |||||
2634 | ||||||
2635 | ret = glusterd_transport_inet_options_build (&options, | |||||
2636 | peerinfo->hostname, | |||||
2637 | peerinfo->port); | |||||
2638 | if (ret) | |||||
2639 | goto out; | |||||
2640 | ||||||
2641 | /* | |||||
2642 | * For simulated multi-node testing, we need to make sure that we | |||||
2643 | * create our RPC endpoint with the same address that the peer would | |||||
2644 | * use to reach us. | |||||
2645 | */ | |||||
2646 | if (this->options) { | |||||
2647 | data = dict_get(this->options,"transport.socket.bind-address"); | |||||
2648 | if (data) { | |||||
2649 | ret = dict_set(options, | |||||
2650 | "transport.socket.source-addr",data); | |||||
2651 | } | |||||
2652 | } | |||||
2653 | ||||||
2654 | ret = glusterd_rpc_create (&peerinfo->rpc, options, | |||||
2655 | glusterd_peer_rpc_notify, peerctx); | |||||
2656 | if (ret) { | |||||
2657 | gf_log (this->name, GF_LOG_ERROR, "failed to create rpc for"do { do { if (0) printf ("failed to create rpc for" " peer %s" , peerinfo->hostname); } while (0); _gf_log (this->name , "glusterd-handler.c", __FUNCTION__, 2658, GF_LOG_ERROR, "failed to create rpc for" " peer %s", peerinfo->hostname); } while (0) | |||||
2658 | " peer %s", peerinfo->hostname)do { do { if (0) printf ("failed to create rpc for" " peer %s" , peerinfo->hostname); } while (0); _gf_log (this->name , "glusterd-handler.c", __FUNCTION__, 2658, GF_LOG_ERROR, "failed to create rpc for" " peer %s", peerinfo->hostname); } while (0); | |||||
2659 | goto out; | |||||
2660 | } | |||||
2661 | peerctx = NULL((void*)0); | |||||
2662 | ret = 0; | |||||
2663 | out: | |||||
2664 | GF_FREE (peerctx)__gf_free (peerctx); | |||||
2665 | return ret; | |||||
2666 | } | |||||
2667 | ||||||
2668 | int | |||||
2669 | glusterd_friend_add (const char *hoststr, int port, | |||||
2670 | glusterd_friend_sm_state_t state, | |||||
2671 | uuid_t *uuid, | |||||
2672 | glusterd_peerinfo_t **friend, | |||||
2673 | gf_boolean_t restore, | |||||
2674 | glusterd_peerctx_args_t *args) | |||||
2675 | { | |||||
2676 | int ret = 0; | |||||
2677 | xlator_t *this = NULL((void*)0); | |||||
2678 | glusterd_conf_t *conf = NULL((void*)0); | |||||
2679 | ||||||
2680 | this = THIS(*__glusterfs_this_location()); | |||||
2681 | conf = this->private; | |||||
2682 | GF_ASSERT (conf)do { if (!(conf)) { do { do { if (0) printf ("Assertion failed: " "conf"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 2682, GF_LOG_ERROR, "Assertion failed: " "conf" ); } while (0); } } while (0); | |||||
2683 | GF_ASSERT (hoststr)do { if (!(hoststr)) { do { do { if (0) printf ("Assertion failed: " "hoststr"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 2683, GF_LOG_ERROR, "Assertion failed: " "hoststr" ); } while (0); } } while (0); | |||||
2684 | ||||||
2685 | ret = glusterd_peerinfo_new (friend, state, uuid, hoststr, port); | |||||
2686 | if (ret) { | |||||
2687 | goto out; | |||||
2688 | } | |||||
2689 | ||||||
2690 | /* | |||||
2691 | * We can't add to the list after calling glusterd_friend_rpc_create, | |||||
2692 | * even if it succeeds, because by then the callback to take it back | |||||
2693 | * off and free might have happened already (notably in the case of an | |||||
2694 | * invalid peer name). That would mean we're adding something that had | |||||
2695 | * just been free, and we're likely to crash later. | |||||
2696 | */ | |||||
2697 | list_add_tail (&(*friend)->uuid_list, &conf->peers); | |||||
2698 | ||||||
2699 | //restore needs to first create the list of peers, then create rpcs | |||||
2700 | //to keep track of quorum in race-free manner. In restore for each peer | |||||
2701 | //rpc-create calls rpc_notify when the friend-list is partially | |||||
2702 | //constructed, leading to wrong quorum calculations. | |||||
2703 | if (!restore) { | |||||
2704 | ret = glusterd_store_peerinfo (*friend); | |||||
2705 | if (ret == 0) { | |||||
2706 | synclock_unlock (&conf->big_lock); | |||||
2707 | ret = glusterd_friend_rpc_create (this, *friend, args); | |||||
2708 | synclock_lock (&conf->big_lock); | |||||
2709 | } | |||||
2710 | else { | |||||
2711 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("Failed to store peerinfo"); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__ , 2712, GF_LOG_ERROR, "Failed to store peerinfo"); } while (0 ) | |||||
2712 | "Failed to store peerinfo")do { do { if (0) printf ("Failed to store peerinfo"); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__ , 2712, GF_LOG_ERROR, "Failed to store peerinfo"); } while (0 ); | |||||
2713 | } | |||||
2714 | } | |||||
2715 | ||||||
2716 | if (ret) { | |||||
2717 | (void) glusterd_friend_cleanup (*friend); | |||||
2718 | *friend = NULL((void*)0); | |||||
2719 | } | |||||
2720 | ||||||
2721 | out: | |||||
2722 | gf_log (this->name, GF_LOG_INFO, "connect returned %d", ret)do { do { if (0) printf ("connect returned %d", ret); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__ , 2722, GF_LOG_INFO, "connect returned %d", ret); } while (0); | |||||
2723 | return ret; | |||||
2724 | } | |||||
2725 | ||||||
2726 | int | |||||
2727 | glusterd_probe_begin (rpcsvc_request_t *req, const char *hoststr, int port) | |||||
2728 | { | |||||
2729 | int ret = -1; | |||||
2730 | glusterd_peerinfo_t *peerinfo = NULL((void*)0); | |||||
2731 | glusterd_peerctx_args_t args = {0}; | |||||
2732 | glusterd_friend_sm_event_t *event = NULL((void*)0); | |||||
2733 | ||||||
2734 | GF_ASSERT (hoststr)do { if (!(hoststr)) { do { do { if (0) printf ("Assertion failed: " "hoststr"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 2734, GF_LOG_ERROR, "Assertion failed: " "hoststr" ); } while (0); } } while (0); | |||||
2735 | ||||||
2736 | ret = glusterd_friend_find (NULL((void*)0), (char *)hoststr, &peerinfo); | |||||
2737 | ||||||
2738 | if (ret) { | |||||
2739 | gf_log ("glusterd", GF_LOG_INFO, "Unable to find peerinfo"do { do { if (0) printf ("Unable to find peerinfo" " for host: %s (%d)" , hoststr, port); } while (0); _gf_log ("glusterd", "glusterd-handler.c" , __FUNCTION__, 2740, GF_LOG_INFO, "Unable to find peerinfo" " for host: %s (%d)" , hoststr, port); } while (0) | |||||
2740 | " for host: %s (%d)", hoststr, port)do { do { if (0) printf ("Unable to find peerinfo" " for host: %s (%d)" , hoststr, port); } while (0); _gf_log ("glusterd", "glusterd-handler.c" , __FUNCTION__, 2740, GF_LOG_INFO, "Unable to find peerinfo" " for host: %s (%d)" , hoststr, port); } while (0); | |||||
2741 | args.mode = GD_MODE_ON; | |||||
2742 | args.req = req; | |||||
2743 | ret = glusterd_friend_add ((char *)hoststr, port, | |||||
2744 | GD_FRIEND_STATE_DEFAULT, | |||||
2745 | NULL((void*)0), &peerinfo, 0, &args); | |||||
2746 | if ((!ret) && (!peerinfo->connected)) { | |||||
2747 | ret = GLUSTERD_CONNECTION_AWAITED; | |||||
2748 | } | |||||
2749 | ||||||
2750 | } else if (peerinfo->connected && | |||||
2751 | (GD_FRIEND_STATE_BEFRIENDED == peerinfo->state.state)) { | |||||
2752 | ret = glusterd_friend_hostname_update (peerinfo, (char*)hoststr, | |||||
2753 | _gf_false); | |||||
2754 | if (ret) | |||||
2755 | goto out; | |||||
2756 | //this is just to rename so inject local acc for cluster update | |||||
2757 | ret = glusterd_friend_sm_new_event (GD_FRIEND_EVENT_LOCAL_ACC, | |||||
2758 | &event); | |||||
2759 | if (!ret) { | |||||
2760 | event->peerinfo = peerinfo; | |||||
2761 | ret = glusterd_friend_sm_inject_event (event); | |||||
2762 | glusterd_xfer_cli_probe_resp (req, 0, GF_PROBE_SUCCESS, | |||||
2763 | NULL((void*)0), (char*)hoststr, | |||||
2764 | port); | |||||
2765 | } | |||||
2766 | } else { | |||||
2767 | glusterd_xfer_cli_probe_resp (req, 0, GF_PROBE_FRIEND, NULL((void*)0), | |||||
2768 | (char*)hoststr, port); | |||||
2769 | } | |||||
2770 | ||||||
2771 | out: | |||||
2772 | gf_log ("", GF_LOG_DEBUG, "returning %d", ret)do { do { if (0) printf ("returning %d", ret); } while (0); _gf_log ("", "glusterd-handler.c", __FUNCTION__, 2772, GF_LOG_DEBUG, "returning %d", ret); } while (0); | |||||
2773 | return ret; | |||||
2774 | } | |||||
2775 | ||||||
2776 | int | |||||
2777 | glusterd_deprobe_begin (rpcsvc_request_t *req, const char *hoststr, int port, | |||||
2778 | uuid_t uuid) | |||||
2779 | { | |||||
2780 | int ret = -1; | |||||
2781 | glusterd_peerinfo_t *peerinfo = NULL((void*)0); | |||||
2782 | glusterd_friend_sm_event_t *event = NULL((void*)0); | |||||
2783 | glusterd_probe_ctx_t *ctx = NULL((void*)0); | |||||
2784 | ||||||
2785 | GF_ASSERT (hoststr)do { if (!(hoststr)) { do { do { if (0) printf ("Assertion failed: " "hoststr"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 2785, GF_LOG_ERROR, "Assertion failed: " "hoststr" ); } while (0); } } while (0); | |||||
2786 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 2786, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
2787 | ||||||
2788 | ret = glusterd_friend_find (uuid, (char *)hoststr, &peerinfo); | |||||
2789 | ||||||
2790 | if (ret) { | |||||
2791 | gf_log ("glusterd", GF_LOG_INFO, "Unable to find peerinfo"do { do { if (0) printf ("Unable to find peerinfo" " for host: %s %d" , hoststr, port); } while (0); _gf_log ("glusterd", "glusterd-handler.c" , __FUNCTION__, 2792, GF_LOG_INFO, "Unable to find peerinfo" " for host: %s %d" , hoststr, port); } while (0) | |||||
2792 | " for host: %s %d", hoststr, port)do { do { if (0) printf ("Unable to find peerinfo" " for host: %s %d" , hoststr, port); } while (0); _gf_log ("glusterd", "glusterd-handler.c" , __FUNCTION__, 2792, GF_LOG_INFO, "Unable to find peerinfo" " for host: %s %d" , hoststr, port); } while (0); | |||||
2793 | goto out; | |||||
2794 | } | |||||
2795 | ||||||
2796 | if (!peerinfo->rpc) { | |||||
2797 | //handle this case | |||||
2798 | goto out; | |||||
2799 | } | |||||
2800 | ||||||
2801 | ret = glusterd_friend_sm_new_event | |||||
2802 | (GD_FRIEND_EVENT_INIT_REMOVE_FRIEND, &event); | |||||
2803 | ||||||
2804 | if (ret) { | |||||
2805 | gf_log ("glusterd", GF_LOG_ERROR,do { do { if (0) printf ("Unable to get new event"); } while ( 0); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__, 2806 , GF_LOG_ERROR, "Unable to get new event"); } while (0) | |||||
2806 | "Unable to get new event")do { do { if (0) printf ("Unable to get new event"); } while ( 0); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__, 2806 , GF_LOG_ERROR, "Unable to get new event"); } while (0); | |||||
2807 | return ret; | |||||
2808 | } | |||||
2809 | ||||||
2810 | ctx = GF_CALLOC (1, sizeof(*ctx), gf_gld_mt_probe_ctx_t)__gf_calloc (1, sizeof(*ctx), gf_gld_mt_probe_ctx_t); | |||||
2811 | ||||||
2812 | if (!ctx) { | |||||
2813 | goto out; | |||||
2814 | } | |||||
2815 | ||||||
2816 | ctx->hostname = gf_strdup (hoststr); | |||||
2817 | ctx->port = port; | |||||
2818 | ctx->req = req; | |||||
2819 | ||||||
2820 | event->ctx = ctx; | |||||
2821 | ||||||
2822 | event->peerinfo = peerinfo; | |||||
2823 | ||||||
2824 | ret = glusterd_friend_sm_inject_event (event); | |||||
2825 | ||||||
2826 | if (ret) { | |||||
2827 | gf_log ("glusterd", GF_LOG_ERROR, "Unable to inject event %d, "do { do { if (0) printf ("Unable to inject event %d, " "ret = %d" , event->event, ret); } while (0); _gf_log ("glusterd", "glusterd-handler.c" , __FUNCTION__, 2828, GF_LOG_ERROR, "Unable to inject event %d, " "ret = %d", event->event, ret); } while (0) | |||||
2828 | "ret = %d", event->event, ret)do { do { if (0) printf ("Unable to inject event %d, " "ret = %d" , event->event, ret); } while (0); _gf_log ("glusterd", "glusterd-handler.c" , __FUNCTION__, 2828, GF_LOG_ERROR, "Unable to inject event %d, " "ret = %d", event->event, ret); } while (0); | |||||
2829 | goto out; | |||||
2830 | } | |||||
2831 | ||||||
2832 | out: | |||||
2833 | return ret; | |||||
2834 | } | |||||
2835 | ||||||
2836 | ||||||
2837 | int | |||||
2838 | glusterd_xfer_friend_remove_resp (rpcsvc_request_t *req, char *hostname, int port) | |||||
2839 | { | |||||
2840 | gd1_mgmt_friend_rsp rsp = {{0}, }; | |||||
2841 | int32_t ret = -1; | |||||
2842 | xlator_t *this = NULL((void*)0); | |||||
2843 | glusterd_conf_t *conf = NULL((void*)0); | |||||
2844 | ||||||
2845 | GF_ASSERT (hostname)do { if (!(hostname)) { do { do { if (0) printf ("Assertion failed: " "hostname"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 2845, GF_LOG_ERROR, "Assertion failed: " "hostname" ); } while (0); } } while (0); | |||||
2846 | ||||||
2847 | rsp.op_ret = 0; | |||||
2848 | this = THIS(*__glusterfs_this_location()); | |||||
2849 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 2849, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
2850 | ||||||
2851 | conf = this->private; | |||||
2852 | ||||||
2853 | uuid_copy (rsp.uuid, MY_UUID(__glusterd_uuid())); | |||||
2854 | rsp.hostname = hostname; | |||||
2855 | rsp.port = port; | |||||
2856 | ret = glusterd_submit_reply (req, &rsp, NULL((void*)0), 0, NULL((void*)0), | |||||
2857 | (xdrproc_t)xdr_gd1_mgmt_friend_rsp); | |||||
2858 | ||||||
2859 | gf_log ("glusterd", GF_LOG_INFO,do { do { if (0) printf ("Responded to %s (%d), ret: %d", hostname , port, ret); } while (0); _gf_log ("glusterd", "glusterd-handler.c" , __FUNCTION__, 2860, GF_LOG_INFO, "Responded to %s (%d), ret: %d" , hostname, port, ret); } while (0) | |||||
2860 | "Responded to %s (%d), ret: %d", hostname, port, ret)do { do { if (0) printf ("Responded to %s (%d), ret: %d", hostname , port, ret); } while (0); _gf_log ("glusterd", "glusterd-handler.c" , __FUNCTION__, 2860, GF_LOG_INFO, "Responded to %s (%d), ret: %d" , hostname, port, ret); } while (0); | |||||
2861 | return ret; | |||||
2862 | } | |||||
2863 | ||||||
2864 | ||||||
2865 | int | |||||
2866 | glusterd_xfer_friend_add_resp (rpcsvc_request_t *req, char *hostname, int port, | |||||
2867 | int32_t op_ret, int32_t op_errno) | |||||
2868 | { | |||||
2869 | gd1_mgmt_friend_rsp rsp = {{0}, }; | |||||
2870 | int32_t ret = -1; | |||||
2871 | xlator_t *this = NULL((void*)0); | |||||
2872 | glusterd_conf_t *conf = NULL((void*)0); | |||||
2873 | ||||||
2874 | GF_ASSERT (hostname)do { if (!(hostname)) { do { do { if (0) printf ("Assertion failed: " "hostname"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 2874, GF_LOG_ERROR, "Assertion failed: " "hostname" ); } while (0); } } while (0); | |||||
2875 | ||||||
2876 | this = THIS(*__glusterfs_this_location()); | |||||
2877 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 2877, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
2878 | ||||||
2879 | conf = this->private; | |||||
2880 | ||||||
2881 | uuid_copy (rsp.uuid, MY_UUID(__glusterd_uuid())); | |||||
2882 | rsp.op_ret = op_ret; | |||||
2883 | rsp.op_errno = op_errno; | |||||
2884 | rsp.hostname = gf_strdup (hostname); | |||||
2885 | rsp.port = port; | |||||
2886 | ||||||
2887 | ret = glusterd_submit_reply (req, &rsp, NULL((void*)0), 0, NULL((void*)0), | |||||
2888 | (xdrproc_t)xdr_gd1_mgmt_friend_rsp); | |||||
2889 | ||||||
2890 | gf_log ("glusterd", GF_LOG_INFO,do { do { if (0) printf ("Responded to %s (%d), ret: %d", hostname , port, ret); } while (0); _gf_log ("glusterd", "glusterd-handler.c" , __FUNCTION__, 2891, GF_LOG_INFO, "Responded to %s (%d), ret: %d" , hostname, port, ret); } while (0) | |||||
2891 | "Responded to %s (%d), ret: %d", hostname, port, ret)do { do { if (0) printf ("Responded to %s (%d), ret: %d", hostname , port, ret); } while (0); _gf_log ("glusterd", "glusterd-handler.c" , __FUNCTION__, 2891, GF_LOG_INFO, "Responded to %s (%d), ret: %d" , hostname, port, ret); } while (0); | |||||
2892 | GF_FREE (rsp.hostname)__gf_free (rsp.hostname); | |||||
2893 | return ret; | |||||
2894 | } | |||||
2895 | ||||||
2896 | int | |||||
2897 | glusterd_xfer_cli_probe_resp (rpcsvc_request_t *req, int32_t op_ret, | |||||
2898 | int32_t op_errno, char *op_errstr, char *hostname, | |||||
2899 | int port) | |||||
2900 | { | |||||
2901 | gf1_cli_probe_rsp rsp = {0, }; | |||||
2902 | int32_t ret = -1; | |||||
2903 | ||||||
2904 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 2904, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
2905 | ||||||
2906 | rsp.op_ret = op_ret; | |||||
2907 | rsp.op_errno = op_errno; | |||||
2908 | rsp.op_errstr = op_errstr ? op_errstr : ""; | |||||
2909 | rsp.hostname = hostname; | |||||
2910 | rsp.port = port; | |||||
2911 | ||||||
2912 | ret = glusterd_submit_reply (req, &rsp, NULL((void*)0), 0, NULL((void*)0), | |||||
2913 | (xdrproc_t)xdr_gf1_cli_probe_rsp); | |||||
2914 | ||||||
2915 | gf_log ("glusterd", GF_LOG_INFO, "Responded to CLI, ret: %d",ret)do { do { if (0) printf ("Responded to CLI, ret: %d",ret); } while (0); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__ , 2915, GF_LOG_INFO, "Responded to CLI, ret: %d",ret); } while (0); | |||||
2916 | ||||||
2917 | return ret; | |||||
2918 | } | |||||
2919 | ||||||
2920 | int | |||||
2921 | glusterd_xfer_cli_deprobe_resp (rpcsvc_request_t *req, int32_t op_ret, | |||||
2922 | int32_t op_errno, char *op_errstr, | |||||
2923 | char *hostname) | |||||
2924 | { | |||||
2925 | gf1_cli_deprobe_rsp rsp = {0, }; | |||||
2926 | int32_t ret = -1; | |||||
2927 | ||||||
2928 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 2928, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
2929 | ||||||
2930 | rsp.op_ret = op_ret; | |||||
2931 | rsp.op_errno = op_errno; | |||||
2932 | rsp.op_errstr = op_errstr ? op_errstr : ""; | |||||
2933 | rsp.hostname = hostname; | |||||
2934 | ||||||
2935 | ret = glusterd_submit_reply (req, &rsp, NULL((void*)0), 0, NULL((void*)0), | |||||
2936 | (xdrproc_t)xdr_gf1_cli_deprobe_rsp); | |||||
2937 | ||||||
2938 | gf_log ("glusterd", GF_LOG_INFO, "Responded to CLI, ret: %d",ret)do { do { if (0) printf ("Responded to CLI, ret: %d",ret); } while (0); _gf_log ("glusterd", "glusterd-handler.c", __FUNCTION__ , 2938, GF_LOG_INFO, "Responded to CLI, ret: %d",ret); } while (0); | |||||
2939 | ||||||
2940 | return ret; | |||||
2941 | } | |||||
2942 | ||||||
2943 | int32_t | |||||
2944 | glusterd_list_friends (rpcsvc_request_t *req, dict_t *dict, int32_t flags) | |||||
2945 | { | |||||
2946 | int32_t ret = -1; | |||||
2947 | glusterd_conf_t *priv = NULL((void*)0); | |||||
2948 | glusterd_peerinfo_t *entry = NULL((void*)0); | |||||
2949 | int32_t count = 0; | |||||
2950 | dict_t *friends = NULL((void*)0); | |||||
2951 | gf1_cli_peer_list_rsp rsp = {0,}; | |||||
2952 | char my_uuid_str[64] = {0,}; | |||||
2953 | char key[256] = {0,}; | |||||
2954 | ||||||
2955 | priv = THIS(*__glusterfs_this_location())->private; | |||||
2956 | GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: " "priv"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 2956, GF_LOG_ERROR, "Assertion failed: " "priv" ); } while (0); } } while (0); | |||||
2957 | ||||||
2958 | friends = dict_new (); | |||||
2959 | if (!friends) { | |||||
2960 | gf_log ("", GF_LOG_WARNING, "Out of Memory")do { do { if (0) printf ("Out of Memory"); } while (0); _gf_log ("", "glusterd-handler.c", __FUNCTION__, 2960, GF_LOG_WARNING , "Out of Memory"); } while (0); | |||||
2961 | goto out; | |||||
2962 | } | |||||
2963 | if (!list_empty (&priv->peers)) { | |||||
2964 | list_for_each_entry (entry, &priv->peers, uuid_list)for (entry = ((typeof(*entry) *)((char *)((&priv->peers )->next)-(unsigned long)(&((typeof(*entry) *)0)->uuid_list ))); &entry->uuid_list != (&priv->peers); entry = ((typeof(*entry) *)((char *)(entry->uuid_list.next)-(unsigned long)(&((typeof(*entry) *)0)->uuid_list)))) { | |||||
2965 | count++; | |||||
2966 | ret = glusterd_add_peer_detail_to_dict (entry, | |||||
2967 | friends, count); | |||||
2968 | if (ret) | |||||
2969 | goto out; | |||||
2970 | } | |||||
2971 | } | |||||
2972 | ||||||
2973 | if (flags == GF_CLI_LIST_POOL_NODES) { | |||||
2974 | count++; | |||||
2975 | snprintf (key, 256, "friend%d.uuid", count); | |||||
2976 | uuid_utoa_r (MY_UUID(__glusterd_uuid()), my_uuid_str); | |||||
2977 | ret = dict_set_str (friends, key, my_uuid_str); | |||||
2978 | if (ret) | |||||
2979 | goto out; | |||||
2980 | ||||||
2981 | snprintf (key, 256, "friend%d.hostname", count); | |||||
2982 | ret = dict_set_str (friends, key, "localhost"); | |||||
2983 | if (ret) | |||||
2984 | goto out; | |||||
2985 | ||||||
2986 | snprintf (key, 256, "friend%d.connected", count); | |||||
2987 | ret = dict_set_int32 (friends, key, 1); | |||||
2988 | if (ret) | |||||
2989 | goto out; | |||||
2990 | } | |||||
2991 | ||||||
2992 | ret = dict_set_int32 (friends, "count", count); | |||||
2993 | if (ret) | |||||
2994 | goto out; | |||||
2995 | ||||||
2996 | ret = dict_allocate_and_serialize (friends, &rsp.friends.friends_val, | |||||
2997 | &rsp.friends.friends_len); | |||||
2998 | ||||||
2999 | if (ret) | |||||
3000 | goto out; | |||||
3001 | ||||||
3002 | ret = 0; | |||||
3003 | out: | |||||
3004 | ||||||
3005 | if (friends) | |||||
3006 | dict_unref (friends); | |||||
3007 | ||||||
3008 | rsp.op_ret = ret; | |||||
3009 | ||||||
3010 | glusterd_submit_reply (req, &rsp, NULL((void*)0), 0, NULL((void*)0), | |||||
3011 | (xdrproc_t)xdr_gf1_cli_peer_list_rsp); | |||||
3012 | ret = 0; | |||||
3013 | GF_FREE (rsp.friends.friends_val)__gf_free (rsp.friends.friends_val); | |||||
3014 | ||||||
3015 | return ret; | |||||
3016 | } | |||||
3017 | ||||||
3018 | int32_t | |||||
3019 | glusterd_get_volumes (rpcsvc_request_t *req, dict_t *dict, int32_t flags) | |||||
3020 | { | |||||
3021 | int32_t ret = -1; | |||||
3022 | glusterd_conf_t *priv = NULL((void*)0); | |||||
3023 | glusterd_volinfo_t *entry = NULL((void*)0); | |||||
3024 | int32_t count = 0; | |||||
3025 | dict_t *volumes = NULL((void*)0); | |||||
3026 | gf_cli_rsp rsp = {0,}; | |||||
3027 | char *volname = NULL((void*)0); | |||||
3028 | ||||||
3029 | priv = THIS(*__glusterfs_this_location())->private; | |||||
3030 | GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: " "priv"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 3030, GF_LOG_ERROR, "Assertion failed: " "priv" ); } while (0); } } while (0); | |||||
3031 | ||||||
3032 | volumes = dict_new (); | |||||
3033 | if (!volumes) { | |||||
3034 | gf_log ("", GF_LOG_WARNING, "Out of Memory")do { do { if (0) printf ("Out of Memory"); } while (0); _gf_log ("", "glusterd-handler.c", __FUNCTION__, 3034, GF_LOG_WARNING , "Out of Memory"); } while (0); | |||||
3035 | goto out; | |||||
3036 | } | |||||
3037 | ||||||
3038 | if (list_empty (&priv->volumes)) { | |||||
3039 | ret = 0; | |||||
3040 | goto respond; | |||||
3041 | } | |||||
3042 | ||||||
3043 | if (flags == GF_CLI_GET_VOLUME_ALL) { | |||||
3044 | list_for_each_entry (entry, &priv->volumes, vol_list)for (entry = ((typeof(*entry) *)((char *)((&priv->volumes )->next)-(unsigned long)(&((typeof(*entry) *)0)->vol_list ))); &entry->vol_list != (&priv->volumes); entry = ((typeof(*entry) *)((char *)(entry->vol_list.next)-(unsigned long)(&((typeof(*entry) *)0)->vol_list)))) { | |||||
3045 | ret = glusterd_add_volume_detail_to_dict (entry, | |||||
3046 | volumes, count); | |||||
3047 | if (ret) | |||||
3048 | goto respond; | |||||
3049 | ||||||
3050 | count++; | |||||
3051 | ||||||
3052 | } | |||||
3053 | ||||||
3054 | } else if (flags == GF_CLI_GET_NEXT_VOLUME) { | |||||
3055 | ret = dict_get_str (dict, "volname", &volname); | |||||
3056 | ||||||
3057 | if (ret) { | |||||
3058 | if (priv->volumes.next) { | |||||
3059 | entry = list_entry (priv->volumes.next,((typeof (*entry) *)((char *)(priv->volumes.next)-(unsigned long)(&((typeof (*entry) *)0)->vol_list))) | |||||
3060 | typeof (*entry),((typeof (*entry) *)((char *)(priv->volumes.next)-(unsigned long)(&((typeof (*entry) *)0)->vol_list))) | |||||
3061 | vol_list)((typeof (*entry) *)((char *)(priv->volumes.next)-(unsigned long)(&((typeof (*entry) *)0)->vol_list))); | |||||
3062 | } | |||||
3063 | } else { | |||||
3064 | ret = glusterd_volinfo_find (volname, &entry); | |||||
3065 | if (ret) | |||||
3066 | goto respond; | |||||
3067 | entry = list_entry (entry->vol_list.next,((typeof (*entry) *)((char *)(entry->vol_list.next)-(unsigned long)(&((typeof (*entry) *)0)->vol_list))) | |||||
3068 | typeof (*entry),((typeof (*entry) *)((char *)(entry->vol_list.next)-(unsigned long)(&((typeof (*entry) *)0)->vol_list))) | |||||
3069 | vol_list)((typeof (*entry) *)((char *)(entry->vol_list.next)-(unsigned long)(&((typeof (*entry) *)0)->vol_list))); | |||||
3070 | } | |||||
3071 | ||||||
3072 | if (&entry->vol_list == &priv->volumes) { | |||||
3073 | goto respond; | |||||
3074 | } else { | |||||
3075 | ret = glusterd_add_volume_detail_to_dict (entry, | |||||
3076 | volumes, count); | |||||
3077 | if (ret) | |||||
3078 | goto respond; | |||||
3079 | ||||||
3080 | count++; | |||||
3081 | } | |||||
3082 | } else if (flags == GF_CLI_GET_VOLUME) { | |||||
3083 | ret = dict_get_str (dict, "volname", &volname); | |||||
3084 | if (ret) | |||||
3085 | goto respond; | |||||
3086 | ||||||
3087 | ret = glusterd_volinfo_find (volname, &entry); | |||||
3088 | if (ret) | |||||
3089 | goto respond; | |||||
3090 | ||||||
3091 | ret = glusterd_add_volume_detail_to_dict (entry, | |||||
3092 | volumes, count); | |||||
3093 | if (ret) | |||||
3094 | goto respond; | |||||
3095 | ||||||
3096 | count++; | |||||
3097 | } | |||||
3098 | ||||||
3099 | respond: | |||||
3100 | ret = dict_set_int32 (volumes, "count", count); | |||||
3101 | if (ret) | |||||
3102 | goto out; | |||||
3103 | ret = dict_allocate_and_serialize (volumes, &rsp.dict.dict_val, | |||||
3104 | &rsp.dict.dict_len); | |||||
3105 | ||||||
3106 | if (ret) | |||||
3107 | goto out; | |||||
3108 | ||||||
3109 | ret = 0; | |||||
3110 | out: | |||||
3111 | rsp.op_ret = ret; | |||||
3112 | ||||||
3113 | rsp.op_errstr = ""; | |||||
3114 | glusterd_submit_reply (req, &rsp, NULL((void*)0), 0, NULL((void*)0), | |||||
3115 | (xdrproc_t)xdr_gf_cli_rsp); | |||||
3116 | ret = 0; | |||||
3117 | ||||||
3118 | if (volumes) | |||||
3119 | dict_unref (volumes); | |||||
3120 | ||||||
3121 | GF_FREE (rsp.dict.dict_val)__gf_free (rsp.dict.dict_val); | |||||
3122 | return ret; | |||||
3123 | } | |||||
3124 | ||||||
3125 | int | |||||
3126 | __glusterd_handle_status_volume (rpcsvc_request_t *req) | |||||
3127 | { | |||||
3128 | int32_t ret = -1; | |||||
3129 | uint32_t cmd = 0; | |||||
3130 | dict_t *dict = NULL((void*)0); | |||||
3131 | char *volname = 0; | |||||
3132 | gf_cli_req cli_req = {{0,}}; | |||||
3133 | glusterd_op_t cli_op = GD_OP_STATUS_VOLUME; | |||||
3134 | char err_str[2048] = {0,}; | |||||
3135 | xlator_t *this = NULL((void*)0); | |||||
3136 | ||||||
3137 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 3137, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
3138 | this = THIS(*__glusterfs_this_location()); | |||||
3139 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 3139, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
3140 | ||||||
3141 | ret = xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req); | |||||
3142 | if (ret < 0) { | |||||
3143 | //failed to decode msg; | |||||
3144 | req->rpc_err = GARBAGE_ARGS; | |||||
3145 | goto out; | |||||
3146 | } | |||||
3147 | ||||||
3148 | if (cli_req.dict.dict_len > 0) { | |||||
3149 | dict = dict_new(); | |||||
3150 | if (!dict) | |||||
3151 | goto out; | |||||
3152 | ret = dict_unserialize (cli_req.dict.dict_val, | |||||
3153 | cli_req.dict.dict_len, &dict); | |||||
3154 | if (ret < 0) { | |||||
3155 | gf_log (this->name, GF_LOG_ERROR, "failed to "do { do { if (0) printf ("failed to " "unserialize buffer"); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__ , 3156, GF_LOG_ERROR, "failed to " "unserialize buffer"); } while (0) | |||||
3156 | "unserialize buffer")do { do { if (0) printf ("failed to " "unserialize buffer"); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__ , 3156, GF_LOG_ERROR, "failed to " "unserialize buffer"); } while (0); | |||||
3157 | snprintf (err_str, sizeof (err_str), "Unable to decode " | |||||
3158 | "the command"); | |||||
3159 | goto out; | |||||
3160 | } | |||||
3161 | ||||||
3162 | } | |||||
3163 | ||||||
3164 | ret = dict_get_uint32 (dict, "cmd", &cmd); | |||||
3165 | if (ret) | |||||
3166 | goto out; | |||||
3167 | ||||||
3168 | if (!(cmd & GF_CLI_STATUS_ALL)) { | |||||
3169 | ret = dict_get_str (dict, "volname", &volname); | |||||
3170 | if (ret) { | |||||
3171 | snprintf (err_str, sizeof (err_str), "Unable to get " | |||||
3172 | "volume name"); | |||||
3173 | gf_log (this->name, GF_LOG_ERROR, "%s", err_str)do { do { if (0) printf ("%s", err_str); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 3173, GF_LOG_ERROR , "%s", err_str); } while (0); | |||||
3174 | goto out; | |||||
3175 | } | |||||
3176 | gf_log (this->name, GF_LOG_INFO,do { do { if (0) printf ("Received status volume req for volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-handler.c" , __FUNCTION__, 3177, GF_LOG_INFO, "Received status volume req for volume %s" , volname); } while (0) | |||||
3177 | "Received status volume req for volume %s", volname)do { do { if (0) printf ("Received status volume req for volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-handler.c" , __FUNCTION__, 3177, GF_LOG_INFO, "Received status volume req for volume %s" , volname); } while (0); | |||||
3178 | ||||||
3179 | } | |||||
3180 | ||||||
3181 | ret = glusterd_op_begin_synctask (req, GD_OP_STATUS_VOLUME, dict); | |||||
3182 | ||||||
3183 | out: | |||||
3184 | ||||||
3185 | if (ret) { | |||||
3186 | if (err_str[0] == '\0') | |||||
3187 | snprintf (err_str, sizeof (err_str), | |||||
3188 | "Operation failed"); | |||||
3189 | ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, | |||||
3190 | dict, err_str); | |||||
3191 | } | |||||
3192 | free (cli_req.dict.dict_val); | |||||
3193 | ||||||
3194 | return ret; | |||||
3195 | } | |||||
3196 | ||||||
3197 | int | |||||
3198 | glusterd_handle_status_volume (rpcsvc_request_t *req) | |||||
3199 | { | |||||
3200 | return glusterd_big_locked_handler (req, | |||||
3201 | __glusterd_handle_status_volume); | |||||
3202 | } | |||||
3203 | ||||||
3204 | int | |||||
3205 | __glusterd_handle_cli_clearlocks_volume (rpcsvc_request_t *req) | |||||
3206 | { | |||||
3207 | int32_t ret = -1; | |||||
3208 | gf_cli_req cli_req = {{0,}}; | |||||
3209 | glusterd_op_t cli_op = GD_OP_CLEARLOCKS_VOLUME; | |||||
3210 | char *volname = NULL((void*)0); | |||||
3211 | dict_t *dict = NULL((void*)0); | |||||
3212 | char err_str[2048] = {0,}; | |||||
3213 | xlator_t *this = NULL((void*)0); | |||||
3214 | ||||||
3215 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 3215, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
3216 | this = THIS(*__glusterfs_this_location()); | |||||
3217 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 3217, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
3218 | ||||||
3219 | ret = -1; | |||||
3220 | ret = xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req); | |||||
3221 | if (ret < 0) { | |||||
3222 | req->rpc_err = GARBAGE_ARGS; | |||||
3223 | goto out; | |||||
3224 | } | |||||
3225 | ||||||
3226 | if (cli_req.dict.dict_len) { | |||||
3227 | dict = dict_new (); | |||||
3228 | ||||||
3229 | ret = dict_unserialize (cli_req.dict.dict_val, | |||||
3230 | cli_req.dict.dict_len, | |||||
3231 | &dict); | |||||
3232 | if (ret < 0) { | |||||
3233 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("failed to unserialize req-buffer to" " dictionary"); } while (0); _gf_log (this->name, "glusterd-handler.c" , __FUNCTION__, 3235, GF_LOG_ERROR, "failed to unserialize req-buffer to" " dictionary"); } while (0) | |||||
3234 | "failed to unserialize req-buffer to"do { do { if (0) printf ("failed to unserialize req-buffer to" " dictionary"); } while (0); _gf_log (this->name, "glusterd-handler.c" , __FUNCTION__, 3235, GF_LOG_ERROR, "failed to unserialize req-buffer to" " dictionary"); } while (0) | |||||
3235 | " dictionary")do { do { if (0) printf ("failed to unserialize req-buffer to" " dictionary"); } while (0); _gf_log (this->name, "glusterd-handler.c" , __FUNCTION__, 3235, GF_LOG_ERROR, "failed to unserialize req-buffer to" " dictionary"); } while (0); | |||||
3236 | snprintf (err_str, sizeof (err_str), "unable to decode " | |||||
3237 | "the command"); | |||||
3238 | goto out; | |||||
3239 | } | |||||
3240 | ||||||
3241 | } else { | |||||
3242 | ret = -1; | |||||
3243 | gf_log (this->name, GF_LOG_ERROR, "Empty cli request.")do { do { if (0) printf ("Empty cli request."); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 3243, GF_LOG_ERROR , "Empty cli request."); } while (0); | |||||
3244 | goto out; | |||||
3245 | } | |||||
3246 | ||||||
3247 | ret = dict_get_str (dict, "volname", &volname); | |||||
3248 | if (ret) { | |||||
3249 | snprintf (err_str, sizeof (err_str), "Unable to get volume " | |||||
3250 | "name"); | |||||
3251 | gf_log (this->name, GF_LOG_ERROR, "%s", err_str)do { do { if (0) printf ("%s", err_str); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 3251, GF_LOG_ERROR , "%s", err_str); } while (0); | |||||
3252 | goto out; | |||||
3253 | } | |||||
3254 | ||||||
3255 | gf_log (this->name, GF_LOG_INFO, "Received clear-locks volume req "do { do { if (0) printf ("Received clear-locks volume req " "for volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-handler.c" , __FUNCTION__, 3256, GF_LOG_INFO, "Received clear-locks volume req " "for volume %s", volname); } while (0) | |||||
3256 | "for volume %s", volname)do { do { if (0) printf ("Received clear-locks volume req " "for volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-handler.c" , __FUNCTION__, 3256, GF_LOG_INFO, "Received clear-locks volume req " "for volume %s", volname); } while (0); | |||||
3257 | ||||||
3258 | ret = glusterd_op_begin_synctask (req, GD_OP_CLEARLOCKS_VOLUME, dict); | |||||
3259 | ||||||
3260 | out: | |||||
3261 | if (ret) { | |||||
3262 | if (err_str[0] == '\0') | |||||
3263 | snprintf (err_str, sizeof (err_str), | |||||
3264 | "Operation failed"); | |||||
3265 | ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, | |||||
3266 | dict, err_str); | |||||
3267 | } | |||||
3268 | free (cli_req.dict.dict_val); | |||||
3269 | ||||||
3270 | return ret; | |||||
3271 | } | |||||
3272 | ||||||
3273 | int | |||||
3274 | glusterd_handle_cli_clearlocks_volume (rpcsvc_request_t *req) | |||||
3275 | { | |||||
3276 | return glusterd_big_locked_handler (req, | |||||
3277 | __glusterd_handle_cli_clearlocks_volume); | |||||
3278 | } | |||||
3279 | ||||||
3280 | int | |||||
3281 | __glusterd_brick_rpc_notify (struct rpc_clnt *rpc, void *mydata, | |||||
3282 | rpc_clnt_event_t event, void *data) | |||||
3283 | { | |||||
3284 | xlator_t *this = NULL((void*)0); | |||||
3285 | glusterd_conf_t *conf = NULL((void*)0); | |||||
3286 | int ret = 0; | |||||
3287 | glusterd_brickinfo_t *brickinfo = NULL((void*)0); | |||||
3288 | ||||||
3289 | brickinfo = mydata; | |||||
3290 | if (!brickinfo) | |||||
3291 | return 0; | |||||
3292 | ||||||
3293 | this = THIS(*__glusterfs_this_location()); | |||||
3294 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 3294, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
3295 | conf = this->private; | |||||
3296 | GF_ASSERT (conf)do { if (!(conf)) { do { do { if (0) printf ("Assertion failed: " "conf"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 3296, GF_LOG_ERROR, "Assertion failed: " "conf" ); } while (0); } } while (0); | |||||
3297 | ||||||
3298 | switch (event) { | |||||
3299 | case RPC_CLNT_CONNECT: | |||||
3300 | gf_log (this->name, GF_LOG_DEBUG, "got RPC_CLNT_CONNECT")do { do { if (0) printf ("got RPC_CLNT_CONNECT"); } while (0) ; _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 3300, GF_LOG_DEBUG, "got RPC_CLNT_CONNECT"); } while (0); | |||||
3301 | glusterd_set_brick_status (brickinfo, GF_BRICK_STARTED); | |||||
3302 | ret = default_notify (this, GF_EVENT_CHILD_UP, NULL((void*)0)); | |||||
3303 | ||||||
3304 | break; | |||||
3305 | ||||||
3306 | case RPC_CLNT_DISCONNECT: | |||||
3307 | gf_log (this->name, GF_LOG_DEBUG, "got RPC_CLNT_DISCONNECT")do { do { if (0) printf ("got RPC_CLNT_DISCONNECT"); } while ( 0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__ , 3307, GF_LOG_DEBUG, "got RPC_CLNT_DISCONNECT"); } while (0); | |||||
3308 | glusterd_set_brick_status (brickinfo, GF_BRICK_STOPPED); | |||||
3309 | break; | |||||
3310 | ||||||
3311 | default: | |||||
3312 | gf_log (this->name, GF_LOG_TRACE,do { do { if (0) printf ("got some other RPC event %d", event ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 3313, GF_LOG_TRACE, "got some other RPC event %d" , event); } while (0) | |||||
3313 | "got some other RPC event %d", event)do { do { if (0) printf ("got some other RPC event %d", event ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 3313, GF_LOG_TRACE, "got some other RPC event %d" , event); } while (0); | |||||
3314 | break; | |||||
3315 | } | |||||
3316 | ||||||
3317 | return ret; | |||||
3318 | } | |||||
3319 | ||||||
3320 | int | |||||
3321 | glusterd_brick_rpc_notify (struct rpc_clnt *rpc, void *mydata, | |||||
3322 | rpc_clnt_event_t event, void *data) | |||||
3323 | { | |||||
3324 | return glusterd_big_locked_notify (rpc, mydata, event, data, | |||||
3325 | __glusterd_brick_rpc_notify); | |||||
3326 | } | |||||
3327 | ||||||
3328 | int | |||||
3329 | __glusterd_nodesvc_rpc_notify (struct rpc_clnt *rpc, void *mydata, | |||||
3330 | rpc_clnt_event_t event, void *data) | |||||
3331 | { | |||||
3332 | xlator_t *this = NULL((void*)0); | |||||
3333 | glusterd_conf_t *conf = NULL((void*)0); | |||||
3334 | char *server = NULL((void*)0); | |||||
3335 | int ret = 0; | |||||
3336 | ||||||
3337 | this = THIS(*__glusterfs_this_location()); | |||||
3338 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 3338, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
3339 | conf = this->private; | |||||
3340 | GF_ASSERT (conf)do { if (!(conf)) { do { do { if (0) printf ("Assertion failed: " "conf"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 3340, GF_LOG_ERROR, "Assertion failed: " "conf" ); } while (0); } } while (0); | |||||
3341 | ||||||
3342 | server = mydata; | |||||
3343 | if (!server) | |||||
3344 | return 0; | |||||
3345 | ||||||
3346 | switch (event) { | |||||
3347 | case RPC_CLNT_CONNECT: | |||||
3348 | gf_log (this->name, GF_LOG_DEBUG, "got RPC_CLNT_CONNECT")do { do { if (0) printf ("got RPC_CLNT_CONNECT"); } while (0) ; _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 3348, GF_LOG_DEBUG, "got RPC_CLNT_CONNECT"); } while (0); | |||||
3349 | (void) glusterd_nodesvc_set_online_status (server, _gf_true); | |||||
3350 | ret = default_notify (this, GF_EVENT_CHILD_UP, NULL((void*)0)); | |||||
3351 | ||||||
3352 | break; | |||||
3353 | ||||||
3354 | case RPC_CLNT_DISCONNECT: | |||||
3355 | gf_log (this->name, GF_LOG_DEBUG, "got RPC_CLNT_DISCONNECT")do { do { if (0) printf ("got RPC_CLNT_DISCONNECT"); } while ( 0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__ , 3355, GF_LOG_DEBUG, "got RPC_CLNT_DISCONNECT"); } while (0); | |||||
3356 | (void) glusterd_nodesvc_set_online_status (server, _gf_false); | |||||
3357 | break; | |||||
3358 | ||||||
3359 | default: | |||||
3360 | gf_log (this->name, GF_LOG_TRACE,do { do { if (0) printf ("got some other RPC event %d", event ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 3361, GF_LOG_TRACE, "got some other RPC event %d" , event); } while (0) | |||||
3361 | "got some other RPC event %d", event)do { do { if (0) printf ("got some other RPC event %d", event ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 3361, GF_LOG_TRACE, "got some other RPC event %d" , event); } while (0); | |||||
3362 | break; | |||||
3363 | } | |||||
3364 | ||||||
3365 | return ret; | |||||
3366 | } | |||||
3367 | ||||||
3368 | int | |||||
3369 | glusterd_nodesvc_rpc_notify (struct rpc_clnt *rpc, void *mydata, | |||||
3370 | rpc_clnt_event_t event, void *data) | |||||
3371 | { | |||||
3372 | return glusterd_big_locked_notify (rpc, mydata, event, data, | |||||
3373 | __glusterd_nodesvc_rpc_notify); | |||||
3374 | } | |||||
3375 | ||||||
3376 | int | |||||
3377 | glusterd_friend_remove_notify (glusterd_peerctx_t *peerctx) | |||||
3378 | { | |||||
3379 | int ret = -1; | |||||
3380 | glusterd_friend_sm_event_t *new_event = NULL((void*)0); | |||||
3381 | glusterd_peerinfo_t *peerinfo = peerctx->peerinfo; | |||||
3382 | rpcsvc_request_t *req = peerctx->args.req; | |||||
3383 | char *errstr = peerctx->errstr; | |||||
3384 | ||||||
3385 | GF_ASSERT (peerctx)do { if (!(peerctx)) { do { do { if (0) printf ("Assertion failed: " "peerctx"); } while (0); _gf_log_callingfn ("", "glusterd-handler.c" , __FUNCTION__, 3385, GF_LOG_ERROR, "Assertion failed: " "peerctx" ); } while (0); } } while (0); | |||||
3386 | ||||||
3387 | peerinfo = peerctx->peerinfo; | |||||
3388 | req = peerctx->args.req; | |||||
3389 | errstr = peerctx->errstr; | |||||
3390 | ||||||
3391 | ret = glusterd_friend_sm_new_event (GD_FRIEND_EVENT_REMOVE_FRIEND, | |||||
3392 | &new_event); | |||||
3393 | if (!ret) { | |||||
3394 | if (!req) { | |||||
3395 | gf_log (THIS->name, GF_LOG_WARNING,do { do { if (0) printf ("Unable to find the request for responding " "to User (%s)", peerinfo->hostname); } while (0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-handler.c" , __FUNCTION__, 3397, GF_LOG_WARNING, "Unable to find the request for responding " "to User (%s)", peerinfo->hostname); } while (0) | |||||
3396 | "Unable to find the request for responding "do { do { if (0) printf ("Unable to find the request for responding " "to User (%s)", peerinfo->hostname); } while (0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-handler.c" , __FUNCTION__, 3397, GF_LOG_WARNING, "Unable to find the request for responding " "to User (%s)", peerinfo->hostname); } while (0) | |||||
3397 | "to User (%s)", peerinfo->hostname)do { do { if (0) printf ("Unable to find the request for responding " "to User (%s)", peerinfo->hostname); } while (0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-handler.c" , __FUNCTION__, 3397, GF_LOG_WARNING, "Unable to find the request for responding " "to User (%s)", peerinfo->hostname); } while (0); | |||||
3398 | goto out; | |||||
3399 | } | |||||
3400 | ||||||
3401 | glusterd_xfer_cli_probe_resp (req, -1, ENOTCONN107, errstr, | |||||
3402 | peerinfo->hostname, peerinfo->port); | |||||
3403 | ||||||
3404 | new_event->peerinfo = peerinfo; | |||||
3405 | ret = glusterd_friend_sm_inject_event (new_event); | |||||
3406 | ||||||
3407 | } else { | |||||
3408 | gf_log ("glusterd", GF_LOG_ERROR,do { do { if (0) printf ("Unable to create event for removing peer %s" , peerinfo->hostname); } while (0); _gf_log ("glusterd", "glusterd-handler.c" , __FUNCTION__, 3410, GF_LOG_ERROR, "Unable to create event for removing peer %s" , peerinfo->hostname); } while (0) | |||||
3409 | "Unable to create event for removing peer %s",do { do { if (0) printf ("Unable to create event for removing peer %s" , peerinfo->hostname); } while (0); _gf_log ("glusterd", "glusterd-handler.c" , __FUNCTION__, 3410, GF_LOG_ERROR, "Unable to create event for removing peer %s" , peerinfo->hostname); } while (0) | |||||
3410 | peerinfo->hostname)do { do { if (0) printf ("Unable to create event for removing peer %s" , peerinfo->hostname); } while (0); _gf_log ("glusterd", "glusterd-handler.c" , __FUNCTION__, 3410, GF_LOG_ERROR, "Unable to create event for removing peer %s" , peerinfo->hostname); } while (0); | |||||
3411 | } | |||||
3412 | ||||||
3413 | out: | |||||
3414 | return ret; | |||||
3415 | } | |||||
3416 | ||||||
3417 | int | |||||
3418 | __glusterd_peer_rpc_notify (struct rpc_clnt *rpc, void *mydata, | |||||
3419 | rpc_clnt_event_t event, void *data) | |||||
3420 | { | |||||
3421 | xlator_t *this = NULL((void*)0); | |||||
3422 | glusterd_conf_t *conf = NULL((void*)0); | |||||
3423 | int ret = 0; | |||||
3424 | glusterd_peerinfo_t *peerinfo = NULL((void*)0); | |||||
3425 | glusterd_peerctx_t *peerctx = NULL((void*)0); | |||||
3426 | gf_boolean_t quorum_action = _gf_false; | |||||
3427 | ||||||
3428 | peerctx = mydata; | |||||
3429 | if (!peerctx) | |||||
3430 | return 0; | |||||
3431 | ||||||
3432 | peerinfo = peerctx->peerinfo; | |||||
3433 | this = THIS(*__glusterfs_this_location()); | |||||
3434 | conf = this->private; | |||||
3435 | ||||||
3436 | switch (event) { | |||||
3437 | case RPC_CLNT_CONNECT: | |||||
3438 | { | |||||
3439 | gf_log (this->name, GF_LOG_DEBUG, "got RPC_CLNT_CONNECT")do { do { if (0) printf ("got RPC_CLNT_CONNECT"); } while (0) ; _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 3439, GF_LOG_DEBUG, "got RPC_CLNT_CONNECT"); } while (0); | |||||
3440 | peerinfo->connected = 1; | |||||
3441 | peerinfo->quorum_action = _gf_true; | |||||
3442 | ||||||
3443 | ret = glusterd_peer_dump_version (this, rpc, peerctx); | |||||
3444 | if (ret) | |||||
3445 | gf_log ("", GF_LOG_ERROR, "glusterd handshake failed")do { do { if (0) printf ("glusterd handshake failed"); } while (0); _gf_log ("", "glusterd-handler.c", __FUNCTION__, 3445, GF_LOG_ERROR , "glusterd handshake failed"); } while (0); | |||||
3446 | break; | |||||
3447 | } | |||||
3448 | ||||||
3449 | case RPC_CLNT_DISCONNECT: | |||||
3450 | { | |||||
3451 | gf_log (this->name, GF_LOG_DEBUG, "got RPC_CLNT_DISCONNECT %d",do { do { if (0) printf ("got RPC_CLNT_DISCONNECT %d", peerinfo ->state.state); } while (0); _gf_log (this->name, "glusterd-handler.c" , __FUNCTION__, 3452, GF_LOG_DEBUG, "got RPC_CLNT_DISCONNECT %d" , peerinfo->state.state); } while (0) | |||||
3452 | peerinfo->state.state)do { do { if (0) printf ("got RPC_CLNT_DISCONNECT %d", peerinfo ->state.state); } while (0); _gf_log (this->name, "glusterd-handler.c" , __FUNCTION__, 3452, GF_LOG_DEBUG, "got RPC_CLNT_DISCONNECT %d" , peerinfo->state.state); } while (0); | |||||
3453 | ||||||
3454 | if ((peerinfo->quorum_contrib != QUORUM_DOWN) && | |||||
3455 | (peerinfo->state.state == GD_FRIEND_STATE_BEFRIENDED)) { | |||||
3456 | peerinfo->quorum_contrib = QUORUM_DOWN; | |||||
3457 | quorum_action = _gf_true; | |||||
3458 | peerinfo->quorum_action = _gf_false; | |||||
3459 | } | |||||
3460 | ||||||
3461 | /* Remove peer if it is not a friend and connection/handshake | |||||
3462 | * fails, and notify cli. Happens only during probe. | |||||
3463 | */ | |||||
3464 | if (peerinfo->state.state == GD_FRIEND_STATE_DEFAULT) { | |||||
3465 | glusterd_friend_remove_notify (peerctx); | |||||
3466 | goto out; | |||||
3467 | } | |||||
3468 | ||||||
3469 | peerinfo->connected = 0; | |||||
3470 | break; | |||||
3471 | } | |||||
3472 | default: | |||||
3473 | gf_log (this->name, GF_LOG_TRACE,do { do { if (0) printf ("got some other RPC event %d", event ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 3474, GF_LOG_TRACE, "got some other RPC event %d" , event); } while (0) | |||||
3474 | "got some other RPC event %d", event)do { do { if (0) printf ("got some other RPC event %d", event ); } while (0); _gf_log (this->name, "glusterd-handler.c", __FUNCTION__, 3474, GF_LOG_TRACE, "got some other RPC event %d" , event); } while (0); | |||||
3475 | ret = 0; | |||||
3476 | break; | |||||
3477 | } | |||||
3478 | ||||||
3479 | out: | |||||
3480 | glusterd_friend_sm (); | |||||
3481 | glusterd_op_sm (); | |||||
3482 | if (quorum_action) | |||||
3483 | glusterd_do_quorum_action (); | |||||
3484 | return ret; | |||||
3485 | } | |||||
3486 | ||||||
3487 | int | |||||
3488 | glusterd_peer_rpc_notify (struct rpc_clnt *rpc, void *mydata, | |||||
3489 | rpc_clnt_event_t event, void *data) | |||||
3490 | { | |||||
3491 | return glusterd_big_locked_notify (rpc, mydata, event, data, | |||||
3492 | __glusterd_peer_rpc_notify); | |||||
3493 | } | |||||
3494 | ||||||
3495 | int | |||||
3496 | glusterd_null (rpcsvc_request_t *req) | |||||
3497 | { | |||||
3498 | ||||||
3499 | return 0; | |||||
3500 | } | |||||
3501 | ||||||
3502 | rpcsvc_actor_t gd_svc_mgmt_actors[] = { | |||||
3503 | [GLUSTERD_MGMT_NULL] = { "NULL", GLUSTERD_MGMT_NULL, glusterd_null, NULL((void*)0), 0}, | |||||
3504 | [GLUSTERD_MGMT_CLUSTER_LOCK] = { "CLUSTER_LOCK", GLUSTERD_MGMT_CLUSTER_LOCK, glusterd_handle_cluster_lock, NULL((void*)0), 0}, | |||||
3505 | [GLUSTERD_MGMT_CLUSTER_UNLOCK] = { "CLUSTER_UNLOCK", GLUSTERD_MGMT_CLUSTER_UNLOCK, glusterd_handle_cluster_unlock, NULL((void*)0), 0}, | |||||
3506 | [GLUSTERD_MGMT_STAGE_OP] = { "STAGE_OP", GLUSTERD_MGMT_STAGE_OP, glusterd_handle_stage_op, NULL((void*)0), 0}, | |||||
3507 | [GLUSTERD_MGMT_COMMIT_OP] = { "COMMIT_OP", GLUSTERD_MGMT_COMMIT_OP, glusterd_handle_commit_op, NULL((void*)0), 0}, | |||||
3508 | }; | |||||
3509 | ||||||
3510 | struct rpcsvc_program gd_svc_mgmt_prog = { | |||||
3511 | .progname = "GlusterD svc mgmt", | |||||
3512 | .prognum = GD_MGMT_PROGRAM1238433, | |||||
3513 | .progver = GD_MGMT_VERSION2, | |||||
3514 | .numactors = GLUSTERD_MGMT_MAXVALUE, | |||||
3515 | .actors = gd_svc_mgmt_actors, | |||||
3516 | .synctask = _gf_true, | |||||
3517 | }; | |||||
3518 | ||||||
3519 | rpcsvc_actor_t gd_svc_peer_actors[] = { | |||||
3520 | [GLUSTERD_FRIEND_NULL] = { "NULL", GLUSTERD_MGMT_NULL, glusterd_null, NULL((void*)0), 0}, | |||||
3521 | [GLUSTERD_PROBE_QUERY] = { "PROBE_QUERY", GLUSTERD_PROBE_QUERY, glusterd_handle_probe_query, NULL((void*)0), 0}, | |||||
3522 | [GLUSTERD_FRIEND_ADD] = { "FRIEND_ADD", GLUSTERD_FRIEND_ADD, glusterd_handle_incoming_friend_req, NULL((void*)0), 0}, | |||||
3523 | [GLUSTERD_FRIEND_REMOVE] = { "FRIEND_REMOVE", GLUSTERD_FRIEND_REMOVE, glusterd_handle_incoming_unfriend_req, NULL((void*)0), 0}, | |||||
3524 | [GLUSTERD_FRIEND_UPDATE] = { "FRIEND_UPDATE", GLUSTERD_FRIEND_UPDATE, glusterd_handle_friend_update, NULL((void*)0), 0}, | |||||
3525 | }; | |||||
3526 | ||||||
3527 | struct rpcsvc_program gd_svc_peer_prog = { | |||||
3528 | .progname = "GlusterD svc peer", | |||||
3529 | .prognum = GD_FRIEND_PROGRAM1238437, | |||||
3530 | .progver = GD_FRIEND_VERSION2, | |||||
3531 | .numactors = GLUSTERD_FRIEND_MAXVALUE, | |||||
3532 | .actors = gd_svc_peer_actors, | |||||
3533 | .synctask = _gf_false, | |||||
3534 | }; | |||||
3535 | ||||||
3536 | ||||||
3537 | ||||||
3538 | rpcsvc_actor_t gd_svc_cli_actors[] = { | |||||
3539 | [GLUSTER_CLI_PROBE] = { "CLI_PROBE", GLUSTER_CLI_PROBE, glusterd_handle_cli_probe, NULL((void*)0), 0}, | |||||
3540 | [GLUSTER_CLI_CREATE_VOLUME] = { "CLI_CREATE_VOLUME", GLUSTER_CLI_CREATE_VOLUME, glusterd_handle_create_volume, NULL((void*)0), 0}, | |||||
3541 | [GLUSTER_CLI_DEFRAG_VOLUME] = { "CLI_DEFRAG_VOLUME", GLUSTER_CLI_DEFRAG_VOLUME, glusterd_handle_defrag_volume, NULL((void*)0), 0}, | |||||
3542 | [GLUSTER_CLI_DEPROBE] = { "FRIEND_REMOVE", GLUSTER_CLI_DEPROBE, glusterd_handle_cli_deprobe, NULL((void*)0), 0}, | |||||
3543 | [GLUSTER_CLI_LIST_FRIENDS] = { "LIST_FRIENDS", GLUSTER_CLI_LIST_FRIENDS, glusterd_handle_cli_list_friends, NULL((void*)0), 0}, | |||||
3544 | [GLUSTER_CLI_UUID_RESET] = { "UUID_RESET", GLUSTER_CLI_UUID_RESET, glusterd_handle_cli_uuid_reset, NULL((void*)0), 0}, | |||||
3545 | [GLUSTER_CLI_START_VOLUME] = { "START_VOLUME", GLUSTER_CLI_START_VOLUME, glusterd_handle_cli_start_volume, NULL((void*)0), 0}, | |||||
3546 | [GLUSTER_CLI_STOP_VOLUME] = { "STOP_VOLUME", GLUSTER_CLI_STOP_VOLUME, glusterd_handle_cli_stop_volume, NULL((void*)0), 0}, | |||||
3547 | [GLUSTER_CLI_DELETE_VOLUME] = { "DELETE_VOLUME", GLUSTER_CLI_DELETE_VOLUME, glusterd_handle_cli_delete_volume, NULL((void*)0), 0}, | |||||
3548 | [GLUSTER_CLI_GET_VOLUME] = { "GET_VOLUME", GLUSTER_CLI_GET_VOLUME, glusterd_handle_cli_get_volume, NULL((void*)0), 0}, | |||||
3549 | [GLUSTER_CLI_ADD_BRICK] = { "ADD_BRICK", GLUSTER_CLI_ADD_BRICK, glusterd_handle_add_brick, NULL((void*)0), 0}, | |||||
3550 | [GLUSTER_CLI_REPLACE_BRICK] = { "REPLACE_BRICK", GLUSTER_CLI_REPLACE_BRICK, glusterd_handle_replace_brick, NULL((void*)0), 0}, | |||||
3551 | [GLUSTER_CLI_REMOVE_BRICK] = { "REMOVE_BRICK", GLUSTER_CLI_REMOVE_BRICK, glusterd_handle_remove_brick, NULL((void*)0), 0}, | |||||
3552 | [GLUSTER_CLI_LOG_ROTATE] = { "LOG FILENAME", GLUSTER_CLI_LOG_ROTATE, glusterd_handle_log_rotate, NULL((void*)0), 0}, | |||||
3553 | [GLUSTER_CLI_SET_VOLUME] = { "SET_VOLUME", GLUSTER_CLI_SET_VOLUME, glusterd_handle_set_volume, NULL((void*)0), 0}, | |||||
3554 | [GLUSTER_CLI_SYNC_VOLUME] = { "SYNC_VOLUME", GLUSTER_CLI_SYNC_VOLUME, glusterd_handle_sync_volume, NULL((void*)0), 0}, | |||||
3555 | [GLUSTER_CLI_RESET_VOLUME] = { "RESET_VOLUME", GLUSTER_CLI_RESET_VOLUME, glusterd_handle_reset_volume, NULL((void*)0), 0}, | |||||
3556 | [GLUSTER_CLI_FSM_LOG] = { "FSM_LOG", GLUSTER_CLI_FSM_LOG, glusterd_handle_fsm_log, NULL((void*)0), 0}, | |||||
3557 | [GLUSTER_CLI_GSYNC_SET] = { "GSYNC_SET", GLUSTER_CLI_GSYNC_SET, glusterd_handle_gsync_set, NULL((void*)0), 0}, | |||||
3558 | [GLUSTER_CLI_PROFILE_VOLUME] = { "STATS_VOLUME", GLUSTER_CLI_PROFILE_VOLUME, glusterd_handle_cli_profile_volume, NULL((void*)0), 0}, | |||||
3559 | [GLUSTER_CLI_QUOTA] = { "QUOTA", GLUSTER_CLI_QUOTA, glusterd_handle_quota, NULL((void*)0), 0}, | |||||
3560 | [GLUSTER_CLI_GETWD] = { "GETWD", GLUSTER_CLI_GETWD, glusterd_handle_getwd, NULL((void*)0), 1}, | |||||
3561 | [GLUSTER_CLI_STATUS_VOLUME] = {"STATUS_VOLUME", GLUSTER_CLI_STATUS_VOLUME, glusterd_handle_status_volume, NULL((void*)0), 0}, | |||||
3562 | [GLUSTER_CLI_MOUNT] = { "MOUNT", GLUSTER_CLI_MOUNT, glusterd_handle_mount, NULL((void*)0), 1}, | |||||
3563 | [GLUSTER_CLI_UMOUNT] = { "UMOUNT", GLUSTER_CLI_UMOUNT, glusterd_handle_umount, NULL((void*)0), 1}, | |||||
3564 | [GLUSTER_CLI_HEAL_VOLUME] = { "HEAL_VOLUME", GLUSTER_CLI_HEAL_VOLUME, glusterd_handle_cli_heal_volume, NULL((void*)0), 0}, | |||||
3565 | [GLUSTER_CLI_STATEDUMP_VOLUME] = {"STATEDUMP_VOLUME", GLUSTER_CLI_STATEDUMP_VOLUME, glusterd_handle_cli_statedump_volume, NULL((void*)0), 0}, | |||||
3566 | [GLUSTER_CLI_LIST_VOLUME] = {"LIST_VOLUME", GLUSTER_CLI_LIST_VOLUME, glusterd_handle_cli_list_volume, NULL((void*)0), 0}, | |||||
3567 | [GLUSTER_CLI_CLRLOCKS_VOLUME] = {"CLEARLOCKS_VOLUME", GLUSTER_CLI_CLRLOCKS_VOLUME, glusterd_handle_cli_clearlocks_volume, NULL((void*)0), 0}, | |||||
3568 | #ifdef HAVE_BD_XLATOR | |||||
3569 | [GLUSTER_CLI_BD_OP] = {"BD_OP", GLUSTER_CLI_BD_OP, glusterd_handle_cli_bd_op, NULL((void*)0), 0}, | |||||
3570 | #endif | |||||
3571 | }; | |||||
3572 | ||||||
3573 | struct rpcsvc_program gd_svc_cli_prog = { | |||||
3574 | .progname = "GlusterD svc cli", | |||||
3575 | .prognum = GLUSTER_CLI_PROGRAM1238463, | |||||
3576 | .progver = GLUSTER_CLI_VERSION2, | |||||
3577 | .numactors = GLUSTER_CLI_MAXVALUE, | |||||
3578 | .actors = gd_svc_cli_actors, | |||||
3579 | .synctask = _gf_true, | |||||
3580 | }; |