10
#include <glusterfs/common-utils.h>
11
#include <glusterfs/glusterfs.h>
12
#include "glusterd-op-sm.h"
13
#include "glusterd-geo-rep.h"
14
#include "glusterd-store.h"
15
#include "glusterd-utils.h"
16
#include "glusterd-svc-mgmt.h"
17
#include "glusterd-svc-helper.h"
18
#include "glusterd-volgen.h"
19
#include "glusterd-messages.h"
20
#include "glusterd-mgmt.h"
21
#include <glusterfs/run.h>
22
#include <glusterfs/syscall.h>
27
glusterd_reset_brick_prevalidate(dict_t *dict, char **op_errstr,
31
char *src_brick = NULL;
32
char *dst_brick = NULL;
35
glusterd_op_t gd_op = -1;
36
glusterd_volinfo_t *volinfo = NULL;
37
glusterd_brickinfo_t *src_brickinfo = NULL;
40
glusterd_peerinfo_t *peerinfo = NULL;
41
glusterd_brickinfo_t *dst_brickinfo = NULL;
42
glusterd_conf_t *priv = NULL;
43
char pidfile[PATH_MAX] = {0};
44
xlator_t *this = THIS;
45
gf_boolean_t is_force = _gf_false;
46
int32_t ignore_partition = 0;
51
char *dup_dstbrick = NULL;
56
ret = glusterd_brick_op_prerequisites(dict, &op, &gd_op, &volname, &volinfo,
57
&src_brick, &src_brickinfo, pidfile,
62
if (!strcmp(op, "GF_RESET_OP_START"))
65
if (!strcmp(op, "GF_RESET_OP_COMMIT_FORCE"))
68
ret = glusterd_get_dst_brick_info(&dst_brick, volname, op_errstr,
69
&dst_brickinfo, &host, dict,
74
ret = glusterd_new_brick_validate(dst_brick, dst_brickinfo, msg,
81
if (!gf_uuid_compare(MY_UUID, dst_brickinfo->uuid)) {
83
*op_errstr = gf_strdup(
84
"When destination brick is new,"
87
"replace-brick <volname> "
88
"<src-brick> <dst-brick> "
91
gf_msg(this->name, GF_LOG_ERROR, EPERM,
92
GD_MSG_BRICK_VALIDATE_FAIL, "%s", *op_errstr);
95
} else if (ret == 1) {
96
if (gf_is_service_running(pidfile, &pid)) {
98
*op_errstr = gf_strdup(
103
"reset-brick <volname> "
104
"<dst-brick> start.");
106
gf_msg(this->name, GF_LOG_ERROR, EPERM,
107
GD_MSG_BRICK_VALIDATE_FAIL, "%s", *op_errstr);
110
ret = sys_lgetxattr(dst_brickinfo->path, GF_XATTR_VOL_ID_KEY, volume_id,
112
if (gf_uuid_compare(dst_brickinfo->uuid, src_brickinfo->uuid) ||
113
(ret >= 0 && is_force == _gf_false)) {
115
*op_errstr = gf_strdup(
116
"Brick not available."
117
"It may be containing "
119
"by an existing brick."
120
"Use 'force' option to "
123
gf_msg(this->name, GF_LOG_ERROR, EPERM,
124
GD_MSG_BRICK_VALIDATE_FAIL, "%s", *op_errstr);
129
*op_errstr = gf_strdup(msg);
131
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_BRICK_VALIDATE_FAIL, "%s",
136
volinfo->rep_brick.src_brick = src_brickinfo;
137
volinfo->rep_brick.dst_brick = dst_brickinfo;
139
ret = dict_get_int32(dict, "ignore-partition", &ignore_partition);
141
if (glusterd_gf_is_local_addr(host)) {
142
ret = glusterd_validate_and_create_brickpath(
143
dst_brickinfo, volinfo->volume_id, volinfo->volname, op_errstr,
144
is_force, ignore_partition);
150
peerinfo = glusterd_peerinfo_find(NULL, host);
151
if (peerinfo == NULL) {
154
snprintf(msg, sizeof(msg), "%s, is not a friend.", host);
155
*op_errstr = gf_strdup(msg);
158
} else if (!peerinfo->connected) {
161
snprintf(msg, sizeof(msg),
163
"is not connected at "
166
*op_errstr = gf_strdup(msg);
169
} else if (GD_FRIEND_STATE_BEFRIENDED != peerinfo->state) {
172
snprintf(msg, sizeof(msg),
173
"%s, is not befriended "
176
*op_errstr = gf_strdup(msg);
182
if (!(gf_uuid_compare(dst_brickinfo->uuid, MY_UUID))) {
183
ret = glusterd_get_brick_mount_dir(dst_brickinfo->path,
184
dst_brickinfo->hostname,
185
dst_brickinfo->mount_dir);
187
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_BRICK_MOUNTDIR_GET_FAIL,
188
"Failed to get brick mount_dir");
191
ret = dict_set_dynstr_with_alloc(rsp_dict, "brick1.mount_dir",
192
dst_brickinfo->mount_dir);
194
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED,
195
"Failed to set brick.mount_dir");
200
ret = dict_set_int32_sizen(rsp_dict, "brick_count", 1);
202
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED,
203
"Failed to set local_brick_count.");
210
GF_FREE(dup_dstbrick);
211
gf_msg_debug(this->name, 0, "Returning %d.", ret);
217
glusterd_op_reset_brick(dict_t *dict, dict_t *rsp_dict)
221
glusterd_volinfo_t *volinfo = NULL;
222
char *volname = NULL;
223
xlator_t *this = THIS;
224
glusterd_conf_t *priv = NULL;
225
char *src_brick = NULL;
226
char *dst_brick = NULL;
227
glusterd_brickinfo_t *src_brickinfo = NULL;
228
glusterd_brickinfo_t *dst_brickinfo = NULL;
230
priv = this->private;
233
ret = dict_get_str(dict, "operation", &op);
235
gf_msg_debug(this->name, 0, "dict_get on operation failed");
239
ret = dict_get_str(dict, "volname", &volname);
241
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED,
242
"Unable to get volume name");
246
ret = glusterd_volinfo_find(volname, &volinfo);
250
ret = dict_get_str(dict, "src-brick", &src_brick);
252
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED,
253
"Unable to get src brick");
257
gf_msg_debug(this->name, 0, "src brick=%s", src_brick);
259
ret = glusterd_volume_brickinfo_get_by_brick(src_brick, volinfo,
260
&src_brickinfo, _gf_false);
262
gf_msg_debug(this->name, 0, "Unable to get src-brickinfo");
266
if (!strcmp(op, "GF_RESET_OP_START")) {
267
ret = glusterd_volume_stop_glusterfs(volinfo, src_brickinfo, _gf_false);
269
gf_msg(this->name, GF_LOG_CRITICAL, 0, GD_MSG_BRICK_STOP_FAIL,
272
src_brickinfo->hostname, src_brickinfo->path);
277
} else if (!strcmp(op, "GF_RESET_OP_COMMIT") ||
278
!strcmp(op, "GF_RESET_OP_COMMIT_FORCE")) {
279
ret = dict_get_str(dict, "dst-brick", &dst_brick);
281
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED,
282
"Unable to get dst brick");
286
gf_msg_debug(this->name, 0, "dst brick=%s", dst_brick);
288
ret = glusterd_get_rb_dst_brickinfo(volinfo, &dst_brickinfo);
290
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_RB_BRICKINFO_GET_FAIL,
293
"destination brickinfo");
297
ret = glusterd_resolve_brick(dst_brickinfo);
299
gf_msg_debug(this->name, 0, "Unable to resolve dst-brickinfo");
303
ret = rb_update_dstbrick_port(dst_brickinfo, rsp_dict, dict);
307
if (gf_uuid_compare(dst_brickinfo->uuid, MY_UUID)) {
308
gf_msg_debug(this->name, 0, "I AM THE DESTINATION HOST");
309
ret = glusterd_volume_stop_glusterfs(volinfo, src_brickinfo,
312
gf_msg(this->name, GF_LOG_CRITICAL, 0, GD_MSG_BRICK_STOP_FAIL,
313
"Unable to stop brick: %s:%s", src_brickinfo->hostname,
314
src_brickinfo->path);
319
ret = glusterd_svcs_stop(volinfo);
321
gf_msg(this->name, GF_LOG_ERROR, 0,
322
GD_MSG_GLUSTER_SERVICES_STOP_FAIL,
323
"Unable to stop gluster services, ret: %d", ret);
326
ret = glusterd_op_perform_replace_brick(volinfo, src_brick, dst_brick,
329
gf_msg(this->name, GF_LOG_CRITICAL, 0, GD_MSG_BRICK_ADD_FAIL,
330
"Unable to add dst-brick: "
332
dst_brick, volinfo->volname);
333
(void)glusterd_svcs_manager(volinfo);
337
if (volinfo->rebal.defrag_status != GF_DEFRAG_STATUS_NOT_STARTED)
338
volinfo->rebal.defrag_status = GF_DEFRAG_STATUS_RESET_DUE_RESET_BRC;
340
ret = glusterd_svcs_manager(volinfo);
342
gf_msg(this->name, GF_LOG_CRITICAL, 0,
343
GD_MSG_GLUSTER_SERVICE_START_FAIL,
344
"Failed to start one or more gluster services.");
347
ret = glusterd_fetchspec_notify(THIS);
348
glusterd_brickinfo_delete(volinfo->rep_brick.dst_brick);
349
volinfo->rep_brick.src_brick = NULL;
350
volinfo->rep_brick.dst_brick = NULL;
353
ret = glusterd_store_volinfo(volinfo,
354
GLUSTERD_VOLINFO_VER_AC_INCREMENT);
356
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_RBOP_STATE_STORE_FAIL,
358
" reset brick operation's state.");