diff options
-rw-r--r-- | cli/src/cli-cmd-volume.c | 4 | ||||
-rw-r--r-- | cli/src/cli-rpc-ops.c | 56 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-op-sm.c | 4 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-utils.c | 50 |
4 files changed, 71 insertions, 43 deletions
diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index 9dc70d2ea..f6caddbc3 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -1086,7 +1086,7 @@ out: dict_unref (options); if (ret && parse_err == 0) - cli_out (GEOREP" start failed"); + cli_out (GEOREP" command failed"); return ret; } @@ -1165,7 +1165,7 @@ struct cli_cmd volume_cmds[] = { "reset all the reconfigured options"}, #if (SYNCDAEMON_COMPILE) - {"volume "GEOREP" <start|stop|config> <MASTER> <SLAVE> [options]", + {"volume "GEOREP" <start|stop|config|status> [[<VOLNAME>] <SLAVE>] [options]", cli_cmd_volume_gsync_set_cbk, "Geo-sync operations"}, #endif diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c index 1b882cd8f..aa6d80f37 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -2630,20 +2630,27 @@ gf_cli3_1_gsync_out_status (dict_t *dict) char mst[PATH_MAX] = {0, }; char slv[PATH_MAX]= {0, }; char sts[PATH_MAX] = {0, }; + char hyphens[81] = {0, }; char *mst_val = NULL; char *slv_val = NULL; char *sts_val = NULL; + cli_out ("%-20s %-50s %-10s", "MASTER", "SLAVE", "STATUS"); + + for (i=0; i<sizeof(hyphens)-1; i++) + hyphens[i] = '-'; + + cli_out ("%s", hyphens); + ret = dict_get_int32 (dict, "gsync-count", &gsync_count); if (ret) { - cli_out ("No "GEOREP" sessions for the selected"); + gf_log ("cli", GF_LOG_INFO, "No active geo-replication sessions" + "present for the selected"); ret = 0; goto out; } - cli_out (GEOREP" Status:"); - for (i = 1; i <= gsync_count; i++) { snprintf (mst, sizeof(mst), "master%d", i); snprintf (slv, sizeof(slv), "slave%d", i); @@ -2661,7 +2668,7 @@ gf_cli3_1_gsync_out_status (dict_t *dict) if (ret) goto out; - cli_out ("Master:%-20s Slave:%-50s Status:%-10s", mst_val, + cli_out ("%-20s %-50s %-10s", mst_val, slv_val, sts_val); } @@ -2707,25 +2714,36 @@ gf_cli3_1_gsync_set_cbk (struct rpc_req *req, struct iovec *iov, if (rsp.op_ret) { cli_out ("%s", rsp.op_errstr ? rsp.op_errstr : - "command unsuccessful"); + GEOREP" command unsuccessful"); + ret = rsp.op_ret; goto out; - } else { - if (rsp.type == GF_GSYNC_OPTION_TYPE_START) - cli_out ("Gsync started Successfully"); - 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 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) + } + + switch (rsp.type) { + case GF_GSYNC_OPTION_TYPE_START: + cli_out (GEOREP" session started Successfully"); + break; + + case GF_GSYNC_OPTION_TYPE_STOP: cli_out (GEOREP" session stopped successfully"); - else if (!rsp.op_errstr) - cli_out ("command executed successfully"); - else - cli_out (rsp.op_errstr); + break; + + case GF_GSYNC_OPTION_TYPE_CONFIGURE: + 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 + cli_out (GEOREP" config updated successfully"); + break; + + case GF_GSYNC_OPTION_TYPE_STATUS: + ret = gf_cli3_1_gsync_out_status (dict); + goto out; + default: + cli_out (GEOREP" command executed successfully"); } + out: - ret = rsp.op_ret; cli_cmd_broadcast_response (ret); diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c index 75629f47c..e02d9aecb 100644 --- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c +++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c @@ -4257,6 +4257,8 @@ glusterd_gsync_read_frm_status (char *path, char *data) return -1; } + data[strlen(data)-1] = '\0'; + return 0; } @@ -4289,7 +4291,7 @@ glusterd_read_status_file (char *master, char *slave, ret = gsync_status (master, slave, &status); if (ret == 0 && status == -1) { - strncpy (buff, "Corrupt\n", sizeof (buff)); + strncpy (buff, "corrupt", sizeof (buff)); goto done; } else if (ret == -1) goto out; diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index 8001cb3db..16b2bf081 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-utils.c @@ -3202,6 +3202,7 @@ glusterd_start_gsync (char *master, char *slave, char *uuid_str, xlator_t *this = NULL; glusterd_conf_t *priv = NULL; char msg[3*PATH_MAX] = {0}; + int errcode = 0; this = THIS; GF_ASSERT (this); @@ -3218,7 +3219,7 @@ glusterd_start_gsync (char *master, char *slave, char *uuid_str, ret = glusterd_gsync_get_param_file (prmfile, "pid", master, slave, priv->workdir); if (ret == -1) { - snprintf (msg, sizeof (msg), "failed to create the pidfile string"); + errcode = -1; goto out; } unlink (prmfile); @@ -3227,8 +3228,9 @@ glusterd_start_gsync (char *master, char *slave, char *uuid_str, *tslash = '\0'; ret = mkdir (prmfile, 0777); if (ret && (errno != EEXIST)) { - snprintf (msg, sizeof (msg), "mkdir %s failed, (%s)", - prmfile, strerror (errno)); + errcode = -1; + gf_log ("", GF_LOG_WARNING, "Failed to create the" + " directory %s", prmfile); goto out; } *tslash = '/'; @@ -3240,8 +3242,7 @@ glusterd_start_gsync (char *master, char *slave, char *uuid_str, GSYNC_CONF, master, slave, prmfile); if (ret <= 0) { ret = -1; - snprintf (msg, sizeof (msg), "failed to construct the " - "config set command for %s %s", master, slave); + errcode = -1; gf_log ("", GF_LOG_WARNING, "failed to construct the " "config set command for %s %s", master, slave); goto out; @@ -3249,8 +3250,7 @@ glusterd_start_gsync (char *master, char *slave, char *uuid_str, ret = gf_system (cmd); if (ret) { - snprintf (msg, sizeof (msg), "failed to set the pid " - "option for %s %s", master, slave); + errcode = -1; gf_log ("", GF_LOG_WARNING, "failed to set the pid " "option for %s %s", master, slave); goto out; @@ -3267,8 +3267,7 @@ glusterd_start_gsync (char *master, char *slave, char *uuid_str, if (ret != -1) ret = gf_system (cmd) ? -1 : 0; if (ret == -1) { - snprintf (msg, sizeof (msg), "failed to set status file " - "for %s %s", master, slave); + errcode = -1; gf_log ("", GF_LOG_WARNING, "failed to set status file " "for %s %s", master, slave); goto out; @@ -3277,8 +3276,7 @@ glusterd_start_gsync (char *master, char *slave, char *uuid_str, ret = glusterd_gsync_get_param_file (prmfile, "log", master, slave, DEFAULT_LOG_FILE_DIRECTORY); if (ret == -1) { - snprintf (msg, sizeof (msg), "failed to construct the " - "logfile string"); + errcode = -1; goto out; } /* XXX "mkdir -p": eventually this should be made into a library routine */ @@ -3296,8 +3294,9 @@ glusterd_start_gsync (char *master, char *slave, char *uuid_str, *slash = '\0'; ret = mkdir (prmfile, 0777); if (ret == -1 && errno != EEXIST) { - snprintf (msg, sizeof (msg), "mkdir %s failed, " - "(%s)", prmfile, strerror (errno)); + errcode = -1; + gf_log ("", GF_LOG_WARNING, "Failed to create" + " the directory %s", prmfile); goto out; } if (slash) { @@ -3308,8 +3307,9 @@ glusterd_start_gsync (char *master, char *slave, char *uuid_str, ret = stat (prmfile, &st); if (ret == -1 || !S_ISDIR (st.st_mode)) { ret = -1; - snprintf (msg, sizeof (msg), "mkdir %s failed, " - "(%s)", prmfile, strerror (errno)); + errcode = -1; + gf_log ("", GF_LOG_WARNING, "Failed to create the" + "directory %s", prmfile); goto out; } *tslash = '/'; @@ -3323,8 +3323,7 @@ glusterd_start_gsync (char *master, char *slave, char *uuid_str, if (ret != -1) ret = gf_system (cmd) ? -1 : 0; if (ret == -1) { - snprintf (msg, sizeof (msg), "failed to set status file " - "for %s %s", master, slave); + errcode = -1; gf_log ("", GF_LOG_WARNING, "failed to set status file " "for %s %s", master, slave); goto out; @@ -3336,20 +3335,29 @@ glusterd_start_gsync (char *master, char *slave, char *uuid_str, slave); if (ret <= 0) { ret = -1; + errcode = -1; goto out; } ret = gf_system (cmd); - if (ret == -1) + if (ret == -1) { + ret = snprintf (msg, sizeof (msg), GEOREP" start failed for %s " + "%s", master, slave); + if (ret <=0) + goto out; + *op_errstr = gf_strdup (msg); goto out; + } ret = 0; out: - if ((ret != 0) && (msg[0] != '\0')) { - gf_log ("glusterd", GF_LOG_ERROR, "%s", msg); + if ((ret != 0) && errcode == -1) { if (op_errstr) - *op_errstr = gf_strdup (msg); + *op_errstr = gf_strdup ("internal error, cannot start" + "the " GEOREP " session"); } + + gf_log ("", GF_LOG_DEBUG, "Returning %d", ret); return ret; } |