summaryrefslogtreecommitdiffstats
path: root/xlators
diff options
context:
space:
mode:
authorKaushik BV <kaushikbv@gluster.com>2011-03-14 05:01:31 +0000
committerVijay Bellur <vijay@dev.gluster.com>2011-03-14 04:57:00 -0700
commit9043b0f8b927e687decc738cf736e603436e9e51 (patch)
treed9a16bf5040e33c1197e6d0ca31b265a5594dcda /xlators
parenteadce9083876fb71d1be8f77715866fc8af45ba4 (diff)
mgmt/Glusterd: Make use of regexp pattern-matching sections to set a sane value for remote-gsyncd
Signed-off-by: Kaushik BV <kaushikbv@gluster.com> Signed-off-by: Vijay Bellur <vijay@dev.gluster.com> BUG: 2427 (set a proper default for remote syncdaemon) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2427
Diffstat (limited to 'xlators')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-op-sm.c194
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-op-sm.h4
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-rpc-ops.c8
-rw-r--r--xlators/mgmt/glusterd/src/glusterd.c35
4 files changed, 129 insertions, 112 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
index 067956280..7c9430bc5 100644
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
@@ -1672,33 +1672,53 @@ volname_from_master (char *master)
}
int
-gsync_get_pid_file (char *pidfile, char *master, char *slave)
+glusterd_gsync_get_pid_file (char *pidfile, char *master, char *slave)
{
- int ret = -1;
- int i = 0;
- char str[256] = {0, };
+ FILE *in = NULL;
+ char buff[PATH_MAX] = {0, };
+ char cmd[PATH_MAX] = {0, };
+ char *ptr = NULL;
+ char buffer[PATH_MAX] = {0, };
+ char pidfolder[PATH_MAX] = {0, };
+ glusterd_conf_t *priv = NULL;
- GF_VALIDATE_OR_GOTO ("gsync", pidfile, out);
- GF_VALIDATE_OR_GOTO ("gsync", master, out);
- GF_VALIDATE_OR_GOTO ("gsync", slave, out);
+ GF_ASSERT (THIS);
- i = 0;
- //change '/' to '-'
- while (slave[i]) {
- (slave[i] == '/') ? (str[i] = '-') : (str[i] = slave[i]);
- i++;
+ priv = THIS->private;
+
+ snprintf (cmd, PATH_MAX, GSYNCD_PREFIX"/gsyncd --canonicalize-escape-url"
+ " %s %s", master, slave);
+ if (!(in = popen(cmd, "r"))) {
+ gf_log ("", GF_LOG_ERROR, "popen failed");
+ return -1;
}
- ret = snprintf (pidfile, 1024, "/etc/glusterd/gsync/%s/%s.pid",
- master, str);
- if (ret <= 0) {
- ret = -1;
- goto out;
+ ptr = fgets(buff, sizeof(buff), in);
+ if (ptr) {
+ buff[strlen(buff)-1]='\0'; //strip off \n
+ snprintf (buffer, PATH_MAX, "%s/gsync/%s", priv->workdir, buff);
+ strncpy (pidfolder, buffer, PATH_MAX);
+ }
+ else {
+ gf_log ("", GF_LOG_ERROR, "popen failed");
+ return -1;
}
- ret = 0;
-out:
- return ret;
+ memset (buff, 0, PATH_MAX);
+ memset (buffer, 0, PATH_MAX);
+
+ ptr = fgets(buff, sizeof(buff), in);
+ if (ptr) {
+ buff[strlen(buff)-1]='\0'; //strip off \n
+ snprintf (buffer, PATH_MAX, "%s/%s", pidfolder, buff);
+ strncpy (pidfile, buffer, PATH_MAX);
+ }
+ else {
+ gf_log ("", GF_LOG_ERROR, "popen failed");
+ return -1;
+ }
+
+ return 0;
}
/* status: return 0 when gsync is running
@@ -1708,16 +1728,19 @@ int
gsync_status (char *master, char *slave, int *status)
{
int ret = -1;
- char pidfile[1024] = {0,};
+ char pidfile[PATH_MAX] = {0,};
FILE *file = NULL;
GF_VALIDATE_OR_GOTO ("gsync", master, out);
GF_VALIDATE_OR_GOTO ("gsync", slave, out);
GF_VALIDATE_OR_GOTO ("gsync", status, out);
- ret = gsync_get_pid_file (pidfile, master, slave);
- if (ret == -1)
+ ret = glusterd_gsync_get_pid_file (pidfile, master, slave);
+ if (ret == -1) {
+ ret = -1;
+ gf_log ("", GF_LOG_WARNING, "failed to create the pidfile string");
goto out;
+ }
file = fopen (pidfile, "r+");
if (file) {
@@ -3532,8 +3555,7 @@ stop_gsync (char *master, char *slave, char **op_errstr)
goto out;
}
- //change '/' to '-'
- ret = gsync_get_pid_file (pidfile, master, slave);
+ ret = glusterd_gsync_get_pid_file (pidfile, master, slave);
if (ret == -1) {
ret = -1;
gf_log ("", GF_LOG_WARNING, "failed to create the pidfile string");
@@ -3577,6 +3599,21 @@ gsync_config_set (char *master, char *slave,
char *op_name = NULL;
char *op_value = NULL;
char cmd[1024] = {0,};
+ glusterd_conf_t *priv = NULL;
+
+ if (THIS == NULL) {
+ gf_log ("", GF_LOG_ERROR, "THIS of glusterd not present");
+ *op_errstr = gf_strdup ("Error! Glusterd cannot start gsyncd");
+ goto out;
+ }
+
+ priv = THIS->private;
+
+ if (priv == NULL) {
+ gf_log ("", GF_LOG_ERROR, "priv of glusterd not present");
+ *op_errstr = gf_strdup ("Error! Glusterd cannot start gsyncd");
+ goto out;
+ }
ret = dict_get_str (dict, "op_name", &op_name);
if (ret < 0) {
@@ -3600,8 +3637,9 @@ gsync_config_set (char *master, char *slave,
goto out;
}
- ret = snprintf (cmd, 1024, GSYNCD_PREFIX "/gsyncd %s %s "
- "--config-set %s %s", master, slave, op_name, op_value);
+ ret = snprintf (cmd, 1024, GSYNCD_PREFIX"/gsyncd -c %s/%s %s %s"
+ "--config-set %s %s", priv->workdir,
+ GSYNC_CONF, master, slave, op_name, op_value);
if (ret <= 0) {
gf_log ("", GF_LOG_WARNING, "failed to "
"construct the gsyncd command");
@@ -3635,53 +3673,22 @@ gsync_config_del (char *master, char *slave,
{
int32_t ret = -1;
char *op_name = NULL;
- char cmd[1024] = {0,};
-
- ret = dict_get_str (dict, "op_name", &op_name);
- if (ret < 0) {
- gf_log ("", GF_LOG_WARNING, "failed to get "
- "the option for %s %s", master, slave);
+ char cmd[PATH_MAX] = {0,};
+ glusterd_conf_t *priv = NULL;
- *op_errstr = gf_strdup ("configure command "
- "failed, please check "
- "the log-file\n");
+ if (THIS == NULL) {
+ gf_log ("", GF_LOG_ERROR, "THIS of glusterd not present");
+ *op_errstr = gf_strdup ("Error! Glusterd cannot start gsyncd");
goto out;
}
- ret = snprintf (cmd, 4096, GSYNCD_PREFIX "/gsyncd %s %s "
- "--config-del %s", master, slave, op_name);
- if (ret <= 0) {
- gf_log ("", GF_LOG_WARNING, "failed to "
- "construct the gsyncd command");
- *op_errstr = gf_strdup ("configure command "
- "failed, please check "
- "the log-file\n");
- goto out;
- }
+ priv = THIS->private;
- ret = system (cmd);
- if (ret == -1) {
- gf_log ("", GF_LOG_WARNING, "failed to delete "
- "%s option for %s %s peer", op_name,
- master, slave);
- *op_errstr = gf_strdup ("configure command "
- "failed, please check "
- "the log-file\n");
+ if (priv == NULL) {
+ gf_log ("", GF_LOG_ERROR, "priv of glusterd not present");
+ *op_errstr = gf_strdup ("Error! Glusterd cannot start gsyncd");
goto out;
}
- ret = 0;
- *op_errstr = gf_strdup ("config-del successful");
-out:
- return ret;
-}
-
-int
-gsync_config_get (char *master, char *slave,
- dict_t *dict, char **op_errstr)
-{
- int32_t ret = -1;
- char *op_name = NULL;
- char cmd[1024] = {0,};
ret = dict_get_str (dict, "op_name", &op_name);
if (ret < 0) {
@@ -3694,8 +3701,9 @@ gsync_config_get (char *master, char *slave,
goto out;
}
- ret = snprintf (cmd, 4096, GSYNCD_PREFIX "/gsyncd %s %s "
- "--config-get %s", master, slave, op_name);
+ ret = snprintf (cmd, PATH_MAX, GSYNCD_PREFIX"/gsyncd -c %s/%s %s %s"
+ " --config-del %s ", priv->workdir,
+ GSYNC_CONF, master, slave, op_name);
if (ret <= 0) {
gf_log ("", GF_LOG_WARNING, "failed to "
"construct the gsyncd command");
@@ -3707,7 +3715,7 @@ gsync_config_get (char *master, char *slave,
ret = system (cmd);
if (ret == -1) {
- gf_log ("", GF_LOG_WARNING, "failed to get "
+ gf_log ("", GF_LOG_WARNING, "failed to delete "
"%s option for %s %s peer", op_name,
master, slave);
*op_errstr = gf_strdup ("configure command "
@@ -3716,44 +3724,11 @@ gsync_config_get (char *master, char *slave,
goto out;
}
ret = 0;
- *op_errstr = gf_strdup ("config-get successful");
+ *op_errstr = gf_strdup ("config-del successful");
out:
return ret;
}
-int
-gsync_config_get_all (char *master, char *slave, char **op_errstr)
-{
- int32_t ret = -1;
- char cmd[1024] = {0,};
-
- ret = snprintf (cmd, 4096, GSYNCD_PREFIX "/gsyncd %s %s "
- "config-get-all", master, slave);
- if (ret <= 0) {
- gf_log ("", GF_LOG_WARNING, "failed to "
- "construct the gsyncd command "
- "for config-get-all");
- *op_errstr = gf_strdup ("configure command "
- "failed, please check "
- "the log-file\n");
- goto out;
- }
-
- ret = system (cmd);
- if (ret == -1) {
- gf_log ("", GF_LOG_WARNING, "failed to get "
- "all options for %s %s peer", master,
- slave);
- *op_errstr = gf_strdup ("configure command "
- "failed, please check "
- "the log-file\n");
- goto out;
- }
- ret = 0;
- *op_errstr = gf_strdup ("config-get successful");
-out:
- return ret;
-}
int
gsync_configure (char *master, char *slave,
@@ -3781,15 +3756,10 @@ gsync_configure (char *master, char *slave,
goto out;
}
- if (config_type == GF_GSYNC_OPTION_TYPE_CONFIG_GET) {
- ret = gsync_config_get (master, slave, dict, op_errstr);
- goto out;
- }
-
- if (config_type == GF_GSYNC_OPTION_TYPE_CONFIG_GET_ALL) {
- ret = gsync_config_get_all (master, slave, op_errstr);
+ if ((config_type == GF_GSYNC_OPTION_TYPE_CONFIG_GET_ALL) ||
+ (config_type == GF_GSYNC_OPTION_TYPE_CONFIG_GET))
goto out;
- } else {
+ else {
gf_log ("", GF_LOG_WARNING, "Invalid config type");
*op_errstr = gf_strdup ("Invalid config type");
ret = -1;
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.h b/xlators/mgmt/glusterd/src/glusterd-op-sm.h
index c9c3889b5..ff507abba 100644
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.h
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.h
@@ -25,6 +25,10 @@
#include "config.h"
#endif
+#ifndef GSYNC_CONF
+#define GSYNC_CONF "gsync/gsyncd.conf"
+#endif
+
#include <pthread.h>
#include "uuid.h"
diff --git a/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c b/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c
index 8eba024a9..b46fb23db 100644
--- a/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c
+++ b/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c
@@ -56,6 +56,13 @@ glusterd_op_send_cli_response (glusterd_op_t op, int32_t op_ret,
void *cli_rsp = NULL;
dict_t *ctx = NULL;
char *free_ptr = NULL;
+ glusterd_conf_t *conf = NULL;
+
+ GF_ASSERT (THIS);
+
+ conf = THIS->private;
+
+ GF_ASSERT (conf);
switch (op) {
case GD_OP_CREATE_VOLUME:
@@ -264,6 +271,7 @@ glusterd_op_send_cli_response (glusterd_op_t op, int32_t op_ret,
rsp.op_name = "";
rsp.master = "";
rsp.slave = "";
+ rsp.glusterd_workdir = gf_strdup (conf->workdir);
rsp.gsync_prefix = gf_strdup (GSYNCD_PREFIX);
if (ctx) {
ret = dict_get_str (ctx, "errstr",
diff --git a/xlators/mgmt/glusterd/src/glusterd.c b/xlators/mgmt/glusterd/src/glusterd.c
index 732a9a3e2..570fd1662 100644
--- a/xlators/mgmt/glusterd/src/glusterd.c
+++ b/xlators/mgmt/glusterd/src/glusterd.c
@@ -233,6 +233,7 @@ init (xlator_t *this)
char dirname [PATH_MAX];
char cmd_log_filename [PATH_MAX] = {0,};
int first_time = 0;
+ char cmd [PATH_MAX] = {0,};
dir_data = dict_get (this->options, "working-directory");
@@ -323,7 +324,41 @@ init (xlator_t *this)
" ,errno = %d", voldir, errno);
exit (1);
}
+#if (SYNCDAEMON_COMPILE)
+ snprintf (voldir, PATH_MAX, "%s/gsync", dirname);
+ ret = mkdir (voldir, 0777);
+ if ((-1 == ret) && (errno != EEXIST)) {
+ gf_log (this->name, GF_LOG_CRITICAL,
+ "Unable to create gsync directory %s"
+ " ,errno = %d", voldir, errno);
+ exit (1);
+ }
+
+ ret = snprintf (cmd, PATH_MAX, GSYNCD_PREFIX "/gsyncd -c %s/%s "
+ " --config-set-rx remote-gsyncd %s/gsyncd . ."
+ , dirname, GSYNC_CONF, GSYNCD_PREFIX);
+ if (ret <= 0) {
+ ret = -1;
+ goto out;
+ }
+
+ ret = system (cmd);
+ if (ret == -1)
+ goto out;
+ ret = snprintf (cmd, 1024, GSYNCD_PREFIX "/gsyncd -c %s/%s "
+ " --config-set-rx remote-gsyncd"
+ " /usr/local/libexec/glusterfs/gsyncd . ^ssh:"
+ , dirname, GSYNC_CONF);
+ if (ret <= 0) {
+ ret = -1;
+ goto out;
+ }
+
+ ret = system (cmd);
+ if (ret == -1)
+ goto out;
+#endif
rpc = rpcsvc_init (this->ctx, this->options);
if (rpc == NULL) {
gf_log (this->name, GF_LOG_ERROR,