summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt
diff options
context:
space:
mode:
authorKaushik BV <kaushikbv@gluster.com>2010-10-05 07:01:52 +0000
committerVijay Bellur <vijay@dev.gluster.com>2010-10-05 05:47:33 -0700
commit7aec50bdad06665243a16f1ce83a03037bcd5d56 (patch)
tree7b034228b529e7bd8abe318e2f3d6609f4679ccb /xlators/mgmt
parent79db3aced2ffca84a696192343d5b811833eb671 (diff)
mgmt/Glusterd : Reply to CLI error: graph construction
Signed-off-by: Kaushik BV <kaushikbv@gluster.com> Signed-off-by: Vijay Bellur <vijay@dev.gluster.com> BUG: 1159 () URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1159
Diffstat (limited to 'xlators/mgmt')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-handler.c2
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-op-sm.c129
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-volgen.c97
-rw-r--r--xlators/mgmt/glusterd/src/glusterd.h3
4 files changed, 205 insertions, 26 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
index ee547639e0b..c337655857f 100644
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
@@ -2760,6 +2760,8 @@ glusterd_set_volume_history (rpcsvc_request_t *req,dict_t *dict)
rsp.op_ret = ret;
if (!rsp.volname)
rsp.volname = "";
+ if (!rsp.op_errstr)
+ rsp.op_errstr = "";
ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,
gf_xdr_serialize_cli_set_vol_rsp);
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
index 26e23e9fc62..7eb83a2d338 100644
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
@@ -1042,22 +1042,32 @@ out:
}
static int
-glusterd_op_stage_set_volume (gd1_mgmt_stage_op_req *req)
+glusterd_op_stage_set_volume (gd1_mgmt_stage_op_req *req, char **op_errstr)
{
- int ret = 0;
- dict_t *dict = NULL;
- char *volname = NULL;
- int exists = 0;
- char *key = NULL;
- char str[100] = {0, };
- int count = 0;
-
- GF_ASSERT (req);
-
- dict = dict_new ();
- if (!dict)
+ int ret = 0;
+ dict_t *dict = NULL;
+ char *volname = NULL;
+ gf_boolean_t exists = _gf_false;
+ char *key = NULL;
+ char *value = NULL;
+ char str[100] = {0, };
+ int count = 0;
+ int dict_count = 0;
+ char errstr[2048] = {0, };
+ glusterd_volinfo_t *volinfo = NULL;
+ dict_t *val_dict = NULL;
+
+ GF_ASSERT (req);
+
+ dict = dict_new ();
+ if (!dict)
+ goto out;
+
+ val_dict = dict_new();
+ if (!val_dict)
goto out;
-
+
+ ret = dict_unserialize (req->buf.buf_val, req->buf.buf_len, &dict);
ret = dict_unserialize (req->buf.buf_val, req->buf.buf_len, &dict);
if (ret) {
@@ -1076,11 +1086,38 @@ glusterd_op_stage_set_volume (gd1_mgmt_stage_op_req *req)
if (!exists) {
gf_log ("", GF_LOG_ERROR, "Volume with name: %s "
- "does not exist",
- volname);
+ "does not exist", volname);
+ snprintf (errstr, 2048, "Volume : %s does not exist",
+ key);
+ *op_errstr = gf_strdup (errstr);
ret = -1;
goto out;
}
+
+ ret = glusterd_volinfo_find (volname, &volinfo);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Unable to allocate memory");
+ goto out;
+ }
+
+ ret = dict_get_int32 (dict, "count", &dict_count);
+
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Count(dict),not set in Volume-Set");
+ goto out;
+ }
+
+ if ( dict_count == 1 ) {
+ if (dict_get (dict, "history" )) {
+ ret = 0;
+ goto out;
+ }
+
+ gf_log ("", GF_LOG_ERROR, "No options received ");
+ ret = -1;
+ goto out;
+ }
+
for ( count = 1; ret != -1 ; count++ ) {
@@ -1097,27 +1134,63 @@ glusterd_op_stage_set_volume (gd1_mgmt_stage_op_req *req)
if (exists != 1) {
gf_log ("", GF_LOG_ERROR, "Option with name: %s "
"does not exist", key);
+ snprintf (errstr, 2048, "option : %s does not exist",
+ key);
+ *op_errstr = gf_strdup (errstr);
+
ret = -1;
goto out;
}
+
+ sprintf (str, "value%d", count);
+ ret = dict_get_str (dict, str, &value);
+
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "invalid key,value pair"
+ "in 'volume set'");
+ ret = -1;
+ goto out;
+ }
+
+ ret = dict_set_str (val_dict, key, value);
+
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Unable to set the options"
+ "in 'volume set'");
+ ret = -1;
+ goto out;
+ }
}
- if ( count == 1 ) {
- gf_log ("", GF_LOG_ERROR, "No options received ");
- ret = -1;
- goto out;
- }
+ *op_errstr = NULL;
+ ret = glusterd_validate_reconfopts (volinfo, val_dict, op_errstr);
+ if (ret) {
+ gf_log ("glsuterd", GF_LOG_DEBUG,
+ "Could not create temp volfile, some option failed: %s",
+ *op_errstr);
+ goto out;
+ }
+
ret = 0;
out:
- if (dict)
+ if (dict)
dict_unref (dict);
- gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
-
- return ret;
+ if (ret) {
+ if (!(*op_errstr)) {
+ *op_errstr = gf_strdup ("Error, Validation Failed");
+ gf_log ("glsuterd", GF_LOG_DEBUG,
+ "Error, Cannot Validate option :%s",
+ *op_errstr);
+ }
+ else
+ gf_log ("glsuterd", GF_LOG_DEBUG,
+ "Error, Cannot Validate option");
+ }
+ return ret;
}
static int
@@ -4228,6 +4301,10 @@ glusterd_op_send_cli_response (int32_t op, int32_t op_ret,
rsp.op_ret = op_ret;
rsp.op_errno = op_errno;
rsp.volname = "";
+ if (op_errstr)
+ rsp.op_errstr = op_errstr;
+ else
+ rsp.op_errstr = "";
cli_rsp = &rsp;
sfunc = gf_xdr_serialize_cli_set_vol_rsp;
break;
@@ -4528,7 +4605,7 @@ glusterd_op_stage_validate (gd1_mgmt_stage_op_req *req, char **op_errstr)
break;
case GD_OP_SET_VOLUME:
- ret = glusterd_op_stage_set_volume (req);
+ ret = glusterd_op_stage_set_volume (req, op_errstr);
break;
case GD_OP_RESET_VOLUME:
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c
index 1b01e10eb0d..9d3ceaf5659 100644
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.c
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c
@@ -1254,3 +1254,100 @@ glusterd_delete_volfile (glusterd_volinfo_t *volinfo,
get_brick_filepath (filename, volinfo, brickinfo);
return unlink (filename);
}
+
+int
+validate_clientopts (glusterd_volinfo_t *volinfo,
+ dict_t *val_dict,
+ char **op_errstr)
+{
+ glusterfs_graph_t graph = {{0,},};
+ int ret = -1;
+
+ GF_ASSERT (volinfo);
+
+
+ ret = build_client_graph (&graph, volinfo, val_dict);
+ if (!ret)
+ ret = graph_reconf_validateopt (&graph, op_errstr);
+
+ volgen_graph_free (&graph);
+
+ gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
+ return ret;
+}
+
+int
+validate_brickopts (glusterd_volinfo_t *volinfo,
+ char *brickinfo_path,
+ dict_t *val_dict,
+ char **op_errstr)
+{
+ glusterfs_graph_t graph = {{0,},};
+ int ret = -1;
+
+ GF_ASSERT (volinfo);
+
+
+
+ ret = build_server_graph (&graph, volinfo, val_dict, brickinfo_path);
+ if (!ret)
+ ret = graph_reconf_validateopt (&graph, op_errstr);
+
+ volgen_graph_free (&graph);
+
+ gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
+ return ret;
+}
+
+int
+glusterd_validate_brickreconf (glusterd_volinfo_t *volinfo,
+ dict_t *val_dict,
+ char **op_errstr)
+{
+ glusterd_brickinfo_t *brickinfo = NULL;
+ int ret = -1;
+
+ list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) {
+ gf_log ("", GF_LOG_DEBUG,
+ "Validating %s", brickinfo->hostname);
+
+ ret = validate_brickopts (volinfo, brickinfo->path, val_dict,
+ op_errstr);
+ if (ret)
+ goto out;
+ }
+
+ ret = 0;
+out:
+
+ return ret;
+}
+
+int
+glusterd_validate_reconfopts (glusterd_volinfo_t *volinfo, dict_t *val_dict,
+ char **op_errstr)
+{
+ int ret = -1;
+
+ gf_log ("", GF_LOG_DEBUG, "Inside Validate reconfigure options");
+
+ ret = glusterd_validate_brickreconf (volinfo, val_dict, op_errstr);
+
+ if (ret) {
+ gf_log ("", GF_LOG_DEBUG,
+ "Could not Validate bricks");
+ goto out;
+ }
+
+ ret = validate_clientopts (volinfo, val_dict, op_errstr);
+ if (ret) {
+ gf_log ("", GF_LOG_DEBUG,
+ "Could not Validate client");
+ goto out;
+ }
+
+
+out:
+ gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
+ return ret;
+} \ No newline at end of file
diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h
index e1cbc3583d1..ac983760130 100644
--- a/xlators/mgmt/glusterd/src/glusterd.h
+++ b/xlators/mgmt/glusterd/src/glusterd.h
@@ -446,4 +446,7 @@ glusterd_restart_bricks(glusterd_conf_t *conf);
int32_t
glusterd_volume_txn (rpcsvc_request_t *req, char *volname, int flags,
glusterd_op_t op);
+
+int
+glusterd_validate_reconfopts (glusterd_volinfo_t *volinfo, dict_t *val_dict, char **op_errstr);
#endif