diff options
Diffstat (limited to 'xlators/mgmt')
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-rebalance.c | 111 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-utils.c | 19 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-utils.h | 2 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd.h | 10 |
4 files changed, 95 insertions, 47 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-rebalance.c b/xlators/mgmt/glusterd/src/glusterd-rebalance.c index ea443aaa05e..5f49e4b8752 100644 --- a/xlators/mgmt/glusterd/src/glusterd-rebalance.c +++ b/xlators/mgmt/glusterd/src/glusterd-rebalance.c @@ -270,7 +270,8 @@ glusterd_handle_defrag_start (glusterd_volinfo_t *volinfo, char *op_errstr, priv); snprintf (logfile, PATH_MAX, "%s/%s-%s-%s.log", DEFAULT_LOG_FILE_DIRECTORY, volinfo->volname, - (cmd == GF_DEFRAG_CMD_START_TIER ? "tier":"rebalance"), + (cmd == GF_DEFRAG_CMD_START_TIER ? + "tier":"rebalance"), uuid_utoa(MY_UUID)); } else { @@ -605,6 +606,7 @@ glusterd_op_stage_rebalance (dict_t *dict, char **op_errstr) char *task_id_str = NULL; dict_t *op_ctx = NULL; xlator_t *this = 0; + int32_t is_force = 0; this = THIS; GF_ASSERT (this); @@ -629,16 +631,20 @@ glusterd_op_stage_rebalance (dict_t *dict, char **op_errstr) } switch (cmd) { case GF_DEFRAG_CMD_START_TIER: + ret = dict_get_int32 (dict, "force", &is_force); + if (ret) + is_force = 0; + if (volinfo->type != GF_CLUSTER_TYPE_TIER) { gf_asprintf (op_errstr, "volume %s is not a tier " "volume.", volinfo->volname); ret = -1; goto out; } - if (glusterd_is_tier_daemon_running (volinfo)) { + if ((!is_force) && glusterd_is_tier_daemon_running (volinfo)) { ret = gf_asprintf (op_errstr, "A Tier daemon is " - "already running on volume %s", - volname); + "already running on volume %s", + volname); ret = -1; goto out; } @@ -797,6 +803,7 @@ glusterd_op_rebalance (dict_t *dict, char **op_errstr, dict_t *rsp_dict) dict_t *ctx = NULL; xlator_t *this = NULL; uint32_t commit_hash; + int32_t is_force = 0; this = THIS; GF_ASSERT (this); @@ -860,39 +867,79 @@ glusterd_op_rebalance (dict_t *dict, char **op_errstr, dict_t *rsp_dict) case GF_DEFRAG_CMD_START_LAYOUT_FIX: case GF_DEFRAG_CMD_START_FORCE: case GF_DEFRAG_CMD_START_TIER: - /* Reset defrag status to 'NOT STARTED' whenever a - * remove-brick/rebalance command is issued to remove - * stale information from previous run. - */ - volinfo->rebal.defrag_status = GF_DEFRAG_STATUS_NOT_STARTED; - ret = dict_get_str (dict, GF_REBALANCE_TID_KEY, &task_id_str); - if (ret) { - gf_msg_debug (this->name, 0, "Missing rebalance " - "id"); - ret = 0; + + ret = dict_get_int32 (dict, "force", &is_force); + if (ret) + is_force = 0; + if (!is_force) { + /* Reset defrag status to 'NOT STARTED' whenever a + * remove-brick/rebalance command is issued to remove + * stale information from previous run. + */ + volinfo->rebal.defrag_status = + GF_DEFRAG_STATUS_NOT_STARTED; + + ret = dict_get_str (dict, GF_REBALANCE_TID_KEY, + &task_id_str); + if (ret) { + gf_msg_debug (this->name, 0, "Missing rebalance" + " id"); + ret = 0; + } else { + gf_uuid_parse (task_id_str, + volinfo->rebal.rebalance_id); + volinfo->rebal.op = GD_OP_REBALANCE; + } + if (!gd_should_i_start_rebalance (volinfo)) { + /* Store the rebalance-id and rebalance command + * even if the peer isn't starting a rebalance + * process. On peers where a rebalance process + * is started, glusterd_handle_defrag_start + * performs the storing. + * Storing this is needed for having + * 'volume status' work correctly. + */ + glusterd_store_perform_node_state_store + (volinfo); + break; + } + if (dict_get_uint32 (dict, "commit-hash", &commit_hash) + == 0) { + volinfo->rebal.commit_hash = commit_hash; + } + ret = glusterd_handle_defrag_start (volinfo, msg, + sizeof (msg), + cmd, NULL, GD_OP_REBALANCE); + break; } else { - gf_uuid_parse (task_id_str, volinfo->rebal.rebalance_id) ; - volinfo->rebal.op = GD_OP_REBALANCE; - } - if (!gd_should_i_start_rebalance (volinfo)) { - /* Store the rebalance-id and rebalance command even if - * the peer isn't starting a rebalance process. On peers - * where a rebalance process is started, - * glusterd_handle_defrag_start performs the storing. - * - * Storing this is needed for having 'volume status' - * work correctly. + /* Reset defrag status to 'STARTED' so that the + * pid is checked and restarted accordingly. + * If the pid is not running it executes the + * "NOT_STARTED" case and restarts the process */ - glusterd_store_perform_node_state_store (volinfo); + volinfo->rebal.defrag_status = GF_DEFRAG_STATUS_STARTED; + volinfo->rebal.defrag_cmd = cmd; + volinfo->rebal.op = GD_OP_REBALANCE; + + ret = dict_get_str (dict, GF_REBALANCE_TID_KEY, + &task_id_str); + if (ret) { + gf_msg_debug (this->name, 0, "Missing rebalance" + " id"); + ret = 0; + } else { + gf_uuid_parse (task_id_str, + volinfo->rebal.rebalance_id); + volinfo->rebal.op = GD_OP_REBALANCE; + } + if (dict_get_uint32 (dict, "commit-hash", &commit_hash) + == 0) { + volinfo->rebal.commit_hash = commit_hash; + } + ret = glusterd_restart_rebalance_for_volume (volinfo); break; } - if (dict_get_uint32 (dict, "commit-hash", &commit_hash) == 0) { - volinfo->rebal.commit_hash = commit_hash; - } - ret = glusterd_handle_defrag_start (volinfo, msg, sizeof (msg), - cmd, NULL, GD_OP_REBALANCE); - break; case GF_DEFRAG_CMD_STOP: case GF_DEFRAG_CMD_STOP_DETACH_TIER: /* Clear task-id only on explicitly stopping rebalance. diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index c9457e89b45..6fc0dcdc603 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-utils.c @@ -5647,7 +5647,7 @@ glusterd_is_tier_daemon_running (glusterd_volinfo_t *volinfo) return _gf_false; if (volinfo->rebal.defrag && - volinfo->rebal.defrag_cmd == GF_DEFRAG_CMD_START_TIER) { + volinfo->rebal.defrag_cmd == GF_DEFRAG_CMD_START_TIER) { return _gf_true; } @@ -7030,12 +7030,12 @@ glusterd_volume_defrag_restart (glusterd_volinfo_t *volinfo, char *op_errstr, case GF_DEFRAG_STATUS_STARTED: GLUSTERD_GET_DEFRAG_PID_FILE(pidfile, volinfo, priv); if (gf_is_service_running (pidfile, &pid)) { - glusterd_rebalance_rpc_create (volinfo, _gf_true); + ret = glusterd_rebalance_rpc_create (volinfo, _gf_true); break; } case GF_DEFRAG_STATUS_NOT_STARTED: - glusterd_handle_defrag_start (volinfo, op_errstr, len, cmd, - cbk, volinfo->rebal.op); + ret = glusterd_handle_defrag_start (volinfo, op_errstr, len, + cmd, cbk, volinfo->rebal.op); break; default: gf_msg (this->name, GF_LOG_ERROR, 0, @@ -7102,14 +7102,14 @@ out: } -void +int glusterd_restart_rebalance_for_volume (glusterd_volinfo_t *volinfo) { - + int ret = -1; char op_errstr[PATH_MAX]; if (!volinfo->rebal.defrag_cmd) - return; + return -1; if (!gd_should_i_start_rebalance (volinfo)) { /* Store the rebalance-id and rebalance command even if @@ -7123,10 +7123,11 @@ glusterd_restart_rebalance_for_volume (glusterd_volinfo_t *volinfo) if (volinfo->type == GF_CLUSTER_TYPE_TIER) glusterd_store_perform_node_state_store (volinfo); - return; + return 0; } - glusterd_volume_defrag_restart (volinfo, op_errstr, PATH_MAX, + ret = glusterd_volume_defrag_restart (volinfo, op_errstr, PATH_MAX, volinfo->rebal.defrag_cmd, NULL); + return ret; } int glusterd_restart_rebalance (glusterd_conf_t *conf) diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h index 99225c674eb..e912f64ae23 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.h +++ b/xlators/mgmt/glusterd/src/glusterd-utils.h @@ -374,7 +374,7 @@ glusterd_create_sub_tier_volinfo (glusterd_volinfo_t *volinfo, glusterd_volinfo_t **dup_volinfo, gf_boolean_t is_hot_tier, const char *new_name); -void +int glusterd_restart_rebalance_for_volume (glusterd_volinfo_t *volinfo); void diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h index 1e573f8c5ee..ceb472284b2 100644 --- a/xlators/mgmt/glusterd/src/glusterd.h +++ b/xlators/mgmt/glusterd/src/glusterd.h @@ -632,11 +632,11 @@ typedef ssize_t (*gd_serialize_t) (struct iovec outmsg, void *args); STACK_DESTROY (frame->root); \ } while (0) -#define GLUSTERD_GET_DEFRAG_PROCESS(path, volinfo) do { \ - if (volinfo->rebal.defrag_cmd == GF_DEFRAG_CMD_START_TIER) \ - snprintf (path, NAME_MAX, "tier"); \ - else \ - snprintf (path, NAME_MAX, "rebalance"); \ +#define GLUSTERD_GET_DEFRAG_PROCESS(path, volinfo) do { \ + if (volinfo->rebal.defrag_cmd == GF_DEFRAG_CMD_START_TIER) \ + snprintf (path, NAME_MAX, "tier"); \ + else \ + snprintf (path, NAME_MAX, "rebalance"); \ } while (0) #define GLUSTERD_GET_DEFRAG_DIR(path, volinfo, priv) do { \ |