File: | cli/src/cli-cmd-volume.c |
Location: | line 72, column 17 |
Description: | Value stored to 'parse_error' is never read |
1 | /* |
2 | Copyright (c) 2010-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 | #include <stdio.h> |
11 | #include <string.h> |
12 | #include <stdlib.h> |
13 | #include <stdint.h> |
14 | #include <pthread.h> |
15 | |
16 | #include <sys/socket.h> |
17 | #include <netdb.h> |
18 | #include <sys/types.h> |
19 | #include <netinet/in.h> |
20 | |
21 | #ifndef _CONFIG_H |
22 | #define _CONFIG_H |
23 | #include "config.h" |
24 | #endif |
25 | |
26 | #include "cli.h" |
27 | #include "cli-cmd.h" |
28 | #include "cli-mem-types.h" |
29 | #include "cli1-xdr.h" |
30 | #include "run.h" |
31 | |
32 | extern struct rpc_clnt *global_rpc; |
33 | |
34 | extern rpc_clnt_prog_t *cli_rpc_prog; |
35 | |
36 | int |
37 | cli_cmd_volume_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word, |
38 | const char **words, int wordcount); |
39 | |
40 | int |
41 | cli_cmd_volume_info_cbk (struct cli_state *state, struct cli_cmd_word *word, |
42 | const char **words, int wordcount) |
43 | { |
44 | int ret = -1; |
45 | rpc_clnt_procedure_t *proc = NULL((void*)0); |
46 | call_frame_t *frame = NULL((void*)0); |
47 | cli_cmd_volume_get_ctx_t ctx = {0,}; |
48 | cli_local_t *local = NULL((void*)0); |
49 | int sent = 0; |
50 | int parse_error = 0; |
51 | |
52 | proc = &cli_rpc_prog->proctable[GLUSTER_CLI_GET_VOLUME]; |
53 | |
54 | frame = create_frame (THIS(*__glusterfs_this_location()), THIS(*__glusterfs_this_location())->ctx->pool); |
55 | if (!frame) |
56 | goto out; |
57 | |
58 | if ((wordcount == 2) || (wordcount == 3 && |
59 | !strcmp (words[2], "all"))) { |
60 | ctx.flags = GF_CLI_GET_NEXT_VOLUME; |
61 | proc = &cli_rpc_prog->proctable[GLUSTER_CLI_GET_NEXT_VOLUME]; |
62 | } else if (wordcount == 3) { |
63 | ctx.flags = GF_CLI_GET_VOLUME; |
64 | ctx.volname = (char *)words[2]; |
65 | if (strlen (ctx.volname) > 1024) { |
66 | cli_out ("Invalid volume name")do { do { if (0) printf ("Invalid volume name"); } while (0); _cli_out("Invalid volume name"); } while (0); |
67 | goto out; |
68 | } |
69 | proc = &cli_rpc_prog->proctable[GLUSTER_CLI_GET_VOLUME]; |
70 | } else { |
71 | cli_usage_out (word->pattern); |
72 | parse_error = 1; |
Value stored to 'parse_error' is never read | |
73 | return -1; |
74 | } |
75 | |
76 | local = cli_local_get (); |
77 | |
78 | if (!local) |
79 | goto out; |
80 | |
81 | local->get_vol.flags = ctx.flags; |
82 | if (ctx.volname) |
83 | local->get_vol.volname = gf_strdup (ctx.volname); |
84 | |
85 | frame->local = local; |
86 | |
87 | if (proc->fn) { |
88 | ret = proc->fn (frame, THIS(*__glusterfs_this_location()), &ctx); |
89 | } |
90 | |
91 | out: |
92 | if (ret) { |
93 | cli_cmd_sent_status_get (&sent); |
94 | if ((sent == 0) && (parse_error == 0)) |
95 | cli_out ("Getting Volume information failed!")do { do { if (0) printf ("Getting Volume information failed!" ); } while (0); _cli_out("Getting Volume information failed!" ); } while (0); |
96 | } |
97 | |
98 | CLI_STACK_DESTROY (frame)do { if (frame) { if (frame->local) { do { do { if (0) printf ("frame->local " "is not NULL (%p)", frame->local); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__, 98, GF_LOG_DEBUG , "frame->local " "is not NULL (%p)", frame->local); } while (0); cli_local_wipe (frame->local); frame->local = ((void *)0); } STACK_DESTROY (frame->root); } } while (0);; |
99 | |
100 | return ret; |
101 | |
102 | } |
103 | |
104 | int |
105 | cli_cmd_sync_volume_cbk (struct cli_state *state, struct cli_cmd_word *word, |
106 | const char **words, int wordcount) |
107 | { |
108 | int ret = -1; |
109 | rpc_clnt_procedure_t *proc = NULL((void*)0); |
110 | call_frame_t *frame = NULL((void*)0); |
111 | int sent = 0; |
112 | int parse_error = 0; |
113 | dict_t *dict = NULL((void*)0); |
114 | cli_local_t *local = NULL((void*)0); |
115 | gf_answer_t answer = GF_ANSWER_NO; |
116 | const char *question = "Sync volume may make data " |
117 | "inaccessible while the sync " |
118 | "is in progress. Do you want " |
119 | "to continue?"; |
120 | |
121 | if ((wordcount < 3) || (wordcount > 4)) { |
122 | cli_usage_out (word->pattern); |
123 | parse_error = 1; |
124 | goto out; |
125 | } |
126 | |
127 | dict = dict_new (); |
128 | if (!dict) |
129 | goto out; |
130 | |
131 | if ((wordcount == 3) || !strcmp(words[3], "all")) { |
132 | ret = dict_set_int32 (dict, "flags", (int32_t) |
133 | GF_CLI_SYNC_ALL); |
134 | if (ret) { |
135 | gf_log (THIS->name, GF_LOG_ERROR, "failed to set"do { do { if (0) printf ("failed to set" "flag"); } while (0) ; _gf_log ((*__glusterfs_this_location())->name, "cli-cmd-volume.c" , __FUNCTION__, 136, GF_LOG_ERROR, "failed to set" "flag"); } while (0) |
136 | "flag")do { do { if (0) printf ("failed to set" "flag"); } while (0) ; _gf_log ((*__glusterfs_this_location())->name, "cli-cmd-volume.c" , __FUNCTION__, 136, GF_LOG_ERROR, "failed to set" "flag"); } while (0); |
137 | goto out; |
138 | } |
139 | } else { |
140 | ret = dict_set_str (dict, "volname", (char *) words[3]); |
141 | if (ret) { |
142 | gf_log (THIS->name, GF_LOG_ERROR, "failed to set "do { do { if (0) printf ("failed to set " "volume"); } while ( 0); _gf_log ((*__glusterfs_this_location())->name, "cli-cmd-volume.c" , __FUNCTION__, 143, GF_LOG_ERROR, "failed to set " "volume") ; } while (0) |
143 | "volume")do { do { if (0) printf ("failed to set " "volume"); } while ( 0); _gf_log ((*__glusterfs_this_location())->name, "cli-cmd-volume.c" , __FUNCTION__, 143, GF_LOG_ERROR, "failed to set " "volume") ; } while (0); |
144 | goto out; |
145 | } |
146 | } |
147 | |
148 | ret = dict_set_str (dict, "hostname", (char *) words[2]); |
149 | if (ret) { |
150 | gf_log (THIS->name, GF_LOG_ERROR, "failed to set hostname")do { do { if (0) printf ("failed to set hostname"); } while ( 0); _gf_log ((*__glusterfs_this_location())->name, "cli-cmd-volume.c" , __FUNCTION__, 150, GF_LOG_ERROR, "failed to set hostname"); } while (0); |
151 | goto out; |
152 | } |
153 | |
154 | if (!(state->mode & GLUSTER_MODE_SCRIPT(1 << 0))) { |
155 | answer = cli_cmd_get_confirmation (state, question); |
156 | if (GF_ANSWER_NO == answer) { |
157 | ret = 0; |
158 | goto out; |
159 | } |
160 | } |
161 | |
162 | proc = &cli_rpc_prog->proctable[GLUSTER_CLI_SYNC_VOLUME]; |
163 | |
164 | frame = create_frame (THIS(*__glusterfs_this_location()), THIS(*__glusterfs_this_location())->ctx->pool); |
165 | if (!frame) |
166 | goto out; |
167 | |
168 | CLI_LOCAL_INIT (local, words, frame, dict)do { local = cli_local_get (); if (local) { local->words = words; if (dict) local->dict = dict; if (frame) frame-> local = local; } } while (0); |
169 | |
170 | if (proc->fn) { |
171 | ret = proc->fn (frame, THIS(*__glusterfs_this_location()), dict); |
172 | } |
173 | |
174 | out: |
175 | if (ret) { |
176 | cli_cmd_sent_status_get (&sent); |
177 | if ((sent == 0) && (parse_error == 0)) |
178 | cli_out ("Volume sync failed")do { do { if (0) printf ("Volume sync failed"); } while (0); _cli_out ("Volume sync failed"); } while (0); |
179 | } |
180 | |
181 | CLI_STACK_DESTROY (frame)do { if (frame) { if (frame->local) { do { do { if (0) printf ("frame->local " "is not NULL (%p)", frame->local); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__, 181, GF_LOG_DEBUG , "frame->local " "is not NULL (%p)", frame->local); } while (0); cli_local_wipe (frame->local); frame->local = ((void *)0); } STACK_DESTROY (frame->root); } } while (0);; |
182 | |
183 | return ret; |
184 | } |
185 | |
186 | gf_ai_compare_t |
187 | cli_cmd_compare_addrinfo (struct addrinfo *first, struct addrinfo *next) |
188 | { |
189 | int ret = -1; |
190 | struct addrinfo *tmp1 = NULL((void*)0); |
191 | struct addrinfo *tmp2 = NULL((void*)0); |
192 | char firstip[NI_MAXHOST1025] = {0.}; |
193 | char nextip[NI_MAXHOST1025] = {0,}; |
194 | |
195 | for (tmp1 = first; tmp1 != NULL((void*)0); tmp1 = tmp1->ai_next) { |
196 | ret = getnameinfo (tmp1->ai_addr, tmp1->ai_addrlen, firstip, |
197 | NI_MAXHOST1025, NULL((void*)0), 0, NI_NUMERICHOST1); |
198 | if (ret) |
199 | return GF_AI_COMPARE_ERROR; |
200 | for (tmp2 = next; tmp2 != NULL((void*)0); tmp2 = tmp2->ai_next) { |
201 | ret = getnameinfo (tmp2->ai_addr, tmp2->ai_addrlen, nextip, |
202 | NI_MAXHOST1025, NULL((void*)0), 0, NI_NUMERICHOST1); |
203 | if (ret) |
204 | return GF_AI_COMPARE_ERROR; |
205 | if (!strcmp (firstip, nextip)) { |
206 | return GF_AI_COMPARE_MATCH; |
207 | } |
208 | } |
209 | } |
210 | return GF_AI_COMPARE_NO_MATCH; |
211 | } |
212 | |
213 | /* Check for non optimal brick order for replicate : |
214 | * Checks if bricks belonging to a replicate volume |
215 | * are present on the same server |
216 | */ |
217 | int32_t |
218 | cli_cmd_check_brick_order (struct cli_state *state, const char *bricks, |
219 | int brick_count, int sub_count) |
220 | { |
221 | int ret = -1; |
222 | int i = 0; |
223 | int j = 0; |
224 | int k = 0; |
225 | addrinfo_list_t *ai_list = NULL((void*)0); |
226 | addrinfo_list_t *ai_list_tmp1 = NULL((void*)0); |
227 | addrinfo_list_t *ai_list_tmp2 = NULL((void*)0); |
228 | char *brick = NULL((void*)0); |
229 | char *brick_list = NULL((void*)0); |
230 | char *brick_list_dup = NULL((void*)0); |
231 | char *tmpptr = NULL((void*)0); |
232 | struct addrinfo *ai_info = NULL((void*)0); |
233 | gf_answer_t answer = GF_ANSWER_NO; |
234 | const char *failed_question = NULL((void*)0); |
235 | const char *found_question = NULL((void*)0); |
236 | failed_question = "Failed to perform brick order check. " |
237 | "Do you want to continue creating the volume? "; |
238 | found_question = "Multiple bricks of a replicate volume are present" |
239 | " on the same server. This setup is not optimal.\n" |
240 | "Do you still want to continue creating the volume? "; |
241 | |
242 | GF_ASSERT (bricks)do { if (!(bricks)) { do { do { if (0) printf ("Assertion failed: " "bricks"); } while (0); _gf_log_callingfn ("", "cli-cmd-volume.c" , __FUNCTION__, 242, GF_LOG_ERROR, "Assertion failed: " "bricks" ); } while (0); } } while (0); |
243 | GF_ASSERT (brick_count > 0)do { if (!(brick_count > 0)) { do { do { if (0) printf ("Assertion failed: " "brick_count > 0"); } while (0); _gf_log_callingfn ("", "cli-cmd-volume.c" , __FUNCTION__, 243, GF_LOG_ERROR, "Assertion failed: " "brick_count > 0" ); } while (0); } } while (0); |
244 | GF_ASSERT (sub_count > 0)do { if (!(sub_count > 0)) { do { do { if (0) printf ("Assertion failed: " "sub_count > 0"); } while (0); _gf_log_callingfn ("", "cli-cmd-volume.c" , __FUNCTION__, 244, GF_LOG_ERROR, "Assertion failed: " "sub_count > 0" ); } while (0); } } while (0); |
245 | |
246 | ai_list = malloc (sizeof (addrinfo_list_t)); |
247 | ai_list->info = NULL((void*)0); |
248 | INIT_LIST_HEAD (&ai_list->list)do { (&ai_list->list)->next = (&ai_list->list )->prev = &ai_list->list; } while (0); |
249 | brick_list = gf_strdup (bricks); |
250 | if (brick_list == NULL((void*)0)) { |
251 | gf_log ("cli", GF_LOG_DEBUG, "failed to allocate memory")do { do { if (0) printf ("failed to allocate memory"); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__, 251, GF_LOG_DEBUG , "failed to allocate memory"); } while (0); |
252 | goto check_failed; |
253 | } |
254 | brick_list_dup = brick_list; |
255 | /* Resolve hostnames and get addrinfo */ |
256 | while (i < brick_count) { |
257 | ++i; |
258 | brick = strtok_r (brick_list, " \n", &tmpptr); |
259 | brick_list = tmpptr; |
260 | if (brick == NULL((void*)0)) |
261 | goto check_failed; |
262 | brick = strtok_r (brick, ":", &tmpptr); |
263 | if (brick == NULL((void*)0)) |
264 | goto check_failed; |
265 | ret = getaddrinfo (brick, NULL((void*)0), NULL((void*)0), &ai_info); |
266 | if (ret) |
267 | goto check_failed; |
268 | ai_list_tmp1 = malloc (sizeof (addrinfo_list_t)); |
269 | if (ai_list_tmp1 == NULL((void*)0)) |
270 | goto check_failed; |
271 | ai_list_tmp1->info = ai_info; |
272 | list_add_tail (&ai_list_tmp1->list, &ai_list->list); |
273 | ai_list_tmp1 = NULL((void*)0); |
274 | } |
275 | |
276 | i = 0; |
277 | ai_list_tmp1 = list_entry (ai_list->list.next, addrinfo_list_t, list)((addrinfo_list_t *)((char *)(ai_list->list.next)-(unsigned long)(&((addrinfo_list_t *)0)->list))); |
278 | |
279 | /* Check for bad brick order */ |
280 | while (i < brick_count) { |
281 | ++i; |
282 | ai_info = ai_list_tmp1->info; |
283 | ai_list_tmp1 = list_entry (ai_list_tmp1->list.next,((addrinfo_list_t *)((char *)(ai_list_tmp1->list.next)-(unsigned long)(&((addrinfo_list_t *)0)->list))) |
284 | addrinfo_list_t, list)((addrinfo_list_t *)((char *)(ai_list_tmp1->list.next)-(unsigned long)(&((addrinfo_list_t *)0)->list))); |
285 | if ( 0 == i % sub_count) { |
286 | j = 0; |
287 | continue; |
288 | } |
289 | ai_list_tmp2 = ai_list_tmp1; |
290 | k = j; |
291 | while (k < sub_count - 1) { |
292 | ++k; |
293 | ret = cli_cmd_compare_addrinfo (ai_info, |
294 | ai_list_tmp2->info); |
295 | if (GF_AI_COMPARE_ERROR == ret) |
296 | goto check_failed; |
297 | if (GF_AI_COMPARE_MATCH == ret) |
298 | goto found_bad_brick_order; |
299 | ai_list_tmp2 = list_entry (ai_list_tmp2->list.next,((addrinfo_list_t *)((char *)(ai_list_tmp2->list.next)-(unsigned long)(&((addrinfo_list_t *)0)->list))) |
300 | addrinfo_list_t, list)((addrinfo_list_t *)((char *)(ai_list_tmp2->list.next)-(unsigned long)(&((addrinfo_list_t *)0)->list))); |
301 | } |
302 | ++j; |
303 | } |
304 | gf_log ("cli", GF_LOG_INFO, "Brick order okay")do { do { if (0) printf ("Brick order okay"); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__, 304, GF_LOG_INFO, "Brick order okay" ); } while (0); |
305 | ret = 0; |
306 | goto out; |
307 | |
308 | check_failed: |
309 | gf_log ("cli", GF_LOG_INFO, "Failed bad brick order check")do { do { if (0) printf ("Failed bad brick order check"); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__, 309, GF_LOG_INFO , "Failed bad brick order check"); } while (0); |
310 | answer = cli_cmd_get_confirmation(state, failed_question); |
311 | if (GF_ANSWER_YES == answer) |
312 | ret = 0; |
313 | goto out; |
314 | |
315 | found_bad_brick_order: |
316 | gf_log ("cli", GF_LOG_INFO, "Bad brick order found")do { do { if (0) printf ("Bad brick order found"); } while (0 ); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__, 316, GF_LOG_INFO , "Bad brick order found"); } while (0); |
317 | answer = cli_cmd_get_confirmation (state, found_question); |
318 | if (GF_ANSWER_YES == answer) |
319 | ret = 0; |
320 | out: |
321 | ai_list_tmp2 = NULL((void*)0); |
322 | i = 0; |
323 | GF_FREE (brick_list_dup)__gf_free (brick_list_dup); |
324 | list_for_each_entry (ai_list_tmp1, &ai_list->list, list)for (ai_list_tmp1 = ((typeof(*ai_list_tmp1) *)((char *)((& ai_list->list)->next)-(unsigned long)(&((typeof(*ai_list_tmp1 ) *)0)->list))); &ai_list_tmp1->list != (&ai_list ->list); ai_list_tmp1 = ((typeof(*ai_list_tmp1) *)((char * )(ai_list_tmp1->list.next)-(unsigned long)(&((typeof(* ai_list_tmp1) *)0)->list)))) { |
325 | if (ai_list_tmp1->info) |
326 | freeaddrinfo (ai_list_tmp1->info); |
327 | free (ai_list_tmp2); |
328 | ai_list_tmp2 = ai_list_tmp1; |
329 | } |
330 | free (ai_list_tmp2); |
331 | return ret; |
332 | } |
333 | |
334 | int |
335 | cli_cmd_volume_create_cbk (struct cli_state *state, struct cli_cmd_word *word, |
336 | const char **words, int wordcount) |
337 | { |
338 | int ret = -1; |
339 | rpc_clnt_procedure_t *proc = NULL((void*)0); |
340 | call_frame_t *frame = NULL((void*)0); |
341 | dict_t *options = NULL((void*)0); |
342 | int sent = 0; |
343 | int parse_error = 0; |
344 | char *brick_list = NULL((void*)0); |
345 | int32_t brick_count = 0; |
346 | int32_t sub_count = 0; |
347 | int32_t type = GF_CLUSTER_TYPE_NONE; |
348 | cli_local_t *local = NULL((void*)0); |
349 | |
350 | proc = &cli_rpc_prog->proctable[GLUSTER_CLI_CREATE_VOLUME]; |
351 | |
352 | frame = create_frame (THIS(*__glusterfs_this_location()), THIS(*__glusterfs_this_location())->ctx->pool); |
353 | if (!frame) |
354 | goto out; |
355 | |
356 | ret = cli_cmd_volume_create_parse (words, wordcount, &options); |
357 | |
358 | if (ret) { |
359 | cli_usage_out (word->pattern); |
360 | parse_error = 1; |
361 | goto out; |
362 | } |
363 | /*Check brick order if type is replicate*/ |
364 | ret = dict_get_int32 (options, "type", &type); |
365 | if (ret) { |
366 | gf_log ("cli", GF_LOG_ERROR, "Could not get brick type")do { do { if (0) printf ("Could not get brick type"); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__, 366, GF_LOG_ERROR , "Could not get brick type"); } while (0); |
367 | goto out; |
368 | } |
369 | if ((type == GF_CLUSTER_TYPE_REPLICATE) || |
370 | (type == GF_CLUSTER_TYPE_STRIPE_REPLICATE)) { |
371 | if ((ret = dict_get_str (options, "bricks", &brick_list)) != 0) { |
372 | gf_log ("cli", GF_LOG_ERROR, "Replica bricks check : "do { do { if (0) printf ("Replica bricks check : " "Could not retrieve bricks list" ); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__ , 373, GF_LOG_ERROR, "Replica bricks check : " "Could not retrieve bricks list" ); } while (0) |
373 | "Could not retrieve bricks list")do { do { if (0) printf ("Replica bricks check : " "Could not retrieve bricks list" ); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__ , 373, GF_LOG_ERROR, "Replica bricks check : " "Could not retrieve bricks list" ); } while (0); |
374 | goto out; |
375 | } |
376 | if ((ret = dict_get_int32 (options, "count", &brick_count)) != 0) { |
377 | gf_log ("cli", GF_LOG_ERROR, "Replica bricks check : "do { do { if (0) printf ("Replica bricks check : " "Could not retrieve brick count" ); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__ , 378, GF_LOG_ERROR, "Replica bricks check : " "Could not retrieve brick count" ); } while (0) |
378 | "Could not retrieve brick count")do { do { if (0) printf ("Replica bricks check : " "Could not retrieve brick count" ); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__ , 378, GF_LOG_ERROR, "Replica bricks check : " "Could not retrieve brick count" ); } while (0); |
379 | goto out; |
380 | } |
381 | if ((ret = dict_get_int32 (options, "replica-count", &sub_count)) != 0) { |
382 | gf_log ("cli", GF_LOG_ERROR, "Replica bricks check : "do { do { if (0) printf ("Replica bricks check : " "Could not retrieve replica count" ); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__ , 383, GF_LOG_ERROR, "Replica bricks check : " "Could not retrieve replica count" ); } while (0) |
383 | "Could not retrieve replica count")do { do { if (0) printf ("Replica bricks check : " "Could not retrieve replica count" ); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__ , 383, GF_LOG_ERROR, "Replica bricks check : " "Could not retrieve replica count" ); } while (0); |
384 | goto out; |
385 | } |
386 | gf_log ("cli", GF_LOG_INFO, "Replicate cluster type found."do { do { if (0) printf ("Replicate cluster type found." " Checking brick order." ); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__ , 387, GF_LOG_INFO, "Replicate cluster type found." " Checking brick order." ); } while (0) |
387 | " Checking brick order.")do { do { if (0) printf ("Replicate cluster type found." " Checking brick order." ); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__ , 387, GF_LOG_INFO, "Replicate cluster type found." " Checking brick order." ); } while (0); |
388 | ret = cli_cmd_check_brick_order (state, brick_list, brick_count, sub_count); |
389 | if (ret) { |
390 | gf_log("cli", GF_LOG_INFO, "Not creating volume because of bad brick order")do { do { if (0) printf ("Not creating volume because of bad brick order" ); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__ , 390, GF_LOG_INFO, "Not creating volume because of bad brick order" ); } while (0); |
391 | goto out; |
392 | } |
393 | } |
394 | |
395 | if (state->mode & GLUSTER_MODE_SCRIPT(1 << 0)) { |
396 | ret = dict_set_int32 (options, "force", _gf_true); |
397 | if (ret) { |
398 | gf_log ("cli", GF_LOG_ERROR, "Failed to set force "do { do { if (0) printf ("Failed to set force " "option"); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__, 399, GF_LOG_ERROR , "Failed to set force " "option"); } while (0) |
399 | "option")do { do { if (0) printf ("Failed to set force " "option"); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__, 399, GF_LOG_ERROR , "Failed to set force " "option"); } while (0); |
400 | goto out; |
401 | } |
402 | } |
403 | |
404 | CLI_LOCAL_INIT (local, words, frame, options)do { local = cli_local_get (); if (local) { local->words = words; if (options) local->dict = options; if (frame) frame ->local = local; } } while (0); |
405 | |
406 | if (proc->fn) { |
407 | ret = proc->fn (frame, THIS(*__glusterfs_this_location()), options); |
408 | } |
409 | |
410 | out: |
411 | if (ret) { |
412 | cli_cmd_sent_status_get (&sent); |
413 | if ((sent == 0) && (parse_error == 0)) |
414 | cli_out ("Volume create failed")do { do { if (0) printf ("Volume create failed"); } while (0) ; _cli_out("Volume create failed"); } while (0); |
415 | } |
416 | |
417 | CLI_STACK_DESTROY (frame)do { if (frame) { if (frame->local) { do { do { if (0) printf ("frame->local " "is not NULL (%p)", frame->local); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__, 417, GF_LOG_DEBUG , "frame->local " "is not NULL (%p)", frame->local); } while (0); cli_local_wipe (frame->local); frame->local = ((void *)0); } STACK_DESTROY (frame->root); } } while (0);; |
418 | |
419 | return ret; |
420 | } |
421 | |
422 | |
423 | int |
424 | cli_cmd_volume_delete_cbk (struct cli_state *state, struct cli_cmd_word *word, |
425 | const char **words, int wordcount) |
426 | { |
427 | int ret = -1; |
428 | rpc_clnt_procedure_t *proc = NULL((void*)0); |
429 | call_frame_t *frame = NULL((void*)0); |
430 | char *volname = NULL((void*)0); |
431 | gf_answer_t answer = GF_ANSWER_NO; |
432 | const char *question = NULL((void*)0); |
433 | int sent = 0; |
434 | int parse_error = 0; |
435 | cli_local_t *local = NULL((void*)0); |
436 | dict_t *dict = NULL((void*)0); |
437 | |
438 | question = "Deleting volume will erase all information about the volume. " |
439 | "Do you want to continue?"; |
440 | proc = &cli_rpc_prog->proctable[GLUSTER_CLI_DELETE_VOLUME]; |
441 | |
442 | frame = create_frame (THIS(*__glusterfs_this_location()), THIS(*__glusterfs_this_location())->ctx->pool); |
443 | if (!frame) |
444 | goto out; |
445 | |
446 | dict = dict_new (); |
447 | if (!dict) |
448 | goto out; |
449 | |
450 | if (wordcount != 3) { |
451 | cli_usage_out (word->pattern); |
452 | parse_error = 1; |
453 | goto out; |
454 | } |
455 | |
456 | answer = cli_cmd_get_confirmation (state, question); |
457 | |
458 | if (GF_ANSWER_NO == answer) { |
459 | ret = 0; |
460 | goto out; |
461 | } |
462 | |
463 | volname = (char *)words[2]; |
464 | |
465 | ret = dict_set_str (dict, "volname", volname); |
466 | |
467 | if (ret) { |
468 | gf_log (THIS->name, GF_LOG_WARNING, "dict set failed")do { do { if (0) printf ("dict set failed"); } while (0); _gf_log ((*__glusterfs_this_location())->name, "cli-cmd-volume.c" , __FUNCTION__, 468, GF_LOG_WARNING, "dict set failed"); } while (0); |
469 | goto out; |
470 | } |
471 | |
472 | CLI_LOCAL_INIT (local, words, frame, dict)do { local = cli_local_get (); if (local) { local->words = words; if (dict) local->dict = dict; if (frame) frame-> local = local; } } while (0); |
473 | |
474 | if (proc->fn) { |
475 | ret = proc->fn (frame, THIS(*__glusterfs_this_location()), dict); |
476 | } |
477 | |
478 | out: |
479 | if (ret) { |
480 | cli_cmd_sent_status_get (&sent); |
481 | if ((sent == 0) && (parse_error == 0)) |
482 | cli_out ("Volume delete failed")do { do { if (0) printf ("Volume delete failed"); } while (0) ; _cli_out("Volume delete failed"); } while (0); |
483 | } |
484 | |
485 | CLI_STACK_DESTROY (frame)do { if (frame) { if (frame->local) { do { do { if (0) printf ("frame->local " "is not NULL (%p)", frame->local); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__, 485, GF_LOG_DEBUG , "frame->local " "is not NULL (%p)", frame->local); } while (0); cli_local_wipe (frame->local); frame->local = ((void *)0); } STACK_DESTROY (frame->root); } } while (0);; |
486 | |
487 | return ret; |
488 | } |
489 | |
490 | int |
491 | cli_cmd_volume_start_cbk (struct cli_state *state, struct cli_cmd_word *word, |
492 | const char **words, int wordcount) |
493 | { |
494 | int ret = -1; |
495 | rpc_clnt_procedure_t *proc = NULL((void*)0); |
496 | call_frame_t *frame = NULL((void*)0); |
497 | int sent = 0; |
498 | int parse_error = 0; |
499 | dict_t *dict = NULL((void*)0); |
500 | int flags = 0; |
501 | cli_local_t *local = NULL((void*)0); |
502 | |
503 | frame = create_frame (THIS(*__glusterfs_this_location()), THIS(*__glusterfs_this_location())->ctx->pool); |
504 | if (!frame) |
505 | goto out; |
506 | |
507 | if (wordcount < 3 || wordcount > 4) { |
508 | cli_usage_out (word->pattern); |
509 | parse_error = 1; |
510 | goto out; |
511 | } |
512 | |
513 | dict = dict_new (); |
514 | if (!dict) { |
515 | goto out; |
516 | } |
517 | |
518 | if (!words[2]) |
519 | goto out; |
520 | |
521 | ret = dict_set_str (dict, "volname", (char *)words[2]); |
522 | if (ret) { |
523 | gf_log (THIS->name, GF_LOG_ERROR, "dict set failed")do { do { if (0) printf ("dict set failed"); } while (0); _gf_log ((*__glusterfs_this_location())->name, "cli-cmd-volume.c" , __FUNCTION__, 523, GF_LOG_ERROR, "dict set failed"); } while (0); |
524 | goto out; |
525 | } |
526 | |
527 | if (wordcount == 4) { |
528 | if (!strcmp("force", words[3])) { |
529 | flags |= GF_CLI_FLAG_OP_FORCE; |
530 | } else { |
531 | ret = -1; |
532 | cli_usage_out (word->pattern); |
533 | parse_error = 1; |
534 | goto out; |
535 | } |
536 | } |
537 | ret = dict_set_int32 (dict, "flags", flags); |
538 | if (ret) { |
539 | gf_log (THIS->name, GF_LOG_ERROR,do { do { if (0) printf ("dict set failed"); } while (0); _gf_log ((*__glusterfs_this_location())->name, "cli-cmd-volume.c" , __FUNCTION__, 540, GF_LOG_ERROR, "dict set failed"); } while (0) |
540 | "dict set failed")do { do { if (0) printf ("dict set failed"); } while (0); _gf_log ((*__glusterfs_this_location())->name, "cli-cmd-volume.c" , __FUNCTION__, 540, GF_LOG_ERROR, "dict set failed"); } while (0); |
541 | goto out; |
542 | } |
543 | |
544 | if (ret < 0) { |
545 | gf_log (THIS->name, GF_LOG_ERROR,do { do { if (0) printf ("failed to serialize dict"); } while (0); _gf_log ((*__glusterfs_this_location())->name, "cli-cmd-volume.c" , __FUNCTION__, 546, GF_LOG_ERROR, "failed to serialize dict" ); } while (0) |
546 | "failed to serialize dict")do { do { if (0) printf ("failed to serialize dict"); } while (0); _gf_log ((*__glusterfs_this_location())->name, "cli-cmd-volume.c" , __FUNCTION__, 546, GF_LOG_ERROR, "failed to serialize dict" ); } while (0); |
547 | goto out; |
548 | } |
549 | |
550 | proc = &cli_rpc_prog->proctable[GLUSTER_CLI_START_VOLUME]; |
551 | |
552 | CLI_LOCAL_INIT (local, words, frame, dict)do { local = cli_local_get (); if (local) { local->words = words; if (dict) local->dict = dict; if (frame) frame-> local = local; } } while (0); |
553 | |
554 | if (proc->fn) { |
555 | ret = proc->fn (frame, THIS(*__glusterfs_this_location()), dict); |
556 | } |
557 | |
558 | out: |
559 | if (ret) { |
560 | cli_cmd_sent_status_get (&sent); |
561 | if ((sent == 0) && (parse_error == 0)) |
562 | cli_out ("Volume start failed")do { do { if (0) printf ("Volume start failed"); } while (0); _cli_out("Volume start failed"); } while (0); |
563 | } |
564 | |
565 | CLI_STACK_DESTROY (frame)do { if (frame) { if (frame->local) { do { do { if (0) printf ("frame->local " "is not NULL (%p)", frame->local); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__, 565, GF_LOG_DEBUG , "frame->local " "is not NULL (%p)", frame->local); } while (0); cli_local_wipe (frame->local); frame->local = ((void *)0); } STACK_DESTROY (frame->root); } } while (0);; |
566 | |
567 | return ret; |
568 | } |
569 | |
570 | gf_answer_t |
571 | cli_cmd_get_confirmation (struct cli_state *state, const char *question) |
572 | { |
573 | char answer[5] = {'\0', }; |
574 | char flush = '\0'; |
575 | size_t len; |
576 | |
577 | if (state->mode & GLUSTER_MODE_SCRIPT(1 << 0)) |
578 | return GF_ANSWER_YES; |
579 | |
580 | printf ("%s (y/n) ", question); |
581 | |
582 | if (fgets (answer, 4, stdinstdin) == NULL((void*)0)) { |
583 | cli_out("gluster cli read error")do { do { if (0) printf ("gluster cli read error"); } while ( 0); _cli_out("gluster cli read error"); } while (0); |
584 | goto out; |
585 | } |
586 | |
587 | len = strlen (answer); |
588 | |
589 | if (len && answer [len - 1] == '\n'){ |
590 | answer [--len] = '\0'; |
591 | } else { |
592 | do{ |
593 | flush = getchar (); |
594 | }while (flush != '\n'); |
595 | } |
596 | |
597 | if (len > 3) |
598 | goto out; |
599 | |
600 | if (!strcasecmp (answer, "y") || !strcasecmp (answer, "yes")) |
601 | return GF_ANSWER_YES; |
602 | |
603 | else if (!strcasecmp (answer, "n") || !strcasecmp (answer, "no")) |
604 | return GF_ANSWER_NO; |
605 | |
606 | out: |
607 | cli_out ("Invalid input, please enter y/n")do { do { if (0) printf ("Invalid input, please enter y/n"); } while (0); _cli_out("Invalid input, please enter y/n"); } while (0); |
608 | |
609 | return GF_ANSWER_NO; |
610 | } |
611 | |
612 | int |
613 | cli_cmd_volume_stop_cbk (struct cli_state *state, struct cli_cmd_word *word, |
614 | const char **words, int wordcount) |
615 | { |
616 | int ret = -1; |
617 | rpc_clnt_procedure_t *proc = NULL((void*)0); |
618 | call_frame_t *frame = NULL((void*)0); |
619 | int flags = 0; |
620 | gf_answer_t answer = GF_ANSWER_NO; |
621 | int sent = 0; |
622 | int parse_error = 0; |
623 | dict_t *dict = NULL((void*)0); |
624 | char *volname = NULL((void*)0); |
625 | cli_local_t *local = NULL((void*)0); |
626 | |
627 | const char *question = "Stopping volume will make its data inaccessible. " |
628 | "Do you want to continue?"; |
629 | |
630 | frame = create_frame (THIS(*__glusterfs_this_location()), THIS(*__glusterfs_this_location())->ctx->pool); |
631 | if (!frame) |
632 | goto out; |
633 | |
634 | if (wordcount < 3 || wordcount > 4) { |
635 | cli_usage_out (word->pattern); |
636 | parse_error = 1; |
637 | goto out; |
638 | } |
639 | |
640 | volname = (char*) words[2]; |
641 | |
642 | dict = dict_new (); |
643 | ret = dict_set_str (dict, "volname", volname); |
644 | if (ret) { |
645 | gf_log (THIS->name, GF_LOG_ERROR, "dict set failed")do { do { if (0) printf ("dict set failed"); } while (0); _gf_log ((*__glusterfs_this_location())->name, "cli-cmd-volume.c" , __FUNCTION__, 645, GF_LOG_ERROR, "dict set failed"); } while (0); |
646 | goto out; |
647 | } |
648 | |
649 | if (wordcount == 4) { |
650 | if (!strcmp("force", words[3])) { |
651 | flags |= GF_CLI_FLAG_OP_FORCE; |
652 | } else { |
653 | ret = -1; |
654 | cli_usage_out (word->pattern); |
655 | parse_error = 1; |
656 | goto out; |
657 | } |
658 | } |
659 | ret = dict_set_int32 (dict, "flags", flags); |
660 | if (ret) { |
661 | gf_log (THIS->name, GF_LOG_ERROR,do { do { if (0) printf ("dict set failed"); } while (0); _gf_log ((*__glusterfs_this_location())->name, "cli-cmd-volume.c" , __FUNCTION__, 662, GF_LOG_ERROR, "dict set failed"); } while (0) |
662 | "dict set failed")do { do { if (0) printf ("dict set failed"); } while (0); _gf_log ((*__glusterfs_this_location())->name, "cli-cmd-volume.c" , __FUNCTION__, 662, GF_LOG_ERROR, "dict set failed"); } while (0); |
663 | goto out; |
664 | } |
665 | |
666 | answer = cli_cmd_get_confirmation (state, question); |
667 | |
668 | if (GF_ANSWER_NO == answer) { |
669 | ret = 0; |
670 | goto out; |
671 | } |
672 | |
673 | proc = &cli_rpc_prog->proctable[GLUSTER_CLI_STOP_VOLUME]; |
674 | |
675 | CLI_LOCAL_INIT (local, words, frame, dict)do { local = cli_local_get (); if (local) { local->words = words; if (dict) local->dict = dict; if (frame) frame-> local = local; } } while (0); |
676 | |
677 | if (proc->fn) { |
678 | ret = proc->fn (frame, THIS(*__glusterfs_this_location()), dict); |
679 | } |
680 | |
681 | out: |
682 | if (ret) { |
683 | cli_cmd_sent_status_get (&sent); |
684 | if ((sent == 0) && (parse_error == 0)) |
685 | cli_out ("Volume stop on '%s' failed", volname)do { do { if (0) printf ("Volume stop on '%s' failed", volname ); } while (0); _cli_out("Volume stop on '%s' failed", volname ); } while (0); |
686 | } |
687 | |
688 | CLI_STACK_DESTROY (frame)do { if (frame) { if (frame->local) { do { do { if (0) printf ("frame->local " "is not NULL (%p)", frame->local); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__, 688, GF_LOG_DEBUG , "frame->local " "is not NULL (%p)", frame->local); } while (0); cli_local_wipe (frame->local); frame->local = ((void *)0); } STACK_DESTROY (frame->root); } } while (0);; |
689 | |
690 | return ret; |
691 | } |
692 | |
693 | |
694 | int |
695 | cli_cmd_volume_rename_cbk (struct cli_state *state, struct cli_cmd_word *word, |
696 | const char **words, int wordcount) |
697 | { |
698 | int ret = -1; |
699 | rpc_clnt_procedure_t *proc = NULL((void*)0); |
700 | call_frame_t *frame = NULL((void*)0); |
701 | dict_t *dict = NULL((void*)0); |
702 | int sent = 0; |
703 | int parse_error = 0; |
704 | |
705 | |
706 | frame = create_frame (THIS(*__glusterfs_this_location()), THIS(*__glusterfs_this_location())->ctx->pool); |
707 | if (!frame) |
708 | goto out; |
709 | |
710 | dict = dict_new (); |
711 | if (!dict) |
712 | goto out; |
713 | |
714 | if (wordcount != 4) { |
715 | cli_usage_out (word->pattern); |
716 | parse_error = 1; |
717 | goto out; |
718 | } |
719 | |
720 | ret = dict_set_str (dict, "old-volname", (char *)words[2]); |
721 | |
722 | if (ret) |
723 | goto out; |
724 | |
725 | ret = dict_set_str (dict, "new-volname", (char *)words[3]); |
726 | |
727 | if (ret) |
728 | goto out; |
729 | |
730 | proc = &cli_rpc_prog->proctable[GLUSTER_CLI_RENAME_VOLUME]; |
731 | |
732 | if (proc->fn) { |
733 | ret = proc->fn (frame, THIS(*__glusterfs_this_location()), dict); |
734 | } |
735 | |
736 | out: |
737 | if (dict) |
738 | dict_destroy (dict); |
739 | |
740 | if (ret) { |
741 | cli_cmd_sent_status_get (&sent); |
742 | if ((sent == 0) && (parse_error == 0)) |
743 | cli_out ("Volume rename on '%s' failed", (char *)words[2])do { do { if (0) printf ("Volume rename on '%s' failed", (char *)words[2]); } while (0); _cli_out("Volume rename on '%s' failed" , (char *)words[2]); } while (0); |
744 | } |
745 | |
746 | CLI_STACK_DESTROY (frame)do { if (frame) { if (frame->local) { do { do { if (0) printf ("frame->local " "is not NULL (%p)", frame->local); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__, 746, GF_LOG_DEBUG , "frame->local " "is not NULL (%p)", frame->local); } while (0); cli_local_wipe (frame->local); frame->local = ((void *)0); } STACK_DESTROY (frame->root); } } while (0);; |
747 | |
748 | return ret; |
749 | } |
750 | |
751 | int |
752 | cli_cmd_volume_defrag_cbk (struct cli_state *state, struct cli_cmd_word *word, |
753 | const char **words, int wordcount) |
754 | { |
755 | int ret = -1; |
756 | rpc_clnt_procedure_t *proc = NULL((void*)0); |
757 | call_frame_t *frame = NULL((void*)0); |
758 | dict_t *dict = NULL((void*)0); |
759 | int sent = 0; |
760 | int parse_error = 0; |
761 | cli_local_t *local = NULL((void*)0); |
762 | #ifdef GF_SOLARIS_HOST_OS |
763 | cli_out ("Command not supported on Solaris")do { do { if (0) printf ("Command not supported on Solaris"); } while (0); _cli_out("Command not supported on Solaris"); } while (0); |
764 | goto out; |
765 | #endif |
766 | |
767 | frame = create_frame (THIS(*__glusterfs_this_location()), THIS(*__glusterfs_this_location())->ctx->pool); |
768 | if (!frame) |
769 | goto out; |
770 | |
771 | ret = cli_cmd_volume_defrag_parse (words, wordcount, &dict); |
772 | |
773 | if (ret) { |
774 | cli_usage_out (word->pattern); |
775 | parse_error = 1; |
776 | } |
777 | |
778 | proc = &cli_rpc_prog->proctable[GLUSTER_CLI_DEFRAG_VOLUME]; |
779 | |
780 | CLI_LOCAL_INIT (local, words, frame, dict)do { local = cli_local_get (); if (local) { local->words = words; if (dict) local->dict = dict; if (frame) frame-> local = local; } } while (0); |
781 | |
782 | if (proc->fn) { |
783 | ret = proc->fn (frame, THIS(*__glusterfs_this_location()), dict); |
784 | } |
785 | |
786 | out: |
787 | if (ret) { |
788 | cli_cmd_sent_status_get (&sent); |
789 | if ((sent == 0) && (parse_error == 0)) |
790 | cli_out ("Volume rebalance failed")do { do { if (0) printf ("Volume rebalance failed"); } while ( 0); _cli_out("Volume rebalance failed"); } while (0); |
791 | } |
792 | |
793 | CLI_STACK_DESTROY (frame)do { if (frame) { if (frame->local) { do { do { if (0) printf ("frame->local " "is not NULL (%p)", frame->local); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__, 793, GF_LOG_DEBUG , "frame->local " "is not NULL (%p)", frame->local); } while (0); cli_local_wipe (frame->local); frame->local = ((void *)0); } STACK_DESTROY (frame->root); } } while (0);; |
794 | |
795 | return ret; |
796 | } |
797 | |
798 | int |
799 | cli_cmd_volume_reset_cbk (struct cli_state *state, struct cli_cmd_word *word, |
800 | const char **words, int wordcount) |
801 | { |
802 | int sent = 0; |
803 | int parse_error = 0; |
804 | int ret = -1; |
805 | rpc_clnt_procedure_t *proc = NULL((void*)0); |
806 | call_frame_t *frame = NULL((void*)0); |
807 | dict_t *options = NULL((void*)0); |
808 | cli_local_t *local = NULL((void*)0); |
809 | |
810 | proc = &cli_rpc_prog->proctable[GLUSTER_CLI_RESET_VOLUME]; |
811 | |
812 | frame = create_frame (THIS(*__glusterfs_this_location()), THIS(*__glusterfs_this_location())->ctx->pool); |
813 | if (!frame) |
814 | goto out; |
815 | |
816 | ret = cli_cmd_volume_reset_parse (words, wordcount, &options); |
817 | if (ret) { |
818 | cli_usage_out (word->pattern); |
819 | parse_error = 1; |
820 | goto out; |
821 | } |
822 | |
823 | CLI_LOCAL_INIT (local, words, frame, options)do { local = cli_local_get (); if (local) { local->words = words; if (options) local->dict = options; if (frame) frame ->local = local; } } while (0); |
824 | |
825 | if (proc->fn) { |
826 | ret = proc->fn (frame, THIS(*__glusterfs_this_location()), options); |
827 | } |
828 | |
829 | out: |
830 | if (ret) { |
831 | cli_cmd_sent_status_get (&sent); |
832 | if ((sent == 0) && (parse_error == 0)) |
833 | cli_out ("Volume reset failed")do { do { if (0) printf ("Volume reset failed"); } while (0); _cli_out("Volume reset failed"); } while (0); |
834 | } |
835 | |
836 | CLI_STACK_DESTROY (frame)do { if (frame) { if (frame->local) { do { do { if (0) printf ("frame->local " "is not NULL (%p)", frame->local); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__, 836, GF_LOG_DEBUG , "frame->local " "is not NULL (%p)", frame->local); } while (0); cli_local_wipe (frame->local); frame->local = ((void *)0); } STACK_DESTROY (frame->root); } } while (0);; |
837 | |
838 | return ret; |
839 | |
840 | } |
841 | |
842 | int |
843 | cli_cmd_volume_profile_cbk (struct cli_state *state, struct cli_cmd_word *word, |
844 | const char **words, int wordcount) |
845 | { |
846 | int sent = 0; |
847 | int parse_error = 0; |
848 | |
849 | int ret = -1; |
850 | rpc_clnt_procedure_t *proc = NULL((void*)0); |
851 | call_frame_t *frame = NULL((void*)0); |
852 | dict_t *options = NULL((void*)0); |
853 | cli_local_t *local = NULL((void*)0); |
854 | |
855 | ret = cli_cmd_volume_profile_parse (words, wordcount, &options); |
856 | |
857 | if (ret) { |
858 | cli_usage_out (word->pattern); |
859 | parse_error = 1; |
860 | goto out; |
861 | } |
862 | |
863 | proc = &cli_rpc_prog->proctable[GLUSTER_CLI_PROFILE_VOLUME]; |
864 | |
865 | frame = create_frame (THIS(*__glusterfs_this_location()), THIS(*__glusterfs_this_location())->ctx->pool); |
866 | if (!frame) |
867 | goto out; |
868 | |
869 | CLI_LOCAL_INIT (local, words, frame, options)do { local = cli_local_get (); if (local) { local->words = words; if (options) local->dict = options; if (frame) frame ->local = local; } } while (0); |
870 | |
871 | if (proc->fn) { |
872 | ret = proc->fn (frame, THIS(*__glusterfs_this_location()), options); |
873 | } |
874 | |
875 | out: |
876 | if (ret) { |
877 | cli_cmd_sent_status_get (&sent); |
878 | if ((sent == 0) && (parse_error == 0)) |
879 | cli_out ("Volume profile failed")do { do { if (0) printf ("Volume profile failed"); } while (0 ); _cli_out("Volume profile failed"); } while (0); |
880 | } |
881 | |
882 | CLI_STACK_DESTROY (frame)do { if (frame) { if (frame->local) { do { do { if (0) printf ("frame->local " "is not NULL (%p)", frame->local); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__, 882, GF_LOG_DEBUG , "frame->local " "is not NULL (%p)", frame->local); } while (0); cli_local_wipe (frame->local); frame->local = ((void *)0); } STACK_DESTROY (frame->root); } } while (0);; |
883 | |
884 | return ret; |
885 | |
886 | } |
887 | |
888 | int |
889 | cli_cmd_volume_set_cbk (struct cli_state *state, struct cli_cmd_word *word, |
890 | const char **words, int wordcount) |
891 | { |
892 | int sent = 0; |
893 | int parse_error = 0; |
894 | |
895 | int ret = -1; |
896 | rpc_clnt_procedure_t *proc = NULL((void*)0); |
897 | call_frame_t *frame = NULL((void*)0); |
898 | dict_t *options = NULL((void*)0); |
899 | cli_local_t *local = NULL((void*)0); |
900 | |
901 | proc = &cli_rpc_prog->proctable[GLUSTER_CLI_SET_VOLUME]; |
902 | |
903 | frame = create_frame (THIS(*__glusterfs_this_location()), THIS(*__glusterfs_this_location())->ctx->pool); |
904 | if (!frame) |
905 | goto out; |
906 | |
907 | ret = cli_cmd_volume_set_parse (words, wordcount, &options); |
908 | if (ret) { |
909 | cli_usage_out (word->pattern); |
910 | parse_error = 1; |
911 | goto out; |
912 | } |
913 | |
914 | CLI_LOCAL_INIT (local, words, frame, options)do { local = cli_local_get (); if (local) { local->words = words; if (options) local->dict = options; if (frame) frame ->local = local; } } while (0); |
915 | |
916 | if (proc->fn) { |
917 | ret = proc->fn (frame, THIS(*__glusterfs_this_location()), options); |
918 | } |
919 | |
920 | out: |
921 | if (ret) { |
922 | cli_cmd_sent_status_get (&sent); |
923 | if ((sent == 0) && (parse_error == 0)) |
924 | cli_out ("Volume set failed")do { do { if (0) printf ("Volume set failed"); } while (0); _cli_out ("Volume set failed"); } while (0); |
925 | } |
926 | |
927 | CLI_STACK_DESTROY (frame)do { if (frame) { if (frame->local) { do { do { if (0) printf ("frame->local " "is not NULL (%p)", frame->local); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__, 927, GF_LOG_DEBUG , "frame->local " "is not NULL (%p)", frame->local); } while (0); cli_local_wipe (frame->local); frame->local = ((void *)0); } STACK_DESTROY (frame->root); } } while (0);; |
928 | |
929 | return ret; |
930 | |
931 | } |
932 | |
933 | int |
934 | cli_cmd_volume_add_brick_cbk (struct cli_state *state, |
935 | struct cli_cmd_word *word, const char **words, |
936 | int wordcount) |
937 | { |
938 | int ret = -1; |
939 | rpc_clnt_procedure_t *proc = NULL((void*)0); |
940 | call_frame_t *frame = NULL((void*)0); |
941 | dict_t *options = NULL((void*)0); |
942 | int sent = 0; |
943 | int parse_error = 0; |
944 | gf_answer_t answer = GF_ANSWER_NO; |
945 | cli_local_t *local = NULL((void*)0); |
946 | |
947 | const char *question = "Changing the 'stripe count' of the volume is " |
948 | "not a supported feature. In some cases it may result in data " |
949 | "loss on the volume. Also there may be issues with regular " |
950 | "filesystem operations on the volume after the change. Do you " |
951 | "really want to continue with 'stripe' count option ? "; |
952 | |
953 | frame = create_frame (THIS(*__glusterfs_this_location()), THIS(*__glusterfs_this_location())->ctx->pool); |
954 | if (!frame) |
955 | goto out; |
956 | |
957 | ret = cli_cmd_volume_add_brick_parse (words, wordcount, &options); |
958 | if (ret) { |
959 | cli_usage_out (word->pattern); |
960 | parse_error = 1; |
961 | goto out; |
962 | } |
963 | |
964 | /* TODO: there are challenges in supporting changing of |
965 | stripe-count, untill it is properly supported give warning to user */ |
966 | if (dict_get (options, "stripe-count")) { |
967 | answer = cli_cmd_get_confirmation (state, question); |
968 | |
969 | if (GF_ANSWER_NO == answer) { |
970 | ret = 0; |
971 | goto out; |
972 | } |
973 | } |
974 | |
975 | if (state->mode & GLUSTER_MODE_SCRIPT(1 << 0)) { |
976 | ret = dict_set_int32 (options, "force", _gf_true); |
977 | if (ret) { |
978 | gf_log ("cli", GF_LOG_ERROR, "Failed to set force "do { do { if (0) printf ("Failed to set force " "option"); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__, 979, GF_LOG_ERROR , "Failed to set force " "option"); } while (0) |
979 | "option")do { do { if (0) printf ("Failed to set force " "option"); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__, 979, GF_LOG_ERROR , "Failed to set force " "option"); } while (0); |
980 | goto out; |
981 | } |
982 | } |
983 | |
984 | proc = &cli_rpc_prog->proctable[GLUSTER_CLI_ADD_BRICK]; |
985 | |
986 | CLI_LOCAL_INIT (local, words, frame, options)do { local = cli_local_get (); if (local) { local->words = words; if (options) local->dict = options; if (frame) frame ->local = local; } } while (0); |
987 | |
988 | if (proc->fn) { |
989 | ret = proc->fn (frame, THIS(*__glusterfs_this_location()), options); |
990 | } |
991 | |
992 | out: |
993 | if (ret) { |
994 | cli_cmd_sent_status_get (&sent); |
995 | if ((sent == 0) && (parse_error == 0)) |
996 | cli_out ("Volume add-brick failed")do { do { if (0) printf ("Volume add-brick failed"); } while ( 0); _cli_out("Volume add-brick failed"); } while (0); |
997 | } |
998 | |
999 | CLI_STACK_DESTROY (frame)do { if (frame) { if (frame->local) { do { do { if (0) printf ("frame->local " "is not NULL (%p)", frame->local); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__, 999, GF_LOG_DEBUG , "frame->local " "is not NULL (%p)", frame->local); } while (0); cli_local_wipe (frame->local); frame->local = ((void *)0); } STACK_DESTROY (frame->root); } } while (0);; |
1000 | |
1001 | return ret; |
1002 | } |
1003 | |
1004 | int |
1005 | cli_cmd_quota_cbk (struct cli_state *state, struct cli_cmd_word *word, |
1006 | const char **words, int wordcount) |
1007 | { |
1008 | |
1009 | int ret = 0; |
1010 | int parse_err = 0; |
1011 | int32_t type = 0; |
1012 | rpc_clnt_procedure_t *proc = NULL((void*)0); |
1013 | call_frame_t *frame = NULL((void*)0); |
1014 | dict_t *options = NULL((void*)0); |
1015 | gf_answer_t answer = GF_ANSWER_NO; |
1016 | cli_local_t *local = NULL((void*)0); |
1017 | const char *question = "Disabling quota will delete all the quota " |
1018 | "configuration. Do you want to continue?"; |
1019 | |
1020 | proc = &cli_rpc_prog->proctable[GLUSTER_CLI_QUOTA]; |
1021 | if (proc == NULL((void*)0)) { |
1022 | ret = -1; |
1023 | goto out; |
1024 | } |
1025 | |
1026 | frame = create_frame (THIS(*__glusterfs_this_location()), THIS(*__glusterfs_this_location())->ctx->pool); |
1027 | if (!frame) { |
1028 | ret = -1; |
1029 | goto out; |
1030 | } |
1031 | |
1032 | ret = cli_cmd_quota_parse (words, wordcount, &options); |
1033 | |
1034 | if (ret < 0) { |
1035 | cli_usage_out (word->pattern); |
1036 | parse_err = 1; |
1037 | goto out; |
1038 | } else if (dict_get_int32 (options, "type", &type) == 0 && |
1039 | type == GF_QUOTA_OPTION_TYPE_DISABLE) { |
1040 | answer = cli_cmd_get_confirmation (state, question); |
1041 | if (answer == GF_ANSWER_NO) |
1042 | goto out; |
1043 | } |
1044 | |
1045 | CLI_LOCAL_INIT (local, words, frame, options)do { local = cli_local_get (); if (local) { local->words = words; if (options) local->dict = options; if (frame) frame ->local = local; } } while (0); |
1046 | |
1047 | if (proc->fn) |
1048 | ret = proc->fn (frame, THIS(*__glusterfs_this_location()), options); |
1049 | |
1050 | out: |
1051 | if (ret && parse_err == 0) |
1052 | cli_out ("Quota command failed")do { do { if (0) printf ("Quota command failed"); } while (0) ; _cli_out("Quota command failed"); } while (0); |
1053 | |
1054 | CLI_STACK_DESTROY (frame)do { if (frame) { if (frame->local) { do { do { if (0) printf ("frame->local " "is not NULL (%p)", frame->local); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__, 1054, GF_LOG_DEBUG, "frame->local " "is not NULL (%p)", frame-> local); } while (0); cli_local_wipe (frame->local); frame-> local = ((void*)0); } STACK_DESTROY (frame->root); } } while (0);; |
1055 | |
1056 | return ret; |
1057 | |
1058 | } |
1059 | |
1060 | int |
1061 | cli_cmd_volume_remove_brick_cbk (struct cli_state *state, |
1062 | struct cli_cmd_word *word, const char **words, |
1063 | int wordcount) |
1064 | { |
1065 | int ret = -1; |
1066 | rpc_clnt_procedure_t *proc = NULL((void*)0); |
1067 | call_frame_t *frame = NULL((void*)0); |
1068 | dict_t *options = NULL((void*)0); |
1069 | gf_answer_t answer = GF_ANSWER_NO; |
1070 | int sent = 0; |
1071 | int parse_error = 0; |
1072 | int need_question = 0; |
1073 | cli_local_t *local = NULL((void*)0); |
1074 | |
1075 | const char *question = "Removing brick(s) can result in data loss. " |
1076 | "Do you want to Continue?"; |
1077 | |
1078 | frame = create_frame (THIS(*__glusterfs_this_location()), THIS(*__glusterfs_this_location())->ctx->pool); |
1079 | if (!frame) |
1080 | goto out; |
1081 | |
1082 | ret = cli_cmd_volume_remove_brick_parse (words, wordcount, &options, |
1083 | &need_question); |
1084 | if (ret) { |
1085 | cli_usage_out (word->pattern); |
1086 | parse_error = 1; |
1087 | goto out; |
1088 | } |
1089 | |
1090 | if (!(state->mode & GLUSTER_MODE_SCRIPT(1 << 0)) && need_question) { |
1091 | /* we need to ask question only in case of 'commit or force' */ |
1092 | answer = cli_cmd_get_confirmation (state, question); |
1093 | if (GF_ANSWER_NO == answer) { |
1094 | ret = 0; |
1095 | goto out; |
1096 | } |
1097 | } |
1098 | |
1099 | proc = &cli_rpc_prog->proctable[GLUSTER_CLI_REMOVE_BRICK]; |
1100 | |
1101 | CLI_LOCAL_INIT (local, words, frame, options)do { local = cli_local_get (); if (local) { local->words = words; if (options) local->dict = options; if (frame) frame ->local = local; } } while (0); |
1102 | |
1103 | if (proc->fn) { |
1104 | ret = proc->fn (frame, THIS(*__glusterfs_this_location()), options); |
1105 | } |
1106 | |
1107 | out: |
1108 | if (ret) { |
1109 | cli_cmd_sent_status_get (&sent); |
1110 | if ((sent == 0) && (parse_error == 0)) |
1111 | cli_out ("Volume remove-brick failed")do { do { if (0) printf ("Volume remove-brick failed"); } while (0); _cli_out("Volume remove-brick failed"); } while (0); |
1112 | } |
1113 | |
1114 | CLI_STACK_DESTROY (frame)do { if (frame) { if (frame->local) { do { do { if (0) printf ("frame->local " "is not NULL (%p)", frame->local); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__, 1114, GF_LOG_DEBUG, "frame->local " "is not NULL (%p)", frame-> local); } while (0); cli_local_wipe (frame->local); frame-> local = ((void*)0); } STACK_DESTROY (frame->root); } } while (0);; |
1115 | |
1116 | return ret; |
1117 | |
1118 | } |
1119 | |
1120 | int |
1121 | cli_cmd_volume_replace_brick_cbk (struct cli_state *state, |
1122 | struct cli_cmd_word *word, |
1123 | const char **words, |
1124 | int wordcount) |
1125 | { |
1126 | int ret = -1; |
1127 | rpc_clnt_procedure_t *proc = NULL((void*)0); |
1128 | call_frame_t *frame = NULL((void*)0); |
1129 | dict_t *options = NULL((void*)0); |
1130 | int sent = 0; |
1131 | int parse_error = 0; |
1132 | cli_local_t *local = NULL((void*)0); |
1133 | |
1134 | #ifdef GF_SOLARIS_HOST_OS |
1135 | cli_out ("Command not supported on Solaris")do { do { if (0) printf ("Command not supported on Solaris"); } while (0); _cli_out("Command not supported on Solaris"); } while (0); |
1136 | goto out; |
1137 | #endif |
1138 | proc = &cli_rpc_prog->proctable[GLUSTER_CLI_REPLACE_BRICK]; |
1139 | |
1140 | frame = create_frame (THIS(*__glusterfs_this_location()), THIS(*__glusterfs_this_location())->ctx->pool); |
1141 | if (!frame) |
1142 | goto out; |
1143 | |
1144 | ret = cli_cmd_volume_replace_brick_parse (words, wordcount, &options); |
1145 | |
1146 | if (ret) { |
1147 | cli_usage_out (word->pattern); |
1148 | parse_error = 1; |
1149 | goto out; |
1150 | } |
1151 | |
1152 | if (state->mode & GLUSTER_MODE_SCRIPT(1 << 0)) { |
1153 | ret = dict_set_int32 (options, "force", _gf_true); |
1154 | if (ret) { |
1155 | gf_log ("cli", GF_LOG_ERROR, "Failed to set force"do { do { if (0) printf ("Failed to set force" "option"); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__, 1156, GF_LOG_ERROR, "Failed to set force" "option"); } while (0) |
1156 | "option")do { do { if (0) printf ("Failed to set force" "option"); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__, 1156, GF_LOG_ERROR, "Failed to set force" "option"); } while (0); |
1157 | goto out; |
1158 | } |
1159 | } |
1160 | |
1161 | CLI_LOCAL_INIT (local, words, frame, options)do { local = cli_local_get (); if (local) { local->words = words; if (options) local->dict = options; if (frame) frame ->local = local; } } while (0); |
1162 | |
1163 | if (proc->fn) { |
1164 | ret = proc->fn (frame, THIS(*__glusterfs_this_location()), options); |
1165 | } |
1166 | |
1167 | out: |
1168 | if (ret) { |
1169 | cli_cmd_sent_status_get (&sent); |
1170 | if ((sent == 0) && (parse_error == 0)) |
1171 | cli_out ("Volume replace-brick failed")do { do { if (0) printf ("Volume replace-brick failed"); } while (0); _cli_out("Volume replace-brick failed"); } while (0); |
1172 | } |
1173 | |
1174 | CLI_STACK_DESTROY (frame)do { if (frame) { if (frame->local) { do { do { if (0) printf ("frame->local " "is not NULL (%p)", frame->local); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__, 1174, GF_LOG_DEBUG, "frame->local " "is not NULL (%p)", frame-> local); } while (0); cli_local_wipe (frame->local); frame-> local = ((void*)0); } STACK_DESTROY (frame->root); } } while (0);; |
1175 | |
1176 | return ret; |
1177 | } |
1178 | |
1179 | |
1180 | int |
1181 | cli_cmd_volume_set_transport_cbk (struct cli_state *state, |
1182 | struct cli_cmd_word *word, |
1183 | const char **words, int wordcount) |
1184 | { |
1185 | cli_cmd_broadcast_response (0); |
1186 | return 0; |
1187 | } |
1188 | |
1189 | int |
1190 | cli_cmd_volume_top_cbk (struct cli_state *state, struct cli_cmd_word *word, |
1191 | const char **words, int wordcount) |
1192 | { |
1193 | |
1194 | int ret = -1; |
1195 | rpc_clnt_procedure_t *proc = NULL((void*)0); |
1196 | call_frame_t *frame = NULL((void*)0); |
1197 | dict_t *options = NULL((void*)0); |
1198 | int sent = 0; |
1199 | int parse_error = 0; |
1200 | cli_local_t *local = NULL((void*)0); |
1201 | |
1202 | ret = cli_cmd_volume_top_parse (words, wordcount, &options); |
1203 | |
1204 | if (ret) { |
1205 | parse_error = 1; |
1206 | cli_usage_out (word->pattern); |
1207 | goto out; |
1208 | } |
1209 | |
1210 | proc = &cli_rpc_prog->proctable[GLUSTER_CLI_TOP_VOLUME]; |
1211 | |
1212 | frame = create_frame (THIS(*__glusterfs_this_location()), THIS(*__glusterfs_this_location())->ctx->pool); |
1213 | if (!frame) |
1214 | goto out; |
1215 | |
1216 | CLI_LOCAL_INIT (local, words, frame, options)do { local = cli_local_get (); if (local) { local->words = words; if (options) local->dict = options; if (frame) frame ->local = local; } } while (0); |
1217 | |
1218 | if (proc->fn) { |
1219 | ret = proc->fn (frame, THIS(*__glusterfs_this_location()), options); |
1220 | } |
1221 | |
1222 | out: |
1223 | if (ret) { |
1224 | cli_cmd_sent_status_get (&sent); |
1225 | if ((sent == 0) && (parse_error == 0)) |
1226 | cli_out ("Volume top failed")do { do { if (0) printf ("Volume top failed"); } while (0); _cli_out ("Volume top failed"); } while (0); |
1227 | } |
1228 | |
1229 | CLI_STACK_DESTROY (frame)do { if (frame) { if (frame->local) { do { do { if (0) printf ("frame->local " "is not NULL (%p)", frame->local); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__, 1229, GF_LOG_DEBUG, "frame->local " "is not NULL (%p)", frame-> local); } while (0); cli_local_wipe (frame->local); frame-> local = ((void*)0); } STACK_DESTROY (frame->root); } } while (0);; |
1230 | |
1231 | return ret; |
1232 | |
1233 | } |
1234 | |
1235 | |
1236 | int |
1237 | cli_cmd_log_rotate_cbk (struct cli_state *state, struct cli_cmd_word *word, |
1238 | const char **words, int wordcount) |
1239 | { |
1240 | int ret = -1; |
1241 | rpc_clnt_procedure_t *proc = NULL((void*)0); |
1242 | call_frame_t *frame = NULL((void*)0); |
1243 | dict_t *options = NULL((void*)0); |
1244 | int sent = 0; |
1245 | int parse_error = 0; |
1246 | cli_local_t *local = NULL((void*)0); |
1247 | |
1248 | if (!((wordcount == 4) || (wordcount == 5))) { |
1249 | cli_usage_out (word->pattern); |
1250 | parse_error = 1; |
1251 | goto out; |
1252 | } |
1253 | |
1254 | proc = &cli_rpc_prog->proctable[GLUSTER_CLI_LOG_ROTATE]; |
1255 | |
1256 | frame = create_frame (THIS(*__glusterfs_this_location()), THIS(*__glusterfs_this_location())->ctx->pool); |
1257 | if (!frame) |
1258 | goto out; |
1259 | |
1260 | ret = cli_cmd_log_rotate_parse (words, wordcount, &options); |
1261 | if (ret) |
1262 | goto out; |
1263 | |
1264 | CLI_LOCAL_INIT (local, words, frame, options)do { local = cli_local_get (); if (local) { local->words = words; if (options) local->dict = options; if (frame) frame ->local = local; } } while (0); |
1265 | |
1266 | if (proc->fn) { |
1267 | ret = proc->fn (frame, THIS(*__glusterfs_this_location()), options); |
1268 | } |
1269 | |
1270 | out: |
1271 | if (ret) { |
1272 | cli_cmd_sent_status_get (&sent); |
1273 | if ((sent == 0) && (parse_error == 0)) |
1274 | cli_out ("Volume log rotate failed")do { do { if (0) printf ("Volume log rotate failed"); } while (0); _cli_out("Volume log rotate failed"); } while (0); |
1275 | } |
1276 | CLI_STACK_DESTROY (frame)do { if (frame) { if (frame->local) { do { do { if (0) printf ("frame->local " "is not NULL (%p)", frame->local); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__, 1276, GF_LOG_DEBUG, "frame->local " "is not NULL (%p)", frame-> local); } while (0); cli_local_wipe (frame->local); frame-> local = ((void*)0); } STACK_DESTROY (frame->root); } } while (0);; |
1277 | |
1278 | return ret; |
1279 | } |
1280 | |
1281 | #if (SYNCDAEMON_COMPILE1) |
1282 | static int |
1283 | cli_check_gsync_present () |
1284 | { |
1285 | char buff[PATH_MAX4096] = {0, }; |
1286 | runner_t runner = {0,}; |
1287 | char *ptr = NULL((void*)0); |
1288 | int ret = 0; |
1289 | |
1290 | ret = setenv ("_GLUSTERD_CALLED_", "1", 1); |
1291 | if (-1 == ret) { |
1292 | gf_log ("", GF_LOG_WARNING, "setenv syscall failed, hence could"do { do { if (0) printf ("setenv syscall failed, hence could" "not assert if geo-replication is installed"); } while (0); _gf_log ("", "cli-cmd-volume.c", __FUNCTION__, 1293, GF_LOG_WARNING, "setenv syscall failed, hence could" "not assert if geo-replication is installed" ); } while (0) |
1293 | "not assert if geo-replication is installed")do { do { if (0) printf ("setenv syscall failed, hence could" "not assert if geo-replication is installed"); } while (0); _gf_log ("", "cli-cmd-volume.c", __FUNCTION__, 1293, GF_LOG_WARNING, "setenv syscall failed, hence could" "not assert if geo-replication is installed" ); } while (0); |
1294 | goto out; |
1295 | } |
1296 | |
1297 | runinit (&runner); |
1298 | runner_add_args (&runner, GSYNCD_PREFIX"/usr/local/libexec/glusterfs""/gsyncd", "--version", NULL((void*)0)); |
1299 | runner_redir (&runner, STDOUT_FILENO1, RUN_PIPE-1); |
1300 | ret = runner_start (&runner); |
1301 | if (ret == -1) { |
1302 | gf_log ("", GF_LOG_INFO, "geo-replication not installed")do { do { if (0) printf ("geo-replication not installed"); } while (0); _gf_log ("", "cli-cmd-volume.c", __FUNCTION__, 1302, GF_LOG_INFO , "geo-replication not installed"); } while (0); |
1303 | goto out; |
1304 | } |
1305 | |
1306 | ptr = fgets(buff, sizeof(buff), runner_chio (&runner, STDOUT_FILENO1)); |
1307 | if (ptr) { |
1308 | if (!strstr (buff, "gsyncd")) { |
1309 | ret = -1; |
1310 | goto out; |
1311 | } |
1312 | } else { |
1313 | ret = -1; |
1314 | goto out; |
1315 | } |
1316 | |
1317 | ret = runner_end (&runner); |
1318 | |
1319 | if (ret) |
1320 | gf_log ("", GF_LOG_ERROR, "geo-replication not installed")do { do { if (0) printf ("geo-replication not installed"); } while (0); _gf_log ("", "cli-cmd-volume.c", __FUNCTION__, 1320, GF_LOG_ERROR , "geo-replication not installed"); } while (0); |
1321 | |
1322 | out: |
1323 | gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__, 1323, GF_LOG_DEBUG , "Returning %d", ret); } while (0); |
1324 | return ret ? -1 : 0; |
1325 | |
1326 | } |
1327 | |
1328 | void |
1329 | cli_cmd_check_gsync_exists_cbk (struct cli_cmd *this) |
1330 | { |
1331 | |
1332 | int ret = 0; |
1333 | |
1334 | ret = cli_check_gsync_present (); |
1335 | if (ret) |
1336 | this->disable = _gf_true; |
1337 | |
1338 | } |
1339 | #endif |
1340 | |
1341 | int |
1342 | cli_cmd_volume_gsync_set_cbk (struct cli_state *state, struct cli_cmd_word *word, |
1343 | const char **words, int wordcount) |
1344 | { |
1345 | int ret = 0; |
1346 | int parse_err = 0; |
1347 | dict_t *options = NULL((void*)0); |
1348 | rpc_clnt_procedure_t *proc = NULL((void*)0); |
1349 | call_frame_t *frame = NULL((void*)0); |
1350 | cli_local_t *local = NULL((void*)0); |
1351 | |
1352 | proc = &cli_rpc_prog->proctable [GLUSTER_CLI_GSYNC_SET]; |
1353 | if (proc == NULL((void*)0)) { |
1354 | ret = -1; |
1355 | goto out; |
1356 | } |
1357 | |
1358 | frame = create_frame (THIS(*__glusterfs_this_location()), THIS(*__glusterfs_this_location())->ctx->pool); |
1359 | if (frame == NULL((void*)0)) { |
1360 | ret = -1; |
1361 | goto out; |
1362 | } |
1363 | |
1364 | ret = cli_cmd_gsync_set_parse (words, wordcount, &options); |
1365 | if (ret) { |
1366 | cli_usage_out (word->pattern); |
1367 | parse_err = 1; |
1368 | goto out; |
1369 | } |
1370 | |
1371 | CLI_LOCAL_INIT (local, words, frame, options)do { local = cli_local_get (); if (local) { local->words = words; if (options) local->dict = options; if (frame) frame ->local = local; } } while (0); |
1372 | |
1373 | if (proc->fn) |
1374 | ret = proc->fn (frame, THIS(*__glusterfs_this_location()), options); |
1375 | |
1376 | out: |
1377 | if (ret && parse_err == 0) |
1378 | cli_out (GEOREP" command failed")do { do { if (0) printf ("geo-replication"" command failed"); } while (0); _cli_out("geo-replication"" command failed"); } while (0); |
1379 | |
1380 | CLI_STACK_DESTROY (frame)do { if (frame) { if (frame->local) { do { do { if (0) printf ("frame->local " "is not NULL (%p)", frame->local); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__, 1380, GF_LOG_DEBUG, "frame->local " "is not NULL (%p)", frame-> local); } while (0); cli_local_wipe (frame->local); frame-> local = ((void*)0); } STACK_DESTROY (frame->root); } } while (0);; |
1381 | |
1382 | return ret; |
1383 | } |
1384 | |
1385 | int |
1386 | cli_cmd_volume_status_cbk (struct cli_state *state, |
1387 | struct cli_cmd_word *word, |
1388 | const char **words, int wordcount) |
1389 | { |
1390 | int ret = -1; |
1391 | rpc_clnt_procedure_t *proc = NULL((void*)0); |
1392 | call_frame_t *frame = NULL((void*)0); |
1393 | dict_t *dict = NULL((void*)0); |
1394 | uint32_t cmd = 0; |
1395 | cli_local_t *local = NULL((void*)0); |
1396 | |
1397 | ret = cli_cmd_volume_status_parse (words, wordcount, &dict); |
1398 | |
1399 | if (ret) { |
1400 | cli_usage_out (word->pattern); |
1401 | goto out; |
1402 | } |
1403 | |
1404 | ret = dict_get_uint32 (dict, "cmd", &cmd); |
1405 | if (ret) |
1406 | goto out; |
1407 | |
1408 | if (!(cmd & GF_CLI_STATUS_ALL)) { |
1409 | /* for one volume or brick */ |
1410 | proc = &cli_rpc_prog->proctable[GLUSTER_CLI_STATUS_VOLUME]; |
1411 | } else { |
1412 | /* volume status all or all detail */ |
1413 | proc = &cli_rpc_prog->proctable[GLUSTER_CLI_STATUS_ALL]; |
1414 | } |
1415 | |
1416 | if (!proc->fn) |
1417 | goto out; |
1418 | |
1419 | frame = create_frame (THIS(*__glusterfs_this_location()), THIS(*__glusterfs_this_location())->ctx->pool); |
1420 | if (!frame) |
1421 | goto out; |
1422 | |
1423 | CLI_LOCAL_INIT (local, words, frame, dict)do { local = cli_local_get (); if (local) { local->words = words; if (dict) local->dict = dict; if (frame) frame-> local = local; } } while (0); |
1424 | |
1425 | ret = proc->fn (frame, THIS(*__glusterfs_this_location()), dict); |
1426 | |
1427 | out: |
1428 | CLI_STACK_DESTROY (frame)do { if (frame) { if (frame->local) { do { do { if (0) printf ("frame->local " "is not NULL (%p)", frame->local); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__, 1428, GF_LOG_DEBUG, "frame->local " "is not NULL (%p)", frame-> local); } while (0); cli_local_wipe (frame->local); frame-> local = ((void*)0); } STACK_DESTROY (frame->root); } } while (0);; |
1429 | |
1430 | return ret; |
1431 | } |
1432 | |
1433 | |
1434 | int |
1435 | cli_get_detail_status (dict_t *dict, int i, cli_volume_status_t *status) |
1436 | { |
1437 | uint64_t free = 0; |
1438 | uint64_t total = 0; |
1439 | char key[1024] = {0}; |
1440 | int ret = 0; |
1441 | |
1442 | memset (key, 0, sizeof (key)); |
1443 | snprintf (key, sizeof (key), "brick%d.free", i); |
1444 | ret = dict_get_uint64 (dict, key, &free); |
1445 | |
1446 | status->free = gf_uint64_2human_readable (free); |
1447 | if (!status->free) |
1448 | goto out; |
1449 | |
1450 | memset (key, 0, sizeof (key)); |
1451 | snprintf (key, sizeof (key), "brick%d.total", i); |
1452 | ret = dict_get_uint64 (dict, key, &total); |
1453 | |
1454 | status->total = gf_uint64_2human_readable (total); |
1455 | if (!status->total) |
1456 | goto out; |
1457 | |
1458 | #ifdef GF_LINUX_HOST_OS1 |
1459 | memset (key, 0, sizeof (key)); |
1460 | snprintf (key, sizeof (key), "brick%d.device", i); |
1461 | ret = dict_get_str (dict, key, &(status->device)); |
1462 | if (ret) |
1463 | status->device = NULL((void*)0); |
1464 | #endif |
1465 | |
1466 | memset (key, 0, sizeof (key)); |
1467 | snprintf (key, sizeof (key), "brick%d.block_size", i); |
1468 | ret = dict_get_uint64 (dict, key, &(status->block_size)); |
1469 | if (ret) { |
1470 | ret = 0; |
1471 | status->block_size = 0; |
1472 | } |
1473 | |
1474 | #ifdef GF_LINUX_HOST_OS1 |
1475 | memset (key, 0, sizeof (key)); |
1476 | snprintf (key, sizeof (key), "brick%d.mnt_options", i); |
1477 | ret = dict_get_str (dict, key, &(status->mount_options)); |
1478 | if (ret) |
1479 | status->mount_options = NULL((void*)0); |
1480 | |
1481 | memset (key, 0, sizeof (key)); |
1482 | snprintf (key, sizeof (key), "brick%d.fs_name", i); |
1483 | ret = dict_get_str (dict, key, &(status->fs_name)); |
1484 | if (ret) { |
1485 | ret = 0; |
1486 | status->fs_name = NULL((void*)0); |
1487 | } |
1488 | |
1489 | memset (key, 0, sizeof (key)); |
1490 | snprintf (key, sizeof (key), "brick%d.inode_size", i); |
1491 | ret = dict_get_str (dict, key, &(status->inode_size)); |
1492 | if (ret) |
1493 | status->inode_size = NULL((void*)0); |
1494 | #endif /* GF_LINUX_HOST_OS */ |
1495 | |
1496 | memset (key, 0, sizeof (key)); |
1497 | snprintf (key, sizeof (key), "brick%d.total_inodes", i); |
1498 | ret = dict_get_uint64 (dict, key, |
1499 | &(status->total_inodes)); |
1500 | if (ret) |
1501 | status->total_inodes = 0; |
1502 | |
1503 | memset (key, 0, sizeof (key)); |
1504 | snprintf (key, sizeof (key), "brick%d.free_inodes", i); |
1505 | ret = dict_get_uint64 (dict, key, &(status->free_inodes)); |
1506 | if (ret) { |
1507 | ret = 0; |
1508 | status->free_inodes = 0; |
1509 | } |
1510 | |
1511 | |
1512 | out: |
1513 | return ret; |
1514 | } |
1515 | |
1516 | void |
1517 | cli_print_detailed_status (cli_volume_status_t *status) |
1518 | { |
1519 | cli_out ("%-20s : %-20s", "Brick", status->brick)do { do { if (0) printf ("%-20s : %-20s", "Brick", status-> brick); } while (0); _cli_out("%-20s : %-20s", "Brick", status ->brick); } while (0); |
1520 | if (status->online) |
1521 | cli_out ("%-20s : %-20d", "Port", status->port)do { do { if (0) printf ("%-20s : %-20d", "Port", status-> port); } while (0); _cli_out("%-20s : %-20d", "Port", status-> port); } while (0); |
1522 | else |
1523 | cli_out ("%-20s : %-20s", "Port", "N/A")do { do { if (0) printf ("%-20s : %-20s", "Port", "N/A"); } while (0); _cli_out("%-20s : %-20s", "Port", "N/A"); } while (0); |
1524 | cli_out ("%-20s : %-20c", "Online", (status->online) ? 'Y' : 'N')do { do { if (0) printf ("%-20s : %-20c", "Online", (status-> online) ? 'Y' : 'N'); } while (0); _cli_out("%-20s : %-20c", "Online" , (status->online) ? 'Y' : 'N'); } while (0); |
1525 | cli_out ("%-20s : %-20s", "Pid", status->pid_str)do { do { if (0) printf ("%-20s : %-20s", "Pid", status->pid_str ); } while (0); _cli_out("%-20s : %-20s", "Pid", status->pid_str ); } while (0); |
1526 | |
1527 | #ifdef GF_LINUX_HOST_OS1 |
1528 | if (status->fs_name) |
1529 | cli_out ("%-20s : %-20s", "File System", status->fs_name)do { do { if (0) printf ("%-20s : %-20s", "File System", status ->fs_name); } while (0); _cli_out("%-20s : %-20s", "File System" , status->fs_name); } while (0); |
1530 | else |
1531 | cli_out ("%-20s : %-20s", "File System", "N/A")do { do { if (0) printf ("%-20s : %-20s", "File System", "N/A" ); } while (0); _cli_out("%-20s : %-20s", "File System", "N/A" ); } while (0); |
1532 | |
1533 | if (status->device) |
1534 | cli_out ("%-20s : %-20s", "Device", status->device)do { do { if (0) printf ("%-20s : %-20s", "Device", status-> device); } while (0); _cli_out("%-20s : %-20s", "Device", status ->device); } while (0); |
1535 | else |
1536 | cli_out ("%-20s : %-20s", "Device", "N/A")do { do { if (0) printf ("%-20s : %-20s", "Device", "N/A"); } while (0); _cli_out("%-20s : %-20s", "Device", "N/A"); } while (0); |
1537 | |
1538 | if (status->mount_options) { |
1539 | cli_out ("%-20s : %-20s", "Mount Options",do { do { if (0) printf ("%-20s : %-20s", "Mount Options", status ->mount_options); } while (0); _cli_out("%-20s : %-20s", "Mount Options" , status->mount_options); } while (0) |
1540 | status->mount_options)do { do { if (0) printf ("%-20s : %-20s", "Mount Options", status ->mount_options); } while (0); _cli_out("%-20s : %-20s", "Mount Options" , status->mount_options); } while (0); |
1541 | } else { |
1542 | cli_out ("%-20s : %-20s", "Mount Options", "N/A")do { do { if (0) printf ("%-20s : %-20s", "Mount Options", "N/A" ); } while (0); _cli_out("%-20s : %-20s", "Mount Options", "N/A" ); } while (0); |
1543 | } |
1544 | |
1545 | if (status->inode_size) { |
1546 | cli_out ("%-20s : %-20s", "Inode Size",do { do { if (0) printf ("%-20s : %-20s", "Inode Size", status ->inode_size); } while (0); _cli_out("%-20s : %-20s", "Inode Size" , status->inode_size); } while (0) |
1547 | status->inode_size)do { do { if (0) printf ("%-20s : %-20s", "Inode Size", status ->inode_size); } while (0); _cli_out("%-20s : %-20s", "Inode Size" , status->inode_size); } while (0); |
1548 | } else { |
1549 | cli_out ("%-20s : %-20s", "Inode Size", "N/A")do { do { if (0) printf ("%-20s : %-20s", "Inode Size", "N/A" ); } while (0); _cli_out("%-20s : %-20s", "Inode Size", "N/A" ); } while (0); |
1550 | } |
1551 | #endif |
1552 | if (status->free) |
1553 | cli_out ("%-20s : %-20s", "Disk Space Free", status->free)do { do { if (0) printf ("%-20s : %-20s", "Disk Space Free", status ->free); } while (0); _cli_out("%-20s : %-20s", "Disk Space Free" , status->free); } while (0); |
1554 | else |
1555 | cli_out ("%-20s : %-20s", "Disk Space Free", "N/A")do { do { if (0) printf ("%-20s : %-20s", "Disk Space Free", "N/A" ); } while (0); _cli_out("%-20s : %-20s", "Disk Space Free", "N/A" ); } while (0); |
1556 | |
1557 | if (status->total) |
1558 | cli_out ("%-20s : %-20s", "Total Disk Space", status->total)do { do { if (0) printf ("%-20s : %-20s", "Total Disk Space", status->total); } while (0); _cli_out("%-20s : %-20s", "Total Disk Space" , status->total); } while (0); |
1559 | else |
1560 | cli_out ("%-20s : %-20s", "Total Disk Space", "N/A")do { do { if (0) printf ("%-20s : %-20s", "Total Disk Space", "N/A"); } while (0); _cli_out("%-20s : %-20s", "Total Disk Space" , "N/A"); } while (0); |
1561 | |
1562 | |
1563 | if (status->total_inodes) { |
1564 | cli_out ("%-20s : %-20ld", "Inode Count",do { do { if (0) printf ("%-20s : %-20ld", "Inode Count", status ->total_inodes); } while (0); _cli_out("%-20s : %-20ld", "Inode Count" , status->total_inodes); } while (0) |
1565 | status->total_inodes)do { do { if (0) printf ("%-20s : %-20ld", "Inode Count", status ->total_inodes); } while (0); _cli_out("%-20s : %-20ld", "Inode Count" , status->total_inodes); } while (0); |
1566 | } else { |
1567 | cli_out ("%-20s : %-20s", "Inode Count", "N/A")do { do { if (0) printf ("%-20s : %-20s", "Inode Count", "N/A" ); } while (0); _cli_out("%-20s : %-20s", "Inode Count", "N/A" ); } while (0); |
1568 | } |
1569 | |
1570 | if (status->free_inodes) { |
1571 | cli_out ("%-20s : %-20ld", "Free Inodes",do { do { if (0) printf ("%-20s : %-20ld", "Free Inodes", status ->free_inodes); } while (0); _cli_out("%-20s : %-20ld", "Free Inodes" , status->free_inodes); } while (0) |
1572 | status->free_inodes)do { do { if (0) printf ("%-20s : %-20ld", "Free Inodes", status ->free_inodes); } while (0); _cli_out("%-20s : %-20ld", "Free Inodes" , status->free_inodes); } while (0); |
1573 | } else { |
1574 | cli_out ("%-20s : %-20s", "Free Inodes", "N/A")do { do { if (0) printf ("%-20s : %-20s", "Free Inodes", "N/A" ); } while (0); _cli_out("%-20s : %-20s", "Free Inodes", "N/A" ); } while (0); |
1575 | } |
1576 | } |
1577 | |
1578 | int |
1579 | cli_print_brick_status (cli_volume_status_t *status) |
1580 | { |
1581 | int fieldlen = CLI_VOL_STATUS_BRICK_LEN55; |
1582 | int bricklen = 0; |
1583 | char *p = NULL((void*)0); |
1584 | int num_tabs = 0; |
1585 | |
1586 | p = status->brick; |
1587 | bricklen = strlen (p); |
1588 | while (bricklen > 0) { |
1589 | if (bricklen > fieldlen) { |
1590 | cli_out ("%.*s", fieldlen, p)do { do { if (0) printf ("%.*s", fieldlen, p); } while (0); _cli_out ("%.*s", fieldlen, p); } while (0); |
1591 | p += fieldlen; |
1592 | bricklen -= fieldlen; |
1593 | } else { |
1594 | num_tabs = (fieldlen - bricklen) / CLI_TAB_LENGTH8 + 1; |
1595 | printf ("%s", p); |
1596 | while (num_tabs-- != 0) |
1597 | printf ("\t"); |
1598 | if (status->port) { |
1599 | if (status->online) |
1600 | cli_out ("%d\t%c\t%s",do { do { if (0) printf ("%d\t%c\t%s", status->port, status ->online?'Y':'N', status->pid_str); } while (0); _cli_out ("%d\t%c\t%s", status->port, status->online?'Y':'N', status ->pid_str); } while (0) |
1601 | status->port,do { do { if (0) printf ("%d\t%c\t%s", status->port, status ->online?'Y':'N', status->pid_str); } while (0); _cli_out ("%d\t%c\t%s", status->port, status->online?'Y':'N', status ->pid_str); } while (0) |
1602 | status->online?'Y':'N',do { do { if (0) printf ("%d\t%c\t%s", status->port, status ->online?'Y':'N', status->pid_str); } while (0); _cli_out ("%d\t%c\t%s", status->port, status->online?'Y':'N', status ->pid_str); } while (0) |
1603 | status->pid_str)do { do { if (0) printf ("%d\t%c\t%s", status->port, status ->online?'Y':'N', status->pid_str); } while (0); _cli_out ("%d\t%c\t%s", status->port, status->online?'Y':'N', status ->pid_str); } while (0); |
1604 | else |
1605 | cli_out ("%s\t%c\t%s",do { do { if (0) printf ("%s\t%c\t%s", "N/A", status->online ?'Y':'N', status->pid_str); } while (0); _cli_out("%s\t%c\t%s" , "N/A", status->online?'Y':'N', status->pid_str); } while (0) |
1606 | "N/A",do { do { if (0) printf ("%s\t%c\t%s", "N/A", status->online ?'Y':'N', status->pid_str); } while (0); _cli_out("%s\t%c\t%s" , "N/A", status->online?'Y':'N', status->pid_str); } while (0) |
1607 | status->online?'Y':'N',do { do { if (0) printf ("%s\t%c\t%s", "N/A", status->online ?'Y':'N', status->pid_str); } while (0); _cli_out("%s\t%c\t%s" , "N/A", status->online?'Y':'N', status->pid_str); } while (0) |
1608 | status->pid_str)do { do { if (0) printf ("%s\t%c\t%s", "N/A", status->online ?'Y':'N', status->pid_str); } while (0); _cli_out("%s\t%c\t%s" , "N/A", status->online?'Y':'N', status->pid_str); } while (0); |
1609 | } |
1610 | else |
1611 | cli_out ("%s\t%c\t%s",do { do { if (0) printf ("%s\t%c\t%s", "N/A", status->online ?'Y':'N', status->pid_str); } while (0); _cli_out("%s\t%c\t%s" , "N/A", status->online?'Y':'N', status->pid_str); } while (0) |
1612 | "N/A", status->online?'Y':'N',do { do { if (0) printf ("%s\t%c\t%s", "N/A", status->online ?'Y':'N', status->pid_str); } while (0); _cli_out("%s\t%c\t%s" , "N/A", status->online?'Y':'N', status->pid_str); } while (0) |
1613 | status->pid_str)do { do { if (0) printf ("%s\t%c\t%s", "N/A", status->online ?'Y':'N', status->pid_str); } while (0); _cli_out("%s\t%c\t%s" , "N/A", status->online?'Y':'N', status->pid_str); } while (0); |
1614 | bricklen = 0; |
1615 | } |
1616 | } |
1617 | |
1618 | return 0; |
1619 | } |
1620 | |
1621 | int |
1622 | cli_cmd_volume_heal_cbk (struct cli_state *state, struct cli_cmd_word *word, |
1623 | const char **words, int wordcount) |
1624 | { |
1625 | int ret = -1; |
1626 | rpc_clnt_procedure_t *proc = NULL((void*)0); |
1627 | call_frame_t *frame = NULL((void*)0); |
1628 | int sent = 0; |
1629 | int parse_error = 0; |
1630 | dict_t *options = NULL((void*)0); |
1631 | xlator_t *this = NULL((void*)0); |
1632 | cli_local_t *local = NULL((void*)0); |
1633 | |
1634 | this = THIS(*__glusterfs_this_location()); |
1635 | frame = create_frame (this, this->ctx->pool); |
1636 | if (!frame) |
1637 | goto out; |
1638 | |
1639 | if (wordcount < 3) { |
1640 | cli_usage_out (word->pattern); |
1641 | parse_error = 1; |
1642 | goto out; |
1643 | } |
1644 | |
1645 | ret = cli_cmd_volume_heal_options_parse (words, wordcount, &options); |
1646 | if (ret) { |
1647 | cli_usage_out (word->pattern); |
1648 | parse_error = 1; |
1649 | goto out; |
1650 | } |
1651 | |
1652 | proc = &cli_rpc_prog->proctable[GLUSTER_CLI_HEAL_VOLUME]; |
1653 | |
1654 | CLI_LOCAL_INIT (local, words, frame, options)do { local = cli_local_get (); if (local) { local->words = words; if (options) local->dict = options; if (frame) frame ->local = local; } } while (0); |
1655 | |
1656 | if (proc->fn) { |
1657 | ret = proc->fn (frame, THIS(*__glusterfs_this_location()), options); |
1658 | } |
1659 | |
1660 | out: |
1661 | if (ret) { |
1662 | cli_cmd_sent_status_get (&sent); |
1663 | if ((sent == 0) && (parse_error == 0)) |
1664 | cli_out ("Volume heal failed")do { do { if (0) printf ("Volume heal failed"); } while (0); _cli_out ("Volume heal failed"); } while (0); |
1665 | } |
1666 | |
1667 | CLI_STACK_DESTROY (frame)do { if (frame) { if (frame->local) { do { do { if (0) printf ("frame->local " "is not NULL (%p)", frame->local); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__, 1667, GF_LOG_DEBUG, "frame->local " "is not NULL (%p)", frame-> local); } while (0); cli_local_wipe (frame->local); frame-> local = ((void*)0); } STACK_DESTROY (frame->root); } } while (0);; |
1668 | |
1669 | return ret; |
1670 | } |
1671 | |
1672 | int |
1673 | cli_cmd_volume_statedump_cbk (struct cli_state *state, struct cli_cmd_word *word, |
1674 | const char **words, int wordcount) |
1675 | { |
1676 | int ret = -1; |
1677 | rpc_clnt_procedure_t *proc = NULL((void*)0); |
1678 | call_frame_t *frame = NULL((void*)0); |
1679 | dict_t *options = NULL((void*)0); |
1680 | int sent = 0; |
1681 | int parse_error = 0; |
1682 | cli_local_t *local = NULL((void*)0); |
1683 | |
1684 | frame = create_frame (THIS(*__glusterfs_this_location()), THIS(*__glusterfs_this_location())->ctx->pool); |
1685 | if (!frame) |
1686 | goto out; |
1687 | |
1688 | if (wordcount < 3) { |
1689 | cli_usage_out (word->pattern); |
1690 | parse_error = 1; |
1691 | goto out; |
1692 | } |
1693 | |
1694 | if (wordcount >= 3) { |
1695 | ret = cli_cmd_volume_statedump_options_parse (words, wordcount, |
1696 | &options); |
1697 | if (ret) { |
1698 | parse_error = 1; |
1699 | gf_log ("cli", GF_LOG_ERROR, "Error parsing "do { do { if (0) printf ("Error parsing " "statedump options" ); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__ , 1700, GF_LOG_ERROR, "Error parsing " "statedump options"); } while (0) |
1700 | "statedump options")do { do { if (0) printf ("Error parsing " "statedump options" ); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__ , 1700, GF_LOG_ERROR, "Error parsing " "statedump options"); } while (0); |
1701 | cli_out ("Error parsing options")do { do { if (0) printf ("Error parsing options"); } while (0 ); _cli_out("Error parsing options"); } while (0); |
1702 | cli_usage_out (word->pattern); |
1703 | } |
1704 | } |
1705 | |
1706 | ret = dict_set_str (options, "volname", (char *)words[2]); |
1707 | if (ret) |
1708 | goto out; |
1709 | |
1710 | proc = &cli_rpc_prog->proctable[GLUSTER_CLI_STATEDUMP_VOLUME]; |
1711 | |
1712 | CLI_LOCAL_INIT (local, words, frame, options)do { local = cli_local_get (); if (local) { local->words = words; if (options) local->dict = options; if (frame) frame ->local = local; } } while (0); |
1713 | |
1714 | if (proc->fn) { |
1715 | ret = proc->fn (frame, THIS(*__glusterfs_this_location()), options); |
1716 | } |
1717 | |
1718 | out: |
1719 | if (ret) { |
1720 | cli_cmd_sent_status_get (&sent); |
1721 | if ((sent == 0) && (parse_error = 0)) |
1722 | cli_out ("Volume statedump failed")do { do { if (0) printf ("Volume statedump failed"); } while ( 0); _cli_out("Volume statedump failed"); } while (0); |
1723 | } |
1724 | |
1725 | CLI_STACK_DESTROY (frame)do { if (frame) { if (frame->local) { do { do { if (0) printf ("frame->local " "is not NULL (%p)", frame->local); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__, 1725, GF_LOG_DEBUG, "frame->local " "is not NULL (%p)", frame-> local); } while (0); cli_local_wipe (frame->local); frame-> local = ((void*)0); } STACK_DESTROY (frame->root); } } while (0);; |
1726 | |
1727 | return ret; |
1728 | } |
1729 | |
1730 | int |
1731 | cli_cmd_volume_list_cbk (struct cli_state *state, struct cli_cmd_word *word, |
1732 | const char **words, int wordcount) |
1733 | { |
1734 | int ret = -1; |
1735 | call_frame_t *frame = NULL((void*)0); |
1736 | rpc_clnt_procedure_t *proc = NULL((void*)0); |
1737 | int sent = 0; |
1738 | |
1739 | frame = create_frame (THIS(*__glusterfs_this_location()), THIS(*__glusterfs_this_location())->ctx->pool); |
1740 | if (!frame) |
1741 | goto out; |
1742 | |
1743 | proc = &cli_rpc_prog->proctable[GLUSTER_CLI_LIST_VOLUME]; |
1744 | if (proc->fn) { |
1745 | ret = proc->fn (frame, THIS(*__glusterfs_this_location()), NULL((void*)0)); |
1746 | } |
1747 | |
1748 | out: |
1749 | if (ret) { |
1750 | cli_cmd_sent_status_get (&sent); |
1751 | if (sent == 0) |
1752 | cli_out ("Volume list failed")do { do { if (0) printf ("Volume list failed"); } while (0); _cli_out ("Volume list failed"); } while (0); |
1753 | } |
1754 | |
1755 | CLI_STACK_DESTROY (frame)do { if (frame) { if (frame->local) { do { do { if (0) printf ("frame->local " "is not NULL (%p)", frame->local); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__, 1755, GF_LOG_DEBUG, "frame->local " "is not NULL (%p)", frame-> local); } while (0); cli_local_wipe (frame->local); frame-> local = ((void*)0); } STACK_DESTROY (frame->root); } } while (0);; |
1756 | |
1757 | return ret; |
1758 | } |
1759 | |
1760 | int |
1761 | cli_cmd_volume_clearlocks_cbk (struct cli_state *state, |
1762 | struct cli_cmd_word *word, |
1763 | const char **words, int wordcount) |
1764 | { |
1765 | int ret = -1; |
1766 | rpc_clnt_procedure_t *proc = NULL((void*)0); |
1767 | call_frame_t *frame = NULL((void*)0); |
1768 | dict_t *options = NULL((void*)0); |
1769 | int sent = 0; |
1770 | int parse_error = 0; |
1771 | cli_local_t *local = NULL((void*)0); |
1772 | |
1773 | frame = create_frame (THIS(*__glusterfs_this_location()), THIS(*__glusterfs_this_location())->ctx->pool); |
1774 | if (!frame) |
1775 | goto out; |
1776 | |
1777 | if (wordcount < 7 || wordcount > 8) { |
1778 | cli_usage_out (word->pattern); |
1779 | parse_error = 1; |
1780 | goto out; |
1781 | } |
1782 | |
1783 | ret = cli_cmd_volume_clrlks_opts_parse (words, wordcount, &options); |
1784 | if (ret) { |
1785 | parse_error = 1; |
1786 | gf_log ("cli", GF_LOG_ERROR, "Error parsing "do { do { if (0) printf ("Error parsing " "clear-locks options" ); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__ , 1787, GF_LOG_ERROR, "Error parsing " "clear-locks options") ; } while (0) |
1787 | "clear-locks options")do { do { if (0) printf ("Error parsing " "clear-locks options" ); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__ , 1787, GF_LOG_ERROR, "Error parsing " "clear-locks options") ; } while (0); |
1788 | cli_out ("Error parsing options")do { do { if (0) printf ("Error parsing options"); } while (0 ); _cli_out("Error parsing options"); } while (0); |
1789 | cli_usage_out (word->pattern); |
1790 | } |
1791 | |
1792 | ret = dict_set_str (options, "volname", (char *)words[2]); |
1793 | if (ret) |
1794 | goto out; |
1795 | |
1796 | ret = dict_set_str (options, "path", (char *)words[3]); |
1797 | if (ret) |
1798 | goto out; |
1799 | |
1800 | proc = &cli_rpc_prog->proctable[GLUSTER_CLI_CLRLOCKS_VOLUME]; |
1801 | |
1802 | CLI_LOCAL_INIT (local, words, frame, options)do { local = cli_local_get (); if (local) { local->words = words; if (options) local->dict = options; if (frame) frame ->local = local; } } while (0); |
1803 | |
1804 | if (proc->fn) { |
1805 | ret = proc->fn (frame, THIS(*__glusterfs_this_location()), options); |
1806 | } |
1807 | |
1808 | out: |
1809 | if (ret) { |
1810 | cli_cmd_sent_status_get (&sent); |
1811 | if ((sent == 0) && (parse_error = 0)) |
1812 | cli_out ("Volume clear-locks failed")do { do { if (0) printf ("Volume clear-locks failed"); } while (0); _cli_out("Volume clear-locks failed"); } while (0); |
1813 | } |
1814 | |
1815 | CLI_STACK_DESTROY (frame)do { if (frame) { if (frame->local) { do { do { if (0) printf ("frame->local " "is not NULL (%p)", frame->local); } while (0); _gf_log ("cli", "cli-cmd-volume.c", __FUNCTION__, 1815, GF_LOG_DEBUG, "frame->local " "is not NULL (%p)", frame-> local); } while (0); cli_local_wipe (frame->local); frame-> local = ((void*)0); } STACK_DESTROY (frame->root); } } while (0);; |
1816 | |
1817 | return ret; |
1818 | } |
1819 | |
1820 | struct cli_cmd volume_cmds[] = { |
1821 | { "volume info [all|<VOLNAME>]", |
1822 | cli_cmd_volume_info_cbk, |
1823 | "list information of all volumes"}, |
1824 | |
1825 | { "volume create <NEW-VOLNAME> [stripe <COUNT>] [replica <COUNT>] " |
1826 | #ifdef HAVE_BD_XLATOR |
1827 | "[device vg] " |
1828 | #endif |
1829 | "[transport <tcp|rdma|tcp,rdma>] <NEW-BRICK> ... [force]", |
1830 | cli_cmd_volume_create_cbk, |
1831 | "create a new volume of specified type with mentioned bricks"}, |
1832 | |
1833 | { "volume delete <VOLNAME>", |
1834 | cli_cmd_volume_delete_cbk, |
1835 | "delete volume specified by <VOLNAME>"}, |
1836 | |
1837 | { "volume start <VOLNAME> [force]", |
1838 | cli_cmd_volume_start_cbk, |
1839 | "start volume specified by <VOLNAME>"}, |
1840 | |
1841 | { "volume stop <VOLNAME> [force]", |
1842 | cli_cmd_volume_stop_cbk, |
1843 | "stop volume specified by <VOLNAME>"}, |
1844 | |
1845 | /*{ "volume rename <VOLNAME> <NEW-VOLNAME>", |
1846 | cli_cmd_volume_rename_cbk, |
1847 | "rename volume <VOLNAME> to <NEW-VOLNAME>"},*/ |
1848 | |
1849 | { "volume add-brick <VOLNAME> [<stripe|replica> <COUNT>] <NEW-BRICK> ... [force]", |
1850 | cli_cmd_volume_add_brick_cbk, |
1851 | "add brick to volume <VOLNAME>"}, |
1852 | |
1853 | { "volume remove-brick <VOLNAME> [replica <COUNT>] <BRICK> ... {start|stop|status|commit|force}", |
1854 | cli_cmd_volume_remove_brick_cbk, |
1855 | "remove brick from volume <VOLNAME>"}, |
1856 | |
1857 | { "volume rebalance <VOLNAME> [fix-layout] {start|stop|status} [force]", |
1858 | cli_cmd_volume_defrag_cbk, |
1859 | "rebalance operations"}, |
1860 | |
1861 | { "volume replace-brick <VOLNAME> <BRICK> <NEW-BRICK> {start [force]|pause|abort|status|commit [force]}", |
1862 | cli_cmd_volume_replace_brick_cbk, |
1863 | "replace-brick operations"}, |
1864 | |
1865 | /*{ "volume set-transport <VOLNAME> <TRANSPORT-TYPE> [<TRANSPORT-TYPE>] ...", |
1866 | cli_cmd_volume_set_transport_cbk, |
1867 | "set transport type for volume <VOLNAME>"},*/ |
1868 | |
1869 | { "volume set <VOLNAME> <KEY> <VALUE>", |
1870 | cli_cmd_volume_set_cbk, |
1871 | "set options for volume <VOLNAME>"}, |
1872 | |
1873 | { "volume help", |
1874 | cli_cmd_volume_help_cbk, |
1875 | "display help for the volume command"}, |
1876 | |
1877 | { "volume log rotate <VOLNAME> [BRICK]", |
1878 | cli_cmd_log_rotate_cbk, |
1879 | "rotate the log file for corresponding volume/brick"}, |
1880 | |
1881 | { "volume sync <HOSTNAME> [all|<VOLNAME>]", |
1882 | cli_cmd_sync_volume_cbk, |
1883 | "sync the volume information from a peer"}, |
1884 | |
1885 | { "volume reset <VOLNAME> [option] [force]", |
1886 | cli_cmd_volume_reset_cbk, |
1887 | "reset all the reconfigured options"}, |
1888 | |
1889 | #if (SYNCDAEMON_COMPILE1) |
1890 | {"volume "GEOREP"geo-replication"" [<VOLNAME>] [<SLAVE-URL>] {start|stop|config|status|log-rotate} [options...]", |
1891 | cli_cmd_volume_gsync_set_cbk, |
1892 | "Geo-sync operations", |
1893 | cli_cmd_check_gsync_exists_cbk}, |
1894 | #endif |
1895 | |
1896 | { "volume profile <VOLNAME> {start|stop|info [nfs]}", |
1897 | cli_cmd_volume_profile_cbk, |
1898 | "volume profile operations"}, |
1899 | |
1900 | { "volume quota <VOLNAME> <enable|disable|limit-usage|list|remove> [path] [value]", |
1901 | cli_cmd_quota_cbk, |
1902 | "quota translator specific operations"}, |
1903 | |
1904 | { "volume top <VOLNAME> {open|read|write|opendir|readdir|clear} [nfs|brick <brick>] [list-cnt <value>] |\n" |
1905 | "volume top <VOLNAME> {read-perf|write-perf} [bs <size> count <count>] [brick <brick>] [list-cnt <value>]", |
1906 | cli_cmd_volume_top_cbk, |
1907 | "volume top operations"}, |
1908 | |
1909 | { "volume status [all | <VOLNAME> [nfs|shd|<BRICK>]]" |
1910 | " [detail|clients|mem|inode|fd|callpool]", |
1911 | cli_cmd_volume_status_cbk, |
1912 | "display status of all or specified volume(s)/brick"}, |
1913 | |
1914 | { "volume heal <VOLNAME> [{full | info {healed | heal-failed | split-brain}}]", |
1915 | cli_cmd_volume_heal_cbk, |
1916 | "self-heal commands on volume specified by <VOLNAME>"}, |
1917 | |
1918 | {"volume statedump <VOLNAME> [nfs] [all|mem|iobuf|callpool|priv|fd|" |
1919 | "inode|history]...", |
1920 | cli_cmd_volume_statedump_cbk, |
1921 | "perform statedump on bricks"}, |
1922 | |
1923 | {"volume list", |
1924 | cli_cmd_volume_list_cbk, |
1925 | "list all volumes in cluster"}, |
1926 | |
1927 | {"volume clear-locks <VOLNAME> <path> kind {blocked|granted|all}" |
1928 | "{inode [range]|entry [basename]|posix [range]}", |
1929 | cli_cmd_volume_clearlocks_cbk, |
1930 | "Clear locks held on path" |
1931 | }, |
1932 | |
1933 | { NULL((void*)0), NULL((void*)0), NULL((void*)0) } |
1934 | }; |
1935 | |
1936 | int |
1937 | cli_cmd_volume_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word, |
1938 | const char **words, int wordcount) |
1939 | { |
1940 | struct cli_cmd *cmd = NULL((void*)0); |
1941 | |
1942 | for (cmd = volume_cmds; cmd->pattern; cmd++) |
1943 | if (_gf_false == cmd->disable) |
1944 | cli_out ("%s - %s", cmd->pattern, cmd->desc)do { do { if (0) printf ("%s - %s", cmd->pattern, cmd-> desc); } while (0); _cli_out("%s - %s", cmd->pattern, cmd-> desc); } while (0); |
1945 | |
1946 | return 0; |
1947 | } |
1948 | |
1949 | int |
1950 | cli_cmd_volume_register (struct cli_state *state) |
1951 | { |
1952 | int ret = 0; |
1953 | struct cli_cmd *cmd = NULL((void*)0); |
1954 | |
1955 | for (cmd = volume_cmds; cmd->pattern; cmd++) { |
1956 | |
1957 | ret = cli_cmd_register (&state->tree, cmd); |
1958 | if (ret) |
1959 | goto out; |
1960 | } |
1961 | out: |
1962 | return ret; |
1963 | } |