summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src
diff options
context:
space:
mode:
authorCsaba Henk <csaba@gluster.com>2011-04-19 07:19:17 +0000
committerAnand Avati <avati@gluster.com>2011-04-21 00:39:50 -0700
commit0dd8c38d17e51c4b8bd1471854315e27c25cc615 (patch)
tree93a85fc17bf65ba58421afb30be2c9a73ed1c6b5 /xlators/mgmt/glusterd/src
parent29ac0febecbca0700bb4b1e2335b8dace5ff452c (diff)
geo-replication: revamp CONFIG command
Drop the config_type RPC req field, use just a "subop" key in the param dict. Signed-off-by: Csaba Henk <csaba@gluster.com> Signed-off-by: Anand Avati <avati@gluster.com> BUG: 2785 (gsyncd logs on slave side go to /dev/null) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2785
Diffstat (limited to 'xlators/mgmt/glusterd/src')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-handler.c4
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-op-sm.c338
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-rpc-ops.c15
3 files changed, 109 insertions, 248 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
index a78c876e3f5..bf601efcda5 100644
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
@@ -1752,8 +1752,8 @@ glusterd_handle_gsync_set (rpcsvc_request_t *req)
strncpy (operation, "stop", sizeof (operation));
break;
- case GF_GSYNC_OPTION_TYPE_CONFIGURE:
- strncpy (operation, "configure", sizeof (operation));
+ case GF_GSYNC_OPTION_TYPE_CONFIG:
+ strncpy (operation, "config", sizeof (operation));
break;
case GF_GSYNC_OPTION_TYPE_STATUS:
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
index 7003c579362..af0a4484c5a 100644
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
@@ -1844,20 +1844,6 @@ gsync_status (char *master, char *slave, int *status)
}
-int
-gsync_validate_config_type (int32_t config_type)
-{
- switch (config_type) {
- case GF_GSYNC_OPTION_TYPE_CONFIG_SET:
- case GF_GSYNC_OPTION_TYPE_CONFIG_DEL:
- case GF_GSYNC_OPTION_TYPE_CONFIG_GET:
- case GF_GSYNC_OPTION_TYPE_CONFIG_GET_ALL:return 0;
- default: return -1;
- }
- return 0;
-}
-
-
int32_t
glusterd_gsync_volinfo_dict_set (glusterd_volinfo_t *volinfo,
char *key, char *value)
@@ -1883,61 +1869,77 @@ out:
}
int
-gsync_validate_config_option (dict_t *dict, int32_t config_type,
- char **op_errstr)
+gsync_verify_config_options (dict_t *dict, char **op_errstr)
{
char cmd[PATH_MAX] = {0,};
- int ret = -1;
char **resopt = NULL;
int i = 0;
+ char *subop = NULL;
char *op_name = NULL;
+ char *op_value = NULL;
gf_boolean_t banned = _gf_true;
- if (config_type == GF_GSYNC_OPTION_TYPE_CONFIG_GET_ALL)
+ if (dict_get_str (dict, "subop", &subop) != 0) {
+ gf_log ("", GF_LOG_WARNING, "missing subop");
+ *op_errstr = gf_strdup ("Invalid config request");
+ return -1;
+ }
+
+ if (strcmp (subop, "get-all") == 0)
return 0;
- ret = dict_get_str (dict, "op_name", &op_name);
- if (ret < 0) {
- gf_log ("", GF_LOG_WARNING, "option not specified");
- *op_errstr = gf_strdup ("Please specify the option");
+ if (dict_get_str (dict, "op_name", &op_name) != 0) {
+ gf_log ("", GF_LOG_WARNING, "option name missing");
+ *op_errstr = gf_strdup ("Option name missing");
return -1;
}
snprintf (cmd, PATH_MAX, GSYNCD_PREFIX"/gsyncd --config-check %s", op_name);
- ret = system (cmd);
- if (ret) {
+ if (system (cmd)) {
gf_log ("", GF_LOG_WARNING, "Invalid option %s", op_name);
*op_errstr = gf_strdup ("Invalid option");
- ret = -1;
+ return -1;
}
- if (ret != -1 &&
- (config_type == GF_GSYNC_OPTION_TYPE_CONFIG_SET ||
- config_type == GF_GSYNC_OPTION_TYPE_CONFIG_DEL)) {
- /* match option name against reserved options, modulo -/-
- * difference
- */
- for (resopt = gsync_reserved_opts; *resopt; resopt++) {
- banned = _gf_true;
- for (i = 0; (*resopt)[i] && op_name[i]; i++) {
- if ((*resopt)[i] == op_name[i] ||
- ((*resopt)[i] == '-' && op_name[i] == '_'))
- continue;
- banned = _gf_false;
- }
- if (banned) {
- gf_log ("", GF_LOG_WARNING, "Reserved option %s", op_name);
- *op_errstr = gf_strdup ("Reserved option");
+ if (strcmp (subop, "get") == 0)
+ return 0;
- ret = -1;
- break;
- }
+ if (strcmp (subop, "set") != 0 && strcmp (subop, "del") != 0) {
+ gf_log ("", GF_LOG_WARNING, "unknown subop %s", subop);
+ *op_errstr = gf_strdup ("Invalid config request");
+ return -1;
+ }
+
+ if (strcmp (subop, "set") == 0 &&
+ dict_get_str (dict, "op_value", &op_value) != 0) {
+ gf_log ("", GF_LOG_WARNING, "missing value for set");
+ *op_errstr = gf_strdup ("missing value");
+ }
+
+ /* match option name against reserved options, modulo -/_
+ * difference
+ */
+ for (resopt = gsync_reserved_opts; *resopt; resopt++) {
+ banned = _gf_true;
+ for (i = 0; (*resopt)[i] && op_name[i]; i++) {
+ if ((*resopt)[i] == op_name[i] ||
+ ((*resopt)[i] == '-' && op_name[i] == '_'))
+ continue;
+ banned = _gf_false;
+ }
+ if (banned) {
+ gf_log ("", GF_LOG_WARNING, "Reserved option %s", op_name);
+ *op_errstr = gf_strdup ("Reserved option");
+
+ return -1;
+ break;
}
}
- return ret;
+ return 0;
}
+
static void
_get_status_mst_slv (dict_t *this, char *key, data_t *value, void *data)
{
@@ -2025,38 +2027,6 @@ _remove_gsync_slave (dict_t *this, char *key, data_t *value, void *data)
}
-int
-gsync_verify_config_options (dict_t *dict, char **op_errstr)
-{
- int ret = -1;
- int config_type = 0;
-
- GF_VALIDATE_OR_GOTO ("gsync", dict, out);
- GF_VALIDATE_OR_GOTO ("gsync", op_errstr, out);
-
- ret = dict_get_int32 (dict, "config_type", &config_type);
- if (ret < 0) {
- gf_log ("", GF_LOG_WARNING, "config type is missing");
- *op_errstr = gf_strdup ("config-type missing");
- goto out;
- }
-
- ret = gsync_validate_config_type (config_type);
- if (ret == -1) {
- gf_log ("", GF_LOG_WARNING, "Invalid config type");
- *op_errstr = gf_strdup ("Invalid config type");
- goto out;
- }
-
- ret = gsync_validate_config_option (dict, config_type, op_errstr);
- if (ret < 0)
- goto out;
-
- ret = 0;
-out:
- return ret;
-}
-
static int
glusterd_remove_slave_in_info (glusterd_volinfo_t *volinfo, char *slave,
char *host_uuid, char **op_errstr)
@@ -2451,7 +2421,7 @@ glusterd_op_stage_gsync_set (dict_t *dict, char **op_errstr)
if (ret)
goto out;
break;
- case GF_GSYNC_OPTION_TYPE_CONFIGURE:
+ case GF_GSYNC_OPTION_TYPE_CONFIG:
ret = gsync_verify_config_options (dict, op_errstr);
if (ret < 0)
goto out;
@@ -4109,140 +4079,85 @@ out:
}
int
-gsync_config_set (char *master, char *slave,
- dict_t *dict, char **op_errstr)
+glusterd_check_restart_gsync_session (glusterd_volinfo_t *volinfo, char *slave);
+
+int
+glusterd_gsync_configure (glusterd_volinfo_t *volinfo, char *slave,
+ dict_t *dict, char **op_errstr)
{
int32_t ret = -1;
char *op_name = NULL;
char *op_value = NULL;
char cmd[1024] = {0,};
glusterd_conf_t *priv = NULL;
+ char *subop = NULL;
+ char *q1 = NULL;
+ char *q2 = NULL;
- if (THIS == NULL) {
- gf_log ("", GF_LOG_ERROR, "THIS of glusterd not present");
- *op_errstr = gf_strdup ("Error! Glusterd cannot start "GEOREP);
- goto out;
- }
-
- priv = THIS->private;
+ GF_ASSERT (volinfo);
+ GF_ASSERT (slave);
+ GF_ASSERT (op_errstr);
- if (priv == NULL) {
- gf_log ("", GF_LOG_ERROR, "priv of glusterd not present");
- *op_errstr = gf_strdup ("Error! Glusterd cannot start "GEOREP);
+ ret = dict_get_str (dict, "subop", &subop);
+ if (ret != 0)
goto out;
+
+ if (strcmp (subop, "get") == 0 || strcmp (subop, "get-all") == 0) {
+ /* deferred to cli */
+ gf_log ("", GF_LOG_DEBUG, "Returning 0");
+ return 0;
}
ret = dict_get_str (dict, "op_name", &op_name);
- if (ret < 0) {
- gf_log ("", GF_LOG_WARNING, "failed to get the "
- "option name for %s %s", master, slave);
-
- *op_errstr = gf_strdup ("configure command failed, "
- "please check the log-file\n");
+ if (ret != 0)
goto out;
- }
-
- ret = dict_get_str (dict, "op_value", &op_value);
- if (ret < 0) {
- gf_log ("", GF_LOG_WARNING, "failed to get "
- "the option value for %s %s",
- master, slave);
- *op_errstr = gf_strdup ("configure command "
- "failed, please check "
- "the log-file\n");
- goto out;
+ if (strcmp (subop, "set") == 0) {
+ ret = dict_get_str (dict, "op_value", &op_value);
+ if (ret != 0)
+ goto out;
+ q1 = " \"";
+ q2 = "\"";
+ } else {
+ q1 = "";
+ op_value = "";
+ q2 = "";
}
- 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");
-
- *op_errstr = gf_strdup ("configure command failed, "
- "please check the log-file\n");
+ if (THIS)
+ priv = THIS->private;
+ if (priv == NULL) {
+ gf_log ("", GF_LOG_ERROR, "priv of glusterd not present");
+ *op_errstr = gf_strdup ("glusterd defunct");
goto out;
}
+ ret = snprintf (cmd, 1024, GSYNCD_PREFIX"/gsyncd -c %s/"GSYNC_CONF" :%s %s"
+ " --config-%s %s" "%s%s%s", priv->workdir,
+ volinfo->volname, slave, subop, op_name,
+ q1, op_value, q2);
ret = system (cmd);
- if (ret == -1) {
+ if (ret) {
gf_log ("", GF_LOG_WARNING, "gsyncd failed to "
- "set %s option for %s %s peer",
- op_name, master, slave);
+ "%s %s option for %s %s peers",
+ subop, op_name, volinfo->volname, slave);
+
+ gf_asprintf (op_errstr, GEOREP" config-%s failed for %s %s",
+ subop, volinfo->volname, slave);
- *op_errstr = gf_strdup ("configure command "
- "failed, please check "
- "the log-file\n");
goto out;
}
ret = 0;
- *op_errstr = gf_strdup ("config-set successful");
+ gf_asprintf (op_errstr, "config-%s successful", subop);
out:
- return ret;
-}
-
-int
-gsync_config_del (char *master, char *slave,
- dict_t *dict, char **op_errstr)
-{
- int32_t ret = -1;
- char *op_name = NULL;
- char cmd[PATH_MAX] = {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 "GEOREP);
- 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 "GEOREP);
- goto out;
- }
-
- 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);
-
- *op_errstr = gf_strdup ("configure command "
- "failed, please check "
- "the log-file\n");
- goto out;
- }
-
- 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");
- *op_errstr = gf_strdup ("configure command "
- "failed, please check "
- "the log-file\n");
- goto out;
+ if (!ret) {
+ ret = glusterd_check_restart_gsync_session (volinfo, slave);
+ if (ret)
+ *op_errstr = gf_strdup ("internal error");
}
- 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");
- goto out;
- }
- ret = 0;
- *op_errstr = gf_strdup ("config-del successful");
-out:
+ gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
return ret;
}
@@ -4387,59 +4302,6 @@ glusterd_check_restart_gsync_session (glusterd_volinfo_t *volinfo, char *slave)
return ret;
}
-int
-glusterd_gsync_configure (glusterd_volinfo_t *volinfo, char *slave,
- dict_t *dict, char **op_errstr)
-{
- int32_t ret = -1;
- int32_t config_type = 0;
-
- GF_ASSERT (volinfo);
- GF_ASSERT (slave);
- GF_ASSERT (op_errstr);
-
- ret = dict_get_int32 (dict, "config_type", &config_type);
- if (ret < 0) {
- gf_log ("", GF_LOG_WARNING, "couldn't get the config-type"
- " for %s %s", volinfo->volname, slave);
- *op_errstr = gf_strdup ("configure command failed, "
- "please check the log-file\n");
- goto out;
- }
-
- if (config_type == GF_GSYNC_OPTION_TYPE_CONFIG_SET) {
- ret = gsync_config_set (volinfo->volname, slave, dict,
- op_errstr);
- if (ret)
- goto out;
- goto config_done;
- }
-
- if (config_type == GF_GSYNC_OPTION_TYPE_CONFIG_DEL) {
- ret = gsync_config_del (volinfo->volname, slave, dict,
- op_errstr);
- goto config_done;
- }
-
- if ((config_type == GF_GSYNC_OPTION_TYPE_CONFIG_GET_ALL) ||
- (config_type == GF_GSYNC_OPTION_TYPE_CONFIG_GET))
- goto out;
- else {
- gf_log ("", GF_LOG_WARNING, "Invalid config type");
- *op_errstr = gf_strdup ("Invalid config type");
- ret = -1;
- goto out;
- }
-
- config_done:
- ret = glusterd_check_restart_gsync_session (volinfo, slave);
- if (ret)
- *op_errstr = gf_strdup (GEOREP" conig: Internal error");
-out:
- gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
- return ret;
-}
-
int32_t
glusterd_marker_create_volfile (glusterd_volinfo_t *volinfo)
{
@@ -4724,7 +4586,7 @@ glusterd_op_gsync_set (dict_t *dict, char **op_errstr, dict_t *rsp_dict)
}
- if (type == GF_GSYNC_OPTION_TYPE_CONFIGURE) {
+ if (type == GF_GSYNC_OPTION_TYPE_CONFIG) {
ret = glusterd_gsync_configure (volinfo, slave, dict,
op_errstr);
goto out;
diff --git a/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c b/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c
index 3b5c3df6bd0..65ccec4d449 100644
--- a/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c
+++ b/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c
@@ -258,17 +258,19 @@ glusterd_op_send_cli_response (glusterd_op_t op, int32_t op_ret,
case GD_OP_GSYNC_SET:
{
int type = 0;
- int config_type = 0;
char *str = NULL;
char *master = NULL;
char *slave = NULL;
char *op_name = NULL;
+ char *subop = NULL;
gf1_cli_gsync_set_rsp rsp = {0,};
+
ctx = op_ctx;
rsp.op_ret = op_ret;
rsp.op_errno = op_errno;
rsp.op_errstr = "";
rsp.op_name = "";
+ rsp.subop = "";
rsp.master = "";
rsp.slave = "";
rsp.glusterd_workdir = conf->workdir;
@@ -280,10 +282,6 @@ glusterd_op_send_cli_response (glusterd_op_t op, int32_t op_ret,
ret = dict_get_int32 (ctx, "type", &type);
if (ret == 0)
rsp.type = type;
- ret = dict_get_int32 (ctx, "config_type",
- &config_type);
- if (ret == 0)
- rsp.config_type = config_type;
ret = dict_get_str (ctx, "master", &master);
if (ret == 0)
rsp.master = master;
@@ -292,10 +290,11 @@ glusterd_op_send_cli_response (glusterd_op_t op, int32_t op_ret,
if (ret == 0)
rsp.slave = slave;
- if (config_type == GF_GSYNC_OPTION_TYPE_CONFIG_GET) {
- ret = dict_get_str (ctx, "op_name", &op_name);
- if (ret == 0)
+ if (type == GF_GSYNC_OPTION_TYPE_CONFIG) {
+ if (dict_get_str (ctx, "op_name", &op_name) == 0)
rsp.op_name = op_name;
+ if (dict_get_str (ctx, "subop", &subop) == 0)
+ rsp.subop = subop;
}
ret = dict_allocate_and_serialize (ctx,