summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cli/src/cli-cmd-volume.c20
-rw-r--r--cli/src/cli-rpc-ops.c44
-rw-r--r--rpc/xdr/src/cli1.h10
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-rebalance.c119
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.c4
-rw-r--r--xlators/mgmt/glusterd/src/glusterd.h7
6 files changed, 123 insertions, 81 deletions
diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c
index 9e93d4e97..a790b326e 100644
--- a/cli/src/cli-cmd-volume.c
+++ b/cli/src/cli-cmd-volume.c
@@ -476,7 +476,7 @@ cli_cmd_volume_defrag_cbk (struct cli_state *state, struct cli_cmd_word *word,
if (!dict)
goto out;
- if (wordcount != 4) {
+ if (!((wordcount == 4) || (wordcount == 5))) {
cli_usage_out (word->pattern);
parse_error = 1;
goto out;
@@ -486,9 +486,19 @@ cli_cmd_volume_defrag_cbk (struct cli_state *state, struct cli_cmd_word *word,
if (ret)
goto out;
- ret = dict_set_str (dict, "command", (char *)words[3]);
- if (ret)
- goto out;
+ if (wordcount == 4) {
+ ret = dict_set_str (dict, "command", (char *)words[3]);
+ if (ret)
+ goto out;
+ }
+ if (wordcount == 5) {
+ ret = dict_set_str (dict, "start-type", (char *)words[3]);
+ if (ret)
+ goto out;
+ ret = dict_set_str (dict, "command", (char *)words[4]);
+ if (ret)
+ goto out;
+ }
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_DEFRAG_VOLUME];
@@ -962,7 +972,7 @@ struct cli_cmd volume_cmds[] = {
cli_cmd_volume_remove_brick_cbk,
"remove brick from volume <VOLNAME>"},
- { "volume rebalance <VOLNAME> {start|stop|status}",
+ { "volume rebalance <VOLNAME> [fix-layout|migrate-data] {start|stop|status}",
cli_cmd_volume_defrag_cbk,
"rebalance operations"},
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c
index 4e713eef5..d95c91bbe 100644
--- a/cli/src/cli-rpc-ops.c
+++ b/cli/src/cli-rpc-ops.c
@@ -803,7 +803,9 @@ gf_cli3_1_defrag_volume_cbk (struct rpc_req *req, struct iovec *iov,
volname = local->u.defrag_vol.volname;
cmd = local->u.defrag_vol.cmd;
}
- if (cmd == GF_DEFRAG_CMD_START) {
+ if ((cmd == GF_DEFRAG_CMD_START) ||
+ (cmd == GF_DEFRAG_CMD_START_LAYOUT_FIX) ||
+ (cmd == GF_DEFRAG_CMD_START_MIGRATE_DATA)) {
if (rsp.op_ret && strcmp (rsp.op_errstr, ""))
cli_out (rsp.op_errstr);
else
@@ -845,21 +847,34 @@ gf_cli3_1_defrag_volume_cbk (struct rpc_req *req, struct iovec *iov,
status = "completed";
if (rsp.op_errno == 5)
status = "failed";
+ if (rsp.op_errno == 6)
+ status = "step 1: layout fix complete";
+ if (rsp.op_errno == 7)
+ status = "step 2: data migration complete";
if (rsp.files && (rsp.op_errno == 1)) {
cli_out ("rebalance %s: fixed layout %"PRId64,
status, rsp.files);
- } else if (rsp.files) {
+ goto done;
+ }
+ if (rsp.files && (rsp.op_errno == 6)) {
+ cli_out ("rebalance %s: fixed layout %"PRId64,
+ status, rsp.files);
+ goto done;
+ }
+ if (rsp.files) {
cli_out ("rebalance %s: rebalanced %"PRId64
" files of size %"PRId64" (total files"
" scanned %"PRId64")", status,
rsp.files, rsp.size, rsp.lookedup_files);
- } else {
- cli_out ("rebalance %s", status);
+ goto done;
}
+
+ cli_out ("rebalance %s", status);
}
}
+done:
if (volname)
GF_FREE (volname);
@@ -1723,15 +1738,28 @@ gf_cli3_1_defrag_volume (call_frame_t *frame, xlator_t *this,
goto out;
}
- if (strncasecmp (cmd_str, "start", 6) == 0) {
+ if (strcmp (cmd_str, "start") == 0) {
req.cmd = GF_DEFRAG_CMD_START;
- } else if (strncasecmp (cmd_str, "stop", 5) == 0) {
+ ret = dict_get_str (dict, "start-type", &cmd_str);
+ if (!ret) {
+ if (strcmp (cmd_str, "fix-layout") == 0) {
+ req.cmd = GF_DEFRAG_CMD_START_LAYOUT_FIX;
+ }
+ if (strcmp (cmd_str, "migrate-data") == 0) {
+ req.cmd = GF_DEFRAG_CMD_START_MIGRATE_DATA;
+ }
+ }
+ goto done;
+ }
+ if (strcmp (cmd_str, "stop") == 0) {
req.cmd = GF_DEFRAG_CMD_STOP;
- } else if (strncasecmp (cmd_str, "status", 7) == 0) {
+ goto done;
+ }
+ if (strcmp (cmd_str, "status") == 0) {
req.cmd = GF_DEFRAG_CMD_STATUS;
}
-
+done:
local = cli_local_get ();
if (local) {
diff --git a/rpc/xdr/src/cli1.h b/rpc/xdr/src/cli1.h
index 2b7c2c65c..96b511bfe 100644
--- a/rpc/xdr/src/cli1.h
+++ b/rpc/xdr/src/cli1.h
@@ -25,9 +25,13 @@
#include "cli1-xdr.h"
-#define GF_DEFRAG_CMD_START 1
-#define GF_DEFRAG_CMD_STOP 2
-#define GF_DEFRAG_CMD_STATUS 3
+enum gf_cli_defrag_type {
+ GF_DEFRAG_CMD_START = 1,
+ GF_DEFRAG_CMD_STOP,
+ GF_DEFRAG_CMD_STATUS,
+ GF_DEFRAG_CMD_START_LAYOUT_FIX,
+ GF_DEFRAG_CMD_START_MIGRATE_DATA,
+};
ssize_t
gf_xdr_serialize_cli_probe_rsp (struct iovec outmsg, void *rsp);
diff --git a/xlators/mgmt/glusterd/src/glusterd-rebalance.c b/xlators/mgmt/glusterd/src/glusterd-rebalance.c
index c1dbead2e..58c12c193 100644
--- a/xlators/mgmt/glusterd/src/glusterd-rebalance.c
+++ b/xlators/mgmt/glusterd/src/glusterd-rebalance.c
@@ -184,8 +184,7 @@ gf_glusterd_rebalance_move_data (glusterd_volinfo_t *volinfo, const char *dir)
if (!S_ISDIR (stbuf.st_mode))
continue;
- ret = gf_glusterd_rebalance_move_data (volinfo,
- full_path);
+ ret = gf_glusterd_rebalance_move_data (volinfo, full_path);
if (ret)
break;
}
@@ -289,32 +288,44 @@ glusterd_defrag_start (void *data)
sys_lgetxattr (defrag->mount, "trusted.distribute.fix.layout",
&value, 128);
- /* root's layout got fixed */
- defrag->total_files = 1;
+ if ((defrag->cmd == GF_DEFRAG_CMD_START) ||
+ (defrag->cmd == GF_DEFRAG_CMD_START_LAYOUT_FIX)) {
+ /* root's layout got fixed */
+ defrag->total_files = 1;
- /* Step 1: Fix layout of all the directories */
- ret = gf_glusterd_rebalance_fix_layout (volinfo, defrag->mount);
- if (ret) {
- volinfo->defrag_status = GF_DEFRAG_STATUS_FAILED;
- goto out;
+ /* Step 1: Fix layout of all the directories */
+ ret = gf_glusterd_rebalance_fix_layout (volinfo, defrag->mount);
+ if (ret) {
+ volinfo->defrag_status = GF_DEFRAG_STATUS_FAILED;
+ goto out;
+ }
+
+ /* Completed first step */
+ volinfo->defrag_status = GF_DEFRAG_STATUS_LAYOUT_FIX_COMPLETE;
}
- /* Completed first step */
- volinfo->defrag_status = GF_DEFRAG_STATUS_LAYOUT_FIX_COMPLETE;
+ if ((defrag->cmd == GF_DEFRAG_CMD_START) ||
+ (defrag->cmd == GF_DEFRAG_CMD_START_MIGRATE_DATA)) {
+ /* It was used by number of layout fixes on directories */
+ defrag->total_files = 0;
- /* It was used by number of layout fixes on directories */
- defrag->total_files = 0;
+ volinfo->defrag_status = GF_DEFRAG_STATUS_MIGRATE_DATA_STARTED;
- /* Step 2: Iterate over directories to move data */
- ret = gf_glusterd_rebalance_move_data (volinfo, defrag->mount);
- if (ret) {
- volinfo->defrag_status = GF_DEFRAG_STATUS_FAILED;
+ /* Step 2: Iterate over directories to move data */
+ ret = gf_glusterd_rebalance_move_data (volinfo, defrag->mount);
+ if (ret) {
+ volinfo->defrag_status = GF_DEFRAG_STATUS_FAILED;
+ goto out;
+ }
+
+ /* Completed second step */
+ volinfo->defrag_status = GF_DEFRAG_STATUS_MIGRATE_DATA_COMPLETE;
}
/* Completed whole process */
- if (!ret) {
- volinfo->defrag_status = GF_DEFRAG_STATUS_COMPLETE;
- }
+ if (defrag->cmd == GF_DEFRAG_CMD_START)
+ volinfo->defrag_status = GF_DEFRAG_STATUS_COMPLETE;
+
volinfo->rebalance_files = defrag->total_files;
volinfo->rebalance_data = defrag->total_data;
volinfo->lookedup_files = defrag->num_files_lookedup;
@@ -441,6 +452,16 @@ void
glusterd_rebalance_cmd_attempted_log (int cmd, char *volname)
{
switch (cmd) {
+ case GF_DEFRAG_CMD_START_LAYOUT_FIX:
+ gf_cmd_log ("Volume rebalance"," on volname: %s "
+ "cmd: start fix layout , attempted",
+ volname);
+ break;
+ case GF_DEFRAG_CMD_START_MIGRATE_DATA:
+ gf_cmd_log ("Volume rebalance"," on volname: %s "
+ "cmd: start data migrate attempted",
+ volname);
+ break;
case GF_DEFRAG_CMD_START:
gf_cmd_log ("Volume rebalance"," on volname: %s "
"cmd: start, attempted", volname);
@@ -452,9 +473,9 @@ glusterd_rebalance_cmd_attempted_log (int cmd, char *volname)
default:
break;
}
- gf_log ("glusterd", GF_LOG_NORMAL, "Received rebalance volume %s on %s",
- (cmd == GF_DEFRAG_CMD_START)?"start":(cmd == GF_DEFRAG_CMD_STOP)?"stop":"status"
- , volname);
+
+ gf_log ("glusterd", GF_LOG_NORMAL, "Received rebalance volume %d on %s",
+ cmd, volname);
}
void
@@ -498,7 +519,7 @@ out:
int
glusterd_handle_defrag_start (glusterd_volinfo_t *volinfo, char *op_errstr,
- size_t len)
+ size_t len, int cmd)
{
int ret = -1;
glusterd_defrag_info_t *defrag = NULL;
@@ -521,6 +542,8 @@ glusterd_handle_defrag_start (glusterd_volinfo_t *volinfo, char *op_errstr,
defrag = volinfo->defrag;
+ defrag->cmd = cmd;
+
LOCK_INIT (&defrag->lock);
snprintf (defrag->mount, 1024, "%s/mount/%s",
priv->workdir, volinfo->volname);
@@ -546,7 +569,7 @@ glusterd_handle_defrag_start (glusterd_volinfo_t *volinfo, char *op_errstr,
goto out;
}
- volinfo->defrag_status = GF_DEFRAG_STATUS_STARTED;
+ volinfo->defrag_status = GF_DEFRAG_STATUS_LAYOUT_FIX_STARTED;
ret = pthread_create (&defrag->th, NULL, glusterd_defrag_start,
volinfo);
@@ -608,24 +631,6 @@ glusterd_handle_defrag_volume_v2 (rpcsvc_request_t *req)
goto out;
}
- switch (cli_req.cmd) {
- case GF_DEFRAG_CMD_START:
- gf_cmd_log ("Volume rebalance"," on volname: %s "
- "cmd: start, attempted", cli_req.volname);
- break;
- case GF_DEFRAG_CMD_STOP:
- gf_cmd_log ("Volume rebalance"," on volname: %s "
- "cmd: stop, attempted", cli_req.volname);
- break;
- default:
- break;
- }
-
- gf_log ("glusterd", GF_LOG_NORMAL, "Received rebalance volume %s on %s",
- ((cli_req.cmd == GF_DEFRAG_CMD_START) ? "start" :
- (cli_req.cmd == GF_DEFRAG_CMD_STOP) ? "stop" : "status"),
- cli_req.volname);
-
glusterd_rebalance_cmd_attempted_log (cli_req.cmd, cli_req.volname);
rsp.volname = cli_req.volname;
@@ -636,9 +641,13 @@ glusterd_handle_defrag_volume_v2 (rpcsvc_request_t *req)
&volinfo, msg, sizeof (msg));
if (ret)
goto out;
+
switch (cli_req.cmd) {
case GF_DEFRAG_CMD_START:
- ret = glusterd_handle_defrag_start (volinfo, msg, sizeof (msg));
+ case GF_DEFRAG_CMD_START_LAYOUT_FIX:
+ case GF_DEFRAG_CMD_START_MIGRATE_DATA:
+ ret = glusterd_handle_defrag_start (volinfo, msg, sizeof (msg),
+ cli_req.cmd);
rsp.op_ret = ret;
break;
case GF_DEFRAG_CMD_STOP:
@@ -684,22 +693,7 @@ glusterd_handle_defrag_volume (rpcsvc_request_t *req)
goto out;
}
- switch (cli_req.cmd) {
- case GF_DEFRAG_CMD_START:
- gf_cmd_log ("Volume rebalance"," on volname: %s "
- "cmd: start, attempted", cli_req.volname);
- break;
- case GF_DEFRAG_CMD_STOP:
- gf_cmd_log ("Volume rebalance"," on volname: %s "
- "cmd: stop, attempted", cli_req.volname);
- break;
- default:
- break;
- }
- gf_log ("glusterd", GF_LOG_NORMAL, "Received rebalance volume %s on %s",
- ((cli_req.cmd == GF_DEFRAG_CMD_START) ? "start" :
- (cli_req.cmd == GF_DEFRAG_CMD_STOP) ? "stop" : "status"),
- cli_req.volname);
+ glusterd_rebalance_cmd_attempted_log (cli_req.cmd, cli_req.volname);
rsp.volname = cli_req.volname;
rsp.op_ret = -1;
@@ -710,8 +704,11 @@ glusterd_handle_defrag_volume (rpcsvc_request_t *req)
goto out;
switch (cli_req.cmd) {
case GF_DEFRAG_CMD_START:
+ case GF_DEFRAG_CMD_START_LAYOUT_FIX:
+ case GF_DEFRAG_CMD_START_MIGRATE_DATA:
{
- ret = glusterd_handle_defrag_start (volinfo, msg, sizeof (msg));
+ ret = glusterd_handle_defrag_start (volinfo, msg, sizeof (msg),
+ cli_req.cmd);
rsp.op_ret = ret;
break;
}
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index 0c9104776..cb38ddf88 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -2240,8 +2240,8 @@ out:
int
glusterd_is_defrag_on (glusterd_volinfo_t *volinfo)
{
- return ((volinfo->defrag_status == GF_DEFRAG_STATUS_STARTED) ||
- (volinfo->defrag_status == GF_DEFRAG_STATUS_LAYOUT_FIX_COMPLETE));
+ return ((volinfo->defrag_status == GF_DEFRAG_STATUS_LAYOUT_FIX_STARTED) ||
+ (volinfo->defrag_status == GF_DEFRAG_STATUS_MIGRATE_DATA_STARTED));
}
int
diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h
index 06f35479c..2b02a5139 100644
--- a/xlators/mgmt/glusterd/src/glusterd.h
+++ b/xlators/mgmt/glusterd/src/glusterd.h
@@ -133,11 +133,13 @@ struct gf_defrag_brickinfo_ {
typedef enum gf_defrag_status_ {
GF_DEFRAG_STATUS_NOT_STARTED,
- GF_DEFRAG_STATUS_STARTED,
- GF_DEFRAG_STATUS_LAYOUT_FIX_COMPLETE,
+ GF_DEFRAG_STATUS_LAYOUT_FIX_STARTED,
+ GF_DEFRAG_STATUS_MIGRATE_DATA_STARTED,
GF_DEFRAG_STATUS_STOPED,
GF_DEFRAG_STATUS_COMPLETE,
GF_DEFRAG_STATUS_FAILED,
+ GF_DEFRAG_STATUS_LAYOUT_FIX_COMPLETE,
+ GF_DEFRAG_STATUS_MIGRATE_DATA_COMPLETE,
} gf_defrag_status_t;
struct glusterd_defrag_info_ {
@@ -145,6 +147,7 @@ struct glusterd_defrag_info_ {
uint64_t total_data;
uint64_t num_files_lookedup;
gf_lock_t lock;
+ int cmd;
pthread_t th;
char mount[1024];
char databuf[131072];