summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamikshan Bairagya <samikshan@gmail.com>2016-03-29 16:24:07 +0530
committerAtin Mukherjee <amukherj@redhat.com>2016-06-21 00:11:06 -0700
commita6e551122c603ab0cba798e7e2b30d3a15191b68 (patch)
tree270790caeac909da89ea9753c2048b7efb2c9ae4
parent4797ca3778d82a671716d4913c14f285591ae959 (diff)
Fix opRet value for volume info --xml call on non-existent volume
The opRet field was being assigned to 0 in the XML output when a gluster volume info --xml call is made on a non-existent volume. This change assigns a value of -1 to opRet for volume info calls for non-existent volumes. Other fields like opErrno and opErrstr are also assigned relevant values Change-Id: I3920c602328f74252c87bb521f5a43d4bdc7d44d BUG: 1321836 Signed-off-by: Samikshan Bairagya <samikshan@gmail.com> Reviewed-on: http://review.gluster.org/13843 Smoke: Gluster Build System <jenkins@build.gluster.org> CentOS-regression: Gluster Build System <jenkins@build.gluster.org> Reviewed-by: darshan n <dnarayan@redhat.com> Reviewed-by: Atin Mukherjee <amukherj@redhat.com> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
-rw-r--r--cli/src/cli-rpc-ops.c12
-rw-r--r--tests/bugs/glusterd/bug-1321836-fix-opret-for-volume-info-xml-output.t24
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-handler.c23
3 files changed, 47 insertions, 12 deletions
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c
index 12776065128..de3a382869d 100644
--- a/cli/src/cli-rpc-ops.c
+++ b/cli/src/cli-rpc-ops.c
@@ -815,11 +815,6 @@ gf_cli_get_volume_cbk (struct rpc_req *req, struct iovec *iov,
gf_log ("cli", GF_LOG_INFO, "Received resp to get vol: %d",
rsp.op_ret);
- if (rsp.op_ret) {
- ret = -1;
- goto out;
- }
-
if (!rsp.dict.dict_len) {
if (global_state->mode & GLUSTER_MODE_XML)
goto xml_output;
@@ -869,6 +864,13 @@ gf_cli_get_volume_cbk (struct rpc_req *req, struct iovec *iov,
}
}
+ if (rsp.op_ret) {
+ if (global_state->mode & GLUSTER_MODE_XML)
+ goto xml_output;
+ ret = -1;
+ goto out;
+ }
+
xml_output:
if (global_state->mode & GLUSTER_MODE_XML) {
/* For GET_NEXT_VOLUME output is already begun in
diff --git a/tests/bugs/glusterd/bug-1321836-fix-opret-for-volume-info-xml-output.t b/tests/bugs/glusterd/bug-1321836-fix-opret-for-volume-info-xml-output.t
new file mode 100644
index 00000000000..48fccc621d8
--- /dev/null
+++ b/tests/bugs/glusterd/bug-1321836-fix-opret-for-volume-info-xml-output.t
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+. $(dirname $0)/../../include.rc
+. $(dirname $0)/../../cluster.rc
+
+## Check that opRet field has correct value assigned for non existent volumes
+## --------------------------------------------------------------------------
+
+function get_opret_value () {
+ local VOL=$1
+ $CLI volume info $VOL --xml | sed -ne 's/.*<opRet>\([-0-9]*\)<\/opRet>/\1/p'
+}
+
+cleanup;
+
+TEST glusterd;
+TEST pidof glusterd
+
+TEST $CLI volume create $V0 $H0:$B0/$V0;
+
+EXPECT 0 get_opret_value $V0
+EXPECT -1 get_opret_value "novol"
+
+cleanup;
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
index c7ffd818a44..91ae6237c54 100644
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
@@ -40,6 +40,7 @@
#include "glusterd-volgen.h"
#include "glusterd-mountbroker.h"
#include "glusterd-messages.h"
+#include "glusterd-errno.h"
#include <sys/resource.h>
#include <inttypes.h>
@@ -1554,7 +1555,6 @@ __glusterd_handle_cli_get_volume (rpcsvc_request_t *req)
GD_MSG_FLAGS_NOTFOUND_IN_DICT, "failed to get flags");
goto out;
}
-
ret = glusterd_get_volumes (req, dict, flags);
out:
@@ -4167,6 +4167,7 @@ int32_t
glusterd_get_volumes (rpcsvc_request_t *req, dict_t *dict, int32_t flags)
{
int32_t ret = -1;
+ int32_t ret_bkp = 0;
glusterd_conf_t *priv = NULL;
glusterd_volinfo_t *entry = NULL;
int32_t count = 0;
@@ -4176,7 +4177,6 @@ glusterd_get_volumes (rpcsvc_request_t *req, dict_t *dict, int32_t flags)
priv = THIS->private;
GF_ASSERT (priv);
-
volumes = dict_new ();
if (!volumes) {
gf_msg ("glusterd", GF_LOG_ERROR, ENOMEM,
@@ -4185,10 +4185,11 @@ glusterd_get_volumes (rpcsvc_request_t *req, dict_t *dict, int32_t flags)
}
if (cds_list_empty (&priv->volumes)) {
+ if (flags == GF_CLI_GET_VOLUME)
+ ret_bkp = -1;
ret = 0;
goto respond;
}
-
if (flags == GF_CLI_GET_VOLUME_ALL) {
cds_list_for_each_entry (entry, &priv->volumes, vol_list) {
ret = glusterd_add_volume_detail_to_dict (entry,
@@ -4230,12 +4231,15 @@ glusterd_get_volumes (rpcsvc_request_t *req, dict_t *dict, int32_t flags)
}
} else if (flags == GF_CLI_GET_VOLUME) {
ret = dict_get_str (dict, "volname", &volname);
+
if (ret)
goto respond;
ret = glusterd_volinfo_find (volname, &entry);
- if (ret)
+ if (ret) {
+ ret_bkp = ret;
goto respond;
+ }
ret = glusterd_add_volume_detail_to_dict (entry,
volumes, count);
@@ -4257,9 +4261,14 @@ respond:
ret = 0;
out:
- rsp.op_ret = ret;
-
- rsp.op_errstr = "";
+ if (ret_bkp == -1) {
+ rsp.op_ret = ret_bkp;
+ rsp.op_errstr = "Volume does not exist";
+ rsp.op_errno = EG_NOVOL;
+ } else {
+ rsp.op_ret = ret;
+ rsp.op_errstr = "";
+ }
glusterd_submit_reply (req, &rsp, NULL, 0, NULL,
(xdrproc_t)xdr_gf_cli_rsp);
ret = 0;