summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cli/src/cli-rpc-ops.c156
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-op-sm.c7
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-op-sm.h5
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.c196
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.h4
-rw-r--r--xlators/mgmt/glusterd/src/glusterd.c3
6 files changed, 214 insertions, 157 deletions
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c
index a6665d1ed5d..9a2bb87f14e 100644
--- a/cli/src/cli-rpc-ops.c
+++ b/cli/src/cli-rpc-ops.c
@@ -2756,156 +2756,6 @@ out:
}
int
-gf_cli3_1_start_gsync (char *master, char *slave, char *gl_workdir)
-{
- int32_t ret = -1;
- int32_t status = 0;
- char cmd[PATH_MAX] = {0,};
- char prmfile[PATH_MAX] = {0,};
- char *tslash = NULL;
-
- ret = gf_cli3_1_gsync_get_param_file (prmfile, "pid", master,
- slave, gl_workdir);
- if (ret == -1) {
- ret = -1;
- gf_log ("", GF_LOG_WARNING, "failed to construct the "
- "pidfile string");
- goto out;
- }
-
- ret = gf_cli3_1_gsync_status (master, slave, prmfile, &status);
- if ((ret == 0 && status == 0)) {
- gf_log ("", GF_LOG_WARNING, "gsync %s:%s"
- "already started", master, slave);
-
- cli_out ("gsyncd is already running");
-
- ret = -1;
- goto out;
- }
-
- unlink (prmfile);
-
- tslash = strrchr(prmfile, '/');
- if (tslash) {
- *tslash = '\0';
- ret = mkdir (prmfile, 0777);
- if (ret && (errno != EEXIST)) {
- gf_log ("", GF_LOG_DEBUG, "mkdir failed, errno: %d",
- errno);
- goto out;
- }
- *tslash = '/';
- }
-
- memset (cmd, 0, sizeof (cmd));
- ret = snprintf (cmd, PATH_MAX, GSYNCD_PREFIX "/gsyncd -c %s/%s %s %s"
- " --config-set pid-file %s", gl_workdir,
- GSYNC_CONF, master, slave, prmfile);
- if (ret <= 0) {
- ret = -1;
- gf_log ("", GF_LOG_WARNING, "failed to construct the "
- "config set command for %s %s", master, slave);
- goto out;
- }
-
- ret = system (cmd);
- if (ret) {
- gf_log ("", GF_LOG_WARNING, "failed to set the pid "
- "option for %s %s", master, slave);
- goto out;
- }
-
- ret = gf_cli3_1_gsync_get_param_file (prmfile, "status", NULL, NULL, NULL);
- if (ret != -1)
- ret = snprintf (cmd, PATH_MAX, GSYNCD_PREFIX "/gsyncd -c %s/%s %s %s"
- " --config-set state-file %s", gl_workdir,
- GSYNC_CONF, master, slave, prmfile);
- if (ret >= PATH_MAX)
- ret = -1;
- if (ret != -1)
- ret = system (cmd) ? -1 : 0;
- if (ret == -1) {
- gf_log ("", GF_LOG_WARNING, "failed to set status file "
- "for %s %s", master, slave);
- goto out;
- }
-
- ret = gf_cli3_1_gsync_get_param_file (prmfile, "log", master,
- slave, DEFAULT_LOG_FILE_DIRECTORY);
- if (ret == -1) {
- gf_log ("", GF_LOG_WARNING, "failed to construct the "
- "logfile string");
- goto out;
- }
- /* XXX "mkdir -p": eventually this should be made into a library routine */
- tslash = strrchr(prmfile, '/');
- if (tslash) {
- char *slash = prmfile;
- struct stat st = {0,};
-
- *tslash = '\0';
- if (*slash == '/')
- slash++;
- while (slash) {
- slash = strchr (slash, '/');
- if (slash)
- *slash = '\0';
- ret = mkdir (prmfile, 0777);
- if (ret == -1 && errno != EEXIST) {
- gf_log ("", GF_LOG_DEBUG, "mkdir failed (%s)",
- strerror (errno));
- goto out;
- }
- if (slash) {
- *slash = '/';
- slash++;
- }
- }
- ret = stat (prmfile, &st);
- if (ret == -1 || !S_ISDIR (st.st_mode)) {
- ret = -1;
- gf_log ("", GF_LOG_DEBUG, "mkdir failed (%s)",
- strerror (errno));
- goto out;
- }
- *tslash = '/';
- }
-
- ret = snprintf (cmd, PATH_MAX, GSYNCD_PREFIX "/gsyncd -c %s/%s %s %s"
- " --config-set log-file %s", gl_workdir,
- GSYNC_CONF, master, slave, prmfile);
- if (ret >= PATH_MAX)
- ret = -1;
- if (ret != -1)
- ret = system (cmd) ? -1 : 0;
- if (ret == -1) {
- gf_log ("", GF_LOG_WARNING, "failed to set status file "
- "for %s %s", master, slave);
- goto out;
- }
-
- memset (cmd, 0, sizeof (cmd));
- ret = snprintf (cmd, PATH_MAX, GSYNCD_PREFIX "/gsyncd --monitor -c %s/%s %s %s"
- , gl_workdir, GSYNC_CONF, master, slave);
- if (ret <= 0) {
- ret = -1;
- goto out;
- }
-
- ret = system (cmd);
- if (ret == -1)
- goto out;
-
- cli_out ("gsync started");
- ret = 0;
-
-out:
-
- return ret;
-}
-
-int
gf_cli3_1_gsync_set_cbk (struct rpc_req *req, struct iovec *iov,
int count, void *myframe)
{
@@ -2943,11 +2793,9 @@ gf_cli3_1_gsync_set_cbk (struct rpc_req *req, struct iovec *iov,
cli_out ("%s", rsp.op_errstr ? rsp.op_errstr :
"command unsuccessful");
goto out;
- }
- else {
+ } else {
if (rsp.type == GF_GSYNC_OPTION_TYPE_START)
- ret = gf_cli3_1_start_gsync (rsp.master, rsp.slave,
- rsp.glusterd_workdir);
+ 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);
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
index b1ace26da98..b446f79d0f3 100644
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
@@ -1912,6 +1912,8 @@ gsync_status (char *master, char *slave, int *status)
}
ret = 0;
out:
+ if (file)
+ fclose (file);
return ret;
}
@@ -2174,7 +2176,7 @@ glusterd_gsync_get_uuid (char *master, char *slave, glusterd_volinfo_t *vol,
int ret = 0;
glusterd_gsync_slaves_t status = {0, };
char cann_slave[PATH_MAX] = {0, };
- char host_uuid_str[32] = {0};
+ char host_uuid_str[64] = {0};
xlator_t *this = NULL;
glusterd_conf_t *priv = NULL;
@@ -2214,7 +2216,7 @@ glusterd_gsync_get_uuid (char *master, char *slave, glusterd_volinfo_t *vol,
static int
glusterd_check_gsync_running_local (char *master, char *slave,
- gf_boolean_t *is_run)
+ gf_boolean_t *is_run)
{
int ret = -1;
int ret_status = 0;
@@ -4802,6 +4804,7 @@ glusterd_op_gsync_set (dict_t *dict, char **op_errstr, dict_t *rsp_dict)
host_uuid, op_errstr);
if (ret)
goto out;
+ ret = glusterd_start_gsync (volinfo->volname, slave, host_uuid);
}
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.h b/xlators/mgmt/glusterd/src/glusterd-op-sm.h
index d10d5c1a4f9..399d9a5c919 100644
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.h
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.h
@@ -300,5 +300,10 @@ glusterd_stop_bricks (glusterd_volinfo_t *volinfo);
int
glusterd_get_gsync_status_mst_slv( glusterd_volinfo_t *volinfo, char *master,
char *slave, dict_t *rsp_dict);
+int
+gsync_status (char *master, char *slave, int *status);
+int
+glusterd_gsync_get_param_file (char *prmfile, const char *ext, char *master,
+ char *slave, char *gl_workdir);
#endif
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index bd6a4ed0432..855215f65a5 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -2289,7 +2289,7 @@ glusterd_restart_bricks (glusterd_conf_t *conf)
{
glusterd_volinfo_t *volinfo = NULL;
glusterd_brickinfo_t *brickinfo = NULL;
- int ret = -1;
+ int ret = 0;
GF_ASSERT (conf);
@@ -2306,6 +2306,49 @@ glusterd_restart_bricks (glusterd_conf_t *conf)
return ret;
}
+void
+_local_gsyncd_start (dict_t *this, char *key, data_t *value, void *data)
+{
+ char *slave = NULL;
+ int uuid_len = 0;
+ char uuid_str[64] = {0};
+ glusterd_volinfo_t *volinfo = NULL;
+
+ volinfo = data;
+ GF_ASSERT (volinfo);
+ slave = strchr(value->data, ':');
+ if (slave)
+ slave ++;
+ else
+ return;
+ uuid_len = (slave - value->data - 1);
+
+
+ strncpy (uuid_str, (char*)value->data, uuid_len);
+ glusterd_start_gsync (volinfo->volname, slave, uuid_str);
+}
+
+int
+glusterd_volume_restart_gsyncds (glusterd_volinfo_t *volinfo)
+{
+ GF_ASSERT (volinfo);
+
+ dict_foreach (volinfo->gsync_slaves, _local_gsyncd_start, volinfo);
+ return 0;
+}
+
+int
+glusterd_restart_gsyncds (glusterd_conf_t *conf)
+{
+ glusterd_volinfo_t *volinfo = NULL;
+ int ret = 0;
+
+ list_for_each_entry (volinfo, &conf->volumes, vol_list) {
+ glusterd_volume_restart_gsyncds (volinfo);
+ }
+ return ret;
+}
+
int
glusterd_get_brickinfo (xlator_t *this, const char *brickname, int port,
gf_boolean_t localhost, glusterd_brickinfo_t **brickinfo)
@@ -3142,3 +3185,154 @@ glusterd_delete_all_bricks (glusterd_volinfo_t* volinfo)
}
return ret;
}
+
+int
+glusterd_start_gsync (char *master, char *slave, char *uuid_str)
+{
+ int32_t ret = 0;
+ int32_t status = 0;
+ char cmd[PATH_MAX] = {0,};
+ char prmfile[PATH_MAX] = {0,};
+ char local_uuid_str [64] = {0};
+ char *tslash = NULL;
+ xlator_t *this = NULL;
+ glusterd_conf_t *priv = NULL;
+ char master_url[GLUSTERD_MAX_VOLUME_NAME + 8] = {0};
+
+ this = THIS;
+ GF_ASSERT (this);
+ priv = this->private;
+ GF_ASSERT (priv);
+
+ uuid_utoa_r (priv->uuid, local_uuid_str);
+ if (strcmp (local_uuid_str, uuid_str))
+ goto out;
+
+ snprintf (master_url, sizeof (master_url), ":%s", master);
+ ret = gsync_status (master_url, slave, &status);
+ if (status == 0)
+ goto out;
+ ret = glusterd_gsync_get_param_file (prmfile, "pid", master_url,
+ slave, priv->workdir);
+ if (ret == -1) {
+ gf_log ("", GF_LOG_WARNING, "failed to create the pidfile string");
+ goto out;
+ }
+ unlink (prmfile);
+ tslash = strrchr(prmfile, '/');
+ if (tslash) {
+ *tslash = '\0';
+ ret = mkdir (prmfile, 0777);
+ if (ret && (errno != EEXIST)) {
+ gf_log ("", GF_LOG_DEBUG, "mkdir failed, errno: %d",
+ errno);
+ goto out;
+ }
+ *tslash = '/';
+ }
+
+ memset (cmd, 0, sizeof (cmd));
+ ret = snprintf (cmd, PATH_MAX, GSYNCD_PREFIX "/gsyncd -c %s/%s %s %s"
+ " --config-set pid-file %s", priv->workdir,
+ GSYNC_CONF, master_url, slave, prmfile);
+ if (ret <= 0) {
+ ret = -1;
+ gf_log ("", GF_LOG_WARNING, "failed to construct the "
+ "config set command for %s %s", master_url, slave);
+ goto out;
+ }
+
+ ret = gf_system (cmd);
+ if (ret) {
+ gf_log ("", GF_LOG_WARNING, "failed to set the pid "
+ "option for %s %s", master_url, slave);
+ goto out;
+ }
+
+ ret = glusterd_gsync_get_param_file (prmfile, "status", NULL, NULL, NULL);
+ if (ret != -1)
+ ret = snprintf (cmd, PATH_MAX, GSYNCD_PREFIX "/gsyncd -c %s/%s %s %s"
+ " --config-set state-file %s", priv->workdir,
+ GSYNC_CONF, master_url, slave, prmfile);
+ if (ret >= PATH_MAX)
+ ret = -1;
+ if (ret != -1)
+ ret = gf_system (cmd) ? -1 : 0;
+ if (ret == -1) {
+ gf_log ("", GF_LOG_WARNING, "failed to set status file "
+ "for %s %s", master_url, slave);
+ goto out;
+ }
+
+ ret = glusterd_gsync_get_param_file (prmfile, "log", master_url,
+ slave, DEFAULT_LOG_FILE_DIRECTORY);
+ if (ret == -1) {
+ gf_log ("", GF_LOG_WARNING, "failed to construct the "
+ "logfile string");
+ goto out;
+ }
+ /* XXX "mkdir -p": eventually this should be made into a library routine */
+ tslash = strrchr(prmfile, '/');
+ if (tslash) {
+ char *slash = prmfile;
+ struct stat st = {0,};
+
+ *tslash = '\0';
+ if (*slash == '/')
+ slash++;
+ while (slash) {
+ slash = strchr (slash, '/');
+ if (slash)
+ *slash = '\0';
+ ret = mkdir (prmfile, 0777);
+ if (ret == -1 && errno != EEXIST) {
+ gf_log ("", GF_LOG_DEBUG, "mkdir failed (%s)",
+ strerror (errno));
+ goto out;
+ }
+ if (slash) {
+ *slash = '/';
+ slash++;
+ }
+ }
+ ret = stat (prmfile, &st);
+ if (ret == -1 || !S_ISDIR (st.st_mode)) {
+ ret = -1;
+ gf_log ("", GF_LOG_DEBUG, "mkdir failed (%s)",
+ strerror (errno));
+ goto out;
+ }
+ *tslash = '/';
+ }
+
+ ret = snprintf (cmd, PATH_MAX, GSYNCD_PREFIX "/gsyncd -c %s/%s %s %s"
+ " --config-set log-file %s", priv->workdir,
+ GSYNC_CONF, master_url, slave, prmfile);
+ if (ret >= PATH_MAX)
+ ret = -1;
+ if (ret != -1)
+ ret = gf_system (cmd) ? -1 : 0;
+ if (ret == -1) {
+ gf_log ("", GF_LOG_WARNING, "failed to set status file "
+ "for %s %s", master_url, slave);
+ goto out;
+ }
+
+ memset (cmd, 0, sizeof (cmd));
+ ret = snprintf (cmd, PATH_MAX, GSYNCD_PREFIX "/gsyncd --monitor -c %s/%s %s %s"
+ , priv->workdir, GSYNC_CONF, master_url, slave);
+ if (ret <= 0) {
+ ret = -1;
+ goto out;
+ }
+
+ ret = gf_system (cmd);
+ if (ret == -1)
+ goto out;
+
+ ret = 0;
+
+out:
+
+ return ret;
+}
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h
index ffb9e971aff..56c715cbe06 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.h
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.h
@@ -269,4 +269,8 @@ glusterd_delete_brick (glusterd_volinfo_t* volinfo,
glusterd_brickinfo_t *brickinfo);
int32_t
glusterd_delete_all_bricks (glusterd_volinfo_t* volinfo);
+int
+glusterd_restart_gsyncds (glusterd_conf_t *conf);
+int
+glusterd_start_gsync (char *master, char *slave, char *uuid_str);
#endif
diff --git a/xlators/mgmt/glusterd/src/glusterd.c b/xlators/mgmt/glusterd/src/glusterd.c
index e1c338bc38b..7d20d6c5ea2 100644
--- a/xlators/mgmt/glusterd/src/glusterd.c
+++ b/xlators/mgmt/glusterd/src/glusterd.c
@@ -500,6 +500,9 @@ init (xlator_t *this)
glusterd_opinfo_init ();
glusterd_restart_bricks (conf);
+ ret = glusterd_restart_gsyncds (conf);
+ if (ret)
+ goto out;
ret = 0;
out:
if (ret < 0) {