summaryrefslogtreecommitdiffstats
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/src/cli-cmd-parser.c49
-rw-r--r--cli/src/cli-rpc-ops.c77
2 files changed, 123 insertions, 3 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
index 1cfba3561fc..e8b0e778ae6 100644
--- a/cli/src/cli-cmd-parser.c
+++ b/cli/src/cli-cmd-parser.c
@@ -1120,13 +1120,14 @@ out:
int32_t
cli_cmd_gsync_set_parse (const char **words, int wordcount, dict_t **options)
{
- int32_t ret = 0;
+ int32_t ret = -1;
int32_t config_type = 0;
dict_t *dict = NULL;
gf1_cli_gsync_set type = GF_GSYNC_OPTION_TYPE_NONE;
char *append_str = NULL;
size_t append_len = 0;
int i = 0;
+ int32_t status_type = 0;
GF_ASSERT (words);
GF_ASSERT (options);
@@ -1138,6 +1139,43 @@ cli_cmd_gsync_set_parse (const char **words, int wordcount, dict_t **options)
if (!dict)
goto out;
+ if (wordcount < 3)
+ goto out;
+
+ if ((strcmp (words[2], "status")) == 0) {
+ type = GF_GSYNC_OPTION_TYPE_STATUS;
+
+ if (wordcount == 3)
+ status_type = GF_GSYNC_OPTION_TYPE_STATUS_ALL;
+ else if (wordcount == 4)
+ status_type = GF_GSYNC_OPTION_TYPE_STATUS_MASTER;
+ else if (wordcount == 5)
+ status_type = GF_GSYNC_OPTION_TYPE_STATUS_MST_SLV;
+ else
+ goto out;
+
+
+ ret = dict_set_int32 (dict, "status-type", status_type);
+ if (ret < 0)
+ goto out;
+
+ if (wordcount < 4)
+ goto set_type;
+ ret = dict_set_str (dict, "master", (char *)words[3]);
+ if (ret < 0)
+ goto out;
+
+ if (wordcount < 5)
+ goto set_type;
+ ret = dict_set_str (dict, "slave", (char *)words[4]);
+ if (ret < 0)
+ goto out;
+
+
+
+ goto set_type;
+ }
+
if (wordcount < 5)
goto out;
@@ -1150,12 +1188,18 @@ cli_cmd_gsync_set_parse (const char **words, int wordcount, dict_t **options)
goto out;
if ((strcmp (words[2], "start")) == 0) {
+ if (wordcount != 5)
+ goto out;
+
type = GF_GSYNC_OPTION_TYPE_START;
goto set_type;
}
if ((strcmp (words[2], "stop")) == 0) {
+ if (wordcount != 5)
+ goto out;
+
type = GF_GSYNC_OPTION_TYPE_STOP;
goto set_type;
@@ -1219,6 +1263,9 @@ cli_cmd_gsync_set_parse (const char **words, int wordcount, dict_t **options)
ret = dict_set_int32 (dict, "config_type", config_type);
if (ret < 0)
goto out;
+ } else {
+ ret = -1;
+ goto out;
}
set_type:
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c
index 9da2d9378f8..a6665d1ed5d 100644
--- a/cli/src/cli-rpc-ops.c
+++ b/cli/src/cli-rpc-ops.c
@@ -2580,6 +2580,7 @@ out:
return ret;
}
+
int
gf_cli3_1_gsync_get_command (gf1_cli_gsync_set_rsp rsp)
{
@@ -2616,6 +2617,7 @@ gf_cli3_1_gsync_get_command (gf1_cli_gsync_set_rsp rsp)
return 0;
}
+
int
gf_cli3_1_gsync_get_param_file (char *prmfile, const char *ext, char *master, char *slave, char *gl_workdir)
{
@@ -2673,6 +2675,55 @@ gf_cli3_1_gsync_get_param_file (char *prmfile, const char *ext, char *master, ch
return ret ? -1 : 0;
}
+int
+gf_cli3_1_gsync_out_status (dict_t *dict)
+{
+ int gsync_count = 0;
+ int i = 0;
+ int ret = 0;
+ char mst[PATH_MAX] = {0, };
+ char slv[PATH_MAX]= {0, };
+ char sts[PATH_MAX] = {0, };
+ char *mst_val = NULL;
+ char *slv_val = NULL;
+ char *sts_val = NULL;
+
+
+ ret = dict_get_int32 (dict, "gsync-count", &gsync_count);
+ if (ret) {
+ cli_out ("No Gsync sessions for the selected");
+ ret = 0;
+ goto out;
+ }
+
+ cli_out ("Gsync Status:");
+
+ for (i = 1; i <= gsync_count; i++) {
+ snprintf (mst, sizeof(mst), "master%d", i);
+ snprintf (slv, sizeof(slv), "slave%d", i);
+ snprintf (sts, sizeof(sts), "status%d", i);
+
+ ret = dict_get_str (dict, mst, &mst_val);
+ if (ret)
+ goto out;
+
+ ret = dict_get_str (dict, slv, &slv_val);
+ if (ret)
+ goto out;
+
+ ret = dict_get_str (dict, sts, &sts_val);
+ if (ret)
+ goto out;
+
+ cli_out ("Master:%-20s Slave:%-50s Status:%-10s", mst_val,
+ slv_val, sts_val);
+
+ }
+
+ out:
+ return ret;
+
+}
/* status: 0 when gsync is running
* -1 when not running
@@ -2860,6 +2911,7 @@ gf_cli3_1_gsync_set_cbk (struct rpc_req *req, struct iovec *iov,
{
int ret = 0;
gf1_cli_gsync_set_rsp rsp = {0, };
+ dict_t *dict = NULL;
if (req->rpc_status == -1) {
ret = -1;
@@ -2873,6 +2925,20 @@ gf_cli3_1_gsync_set_cbk (struct rpc_req *req, struct iovec *iov,
goto out;
}
+ dict = dict_new ();
+
+ if (!dict) {
+ ret = -1;
+ goto out;
+ }
+
+ ret = dict_unserialize (rsp.status_dict.status_dict_val,
+ rsp.status_dict.status_dict_len,
+ &dict);
+
+ if (ret)
+ goto out;
+
if (rsp.op_ret) {
cli_out ("%s", rsp.op_errstr ? rsp.op_errstr :
"command unsuccessful");
@@ -2882,10 +2948,17 @@ gf_cli3_1_gsync_set_cbk (struct rpc_req *req, struct iovec *iov,
if (rsp.type == GF_GSYNC_OPTION_TYPE_START)
ret = gf_cli3_1_start_gsync (rsp.master, rsp.slave,
rsp.glusterd_workdir);
- else if (rsp.config_type == GF_GSYNC_OPTION_TYPE_CONFIG_GET_ALL)
+ else if (rsp.config_type == GF_GSYNC_OPTION_TYPE_CONFIG_GET_ALL
+ || rsp.config_type == GF_GSYNC_OPTION_TYPE_CONFIG_GET)
ret = gf_cli3_1_gsync_get_command (rsp);
- else
+ else if (rsp.type == GF_GSYNC_OPTION_TYPE_STATUS)
+ ret = gf_cli3_1_gsync_out_status (dict);
+ else if (rsp.type == GF_GSYNC_OPTION_TYPE_STOP)
+ cli_out ("Gsync session stopped successfully");
+ else if (!rsp.op_errstr)
cli_out ("command executed successfully");
+ else
+ cli_out (rsp.op_errstr);
}
out:
ret = rsp.op_ret;