File: | xlators/mgmt/glusterd/src/glusterd-geo-rep.c |
Location: | line 842, column 29 |
Description: | Access to field 'gsync_slaves' results in a dereference of a null pointer (loaded from variable 'vol') |
1 | /* | |||
2 | Copyright (c) 2011-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 | ||||
15 | #include "common-utils.h" | |||
16 | #include "cli1-xdr.h" | |||
17 | #include "xdr-generic.h" | |||
18 | #include "glusterd.h" | |||
19 | #include "glusterd-op-sm.h" | |||
20 | #include "glusterd-store.h" | |||
21 | #include "glusterd-utils.h" | |||
22 | #include "glusterd-volgen.h" | |||
23 | #include "run.h" | |||
24 | #include "syscall.h" | |||
25 | ||||
26 | #include <signal.h> | |||
27 | ||||
28 | static char *gsync_reserved_opts[] = { | |||
29 | "gluster-command-dir", | |||
30 | "pid-file", | |||
31 | "remote-gsyncd" | |||
32 | "state-file", | |||
33 | "session-owner", | |||
34 | "state-socket-unencoded", | |||
35 | "socketdir", | |||
36 | NULL((void*)0) | |||
37 | }; | |||
38 | ||||
39 | int | |||
40 | __glusterd_handle_gsync_set (rpcsvc_request_t *req) | |||
41 | { | |||
42 | int32_t ret = 0; | |||
43 | dict_t *dict = NULL((void*)0); | |||
44 | gf_cli_req cli_req = {{0},}; | |||
45 | glusterd_op_t cli_op = GD_OP_GSYNC_SET; | |||
46 | char *master = NULL((void*)0); | |||
47 | char *slave = NULL((void*)0); | |||
48 | char operation[256] = {0,}; | |||
49 | int type = 0; | |||
50 | glusterd_conf_t *priv = NULL((void*)0); | |||
51 | char *host_uuid = NULL((void*)0); | |||
52 | char err_str[2048] = {0,}; | |||
53 | xlator_t *this = NULL((void*)0); | |||
54 | ||||
55 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 55, GF_LOG_ERROR, "Assertion failed: " "req") ; } while (0); } } while (0); | |||
56 | ||||
57 | this = THIS(*__glusterfs_this_location()); | |||
58 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 58, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||
59 | priv = this->private; | |||
60 | GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: " "priv"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 60, GF_LOG_ERROR, "Assertion failed: " "priv" ); } while (0); } } while (0); | |||
61 | ||||
62 | ret = xdr_to_generic (req->msg[0], &cli_req, | |||
63 | (xdrproc_t)xdr_gf_cli_req); | |||
64 | if (ret < 0) { | |||
65 | req->rpc_err = GARBAGE_ARGS; | |||
66 | goto out; | |||
67 | } | |||
68 | ||||
69 | if (cli_req.dict.dict_len) { | |||
70 | dict = dict_new (); | |||
71 | if (!dict) | |||
72 | goto out; | |||
73 | ||||
74 | ret = dict_unserialize (cli_req.dict.dict_val, | |||
75 | cli_req.dict.dict_len, | |||
76 | &dict); | |||
77 | if (ret < 0) { | |||
78 | 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-geo-rep.c", __FUNCTION__, 79, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0) | |||
79 | "unserialize req-buffer to dictionary")do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log (this->name, "glusterd-geo-rep.c", __FUNCTION__, 79, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0); | |||
80 | snprintf (err_str, sizeof (err_str), "Unable to decode " | |||
81 | "the command"); | |||
82 | goto out; | |||
83 | } else { | |||
84 | dict->extra_stdfree = cli_req.dict.dict_val; | |||
85 | } | |||
86 | ||||
87 | host_uuid = gf_strdup (uuid_utoa(MY_UUID(__glusterd_uuid()))); | |||
88 | if (host_uuid == NULL((void*)0)) { | |||
89 | snprintf (err_str, sizeof (err_str), "Failed to get " | |||
90 | "the uuid of local glusterd"); | |||
91 | ret = -1; | |||
92 | goto out; | |||
93 | } | |||
94 | ret = dict_set_dynstr (dict, "host-uuid", host_uuid); | |||
95 | if (ret) | |||
96 | goto out; | |||
97 | ||||
98 | } | |||
99 | ||||
100 | ret = dict_get_str (dict, "master", &master); | |||
101 | if (ret < 0) { | |||
102 | gf_log (this->name, GF_LOG_INFO, "master not found, while "do { do { if (0) printf ("master not found, while " "handling" "geo-replication"" options"); } while (0); _gf_log (this-> name, "glusterd-geo-rep.c", __FUNCTION__, 103, GF_LOG_INFO, "master not found, while " "handling""geo-replication"" options"); } while (0) | |||
103 | "handling"GEOREP" options")do { do { if (0) printf ("master not found, while " "handling" "geo-replication"" options"); } while (0); _gf_log (this-> name, "glusterd-geo-rep.c", __FUNCTION__, 103, GF_LOG_INFO, "master not found, while " "handling""geo-replication"" options"); } while (0); | |||
104 | master = "(No Master)"; | |||
105 | } | |||
106 | ||||
107 | ret = dict_get_str (dict, "slave", &slave); | |||
108 | if (ret < 0) { | |||
109 | gf_log (this->name, GF_LOG_INFO, "slave not not found, while"do { do { if (0) printf ("slave not not found, while" "handling " "geo-replication"" options"); } while (0); _gf_log (this-> name, "glusterd-geo-rep.c", __FUNCTION__, 110, GF_LOG_INFO, "slave not not found, while" "handling ""geo-replication"" options"); } while (0) | |||
110 | "handling "GEOREP" options")do { do { if (0) printf ("slave not not found, while" "handling " "geo-replication"" options"); } while (0); _gf_log (this-> name, "glusterd-geo-rep.c", __FUNCTION__, 110, GF_LOG_INFO, "slave not not found, while" "handling ""geo-replication"" options"); } while (0); | |||
111 | slave = "(No Slave)"; | |||
112 | } | |||
113 | ||||
114 | ret = dict_get_int32 (dict, "type", &type); | |||
115 | if (ret < 0) { | |||
116 | snprintf (err_str, sizeof (err_str), "Command type not found " | |||
117 | "while handling "GEOREP"geo-replication"" options"); | |||
118 | 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-geo-rep.c", __FUNCTION__, 118, GF_LOG_ERROR , "%s", err_str); } while (0); | |||
119 | goto out; | |||
120 | } | |||
121 | ||||
122 | switch (type) { | |||
123 | ||||
124 | case GF_GSYNC_OPTION_TYPE_START: | |||
125 | strncpy (operation, "start", sizeof (operation)); | |||
126 | break; | |||
127 | ||||
128 | case GF_GSYNC_OPTION_TYPE_STOP: | |||
129 | strncpy (operation, "stop", sizeof (operation)); | |||
130 | break; | |||
131 | ||||
132 | case GF_GSYNC_OPTION_TYPE_CONFIG: | |||
133 | strncpy (operation, "config", sizeof (operation)); | |||
134 | break; | |||
135 | ||||
136 | case GF_GSYNC_OPTION_TYPE_STATUS: | |||
137 | strncpy (operation, "status", sizeof (operation)); | |||
138 | break; | |||
139 | case GF_GSYNC_OPTION_TYPE_ROTATE: | |||
140 | strncpy (operation, "rotate", sizeof(operation)); | |||
141 | break; | |||
142 | } | |||
143 | ||||
144 | ret = glusterd_op_begin_synctask (req, GD_OP_GSYNC_SET, dict); | |||
145 | ||||
146 | out: | |||
147 | if (ret) { | |||
148 | if (err_str[0] == '\0') | |||
149 | snprintf (err_str, sizeof (err_str), | |||
150 | "Operation failed"); | |||
151 | ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, | |||
152 | dict, err_str); | |||
153 | } | |||
154 | return ret; | |||
155 | } | |||
156 | ||||
157 | ||||
158 | int | |||
159 | glusterd_handle_gsync_set (rpcsvc_request_t *req) | |||
160 | { | |||
161 | return glusterd_big_locked_handler (req, __glusterd_handle_gsync_set); | |||
162 | } | |||
163 | ||||
164 | /***** | |||
165 | * | |||
166 | * glusterd_urltransform* internal API | |||
167 | * | |||
168 | *****/ | |||
169 | ||||
170 | static void | |||
171 | glusterd_urltransform_init (runner_t *runner, const char *transname) | |||
172 | { | |||
173 | runinit (runner); | |||
174 | runner_add_arg (runner, GSYNCD_PREFIX"/usr/local/libexec/glusterfs""/gsyncd"); | |||
175 | runner_argprintf (runner, "--%s-url", transname); | |||
176 | } | |||
177 | ||||
178 | static void | |||
179 | glusterd_urltransform_add (runner_t *runner, const char *url) | |||
180 | { | |||
181 | runner_add_arg (runner, url); | |||
182 | } | |||
183 | ||||
184 | static int | |||
185 | _glusterd_urltransform_add_iter (dict_t *dict, char *key, data_t *value, void *data) | |||
186 | { | |||
187 | runner_t *runner = (runner_t *)data; | |||
188 | char *slave = NULL((void*)0); | |||
189 | ||||
190 | slave = strchr (value->data, ':'); | |||
191 | GF_ASSERT (slave)do { if (!(slave)) { do { do { if (0) printf ("Assertion failed: " "slave"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 191, GF_LOG_ERROR, "Assertion failed: " "slave" ); } while (0); } } while (0); | |||
192 | slave++; | |||
193 | runner_add_arg (runner, slave); | |||
194 | ||||
195 | return 0; | |||
196 | } | |||
197 | ||||
198 | static void | |||
199 | glusterd_urltransform_free (char **linearr, unsigned n) | |||
200 | { | |||
201 | int i = 0; | |||
202 | ||||
203 | for (; i < n; i++) | |||
204 | GF_FREE (linearr[i])__gf_free (linearr[i]); | |||
205 | ||||
206 | GF_FREE (linearr)__gf_free (linearr); | |||
207 | } | |||
208 | ||||
209 | static int | |||
210 | glusterd_urltransform (runner_t *runner, char ***linearrp) | |||
211 | { | |||
212 | char **linearr = NULL((void*)0); | |||
213 | char *line = NULL((void*)0); | |||
214 | unsigned arr_len = 32; | |||
215 | unsigned arr_idx = 0; | |||
216 | gf_boolean_t error = _gf_false; | |||
217 | ||||
218 | linearr = GF_CALLOC (arr_len, sizeof (char *), gf_gld_mt_linearr)__gf_calloc (arr_len, sizeof (char *), gf_gld_mt_linearr); | |||
219 | if (!linearr) { | |||
220 | error = _gf_true; | |||
221 | goto out; | |||
222 | } | |||
223 | ||||
224 | runner_redir (runner, STDOUT_FILENO1, RUN_PIPE-1); | |||
225 | if (runner_start (runner) != 0) { | |||
226 | gf_log ("", GF_LOG_ERROR, "spawning child failed")do { do { if (0) printf ("spawning child failed"); } while (0 ); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 226, GF_LOG_ERROR , "spawning child failed"); } while (0); | |||
227 | ||||
228 | error = _gf_true; | |||
229 | goto out; | |||
230 | } | |||
231 | ||||
232 | arr_idx = 0; | |||
233 | for (;;) { | |||
234 | size_t len; | |||
235 | line = GF_MALLOC (1024, gf_gld_mt_linebuf)__gf_malloc (1024, gf_gld_mt_linebuf); | |||
236 | if (!line) { | |||
237 | error = _gf_true; | |||
238 | goto out; | |||
239 | } | |||
240 | ||||
241 | if (fgets (line, 1024, runner_chio (runner, STDOUT_FILENO1)) == | |||
242 | NULL((void*)0)) | |||
243 | break; | |||
244 | ||||
245 | len = strlen (line); | |||
246 | if (len == 0 || line[len - 1] != '\n') { | |||
247 | GF_FREE (line)__gf_free (line); | |||
248 | error = _gf_true; | |||
249 | goto out; | |||
250 | } | |||
251 | line[len - 1] = '\0'; | |||
252 | ||||
253 | if (arr_idx == arr_len) { | |||
254 | void *p = linearr; | |||
255 | arr_len <<= 1; | |||
256 | p = GF_REALLOC (linearr, arr_len)__gf_realloc (linearr, arr_len); | |||
257 | if (!p) { | |||
258 | GF_FREE (line)__gf_free (line); | |||
259 | error = _gf_true; | |||
260 | goto out; | |||
261 | } | |||
262 | linearr = p; | |||
263 | } | |||
264 | linearr[arr_idx] = line; | |||
265 | ||||
266 | arr_idx++; | |||
267 | } | |||
268 | ||||
269 | out: | |||
270 | ||||
271 | /* XXX chpid field is not exported by run API | |||
272 | * but runner_end() does not abort the invoked | |||
273 | * process (ie. it might block in waitpid(2)) | |||
274 | * so we resort to a manual kill a the private field | |||
275 | */ | |||
276 | if (error && runner->chpid > 0) | |||
277 | kill (runner->chpid, SIGKILL9); | |||
278 | ||||
279 | if (runner_end (runner) != 0) | |||
280 | error = _gf_true; | |||
281 | ||||
282 | if (error) { | |||
283 | gf_log ("", GF_LOG_ERROR, "reading data from child failed")do { do { if (0) printf ("reading data from child failed"); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 283 , GF_LOG_ERROR, "reading data from child failed"); } while (0 ); | |||
284 | glusterd_urltransform_free (linearr, arr_idx); | |||
285 | return -1; | |||
286 | } | |||
287 | ||||
288 | *linearrp = linearr; | |||
289 | return arr_idx; | |||
290 | } | |||
291 | ||||
292 | static int | |||
293 | glusterd_urltransform_single (const char *url, const char *transname, | |||
294 | char ***linearrp) | |||
295 | { | |||
296 | runner_t runner = {0,}; | |||
297 | ||||
298 | glusterd_urltransform_init (&runner, transname); | |||
299 | glusterd_urltransform_add (&runner, url); | |||
300 | return glusterd_urltransform (&runner, linearrp); | |||
301 | } | |||
302 | ||||
303 | ||||
304 | struct dictidxmark { | |||
305 | unsigned isrch; | |||
306 | unsigned ithis; | |||
307 | char *ikey; | |||
308 | }; | |||
309 | ||||
310 | static int | |||
311 | _dict_mark_atindex (dict_t *dict, char *key, data_t *value, void *data) | |||
312 | { | |||
313 | struct dictidxmark *dim = data; | |||
314 | ||||
315 | if (dim->isrch == dim->ithis) | |||
316 | dim->ikey = key; | |||
317 | ||||
318 | dim->ithis++; | |||
319 | return 0; | |||
320 | } | |||
321 | ||||
322 | static char * | |||
323 | dict_get_by_index (dict_t *dict, unsigned i) | |||
324 | { | |||
325 | struct dictidxmark dim = {0,}; | |||
326 | ||||
327 | dim.isrch = i; | |||
328 | dict_foreach (dict, _dict_mark_atindex, &dim); | |||
329 | ||||
330 | return dim.ikey; | |||
331 | } | |||
332 | ||||
333 | static int | |||
334 | glusterd_get_slave (glusterd_volinfo_t *vol, const char *slaveurl, char **slavekey) | |||
335 | { | |||
336 | runner_t runner = {0,}; | |||
337 | int n = 0; | |||
338 | int i = 0; | |||
339 | char **linearr = NULL((void*)0); | |||
340 | ||||
341 | glusterd_urltransform_init (&runner, "canonicalize"); | |||
342 | dict_foreach (vol->gsync_slaves, _glusterd_urltransform_add_iter, &runner); | |||
343 | glusterd_urltransform_add (&runner, slaveurl); | |||
344 | ||||
345 | n = glusterd_urltransform (&runner, &linearr); | |||
346 | if (n == -1) | |||
347 | return -2; | |||
348 | ||||
349 | for (i = 0; i < n - 1; i++) { | |||
350 | if (strcmp (linearr[i], linearr[n - 1]) == 0) | |||
351 | break; | |||
352 | } | |||
353 | glusterd_urltransform_free (linearr, i); | |||
354 | ||||
355 | if (i < n - 1) | |||
356 | *slavekey = dict_get_by_index (vol->gsync_slaves, i); | |||
357 | else | |||
358 | i = -1; | |||
359 | ||||
360 | return i; | |||
361 | } | |||
362 | ||||
363 | ||||
364 | static int | |||
365 | glusterd_query_extutil_generic (char *resbuf, size_t blen, runner_t *runner, void *data, | |||
366 | int (*fcbk)(char *resbuf, size_t blen, FILE *fp, void *data)) | |||
367 | { | |||
368 | int ret = 0; | |||
369 | ||||
370 | runner_redir (runner, STDOUT_FILENO1, RUN_PIPE-1); | |||
371 | if (runner_start (runner) != 0) { | |||
372 | gf_log ("", GF_LOG_ERROR, "spawning child failed")do { do { if (0) printf ("spawning child failed"); } while (0 ); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 372, GF_LOG_ERROR , "spawning child failed"); } while (0); | |||
373 | ||||
374 | return -1; | |||
375 | } | |||
376 | ||||
377 | ret = fcbk (resbuf, blen, runner_chio (runner, STDOUT_FILENO1), data); | |||
378 | ||||
379 | ret |= runner_end (runner); | |||
380 | if (ret) | |||
381 | gf_log ("", GF_LOG_ERROR, "reading data from child failed")do { do { if (0) printf ("reading data from child failed"); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 381 , GF_LOG_ERROR, "reading data from child failed"); } while (0 ); | |||
382 | ||||
383 | return ret ? -1 : 0; | |||
384 | } | |||
385 | ||||
386 | static int | |||
387 | _fcbk_singleline(char *resbuf, size_t blen, FILE *fp, void *data) | |||
388 | { | |||
389 | char *ptr = NULL((void*)0); | |||
390 | ||||
391 | errno(*__errno_location ()) = 0; | |||
392 | ptr = fgets (resbuf, blen, fp); | |||
393 | if (ptr) { | |||
394 | size_t len = strlen(resbuf); | |||
395 | if (len && resbuf[len-1] == '\n') | |||
396 | resbuf[len-1] = '\0'; //strip off \n | |||
397 | } | |||
398 | ||||
399 | return errno(*__errno_location ()) ? -1 : 0; | |||
400 | } | |||
401 | ||||
402 | static int | |||
403 | glusterd_query_extutil (char *resbuf, runner_t *runner) | |||
404 | { | |||
405 | return glusterd_query_extutil_generic (resbuf, PATH_MAX4096, runner, NULL((void*)0), | |||
406 | _fcbk_singleline); | |||
407 | } | |||
408 | ||||
409 | static int | |||
410 | _fcbk_conftodict (char *resbuf, size_t blen, FILE *fp, void *data) | |||
411 | { | |||
412 | char *ptr = NULL((void*)0); | |||
413 | dict_t *dict = data; | |||
414 | char *v = NULL((void*)0); | |||
415 | ||||
416 | for (;;) { | |||
417 | errno(*__errno_location ()) = 0; | |||
418 | ptr = fgets (resbuf, blen, fp); | |||
419 | if (!ptr) | |||
420 | break; | |||
421 | v = resbuf + strlen(resbuf) - 1; | |||
422 | while (isspace (*v)((*__ctype_b_loc ())[(int) ((*v))] & (unsigned short int) _ISspace)) | |||
423 | /* strip trailing space */ | |||
424 | *v-- = '\0'; | |||
425 | if (v == resbuf) | |||
426 | /* skip empty line */ | |||
427 | continue; | |||
428 | v = strchr (resbuf, ':'); | |||
429 | if (!v) | |||
430 | return -1; | |||
431 | *v++ = '\0'; | |||
432 | while (isspace (*v)((*__ctype_b_loc ())[(int) ((*v))] & (unsigned short int) _ISspace)) | |||
433 | v++; | |||
434 | v = gf_strdup (v); | |||
435 | if (!v) | |||
436 | return -1; | |||
437 | if (dict_set_dynstr (dict, resbuf, v) != 0) { | |||
438 | GF_FREE (v)__gf_free (v); | |||
439 | return -1; | |||
440 | } | |||
441 | } | |||
442 | ||||
443 | return errno(*__errno_location ()) ? -1 : 0; | |||
444 | } | |||
445 | ||||
446 | static int | |||
447 | glusterd_gsync_get_config (char *master, char *slave, char *gl_workdir, dict_t *dict) | |||
448 | { | |||
449 | /* key + value, where value must be able to accommodate a path */ | |||
450 | char resbuf[256 + PATH_MAX4096] = {0,}; | |||
451 | runner_t runner = {0,}; | |||
452 | ||||
453 | runinit (&runner); | |||
454 | runner_add_args (&runner, GSYNCD_PREFIX"/usr/local/libexec/glusterfs""/gsyncd", "-c", NULL((void*)0)); | |||
455 | runner_argprintf (&runner, "%s/"GSYNC_CONF"geo-replication""/gsyncd.conf", gl_workdir); | |||
456 | runner_argprintf (&runner, ":%s", master); | |||
457 | runner_add_args (&runner, slave, "--config-get-all", NULL((void*)0)); | |||
458 | ||||
459 | return glusterd_query_extutil_generic (resbuf, sizeof (resbuf), | |||
460 | &runner, dict, _fcbk_conftodict); | |||
461 | } | |||
462 | ||||
463 | static int | |||
464 | glusterd_gsync_get_param_file (char *prmfile, const char *param, char *master, | |||
465 | char *slave, char *gl_workdir) | |||
466 | { | |||
467 | runner_t runner = {0,}; | |||
468 | ||||
469 | runinit (&runner); | |||
470 | runner_add_args (&runner, GSYNCD_PREFIX"/usr/local/libexec/glusterfs""/gsyncd", "-c", NULL((void*)0)); | |||
471 | runner_argprintf (&runner, "%s/"GSYNC_CONF"geo-replication""/gsyncd.conf", gl_workdir); | |||
472 | runner_argprintf (&runner, ":%s", master); | |||
473 | runner_add_args (&runner, slave, "--config-get", NULL((void*)0)); | |||
474 | runner_argprintf (&runner, "%s-file", param); | |||
475 | ||||
476 | return glusterd_query_extutil (prmfile, &runner); | |||
477 | } | |||
478 | ||||
479 | static int | |||
480 | glusterd_gsync_get_session_owner (char *master, char *slave, char *session_owner, | |||
481 | char *gl_workdir) | |||
482 | { | |||
483 | runner_t runner = {0,}; | |||
484 | ||||
485 | runinit(&runner); | |||
486 | runner_add_args (&runner, GSYNCD_PREFIX"/usr/local/libexec/glusterfs""/gsyncd", "-c", NULL((void*)0)); | |||
487 | runner_argprintf (&runner, "%s/"GSYNC_CONF"geo-replication""/gsyncd.conf", gl_workdir); | |||
488 | runner_argprintf (&runner, ":%s", master); | |||
489 | runner_add_args (&runner, slave, "--config-get", "session-owner", | |||
490 | NULL((void*)0)); | |||
491 | ||||
492 | return glusterd_query_extutil (session_owner, &runner); | |||
493 | } | |||
494 | ||||
495 | /* check whether @slave is local or remote. normalized | |||
496 | * urls starting with ssh are considered to be remote | |||
497 | * @returns | |||
498 | * 1 if slave is remote | |||
499 | * 0 is slave is local | |||
500 | */ | |||
501 | static int | |||
502 | glusterd_gsync_slave_is_remote (char *slave) | |||
503 | { | |||
504 | int ret = 0; | |||
505 | char *ssh_pos = NULL((void*)0); | |||
506 | ||||
507 | ssh_pos = strstr(slave, "ssh://"); | |||
508 | if ( ssh_pos && ((ssh_pos - slave) == 0) ) | |||
509 | ret = 1; | |||
510 | ||||
511 | return ret; | |||
512 | } | |||
513 | ||||
514 | static int | |||
515 | glusterd_gsync_get_slave_log_file (char *master, char *slave, char *log_file) | |||
516 | { | |||
517 | int ret = -1; | |||
518 | runner_t runner = {0,}; | |||
519 | char uuid_str[64] = {0,}; | |||
520 | glusterd_conf_t *priv = NULL((void*)0); | |||
521 | char *gl_workdir = NULL((void*)0); | |||
522 | ||||
523 | GF_ASSERT(THIS)do { if (!((*__glusterfs_this_location()))) { do { do { if (0 ) printf ("Assertion failed: " "THIS"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c", __FUNCTION__, 523, GF_LOG_ERROR, "Assertion failed: " "THIS"); } while (0); } } while (0); | |||
524 | GF_ASSERT(THIS->private)do { if (!((*__glusterfs_this_location())->private)) { do { do { if (0) printf ("Assertion failed: " "THIS->private") ; } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c", __FUNCTION__ , 524, GF_LOG_ERROR, "Assertion failed: " "THIS->private") ; } while (0); } } while (0); | |||
525 | ||||
526 | priv = THIS(*__glusterfs_this_location())->private; | |||
527 | ||||
528 | GF_VALIDATE_OR_GOTO("gsyncd", master, out)do { if (!master) { (*__errno_location ()) = 22; do { do { if (0) printf ("invalid argument: " "master"); } while (0); _gf_log_callingfn ("gsyncd", "glusterd-geo-rep.c", __FUNCTION__, 528, GF_LOG_ERROR , "invalid argument: " "master"); } while (0); goto out; } } while (0); | |||
529 | GF_VALIDATE_OR_GOTO("gsyncd", slave, out)do { if (!slave) { (*__errno_location ()) = 22; do { do { if ( 0) printf ("invalid argument: " "slave"); } while (0); _gf_log_callingfn ("gsyncd", "glusterd-geo-rep.c", __FUNCTION__, 529, GF_LOG_ERROR , "invalid argument: " "slave"); } while (0); goto out; } } while (0); | |||
530 | ||||
531 | gl_workdir = priv->workdir; | |||
532 | ||||
533 | /* get the session owner for the master-slave session */ | |||
534 | ret = glusterd_gsync_get_session_owner (master, slave, uuid_str, | |||
535 | gl_workdir); | |||
536 | if (ret) | |||
537 | goto out; | |||
538 | ||||
539 | /* get the log file for the slave */ | |||
540 | runinit(&runner); | |||
541 | runner_add_args (&runner, GSYNCD_PREFIX"/usr/local/libexec/glusterfs""/gsyncd", "-c", NULL((void*)0)); | |||
542 | runner_argprintf (&runner, "%s/"GSYNC_CONF"geo-replication""/gsyncd.conf", gl_workdir); | |||
543 | runner_argprintf (&runner, "--session-owner=%s", uuid_str); | |||
544 | runner_add_args (&runner, slave, "--config-get", "log-file", NULL((void*)0)); | |||
545 | ||||
546 | ret = glusterd_query_extutil (log_file, &runner); | |||
547 | ||||
548 | out: | |||
549 | return ret; | |||
550 | } | |||
551 | ||||
552 | static int | |||
553 | gsyncd_getpidfile (char *master, char *slave, char *pidfile) | |||
554 | { | |||
555 | int ret = -1; | |||
556 | glusterd_conf_t *priv = NULL((void*)0); | |||
557 | ||||
558 | GF_ASSERT (THIS)do { if (!((*__glusterfs_this_location()))) { do { do { if (0 ) printf ("Assertion failed: " "THIS"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c", __FUNCTION__, 558, GF_LOG_ERROR, "Assertion failed: " "THIS"); } while (0); } } while (0); | |||
559 | GF_ASSERT (THIS->private)do { if (!((*__glusterfs_this_location())->private)) { do { do { if (0) printf ("Assertion failed: " "THIS->private") ; } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c", __FUNCTION__ , 559, GF_LOG_ERROR, "Assertion failed: " "THIS->private") ; } while (0); } } while (0); | |||
560 | ||||
561 | priv = THIS(*__glusterfs_this_location())->private; | |||
562 | ||||
563 | GF_VALIDATE_OR_GOTO ("gsync", master, out)do { if (!master) { (*__errno_location ()) = 22; do { do { if (0) printf ("invalid argument: " "master"); } while (0); _gf_log_callingfn ("gsync", "glusterd-geo-rep.c", __FUNCTION__, 563, GF_LOG_ERROR , "invalid argument: " "master"); } while (0); goto out; } } while (0); | |||
564 | GF_VALIDATE_OR_GOTO ("gsync", slave, out)do { if (!slave) { (*__errno_location ()) = 22; do { do { if ( 0) printf ("invalid argument: " "slave"); } while (0); _gf_log_callingfn ("gsync", "glusterd-geo-rep.c", __FUNCTION__, 564, GF_LOG_ERROR , "invalid argument: " "slave"); } while (0); goto out; } } while (0); | |||
565 | ||||
566 | ret = glusterd_gsync_get_param_file (pidfile, "pid", master, | |||
567 | slave, priv->workdir); | |||
568 | if (ret == -1) { | |||
569 | ret = -2; | |||
570 | gf_log ("", GF_LOG_WARNING, "failed to create the pidfile string")do { do { if (0) printf ("failed to create the pidfile string" ); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__ , 570, GF_LOG_WARNING, "failed to create the pidfile string") ; } while (0); | |||
571 | goto out; | |||
572 | } | |||
573 | ||||
574 | ret = open (pidfile, O_RDWR02); | |||
575 | ||||
576 | out: | |||
577 | return ret; | |||
578 | } | |||
579 | ||||
580 | static int | |||
581 | glusterd_gsyncd_getlogfile (char *master, char *slave, char *log_file) | |||
582 | { | |||
583 | int ret = -1; | |||
584 | glusterd_conf_t *priv = NULL((void*)0); | |||
585 | ||||
586 | GF_ASSERT (THIS)do { if (!((*__glusterfs_this_location()))) { do { do { if (0 ) printf ("Assertion failed: " "THIS"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c", __FUNCTION__, 586, GF_LOG_ERROR, "Assertion failed: " "THIS"); } while (0); } } while (0); | |||
587 | GF_ASSERT (THIS->private)do { if (!((*__glusterfs_this_location())->private)) { do { do { if (0) printf ("Assertion failed: " "THIS->private") ; } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c", __FUNCTION__ , 587, GF_LOG_ERROR, "Assertion failed: " "THIS->private") ; } while (0); } } while (0); | |||
588 | ||||
589 | priv = THIS(*__glusterfs_this_location())->private; | |||
590 | ||||
591 | GF_VALIDATE_OR_GOTO ("gsync", master, out)do { if (!master) { (*__errno_location ()) = 22; do { do { if (0) printf ("invalid argument: " "master"); } while (0); _gf_log_callingfn ("gsync", "glusterd-geo-rep.c", __FUNCTION__, 591, GF_LOG_ERROR , "invalid argument: " "master"); } while (0); goto out; } } while (0); | |||
592 | GF_VALIDATE_OR_GOTO ("gsync", slave, out)do { if (!slave) { (*__errno_location ()) = 22; do { do { if ( 0) printf ("invalid argument: " "slave"); } while (0); _gf_log_callingfn ("gsync", "glusterd-geo-rep.c", __FUNCTION__, 592, GF_LOG_ERROR , "invalid argument: " "slave"); } while (0); goto out; } } while (0); | |||
593 | ||||
594 | ret = glusterd_gsync_get_param_file (log_file, "log", master, | |||
595 | slave, priv->workdir); | |||
596 | if (ret == -1) { | |||
597 | ret = -2; | |||
598 | gf_log ("", GF_LOG_WARNING, "failed to gsyncd logfile")do { do { if (0) printf ("failed to gsyncd logfile"); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 598, GF_LOG_WARNING , "failed to gsyncd logfile"); } while (0); | |||
599 | goto out; | |||
600 | } | |||
601 | ||||
602 | out: | |||
603 | return ret; | |||
604 | } | |||
605 | ||||
606 | static int | |||
607 | gsync_status_byfd (int fd) | |||
608 | { | |||
609 | GF_ASSERT (fd >= -1)do { if (!(fd >= -1)) { do { do { if (0) printf ("Assertion failed: " "fd >= -1"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 609, GF_LOG_ERROR, "Assertion failed: " "fd >= -1" ); } while (0); } } while (0); | |||
610 | ||||
611 | if (lockf (fd, F_TEST3, 0) == -1 && | |||
612 | (errno(*__errno_location ()) == EAGAIN11 || errno(*__errno_location ()) == EACCES13)) | |||
613 | /* gsyncd keeps the pidfile locked */ | |||
614 | return 0; | |||
615 | ||||
616 | return -1; | |||
617 | } | |||
618 | ||||
619 | /* status: return 0 when gsync is running | |||
620 | * return -1 when not running | |||
621 | */ | |||
622 | int | |||
623 | gsync_status (char *master, char *slave, int *status) | |||
624 | { | |||
625 | char pidfile[PATH_MAX4096] = {0,}; | |||
626 | int fd = -1; | |||
627 | ||||
628 | fd = gsyncd_getpidfile (master, slave, pidfile); | |||
629 | if (fd == -2) | |||
630 | return -1; | |||
631 | ||||
632 | *status = gsync_status_byfd (fd); | |||
633 | ||||
634 | sys_close (fd); | |||
635 | ||||
636 | return 0; | |||
637 | } | |||
638 | ||||
639 | ||||
640 | static int32_t | |||
641 | glusterd_gsync_volinfo_dict_set (glusterd_volinfo_t *volinfo, | |||
642 | char *key, char *value) | |||
643 | { | |||
644 | int32_t ret = -1; | |||
645 | char *gsync_status = NULL((void*)0); | |||
646 | ||||
647 | gsync_status = gf_strdup (value); | |||
648 | if (!gsync_status) { | |||
649 | gf_log ("", GF_LOG_ERROR, "Unable to allocate memory")do { do { if (0) printf ("Unable to allocate memory"); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 649, GF_LOG_ERROR , "Unable to allocate memory"); } while (0); | |||
650 | goto out; | |||
651 | } | |||
652 | ||||
653 | ret = dict_set_dynstr (volinfo->dict, key, gsync_status); | |||
654 | if (ret) { | |||
655 | gf_log ("", GF_LOG_ERROR, "Unable to set dict")do { do { if (0) printf ("Unable to set dict"); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 655, GF_LOG_ERROR, "Unable to set dict" ); } while (0); | |||
656 | goto out; | |||
657 | } | |||
658 | ||||
659 | ret = 0; | |||
660 | out: | |||
661 | return 0; | |||
662 | } | |||
663 | ||||
664 | static int | |||
665 | gsync_verify_config_options (dict_t *dict, char **op_errstr) | |||
666 | { | |||
667 | char **resopt = NULL((void*)0); | |||
668 | int i = 0; | |||
669 | char *subop = NULL((void*)0); | |||
670 | char *slave = NULL((void*)0); | |||
671 | char *op_name = NULL((void*)0); | |||
672 | char *op_value = NULL((void*)0); | |||
673 | char *t = NULL((void*)0); | |||
674 | gf_boolean_t banned = _gf_true; | |||
675 | ||||
676 | if (dict_get_str (dict, "subop", &subop) != 0) { | |||
677 | gf_log ("", GF_LOG_WARNING, "missing subop")do { do { if (0) printf ("missing subop"); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 677, GF_LOG_WARNING , "missing subop"); } while (0); | |||
678 | *op_errstr = gf_strdup ("Invalid config request"); | |||
679 | return -1; | |||
680 | } | |||
681 | ||||
682 | if (dict_get_str (dict, "slave", &slave) != 0) { | |||
683 | gf_log ("", GF_LOG_WARNING, GEOREP" CONFIG: no slave given")do { do { if (0) printf ("geo-replication"" CONFIG: no slave given" ); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__ , 683, GF_LOG_WARNING, "geo-replication"" CONFIG: no slave given" ); } while (0); | |||
684 | *op_errstr = gf_strdup ("Slave required"); | |||
685 | return -1; | |||
686 | } | |||
687 | ||||
688 | if (strcmp (subop, "get-all") == 0) | |||
689 | return 0; | |||
690 | ||||
691 | if (dict_get_str (dict, "op_name", &op_name) != 0) { | |||
692 | gf_log ("", GF_LOG_WARNING, "option name missing")do { do { if (0) printf ("option name missing"); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 692, GF_LOG_WARNING , "option name missing"); } while (0); | |||
693 | *op_errstr = gf_strdup ("Option name missing"); | |||
694 | return -1; | |||
695 | } | |||
696 | ||||
697 | if (runcmd (GSYNCD_PREFIX"/usr/local/libexec/glusterfs""/gsyncd", "--config-check", op_name, NULL((void*)0))) { | |||
698 | gf_log ("", GF_LOG_WARNING, "Invalid option %s", op_name)do { do { if (0) printf ("Invalid option %s", op_name); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 698, GF_LOG_WARNING , "Invalid option %s", op_name); } while (0); | |||
699 | *op_errstr = gf_strdup ("Invalid option"); | |||
700 | ||||
701 | return -1; | |||
702 | } | |||
703 | ||||
704 | if (strcmp (subop, "get") == 0) | |||
705 | return 0; | |||
706 | ||||
707 | t = strtail (subop, "set"); | |||
708 | if (!t) | |||
709 | t = strtail (subop, "del"); | |||
710 | if (!t || (t[0] && strcmp (t, "-glob") != 0)) { | |||
711 | gf_log ("", GF_LOG_WARNING, "unknown subop %s", subop)do { do { if (0) printf ("unknown subop %s", subop); } while ( 0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 711, GF_LOG_WARNING , "unknown subop %s", subop); } while (0); | |||
712 | *op_errstr = gf_strdup ("Invalid config request"); | |||
713 | return -1; | |||
714 | } | |||
715 | ||||
716 | if (strtail (subop, "set") && | |||
717 | dict_get_str (dict, "op_value", &op_value) != 0) { | |||
718 | gf_log ("", GF_LOG_WARNING, "missing value for set")do { do { if (0) printf ("missing value for set"); } while (0 ); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 718, GF_LOG_WARNING , "missing value for set"); } while (0); | |||
719 | *op_errstr = gf_strdup ("missing value"); | |||
720 | } | |||
721 | ||||
722 | /* match option name against reserved options, modulo -/_ | |||
723 | * difference | |||
724 | */ | |||
725 | for (resopt = gsync_reserved_opts; *resopt; resopt++) { | |||
726 | banned = _gf_true; | |||
727 | for (i = 0; (*resopt)[i] && op_name[i]; i++) { | |||
728 | if ((*resopt)[i] == op_name[i] || | |||
729 | ((*resopt)[i] == '-' && op_name[i] == '_')) | |||
730 | continue; | |||
731 | banned = _gf_false; | |||
732 | } | |||
733 | if (banned) { | |||
734 | gf_log ("", GF_LOG_WARNING, "Reserved option %s", op_name)do { do { if (0) printf ("Reserved option %s", op_name); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 734, GF_LOG_WARNING , "Reserved option %s", op_name); } while (0); | |||
735 | *op_errstr = gf_strdup ("Reserved option"); | |||
736 | ||||
737 | return -1; | |||
738 | break; | |||
739 | } | |||
740 | } | |||
741 | ||||
742 | return 0; | |||
743 | } | |||
744 | ||||
745 | static int | |||
746 | glusterd_get_gsync_status_mst_slv (glusterd_volinfo_t *volinfo, | |||
747 | char *slave, dict_t *rsp_dict, char *node); | |||
748 | ||||
749 | static int | |||
750 | _get_status_mst_slv (dict_t *this, char *key, data_t *value, void *data) | |||
751 | { | |||
752 | glusterd_gsync_status_temp_t *param = NULL((void*)0); | |||
753 | char *slave = NULL((void*)0); | |||
754 | int ret = 0; | |||
755 | ||||
756 | param = (glusterd_gsync_status_temp_t *)data; | |||
757 | ||||
758 | GF_ASSERT (param)do { if (!(param)) { do { do { if (0) printf ("Assertion failed: " "param"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 758, GF_LOG_ERROR, "Assertion failed: " "param" ); } while (0); } } while (0); | |||
759 | GF_ASSERT (param->volinfo)do { if (!(param->volinfo)) { do { do { if (0) printf ("Assertion failed: " "param->volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 759, GF_LOG_ERROR, "Assertion failed: " "param->volinfo" ); } while (0); } } while (0); | |||
760 | ||||
761 | slave = strchr(value->data, ':'); | |||
762 | if (slave) | |||
763 | slave ++; | |||
764 | else | |||
765 | return 0; | |||
766 | ||||
767 | ret = glusterd_get_gsync_status_mst_slv(param->volinfo, | |||
768 | slave, param->rsp_dict, | |||
769 | param->node); | |||
770 | return 0; | |||
771 | } | |||
772 | ||||
773 | ||||
774 | static int | |||
775 | _get_max_gsync_slave_num (dict_t *this, char *key, data_t *value, void *data) | |||
776 | { | |||
777 | int tmp_slvnum = 0; | |||
778 | int *slvnum = (int *)data; | |||
779 | ||||
780 | sscanf (key, "slave%d", &tmp_slvnum); | |||
781 | if (tmp_slvnum > *slvnum) | |||
782 | *slvnum = tmp_slvnum; | |||
783 | ||||
784 | return 0; | |||
785 | } | |||
786 | ||||
787 | static int | |||
788 | glusterd_remove_slave_in_info (glusterd_volinfo_t *volinfo, char *slave, | |||
789 | char **op_errstr) | |||
790 | { | |||
791 | int ret = 0; | |||
792 | char *slavekey = NULL((void*)0); | |||
793 | ||||
794 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 794, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); | |||
795 | GF_ASSERT (slave)do { if (!(slave)) { do { do { if (0) printf ("Assertion failed: " "slave"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 795, GF_LOG_ERROR, "Assertion failed: " "slave" ); } while (0); } } while (0); | |||
796 | ||||
797 | ret = glusterd_get_slave (volinfo, slave, &slavekey); | |||
798 | if (ret < 0) { | |||
799 | ret++; | |||
800 | goto out; | |||
801 | } | |||
802 | ||||
803 | dict_del (volinfo->gsync_slaves, slavekey); | |||
804 | ||||
805 | ret = glusterd_store_volinfo (volinfo, | |||
806 | GLUSTERD_VOLINFO_VER_AC_INCREMENT); | |||
807 | if (ret) { | |||
808 | *op_errstr = gf_strdup ("Failed to store the Volume" | |||
809 | "information"); | |||
810 | goto out; | |||
811 | } | |||
812 | out: | |||
813 | gf_log ("", GF_LOG_DEBUG, "returning %d", ret)do { do { if (0) printf ("returning %d", ret); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 813, GF_LOG_DEBUG, "returning %d" , ret); } while (0); | |||
814 | return ret; | |||
815 | ||||
816 | } | |||
817 | ||||
818 | static int | |||
819 | glusterd_gsync_get_uuid (char *slave, glusterd_volinfo_t *vol, | |||
820 | uuid_t uuid) | |||
821 | { | |||
822 | int ret = 0; | |||
823 | char *slavekey = NULL((void*)0); | |||
824 | char *slaveentry = NULL((void*)0); | |||
825 | char *t = NULL((void*)0); | |||
826 | ||||
827 | GF_ASSERT (vol)do { if (!(vol)) { do { do { if (0) printf ("Assertion failed: " "vol"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 827, GF_LOG_ERROR, "Assertion failed: " "vol" ); } while (0); } } while (0); | |||
828 | GF_ASSERT (slave)do { if (!(slave)) { do { do { if (0) printf ("Assertion failed: " "slave"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 828, GF_LOG_ERROR, "Assertion failed: " "slave" ); } while (0); } } while (0); | |||
829 | ||||
830 | ret = glusterd_get_slave (vol, slave, &slavekey); | |||
831 | if (ret < 0) { | |||
832 | /* XXX colliding cases of failure and non-extant | |||
833 | * slave... now just doing this as callers of this | |||
834 | * function can make sense only of -1 and 0 as retvals; | |||
835 | * getting at the proper semanticals will involve | |||
836 | * fixing callers as well. | |||
837 | */ | |||
838 | ret = -1; | |||
839 | goto out; | |||
840 | } | |||
841 | ||||
842 | ret = dict_get_str (vol->gsync_slaves, slavekey, &slaveentry); | |||
| ||||
843 | GF_ASSERT (ret == 0)do { if (!(ret == 0)) { do { do { if (0) printf ("Assertion failed: " "ret == 0"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 843, GF_LOG_ERROR, "Assertion failed: " "ret == 0" ); } while (0); } } while (0); | |||
844 | ||||
845 | t = strchr (slaveentry, ':'); | |||
846 | GF_ASSERT (t)do { if (!(t)) { do { do { if (0) printf ("Assertion failed: " "t"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 846, GF_LOG_ERROR, "Assertion failed: " "t"); } while (0); } } while (0); | |||
847 | *t = '\0'; | |||
848 | ret = uuid_parse (slaveentry, uuid); | |||
849 | *t = ':'; | |||
850 | ||||
851 | out: | |||
852 | gf_log ("", GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 852, GF_LOG_DEBUG, "Returning %d" , ret); } while (0); | |||
853 | return ret; | |||
854 | } | |||
855 | ||||
856 | static int | |||
857 | glusterd_check_gsync_running_local (char *master, char *slave, | |||
858 | gf_boolean_t *is_run) | |||
859 | { | |||
860 | int ret = -1; | |||
861 | int ret_status = 0; | |||
862 | ||||
863 | GF_ASSERT (master)do { if (!(master)) { do { do { if (0) printf ("Assertion failed: " "master"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 863, GF_LOG_ERROR, "Assertion failed: " "master" ); } while (0); } } while (0); | |||
864 | GF_ASSERT (slave)do { if (!(slave)) { do { do { if (0) printf ("Assertion failed: " "slave"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 864, GF_LOG_ERROR, "Assertion failed: " "slave" ); } while (0); } } while (0); | |||
865 | GF_ASSERT (is_run)do { if (!(is_run)) { do { do { if (0) printf ("Assertion failed: " "is_run"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 865, GF_LOG_ERROR, "Assertion failed: " "is_run" ); } while (0); } } while (0); | |||
866 | ||||
867 | *is_run = _gf_false; | |||
868 | ret = gsync_status (master, slave, &ret_status); | |||
869 | if (ret == 0 && ret_status == 0) { | |||
870 | *is_run = _gf_true; | |||
871 | } else if (ret == -1) { | |||
872 | gf_log ("", GF_LOG_WARNING, GEOREP" validation "do { do { if (0) printf ("geo-replication"" validation " " failed" ); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__ , 873, GF_LOG_WARNING, "geo-replication"" validation " " failed" ); } while (0) | |||
873 | " failed")do { do { if (0) printf ("geo-replication"" validation " " failed" ); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__ , 873, GF_LOG_WARNING, "geo-replication"" validation " " failed" ); } while (0); | |||
874 | goto out; | |||
875 | } | |||
876 | ret = 0; | |||
877 | out: | |||
878 | gf_log ("", GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 878, GF_LOG_DEBUG, "Returning %d" , ret); } while (0); | |||
879 | return ret; | |||
880 | ||||
881 | } | |||
882 | ||||
883 | static int | |||
884 | glusterd_store_slave_in_info (glusterd_volinfo_t *volinfo, char *slave, | |||
885 | char *host_uuid, char **op_errstr) | |||
886 | { | |||
887 | int ret = 0; | |||
888 | int maxslv = 0; | |||
889 | char **linearr = NULL((void*)0); | |||
890 | char *value = NULL((void*)0); | |||
891 | char *slavekey = NULL((void*)0); | |||
892 | char *slaveentry = NULL((void*)0); | |||
893 | char key[512] = {0, }; | |||
894 | char *t = NULL((void*)0); | |||
895 | ||||
896 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 896, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); | |||
897 | GF_ASSERT (slave)do { if (!(slave)) { do { do { if (0) printf ("Assertion failed: " "slave"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 897, GF_LOG_ERROR, "Assertion failed: " "slave" ); } while (0); } } while (0); | |||
898 | GF_ASSERT (host_uuid)do { if (!(host_uuid)) { do { do { if (0) printf ("Assertion failed: " "host_uuid"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 898, GF_LOG_ERROR, "Assertion failed: " "host_uuid" ); } while (0); } } while (0); | |||
899 | ||||
900 | ret = glusterd_get_slave (volinfo, slave, &slavekey); | |||
901 | switch (ret) { | |||
902 | case -2: | |||
903 | ret = -1; | |||
904 | goto out; | |||
905 | case -1: | |||
906 | break; | |||
907 | default: | |||
908 | GF_ASSERT (ret > 0)do { if (!(ret > 0)) { do { do { if (0) printf ("Assertion failed: " "ret > 0"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 908, GF_LOG_ERROR, "Assertion failed: " "ret > 0" ); } while (0); } } while (0); | |||
909 | ret = dict_get_str (volinfo->gsync_slaves, slavekey, &slaveentry); | |||
910 | GF_ASSERT (ret == 0)do { if (!(ret == 0)) { do { do { if (0) printf ("Assertion failed: " "ret == 0"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 910, GF_LOG_ERROR, "Assertion failed: " "ret == 0" ); } while (0); } } while (0); | |||
911 | ||||
912 | /* same-name + same-uuid slave entries should have been filtered | |||
913 | * out in glusterd_op_verify_gsync_start_options(), so we can | |||
914 | * assert an uuid mismatch | |||
915 | */ | |||
916 | t = strtail (slaveentry, host_uuid); | |||
917 | GF_ASSERT (!t || *t != ':')do { if (!(!t || *t != ':')) { do { do { if (0) printf ("Assertion failed: " "!t || *t != ':'"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 917, GF_LOG_ERROR, "Assertion failed: " "!t || *t != ':'" ); } while (0); } } while (0); | |||
918 | ||||
919 | gf_log ("", GF_LOG_ERROR, GEOREP" has already been invoked for "do { do { if (0) printf ("geo-replication"" has already been invoked for " "the %s (master) and %s (slave) " "from a different machine" , volinfo->volname, slave); } while (0); _gf_log ("", "glusterd-geo-rep.c" , __FUNCTION__, 922, GF_LOG_ERROR, "geo-replication"" has already been invoked for " "the %s (master) and %s (slave) " "from a different machine" , volinfo->volname, slave); } while (0) | |||
920 | "the %s (master) and %s (slave) "do { do { if (0) printf ("geo-replication"" has already been invoked for " "the %s (master) and %s (slave) " "from a different machine" , volinfo->volname, slave); } while (0); _gf_log ("", "glusterd-geo-rep.c" , __FUNCTION__, 922, GF_LOG_ERROR, "geo-replication"" has already been invoked for " "the %s (master) and %s (slave) " "from a different machine" , volinfo->volname, slave); } while (0) | |||
921 | "from a different machine",do { do { if (0) printf ("geo-replication"" has already been invoked for " "the %s (master) and %s (slave) " "from a different machine" , volinfo->volname, slave); } while (0); _gf_log ("", "glusterd-geo-rep.c" , __FUNCTION__, 922, GF_LOG_ERROR, "geo-replication"" has already been invoked for " "the %s (master) and %s (slave) " "from a different machine" , volinfo->volname, slave); } while (0) | |||
922 | volinfo->volname, slave)do { do { if (0) printf ("geo-replication"" has already been invoked for " "the %s (master) and %s (slave) " "from a different machine" , volinfo->volname, slave); } while (0); _gf_log ("", "glusterd-geo-rep.c" , __FUNCTION__, 922, GF_LOG_ERROR, "geo-replication"" has already been invoked for " "the %s (master) and %s (slave) " "from a different machine" , volinfo->volname, slave); } while (0); | |||
923 | *op_errstr = gf_strdup (GEOREP"geo-replication"" already running in an an" | |||
924 | "another machine"); | |||
925 | ret = -1; | |||
926 | goto out; | |||
927 | } | |||
928 | ||||
929 | ret = glusterd_urltransform_single (slave, "normalize", &linearr); | |||
930 | if (ret == -1) | |||
931 | goto out; | |||
932 | ||||
933 | ret = gf_asprintf (&value, "%s:%s", host_uuid, linearr[0]); | |||
934 | glusterd_urltransform_free (linearr, 1); | |||
935 | if (ret == -1) | |||
936 | goto out; | |||
937 | ||||
938 | dict_foreach (volinfo->gsync_slaves, _get_max_gsync_slave_num, &maxslv); | |||
939 | snprintf (key, 512, "slave%d", maxslv + 1); | |||
940 | ret = dict_set_dynstr (volinfo->gsync_slaves, key, value); | |||
941 | if (ret) | |||
942 | goto out; | |||
943 | ||||
944 | ret = glusterd_store_volinfo (volinfo, | |||
945 | GLUSTERD_VOLINFO_VER_AC_INCREMENT); | |||
946 | if (ret) { | |||
947 | *op_errstr = gf_strdup ("Failed to store the Volume " | |||
948 | "information"); | |||
949 | goto out; | |||
950 | } | |||
951 | ret = 0; | |||
952 | out: | |||
953 | return ret; | |||
954 | } | |||
955 | ||||
956 | ||||
957 | static int | |||
958 | glusterd_op_verify_gsync_start_options (glusterd_volinfo_t *volinfo, | |||
959 | char *slave, char **op_errstr) | |||
960 | { | |||
961 | int ret = -1; | |||
962 | gf_boolean_t is_running = _gf_false; | |||
963 | char msg[2048] = {0}; | |||
964 | uuid_t uuid = {0}; | |||
965 | glusterd_conf_t *priv = NULL((void*)0); | |||
966 | xlator_t *this = NULL((void*)0); | |||
967 | ||||
968 | this = THIS(*__glusterfs_this_location()); | |||
969 | ||||
970 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 970, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); | |||
971 | GF_ASSERT (slave)do { if (!(slave)) { do { do { if (0) printf ("Assertion failed: " "slave"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 971, GF_LOG_ERROR, "Assertion failed: " "slave" ); } while (0); } } while (0); | |||
972 | GF_ASSERT (op_errstr)do { if (!(op_errstr)) { do { do { if (0) printf ("Assertion failed: " "op_errstr"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 972, GF_LOG_ERROR, "Assertion failed: " "op_errstr" ); } while (0); } } while (0); | |||
973 | GF_ASSERT (this && this->private)do { if (!(this && this->private)) { do { do { if ( 0) printf ("Assertion failed: " "this && this->private" ); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c", __FUNCTION__ , 973, GF_LOG_ERROR, "Assertion failed: " "this && this->private" ); } while (0); } } while (0); | |||
974 | ||||
975 | priv = this->private; | |||
976 | ||||
977 | if (GLUSTERD_STATUS_STARTED != volinfo->status) { | |||
978 | snprintf (msg, sizeof (msg), "Volume %s needs to be started " | |||
979 | "before "GEOREP"geo-replication"" start", volinfo->volname); | |||
980 | goto out; | |||
981 | } | |||
982 | /*Check if the gsync is already started in cmd. inited host | |||
983 | * If so initiate add it into the glusterd's priv*/ | |||
984 | ret = glusterd_gsync_get_uuid (slave, volinfo, uuid); | |||
985 | if ((ret == 0) && (uuid_compare (MY_UUID(__glusterd_uuid()), uuid) == 0)) { | |||
986 | ret = glusterd_check_gsync_running_local (volinfo->volname, | |||
987 | slave, &is_running); | |||
988 | if (ret) { | |||
989 | snprintf (msg, sizeof (msg), GEOREP"geo-replication"" start option " | |||
990 | "validation failed "); | |||
991 | goto out; | |||
992 | } | |||
993 | if (_gf_true == is_running) { | |||
994 | snprintf (msg, sizeof (msg), GEOREP"geo-replication" " session between" | |||
995 | " %s & %s already started", volinfo->volname, | |||
996 | slave); | |||
997 | ret = -1; | |||
998 | goto out; | |||
999 | } | |||
1000 | } | |||
1001 | ret = 0; | |||
1002 | out: | |||
1003 | if (ret && (msg[0] != '\0')) { | |||
1004 | *op_errstr = gf_strdup (msg); | |||
1005 | } | |||
1006 | gf_log ("", GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 1006, GF_LOG_DEBUG, "Returning %d", ret); } while (0); | |||
1007 | return ret; | |||
1008 | } | |||
1009 | ||||
1010 | int | |||
1011 | glusterd_check_gsync_running (glusterd_volinfo_t *volinfo, gf_boolean_t *flag) | |||
1012 | { | |||
1013 | ||||
1014 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 1014, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); | |||
1015 | GF_ASSERT (flag)do { if (!(flag)) { do { do { if (0) printf ("Assertion failed: " "flag"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 1015, GF_LOG_ERROR, "Assertion failed: " "flag" ); } while (0); } } while (0); | |||
1016 | ||||
1017 | if (volinfo->gsync_slaves->count) | |||
1018 | *flag = _gf_true; | |||
1019 | else | |||
1020 | *flag = _gf_false; | |||
1021 | ||||
1022 | return 0; | |||
1023 | } | |||
1024 | ||||
1025 | static int | |||
1026 | glusterd_op_verify_gsync_running (glusterd_volinfo_t *volinfo, | |||
1027 | char *slave, char **op_errstr) | |||
1028 | { | |||
1029 | int ret = -1; | |||
1030 | char msg[2048] = {0}; | |||
1031 | uuid_t uuid = {0}; | |||
1032 | ||||
1033 | GF_ASSERT (THIS && THIS->private)do { if (!((*__glusterfs_this_location()) && (*__glusterfs_this_location ())->private)) { do { do { if (0) printf ("Assertion failed: " "THIS && THIS->private"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c", __FUNCTION__, 1033, GF_LOG_ERROR, "Assertion failed: " "THIS && THIS->private"); } while (0); } } while (0); | |||
1034 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 1034, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); | |||
1035 | GF_ASSERT (slave)do { if (!(slave)) { do { do { if (0) printf ("Assertion failed: " "slave"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 1035, GF_LOG_ERROR, "Assertion failed: " "slave" ); } while (0); } } while (0); | |||
1036 | GF_ASSERT (op_errstr)do { if (!(op_errstr)) { do { do { if (0) printf ("Assertion failed: " "op_errstr"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 1036, GF_LOG_ERROR, "Assertion failed: " "op_errstr" ); } while (0); } } while (0); | |||
1037 | ||||
1038 | if (GLUSTERD_STATUS_STARTED != volinfo->status) { | |||
1039 | snprintf (msg, sizeof (msg), "Volume %s needs to be started " | |||
1040 | "before "GEOREP"geo-replication"" start", volinfo->volname); | |||
1041 | ||||
1042 | goto out; | |||
1043 | } | |||
1044 | ret = glusterd_gsync_get_uuid (slave, volinfo, uuid); | |||
1045 | if (ret == -1) { | |||
1046 | snprintf (msg, sizeof (msg), GEOREP"geo-replication"" session between %s & %s" | |||
1047 | " not active", volinfo->volname, slave); | |||
1048 | goto out; | |||
1049 | } | |||
1050 | ||||
1051 | ret = 0; | |||
1052 | out: | |||
1053 | if (ret && (msg[0] != '\0')) { | |||
1054 | *op_errstr = gf_strdup (msg); | |||
1055 | } | |||
1056 | gf_log ("", GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 1056, GF_LOG_DEBUG, "Returning %d", ret); } while (0); | |||
1057 | return ret; | |||
1058 | } | |||
1059 | ||||
1060 | static int | |||
1061 | glusterd_verify_gsync_status_opts (dict_t *dict, char **op_errstr) | |||
1062 | { | |||
1063 | char *slave = NULL((void*)0); | |||
1064 | char *volname = NULL((void*)0); | |||
1065 | char errmsg[PATH_MAX4096] = {0, }; | |||
1066 | gf_boolean_t exists = _gf_false; | |||
1067 | glusterd_volinfo_t *volinfo = NULL((void*)0); | |||
1068 | int ret = 0; | |||
1069 | ||||
1070 | ret = dict_get_str (dict, "master", &volname); | |||
1071 | if (ret < 0) { | |||
1072 | ret = 0; | |||
1073 | goto out; | |||
1074 | } | |||
1075 | ||||
1076 | exists = glusterd_check_volume_exists (volname); | |||
1077 | ret = glusterd_volinfo_find (volname, &volinfo); | |||
1078 | if ((ret) || (!exists)) { | |||
1079 | gf_log ("", GF_LOG_WARNING, "volume name does not exist")do { do { if (0) printf ("volume name does not exist"); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 1079, GF_LOG_WARNING , "volume name does not exist"); } while (0); | |||
1080 | snprintf (errmsg, sizeof(errmsg), "Volume name %s does not" | |||
1081 | " exist", volname); | |||
1082 | *op_errstr = gf_strdup (errmsg); | |||
1083 | ret = -1; | |||
1084 | goto out; | |||
1085 | } | |||
1086 | ||||
1087 | ret = dict_get_str (dict, "slave", &slave); | |||
1088 | if (ret < 0) { | |||
1089 | ret = 0; | |||
1090 | goto out; | |||
1091 | } | |||
1092 | ||||
1093 | out: | |||
1094 | gf_log ("", GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 1094, GF_LOG_DEBUG, "Returning %d", ret); } while (0); | |||
1095 | return ret; | |||
1096 | ||||
1097 | } | |||
1098 | ||||
1099 | ||||
1100 | int | |||
1101 | glusterd_op_gsync_args_get (dict_t *dict, char **op_errstr, | |||
1102 | char **master, char **slave) | |||
1103 | { | |||
1104 | ||||
1105 | int ret = -1; | |||
1106 | GF_ASSERT (dict)do { if (!(dict)) { do { do { if (0) printf ("Assertion failed: " "dict"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 1106, GF_LOG_ERROR, "Assertion failed: " "dict" ); } while (0); } } while (0); | |||
1107 | GF_ASSERT (op_errstr)do { if (!(op_errstr)) { do { do { if (0) printf ("Assertion failed: " "op_errstr"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 1107, GF_LOG_ERROR, "Assertion failed: " "op_errstr" ); } while (0); } } while (0); | |||
1108 | ||||
1109 | if (master) { | |||
1110 | ret = dict_get_str (dict, "master", master); | |||
1111 | if (ret < 0) { | |||
1112 | gf_log ("", GF_LOG_WARNING, "master not found")do { do { if (0) printf ("master not found"); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 1112, GF_LOG_WARNING , "master not found"); } while (0); | |||
1113 | *op_errstr = gf_strdup ("master not found"); | |||
1114 | goto out; | |||
1115 | } | |||
1116 | } | |||
1117 | ||||
1118 | if (slave) { | |||
1119 | ret = dict_get_str (dict, "slave", slave); | |||
1120 | if (ret < 0) { | |||
1121 | gf_log ("", GF_LOG_WARNING, "slave not found")do { do { if (0) printf ("slave not found"); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 1121, GF_LOG_WARNING , "slave not found"); } while (0); | |||
1122 | *op_errstr = gf_strdup ("slave not found"); | |||
1123 | goto out; | |||
1124 | } | |||
1125 | } | |||
1126 | ||||
1127 | ||||
1128 | ret = 0; | |||
1129 | out: | |||
1130 | gf_log ("", GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 1130, GF_LOG_DEBUG, "Returning %d", ret); } while (0); | |||
1131 | return ret; | |||
1132 | } | |||
1133 | ||||
1134 | int | |||
1135 | glusterd_op_stage_gsync_set (dict_t *dict, char **op_errstr) | |||
1136 | { | |||
1137 | int ret = 0; | |||
1138 | int type = 0; | |||
1139 | char *volname = NULL((void*)0); | |||
1140 | char *slave = NULL((void*)0); | |||
1141 | gf_boolean_t exists = _gf_false; | |||
1142 | glusterd_volinfo_t *volinfo = NULL((void*)0); | |||
1143 | char errmsg[PATH_MAX4096] = {0,}; | |||
1144 | dict_t *ctx = NULL((void*)0); | |||
1145 | ||||
1146 | ||||
1147 | ret = dict_get_int32 (dict, "type", &type); | |||
1148 | if (ret < 0) { | |||
1149 | gf_log ("", GF_LOG_WARNING, "command type not found")do { do { if (0) printf ("command type not found"); } while ( 0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 1149, GF_LOG_WARNING , "command type not found"); } while (0); | |||
1150 | *op_errstr = gf_strdup ("command unsuccessful"); | |||
1151 | goto out; | |||
1152 | } | |||
1153 | ||||
1154 | switch (type) { | |||
1155 | case GF_GSYNC_OPTION_TYPE_STATUS: | |||
1156 | ret = glusterd_verify_gsync_status_opts (dict, op_errstr); | |||
1157 | ||||
1158 | goto out; | |||
1159 | case GF_GSYNC_OPTION_TYPE_CONFIG: | |||
1160 | ret = gsync_verify_config_options (dict, op_errstr); | |||
1161 | ||||
1162 | goto out; | |||
1163 | ||||
1164 | case GF_GSYNC_OPTION_TYPE_ROTATE: | |||
1165 | /* checks same as status mode */ | |||
1166 | ret = glusterd_verify_gsync_status_opts(dict, op_errstr); | |||
1167 | goto out; | |||
1168 | } | |||
1169 | ||||
1170 | ret = glusterd_op_gsync_args_get (dict, op_errstr, &volname, &slave); | |||
1171 | if (ret) | |||
1172 | goto out; | |||
1173 | ||||
1174 | exists = glusterd_check_volume_exists (volname); | |||
1175 | ret = glusterd_volinfo_find (volname, &volinfo); | |||
1176 | if ((ret) || (!exists)) { | |||
1177 | gf_log ("", GF_LOG_WARNING, "volume name does not exist")do { do { if (0) printf ("volume name does not exist"); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 1177, GF_LOG_WARNING , "volume name does not exist"); } while (0); | |||
1178 | snprintf (errmsg, sizeof(errmsg), "Volume name %s does not" | |||
1179 | " exist", volname); | |||
1180 | *op_errstr = gf_strdup (errmsg); | |||
1181 | ret = -1; | |||
1182 | goto out; | |||
1183 | } | |||
1184 | ||||
1185 | switch (type) { | |||
1186 | case GF_GSYNC_OPTION_TYPE_START: | |||
1187 | /* don't attempt to start gsync if replace-brick is | |||
1188 | * in progress */ | |||
1189 | if (glusterd_is_rb_ongoing (volinfo)) { | |||
1190 | snprintf (errmsg, sizeof(errmsg),"replace-brick is in" | |||
1191 | " progress, not starting geo-replication"); | |||
1192 | *op_errstr = gf_strdup (errmsg); | |||
1193 | ret = -1; | |||
1194 | goto out; | |||
1195 | } | |||
1196 | ||||
1197 | ret = glusterd_op_verify_gsync_start_options (volinfo, slave, | |||
1198 | op_errstr); | |||
1199 | if (ret) | |||
1200 | goto out; | |||
1201 | ctx = glusterd_op_get_ctx(); | |||
1202 | if (ctx) { | |||
1203 | /*gsyncd does a fuse mount to start the geo-rep session*/ | |||
1204 | if (!glusterd_is_fuse_available ()) { | |||
1205 | gf_log ("glusterd", GF_LOG_ERROR, "Unable to open"do { do { if (0) printf ("Unable to open" " /dev/fuse (%s), geo-replication start" " failed", strerror ((*__errno_location ()))); } while (0); _gf_log ("glusterd", "glusterd-geo-rep.c", __FUNCTION__, 1207, GF_LOG_ERROR , "Unable to open" " /dev/fuse (%s), geo-replication start" " failed" , strerror ((*__errno_location ()))); } while (0) | |||
1206 | " /dev/fuse (%s), geo-replication start"do { do { if (0) printf ("Unable to open" " /dev/fuse (%s), geo-replication start" " failed", strerror ((*__errno_location ()))); } while (0); _gf_log ("glusterd", "glusterd-geo-rep.c", __FUNCTION__, 1207, GF_LOG_ERROR , "Unable to open" " /dev/fuse (%s), geo-replication start" " failed" , strerror ((*__errno_location ()))); } while (0) | |||
1207 | " failed", strerror (errno))do { do { if (0) printf ("Unable to open" " /dev/fuse (%s), geo-replication start" " failed", strerror ((*__errno_location ()))); } while (0); _gf_log ("glusterd", "glusterd-geo-rep.c", __FUNCTION__, 1207, GF_LOG_ERROR , "Unable to open" " /dev/fuse (%s), geo-replication start" " failed" , strerror ((*__errno_location ()))); } while (0); | |||
1208 | snprintf (errmsg, sizeof(errmsg), | |||
1209 | "fuse unvailable"); | |||
1210 | *op_errstr = gf_strdup (errmsg); | |||
1211 | ret = -1; | |||
1212 | goto out; | |||
1213 | } | |||
1214 | } | |||
1215 | break; | |||
1216 | ||||
1217 | case GF_GSYNC_OPTION_TYPE_STOP: | |||
1218 | ret = glusterd_op_verify_gsync_running (volinfo, slave, | |||
1219 | op_errstr); | |||
1220 | break; | |||
1221 | } | |||
1222 | ||||
1223 | out: | |||
1224 | return ret; | |||
1225 | } | |||
1226 | ||||
1227 | static int | |||
1228 | stop_gsync (char *master, char *slave, char **msg) | |||
1229 | { | |||
1230 | int32_t ret = 0; | |||
1231 | int pfd = -1; | |||
1232 | pid_t pid = 0; | |||
1233 | char pidfile[PATH_MAX4096] = {0,}; | |||
1234 | char buf [1024] = {0,}; | |||
1235 | int i = 0; | |||
1236 | ||||
1237 | GF_ASSERT (THIS)do { if (!((*__glusterfs_this_location()))) { do { do { if (0 ) printf ("Assertion failed: " "THIS"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c", __FUNCTION__, 1237, GF_LOG_ERROR, "Assertion failed: " "THIS"); } while (0); } } while (0); | |||
1238 | GF_ASSERT (THIS->private)do { if (!((*__glusterfs_this_location())->private)) { do { do { if (0) printf ("Assertion failed: " "THIS->private") ; } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c", __FUNCTION__ , 1238, GF_LOG_ERROR, "Assertion failed: " "THIS->private" ); } while (0); } } while (0); | |||
1239 | ||||
1240 | pfd = gsyncd_getpidfile (master, slave, pidfile); | |||
1241 | if (pfd == -2) { | |||
1242 | gf_log ("", GF_LOG_ERROR, GEOREP" stop validation "do { do { if (0) printf ("geo-replication"" stop validation " " failed for %s & %s", master, slave); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 1243, GF_LOG_ERROR, "geo-replication"" stop validation " " failed for %s & %s" , master, slave); } while (0) | |||
1243 | " failed for %s & %s", master, slave)do { do { if (0) printf ("geo-replication"" stop validation " " failed for %s & %s", master, slave); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 1243, GF_LOG_ERROR, "geo-replication"" stop validation " " failed for %s & %s" , master, slave); } while (0); | |||
1244 | ret = -1; | |||
1245 | goto out; | |||
1246 | } | |||
1247 | if (gsync_status_byfd (pfd) == -1) { | |||
1248 | gf_log ("", GF_LOG_ERROR, "gsyncd b/w %s & %s is not"do { do { if (0) printf ("gsyncd b/w %s & %s is not" " running" , master, slave); } while (0); _gf_log ("", "glusterd-geo-rep.c" , __FUNCTION__, 1249, GF_LOG_ERROR, "gsyncd b/w %s & %s is not" " running", master, slave); } while (0) | |||
1249 | " running", master, slave)do { do { if (0) printf ("gsyncd b/w %s & %s is not" " running" , master, slave); } while (0); _gf_log ("", "glusterd-geo-rep.c" , __FUNCTION__, 1249, GF_LOG_ERROR, "gsyncd b/w %s & %s is not" " running", master, slave); } while (0); | |||
1250 | if (msg) | |||
1251 | *msg = gf_strdup ("Warning: "GEOREP"geo-replication"" session was " | |||
1252 | "defunct at stop time"); | |||
1253 | /* monitor gsyncd already dead */ | |||
1254 | goto out; | |||
1255 | } | |||
1256 | ||||
1257 | if (pfd < 0) | |||
1258 | goto out; | |||
1259 | ||||
1260 | ret = read (pfd, buf, 1024); | |||
1261 | if (ret > 0) { | |||
1262 | pid = strtol (buf, NULL((void*)0), 10); | |||
1263 | ret = kill (-pid, SIGTERM15); | |||
1264 | if (ret) { | |||
1265 | gf_log ("", GF_LOG_WARNING,do { do { if (0) printf ("failed to kill gsyncd"); } while (0 ); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 1266, GF_LOG_WARNING , "failed to kill gsyncd"); } while (0) | |||
1266 | "failed to kill gsyncd")do { do { if (0) printf ("failed to kill gsyncd"); } while (0 ); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 1266, GF_LOG_WARNING , "failed to kill gsyncd"); } while (0); | |||
1267 | goto out; | |||
1268 | } | |||
1269 | for (i = 0; i < 20; i++) { | |||
1270 | if (gsync_status_byfd (pfd) == -1) { | |||
1271 | /* monitor gsyncd is dead but worker may | |||
1272 | * still be alive, give some more time | |||
1273 | * before SIGKILL (hack) | |||
1274 | */ | |||
1275 | usleep (50000); | |||
1276 | break; | |||
1277 | } | |||
1278 | usleep (50000); | |||
1279 | } | |||
1280 | kill (-pid, SIGKILL9); | |||
1281 | unlink (pidfile); | |||
1282 | } | |||
1283 | ret = 0; | |||
1284 | ||||
1285 | out: | |||
1286 | sys_close (pfd); | |||
1287 | return ret; | |||
1288 | } | |||
1289 | ||||
1290 | static int | |||
1291 | glusterd_check_restart_gsync_session (glusterd_volinfo_t *volinfo, char *slave, | |||
1292 | dict_t *resp_dict); | |||
1293 | ||||
1294 | static int | |||
1295 | glusterd_gsync_configure (glusterd_volinfo_t *volinfo, char *slave, | |||
1296 | dict_t *dict, dict_t *resp_dict, char **op_errstr) | |||
1297 | { | |||
1298 | int32_t ret = -1; | |||
1299 | char *op_name = NULL((void*)0); | |||
1300 | char *op_value = NULL((void*)0); | |||
1301 | runner_t runner = {0,}; | |||
1302 | glusterd_conf_t *priv = NULL((void*)0); | |||
1303 | char *subop = NULL((void*)0); | |||
1304 | char *master = NULL((void*)0); | |||
1305 | ||||
1306 | GF_ASSERT (slave)do { if (!(slave)) { do { do { if (0) printf ("Assertion failed: " "slave"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 1306, GF_LOG_ERROR, "Assertion failed: " "slave" ); } while (0); } } while (0); | |||
1307 | GF_ASSERT (op_errstr)do { if (!(op_errstr)) { do { do { if (0) printf ("Assertion failed: " "op_errstr"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 1307, GF_LOG_ERROR, "Assertion failed: " "op_errstr" ); } while (0); } } while (0); | |||
1308 | GF_ASSERT (dict)do { if (!(dict)) { do { do { if (0) printf ("Assertion failed: " "dict"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 1308, GF_LOG_ERROR, "Assertion failed: " "dict" ); } while (0); } } while (0); | |||
1309 | GF_ASSERT (resp_dict)do { if (!(resp_dict)) { do { do { if (0) printf ("Assertion failed: " "resp_dict"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 1309, GF_LOG_ERROR, "Assertion failed: " "resp_dict" ); } while (0); } } while (0); | |||
1310 | ||||
1311 | ret = dict_get_str (dict, "subop", &subop); | |||
1312 | if (ret != 0) | |||
1313 | goto out; | |||
1314 | ||||
1315 | if (strcmp (subop, "get") == 0 || strcmp (subop, "get-all") == 0) { | |||
1316 | /* deferred to cli */ | |||
1317 | gf_log ("", GF_LOG_DEBUG, "Returning 0")do { do { if (0) printf ("Returning 0"); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 1317, GF_LOG_DEBUG, "Returning 0"); } while (0); | |||
1318 | return 0; | |||
1319 | } | |||
1320 | ||||
1321 | ret = dict_get_str (dict, "op_name", &op_name); | |||
1322 | if (ret != 0) | |||
1323 | goto out; | |||
1324 | ||||
1325 | if (strtail (subop, "set")) { | |||
1326 | ret = dict_get_str (dict, "op_value", &op_value); | |||
1327 | if (ret != 0) | |||
1328 | goto out; | |||
1329 | } | |||
1330 | ||||
1331 | if (THIS(*__glusterfs_this_location())) | |||
1332 | priv = THIS(*__glusterfs_this_location())->private; | |||
1333 | if (priv == NULL((void*)0)) { | |||
1334 | gf_log ("", GF_LOG_ERROR, "priv of glusterd not present")do { do { if (0) printf ("priv of glusterd not present"); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 1334, GF_LOG_ERROR , "priv of glusterd not present"); } while (0); | |||
1335 | *op_errstr = gf_strdup ("glusterd defunct"); | |||
1336 | goto out; | |||
1337 | } | |||
1338 | ||||
1339 | master = ""; | |||
1340 | runinit (&runner); | |||
1341 | runner_add_args (&runner, GSYNCD_PREFIX"/usr/local/libexec/glusterfs""/gsyncd", "-c", NULL((void*)0)); | |||
1342 | runner_argprintf (&runner, "%s/"GSYNC_CONF"geo-replication""/gsyncd.conf", priv->workdir); | |||
1343 | if (volinfo) { | |||
1344 | master = volinfo->volname; | |||
1345 | runner_argprintf (&runner, ":%s", master); | |||
1346 | } | |||
1347 | runner_add_arg (&runner, slave); | |||
1348 | runner_argprintf (&runner, "--config-%s", subop); | |||
1349 | runner_add_arg (&runner, op_name); | |||
1350 | if (op_value) | |||
1351 | runner_add_arg (&runner, op_value); | |||
1352 | synclock_unlock (&priv->big_lock); | |||
1353 | ret = runner_run (&runner); | |||
1354 | synclock_lock (&priv->big_lock); | |||
1355 | if (ret) { | |||
1356 | gf_log ("", GF_LOG_WARNING, "gsyncd failed to "do { do { if (0) printf ("gsyncd failed to " "%s %s option for %s %s peers" , subop, op_name, master, slave); } while (0); _gf_log ("", "glusterd-geo-rep.c" , __FUNCTION__, 1358, GF_LOG_WARNING, "gsyncd failed to " "%s %s option for %s %s peers" , subop, op_name, master, slave); } while (0) | |||
1357 | "%s %s option for %s %s peers",do { do { if (0) printf ("gsyncd failed to " "%s %s option for %s %s peers" , subop, op_name, master, slave); } while (0); _gf_log ("", "glusterd-geo-rep.c" , __FUNCTION__, 1358, GF_LOG_WARNING, "gsyncd failed to " "%s %s option for %s %s peers" , subop, op_name, master, slave); } while (0) | |||
1358 | subop, op_name, master, slave)do { do { if (0) printf ("gsyncd failed to " "%s %s option for %s %s peers" , subop, op_name, master, slave); } while (0); _gf_log ("", "glusterd-geo-rep.c" , __FUNCTION__, 1358, GF_LOG_WARNING, "gsyncd failed to " "%s %s option for %s %s peers" , subop, op_name, master, slave); } while (0); | |||
1359 | ||||
1360 | gf_asprintf (op_errstr, GEOREP"geo-replication"" config-%s failed for %s %s", | |||
1361 | subop, master, slave); | |||
1362 | ||||
1363 | goto out; | |||
1364 | } | |||
1365 | ret = 0; | |||
1366 | gf_asprintf (op_errstr, "config-%s successful", subop); | |||
1367 | ||||
1368 | out: | |||
1369 | if (!ret && volinfo) { | |||
1370 | ret = glusterd_check_restart_gsync_session (volinfo, slave, | |||
1371 | resp_dict); | |||
1372 | if (ret) | |||
1373 | *op_errstr = gf_strdup ("internal error"); | |||
1374 | } | |||
1375 | ||||
1376 | gf_log ("", GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 1376, GF_LOG_DEBUG, "Returning %d", ret); } while (0); | |||
1377 | return ret; | |||
1378 | } | |||
1379 | ||||
1380 | static int | |||
1381 | glusterd_gsync_read_frm_status (char *path, char *buf, size_t blen) | |||
1382 | { | |||
1383 | int ret = 0; | |||
1384 | int status_fd = -1; | |||
1385 | ||||
1386 | GF_ASSERT (path)do { if (!(path)) { do { do { if (0) printf ("Assertion failed: " "path"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 1386, GF_LOG_ERROR, "Assertion failed: " "path" ); } while (0); } } while (0); | |||
1387 | GF_ASSERT (buf)do { if (!(buf)) { do { do { if (0) printf ("Assertion failed: " "buf"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 1387, GF_LOG_ERROR, "Assertion failed: " "buf" ); } while (0); } } while (0); | |||
1388 | status_fd = open (path, O_RDONLY00); | |||
1389 | if (status_fd == -1) { | |||
1390 | gf_log ("", GF_LOG_ERROR, "Unable to read gsyncd status"do { do { if (0) printf ("Unable to read gsyncd status" " file" ); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__ , 1391, GF_LOG_ERROR, "Unable to read gsyncd status" " file") ; } while (0) | |||
1391 | " file")do { do { if (0) printf ("Unable to read gsyncd status" " file" ); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__ , 1391, GF_LOG_ERROR, "Unable to read gsyncd status" " file") ; } while (0); | |||
1392 | return -1; | |||
1393 | } | |||
1394 | ret = read (status_fd, buf, blen - 1); | |||
1395 | if (ret > 0) { | |||
1396 | size_t len = strnlen (buf, ret); | |||
1397 | /* Ensure there is a NUL byte and that it's not the first. */ | |||
1398 | if (len == 0 || len == blen - 1) { | |||
1399 | ret = -1; | |||
1400 | } else { | |||
1401 | char *p = buf + len - 1; | |||
1402 | while (isspace (*p)((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISspace)) | |||
1403 | *p-- = '\0'; | |||
1404 | ret = 0; | |||
1405 | } | |||
1406 | } else if (ret < 0) | |||
1407 | gf_log ("", GF_LOG_ERROR, "Status file of gsyncd is corrupt")do { do { if (0) printf ("Status file of gsyncd is corrupt"); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__ , 1407, GF_LOG_ERROR, "Status file of gsyncd is corrupt"); } while (0); | |||
1408 | ||||
1409 | close (status_fd); | |||
1410 | return ret; | |||
1411 | } | |||
1412 | ||||
1413 | static int | |||
1414 | glusterd_gsync_fetch_status_extra (char *path, char *buf, size_t blen) | |||
1415 | { | |||
1416 | char sockpath[PATH_MAX4096] = {0,}; | |||
1417 | struct sockaddr_un sa = {0,}; | |||
1418 | size_t l = 0; | |||
1419 | int s = -1; | |||
1420 | struct pollfd pfd = {0,}; | |||
1421 | int ret = 0; | |||
1422 | ||||
1423 | l = strlen (buf); | |||
1424 | /* seek to end of data in buf */ | |||
1425 | buf += l; | |||
1426 | blen -= l; | |||
1427 | ||||
1428 | glusterd_set_socket_filepath (path, sockpath, sizeof (sockpath)); | |||
1429 | ||||
1430 | strncpy(sa.sun_path, sockpath, sizeof(sa.sun_path)); | |||
1431 | if (sa.sun_path[sizeof (sa.sun_path) - 1]) | |||
1432 | return -1; | |||
1433 | sa.sun_family = AF_UNIX1; | |||
1434 | ||||
1435 | s = socket(AF_UNIX1, SOCK_STREAMSOCK_STREAM, 0); | |||
1436 | if (s == -1) | |||
1437 | return -1; | |||
1438 | ret = fcntl (s, F_GETFL3); | |||
1439 | if (ret != -1) | |||
1440 | ret = fcntl (s, F_SETFL4, ret | O_NONBLOCK04000); | |||
1441 | if (ret == -1) | |||
1442 | goto out; | |||
1443 | ||||
1444 | ret = connect (s, (struct sockaddr *)&sa, sizeof (sa)); | |||
1445 | if (ret == -1) | |||
1446 | goto out; | |||
1447 | pfd.fd = s; | |||
1448 | pfd.events = POLLIN0x001; | |||
1449 | /* we don't want to hang on gsyncd */ | |||
1450 | if (poll (&pfd, 1, 5000) < 1 || | |||
1451 | !(pfd.revents & POLLIN0x001)) { | |||
1452 | ret = -1; | |||
1453 | goto out; | |||
1454 | } | |||
1455 | ret = read(s, buf, blen); | |||
1456 | /* we expect a terminating 0 byte */ | |||
1457 | if (ret == 0 || (ret > 0 && buf[ret - 1])) | |||
1458 | ret = -1; | |||
1459 | if (ret > 0) | |||
1460 | ret = 0; | |||
1461 | ||||
1462 | out: | |||
1463 | close (s); | |||
1464 | return ret; | |||
1465 | } | |||
1466 | ||||
1467 | static int | |||
1468 | dict_get_param (dict_t *dict, char *key, char **param) | |||
1469 | { | |||
1470 | char *dk = NULL((void*)0); | |||
1471 | char *s = NULL((void*)0); | |||
1472 | char x = '\0'; | |||
1473 | int ret = 0; | |||
1474 | ||||
1475 | if (dict_get_str (dict, key, param) == 0) | |||
1476 | return 0; | |||
1477 | ||||
1478 | dk = gf_strdup (key); | |||
1479 | if (!key) | |||
1480 | return -1; | |||
1481 | ||||
1482 | s = strpbrk (dk, "-_"); | |||
1483 | if (!s) | |||
1484 | return -1; | |||
1485 | x = (*s == '-') ? '_' : '-'; | |||
1486 | *s++ = x; | |||
1487 | while ((s = strpbrk (s, "-_"))) | |||
1488 | *s++ = x; | |||
1489 | ||||
1490 | ret = dict_get_str (dict, dk, param); | |||
1491 | ||||
1492 | GF_FREE (dk)__gf_free (dk); | |||
1493 | return ret; | |||
1494 | } | |||
1495 | ||||
1496 | static int | |||
1497 | glusterd_read_status_file (char *master, char *slave, | |||
1498 | dict_t *dict, char *node) | |||
1499 | { | |||
1500 | glusterd_conf_t *priv = NULL((void*)0); | |||
1501 | int ret = 0; | |||
1502 | char *statefile = NULL((void*)0); | |||
1503 | char buf[1024] = {0, }; | |||
1504 | char nds[1024] = {0, }; | |||
1505 | char mst[1024] = {0, }; | |||
1506 | char slv[1024] = {0, }; | |||
1507 | char sts[1024] = {0, }; | |||
1508 | char *bufp = NULL((void*)0); | |||
1509 | dict_t *confd = NULL((void*)0); | |||
1510 | int gsync_count = 0; | |||
1511 | int status = 0; | |||
1512 | char *dyn_node = NULL((void*)0); | |||
1513 | ||||
1514 | GF_ASSERT (THIS)do { if (!((*__glusterfs_this_location()))) { do { do { if (0 ) printf ("Assertion failed: " "THIS"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c", __FUNCTION__, 1514, GF_LOG_ERROR, "Assertion failed: " "THIS"); } while (0); } } while (0); | |||
1515 | GF_ASSERT (THIS->private)do { if (!((*__glusterfs_this_location())->private)) { do { do { if (0) printf ("Assertion failed: " "THIS->private") ; } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c", __FUNCTION__ , 1515, GF_LOG_ERROR, "Assertion failed: " "THIS->private" ); } while (0); } } while (0); | |||
1516 | ||||
1517 | confd = dict_new (); | |||
1518 | if (!dict) | |||
1519 | return -1; | |||
1520 | ||||
1521 | priv = THIS(*__glusterfs_this_location())->private; | |||
1522 | ret = glusterd_gsync_get_config (master, slave, priv->workdir, | |||
1523 | confd); | |||
1524 | if (ret) { | |||
1525 | gf_log ("", GF_LOG_ERROR, "Unable to get configuration data"do { do { if (0) printf ("Unable to get configuration data" "for %s(master), %s(slave)" , master, slave); } while (0); _gf_log ("", "glusterd-geo-rep.c" , __FUNCTION__, 1526, GF_LOG_ERROR, "Unable to get configuration data" "for %s(master), %s(slave)", master, slave); } while (0) | |||
1526 | "for %s(master), %s(slave)", master, slave)do { do { if (0) printf ("Unable to get configuration data" "for %s(master), %s(slave)" , master, slave); } while (0); _gf_log ("", "glusterd-geo-rep.c" , __FUNCTION__, 1526, GF_LOG_ERROR, "Unable to get configuration data" "for %s(master), %s(slave)", master, slave); } while (0); | |||
1527 | goto out; | |||
1528 | ||||
1529 | } | |||
1530 | ||||
1531 | ret = gsync_status (master, slave, &status); | |||
1532 | if (ret == 0 && status == -1) { | |||
1533 | strncpy (buf, "defunct", sizeof (buf)); | |||
1534 | goto done; | |||
1535 | } else if (ret == -1) | |||
1536 | goto out; | |||
1537 | ||||
1538 | ret = dict_get_param (confd, "state_file", &statefile); | |||
1539 | if (ret) | |||
1540 | goto out; | |||
1541 | ret = glusterd_gsync_read_frm_status (statefile, buf, sizeof (buf)); | |||
1542 | if (ret) { | |||
1543 | gf_log ("", GF_LOG_ERROR, "Unable to read the status"do { do { if (0) printf ("Unable to read the status" "file for %s(master), %s(slave)" , master, slave); } while (0); _gf_log ("", "glusterd-geo-rep.c" , __FUNCTION__, 1544, GF_LOG_ERROR, "Unable to read the status" "file for %s(master), %s(slave)", master, slave); } while (0 ) | |||
1544 | "file for %s(master), %s(slave)", master, slave)do { do { if (0) printf ("Unable to read the status" "file for %s(master), %s(slave)" , master, slave); } while (0); _gf_log ("", "glusterd-geo-rep.c" , __FUNCTION__, 1544, GF_LOG_ERROR, "Unable to read the status" "file for %s(master), %s(slave)", master, slave); } while (0 ); | |||
1545 | strncpy (buf, "defunct", sizeof (buf)); | |||
1546 | goto done; | |||
1547 | } | |||
1548 | if (strcmp (buf, "OK") != 0) | |||
1549 | goto done; | |||
1550 | ||||
1551 | ret = dict_get_param (confd, "state_socket_unencoded", &statefile); | |||
1552 | if (ret) | |||
1553 | goto out; | |||
1554 | ret = glusterd_gsync_fetch_status_extra (statefile, buf, sizeof (buf)); | |||
1555 | if (ret) { | |||
1556 | gf_log ("", GF_LOG_ERROR, "Unable to fetch extra status"do { do { if (0) printf ("Unable to fetch extra status" "for %s(master), %s(slave)" , master, slave); } while (0); _gf_log ("", "glusterd-geo-rep.c" , __FUNCTION__, 1557, GF_LOG_ERROR, "Unable to fetch extra status" "for %s(master), %s(slave)", master, slave); } while (0) | |||
1557 | "for %s(master), %s(slave)", master, slave)do { do { if (0) printf ("Unable to fetch extra status" "for %s(master), %s(slave)" , master, slave); } while (0); _gf_log ("", "glusterd-geo-rep.c" , __FUNCTION__, 1557, GF_LOG_ERROR, "Unable to fetch extra status" "for %s(master), %s(slave)", master, slave); } while (0); | |||
1558 | /* there is a slight chance that this occurs due to race | |||
1559 | * -- in that case, the following options all seem bad: | |||
1560 | * | |||
1561 | * - suppress irregurlar behavior by just leaving status | |||
1562 | * on "OK" | |||
1563 | * - freak out users with a misleading "defunct" | |||
1564 | * - overload the meaning of the regular error signal | |||
1565 | * mechanism of gsyncd, that is, when status is "faulty" | |||
1566 | * | |||
1567 | * -- so we just come up with something new... | |||
1568 | */ | |||
1569 | strncpy (buf, "N/A", sizeof (buf)); | |||
1570 | goto done; | |||
1571 | } | |||
1572 | ||||
1573 | done: | |||
1574 | ret = dict_get_int32 (dict, "gsync-count", &gsync_count); | |||
1575 | ||||
1576 | if (ret) | |||
1577 | gsync_count = 1; | |||
1578 | else | |||
1579 | gsync_count++; | |||
1580 | ||||
1581 | (void) snprintf (nds, sizeof (nds), "node%d", gsync_count); | |||
1582 | dyn_node = gf_strdup (node); | |||
1583 | if (!dyn_node) | |||
1584 | goto out; | |||
1585 | ret = dict_set_dynstr (dict, nds, dyn_node); | |||
1586 | if (ret) { | |||
1587 | GF_FREE (dyn_node)__gf_free (dyn_node); | |||
1588 | goto out; | |||
1589 | } | |||
1590 | ||||
1591 | snprintf (mst, sizeof (mst), "master%d", gsync_count); | |||
1592 | master = gf_strdup (master); | |||
1593 | if (!master) | |||
1594 | goto out; | |||
1595 | ret = dict_set_dynstr (dict, mst, master); | |||
1596 | if (ret) { | |||
1597 | GF_FREE (master)__gf_free (master); | |||
1598 | goto out; | |||
1599 | } | |||
1600 | ||||
1601 | snprintf (slv, sizeof (slv), "slave%d", gsync_count); | |||
1602 | slave = gf_strdup (slave); | |||
1603 | if (!slave) | |||
1604 | goto out; | |||
1605 | ret = dict_set_dynstr (dict, slv, slave); | |||
1606 | if (ret) { | |||
1607 | GF_FREE (slave)__gf_free (slave); | |||
1608 | goto out; | |||
1609 | } | |||
1610 | ||||
1611 | snprintf (sts, sizeof (slv), "status%d", gsync_count); | |||
1612 | bufp = gf_strdup (buf); | |||
1613 | if (!bufp) | |||
1614 | goto out; | |||
1615 | ret = dict_set_dynstr (dict, sts, bufp); | |||
1616 | if (ret) { | |||
1617 | GF_FREE (bufp)__gf_free (bufp); | |||
1618 | goto out; | |||
1619 | } | |||
1620 | ret = dict_set_int32 (dict, "gsync-count", gsync_count); | |||
1621 | if (ret) | |||
1622 | goto out; | |||
1623 | ||||
1624 | ret = 0; | |||
1625 | out: | |||
1626 | dict_destroy (confd); | |||
1627 | ||||
1628 | gf_log ("", GF_LOG_DEBUG, "Returning %d ", ret)do { do { if (0) printf ("Returning %d ", ret); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 1628, GF_LOG_DEBUG, "Returning %d ", ret); } while (0); | |||
1629 | return ret; | |||
1630 | } | |||
1631 | ||||
1632 | static int | |||
1633 | glusterd_check_restart_gsync_session (glusterd_volinfo_t *volinfo, char *slave, | |||
1634 | dict_t *resp_dict) | |||
1635 | { | |||
1636 | ||||
1637 | int ret = 0; | |||
1638 | uuid_t uuid = {0, }; | |||
1639 | glusterd_conf_t *priv = NULL((void*)0); | |||
1640 | char *status_msg = NULL((void*)0); | |||
1641 | ||||
1642 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 1642, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); | |||
1643 | GF_ASSERT (slave)do { if (!(slave)) { do { do { if (0) printf ("Assertion failed: " "slave"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 1643, GF_LOG_ERROR, "Assertion failed: " "slave" ); } while (0); } } while (0); | |||
1644 | GF_ASSERT (THIS)do { if (!((*__glusterfs_this_location()))) { do { do { if (0 ) printf ("Assertion failed: " "THIS"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c", __FUNCTION__, 1644, GF_LOG_ERROR, "Assertion failed: " "THIS"); } while (0); } } while (0); | |||
1645 | GF_ASSERT (THIS->private)do { if (!((*__glusterfs_this_location())->private)) { do { do { if (0) printf ("Assertion failed: " "THIS->private") ; } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c", __FUNCTION__ , 1645, GF_LOG_ERROR, "Assertion failed: " "THIS->private" ); } while (0); } } while (0); | |||
1646 | ||||
1647 | priv = THIS(*__glusterfs_this_location())->private; | |||
1648 | ||||
1649 | if (glusterd_gsync_get_uuid (slave, volinfo, uuid)) | |||
1650 | /* session does not exist, nothing to do */ | |||
1651 | goto out; | |||
1652 | if (uuid_compare (MY_UUID(__glusterd_uuid()), uuid) == 0) { | |||
1653 | ret = stop_gsync (volinfo->volname, slave, &status_msg); | |||
1654 | if (ret == 0 && status_msg) | |||
1655 | ret = dict_set_str (resp_dict, "gsync-status", | |||
1656 | status_msg); | |||
1657 | if (ret == 0) | |||
1658 | ret = glusterd_start_gsync (volinfo, slave, | |||
1659 | uuid_utoa(MY_UUID(__glusterd_uuid())), NULL((void*)0)); | |||
1660 | } | |||
1661 | ||||
1662 | out: | |||
1663 | gf_log ("", GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 1663, GF_LOG_DEBUG, "Returning %d", ret); } while (0); | |||
1664 | return ret; | |||
1665 | } | |||
1666 | ||||
1667 | static int32_t | |||
1668 | glusterd_marker_create_volfile (glusterd_volinfo_t *volinfo) | |||
1669 | { | |||
1670 | int32_t ret = 0; | |||
1671 | ||||
1672 | ret = glusterd_create_volfiles_and_notify_services (volinfo); | |||
1673 | if (ret) { | |||
1674 | gf_log ("", GF_LOG_ERROR, "Unable to create volfile"do { do { if (0) printf ("Unable to create volfile" " for setting of marker while '" "geo-replication"" start'"); } while (0); _gf_log ("", "glusterd-geo-rep.c" , __FUNCTION__, 1675, GF_LOG_ERROR, "Unable to create volfile" " for setting of marker while '""geo-replication"" start'"); } while (0) | |||
1675 | " for setting of marker while '"GEOREP" start'")do { do { if (0) printf ("Unable to create volfile" " for setting of marker while '" "geo-replication"" start'"); } while (0); _gf_log ("", "glusterd-geo-rep.c" , __FUNCTION__, 1675, GF_LOG_ERROR, "Unable to create volfile" " for setting of marker while '""geo-replication"" start'"); } while (0); | |||
1676 | ret = -1; | |||
1677 | goto out; | |||
1678 | } | |||
1679 | ||||
1680 | ret = glusterd_store_volinfo (volinfo, GLUSTERD_VOLINFO_VER_AC_INCREMENT); | |||
1681 | if (ret) | |||
1682 | goto out; | |||
1683 | ||||
1684 | if (GLUSTERD_STATUS_STARTED == volinfo->status) | |||
1685 | ret = glusterd_nodesvcs_handle_graph_change (volinfo); | |||
1686 | ret = 0; | |||
1687 | out: | |||
1688 | return ret; | |||
1689 | } | |||
1690 | ||||
1691 | static int | |||
1692 | glusterd_set_marker_gsync (glusterd_volinfo_t *volinfo) | |||
1693 | { | |||
1694 | int ret = -1; | |||
1695 | int marker_set = _gf_false; | |||
1696 | char *gsync_status = NULL((void*)0); | |||
1697 | ||||
1698 | GF_ASSERT (THIS)do { if (!((*__glusterfs_this_location()))) { do { do { if (0 ) printf ("Assertion failed: " "THIS"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c", __FUNCTION__, 1698, GF_LOG_ERROR, "Assertion failed: " "THIS"); } while (0); } } while (0); | |||
1699 | GF_ASSERT (THIS->private)do { if (!((*__glusterfs_this_location())->private)) { do { do { if (0) printf ("Assertion failed: " "THIS->private") ; } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c", __FUNCTION__ , 1699, GF_LOG_ERROR, "Assertion failed: " "THIS->private" ); } while (0); } } while (0); | |||
1700 | ||||
1701 | marker_set = glusterd_volinfo_get_boolean (volinfo, VKEY_MARKER_XTIME"geo-replication"".indexing"); | |||
1702 | if (marker_set == -1) { | |||
1703 | gf_log ("", GF_LOG_ERROR, "failed to get the marker status")do { do { if (0) printf ("failed to get the marker status"); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 1703 , GF_LOG_ERROR, "failed to get the marker status"); } while ( 0); | |||
1704 | ret = -1; | |||
1705 | goto out; | |||
1706 | } | |||
1707 | ||||
1708 | if (marker_set == _gf_false) { | |||
1709 | gsync_status = gf_strdup ("on"); | |||
1710 | if (gsync_status == NULL((void*)0)) { | |||
1711 | ret = -1; | |||
1712 | goto out; | |||
1713 | } | |||
1714 | ||||
1715 | ret = glusterd_gsync_volinfo_dict_set (volinfo, | |||
1716 | VKEY_MARKER_XTIME"geo-replication"".indexing", gsync_status); | |||
1717 | if (ret < 0) | |||
1718 | goto out; | |||
1719 | ||||
1720 | ret = glusterd_marker_create_volfile (volinfo); | |||
1721 | if (ret) { | |||
1722 | gf_log ("", GF_LOG_ERROR, "Setting dict failed")do { do { if (0) printf ("Setting dict failed"); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 1722, GF_LOG_ERROR , "Setting dict failed"); } while (0); | |||
1723 | goto out; | |||
1724 | } | |||
1725 | } | |||
1726 | ret = 0; | |||
1727 | ||||
1728 | out: | |||
1729 | gf_log ("", GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 1729, GF_LOG_DEBUG, "Returning %d", ret); } while (0); | |||
1730 | return ret; | |||
1731 | } | |||
1732 | ||||
1733 | ||||
1734 | ||||
1735 | ||||
1736 | static int | |||
1737 | glusterd_get_gsync_status_mst_slv (glusterd_volinfo_t *volinfo, | |||
1738 | char *slave, dict_t *rsp_dict, | |||
1739 | char *node) | |||
1740 | { | |||
1741 | uuid_t uuid = {0, }; | |||
1742 | glusterd_conf_t *priv = NULL((void*)0); | |||
1743 | int ret = 0; | |||
1744 | ||||
1745 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 1745, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); | |||
1746 | GF_ASSERT (slave)do { if (!(slave)) { do { do { if (0) printf ("Assertion failed: " "slave"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 1746, GF_LOG_ERROR, "Assertion failed: " "slave" ); } while (0); } } while (0); | |||
1747 | GF_ASSERT (THIS)do { if (!((*__glusterfs_this_location()))) { do { do { if (0 ) printf ("Assertion failed: " "THIS"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c", __FUNCTION__, 1747, GF_LOG_ERROR, "Assertion failed: " "THIS"); } while (0); } } while (0); | |||
1748 | GF_ASSERT (THIS->private)do { if (!((*__glusterfs_this_location())->private)) { do { do { if (0) printf ("Assertion failed: " "THIS->private") ; } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c", __FUNCTION__ , 1748, GF_LOG_ERROR, "Assertion failed: " "THIS->private" ); } while (0); } } while (0); | |||
1749 | ||||
1750 | priv = THIS(*__glusterfs_this_location())->private; | |||
1751 | ||||
1752 | ret = glusterd_gsync_get_uuid (slave, volinfo, uuid); | |||
1753 | if ((ret == 0) && (uuid_compare (MY_UUID(__glusterd_uuid()), uuid) != 0)) | |||
1754 | goto out; | |||
1755 | ||||
1756 | if (ret) { | |||
1757 | ret = 0; | |||
1758 | gf_log ("", GF_LOG_INFO, "geo-replication status %s %s :"do { do { if (0) printf ("geo-replication status %s %s :" "session is not active" , volinfo->volname, slave); } while (0); _gf_log ("", "glusterd-geo-rep.c" , __FUNCTION__, 1759, GF_LOG_INFO, "geo-replication status %s %s :" "session is not active", volinfo->volname, slave); } while (0) | |||
1759 | "session is not active", volinfo->volname, slave)do { do { if (0) printf ("geo-replication status %s %s :" "session is not active" , volinfo->volname, slave); } while (0); _gf_log ("", "glusterd-geo-rep.c" , __FUNCTION__, 1759, GF_LOG_INFO, "geo-replication status %s %s :" "session is not active", volinfo->volname, slave); } while (0); | |||
1760 | goto out; | |||
1761 | } | |||
1762 | ||||
1763 | ret = glusterd_read_status_file (volinfo->volname, | |||
1764 | slave, rsp_dict, node); | |||
1765 | out: | |||
1766 | gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while ( 0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 1766, GF_LOG_DEBUG , "Returning with %d", ret); } while (0); | |||
1767 | return ret; | |||
1768 | } | |||
1769 | ||||
1770 | static int | |||
1771 | glusterd_get_gsync_status_mst (glusterd_volinfo_t *volinfo, dict_t *rsp_dict, | |||
1772 | char *node) | |||
1773 | { | |||
1774 | glusterd_gsync_status_temp_t param = {0, }; | |||
1775 | ||||
1776 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 1776, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); | |||
1777 | ||||
1778 | param.rsp_dict = rsp_dict; | |||
1779 | param.volinfo = volinfo; | |||
1780 | param.node = node; | |||
1781 | dict_foreach (volinfo->gsync_slaves, _get_status_mst_slv, ¶m); | |||
1782 | ||||
1783 | return 0; | |||
1784 | } | |||
1785 | ||||
1786 | static int | |||
1787 | glusterd_get_gsync_status_all (dict_t *rsp_dict, char *node) | |||
1788 | { | |||
1789 | ||||
1790 | int32_t ret = 0; | |||
1791 | glusterd_conf_t *priv = NULL((void*)0); | |||
1792 | glusterd_volinfo_t *volinfo = NULL((void*)0); | |||
1793 | ||||
1794 | GF_ASSERT (THIS)do { if (!((*__glusterfs_this_location()))) { do { do { if (0 ) printf ("Assertion failed: " "THIS"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c", __FUNCTION__, 1794, GF_LOG_ERROR, "Assertion failed: " "THIS"); } while (0); } } while (0); | |||
1795 | priv = THIS(*__glusterfs_this_location())->private; | |||
1796 | ||||
1797 | GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: " "priv"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 1797, GF_LOG_ERROR, "Assertion failed: " "priv" ); } while (0); } } while (0); | |||
1798 | ||||
1799 | 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)))) { | |||
1800 | ret = glusterd_get_gsync_status_mst (volinfo, rsp_dict, node); | |||
1801 | if (ret) | |||
1802 | goto out; | |||
1803 | } | |||
1804 | ||||
1805 | out: | |||
1806 | gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while ( 0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 1806, GF_LOG_DEBUG , "Returning with %d", ret); } while (0); | |||
1807 | return ret; | |||
1808 | ||||
1809 | } | |||
1810 | ||||
1811 | static int | |||
1812 | glusterd_get_gsync_status (dict_t *dict, char **op_errstr, dict_t *rsp_dict) | |||
1813 | { | |||
1814 | char *slave = NULL((void*)0); | |||
1815 | char *volname = NULL((void*)0); | |||
1816 | char errmsg[PATH_MAX4096] = {0, }; | |||
1817 | gf_boolean_t exists = _gf_false; | |||
1818 | glusterd_volinfo_t *volinfo = NULL((void*)0); | |||
1819 | int ret = 0; | |||
1820 | char my_hostname[256] = {0,}; | |||
1821 | ||||
1822 | ret = gethostname(my_hostname, 256); | |||
1823 | if (ret) { | |||
1824 | /* stick to N/A */ | |||
1825 | (void) strcpy (my_hostname, "N/A"); | |||
1826 | } | |||
1827 | ||||
1828 | ret = dict_get_str (dict, "master", &volname); | |||
1829 | if (ret < 0){ | |||
1830 | ret = glusterd_get_gsync_status_all (rsp_dict, my_hostname); | |||
1831 | goto out; | |||
1832 | } | |||
1833 | ||||
1834 | exists = glusterd_check_volume_exists (volname); | |||
1835 | ret = glusterd_volinfo_find (volname, &volinfo); | |||
1836 | if ((ret) || (!exists)) { | |||
1837 | gf_log ("", GF_LOG_WARNING, "volume name does not exist")do { do { if (0) printf ("volume name does not exist"); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 1837, GF_LOG_WARNING , "volume name does not exist"); } while (0); | |||
1838 | snprintf (errmsg, sizeof(errmsg), "Volume name %s does not" | |||
1839 | " exist", volname); | |||
1840 | *op_errstr = gf_strdup (errmsg); | |||
1841 | ret = -1; | |||
1842 | goto out; | |||
1843 | } | |||
1844 | ||||
1845 | ||||
1846 | ret = dict_get_str (dict, "slave", &slave); | |||
1847 | if (ret < 0) { | |||
1848 | ret = glusterd_get_gsync_status_mst (volinfo, | |||
1849 | rsp_dict, my_hostname); | |||
1850 | goto out; | |||
1851 | } | |||
1852 | ||||
1853 | ret = glusterd_get_gsync_status_mst_slv (volinfo, slave, | |||
1854 | rsp_dict, my_hostname); | |||
1855 | ||||
1856 | out: | |||
1857 | gf_log ("", GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 1857, GF_LOG_DEBUG, "Returning %d", ret); } while (0); | |||
1858 | return ret; | |||
1859 | } | |||
1860 | ||||
1861 | static int | |||
1862 | glusterd_send_sigstop (pid_t pid) | |||
1863 | { | |||
1864 | int ret = 0; | |||
1865 | ret = kill (pid, SIGSTOP19); | |||
1866 | if (ret) | |||
1867 | gf_log ("", GF_LOG_ERROR, GEOREP"failed to send SIGSTOP signal")do { do { if (0) printf ("geo-replication""failed to send SIGSTOP signal" ); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__ , 1867, GF_LOG_ERROR, "geo-replication""failed to send SIGSTOP signal" ); } while (0); | |||
1868 | return ret; | |||
1869 | } | |||
1870 | ||||
1871 | static int | |||
1872 | glusterd_send_sigcont (pid_t pid) | |||
1873 | { | |||
1874 | int ret = 0; | |||
1875 | ret = kill (pid, SIGCONT18); | |||
1876 | if (ret) | |||
1877 | gf_log ("", GF_LOG_ERROR, GEOREP"failed to send SIGCONT signal")do { do { if (0) printf ("geo-replication""failed to send SIGCONT signal" ); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__ , 1877, GF_LOG_ERROR, "geo-replication""failed to send SIGCONT signal" ); } while (0); | |||
1878 | return ret; | |||
1879 | } | |||
1880 | ||||
1881 | /* | |||
1882 | * Log rotations flow is something like this: | |||
1883 | * - Send SIGSTOP to process group (this will stop monitor/worker process | |||
1884 | * and also the slave if it's local) | |||
1885 | * - Rotate log file for monitor/worker | |||
1886 | * - Rotate log file for slave if it's local | |||
1887 | * - Send SIGCONT to the process group. Monitor wakes up, kills the worker | |||
1888 | * (this is done in the SIGCONT handler), which results in the termination | |||
1889 | * of the slave (local/remote). After returning from signal handler, | |||
1890 | * monitor detects absence of worker and starts it again, which in-turn | |||
1891 | * starts the slave. | |||
1892 | */ | |||
1893 | static int | |||
1894 | glusterd_send_log_rotate_signal (pid_t pid, char *logfile1, char *logfile2) | |||
1895 | { | |||
1896 | int ret = 0; | |||
1897 | char rlogfile[PATH_MAX4096] = {0,}; | |||
1898 | time_t rottime = 0; | |||
1899 | ||||
1900 | ret = glusterd_send_sigstop (-pid); | |||
1901 | rottime = time (NULL((void*)0)); | |||
1902 | ||||
1903 | snprintf (rlogfile, sizeof (rlogfile), "%s.%"PRIu64"ll" "u", logfile1, | |||
1904 | (uint64_t) rottime); | |||
1905 | ret = rename (logfile1, rlogfile); | |||
1906 | if (ret) | |||
1907 | gf_log ("", GF_LOG_ERROR, "rename failed for geo-rep log file")do { do { if (0) printf ("rename failed for geo-rep log file" ); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__ , 1907, GF_LOG_ERROR, "rename failed for geo-rep log file"); } while (0); | |||
1908 | ||||
1909 | if (!*logfile2) { | |||
1910 | gf_log ("", GF_LOG_DEBUG, "Slave is not local,"do { do { if (0) printf ("Slave is not local," " skipping rotation" ); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__ , 1911, GF_LOG_DEBUG, "Slave is not local," " skipping rotation" ); } while (0) | |||
1911 | " skipping rotation")do { do { if (0) printf ("Slave is not local," " skipping rotation" ); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__ , 1911, GF_LOG_DEBUG, "Slave is not local," " skipping rotation" ); } while (0); | |||
1912 | ret = 0; | |||
1913 | goto out; | |||
1914 | } | |||
1915 | ||||
1916 | (void) snprintf (rlogfile, sizeof (rlogfile), "%s.%"PRIu64"ll" "u", logfile2, | |||
1917 | (uint64_t) rottime); | |||
1918 | ret = rename (logfile2, rlogfile); | |||
1919 | if (ret) | |||
1920 | gf_log ("", GF_LOG_ERROR, "rename failed for geo-rep slave"do { do { if (0) printf ("rename failed for geo-rep slave" " log file" ); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__ , 1921, GF_LOG_ERROR, "rename failed for geo-rep slave" " log file" ); } while (0) | |||
1921 | " log file")do { do { if (0) printf ("rename failed for geo-rep slave" " log file" ); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__ , 1921, GF_LOG_ERROR, "rename failed for geo-rep slave" " log file" ); } while (0); | |||
1922 | ||||
1923 | out: | |||
1924 | ret = glusterd_send_sigcont (-pid); | |||
1925 | ||||
1926 | return ret; | |||
1927 | } | |||
1928 | ||||
1929 | static int | |||
1930 | glusterd_get_pid_from_file (char *master, char *slave, pid_t *pid) | |||
1931 | { | |||
1932 | int ret = -1; | |||
1933 | int pfd = 0; | |||
1934 | char pidfile[PATH_MAX4096] = {0,}; | |||
1935 | char buff[1024] = {0,}; | |||
1936 | ||||
1937 | pfd = gsyncd_getpidfile (master, slave, pidfile); | |||
1938 | if (pfd == -2) { | |||
1939 | gf_log ("", GF_LOG_ERROR, GEOREP" log-rotate validation "do { do { if (0) printf ("geo-replication"" log-rotate validation " " failed for %s & %s", master, slave); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 1940, GF_LOG_ERROR, "geo-replication"" log-rotate validation " " failed for %s & %s" , master, slave); } while (0) | |||
1940 | " failed for %s & %s", master, slave)do { do { if (0) printf ("geo-replication"" log-rotate validation " " failed for %s & %s", master, slave); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 1940, GF_LOG_ERROR, "geo-replication"" log-rotate validation " " failed for %s & %s" , master, slave); } while (0); | |||
1941 | goto out; | |||
1942 | } | |||
1943 | if (gsync_status_byfd (pfd) == -1) { | |||
1944 | gf_log ("", GF_LOG_ERROR, "gsyncd b/w %s & %s is not"do { do { if (0) printf ("gsyncd b/w %s & %s is not" " running" , master, slave); } while (0); _gf_log ("", "glusterd-geo-rep.c" , __FUNCTION__, 1945, GF_LOG_ERROR, "gsyncd b/w %s & %s is not" " running", master, slave); } while (0) | |||
1945 | " running", master, slave)do { do { if (0) printf ("gsyncd b/w %s & %s is not" " running" , master, slave); } while (0); _gf_log ("", "glusterd-geo-rep.c" , __FUNCTION__, 1945, GF_LOG_ERROR, "gsyncd b/w %s & %s is not" " running", master, slave); } while (0); | |||
1946 | goto out; | |||
1947 | } | |||
1948 | ||||
1949 | if (pfd < 0) | |||
1950 | goto out; | |||
1951 | ||||
1952 | ret = read (pfd, buff, 1024); | |||
1953 | if (ret < 0) { | |||
1954 | gf_log ("", GF_LOG_ERROR, GEOREP" cannot read pid from pid-file")do { do { if (0) printf ("geo-replication"" cannot read pid from pid-file" ); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__ , 1954, GF_LOG_ERROR, "geo-replication"" cannot read pid from pid-file" ); } while (0); | |||
1955 | goto out; | |||
1956 | } | |||
1957 | ||||
1958 | ||||
1959 | *pid = strtol (buff, NULL((void*)0), 10); | |||
1960 | ret = 0; | |||
1961 | ||||
1962 | out: | |||
1963 | sys_close(pfd); | |||
1964 | return ret; | |||
1965 | } | |||
1966 | ||||
1967 | static int | |||
1968 | glusterd_do_gsync_log_rotate (char *master, char *slave, uuid_t *uuid, char **op_errstr) | |||
1969 | { | |||
1970 | int ret = 0; | |||
1971 | glusterd_conf_t *priv = NULL((void*)0); | |||
1972 | pid_t pid = 0; | |||
1973 | char log_file1[PATH_MAX4096] = {0,}; | |||
1974 | char log_file2[PATH_MAX4096] = {0,}; | |||
1975 | ||||
1976 | GF_ASSERT (THIS)do { if (!((*__glusterfs_this_location()))) { do { do { if (0 ) printf ("Assertion failed: " "THIS"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c", __FUNCTION__, 1976, GF_LOG_ERROR, "Assertion failed: " "THIS"); } while (0); } } while (0); | |||
1977 | GF_ASSERT (THIS->private)do { if (!((*__glusterfs_this_location())->private)) { do { do { if (0) printf ("Assertion failed: " "THIS->private") ; } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c", __FUNCTION__ , 1977, GF_LOG_ERROR, "Assertion failed: " "THIS->private" ); } while (0); } } while (0); | |||
1978 | ||||
1979 | priv = THIS(*__glusterfs_this_location())->private; | |||
1980 | ||||
1981 | ret = glusterd_get_pid_from_file (master, slave, &pid); | |||
1982 | if (ret) | |||
1983 | goto out; | |||
1984 | ||||
1985 | /* log file */ | |||
1986 | ret = glusterd_gsyncd_getlogfile (master, slave, log_file1); | |||
1987 | if (ret) | |||
1988 | goto out; | |||
1989 | ||||
1990 | /* check if slave is local or remote */ | |||
1991 | ret = glusterd_gsync_slave_is_remote (slave); | |||
1992 | if (ret) | |||
1993 | goto do_rotate; | |||
1994 | ||||
1995 | /* slave log file - slave is local and it's log can be rotated */ | |||
1996 | ret = glusterd_gsync_get_slave_log_file (master, slave, log_file2); | |||
1997 | if (ret) | |||
1998 | goto out; | |||
1999 | ||||
2000 | do_rotate: | |||
2001 | ret = glusterd_send_log_rotate_signal (pid, log_file1, log_file2); | |||
2002 | ||||
2003 | out: | |||
2004 | if (ret && op_errstr) | |||
2005 | *op_errstr = gf_strdup("Error rotating log file"); | |||
2006 | return ret; | |||
2007 | } | |||
2008 | ||||
2009 | static int | |||
2010 | glusterd_do_gsync_log_rotation_mst_slv (glusterd_volinfo_t *volinfo, char *slave, | |||
2011 | char **op_errstr) | |||
2012 | { | |||
2013 | uuid_t uuid = {0, }; | |||
2014 | glusterd_conf_t *priv = NULL((void*)0); | |||
2015 | int ret = 0; | |||
2016 | char errmsg[1024] = {0,}; | |||
2017 | xlator_t *this = NULL((void*)0); | |||
2018 | ||||
2019 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 2019, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); | |||
2020 | GF_ASSERT (slave)do { if (!(slave)) { do { do { if (0) printf ("Assertion failed: " "slave"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 2020, GF_LOG_ERROR, "Assertion failed: " "slave" ); } while (0); } } while (0); | |||
2021 | GF_ASSERT (THIS)do { if (!((*__glusterfs_this_location()))) { do { do { if (0 ) printf ("Assertion failed: " "THIS"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c", __FUNCTION__, 2021, GF_LOG_ERROR, "Assertion failed: " "THIS"); } while (0); } } while (0); | |||
2022 | this = THIS(*__glusterfs_this_location()); | |||
2023 | GF_ASSERT (this->private)do { if (!(this->private)) { do { do { if (0) printf ("Assertion failed: " "this->private"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 2023, GF_LOG_ERROR, "Assertion failed: " "this->private" ); } while (0); } } while (0); | |||
2024 | priv = this->private; | |||
2025 | ||||
2026 | ret = glusterd_gsync_get_uuid (slave, volinfo, uuid); | |||
2027 | if ((ret == 0) && (uuid_compare (MY_UUID(__glusterd_uuid()), uuid) != 0)) | |||
2028 | goto out; | |||
2029 | ||||
2030 | if (ret) { | |||
2031 | snprintf(errmsg, sizeof(errmsg), "geo-replication session b/w %s %s not active", | |||
2032 | volinfo->volname, slave); | |||
2033 | gf_log (this->name, GF_LOG_WARNING, "%s", errmsg)do { do { if (0) printf ("%s", errmsg); } while (0); _gf_log ( this->name, "glusterd-geo-rep.c", __FUNCTION__, 2033, GF_LOG_WARNING , "%s", errmsg); } while (0); | |||
2034 | if (op_errstr) | |||
2035 | *op_errstr = gf_strdup(errmsg); | |||
2036 | goto out; | |||
2037 | } | |||
2038 | ||||
2039 | ret = glusterd_do_gsync_log_rotate (volinfo->volname, slave, &uuid, op_errstr); | |||
2040 | ||||
2041 | out: | |||
2042 | gf_log (this->name, GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while ( 0); _gf_log (this->name, "glusterd-geo-rep.c", __FUNCTION__ , 2042, GF_LOG_DEBUG, "Returning with %d", ret); } while (0); | |||
2043 | return ret; | |||
2044 | } | |||
2045 | ||||
2046 | static int | |||
2047 | _iterate_log_rotate_mst_slv (dict_t *this, char *key, data_t *value, void *data) | |||
2048 | { | |||
2049 | glusterd_gsync_status_temp_t *param = NULL((void*)0); | |||
2050 | char *slave = NULL((void*)0); | |||
2051 | ||||
2052 | param = (glusterd_gsync_status_temp_t *) data; | |||
2053 | ||||
2054 | GF_ASSERT (param)do { if (!(param)) { do { do { if (0) printf ("Assertion failed: " "param"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 2054, GF_LOG_ERROR, "Assertion failed: " "param" ); } while (0); } } while (0); | |||
2055 | GF_ASSERT (param->volinfo)do { if (!(param->volinfo)) { do { do { if (0) printf ("Assertion failed: " "param->volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 2055, GF_LOG_ERROR, "Assertion failed: " "param->volinfo" ); } while (0); } } while (0); | |||
2056 | ||||
2057 | slave = strchr (value->data, ':'); | |||
2058 | if (slave) | |||
2059 | slave++; | |||
2060 | else { | |||
2061 | gf_log ("", GF_LOG_ERROR, "geo-replication log-rotate: slave (%s) "do { do { if (0) printf ("geo-replication log-rotate: slave (%s) " "not conforming to format", slave); } while (0); _gf_log ("" , "glusterd-geo-rep.c", __FUNCTION__, 2062, GF_LOG_ERROR, "geo-replication log-rotate: slave (%s) " "not conforming to format", slave); } while (0) | |||
2062 | "not conforming to format", slave)do { do { if (0) printf ("geo-replication log-rotate: slave (%s) " "not conforming to format", slave); } while (0); _gf_log ("" , "glusterd-geo-rep.c", __FUNCTION__, 2062, GF_LOG_ERROR, "geo-replication log-rotate: slave (%s) " "not conforming to format", slave); } while (0); | |||
2063 | return -1; | |||
2064 | } | |||
2065 | ||||
2066 | (void) glusterd_do_gsync_log_rotation_mst_slv (param->volinfo, slave, NULL((void*)0)); | |||
2067 | return 0; | |||
2068 | } | |||
2069 | ||||
2070 | static int | |||
2071 | glusterd_do_gsync_log_rotation_mst (glusterd_volinfo_t *volinfo) | |||
2072 | { | |||
2073 | glusterd_gsync_status_temp_t param = {0, }; | |||
2074 | ||||
2075 | GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: " "volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 2075, GF_LOG_ERROR, "Assertion failed: " "volinfo" ); } while (0); } } while (0); | |||
2076 | ||||
2077 | param.volinfo = volinfo; | |||
2078 | dict_foreach (volinfo->gsync_slaves, _iterate_log_rotate_mst_slv, ¶m); | |||
2079 | return 0; | |||
2080 | } | |||
2081 | ||||
2082 | static int | |||
2083 | glusterd_rotate_gsync_all () | |||
2084 | { | |||
2085 | int32_t ret = 0; | |||
2086 | glusterd_conf_t *priv = NULL((void*)0); | |||
2087 | glusterd_volinfo_t *volinfo = NULL((void*)0); | |||
2088 | ||||
2089 | GF_ASSERT (THIS)do { if (!((*__glusterfs_this_location()))) { do { do { if (0 ) printf ("Assertion failed: " "THIS"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c", __FUNCTION__, 2089, GF_LOG_ERROR, "Assertion failed: " "THIS"); } while (0); } } while (0); | |||
2090 | priv = THIS(*__glusterfs_this_location())->private; | |||
2091 | ||||
2092 | GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: " "priv"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 2092, GF_LOG_ERROR, "Assertion failed: " "priv" ); } while (0); } } while (0); | |||
2093 | ||||
2094 | 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)))) { | |||
2095 | ret = glusterd_do_gsync_log_rotation_mst (volinfo); | |||
2096 | if (ret) | |||
2097 | goto out; | |||
2098 | } | |||
2099 | ||||
2100 | out: | |||
2101 | gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret)do { do { if (0) printf ("Returning with %d", ret); } while ( 0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 2101, GF_LOG_DEBUG , "Returning with %d", ret); } while (0); | |||
2102 | return ret; | |||
2103 | } | |||
2104 | ||||
2105 | static int | |||
2106 | glusterd_rotate_gsync_logs (dict_t *dict, char **op_errstr, dict_t *rsp_dict) | |||
2107 | { | |||
2108 | char *slave = NULL((void*)0); | |||
2109 | char *volname = NULL((void*)0); | |||
2110 | char errmsg[1024] = {0,}; | |||
2111 | gf_boolean_t exists = _gf_false; | |||
2112 | glusterd_volinfo_t *volinfo = NULL((void*)0); | |||
2113 | char **linearr = NULL((void*)0); | |||
2114 | int ret = 0; | |||
2115 | ||||
2116 | ret = dict_get_str (dict, "master", &volname); | |||
2117 | if (ret < 0) { | |||
2118 | ret = glusterd_rotate_gsync_all (); | |||
2119 | goto out; | |||
2120 | } | |||
2121 | ||||
2122 | exists = glusterd_check_volume_exists (volname); | |||
2123 | ret = glusterd_volinfo_find (volname, &volinfo); | |||
2124 | if ((ret) || (!exists)) { | |||
2125 | snprintf (errmsg, sizeof(errmsg), "Volume %s does not" | |||
2126 | " exist", volname); | |||
2127 | gf_log ("", GF_LOG_WARNING, "%s", errmsg)do { do { if (0) printf ("%s", errmsg); } while (0); _gf_log ( "", "glusterd-geo-rep.c", __FUNCTION__, 2127, GF_LOG_WARNING, "%s", errmsg); } while (0); | |||
2128 | *op_errstr = gf_strdup (errmsg); | |||
2129 | ret = -1; | |||
2130 | goto out; | |||
2131 | } | |||
2132 | ||||
2133 | ret = dict_get_str (dict, "slave", &slave); | |||
2134 | if (ret < 0) { | |||
2135 | ret = glusterd_do_gsync_log_rotation_mst (volinfo); | |||
2136 | goto out; | |||
2137 | } | |||
2138 | ||||
2139 | /* for the given slave use the normalized url */ | |||
2140 | ret = glusterd_urltransform_single (slave, "normalize", &linearr); | |||
2141 | if (ret == -1) | |||
2142 | goto out; | |||
2143 | ||||
2144 | ret = glusterd_do_gsync_log_rotation_mst_slv (volinfo, linearr[0], | |||
2145 | op_errstr); | |||
2146 | if (ret) | |||
2147 | gf_log ("gsyncd", GF_LOG_ERROR, "gsyncd log-rotate failed for"do { do { if (0) printf ("gsyncd log-rotate failed for" " %s & %s" , volname, slave); } while (0); _gf_log ("gsyncd", "glusterd-geo-rep.c" , __FUNCTION__, 2148, GF_LOG_ERROR, "gsyncd log-rotate failed for" " %s & %s", volname, slave); } while (0) | |||
2148 | " %s & %s", volname, slave)do { do { if (0) printf ("gsyncd log-rotate failed for" " %s & %s" , volname, slave); } while (0); _gf_log ("gsyncd", "glusterd-geo-rep.c" , __FUNCTION__, 2148, GF_LOG_ERROR, "gsyncd log-rotate failed for" " %s & %s", volname, slave); } while (0); | |||
2149 | ||||
2150 | glusterd_urltransform_free (linearr, 1); | |||
2151 | out: | |||
2152 | return ret; | |||
2153 | } | |||
2154 | ||||
2155 | ||||
2156 | int | |||
2157 | glusterd_op_gsync_set (dict_t *dict, char **op_errstr, dict_t *rsp_dict) | |||
2158 | { | |||
2159 | int32_t ret = -1; | |||
2160 | int32_t type = -1; | |||
2161 | dict_t *ctx = NULL((void*)0); | |||
2162 | dict_t *resp_dict = NULL((void*)0); | |||
2163 | char *host_uuid = NULL((void*)0); | |||
2164 | char *slave = NULL((void*)0); | |||
2165 | char *volname = NULL((void*)0); | |||
2166 | glusterd_volinfo_t *volinfo = NULL((void*)0); | |||
2167 | glusterd_conf_t *priv = NULL((void*)0); | |||
2168 | char *status_msg = NULL((void*)0); | |||
2169 | uuid_t uuid = {0, }; | |||
2170 | ||||
2171 | GF_ASSERT (THIS)do { if (!((*__glusterfs_this_location()))) { do { do { if (0 ) printf ("Assertion failed: " "THIS"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c", __FUNCTION__, 2171, GF_LOG_ERROR, "Assertion failed: " "THIS"); } while (0); } } while (0); | |||
2172 | GF_ASSERT (THIS->private)do { if (!((*__glusterfs_this_location())->private)) { do { do { if (0) printf ("Assertion failed: " "THIS->private") ; } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c", __FUNCTION__ , 2172, GF_LOG_ERROR, "Assertion failed: " "THIS->private" ); } while (0); } } while (0); | |||
2173 | GF_ASSERT (dict)do { if (!(dict)) { do { do { if (0) printf ("Assertion failed: " "dict"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 2173, GF_LOG_ERROR, "Assertion failed: " "dict" ); } while (0); } } while (0); | |||
2174 | GF_ASSERT (op_errstr)do { if (!(op_errstr)) { do { do { if (0) printf ("Assertion failed: " "op_errstr"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 2174, GF_LOG_ERROR, "Assertion failed: " "op_errstr" ); } while (0); } } while (0); | |||
2175 | ||||
2176 | priv = THIS(*__glusterfs_this_location())->private; | |||
2177 | ||||
2178 | ret = dict_get_int32 (dict, "type", &type); | |||
2179 | if (ret < 0) | |||
| ||||
2180 | goto out; | |||
2181 | ||||
2182 | ret = dict_get_str (dict, "host-uuid", &host_uuid); | |||
2183 | if (ret < 0) | |||
2184 | goto out; | |||
2185 | ||||
2186 | ctx = glusterd_op_get_ctx (); | |||
2187 | resp_dict = ctx ? ctx : rsp_dict; | |||
2188 | GF_ASSERT (resp_dict)do { if (!(resp_dict)) { do { do { if (0) printf ("Assertion failed: " "resp_dict"); } while (0); _gf_log_callingfn ("", "glusterd-geo-rep.c" , __FUNCTION__, 2188, GF_LOG_ERROR, "Assertion failed: " "resp_dict" ); } while (0); } } while (0); | |||
2189 | ||||
2190 | if (type == GF_GSYNC_OPTION_TYPE_STATUS) { | |||
2191 | ret = glusterd_get_gsync_status (dict, op_errstr, resp_dict); | |||
2192 | goto out; | |||
2193 | } | |||
2194 | ||||
2195 | if (type == GF_GSYNC_OPTION_TYPE_ROTATE) { | |||
2196 | ret = glusterd_rotate_gsync_logs (dict, op_errstr, resp_dict); | |||
2197 | goto out; | |||
2198 | ||||
2199 | } | |||
2200 | ||||
2201 | ret = dict_get_str (dict, "slave", &slave); | |||
2202 | if (ret < 0) | |||
2203 | goto out; | |||
2204 | ||||
2205 | if (dict_get_str (dict, "master", &volname) == 0) { | |||
2206 | ret = glusterd_volinfo_find (volname, &volinfo); | |||
2207 | if (ret) { | |||
2208 | gf_log ("", GF_LOG_WARNING, "Volinfo for %s (master) not found",do { do { if (0) printf ("Volinfo for %s (master) not found", volname); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__ , 2209, GF_LOG_WARNING, "Volinfo for %s (master) not found", volname ); } while (0) | |||
2209 | volname)do { do { if (0) printf ("Volinfo for %s (master) not found", volname); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__ , 2209, GF_LOG_WARNING, "Volinfo for %s (master) not found", volname ); } while (0); | |||
2210 | goto out; | |||
2211 | } | |||
2212 | } | |||
2213 | ||||
2214 | if (type == GF_GSYNC_OPTION_TYPE_CONFIG) { | |||
2215 | ret = glusterd_gsync_configure (volinfo, slave, dict, resp_dict, | |||
2216 | op_errstr); | |||
2217 | goto out; | |||
2218 | } | |||
2219 | ||||
2220 | if (!volinfo) { | |||
2221 | ret = -1; | |||
2222 | goto out; | |||
2223 | } | |||
2224 | ||||
2225 | if (type == GF_GSYNC_OPTION_TYPE_START) { | |||
2226 | ||||
2227 | ret = glusterd_set_marker_gsync (volinfo); | |||
2228 | if (ret != 0) { | |||
2229 | gf_log ("", GF_LOG_WARNING, "marker start failed")do { do { if (0) printf ("marker start failed"); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 2229, GF_LOG_WARNING , "marker start failed"); } while (0); | |||
2230 | *op_errstr = gf_strdup ("failed to initialize indexing"); | |||
2231 | ret = -1; | |||
2232 | goto out; | |||
2233 | } | |||
2234 | ret = glusterd_store_slave_in_info(volinfo, slave, | |||
2235 | host_uuid, op_errstr); | |||
2236 | if (ret) | |||
2237 | goto out; | |||
2238 | ||||
2239 | ret = glusterd_start_gsync (volinfo, slave, host_uuid, | |||
2240 | op_errstr); | |||
2241 | } | |||
2242 | ||||
2243 | if (type == GF_GSYNC_OPTION_TYPE_STOP) { | |||
2244 | ||||
2245 | ret = glusterd_gsync_get_uuid (slave, volinfo, uuid); | |||
2246 | if (ret) { | |||
2247 | gf_log ("", GF_LOG_WARNING, GEOREP" is not set up for"do { do { if (0) printf ("geo-replication"" is not set up for" "%s(master) and %s(slave)", volname, slave); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 2248, GF_LOG_WARNING , "geo-replication"" is not set up for" "%s(master) and %s(slave)" , volname, slave); } while (0) | |||
2248 | "%s(master) and %s(slave)", volname, slave)do { do { if (0) printf ("geo-replication"" is not set up for" "%s(master) and %s(slave)", volname, slave); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 2248, GF_LOG_WARNING , "geo-replication"" is not set up for" "%s(master) and %s(slave)" , volname, slave); } while (0); | |||
2249 | *op_errstr = strdup (GEOREP"geo-replication"" is not set up"); | |||
2250 | goto out; | |||
2251 | } | |||
2252 | ||||
2253 | ret = glusterd_remove_slave_in_info(volinfo, slave, op_errstr); | |||
2254 | if (ret) | |||
2255 | goto out; | |||
2256 | ||||
2257 | if (uuid_compare (MY_UUID(__glusterd_uuid()), uuid) != 0) { | |||
2258 | goto out; | |||
2259 | } | |||
2260 | ||||
2261 | ret = stop_gsync (volname, slave, &status_msg); | |||
2262 | if (ret == 0 && status_msg) | |||
2263 | ret = dict_set_str (resp_dict, "gsync-status", | |||
2264 | status_msg); | |||
2265 | if (ret != 0) | |||
2266 | *op_errstr = gf_strdup ("internal error"); | |||
2267 | } | |||
2268 | ||||
2269 | out: | |||
2270 | gf_log ("", GF_LOG_DEBUG,"Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ("", "glusterd-geo-rep.c", __FUNCTION__, 2270, GF_LOG_DEBUG, "Returning %d", ret); } while (0); | |||
2271 | return ret; | |||
2272 | } |