diff options
author | Pranith Kumar K <pranithk@gluster.com> | 2011-04-14 11:53:12 +0000 |
---|---|---|
committer | Anand Avati <avati@gluster.com> | 2011-04-14 11:41:26 -0700 |
commit | 4175e092e3521c1f095d6307ea9b05c7c49b02c6 (patch) | |
tree | f530e79b071bff2f3146dba4881ca0abff599137 /xlators/mgmt/glusterd | |
parent | 4055c85a23043afdf3ad708d28aedc55805b1043 (diff) |
mgmt/glusterd: restart gsyncd on glusterd restart
Signed-off-by: Pranith Kumar K <pranithk@gluster.com>
Signed-off-by: Anand Avati <avati@gluster.com>
BUG: 2761 (Restart gsyncd processes on glusterd restart)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2761
Diffstat (limited to 'xlators/mgmt/glusterd')
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-op-sm.c | 7 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-op-sm.h | 5 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-utils.c | 196 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-utils.h | 4 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd.c | 3 |
5 files changed, 212 insertions, 3 deletions
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) { |