summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt
diff options
context:
space:
mode:
authorRaghavendra Bhat <raghavendrabhat@gluster.com>2011-12-15 22:16:13 +0530
committerVijay Bellur <vijay@gluster.com>2011-12-19 08:58:50 -0800
commit255fed3b0d5b9d210d1da47dbd647dd6497cd550 (patch)
tree9e29c433cc76dca8337e82088cfa2bf44ac68d48 /xlators/mgmt
parent4debbfe7f629626fd2e77a2d98f37f4e808e9f95 (diff)
cli: validate the volume set command properly
For volume set command if after the volume name the key and the value of the option are not given, then gracefully exit by showing the proper usage of volume set, instead of sending the request to glusterd, which makes glusterd crash. Signed-off-by: Raghavendra Bhat <raghavendrabhat@gluster.com> Change-Id: I2f0d189a55663c7f47dddff35d4dc68fae16b755 BUG: 767591 Signed-off-by: Raghavendra Bhat <raghavendrabhat@gluster.com> Reviewed-on: http://review.gluster.com/797 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Krishnan Parthasarathi <kp@gluster.com> Reviewed-by: Jeff Darcy <jdarcy@redhat.com>
Diffstat (limited to 'xlators/mgmt')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-handler.c2
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-rpc-ops.c108
2 files changed, 51 insertions, 59 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
index a331bfbb2f5..664798ca376 100644
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
@@ -989,7 +989,7 @@ glusterd_handle_set_volume (rpcsvc_request_t *req)
ret = dict_get_str (dict, "key1", &key);
if (ret) {
if (strcmp (volname, "help-xml") && strcmp (volname, "help")) {
- gf_log ("", GF_LOG_WARNING, "Unable to get key, while"
+ gf_log ("", GF_LOG_WARNING, "Unable to get key, while "
"handling volume set for %s",volname);
goto out;
}
diff --git a/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c b/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c
index 22d1bffcfae..a4dd7e25c6c 100644
--- a/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c
+++ b/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c
@@ -57,8 +57,8 @@ glusterd_op_send_cli_response (glusterd_op_t op, int32_t op_ret,
xdrproc_t xdrproc = NULL;
char *errstr = NULL;
int32_t status = 0;
- int32_t is_ctx_dict = 0;
int32_t count = 0;
+ gf_cli_rsp rsp = {0,};
GF_ASSERT (THIS);
@@ -73,14 +73,13 @@ glusterd_op_send_cli_response (glusterd_op_t op, int32_t op_ret,
{
if (ctx)
ret = dict_get_str (ctx, "errstr", &errstr);
- is_ctx_dict = 1;
- goto done;
+ break;
}
case GD_OP_RESET_VOLUME:
{
if (op_ret && !op_errstr)
errstr = "Error while resetting options";
- goto done;
+ break;
}
case GD_OP_REBALANCE:
{
@@ -90,9 +89,8 @@ glusterd_op_send_cli_response (glusterd_op_t op, int32_t op_ret,
gf_log (THIS->name, GF_LOG_TRACE,
"failed to get status");
}
- is_ctx_dict = 1;
}
- goto done;
+ break;
}
case GD_OP_GSYNC_SET:
{
@@ -101,9 +99,8 @@ glusterd_op_send_cli_response (glusterd_op_t op, int32_t op_ret,
ret = dict_set_str (ctx, "glusterd_workdir", conf->workdir);
/* swallow error here, that will be re-triggered in cli */
- is_ctx_dict = 1;
- goto done;
}
+ break;
}
case GD_OP_QUOTA:
@@ -111,23 +108,30 @@ glusterd_op_send_cli_response (glusterd_op_t op, int32_t op_ret,
if (ctx && !op_errstr) {
ret = dict_get_str (ctx, "errstr", &errstr);
}
- is_ctx_dict = 1;
- goto done;
+ break;
}
- case GD_OP_REPLACE_BRICK:
- case GD_OP_STATUS_VOLUME:
- case GD_OP_SET_VOLUME:
case GD_OP_PROFILE_VOLUME:
{
- if (dict_get_int32 (ctx, "count", &count)) {
+ if (ctx && dict_get_int32 (ctx, "count", &count)) {
ret = dict_set_int32 (ctx, "count", 0);
if (ret) {
gf_log (THIS->name, GF_LOG_ERROR,
- "Failed to set brick count");
- break;
+ "failed to set count in dictionary");
}
}
- is_ctx_dict = 1;
+ break;
+ }
+ case GD_OP_START_BRICK:
+ case GD_OP_STOP_BRICK:
+ {
+ gf_log ("", GF_LOG_DEBUG, "not supported op %d", op);
+ break;
+ }
+ case GD_OP_NONE:
+ case GD_OP_MAX:
+ {
+ gf_log ("", GF_LOG_ERROR, "invalid operation %d", op);
+ break;
}
case GD_OP_CREATE_VOLUME:
case GD_OP_START_VOLUME:
@@ -139,54 +143,42 @@ glusterd_op_send_cli_response (glusterd_op_t op, int32_t op_ret,
case GD_OP_SYNC_VOLUME:
case GD_OP_HEAL_VOLUME:
case GD_OP_STATEDUMP_VOLUME:
-
-done:
+ case GD_OP_REPLACE_BRICK:
+ case GD_OP_STATUS_VOLUME:
+ case GD_OP_SET_VOLUME:
{
- gf_cli_rsp rsp = {0,};
- rsp.op_ret = op_ret;
- rsp.op_errno = errno;
- if (errstr)
- rsp.op_errstr = errstr;
- else if (op_errstr)
- rsp.op_errstr = op_errstr;
-
- if (!rsp.op_errstr)
- rsp.op_errstr = "";
-
- if (ctx && is_ctx_dict) {
- ret = dict_allocate_and_serialize (ctx, &rsp.dict.dict_val,
- (size_t*)&rsp.dict.dict_len);
- if (ret < 0 ) {
- gf_log (THIS->name, GF_LOG_ERROR, "failed to "
- "serialize buffer");
- break;
- }
- free_ptr = rsp.dict.dict_val;
- }
- /* needed by 'rebalance status' */
- if (status)
- rsp.op_errno = status;
-
- cli_rsp = &rsp;
- xdrproc = (xdrproc_t) xdr_gf_cli_rsp;
+ /*nothing specific to be done*/
break;
}
-
- case GD_OP_START_BRICK:
- case GD_OP_STOP_BRICK:
- {
- gf_log ("", GF_LOG_DEBUG, "not supported op %d", op);
- break;
}
- case GD_OP_NONE:
- case GD_OP_MAX:
- {
- gf_log ("", GF_LOG_ERROR, "invalid operation %d", op);
- break;
- }
+ rsp.op_ret = op_ret;
+ rsp.op_errno = errno;
+ if (errstr)
+ rsp.op_errstr = errstr;
+ else if (op_errstr)
+ rsp.op_errstr = op_errstr;
+
+ if (!rsp.op_errstr)
+ rsp.op_errstr = "";
+
+ if (ctx) {
+ ret = dict_allocate_and_serialize (ctx, &rsp.dict.dict_val,
+ (size_t*)&rsp.dict.dict_len);
+ if (ret < 0 )
+ gf_log (THIS->name, GF_LOG_ERROR, "failed to "
+ "serialize buffer");
+ else
+ free_ptr = rsp.dict.dict_val;
}
+ /* needed by 'rebalance status' */
+ if (status)
+ rsp.op_errno = status;
+
+ cli_rsp = &rsp;
+ xdrproc = (xdrproc_t) xdr_gf_cli_rsp;
+
ret = glusterd_submit_reply (req, cli_rsp, NULL, 0, NULL,
xdrproc);