File: | xlators/mgmt/glusterd/src/glusterd-volume-ops.c |
Location: | line 1002, column 17 |
Description: | Access to field 'name' results in a dereference of a null pointer (loaded from variable 'this') |
1 | /* | |||||
2 | Copyright (c) 2011-2012 Red Hat, Inc. <http://www.redhat.com> | |||||
3 | This file is part of GlusterFS. | |||||
4 | ||||||
5 | This file is licensed to you under your choice of the GNU Lesser | |||||
6 | General Public License, version 3 or any later version (LGPLv3 or | |||||
7 | later), or the GNU General Public License, version 2 (GPLv2), in all | |||||
8 | cases as published by the Free Software Foundation. | |||||
9 | */ | |||||
10 | #ifndef _CONFIG_H | |||||
11 | #define _CONFIG_H | |||||
12 | #include "config.h" | |||||
13 | #endif | |||||
14 | ||||||
15 | #ifdef HAVE_BD_XLATOR | |||||
16 | #include <lvm2app.h> | |||||
17 | #endif | |||||
18 | ||||||
19 | #include "common-utils.h" | |||||
20 | #include "syscall.h" | |||||
21 | #include "cli1-xdr.h" | |||||
22 | #include "xdr-generic.h" | |||||
23 | #include "glusterd.h" | |||||
24 | #include "glusterd-op-sm.h" | |||||
25 | #include "glusterd-store.h" | |||||
26 | #include "glusterd-utils.h" | |||||
27 | #include "glusterd-volgen.h" | |||||
28 | #include "run.h" | |||||
29 | ||||||
30 | #define glusterd_op_start_volume_args_get(dict, volname, flags)glusterd_op_stop_volume_args_get (dict, volname, flags) \ | |||||
31 | glusterd_op_stop_volume_args_get (dict, volname, flags) | |||||
32 | ||||||
33 | int | |||||
34 | __glusterd_handle_create_volume (rpcsvc_request_t *req) | |||||
35 | { | |||||
36 | int32_t ret = -1; | |||||
37 | gf_cli_req cli_req = {{0,}}; | |||||
38 | dict_t *dict = NULL((void*)0); | |||||
39 | char *bricks = NULL((void*)0); | |||||
40 | char *volname = NULL((void*)0); | |||||
41 | int brick_count = 0; | |||||
42 | void *cli_rsp = NULL((void*)0); | |||||
43 | char err_str[2048] = {0,}; | |||||
44 | gf_cli_rsp rsp = {0,}; | |||||
45 | xlator_t *this = NULL((void*)0); | |||||
46 | char *free_ptr = NULL((void*)0); | |||||
47 | char *trans_type = NULL((void*)0); | |||||
48 | uuid_t volume_id = {0,}; | |||||
49 | uuid_t tmp_uuid = {0}; | |||||
50 | int32_t type = 0; | |||||
51 | char *username = NULL((void*)0); | |||||
52 | char *password = NULL((void*)0); | |||||
53 | ||||||
54 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-volume-ops.c" , __FUNCTION__, 54, GF_LOG_ERROR, "Assertion failed: " "req") ; } while (0); } } while (0); | |||||
55 | ||||||
56 | this = THIS(*__glusterfs_this_location()); | |||||
57 | GF_ASSERT(this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-volume-ops.c" , __FUNCTION__, 57, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
58 | ||||||
59 | ret = -1; | |||||
60 | ret = xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req); | |||||
61 | if (ret < 0) { | |||||
62 | req->rpc_err = GARBAGE_ARGS; | |||||
63 | snprintf (err_str, sizeof (err_str), "Failed to decode request " | |||||
64 | "received from cli"); | |||||
65 | gf_log (this->name, GF_LOG_ERROR, "%s", err_str)do { do { if (0) printf ("%s", err_str); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__, 65, GF_LOG_ERROR , "%s", err_str); } while (0); | |||||
66 | goto out; | |||||
67 | } | |||||
68 | ||||||
69 | gf_log (this->name, GF_LOG_DEBUG, "Received create volume req")do { do { if (0) printf ("Received create volume req"); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__ , 69, GF_LOG_DEBUG, "Received create volume req"); } while (0 ); | |||||
70 | ||||||
71 | if (cli_req.dict.dict_len) { | |||||
72 | /* Unserialize the dictionary */ | |||||
73 | dict = dict_new (); | |||||
74 | ||||||
75 | ret = dict_unserialize (cli_req.dict.dict_val, | |||||
76 | cli_req.dict.dict_len, | |||||
77 | &dict); | |||||
78 | if (ret < 0) { | |||||
79 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 81, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0) | |||||
80 | "failed to "do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 81, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0) | |||||
81 | "unserialize req-buffer to dictionary")do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 81, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0); | |||||
82 | snprintf (err_str, sizeof (err_str), "Unable to decode " | |||||
83 | "the command"); | |||||
84 | goto out; | |||||
85 | } else { | |||||
86 | dict->extra_stdfree = cli_req.dict.dict_val; | |||||
87 | } | |||||
88 | } | |||||
89 | ||||||
90 | ret = dict_get_str (dict, "volname", &volname); | |||||
91 | ||||||
92 | if (ret) { | |||||
93 | snprintf (err_str, sizeof (err_str), "Unable to get volume " | |||||
94 | "name"); | |||||
95 | gf_log (this->name, GF_LOG_ERROR, "%s", err_str)do { do { if (0) printf ("%s", err_str); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__, 95, GF_LOG_ERROR , "%s", err_str); } while (0); | |||||
96 | goto out; | |||||
97 | } | |||||
98 | ||||||
99 | if ((ret = glusterd_check_volume_exists (volname))) { | |||||
100 | snprintf (err_str, sizeof (err_str), "Volume %s already exists", | |||||
101 | volname); | |||||
102 | gf_log (this->name, GF_LOG_ERROR, "%s", err_str)do { do { if (0) printf ("%s", err_str); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__, 102, GF_LOG_ERROR , "%s", err_str); } while (0); | |||||
103 | goto out; | |||||
104 | } | |||||
105 | ||||||
106 | ret = dict_get_int32 (dict, "count", &brick_count); | |||||
107 | if (ret) { | |||||
108 | snprintf (err_str, sizeof (err_str), "Unable to get brick count" | |||||
109 | " for volume %s", volname); | |||||
110 | gf_log (this->name, GF_LOG_ERROR, "%s", err_str)do { do { if (0) printf ("%s", err_str); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__, 110, GF_LOG_ERROR , "%s", err_str); } while (0); | |||||
111 | goto out; | |||||
112 | } | |||||
113 | ||||||
114 | ret = dict_get_int32 (dict, "type", &type); | |||||
115 | if (ret) { | |||||
116 | snprintf (err_str, sizeof (err_str), "Unable to get type of " | |||||
117 | "volume %s", volname); | |||||
118 | gf_log (this->name, GF_LOG_ERROR, "%s", err_str)do { do { if (0) printf ("%s", err_str); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__, 118, GF_LOG_ERROR , "%s", err_str); } while (0); | |||||
119 | goto out; | |||||
120 | } | |||||
121 | ||||||
122 | ret = dict_get_str (dict, "transport", &trans_type); | |||||
123 | if (ret) { | |||||
124 | snprintf (err_str, sizeof (err_str), "Unable to get " | |||||
125 | "transport-type of volume %s", volname); | |||||
126 | gf_log (this->name, GF_LOG_ERROR, "%s", err_str)do { do { if (0) printf ("%s", err_str); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__, 126, GF_LOG_ERROR , "%s", err_str); } while (0); | |||||
127 | goto out; | |||||
128 | } | |||||
129 | ret = dict_get_str (dict, "bricks", &bricks); | |||||
130 | if (ret) { | |||||
131 | snprintf (err_str, sizeof (err_str), "Unable to get bricks for " | |||||
132 | "volume %s", volname); | |||||
133 | gf_log (this->name, GF_LOG_ERROR, "%s", err_str)do { do { if (0) printf ("%s", err_str); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__, 133, GF_LOG_ERROR , "%s", err_str); } while (0); | |||||
134 | goto out; | |||||
135 | } | |||||
136 | ||||||
137 | if (!dict_get (dict, "force")) { | |||||
138 | gf_log (this->name, GF_LOG_ERROR, "Failed to get 'force' flag")do { do { if (0) printf ("Failed to get 'force' flag"); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__ , 138, GF_LOG_ERROR, "Failed to get 'force' flag"); } while ( 0); | |||||
139 | goto out; | |||||
140 | } | |||||
141 | ||||||
142 | uuid_generate (volume_id); | |||||
143 | free_ptr = gf_strdup (uuid_utoa (volume_id)); | |||||
144 | ret = dict_set_dynstr (dict, "volume-id", free_ptr); | |||||
145 | if (ret) { | |||||
146 | snprintf (err_str, sizeof (err_str), "Unable to set volume " | |||||
147 | "id of volume %s", volname); | |||||
148 | gf_log (this->name, GF_LOG_ERROR, "%s", err_str)do { do { if (0) printf ("%s", err_str); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__, 148, GF_LOG_ERROR , "%s", err_str); } while (0); | |||||
149 | goto out; | |||||
150 | } | |||||
151 | free_ptr = NULL((void*)0); | |||||
152 | ||||||
153 | /* generate internal username and password */ | |||||
154 | ||||||
155 | uuid_generate (tmp_uuid); | |||||
156 | username = gf_strdup (uuid_utoa (tmp_uuid)); | |||||
157 | ret = dict_set_dynstr (dict, "internal-username", username); | |||||
158 | if (ret) { | |||||
159 | gf_log (this->name, GF_LOG_ERROR, "Failed to set username for "do { do { if (0) printf ("Failed to set username for " "volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 160, GF_LOG_ERROR, "Failed to set username for " "volume %s", volname); } while (0) | |||||
160 | "volume %s", volname)do { do { if (0) printf ("Failed to set username for " "volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 160, GF_LOG_ERROR, "Failed to set username for " "volume %s", volname); } while (0); | |||||
161 | goto out; | |||||
162 | } | |||||
163 | ||||||
164 | uuid_generate (tmp_uuid); | |||||
165 | password = gf_strdup (uuid_utoa (tmp_uuid)); | |||||
166 | ret = dict_set_dynstr (dict, "internal-password", password); | |||||
167 | if (ret) { | |||||
168 | gf_log (this->name, GF_LOG_ERROR, "Failed to set password for "do { do { if (0) printf ("Failed to set password for " "volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 169, GF_LOG_ERROR, "Failed to set password for " "volume %s", volname); } while (0) | |||||
169 | "volume %s", volname)do { do { if (0) printf ("Failed to set password for " "volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 169, GF_LOG_ERROR, "Failed to set password for " "volume %s", volname); } while (0); | |||||
170 | goto out; | |||||
171 | } | |||||
172 | ||||||
173 | ret = glusterd_op_begin_synctask (req, GD_OP_CREATE_VOLUME, dict); | |||||
174 | ||||||
175 | out: | |||||
176 | if (ret) { | |||||
177 | rsp.op_ret = -1; | |||||
178 | rsp.op_errno = 0; | |||||
179 | if (err_str[0] == '\0') | |||||
180 | snprintf (err_str, sizeof (err_str), | |||||
181 | "Operation failed"); | |||||
182 | rsp.op_errstr = err_str; | |||||
183 | cli_rsp = &rsp; | |||||
184 | glusterd_to_cli (req, cli_rsp, NULL((void*)0), 0, NULL((void*)0), | |||||
185 | (xdrproc_t)xdr_gf_cli_rsp, dict); | |||||
186 | ret = 0; //Client response sent, prevent second response | |||||
187 | } | |||||
188 | ||||||
189 | GF_FREE(free_ptr)__gf_free (free_ptr); | |||||
190 | ||||||
191 | return ret; | |||||
192 | } | |||||
193 | ||||||
194 | int | |||||
195 | glusterd_handle_create_volume (rpcsvc_request_t *req) | |||||
196 | { | |||||
197 | return glusterd_big_locked_handler (req, | |||||
198 | __glusterd_handle_create_volume); | |||||
199 | } | |||||
200 | ||||||
201 | int | |||||
202 | __glusterd_handle_cli_start_volume (rpcsvc_request_t *req) | |||||
203 | { | |||||
204 | int32_t ret = -1; | |||||
205 | gf_cli_req cli_req = {{0,}}; | |||||
206 | char *volname = NULL((void*)0); | |||||
207 | dict_t *dict = NULL((void*)0); | |||||
208 | glusterd_op_t cli_op = GD_OP_START_VOLUME; | |||||
209 | char errstr[2048] = {0,}; | |||||
210 | xlator_t *this = NULL((void*)0); | |||||
211 | ||||||
212 | this = THIS(*__glusterfs_this_location()); | |||||
213 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-volume-ops.c" , __FUNCTION__, 213, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
214 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-volume-ops.c" , __FUNCTION__, 214, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
215 | ||||||
216 | ret = xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req); | |||||
217 | if (ret < 0) { | |||||
218 | snprintf (errstr, sizeof (errstr), "Failed to decode message " | |||||
219 | "received from cli"); | |||||
220 | req->rpc_err = GARBAGE_ARGS; | |||||
221 | gf_log (this->name, sizeof (errstr), "%s", errstr)do { do { if (0) printf ("%s", errstr); } while (0); _gf_log ( this->name, "glusterd-volume-ops.c", __FUNCTION__, 221, sizeof (errstr), "%s", errstr); } while (0); | |||||
222 | goto out; | |||||
223 | } | |||||
224 | ||||||
225 | if (cli_req.dict.dict_len) { | |||||
226 | /* Unserialize the dictionary */ | |||||
227 | dict = dict_new (); | |||||
228 | ||||||
229 | ret = dict_unserialize (cli_req.dict.dict_val, | |||||
230 | cli_req.dict.dict_len, | |||||
231 | &dict); | |||||
232 | if (ret < 0) { | |||||
233 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 235, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0) | |||||
234 | "failed to "do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 235, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0) | |||||
235 | "unserialize req-buffer to dictionary")do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 235, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0); | |||||
236 | snprintf (errstr, sizeof (errstr), "Unable to decode " | |||||
237 | "the command"); | |||||
238 | goto out; | |||||
239 | } | |||||
240 | } | |||||
241 | ||||||
242 | ret = dict_get_str (dict, "volname", &volname); | |||||
243 | if (ret) { | |||||
244 | snprintf (errstr, sizeof (errstr), "Unable to get volume name"); | |||||
245 | gf_log (this->name, GF_LOG_ERROR, "%s", errstr)do { do { if (0) printf ("%s", errstr); } while (0); _gf_log ( this->name, "glusterd-volume-ops.c", __FUNCTION__, 245, GF_LOG_ERROR , "%s", errstr); } while (0); | |||||
246 | goto out; | |||||
247 | } | |||||
248 | ||||||
249 | gf_log (this->name, GF_LOG_DEBUG, "Received start vol req"do { do { if (0) printf ("Received start vol req" " for volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 250, GF_LOG_DEBUG, "Received start vol req" " for volume %s" , volname); } while (0) | |||||
250 | " for volume %s", volname)do { do { if (0) printf ("Received start vol req" " for volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 250, GF_LOG_DEBUG, "Received start vol req" " for volume %s" , volname); } while (0); | |||||
251 | ||||||
252 | ret = glusterd_op_begin_synctask (req, GD_OP_START_VOLUME, dict); | |||||
253 | ||||||
254 | out: | |||||
255 | free (cli_req.dict.dict_val); //its malloced by xdr | |||||
256 | ||||||
257 | if (ret) { | |||||
258 | if(errstr[0] == '\0') | |||||
259 | snprintf (errstr, sizeof (errstr), "Operation failed"); | |||||
260 | ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, | |||||
261 | dict, errstr); | |||||
262 | } | |||||
263 | ||||||
264 | return ret; | |||||
265 | } | |||||
266 | ||||||
267 | int | |||||
268 | glusterd_handle_cli_start_volume (rpcsvc_request_t *req) | |||||
269 | { | |||||
270 | return glusterd_big_locked_handler (req, | |||||
271 | __glusterd_handle_cli_start_volume); | |||||
272 | } | |||||
273 | ||||||
274 | int | |||||
275 | __glusterd_handle_cli_stop_volume (rpcsvc_request_t *req) | |||||
276 | { | |||||
277 | int32_t ret = -1; | |||||
278 | gf_cli_req cli_req = {{0,}}; | |||||
279 | char *dup_volname = NULL((void*)0); | |||||
280 | dict_t *dict = NULL((void*)0); | |||||
281 | glusterd_op_t cli_op = GD_OP_STOP_VOLUME; | |||||
282 | xlator_t *this = NULL((void*)0); | |||||
283 | char err_str[2048] = {0,}; | |||||
284 | ||||||
285 | this = THIS(*__glusterfs_this_location()); | |||||
286 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-volume-ops.c" , __FUNCTION__, 286, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
287 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-volume-ops.c" , __FUNCTION__, 287, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
288 | ||||||
289 | ret = xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req); | |||||
290 | if (ret < 0) { | |||||
291 | snprintf (err_str, sizeof (err_str), "Failed to decode message " | |||||
292 | "received from cli"); | |||||
293 | req->rpc_err = GARBAGE_ARGS; | |||||
294 | gf_log (this->name, GF_LOG_ERROR, "%s", err_str)do { do { if (0) printf ("%s", err_str); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__, 294, GF_LOG_ERROR , "%s", err_str); } while (0); | |||||
295 | goto out; | |||||
296 | } | |||||
297 | if (cli_req.dict.dict_len) { | |||||
298 | /* Unserialize the dictionary */ | |||||
299 | dict = dict_new (); | |||||
300 | ||||||
301 | ret = dict_unserialize (cli_req.dict.dict_val, | |||||
302 | cli_req.dict.dict_len, | |||||
303 | &dict); | |||||
304 | if (ret < 0) { | |||||
305 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 307, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0) | |||||
306 | "failed to "do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 307, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0) | |||||
307 | "unserialize req-buffer to dictionary")do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 307, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0); | |||||
308 | snprintf (err_str, sizeof (err_str), "Unable to decode " | |||||
309 | "the command"); | |||||
310 | goto out; | |||||
311 | } | |||||
312 | } | |||||
313 | ||||||
314 | ret = dict_get_str (dict, "volname", &dup_volname); | |||||
315 | ||||||
316 | if (ret) { | |||||
317 | snprintf (err_str, sizeof (err_str), "Failed to get volume " | |||||
318 | "name"); | |||||
319 | gf_log (this->name, GF_LOG_ERROR, "%s", err_str)do { do { if (0) printf ("%s", err_str); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__, 319, GF_LOG_ERROR , "%s", err_str); } while (0); | |||||
320 | goto out; | |||||
321 | } | |||||
322 | ||||||
323 | gf_log (this->name, GF_LOG_DEBUG, "Received stop vol req "do { do { if (0) printf ("Received stop vol req " "for volume %s" , dup_volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 324, GF_LOG_DEBUG, "Received stop vol req " "for volume %s" , dup_volname); } while (0) | |||||
324 | "for volume %s", dup_volname)do { do { if (0) printf ("Received stop vol req " "for volume %s" , dup_volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 324, GF_LOG_DEBUG, "Received stop vol req " "for volume %s" , dup_volname); } while (0); | |||||
325 | ||||||
326 | ret = glusterd_op_begin_synctask (req, GD_OP_STOP_VOLUME, dict); | |||||
327 | ||||||
328 | out: | |||||
329 | free (cli_req.dict.dict_val); //its malloced by xdr | |||||
330 | ||||||
331 | if (ret) { | |||||
332 | if (err_str[0] == '\0') | |||||
333 | snprintf (err_str, sizeof (err_str), | |||||
334 | "Operation failed"); | |||||
335 | ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, | |||||
336 | dict, err_str); | |||||
337 | } | |||||
338 | ||||||
339 | return ret; | |||||
340 | } | |||||
341 | ||||||
342 | int | |||||
343 | glusterd_handle_cli_stop_volume (rpcsvc_request_t *req) | |||||
344 | { | |||||
345 | return glusterd_big_locked_handler (req, | |||||
346 | __glusterd_handle_cli_stop_volume); | |||||
347 | } | |||||
348 | ||||||
349 | int | |||||
350 | __glusterd_handle_cli_delete_volume (rpcsvc_request_t *req) | |||||
351 | { | |||||
352 | int32_t ret = -1; | |||||
353 | gf_cli_req cli_req = {{0,},}; | |||||
354 | glusterd_op_t cli_op = GD_OP_DELETE_VOLUME; | |||||
355 | dict_t *dict = NULL((void*)0); | |||||
356 | char *volname = NULL((void*)0); | |||||
357 | char err_str[2048]= {0,}; | |||||
358 | xlator_t *this = NULL((void*)0); | |||||
359 | ||||||
360 | this = THIS(*__glusterfs_this_location()); | |||||
361 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-volume-ops.c" , __FUNCTION__, 361, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
362 | ||||||
363 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-volume-ops.c" , __FUNCTION__, 363, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
364 | ||||||
365 | ret = xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req); | |||||
366 | if (ret < 0) { | |||||
367 | snprintf (err_str, sizeof (err_str), "Failed to decode request " | |||||
368 | "received from cli"); | |||||
369 | gf_log (this->name, GF_LOG_ERROR, "%s", err_str)do { do { if (0) printf ("%s", err_str); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__, 369, GF_LOG_ERROR , "%s", err_str); } while (0); | |||||
370 | req->rpc_err = GARBAGE_ARGS; | |||||
371 | goto out; | |||||
372 | } | |||||
373 | ||||||
374 | if (cli_req.dict.dict_len) { | |||||
375 | /* Unserialize the dictionary */ | |||||
376 | dict = dict_new (); | |||||
377 | ||||||
378 | ret = dict_unserialize (cli_req.dict.dict_val, | |||||
379 | cli_req.dict.dict_len, | |||||
380 | &dict); | |||||
381 | if (ret < 0) { | |||||
382 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 384, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0) | |||||
383 | "failed to "do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 384, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0) | |||||
384 | "unserialize req-buffer to dictionary")do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 384, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0); | |||||
385 | snprintf (err_str, sizeof (err_str), "Unable to decode " | |||||
386 | "the command"); | |||||
387 | goto out; | |||||
388 | } | |||||
389 | } | |||||
390 | ||||||
391 | ret = dict_get_str (dict, "volname", &volname); | |||||
392 | if (ret) { | |||||
393 | snprintf (err_str, sizeof (err_str), "Failed to get volume " | |||||
394 | "name"); | |||||
395 | gf_log (this->name, GF_LOG_ERROR, "%s", err_str)do { do { if (0) printf ("%s", err_str); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__, 395, GF_LOG_ERROR , "%s", err_str); } while (0); | |||||
396 | req->rpc_err = GARBAGE_ARGS; | |||||
397 | goto out; | |||||
398 | } | |||||
399 | ||||||
400 | gf_log (this->name, GF_LOG_DEBUG, "Received delete vol req"do { do { if (0) printf ("Received delete vol req" "for volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 401, GF_LOG_DEBUG, "Received delete vol req" "for volume %s" , volname); } while (0) | |||||
401 | "for volume %s", volname)do { do { if (0) printf ("Received delete vol req" "for volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 401, GF_LOG_DEBUG, "Received delete vol req" "for volume %s" , volname); } while (0); | |||||
402 | ||||||
403 | ret = glusterd_op_begin_synctask (req, GD_OP_DELETE_VOLUME, dict); | |||||
404 | ||||||
405 | out: | |||||
406 | free (cli_req.dict.dict_val); //its malloced by xdr | |||||
407 | ||||||
408 | if (ret) { | |||||
409 | if (err_str[0] == '\0') | |||||
410 | snprintf (err_str, sizeof (err_str), | |||||
411 | "Operation failed"); | |||||
412 | ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, | |||||
413 | dict, err_str); | |||||
414 | } | |||||
415 | ||||||
416 | return ret; | |||||
417 | } | |||||
418 | ||||||
419 | int | |||||
420 | glusterd_handle_cli_delete_volume (rpcsvc_request_t *req) | |||||
421 | { | |||||
422 | return glusterd_big_locked_handler (req, | |||||
423 | __glusterd_handle_cli_delete_volume); | |||||
424 | } | |||||
425 | ||||||
426 | int | |||||
427 | __glusterd_handle_cli_heal_volume (rpcsvc_request_t *req) | |||||
428 | { | |||||
429 | int32_t ret = -1; | |||||
430 | gf_cli_req cli_req = {{0,}}; | |||||
431 | dict_t *dict = NULL((void*)0); | |||||
432 | glusterd_op_t cli_op = GD_OP_HEAL_VOLUME; | |||||
433 | char *volname = NULL((void*)0); | |||||
434 | glusterd_volinfo_t *volinfo = NULL((void*)0); | |||||
435 | xlator_t *this = NULL((void*)0); | |||||
436 | char op_errstr[2048] = {0,}; | |||||
437 | ||||||
438 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-volume-ops.c" , __FUNCTION__, 438, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
439 | ||||||
440 | ret = xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req); | |||||
441 | if (ret < 0) { | |||||
442 | //failed to decode msg; | |||||
443 | req->rpc_err = GARBAGE_ARGS; | |||||
444 | goto out; | |||||
445 | } | |||||
446 | ||||||
447 | this = THIS(*__glusterfs_this_location()); | |||||
448 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-volume-ops.c" , __FUNCTION__, 448, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
449 | ||||||
450 | if (cli_req.dict.dict_len) { | |||||
451 | /* Unserialize the dictionary */ | |||||
452 | dict = dict_new (); | |||||
453 | ||||||
454 | ret = dict_unserialize (cli_req.dict.dict_val, | |||||
455 | cli_req.dict.dict_len, | |||||
456 | &dict); | |||||
457 | if (ret < 0) { | |||||
458 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 460, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0) | |||||
459 | "failed to "do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 460, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0) | |||||
460 | "unserialize req-buffer to dictionary")do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 460, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0); | |||||
461 | snprintf (op_errstr, sizeof (op_errstr), | |||||
462 | "Unable to decode the command"); | |||||
463 | goto out; | |||||
464 | } else { | |||||
465 | dict->extra_stdfree = cli_req.dict.dict_val; | |||||
466 | } | |||||
467 | } | |||||
468 | ||||||
469 | ret = dict_get_str (dict, "volname", &volname); | |||||
470 | if (ret) { | |||||
471 | snprintf (op_errstr, sizeof (op_errstr), "Unable to find " | |||||
472 | "volume name"); | |||||
473 | gf_log (this->name, GF_LOG_ERROR, "%s", op_errstr)do { do { if (0) printf ("%s", op_errstr); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__, 473, GF_LOG_ERROR , "%s", op_errstr); } while (0); | |||||
474 | goto out; | |||||
475 | } | |||||
476 | ||||||
477 | gf_log (this->name, GF_LOG_INFO, "Received heal vol req "do { do { if (0) printf ("Received heal vol req " "for volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 478, GF_LOG_INFO, "Received heal vol req " "for volume %s" , volname); } while (0) | |||||
478 | "for volume %s", volname)do { do { if (0) printf ("Received heal vol req " "for volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 478, GF_LOG_INFO, "Received heal vol req " "for volume %s" , volname); } while (0); | |||||
479 | ||||||
480 | ret = glusterd_volinfo_find (volname, &volinfo); | |||||
481 | if (ret) { | |||||
482 | snprintf (op_errstr, sizeof (op_errstr), | |||||
483 | "Volume %s does not exist", volname); | |||||
484 | gf_log (this->name, GF_LOG_ERROR, "%s", op_errstr)do { do { if (0) printf ("%s", op_errstr); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__, 484, GF_LOG_ERROR , "%s", op_errstr); } while (0); | |||||
485 | goto out; | |||||
486 | } | |||||
487 | ||||||
488 | ret = glusterd_add_bricks_hname_path_to_dict (dict, volinfo); | |||||
489 | if (ret) | |||||
490 | goto out; | |||||
491 | ||||||
492 | ret = dict_set_int32 (dict, "count", volinfo->brick_count); | |||||
493 | if (ret) | |||||
494 | goto out; | |||||
495 | ||||||
496 | ret = glusterd_op_begin_synctask (req, GD_OP_HEAL_VOLUME, dict); | |||||
497 | ||||||
498 | out: | |||||
499 | if (ret) { | |||||
500 | if (op_errstr[0] == '\0') | |||||
501 | snprintf (op_errstr, sizeof (op_errstr), | |||||
502 | "operation failed"); | |||||
503 | ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, | |||||
504 | dict, op_errstr); | |||||
505 | } | |||||
506 | ||||||
507 | return ret; | |||||
508 | } | |||||
509 | ||||||
510 | int | |||||
511 | glusterd_handle_cli_heal_volume (rpcsvc_request_t *req) | |||||
512 | { | |||||
513 | return glusterd_big_locked_handler (req, | |||||
514 | __glusterd_handle_cli_heal_volume); | |||||
515 | } | |||||
516 | ||||||
517 | int | |||||
518 | __glusterd_handle_cli_statedump_volume (rpcsvc_request_t *req) | |||||
519 | { | |||||
520 | int32_t ret = -1; | |||||
521 | gf_cli_req cli_req = {{0,}}; | |||||
522 | char *volname = NULL((void*)0); | |||||
523 | char *options = NULL((void*)0); | |||||
524 | dict_t *dict = NULL((void*)0); | |||||
525 | int32_t option_cnt = 0; | |||||
526 | glusterd_op_t cli_op = GD_OP_STATEDUMP_VOLUME; | |||||
527 | char err_str[2048] = {0,}; | |||||
528 | xlator_t *this = NULL((void*)0); | |||||
529 | ||||||
530 | this = THIS(*__glusterfs_this_location()); | |||||
531 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-volume-ops.c" , __FUNCTION__, 531, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
532 | ||||||
533 | GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: " "req"); } while (0); _gf_log_callingfn ("", "glusterd-volume-ops.c" , __FUNCTION__, 533, GF_LOG_ERROR, "Assertion failed: " "req" ); } while (0); } } while (0); | |||||
534 | ||||||
535 | ret = -1; | |||||
536 | ret = xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req); | |||||
537 | if (ret < 0) { | |||||
538 | req->rpc_err = GARBAGE_ARGS; | |||||
539 | goto out; | |||||
540 | } | |||||
541 | if (cli_req.dict.dict_len) { | |||||
542 | /* Unserialize the dictionary */ | |||||
543 | dict = dict_new (); | |||||
544 | ||||||
545 | ret = dict_unserialize (cli_req.dict.dict_val, | |||||
546 | cli_req.dict.dict_len, | |||||
547 | &dict); | |||||
548 | if (ret < 0) { | |||||
549 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 551, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0) | |||||
550 | "failed to "do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 551, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0) | |||||
551 | "unserialize req-buffer to dictionary")do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary" ); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 551, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary" ); } while (0); | |||||
552 | snprintf (err_str, sizeof (err_str), "Unable to " | |||||
553 | "decode the command"); | |||||
554 | goto out; | |||||
555 | } | |||||
556 | } | |||||
557 | ret = dict_get_str (dict, "volname", &volname); | |||||
558 | if (ret) { | |||||
559 | snprintf (err_str, sizeof (err_str), "Unable to get the volume " | |||||
560 | "name"); | |||||
561 | gf_log (this->name, GF_LOG_ERROR, "%s", err_str)do { do { if (0) printf ("%s", err_str); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__, 561, GF_LOG_ERROR , "%s", err_str); } while (0); | |||||
562 | goto out; | |||||
563 | } | |||||
564 | ||||||
565 | ret = dict_get_str (dict, "options", &options); | |||||
566 | if (ret) { | |||||
567 | snprintf (err_str, sizeof (err_str), "Unable to get options"); | |||||
568 | gf_log (this->name, GF_LOG_ERROR, "%s", err_str)do { do { if (0) printf ("%s", err_str); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__, 568, GF_LOG_ERROR , "%s", err_str); } while (0); | |||||
569 | goto out; | |||||
570 | } | |||||
571 | ||||||
572 | ret = dict_get_int32 (dict, "option_cnt", &option_cnt); | |||||
573 | if (ret) { | |||||
574 | snprintf (err_str , sizeof (err_str), "Unable to get option " | |||||
575 | "count"); | |||||
576 | gf_log (this->name, GF_LOG_ERROR, "%s", err_str)do { do { if (0) printf ("%s", err_str); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__, 576, GF_LOG_ERROR , "%s", err_str); } while (0); | |||||
577 | goto out; | |||||
578 | } | |||||
579 | ||||||
580 | ||||||
581 | gf_log (this->name, GF_LOG_INFO, "Received statedump request for "do { do { if (0) printf ("Received statedump request for " "volume %s with options %s" , volname, options); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 582, GF_LOG_INFO, "Received statedump request for " "volume %s with options %s", volname, options); } while (0) | |||||
582 | "volume %s with options %s", volname, options)do { do { if (0) printf ("Received statedump request for " "volume %s with options %s" , volname, options); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 582, GF_LOG_INFO, "Received statedump request for " "volume %s with options %s", volname, options); } while (0); | |||||
583 | ||||||
584 | ret = glusterd_op_begin_synctask (req, GD_OP_STATEDUMP_VOLUME, dict); | |||||
585 | ||||||
586 | out: | |||||
587 | if (ret) { | |||||
588 | if (err_str[0] == '\0') | |||||
589 | snprintf (err_str, sizeof (err_str), | |||||
590 | "Operation failed"); | |||||
591 | ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, | |||||
592 | dict, err_str); | |||||
593 | } | |||||
594 | free (cli_req.dict.dict_val); | |||||
595 | ||||||
596 | return ret; | |||||
597 | } | |||||
598 | ||||||
599 | int | |||||
600 | glusterd_handle_cli_statedump_volume (rpcsvc_request_t *req) | |||||
601 | { | |||||
602 | return glusterd_big_locked_handler (req, | |||||
603 | __glusterd_handle_cli_statedump_volume); | |||||
604 | } | |||||
605 | ||||||
606 | #ifdef HAVE_BD_XLATOR | |||||
607 | int | |||||
608 | glusterd_is_valid_vg (const char *name) | |||||
609 | { | |||||
610 | lvm_t handle = NULL((void*)0); | |||||
611 | vg_t vg = NULL((void*)0); | |||||
612 | char *vg_name = NULL((void*)0); | |||||
613 | int retval = -1; | |||||
614 | ||||||
615 | handle = lvm_init (NULL((void*)0)); | |||||
616 | if (!handle) { | |||||
617 | gf_log ("", GF_LOG_ERROR, "lvm_init failed")do { do { if (0) printf ("lvm_init failed"); } while (0); _gf_log ("", "glusterd-volume-ops.c", __FUNCTION__, 617, GF_LOG_ERROR , "lvm_init failed"); } while (0); | |||||
618 | return -1; | |||||
619 | } | |||||
620 | vg_name = gf_strdup (name); | |||||
621 | vg = lvm_vg_open (handle, basename__xpg_basename (vg_name), "r", 0); | |||||
622 | if (!vg) { | |||||
623 | gf_log ("", GF_LOG_ERROR, "no such vg: %s", vg_name)do { do { if (0) printf ("no such vg: %s", vg_name); } while ( 0); _gf_log ("", "glusterd-volume-ops.c", __FUNCTION__, 623, GF_LOG_ERROR , "no such vg: %s", vg_name); } while (0); | |||||
624 | goto out; | |||||
625 | } | |||||
626 | retval = 0; | |||||
627 | out: | |||||
628 | if (vg) | |||||
629 | lvm_vg_close (vg); | |||||
630 | lvm_quit (handle); | |||||
631 | GF_FREE (vg_name)__gf_free (vg_name); | |||||
632 | return retval; | |||||
633 | } | |||||
634 | #endif | |||||
635 | ||||||
636 | /* op-sm */ | |||||
637 | int | |||||
638 | glusterd_op_stage_create_volume (dict_t *dict, char **op_errstr) | |||||
639 | { | |||||
640 | int ret = 0; | |||||
641 | char *volname = NULL((void*)0); | |||||
642 | gf_boolean_t exists = _gf_false; | |||||
643 | char *bricks = NULL((void*)0); | |||||
644 | char *brick_list = NULL((void*)0); | |||||
645 | char *free_ptr = NULL((void*)0); | |||||
646 | glusterd_brickinfo_t *brick_info = NULL((void*)0); | |||||
647 | int32_t brick_count = 0; | |||||
648 | int32_t i = 0; | |||||
649 | char *brick = NULL((void*)0); | |||||
650 | char *tmpptr = NULL((void*)0); | |||||
651 | xlator_t *this = NULL((void*)0); | |||||
652 | glusterd_conf_t *priv = NULL((void*)0); | |||||
653 | char msg[2048] = {0}; | |||||
654 | uuid_t volume_uuid; | |||||
655 | char *volume_uuid_str; | |||||
656 | #ifdef HAVE_BD_XLATOR | |||||
657 | char *dev_type = NULL((void*)0); | |||||
658 | #endif | |||||
659 | gf_boolean_t is_force = _gf_false; | |||||
660 | ||||||
661 | this = THIS(*__glusterfs_this_location()); | |||||
662 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-volume-ops.c" , __FUNCTION__, 662, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
663 | priv = this->private; | |||||
664 | GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: " "priv"); } while (0); _gf_log_callingfn ("", "glusterd-volume-ops.c" , __FUNCTION__, 664, GF_LOG_ERROR, "Assertion failed: " "priv" ); } while (0); } } while (0); | |||||
665 | ||||||
666 | ret = dict_get_str (dict, "volname", &volname); | |||||
667 | if (ret) { | |||||
668 | gf_log (this->name, GF_LOG_ERROR, "Unable to get volume name")do { do { if (0) printf ("Unable to get volume name"); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__ , 668, GF_LOG_ERROR, "Unable to get volume name"); } while (0 ); | |||||
669 | goto out; | |||||
670 | } | |||||
671 | ||||||
672 | exists = glusterd_check_volume_exists (volname); | |||||
673 | if (exists) { | |||||
674 | snprintf (msg, sizeof (msg), "Volume %s already exists", | |||||
675 | volname); | |||||
676 | ret = -1; | |||||
677 | goto out; | |||||
678 | } else { | |||||
679 | ret = 0; | |||||
680 | } | |||||
681 | ||||||
682 | ret = dict_get_int32 (dict, "count", &brick_count); | |||||
683 | if (ret) { | |||||
684 | gf_log (this->name, GF_LOG_ERROR, "Unable to get brick count "do { do { if (0) printf ("Unable to get brick count " "for volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 685, GF_LOG_ERROR, "Unable to get brick count " "for volume %s", volname); } while (0) | |||||
685 | "for volume %s", volname)do { do { if (0) printf ("Unable to get brick count " "for volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 685, GF_LOG_ERROR, "Unable to get brick count " "for volume %s", volname); } while (0); | |||||
686 | goto out; | |||||
687 | } | |||||
688 | ||||||
689 | ret = dict_get_str (dict, "volume-id", &volume_uuid_str); | |||||
690 | if (ret) { | |||||
691 | gf_log (this->name, GF_LOG_ERROR, "Unable to get volume id of "do { do { if (0) printf ("Unable to get volume id of " "volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 692, GF_LOG_ERROR, "Unable to get volume id of " "volume %s", volname); } while (0) | |||||
692 | "volume %s", volname)do { do { if (0) printf ("Unable to get volume id of " "volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 692, GF_LOG_ERROR, "Unable to get volume id of " "volume %s", volname); } while (0); | |||||
693 | goto out; | |||||
694 | } | |||||
695 | ||||||
696 | ret = uuid_parse (volume_uuid_str, volume_uuid); | |||||
697 | if (ret) { | |||||
698 | gf_log (this->name, GF_LOG_ERROR, "Unable to parse volume id of"do { do { if (0) printf ("Unable to parse volume id of" " volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 699, GF_LOG_ERROR, "Unable to parse volume id of" " volume %s", volname); } while (0) | |||||
699 | " volume %s", volname)do { do { if (0) printf ("Unable to parse volume id of" " volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 699, GF_LOG_ERROR, "Unable to parse volume id of" " volume %s", volname); } while (0); | |||||
700 | goto out; | |||||
701 | } | |||||
702 | ||||||
703 | #ifdef HAVE_BD_XLATOR | |||||
704 | ret = dict_get_str (dict, "device", &dev_type); | |||||
705 | #endif | |||||
706 | ||||||
707 | ret = dict_get_str (dict, "bricks", &bricks); | |||||
708 | if (ret) { | |||||
709 | gf_log (this->name, GF_LOG_ERROR, "Unable to get bricks for "do { do { if (0) printf ("Unable to get bricks for " "volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 710, GF_LOG_ERROR, "Unable to get bricks for " "volume %s", volname); } while (0) | |||||
710 | "volume %s", volname)do { do { if (0) printf ("Unable to get bricks for " "volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 710, GF_LOG_ERROR, "Unable to get bricks for " "volume %s", volname); } while (0); | |||||
711 | goto out; | |||||
712 | } | |||||
713 | ||||||
714 | is_force = dict_get_str_boolean (dict, "force", _gf_false); | |||||
715 | ||||||
716 | if (bricks) { | |||||
717 | brick_list = gf_strdup (bricks); | |||||
718 | if (!brick_list) { | |||||
719 | ret = -1; | |||||
720 | goto out; | |||||
721 | } else { | |||||
722 | free_ptr = brick_list; | |||||
723 | } | |||||
724 | } | |||||
725 | ||||||
726 | while ( i < brick_count) { | |||||
727 | i++; | |||||
728 | brick= strtok_r (brick_list, " \n", &tmpptr); | |||||
729 | brick_list = tmpptr; | |||||
730 | ||||||
731 | if (!glusterd_store_is_valid_brickpath (volname, brick) || | |||||
732 | !glusterd_is_valid_volfpath (volname, brick)) { | |||||
733 | snprintf (msg, sizeof (msg), "brick path %s is too " | |||||
734 | "long.", brick); | |||||
735 | ret = -1; | |||||
736 | goto out; | |||||
737 | } | |||||
738 | ||||||
739 | ret = glusterd_brickinfo_new_from_brick (brick, &brick_info); | |||||
740 | if (ret) | |||||
741 | goto out; | |||||
742 | ||||||
743 | ret = glusterd_new_brick_validate (brick, brick_info, msg, | |||||
744 | sizeof (msg)); | |||||
745 | if (ret) | |||||
746 | goto out; | |||||
747 | ||||||
748 | ret = glusterd_resolve_brick (brick_info); | |||||
749 | if (ret) { | |||||
750 | gf_log (this->name, GF_LOG_ERROR, FMTSTR_RESOLVE_BRICK,do { do { if (0) printf ("Could not find peer on which brick %s:%s resides" , brick_info->hostname, brick_info->path); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__ , 751, GF_LOG_ERROR, "Could not find peer on which brick %s:%s resides" , brick_info->hostname, brick_info->path); } while (0) | |||||
751 | brick_info->hostname, brick_info->path)do { do { if (0) printf ("Could not find peer on which brick %s:%s resides" , brick_info->hostname, brick_info->path); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__ , 751, GF_LOG_ERROR, "Could not find peer on which brick %s:%s resides" , brick_info->hostname, brick_info->path); } while (0); | |||||
752 | goto out; | |||||
753 | } | |||||
754 | ||||||
755 | #ifdef HAVE_BD_XLATOR | |||||
756 | if (dev_type) { | |||||
757 | ret = glusterd_is_valid_vg (brick_info->path); | |||||
758 | if (ret) { | |||||
759 | snprintf (msg, sizeof(msg), "invalid vg %s", | |||||
760 | brick_info->path); | |||||
761 | goto out; | |||||
762 | } | |||||
763 | ||||||
764 | break; | |||||
765 | } else | |||||
766 | #endif | |||||
767 | if (!uuid_compare (brick_info->uuid, MY_UUID(__glusterd_uuid()))) { | |||||
768 | ret = glusterd_validate_and_create_brickpath (brick_info, | |||||
769 | volume_uuid, op_errstr, | |||||
770 | is_force); | |||||
771 | if (ret) | |||||
772 | goto out; | |||||
773 | brick_list = tmpptr; | |||||
774 | } | |||||
775 | glusterd_brickinfo_delete (brick_info); | |||||
776 | brick_info = NULL((void*)0); | |||||
777 | } | |||||
778 | out: | |||||
779 | GF_FREE (free_ptr)__gf_free (free_ptr); | |||||
780 | if (brick_info) | |||||
781 | glusterd_brickinfo_delete (brick_info); | |||||
782 | ||||||
783 | if (msg[0] != '\0') { | |||||
784 | gf_log (this->name, GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log (this ->name, "glusterd-volume-ops.c", __FUNCTION__, 784, GF_LOG_ERROR , "%s", msg); } while (0); | |||||
785 | *op_errstr = gf_strdup (msg); | |||||
786 | } | |||||
787 | gf_log (this->name, GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__, 787, GF_LOG_DEBUG , "Returning %d", ret); } while (0); | |||||
788 | ||||||
789 | return ret; | |||||
790 | } | |||||
791 | ||||||
792 | int | |||||
793 | glusterd_op_stop_volume_args_get (dict_t *dict, char** volname, int *flags) | |||||
794 | { | |||||
795 | int ret = -1; | |||||
796 | xlator_t *this = NULL((void*)0); | |||||
797 | ||||||
798 | this = THIS(*__glusterfs_this_location()); | |||||
799 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-volume-ops.c" , __FUNCTION__, 799, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
800 | ||||||
801 | if (!dict || !volname || !flags) | |||||
802 | goto out; | |||||
803 | ||||||
804 | ret = dict_get_str (dict, "volname", volname); | |||||
805 | if (ret) { | |||||
806 | gf_log (this->name, GF_LOG_ERROR, "Unable to get volume name")do { do { if (0) printf ("Unable to get volume name"); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__ , 806, GF_LOG_ERROR, "Unable to get volume name"); } while (0 ); | |||||
807 | goto out; | |||||
808 | } | |||||
809 | ||||||
810 | ret = dict_get_int32 (dict, "flags", flags); | |||||
811 | if (ret) { | |||||
812 | gf_log (this->name, GF_LOG_ERROR, "Unable to get flags")do { do { if (0) printf ("Unable to get flags"); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__ , 812, GF_LOG_ERROR, "Unable to get flags"); } while (0); | |||||
813 | goto out; | |||||
814 | } | |||||
815 | out: | |||||
816 | return ret; | |||||
817 | } | |||||
818 | ||||||
819 | int | |||||
820 | glusterd_op_statedump_volume_args_get (dict_t *dict, char **volname, | |||||
821 | char **options, int *option_cnt) | |||||
822 | { | |||||
823 | int ret = -1; | |||||
824 | ||||||
825 | if (!dict || !volname || !options || !option_cnt) | |||||
826 | goto out; | |||||
827 | ||||||
828 | ret = dict_get_str (dict, "volname", volname); | |||||
829 | if (ret) { | |||||
830 | gf_log ("", GF_LOG_ERROR, "Unable to get volname")do { do { if (0) printf ("Unable to get volname"); } while (0 ); _gf_log ("", "glusterd-volume-ops.c", __FUNCTION__, 830, GF_LOG_ERROR , "Unable to get volname"); } while (0); | |||||
831 | goto out; | |||||
832 | } | |||||
833 | ||||||
834 | ret = dict_get_str (dict, "options", options); | |||||
835 | if (ret) { | |||||
836 | gf_log ("", GF_LOG_ERROR, "Unable to get options")do { do { if (0) printf ("Unable to get options"); } while (0 ); _gf_log ("", "glusterd-volume-ops.c", __FUNCTION__, 836, GF_LOG_ERROR , "Unable to get options"); } while (0); | |||||
837 | goto out; | |||||
838 | } | |||||
839 | ||||||
840 | ret = dict_get_int32 (dict, "option_cnt", option_cnt); | |||||
841 | if (ret) { | |||||
842 | gf_log ("", GF_LOG_ERROR, "Unable to get option count")do { do { if (0) printf ("Unable to get option count"); } while (0); _gf_log ("", "glusterd-volume-ops.c", __FUNCTION__, 842 , GF_LOG_ERROR, "Unable to get option count"); } while (0); | |||||
843 | goto out; | |||||
844 | } | |||||
845 | ||||||
846 | out: | |||||
847 | return ret; | |||||
848 | } | |||||
849 | ||||||
850 | int | |||||
851 | glusterd_op_stage_start_volume (dict_t *dict, char **op_errstr) | |||||
852 | { | |||||
853 | int ret = 0; | |||||
854 | char *volname = NULL((void*)0); | |||||
855 | int flags = 0; | |||||
856 | gf_boolean_t exists = _gf_false; | |||||
857 | glusterd_volinfo_t *volinfo = NULL((void*)0); | |||||
858 | glusterd_brickinfo_t *brickinfo = NULL((void*)0); | |||||
859 | char msg[2048]; | |||||
860 | glusterd_conf_t *priv = NULL((void*)0); | |||||
861 | xlator_t *this = NULL((void*)0); | |||||
862 | uuid_t volume_id = {0,}; | |||||
863 | char volid[50] = {0,}; | |||||
864 | char xattr_volid[50] = {0,}; | |||||
865 | ||||||
866 | this = THIS(*__glusterfs_this_location()); | |||||
867 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-volume-ops.c" , __FUNCTION__, 867, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
868 | priv = this->private; | |||||
869 | GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: " "priv"); } while (0); _gf_log_callingfn ("", "glusterd-volume-ops.c" , __FUNCTION__, 869, GF_LOG_ERROR, "Assertion failed: " "priv" ); } while (0); } } while (0); | |||||
870 | ||||||
871 | ret = glusterd_op_start_volume_args_get (dict, &volname, &flags)glusterd_op_stop_volume_args_get (dict, &volname, &flags ); | |||||
872 | if (ret) | |||||
873 | goto out; | |||||
874 | ||||||
875 | exists = glusterd_check_volume_exists (volname); | |||||
876 | ||||||
877 | if (!exists) { | |||||
878 | snprintf (msg, sizeof (msg), FMTSTR_CHECK_VOL_EXISTS"Volume %s does not exist", volname); | |||||
879 | ret = -1; | |||||
880 | goto out; | |||||
881 | } | |||||
882 | ||||||
883 | ret = glusterd_volinfo_find (volname, &volinfo); | |||||
884 | if (ret) { | |||||
885 | gf_log (this->name, GF_LOG_ERROR, FMTSTR_CHECK_VOL_EXISTS,do { do { if (0) printf ("Volume %s does not exist", volname) ; } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 886, GF_LOG_ERROR, "Volume %s does not exist" , volname); } while (0) | |||||
886 | volname)do { do { if (0) printf ("Volume %s does not exist", volname) ; } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 886, GF_LOG_ERROR, "Volume %s does not exist" , volname); } while (0); | |||||
887 | goto out; | |||||
888 | } | |||||
889 | ||||||
890 | ret = glusterd_validate_volume_id (dict, volinfo); | |||||
891 | if (ret) | |||||
892 | goto out; | |||||
893 | ||||||
894 | if (!(flags & GF_CLI_FLAG_OP_FORCE)) { | |||||
895 | if (glusterd_is_volume_started (volinfo)) { | |||||
896 | snprintf (msg, sizeof (msg), "Volume %s already " | |||||
897 | "started", volname); | |||||
898 | ret = -1; | |||||
899 | goto out; | |||||
900 | } | |||||
901 | } | |||||
902 | ||||||
903 | list_for_each_entry (brickinfo, &volinfo->bricks, brick_list)for (brickinfo = ((typeof(*brickinfo) *)((char *)((&volinfo ->bricks)->next)-(unsigned long)(&((typeof(*brickinfo ) *)0)->brick_list))); &brickinfo->brick_list != (& volinfo->bricks); brickinfo = ((typeof(*brickinfo) *)((char *)(brickinfo->brick_list.next)-(unsigned long)(&((typeof (*brickinfo) *)0)->brick_list)))) { | |||||
904 | ret = glusterd_resolve_brick (brickinfo); | |||||
905 | if (ret) { | |||||
906 | gf_log (this->name, GF_LOG_ERROR, FMTSTR_RESOLVE_BRICK,do { do { if (0) printf ("Could not find peer on which brick %s:%s resides" , brickinfo->hostname, brickinfo->path); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__, 907, GF_LOG_ERROR , "Could not find peer on which brick %s:%s resides", brickinfo ->hostname, brickinfo->path); } while (0) | |||||
907 | brickinfo->hostname, brickinfo->path)do { do { if (0) printf ("Could not find peer on which brick %s:%s resides" , brickinfo->hostname, brickinfo->path); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__, 907, GF_LOG_ERROR , "Could not find peer on which brick %s:%s resides", brickinfo ->hostname, brickinfo->path); } while (0); | |||||
908 | goto out; | |||||
909 | } | |||||
910 | ||||||
911 | if (uuid_compare (brickinfo->uuid, MY_UUID(__glusterd_uuid()))) | |||||
912 | continue; | |||||
913 | ||||||
914 | if (volinfo->backend == GD_VOL_BK_BD) | |||||
915 | continue; | |||||
916 | ||||||
917 | ret = gf_lstat_dir (brickinfo->path, NULL((void*)0)); | |||||
918 | if (ret) { | |||||
919 | snprintf (msg, sizeof (msg), "Failed to find " | |||||
920 | "brick directory %s for volume %s. " | |||||
921 | "Reason : %s", brickinfo->path, | |||||
922 | volname, strerror (errno(*__errno_location ()))); | |||||
923 | goto out; | |||||
924 | } | |||||
925 | ret = sys_lgetxattr (brickinfo->path, GF_XATTR_VOL_ID_KEY"trusted.glusterfs.volume-id", | |||||
926 | volume_id, 16); | |||||
927 | if (ret < 0) { | |||||
928 | snprintf (msg, sizeof (msg), "Failed to get " | |||||
929 | "extended attribute %s for brick dir %s. " | |||||
930 | "Reason : %s", GF_XATTR_VOL_ID_KEY"trusted.glusterfs.volume-id", | |||||
931 | brickinfo->path, strerror (errno(*__errno_location ()))); | |||||
932 | ret = -1; | |||||
933 | goto out; | |||||
934 | } | |||||
935 | if (uuid_compare (volinfo->volume_id, volume_id)) { | |||||
936 | snprintf (msg, sizeof (msg), "Volume id mismatch for " | |||||
937 | "brick %s:%s. Expected volume id %s, " | |||||
938 | "volume id %s found", brickinfo->hostname, | |||||
939 | brickinfo->path, | |||||
940 | uuid_utoa_r (volinfo->volume_id, volid), | |||||
941 | uuid_utoa_r (volume_id, xattr_volid)); | |||||
942 | ret = -1; | |||||
943 | goto out; | |||||
944 | } | |||||
945 | } | |||||
946 | ||||||
947 | ret = 0; | |||||
948 | out: | |||||
949 | if (ret && (msg[0] != '\0')) { | |||||
950 | gf_log (this->name, GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log (this ->name, "glusterd-volume-ops.c", __FUNCTION__, 950, GF_LOG_ERROR , "%s", msg); } while (0); | |||||
951 | *op_errstr = gf_strdup (msg); | |||||
952 | } | |||||
953 | return ret; | |||||
954 | } | |||||
955 | ||||||
956 | int | |||||
957 | glusterd_op_stage_stop_volume (dict_t *dict, char **op_errstr) | |||||
958 | { | |||||
959 | int ret = -1; | |||||
960 | char *volname = NULL((void*)0); | |||||
961 | int flags = 0; | |||||
962 | gf_boolean_t exists = _gf_false; | |||||
963 | gf_boolean_t is_run = _gf_false; | |||||
964 | glusterd_volinfo_t *volinfo = NULL((void*)0); | |||||
965 | char msg[2048] = {0}; | |||||
966 | xlator_t *this = NULL((void*)0); | |||||
967 | ||||||
968 | this = THIS(*__glusterfs_this_location()); | |||||
| ||||||
969 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-volume-ops.c" , __FUNCTION__, 969, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
970 | ||||||
971 | ret = glusterd_op_stop_volume_args_get (dict, &volname, &flags); | |||||
972 | if (ret) | |||||
973 | goto out; | |||||
974 | ||||||
975 | exists = glusterd_check_volume_exists (volname); | |||||
976 | ||||||
977 | if (!exists) { | |||||
978 | snprintf (msg, sizeof (msg), FMTSTR_CHECK_VOL_EXISTS"Volume %s does not exist", volname); | |||||
979 | gf_log (this->name, GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log (this ->name, "glusterd-volume-ops.c", __FUNCTION__, 979, GF_LOG_ERROR , "%s", msg); } while (0); | |||||
980 | ret = -1; | |||||
981 | goto out; | |||||
982 | } | |||||
983 | ||||||
984 | ret = glusterd_volinfo_find (volname, &volinfo); | |||||
985 | if (ret) { | |||||
986 | snprintf (msg, sizeof (msg), FMTSTR_CHECK_VOL_EXISTS"Volume %s does not exist", volname); | |||||
987 | gf_log (this->name, GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log (this ->name, "glusterd-volume-ops.c", __FUNCTION__, 987, GF_LOG_ERROR , "%s", msg); } while (0); | |||||
988 | goto out; | |||||
989 | } | |||||
990 | ||||||
991 | ret = glusterd_validate_volume_id (dict, volinfo); | |||||
992 | if (ret) | |||||
993 | goto out; | |||||
994 | ||||||
995 | /* If 'force' flag is given, no check is required */ | |||||
996 | if (flags & GF_CLI_FLAG_OP_FORCE) | |||||
997 | goto out; | |||||
998 | ||||||
999 | if (_gf_false == glusterd_is_volume_started (volinfo)) { | |||||
1000 | snprintf (msg, sizeof(msg), "Volume %s " | |||||
1001 | "is not in the started state", volname); | |||||
1002 | gf_log (this->name, GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log (this ->name, "glusterd-volume-ops.c", __FUNCTION__, 1002, GF_LOG_ERROR , "%s", msg); } while (0); | |||||
| ||||||
1003 | ret = -1; | |||||
1004 | goto out; | |||||
1005 | } | |||||
1006 | ret = glusterd_check_gsync_running (volinfo, &is_run); | |||||
1007 | if (ret && (is_run == _gf_false)) | |||||
1008 | gf_log (this->name, GF_LOG_WARNING, "Unable to get the status"do { do { if (0) printf ("Unable to get the status" " of active " "geo-replication"" session"); } while (0); _gf_log (this-> name, "glusterd-volume-ops.c", __FUNCTION__, 1009, GF_LOG_WARNING , "Unable to get the status" " of active ""geo-replication"" session" ); } while (0) | |||||
1009 | " of active "GEOREP" session")do { do { if (0) printf ("Unable to get the status" " of active " "geo-replication"" session"); } while (0); _gf_log (this-> name, "glusterd-volume-ops.c", __FUNCTION__, 1009, GF_LOG_WARNING , "Unable to get the status" " of active ""geo-replication"" session" ); } while (0); | |||||
1010 | if (is_run) { | |||||
1011 | gf_log (this->name, GF_LOG_WARNING, GEOREP" sessions active"do { do { if (0) printf ("geo-replication"" sessions active" "for the volume %s " , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1012, GF_LOG_WARNING, "geo-replication"" sessions active" "for the volume %s ", volname); } while (0) | |||||
1012 | "for the volume %s ", volname)do { do { if (0) printf ("geo-replication"" sessions active" "for the volume %s " , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1012, GF_LOG_WARNING, "geo-replication"" sessions active" "for the volume %s ", volname); } while (0); | |||||
1013 | snprintf (msg, sizeof(msg), GEOREP"geo-replication"" sessions are active " | |||||
1014 | "for the volume '%s'.\nUse 'volume "GEOREP"geo-replication"" " | |||||
1015 | "status' command for more info. Use 'force' " | |||||
1016 | "option to ignore and stop the volume.", | |||||
1017 | volname); | |||||
1018 | ret = -1; | |||||
1019 | goto out; | |||||
1020 | } | |||||
1021 | ||||||
1022 | if (glusterd_is_rb_ongoing (volinfo)) { | |||||
1023 | snprintf (msg, sizeof (msg), "Replace brick is in progress on " | |||||
1024 | "volume %s. Please retry after replace-brick " | |||||
1025 | "operation is committed or aborted", volname); | |||||
1026 | gf_log (this->name, GF_LOG_WARNING, "replace-brick in progress "do { do { if (0) printf ("replace-brick in progress " "on volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1027, GF_LOG_WARNING, "replace-brick in progress " "on volume %s", volname); } while (0) | |||||
1027 | "on volume %s", volname)do { do { if (0) printf ("replace-brick in progress " "on volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1027, GF_LOG_WARNING, "replace-brick in progress " "on volume %s", volname); } while (0); | |||||
1028 | ret = -1; | |||||
1029 | goto out; | |||||
1030 | } | |||||
1031 | ||||||
1032 | if (glusterd_is_defrag_on (volinfo)) { | |||||
1033 | snprintf (msg, sizeof(msg), "rebalance session is " | |||||
1034 | "in progress for the volume '%s'", volname); | |||||
1035 | gf_log (this->name, GF_LOG_WARNING, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log (this ->name, "glusterd-volume-ops.c", __FUNCTION__, 1035, GF_LOG_WARNING , "%s", msg); } while (0); | |||||
1036 | ret = -1; | |||||
1037 | goto out; | |||||
1038 | } | |||||
1039 | if (volinfo->rep_brick.rb_status != GF_RB_STATUS_NONE) { | |||||
1040 | snprintf (msg, sizeof(msg), "replace-brick session is " | |||||
1041 | "in progress for the volume '%s'", volname); | |||||
1042 | gf_log (this->name, GF_LOG_WARNING, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log (this ->name, "glusterd-volume-ops.c", __FUNCTION__, 1042, GF_LOG_WARNING , "%s", msg); } while (0); | |||||
1043 | ret = -1; | |||||
1044 | goto out; | |||||
1045 | } | |||||
1046 | ||||||
1047 | out: | |||||
1048 | if (msg[0] != 0) | |||||
1049 | *op_errstr = gf_strdup (msg); | |||||
1050 | gf_log (this->name, GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__, 1050, GF_LOG_DEBUG, "Returning %d", ret); } while (0); | |||||
1051 | ||||||
1052 | return ret; | |||||
1053 | } | |||||
1054 | ||||||
1055 | int | |||||
1056 | glusterd_op_stage_delete_volume (dict_t *dict, char **op_errstr) | |||||
1057 | { | |||||
1058 | int ret = 0; | |||||
1059 | char *volname = NULL((void*)0); | |||||
1060 | gf_boolean_t exists = _gf_false; | |||||
1061 | glusterd_volinfo_t *volinfo = NULL((void*)0); | |||||
1062 | char msg[2048] = {0}; | |||||
1063 | xlator_t *this = NULL((void*)0); | |||||
1064 | ||||||
1065 | this = THIS(*__glusterfs_this_location()); | |||||
1066 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-volume-ops.c" , __FUNCTION__, 1066, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
1067 | ||||||
1068 | ret = dict_get_str (dict, "volname", &volname); | |||||
1069 | if (ret) { | |||||
1070 | gf_log (this->name, GF_LOG_ERROR, "Unable to get volume name")do { do { if (0) printf ("Unable to get volume name"); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__ , 1070, GF_LOG_ERROR, "Unable to get volume name"); } while ( 0); | |||||
1071 | goto out; | |||||
1072 | } | |||||
1073 | ||||||
1074 | exists = glusterd_check_volume_exists (volname); | |||||
1075 | if (!exists) { | |||||
1076 | snprintf (msg, sizeof (msg), FMTSTR_CHECK_VOL_EXISTS"Volume %s does not exist", volname); | |||||
1077 | ret = -1; | |||||
1078 | goto out; | |||||
1079 | } else { | |||||
1080 | ret = 0; | |||||
1081 | } | |||||
1082 | ||||||
1083 | ret = glusterd_volinfo_find (volname, &volinfo); | |||||
1084 | if (ret) { | |||||
1085 | snprintf (msg, sizeof (msg), FMTSTR_CHECK_VOL_EXISTS"Volume %s does not exist", volname); | |||||
1086 | goto out; | |||||
1087 | } | |||||
1088 | ||||||
1089 | ret = glusterd_validate_volume_id (dict, volinfo); | |||||
1090 | if (ret) | |||||
1091 | goto out; | |||||
1092 | ||||||
1093 | if (glusterd_is_volume_started (volinfo)) { | |||||
1094 | snprintf (msg, sizeof (msg), "Volume %s has been started." | |||||
1095 | "Volume needs to be stopped before deletion.", | |||||
1096 | volname); | |||||
1097 | ret = -1; | |||||
1098 | goto out; | |||||
1099 | } | |||||
1100 | ||||||
1101 | ret = 0; | |||||
1102 | ||||||
1103 | out: | |||||
1104 | if (msg[0] != '\0') { | |||||
1105 | gf_log (this->name, GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log (this ->name, "glusterd-volume-ops.c", __FUNCTION__, 1105, GF_LOG_ERROR , "%s", msg); } while (0); | |||||
1106 | *op_errstr = gf_strdup (msg); | |||||
1107 | } | |||||
1108 | gf_log (this->name, GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__, 1108, GF_LOG_DEBUG, "Returning %d", ret); } while (0); | |||||
1109 | ||||||
1110 | return ret; | |||||
1111 | } | |||||
1112 | ||||||
1113 | int | |||||
1114 | glusterd_op_stage_heal_volume (dict_t *dict, char **op_errstr) | |||||
1115 | { | |||||
1116 | int ret = 0; | |||||
1117 | char *volname = NULL((void*)0); | |||||
1118 | gf_boolean_t enabled = _gf_false; | |||||
1119 | glusterd_volinfo_t *volinfo = NULL((void*)0); | |||||
1120 | char msg[2048]; | |||||
1121 | glusterd_conf_t *priv = NULL((void*)0); | |||||
1122 | dict_t *opt_dict = NULL((void*)0); | |||||
1123 | gf_xl_afr_op_t heal_op = GF_AFR_OP_INVALID; | |||||
1124 | xlator_t *this = NULL((void*)0); | |||||
1125 | ||||||
1126 | this = THIS(*__glusterfs_this_location()); | |||||
1127 | priv = this->private; | |||||
1128 | if (!priv) { | |||||
1129 | ret = -1; | |||||
1130 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("priv is NULL"); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__, 1131, GF_LOG_ERROR, "priv is NULL"); } while (0) | |||||
1131 | "priv is NULL")do { do { if (0) printf ("priv is NULL"); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__, 1131, GF_LOG_ERROR, "priv is NULL"); } while (0); | |||||
1132 | goto out; | |||||
1133 | } | |||||
1134 | ||||||
1135 | ret = dict_get_str (dict, "volname", &volname); | |||||
1136 | if (ret) { | |||||
1137 | gf_log ("", GF_LOG_ERROR, "Unable to get volume name")do { do { if (0) printf ("Unable to get volume name"); } while (0); _gf_log ("", "glusterd-volume-ops.c", __FUNCTION__, 1137 , GF_LOG_ERROR, "Unable to get volume name"); } while (0); | |||||
1138 | goto out; | |||||
1139 | } | |||||
1140 | ||||||
1141 | ret = glusterd_volinfo_find (volname, &volinfo); | |||||
1142 | if (ret) { | |||||
1143 | ret = -1; | |||||
1144 | snprintf (msg, sizeof (msg), "Volume %s does not exist", volname); | |||||
1145 | gf_log (this->name, GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log (this ->name, "glusterd-volume-ops.c", __FUNCTION__, 1145, GF_LOG_ERROR , "%s", msg); } while (0); | |||||
1146 | *op_errstr = gf_strdup (msg); | |||||
1147 | goto out; | |||||
1148 | } | |||||
1149 | ||||||
1150 | ret = glusterd_validate_volume_id (dict, volinfo); | |||||
1151 | if (ret) | |||||
1152 | goto out; | |||||
1153 | ||||||
1154 | if (!glusterd_is_volume_replicate (volinfo)) { | |||||
1155 | ret = -1; | |||||
1156 | snprintf (msg, sizeof (msg), "Volume %s is not of type " | |||||
1157 | "replicate", volname); | |||||
1158 | *op_errstr = gf_strdup (msg); | |||||
1159 | gf_log (this->name, GF_LOG_WARNING, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log (this ->name, "glusterd-volume-ops.c", __FUNCTION__, 1159, GF_LOG_WARNING , "%s", msg); } while (0); | |||||
1160 | goto out; | |||||
1161 | } | |||||
1162 | ||||||
1163 | if (!glusterd_is_volume_started (volinfo)) { | |||||
1164 | ret = -1; | |||||
1165 | snprintf (msg, sizeof (msg), "Volume %s is not started.", | |||||
1166 | volname); | |||||
1167 | gf_log (THIS->name, GF_LOG_WARNING, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log ((* __glusterfs_this_location())->name, "glusterd-volume-ops.c" , __FUNCTION__, 1167, GF_LOG_WARNING, "%s", msg); } while (0); | |||||
1168 | *op_errstr = gf_strdup (msg); | |||||
1169 | goto out; | |||||
1170 | } | |||||
1171 | ||||||
1172 | opt_dict = volinfo->dict; | |||||
1173 | if (!opt_dict) { | |||||
1174 | ret = 0; | |||||
1175 | goto out; | |||||
1176 | } | |||||
1177 | ||||||
1178 | enabled = dict_get_str_boolean (opt_dict, "cluster.self-heal-daemon", | |||||
1179 | 1); | |||||
1180 | if (!enabled) { | |||||
1181 | ret = -1; | |||||
1182 | snprintf (msg, sizeof (msg), "Self-heal-daemon is " | |||||
1183 | "disabled. Heal will not be triggered on volume %s", | |||||
1184 | volname); | |||||
1185 | gf_log (this->name, GF_LOG_WARNING, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log (this ->name, "glusterd-volume-ops.c", __FUNCTION__, 1185, GF_LOG_WARNING , "%s", msg); } while (0); | |||||
1186 | *op_errstr = gf_strdup (msg); | |||||
1187 | goto out; | |||||
1188 | } | |||||
1189 | ||||||
1190 | ret = dict_get_int32 (dict, "heal-op", (int32_t*)&heal_op); | |||||
1191 | if (ret || (heal_op == GF_AFR_OP_INVALID)) { | |||||
1192 | ret = -1; | |||||
1193 | *op_errstr = gf_strdup("Invalid heal-op"); | |||||
1194 | gf_log (this->name, GF_LOG_WARNING, "%s", "Invalid heal-op")do { do { if (0) printf ("%s", "Invalid heal-op"); } while (0 ); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__ , 1194, GF_LOG_WARNING, "%s", "Invalid heal-op"); } while (0); | |||||
1195 | goto out; | |||||
1196 | } | |||||
1197 | ||||||
1198 | if ((heal_op != GF_AFR_OP_INDEX_SUMMARY) && | |||||
1199 | !glusterd_is_nodesvc_online ("glustershd")) { | |||||
1200 | ret = -1; | |||||
1201 | *op_errstr = gf_strdup ("Self-heal daemon is not running." | |||||
1202 | " Check self-heal daemon log file."); | |||||
1203 | gf_log (this->name, GF_LOG_WARNING, "%s", "Self-heal daemon is "do { do { if (0) printf ("%s", "Self-heal daemon is " "not running. Check self-heal daemon log file." ); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1204, GF_LOG_WARNING, "%s", "Self-heal daemon is " "not running. Check self-heal daemon log file."); } while (0 ) | |||||
1204 | "not running. Check self-heal daemon log file.")do { do { if (0) printf ("%s", "Self-heal daemon is " "not running. Check self-heal daemon log file." ); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1204, GF_LOG_WARNING, "%s", "Self-heal daemon is " "not running. Check self-heal daemon log file."); } while (0 ); | |||||
1205 | goto out; | |||||
1206 | } | |||||
1207 | ||||||
1208 | ret = 0; | |||||
1209 | out: | |||||
1210 | gf_log ("", GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ("", "glusterd-volume-ops.c", __FUNCTION__, 1210, GF_LOG_DEBUG , "Returning %d", ret); } while (0); | |||||
1211 | ||||||
1212 | return ret; | |||||
1213 | } | |||||
1214 | ||||||
1215 | int | |||||
1216 | glusterd_op_stage_statedump_volume (dict_t *dict, char **op_errstr) | |||||
1217 | { | |||||
1218 | int ret = -1; | |||||
1219 | char *volname = NULL((void*)0); | |||||
1220 | char *options = NULL((void*)0); | |||||
1221 | int option_cnt = 0; | |||||
1222 | gf_boolean_t is_running = _gf_false; | |||||
1223 | glusterd_volinfo_t *volinfo = NULL((void*)0); | |||||
1224 | char msg[2408] = {0,}; | |||||
1225 | ||||||
1226 | ret = glusterd_op_statedump_volume_args_get (dict, &volname, &options, | |||||
1227 | &option_cnt); | |||||
1228 | if (ret) | |||||
1229 | goto out; | |||||
1230 | ||||||
1231 | ret = glusterd_volinfo_find (volname, &volinfo); | |||||
1232 | if (ret) { | |||||
1233 | snprintf (msg, sizeof(msg), "Volume %s does not exist", | |||||
1234 | volname); | |||||
1235 | gf_log ("", GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log ("" , "glusterd-volume-ops.c", __FUNCTION__, 1235, GF_LOG_ERROR, "%s" , msg); } while (0); | |||||
1236 | *op_errstr = gf_strdup (msg); | |||||
1237 | goto out; | |||||
1238 | } | |||||
1239 | ||||||
1240 | ret = glusterd_validate_volume_id (dict, volinfo); | |||||
1241 | if (ret) | |||||
1242 | goto out; | |||||
1243 | ||||||
1244 | is_running = glusterd_is_volume_started (volinfo); | |||||
1245 | if (!is_running) { | |||||
1246 | snprintf (msg, sizeof(msg), "Volume %s is not in a started" | |||||
1247 | " state", volname); | |||||
1248 | gf_log ("", GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log ("" , "glusterd-volume-ops.c", __FUNCTION__, 1248, GF_LOG_ERROR, "%s" , msg); } while (0); | |||||
1249 | *op_errstr = gf_strdup (msg); | |||||
1250 | ret = -1; | |||||
1251 | goto out; | |||||
1252 | } | |||||
1253 | ||||||
1254 | out: | |||||
1255 | gf_log ("", GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ("", "glusterd-volume-ops.c", __FUNCTION__, 1255, GF_LOG_DEBUG , "Returning %d", ret); } while (0); | |||||
1256 | return ret; | |||||
1257 | } | |||||
1258 | ||||||
1259 | int | |||||
1260 | glusterd_op_stage_clearlocks_volume (dict_t *dict, char **op_errstr) | |||||
1261 | { | |||||
1262 | int ret = -1; | |||||
1263 | char *volname = NULL((void*)0); | |||||
1264 | char *path = NULL((void*)0); | |||||
1265 | char *type = NULL((void*)0); | |||||
1266 | char *kind = NULL((void*)0); | |||||
1267 | glusterd_volinfo_t *volinfo = NULL((void*)0); | |||||
1268 | char msg[2048] = {0,}; | |||||
1269 | ||||||
1270 | ret = dict_get_str (dict, "volname", &volname); | |||||
1271 | if (ret) { | |||||
1272 | snprintf (msg, sizeof(msg), "Failed to get volume name"); | |||||
1273 | gf_log (THIS->name, GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log ((* __glusterfs_this_location())->name, "glusterd-volume-ops.c" , __FUNCTION__, 1273, GF_LOG_ERROR, "%s", msg); } while (0); | |||||
1274 | *op_errstr = gf_strdup (msg); | |||||
1275 | goto out; | |||||
1276 | } | |||||
1277 | ||||||
1278 | ret = dict_get_str (dict, "path", &path); | |||||
1279 | if (ret) { | |||||
1280 | snprintf (msg, sizeof(msg), "Failed to get path"); | |||||
1281 | gf_log (THIS->name, GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log ((* __glusterfs_this_location())->name, "glusterd-volume-ops.c" , __FUNCTION__, 1281, GF_LOG_ERROR, "%s", msg); } while (0); | |||||
1282 | *op_errstr = gf_strdup (msg); | |||||
1283 | goto out; | |||||
1284 | } | |||||
1285 | ||||||
1286 | ret = dict_get_str (dict, "kind", &kind); | |||||
1287 | if (ret) { | |||||
1288 | snprintf (msg, sizeof(msg), "Failed to get kind"); | |||||
1289 | gf_log ("", GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log ("" , "glusterd-volume-ops.c", __FUNCTION__, 1289, GF_LOG_ERROR, "%s" , msg); } while (0); | |||||
1290 | *op_errstr = gf_strdup (msg); | |||||
1291 | goto out; | |||||
1292 | } | |||||
1293 | ||||||
1294 | ret = dict_get_str (dict, "type", &type); | |||||
1295 | if (ret) { | |||||
1296 | snprintf (msg, sizeof(msg), "Failed to get type"); | |||||
1297 | gf_log ("", GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log ("" , "glusterd-volume-ops.c", __FUNCTION__, 1297, GF_LOG_ERROR, "%s" , msg); } while (0); | |||||
1298 | *op_errstr = gf_strdup (msg); | |||||
1299 | goto out; | |||||
1300 | } | |||||
1301 | ||||||
1302 | ret = glusterd_volinfo_find (volname, &volinfo); | |||||
1303 | if (ret) { | |||||
1304 | snprintf (msg, sizeof(msg), "Volume %s does not exist", | |||||
1305 | volname); | |||||
1306 | gf_log ("", GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log ("" , "glusterd-volume-ops.c", __FUNCTION__, 1306, GF_LOG_ERROR, "%s" , msg); } while (0); | |||||
1307 | *op_errstr = gf_strdup (msg); | |||||
1308 | goto out; | |||||
1309 | } | |||||
1310 | ||||||
1311 | ret = glusterd_validate_volume_id (dict, volinfo); | |||||
1312 | if (ret) | |||||
1313 | goto out; | |||||
1314 | ||||||
1315 | if (!glusterd_is_volume_started (volinfo)) { | |||||
1316 | snprintf (msg, sizeof(msg), "Volume %s is not started", | |||||
1317 | volname); | |||||
1318 | gf_log ("", GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log ("" , "glusterd-volume-ops.c", __FUNCTION__, 1318, GF_LOG_ERROR, "%s" , msg); } while (0); | |||||
1319 | *op_errstr = gf_strdup (msg); | |||||
1320 | goto out; | |||||
1321 | } | |||||
1322 | ||||||
1323 | ret = 0; | |||||
1324 | out: | |||||
1325 | gf_log ("", GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ("", "glusterd-volume-ops.c", __FUNCTION__, 1325, GF_LOG_DEBUG , "Returning %d", ret); } while (0); | |||||
1326 | return ret; | |||||
1327 | } | |||||
1328 | ||||||
1329 | #ifdef HAVE_BD_XLATOR | |||||
1330 | int | |||||
1331 | glusterd_op_stage_bd (dict_t *dict, char **op_errstr) | |||||
1332 | { | |||||
1333 | int ret = -1; | |||||
1334 | char *volname = NULL((void*)0); | |||||
1335 | char *path = NULL((void*)0); | |||||
1336 | char *size = NULL((void*)0); | |||||
1337 | glusterd_volinfo_t *volinfo = NULL((void*)0); | |||||
1338 | char msg[2048] = {0,}; | |||||
1339 | gf_xl_bd_op_t bd_op = GF_BD_OP_INVALID; | |||||
1340 | uint64_t bytes = 0; | |||||
1341 | ||||||
1342 | ret = dict_get_str (dict, "volname", &volname); | |||||
1343 | if (ret) { | |||||
1344 | snprintf (msg, sizeof(msg), "Failed to get volume name"); | |||||
1345 | gf_log (THIS->name, GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log ((* __glusterfs_this_location())->name, "glusterd-volume-ops.c" , __FUNCTION__, 1345, GF_LOG_ERROR, "%s", msg); } while (0); | |||||
1346 | *op_errstr = gf_strdup (msg); | |||||
1347 | goto out; | |||||
1348 | } | |||||
1349 | ||||||
1350 | ret = dict_get_int32 (dict, "bd-op", (int32_t *)&bd_op); | |||||
1351 | if (ret) { | |||||
1352 | snprintf (msg, sizeof(msg), "Failed to get bd-op"); | |||||
1353 | gf_log (THIS->name, GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log ((* __glusterfs_this_location())->name, "glusterd-volume-ops.c" , __FUNCTION__, 1353, GF_LOG_ERROR, "%s", msg); } while (0); | |||||
1354 | *op_errstr = gf_strdup (msg); | |||||
1355 | goto out; | |||||
1356 | } | |||||
1357 | ||||||
1358 | ret = dict_get_str (dict, "path", &path); | |||||
1359 | if (ret) { | |||||
1360 | snprintf (msg, sizeof(msg), "Failed to get path"); | |||||
1361 | gf_log (THIS->name, GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log ((* __glusterfs_this_location())->name, "glusterd-volume-ops.c" , __FUNCTION__, 1361, GF_LOG_ERROR, "%s", msg); } while (0); | |||||
1362 | *op_errstr = gf_strdup (msg); | |||||
1363 | goto out; | |||||
1364 | } | |||||
1365 | ||||||
1366 | if (bd_op == GF_BD_OP_NEW_BD) { | |||||
1367 | ret = dict_get_str (dict, "size", &size); | |||||
1368 | if (ret) { | |||||
1369 | snprintf (msg, sizeof(msg), "Failed to get size"); | |||||
1370 | gf_log ("", GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log ("" , "glusterd-volume-ops.c", __FUNCTION__, 1370, GF_LOG_ERROR, "%s" , msg); } while (0); | |||||
1371 | *op_errstr = gf_strdup (msg); | |||||
1372 | goto out; | |||||
1373 | } | |||||
1374 | if (gf_string2bytesize (size, &bytes) < 0) { | |||||
1375 | snprintf (msg, sizeof(msg), | |||||
1376 | "Invalid size %s, suffix with KB, MB etc", | |||||
1377 | size); | |||||
1378 | gf_log ("", GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log ("" , "glusterd-volume-ops.c", __FUNCTION__, 1378, GF_LOG_ERROR, "%s" , msg); } while (0); | |||||
1379 | *op_errstr = gf_strdup (msg); | |||||
1380 | ret = -1; | |||||
1381 | goto out; | |||||
1382 | } | |||||
1383 | } else if (bd_op == GF_BD_OP_SNAPSHOT_BD) { | |||||
1384 | ret = dict_get_str (dict, "size", &size); | |||||
1385 | if (ret) { | |||||
1386 | snprintf (msg, sizeof(msg), "Failed to get size"); | |||||
1387 | gf_log ("", GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log ("" , "glusterd-volume-ops.c", __FUNCTION__, 1387, GF_LOG_ERROR, "%s" , msg); } while (0); | |||||
1388 | *op_errstr = gf_strdup (msg); | |||||
1389 | goto out; | |||||
1390 | } | |||||
1391 | ||||||
1392 | if (gf_string2bytesize (size, &bytes) < 0) { | |||||
1393 | ret = -1; | |||||
1394 | snprintf (msg, sizeof(msg), | |||||
1395 | "Invalid size %s, suffix with KB, MB etc", | |||||
1396 | size); | |||||
1397 | gf_log ("", GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log ("" , "glusterd-volume-ops.c", __FUNCTION__, 1397, GF_LOG_ERROR, "%s" , msg); } while (0); | |||||
1398 | *op_errstr = gf_strdup (msg); | |||||
1399 | goto out; | |||||
1400 | } | |||||
1401 | } | |||||
1402 | ||||||
1403 | ret = glusterd_volinfo_find (volname, &volinfo); | |||||
1404 | if (ret) { | |||||
1405 | snprintf (msg, sizeof(msg), "Volume %s does not exist", | |||||
1406 | volname); | |||||
1407 | gf_log ("", GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log ("" , "glusterd-volume-ops.c", __FUNCTION__, 1407, GF_LOG_ERROR, "%s" , msg); } while (0); | |||||
1408 | *op_errstr = gf_strdup (msg); | |||||
1409 | goto out; | |||||
1410 | } | |||||
1411 | ||||||
1412 | ret = glusterd_validate_volume_id (dict, volinfo); | |||||
1413 | if (ret) | |||||
1414 | goto out; | |||||
1415 | ||||||
1416 | if (!glusterd_is_volume_started (volinfo)) { | |||||
1417 | snprintf (msg, sizeof(msg), "Volume %s is not started", | |||||
1418 | volname); | |||||
1419 | gf_log ("", GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log ("" , "glusterd-volume-ops.c", __FUNCTION__, 1419, GF_LOG_ERROR, "%s" , msg); } while (0); | |||||
1420 | *op_errstr = gf_strdup (msg); | |||||
1421 | ret = -1; | |||||
1422 | goto out; | |||||
1423 | } | |||||
1424 | ||||||
1425 | ret = 0; | |||||
1426 | out: | |||||
1427 | gf_log ("", GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log ("", "glusterd-volume-ops.c", __FUNCTION__, 1427, GF_LOG_DEBUG , "Returning %d", ret); } while (0); | |||||
1428 | return ret; | |||||
1429 | } | |||||
1430 | #endif | |||||
1431 | ||||||
1432 | int | |||||
1433 | glusterd_op_create_volume (dict_t *dict, char **op_errstr) | |||||
1434 | { | |||||
1435 | int ret = 0; | |||||
1436 | char *volname = NULL((void*)0); | |||||
1437 | glusterd_conf_t *priv = NULL((void*)0); | |||||
1438 | glusterd_volinfo_t *volinfo = NULL((void*)0); | |||||
1439 | gf_boolean_t vol_added = _gf_false; | |||||
1440 | glusterd_brickinfo_t *brickinfo = NULL((void*)0); | |||||
1441 | xlator_t *this = NULL((void*)0); | |||||
1442 | char *brick = NULL((void*)0); | |||||
1443 | int32_t count = 0; | |||||
1444 | int32_t i = 1; | |||||
1445 | char *bricks = NULL((void*)0); | |||||
1446 | char *brick_list = NULL((void*)0); | |||||
1447 | char *free_ptr = NULL((void*)0); | |||||
1448 | char *saveptr = NULL((void*)0); | |||||
1449 | char *trans_type = NULL((void*)0); | |||||
1450 | char *str = NULL((void*)0); | |||||
1451 | char *username = NULL((void*)0); | |||||
1452 | char *password = NULL((void*)0); | |||||
1453 | #ifdef HAVE_BD_XLATOR | |||||
1454 | char *device = NULL((void*)0); | |||||
1455 | #endif | |||||
1456 | ||||||
1457 | this = THIS(*__glusterfs_this_location()); | |||||
1458 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-volume-ops.c" , __FUNCTION__, 1458, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
1459 | ||||||
1460 | priv = this->private; | |||||
1461 | GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: " "priv"); } while (0); _gf_log_callingfn ("", "glusterd-volume-ops.c" , __FUNCTION__, 1461, GF_LOG_ERROR, "Assertion failed: " "priv" ); } while (0); } } while (0); | |||||
1462 | ||||||
1463 | ret = glusterd_volinfo_new (&volinfo); | |||||
1464 | ||||||
1465 | if (ret) { | |||||
1466 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("Unable to allocate memory for volinfo" ); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1467, GF_LOG_ERROR, "Unable to allocate memory for volinfo" ); } while (0) | |||||
1467 | "Unable to allocate memory for volinfo")do { do { if (0) printf ("Unable to allocate memory for volinfo" ); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1467, GF_LOG_ERROR, "Unable to allocate memory for volinfo" ); } while (0); | |||||
1468 | goto out; | |||||
1469 | } | |||||
1470 | ||||||
1471 | ret = dict_get_str (dict, "volname", &volname); | |||||
1472 | ||||||
1473 | if (ret) { | |||||
1474 | gf_log (this->name, GF_LOG_ERROR, "Unable to get volume name")do { do { if (0) printf ("Unable to get volume name"); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__ , 1474, GF_LOG_ERROR, "Unable to get volume name"); } while ( 0); | |||||
1475 | goto out; | |||||
1476 | } | |||||
1477 | ||||||
1478 | strncpy (volinfo->volname, volname, GLUSTERD_MAX_VOLUME_NAME1000); | |||||
1479 | GF_ASSERT (volinfo->volname)do { if (!(volinfo->volname)) { do { do { if (0) printf ("Assertion failed: " "volinfo->volname"); } while (0); _gf_log_callingfn ("", "glusterd-volume-ops.c" , __FUNCTION__, 1479, GF_LOG_ERROR, "Assertion failed: " "volinfo->volname" ); } while (0); } } while (0); | |||||
1480 | ||||||
1481 | ret = dict_get_int32 (dict, "type", &volinfo->type); | |||||
1482 | if (ret) { | |||||
1483 | gf_log (this->name, GF_LOG_ERROR, "Unable to get type of volume"do { do { if (0) printf ("Unable to get type of volume" " %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1484, GF_LOG_ERROR, "Unable to get type of volume" " %s", volname); } while (0) | |||||
1484 | " %s", volname)do { do { if (0) printf ("Unable to get type of volume" " %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1484, GF_LOG_ERROR, "Unable to get type of volume" " %s", volname); } while (0); | |||||
1485 | goto out; | |||||
1486 | } | |||||
1487 | ||||||
1488 | ret = dict_get_int32 (dict, "count", &volinfo->brick_count); | |||||
1489 | if (ret) { | |||||
1490 | gf_log (this->name, GF_LOG_ERROR, "Unable to get brick count of"do { do { if (0) printf ("Unable to get brick count of" " volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1491, GF_LOG_ERROR, "Unable to get brick count of" " volume %s", volname); } while (0) | |||||
1491 | " volume %s", volname)do { do { if (0) printf ("Unable to get brick count of" " volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1491, GF_LOG_ERROR, "Unable to get brick count of" " volume %s", volname); } while (0); | |||||
1492 | goto out; | |||||
1493 | } | |||||
1494 | ||||||
1495 | ret = dict_get_int32 (dict, "port", &volinfo->port); | |||||
1496 | if (ret) { | |||||
1497 | gf_log (this->name, GF_LOG_ERROR, "Unable to get port")do { do { if (0) printf ("Unable to get port"); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__, 1497, GF_LOG_ERROR, "Unable to get port"); } while (0); | |||||
1498 | goto out; | |||||
1499 | } | |||||
1500 | ||||||
1501 | count = volinfo->brick_count; | |||||
1502 | ||||||
1503 | ret = dict_get_str (dict, "bricks", &bricks); | |||||
1504 | if (ret) { | |||||
1505 | gf_log (this->name, GF_LOG_ERROR, "Unable to get bricks for "do { do { if (0) printf ("Unable to get bricks for " "volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1506, GF_LOG_ERROR, "Unable to get bricks for " "volume %s", volname); } while (0) | |||||
1506 | "volume %s", volname)do { do { if (0) printf ("Unable to get bricks for " "volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1506, GF_LOG_ERROR, "Unable to get bricks for " "volume %s", volname); } while (0); | |||||
1507 | goto out; | |||||
1508 | } | |||||
1509 | ||||||
1510 | #ifdef HAVE_BD_XLATOR | |||||
1511 | ret = dict_get_str (dict, "device", &device); | |||||
1512 | if (!ret) | |||||
1513 | volinfo->backend = GD_VOL_BK_BD; | |||||
1514 | #endif | |||||
1515 | ||||||
1516 | /* replica-count 1 means, no replication, file is in one brick only */ | |||||
1517 | volinfo->replica_count = 1; | |||||
1518 | /* stripe-count 1 means, no striping, file is present as a whole */ | |||||
1519 | volinfo->stripe_count = 1; | |||||
1520 | ||||||
1521 | if (GF_CLUSTER_TYPE_REPLICATE == volinfo->type) { | |||||
1522 | ret = dict_get_int32 (dict, "replica-count", | |||||
1523 | &volinfo->replica_count); | |||||
1524 | if (ret) { | |||||
1525 | gf_log (this->name, GF_LOG_ERROR, "Failed to get "do { do { if (0) printf ("Failed to get " "replica count for volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1526, GF_LOG_ERROR, "Failed to get " "replica count for volume %s" , volname); } while (0) | |||||
1526 | "replica count for volume %s", volname)do { do { if (0) printf ("Failed to get " "replica count for volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1526, GF_LOG_ERROR, "Failed to get " "replica count for volume %s" , volname); } while (0); | |||||
1527 | goto out; | |||||
1528 | } | |||||
1529 | } else if (GF_CLUSTER_TYPE_STRIPE == volinfo->type) { | |||||
1530 | ret = dict_get_int32 (dict, "stripe-count", | |||||
1531 | &volinfo->stripe_count); | |||||
1532 | if (ret) { | |||||
1533 | gf_log (this->name, GF_LOG_ERROR, "Failed to get stripe"do { do { if (0) printf ("Failed to get stripe" " count for volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1534, GF_LOG_ERROR, "Failed to get stripe" " count for volume %s" , volname); } while (0) | |||||
1534 | " count for volume %s", volname)do { do { if (0) printf ("Failed to get stripe" " count for volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1534, GF_LOG_ERROR, "Failed to get stripe" " count for volume %s" , volname); } while (0); | |||||
1535 | goto out; | |||||
1536 | } | |||||
1537 | } else if (GF_CLUSTER_TYPE_STRIPE_REPLICATE == volinfo->type) { | |||||
1538 | ret = dict_get_int32 (dict, "stripe-count", | |||||
1539 | &volinfo->stripe_count); | |||||
1540 | if (ret) { | |||||
1541 | gf_log (this->name, GF_LOG_ERROR, "Failed to get stripe"do { do { if (0) printf ("Failed to get stripe" " count for volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1542, GF_LOG_ERROR, "Failed to get stripe" " count for volume %s" , volname); } while (0) | |||||
1542 | " count for volume %s", volname)do { do { if (0) printf ("Failed to get stripe" " count for volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1542, GF_LOG_ERROR, "Failed to get stripe" " count for volume %s" , volname); } while (0); | |||||
1543 | goto out; | |||||
1544 | } | |||||
1545 | ret = dict_get_int32 (dict, "replica-count", | |||||
1546 | &volinfo->replica_count); | |||||
1547 | if (ret) { | |||||
1548 | gf_log (this->name, GF_LOG_ERROR, "Failed to get "do { do { if (0) printf ("Failed to get " "replica count for volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1549, GF_LOG_ERROR, "Failed to get " "replica count for volume %s" , volname); } while (0) | |||||
1549 | "replica count for volume %s", volname)do { do { if (0) printf ("Failed to get " "replica count for volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1549, GF_LOG_ERROR, "Failed to get " "replica count for volume %s" , volname); } while (0); | |||||
1550 | goto out; | |||||
1551 | } | |||||
1552 | } | |||||
1553 | ||||||
1554 | /* dist-leaf-count is the count of brick nodes for a given | |||||
1555 | subvolume of distribute */ | |||||
1556 | volinfo->dist_leaf_count = glusterd_get_dist_leaf_count (volinfo); | |||||
1557 | ||||||
1558 | /* subvol_count is the count of number of subvolumes present | |||||
1559 | for a given distribute volume */ | |||||
1560 | volinfo->subvol_count = (volinfo->brick_count / | |||||
1561 | volinfo->dist_leaf_count); | |||||
1562 | ||||||
1563 | /* Keep sub-count same as earlier, for the sake of backward | |||||
1564 | compatibility */ | |||||
1565 | if (volinfo->dist_leaf_count > 1) | |||||
1566 | volinfo->sub_count = volinfo->dist_leaf_count; | |||||
1567 | ||||||
1568 | ret = dict_get_str (dict, "transport", &trans_type); | |||||
1569 | if (ret) { | |||||
1570 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("Unable to get transport type of volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1571, GF_LOG_ERROR, "Unable to get transport type of volume %s" , volname); } while (0) | |||||
1571 | "Unable to get transport type of volume %s", volname)do { do { if (0) printf ("Unable to get transport type of volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1571, GF_LOG_ERROR, "Unable to get transport type of volume %s" , volname); } while (0); | |||||
1572 | goto out; | |||||
1573 | } | |||||
1574 | ||||||
1575 | ret = dict_get_str (dict, "volume-id", &str); | |||||
1576 | if (ret) { | |||||
1577 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("Unable to get volume-id of volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1578, GF_LOG_ERROR, "Unable to get volume-id of volume %s" , volname); } while (0) | |||||
1578 | "Unable to get volume-id of volume %s", volname)do { do { if (0) printf ("Unable to get volume-id of volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1578, GF_LOG_ERROR, "Unable to get volume-id of volume %s" , volname); } while (0); | |||||
1579 | goto out; | |||||
1580 | } | |||||
1581 | ret = uuid_parse (str, volinfo->volume_id); | |||||
1582 | if (ret) { | |||||
1583 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("unable to parse uuid %s of volume %s" , str, volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1584, GF_LOG_ERROR, "unable to parse uuid %s of volume %s" , str, volname); } while (0) | |||||
1584 | "unable to parse uuid %s of volume %s", str, volname)do { do { if (0) printf ("unable to parse uuid %s of volume %s" , str, volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1584, GF_LOG_ERROR, "unable to parse uuid %s of volume %s" , str, volname); } while (0); | |||||
1585 | goto out; | |||||
1586 | } | |||||
1587 | ||||||
1588 | ret = dict_get_str (dict, "internal-username", &username); | |||||
1589 | if (ret) { | |||||
1590 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("unable to get internal username of volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1592, GF_LOG_ERROR, "unable to get internal username of volume %s" , volname); } while (0) | |||||
1591 | "unable to get internal username of volume %s",do { do { if (0) printf ("unable to get internal username of volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1592, GF_LOG_ERROR, "unable to get internal username of volume %s" , volname); } while (0) | |||||
1592 | volname)do { do { if (0) printf ("unable to get internal username of volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1592, GF_LOG_ERROR, "unable to get internal username of volume %s" , volname); } while (0); | |||||
1593 | goto out; | |||||
1594 | } | |||||
1595 | glusterd_auth_set_username (volinfo, username); | |||||
1596 | ||||||
1597 | ret = dict_get_str (dict, "internal-password", &password); | |||||
1598 | if (ret) { | |||||
1599 | gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("unable to get internal password of volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1601, GF_LOG_ERROR, "unable to get internal password of volume %s" , volname); } while (0) | |||||
1600 | "unable to get internal password of volume %s",do { do { if (0) printf ("unable to get internal password of volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1601, GF_LOG_ERROR, "unable to get internal password of volume %s" , volname); } while (0) | |||||
1601 | volname)do { do { if (0) printf ("unable to get internal password of volume %s" , volname); } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1601, GF_LOG_ERROR, "unable to get internal password of volume %s" , volname); } while (0); | |||||
1602 | goto out; | |||||
1603 | } | |||||
1604 | glusterd_auth_set_password (volinfo, password); | |||||
1605 | ||||||
1606 | if (strcasecmp (trans_type, "rdma") == 0) { | |||||
1607 | volinfo->transport_type = GF_TRANSPORT_RDMA; | |||||
1608 | volinfo->nfs_transport_type = GF_TRANSPORT_RDMA; | |||||
1609 | } else if (strcasecmp (trans_type, "tcp") == 0) { | |||||
1610 | volinfo->transport_type = GF_TRANSPORT_TCP; | |||||
1611 | volinfo->nfs_transport_type = GF_TRANSPORT_TCP; | |||||
1612 | } else { | |||||
1613 | volinfo->transport_type = GF_TRANSPORT_BOTH_TCP_RDMA; | |||||
1614 | volinfo->nfs_transport_type = GF_DEFAULT_NFS_TRANSPORTGF_TRANSPORT_RDMA; | |||||
1615 | } | |||||
1616 | ||||||
1617 | if (bricks) { | |||||
1618 | brick_list = gf_strdup (bricks); | |||||
1619 | free_ptr = brick_list; | |||||
1620 | } | |||||
1621 | ||||||
1622 | if (count) | |||||
1623 | brick = strtok_r (brick_list+1, " \n", &saveptr); | |||||
1624 | ||||||
1625 | while ( i <= count) { | |||||
1626 | ret = glusterd_brickinfo_new_from_brick (brick, &brickinfo); | |||||
1627 | if (ret) | |||||
1628 | goto out; | |||||
1629 | ||||||
1630 | ret = glusterd_resolve_brick (brickinfo); | |||||
1631 | if (ret) { | |||||
1632 | gf_log (this->name, GF_LOG_ERROR, FMTSTR_RESOLVE_BRICK,do { do { if (0) printf ("Could not find peer on which brick %s:%s resides" , brickinfo->hostname, brickinfo->path); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__, 1633, GF_LOG_ERROR, "Could not find peer on which brick %s:%s resides" , brickinfo->hostname, brickinfo->path); } while (0) | |||||
1633 | brickinfo->hostname, brickinfo->path)do { do { if (0) printf ("Could not find peer on which brick %s:%s resides" , brickinfo->hostname, brickinfo->path); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__, 1633, GF_LOG_ERROR, "Could not find peer on which brick %s:%s resides" , brickinfo->hostname, brickinfo->path); } while (0); | |||||
1634 | goto out; | |||||
1635 | } | |||||
1636 | list_add_tail (&brickinfo->brick_list, &volinfo->bricks); | |||||
1637 | brick = strtok_r (NULL((void*)0), " \n", &saveptr); | |||||
1638 | i++; | |||||
1639 | } | |||||
1640 | ||||||
1641 | ret = glusterd_store_volinfo (volinfo, GLUSTERD_VOLINFO_VER_AC_INCREMENT); | |||||
1642 | if (ret) { | |||||
1643 | glusterd_store_delete_volume (volinfo); | |||||
1644 | *op_errstr = gf_strdup ("Failed to store the Volume information"); | |||||
1645 | goto out; | |||||
1646 | } | |||||
1647 | ||||||
1648 | ret = glusterd_create_volfiles_and_notify_services (volinfo); | |||||
1649 | if (ret) { | |||||
1650 | *op_errstr = gf_strdup ("Failed to create volume files"); | |||||
1651 | goto out; | |||||
1652 | } | |||||
1653 | ||||||
1654 | volinfo->rebal.defrag_status = 0; | |||||
1655 | list_add_tail (&volinfo->vol_list, &priv->volumes); | |||||
1656 | vol_added = _gf_true; | |||||
1657 | ||||||
1658 | gd_update_volume_op_versions (volinfo); | |||||
1659 | out: | |||||
1660 | GF_FREE(free_ptr)__gf_free (free_ptr); | |||||
1661 | if (!vol_added && volinfo) | |||||
1662 | glusterd_volinfo_delete (volinfo); | |||||
1663 | return ret; | |||||
1664 | } | |||||
1665 | ||||||
1666 | int | |||||
1667 | glusterd_op_start_volume (dict_t *dict, char **op_errstr) | |||||
1668 | { | |||||
1669 | int ret = 0; | |||||
1670 | char *volname = NULL((void*)0); | |||||
1671 | int flags = 0; | |||||
1672 | glusterd_volinfo_t *volinfo = NULL((void*)0); | |||||
1673 | glusterd_brickinfo_t *brickinfo = NULL((void*)0); | |||||
1674 | xlator_t *this = NULL((void*)0); | |||||
1675 | ||||||
1676 | this = THIS(*__glusterfs_this_location()); | |||||
1677 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-volume-ops.c" , __FUNCTION__, 1677, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
1678 | ||||||
1679 | ret = glusterd_op_start_volume_args_get (dict, &volname, &flags)glusterd_op_stop_volume_args_get (dict, &volname, &flags ); | |||||
1680 | if (ret) | |||||
1681 | goto out; | |||||
1682 | ||||||
1683 | ret = glusterd_volinfo_find (volname, &volinfo); | |||||
1684 | if (ret) { | |||||
1685 | gf_log (this->name, GF_LOG_ERROR, FMTSTR_CHECK_VOL_EXISTS,do { do { if (0) printf ("Volume %s does not exist", volname) ; } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1686, GF_LOG_ERROR, "Volume %s does not exist" , volname); } while (0) | |||||
1686 | volname)do { do { if (0) printf ("Volume %s does not exist", volname) ; } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1686, GF_LOG_ERROR, "Volume %s does not exist" , volname); } while (0); | |||||
1687 | goto out; | |||||
1688 | } | |||||
1689 | ||||||
1690 | list_for_each_entry (brickinfo, &volinfo->bricks, brick_list)for (brickinfo = ((typeof(*brickinfo) *)((char *)((&volinfo ->bricks)->next)-(unsigned long)(&((typeof(*brickinfo ) *)0)->brick_list))); &brickinfo->brick_list != (& volinfo->bricks); brickinfo = ((typeof(*brickinfo) *)((char *)(brickinfo->brick_list.next)-(unsigned long)(&((typeof (*brickinfo) *)0)->brick_list)))) { | |||||
1691 | ret = glusterd_brick_start (volinfo, brickinfo, _gf_true); | |||||
1692 | if (ret) | |||||
1693 | goto out; | |||||
1694 | } | |||||
1695 | ||||||
1696 | glusterd_set_volume_status (volinfo, GLUSTERD_STATUS_STARTED); | |||||
1697 | ||||||
1698 | ret = glusterd_store_volinfo (volinfo, GLUSTERD_VOLINFO_VER_AC_INCREMENT); | |||||
1699 | if (ret) | |||||
1700 | goto out; | |||||
1701 | ||||||
1702 | ret = glusterd_nodesvcs_handle_graph_change (volinfo); | |||||
1703 | ||||||
1704 | out: | |||||
1705 | gf_log (this->name, GF_LOG_DEBUG, "returning %d ", ret)do { do { if (0) printf ("returning %d ", ret); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__, 1705, GF_LOG_DEBUG, "returning %d ", ret); } while (0); | |||||
1706 | return ret; | |||||
1707 | } | |||||
1708 | ||||||
1709 | ||||||
1710 | int | |||||
1711 | glusterd_op_stop_volume (dict_t *dict) | |||||
1712 | { | |||||
1713 | int ret = 0; | |||||
1714 | int flags = 0; | |||||
1715 | char *volname = NULL((void*)0); | |||||
1716 | glusterd_volinfo_t *volinfo = NULL((void*)0); | |||||
1717 | glusterd_brickinfo_t *brickinfo = NULL((void*)0); | |||||
1718 | xlator_t *this = NULL((void*)0); | |||||
1719 | ||||||
1720 | this = THIS(*__glusterfs_this_location()); | |||||
1721 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-volume-ops.c" , __FUNCTION__, 1721, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
1722 | ||||||
1723 | ret = glusterd_op_stop_volume_args_get (dict, &volname, &flags); | |||||
1724 | if (ret) | |||||
1725 | goto out; | |||||
1726 | ||||||
1727 | ret = glusterd_volinfo_find (volname, &volinfo); | |||||
1728 | if (ret) { | |||||
1729 | gf_log (this->name, GF_LOG_ERROR, FMTSTR_CHECK_VOL_EXISTS,do { do { if (0) printf ("Volume %s does not exist", volname) ; } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1730, GF_LOG_ERROR, "Volume %s does not exist" , volname); } while (0) | |||||
1730 | volname)do { do { if (0) printf ("Volume %s does not exist", volname) ; } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1730, GF_LOG_ERROR, "Volume %s does not exist" , volname); } while (0); | |||||
1731 | goto out; | |||||
1732 | } | |||||
1733 | ||||||
1734 | list_for_each_entry (brickinfo, &volinfo->bricks, brick_list)for (brickinfo = ((typeof(*brickinfo) *)((char *)((&volinfo ->bricks)->next)-(unsigned long)(&((typeof(*brickinfo ) *)0)->brick_list))); &brickinfo->brick_list != (& volinfo->bricks); brickinfo = ((typeof(*brickinfo) *)((char *)(brickinfo->brick_list.next)-(unsigned long)(&((typeof (*brickinfo) *)0)->brick_list)))) { | |||||
1735 | ret = glusterd_brick_stop (volinfo, brickinfo, _gf_false); | |||||
1736 | if (ret) | |||||
1737 | goto out; | |||||
1738 | } | |||||
1739 | ||||||
1740 | glusterd_set_volume_status (volinfo, GLUSTERD_STATUS_STOPPED); | |||||
1741 | ||||||
1742 | ret = glusterd_store_volinfo (volinfo, GLUSTERD_VOLINFO_VER_AC_INCREMENT); | |||||
1743 | if (ret) | |||||
1744 | goto out; | |||||
1745 | ||||||
1746 | ret = glusterd_nodesvcs_handle_graph_change (volinfo); | |||||
1747 | out: | |||||
1748 | return ret; | |||||
1749 | } | |||||
1750 | ||||||
1751 | int | |||||
1752 | glusterd_op_delete_volume (dict_t *dict) | |||||
1753 | { | |||||
1754 | int ret = 0; | |||||
1755 | char *volname = NULL((void*)0); | |||||
1756 | glusterd_conf_t *priv = NULL((void*)0); | |||||
1757 | glusterd_volinfo_t *volinfo = NULL((void*)0); | |||||
1758 | xlator_t *this = NULL((void*)0); | |||||
1759 | ||||||
1760 | this = THIS(*__glusterfs_this_location()); | |||||
1761 | GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: " "this"); } while (0); _gf_log_callingfn ("", "glusterd-volume-ops.c" , __FUNCTION__, 1761, GF_LOG_ERROR, "Assertion failed: " "this" ); } while (0); } } while (0); | |||||
1762 | priv = this->private; | |||||
1763 | GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: " "priv"); } while (0); _gf_log_callingfn ("", "glusterd-volume-ops.c" , __FUNCTION__, 1763, GF_LOG_ERROR, "Assertion failed: " "priv" ); } while (0); } } while (0); | |||||
1764 | ||||||
1765 | ret = dict_get_str (dict, "volname", &volname); | |||||
1766 | if (ret) { | |||||
1767 | gf_log (this->name, GF_LOG_ERROR, "Unable to get volume name")do { do { if (0) printf ("Unable to get volume name"); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__ , 1767, GF_LOG_ERROR, "Unable to get volume name"); } while ( 0); | |||||
1768 | goto out; | |||||
1769 | } | |||||
1770 | ||||||
1771 | ret = glusterd_volinfo_find (volname, &volinfo); | |||||
1772 | if (ret) { | |||||
1773 | gf_log (this->name, GF_LOG_ERROR, FMTSTR_CHECK_VOL_EXISTS,do { do { if (0) printf ("Volume %s does not exist", volname) ; } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1774, GF_LOG_ERROR, "Volume %s does not exist" , volname); } while (0) | |||||
1774 | volname)do { do { if (0) printf ("Volume %s does not exist", volname) ; } while (0); _gf_log (this->name, "glusterd-volume-ops.c" , __FUNCTION__, 1774, GF_LOG_ERROR, "Volume %s does not exist" , volname); } while (0); | |||||
1775 | goto out; | |||||
1776 | } | |||||
1777 | ||||||
1778 | ret = glusterd_delete_volume (volinfo); | |||||
1779 | out: | |||||
1780 | gf_log (this->name, GF_LOG_DEBUG, "returning %d", ret)do { do { if (0) printf ("returning %d", ret); } while (0); _gf_log (this->name, "glusterd-volume-ops.c", __FUNCTION__, 1780, GF_LOG_DEBUG, "returning %d", ret); } while (0); | |||||
1781 | return ret; | |||||
1782 | } | |||||
1783 | ||||||
1784 | int | |||||
1785 | glusterd_op_heal_volume (dict_t *dict, char **op_errstr) | |||||
1786 | { | |||||
1787 | int ret = 0; | |||||
1788 | /* Necessary subtasks of heal are completed in brick op */ | |||||
1789 | ||||||
1790 | return ret; | |||||
1791 | } | |||||
1792 | ||||||
1793 | int | |||||
1794 | glusterd_op_statedump_volume (dict_t *dict, char **op_errstr) | |||||
1795 | { | |||||
1796 | int ret = 0; | |||||
1797 | char *volname = NULL((void*)0); | |||||
1798 | char *options = NULL((void*)0); | |||||
1799 | int option_cnt = 0; | |||||
1800 | glusterd_volinfo_t *volinfo = NULL((void*)0); | |||||
1801 | glusterd_brickinfo_t *brickinfo = NULL((void*)0); | |||||
1802 | ||||||
1803 | ret = glusterd_op_statedump_volume_args_get (dict, &volname, &options, | |||||
1804 | &option_cnt); | |||||
1805 | if (ret) | |||||
1806 | goto out; | |||||
1807 | ||||||
1808 | ret = glusterd_volinfo_find (volname, &volinfo); | |||||
1809 | if (ret) | |||||
1810 | goto out; | |||||
1811 | gf_log ("", GF_LOG_DEBUG, "Performing statedump on volume %s", volname)do { do { if (0) printf ("Performing statedump on volume %s", volname); } while (0); _gf_log ("", "glusterd-volume-ops.c", __FUNCTION__, 1811, GF_LOG_DEBUG, "Performing statedump on volume %s" , volname); } while (0); | |||||
1812 | if (strstr (options, "nfs") != NULL((void*)0)) { | |||||
1813 | ret = glusterd_nfs_statedump (options, option_cnt, op_errstr); | |||||
1814 | if (ret) | |||||
1815 | goto out; | |||||
1816 | } else { | |||||
1817 | list_for_each_entry (brickinfo, &volinfo->bricks,for (brickinfo = ((typeof(*brickinfo) *)((char *)((&volinfo ->bricks)->next)-(unsigned long)(&((typeof(*brickinfo ) *)0)->brick_list))); &brickinfo->brick_list != (& volinfo->bricks); brickinfo = ((typeof(*brickinfo) *)((char *)(brickinfo->brick_list.next)-(unsigned long)(&((typeof (*brickinfo) *)0)->brick_list)))) | |||||
1818 | brick_list)for (brickinfo = ((typeof(*brickinfo) *)((char *)((&volinfo ->bricks)->next)-(unsigned long)(&((typeof(*brickinfo ) *)0)->brick_list))); &brickinfo->brick_list != (& volinfo->bricks); brickinfo = ((typeof(*brickinfo) *)((char *)(brickinfo->brick_list.next)-(unsigned long)(&((typeof (*brickinfo) *)0)->brick_list)))) { | |||||
1819 | ret = glusterd_brick_statedump (volinfo, brickinfo, | |||||
1820 | options, option_cnt, | |||||
1821 | op_errstr); | |||||
1822 | /* Let us take the statedump of other bricks instead of | |||||
1823 | * exiting, if statedump of this brick fails. | |||||
1824 | */ | |||||
1825 | if (ret) | |||||
1826 | gf_log (THIS->name, GF_LOG_WARNING, "could not "do { do { if (0) printf ("could not " "take the statedump of the brick %s:%s." " Proceeding to other bricks", brickinfo->hostname, brickinfo ->path); } while (0); _gf_log ((*__glusterfs_this_location ())->name, "glusterd-volume-ops.c", __FUNCTION__, 1829, GF_LOG_WARNING , "could not " "take the statedump of the brick %s:%s." " Proceeding to other bricks" , brickinfo->hostname, brickinfo->path); } while (0) | |||||
1827 | "take the statedump of the brick %s:%s."do { do { if (0) printf ("could not " "take the statedump of the brick %s:%s." " Proceeding to other bricks", brickinfo->hostname, brickinfo ->path); } while (0); _gf_log ((*__glusterfs_this_location ())->name, "glusterd-volume-ops.c", __FUNCTION__, 1829, GF_LOG_WARNING , "could not " "take the statedump of the brick %s:%s." " Proceeding to other bricks" , brickinfo->hostname, brickinfo->path); } while (0) | |||||
1828 | " Proceeding to other bricks",do { do { if (0) printf ("could not " "take the statedump of the brick %s:%s." " Proceeding to other bricks", brickinfo->hostname, brickinfo ->path); } while (0); _gf_log ((*__glusterfs_this_location ())->name, "glusterd-volume-ops.c", __FUNCTION__, 1829, GF_LOG_WARNING , "could not " "take the statedump of the brick %s:%s." " Proceeding to other bricks" , brickinfo->hostname, brickinfo->path); } while (0) | |||||
1829 | brickinfo->hostname, brickinfo->path)do { do { if (0) printf ("could not " "take the statedump of the brick %s:%s." " Proceeding to other bricks", brickinfo->hostname, brickinfo ->path); } while (0); _gf_log ((*__glusterfs_this_location ())->name, "glusterd-volume-ops.c", __FUNCTION__, 1829, GF_LOG_WARNING , "could not " "take the statedump of the brick %s:%s." " Proceeding to other bricks" , brickinfo->hostname, brickinfo->path); } while (0); | |||||
1830 | } | |||||
1831 | } | |||||
1832 | ||||||
1833 | out: | |||||
1834 | return ret; | |||||
1835 | } | |||||
1836 | ||||||
1837 | int | |||||
1838 | glusterd_clearlocks_send_cmd (glusterd_volinfo_t *volinfo, char *cmd, | |||||
1839 | char *path, char *result, char *errstr, | |||||
1840 | int err_len, char *mntpt) | |||||
1841 | { | |||||
1842 | int ret = -1; | |||||
1843 | glusterd_conf_t *priv = NULL((void*)0); | |||||
1844 | char abspath[PATH_MAX4096] = {0, }; | |||||
1845 | ||||||
1846 | priv = THIS(*__glusterfs_this_location())->private; | |||||
1847 | ||||||
1848 | snprintf (abspath, sizeof (abspath), "%s/%s", mntpt, path); | |||||
1849 | ret = sys_lgetxattr (abspath, cmd, result, PATH_MAX4096); | |||||
1850 | if (ret < 0) { | |||||
1851 | snprintf (errstr, err_len, "clear-locks getxattr command " | |||||
1852 | "failed. Reason: %s", strerror (errno(*__errno_location ()))); | |||||
1853 | gf_log (THIS->name, GF_LOG_DEBUG, "%s", errstr)do { do { if (0) printf ("%s", errstr); } while (0); _gf_log ( (*__glusterfs_this_location())->name, "glusterd-volume-ops.c" , __FUNCTION__, 1853, GF_LOG_DEBUG, "%s", errstr); } while (0 ); | |||||
1854 | goto out; | |||||
1855 | } | |||||
1856 | ||||||
1857 | ret = 0; | |||||
1858 | out: | |||||
1859 | return ret; | |||||
1860 | } | |||||
1861 | ||||||
1862 | int | |||||
1863 | glusterd_clearlocks_rmdir_mount (glusterd_volinfo_t *volinfo, char *mntpt) | |||||
1864 | { | |||||
1865 | int ret = -1; | |||||
1866 | glusterd_conf_t *priv = NULL((void*)0); | |||||
1867 | ||||||
1868 | priv = THIS(*__glusterfs_this_location())->private; | |||||
1869 | ||||||
1870 | ret = rmdir (mntpt); | |||||
1871 | if (ret) { | |||||
1872 | gf_log (THIS->name, GF_LOG_DEBUG, "rmdir failed")do { do { if (0) printf ("rmdir failed"); } while (0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-volume-ops.c" , __FUNCTION__, 1872, GF_LOG_DEBUG, "rmdir failed"); } while ( 0); | |||||
1873 | goto out; | |||||
1874 | } | |||||
1875 | ||||||
1876 | ret = 0; | |||||
1877 | out: | |||||
1878 | return ret; | |||||
1879 | } | |||||
1880 | ||||||
1881 | void | |||||
1882 | glusterd_clearlocks_unmount (glusterd_volinfo_t *volinfo, char *mntpt) | |||||
1883 | { | |||||
1884 | glusterd_conf_t *priv = NULL((void*)0); | |||||
1885 | runner_t runner = {0,}; | |||||
1886 | int ret = 0; | |||||
1887 | ||||||
1888 | priv = THIS(*__glusterfs_this_location())->private; | |||||
1889 | ||||||
1890 | /*umount failures are ignored. Using stat we could have avoided | |||||
1891 | * attempting to unmount a non-existent filesystem. But a failure of | |||||
1892 | * stat() on mount can be due to network failures.*/ | |||||
1893 | ||||||
1894 | runinit (&runner); | |||||
1895 | runner_add_args (&runner, "/bin/umount", "-f", NULL((void*)0)); | |||||
1896 | runner_argprintf (&runner, "%s", mntpt); | |||||
1897 | ||||||
1898 | synclock_unlock (&priv->big_lock); | |||||
1899 | ret = runner_run (&runner); | |||||
1900 | synclock_lock (&priv->big_lock); | |||||
1901 | if (ret) { | |||||
1902 | ret = 0; | |||||
1903 | gf_log ("", GF_LOG_DEBUG,do { do { if (0) printf ("umount failed on maintenance client" ); } while (0); _gf_log ("", "glusterd-volume-ops.c", __FUNCTION__ , 1904, GF_LOG_DEBUG, "umount failed on maintenance client"); } while (0) | |||||
1904 | "umount failed on maintenance client")do { do { if (0) printf ("umount failed on maintenance client" ); } while (0); _gf_log ("", "glusterd-volume-ops.c", __FUNCTION__ , 1904, GF_LOG_DEBUG, "umount failed on maintenance client"); } while (0); | |||||
1905 | } | |||||
1906 | ||||||
1907 | return; | |||||
1908 | } | |||||
1909 | ||||||
1910 | int | |||||
1911 | glusterd_clearlocks_create_mount (glusterd_volinfo_t *volinfo, char **mntpt) | |||||
1912 | { | |||||
1913 | int ret = -1; | |||||
1914 | glusterd_conf_t *priv = NULL((void*)0); | |||||
1915 | char template[PATH_MAX4096] = {0,}; | |||||
1916 | char *tmpl = NULL((void*)0); | |||||
1917 | ||||||
1918 | priv = THIS(*__glusterfs_this_location())->private; | |||||
1919 | ||||||
1920 | snprintf (template, sizeof (template), "/tmp/%s.XXXXXX", | |||||
1921 | volinfo->volname); | |||||
1922 | tmpl = mkdtemp (template); | |||||
1923 | if (!tmpl) { | |||||
1924 | gf_log (THIS->name, GF_LOG_DEBUG, "Couldn't create temporary "do { do { if (0) printf ("Couldn't create temporary " "mount directory. Reason %s" , strerror ((*__errno_location ()))); } while (0); _gf_log (( *__glusterfs_this_location())->name, "glusterd-volume-ops.c" , __FUNCTION__, 1925, GF_LOG_DEBUG, "Couldn't create temporary " "mount directory. Reason %s", strerror ((*__errno_location ( )))); } while (0) | |||||
1925 | "mount directory. Reason %s", strerror (errno))do { do { if (0) printf ("Couldn't create temporary " "mount directory. Reason %s" , strerror ((*__errno_location ()))); } while (0); _gf_log (( *__glusterfs_this_location())->name, "glusterd-volume-ops.c" , __FUNCTION__, 1925, GF_LOG_DEBUG, "Couldn't create temporary " "mount directory. Reason %s", strerror ((*__errno_location ( )))); } while (0); | |||||
1926 | goto out; | |||||
1927 | } | |||||
1928 | ||||||
1929 | *mntpt = gf_strdup (tmpl); | |||||
1930 | ret = 0; | |||||
1931 | out: | |||||
1932 | return ret; | |||||
1933 | } | |||||
1934 | ||||||
1935 | int | |||||
1936 | glusterd_clearlocks_mount (glusterd_volinfo_t *volinfo, char **xl_opts, | |||||
1937 | char *mntpt) | |||||
1938 | { | |||||
1939 | int ret = -1; | |||||
1940 | int i = 0; | |||||
1941 | glusterd_conf_t *priv = NULL((void*)0); | |||||
1942 | runner_t runner = {0,}; | |||||
1943 | char client_volfpath[PATH_MAX4096] = {0,}; | |||||
1944 | char self_heal_opts[3][1024] = {"*replicate*.data-self-heal=off", | |||||
1945 | "*replicate*.metadata-self-heal=off", | |||||
1946 | "*replicate*.entry-self-heal=off"}; | |||||
1947 | ||||||
1948 | priv = THIS(*__glusterfs_this_location())->private; | |||||
1949 | ||||||
1950 | runinit (&runner); | |||||
1951 | glusterd_get_trusted_client_filepath (client_volfpath, volinfo, | |||||
1952 | volinfo->transport_type); | |||||
1953 | runner_add_args (&runner, SBIN_DIR"/usr/local/sbin""/glusterfs", "-f", NULL((void*)0)); | |||||
1954 | runner_argprintf (&runner, "%s", client_volfpath); | |||||
1955 | runner_add_arg (&runner, "-l"); | |||||
1956 | runner_argprintf (&runner, DEFAULT_LOG_FILE_DIRECTORY"/usr/local/var" "/log/glusterfs" | |||||
1957 | "/%s-clearlocks-mnt.log", volinfo->volname); | |||||
1958 | if (volinfo->memory_accounting) | |||||
1959 | runner_add_arg (&runner, "--mem-accounting"); | |||||
1960 | ||||||
1961 | for (i = 0; i < volinfo->brick_count && xl_opts[i]; i++) { | |||||
1962 | runner_add_arg (&runner, "--xlator-option"); | |||||
1963 | runner_argprintf (&runner, "%s", xl_opts[i]); | |||||
1964 | } | |||||
1965 | ||||||
1966 | for (i = 0; i < 3; i++) { | |||||
1967 | runner_add_args (&runner, "--xlator-option", | |||||
1968 | self_heal_opts[i], NULL((void*)0)); | |||||
1969 | } | |||||
1970 | ||||||
1971 | runner_argprintf (&runner, "%s", mntpt); | |||||
1972 | synclock_unlock (&priv->big_lock); | |||||
1973 | ret = runner_run (&runner); | |||||
1974 | synclock_lock (&priv->big_lock); | |||||
1975 | if (ret) { | |||||
1976 | gf_log (THIS->name, GF_LOG_DEBUG,do { do { if (0) printf ("Could not start glusterfs"); } while (0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-volume-ops.c" , __FUNCTION__, 1977, GF_LOG_DEBUG, "Could not start glusterfs" ); } while (0) | |||||
1977 | "Could not start glusterfs")do { do { if (0) printf ("Could not start glusterfs"); } while (0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-volume-ops.c" , __FUNCTION__, 1977, GF_LOG_DEBUG, "Could not start glusterfs" ); } while (0); | |||||
1978 | goto out; | |||||
1979 | } | |||||
1980 | gf_log (THIS->name, GF_LOG_DEBUG,do { do { if (0) printf ("Started glusterfs successfully"); } while (0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-volume-ops.c", __FUNCTION__, 1981, GF_LOG_DEBUG, "Started glusterfs successfully" ); } while (0) | |||||
1981 | "Started glusterfs successfully")do { do { if (0) printf ("Started glusterfs successfully"); } while (0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-volume-ops.c", __FUNCTION__, 1981, GF_LOG_DEBUG, "Started glusterfs successfully" ); } while (0); | |||||
1982 | ||||||
1983 | out: | |||||
1984 | return ret; | |||||
1985 | } | |||||
1986 | ||||||
1987 | int | |||||
1988 | glusterd_clearlocks_get_local_client_ports (glusterd_volinfo_t *volinfo, | |||||
1989 | char **xl_opts) | |||||
1990 | { | |||||
1991 | glusterd_brickinfo_t *brickinfo = NULL((void*)0); | |||||
1992 | glusterd_conf_t *priv = NULL((void*)0); | |||||
1993 | int index = 0; | |||||
1994 | int ret = -1; | |||||
1995 | int i = 0; | |||||
1996 | int port = 0; | |||||
1997 | ||||||
1998 | GF_ASSERT (xl_opts)do { if (!(xl_opts)) { do { do { if (0) printf ("Assertion failed: " "xl_opts"); } while (0); _gf_log_callingfn ("", "glusterd-volume-ops.c" , __FUNCTION__, 1998, GF_LOG_ERROR, "Assertion failed: " "xl_opts" ); } while (0); } } while (0); | |||||
1999 | if (!xl_opts) { | |||||
2000 | gf_log (THIS->name, GF_LOG_DEBUG, "Should pass non-NULL "do { do { if (0) printf ("Should pass non-NULL " "xl_opts"); } while (0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-volume-ops.c", __FUNCTION__, 2001, GF_LOG_DEBUG, "Should pass non-NULL " "xl_opts"); } while (0) | |||||
2001 | "xl_opts")do { do { if (0) printf ("Should pass non-NULL " "xl_opts"); } while (0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-volume-ops.c", __FUNCTION__, 2001, GF_LOG_DEBUG, "Should pass non-NULL " "xl_opts"); } while (0); | |||||
2002 | goto out; | |||||
2003 | } | |||||
2004 | ||||||
2005 | priv = THIS(*__glusterfs_this_location())->private; | |||||
2006 | ||||||
2007 | index = -1; | |||||
2008 | list_for_each_entry (brickinfo, &volinfo->bricks, brick_list)for (brickinfo = ((typeof(*brickinfo) *)((char *)((&volinfo ->bricks)->next)-(unsigned long)(&((typeof(*brickinfo ) *)0)->brick_list))); &brickinfo->brick_list != (& volinfo->bricks); brickinfo = ((typeof(*brickinfo) *)((char *)(brickinfo->brick_list.next)-(unsigned long)(&((typeof (*brickinfo) *)0)->brick_list)))) { | |||||
2009 | index++; | |||||
2010 | if (uuid_compare (brickinfo->uuid, MY_UUID(__glusterd_uuid()))) | |||||
2011 | continue; | |||||
2012 | ||||||
2013 | port = pmap_registry_search (THIS(*__glusterfs_this_location()), brickinfo->path, | |||||
2014 | GF_PMAP_PORT_BRICKSERVER); | |||||
2015 | if (!port) { | |||||
2016 | ret = -1; | |||||
2017 | gf_log (THIS->name, GF_LOG_DEBUG, "Couldn't get port "do { do { if (0) printf ("Couldn't get port " " for brick %s:%s" , brickinfo->hostname, brickinfo->path); } while (0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-volume-ops.c" , __FUNCTION__, 2019, GF_LOG_DEBUG, "Couldn't get port " " for brick %s:%s" , brickinfo->hostname, brickinfo->path); } while (0) | |||||
2018 | " for brick %s:%s", brickinfo->hostname,do { do { if (0) printf ("Couldn't get port " " for brick %s:%s" , brickinfo->hostname, brickinfo->path); } while (0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-volume-ops.c" , __FUNCTION__, 2019, GF_LOG_DEBUG, "Couldn't get port " " for brick %s:%s" , brickinfo->hostname, brickinfo->path); } while (0) | |||||
2019 | brickinfo->path)do { do { if (0) printf ("Couldn't get port " " for brick %s:%s" , brickinfo->hostname, brickinfo->path); } while (0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-volume-ops.c" , __FUNCTION__, 2019, GF_LOG_DEBUG, "Couldn't get port " " for brick %s:%s" , brickinfo->hostname, brickinfo->path); } while (0); | |||||
2020 | goto out; | |||||
2021 | } | |||||
2022 | ||||||
2023 | ret = gf_asprintf (&xl_opts[i], "%s-client-%d.remote-port=%d", | |||||
2024 | volinfo->volname, index, port); | |||||
2025 | if (ret == -1) { | |||||
2026 | xl_opts[i] = NULL((void*)0); | |||||
2027 | goto out; | |||||
2028 | } | |||||
2029 | i++; | |||||
2030 | } | |||||
2031 | ||||||
2032 | ret = 0; | |||||
2033 | out: | |||||
2034 | return ret; | |||||
2035 | } | |||||
2036 | ||||||
2037 | int | |||||
2038 | glusterd_op_clearlocks_volume (dict_t *dict, char **op_errstr, dict_t *rsp_dict) | |||||
2039 | { | |||||
2040 | int32_t ret = -1; | |||||
2041 | int i = 0; | |||||
2042 | char *volname = NULL((void*)0); | |||||
2043 | char *path = NULL((void*)0); | |||||
2044 | char *kind = NULL((void*)0); | |||||
2045 | char *type = NULL((void*)0); | |||||
2046 | char *opts = NULL((void*)0); | |||||
2047 | char *cmd_str = NULL((void*)0); | |||||
2048 | char *free_ptr = NULL((void*)0); | |||||
2049 | char msg[PATH_MAX4096] = {0,}; | |||||
2050 | char result[PATH_MAX4096] = {0,}; | |||||
2051 | char *mntpt = NULL((void*)0); | |||||
2052 | char **xl_opts = NULL((void*)0); | |||||
2053 | glusterd_volinfo_t *volinfo = NULL((void*)0); | |||||
2054 | ||||||
2055 | ret = dict_get_str (dict, "volname", &volname); | |||||
2056 | if (ret) { | |||||
2057 | gf_log (THIS->name, GF_LOG_ERROR, "Failed to get volume name")do { do { if (0) printf ("Failed to get volume name"); } while (0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-volume-ops.c" , __FUNCTION__, 2057, GF_LOG_ERROR, "Failed to get volume name" ); } while (0); | |||||
2058 | goto out; | |||||
2059 | } | |||||
2060 | gf_log ("", GF_LOG_DEBUG, "Performing clearlocks on volume %s", volname)do { do { if (0) printf ("Performing clearlocks on volume %s" , volname); } while (0); _gf_log ("", "glusterd-volume-ops.c" , __FUNCTION__, 2060, GF_LOG_DEBUG, "Performing clearlocks on volume %s" , volname); } while (0); | |||||
2061 | ||||||
2062 | ret = dict_get_str (dict, "path", &path); | |||||
2063 | if (ret) { | |||||
2064 | gf_log (THIS->name, GF_LOG_ERROR, "Failed to get path")do { do { if (0) printf ("Failed to get path"); } while (0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-volume-ops.c" , __FUNCTION__, 2064, GF_LOG_ERROR, "Failed to get path"); } while (0); | |||||
2065 | goto out; | |||||
2066 | } | |||||
2067 | ||||||
2068 | ret = dict_get_str (dict, "kind", &kind); | |||||
2069 | if (ret) { | |||||
2070 | gf_log (THIS->name, GF_LOG_ERROR, "Failed to get kind")do { do { if (0) printf ("Failed to get kind"); } while (0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-volume-ops.c" , __FUNCTION__, 2070, GF_LOG_ERROR, "Failed to get kind"); } while (0); | |||||
2071 | goto out; | |||||
2072 | } | |||||
2073 | ||||||
2074 | ret = dict_get_str (dict, "type", &type); | |||||
2075 | if (ret) { | |||||
2076 | gf_log (THIS->name, GF_LOG_ERROR, "Failed to get type")do { do { if (0) printf ("Failed to get type"); } while (0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-volume-ops.c" , __FUNCTION__, 2076, GF_LOG_ERROR, "Failed to get type"); } while (0); | |||||
2077 | goto out; | |||||
2078 | } | |||||
2079 | ||||||
2080 | ret = dict_get_str (dict, "opts", &opts); | |||||
2081 | if (ret) | |||||
2082 | ret = 0; | |||||
2083 | ||||||
2084 | gf_log (THIS->name, GF_LOG_INFO, "Received clear-locks request for "do { do { if (0) printf ("Received clear-locks request for " "volume %s with kind %s type %s and options %s" , volname, kind, type, opts); } while (0); _gf_log ((*__glusterfs_this_location ())->name, "glusterd-volume-ops.c", __FUNCTION__, 2086, GF_LOG_INFO , "Received clear-locks request for " "volume %s with kind %s type %s and options %s" , volname, kind, type, opts); } while (0) | |||||
2085 | "volume %s with kind %s type %s and options %s", volname,do { do { if (0) printf ("Received clear-locks request for " "volume %s with kind %s type %s and options %s" , volname, kind, type, opts); } while (0); _gf_log ((*__glusterfs_this_location ())->name, "glusterd-volume-ops.c", __FUNCTION__, 2086, GF_LOG_INFO , "Received clear-locks request for " "volume %s with kind %s type %s and options %s" , volname, kind, type, opts); } while (0) | |||||
2086 | kind, type, opts)do { do { if (0) printf ("Received clear-locks request for " "volume %s with kind %s type %s and options %s" , volname, kind, type, opts); } while (0); _gf_log ((*__glusterfs_this_location ())->name, "glusterd-volume-ops.c", __FUNCTION__, 2086, GF_LOG_INFO , "Received clear-locks request for " "volume %s with kind %s type %s and options %s" , volname, kind, type, opts); } while (0); | |||||
2087 | ||||||
2088 | if (opts) | |||||
2089 | ret = gf_asprintf (&cmd_str, GF_XATTR_CLRLK_CMD"glusterfs.clrlk"".t%s.k%s.%s", | |||||
2090 | type, kind, opts); | |||||
2091 | else | |||||
2092 | ret = gf_asprintf (&cmd_str, GF_XATTR_CLRLK_CMD"glusterfs.clrlk"".t%s.k%s", | |||||
2093 | type, kind); | |||||
2094 | if (ret == -1) | |||||
2095 | goto out; | |||||
2096 | ||||||
2097 | ret = glusterd_volinfo_find (volname, &volinfo); | |||||
2098 | if (ret) { | |||||
2099 | snprintf (msg, sizeof (msg), "Volume %s doesn't exist.", | |||||
2100 | volname); | |||||
2101 | gf_log (THIS->name, GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log ((* __glusterfs_this_location())->name, "glusterd-volume-ops.c" , __FUNCTION__, 2101, GF_LOG_ERROR, "%s", msg); } while (0); | |||||
2102 | goto out; | |||||
2103 | } | |||||
2104 | ||||||
2105 | xl_opts = GF_CALLOC (volinfo->brick_count+1, sizeof (char*),__gf_calloc (volinfo->brick_count+1, sizeof (char*), gf_gld_mt_charptr ) | |||||
2106 | gf_gld_mt_charptr)__gf_calloc (volinfo->brick_count+1, sizeof (char*), gf_gld_mt_charptr ); | |||||
2107 | if (!xl_opts) | |||||
2108 | goto out; | |||||
2109 | ||||||
2110 | ret = glusterd_clearlocks_get_local_client_ports (volinfo, xl_opts); | |||||
2111 | if (ret) { | |||||
2112 | snprintf (msg, sizeof (msg), "Couldn't get port numbers of " | |||||
2113 | "local bricks"); | |||||
2114 | gf_log (THIS->name, GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log ((* __glusterfs_this_location())->name, "glusterd-volume-ops.c" , __FUNCTION__, 2114, GF_LOG_ERROR, "%s", msg); } while (0); | |||||
2115 | goto out; | |||||
2116 | } | |||||
2117 | ||||||
2118 | ret = glusterd_clearlocks_create_mount (volinfo, &mntpt); | |||||
2119 | if (ret) { | |||||
2120 | snprintf (msg, sizeof (msg), "Creating mount directory " | |||||
2121 | "for clear-locks failed."); | |||||
2122 | gf_log (THIS->name, GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log ((* __glusterfs_this_location())->name, "glusterd-volume-ops.c" , __FUNCTION__, 2122, GF_LOG_ERROR, "%s", msg); } while (0); | |||||
2123 | goto out; | |||||
2124 | } | |||||
2125 | ||||||
2126 | ret = glusterd_clearlocks_mount (volinfo, xl_opts, mntpt); | |||||
2127 | if (ret) { | |||||
2128 | snprintf (msg, sizeof (msg), "Failed to mount clear-locks " | |||||
2129 | "maintenance client."); | |||||
2130 | gf_log (THIS->name, GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log ((* __glusterfs_this_location())->name, "glusterd-volume-ops.c" , __FUNCTION__, 2130, GF_LOG_ERROR, "%s", msg); } while (0); | |||||
2131 | goto out; | |||||
2132 | } | |||||
2133 | ||||||
2134 | ret = glusterd_clearlocks_send_cmd (volinfo, cmd_str, path, result, | |||||
2135 | msg, sizeof (msg), mntpt); | |||||
2136 | if (ret) { | |||||
2137 | gf_log (THIS->name, GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log ((* __glusterfs_this_location())->name, "glusterd-volume-ops.c" , __FUNCTION__, 2137, GF_LOG_ERROR, "%s", msg); } while (0); | |||||
2138 | goto umount; | |||||
2139 | } | |||||
2140 | ||||||
2141 | free_ptr = gf_strdup(result); | |||||
2142 | if (dict_set_dynstr (rsp_dict, "lk-summary", free_ptr)) { | |||||
2143 | GF_FREE (free_ptr)__gf_free (free_ptr); | |||||
2144 | snprintf (msg, sizeof (msg), "Failed to set clear-locks " | |||||
2145 | "result"); | |||||
2146 | gf_log (THIS->name, GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log ((* __glusterfs_this_location())->name, "glusterd-volume-ops.c" , __FUNCTION__, 2146, GF_LOG_ERROR, "%s", msg); } while (0); | |||||
2147 | } | |||||
2148 | ||||||
2149 | umount: | |||||
2150 | glusterd_clearlocks_unmount (volinfo, mntpt); | |||||
2151 | ||||||
2152 | if (glusterd_clearlocks_rmdir_mount (volinfo, mntpt)) | |||||
2153 | gf_log (THIS->name, GF_LOG_WARNING, "Couldn't unmount "do { do { if (0) printf ("Couldn't unmount " "clear-locks mount point" ); } while (0); _gf_log ((*__glusterfs_this_location())->name , "glusterd-volume-ops.c", __FUNCTION__, 2154, GF_LOG_WARNING , "Couldn't unmount " "clear-locks mount point"); } while (0) | |||||
2154 | "clear-locks mount point")do { do { if (0) printf ("Couldn't unmount " "clear-locks mount point" ); } while (0); _gf_log ((*__glusterfs_this_location())->name , "glusterd-volume-ops.c", __FUNCTION__, 2154, GF_LOG_WARNING , "Couldn't unmount " "clear-locks mount point"); } while (0); | |||||
2155 | ||||||
2156 | out: | |||||
2157 | if (ret) | |||||
2158 | *op_errstr = gf_strdup (msg); | |||||
2159 | ||||||
2160 | if (xl_opts) { | |||||
2161 | for (i = 0; i < volinfo->brick_count && xl_opts[i]; i++) | |||||
2162 | GF_FREE (xl_opts[i])__gf_free (xl_opts[i]); | |||||
2163 | GF_FREE (xl_opts)__gf_free (xl_opts); | |||||
2164 | } | |||||
2165 | ||||||
2166 | GF_FREE (cmd_str)__gf_free (cmd_str); | |||||
2167 | ||||||
2168 | GF_FREE (mntpt)__gf_free (mntpt); | |||||
2169 | ||||||
2170 | return ret; | |||||
2171 | } |