File: | cli/src/cli-cmd-parser.c |
Location: | line 697, column 18 |
Description: | Dereference of null pointer (loaded from variable 'options') |
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 | #ifndef _CONFIG_H | |||||
17 | #define _CONFIG_H | |||||
18 | #include "config.h" | |||||
19 | #endif | |||||
20 | ||||||
21 | #include "cli.h" | |||||
22 | #include "cli-cmd.h" | |||||
23 | #include "cli-mem-types.h" | |||||
24 | #include "dict.h" | |||||
25 | ||||||
26 | #include "protocol-common.h" | |||||
27 | #include "cli1-xdr.h" | |||||
28 | ||||||
29 | static const char * | |||||
30 | id_sel (void *wcon) | |||||
31 | { | |||||
32 | return (const char *)wcon; | |||||
33 | } | |||||
34 | ||||||
35 | static char * | |||||
36 | str_getunamb (const char *tok, char **opwords) | |||||
37 | { | |||||
38 | return (char *)cli_getunamb (tok, (void **)opwords, id_sel); | |||||
39 | } | |||||
40 | ||||||
41 | int32_t | |||||
42 | cli_cmd_bricks_parse (const char **words, int wordcount, int brick_index, | |||||
43 | char **bricks, int *brick_count) | |||||
44 | { | |||||
45 | int ret = 0; | |||||
46 | char *tmp_list = NULL((void*)0); | |||||
47 | char brick_list[120000] = {0,}; | |||||
48 | char *space = " "; | |||||
49 | char *delimiter = NULL((void*)0); | |||||
50 | char *host_name = NULL((void*)0); | |||||
51 | char *free_list_ptr = NULL((void*)0); | |||||
52 | char *tmpptr = NULL((void*)0); | |||||
53 | int j = 0; | |||||
54 | int brick_list_len = 0; | |||||
55 | char *tmp_host = NULL((void*)0); | |||||
56 | ||||||
57 | GF_ASSERT (words)do { if (!(words)) { do { do { if (0) printf ("Assertion failed: " "words"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 57, GF_LOG_ERROR, "Assertion failed: " "words" ); } while (0); } } while (0); | |||||
58 | GF_ASSERT (wordcount)do { if (!(wordcount)) { do { do { if (0) printf ("Assertion failed: " "wordcount"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 58, GF_LOG_ERROR, "Assertion failed: " "wordcount" ); } while (0); } } while (0); | |||||
59 | GF_ASSERT (bricks)do { if (!(bricks)) { do { do { if (0) printf ("Assertion failed: " "bricks"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 59, GF_LOG_ERROR, "Assertion failed: " "bricks" ); } while (0); } } while (0); | |||||
60 | GF_ASSERT (brick_index > 0)do { if (!(brick_index > 0)) { do { do { if (0) printf ("Assertion failed: " "brick_index > 0"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 60, GF_LOG_ERROR, "Assertion failed: " "brick_index > 0" ); } while (0); } } while (0); | |||||
61 | GF_ASSERT (brick_index < wordcount)do { if (!(brick_index < wordcount)) { do { do { if (0) printf ("Assertion failed: " "brick_index < wordcount"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c", __FUNCTION__ , 61, GF_LOG_ERROR, "Assertion failed: " "brick_index < wordcount" ); } while (0); } } while (0); | |||||
62 | ||||||
63 | strncpy (brick_list, space, strlen (space)); | |||||
64 | brick_list_len++; | |||||
65 | while (brick_index < wordcount) { | |||||
66 | if (validate_brick_name ((char *)words[brick_index])) { | |||||
67 | cli_err ("Wrong brick type: %s, use <HOSTNAME>:"do { do { if (0) printf ("Wrong brick type: %s, use <HOSTNAME>:" "<export-dir-abs-path>", words[brick_index]); } while ( 0); _cli_err("Wrong brick type: %s, use <HOSTNAME>:" "<export-dir-abs-path>" , words[brick_index]); } while (0) | |||||
68 | "<export-dir-abs-path>", words[brick_index])do { do { if (0) printf ("Wrong brick type: %s, use <HOSTNAME>:" "<export-dir-abs-path>", words[brick_index]); } while ( 0); _cli_err("Wrong brick type: %s, use <HOSTNAME>:" "<export-dir-abs-path>" , words[brick_index]); } while (0); | |||||
69 | ret = -1; | |||||
70 | goto out; | |||||
71 | } else { | |||||
72 | delimiter = strrchr (words[brick_index], ':'); | |||||
73 | ret = gf_canonicalize_path (delimiter + 1); | |||||
74 | if (ret) | |||||
75 | goto out; | |||||
76 | } | |||||
77 | ||||||
78 | if ((brick_list_len + strlen (words[brick_index]) + 1) > sizeof (brick_list)) { | |||||
79 | cli_err ("Total brick list is larger than a request. "do { do { if (0) printf ("Total brick list is larger than a request. " "Can take (brick_count %d)", *brick_count); } while (0); _cli_err ("Total brick list is larger than a request. " "Can take (brick_count %d)" , *brick_count); } while (0) | |||||
80 | "Can take (brick_count %d)", *brick_count)do { do { if (0) printf ("Total brick list is larger than a request. " "Can take (brick_count %d)", *brick_count); } while (0); _cli_err ("Total brick list is larger than a request. " "Can take (brick_count %d)" , *brick_count); } while (0); | |||||
81 | ret = -1; | |||||
82 | goto out; | |||||
83 | } | |||||
84 | ||||||
85 | tmp_host = gf_strdup ((char *)words[brick_index]); | |||||
86 | if (!tmp_host) { | |||||
87 | gf_log ("cli", GF_LOG_ERROR, "Out of memory")do { do { if (0) printf ("Out of memory"); } while (0); _gf_log ("cli", "cli-cmd-parser.c", __FUNCTION__, 87, GF_LOG_ERROR, "Out of memory" ); } while (0); | |||||
88 | ret = -1; | |||||
89 | goto out; | |||||
90 | } | |||||
91 | get_host_name (tmp_host, &host_name); | |||||
92 | if (!host_name) { | |||||
93 | ret = -1; | |||||
94 | gf_log("cli",GF_LOG_ERROR, "Unable to allocate "do { do { if (0) printf ("Unable to allocate " "memory"); } while (0); _gf_log ("cli", "cli-cmd-parser.c", __FUNCTION__, 95, GF_LOG_ERROR , "Unable to allocate " "memory"); } while (0) | |||||
95 | "memory")do { do { if (0) printf ("Unable to allocate " "memory"); } while (0); _gf_log ("cli", "cli-cmd-parser.c", __FUNCTION__, 95, GF_LOG_ERROR , "Unable to allocate " "memory"); } while (0); | |||||
96 | goto out; | |||||
97 | } | |||||
98 | ||||||
99 | if (!(strcmp (host_name, "localhost") && | |||||
100 | strcmp (host_name, "127.0.0.1") && | |||||
101 | strncmp (host_name, "0.", 2))) { | |||||
102 | cli_err ("Please provide a valid hostname/ip other "do { do { if (0) printf ("Please provide a valid hostname/ip other " "than localhost, 127.0.0.1 or loopback " "address (0.0.0.0 to 0.255.255.255)." ); } while (0); _cli_err("Please provide a valid hostname/ip other " "than localhost, 127.0.0.1 or loopback " "address (0.0.0.0 to 0.255.255.255)." ); } while (0) | |||||
103 | "than localhost, 127.0.0.1 or loopback "do { do { if (0) printf ("Please provide a valid hostname/ip other " "than localhost, 127.0.0.1 or loopback " "address (0.0.0.0 to 0.255.255.255)." ); } while (0); _cli_err("Please provide a valid hostname/ip other " "than localhost, 127.0.0.1 or loopback " "address (0.0.0.0 to 0.255.255.255)." ); } while (0) | |||||
104 | "address (0.0.0.0 to 0.255.255.255).")do { do { if (0) printf ("Please provide a valid hostname/ip other " "than localhost, 127.0.0.1 or loopback " "address (0.0.0.0 to 0.255.255.255)." ); } while (0); _cli_err("Please provide a valid hostname/ip other " "than localhost, 127.0.0.1 or loopback " "address (0.0.0.0 to 0.255.255.255)." ); } while (0); | |||||
105 | ret = -1; | |||||
106 | GF_FREE (tmp_host)__gf_free (tmp_host); | |||||
107 | goto out; | |||||
108 | } | |||||
109 | if (!valid_internet_address (host_name, _gf_false)) { | |||||
110 | cli_err ("internet address '%s' does not conform to "do { do { if (0) printf ("internet address '%s' does not conform to " "standards", host_name); } while (0); _cli_err("internet address '%s' does not conform to " "standards", host_name); } while (0) | |||||
111 | "standards", host_name)do { do { if (0) printf ("internet address '%s' does not conform to " "standards", host_name); } while (0); _cli_err("internet address '%s' does not conform to " "standards", host_name); } while (0); | |||||
112 | } | |||||
113 | GF_FREE (tmp_host)__gf_free (tmp_host); | |||||
114 | tmp_list = gf_strdup (brick_list + 1); | |||||
115 | if (free_list_ptr) { | |||||
116 | GF_FREE (free_list_ptr)__gf_free (free_list_ptr); | |||||
117 | free_list_ptr = NULL((void*)0); | |||||
118 | } | |||||
119 | free_list_ptr = tmp_list; | |||||
120 | j = 0; | |||||
121 | while(j < *brick_count) { | |||||
122 | strtok_r (tmp_list, " ", &tmpptr); | |||||
123 | if (!(strcmp (tmp_list, words[brick_index]))) { | |||||
124 | ret = -1; | |||||
125 | cli_err ("Found duplicate"do { do { if (0) printf ("Found duplicate" " exports %s",words [brick_index]); } while (0); _cli_err("Found duplicate" " exports %s" ,words[brick_index]); } while (0) | |||||
126 | " exports %s",words[brick_index])do { do { if (0) printf ("Found duplicate" " exports %s",words [brick_index]); } while (0); _cli_err("Found duplicate" " exports %s" ,words[brick_index]); } while (0); | |||||
127 | goto out; | |||||
128 | } | |||||
129 | tmp_list = tmpptr; | |||||
130 | j++; | |||||
131 | } | |||||
132 | strcat (brick_list, words[brick_index]); | |||||
133 | strcat (brick_list, " "); | |||||
134 | brick_list_len += (strlen (words[brick_index]) + 1); | |||||
135 | ++(*brick_count); | |||||
136 | ++brick_index; | |||||
137 | } | |||||
138 | ||||||
139 | *bricks = gf_strdup (brick_list); | |||||
140 | if (!*bricks) | |||||
141 | ret = -1; | |||||
142 | out: | |||||
143 | GF_FREE (free_list_ptr)__gf_free (free_list_ptr); | |||||
144 | return ret; | |||||
145 | } | |||||
146 | ||||||
147 | int32_t | |||||
148 | cli_cmd_volume_create_parse (const char **words, int wordcount, dict_t **options) | |||||
149 | { | |||||
150 | dict_t *dict = NULL((void*)0); | |||||
151 | char *volname = NULL((void*)0); | |||||
152 | int ret = -1; | |||||
153 | gf1_cluster_type type = GF_CLUSTER_TYPE_NONE; | |||||
154 | int count = 1; | |||||
155 | int sub_count = 1; | |||||
156 | int brick_index = 0; | |||||
157 | int i = 0; | |||||
158 | char *trans_type = NULL((void*)0); | |||||
159 | int32_t index = 0; | |||||
160 | char *bricks = NULL((void*)0); | |||||
161 | int32_t brick_count = 0; | |||||
162 | char *opwords[] = { "replica", "stripe", "transport", | |||||
163 | #ifdef HAVE_BD_XLATOR | |||||
164 | "device", | |||||
165 | #endif | |||||
166 | NULL((void*)0) }; | |||||
167 | ||||||
168 | char *invalid_volnames[] = {"volume", "type", "subvolumes", "option", | |||||
169 | "end-volume", "all", "volume_not_in_ring", | |||||
170 | NULL((void*)0)}; | |||||
171 | char *w = NULL((void*)0); | |||||
172 | int op_count = 0; | |||||
173 | int32_t replica_count = 1; | |||||
174 | int32_t stripe_count = 1; | |||||
175 | #ifdef HAVE_BD_XLATOR | |||||
176 | char *dev_type = NULL((void*)0); | |||||
177 | #endif | |||||
178 | gf_boolean_t is_force = _gf_false; | |||||
179 | int wc = wordcount; | |||||
180 | ||||||
181 | GF_ASSERT (words)do { if (!(words)) { do { do { if (0) printf ("Assertion failed: " "words"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 181, GF_LOG_ERROR, "Assertion failed: " "words" ); } while (0); } } while (0); | |||||
182 | GF_ASSERT (options)do { if (!(options)) { do { do { if (0) printf ("Assertion failed: " "options"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 182, GF_LOG_ERROR, "Assertion failed: " "options" ); } while (0); } } while (0); | |||||
183 | ||||||
184 | dict = dict_new (); | |||||
185 | ||||||
186 | if (!dict) | |||||
187 | goto out; | |||||
188 | ||||||
189 | if (wordcount < 3) | |||||
190 | goto out; | |||||
191 | ||||||
192 | volname = (char *)words[2]; | |||||
193 | ||||||
194 | GF_ASSERT (volname)do { if (!(volname)) { do { do { if (0) printf ("Assertion failed: " "volname"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 194, GF_LOG_ERROR, "Assertion failed: " "volname" ); } while (0); } } while (0); | |||||
195 | ||||||
196 | /* Validate the volume name here itself */ | |||||
197 | { | |||||
198 | if (volname[0] == '-') | |||||
199 | goto out; | |||||
200 | ||||||
201 | for (i = 0; invalid_volnames[i]; i++) { | |||||
202 | if (!strcmp (volname, invalid_volnames[i])) { | |||||
203 | cli_err ("\"%s\" cannot be the name of a volume.",do { do { if (0) printf ("\"%s\" cannot be the name of a volume." , volname); } while (0); _cli_err("\"%s\" cannot be the name of a volume." , volname); } while (0) | |||||
204 | volname)do { do { if (0) printf ("\"%s\" cannot be the name of a volume." , volname); } while (0); _cli_err("\"%s\" cannot be the name of a volume." , volname); } while (0); | |||||
205 | goto out; | |||||
206 | } | |||||
207 | } | |||||
208 | ||||||
209 | if (strchr (volname, '/')) | |||||
210 | goto out; | |||||
211 | ||||||
212 | if (strlen (volname) > 512) | |||||
213 | goto out; | |||||
214 | ||||||
215 | for (i = 0; i < strlen (volname); i++) | |||||
216 | if (!isalnum (volname[i])((*__ctype_b_loc ())[(int) ((volname[i]))] & (unsigned short int) _ISalnum) && (volname[i] != '_') && (volname[i] != '-')) | |||||
217 | goto out; | |||||
218 | } | |||||
219 | ||||||
220 | if (wordcount < 4) { | |||||
221 | ret = -1; | |||||
222 | goto out; | |||||
223 | } | |||||
224 | ||||||
225 | type = GF_CLUSTER_TYPE_NONE; | |||||
226 | index = 3; | |||||
227 | ||||||
228 | while (op_count < 3) { | |||||
229 | ret = -1; | |||||
230 | w = str_getunamb (words[index], opwords); | |||||
231 | if (!w) { | |||||
232 | break; | |||||
233 | } else if ((strcmp (w, "replica")) == 0) { | |||||
234 | switch (type) { | |||||
235 | case GF_CLUSTER_TYPE_STRIPE_REPLICATE: | |||||
236 | case GF_CLUSTER_TYPE_REPLICATE: | |||||
237 | cli_err ("replica option given twice")do { do { if (0) printf ("replica option given twice"); } while (0); _cli_err("replica option given twice"); } while (0); | |||||
238 | goto out; | |||||
239 | case GF_CLUSTER_TYPE_NONE: | |||||
240 | type = GF_CLUSTER_TYPE_REPLICATE; | |||||
241 | break; | |||||
242 | case GF_CLUSTER_TYPE_STRIPE: | |||||
243 | type = GF_CLUSTER_TYPE_STRIPE_REPLICATE; | |||||
244 | break; | |||||
245 | } | |||||
246 | ||||||
247 | if (wordcount < (index+2)) { | |||||
248 | ret = -1; | |||||
249 | goto out; | |||||
250 | } | |||||
251 | replica_count = strtol (words[index+1], NULL((void*)0), 0); | |||||
252 | if (replica_count < 2) { | |||||
253 | cli_err ("replica count should be greater"do { do { if (0) printf ("replica count should be greater" " than 1" ); } while (0); _cli_err("replica count should be greater" " than 1" ); } while (0) | |||||
254 | " than 1")do { do { if (0) printf ("replica count should be greater" " than 1" ); } while (0); _cli_err("replica count should be greater" " than 1" ); } while (0); | |||||
255 | ret = -1; | |||||
256 | goto out; | |||||
257 | } | |||||
258 | ret = dict_set_int32 (dict, "replica-count", replica_count); | |||||
259 | if (ret) | |||||
260 | goto out; | |||||
261 | ||||||
262 | index += 2; | |||||
263 | ||||||
264 | } else if ((strcmp (w, "stripe")) == 0) { | |||||
265 | switch (type) { | |||||
266 | case GF_CLUSTER_TYPE_STRIPE_REPLICATE: | |||||
267 | case GF_CLUSTER_TYPE_STRIPE: | |||||
268 | cli_err ("stripe option given twice")do { do { if (0) printf ("stripe option given twice"); } while (0); _cli_err("stripe option given twice"); } while (0); | |||||
269 | goto out; | |||||
270 | case GF_CLUSTER_TYPE_NONE: | |||||
271 | type = GF_CLUSTER_TYPE_STRIPE; | |||||
272 | break; | |||||
273 | case GF_CLUSTER_TYPE_REPLICATE: | |||||
274 | type = GF_CLUSTER_TYPE_STRIPE_REPLICATE; | |||||
275 | break; | |||||
276 | } | |||||
277 | if (wordcount < (index + 2)) { | |||||
278 | ret = -1; | |||||
279 | goto out; | |||||
280 | } | |||||
281 | stripe_count = strtol (words[index+1], NULL((void*)0), 0); | |||||
282 | if (stripe_count < 2) { | |||||
283 | cli_err ("stripe count should be greater"do { do { if (0) printf ("stripe count should be greater" " than 1" ); } while (0); _cli_err("stripe count should be greater" " than 1" ); } while (0) | |||||
284 | " than 1")do { do { if (0) printf ("stripe count should be greater" " than 1" ); } while (0); _cli_err("stripe count should be greater" " than 1" ); } while (0); | |||||
285 | ret = -1; | |||||
286 | goto out; | |||||
287 | } | |||||
288 | ret = dict_set_int32 (dict, "stripe-count", stripe_count); | |||||
289 | if (ret) | |||||
290 | goto out; | |||||
291 | ||||||
292 | index += 2; | |||||
293 | ||||||
294 | } else if ((strcmp (w, "transport")) == 0) { | |||||
295 | if (trans_type) { | |||||
296 | cli_err ("'transport' option given more"do { do { if (0) printf ("'transport' option given more" " than one time" ); } while (0); _cli_err("'transport' option given more" " than one time" ); } while (0) | |||||
297 | " than one time")do { do { if (0) printf ("'transport' option given more" " than one time" ); } while (0); _cli_err("'transport' option given more" " than one time" ); } while (0); | |||||
298 | goto out; | |||||
299 | } | |||||
300 | if ((strcasecmp (words[index+1], "tcp") == 0)) { | |||||
301 | trans_type = gf_strdup ("tcp"); | |||||
302 | } else if ((strcasecmp (words[index+1], "rdma") == 0)) { | |||||
303 | trans_type = gf_strdup ("rdma"); | |||||
304 | } else if ((strcasecmp (words[index+1], "tcp,rdma") == 0) || | |||||
305 | (strcasecmp (words[index+1], "rdma,tcp") == 0)) { | |||||
306 | trans_type = gf_strdup ("tcp,rdma"); | |||||
307 | } else { | |||||
308 | gf_log ("", GF_LOG_ERROR, "incorrect transport"do { do { if (0) printf ("incorrect transport" " protocol specified" ); } while (0); _gf_log ("", "cli-cmd-parser.c", __FUNCTION__ , 309, GF_LOG_ERROR, "incorrect transport" " protocol specified" ); } while (0) | |||||
309 | " protocol specified")do { do { if (0) printf ("incorrect transport" " protocol specified" ); } while (0); _gf_log ("", "cli-cmd-parser.c", __FUNCTION__ , 309, GF_LOG_ERROR, "incorrect transport" " protocol specified" ); } while (0); | |||||
310 | ret = -1; | |||||
311 | goto out; | |||||
312 | } | |||||
313 | index += 2; | |||||
314 | } | |||||
315 | #ifdef HAVE_BD_XLATOR | |||||
316 | else if ((strcmp (w, "device")) == 0) { | |||||
317 | if (dev_type) { | |||||
318 | cli_err ("'device' option given more"do { do { if (0) printf ("'device' option given more" " than one time" ); } while (0); _cli_err("'device' option given more" " than one time" ); } while (0) | |||||
319 | " than one time")do { do { if (0) printf ("'device' option given more" " than one time" ); } while (0); _cli_err("'device' option given more" " than one time" ); } while (0); | |||||
320 | goto out; | |||||
321 | } | |||||
322 | if ((strcasecmp (words[index+1], "vg") == 0)) { | |||||
323 | dev_type = gf_strdup ("vg"); | |||||
324 | } else { | |||||
325 | gf_log ("", GF_LOG_ERROR, "incorrect"do { do { if (0) printf ("incorrect" " device type specified" ); } while (0); _gf_log ("", "cli-cmd-parser.c", __FUNCTION__ , 326, GF_LOG_ERROR, "incorrect" " device type specified"); } while (0) | |||||
326 | " device type specified")do { do { if (0) printf ("incorrect" " device type specified" ); } while (0); _gf_log ("", "cli-cmd-parser.c", __FUNCTION__ , 326, GF_LOG_ERROR, "incorrect" " device type specified"); } while (0); | |||||
327 | ret = -1; | |||||
328 | goto out; | |||||
329 | } | |||||
330 | index += 2; | |||||
331 | } | |||||
332 | #endif | |||||
333 | else { | |||||
334 | GF_ASSERT (!"opword mismatch")do { if (!(!"opword mismatch")) { do { do { if (0) printf ("Assertion failed: " "!\"opword mismatch\""); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c", __FUNCTION__, 334, GF_LOG_ERROR, "Assertion failed: " "!\"opword mismatch\""); } while (0); } } while (0); | |||||
335 | ret = -1; | |||||
336 | goto out; | |||||
337 | } | |||||
338 | op_count++; | |||||
339 | } | |||||
340 | ||||||
341 | if (!trans_type) | |||||
342 | trans_type = gf_strdup ("tcp"); | |||||
343 | ||||||
344 | sub_count = stripe_count * replica_count; | |||||
345 | ||||||
346 | /* reset the count value now */ | |||||
347 | count = 1; | |||||
348 | ||||||
349 | if (index >= wordcount) { | |||||
350 | ret = -1; | |||||
351 | goto out; | |||||
352 | } | |||||
353 | ||||||
354 | brick_index = index; | |||||
355 | ||||||
356 | if (strcmp (words[wordcount - 1], "force") == 0) { | |||||
357 | is_force = _gf_true; | |||||
358 | wc = wordcount - 1; | |||||
359 | } | |||||
360 | ||||||
361 | ret = cli_cmd_bricks_parse (words, wc, brick_index, &bricks, | |||||
362 | &brick_count); | |||||
363 | if (ret) | |||||
364 | goto out; | |||||
365 | ||||||
366 | /* If brick-count is not valid when replica or stripe is | |||||
367 | given, exit here */ | |||||
368 | if (!brick_count) { | |||||
369 | cli_err ("No bricks specified")do { do { if (0) printf ("No bricks specified"); } while (0); _cli_err("No bricks specified"); } while (0); | |||||
370 | ret = -1; | |||||
371 | goto out; | |||||
372 | } | |||||
373 | ||||||
374 | /* BD xlator does not support multiple bricks */ | |||||
375 | #ifdef HAVE_BD_XLATOR | |||||
376 | if (brick_count > 1 && dev_type) { | |||||
377 | cli_err ("Block Device backend volume does not support multiple"do { do { if (0) printf ("Block Device backend volume does not support multiple" " bricks"); } while (0); _cli_err("Block Device backend volume does not support multiple" " bricks"); } while (0) | |||||
378 | " bricks")do { do { if (0) printf ("Block Device backend volume does not support multiple" " bricks"); } while (0); _cli_err("Block Device backend volume does not support multiple" " bricks"); } while (0); | |||||
379 | gf_log ("", GF_LOG_ERROR,do { do { if (0) printf ("Block Device backend volume does not support multiple" " bricks"); } while (0); _gf_log ("", "cli-cmd-parser.c", __FUNCTION__ , 381, GF_LOG_ERROR, "Block Device backend volume does not support multiple" " bricks"); } while (0) | |||||
380 | "Block Device backend volume does not support multiple"do { do { if (0) printf ("Block Device backend volume does not support multiple" " bricks"); } while (0); _gf_log ("", "cli-cmd-parser.c", __FUNCTION__ , 381, GF_LOG_ERROR, "Block Device backend volume does not support multiple" " bricks"); } while (0) | |||||
381 | " bricks")do { do { if (0) printf ("Block Device backend volume does not support multiple" " bricks"); } while (0); _gf_log ("", "cli-cmd-parser.c", __FUNCTION__ , 381, GF_LOG_ERROR, "Block Device backend volume does not support multiple" " bricks"); } while (0); | |||||
382 | ret = -1; | |||||
383 | goto out; | |||||
384 | } | |||||
385 | #endif | |||||
386 | ||||||
387 | if (brick_count % sub_count) { | |||||
388 | if (type == GF_CLUSTER_TYPE_STRIPE) | |||||
389 | cli_err ("number of bricks is not a multiple of "do { do { if (0) printf ("number of bricks is not a multiple of " "stripe count"); } while (0); _cli_err("number of bricks is not a multiple of " "stripe count"); } while (0) | |||||
390 | "stripe count")do { do { if (0) printf ("number of bricks is not a multiple of " "stripe count"); } while (0); _cli_err("number of bricks is not a multiple of " "stripe count"); } while (0); | |||||
391 | else if (type == GF_CLUSTER_TYPE_REPLICATE) | |||||
392 | cli_err ("number of bricks is not a multiple of "do { do { if (0) printf ("number of bricks is not a multiple of " "replica count"); } while (0); _cli_err("number of bricks is not a multiple of " "replica count"); } while (0) | |||||
393 | "replica count")do { do { if (0) printf ("number of bricks is not a multiple of " "replica count"); } while (0); _cli_err("number of bricks is not a multiple of " "replica count"); } while (0); | |||||
394 | else | |||||
395 | cli_err ("number of bricks given doesn't match "do { do { if (0) printf ("number of bricks given doesn't match " "required count"); } while (0); _cli_err("number of bricks given doesn't match " "required count"); } while (0) | |||||
396 | "required count")do { do { if (0) printf ("number of bricks given doesn't match " "required count"); } while (0); _cli_err("number of bricks given doesn't match " "required count"); } while (0); | |||||
397 | ||||||
398 | ret = -1; | |||||
399 | goto out; | |||||
400 | } | |||||
401 | ||||||
402 | /* Everything if parsed fine. start setting info in dict */ | |||||
403 | ret = dict_set_str (dict, "volname", volname); | |||||
404 | if (ret) | |||||
405 | goto out; | |||||
406 | ||||||
407 | ret = dict_set_int32 (dict, "type", type); | |||||
408 | if (ret) | |||||
409 | goto out; | |||||
410 | ||||||
411 | ret = dict_set_dynstr (dict, "transport", trans_type); | |||||
412 | if (ret) | |||||
413 | goto out; | |||||
414 | trans_type = NULL((void*)0); | |||||
415 | ||||||
416 | ret = dict_set_dynstr (dict, "bricks", bricks); | |||||
417 | if (ret) | |||||
418 | goto out; | |||||
419 | ||||||
420 | #ifdef HAVE_BD_XLATOR | |||||
421 | if (dev_type) { | |||||
422 | ret = dict_set_dynstr (dict, "device", dev_type); | |||||
423 | if (ret) | |||||
424 | goto out; | |||||
425 | } | |||||
426 | #endif | |||||
427 | ||||||
428 | ret = dict_set_int32 (dict, "count", brick_count); | |||||
429 | if (ret) | |||||
430 | goto out; | |||||
431 | ||||||
432 | ret = dict_set_int32 (dict, "force", is_force); | |||||
433 | if (ret) | |||||
434 | goto out; | |||||
435 | ||||||
436 | *options = dict; | |||||
437 | ||||||
438 | out: | |||||
439 | if (ret) { | |||||
440 | gf_log ("cli", GF_LOG_ERROR, "Unable to parse create volume CLI")do { do { if (0) printf ("Unable to parse create volume CLI") ; } while (0); _gf_log ("cli", "cli-cmd-parser.c", __FUNCTION__ , 440, GF_LOG_ERROR, "Unable to parse create volume CLI"); } while (0); | |||||
441 | if (dict) | |||||
442 | dict_destroy (dict); | |||||
443 | } | |||||
444 | ||||||
445 | GF_FREE (trans_type)__gf_free (trans_type); | |||||
446 | ||||||
447 | return ret; | |||||
448 | } | |||||
449 | ||||||
450 | int32_t | |||||
451 | cli_cmd_volume_reset_parse (const char **words, int wordcount, dict_t **options) | |||||
452 | { | |||||
453 | dict_t *dict = NULL((void*)0); | |||||
454 | char *volname = NULL((void*)0); | |||||
455 | int ret = -1; | |||||
456 | ||||||
457 | GF_ASSERT (words)do { if (!(words)) { do { do { if (0) printf ("Assertion failed: " "words"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 457, GF_LOG_ERROR, "Assertion failed: " "words" ); } while (0); } } while (0); | |||||
458 | GF_ASSERT (options)do { if (!(options)) { do { do { if (0) printf ("Assertion failed: " "options"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 458, GF_LOG_ERROR, "Assertion failed: " "options" ); } while (0); } } while (0); | |||||
459 | ||||||
460 | dict = dict_new (); | |||||
461 | ||||||
462 | if (!dict) | |||||
463 | goto out; | |||||
464 | ||||||
465 | if (wordcount < 3) | |||||
466 | goto out; | |||||
467 | ||||||
468 | if (wordcount > 5) | |||||
469 | goto out; | |||||
470 | ||||||
471 | volname = (char *)words[2]; | |||||
472 | ||||||
473 | if (!volname) { | |||||
474 | ret = -1; | |||||
475 | goto out; | |||||
476 | } | |||||
477 | ||||||
478 | ret = dict_set_str (dict, "volname", volname); | |||||
479 | if (ret) | |||||
480 | goto out; | |||||
481 | ||||||
482 | if (wordcount == 3) { | |||||
483 | ret = dict_set_str (dict, "key", "all"); | |||||
484 | if (ret) | |||||
485 | goto out; | |||||
486 | } | |||||
487 | ||||||
488 | if (wordcount >= 4) { | |||||
489 | if (!strcmp ("force", (char*)words[3])) { | |||||
490 | ret = dict_set_int32 (dict, "force", 1); | |||||
491 | if (ret) | |||||
492 | goto out; | |||||
493 | ret = dict_set_str (dict, "key", "all"); | |||||
494 | if (ret) | |||||
495 | goto out; | |||||
496 | } else { | |||||
497 | ret = dict_set_str (dict, "key", (char *)words[3]); | |||||
498 | if (ret) | |||||
499 | goto out; | |||||
500 | } | |||||
501 | } | |||||
502 | ||||||
503 | if (wordcount == 5) { | |||||
504 | if (strcmp ("force", (char*)words[4])) { | |||||
505 | ret = -1; | |||||
506 | goto out; | |||||
507 | } else { | |||||
508 | ret = dict_set_int32 (dict, "force", 1); | |||||
509 | if (ret) | |||||
510 | goto out; | |||||
511 | } | |||||
512 | } | |||||
513 | ||||||
514 | *options = dict; | |||||
515 | ||||||
516 | out: | |||||
517 | if (ret && dict) { | |||||
518 | dict_destroy (dict); | |||||
519 | } | |||||
520 | ||||||
521 | return ret; | |||||
522 | } | |||||
523 | ||||||
524 | int32_t | |||||
525 | cli_cmd_quota_parse (const char **words, int wordcount, dict_t **options) | |||||
526 | { | |||||
527 | dict_t *dict = NULL((void*)0); | |||||
528 | char *volname = NULL((void*)0); | |||||
529 | int ret = -1; | |||||
530 | int i = 0; | |||||
531 | char key[20] = {0, }; | |||||
532 | uint64_t value = 0; | |||||
533 | gf_quota_type type = GF_QUOTA_OPTION_TYPE_NONE; | |||||
534 | char *opwords[] = { "enable", "disable", "limit-usage", | |||||
535 | "remove", "list", "version", NULL((void*)0) }; | |||||
536 | char *w = NULL((void*)0); | |||||
537 | ||||||
538 | GF_ASSERT (words)do { if (!(words)) { do { do { if (0) printf ("Assertion failed: " "words"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 538, GF_LOG_ERROR, "Assertion failed: " "words" ); } while (0); } } while (0); | |||||
539 | GF_ASSERT (options)do { if (!(options)) { do { do { if (0) printf ("Assertion failed: " "options"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 539, GF_LOG_ERROR, "Assertion failed: " "options" ); } while (0); } } while (0); | |||||
| ||||||
540 | ||||||
541 | dict = dict_new (); | |||||
542 | if (!dict) | |||||
543 | goto out; | |||||
544 | ||||||
545 | if (wordcount < 4) | |||||
546 | goto out; | |||||
547 | ||||||
548 | volname = (char *)words[2]; | |||||
549 | if (!volname) { | |||||
550 | ret = -1; | |||||
551 | goto out; | |||||
552 | } | |||||
553 | ||||||
554 | /* Validate the volume name here itself */ | |||||
555 | { | |||||
556 | if (volname[0] == '-') | |||||
557 | goto out; | |||||
558 | ||||||
559 | if (!strcmp (volname, "all")) { | |||||
560 | cli_err ("\"all\" cannot be the name of a volume.")do { do { if (0) printf ("\"all\" cannot be the name of a volume." ); } while (0); _cli_err("\"all\" cannot be the name of a volume." ); } while (0); | |||||
561 | goto out; | |||||
562 | } | |||||
563 | ||||||
564 | if (strchr (volname, '/')) | |||||
565 | goto out; | |||||
566 | ||||||
567 | if (strlen (volname) > 512) | |||||
568 | goto out; | |||||
569 | ||||||
570 | for (i = 0; i < strlen (volname); i++) | |||||
571 | if (!isalnum (volname[i])((*__ctype_b_loc ())[(int) ((volname[i]))] & (unsigned short int) _ISalnum) && (volname[i] != '_') && (volname[i] != '-')) | |||||
572 | goto out; | |||||
573 | } | |||||
574 | ||||||
575 | ret = dict_set_str (dict, "volname", volname); | |||||
576 | if (ret < 0) | |||||
577 | goto out; | |||||
578 | ||||||
579 | w = str_getunamb (words[3], opwords); | |||||
580 | if (!w) { | |||||
581 | ret = - 1; | |||||
582 | goto out; | |||||
583 | } | |||||
584 | ||||||
585 | if (strcmp (w, "enable") == 0) { | |||||
586 | if (wordcount == 4) { | |||||
587 | type = GF_QUOTA_OPTION_TYPE_ENABLE; | |||||
588 | ret = 0; | |||||
589 | goto set_type; | |||||
590 | } else { | |||||
591 | ret = -1; | |||||
592 | goto out; | |||||
593 | } | |||||
594 | } | |||||
595 | ||||||
596 | if (strcmp (w, "disable") == 0) { | |||||
597 | if (wordcount == 4) { | |||||
598 | type = GF_QUOTA_OPTION_TYPE_DISABLE; | |||||
599 | ret = 0; | |||||
600 | goto set_type; | |||||
601 | } else { | |||||
602 | ret = -1; | |||||
603 | goto out; | |||||
604 | } | |||||
605 | } | |||||
606 | ||||||
607 | if (strcmp (w, "limit-usage") == 0) { | |||||
608 | if (wordcount != 6) { | |||||
609 | ret = -1; | |||||
610 | goto out; | |||||
611 | } | |||||
612 | ||||||
613 | type = GF_QUOTA_OPTION_TYPE_LIMIT_USAGE; | |||||
614 | ||||||
615 | if (words[4][0] != '/') { | |||||
616 | cli_err ("Please enter absolute path")do { do { if (0) printf ("Please enter absolute path"); } while (0); _cli_err("Please enter absolute path"); } while (0); | |||||
617 | ||||||
618 | return -2; | |||||
619 | } | |||||
620 | ret = dict_set_str (dict, "path", (char *) words[4]); | |||||
621 | if (ret) | |||||
622 | goto out; | |||||
623 | ||||||
624 | if (!words[5]) { | |||||
625 | cli_err ("Please enter the limit value to be set")do { do { if (0) printf ("Please enter the limit value to be set" ); } while (0); _cli_err("Please enter the limit value to be set" ); } while (0); | |||||
626 | ||||||
627 | return -2; | |||||
628 | } | |||||
629 | ||||||
630 | ret = gf_string2bytesize (words[5], &value); | |||||
631 | if (ret != 0) { | |||||
632 | cli_err ("Please enter a correct value")do { do { if (0) printf ("Please enter a correct value"); } while (0); _cli_err("Please enter a correct value"); } while (0); | |||||
633 | return -1; | |||||
634 | } | |||||
635 | ||||||
636 | ret = dict_set_str (dict, "limit", (char *) words[5]); | |||||
637 | if (ret < 0) | |||||
638 | goto out; | |||||
639 | ||||||
640 | goto set_type; | |||||
641 | } | |||||
642 | if (strcmp (w, "remove") == 0) { | |||||
643 | if (wordcount != 5) { | |||||
644 | ret = -1; | |||||
645 | goto out; | |||||
646 | } | |||||
647 | ||||||
648 | type = GF_QUOTA_OPTION_TYPE_REMOVE; | |||||
649 | ||||||
650 | if (words[4][0] != '/') { | |||||
651 | cli_err ("Please enter absolute path")do { do { if (0) printf ("Please enter absolute path"); } while (0); _cli_err("Please enter absolute path"); } while (0); | |||||
652 | ||||||
653 | return -2; | |||||
654 | } | |||||
655 | ||||||
656 | ret = dict_set_str (dict, "path", (char *) words[4]); | |||||
657 | if (ret < 0) | |||||
658 | goto out; | |||||
659 | goto set_type; | |||||
660 | } | |||||
661 | ||||||
662 | if (strcmp (w, "list") == 0) { | |||||
663 | if (wordcount < 4) { | |||||
664 | ret = -1; | |||||
665 | goto out; | |||||
666 | } | |||||
667 | ||||||
668 | type = GF_QUOTA_OPTION_TYPE_LIST; | |||||
669 | ||||||
670 | i = 4; | |||||
671 | while (i < wordcount) { | |||||
672 | snprintf (key, 20, "path%d", i-4); | |||||
673 | ||||||
674 | ret = dict_set_str (dict, key, (char *) words [i++]); | |||||
675 | if (ret < 0) | |||||
676 | goto out; | |||||
677 | } | |||||
678 | ||||||
679 | ret = dict_set_int32 (dict, "count", i - 4); | |||||
680 | if (ret < 0) | |||||
681 | goto out; | |||||
682 | ||||||
683 | goto set_type; | |||||
684 | } | |||||
685 | ||||||
686 | if (strcmp (w, "version") == 0) { | |||||
687 | type = GF_QUOTA_OPTION_TYPE_VERSION; | |||||
688 | } else { | |||||
689 | GF_ASSERT (!"opword mismatch")do { if (!(!"opword mismatch")) { do { do { if (0) printf ("Assertion failed: " "!\"opword mismatch\""); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c", __FUNCTION__, 689, GF_LOG_ERROR, "Assertion failed: " "!\"opword mismatch\""); } while (0); } } while (0); | |||||
690 | } | |||||
691 | ||||||
692 | set_type: | |||||
693 | ret = dict_set_int32 (dict, "type", type); | |||||
694 | if (ret < 0) | |||||
695 | goto out; | |||||
696 | ||||||
697 | *options = dict; | |||||
| ||||||
698 | out: | |||||
699 | if (ret < 0) { | |||||
700 | if (dict) | |||||
701 | dict_destroy (dict); | |||||
702 | } | |||||
703 | ||||||
704 | return ret; | |||||
705 | } | |||||
706 | ||||||
707 | static inline gf_boolean_t | |||||
708 | cli_is_key_spl (char *key) | |||||
709 | { | |||||
710 | return (strcmp (key, "group") == 0); | |||||
711 | } | |||||
712 | ||||||
713 | #define GLUSTERD_DEFAULT_WORKDIR "/var/lib/glusterd" | |||||
714 | static int | |||||
715 | cli_add_key_group (dict_t *dict, char *key, char *value) | |||||
716 | { | |||||
717 | int ret = -1; | |||||
718 | int opt_count = 0; | |||||
719 | char iter_key[1024] = {0,}; | |||||
720 | char iter_val[1024] = {0,}; | |||||
721 | char *saveptr = NULL((void*)0); | |||||
722 | char *tok_key = NULL((void*)0); | |||||
723 | char *tok_val = NULL((void*)0); | |||||
724 | char *dkey = NULL((void*)0); | |||||
725 | char *dval = NULL((void*)0); | |||||
726 | char *tagpath = NULL((void*)0); | |||||
727 | char *buf = NULL((void*)0); | |||||
728 | char line[PATH_MAX4096 + 256] = {0,}; | |||||
729 | FILE *fp = NULL((void*)0); | |||||
730 | ||||||
731 | ret = gf_asprintf (&tagpath, "%s/groups/%s", | |||||
732 | GLUSTERD_DEFAULT_WORKDIR, value); | |||||
733 | if (ret == -1) { | |||||
734 | tagpath = NULL((void*)0); | |||||
735 | goto out; | |||||
736 | } | |||||
737 | ||||||
738 | fp = fopen (tagpath, "r"); | |||||
739 | if (!fp) { | |||||
740 | ret = -1; | |||||
741 | goto out; | |||||
742 | } | |||||
743 | ||||||
744 | opt_count = 0; | |||||
745 | buf = line; | |||||
746 | while (fscanf (fp, "%s", buf) != EOF(-1)) { | |||||
747 | ||||||
748 | opt_count++; | |||||
749 | tok_key = strtok_r (line, "=", &saveptr); | |||||
750 | tok_val = strtok_r (NULL((void*)0), "=", &saveptr); | |||||
751 | if (!tok_key || !tok_val) { | |||||
752 | ret = -1; | |||||
753 | goto out; | |||||
754 | } | |||||
755 | ||||||
756 | snprintf (iter_key, sizeof (iter_key), "key%d", opt_count); | |||||
757 | dkey = gf_strdup (tok_key); | |||||
758 | ret = dict_set_dynstr (dict, iter_key, dkey); | |||||
759 | if (ret) | |||||
760 | goto out; | |||||
761 | dkey = NULL((void*)0); | |||||
762 | ||||||
763 | snprintf (iter_val, sizeof (iter_val), "value%d", opt_count); | |||||
764 | dval = gf_strdup (tok_val); | |||||
765 | ret = dict_set_dynstr (dict, iter_val, dval); | |||||
766 | if (ret) | |||||
767 | goto out; | |||||
768 | dval = NULL((void*)0); | |||||
769 | ||||||
770 | } | |||||
771 | ||||||
772 | if (!opt_count) { | |||||
773 | ret = -1; | |||||
774 | goto out; | |||||
775 | } | |||||
776 | ret = dict_set_int32 (dict, "count", opt_count); | |||||
777 | out: | |||||
778 | ||||||
779 | GF_FREE (tagpath)__gf_free (tagpath); | |||||
780 | ||||||
781 | if (ret) { | |||||
782 | GF_FREE (dkey)__gf_free (dkey); | |||||
783 | GF_FREE (dval)__gf_free (dval); | |||||
784 | } | |||||
785 | ||||||
786 | if (fp) | |||||
787 | fclose (fp); | |||||
788 | ||||||
789 | return ret; | |||||
790 | } | |||||
791 | #undef GLUSTERD_DEFAULT_WORKDIR | |||||
792 | ||||||
793 | int32_t | |||||
794 | cli_cmd_volume_set_parse (const char **words, int wordcount, dict_t **options) | |||||
795 | { | |||||
796 | dict_t *dict = NULL((void*)0); | |||||
797 | char *volname = NULL((void*)0); | |||||
798 | int ret = -1; | |||||
799 | int count = 0; | |||||
800 | char *key = NULL((void*)0); | |||||
801 | char *value = NULL((void*)0); | |||||
802 | int i = 0; | |||||
803 | char str[50] = {0,}; | |||||
804 | ||||||
805 | GF_ASSERT (words)do { if (!(words)) { do { do { if (0) printf ("Assertion failed: " "words"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 805, GF_LOG_ERROR, "Assertion failed: " "words" ); } while (0); } } while (0); | |||||
806 | GF_ASSERT (options)do { if (!(options)) { do { do { if (0) printf ("Assertion failed: " "options"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 806, GF_LOG_ERROR, "Assertion failed: " "options" ); } while (0); } } while (0); | |||||
807 | ||||||
808 | dict = dict_new (); | |||||
809 | ||||||
810 | if (!dict) | |||||
811 | goto out; | |||||
812 | ||||||
813 | if (wordcount < 3) | |||||
814 | goto out; | |||||
815 | ||||||
816 | volname = (char *)words[2]; | |||||
817 | ||||||
818 | GF_ASSERT (volname)do { if (!(volname)) { do { do { if (0) printf ("Assertion failed: " "volname"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 818, GF_LOG_ERROR, "Assertion failed: " "volname" ); } while (0); } } while (0); | |||||
819 | ||||||
820 | ret = dict_set_str (dict, "volname", volname); | |||||
821 | ||||||
822 | if (ret) | |||||
823 | goto out; | |||||
824 | ||||||
825 | if ((!strcmp (volname, "help") || !strcmp (volname, "help-xml")) | |||||
826 | && wordcount == 3 ) { | |||||
827 | ret = dict_set_str (dict, volname, volname); | |||||
828 | if (ret) | |||||
829 | goto out; | |||||
830 | ||||||
831 | } else if (wordcount < 5) { | |||||
832 | ret = -1; | |||||
833 | goto out; | |||||
834 | ||||||
835 | } else if (wordcount == 5 && cli_is_key_spl ((char *)words[3])) { | |||||
836 | key = (char *) words[3]; | |||||
837 | value = (char *) words[4]; | |||||
838 | if ( !key || !value) { | |||||
839 | ret = -1; | |||||
840 | goto out; | |||||
841 | } | |||||
842 | ||||||
843 | ret = gf_strip_whitespace (value, strlen (value)); | |||||
844 | if (ret == -1) | |||||
845 | goto out; | |||||
846 | ||||||
847 | if (strlen (value) == 0) { | |||||
848 | ret = -1; | |||||
849 | goto out; | |||||
850 | } | |||||
851 | ||||||
852 | ret = cli_add_key_group (dict, key, value); | |||||
853 | if (ret == 0) | |||||
854 | *options = dict; | |||||
855 | goto out; | |||||
856 | } | |||||
857 | ||||||
858 | for (i = 3; i < wordcount; i+=2) { | |||||
859 | ||||||
860 | key = (char *) words[i]; | |||||
861 | value = (char *) words[i+1]; | |||||
862 | ||||||
863 | if ( !key || !value) { | |||||
864 | ret = -1; | |||||
865 | goto out; | |||||
866 | } | |||||
867 | ||||||
868 | count++; | |||||
869 | ||||||
870 | ret = gf_strip_whitespace (value, strlen (value)); | |||||
871 | if (ret == -1) | |||||
872 | goto out; | |||||
873 | ||||||
874 | if (strlen (value) == 0) { | |||||
875 | ret = -1; | |||||
876 | goto out; | |||||
877 | } | |||||
878 | ||||||
879 | if (cli_is_key_spl (key)) { | |||||
880 | ret = -1; | |||||
881 | goto out; | |||||
882 | } | |||||
883 | ||||||
884 | sprintf (str, "key%d", count); | |||||
885 | ret = dict_set_str (dict, str, key); | |||||
886 | if (ret) | |||||
887 | goto out; | |||||
888 | ||||||
889 | sprintf (str, "value%d", count); | |||||
890 | ret = dict_set_str (dict, str, value); | |||||
891 | ||||||
892 | if (ret) | |||||
893 | goto out; | |||||
894 | } | |||||
895 | ||||||
896 | ret = dict_set_int32 (dict, "count", wordcount-3); | |||||
897 | ||||||
898 | if (ret) | |||||
899 | goto out; | |||||
900 | ||||||
901 | *options = dict; | |||||
902 | ||||||
903 | out: | |||||
904 | if (ret) | |||||
905 | dict_destroy (dict); | |||||
906 | ||||||
907 | return ret; | |||||
908 | } | |||||
909 | ||||||
910 | int32_t | |||||
911 | cli_cmd_volume_add_brick_parse (const char **words, int wordcount, | |||||
912 | dict_t **options) | |||||
913 | { | |||||
914 | dict_t *dict = NULL((void*)0); | |||||
915 | char *volname = NULL((void*)0); | |||||
916 | int ret = -1; | |||||
917 | int brick_count = 0, brick_index = 0; | |||||
918 | char *bricks = NULL((void*)0); | |||||
919 | char *opwords_cl[] = { "replica", "stripe", NULL((void*)0) }; | |||||
920 | gf1_cluster_type type = GF_CLUSTER_TYPE_NONE; | |||||
921 | int count = 1; | |||||
922 | char *w = NULL((void*)0); | |||||
923 | int index; | |||||
924 | gf_boolean_t is_force = _gf_false; | |||||
925 | int wc = wordcount; | |||||
926 | ||||||
927 | GF_ASSERT (words)do { if (!(words)) { do { do { if (0) printf ("Assertion failed: " "words"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 927, GF_LOG_ERROR, "Assertion failed: " "words" ); } while (0); } } while (0); | |||||
928 | GF_ASSERT (options)do { if (!(options)) { do { do { if (0) printf ("Assertion failed: " "options"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 928, GF_LOG_ERROR, "Assertion failed: " "options" ); } while (0); } } while (0); | |||||
929 | ||||||
930 | dict = dict_new (); | |||||
931 | ||||||
932 | if (!dict) | |||||
933 | goto out; | |||||
934 | ||||||
935 | if (wordcount < 3) | |||||
936 | goto out; | |||||
937 | ||||||
938 | volname = (char *)words[2]; | |||||
939 | ||||||
940 | GF_ASSERT (volname)do { if (!(volname)) { do { do { if (0) printf ("Assertion failed: " "volname"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 940, GF_LOG_ERROR, "Assertion failed: " "volname" ); } while (0); } } while (0); | |||||
941 | ||||||
942 | ret = dict_set_str (dict, "volname", volname); | |||||
943 | ||||||
944 | if (ret) | |||||
945 | goto out; | |||||
946 | ||||||
947 | if (wordcount < 4) { | |||||
948 | ret = -1; | |||||
949 | goto out; | |||||
950 | } | |||||
951 | if (wordcount < 6) { | |||||
952 | /* seems no options are given, go directly to the parse_brick */ | |||||
953 | brick_index = 3; | |||||
954 | type = GF_CLUSTER_TYPE_NONE; | |||||
955 | goto parse_bricks; | |||||
956 | } | |||||
957 | ||||||
958 | w = str_getunamb (words[3], opwords_cl); | |||||
959 | if (!w) { | |||||
960 | type = GF_CLUSTER_TYPE_NONE; | |||||
961 | index = 3; | |||||
962 | } else if ((strcmp (w, "replica")) == 0) { | |||||
963 | type = GF_CLUSTER_TYPE_REPLICATE; | |||||
964 | if (wordcount < 5) { | |||||
965 | ret = -1; | |||||
966 | goto out; | |||||
967 | } | |||||
968 | count = strtol (words[4], NULL((void*)0), 0); | |||||
969 | if (!count || (count < 2)) { | |||||
970 | cli_err ("replica count should be greater than 1")do { do { if (0) printf ("replica count should be greater than 1" ); } while (0); _cli_err("replica count should be greater than 1" ); } while (0); | |||||
971 | ret = -1; | |||||
972 | goto out; | |||||
973 | } | |||||
974 | ret = dict_set_int32 (dict, "replica-count", count); | |||||
975 | if (ret) | |||||
976 | goto out; | |||||
977 | index = 5; | |||||
978 | } else if ((strcmp (w, "stripe")) == 0) { | |||||
979 | type = GF_CLUSTER_TYPE_STRIPE; | |||||
980 | if (wordcount < 5) { | |||||
981 | ret = -1; | |||||
982 | goto out; | |||||
983 | } | |||||
984 | count = strtol (words[4], NULL((void*)0), 0); | |||||
985 | if (!count || (count < 2)) { | |||||
986 | cli_err ("stripe count should be greater than 1")do { do { if (0) printf ("stripe count should be greater than 1" ); } while (0); _cli_err("stripe count should be greater than 1" ); } while (0); | |||||
987 | ret = -1; | |||||
988 | goto out; | |||||
989 | } | |||||
990 | ret = dict_set_int32 (dict, "stripe-count", count); | |||||
991 | if (ret) | |||||
992 | goto out; | |||||
993 | index = 5; | |||||
994 | } else { | |||||
995 | GF_ASSERT (!"opword mismatch")do { if (!(!"opword mismatch")) { do { do { if (0) printf ("Assertion failed: " "!\"opword mismatch\""); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c", __FUNCTION__, 995, GF_LOG_ERROR, "Assertion failed: " "!\"opword mismatch\""); } while (0); } } while (0); | |||||
996 | ret = -1; | |||||
997 | goto out; | |||||
998 | } | |||||
999 | ||||||
1000 | brick_index = index; | |||||
1001 | ||||||
1002 | parse_bricks: | |||||
1003 | ||||||
1004 | if (strcmp (words[wordcount - 1], "force") == 0) { | |||||
1005 | is_force = _gf_true; | |||||
1006 | wc = wordcount - 1; | |||||
1007 | } | |||||
1008 | ||||||
1009 | ret = cli_cmd_bricks_parse (words, wc, brick_index, &bricks, | |||||
1010 | &brick_count); | |||||
1011 | if (ret) | |||||
1012 | goto out; | |||||
1013 | ||||||
1014 | ret = dict_set_dynstr (dict, "bricks", bricks); | |||||
1015 | if (ret) | |||||
1016 | goto out; | |||||
1017 | ||||||
1018 | ret = dict_set_int32 (dict, "count", brick_count); | |||||
1019 | ||||||
1020 | if (ret) | |||||
1021 | goto out; | |||||
1022 | ||||||
1023 | ret = dict_set_int32 (dict, "force", is_force); | |||||
1024 | if (ret) | |||||
1025 | goto out; | |||||
1026 | ||||||
1027 | *options = dict; | |||||
1028 | ||||||
1029 | out: | |||||
1030 | if (ret) { | |||||
1031 | gf_log ("cli", GF_LOG_ERROR, "Unable to parse add-brick CLI")do { do { if (0) printf ("Unable to parse add-brick CLI"); } while (0); _gf_log ("cli", "cli-cmd-parser.c", __FUNCTION__, 1031, GF_LOG_ERROR, "Unable to parse add-brick CLI"); } while (0); | |||||
1032 | if (dict) | |||||
1033 | dict_destroy (dict); | |||||
1034 | } | |||||
1035 | ||||||
1036 | return ret; | |||||
1037 | } | |||||
1038 | ||||||
1039 | ||||||
1040 | int32_t | |||||
1041 | cli_cmd_volume_remove_brick_parse (const char **words, int wordcount, | |||||
1042 | dict_t **options, int *question) | |||||
1043 | { | |||||
1044 | dict_t *dict = NULL((void*)0); | |||||
1045 | char *volname = NULL((void*)0); | |||||
1046 | char *delimiter = NULL((void*)0); | |||||
1047 | int ret = -1; | |||||
1048 | char key[50]; | |||||
1049 | int brick_count = 0, brick_index = 0; | |||||
1050 | int32_t tmp_index = 0; | |||||
1051 | int32_t j = 0; | |||||
1052 | char *tmp_brick = NULL((void*)0); | |||||
1053 | char *tmp_brick1 = NULL((void*)0); | |||||
1054 | char *type_opword[] = { "replica", NULL((void*)0) }; | |||||
1055 | char *opwords[] = { "start", "commit", "stop", "status", | |||||
1056 | "force", NULL((void*)0) }; | |||||
1057 | char *w = NULL((void*)0); | |||||
1058 | int32_t command = GF_OP_CMD_NONE; | |||||
1059 | long count = 0; | |||||
1060 | ||||||
1061 | GF_ASSERT (words)do { if (!(words)) { do { do { if (0) printf ("Assertion failed: " "words"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 1061, GF_LOG_ERROR, "Assertion failed: " "words" ); } while (0); } } while (0); | |||||
1062 | GF_ASSERT (options)do { if (!(options)) { do { do { if (0) printf ("Assertion failed: " "options"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 1062, GF_LOG_ERROR, "Assertion failed: " "options" ); } while (0); } } while (0); | |||||
1063 | ||||||
1064 | if (wordcount < 4) | |||||
1065 | goto out; | |||||
1066 | ||||||
1067 | dict = dict_new (); | |||||
1068 | if (!dict) | |||||
1069 | goto out; | |||||
1070 | ||||||
1071 | volname = (char *)words[2]; | |||||
1072 | ||||||
1073 | GF_ASSERT (volname)do { if (!(volname)) { do { do { if (0) printf ("Assertion failed: " "volname"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 1073, GF_LOG_ERROR, "Assertion failed: " "volname" ); } while (0); } } while (0); | |||||
1074 | ||||||
1075 | ret = dict_set_str (dict, "volname", volname); | |||||
1076 | if (ret) | |||||
1077 | goto out; | |||||
1078 | ||||||
1079 | brick_index = 3; | |||||
1080 | w = str_getunamb (words[3], type_opword); | |||||
1081 | if (w && !strcmp ("replica", w)) { | |||||
1082 | if (wordcount < 5) { | |||||
1083 | ret = -1; | |||||
1084 | goto out; | |||||
1085 | } | |||||
1086 | count = strtol (words[4], NULL((void*)0), 0); | |||||
1087 | if (count < 1) { | |||||
1088 | cli_err ("replica count should be greater than 0 in "do { do { if (0) printf ("replica count should be greater than 0 in " "case of remove-brick"); } while (0); _cli_err("replica count should be greater than 0 in " "case of remove-brick"); } while (0) | |||||
1089 | "case of remove-brick")do { do { if (0) printf ("replica count should be greater than 0 in " "case of remove-brick"); } while (0); _cli_err("replica count should be greater than 0 in " "case of remove-brick"); } while (0); | |||||
1090 | ret = -1; | |||||
1091 | goto out; | |||||
1092 | } | |||||
1093 | ||||||
1094 | ret = dict_set_int32 (dict, "replica-count", count); | |||||
1095 | if (ret) | |||||
1096 | goto out; | |||||
1097 | brick_index = 5; | |||||
1098 | } else if (w) { | |||||
1099 | GF_ASSERT (!"opword mismatch")do { if (!(!"opword mismatch")) { do { do { if (0) printf ("Assertion failed: " "!\"opword mismatch\""); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c", __FUNCTION__, 1099, GF_LOG_ERROR, "Assertion failed: " "!\"opword mismatch\""); } while (0); } } while (0); | |||||
1100 | } | |||||
1101 | ||||||
1102 | w = str_getunamb (words[wordcount - 1], opwords); | |||||
1103 | if (!w) { | |||||
1104 | /* Should be default 'force' */ | |||||
1105 | command = GF_OP_CMD_COMMIT_FORCE; | |||||
1106 | if (question) | |||||
1107 | *question = 1; | |||||
1108 | } else { | |||||
1109 | /* handled this option */ | |||||
1110 | wordcount--; | |||||
1111 | if (!strcmp ("start", w)) { | |||||
1112 | command = GF_OP_CMD_START; | |||||
1113 | } else if (!strcmp ("commit", w)) { | |||||
1114 | command = GF_OP_CMD_COMMIT; | |||||
1115 | if (question) | |||||
1116 | *question = 1; | |||||
1117 | } else if (!strcmp ("stop", w)) { | |||||
1118 | command = GF_OP_CMD_STOP; | |||||
1119 | } else if (!strcmp ("status", w)) { | |||||
1120 | command = GF_OP_CMD_STATUS; | |||||
1121 | } else if (!strcmp ("force", w)) { | |||||
1122 | command = GF_OP_CMD_COMMIT_FORCE; | |||||
1123 | if (question) | |||||
1124 | *question = 1; | |||||
1125 | } else { | |||||
1126 | GF_ASSERT (!"opword mismatch")do { if (!(!"opword mismatch")) { do { do { if (0) printf ("Assertion failed: " "!\"opword mismatch\""); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c", __FUNCTION__, 1126, GF_LOG_ERROR, "Assertion failed: " "!\"opword mismatch\""); } while (0); } } while (0); | |||||
1127 | ret = -1; | |||||
1128 | goto out; | |||||
1129 | } | |||||
1130 | } | |||||
1131 | ||||||
1132 | if (wordcount < 4) { | |||||
1133 | ret = -1; | |||||
1134 | goto out; | |||||
1135 | } | |||||
1136 | ||||||
1137 | ret = dict_set_int32 (dict, "command", command); | |||||
1138 | if (ret) | |||||
1139 | gf_log ("cli", GF_LOG_INFO, "failed to set 'command' %d",do { do { if (0) printf ("failed to set 'command' %d", command ); } while (0); _gf_log ("cli", "cli-cmd-parser.c", __FUNCTION__ , 1140, GF_LOG_INFO, "failed to set 'command' %d", command); } while (0) | |||||
1140 | command)do { do { if (0) printf ("failed to set 'command' %d", command ); } while (0); _gf_log ("cli", "cli-cmd-parser.c", __FUNCTION__ , 1140, GF_LOG_INFO, "failed to set 'command' %d", command); } while (0); | |||||
1141 | ||||||
1142 | ||||||
1143 | tmp_index = brick_index; | |||||
1144 | tmp_brick = GF_MALLOC(2048 * sizeof(*tmp_brick), gf_common_mt_char)__gf_malloc (2048 * sizeof(*tmp_brick), gf_common_mt_char); | |||||
1145 | ||||||
1146 | if (!tmp_brick) { | |||||
1147 | gf_log ("",GF_LOG_ERROR,"cli_cmd_volume_remove_brick_parse: "do { do { if (0) printf ("cli_cmd_volume_remove_brick_parse: " "Unable to get memory"); } while (0); _gf_log ("", "cli-cmd-parser.c" , __FUNCTION__, 1148, GF_LOG_ERROR,"cli_cmd_volume_remove_brick_parse: " "Unable to get memory"); } while (0) | |||||
1148 | "Unable to get memory")do { do { if (0) printf ("cli_cmd_volume_remove_brick_parse: " "Unable to get memory"); } while (0); _gf_log ("", "cli-cmd-parser.c" , __FUNCTION__, 1148, GF_LOG_ERROR,"cli_cmd_volume_remove_brick_parse: " "Unable to get memory"); } while (0); | |||||
1149 | ret = -1; | |||||
1150 | goto out; | |||||
1151 | } | |||||
1152 | ||||||
1153 | tmp_brick1 = GF_MALLOC(2048 * sizeof(*tmp_brick1), gf_common_mt_char)__gf_malloc (2048 * sizeof(*tmp_brick1), gf_common_mt_char); | |||||
1154 | ||||||
1155 | if (!tmp_brick1) { | |||||
1156 | gf_log ("",GF_LOG_ERROR,"cli_cmd_volume_remove_brick_parse: "do { do { if (0) printf ("cli_cmd_volume_remove_brick_parse: " "Unable to get memory"); } while (0); _gf_log ("", "cli-cmd-parser.c" , __FUNCTION__, 1157, GF_LOG_ERROR,"cli_cmd_volume_remove_brick_parse: " "Unable to get memory"); } while (0) | |||||
1157 | "Unable to get memory")do { do { if (0) printf ("cli_cmd_volume_remove_brick_parse: " "Unable to get memory"); } while (0); _gf_log ("", "cli-cmd-parser.c" , __FUNCTION__, 1157, GF_LOG_ERROR,"cli_cmd_volume_remove_brick_parse: " "Unable to get memory"); } while (0); | |||||
1158 | ret = -1; | |||||
1159 | goto out; | |||||
1160 | } | |||||
1161 | ||||||
1162 | while (brick_index < wordcount) { | |||||
1163 | if (validate_brick_name ((char *)words[brick_index])) { | |||||
1164 | cli_err ("wrong brick type: %s, use <HOSTNAME>:"do { do { if (0) printf ("wrong brick type: %s, use <HOSTNAME>:" "<export-dir-abs-path>", words[brick_index]); } while ( 0); _cli_err("wrong brick type: %s, use <HOSTNAME>:" "<export-dir-abs-path>" , words[brick_index]); } while (0) | |||||
1165 | "<export-dir-abs-path>", words[brick_index])do { do { if (0) printf ("wrong brick type: %s, use <HOSTNAME>:" "<export-dir-abs-path>", words[brick_index]); } while ( 0); _cli_err("wrong brick type: %s, use <HOSTNAME>:" "<export-dir-abs-path>" , words[brick_index]); } while (0); | |||||
1166 | ret = -1; | |||||
1167 | goto out; | |||||
1168 | } else { | |||||
1169 | delimiter = strrchr(words[brick_index], ':'); | |||||
1170 | ret = gf_canonicalize_path (delimiter + 1); | |||||
1171 | if (ret) | |||||
1172 | goto out; | |||||
1173 | } | |||||
1174 | ||||||
1175 | j = tmp_index; | |||||
1176 | strcpy(tmp_brick, words[brick_index]); | |||||
1177 | while ( j < brick_index) { | |||||
1178 | strcpy(tmp_brick1, words[j]); | |||||
1179 | if (!(strcmp (tmp_brick, tmp_brick1))) { | |||||
1180 | gf_log("",GF_LOG_ERROR, "Duplicate bricks"do { do { if (0) printf ("Duplicate bricks" " found %s", words [brick_index]); } while (0); _gf_log ("", "cli-cmd-parser.c", __FUNCTION__, 1181, GF_LOG_ERROR, "Duplicate bricks" " found %s" , words[brick_index]); } while (0) | |||||
1181 | " found %s", words[brick_index])do { do { if (0) printf ("Duplicate bricks" " found %s", words [brick_index]); } while (0); _gf_log ("", "cli-cmd-parser.c", __FUNCTION__, 1181, GF_LOG_ERROR, "Duplicate bricks" " found %s" , words[brick_index]); } while (0); | |||||
1182 | cli_err("Duplicate bricks found %s",do { do { if (0) printf ("Duplicate bricks found %s", words[brick_index ]); } while (0); _cli_err("Duplicate bricks found %s", words[ brick_index]); } while (0) | |||||
1183 | words[brick_index])do { do { if (0) printf ("Duplicate bricks found %s", words[brick_index ]); } while (0); _cli_err("Duplicate bricks found %s", words[ brick_index]); } while (0); | |||||
1184 | ret = -1; | |||||
1185 | goto out; | |||||
1186 | } | |||||
1187 | j++; | |||||
1188 | } | |||||
1189 | snprintf (key, 50, "brick%d", ++brick_count); | |||||
1190 | ret = dict_set_str (dict, key, (char *)words[brick_index++]); | |||||
1191 | ||||||
1192 | if (ret) | |||||
1193 | goto out; | |||||
1194 | } | |||||
1195 | ||||||
1196 | ret = dict_set_int32 (dict, "count", brick_count); | |||||
1197 | if (ret) | |||||
1198 | goto out; | |||||
1199 | ||||||
1200 | *options = dict; | |||||
1201 | ||||||
1202 | out: | |||||
1203 | if (ret) { | |||||
1204 | gf_log ("cli", GF_LOG_ERROR, "Unable to parse remove-brick CLI")do { do { if (0) printf ("Unable to parse remove-brick CLI"); } while (0); _gf_log ("cli", "cli-cmd-parser.c", __FUNCTION__ , 1204, GF_LOG_ERROR, "Unable to parse remove-brick CLI"); } while (0); | |||||
1205 | if (dict) | |||||
1206 | dict_destroy (dict); | |||||
1207 | } | |||||
1208 | ||||||
1209 | GF_FREE (tmp_brick)__gf_free (tmp_brick); | |||||
1210 | GF_FREE (tmp_brick1)__gf_free (tmp_brick1); | |||||
1211 | ||||||
1212 | return ret; | |||||
1213 | } | |||||
1214 | ||||||
1215 | ||||||
1216 | int32_t | |||||
1217 | cli_cmd_volume_replace_brick_parse (const char **words, int wordcount, | |||||
1218 | dict_t **options) | |||||
1219 | { | |||||
1220 | dict_t *dict = NULL((void*)0); | |||||
1221 | char *volname = NULL((void*)0); | |||||
1222 | int ret = -1; | |||||
1223 | int op_index = 0; | |||||
1224 | char *delimiter = NULL((void*)0); | |||||
1225 | gf1_cli_replace_op replace_op = GF_REPLACE_OP_NONE; | |||||
1226 | char *opwords[] = { "start", "commit", "pause", "abort", "status", | |||||
1227 | NULL((void*)0) }; | |||||
1228 | char *w = NULL((void*)0); | |||||
1229 | gf_boolean_t is_force = _gf_false; | |||||
1230 | ||||||
1231 | GF_ASSERT (words)do { if (!(words)) { do { do { if (0) printf ("Assertion failed: " "words"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 1231, GF_LOG_ERROR, "Assertion failed: " "words" ); } while (0); } } while (0); | |||||
1232 | GF_ASSERT (options)do { if (!(options)) { do { do { if (0) printf ("Assertion failed: " "options"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 1232, GF_LOG_ERROR, "Assertion failed: " "options" ); } while (0); } } while (0); | |||||
1233 | ||||||
1234 | dict = dict_new (); | |||||
1235 | ||||||
1236 | if (!dict) | |||||
1237 | goto out; | |||||
1238 | ||||||
1239 | if (wordcount < 3) | |||||
1240 | goto out; | |||||
1241 | ||||||
1242 | volname = (char *)words[2]; | |||||
1243 | ||||||
1244 | GF_ASSERT (volname)do { if (!(volname)) { do { do { if (0) printf ("Assertion failed: " "volname"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 1244, GF_LOG_ERROR, "Assertion failed: " "volname" ); } while (0); } } while (0); | |||||
1245 | ||||||
1246 | ret = dict_set_str (dict, "volname", volname); | |||||
1247 | ||||||
1248 | if (ret) | |||||
1249 | goto out; | |||||
1250 | ||||||
1251 | if (wordcount < 4) { | |||||
1252 | ret = -1; | |||||
1253 | goto out; | |||||
1254 | } | |||||
1255 | ||||||
1256 | if (validate_brick_name ((char *)words[3])) { | |||||
1257 | cli_err ("wrong brick type: %s, use "do { do { if (0) printf ("wrong brick type: %s, use " "<HOSTNAME>:<export-dir-abs-path>" , words[3]); } while (0); _cli_err("wrong brick type: %s, use " "<HOSTNAME>:<export-dir-abs-path>", words[3]); } while (0) | |||||
1258 | "<HOSTNAME>:<export-dir-abs-path>", words[3])do { do { if (0) printf ("wrong brick type: %s, use " "<HOSTNAME>:<export-dir-abs-path>" , words[3]); } while (0); _cli_err("wrong brick type: %s, use " "<HOSTNAME>:<export-dir-abs-path>", words[3]); } while (0); | |||||
1259 | ret = -1; | |||||
1260 | goto out; | |||||
1261 | } else { | |||||
1262 | delimiter = strrchr ((char *)words[3], ':'); | |||||
1263 | ret = gf_canonicalize_path (delimiter + 1); | |||||
1264 | if (ret) | |||||
1265 | goto out; | |||||
1266 | } | |||||
1267 | ret = dict_set_str (dict, "src-brick", (char *)words[3]); | |||||
1268 | ||||||
1269 | if (ret) | |||||
1270 | goto out; | |||||
1271 | ||||||
1272 | if (wordcount < 5) { | |||||
1273 | ret = -1; | |||||
1274 | goto out; | |||||
1275 | } | |||||
1276 | ||||||
1277 | if (validate_brick_name ((char *)words[4])) { | |||||
1278 | cli_err ("wrong brick type: %s, use "do { do { if (0) printf ("wrong brick type: %s, use " "<HOSTNAME>:<export-dir-abs-path>" , words[4]); } while (0); _cli_err("wrong brick type: %s, use " "<HOSTNAME>:<export-dir-abs-path>", words[4]); } while (0) | |||||
1279 | "<HOSTNAME>:<export-dir-abs-path>", words[4])do { do { if (0) printf ("wrong brick type: %s, use " "<HOSTNAME>:<export-dir-abs-path>" , words[4]); } while (0); _cli_err("wrong brick type: %s, use " "<HOSTNAME>:<export-dir-abs-path>", words[4]); } while (0); | |||||
1280 | ret = -1; | |||||
1281 | goto out; | |||||
1282 | } else { | |||||
1283 | delimiter = strrchr ((char *)words[4], ':'); | |||||
1284 | ret = gf_canonicalize_path (delimiter + 1); | |||||
1285 | if (ret) | |||||
1286 | goto out; | |||||
1287 | } | |||||
1288 | ||||||
1289 | ||||||
1290 | ret = dict_set_str (dict, "dst-brick", (char *)words[4]); | |||||
1291 | ||||||
1292 | if (ret) | |||||
1293 | goto out; | |||||
1294 | ||||||
1295 | op_index = 5; | |||||
1296 | if ((wordcount < (op_index + 1))) { | |||||
1297 | ret = -1; | |||||
1298 | goto out; | |||||
1299 | } | |||||
1300 | ||||||
1301 | w = str_getunamb (words[op_index], opwords); | |||||
1302 | ||||||
1303 | if (!w) { | |||||
1304 | } else if (!strcmp ("start", w)) { | |||||
1305 | replace_op = GF_REPLACE_OP_START; | |||||
1306 | } else if (!strcmp ("commit", w)) { | |||||
1307 | replace_op = GF_REPLACE_OP_COMMIT; | |||||
1308 | } else if (!strcmp ("pause", w)) { | |||||
1309 | replace_op = GF_REPLACE_OP_PAUSE; | |||||
1310 | } else if (!strcmp ("abort", w)) { | |||||
1311 | replace_op = GF_REPLACE_OP_ABORT; | |||||
1312 | } else if (!strcmp ("status", w)) { | |||||
1313 | replace_op = GF_REPLACE_OP_STATUS; | |||||
1314 | } else | |||||
1315 | GF_ASSERT (!"opword mismatch")do { if (!(!"opword mismatch")) { do { do { if (0) printf ("Assertion failed: " "!\"opword mismatch\""); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c", __FUNCTION__, 1315, GF_LOG_ERROR, "Assertion failed: " "!\"opword mismatch\""); } while (0); } } while (0); | |||||
1316 | ||||||
1317 | /* commit force option */ | |||||
1318 | ||||||
1319 | op_index = 6; | |||||
1320 | ||||||
1321 | if (wordcount > (op_index + 1)) { | |||||
1322 | ret = -1; | |||||
1323 | goto out; | |||||
1324 | } | |||||
1325 | ||||||
1326 | if (wordcount == (op_index + 1)) { | |||||
1327 | if ((replace_op != GF_REPLACE_OP_COMMIT) && | |||||
1328 | (replace_op != GF_REPLACE_OP_START)) { | |||||
1329 | ret = -1; | |||||
1330 | goto out; | |||||
1331 | } | |||||
1332 | if (!strcmp ("force", words[op_index])) { | |||||
1333 | if (replace_op == GF_REPLACE_OP_COMMIT) | |||||
1334 | replace_op = GF_REPLACE_OP_COMMIT_FORCE; | |||||
1335 | ||||||
1336 | else if (replace_op == GF_REPLACE_OP_START) | |||||
1337 | is_force = _gf_true; | |||||
1338 | } | |||||
1339 | } | |||||
1340 | ||||||
1341 | if (replace_op == GF_REPLACE_OP_NONE) { | |||||
1342 | ret = -1; | |||||
1343 | goto out; | |||||
1344 | } | |||||
1345 | ||||||
1346 | ret = dict_set_int32 (dict, "operation", (int32_t) replace_op); | |||||
1347 | ||||||
1348 | if (ret) | |||||
1349 | goto out; | |||||
1350 | ||||||
1351 | ret = dict_set_int32 (dict, "force", is_force); | |||||
1352 | if (ret) | |||||
1353 | goto out; | |||||
1354 | ||||||
1355 | *options = dict; | |||||
1356 | ||||||
1357 | out: | |||||
1358 | if (ret) { | |||||
1359 | gf_log ("cli", GF_LOG_ERROR, "Unable to parse replace-brick CLI")do { do { if (0) printf ("Unable to parse replace-brick CLI") ; } while (0); _gf_log ("cli", "cli-cmd-parser.c", __FUNCTION__ , 1359, GF_LOG_ERROR, "Unable to parse replace-brick CLI"); } while (0); | |||||
1360 | if (dict) | |||||
1361 | dict_destroy (dict); | |||||
1362 | } | |||||
1363 | ||||||
1364 | return ret; | |||||
1365 | } | |||||
1366 | ||||||
1367 | int32_t | |||||
1368 | cli_cmd_log_filename_parse (const char **words, int wordcount, dict_t **options) | |||||
1369 | { | |||||
1370 | dict_t *dict = NULL((void*)0); | |||||
1371 | char *volname = NULL((void*)0); | |||||
1372 | char *str = NULL((void*)0); | |||||
1373 | int ret = -1; | |||||
1374 | char *delimiter = NULL((void*)0); | |||||
1375 | ||||||
1376 | GF_ASSERT (words)do { if (!(words)) { do { do { if (0) printf ("Assertion failed: " "words"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 1376, GF_LOG_ERROR, "Assertion failed: " "words" ); } while (0); } } while (0); | |||||
1377 | GF_ASSERT (options)do { if (!(options)) { do { do { if (0) printf ("Assertion failed: " "options"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 1377, GF_LOG_ERROR, "Assertion failed: " "options" ); } while (0); } } while (0); | |||||
1378 | ||||||
1379 | dict = dict_new (); | |||||
1380 | if (!dict) | |||||
1381 | goto out; | |||||
1382 | ||||||
1383 | volname = (char *)words[3]; | |||||
1384 | GF_ASSERT (volname)do { if (!(volname)) { do { do { if (0) printf ("Assertion failed: " "volname"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 1384, GF_LOG_ERROR, "Assertion failed: " "volname" ); } while (0); } } while (0); | |||||
1385 | ||||||
1386 | ret = dict_set_str (dict, "volname", volname); | |||||
1387 | if (ret) | |||||
1388 | goto out; | |||||
1389 | ||||||
1390 | str = (char *)words[4]; | |||||
1391 | if (strchr (str, ':')) { | |||||
1392 | delimiter = strchr (words[4], ':'); | |||||
1393 | if (!delimiter || delimiter == words[4] | |||||
1394 | || *(delimiter+1) != '/') { | |||||
1395 | cli_err ("wrong brick type: %s, use <HOSTNAME>:"do { do { if (0) printf ("wrong brick type: %s, use <HOSTNAME>:" "<export-dir-abs-path>", words[4]); } while (0); _cli_err ("wrong brick type: %s, use <HOSTNAME>:" "<export-dir-abs-path>" , words[4]); } while (0) | |||||
1396 | "<export-dir-abs-path>", words[4])do { do { if (0) printf ("wrong brick type: %s, use <HOSTNAME>:" "<export-dir-abs-path>", words[4]); } while (0); _cli_err ("wrong brick type: %s, use <HOSTNAME>:" "<export-dir-abs-path>" , words[4]); } while (0); | |||||
1397 | ret = -1; | |||||
1398 | goto out; | |||||
1399 | } else { | |||||
1400 | ret = gf_canonicalize_path (delimiter + 1); | |||||
1401 | if (ret) | |||||
1402 | goto out; | |||||
1403 | } | |||||
1404 | ret = dict_set_str (dict, "brick", str); | |||||
1405 | if (ret) | |||||
1406 | goto out; | |||||
1407 | /* Path */ | |||||
1408 | str = (char *)words[5]; | |||||
1409 | ret = dict_set_str (dict, "path", str); | |||||
1410 | if (ret) | |||||
1411 | goto out; | |||||
1412 | } else { | |||||
1413 | ret = dict_set_str (dict, "path", str); | |||||
1414 | if (ret) | |||||
1415 | goto out; | |||||
1416 | } | |||||
1417 | ||||||
1418 | *options = dict; | |||||
1419 | ||||||
1420 | out: | |||||
1421 | if (ret && dict) | |||||
1422 | dict_destroy (dict); | |||||
1423 | ||||||
1424 | return ret; | |||||
1425 | } | |||||
1426 | ||||||
1427 | int32_t | |||||
1428 | cli_cmd_log_level_parse (const char **words, int worcount, dict_t **options) | |||||
1429 | { | |||||
1430 | dict_t *dict = NULL((void*)0); | |||||
1431 | int ret = -1; | |||||
1432 | ||||||
1433 | GF_ASSERT (words)do { if (!(words)) { do { do { if (0) printf ("Assertion failed: " "words"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 1433, GF_LOG_ERROR, "Assertion failed: " "words" ); } while (0); } } while (0); | |||||
1434 | GF_ASSERT (options)do { if (!(options)) { do { do { if (0) printf ("Assertion failed: " "options"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 1434, GF_LOG_ERROR, "Assertion failed: " "options" ); } while (0); } } while (0); | |||||
1435 | ||||||
1436 | /* | |||||
1437 | * loglevel command format: | |||||
1438 | * > volume log level <VOL> <XLATOR[*]> <LOGLEVEL> | |||||
1439 | * > volume log level colon-o posix WARNING | |||||
1440 | * > volume log level colon-o replicate* DEBUG | |||||
1441 | * > volume log level coon-o * TRACE | |||||
1442 | */ | |||||
1443 | ||||||
1444 | GF_ASSERT ((strncmp(words[0], "volume", 6) == 0))do { if (!((strncmp(words[0], "volume", 6) == 0))) { do { do { if (0) printf ("Assertion failed: " "(strncmp(words[0], \"volume\", 6) == 0)" ); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c", __FUNCTION__ , 1444, GF_LOG_ERROR, "Assertion failed: " "(strncmp(words[0], \"volume\", 6) == 0)" ); } while (0); } } while (0); | |||||
1445 | GF_ASSERT ((strncmp(words[1], "log", 3) == 0))do { if (!((strncmp(words[1], "log", 3) == 0))) { do { do { if (0) printf ("Assertion failed: " "(strncmp(words[1], \"log\", 3) == 0)" ); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c", __FUNCTION__ , 1445, GF_LOG_ERROR, "Assertion failed: " "(strncmp(words[1], \"log\", 3) == 0)" ); } while (0); } } while (0); | |||||
1446 | GF_ASSERT ((strncmp(words[2], "level", 5) == 0))do { if (!((strncmp(words[2], "level", 5) == 0))) { do { do { if (0) printf ("Assertion failed: " "(strncmp(words[2], \"level\", 5) == 0)" ); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c", __FUNCTION__ , 1446, GF_LOG_ERROR, "Assertion failed: " "(strncmp(words[2], \"level\", 5) == 0)" ); } while (0); } } while (0); | |||||
1447 | ||||||
1448 | ret = glusterd_check_log_level(words[5]); | |||||
1449 | if (ret == -1) { | |||||
1450 | cli_err("Invalid log level [%s] specified", words[5])do { do { if (0) printf ("Invalid log level [%s] specified", words [5]); } while (0); _cli_err("Invalid log level [%s] specified" , words[5]); } while (0); | |||||
1451 | cli_err("Valid values for loglevel: (DEBUG|WARNING|ERROR"do { do { if (0) printf ("Valid values for loglevel: (DEBUG|WARNING|ERROR" "|CRITICAL|NONE|TRACE)"); } while (0); _cli_err("Valid values for loglevel: (DEBUG|WARNING|ERROR" "|CRITICAL|NONE|TRACE)"); } while (0) | |||||
1452 | "|CRITICAL|NONE|TRACE)")do { do { if (0) printf ("Valid values for loglevel: (DEBUG|WARNING|ERROR" "|CRITICAL|NONE|TRACE)"); } while (0); _cli_err("Valid values for loglevel: (DEBUG|WARNING|ERROR" "|CRITICAL|NONE|TRACE)"); } while (0); | |||||
1453 | goto out; | |||||
1454 | } | |||||
1455 | ||||||
1456 | dict = dict_new (); | |||||
1457 | if (!dict) | |||||
1458 | goto out; | |||||
1459 | ||||||
1460 | GF_ASSERT(words[3])do { if (!(words[3])) { do { do { if (0) printf ("Assertion failed: " "words[3]"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 1460, GF_LOG_ERROR, "Assertion failed: " "words[3]" ); } while (0); } } while (0); | |||||
1461 | GF_ASSERT(words[4])do { if (!(words[4])) { do { do { if (0) printf ("Assertion failed: " "words[4]"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 1461, GF_LOG_ERROR, "Assertion failed: " "words[4]" ); } while (0); } } while (0); | |||||
1462 | ||||||
1463 | ret = dict_set_str (dict, "volname", (char *)words[3]); | |||||
1464 | if (ret) | |||||
1465 | goto out; | |||||
1466 | ||||||
1467 | ret = dict_set_str (dict, "xlator", (char *)words[4]); | |||||
1468 | if (ret) | |||||
1469 | goto out; | |||||
1470 | ||||||
1471 | ret = dict_set_str (dict, "loglevel", (char *)words[5]); | |||||
1472 | if (ret) | |||||
1473 | goto out; | |||||
1474 | ||||||
1475 | *options = dict; | |||||
1476 | ||||||
1477 | out: | |||||
1478 | if (ret && dict) | |||||
1479 | dict_destroy (dict); | |||||
1480 | ||||||
1481 | return ret; | |||||
1482 | } | |||||
1483 | ||||||
1484 | int32_t | |||||
1485 | cli_cmd_log_locate_parse (const char **words, int wordcount, dict_t **options) | |||||
1486 | { | |||||
1487 | dict_t *dict = NULL((void*)0); | |||||
1488 | char *volname = NULL((void*)0); | |||||
1489 | char *str = NULL((void*)0); | |||||
1490 | int ret = -1; | |||||
1491 | char *delimiter = NULL((void*)0); | |||||
1492 | ||||||
1493 | GF_ASSERT (words)do { if (!(words)) { do { do { if (0) printf ("Assertion failed: " "words"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 1493, GF_LOG_ERROR, "Assertion failed: " "words" ); } while (0); } } while (0); | |||||
1494 | GF_ASSERT (options)do { if (!(options)) { do { do { if (0) printf ("Assertion failed: " "options"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 1494, GF_LOG_ERROR, "Assertion failed: " "options" ); } while (0); } } while (0); | |||||
1495 | ||||||
1496 | dict = dict_new (); | |||||
1497 | if (!dict) | |||||
1498 | goto out; | |||||
1499 | ||||||
1500 | volname = (char *)words[3]; | |||||
1501 | GF_ASSERT (volname)do { if (!(volname)) { do { do { if (0) printf ("Assertion failed: " "volname"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 1501, GF_LOG_ERROR, "Assertion failed: " "volname" ); } while (0); } } while (0); | |||||
1502 | ||||||
1503 | ret = dict_set_str (dict, "volname", volname); | |||||
1504 | if (ret) | |||||
1505 | goto out; | |||||
1506 | ||||||
1507 | if (words[4]) { | |||||
1508 | delimiter = strchr (words[4], ':'); | |||||
1509 | if (!delimiter || delimiter == words[4] | |||||
1510 | || *(delimiter+1) != '/') { | |||||
1511 | cli_err ("wrong brick type: %s, use <HOSTNAME>:"do { do { if (0) printf ("wrong brick type: %s, use <HOSTNAME>:" "<export-dir-abs-path>", words[4]); } while (0); _cli_err ("wrong brick type: %s, use <HOSTNAME>:" "<export-dir-abs-path>" , words[4]); } while (0) | |||||
1512 | "<export-dir-abs-path>", words[4])do { do { if (0) printf ("wrong brick type: %s, use <HOSTNAME>:" "<export-dir-abs-path>", words[4]); } while (0); _cli_err ("wrong brick type: %s, use <HOSTNAME>:" "<export-dir-abs-path>" , words[4]); } while (0); | |||||
1513 | ret = -1; | |||||
1514 | goto out; | |||||
1515 | } else { | |||||
1516 | ret = gf_canonicalize_path (delimiter + 1); | |||||
1517 | if (ret) | |||||
1518 | goto out; | |||||
1519 | } | |||||
1520 | str = (char *)words[4]; | |||||
1521 | ret = dict_set_str (dict, "brick", str); | |||||
1522 | if (ret) | |||||
1523 | goto out; | |||||
1524 | } | |||||
1525 | ||||||
1526 | *options = dict; | |||||
1527 | ||||||
1528 | out: | |||||
1529 | if (ret && dict) | |||||
1530 | dict_destroy (dict); | |||||
1531 | ||||||
1532 | return ret; | |||||
1533 | } | |||||
1534 | ||||||
1535 | int32_t | |||||
1536 | cli_cmd_log_rotate_parse (const char **words, int wordcount, dict_t **options) | |||||
1537 | { | |||||
1538 | dict_t *dict = NULL((void*)0); | |||||
1539 | char *volname = NULL((void*)0); | |||||
1540 | char *str = NULL((void*)0); | |||||
1541 | int ret = -1; | |||||
1542 | char *delimiter = NULL((void*)0); | |||||
1543 | ||||||
1544 | GF_ASSERT (words)do { if (!(words)) { do { do { if (0) printf ("Assertion failed: " "words"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 1544, GF_LOG_ERROR, "Assertion failed: " "words" ); } while (0); } } while (0); | |||||
1545 | GF_ASSERT (options)do { if (!(options)) { do { do { if (0) printf ("Assertion failed: " "options"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 1545, GF_LOG_ERROR, "Assertion failed: " "options" ); } while (0); } } while (0); | |||||
1546 | ||||||
1547 | dict = dict_new (); | |||||
1548 | if (!dict) | |||||
1549 | goto out; | |||||
1550 | ||||||
1551 | volname = (char *)words[3]; | |||||
1552 | GF_ASSERT (volname)do { if (!(volname)) { do { do { if (0) printf ("Assertion failed: " "volname"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 1552, GF_LOG_ERROR, "Assertion failed: " "volname" ); } while (0); } } while (0); | |||||
1553 | ||||||
1554 | ret = dict_set_str (dict, "volname", volname); | |||||
1555 | if (ret) | |||||
1556 | goto out; | |||||
1557 | ||||||
1558 | if (words[4]) { | |||||
1559 | delimiter = strchr (words[4], ':'); | |||||
1560 | if (!delimiter || delimiter == words[4] | |||||
1561 | || *(delimiter+1) != '/') { | |||||
1562 | cli_err ("wrong brick type: %s, use <HOSTNAME>:"do { do { if (0) printf ("wrong brick type: %s, use <HOSTNAME>:" "<export-dir-abs-path>", words[4]); } while (0); _cli_err ("wrong brick type: %s, use <HOSTNAME>:" "<export-dir-abs-path>" , words[4]); } while (0) | |||||
1563 | "<export-dir-abs-path>", words[4])do { do { if (0) printf ("wrong brick type: %s, use <HOSTNAME>:" "<export-dir-abs-path>", words[4]); } while (0); _cli_err ("wrong brick type: %s, use <HOSTNAME>:" "<export-dir-abs-path>" , words[4]); } while (0); | |||||
1564 | ret = -1; | |||||
1565 | goto out; | |||||
1566 | } else { | |||||
1567 | ret = gf_canonicalize_path (delimiter + 1); | |||||
1568 | if (ret) | |||||
1569 | goto out; | |||||
1570 | } | |||||
1571 | str = (char *)words[4]; | |||||
1572 | ret = dict_set_str (dict, "brick", str); | |||||
1573 | if (ret) | |||||
1574 | goto out; | |||||
1575 | } | |||||
1576 | ||||||
1577 | *options = dict; | |||||
1578 | ||||||
1579 | out: | |||||
1580 | if (ret && dict) | |||||
1581 | dict_destroy (dict); | |||||
1582 | ||||||
1583 | return ret; | |||||
1584 | } | |||||
1585 | ||||||
1586 | static gf_boolean_t | |||||
1587 | gsyncd_url_check (const char *w) | |||||
1588 | { | |||||
1589 | return !!strpbrk (w, ":/"); | |||||
1590 | } | |||||
1591 | ||||||
1592 | static gf_boolean_t | |||||
1593 | gsyncd_glob_check (const char *w) | |||||
1594 | { | |||||
1595 | return !!strpbrk (w, "*?["); | |||||
1596 | } | |||||
1597 | ||||||
1598 | int32_t | |||||
1599 | cli_cmd_gsync_set_parse (const char **words, int wordcount, dict_t **options) | |||||
1600 | { | |||||
1601 | int32_t ret = -1; | |||||
1602 | dict_t *dict = NULL((void*)0); | |||||
1603 | gf1_cli_gsync_set type = GF_GSYNC_OPTION_TYPE_NONE; | |||||
1604 | char *append_str = NULL((void*)0); | |||||
1605 | size_t append_len = 0; | |||||
1606 | char *subop = NULL((void*)0); | |||||
1607 | int i = 0; | |||||
1608 | unsigned masteri = 0; | |||||
1609 | unsigned slavei = 0; | |||||
1610 | unsigned glob = 0; | |||||
1611 | unsigned cmdi = 0; | |||||
1612 | char *opwords[] = { "status", "start", "stop", "config", | |||||
1613 | "log-rotate", NULL((void*)0) }; | |||||
1614 | char *w = NULL((void*)0); | |||||
1615 | ||||||
1616 | GF_ASSERT (words)do { if (!(words)) { do { do { if (0) printf ("Assertion failed: " "words"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 1616, GF_LOG_ERROR, "Assertion failed: " "words" ); } while (0); } } while (0); | |||||
1617 | GF_ASSERT (options)do { if (!(options)) { do { do { if (0) printf ("Assertion failed: " "options"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 1617, GF_LOG_ERROR, "Assertion failed: " "options" ); } while (0); } } while (0); | |||||
1618 | ||||||
1619 | dict = dict_new (); | |||||
1620 | if (!dict) | |||||
1621 | goto out; | |||||
1622 | ||||||
1623 | /* new syntax: | |||||
1624 | * | |||||
1625 | * volume geo-replication [$m [$s]] status | |||||
1626 | * volume geo-replication [$m] $s config [[!]$opt [$val]] | |||||
1627 | * volume geo-replication $m $s start|stop | |||||
1628 | * volume geo-replication $m [$s] log-rotate | |||||
1629 | */ | |||||
1630 | ||||||
1631 | if (wordcount < 3) | |||||
1632 | goto out; | |||||
1633 | ||||||
1634 | for (i = 2; i <= 3 && i < wordcount - 1; i++) { | |||||
1635 | if (gsyncd_glob_check (words[i])) | |||||
1636 | glob = i; | |||||
1637 | if (gsyncd_url_check (words[i])) { | |||||
1638 | slavei = i; | |||||
1639 | break; | |||||
1640 | } | |||||
1641 | } | |||||
1642 | ||||||
1643 | if (glob && !slavei) | |||||
1644 | /* glob is allowed only for config, thus it implies there is a | |||||
1645 | * slave argument; but that might have not been recognized on | |||||
1646 | * the first scan as it's url characteristics has been covered | |||||
1647 | * by the glob syntax. | |||||
1648 | * | |||||
1649 | * In this case, the slave is perforce the last glob-word -- the | |||||
1650 | * upcoming one is neither glob, nor url, so it's definitely not | |||||
1651 | * the slave. | |||||
1652 | */ | |||||
1653 | slavei = glob; | |||||
1654 | if (slavei) { | |||||
1655 | cmdi = slavei + 1; | |||||
1656 | if (slavei == 3) | |||||
1657 | masteri = 2; | |||||
1658 | } else if (i <= 3) { | |||||
1659 | /* no $s, can only be status cmd | |||||
1660 | * (with either a single $m before it or nothing) | |||||
1661 | * -- these conditions imply that i <= 3 after | |||||
1662 | * the iteration and that i is the successor of | |||||
1663 | * the (0 or 1 length) sequence of $m-s. | |||||
1664 | */ | |||||
1665 | cmdi = i; | |||||
1666 | if (i == 3) | |||||
1667 | masteri = 2; | |||||
1668 | } else | |||||
1669 | goto out; | |||||
1670 | ||||||
1671 | /* now check if input really complies syntax | |||||
1672 | * (in a somewhat redundant way, in favor | |||||
1673 | * transparent soundness) | |||||
1674 | */ | |||||
1675 | ||||||
1676 | if (masteri && gsyncd_url_check (words[masteri])) | |||||
1677 | goto out; | |||||
1678 | if (slavei && !glob && !gsyncd_url_check (words[slavei])) | |||||
1679 | goto out; | |||||
1680 | ||||||
1681 | w = str_getunamb (words[cmdi], opwords); | |||||
1682 | if (!w) | |||||
1683 | goto out; | |||||
1684 | ||||||
1685 | if (strcmp (w, "status") == 0) { | |||||
1686 | type = GF_GSYNC_OPTION_TYPE_STATUS; | |||||
1687 | ||||||
1688 | if (slavei && !masteri) | |||||
1689 | goto out; | |||||
1690 | } else if (strcmp (w, "config") == 0) { | |||||
1691 | type = GF_GSYNC_OPTION_TYPE_CONFIG; | |||||
1692 | ||||||
1693 | if (!slavei) | |||||
1694 | goto out; | |||||
1695 | } else if (strcmp (w, "start") == 0) { | |||||
1696 | type = GF_GSYNC_OPTION_TYPE_START; | |||||
1697 | ||||||
1698 | if (!masteri || !slavei) | |||||
1699 | goto out; | |||||
1700 | } else if (strcmp (w, "stop") == 0) { | |||||
1701 | type = GF_GSYNC_OPTION_TYPE_STOP; | |||||
1702 | ||||||
1703 | if (!masteri || !slavei) | |||||
1704 | goto out; | |||||
1705 | } else if (strcmp(w, "log-rotate") == 0) { | |||||
1706 | type = GF_GSYNC_OPTION_TYPE_ROTATE; | |||||
1707 | ||||||
1708 | if (slavei && !masteri) | |||||
1709 | goto out; | |||||
1710 | } else | |||||
1711 | GF_ASSERT (!"opword mismatch")do { if (!(!"opword mismatch")) { do { do { if (0) printf ("Assertion failed: " "!\"opword mismatch\""); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c", __FUNCTION__, 1711, GF_LOG_ERROR, "Assertion failed: " "!\"opword mismatch\""); } while (0); } } while (0); | |||||
1712 | ||||||
1713 | if (type != GF_GSYNC_OPTION_TYPE_CONFIG && | |||||
1714 | (cmdi < wordcount - 1 || glob)) | |||||
1715 | goto out; | |||||
1716 | ||||||
1717 | /* If got so far, input is valid, assemble the message */ | |||||
1718 | ||||||
1719 | ret = 0; | |||||
1720 | ||||||
1721 | if (masteri) | |||||
1722 | ret = dict_set_str (dict, "master", (char *)words[masteri]); | |||||
1723 | if (!ret && slavei) | |||||
1724 | ret = dict_set_str (dict, "slave", (char *)words[slavei]); | |||||
1725 | if (!ret) | |||||
1726 | ret = dict_set_int32 (dict, "type", type); | |||||
1727 | if (!ret && type == GF_GSYNC_OPTION_TYPE_CONFIG) { | |||||
1728 | switch ((wordcount - 1) - cmdi) { | |||||
1729 | case 0: | |||||
1730 | subop = gf_strdup ("get-all"); | |||||
1731 | break; | |||||
1732 | case 1: | |||||
1733 | if (words[cmdi + 1][0] == '!') { | |||||
1734 | (words[cmdi + 1])++; | |||||
1735 | if (gf_asprintf (&subop, "del%s", glob ? "-glob" : "") == -1) | |||||
1736 | subop = NULL((void*)0); | |||||
1737 | } else | |||||
1738 | subop = gf_strdup ("get"); | |||||
1739 | ||||||
1740 | ret = dict_set_str (dict, "op_name", ((char *)words[cmdi + 1])); | |||||
1741 | if (ret < 0) | |||||
1742 | goto out; | |||||
1743 | break; | |||||
1744 | default: | |||||
1745 | if (gf_asprintf (&subop, "set%s", glob ? "-glob" : "") == -1) | |||||
1746 | subop = NULL((void*)0); | |||||
1747 | ||||||
1748 | ret = dict_set_str (dict, "op_name", ((char *)words[cmdi + 1])); | |||||
1749 | if (ret < 0) | |||||
1750 | goto out; | |||||
1751 | ||||||
1752 | /* join the varargs by spaces to get the op_value */ | |||||
1753 | ||||||
1754 | for (i = cmdi + 2; i < wordcount; i++) | |||||
1755 | append_len += (strlen (words[i]) + 1); | |||||
1756 | /* trailing strcat will add two bytes, make space for that */ | |||||
1757 | append_len++; | |||||
1758 | ||||||
1759 | append_str = GF_CALLOC (1, append_len, cli_mt_append_str)__gf_calloc (1, append_len, cli_mt_append_str); | |||||
1760 | if (!append_str) { | |||||
1761 | ret = -1; | |||||
1762 | goto out; | |||||
1763 | } | |||||
1764 | ||||||
1765 | for (i = cmdi + 2; i < wordcount; i++) { | |||||
1766 | strcat (append_str, words[i]); | |||||
1767 | strcat (append_str, " "); | |||||
1768 | } | |||||
1769 | append_str[append_len - 2] = '\0'; | |||||
1770 | ||||||
1771 | /* "checkpoint now" is special: we resolve that "now" */ | |||||
1772 | if (strcmp (words[cmdi + 1], "checkpoint") == 0 && | |||||
1773 | strcmp (append_str, "now") == 0) { | |||||
1774 | struct timeval tv = {0,}; | |||||
1775 | ||||||
1776 | ret = gettimeofday (&tv, NULL((void*)0)); | |||||
1777 | if (ret == -1) | |||||
1778 | goto out; /* FIXME: free append_str? */ | |||||
1779 | ||||||
1780 | GF_FREE (append_str)__gf_free (append_str); | |||||
1781 | append_str = GF_CALLOC (1, 300, cli_mt_append_str)__gf_calloc (1, 300, cli_mt_append_str); | |||||
1782 | if (!append_str) { | |||||
1783 | ret = -1; | |||||
1784 | goto out; | |||||
1785 | } | |||||
1786 | strcpy (append_str, "as of "); | |||||
1787 | gf_time_fmt (append_str + strlen ("as of "), | |||||
1788 | 300 - strlen ("as of "), | |||||
1789 | tv.tv_sec, gf_timefmt_FT); | |||||
1790 | } | |||||
1791 | ||||||
1792 | ret = dict_set_dynstr (dict, "op_value", append_str); | |||||
1793 | } | |||||
1794 | ||||||
1795 | ret = -1; | |||||
1796 | if (subop) { | |||||
1797 | ret = dict_set_dynstr (dict, "subop", subop); | |||||
1798 | if (!ret) | |||||
1799 | subop = NULL((void*)0); | |||||
1800 | } | |||||
1801 | } | |||||
1802 | ||||||
1803 | out: | |||||
1804 | if (ret) { | |||||
1805 | if (dict) | |||||
1806 | dict_destroy (dict); | |||||
1807 | GF_FREE (append_str)__gf_free (append_str); | |||||
1808 | } else | |||||
1809 | *options = dict; | |||||
1810 | ||||||
1811 | GF_FREE (subop)__gf_free (subop); | |||||
1812 | ||||||
1813 | return ret; | |||||
1814 | } | |||||
1815 | ||||||
1816 | int32_t | |||||
1817 | cli_cmd_volume_profile_parse (const char **words, int wordcount, | |||||
1818 | dict_t **options) | |||||
1819 | { | |||||
1820 | dict_t *dict = NULL((void*)0); | |||||
1821 | char *volname = NULL((void*)0); | |||||
1822 | int ret = -1; | |||||
1823 | gf1_cli_stats_op op = GF_CLI_STATS_NONE; | |||||
1824 | char *opwords[] = { "start", "stop", "info", NULL((void*)0) }; | |||||
1825 | char *w = NULL((void*)0); | |||||
1826 | ||||||
1827 | GF_ASSERT (words)do { if (!(words)) { do { do { if (0) printf ("Assertion failed: " "words"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 1827, GF_LOG_ERROR, "Assertion failed: " "words" ); } while (0); } } while (0); | |||||
1828 | GF_ASSERT (options)do { if (!(options)) { do { do { if (0) printf ("Assertion failed: " "options"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 1828, GF_LOG_ERROR, "Assertion failed: " "options" ); } while (0); } } while (0); | |||||
1829 | ||||||
1830 | dict = dict_new (); | |||||
1831 | if (!dict) | |||||
1832 | goto out; | |||||
1833 | ||||||
1834 | if (wordcount < 4 || wordcount >5) | |||||
1835 | goto out; | |||||
1836 | ||||||
1837 | volname = (char *)words[2]; | |||||
1838 | ||||||
1839 | ret = dict_set_str (dict, "volname", volname); | |||||
1840 | if (ret) | |||||
1841 | goto out; | |||||
1842 | ||||||
1843 | w = str_getunamb (words[3], opwords); | |||||
1844 | if (!w) { | |||||
1845 | ret = -1; | |||||
1846 | goto out; | |||||
1847 | } | |||||
1848 | if (strcmp (w, "start") == 0) { | |||||
1849 | op = GF_CLI_STATS_START; | |||||
1850 | } else if (strcmp (w, "stop") == 0) { | |||||
1851 | op = GF_CLI_STATS_STOP; | |||||
1852 | } else if (strcmp (w, "info") == 0) { | |||||
1853 | op = GF_CLI_STATS_INFO; | |||||
1854 | } else | |||||
1855 | GF_ASSERT (!"opword mismatch")do { if (!(!"opword mismatch")) { do { do { if (0) printf ("Assertion failed: " "!\"opword mismatch\""); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c", __FUNCTION__, 1855, GF_LOG_ERROR, "Assertion failed: " "!\"opword mismatch\""); } while (0); } } while (0); | |||||
1856 | ||||||
1857 | ret = dict_set_int32 (dict, "op", (int32_t)op); | |||||
1858 | if (ret) | |||||
1859 | goto out; | |||||
1860 | ||||||
1861 | if (wordcount == 5) { | |||||
1862 | if (!strcmp (words[4], "nfs")) { | |||||
1863 | ret = dict_set_int32 (dict, "nfs", _gf_true); | |||||
1864 | if (ret) | |||||
1865 | goto out; | |||||
1866 | } | |||||
1867 | } | |||||
1868 | ||||||
1869 | *options = dict; | |||||
1870 | out: | |||||
1871 | if (ret && dict) | |||||
1872 | dict_destroy (dict); | |||||
1873 | return ret; | |||||
1874 | } | |||||
1875 | ||||||
1876 | int32_t | |||||
1877 | cli_cmd_volume_top_parse (const char **words, int wordcount, | |||||
1878 | dict_t **options) | |||||
1879 | { | |||||
1880 | dict_t *dict = NULL((void*)0); | |||||
1881 | char *volname = NULL((void*)0); | |||||
1882 | char *value = NULL((void*)0); | |||||
1883 | char *key = NULL((void*)0); | |||||
1884 | int ret = -1; | |||||
1885 | gf1_cli_stats_op op = GF_CLI_STATS_NONE; | |||||
1886 | gf1_cli_top_op top_op = GF_CLI_TOP_NONE; | |||||
1887 | int32_t list_cnt = -1; | |||||
1888 | int index = 0; | |||||
1889 | int perf = 0; | |||||
1890 | uint32_t blk_size = 0; | |||||
1891 | uint32_t count = 0; | |||||
1892 | gf_boolean_t nfs = _gf_false; | |||||
1893 | char *delimiter = NULL((void*)0); | |||||
1894 | char *opwords[] = { "open", "read", "write", "opendir", | |||||
1895 | "readdir", "read-perf", "write-perf", | |||||
1896 | "clear", NULL((void*)0) }; | |||||
1897 | char *w = NULL((void*)0); | |||||
1898 | ||||||
1899 | GF_ASSERT (words)do { if (!(words)) { do { do { if (0) printf ("Assertion failed: " "words"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 1899, GF_LOG_ERROR, "Assertion failed: " "words" ); } while (0); } } while (0); | |||||
1900 | GF_ASSERT (options)do { if (!(options)) { do { do { if (0) printf ("Assertion failed: " "options"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 1900, GF_LOG_ERROR, "Assertion failed: " "options" ); } while (0); } } while (0); | |||||
1901 | ||||||
1902 | dict = dict_new (); | |||||
1903 | if (!dict) | |||||
1904 | goto out; | |||||
1905 | ||||||
1906 | if (wordcount < 4) | |||||
1907 | goto out; | |||||
1908 | ||||||
1909 | volname = (char *)words[2]; | |||||
1910 | ||||||
1911 | ret = dict_set_str (dict, "volname", volname); | |||||
1912 | if (ret) | |||||
1913 | goto out; | |||||
1914 | ||||||
1915 | op = GF_CLI_STATS_TOP; | |||||
1916 | ret = dict_set_int32 (dict, "op", (int32_t)op); | |||||
1917 | if (ret) | |||||
1918 | goto out; | |||||
1919 | ||||||
1920 | w = str_getunamb (words[3], opwords); | |||||
1921 | if (!w) { | |||||
1922 | ret = -1; | |||||
1923 | goto out; | |||||
1924 | } | |||||
1925 | if (strcmp (w, "open") == 0) { | |||||
1926 | top_op = GF_CLI_TOP_OPEN; | |||||
1927 | } else if (strcmp (w, "read") == 0) { | |||||
1928 | top_op = GF_CLI_TOP_READ; | |||||
1929 | } else if (strcmp (w, "write") == 0) { | |||||
1930 | top_op = GF_CLI_TOP_WRITE; | |||||
1931 | } else if (strcmp (w, "opendir") == 0) { | |||||
1932 | top_op = GF_CLI_TOP_OPENDIR; | |||||
1933 | } else if (strcmp (w, "readdir") == 0) { | |||||
1934 | top_op = GF_CLI_TOP_READDIR; | |||||
1935 | } else if (strcmp (w, "read-perf") == 0) { | |||||
1936 | top_op = GF_CLI_TOP_READ_PERF; | |||||
1937 | perf = 1; | |||||
1938 | } else if (strcmp (w, "write-perf") == 0) { | |||||
1939 | top_op = GF_CLI_TOP_WRITE_PERF; | |||||
1940 | perf = 1; | |||||
1941 | } else if (strcmp (w, "clear") == 0) { | |||||
1942 | ret = dict_set_int32 (dict, "clear-stats", 1); | |||||
1943 | if (ret) { | |||||
1944 | gf_log ("cli", GF_LOG_ERROR,do { do { if (0) printf ("Could not set clear-stats in dict") ; } while (0); _gf_log ("cli", "cli-cmd-parser.c", __FUNCTION__ , 1945, GF_LOG_ERROR, "Could not set clear-stats in dict"); } while (0) | |||||
1945 | "Could not set clear-stats in dict")do { do { if (0) printf ("Could not set clear-stats in dict") ; } while (0); _gf_log ("cli", "cli-cmd-parser.c", __FUNCTION__ , 1945, GF_LOG_ERROR, "Could not set clear-stats in dict"); } while (0); | |||||
1946 | goto out; | |||||
1947 | } | |||||
1948 | } else | |||||
1949 | GF_ASSERT (!"opword mismatch")do { if (!(!"opword mismatch")) { do { do { if (0) printf ("Assertion failed: " "!\"opword mismatch\""); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c", __FUNCTION__, 1949, GF_LOG_ERROR, "Assertion failed: " "!\"opword mismatch\""); } while (0); } } while (0); | |||||
1950 | ret = dict_set_int32 (dict, "top-op", (int32_t)top_op); | |||||
1951 | if (ret) | |||||
1952 | goto out; | |||||
1953 | ||||||
1954 | if ((wordcount > 4) && !strcmp (words[4], "nfs")) { | |||||
1955 | nfs = _gf_true; | |||||
1956 | ret = dict_set_int32 (dict, "nfs", nfs); | |||||
1957 | if (ret) | |||||
1958 | goto out; | |||||
1959 | index = 5; | |||||
1960 | } else { | |||||
1961 | index = 4; | |||||
1962 | } | |||||
1963 | ||||||
1964 | for (; index < wordcount; index+=2) { | |||||
1965 | ||||||
1966 | key = (char *) words[index]; | |||||
1967 | value = (char *) words[index+1]; | |||||
1968 | ||||||
1969 | if ( key && !value ) { | |||||
1970 | ret = -1; | |||||
1971 | goto out; | |||||
1972 | } | |||||
1973 | if (!strcmp (key, "brick")) { | |||||
1974 | delimiter = strchr (value, ':'); | |||||
1975 | if (!delimiter || delimiter == value | |||||
1976 | || *(delimiter+1) != '/') { | |||||
1977 | cli_err ("wrong brick type: %s, use <HOSTNAME>:"do { do { if (0) printf ("wrong brick type: %s, use <HOSTNAME>:" "<export-dir-abs-path>", value); } while (0); _cli_err ("wrong brick type: %s, use <HOSTNAME>:" "<export-dir-abs-path>" , value); } while (0) | |||||
1978 | "<export-dir-abs-path>", value)do { do { if (0) printf ("wrong brick type: %s, use <HOSTNAME>:" "<export-dir-abs-path>", value); } while (0); _cli_err ("wrong brick type: %s, use <HOSTNAME>:" "<export-dir-abs-path>" , value); } while (0); | |||||
1979 | ret = -1; | |||||
1980 | goto out; | |||||
1981 | } else { | |||||
1982 | ret = gf_canonicalize_path (delimiter + 1); | |||||
1983 | if (ret) | |||||
1984 | goto out; | |||||
1985 | } | |||||
1986 | ret = dict_set_str (dict, "brick", value); | |||||
1987 | ||||||
1988 | } else if (!strcmp (key, "list-cnt")) { | |||||
1989 | ret = gf_is_str_int (value); | |||||
1990 | if (!ret) | |||||
1991 | list_cnt = atoi (value); | |||||
1992 | if (ret || (list_cnt < 0) || (list_cnt > 100)) { | |||||
1993 | cli_err ("list-cnt should be between 0 to 100")do { do { if (0) printf ("list-cnt should be between 0 to 100" ); } while (0); _cli_err("list-cnt should be between 0 to 100" ); } while (0); | |||||
1994 | ret = -1; | |||||
1995 | goto out; | |||||
1996 | } | |||||
1997 | } else if (perf && !nfs && !strcmp (key, "bs")) { | |||||
1998 | ret = gf_is_str_int (value); | |||||
1999 | if (!ret) | |||||
2000 | blk_size = atoi (value); | |||||
2001 | if (ret || (blk_size <= 0)) { | |||||
2002 | if (blk_size < 0) | |||||
2003 | cli_err ("block size is an invalid"do { do { if (0) printf ("block size is an invalid" " number" ); } while (0); _cli_err("block size is an invalid" " number" ); } while (0) | |||||
2004 | " number")do { do { if (0) printf ("block size is an invalid" " number" ); } while (0); _cli_err("block size is an invalid" " number" ); } while (0); | |||||
2005 | else | |||||
2006 | cli_err ("block size should be an "do { do { if (0) printf ("block size should be an " "integer greater than zero" ); } while (0); _cli_err("block size should be an " "integer greater than zero" ); } while (0) | |||||
2007 | "integer greater than zero")do { do { if (0) printf ("block size should be an " "integer greater than zero" ); } while (0); _cli_err("block size should be an " "integer greater than zero" ); } while (0); | |||||
2008 | ret = -1; | |||||
2009 | goto out; | |||||
2010 | } | |||||
2011 | ret = dict_set_uint32 (dict, "blk-size", blk_size); | |||||
2012 | } else if (perf && !nfs && !strcmp (key, "count")) { | |||||
2013 | ret = gf_is_str_int (value); | |||||
2014 | if (!ret) | |||||
2015 | count = atoi(value); | |||||
2016 | if (ret || (count <= 0)) { | |||||
2017 | if (count < 0) | |||||
2018 | cli_err ("count is an invalid number")do { do { if (0) printf ("count is an invalid number"); } while (0); _cli_err("count is an invalid number"); } while (0); | |||||
2019 | else | |||||
2020 | cli_err ("count should be an integer "do { do { if (0) printf ("count should be an integer " "greater than zero" ); } while (0); _cli_err("count should be an integer " "greater than zero" ); } while (0) | |||||
2021 | "greater than zero")do { do { if (0) printf ("count should be an integer " "greater than zero" ); } while (0); _cli_err("count should be an integer " "greater than zero" ); } while (0); | |||||
2022 | ||||||
2023 | ret = -1; | |||||
2024 | goto out; | |||||
2025 | } | |||||
2026 | ret = dict_set_uint32 (dict, "blk-cnt", count); | |||||
2027 | } else { | |||||
2028 | ret = -1; | |||||
2029 | goto out; | |||||
2030 | } | |||||
2031 | if (ret) { | |||||
2032 | gf_log ("", GF_LOG_WARNING, "Dict set failed for "do { do { if (0) printf ("Dict set failed for " "key %s", key ); } while (0); _gf_log ("", "cli-cmd-parser.c", __FUNCTION__ , 2033, GF_LOG_WARNING, "Dict set failed for " "key %s", key) ; } while (0) | |||||
2033 | "key %s", key)do { do { if (0) printf ("Dict set failed for " "key %s", key ); } while (0); _gf_log ("", "cli-cmd-parser.c", __FUNCTION__ , 2033, GF_LOG_WARNING, "Dict set failed for " "key %s", key) ; } while (0); | |||||
2034 | goto out; | |||||
2035 | } | |||||
2036 | } | |||||
2037 | if (list_cnt == -1) | |||||
2038 | list_cnt = 100; | |||||
2039 | ret = dict_set_int32 (dict, "list-cnt", list_cnt); | |||||
2040 | if (ret) { | |||||
2041 | gf_log ("", GF_LOG_WARNING, "Dict set failed for list_cnt")do { do { if (0) printf ("Dict set failed for list_cnt"); } while (0); _gf_log ("", "cli-cmd-parser.c", __FUNCTION__, 2041, GF_LOG_WARNING , "Dict set failed for list_cnt"); } while (0); | |||||
2042 | goto out; | |||||
2043 | } | |||||
2044 | ||||||
2045 | if ((blk_size > 0) ^ (count > 0)) { | |||||
2046 | cli_err ("Need to give both 'bs' and 'count'")do { do { if (0) printf ("Need to give both 'bs' and 'count'" ); } while (0); _cli_err("Need to give both 'bs' and 'count'" ); } while (0); | |||||
2047 | ret = -1; | |||||
2048 | goto out; | |||||
2049 | } else if (((uint64_t)blk_size * count) > (10 * GF_UNIT_GB1073741824ULL)) { | |||||
2050 | cli_err ("'bs * count' value %"PRIu64" is greater than "do { do { if (0) printf ("'bs * count' value %""ll" "u"" is greater than " "maximum allowed value of 10GB", ((uint64_t)blk_size * count )); } while (0); _cli_err("'bs * count' value %""ll" "u"" is greater than " "maximum allowed value of 10GB", ((uint64_t)blk_size * count )); } while (0) | |||||
2051 | "maximum allowed value of 10GB",do { do { if (0) printf ("'bs * count' value %""ll" "u"" is greater than " "maximum allowed value of 10GB", ((uint64_t)blk_size * count )); } while (0); _cli_err("'bs * count' value %""ll" "u"" is greater than " "maximum allowed value of 10GB", ((uint64_t)blk_size * count )); } while (0) | |||||
2052 | ((uint64_t)blk_size * count))do { do { if (0) printf ("'bs * count' value %""ll" "u"" is greater than " "maximum allowed value of 10GB", ((uint64_t)blk_size * count )); } while (0); _cli_err("'bs * count' value %""ll" "u"" is greater than " "maximum allowed value of 10GB", ((uint64_t)blk_size * count )); } while (0); | |||||
2053 | ret = -1; | |||||
2054 | goto out; | |||||
2055 | } | |||||
2056 | ||||||
2057 | *options = dict; | |||||
2058 | out: | |||||
2059 | if (ret && dict) | |||||
2060 | dict_destroy (dict); | |||||
2061 | return ret; | |||||
2062 | } | |||||
2063 | ||||||
2064 | uint32_t | |||||
2065 | cli_cmd_get_statusop (const char *arg) | |||||
2066 | { | |||||
2067 | int i = 0; | |||||
2068 | uint32_t ret = GF_CLI_STATUS_NONE; | |||||
2069 | char *w = NULL((void*)0); | |||||
2070 | char *opwords[] = {"detail", "mem", "clients", "fd", | |||||
2071 | "inode", "callpool", NULL((void*)0)}; | |||||
2072 | struct { | |||||
2073 | char *opname; | |||||
2074 | uint32_t opcode; | |||||
2075 | } optable[] = { | |||||
2076 | { "detail", GF_CLI_STATUS_DETAIL }, | |||||
2077 | { "mem", GF_CLI_STATUS_MEM }, | |||||
2078 | { "clients", GF_CLI_STATUS_CLIENTS }, | |||||
2079 | { "fd", GF_CLI_STATUS_FD }, | |||||
2080 | { "inode", GF_CLI_STATUS_INODE }, | |||||
2081 | { "callpool", GF_CLI_STATUS_CALLPOOL }, | |||||
2082 | { NULL((void*)0) } | |||||
2083 | }; | |||||
2084 | ||||||
2085 | w = str_getunamb (arg, opwords); | |||||
2086 | if (!w) { | |||||
2087 | gf_log ("cli", GF_LOG_DEBUG,do { do { if (0) printf ("Not a status op %s", arg); } while (0); _gf_log ("cli", "cli-cmd-parser.c", __FUNCTION__, 2088, GF_LOG_DEBUG, "Not a status op %s", arg); } while (0) | |||||
2088 | "Not a status op %s", arg)do { do { if (0) printf ("Not a status op %s", arg); } while (0); _gf_log ("cli", "cli-cmd-parser.c", __FUNCTION__, 2088, GF_LOG_DEBUG, "Not a status op %s", arg); } while (0); | |||||
2089 | goto out; | |||||
2090 | } | |||||
2091 | ||||||
2092 | for (i = 0; optable[i].opname; i++) { | |||||
2093 | if (!strcmp (w, optable[i].opname)) { | |||||
2094 | ret = optable[i].opcode; | |||||
2095 | break; | |||||
2096 | } | |||||
2097 | } | |||||
2098 | ||||||
2099 | out: | |||||
2100 | return ret; | |||||
2101 | } | |||||
2102 | ||||||
2103 | int | |||||
2104 | cli_cmd_volume_status_parse (const char **words, int wordcount, | |||||
2105 | dict_t **options) | |||||
2106 | { | |||||
2107 | dict_t *dict = NULL((void*)0); | |||||
2108 | int ret = -1; | |||||
2109 | uint32_t cmd = 0; | |||||
2110 | ||||||
2111 | GF_ASSERT (options)do { if (!(options)) { do { do { if (0) printf ("Assertion failed: " "options"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 2111, GF_LOG_ERROR, "Assertion failed: " "options" ); } while (0); } } while (0); | |||||
2112 | ||||||
2113 | dict = dict_new (); | |||||
2114 | if (!dict) | |||||
2115 | goto out; | |||||
2116 | ||||||
2117 | switch (wordcount) { | |||||
2118 | ||||||
2119 | case 2: | |||||
2120 | cmd = GF_CLI_STATUS_ALL; | |||||
2121 | ret = 0; | |||||
2122 | break; | |||||
2123 | ||||||
2124 | case 3: | |||||
2125 | if (!strcmp (words[2], "all")) { | |||||
2126 | cmd = GF_CLI_STATUS_ALL; | |||||
2127 | ret = 0; | |||||
2128 | ||||||
2129 | } else { | |||||
2130 | cmd = GF_CLI_STATUS_VOL; | |||||
2131 | ret = dict_set_str (dict, "volname", (char *)words[2]); | |||||
2132 | } | |||||
2133 | ||||||
2134 | break; | |||||
2135 | ||||||
2136 | case 4: | |||||
2137 | cmd = cli_cmd_get_statusop (words[3]); | |||||
2138 | ||||||
2139 | if (!strcmp (words[2], "all")) { | |||||
2140 | if (cmd == GF_CLI_STATUS_NONE) { | |||||
2141 | cli_err ("%s is not a valid status option",do { do { if (0) printf ("%s is not a valid status option", words [3]); } while (0); _cli_err("%s is not a valid status option" , words[3]); } while (0) | |||||
2142 | words[3])do { do { if (0) printf ("%s is not a valid status option", words [3]); } while (0); _cli_err("%s is not a valid status option" , words[3]); } while (0); | |||||
2143 | ret = -1; | |||||
2144 | goto out; | |||||
2145 | } | |||||
2146 | cmd |= GF_CLI_STATUS_ALL; | |||||
2147 | ret = 0; | |||||
2148 | ||||||
2149 | } else { | |||||
2150 | ret = dict_set_str (dict, "volname", | |||||
2151 | (char *)words[2]); | |||||
2152 | if (ret) | |||||
2153 | goto out; | |||||
2154 | ||||||
2155 | if (cmd == GF_CLI_STATUS_NONE) { | |||||
2156 | if (!strcmp (words[3], "nfs")) { | |||||
2157 | cmd |= GF_CLI_STATUS_NFS; | |||||
2158 | } else if (!strcmp (words[3], "shd")) { | |||||
2159 | cmd |= GF_CLI_STATUS_SHD; | |||||
2160 | } else { | |||||
2161 | cmd = GF_CLI_STATUS_BRICK; | |||||
2162 | ret = dict_set_str (dict, "brick", | |||||
2163 | (char *)words[3]); | |||||
2164 | } | |||||
2165 | ||||||
2166 | } else { | |||||
2167 | cmd |= GF_CLI_STATUS_VOL; | |||||
2168 | ret = 0; | |||||
2169 | } | |||||
2170 | } | |||||
2171 | ||||||
2172 | break; | |||||
2173 | ||||||
2174 | case 5: | |||||
2175 | if (!strcmp (words[2], "all")) { | |||||
2176 | cli_err ("Cannot specify brick/nfs for \"all\"")do { do { if (0) printf ("Cannot specify brick/nfs for \"all\"" ); } while (0); _cli_err("Cannot specify brick/nfs for \"all\"" ); } while (0); | |||||
2177 | ret = -1; | |||||
2178 | goto out; | |||||
2179 | } | |||||
2180 | ||||||
2181 | cmd = cli_cmd_get_statusop (words[4]); | |||||
2182 | if (cmd == GF_CLI_STATUS_NONE) { | |||||
2183 | cli_err ("%s is not a valid status option",do { do { if (0) printf ("%s is not a valid status option", words [4]); } while (0); _cli_err("%s is not a valid status option" , words[4]); } while (0) | |||||
2184 | words[4])do { do { if (0) printf ("%s is not a valid status option", words [4]); } while (0); _cli_err("%s is not a valid status option" , words[4]); } while (0); | |||||
2185 | ret = -1; | |||||
2186 | goto out; | |||||
2187 | } | |||||
2188 | ||||||
2189 | ||||||
2190 | ret = dict_set_str (dict, "volname", (char *)words[2]); | |||||
2191 | if (ret) | |||||
2192 | goto out; | |||||
2193 | ||||||
2194 | if (!strcmp (words[3], "nfs")) { | |||||
2195 | if (cmd == GF_CLI_STATUS_FD || | |||||
2196 | cmd == GF_CLI_STATUS_DETAIL) { | |||||
2197 | cli_err ("Detail/FD status not available"do { do { if (0) printf ("Detail/FD status not available" " for NFS Servers" ); } while (0); _cli_err("Detail/FD status not available" " for NFS Servers" ); } while (0) | |||||
2198 | " for NFS Servers")do { do { if (0) printf ("Detail/FD status not available" " for NFS Servers" ); } while (0); _cli_err("Detail/FD status not available" " for NFS Servers" ); } while (0); | |||||
2199 | ret = -1; | |||||
2200 | goto out; | |||||
2201 | } | |||||
2202 | cmd |= GF_CLI_STATUS_NFS; | |||||
2203 | } else if (!strcmp (words[3], "shd")){ | |||||
2204 | if (cmd == GF_CLI_STATUS_FD || | |||||
2205 | cmd == GF_CLI_STATUS_CLIENTS || | |||||
2206 | cmd == GF_CLI_STATUS_DETAIL) { | |||||
2207 | cli_err ("Detail/FD/Clients status not "do { do { if (0) printf ("Detail/FD/Clients status not " "available for Self-heal Daemons" ); } while (0); _cli_err("Detail/FD/Clients status not " "available for Self-heal Daemons" ); } while (0) | |||||
2208 | "available for Self-heal Daemons")do { do { if (0) printf ("Detail/FD/Clients status not " "available for Self-heal Daemons" ); } while (0); _cli_err("Detail/FD/Clients status not " "available for Self-heal Daemons" ); } while (0); | |||||
2209 | ret = -1; | |||||
2210 | goto out; | |||||
2211 | } | |||||
2212 | cmd |= GF_CLI_STATUS_SHD; | |||||
2213 | } else { | |||||
2214 | cmd |= GF_CLI_STATUS_BRICK; | |||||
2215 | ret = dict_set_str (dict, "brick", (char *)words[3]); | |||||
2216 | } | |||||
2217 | break; | |||||
2218 | ||||||
2219 | default: | |||||
2220 | goto out; | |||||
2221 | } | |||||
2222 | ||||||
2223 | if (ret) | |||||
2224 | goto out; | |||||
2225 | ||||||
2226 | ret = dict_set_int32 (dict, "cmd", cmd); | |||||
2227 | if (ret) | |||||
2228 | goto out; | |||||
2229 | ||||||
2230 | *options = dict; | |||||
2231 | ||||||
2232 | out: | |||||
2233 | if (ret && dict) | |||||
2234 | dict_destroy (dict); | |||||
2235 | ||||||
2236 | return ret; | |||||
2237 | } | |||||
2238 | ||||||
2239 | gf_boolean_t | |||||
2240 | cli_cmd_validate_dumpoption (const char *arg, char **option) | |||||
2241 | { | |||||
2242 | char *opwords[] = {"all", "nfs", "mem", "iobuf", "callpool", "priv", | |||||
2243 | "fd", "inode", "history", "inodectx", "fdctx", | |||||
2244 | NULL((void*)0)}; | |||||
2245 | char *w = NULL((void*)0); | |||||
2246 | ||||||
2247 | w = str_getunamb (arg, opwords); | |||||
2248 | if (!w) { | |||||
2249 | gf_log ("cli", GF_LOG_DEBUG, "Unknown statedump option %s",do { do { if (0) printf ("Unknown statedump option %s", arg) ; } while (0); _gf_log ("cli", "cli-cmd-parser.c", __FUNCTION__ , 2250, GF_LOG_DEBUG, "Unknown statedump option %s", arg); } while (0) | |||||
2250 | arg)do { do { if (0) printf ("Unknown statedump option %s", arg) ; } while (0); _gf_log ("cli", "cli-cmd-parser.c", __FUNCTION__ , 2250, GF_LOG_DEBUG, "Unknown statedump option %s", arg); } while (0); | |||||
2251 | return _gf_false; | |||||
2252 | } | |||||
2253 | *option = w; | |||||
2254 | return _gf_true; | |||||
2255 | } | |||||
2256 | ||||||
2257 | int | |||||
2258 | cli_cmd_volume_statedump_options_parse (const char **words, int wordcount, | |||||
2259 | dict_t **options) | |||||
2260 | { | |||||
2261 | int ret = 0; | |||||
2262 | int i = 0; | |||||
2263 | dict_t *dict = NULL((void*)0); | |||||
2264 | int option_cnt = 0; | |||||
2265 | char *option = NULL((void*)0); | |||||
2266 | char option_str[100] = {0,}; | |||||
2267 | ||||||
2268 | for (i = 3; i < wordcount; i++, option_cnt++) { | |||||
2269 | if (!cli_cmd_validate_dumpoption (words[i], &option)) { | |||||
2270 | ret = -1; | |||||
2271 | goto out; | |||||
2272 | } | |||||
2273 | strncat (option_str, option, strlen (option)); | |||||
2274 | strncat (option_str, " ", 1); | |||||
2275 | } | |||||
2276 | ||||||
2277 | dict = dict_new (); | |||||
2278 | if (!dict) | |||||
2279 | goto out; | |||||
2280 | ||||||
2281 | ret = dict_set_dynstr (dict, "options", gf_strdup (option_str)); | |||||
2282 | if (ret) | |||||
2283 | goto out; | |||||
2284 | ||||||
2285 | ret = dict_set_int32 (dict, "option_cnt", option_cnt); | |||||
2286 | if (ret) | |||||
2287 | goto out; | |||||
2288 | ||||||
2289 | *options = dict; | |||||
2290 | out: | |||||
2291 | if (ret && dict) | |||||
2292 | dict_destroy (dict); | |||||
2293 | if (ret) | |||||
2294 | gf_log ("cli", GF_LOG_ERROR, "Error parsing dumpoptions")do { do { if (0) printf ("Error parsing dumpoptions"); } while (0); _gf_log ("cli", "cli-cmd-parser.c", __FUNCTION__, 2294, GF_LOG_ERROR, "Error parsing dumpoptions"); } while (0); | |||||
2295 | return ret; | |||||
2296 | } | |||||
2297 | ||||||
2298 | int | |||||
2299 | cli_cmd_volume_clrlks_opts_parse (const char **words, int wordcount, | |||||
2300 | dict_t **options) | |||||
2301 | { | |||||
2302 | int ret = -1; | |||||
2303 | int i = 0; | |||||
2304 | dict_t *dict = NULL((void*)0); | |||||
2305 | char *kind_opts[4] = {"blocked", "granted", "all", NULL((void*)0)}; | |||||
2306 | char *types[4] = {"inode", "entry", "posix", NULL((void*)0)}; | |||||
2307 | char *free_ptr = NULL((void*)0); | |||||
2308 | ||||||
2309 | dict = dict_new (); | |||||
2310 | if (!dict) | |||||
2311 | goto out; | |||||
2312 | ||||||
2313 | if (strcmp (words[4], "kind")) | |||||
2314 | goto out; | |||||
2315 | ||||||
2316 | for (i = 0; kind_opts[i]; i++) { | |||||
2317 | if (!strcmp (words[5], kind_opts[i])) { | |||||
2318 | free_ptr = gf_strdup (words[5]); | |||||
2319 | ret = dict_set_dynstr (dict, "kind", free_ptr); | |||||
2320 | if (ret) | |||||
2321 | goto out; | |||||
2322 | free_ptr = NULL((void*)0); | |||||
2323 | break; | |||||
2324 | } | |||||
2325 | } | |||||
2326 | if (i == 3) | |||||
2327 | goto out; | |||||
2328 | ||||||
2329 | ret = -1; | |||||
2330 | for (i = 0; types[i]; i++) { | |||||
2331 | if (!strcmp (words[6], types[i])) { | |||||
2332 | free_ptr = gf_strdup (words[6]); | |||||
2333 | ret = dict_set_dynstr (dict, "type", free_ptr); | |||||
2334 | if (ret) | |||||
2335 | goto out; | |||||
2336 | free_ptr = NULL((void*)0); | |||||
2337 | break; | |||||
2338 | } | |||||
2339 | } | |||||
2340 | if (i == 3) | |||||
2341 | goto out; | |||||
2342 | ||||||
2343 | if (wordcount == 8) { | |||||
2344 | free_ptr = gf_strdup (words[7]); | |||||
2345 | ret = dict_set_dynstr (dict, "opts", free_ptr); | |||||
2346 | if (ret) | |||||
2347 | goto out; | |||||
2348 | free_ptr = NULL((void*)0); | |||||
2349 | } | |||||
2350 | ||||||
2351 | ret = 0; | |||||
2352 | *options = dict; | |||||
2353 | out: | |||||
2354 | if (ret) { | |||||
2355 | GF_FREE (free_ptr)__gf_free (free_ptr); | |||||
2356 | dict_unref (dict); | |||||
2357 | } | |||||
2358 | ||||||
2359 | return ret; | |||||
2360 | } | |||||
2361 | ||||||
2362 | int | |||||
2363 | cli_cmd_volume_heal_options_parse (const char **words, int wordcount, | |||||
2364 | dict_t **options) | |||||
2365 | { | |||||
2366 | int ret = 0; | |||||
2367 | dict_t *dict = NULL((void*)0); | |||||
2368 | ||||||
2369 | dict = dict_new (); | |||||
2370 | if (!dict) | |||||
2371 | goto out; | |||||
2372 | ||||||
2373 | ret = dict_set_str (dict, "volname", (char *) words[2]); | |||||
2374 | if (ret) { | |||||
2375 | gf_log (THIS->name, GF_LOG_ERROR, "failed to set volname")do { do { if (0) printf ("failed to set volname"); } while (0 ); _gf_log ((*__glusterfs_this_location())->name, "cli-cmd-parser.c" , __FUNCTION__, 2375, GF_LOG_ERROR, "failed to set volname"); } while (0); | |||||
2376 | goto out; | |||||
2377 | } | |||||
2378 | ||||||
2379 | if (wordcount == 3) { | |||||
2380 | ret = dict_set_int32 (dict, "heal-op", GF_AFR_OP_HEAL_INDEX); | |||||
2381 | goto done; | |||||
2382 | } | |||||
2383 | ||||||
2384 | if (wordcount == 4) { | |||||
2385 | if (!strcmp (words[3], "full")) { | |||||
2386 | ret = dict_set_int32 (dict, "heal-op", | |||||
2387 | GF_AFR_OP_HEAL_FULL); | |||||
2388 | goto done; | |||||
2389 | } else if (!strcmp (words[3], "info")) { | |||||
2390 | ret = dict_set_int32 (dict, "heal-op", | |||||
2391 | GF_AFR_OP_INDEX_SUMMARY); | |||||
2392 | goto done; | |||||
2393 | } else { | |||||
2394 | ret = -1; | |||||
2395 | goto out; | |||||
2396 | } | |||||
2397 | } | |||||
2398 | if (wordcount == 5) { | |||||
2399 | if (strcmp (words[3], "info")) { | |||||
2400 | ret = -1; | |||||
2401 | goto out; | |||||
2402 | } | |||||
2403 | if (!strcmp (words[4], "healed")) { | |||||
2404 | ret = dict_set_int32 (dict, "heal-op", | |||||
2405 | GF_AFR_OP_HEALED_FILES); | |||||
2406 | goto done; | |||||
2407 | } | |||||
2408 | if (!strcmp (words[4], "heal-failed")) { | |||||
2409 | ret = dict_set_int32 (dict, "heal-op", | |||||
2410 | GF_AFR_OP_HEAL_FAILED_FILES); | |||||
2411 | goto done; | |||||
2412 | } | |||||
2413 | if (!strcmp (words[4], "split-brain")) { | |||||
2414 | ret = dict_set_int32 (dict, "heal-op", | |||||
2415 | GF_AFR_OP_SPLIT_BRAIN_FILES); | |||||
2416 | goto done; | |||||
2417 | } | |||||
2418 | ret = -1; | |||||
2419 | goto out; | |||||
2420 | } | |||||
2421 | ret = -1; | |||||
2422 | goto out; | |||||
2423 | done: | |||||
2424 | *options = dict; | |||||
2425 | out: | |||||
2426 | if (ret && dict) { | |||||
2427 | dict_unref (dict); | |||||
2428 | *options = NULL((void*)0); | |||||
2429 | } | |||||
2430 | ||||||
2431 | return ret; | |||||
2432 | } | |||||
2433 | ||||||
2434 | int | |||||
2435 | cli_cmd_volume_defrag_parse (const char **words, int wordcount, | |||||
2436 | dict_t **options) | |||||
2437 | { | |||||
2438 | dict_t *dict = NULL((void*)0); | |||||
2439 | int ret = -1; | |||||
2440 | char *option = NULL((void*)0); | |||||
2441 | char *volname = NULL((void*)0); | |||||
2442 | char *command = NULL((void*)0); | |||||
2443 | gf_cli_defrag_type cmd = 0; | |||||
2444 | ||||||
2445 | GF_ASSERT (words)do { if (!(words)) { do { do { if (0) printf ("Assertion failed: " "words"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 2445, GF_LOG_ERROR, "Assertion failed: " "words" ); } while (0); } } while (0); | |||||
2446 | GF_ASSERT (options)do { if (!(options)) { do { do { if (0) printf ("Assertion failed: " "options"); } while (0); _gf_log_callingfn ("", "cli-cmd-parser.c" , __FUNCTION__, 2446, GF_LOG_ERROR, "Assertion failed: " "options" ); } while (0); } } while (0); | |||||
2447 | ||||||
2448 | dict = dict_new (); | |||||
2449 | if (!dict) | |||||
2450 | goto out; | |||||
2451 | ||||||
2452 | if (!((wordcount == 4) || (wordcount == 5))) | |||||
2453 | goto out; | |||||
2454 | ||||||
2455 | if (wordcount == 4) { | |||||
2456 | if (strcmp (words[3], "start") && strcmp (words[3], "stop") && | |||||
2457 | strcmp (words[3], "status")) | |||||
2458 | goto out; | |||||
2459 | } else { | |||||
2460 | if (strcmp (words[3], "fix-layout") && | |||||
2461 | strcmp (words[3], "start")) | |||||
2462 | goto out; | |||||
2463 | } | |||||
2464 | ||||||
2465 | volname = (char *) words[2]; | |||||
2466 | ||||||
2467 | if (wordcount == 4) { | |||||
2468 | command = (char *) words[3]; | |||||
2469 | } | |||||
2470 | if (wordcount == 5) { | |||||
2471 | if ((strcmp (words[3], "fix-layout") || | |||||
2472 | strcmp (words[4], "start")) && | |||||
2473 | (strcmp (words[3], "start") || | |||||
2474 | strcmp (words[4], "force"))) { | |||||
2475 | ret = -1; | |||||
2476 | goto out; | |||||
2477 | } | |||||
2478 | command = (char *) words[3]; | |||||
2479 | option = (char *) words[4]; | |||||
2480 | } | |||||
2481 | ||||||
2482 | if (strcmp (command, "start") == 0) { | |||||
2483 | cmd = GF_DEFRAG_CMD_START; | |||||
2484 | if (option && strcmp (option, "force") == 0) { | |||||
2485 | cmd = GF_DEFRAG_CMD_START_FORCE; | |||||
2486 | } | |||||
2487 | goto done; | |||||
2488 | } | |||||
2489 | ||||||
2490 | if (strcmp (command, "fix-layout") == 0) { | |||||
2491 | cmd = GF_DEFRAG_CMD_START_LAYOUT_FIX; | |||||
2492 | goto done; | |||||
2493 | } | |||||
2494 | if (strcmp (command, "stop") == 0) { | |||||
2495 | cmd = GF_DEFRAG_CMD_STOP; | |||||
2496 | goto done; | |||||
2497 | } | |||||
2498 | if (strcmp (command, "status") == 0) { | |||||
2499 | cmd = GF_DEFRAG_CMD_STATUS; | |||||
2500 | } | |||||
2501 | ||||||
2502 | done: | |||||
2503 | ret = dict_set_str (dict, "volname", volname); | |||||
2504 | ||||||
2505 | if (ret) { | |||||
2506 | gf_log (THIS->name, GF_LOG_ERROR, "failed to set dict")do { do { if (0) printf ("failed to set dict"); } while (0); _gf_log ((*__glusterfs_this_location())->name, "cli-cmd-parser.c" , __FUNCTION__, 2506, GF_LOG_ERROR, "failed to set dict"); } while (0); | |||||
2507 | goto out; | |||||
2508 | } | |||||
2509 | ||||||
2510 | ret = dict_set_int32 (dict, "rebalance-command", (int32_t) cmd); | |||||
2511 | ||||||
2512 | if (ret) { | |||||
2513 | gf_log (THIS->name, GF_LOG_ERROR, "failed to set dict")do { do { if (0) printf ("failed to set dict"); } while (0); _gf_log ((*__glusterfs_this_location())->name, "cli-cmd-parser.c" , __FUNCTION__, 2513, GF_LOG_ERROR, "failed to set dict"); } while (0); | |||||
2514 | goto out; | |||||
2515 | } | |||||
2516 | ||||||
2517 | *options = dict; | |||||
2518 | ||||||
2519 | out: | |||||
2520 | if (ret && dict) | |||||
2521 | dict_destroy (dict); | |||||
2522 | ||||||
2523 | return ret; | |||||
2524 | } |