summaryrefslogtreecommitdiffstats
path: root/cli/src
diff options
context:
space:
mode:
authorAmar Tumballi <amar@gluster.com>2010-08-09 05:38:46 +0000
committerAnand V. Avati <avati@dev.gluster.com>2010-08-11 22:24:32 -0700
commit0b501ac95edc0ef5945228eb47e6482cfc4efa41 (patch)
tree58fa16eb100868a65e754f704b2a19817250ca91 /cli/src
parent6ff316dca7c9eebab14e71b6ad0908c2e45a5ee2 (diff)
'gluster volume rebalance' related fixes
Signed-off-by: Amar Tumballi <amar@gluster.com> Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 1307 (gluster volume defrag <VOLNAME> status) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1307
Diffstat (limited to 'cli/src')
-rw-r--r--cli/src/cli-cmd-volume.c54
-rw-r--r--cli/src/cli.h1
-rw-r--r--cli/src/cli3_1-cops.c78
3 files changed, 105 insertions, 28 deletions
diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c
index 22844c500ae..63c15473072 100644
--- a/cli/src/cli-cmd-volume.c
+++ b/cli/src/cli-cmd-volume.c
@@ -219,8 +219,7 @@ cli_cmd_volume_rename_cbk (struct cli_state *state, struct cli_cmd_word *word,
goto out;
dict = dict_new ();
-
- if (dict)
+ if (!dict)
goto out;
GF_ASSERT (words[2]);
@@ -254,34 +253,57 @@ out:
return ret;
}
+void
+cli_cmd_volume_defrag_usage ()
+{
+ cli_out ("Usage: volume rebalance <volname> <start|stop|status>");
+}
int
cli_cmd_volume_defrag_cbk (struct cli_state *state, struct cli_cmd_word *word,
const char **words, int wordcount)
{
- int ret = -1;
- rpc_clnt_procedure_t *proc = NULL;
- call_frame_t *frame = NULL;
- char *volname = NULL;
-
+ int ret = -1;
+ rpc_clnt_procedure_t *proc = NULL;
+ call_frame_t *frame = NULL;
+ dict_t *dict = NULL;
frame = create_frame (THIS, THIS->ctx->pool);
if (!frame)
goto out;
+ dict = dict_new ();
+ if (!dict)
+ goto out;
+
+ GF_ASSERT (words[2]);
+
+ if (!(words[3])) {
+ cli_cmd_volume_defrag_usage();
+ goto out;
+ }
//TODO: Build validation here
- volname = (char *)words[2];
- GF_ASSERT (volname);
+ ret = dict_set_str (dict, "volname", (char *)words[2]);
+ if (ret)
+ goto out;
+
+ ret = dict_set_str (dict, "command", (char *)words[3]);
+ if (ret)
+ goto out;
proc = &cli_rpc_prog->proctable[GF1_CLI_DEFRAG_VOLUME];
if (proc->fn) {
- ret = proc->fn (frame, THIS, volname);
+ ret = proc->fn (frame, THIS, dict);
}
out:
- if (!proc && ret)
- cli_out ("Defrag of Volume %s failed", volname);
+ if (!proc && ret) {
+ if (dict)
+ dict_destroy (dict);
+
+ cli_out ("Defrag of Volume %s failed", (char *)words[2]);
+ }
return 0;
}
@@ -438,7 +460,13 @@ struct cli_cmd volume_cmds[] = {
{ "volume remove-brick <VOLNAME> [(replica <COUNT>)|(stripe <COUNT>)] <BRICK> ...",
cli_cmd_volume_remove_brick_cbk },
- { "volume defrag <VOLNAME>",
+ { "volume rebalance <VOLNAME> start",
+ cli_cmd_volume_defrag_cbk },
+
+ { "volume rebalance <VOLNAME> stop",
+ cli_cmd_volume_defrag_cbk },
+
+ { "volume rebalance <VOLNAME> status",
cli_cmd_volume_defrag_cbk },
{ "volume replace-brick <VOLNAME> (<BRICK> <NEW-BRICK>)|pause|abort|start|status",
diff --git a/cli/src/cli.h b/cli/src/cli.h
index 7b2de667358..36ac7214bfd 100644
--- a/cli/src/cli.h
+++ b/cli/src/cli.h
@@ -123,6 +123,7 @@ struct cli_local {
struct {
char *volname;
+ int cmd;
} defrag_vol;
struct {
diff --git a/cli/src/cli3_1-cops.c b/cli/src/cli3_1-cops.c
index 210c881b61b..de3aa6ed2dd 100644
--- a/cli/src/cli3_1-cops.c
+++ b/cli/src/cli3_1-cops.c
@@ -500,11 +500,12 @@ int
gf_cli3_1_defrag_volume_cbk (struct rpc_req *req, struct iovec *iov,
int count, void *myframe)
{
- gf1_cli_defrag_vol_rsp rsp = {0,};
- int ret = 0;
- cli_local_t *local = NULL;
- char *volname = NULL;
- call_frame_t *frame = NULL;
+ gf1_cli_defrag_vol_rsp rsp = {0,};
+ cli_local_t *local = NULL;
+ char *volname = NULL;
+ call_frame_t *frame = NULL;
+ int cmd = 0;
+ int ret = 0;
if (-1 == req->rpc_status) {
goto out;
@@ -521,12 +522,34 @@ gf_cli3_1_defrag_volume_cbk (struct rpc_req *req, struct iovec *iov,
if (frame)
local = frame->local;
- if (local)
- volname = local->u.start_vol.volname;
+ if (local) {
+ volname = local->u.defrag_vol.volname;
+ cmd = local->u.defrag_vol.cmd;
+ }
+ if (cmd == GF_DEFRAG_CMD_START) {
+ cli_out ("starting defrag on volume %s has been %s", volname,
+ (rsp.op_ret) ? "unsuccessful": "successful");
+ }
+ if (cmd == GF_DEFRAG_CMD_STOP) {
+ if (rsp.op_ret == -1)
+ cli_out ("'defrag volume %s stop' failed", volname);
+ else
+ cli_out ("stopped defrag process of volume %s \n"
+ "(after rebalancing %"PRId64" files totaling "
+ "%"PRId64" bytes)", volname, rsp.files, rsp.size);
+ }
+ if (cmd == GF_DEFRAG_CMD_STATUS) {
+ if (rsp.op_ret == -1)
+ cli_out ("failed to get the status of defrag process");
+ else {
+ cli_out ("rebalanced %"PRId64" files of size %"PRId64
+ " (total files scanned %"PRId64")",
+ rsp.files, rsp.size, rsp.lookedup_files);
+ }
+ }
- gf_log ("cli", GF_LOG_NORMAL, "Received resp to probe");
- cli_out ("Defrag of volume %s has been %s", volname,
- (rsp.op_ret) ? "unsuccessful": "successful");
+ if (volname)
+ GF_FREE (volname);
ret = rsp.op_ret;
@@ -1074,23 +1097,48 @@ int32_t
gf_cli3_1_defrag_volume (call_frame_t *frame, xlator_t *this,
void *data)
{
- gf1_cli_defrag_vol_req req = {0,};
- int ret = 0;
- cli_local_t *local = NULL;
+ gf1_cli_defrag_vol_req req = {0,};
+ int ret = 0;
+ cli_local_t *local = NULL;
+ char *volname = NULL;
+ char *cmd_str = NULL;
+ dict_t *dict = NULL;
if (!frame || !this || !data) {
ret = -1;
goto out;
}
+ dict = data;
+
+ ret = dict_get_str (dict, "volname", &volname);
+ if (ret)
+ gf_log ("", GF_LOG_DEBUG, "error");
+
+ ret = dict_get_str (dict, "command", &cmd_str);
+ if (ret) {
+ gf_log ("", GF_LOG_DEBUG, "error");
+ goto out;
+ }
+
+ if (strncasecmp (cmd_str, "start", 6) == 0) {
+ req.cmd = GF_DEFRAG_CMD_START;
+ } else if (strncasecmp (cmd_str, "stop", 5) == 0) {
+ req.cmd = GF_DEFRAG_CMD_STOP;
+ } else if (strncasecmp (cmd_str, "status", 7) == 0) {
+ req.cmd = GF_DEFRAG_CMD_STATUS;
+ }
+
+
local = cli_local_get ();
if (local) {
- local->u.defrag_vol.volname = data;
+ local->u.defrag_vol.volname = gf_strdup (volname);
+ local->u.defrag_vol.cmd = req.cmd;
frame->local = local;
}
- req.volname = data;
+ req.volname = volname;
ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
GD_MGMT_CLI_DEFRAG_VOLUME, NULL,