Bug Summary

File:xlators/mgmt/glusterd/src/glusterd-replace-brick.c
Location:line 1226, column 35
Description:Access to field 'port' results in a dereference of a null pointer (loaded from variable 'dst')

Annotated Source Code

1/*
2 Copyright (c) 2011-2012 Red Hat, Inc. <http://www.redhat.com>
3 This file is part of GlusterFS.
4
5 This file is licensed to you under your choice of the GNU Lesser
6 General Public License, version 3 or any later version (LGPLv3 or
7 later), or the GNU General Public License, version 2 (GPLv2), in all
8 cases as published by the Free Software Foundation.
9*/
10#ifndef _CONFIG_H
11#define _CONFIG_H
12#include "config.h"
13#endif
14
15#include "common-utils.h"
16#include "cli1-xdr.h"
17#include "xdr-generic.h"
18#include "glusterfs.h"
19#include "glusterd.h"
20#include "glusterd-op-sm.h"
21#include "glusterd-store.h"
22#include "glusterd-utils.h"
23#include "glusterd-volgen.h"
24#include "run.h"
25#include "syscall.h"
26
27#include <signal.h>
28
29#define GLUSTERD_GET_RB_MNTPT(path, len, volinfo)snprintf (path, len, "/usr/local/var" "/run/gluster""/%s-""rb_mount"
, volinfo->volname);
\
30 snprintf (path, len, \
31 DEFAULT_VAR_RUN_DIRECTORY"/usr/local/var" "/run/gluster""/%s-"RB_CLIENT_MOUNTPOINT"rb_mount", \
32 volinfo->volname);
33
34
35int
36glusterd_get_replace_op_str (gf1_cli_replace_op op, char *op_str)
37{
38 int ret = -1;
39
40 if (!op_str)
41 goto out;
42
43 switch (op) {
44 case GF_REPLACE_OP_START:
45 strcpy (op_str, "start");
46 break;
47 case GF_REPLACE_OP_COMMIT:
48 strcpy (op_str, "commit");
49 break;
50 case GF_REPLACE_OP_PAUSE:
51 strcpy (op_str, "pause");
52 break;
53 case GF_REPLACE_OP_ABORT:
54 strcpy (op_str, "abort");
55 break;
56 case GF_REPLACE_OP_STATUS:
57 strcpy (op_str, "status");
58 break;
59 case GF_REPLACE_OP_COMMIT_FORCE:
60 strcpy (op_str, "commit-force");
61 break;
62 default:
63 strcpy (op_str, "unknown");
64 break;
65 }
66
67 ret = 0;
68out:
69 return ret;
70}
71
72int
73__glusterd_handle_replace_brick (rpcsvc_request_t *req)
74{
75 int32_t ret = -1;
76 gf_cli_req cli_req = {{0,}};
77 dict_t *dict = NULL((void*)0);
78 char *src_brick = NULL((void*)0);
79 char *dst_brick = NULL((void*)0);
80 int32_t op = 0;
81 char operation[256];
82 glusterd_op_t cli_op = GD_OP_REPLACE_BRICK;
83 char *volname = NULL((void*)0);
84 char msg[2048] = {0,};
85 xlator_t *this = NULL((void*)0);
86
87 GF_ASSERT (req)do { if (!(req)) { do { do { if (0) printf ("Assertion failed: "
"req"); } while (0); _gf_log_callingfn ("", "glusterd-replace-brick.c"
, __FUNCTION__, 87, GF_LOG_ERROR, "Assertion failed: " "req")
; } while (0); } } while (0)
;
88 this = THIS(*__glusterfs_this_location());
89 GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: "
"this"); } while (0); _gf_log_callingfn ("", "glusterd-replace-brick.c"
, __FUNCTION__, 89, GF_LOG_ERROR, "Assertion failed: " "this"
); } while (0); } } while (0)
;
90
91 ret = xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req);
92 if (ret < 0) {
93 //failed to decode msg;
94 req->rpc_err = GARBAGE_ARGS;
95 goto out;
96 }
97
98 gf_log (this->name, GF_LOG_INFO, "Received replace brick req")do { do { if (0) printf ("Received replace brick req"); } while
(0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 98, GF_LOG_INFO, "Received replace brick req"); } while (0)
;
99
100 if (cli_req.dict.dict_len) {
101 /* Unserialize the dictionary */
102 dict = dict_new ();
103
104 ret = dict_unserialize (cli_req.dict.dict_val,
105 cli_req.dict.dict_len,
106 &dict);
107 if (ret < 0) {
108 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-replace-brick.c"
, __FUNCTION__, 110, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary"
); } while (0)
109 "failed to "do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary"
); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 110, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary"
); } while (0)
110 "unserialize req-buffer to dictionary")do { do { if (0) printf ("failed to " "unserialize req-buffer to dictionary"
); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 110, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary"
); } while (0)
;
111 snprintf (msg, sizeof (msg), "Unable to decode the "
112 "command");
113 goto out;
114 }
115 }
116
117 ret = dict_get_str (dict, "volname", &volname);
118 if (ret) {
119 snprintf (msg, sizeof (msg), "Could not get volume name");
120 gf_log (this->name, GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log (this
->name, "glusterd-replace-brick.c", __FUNCTION__, 120, GF_LOG_ERROR
, "%s", msg); } while (0)
;
121 goto out;
122 }
123
124 ret = dict_get_int32 (dict, "operation", &op);
125 if (ret) {
126 gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("dict_get on operation failed"); } while
(0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 127, GF_LOG_DEBUG, "dict_get on operation failed"); } while
(0)
127 "dict_get on operation failed")do { do { if (0) printf ("dict_get on operation failed"); } while
(0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 127, GF_LOG_DEBUG, "dict_get on operation failed"); } while
(0)
;
128 snprintf (msg, sizeof (msg), "Could not get operation");
129 goto out;
130 }
131
132 ret = dict_get_str (dict, "src-brick", &src_brick);
133
134 if (ret) {
135 snprintf (msg, sizeof (msg), "Failed to get src brick");
136 gf_log (this->name, GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log (this
->name, "glusterd-replace-brick.c", __FUNCTION__, 136, GF_LOG_ERROR
, "%s", msg); } while (0)
;
137 goto out;
138 }
139 gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("src brick=%s", src_brick); } while (
0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 140, GF_LOG_DEBUG, "src brick=%s", src_brick); } while (0)
140 "src brick=%s", src_brick)do { do { if (0) printf ("src brick=%s", src_brick); } while (
0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 140, GF_LOG_DEBUG, "src brick=%s", src_brick); } while (0)
;
141
142 ret = dict_get_str (dict, "dst-brick", &dst_brick);
143
144 if (ret) {
145 snprintf (msg, sizeof (msg), "Failed to get dest brick");
146 gf_log (this->name, GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log (this
->name, "glusterd-replace-brick.c", __FUNCTION__, 146, GF_LOG_ERROR
, "%s", msg); } while (0)
;
147 goto out;
148 }
149
150 (void) glusterd_get_replace_op_str (op, operation);
151 gf_log (this->name, GF_LOG_DEBUG, "dst brick=%s", dst_brick)do { do { if (0) printf ("dst brick=%s", dst_brick); } while (
0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 151, GF_LOG_DEBUG, "dst brick=%s", dst_brick); } while (0)
;
152 gf_log (this->name, GF_LOG_INFO, "Received replace brick %s request",do { do { if (0) printf ("Received replace brick %s request",
operation); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 153, GF_LOG_INFO, "Received replace brick %s request"
, operation); } while (0)
153 operation)do { do { if (0) printf ("Received replace brick %s request",
operation); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 153, GF_LOG_INFO, "Received replace brick %s request"
, operation); } while (0)
;
154
155 ret = glusterd_op_begin (req, GD_OP_REPLACE_BRICK, dict,
156 msg, sizeof (msg));
157
158out:
159 free (cli_req.dict.dict_val);//malloced by xdr
160
161 glusterd_friend_sm ();
162 glusterd_op_sm ();
163
164 if (ret) {
165 if (msg[0] == '\0')
166 snprintf (msg, sizeof (msg), "Operation failed");
167 ret = glusterd_op_send_cli_response (cli_op, ret, 0, req,
168 dict, msg);
169 }
170
171 return ret;
172}
173
174int
175glusterd_handle_replace_brick (rpcsvc_request_t *req)
176{
177 return glusterd_big_locked_handler (req,
178 __glusterd_handle_replace_brick);
179}
180
181static int
182glusterd_get_rb_dst_brickinfo (glusterd_volinfo_t *volinfo,
183 glusterd_brickinfo_t **brickinfo)
184{
185 int32_t ret = -1;
186
187 if (!volinfo || !brickinfo)
188 goto out;
189
190 *brickinfo = volinfo->rep_brick.dst_brick;
191
192 ret = 0;
193
194out:
195 return ret;
196}
197
198int
199glusterd_op_stage_replace_brick (dict_t *dict, char **op_errstr,
200 dict_t *rsp_dict)
201{
202 int ret = 0;
203 int32_t port = 0;
204 char *src_brick = NULL((void*)0);
205 char *dst_brick = NULL((void*)0);
206 char *volname = NULL((void*)0);
207 int replace_op = 0;
208 glusterd_volinfo_t *volinfo = NULL((void*)0);
209 glusterd_brickinfo_t *src_brickinfo = NULL((void*)0);
210 char *host = NULL((void*)0);
211 char *path = NULL((void*)0);
212 char msg[2048] = {0};
213 char *dup_dstbrick = NULL((void*)0);
214 glusterd_peerinfo_t *peerinfo = NULL((void*)0);
215 glusterd_brickinfo_t *dst_brickinfo = NULL((void*)0);
216 gf_boolean_t is_run = _gf_false;
217 dict_t *ctx = NULL((void*)0);
218 glusterd_conf_t *priv = NULL((void*)0);
219 char *savetok = NULL((void*)0);
220 char pidfile[PATH_MAX4096] = {0};
221 char *task_id_str = NULL((void*)0);
222 xlator_t *this = NULL((void*)0);
223 gf_boolean_t is_force = _gf_false;
224
225 this = THIS(*__glusterfs_this_location());
226 GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: "
"this"); } while (0); _gf_log_callingfn ("", "glusterd-replace-brick.c"
, __FUNCTION__, 226, GF_LOG_ERROR, "Assertion failed: " "this"
); } while (0); } } while (0)
;
227
228 priv = this->private;
229 GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: "
"priv"); } while (0); _gf_log_callingfn ("", "glusterd-replace-brick.c"
, __FUNCTION__, 229, GF_LOG_ERROR, "Assertion failed: " "priv"
); } while (0); } } while (0)
;
230
231 ret = dict_get_str (dict, "src-brick", &src_brick);
232
233 if (ret) {
234 gf_log (this->name, GF_LOG_ERROR, "Unable to get src brick")do { do { if (0) printf ("Unable to get src brick"); } while (
0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 234, GF_LOG_ERROR, "Unable to get src brick"); } while (0)
;
235 goto out;
236 }
237
238 gf_log (this->name, GF_LOG_DEBUG, "src brick=%s", src_brick)do { do { if (0) printf ("src brick=%s", src_brick); } while (
0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 238, GF_LOG_DEBUG, "src brick=%s", src_brick); } while (0)
;
239
240 ret = dict_get_str (dict, "dst-brick", &dst_brick);
241
242 if (ret) {
243 gf_log (this->name, GF_LOG_ERROR, "Unable to get dest brick")do { do { if (0) printf ("Unable to get dest brick"); } while
(0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 243, GF_LOG_ERROR, "Unable to get dest brick"); } while (0)
;
244 goto out;
245 }
246
247 gf_log (this->name, GF_LOG_DEBUG, "dst brick=%s", dst_brick)do { do { if (0) printf ("dst brick=%s", dst_brick); } while (
0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 247, GF_LOG_DEBUG, "dst brick=%s", dst_brick); } while (0)
;
248
249 ret = dict_get_str (dict, "volname", &volname);
250
251 if (ret) {
252 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-replace-brick.c", __FUNCTION__
, 252, GF_LOG_ERROR, "Unable to get volume name"); } while (0
)
;
253 goto out;
254 }
255
256 ret = dict_get_int32 (dict, "operation", (int32_t *)&replace_op);
257 if (ret) {
258 gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("dict get on replace-brick operation failed"
); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 259, GF_LOG_DEBUG, "dict get on replace-brick operation failed"
); } while (0)
259 "dict get on replace-brick operation failed")do { do { if (0) printf ("dict get on replace-brick operation failed"
); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 259, GF_LOG_DEBUG, "dict get on replace-brick operation failed"
); } while (0)
;
260 goto out;
261 }
262
263 ret = glusterd_volinfo_find (volname, &volinfo);
264 if (ret) {
265 snprintf (msg, sizeof (msg), "volume: %s does not exist",
266 volname);
267 *op_errstr = gf_strdup (msg);
268 goto out;
269 }
270
271 if (volinfo->backend == GD_VOL_BK_BD) {
272 snprintf (msg, sizeof (msg), "replace brick not supported "
273 "for Block backend volume");
274 *op_errstr = gf_strdup (msg);
275 goto out;
276 }
277
278 if (GLUSTERD_STATUS_STARTED != volinfo->status) {
279 ret = -1;
280 snprintf (msg, sizeof (msg), "volume: %s is not started",
281 volname);
282 *op_errstr = gf_strdup (msg);
283 goto out;
284 }
285
286 if (!glusterd_store_is_valid_brickpath (volname, dst_brick) ||
287 !glusterd_is_valid_volfpath (volname, dst_brick)) {
288 snprintf (msg, sizeof (msg), "brick path %s is too "
289 "long.", dst_brick);
290 gf_log (this->name, GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log (this
->name, "glusterd-replace-brick.c", __FUNCTION__, 290, GF_LOG_ERROR
, "%s", msg); } while (0)
;
291 *op_errstr = gf_strdup (msg);
292
293 ret = -1;
294 goto out;
295 }
296
297 ret = glusterd_check_gsync_running (volinfo, &is_run);
298 if (ret && (is_run == _gf_false))
299 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-replace-brick.c", __FUNCTION__, 300, GF_LOG_WARNING
, "Unable to get the status" " of active ""geo-replication"" session"
); } while (0)
300 " 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-replace-brick.c", __FUNCTION__, 300, GF_LOG_WARNING
, "Unable to get the status" " of active ""geo-replication"" session"
); } while (0)
;
301 if (is_run) {
302 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-replace-brick.c"
, __FUNCTION__, 303, GF_LOG_WARNING, "geo-replication"" sessions active"
"for the volume %s ", volname); } while (0)
303 "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-replace-brick.c"
, __FUNCTION__, 303, GF_LOG_WARNING, "geo-replication"" sessions active"
"for the volume %s ", volname); } while (0)
;
304 snprintf (msg, sizeof(msg), GEOREP"geo-replication"" sessions are active "
305 "for the volume %s.\nStop "GEOREP"geo-replication" " sessions "
306 "involved in this volume. Use 'volume "GEOREP"geo-replication"
307 " status' command for more info.",
308 volname);
309 *op_errstr = gf_strdup (msg);
310 ret = -1;
311 goto out;
312 }
313
314 if (glusterd_is_defrag_on(volinfo)) {
315 snprintf (msg, sizeof(msg), "Volume name %s rebalance is in "
316 "progress. Please retry after completion", volname);
317 gf_log (this->name, GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log (this
->name, "glusterd-replace-brick.c", __FUNCTION__, 317, GF_LOG_ERROR
, "%s", msg); } while (0)
;
318 *op_errstr = gf_strdup (msg);
319 ret = -1;
320 goto out;
321 }
322
323 ctx = glusterd_op_get_ctx();
324
325 switch (replace_op) {
326 case GF_REPLACE_OP_START:
327 if (glusterd_is_rb_started (volinfo)) {
328 snprintf (msg, sizeof (msg), "Replace brick is already "
329 "started for volume");
330 gf_log (this->name, GF_LOG_ERROR, "%s", msg)do { do { if (0) printf ("%s", msg); } while (0); _gf_log (this
->name, "glusterd-replace-brick.c", __FUNCTION__, 330, GF_LOG_ERROR
, "%s", msg); } while (0)
;
331 *op_errstr = gf_strdup (msg);
332 ret = -1;
333 goto out;
334 }
335 if (is_origin_glusterd ()) {
336 if (!ctx) {
337 ret = -1;
338 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("Failed to get op_ctx"); } while (0)
; _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 339, GF_LOG_ERROR, "Failed to get op_ctx"); } while (0)
339 "Failed to get op_ctx")do { do { if (0) printf ("Failed to get op_ctx"); } while (0)
; _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 339, GF_LOG_ERROR, "Failed to get op_ctx"); } while (0)
;
340 goto out;
341 }
342
343 ret = glusterd_generate_and_set_task_id
344 (ctx, GF_REPLACE_BRICK_TID_KEY"replace-brick-id");
345 if (ret) {
346 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("Failed to generate task-id"); } while
(0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 347, GF_LOG_ERROR, "Failed to generate task-id"); } while (
0)
347 "Failed to generate task-id")do { do { if (0) printf ("Failed to generate task-id"); } while
(0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 347, GF_LOG_ERROR, "Failed to generate task-id"); } while (
0)
;
348 goto out;
349 }
350
351 } else {
352 ret = dict_get_str (dict, GF_REPLACE_BRICK_TID_KEY"replace-brick-id",
353 &task_id_str);
354 if (ret) {
355 gf_log (this->name, GF_LOG_WARNING,do { do { if (0) printf ("Missing replace-brick-id"); } while
(0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 356, GF_LOG_WARNING, "Missing replace-brick-id"); } while (
0)
356 "Missing replace-brick-id")do { do { if (0) printf ("Missing replace-brick-id"); } while
(0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 356, GF_LOG_WARNING, "Missing replace-brick-id"); } while (
0)
;
357 ret = 0;
358 }
359 }
360 is_force = dict_get_str_boolean (dict, "force", _gf_false);
361
362 break;
363
364 case GF_REPLACE_OP_PAUSE:
365 if (glusterd_is_rb_paused (volinfo)) {
366 gf_log (this->name, GF_LOG_ERROR, "Replace brick is "do { do { if (0) printf ("Replace brick is " "already paused for volume "
); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 367, GF_LOG_ERROR, "Replace brick is " "already paused for volume "
); } while (0)
367 "already paused for volume ")do { do { if (0) printf ("Replace brick is " "already paused for volume "
); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 367, GF_LOG_ERROR, "Replace brick is " "already paused for volume "
); } while (0)
;
368 ret = -1;
369 goto out;
370 } else if (!glusterd_is_rb_started(volinfo)) {
371 gf_log (this->name, GF_LOG_ERROR, "Replace brick is not"do { do { if (0) printf ("Replace brick is not" " started for volume "
); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 372, GF_LOG_ERROR, "Replace brick is not" " started for volume "
); } while (0)
372 " started for volume ")do { do { if (0) printf ("Replace brick is not" " started for volume "
); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 372, GF_LOG_ERROR, "Replace brick is not" " started for volume "
); } while (0)
;
373 ret = -1;
374 goto out;
375 }
376 break;
377
378 case GF_REPLACE_OP_ABORT:
379 if (!glusterd_is_rb_ongoing (volinfo)) {
380 gf_log (this->name, GF_LOG_ERROR, "Replace brick is not"do { do { if (0) printf ("Replace brick is not" " started or paused for volume "
); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 381, GF_LOG_ERROR, "Replace brick is not" " started or paused for volume "
); } while (0)
381 " started or paused for volume ")do { do { if (0) printf ("Replace brick is not" " started or paused for volume "
); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 381, GF_LOG_ERROR, "Replace brick is not" " started or paused for volume "
); } while (0)
;
382 ret = -1;
383 goto out;
384 }
385 break;
386
387 case GF_REPLACE_OP_COMMIT:
388 if (!glusterd_is_rb_ongoing (volinfo)) {
389 gf_log (this->name, GF_LOG_ERROR, "Replace brick is not "do { do { if (0) printf ("Replace brick is not " "started for volume "
); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 390, GF_LOG_ERROR, "Replace brick is not " "started for volume "
); } while (0)
390 "started for volume ")do { do { if (0) printf ("Replace brick is not " "started for volume "
); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 390, GF_LOG_ERROR, "Replace brick is not " "started for volume "
); } while (0)
;
391 ret = -1;
392 goto out;
393 }
394 break;
395
396 case GF_REPLACE_OP_COMMIT_FORCE:
397 is_force = _gf_true;
398 break;
399
400 case GF_REPLACE_OP_STATUS:
401
402 if (glusterd_is_rb_ongoing (volinfo) == _gf_false) {
403 ret = gf_asprintf (op_errstr, "replace-brick not"
404 " started on volume %s",
405 volinfo->volname);
406 if (ret < 0) {
407 *op_errstr = NULL((void*)0);
408 goto out;
409 }
410
411 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-replace-brick.c", __FUNCTION__, 411
, GF_LOG_ERROR, "%s", *op_errstr); } while (0)
;
412 ret = -1;
413 goto out;
414 }
415 break;
416
417 default:
418 ret = -1;
419 goto out;
420 }
421
422 ret = glusterd_volume_brickinfo_get_by_brick (src_brick, volinfo,
423 &src_brickinfo);
424 if (ret) {
425 snprintf (msg, sizeof (msg), "brick: %s does not exist in "
426 "volume: %s", src_brick, volname);
427 *op_errstr = gf_strdup (msg);
428 goto out;
429 }
430
431 if (ctx) {
432 if (!glusterd_is_fuse_available ()) {
433 gf_log (this->name, GF_LOG_ERROR, "Unable to open /dev/"do { do { if (0) printf ("Unable to open /dev/" "fuse (%s), replace-brick command failed"
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "glusterd-replace-brick.c", __FUNCTION__, 435, GF_LOG_ERROR
, "Unable to open /dev/" "fuse (%s), replace-brick command failed"
, strerror ((*__errno_location ()))); } while (0)
434 "fuse (%s), replace-brick command failed",do { do { if (0) printf ("Unable to open /dev/" "fuse (%s), replace-brick command failed"
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "glusterd-replace-brick.c", __FUNCTION__, 435, GF_LOG_ERROR
, "Unable to open /dev/" "fuse (%s), replace-brick command failed"
, strerror ((*__errno_location ()))); } while (0)
435 strerror (errno))do { do { if (0) printf ("Unable to open /dev/" "fuse (%s), replace-brick command failed"
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "glusterd-replace-brick.c", __FUNCTION__, 435, GF_LOG_ERROR
, "Unable to open /dev/" "fuse (%s), replace-brick command failed"
, strerror ((*__errno_location ()))); } while (0)
;
436 snprintf (msg, sizeof(msg), "Fuse unavailable\n "
437 "Replace-brick failed");
438 *op_errstr = gf_strdup (msg);
439 ret = -1;
440 goto out;
441 }
442 }
443
444 if (glusterd_is_local_addr (src_brickinfo->hostname)) {
445 gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("I AM THE SOURCE HOST"); } while (0)
; _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 446, GF_LOG_DEBUG, "I AM THE SOURCE HOST"); } while (0)
446 "I AM THE SOURCE HOST")do { do { if (0) printf ("I AM THE SOURCE HOST"); } while (0)
; _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 446, GF_LOG_DEBUG, "I AM THE SOURCE HOST"); } while (0)
;
447 if (src_brickinfo->port && rsp_dict) {
448 ret = dict_set_int32 (rsp_dict, "src-brick-port",
449 src_brickinfo->port);
450 if (ret) {
451 gf_log ("", GF_LOG_DEBUG,do { do { if (0) printf ("Could not set src-brick-port=%d", src_brickinfo
->port); } while (0); _gf_log ("", "glusterd-replace-brick.c"
, __FUNCTION__, 453, GF_LOG_DEBUG, "Could not set src-brick-port=%d"
, src_brickinfo->port); } while (0)
452 "Could not set src-brick-port=%d",do { do { if (0) printf ("Could not set src-brick-port=%d", src_brickinfo
->port); } while (0); _gf_log ("", "glusterd-replace-brick.c"
, __FUNCTION__, 453, GF_LOG_DEBUG, "Could not set src-brick-port=%d"
, src_brickinfo->port); } while (0)
453 src_brickinfo->port)do { do { if (0) printf ("Could not set src-brick-port=%d", src_brickinfo
->port); } while (0); _gf_log ("", "glusterd-replace-brick.c"
, __FUNCTION__, 453, GF_LOG_DEBUG, "Could not set src-brick-port=%d"
, src_brickinfo->port); } while (0)
;
454 }
455 }
456
457 GLUSTERD_GET_BRICK_PIDFILE (pidfile, volinfo, src_brickinfo,do { char exp_path[4096] = {0,}; char volpath[4096] = {0,}; snprintf
(volpath, 4096, "%s/vols/%s", priv->workdir, volinfo->
volname);; do { int i = 0; for (i = 1; i < strlen (src_brickinfo
->path); i++) { exp_path[i-1] = src_brickinfo->path[i];
if (exp_path[i-1] == '/') exp_path[i-1] = '-'; } } while (0)
; snprintf (pidfile, 4096, "%s/run/%s-%s.pid", volpath, src_brickinfo
->hostname, exp_path); } while (0)
458 priv)do { char exp_path[4096] = {0,}; char volpath[4096] = {0,}; snprintf
(volpath, 4096, "%s/vols/%s", priv->workdir, volinfo->
volname);; do { int i = 0; for (i = 1; i < strlen (src_brickinfo
->path); i++) { exp_path[i-1] = src_brickinfo->path[i];
if (exp_path[i-1] == '/') exp_path[i-1] = '-'; } } while (0)
; snprintf (pidfile, 4096, "%s/run/%s-%s.pid", volpath, src_brickinfo
->hostname, exp_path); } while (0)
;
459 if ((replace_op != GF_REPLACE_OP_COMMIT_FORCE) &&
460 !glusterd_is_service_running (pidfile, NULL((void*)0))) {
461 snprintf(msg, sizeof(msg), "Source brick %s:%s "
462 "is not online.", src_brickinfo->hostname,
463 src_brickinfo->path);
464 *op_errstr = gf_strdup (msg);
465 ret = -1;
466 goto out;
467 }
468
469
470 }
471
472 dup_dstbrick = gf_strdup (dst_brick);
473 if (!dup_dstbrick) {
474 ret = -1;
475 gf_log (this->name, GF_LOG_ERROR, "Memory allocation failed")do { do { if (0) printf ("Memory allocation failed"); } while
(0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 475, GF_LOG_ERROR, "Memory allocation failed"); } while (0)
;
476 goto out;
477 }
478 host = strtok_r (dup_dstbrick, ":", &savetok);
479 path = strtok_r (NULL((void*)0), ":", &savetok);
480
481 if (!host || !path) {
482 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("dst brick %s is not of form <HOSTNAME>:<export-dir>"
, dst_brick); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 484, GF_LOG_ERROR, "dst brick %s is not of form <HOSTNAME>:<export-dir>"
, dst_brick); } while (0)
483 "dst brick %s is not of form <HOSTNAME>:<export-dir>",do { do { if (0) printf ("dst brick %s is not of form <HOSTNAME>:<export-dir>"
, dst_brick); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 484, GF_LOG_ERROR, "dst brick %s is not of form <HOSTNAME>:<export-dir>"
, dst_brick); } while (0)
484 dst_brick)do { do { if (0) printf ("dst brick %s is not of form <HOSTNAME>:<export-dir>"
, dst_brick); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 484, GF_LOG_ERROR, "dst brick %s is not of form <HOSTNAME>:<export-dir>"
, dst_brick); } while (0)
;
485 ret = -1;
486 goto out;
487 }
488
489 ret = glusterd_brickinfo_new_from_brick (dst_brick, &dst_brickinfo);
490 if (ret)
491 goto out;
492
493 ret = glusterd_new_brick_validate (dst_brick, dst_brickinfo,
494 msg, sizeof (msg));
495 if (ret) {
496 *op_errstr = gf_strdup (msg);
497 ret = -1;
498 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-replace-brick.c", __FUNCTION__, 498
, GF_LOG_ERROR, "%s", *op_errstr); } while (0)
;
499 goto out;
500 }
501
502 if (!glusterd_is_rb_ongoing (volinfo) &&
503 (replace_op == GF_REPLACE_OP_START ||
504 replace_op == GF_REPLACE_OP_COMMIT_FORCE)) {
505
506 volinfo->rep_brick.src_brick = src_brickinfo;
507 volinfo->rep_brick.dst_brick = dst_brickinfo;
508 }
509
510 if (glusterd_rb_check_bricks (volinfo, src_brickinfo, dst_brickinfo)) {
511
512 ret = -1;
513 *op_errstr = gf_strdup ("Incorrect source or "
514 "destination brick");
515 if (*op_errstr)
516 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-replace-brick.c", __FUNCTION__, 516
, GF_LOG_ERROR, "%s", *op_errstr); } while (0)
;
517 goto out;
518 }
519
520 if (!glusterd_is_rb_ongoing (volinfo) &&
521 glusterd_is_local_addr (host)) {
522 ret = glusterd_validate_and_create_brickpath (dst_brickinfo,
523 volinfo->volume_id,
524 op_errstr, is_force);
525 if (ret)
526 goto out;
527 }
528
529 if (!glusterd_is_local_addr (host)) {
530 ret = glusterd_friend_find (NULL((void*)0), host, &peerinfo);
531 if (ret) {
532 snprintf (msg, sizeof (msg), "%s, is not a friend",
533 host);
534 *op_errstr = gf_strdup (msg);
535 goto out;
536 }
537
538 if (!peerinfo->connected) {
539 snprintf (msg, sizeof (msg), "%s, is not connected at "
540 "the moment", host);
541 *op_errstr = gf_strdup (msg);
542 ret = -1;
543 goto out;
544 }
545
546 if (GD_FRIEND_STATE_BEFRIENDED != peerinfo->state.state) {
547 snprintf (msg, sizeof (msg), "%s, is not befriended "
548 "at the moment", host);
549 *op_errstr = gf_strdup (msg);
550 ret = -1;
551 goto out;
552 }
553 }
554
555 if (replace_op == GF_REPLACE_OP_START &&
556 glusterd_is_local_addr (volinfo->rep_brick.dst_brick->hostname)) {
557 port = pmap_registry_alloc (THIS(*__glusterfs_this_location()));
558 if (!port) {
559 gf_log (THIS->name, GF_LOG_CRITICAL,do { do { if (0) printf ("No free ports available"); } while (
0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-replace-brick.c"
, __FUNCTION__, 560, GF_LOG_CRITICAL, "No free ports available"
); } while (0)
560 "No free ports available")do { do { if (0) printf ("No free ports available"); } while (
0); _gf_log ((*__glusterfs_this_location())->name, "glusterd-replace-brick.c"
, __FUNCTION__, 560, GF_LOG_CRITICAL, "No free ports available"
); } while (0)
;
561 ret = -1;
562 goto out;
563 }
564
565 ctx = glusterd_op_get_ctx();
566 ret = dict_set_int32 ((ctx)?ctx:rsp_dict, "dst-brick-port",
567 port);
568 if (ret) {
569 gf_log (THIS->name, GF_LOG_ERROR, "Failed to set dst "do { do { if (0) printf ("Failed to set dst " "brick port"); }
while (0); _gf_log ((*__glusterfs_this_location())->name,
"glusterd-replace-brick.c", __FUNCTION__, 570, GF_LOG_ERROR,
"Failed to set dst " "brick port"); } while (0)
570 "brick port")do { do { if (0) printf ("Failed to set dst " "brick port"); }
while (0); _gf_log ((*__glusterfs_this_location())->name,
"glusterd-replace-brick.c", __FUNCTION__, 570, GF_LOG_ERROR,
"Failed to set dst " "brick port"); } while (0)
;
571 goto out;
572 }
573 volinfo->rep_brick.dst_brick->port = port;
574 }
575
576 ret = 0;
577
578out:
579 GF_FREE (dup_dstbrick)__gf_free (dup_dstbrick);
580 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-replace-brick.c", __FUNCTION__, 580
, GF_LOG_DEBUG, "Returning %d", ret); } while (0)
;
581
582 return ret;
583}
584
585static int
586rb_set_mntfd (int mntfd)
587{
588 int ret = -1;
589 dict_t *ctx = NULL((void*)0);
590
591 ctx = glusterd_op_get_ctx ();
592 if (!ctx) {
593 gf_log (THIS->name, GF_LOG_CRITICAL, "Failed to get op ctx")do { do { if (0) printf ("Failed to get op ctx"); } while (0)
; _gf_log ((*__glusterfs_this_location())->name, "glusterd-replace-brick.c"
, __FUNCTION__, 593, GF_LOG_CRITICAL, "Failed to get op ctx")
; } while (0)
;
594 goto out;
595 }
596 ret = dict_set_int32 (ctx, "mntfd", mntfd);
597 if (ret)
598 gf_log (THIS->name, GF_LOG_DEBUG, "Failed to set mnt fd "do { do { if (0) printf ("Failed to set mnt fd " "in op ctx")
; } while (0); _gf_log ((*__glusterfs_this_location())->name
, "glusterd-replace-brick.c", __FUNCTION__, 599, GF_LOG_DEBUG
, "Failed to set mnt fd " "in op ctx"); } while (0)
599 "in op ctx")do { do { if (0) printf ("Failed to set mnt fd " "in op ctx")
; } while (0); _gf_log ((*__glusterfs_this_location())->name
, "glusterd-replace-brick.c", __FUNCTION__, 599, GF_LOG_DEBUG
, "Failed to set mnt fd " "in op ctx"); } while (0)
;
600out:
601 return ret;
602}
603
604static int
605rb_get_mntfd (int *mntfd)
606{
607 int ret = -1;
608 dict_t *ctx = NULL((void*)0);
609
610 ctx = glusterd_op_get_ctx ();
611 if (!ctx) {
612 gf_log (THIS->name, GF_LOG_CRITICAL, "Failed to get op ctx")do { do { if (0) printf ("Failed to get op ctx"); } while (0)
; _gf_log ((*__glusterfs_this_location())->name, "glusterd-replace-brick.c"
, __FUNCTION__, 612, GF_LOG_CRITICAL, "Failed to get op ctx")
; } while (0)
;
613 goto out;
614 }
615 ret = dict_get_int32 (ctx, "mntfd", mntfd);
616 if (ret)
617 gf_log (THIS->name, GF_LOG_DEBUG, "Failed to get mnt fd "do { do { if (0) printf ("Failed to get mnt fd " "from op ctx"
); } while (0); _gf_log ((*__glusterfs_this_location())->name
, "glusterd-replace-brick.c", __FUNCTION__, 618, GF_LOG_DEBUG
, "Failed to get mnt fd " "from op ctx"); } while (0)
618 "from op ctx")do { do { if (0) printf ("Failed to get mnt fd " "from op ctx"
); } while (0); _gf_log ((*__glusterfs_this_location())->name
, "glusterd-replace-brick.c", __FUNCTION__, 618, GF_LOG_DEBUG
, "Failed to get mnt fd " "from op ctx"); } while (0)
;
619out:
620 return ret;
621}
622
623static int
624rb_regenerate_volfiles (glusterd_volinfo_t *volinfo,
625 glusterd_brickinfo_t *brickinfo,
626 int32_t pump_needed)
627{
628 dict_t *dict = NULL((void*)0);
629 int ret = 0;
630
631 dict = volinfo->dict;
632
633 gf_log ("", GF_LOG_DEBUG,do { do { if (0) printf ("attempting to set pump value=%d", pump_needed
); } while (0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__
, 634, GF_LOG_DEBUG, "attempting to set pump value=%d", pump_needed
); } while (0)
634 "attempting to set pump value=%d", pump_needed)do { do { if (0) printf ("attempting to set pump value=%d", pump_needed
); } while (0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__
, 634, GF_LOG_DEBUG, "attempting to set pump value=%d", pump_needed
); } while (0)
;
635
636 ret = dict_set_int32 (dict, "enable-pump", pump_needed);
637 if (ret) {
638 gf_log ("", GF_LOG_DEBUG,do { do { if (0) printf ("could not dict_set enable-pump"); }
while (0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__
, 639, GF_LOG_DEBUG, "could not dict_set enable-pump"); } while
(0)
639 "could not dict_set enable-pump")do { do { if (0) printf ("could not dict_set enable-pump"); }
while (0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__
, 639, GF_LOG_DEBUG, "could not dict_set enable-pump"); } while
(0)
;
640 goto out;
641 }
642
643 ret = glusterd_create_rb_volfiles (volinfo, brickinfo);
644
645 dict_del (dict, "enable-pump");
646
647out:
648 return ret;
649}
650
651static int
652rb_src_brick_restart (glusterd_volinfo_t *volinfo,
653 glusterd_brickinfo_t *src_brickinfo,
654 int activate_pump)
655{
656 int ret = 0;
657
658 gf_log ("", GF_LOG_DEBUG,do { do { if (0) printf ("Attempting to kill src"); } while (
0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__, 659
, GF_LOG_DEBUG, "Attempting to kill src"); } while (0)
659 "Attempting to kill src")do { do { if (0) printf ("Attempting to kill src"); } while (
0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__, 659
, GF_LOG_DEBUG, "Attempting to kill src"); } while (0)
;
660
661 ret = glusterd_nfs_server_stop (volinfo);
662
663 if (ret) {
664 gf_log ("", GF_LOG_ERROR, "Unable to stop nfs, ret: %d",do { do { if (0) printf ("Unable to stop nfs, ret: %d", ret);
} while (0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__
, 665, GF_LOG_ERROR, "Unable to stop nfs, ret: %d", ret); } while
(0)
665 ret)do { do { if (0) printf ("Unable to stop nfs, ret: %d", ret);
} while (0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__
, 665, GF_LOG_ERROR, "Unable to stop nfs, ret: %d", ret); } while
(0)
;
666 }
667
668 ret = glusterd_volume_stop_glusterfs (volinfo, src_brickinfo,
669 _gf_false);
670 if (ret) {
671 gf_log ("", GF_LOG_ERROR, "Unable to stop "do { do { if (0) printf ("Unable to stop " "glusterfs, ret: %d"
, ret); } while (0); _gf_log ("", "glusterd-replace-brick.c",
__FUNCTION__, 672, GF_LOG_ERROR, "Unable to stop " "glusterfs, ret: %d"
, ret); } while (0)
672 "glusterfs, ret: %d", ret)do { do { if (0) printf ("Unable to stop " "glusterfs, ret: %d"
, ret); } while (0); _gf_log ("", "glusterd-replace-brick.c",
__FUNCTION__, 672, GF_LOG_ERROR, "Unable to stop " "glusterfs, ret: %d"
, ret); } while (0)
;
673 goto out;
674 }
675
676 glusterd_delete_volfile (volinfo, src_brickinfo);
677
678 if (activate_pump) {
679 ret = rb_regenerate_volfiles (volinfo, src_brickinfo, 1);
680 if (ret) {
681 gf_log ("", GF_LOG_DEBUG,do { do { if (0) printf ("Could not regenerate volfiles with pump"
); } while (0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__
, 682, GF_LOG_DEBUG, "Could not regenerate volfiles with pump"
); } while (0)
682 "Could not regenerate volfiles with pump")do { do { if (0) printf ("Could not regenerate volfiles with pump"
); } while (0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__
, 682, GF_LOG_DEBUG, "Could not regenerate volfiles with pump"
); } while (0)
;
683 goto out;
684 }
685 } else {
686 ret = rb_regenerate_volfiles (volinfo, src_brickinfo, 0);
687 if (ret) {
688 gf_log ("", GF_LOG_DEBUG,do { do { if (0) printf ("Could not regenerate volfiles without pump"
); } while (0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__
, 689, GF_LOG_DEBUG, "Could not regenerate volfiles without pump"
); } while (0)
689 "Could not regenerate volfiles without pump")do { do { if (0) printf ("Could not regenerate volfiles without pump"
); } while (0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__
, 689, GF_LOG_DEBUG, "Could not regenerate volfiles without pump"
); } while (0)
;
690 goto out;
691 }
692
693 }
694
695 sleep (2);
696 ret = glusterd_volume_start_glusterfs (volinfo, src_brickinfo,
697 _gf_false);
698 if (ret) {
699 gf_log ("", GF_LOG_ERROR, "Unable to start "do { do { if (0) printf ("Unable to start " "glusterfs, ret: %d"
, ret); } while (0); _gf_log ("", "glusterd-replace-brick.c",
__FUNCTION__, 700, GF_LOG_ERROR, "Unable to start " "glusterfs, ret: %d"
, ret); } while (0)
700 "glusterfs, ret: %d", ret)do { do { if (0) printf ("Unable to start " "glusterfs, ret: %d"
, ret); } while (0); _gf_log ("", "glusterd-replace-brick.c",
__FUNCTION__, 700, GF_LOG_ERROR, "Unable to start " "glusterfs, ret: %d"
, ret); } while (0)
;
701 goto out;
702 }
703
704out:
705 ret = glusterd_nfs_server_start (volinfo);
706 if (ret) {
707 gf_log ("", GF_LOG_ERROR, "Unable to start nfs, ret: %d",do { do { if (0) printf ("Unable to start nfs, ret: %d", ret)
; } while (0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__
, 708, GF_LOG_ERROR, "Unable to start nfs, ret: %d", ret); } while
(0)
708 ret)do { do { if (0) printf ("Unable to start nfs, ret: %d", ret)
; } while (0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__
, 708, GF_LOG_ERROR, "Unable to start nfs, ret: %d", ret); } while
(0)
;
709 }
710 return ret;
711}
712
713static int
714rb_send_xattr_command (glusterd_volinfo_t *volinfo,
715 glusterd_brickinfo_t *src_brickinfo,
716 glusterd_brickinfo_t *dst_brickinfo,
717 const char *xattr_key, const char *value)
718{
719 int ret = -1;
720 int mntfd = -1;
721
722 ret = rb_get_mntfd (&mntfd);
723 if (ret)
724 goto out;
725
726 ret = sys_fsetxattr (mntfd, xattr_key, value, strlen (value) + 1, 0);
727 if (ret)
728 gf_log (THIS->name, GF_LOG_DEBUG, "setxattr on key: "do { do { if (0) printf ("setxattr on key: " "%s, reason: %s"
, xattr_key, strerror ((*__errno_location ()))); } while (0);
_gf_log ((*__glusterfs_this_location())->name, "glusterd-replace-brick.c"
, __FUNCTION__, 729, GF_LOG_DEBUG, "setxattr on key: " "%s, reason: %s"
, xattr_key, strerror ((*__errno_location ()))); } while (0)
729 "%s, reason: %s", xattr_key, strerror (errno))do { do { if (0) printf ("setxattr on key: " "%s, reason: %s"
, xattr_key, strerror ((*__errno_location ()))); } while (0);
_gf_log ((*__glusterfs_this_location())->name, "glusterd-replace-brick.c"
, __FUNCTION__, 729, GF_LOG_DEBUG, "setxattr on key: " "%s, reason: %s"
, xattr_key, strerror ((*__errno_location ()))); } while (0)
;
730
731out:
732 return ret;
733}
734
735static int
736rb_spawn_dst_brick (glusterd_volinfo_t *volinfo,
737 glusterd_brickinfo_t *brickinfo)
738{
739 glusterd_conf_t *priv = NULL((void*)0);
740 runner_t runner = {0,};
741 int ret = -1;
742 int32_t port = 0;
743
744 priv = THIS(*__glusterfs_this_location())->private;
745
746 port = brickinfo->port;
747 GF_ASSERT (port)do { if (!(port)) { do { do { if (0) printf ("Assertion failed: "
"port"); } while (0); _gf_log_callingfn ("", "glusterd-replace-brick.c"
, __FUNCTION__, 747, GF_LOG_ERROR, "Assertion failed: " "port"
); } while (0); } } while (0)
;
748
749 runinit (&runner);
750 runner_add_arg (&runner, SBIN_DIR"/usr/local/sbin""/glusterfs");
751 runner_argprintf (&runner, "-f" "%s/vols/%s/"RB_DSTBRICKVOL_FILENAME"rb_dst_brick.vol",
752 priv->workdir, volinfo->volname);
753 runner_argprintf (&runner, "-p" "%s/vols/%s/"RB_DSTBRICK_PIDFILE"rb_dst_brick.pid",
754 priv->workdir, volinfo->volname);
755 runner_add_arg (&runner, "--xlator-option");
756 runner_argprintf (&runner, "src-server.listen-port=%d", port);
757 if (volinfo->memory_accounting)
758 runner_add_arg (&runner, "--mem-accounting");
759
760 ret = runner_run_nowait (&runner);
761 if (ret) {
762 pmap_registry_remove (THIS(*__glusterfs_this_location()), 0, brickinfo->path,
763 GF_PMAP_PORT_BRICKSERVER, NULL((void*)0));
764 gf_log ("", GF_LOG_DEBUG,do { do { if (0) printf ("Could not start glusterfs"); } while
(0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__, 765
, GF_LOG_DEBUG, "Could not start glusterfs"); } while (0)
765 "Could not start glusterfs")do { do { if (0) printf ("Could not start glusterfs"); } while
(0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__, 765
, GF_LOG_DEBUG, "Could not start glusterfs"); } while (0)
;
766 goto out;
767 }
768
769 gf_log ("", GF_LOG_DEBUG,do { do { if (0) printf ("Successfully started glusterfs: brick=%s:%s"
, brickinfo->hostname, brickinfo->path); } while (0); _gf_log
("", "glusterd-replace-brick.c", __FUNCTION__, 771, GF_LOG_DEBUG
, "Successfully started glusterfs: brick=%s:%s", brickinfo->
hostname, brickinfo->path); } while (0)
770 "Successfully started glusterfs: brick=%s:%s",do { do { if (0) printf ("Successfully started glusterfs: brick=%s:%s"
, brickinfo->hostname, brickinfo->path); } while (0); _gf_log
("", "glusterd-replace-brick.c", __FUNCTION__, 771, GF_LOG_DEBUG
, "Successfully started glusterfs: brick=%s:%s", brickinfo->
hostname, brickinfo->path); } while (0)
771 brickinfo->hostname, brickinfo->path)do { do { if (0) printf ("Successfully started glusterfs: brick=%s:%s"
, brickinfo->hostname, brickinfo->path); } while (0); _gf_log
("", "glusterd-replace-brick.c", __FUNCTION__, 771, GF_LOG_DEBUG
, "Successfully started glusterfs: brick=%s:%s", brickinfo->
hostname, brickinfo->path); } while (0)
;
772
773 ret = 0;
774
775out:
776 return ret;
777}
778
779static int
780rb_spawn_glusterfs_client (glusterd_volinfo_t *volinfo,
781 glusterd_brickinfo_t *brickinfo)
782{
783 xlator_t *this = NULL((void*)0);
784 glusterd_conf_t *priv = NULL((void*)0);
785 runner_t runner = {0,};
786 struct stat buf = {0,};
787 char mntpt[PATH_MAX4096] = {0,};
788 int mntfd = -1;
789 int ret = -1;
790
791 this = THIS(*__glusterfs_this_location());
792 priv = this->private;
793
794 GLUSTERD_GET_RB_MNTPT (mntpt, sizeof (mntpt), volinfo)snprintf (mntpt, sizeof (mntpt), "/usr/local/var" "/run/gluster"
"/%s-""rb_mount", volinfo->volname);
;
795 runinit (&runner);
796 runner_add_arg (&runner, SBIN_DIR"/usr/local/sbin""/glusterfs");
797 runner_argprintf (&runner, "-f" "%s/vols/%s/"RB_CLIENTVOL_FILENAME"rb_client.vol",
798 priv->workdir, volinfo->volname);
799 runner_add_arg (&runner, mntpt);
800 if (volinfo->memory_accounting)
801 runner_add_arg (&runner, "--mem-accounting");
802
803 ret = runner_run_reuse (&runner);
804 if (ret) {
805 runner_log (&runner, this->name, GF_LOG_DEBUG,
806 "Could not start glusterfs");
807 runner_end (&runner);
808 goto out;
809 } else {
810 runner_log (&runner, this->name, GF_LOG_DEBUG,
811 "Successfully started glusterfs");
812 runner_end (&runner);
813 }
814
815 ret = stat (mntpt, &buf);
816 if (ret) {
817 gf_log (this->name, GF_LOG_DEBUG, "stat on mount point %s "do { do { if (0) printf ("stat on mount point %s " "failed", mntpt
); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 818, GF_LOG_DEBUG, "stat on mount point %s " "failed"
, mntpt); } while (0)
818 "failed", mntpt)do { do { if (0) printf ("stat on mount point %s " "failed", mntpt
); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 818, GF_LOG_DEBUG, "stat on mount point %s " "failed"
, mntpt); } while (0)
;
819 goto out;
820 }
821
822 mntfd = open (mntpt, O_DIRECTORY0200000);
823 if (mntfd == -1)
824 goto out;
825
826 ret = rb_set_mntfd (mntfd);
827 if (ret)
828 goto out;
829
830 runinit (&runner);
831 runner_add_args (&runner, "/bin/umount", "-l", mntpt, NULL((void*)0));
832 ret = runner_run_reuse (&runner);
833 if (ret) {
834 runner_log (&runner, this->name, GF_LOG_DEBUG,
835 "Lazy unmount failed on maintenance client");
836 runner_end (&runner);
837 goto out;
838 } else {
839 runner_log (&runner, this->name, GF_LOG_DEBUG,
840 "Successfully unmounted maintenance client");
841 runner_end (&runner);
842 }
843
844
845out:
846
847 return ret;
848}
849
850static const char *client_volfile_str = "volume mnt-client\n"
851 " type protocol/client\n"
852 " option remote-host %s\n"
853 " option remote-subvolume %s\n"
854 " option remote-port %d\n"
855 " option transport-type %s\n"
856 " option username %s\n"
857 " option password %s\n"
858 "end-volume\n"
859 "volume mnt-wb\n"
860 " type performance/write-behind\n"
861 " subvolumes mnt-client\n"
862 "end-volume\n";
863
864static int
865rb_generate_client_volfile (glusterd_volinfo_t *volinfo,
866 glusterd_brickinfo_t *src_brickinfo)
867{
868 glusterd_conf_t *priv = NULL((void*)0);
869 xlator_t *this = NULL((void*)0);
870 FILE *file = NULL((void*)0);
871 char filename[PATH_MAX4096] = {0, };
872 int ret = -1;
873 int fd = -1;
874 char *ttype = NULL((void*)0);
875
876 this = THIS(*__glusterfs_this_location());
877 priv = this->private;
878
879 gf_log (this->name, GF_LOG_DEBUG, "Creating volfile")do { do { if (0) printf ("Creating volfile"); } while (0); _gf_log
(this->name, "glusterd-replace-brick.c", __FUNCTION__, 879
, GF_LOG_DEBUG, "Creating volfile"); } while (0)
;
880
881 snprintf (filename, PATH_MAX4096, "%s/vols/%s/%s",
882 priv->workdir, volinfo->volname,
883 RB_CLIENTVOL_FILENAME"rb_client.vol");
884
885 fd = open (filename, O_CREAT0100 | O_RDONLY00, S_IRUSR0400 | S_IWUSR0200);
886 if (fd < 0) {
887 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("%s", strerror ((*__errno_location (
)))); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 888, GF_LOG_ERROR, "%s", strerror ((*__errno_location
()))); } while (0)
888 "%s", strerror (errno))do { do { if (0) printf ("%s", strerror ((*__errno_location (
)))); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 888, GF_LOG_ERROR, "%s", strerror ((*__errno_location
()))); } while (0)
;
889 goto out;
890 }
891 close (fd);
892
893 file = fopen (filename, "w+");
894 if (!file) {
895 gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("Open of volfile failed"); } while (
0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 896, GF_LOG_DEBUG, "Open of volfile failed"); } while (0)
896 "Open of volfile failed")do { do { if (0) printf ("Open of volfile failed"); } while (
0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 896, GF_LOG_DEBUG, "Open of volfile failed"); } while (0)
;
897 ret = -1;
898 goto out;
899 }
900
901 GF_ASSERT (src_brickinfo->port)do { if (!(src_brickinfo->port)) { do { do { if (0) printf
("Assertion failed: " "src_brickinfo->port"); } while (0)
; _gf_log_callingfn ("", "glusterd-replace-brick.c", __FUNCTION__
, 901, GF_LOG_ERROR, "Assertion failed: " "src_brickinfo->port"
); } while (0); } } while (0)
;
902
903 ttype = glusterd_get_trans_type_rb (volinfo->transport_type);
904 if (NULL((void*)0) == ttype){
905 ret = -1;
906 goto out;
907 }
908
909 fprintf (file, client_volfile_str, src_brickinfo->hostname,
910 src_brickinfo->path,
911 src_brickinfo->port, ttype,
912 glusterd_auth_get_username (volinfo),
913 glusterd_auth_get_password (volinfo));
914
915 fclose (file);
916 GF_FREE (ttype)__gf_free (ttype);
917
918 ret = 0;
919
920out:
921 return ret;
922}
923
924static const char *dst_brick_volfile_str = "volume src-posix\n"
925 " type storage/posix\n"
926 " option directory %s\n"
927 " option volume-id %s\n"
928 "end-volume\n"
929 "volume %s\n"
930 " type features/locks\n"
931 " subvolumes src-posix\n"
932 "end-volume\n"
933 "volume src-server\n"
934 " type protocol/server\n"
935 " option auth.login.%s.allow %s\n"
936 " option auth.login.%s.password %s\n"
937 " option auth.addr.%s.allow *\n"
938 " option transport-type %s\n"
939 " subvolumes %s\n"
940 "end-volume\n";
941
942static int
943rb_generate_dst_brick_volfile (glusterd_volinfo_t *volinfo,
944 glusterd_brickinfo_t *dst_brickinfo)
945{
946 glusterd_conf_t *priv = NULL((void*)0);
947 xlator_t *this = NULL((void*)0);
948 FILE *file = NULL((void*)0);
949 char filename[PATH_MAX4096] = {0, };
950 int ret = -1;
951 int fd = -1;
952 char *trans_type = NULL((void*)0);
953
954 this = THIS(*__glusterfs_this_location());
955 priv = this->private;
956
957 gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("Creating volfile"); } while (0); _gf_log
(this->name, "glusterd-replace-brick.c", __FUNCTION__, 958
, GF_LOG_DEBUG, "Creating volfile"); } while (0)
958 "Creating volfile")do { do { if (0) printf ("Creating volfile"); } while (0); _gf_log
(this->name, "glusterd-replace-brick.c", __FUNCTION__, 958
, GF_LOG_DEBUG, "Creating volfile"); } while (0)
;
959
960 snprintf (filename, PATH_MAX4096, "%s/vols/%s/%s",
961 priv->workdir, volinfo->volname,
962 RB_DSTBRICKVOL_FILENAME"rb_dst_brick.vol");
963
964 fd = creat (filename, S_IRUSR0400 | S_IWUSR0200);
965 if (fd < 0) {
966 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("%s", strerror ((*__errno_location (
)))); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 967, GF_LOG_ERROR, "%s", strerror ((*__errno_location
()))); } while (0)
967 "%s", strerror (errno))do { do { if (0) printf ("%s", strerror ((*__errno_location (
)))); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 967, GF_LOG_ERROR, "%s", strerror ((*__errno_location
()))); } while (0)
;
968 goto out;
969 }
970 close (fd);
971
972 file = fopen (filename, "w+");
973 if (!file) {
974 gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("Open of volfile failed"); } while (
0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 975, GF_LOG_DEBUG, "Open of volfile failed"); } while (0)
975 "Open of volfile failed")do { do { if (0) printf ("Open of volfile failed"); } while (
0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 975, GF_LOG_DEBUG, "Open of volfile failed"); } while (0)
;
976 ret = -1;
977 goto out;
978 }
979
980 trans_type = glusterd_get_trans_type_rb (volinfo->transport_type);
981 if (NULL((void*)0) == trans_type){
982 ret = -1;
983 goto out;
984 }
985
986 fprintf (file, dst_brick_volfile_str,
987 dst_brickinfo->path,
988 uuid_utoa (volinfo->volume_id),
989 dst_brickinfo->path,
990 dst_brickinfo->path,
991 glusterd_auth_get_username (volinfo),
992 glusterd_auth_get_username (volinfo),
993 glusterd_auth_get_password (volinfo),
994 dst_brickinfo->path,
995 trans_type,
996 dst_brickinfo->path);
997
998 GF_FREE (trans_type)__gf_free (trans_type);
999
1000 fclose (file);
1001
1002 ret = 0;
1003
1004out:
1005 return ret;
1006}
1007
1008
1009static int
1010rb_mountpoint_mkdir (glusterd_volinfo_t *volinfo,
1011 glusterd_brickinfo_t *src_brickinfo)
1012{
1013 char mntpt[PATH_MAX4096] = {0,};
1014 int ret = -1;
1015
1016 GLUSTERD_GET_RB_MNTPT (mntpt, sizeof (mntpt), volinfo)snprintf (mntpt, sizeof (mntpt), "/usr/local/var" "/run/gluster"
"/%s-""rb_mount", volinfo->volname);
;
1017 ret = mkdir (mntpt, 0777);
1018 if (ret && (errno(*__errno_location ()) != EEXIST17)) {
1019 gf_log ("", GF_LOG_DEBUG, "mkdir failed, due to %s",do { do { if (0) printf ("mkdir failed, due to %s", strerror (
(*__errno_location ()))); } while (0); _gf_log ("", "glusterd-replace-brick.c"
, __FUNCTION__, 1020, GF_LOG_DEBUG, "mkdir failed, due to %s"
, strerror ((*__errno_location ()))); } while (0)
1020 strerror (errno))do { do { if (0) printf ("mkdir failed, due to %s", strerror (
(*__errno_location ()))); } while (0); _gf_log ("", "glusterd-replace-brick.c"
, __FUNCTION__, 1020, GF_LOG_DEBUG, "mkdir failed, due to %s"
, strerror ((*__errno_location ()))); } while (0)
;
1021 goto out;
1022 }
1023
1024 ret = 0;
1025
1026out:
1027 return ret;
1028}
1029
1030static int
1031rb_mountpoint_rmdir (glusterd_volinfo_t *volinfo,
1032 glusterd_brickinfo_t *src_brickinfo)
1033{
1034 char mntpt[PATH_MAX4096] = {0,};
1035 int ret = -1;
1036
1037 GLUSTERD_GET_RB_MNTPT (mntpt, sizeof (mntpt), volinfo)snprintf (mntpt, sizeof (mntpt), "/usr/local/var" "/run/gluster"
"/%s-""rb_mount", volinfo->volname);
;
1038 ret = rmdir (mntpt);
1039 if (ret) {
1040 gf_log ("", GF_LOG_DEBUG, "rmdir failed, reason: %s",do { do { if (0) printf ("rmdir failed, reason: %s", strerror
((*__errno_location ()))); } while (0); _gf_log ("", "glusterd-replace-brick.c"
, __FUNCTION__, 1041, GF_LOG_DEBUG, "rmdir failed, reason: %s"
, strerror ((*__errno_location ()))); } while (0)
1041 strerror (errno))do { do { if (0) printf ("rmdir failed, reason: %s", strerror
((*__errno_location ()))); } while (0); _gf_log ("", "glusterd-replace-brick.c"
, __FUNCTION__, 1041, GF_LOG_DEBUG, "rmdir failed, reason: %s"
, strerror ((*__errno_location ()))); } while (0)
;
1042 goto out;
1043 }
1044
1045 ret = 0;
1046
1047out:
1048 return ret;
1049}
1050
1051static int
1052rb_destroy_maintenance_client (glusterd_volinfo_t *volinfo,
1053 glusterd_brickinfo_t *src_brickinfo)
1054{
1055 xlator_t *this = NULL((void*)0);
1056 glusterd_conf_t *priv = NULL((void*)0);
1057 char volfile[PATH_MAX4096] = {0,};
1058 int ret = -1;
1059 int mntfd = -1;
1060
1061 this = THIS(*__glusterfs_this_location());
1062 priv = this->private;
1063
1064 ret = rb_get_mntfd (&mntfd);
1065 if (ret)
1066 goto out;
1067
1068 ret = close (mntfd);
1069 if (ret) {
1070 gf_log (this->name, GF_LOG_DEBUG, "Failed to close mount "do { do { if (0) printf ("Failed to close mount " "point directory"
); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1071, GF_LOG_DEBUG, "Failed to close mount " "point directory"
); } while (0)
1071 "point directory")do { do { if (0) printf ("Failed to close mount " "point directory"
); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1071, GF_LOG_DEBUG, "Failed to close mount " "point directory"
); } while (0)
;
1072 goto out;
1073 }
1074
1075 ret = rb_mountpoint_rmdir (volinfo, src_brickinfo);
1076 if (ret) {
1077 gf_log (this->name, GF_LOG_DEBUG, "rmdir of mountpoint "do { do { if (0) printf ("rmdir of mountpoint " "failed"); } while
(0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 1078, GF_LOG_DEBUG, "rmdir of mountpoint " "failed"); } while
(0)
1078 "failed")do { do { if (0) printf ("rmdir of mountpoint " "failed"); } while
(0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 1078, GF_LOG_DEBUG, "rmdir of mountpoint " "failed"); } while
(0)
;
1079 goto out;
1080 }
1081
1082 snprintf (volfile, PATH_MAX4096, "%s/vols/%s/%s", priv->workdir,
1083 volinfo->volname, RB_CLIENTVOL_FILENAME"rb_client.vol");
1084
1085 ret = unlink (volfile);
1086 if (ret) {
1087 gf_log ("", GF_LOG_DEBUG, "unlink of %s failed, reason: %s",do { do { if (0) printf ("unlink of %s failed, reason: %s", volfile
, strerror ((*__errno_location ()))); } while (0); _gf_log (""
, "glusterd-replace-brick.c", __FUNCTION__, 1088, GF_LOG_DEBUG
, "unlink of %s failed, reason: %s", volfile, strerror ((*__errno_location
()))); } while (0)
1088 volfile, strerror (errno))do { do { if (0) printf ("unlink of %s failed, reason: %s", volfile
, strerror ((*__errno_location ()))); } while (0); _gf_log (""
, "glusterd-replace-brick.c", __FUNCTION__, 1088, GF_LOG_DEBUG
, "unlink of %s failed, reason: %s", volfile, strerror ((*__errno_location
()))); } while (0)
;
1089 goto out;
1090 }
1091
1092 ret = 0;
1093
1094out:
1095 return ret;
1096}
1097
1098static int
1099rb_spawn_maintenance_client (glusterd_volinfo_t *volinfo,
1100 glusterd_brickinfo_t *src_brickinfo)
1101{
1102 int ret = -1;
1103
1104 ret = rb_generate_client_volfile (volinfo, src_brickinfo);
1105 if (ret) {
1106 gf_log ("", GF_LOG_DEBUG, "Unable to generate client "do { do { if (0) printf ("Unable to generate client " "volfile"
); } while (0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__
, 1107, GF_LOG_DEBUG, "Unable to generate client " "volfile")
; } while (0)
1107 "volfile")do { do { if (0) printf ("Unable to generate client " "volfile"
); } while (0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__
, 1107, GF_LOG_DEBUG, "Unable to generate client " "volfile")
; } while (0)
;
1108 goto out;
1109 }
1110
1111 ret = rb_mountpoint_mkdir (volinfo, src_brickinfo);
1112 if (ret) {
1113 gf_log ("", GF_LOG_DEBUG, "Unable to mkdir "do { do { if (0) printf ("Unable to mkdir " "mountpoint"); } while
(0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__, 1114
, GF_LOG_DEBUG, "Unable to mkdir " "mountpoint"); } while (0)
1114 "mountpoint")do { do { if (0) printf ("Unable to mkdir " "mountpoint"); } while
(0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__, 1114
, GF_LOG_DEBUG, "Unable to mkdir " "mountpoint"); } while (0)
;
1115 goto out;
1116 }
1117
1118 ret = rb_spawn_glusterfs_client (volinfo, src_brickinfo);
1119 if (ret) {
1120 gf_log ("", GF_LOG_DEBUG, "Unable to start glusterfs")do { do { if (0) printf ("Unable to start glusterfs"); } while
(0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__, 1120
, GF_LOG_DEBUG, "Unable to start glusterfs"); } while (0)
;
1121 goto out;
1122 }
1123
1124 ret = 0;
1125out:
1126 return ret;
1127}
1128
1129static int
1130rb_spawn_destination_brick (glusterd_volinfo_t *volinfo,
1131 glusterd_brickinfo_t *dst_brickinfo)
1132
1133{
1134 int ret = -1;
1135
1136 ret = rb_generate_dst_brick_volfile (volinfo, dst_brickinfo);
1137 if (ret) {
1138 gf_log ("", GF_LOG_DEBUG, "Unable to generate client "do { do { if (0) printf ("Unable to generate client " "volfile"
); } while (0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__
, 1139, GF_LOG_DEBUG, "Unable to generate client " "volfile")
; } while (0)
1139 "volfile")do { do { if (0) printf ("Unable to generate client " "volfile"
); } while (0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__
, 1139, GF_LOG_DEBUG, "Unable to generate client " "volfile")
; } while (0)
;
1140 goto out;
1141 }
1142
1143 ret = rb_spawn_dst_brick (volinfo, dst_brickinfo);
1144 if (ret) {
1145 gf_log ("", GF_LOG_DEBUG, "Unable to start glusterfs")do { do { if (0) printf ("Unable to start glusterfs"); } while
(0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__, 1145
, GF_LOG_DEBUG, "Unable to start glusterfs"); } while (0)
;
1146 goto out;
1147 }
1148
1149 ret = 0;
1150out:
1151 return ret;
1152}
1153
1154static int
1155rb_kill_destination_brick (glusterd_volinfo_t *volinfo,
1156 glusterd_brickinfo_t *dst_brickinfo)
1157{
1158 glusterd_conf_t *priv = NULL((void*)0);
1159 char pidfile[PATH_MAX4096] = {0,};
1160
1161 priv = THIS(*__glusterfs_this_location())->private;
1162
1163 snprintf (pidfile, PATH_MAX4096, "%s/vols/%s/%s",
1164 priv->workdir, volinfo->volname,
1165 RB_DSTBRICK_PIDFILE"rb_dst_brick.pid");
1166
1167 return glusterd_service_stop ("brick", pidfile, SIGTERM15, _gf_true);
1168}
1169
1170static int
1171rb_get_xattr_command (glusterd_volinfo_t *volinfo,
1172 glusterd_brickinfo_t *src_brickinfo,
1173 glusterd_brickinfo_t *dst_brickinfo,
1174 const char *xattr_key,
1175 char *value)
1176{
1177 int ret = -1;
1178 int mntfd = -1;
1179
1180 ret = rb_get_mntfd (&mntfd);
1181 if (ret)
1182 goto out;
1183
1184 ret = sys_fgetxattr (mntfd, xattr_key, value, 8192);
1185
1186 if (ret < 0) {
1187 gf_log (THIS->name, GF_LOG_DEBUG, "getxattr on key: %s "do { do { if (0) printf ("getxattr on key: %s " "failed, reason: %s"
, xattr_key, strerror ((*__errno_location ()))); } while (0);
_gf_log ((*__glusterfs_this_location())->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1188, GF_LOG_DEBUG, "getxattr on key: %s " "failed, reason: %s"
, xattr_key, strerror ((*__errno_location ()))); } while (0)
1188 "failed, reason: %s", xattr_key, strerror (errno))do { do { if (0) printf ("getxattr on key: %s " "failed, reason: %s"
, xattr_key, strerror ((*__errno_location ()))); } while (0);
_gf_log ((*__glusterfs_this_location())->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1188, GF_LOG_DEBUG, "getxattr on key: %s " "failed, reason: %s"
, xattr_key, strerror ((*__errno_location ()))); } while (0)
;
1189 goto out;
1190 }
1191
1192 ret = 0;
1193out:
1194 return ret;
1195}
1196
1197static int
1198rb_send_cmd (glusterd_volinfo_t *volinfo,
1199 glusterd_brickinfo_t *src,
1200 glusterd_brickinfo_t *dst,
1201 gf1_cli_replace_op op)
1202{
1203 char start_value[8192] = {0,};
1204 char status_str[8192] = {0,};
1205 char *status_reply = NULL((void*)0);
1206 char *tmp = NULL((void*)0);
1207 char *save_ptr = NULL((void*)0);
1208 char filename[PATH_MAX4096] = {0,};
1209 char *current_file = NULL((void*)0);
1210 uint64_t files = 0;
1211 int status = 0;
1212 dict_t *ctx = NULL((void*)0);
1213 int ret = 0;
1214
1215 GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: "
"volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-replace-brick.c"
, __FUNCTION__, 1215, GF_LOG_ERROR, "Assertion failed: " "volinfo"
); } while (0); } } while (0)
;
1216 GF_ASSERT (src)do { if (!(src)) { do { do { if (0) printf ("Assertion failed: "
"src"); } while (0); _gf_log_callingfn ("", "glusterd-replace-brick.c"
, __FUNCTION__, 1216, GF_LOG_ERROR, "Assertion failed: " "src"
); } while (0); } } while (0)
;
1217 GF_ASSERT (dst)do { if (!(dst)) { do { do { if (0) printf ("Assertion failed: "
"dst"); } while (0); _gf_log_callingfn ("", "glusterd-replace-brick.c"
, __FUNCTION__, 1217, GF_LOG_ERROR, "Assertion failed: " "dst"
); } while (0); } } while (0)
;
1
Within the expansion of the macro 'GF_ASSERT':
a
Assuming 'dst' is null
1218 GF_ASSERT ((op > GF_REPLACE_OP_NONE)do { if (!((op > GF_REPLACE_OP_NONE) && (op <= GF_REPLACE_OP_COMMIT_FORCE
))) { do { do { if (0) printf ("Assertion failed: " "(op > GF_REPLACE_OP_NONE) && (op <= GF_REPLACE_OP_COMMIT_FORCE)"
); } while (0); _gf_log_callingfn ("", "glusterd-replace-brick.c"
, __FUNCTION__, 1219, GF_LOG_ERROR, "Assertion failed: " "(op > GF_REPLACE_OP_NONE) && (op <= GF_REPLACE_OP_COMMIT_FORCE)"
); } while (0); } } while (0)
1219 && (op <= GF_REPLACE_OP_COMMIT_FORCE))do { if (!((op > GF_REPLACE_OP_NONE) && (op <= GF_REPLACE_OP_COMMIT_FORCE
))) { do { do { if (0) printf ("Assertion failed: " "(op > GF_REPLACE_OP_NONE) && (op <= GF_REPLACE_OP_COMMIT_FORCE)"
); } while (0); _gf_log_callingfn ("", "glusterd-replace-brick.c"
, __FUNCTION__, 1219, GF_LOG_ERROR, "Assertion failed: " "(op > GF_REPLACE_OP_NONE) && (op <= GF_REPLACE_OP_COMMIT_FORCE)"
); } while (0); } } while (0)
;
1220
1221 switch (op) {
2
Control jumps to 'case GF_REPLACE_OP_START:' at line 1222
1222 case GF_REPLACE_OP_START:
1223 {
1224 snprintf (start_value, sizeof (start_value),
1225 "%s:%s:%d", dst->hostname, dst->path,
1226 dst->port);
3
Access to field 'port' results in a dereference of a null pointer (loaded from variable 'dst')
1227 ret = rb_send_xattr_command (volinfo, src, dst,
1228 RB_PUMP_CMD_START"glusterfs.pump.start",
1229 start_value);
1230 }
1231 break;
1232 case GF_REPLACE_OP_PAUSE:
1233 {
1234 ret = rb_send_xattr_command (volinfo, src, dst,
1235 RB_PUMP_CMD_PAUSE"glusterfs.pump.pause",
1236 RB_PUMP_DEF_ARG"default");
1237 }
1238 break;
1239 case GF_REPLACE_OP_ABORT:
1240 {
1241 ret = rb_send_xattr_command (volinfo, src, dst,
1242 RB_PUMP_CMD_ABORT"glusterfs.pump.abort",
1243 RB_PUMP_DEF_ARG"default");
1244 }
1245 break;
1246 case GF_REPLACE_OP_COMMIT:
1247 {
1248 ret = rb_send_xattr_command (volinfo, src, dst,
1249 RB_PUMP_CMD_COMMIT"glusterfs.pump.commit",
1250 RB_PUMP_DEF_ARG"default");
1251 }
1252 break;
1253 case GF_REPLACE_OP_STATUS:
1254 {
1255 ret = rb_get_xattr_command (volinfo, src, dst,
1256 RB_PUMP_CMD_STATUS"glusterfs.pump.status",
1257 status_str);
1258 if (ret)
1259 goto out;
1260
1261 ctx = glusterd_op_get_ctx ();
1262 GF_ASSERT (ctx)do { if (!(ctx)) { do { do { if (0) printf ("Assertion failed: "
"ctx"); } while (0); _gf_log_callingfn ("", "glusterd-replace-brick.c"
, __FUNCTION__, 1262, GF_LOG_ERROR, "Assertion failed: " "ctx"
); } while (0); } } while (0)
;
1263 if (!ctx) {
1264 ret = -1;
1265 gf_log (THIS->name, GF_LOG_CRITICAL,do { do { if (0) printf ("ctx is not present."); } while (0);
_gf_log ((*__glusterfs_this_location())->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1266, GF_LOG_CRITICAL, "ctx is not present.")
; } while (0)
1266 "ctx is not present.")do { do { if (0) printf ("ctx is not present."); } while (0);
_gf_log ((*__glusterfs_this_location())->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1266, GF_LOG_CRITICAL, "ctx is not present.")
; } while (0)
;
1267 goto out;
1268 }
1269
1270 /* Split status reply into different parts */
1271 tmp = strtok_r (status_str, ":", &save_ptr);
1272 if (!tmp) {
1273 ret = -1;
1274 gf_log (THIS->name, GF_LOG_ERROR,do { do { if (0) printf ("Couldn't tokenize status string"); }
while (0); _gf_log ((*__glusterfs_this_location())->name,
"glusterd-replace-brick.c", __FUNCTION__, 1275, GF_LOG_ERROR
, "Couldn't tokenize status string"); } while (0)
1275 "Couldn't tokenize status string")do { do { if (0) printf ("Couldn't tokenize status string"); }
while (0); _gf_log ((*__glusterfs_this_location())->name,
"glusterd-replace-brick.c", __FUNCTION__, 1275, GF_LOG_ERROR
, "Couldn't tokenize status string"); } while (0)
;
1276 goto out;
1277 }
1278 sscanf (tmp, "status=%d", &status);
1279 ret = dict_set_int32 (ctx, "status", status);
1280 if (ret) {
1281 gf_log (THIS->name, GF_LOG_ERROR, "Couldn't "do { do { if (0) printf ("Couldn't " "set rb status in context"
); } while (0); _gf_log ((*__glusterfs_this_location())->name
, "glusterd-replace-brick.c", __FUNCTION__, 1282, GF_LOG_ERROR
, "Couldn't " "set rb status in context"); } while (0)
1282 "set rb status in context")do { do { if (0) printf ("Couldn't " "set rb status in context"
); } while (0); _gf_log ((*__glusterfs_this_location())->name
, "glusterd-replace-brick.c", __FUNCTION__, 1282, GF_LOG_ERROR
, "Couldn't " "set rb status in context"); } while (0)
;
1283 goto out;
1284 }
1285
1286 tmp = NULL((void*)0);
1287 tmp = strtok_r (NULL((void*)0), ":", &save_ptr);
1288 if (!tmp) {
1289 ret = -1;
1290 gf_log (THIS->name, GF_LOG_ERROR,do { do { if (0) printf ("Couldn't tokenize status string"); }
while (0); _gf_log ((*__glusterfs_this_location())->name,
"glusterd-replace-brick.c", __FUNCTION__, 1291, GF_LOG_ERROR
, "Couldn't tokenize status string"); } while (0)
1291 "Couldn't tokenize status string")do { do { if (0) printf ("Couldn't tokenize status string"); }
while (0); _gf_log ((*__glusterfs_this_location())->name,
"glusterd-replace-brick.c", __FUNCTION__, 1291, GF_LOG_ERROR
, "Couldn't tokenize status string"); } while (0)
;
1292 goto out;
1293 }
1294 sscanf (tmp, "no_of_files=%"SCNu64"ll" "u", &files);
1295 ret = dict_set_uint64 (ctx, "files", files);
1296 if (ret) {
1297 gf_log (THIS->name, GF_LOG_ERROR, "Couldn't "do { do { if (0) printf ("Couldn't " "set rb files in context"
); } while (0); _gf_log ((*__glusterfs_this_location())->name
, "glusterd-replace-brick.c", __FUNCTION__, 1298, GF_LOG_ERROR
, "Couldn't " "set rb files in context"); } while (0)
1298 "set rb files in context")do { do { if (0) printf ("Couldn't " "set rb files in context"
); } while (0); _gf_log ((*__glusterfs_this_location())->name
, "glusterd-replace-brick.c", __FUNCTION__, 1298, GF_LOG_ERROR
, "Couldn't " "set rb files in context"); } while (0)
;
1299 goto out;
1300 }
1301
1302 if (status == 0) {
1303 tmp = NULL((void*)0);
1304 tmp = strtok_r (NULL((void*)0), ":", &save_ptr);
1305 if (!tmp) {
1306 ret = -1;
1307 gf_log (THIS->name, GF_LOG_ERROR,do { do { if (0) printf ("Couldn't tokenize status " "string"
); } while (0); _gf_log ((*__glusterfs_this_location())->name
, "glusterd-replace-brick.c", __FUNCTION__, 1309, GF_LOG_ERROR
, "Couldn't tokenize status " "string"); } while (0)
1308 "Couldn't tokenize status "do { do { if (0) printf ("Couldn't tokenize status " "string"
); } while (0); _gf_log ((*__glusterfs_this_location())->name
, "glusterd-replace-brick.c", __FUNCTION__, 1309, GF_LOG_ERROR
, "Couldn't tokenize status " "string"); } while (0)
1309 "string")do { do { if (0) printf ("Couldn't tokenize status " "string"
); } while (0); _gf_log ((*__glusterfs_this_location())->name
, "glusterd-replace-brick.c", __FUNCTION__, 1309, GF_LOG_ERROR
, "Couldn't tokenize status " "string"); } while (0)
;
1310 goto out;
1311 }
1312 sscanf (tmp, "current_file=%s", filename);
1313 current_file = gf_strdup (filename);
1314 ret = dict_set_dynstr (ctx, "current_file",
1315 current_file);
1316 if (ret) {
1317 GF_FREE (current_file)__gf_free (current_file);
1318 gf_log (THIS->name, GF_LOG_ERROR,do { do { if (0) printf ("Couldn't set rb current file " "in context"
); } while (0); _gf_log ((*__glusterfs_this_location())->name
, "glusterd-replace-brick.c", __FUNCTION__, 1320, GF_LOG_ERROR
, "Couldn't set rb current file " "in context"); } while (0)
1319 "Couldn't set rb current file "do { do { if (0) printf ("Couldn't set rb current file " "in context"
); } while (0); _gf_log ((*__glusterfs_this_location())->name
, "glusterd-replace-brick.c", __FUNCTION__, 1320, GF_LOG_ERROR
, "Couldn't set rb current file " "in context"); } while (0)
1320 "in context")do { do { if (0) printf ("Couldn't set rb current file " "in context"
); } while (0); _gf_log ((*__glusterfs_this_location())->name
, "glusterd-replace-brick.c", __FUNCTION__, 1320, GF_LOG_ERROR
, "Couldn't set rb current file " "in context"); } while (0)
;
1321 goto out;
1322 }
1323 }
1324 if (status) {
1325 ret = gf_asprintf (&status_reply,
1326 "Number of files migrated = %"
1327 PRIu64"ll" "u""\tMigration complete",
1328 files);
1329 } else {
1330 ret = gf_asprintf (&status_reply,
1331 "Number of files migrated = %"
1332 PRIu64"ll" "u""\tCurrent file = %s",
1333 files, filename);
1334 }
1335 if (ret == -1) {
1336 gf_log (THIS->name, GF_LOG_ERROR,do { do { if (0) printf ("Failed to create status_reply string"
); } while (0); _gf_log ((*__glusterfs_this_location())->name
, "glusterd-replace-brick.c", __FUNCTION__, 1337, GF_LOG_ERROR
, "Failed to create status_reply string"); } while (0)
1337 "Failed to create status_reply string")do { do { if (0) printf ("Failed to create status_reply string"
); } while (0); _gf_log ((*__glusterfs_this_location())->name
, "glusterd-replace-brick.c", __FUNCTION__, 1337, GF_LOG_ERROR
, "Failed to create status_reply string"); } while (0)
;
1338 goto out;
1339 }
1340 ret = dict_set_dynstr (ctx, "status-reply",
1341 status_reply);
1342 if (ret) {
1343 GF_FREE (status_reply)__gf_free (status_reply);
1344 gf_log (THIS->name, GF_LOG_ERROR, "Couldn't "do { do { if (0) printf ("Couldn't " "set rb status response in context."
); } while (0); _gf_log ((*__glusterfs_this_location())->name
, "glusterd-replace-brick.c", __FUNCTION__, 1345, GF_LOG_ERROR
, "Couldn't " "set rb status response in context."); } while (
0)
1345 "set rb status response in context.")do { do { if (0) printf ("Couldn't " "set rb status response in context."
); } while (0); _gf_log ((*__glusterfs_this_location())->name
, "glusterd-replace-brick.c", __FUNCTION__, 1345, GF_LOG_ERROR
, "Couldn't " "set rb status response in context."); } while (
0)
;
1346 goto out;
1347 }
1348 }
1349 break;
1350 default:
1351 {
1352 GF_ASSERT (0)do { if (!(0)) { do { do { if (0) printf ("Assertion failed: "
"0"); } while (0); _gf_log_callingfn ("", "glusterd-replace-brick.c"
, __FUNCTION__, 1352, GF_LOG_ERROR, "Assertion failed: " "0")
; } while (0); } } while (0)
;
1353 ret = -1;
1354 gf_log (THIS->name, GF_LOG_CRITICAL, "Invalid replace"do { do { if (0) printf ("Invalid replace" " brick subcommand."
); } while (0); _gf_log ((*__glusterfs_this_location())->name
, "glusterd-replace-brick.c", __FUNCTION__, 1355, GF_LOG_CRITICAL
, "Invalid replace" " brick subcommand."); } while (0)
1355 " brick subcommand.")do { do { if (0) printf ("Invalid replace" " brick subcommand."
); } while (0); _gf_log ((*__glusterfs_this_location())->name
, "glusterd-replace-brick.c", __FUNCTION__, 1355, GF_LOG_CRITICAL
, "Invalid replace" " brick subcommand."); } while (0)
;
1356 }
1357 break;
1358 }
1359out:
1360 return ret;
1361}
1362
1363static int
1364rb_do_operation (glusterd_volinfo_t *volinfo,
1365 glusterd_brickinfo_t *src_brickinfo,
1366 glusterd_brickinfo_t *dst_brickinfo,
1367 gf1_cli_replace_op op)
1368{
1369
1370 int ret = -1;
1371 char op_str[256] = {0, };
1372 xlator_t *this = NULL((void*)0);
1373
1374 this = THIS(*__glusterfs_this_location());
1375
1376 ret = rb_spawn_maintenance_client (volinfo, src_brickinfo);
1377 if (ret) {
1378 gf_log (this->name, GF_LOG_DEBUG, "Could not spawn "do { do { if (0) printf ("Could not spawn " "maintenance client"
); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1379, GF_LOG_DEBUG, "Could not spawn " "maintenance client"
); } while (0)
1379 "maintenance client")do { do { if (0) printf ("Could not spawn " "maintenance client"
); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1379, GF_LOG_DEBUG, "Could not spawn " "maintenance client"
); } while (0)
;
1380 goto umount;
1381 }
1382
1383 ret = rb_send_cmd (volinfo, src_brickinfo, dst_brickinfo, op);
1384 if (ret) {
1385 (void) glusterd_get_replace_op_str (op, op_str);
1386 gf_log (this->name, GF_LOG_DEBUG, "Sending replace-brick "do { do { if (0) printf ("Sending replace-brick " "sub-command %s failed."
, op_str); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1387, GF_LOG_DEBUG, "Sending replace-brick " "sub-command %s failed."
, op_str); } while (0)
1387 "sub-command %s failed.", op_str)do { do { if (0) printf ("Sending replace-brick " "sub-command %s failed."
, op_str); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1387, GF_LOG_DEBUG, "Sending replace-brick " "sub-command %s failed."
, op_str); } while (0)
;
1388 }
1389
1390umount:
1391 if (rb_destroy_maintenance_client (volinfo, src_brickinfo))
1392 gf_log (this->name, GF_LOG_DEBUG, "Failed to destroy "do { do { if (0) printf ("Failed to destroy " "maintenance client"
); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1393, GF_LOG_DEBUG, "Failed to destroy " "maintenance client"
); } while (0)
1393 "maintenance client")do { do { if (0) printf ("Failed to destroy " "maintenance client"
); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1393, GF_LOG_DEBUG, "Failed to destroy " "maintenance client"
); } while (0)
;
1394
1395 return ret;
1396}
1397
1398/* Set src-brick's port number to be used in the maintenance mount
1399 * after all commit acks are received.
1400 */
1401static int
1402rb_update_srcbrick_port (glusterd_brickinfo_t *src_brickinfo, dict_t *rsp_dict,
1403 dict_t *req_dict, int32_t replace_op)
1404{
1405 xlator_t *this = NULL((void*)0);
1406 dict_t *ctx = NULL((void*)0);
1407 int ret = 0;
1408 int dict_ret = 0;
1409 int src_port = 0;
1410
1411 this = THIS(*__glusterfs_this_location());
1412
1413 dict_ret = dict_get_int32 (req_dict, "src-brick-port", &src_port);
1414 if (src_port)
1415 src_brickinfo->port = src_port;
1416
1417 if (glusterd_is_local_addr (src_brickinfo->hostname)) {
1418 gf_log ("", GF_LOG_INFO,do { do { if (0) printf ("adding src-brick port no"); } while
(0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__, 1419
, GF_LOG_INFO, "adding src-brick port no"); } while (0)
1419 "adding src-brick port no")do { do { if (0) printf ("adding src-brick port no"); } while
(0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__, 1419
, GF_LOG_INFO, "adding src-brick port no"); } while (0)
;
1420
1421 src_brickinfo->port = pmap_registry_search (this,
1422 src_brickinfo->path, GF_PMAP_PORT_BRICKSERVER);
1423 if (!src_brickinfo->port &&
1424 replace_op != GF_REPLACE_OP_COMMIT_FORCE ) {
1425 gf_log ("", GF_LOG_ERROR,do { do { if (0) printf ("Src brick port not available"); } while
(0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__, 1426
, GF_LOG_ERROR, "Src brick port not available"); } while (0)
1426 "Src brick port not available")do { do { if (0) printf ("Src brick port not available"); } while
(0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__, 1426
, GF_LOG_ERROR, "Src brick port not available"); } while (0)
;
1427 ret = -1;
1428 goto out;
1429 }
1430
1431 if (rsp_dict) {
1432 ret = dict_set_int32 (rsp_dict, "src-brick-port", src_brickinfo->port);
1433 if (ret) {
1434 gf_log ("", GF_LOG_DEBUG,do { do { if (0) printf ("Could not set src-brick port no"); }
while (0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__
, 1435, GF_LOG_DEBUG, "Could not set src-brick port no"); } while
(0)
1435 "Could not set src-brick port no")do { do { if (0) printf ("Could not set src-brick port no"); }
while (0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__
, 1435, GF_LOG_DEBUG, "Could not set src-brick port no"); } while
(0)
;
1436 goto out;
1437 }
1438 }
1439
1440 ctx = glusterd_op_get_ctx ();
1441 if (ctx) {
1442 ret = dict_set_int32 (ctx, "src-brick-port", src_brickinfo->port);
1443 if (ret) {
1444 gf_log ("", GF_LOG_DEBUG,do { do { if (0) printf ("Could not set src-brick port no"); }
while (0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__
, 1445, GF_LOG_DEBUG, "Could not set src-brick port no"); } while
(0)
1445 "Could not set src-brick port no")do { do { if (0) printf ("Could not set src-brick port no"); }
while (0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__
, 1445, GF_LOG_DEBUG, "Could not set src-brick port no"); } while
(0)
;
1446 goto out;
1447 }
1448 }
1449
1450 }
1451
1452out:
1453 return ret;
1454
1455}
1456
1457static int
1458rb_update_dstbrick_port (glusterd_brickinfo_t *dst_brickinfo, dict_t *rsp_dict,
1459 dict_t *req_dict, int32_t replace_op)
1460{
1461 dict_t *ctx = NULL((void*)0);
1462 int ret = 0;
1463 int dict_ret = 0;
1464 int dst_port = 0;
1465
1466 dict_ret = dict_get_int32 (req_dict, "dst-brick-port", &dst_port);
1467 if (!dict_ret)
1468 dst_brickinfo->port = dst_port;
1469
1470
1471 if (glusterd_is_local_addr (dst_brickinfo->hostname)) {
1472 gf_log ("", GF_LOG_INFO,do { do { if (0) printf ("adding dst-brick port no"); } while
(0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__, 1473
, GF_LOG_INFO, "adding dst-brick port no"); } while (0)
1473 "adding dst-brick port no")do { do { if (0) printf ("adding dst-brick port no"); } while
(0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__, 1473
, GF_LOG_INFO, "adding dst-brick port no"); } while (0)
;
1474
1475 if (rsp_dict) {
1476 ret = dict_set_int32 (rsp_dict, "dst-brick-port",
1477 dst_brickinfo->port);
1478 if (ret) {
1479 gf_log ("", GF_LOG_DEBUG,do { do { if (0) printf ("Could not set dst-brick port no in rsp dict"
); } while (0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__
, 1480, GF_LOG_DEBUG, "Could not set dst-brick port no in rsp dict"
); } while (0)
1480 "Could not set dst-brick port no in rsp dict")do { do { if (0) printf ("Could not set dst-brick port no in rsp dict"
); } while (0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__
, 1480, GF_LOG_DEBUG, "Could not set dst-brick port no in rsp dict"
); } while (0)
;
1481 goto out;
1482 }
1483 }
1484
1485 ctx = glusterd_op_get_ctx ();
1486 if (ctx) {
1487 ret = dict_set_int32 (ctx, "dst-brick-port",
1488 dst_brickinfo->port);
1489 if (ret) {
1490 gf_log ("", GF_LOG_DEBUG,do { do { if (0) printf ("Could not set dst-brick port no"); }
while (0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__
, 1491, GF_LOG_DEBUG, "Could not set dst-brick port no"); } while
(0)
1491 "Could not set dst-brick port no")do { do { if (0) printf ("Could not set dst-brick port no"); }
while (0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__
, 1491, GF_LOG_DEBUG, "Could not set dst-brick port no"); } while
(0)
;
1492 goto out;
1493 }
1494 }
1495 }
1496out:
1497 return ret;
1498}
1499
1500static int
1501glusterd_op_perform_replace_brick (glusterd_volinfo_t *volinfo,
1502 char *old_brick, char *new_brick)
1503{
1504 glusterd_brickinfo_t *old_brickinfo = NULL((void*)0);
1505 glusterd_brickinfo_t *new_brickinfo = NULL((void*)0);
1506 int32_t ret = -1;
1507
1508 GF_ASSERT (volinfo)do { if (!(volinfo)) { do { do { if (0) printf ("Assertion failed: "
"volinfo"); } while (0); _gf_log_callingfn ("", "glusterd-replace-brick.c"
, __FUNCTION__, 1508, GF_LOG_ERROR, "Assertion failed: " "volinfo"
); } while (0); } } while (0)
;
1509
1510 ret = glusterd_brickinfo_new_from_brick (new_brick,
1511 &new_brickinfo);
1512 if (ret)
1513 goto out;
1514
1515 ret = glusterd_resolve_brick (new_brickinfo);
1516
1517 if (ret)
1518 goto out;
1519
1520 ret = glusterd_volume_brickinfo_get_by_brick (old_brick,
1521 volinfo, &old_brickinfo);
1522 if (ret)
1523 goto out;
1524
1525 list_add_tail (&new_brickinfo->brick_list,
1526 &old_brickinfo->brick_list);
1527
1528 volinfo->brick_count++;
1529
1530 ret = glusterd_op_perform_remove_brick (volinfo, old_brick, 1, NULL((void*)0));
1531 if (ret)
1532 goto out;
1533
1534 ret = glusterd_create_volfiles_and_notify_services (volinfo);
1535 if (ret)
1536 goto out;
1537
1538 if (GLUSTERD_STATUS_STARTED == volinfo->status) {
1539 ret = glusterd_brick_start (volinfo, new_brickinfo, _gf_false);
1540 if (ret)
1541 goto out;
1542 }
1543
1544out:
1545
1546 gf_log ("", GF_LOG_DEBUG, "Returning %d", ret)do { do { if (0) printf ("Returning %d", ret); } while (0); _gf_log
("", "glusterd-replace-brick.c", __FUNCTION__, 1546, GF_LOG_DEBUG
, "Returning %d", ret); } while (0)
;
1547 return ret;
1548}
1549
1550int
1551glusterd_op_replace_brick (dict_t *dict, dict_t *rsp_dict)
1552{
1553 int ret = 0;
1554 dict_t *ctx = NULL((void*)0);
1555 int replace_op = 0;
1556 glusterd_volinfo_t *volinfo = NULL((void*)0);
1557 char *volname = NULL((void*)0);
1558 xlator_t *this = NULL((void*)0);
1559 glusterd_conf_t *priv = NULL((void*)0);
1560 char *src_brick = NULL((void*)0);
1561 char *dst_brick = NULL((void*)0);
1562 glusterd_brickinfo_t *src_brickinfo = NULL((void*)0);
1563 glusterd_brickinfo_t *dst_brickinfo = NULL((void*)0);
1564 char *task_id_str = NULL((void*)0);
1565
1566 this = THIS(*__glusterfs_this_location());
1567 GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: "
"this"); } while (0); _gf_log_callingfn ("", "glusterd-replace-brick.c"
, __FUNCTION__, 1567, GF_LOG_ERROR, "Assertion failed: " "this"
); } while (0); } } while (0)
;
1568
1569 priv = this->private;
1570 GF_ASSERT (priv)do { if (!(priv)) { do { do { if (0) printf ("Assertion failed: "
"priv"); } while (0); _gf_log_callingfn ("", "glusterd-replace-brick.c"
, __FUNCTION__, 1570, GF_LOG_ERROR, "Assertion failed: " "priv"
); } while (0); } } while (0)
;
1571
1572 ret = dict_get_str (dict, "src-brick", &src_brick);
1573 if (ret) {
1574 gf_log (this->name, GF_LOG_ERROR, "Unable to get src brick")do { do { if (0) printf ("Unable to get src brick"); } while (
0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 1574, GF_LOG_ERROR, "Unable to get src brick"); } while (0)
;
1575 goto out;
1576 }
1577
1578 gf_log (this->name, GF_LOG_DEBUG, "src brick=%s", src_brick)do { do { if (0) printf ("src brick=%s", src_brick); } while (
0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 1578, GF_LOG_DEBUG, "src brick=%s", src_brick); } while (0)
;
1579
1580 ret = dict_get_str (dict, "dst-brick", &dst_brick);
1581 if (ret) {
1582 gf_log (this->name, GF_LOG_ERROR, "Unable to get dst brick")do { do { if (0) printf ("Unable to get dst brick"); } while (
0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 1582, GF_LOG_ERROR, "Unable to get dst brick"); } while (0)
;
1583 goto out;
1584 }
1585
1586 gf_log (this->name, GF_LOG_DEBUG, "dst brick=%s", dst_brick)do { do { if (0) printf ("dst brick=%s", dst_brick); } while (
0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 1586, GF_LOG_DEBUG, "dst brick=%s", dst_brick); } while (0)
;
1587
1588 ret = dict_get_str (dict, "volname", &volname);
1589 if (ret) {
1590 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-replace-brick.c", __FUNCTION__
, 1590, GF_LOG_ERROR, "Unable to get volume name"); } while (
0)
;
1591 goto out;
1592 }
1593
1594 ret = dict_get_int32 (dict, "operation", (int32_t *)&replace_op);
1595 if (ret) {
1596 gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("dict_get on operation failed"); } while
(0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 1597, GF_LOG_DEBUG, "dict_get on operation failed"); } while
(0)
1597 "dict_get on operation failed")do { do { if (0) printf ("dict_get on operation failed"); } while
(0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 1597, GF_LOG_DEBUG, "dict_get on operation failed"); } while
(0)
;
1598 goto out;
1599 }
1600
1601 ret = glusterd_volinfo_find (volname, &volinfo);
1602 if (ret) {
1603 gf_log (this->name, GF_LOG_ERROR, "Unable to allocate memory")do { do { if (0) printf ("Unable to allocate memory"); } while
(0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 1603, GF_LOG_ERROR, "Unable to allocate memory"); } while (
0)
;
1604 goto out;
1605 }
1606
1607 ret = glusterd_volume_brickinfo_get_by_brick (src_brick, volinfo,
1608 &src_brickinfo);
1609 if (ret) {
1610 gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("Unable to get src-brickinfo"); } while
(0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 1611, GF_LOG_DEBUG, "Unable to get src-brickinfo"); } while
(0)
1611 "Unable to get src-brickinfo")do { do { if (0) printf ("Unable to get src-brickinfo"); } while
(0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 1611, GF_LOG_DEBUG, "Unable to get src-brickinfo"); } while
(0)
;
1612 goto out;
1613 }
1614
1615
1616 ret = glusterd_get_rb_dst_brickinfo (volinfo, &dst_brickinfo);
1617 if (ret) {
1618 gf_log (this->name, GF_LOG_ERROR, "Unable to get "do { do { if (0) printf ("Unable to get " "replace brick destination brickinfo"
); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1619, GF_LOG_ERROR, "Unable to get " "replace brick destination brickinfo"
); } while (0)
1619 "replace brick destination brickinfo")do { do { if (0) printf ("Unable to get " "replace brick destination brickinfo"
); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1619, GF_LOG_ERROR, "Unable to get " "replace brick destination brickinfo"
); } while (0)
;
1620 goto out;
1621 }
1622
1623 ret = glusterd_resolve_brick (dst_brickinfo);
1624 if (ret) {
1625 gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("Unable to resolve dst-brickinfo"); }
while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1626, GF_LOG_DEBUG, "Unable to resolve dst-brickinfo"
); } while (0)
1626 "Unable to resolve dst-brickinfo")do { do { if (0) printf ("Unable to resolve dst-brickinfo"); }
while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1626, GF_LOG_DEBUG, "Unable to resolve dst-brickinfo"
); } while (0)
;
1627 goto out;
1628 }
1629
1630 ret = rb_update_srcbrick_port (src_brickinfo, rsp_dict,
1631 dict, replace_op);
1632 if (ret)
1633 goto out;
1634
1635
1636 if ((GF_REPLACE_OP_START != replace_op)) {
1637
1638 /* Set task-id, if available, in op_ctx dict for operations
1639 * other than start
1640 */
1641 if (is_origin_glusterd ()) {
1642 ctx = glusterd_op_get_ctx();
1643 if (!ctx) {
1644 gf_log (this->name, GF_LOG_ERROR, "Failed to "do { do { if (0) printf ("Failed to " "get op_ctx"); } while (
0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 1645, GF_LOG_ERROR, "Failed to " "get op_ctx"); } while (0)
1645 "get op_ctx")do { do { if (0) printf ("Failed to " "get op_ctx"); } while (
0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 1645, GF_LOG_ERROR, "Failed to " "get op_ctx"); } while (0)
;
1646 ret = -1;
1647 goto out;
1648 }
1649 if (!uuid_is_null (volinfo->rep_brick.rb_id)) {
1650 ret = glusterd_copy_uuid_to_dict
1651 (volinfo->rep_brick.rb_id, ctx,
1652 GF_REPLACE_BRICK_TID_KEY"replace-brick-id");
1653 if (ret) {
1654 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("Failed to set " "replace-brick-id")
; } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1656, GF_LOG_ERROR, "Failed to set " "replace-brick-id"
); } while (0)
1655 "Failed to set "do { do { if (0) printf ("Failed to set " "replace-brick-id")
; } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1656, GF_LOG_ERROR, "Failed to set " "replace-brick-id"
); } while (0)
1656 "replace-brick-id")do { do { if (0) printf ("Failed to set " "replace-brick-id")
; } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1656, GF_LOG_ERROR, "Failed to set " "replace-brick-id"
); } while (0)
;
1657 goto out;
1658 }
1659 }
1660 }
1661 }
1662 ret = rb_update_dstbrick_port (dst_brickinfo, rsp_dict,
1663 dict, replace_op);
1664 if (ret)
1665 goto out;
1666
1667 switch (replace_op) {
1668 case GF_REPLACE_OP_START:
1669 {
1670 ret = dict_get_str (dict, GF_REPLACE_BRICK_TID_KEY"replace-brick-id", &task_id_str);
1671 if (ret) {
1672 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("Missing replace-brick-id"); } while
(0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 1673, GF_LOG_ERROR, "Missing replace-brick-id"); } while (0
)
1673 "Missing replace-brick-id")do { do { if (0) printf ("Missing replace-brick-id"); } while
(0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 1673, GF_LOG_ERROR, "Missing replace-brick-id"); } while (0
)
;
1674 ret = 0;
1675 } else {
1676 uuid_parse (task_id_str, volinfo->rep_brick.rb_id);
1677 }
1678
1679 if (glusterd_is_local_addr (dst_brickinfo->hostname)) {
1680 gf_log (this->name, GF_LOG_INFO,do { do { if (0) printf ("I AM THE DESTINATION HOST"); } while
(0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 1681, GF_LOG_INFO, "I AM THE DESTINATION HOST"); } while (0
)
1681 "I AM THE DESTINATION HOST")do { do { if (0) printf ("I AM THE DESTINATION HOST"); } while
(0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 1681, GF_LOG_INFO, "I AM THE DESTINATION HOST"); } while (0
)
;
1682 if (!glusterd_is_rb_paused (volinfo)) {
1683 ret = rb_spawn_destination_brick
1684 (volinfo, dst_brickinfo);
1685 if (ret) {
1686 gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("Failed to spawn destination " "brick"
); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1688, GF_LOG_DEBUG, "Failed to spawn destination "
"brick"); } while (0)
1687 "Failed to spawn destination "do { do { if (0) printf ("Failed to spawn destination " "brick"
); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1688, GF_LOG_DEBUG, "Failed to spawn destination "
"brick"); } while (0)
1688 "brick")do { do { if (0) printf ("Failed to spawn destination " "brick"
); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1688, GF_LOG_DEBUG, "Failed to spawn destination "
"brick"); } while (0)
;
1689 goto out;
1690 }
1691 } else {
1692 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("Replace brick is already started=> no "
"need to restart dst brick "); } while (0); _gf_log (this->
name, "glusterd-replace-brick.c", __FUNCTION__, 1694, GF_LOG_ERROR
, "Replace brick is already started=> no " "need to restart dst brick "
); } while (0)
1693 "Replace brick is already started=> no "do { do { if (0) printf ("Replace brick is already started=> no "
"need to restart dst brick "); } while (0); _gf_log (this->
name, "glusterd-replace-brick.c", __FUNCTION__, 1694, GF_LOG_ERROR
, "Replace brick is already started=> no " "need to restart dst brick "
); } while (0)
1694 "need to restart dst brick ")do { do { if (0) printf ("Replace brick is already started=> no "
"need to restart dst brick "); } while (0); _gf_log (this->
name, "glusterd-replace-brick.c", __FUNCTION__, 1694, GF_LOG_ERROR
, "Replace brick is already started=> no " "need to restart dst brick "
); } while (0)
;
1695 }
1696 }
1697
1698
1699 if (glusterd_is_local_addr (src_brickinfo->hostname)) {
1700 ret = rb_src_brick_restart (volinfo, src_brickinfo,
1701 1);
1702 if (ret) {
1703 gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("Could not restart src-brick"); } while
(0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 1704, GF_LOG_DEBUG, "Could not restart src-brick"); } while
(0)
1704 "Could not restart src-brick")do { do { if (0) printf ("Could not restart src-brick"); } while
(0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 1704, GF_LOG_DEBUG, "Could not restart src-brick"); } while
(0)
;
1705 goto out;
1706 }
1707 }
1708
1709 if (glusterd_is_local_addr (dst_brickinfo->hostname)) {
1710 gf_log (this->name, GF_LOG_INFO,do { do { if (0) printf ("adding dst-brick port no"); } while
(0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 1711, GF_LOG_INFO, "adding dst-brick port no"); } while (0)
1711 "adding dst-brick port no")do { do { if (0) printf ("adding dst-brick port no"); } while
(0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 1711, GF_LOG_INFO, "adding dst-brick port no"); } while (0)
;
1712
1713 ret = rb_update_dstbrick_port (dst_brickinfo, rsp_dict,
1714 dict, replace_op);
1715 if (ret)
1716 goto out;
1717 }
1718
1719 glusterd_set_rb_status (volinfo, GF_RB_STATUS_STARTED);
1720 break;
1721 }
1722
1723 case GF_REPLACE_OP_COMMIT:
1724 {
1725 ctx = glusterd_op_get_ctx ();
1726 if (ctx) {
1727 ret = rb_do_operation (volinfo, src_brickinfo,
1728 dst_brickinfo,
1729 GF_REPLACE_OP_COMMIT);
1730 if (ret) {
1731 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("Commit operation failed"); } while (
0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 1732, GF_LOG_ERROR, "Commit operation failed"); } while (0)
1732 "Commit operation failed")do { do { if (0) printf ("Commit operation failed"); } while (
0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 1732, GF_LOG_ERROR, "Commit operation failed"); } while (0)
;
1733 goto out;
1734 }
1735 }
1736 }
1737 /* fall through */
1738 case GF_REPLACE_OP_COMMIT_FORCE:
1739 {
1740 if (glusterd_is_local_addr (dst_brickinfo->hostname)) {
1741 gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("I AM THE DESTINATION HOST"); } while
(0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 1742, GF_LOG_DEBUG, "I AM THE DESTINATION HOST"); } while (
0)
1742 "I AM THE DESTINATION HOST")do { do { if (0) printf ("I AM THE DESTINATION HOST"); } while
(0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 1742, GF_LOG_DEBUG, "I AM THE DESTINATION HOST"); } while (
0)
;
1743 ret = rb_kill_destination_brick (volinfo,
1744 dst_brickinfo);
1745 if (ret) {
1746 gf_log (this->name, GF_LOG_CRITICAL,do { do { if (0) printf ("Unable to cleanup dst brick"); } while
(0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 1747, GF_LOG_CRITICAL, "Unable to cleanup dst brick"); } while
(0)
1747 "Unable to cleanup dst brick")do { do { if (0) printf ("Unable to cleanup dst brick"); } while
(0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 1747, GF_LOG_CRITICAL, "Unable to cleanup dst brick"); } while
(0)
;
1748 goto out;
1749 }
1750 }
1751
1752 ret = glusterd_nodesvcs_stop (volinfo);
1753 if (ret) {
1754 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("Unable to stop nfs server, ret: %d"
, ret); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1755, GF_LOG_ERROR, "Unable to stop nfs server, ret: %d"
, ret); } while (0)
1755 "Unable to stop nfs server, ret: %d", ret)do { do { if (0) printf ("Unable to stop nfs server, ret: %d"
, ret); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1755, GF_LOG_ERROR, "Unable to stop nfs server, ret: %d"
, ret); } while (0)
;
1756 }
1757
1758 ret = glusterd_op_perform_replace_brick (volinfo, src_brick,
1759 dst_brick);
1760 if (ret) {
1761 gf_log (this->name, GF_LOG_CRITICAL, "Unable to add "do { do { if (0) printf ("Unable to add " "dst-brick: %s to volume: %s"
, dst_brick, volinfo->volname); } while (0); _gf_log (this
->name, "glusterd-replace-brick.c", __FUNCTION__, 1763, GF_LOG_CRITICAL
, "Unable to add " "dst-brick: %s to volume: %s", dst_brick, volinfo
->volname); } while (0)
1762 "dst-brick: %s to volume: %s", dst_brick,do { do { if (0) printf ("Unable to add " "dst-brick: %s to volume: %s"
, dst_brick, volinfo->volname); } while (0); _gf_log (this
->name, "glusterd-replace-brick.c", __FUNCTION__, 1763, GF_LOG_CRITICAL
, "Unable to add " "dst-brick: %s to volume: %s", dst_brick, volinfo
->volname); } while (0)
1763 volinfo->volname)do { do { if (0) printf ("Unable to add " "dst-brick: %s to volume: %s"
, dst_brick, volinfo->volname); } while (0); _gf_log (this
->name, "glusterd-replace-brick.c", __FUNCTION__, 1763, GF_LOG_CRITICAL
, "Unable to add " "dst-brick: %s to volume: %s", dst_brick, volinfo
->volname); } while (0)
;
1764 (void) glusterd_nodesvcs_handle_graph_change (volinfo);
1765 goto out;
1766 }
1767
1768 volinfo->rebal.defrag_status = 0;
1769
1770 ret = glusterd_nodesvcs_handle_graph_change (volinfo);
1771 if (ret) {
1772 gf_log (this->name, GF_LOG_CRITICAL,do { do { if (0) printf ("Failed to generate nfs volume file"
); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1773, GF_LOG_CRITICAL, "Failed to generate nfs volume file"
); } while (0)
1773 "Failed to generate nfs volume file")do { do { if (0) printf ("Failed to generate nfs volume file"
); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1773, GF_LOG_CRITICAL, "Failed to generate nfs volume file"
); } while (0)
;
1774 }
1775
1776
1777 ret = glusterd_fetchspec_notify (THIS(*__glusterfs_this_location()));
1778 glusterd_set_rb_status (volinfo, GF_RB_STATUS_NONE);
1779 glusterd_brickinfo_delete (volinfo->rep_brick.dst_brick);
1780 volinfo->rep_brick.src_brick = NULL((void*)0);
1781 volinfo->rep_brick.dst_brick = NULL((void*)0);
1782 uuid_clear (volinfo->rep_brick.rb_id);
1783 }
1784 break;
1785
1786 case GF_REPLACE_OP_PAUSE:
1787 {
1788 gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("Received pause - doing nothing"); }
while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1789, GF_LOG_DEBUG, "Received pause - doing nothing"
); } while (0)
1789 "Received pause - doing nothing")do { do { if (0) printf ("Received pause - doing nothing"); }
while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1789, GF_LOG_DEBUG, "Received pause - doing nothing"
); } while (0)
;
1790 ctx = glusterd_op_get_ctx ();
1791 if (ctx) {
1792 ret = rb_do_operation (volinfo, src_brickinfo,
1793 dst_brickinfo,
1794 GF_REPLACE_OP_PAUSE);
1795 if (ret) {
1796 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("Pause operation failed"); } while (
0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 1797, GF_LOG_ERROR, "Pause operation failed"); } while (0)
1797 "Pause operation failed")do { do { if (0) printf ("Pause operation failed"); } while (
0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 1797, GF_LOG_ERROR, "Pause operation failed"); } while (0)
;
1798 goto out;
1799 }
1800 }
1801
1802 glusterd_set_rb_status (volinfo, GF_RB_STATUS_PAUSED);
1803 }
1804 break;
1805
1806 case GF_REPLACE_OP_ABORT:
1807 {
1808
1809 ctx = glusterd_op_get_ctx ();
1810 if (ctx) {
1811 ret = rb_do_operation (volinfo, src_brickinfo,
1812 dst_brickinfo,
1813 GF_REPLACE_OP_ABORT);
1814 if (ret) {
1815 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("Abort operation failed"); } while (
0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 1816, GF_LOG_ERROR, "Abort operation failed"); } while (0)
1816 "Abort operation failed")do { do { if (0) printf ("Abort operation failed"); } while (
0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 1816, GF_LOG_ERROR, "Abort operation failed"); } while (0)
;
1817 goto out;
1818 }
1819 }
1820
1821 if (glusterd_is_local_addr (src_brickinfo->hostname)) {
1822 ret = rb_src_brick_restart (volinfo, src_brickinfo,
1823 0);
1824 if (ret) {
1825 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("Couldn't restart src brick " "with pump xlator disabled."
); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1827, GF_LOG_ERROR, "Couldn't restart src brick "
"with pump xlator disabled."); } while (0)
1826 "Couldn't restart src brick "do { do { if (0) printf ("Couldn't restart src brick " "with pump xlator disabled."
); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1827, GF_LOG_ERROR, "Couldn't restart src brick "
"with pump xlator disabled."); } while (0)
1827 "with pump xlator disabled.")do { do { if (0) printf ("Couldn't restart src brick " "with pump xlator disabled."
); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1827, GF_LOG_ERROR, "Couldn't restart src brick "
"with pump xlator disabled."); } while (0)
;
1828 goto out;
1829 }
1830 }
1831
1832 if (glusterd_is_local_addr (dst_brickinfo->hostname)) {
1833 gf_log (this->name, GF_LOG_INFO,do { do { if (0) printf ("I AM THE DESTINATION HOST"); } while
(0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 1834, GF_LOG_INFO, "I AM THE DESTINATION HOST"); } while (0
)
1834 "I AM THE DESTINATION HOST")do { do { if (0) printf ("I AM THE DESTINATION HOST"); } while
(0); _gf_log (this->name, "glusterd-replace-brick.c", __FUNCTION__
, 1834, GF_LOG_INFO, "I AM THE DESTINATION HOST"); } while (0
)
;
1835 ret = rb_kill_destination_brick (volinfo, dst_brickinfo);
1836 if (ret) {
1837 gf_log ("", GF_LOG_DEBUG,do { do { if (0) printf ("Failed to kill destination brick");
} while (0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__
, 1838, GF_LOG_DEBUG, "Failed to kill destination brick"); } while
(0)
1838 "Failed to kill destination brick")do { do { if (0) printf ("Failed to kill destination brick");
} while (0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__
, 1838, GF_LOG_DEBUG, "Failed to kill destination brick"); } while
(0)
;
1839 goto out;
1840 }
1841 }
1842 glusterd_set_rb_status (volinfo, GF_RB_STATUS_NONE);
1843 glusterd_brickinfo_delete (volinfo->rep_brick.dst_brick);
1844 volinfo->rep_brick.src_brick = NULL((void*)0);
1845 volinfo->rep_brick.dst_brick = NULL((void*)0);
1846 }
1847 break;
1848
1849 case GF_REPLACE_OP_STATUS:
1850 {
1851 gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("received status - doing nothing"); }
while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1852, GF_LOG_DEBUG, "received status - doing nothing"
); } while (0)
1852 "received status - doing nothing")do { do { if (0) printf ("received status - doing nothing"); }
while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1852, GF_LOG_DEBUG, "received status - doing nothing"
); } while (0)
;
1853 ctx = glusterd_op_get_ctx ();
1854 if (ctx) {
1855 if (glusterd_is_rb_paused (volinfo)) {
1856 ret = dict_set_str (ctx, "status-reply",
1857 "replace brick has been paused");
1858 if (ret)
1859 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("failed to set pump status" " in ctx"
); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1861, GF_LOG_ERROR, "failed to set pump status"
" in ctx"); } while (0)
1860 "failed to set pump status"do { do { if (0) printf ("failed to set pump status" " in ctx"
); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1861, GF_LOG_ERROR, "failed to set pump status"
" in ctx"); } while (0)
1861 " in ctx")do { do { if (0) printf ("failed to set pump status" " in ctx"
); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1861, GF_LOG_ERROR, "failed to set pump status"
" in ctx"); } while (0)
;
1862 goto out;
1863 }
1864
1865 ret = rb_do_operation (volinfo, src_brickinfo,
1866 dst_brickinfo,
1867 GF_REPLACE_OP_STATUS);
1868 if (ret)
1869 goto out;
1870 }
1871
1872 }
1873 break;
1874
1875 default:
1876 ret = -1;
1877 goto out;
1878 }
1879 if (!ret && replace_op != GF_REPLACE_OP_STATUS)
1880 ret = glusterd_store_volinfo (volinfo,
1881 GLUSTERD_VOLINFO_VER_AC_INCREMENT);
1882 if (ret)
1883 gf_log (this->name, GF_LOG_ERROR, "Couldn't store"do { do { if (0) printf ("Couldn't store" " replace brick operation's state"
); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1884, GF_LOG_ERROR, "Couldn't store" " replace brick operation's state"
); } while (0)
1884 " replace brick operation's state")do { do { if (0) printf ("Couldn't store" " replace brick operation's state"
); } while (0); _gf_log (this->name, "glusterd-replace-brick.c"
, __FUNCTION__, 1884, GF_LOG_ERROR, "Couldn't store" " replace brick operation's state"
); } while (0)
;
1885
1886out:
1887 return ret;
1888}
1889
1890void
1891glusterd_do_replace_brick (void *data)
1892{
1893 glusterd_volinfo_t *volinfo = NULL((void*)0);
1894 int32_t op = 0;
1895 int32_t src_port = 0;
1896 int32_t dst_port = 0;
1897 dict_t *dict = NULL((void*)0);
1898 char *src_brick = NULL((void*)0);
1899 char *dst_brick = NULL((void*)0);
1900 char *volname = NULL((void*)0);
1901 glusterd_brickinfo_t *src_brickinfo = NULL((void*)0);
1902 glusterd_brickinfo_t *dst_brickinfo = NULL((void*)0);
1903 glusterd_conf_t *priv = NULL((void*)0);
1904
1905 int ret = 0;
1906
1907 dict = data;
1908
1909 GF_ASSERT (THIS)do { if (!((*__glusterfs_this_location()))) { do { do { if (0
) printf ("Assertion failed: " "THIS"); } while (0); _gf_log_callingfn
("", "glusterd-replace-brick.c", __FUNCTION__, 1909, GF_LOG_ERROR
, "Assertion failed: " "THIS"); } while (0); } } while (0)
;
1910
1911 priv = THIS(*__glusterfs_this_location())->private;
1912
1913 if (priv->timer) {
1914 gf_timer_call_cancel (THIS(*__glusterfs_this_location())->ctx, priv->timer);
1915 priv->timer = NULL((void*)0);
1916 gf_log ("", GF_LOG_DEBUG,do { do { if (0) printf ("Cancelling timer thread"); } while (
0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__, 1917
, GF_LOG_DEBUG, "Cancelling timer thread"); } while (0)
1917 "Cancelling timer thread")do { do { if (0) printf ("Cancelling timer thread"); } while (
0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__, 1917
, GF_LOG_DEBUG, "Cancelling timer thread"); } while (0)
;
1918 }
1919
1920 gf_log ("", GF_LOG_DEBUG,do { do { if (0) printf ("Replace brick operation detected");
} while (0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__
, 1921, GF_LOG_DEBUG, "Replace brick operation detected"); } while
(0)
1921 "Replace brick operation detected")do { do { if (0) printf ("Replace brick operation detected");
} while (0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__
, 1921, GF_LOG_DEBUG, "Replace brick operation detected"); } while
(0)
;
1922
1923 ret = dict_get_int32 (dict, "operation", &op);
1924 if (ret) {
1925 gf_log ("", GF_LOG_DEBUG,do { do { if (0) printf ("dict_get on operation failed"); } while
(0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__, 1926
, GF_LOG_DEBUG, "dict_get on operation failed"); } while (0)
1926 "dict_get on operation failed")do { do { if (0) printf ("dict_get on operation failed"); } while
(0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__, 1926
, GF_LOG_DEBUG, "dict_get on operation failed"); } while (0)
;
1927 goto out;
1928 }
1929 ret = dict_get_str (dict, "src-brick", &src_brick);
1930 if (ret) {
1931 gf_log ("", GF_LOG_ERROR, "Unable to get src brick")do { do { if (0) printf ("Unable to get src brick"); } while (
0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__, 1931
, GF_LOG_ERROR, "Unable to get src brick"); } while (0)
;
1932 goto out;
1933 }
1934
1935 gf_log ("", GF_LOG_DEBUG,do { do { if (0) printf ("src brick=%s", src_brick); } while (
0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__, 1936
, GF_LOG_DEBUG, "src brick=%s", src_brick); } while (0)
1936 "src brick=%s", src_brick)do { do { if (0) printf ("src brick=%s", src_brick); } while (
0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__, 1936
, GF_LOG_DEBUG, "src brick=%s", src_brick); } while (0)
;
1937
1938 ret = dict_get_str (dict, "dst-brick", &dst_brick);
1939 if (ret) {
1940 gf_log ("", GF_LOG_ERROR, "Unable to get dst brick")do { do { if (0) printf ("Unable to get dst brick"); } while (
0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__, 1940
, GF_LOG_ERROR, "Unable to get dst brick"); } while (0)
;
1941 goto out;
1942 }
1943
1944 gf_log ("", GF_LOG_DEBUG,do { do { if (0) printf ("dst brick=%s", dst_brick); } while (
0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__, 1945
, GF_LOG_DEBUG, "dst brick=%s", dst_brick); } while (0)
1945 "dst brick=%s", dst_brick)do { do { if (0) printf ("dst brick=%s", dst_brick); } while (
0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__, 1945
, GF_LOG_DEBUG, "dst brick=%s", dst_brick); } while (0)
;
1946
1947 ret = dict_get_str (dict, "volname", &volname);
1948
1949 if (ret) {
1950 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-replace-brick.c", __FUNCTION__, 1950
, GF_LOG_ERROR, "Unable to get volume name"); } while (0)
;
1951 goto out;
1952 }
1953
1954 ret = glusterd_volinfo_find (volname, &volinfo);
1955 if (ret) {
1956 gf_log ("", GF_LOG_ERROR, "Unable to allocate memory")do { do { if (0) printf ("Unable to allocate memory"); } while
(0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__, 1956
, GF_LOG_ERROR, "Unable to allocate memory"); } while (0)
;
1957 goto out;
1958 }
1959
1960 ret = glusterd_volume_brickinfo_get_by_brick (src_brick, volinfo,
1961 &src_brickinfo);
1962 if (ret) {
1963 gf_log ("", GF_LOG_DEBUG, "Unable to get src-brickinfo")do { do { if (0) printf ("Unable to get src-brickinfo"); } while
(0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__, 1963
, GF_LOG_DEBUG, "Unable to get src-brickinfo"); } while (0)
;
1964 goto out;
1965 }
1966
1967 ret = glusterd_get_rb_dst_brickinfo (volinfo, &dst_brickinfo);
1968 if (!dst_brickinfo) {
1969 gf_log ("", GF_LOG_DEBUG, "Unable to get dst-brickinfo")do { do { if (0) printf ("Unable to get dst-brickinfo"); } while
(0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__, 1969
, GF_LOG_DEBUG, "Unable to get dst-brickinfo"); } while (0)
;
1970 goto out;
1971 }
1972
1973 ret = glusterd_resolve_brick (dst_brickinfo);
1974 if (ret) {
1975 gf_log ("", GF_LOG_DEBUG, "Unable to resolve dst-brickinfo")do { do { if (0) printf ("Unable to resolve dst-brickinfo"); }
while (0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__
, 1975, GF_LOG_DEBUG, "Unable to resolve dst-brickinfo"); } while
(0)
;
1976 goto out;
1977 }
1978
1979 ret = dict_get_int32 (dict, "src-brick-port", &src_port);
1980 if (ret) {
1981 gf_log ("", GF_LOG_ERROR, "Unable to get src-brick port")do { do { if (0) printf ("Unable to get src-brick port"); } while
(0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__, 1981
, GF_LOG_ERROR, "Unable to get src-brick port"); } while (0)
;
1982 goto out;
1983 }
1984
1985 ret = dict_get_int32 (dict, "dst-brick-port", &dst_port);
1986 if (ret) {
1987 gf_log ("", GF_LOG_ERROR, "Unable to get dst-brick port")do { do { if (0) printf ("Unable to get dst-brick port"); } while
(0); _gf_log ("", "glusterd-replace-brick.c", __FUNCTION__, 1987
, GF_LOG_ERROR, "Unable to get dst-brick port"); } while (0)
;
1988 }
1989
1990 dst_brickinfo->port = dst_port;
1991 src_brickinfo->port = src_port;
1992
1993 switch (op) {
1994 case GF_REPLACE_OP_START:
1995 if (!dst_port) {
1996 ret = -1;
1997 goto out;
1998 }
1999
2000 ret = rb_do_operation (volinfo, src_brickinfo, dst_brickinfo,
2001 GF_REPLACE_OP_START);
2002 if (ret)
2003 goto out;
2004 break;
2005 case GF_REPLACE_OP_PAUSE:
2006 case GF_REPLACE_OP_ABORT:
2007 case GF_REPLACE_OP_COMMIT:
2008 case GF_REPLACE_OP_COMMIT_FORCE:
2009 case GF_REPLACE_OP_STATUS:
2010 break;
2011 default:
2012 ret = -1;
2013 goto out;
2014 }
2015
2016out:
2017 if (ret)
2018 ret = glusterd_op_sm_inject_event (GD_OP_EVENT_RCVD_RJT, NULL((void*)0));
2019 else
2020 ret = glusterd_op_sm_inject_event (GD_OP_EVENT_COMMIT_ACC, NULL((void*)0));
2021
2022 glusterd_op_sm ();
2023}