Blob Blame History Raw
From 54ea9d74c5459e93608b16c7d3f762b1bc4096f3 Mon Sep 17 00:00:00 2001
From: Avra Sengupta <asengupt@redhat.com>
Date: Tue, 5 May 2015 18:08:25 +0530
Subject: [PATCH 22/57] glusterd/snapshot: Return correct errno in events of failure - PATCH 2

       Backport of http://review.gluster.org/#/c/10588/

ENUM           RETCODE        ERROR
-------------------------------------------------------------
EG_INTRNL      30800          Internal Error
EG_OPNOTSUP    30801          Gluster Op Not Supported
EG_ANOTRANS    30802          Another Transaction in Progress
EG_BRCKDWN     30803          One or more brick is down
EG_NODEDWN     30804          One or more node is down
EG_HRDLMT      30805          Hard Limit is reached
EG_NOVOL       30806          Volume does not exist
EG_NOSNAP      30807          Snap does not exist
EG_RBALRUN     30808          Rebalance is running
EG_VOLRUN      30809          Volume is running
EG_VOLSTP      30810          Volume is not running
EG_VOLEXST     30811          Volume exists
EG_SNAPEXST    30812          Snapshot exists
EG_ISSNAP      30813          Volume is a snap volume
EG_GEOREPRUN   30814          Geo-Replication is running
EG_NOTTHINP    30815          Bricks are not thinly provisioned

Change-Id: I49a170cdfd77df11fe677e09f4e063d99b159275
BUG: 1186216
Signed-off-by: Avra Sengupta <asengupt@redhat.com>
(cherry picked from commit 2df57ab7dc7b9d7deb0eebad96036149760d607b)
Reviewed-on: https://code.engineering.redhat.com/gerrit/50359
Reviewed-by: Rajesh Joseph <rjoseph@redhat.com>
Tested-by: Rajesh Joseph <rjoseph@redhat.com>
---
 tests/basic/op_errnos.t                            |   38 +++++
 xlators/mgmt/glusterd/src/glusterd-errno.h         |   18 ++-
 xlators/mgmt/glusterd/src/glusterd-locks.c         |    2 +-
 xlators/mgmt/glusterd/src/glusterd-mgmt-handler.c  |   29 ++--
 xlators/mgmt/glusterd/src/glusterd-mgmt.c          |   48 ++++--
 xlators/mgmt/glusterd/src/glusterd-mgmt.h          |    6 +-
 .../mgmt/glusterd/src/glusterd-snapshot-utils.c    |   31 +++-
 .../mgmt/glusterd/src/glusterd-snapshot-utils.h    |    6 +-
 xlators/mgmt/glusterd/src/glusterd-snapshot.c      |  176 +++++++++++++++-----
 xlators/mgmt/glusterd/src/glusterd-syncop.c        |    5 +-
 xlators/mgmt/glusterd/src/glusterd.h               |    5 +-
 11 files changed, 272 insertions(+), 92 deletions(-)
 create mode 100755 tests/basic/op_errnos.t

diff --git a/tests/basic/op_errnos.t b/tests/basic/op_errnos.t
new file mode 100755
index 0000000..8b16267
--- /dev/null
+++ b/tests/basic/op_errnos.t
@@ -0,0 +1,38 @@
+#!/bin/bash
+
+. $(dirname $0)/../include.rc
+. $(dirname $0)/../snapshot.rc
+
+function get-op_errno-xml()
+{
+        $CLI $1 --xml | xmllint --format - | grep opErrno | sed 's/\(<opErrno>\|<\/opErrno>\)//g'
+}
+
+cleanup;
+TEST verify_lvm_version;
+TEST glusterd;
+TEST pidof glusterd;
+
+TEST setup_lvm 1
+
+TEST $CLI volume create $V0 $H0:$L1
+TEST $CLI volume start $V0
+TEST $CLI volume create $V1 replica 2 stripe 2 $H0:$B0/${V0}{1,2,3,4,5,6,7,8};
+TEST $CLI volume start $V1
+
+EXPECT 0 get-op_errno-xml "snapshot create snap1 $V0 no-timestamp"
+EXPECT 30806 get-op_errno-xml "snapshot create snap1 imaginary_volume"
+EXPECT 30807 get-op_errno-xml "snapshot delete imaginary_snap"
+EXPECT 30809 get-op_errno-xml "snapshot restore snap1"
+TEST $CLI volume stop $V0
+EXPECT 30810 get-op_errno-xml "snapshot create snap1 $V0"
+TEST $CLI volume start $V0
+EXPECT 30811 get-op_errno-xml "snapshot clone $V0 snap1"
+EXPECT 30812 get-op_errno-xml "snapshot create snap1 $V0 no-timestamp"
+EXPECT 30815 get-op_errno-xml "snapshot create snap2 $V1 no-timestamp"
+
+EXPECT 0 get-op_errno-xml "snapshot delete snap1"
+TEST $CLI volume stop $V0
+TEST $CLI volume stop $V1
+
+cleanup;
diff --git a/xlators/mgmt/glusterd/src/glusterd-errno.h b/xlators/mgmt/glusterd/src/glusterd-errno.h
index 435b050..55d44a5 100644
--- a/xlators/mgmt/glusterd/src/glusterd-errno.h
+++ b/xlators/mgmt/glusterd/src/glusterd-errno.h
@@ -11,8 +11,22 @@
 #define _GLUSTERD_ERRNO_H
 
 enum glusterd_op_errno {
-        EINTRNL   = 30800,               /* Internal Error */
-        EANOTRANS = 30801,               /* Another Transaction in Progress */
+        EG_INTRNL      = 30800,          /* Internal Error                    */
+        EG_OPNOTSUP    = 30801,          /* Gluster Op Not Supported          */
+        EG_ANOTRANS    = 30802,          /* Another Transaction in Progress   */
+        EG_BRCKDWN     = 30803,          /* One or more brick is down         */
+        EG_NODEDWN     = 30804,          /* One or more node is down          */
+        EG_HRDLMT      = 30805,          /* Hard Limit is reached             */
+        EG_NOVOL       = 30806,          /* Volume does not exist             */
+        EG_NOSNAP      = 30807,          /* Snap does not exist               */
+        EG_RBALRUN     = 30808,          /* Rebalance is running              */
+        EG_VOLRUN      = 30809,          /* Volume is running                 */
+        EG_VOLSTP      = 30810,          /* Volume is not running             */
+        EG_VOLEXST     = 30811,          /* Volume exists                     */
+        EG_SNAPEXST    = 30812,          /* Snapshot exists                   */
+        EG_ISSNAP      = 30813,          /* Volume is a snap volume           */
+        EG_GEOREPRUN   = 30814,          /* Geo-Replication is running        */
+        EG_NOTTHINP    = 30815,          /* Bricks are not thinly provisioned */
 };
 
 #endif
diff --git a/xlators/mgmt/glusterd/src/glusterd-locks.c b/xlators/mgmt/glusterd/src/glusterd-locks.c
index 0f9c2b2..bafdc53 100644
--- a/xlators/mgmt/glusterd/src/glusterd-locks.c
+++ b/xlators/mgmt/glusterd/src/glusterd-locks.c
@@ -554,7 +554,7 @@ glusterd_mgmt_v3_lock (const char *name, uuid_t uuid, uint32_t *op_errno,
                                   "Lock for %s held by %s",
                                   name, uuid_utoa (owner));
                 ret = -1;
-                *op_errno = EANOTRANS;
+                *op_errno = EG_ANOTRANS;
                 goto out;
         }
 
diff --git a/xlators/mgmt/glusterd/src/glusterd-mgmt-handler.c b/xlators/mgmt/glusterd/src/glusterd-mgmt-handler.c
index 9ebaf00..5b7f0fa 100644
--- a/xlators/mgmt/glusterd/src/glusterd-mgmt-handler.c
+++ b/xlators/mgmt/glusterd/src/glusterd-mgmt-handler.c
@@ -232,8 +232,9 @@ out:
 
 static int
 glusterd_mgmt_v3_pre_validate_send_resp (rpcsvc_request_t   *req,
-                                        int32_t op, int32_t status,
-                                        char *op_errstr, dict_t *rsp_dict)
+                                         int32_t op, int32_t status,
+                                         char *op_errstr, dict_t *rsp_dict,
+                                         uint32_t op_errno)
 {
         gd1_mgmt_v3_pre_val_rsp          rsp      = {{0},};
         int                             ret      = -1;
@@ -246,6 +247,7 @@ glusterd_mgmt_v3_pre_validate_send_resp (rpcsvc_request_t   *req,
         rsp.op_ret = status;
         glusterd_get_uuid (&rsp.uuid);
         rsp.op = op;
+        rsp.op_errno = op_errno;
         if (op_errstr)
                 rsp.op_errstr = op_errstr;
         else
@@ -274,11 +276,12 @@ static int
 glusterd_handle_pre_validate_fn (rpcsvc_request_t *req)
 {
         int32_t                         ret       = -1;
-        gd1_mgmt_v3_pre_val_req          op_req    = {{0},};
+        gd1_mgmt_v3_pre_val_req         op_req    = {{0},};
         xlator_t                       *this      = NULL;
         char                           *op_errstr = NULL;
         dict_t                         *dict      = NULL;
         dict_t                         *rsp_dict  = NULL;
+        uint32_t                        op_errno  = 0;
 
         this = THIS;
         GF_ASSERT (this);
@@ -326,8 +329,7 @@ glusterd_handle_pre_validate_fn (rpcsvc_request_t *req)
         }
 
         ret = gd_mgmt_v3_pre_validate_fn (op_req.op, dict, &op_errstr,
-                                         rsp_dict);
-
+                                          rsp_dict, &op_errno);
         if (ret) {
                 gf_msg (this->name, GF_LOG_ERROR, 0,
                         GD_MSG_PRE_VALIDATION_FAIL,
@@ -336,8 +338,8 @@ glusterd_handle_pre_validate_fn (rpcsvc_request_t *req)
         }
 
         ret = glusterd_mgmt_v3_pre_validate_send_resp (req, op_req.op,
-                                                      ret, op_errstr,
-                                                      rsp_dict);
+                                                       ret, op_errstr,
+                                                       rsp_dict, op_errno);
         if (ret) {
                 gf_msg (this->name, GF_LOG_ERROR, 0,
                         GD_MSG_MGMTV3_OP_RESP_FAIL,
@@ -497,8 +499,9 @@ out:
 
 static int
 glusterd_mgmt_v3_commit_send_resp (rpcsvc_request_t   *req,
-                                  int32_t op, int32_t status,
-                                  char *op_errstr, dict_t *rsp_dict)
+                                   int32_t op, int32_t status,
+                                   char *op_errstr, uint32_t op_errno,
+                                   dict_t *rsp_dict)
 {
         gd1_mgmt_v3_commit_rsp           rsp      = {{0},};
         int                             ret      = -1;
@@ -511,6 +514,7 @@ glusterd_mgmt_v3_commit_send_resp (rpcsvc_request_t   *req,
         rsp.op_ret = status;
         glusterd_get_uuid (&rsp.uuid);
         rsp.op = op;
+        rsp.op_errno = op_errno;
         if (op_errstr)
                 rsp.op_errstr = op_errstr;
         else
@@ -543,6 +547,7 @@ glusterd_handle_commit_fn (rpcsvc_request_t *req)
         char                           *op_errstr = NULL;
         dict_t                         *dict      = NULL;
         dict_t                         *rsp_dict  = NULL;
+        uint32_t                        op_errno  = 0;
 
         this = THIS;
         GF_ASSERT (this);
@@ -589,7 +594,7 @@ glusterd_handle_commit_fn (rpcsvc_request_t *req)
         }
 
         ret = gd_mgmt_v3_commit_fn (op_req.op, dict, &op_errstr,
-                                   rsp_dict);
+                                    &op_errno, rsp_dict);
 
         if (ret) {
                 gf_msg (this->name, GF_LOG_ERROR, 0,
@@ -599,8 +604,8 @@ glusterd_handle_commit_fn (rpcsvc_request_t *req)
         }
 
         ret = glusterd_mgmt_v3_commit_send_resp (req, op_req.op,
-                                                ret, op_errstr,
-                                                rsp_dict);
+                                                 ret, op_errstr,
+                                                 op_errno, rsp_dict);
         if (ret) {
                 gf_msg (this->name, GF_LOG_ERROR, 0,
                         GD_MSG_MGMTV3_OP_RESP_FAIL,
diff --git a/xlators/mgmt/glusterd/src/glusterd-mgmt.c b/xlators/mgmt/glusterd/src/glusterd-mgmt.c
index 954ff03..f8e65ac 100644
--- a/xlators/mgmt/glusterd/src/glusterd-mgmt.c
+++ b/xlators/mgmt/glusterd/src/glusterd-mgmt.c
@@ -144,7 +144,8 @@ gd_mgmt_v3_collate_errors (struct syncargs *args, int op_ret, int op_errno,
 
 int32_t
 gd_mgmt_v3_pre_validate_fn (glusterd_op_t op, dict_t *dict,
-                            char **op_errstr, dict_t *rsp_dict)
+                            char **op_errstr, dict_t *rsp_dict,
+                            uint32_t *op_errno)
 {
         int32_t       ret = -1;
         xlator_t     *this = NULL;
@@ -154,11 +155,12 @@ gd_mgmt_v3_pre_validate_fn (glusterd_op_t op, dict_t *dict,
         GF_ASSERT (dict);
         GF_ASSERT (op_errstr);
         GF_ASSERT (rsp_dict);
+        GF_VALIDATE_OR_GOTO (this->name, op_errno, out);
 
         switch (op) {
         case GD_OP_SNAP:
                 ret = glusterd_snapshot_prevalidate (dict, op_errstr,
-                                                     rsp_dict);
+                                                     rsp_dict, op_errno);
 
                 if (ret) {
                         gf_msg (this->name, GF_LOG_WARNING, 0,
@@ -216,7 +218,8 @@ out:
 
 int32_t
 gd_mgmt_v3_commit_fn (glusterd_op_t op, dict_t *dict,
-                      char **op_errstr, dict_t *rsp_dict)
+                      char **op_errstr, uint32_t *op_errno,
+                      dict_t *rsp_dict)
 {
         int32_t       ret = -1;
         xlator_t     *this = NULL;
@@ -225,12 +228,14 @@ gd_mgmt_v3_commit_fn (glusterd_op_t op, dict_t *dict,
         GF_ASSERT (this);
         GF_ASSERT (dict);
         GF_ASSERT (op_errstr);
+        GF_VALIDATE_OR_GOTO (this->name, op_errno, out);
         GF_ASSERT (rsp_dict);
 
         switch (op) {
                case GD_OP_SNAP:
                {
-                       ret = glusterd_snapshot (dict, op_errstr, rsp_dict);
+                       ret = glusterd_snapshot (dict, op_errstr,
+                                                op_errno, rsp_dict);
                        if (ret) {
                                 gf_msg (this->name, GF_LOG_WARNING, 0,
                                                GD_MSG_COMMIT_OP_FAIL,
@@ -683,7 +688,7 @@ out:
 
 int
 glusterd_mgmt_v3_pre_validate (glusterd_op_t op, dict_t *req_dict,
-                               char **op_errstr,
+                               char **op_errstr, uint32_t *op_errno,
                                uint32_t txn_generation)
 {
         int32_t              ret        = -1;
@@ -702,6 +707,7 @@ glusterd_mgmt_v3_pre_validate (glusterd_op_t op, dict_t *req_dict,
 
         GF_ASSERT (req_dict);
         GF_ASSERT (op_errstr);
+        GF_VALIDATE_OR_GOTO (this->name, op_errno, out);
 
         rsp_dict = dict_new ();
         if (!rsp_dict) {
@@ -713,7 +719,7 @@ glusterd_mgmt_v3_pre_validate (glusterd_op_t op, dict_t *req_dict,
 
         /* Pre Validation on local node */
         ret = gd_mgmt_v3_pre_validate_fn (op, req_dict, op_errstr,
-                                          rsp_dict);
+                                          rsp_dict, op_errno);
 
         if (ret) {
                 gf_msg (this->name, GF_LOG_ERROR, 0,
@@ -790,6 +796,7 @@ glusterd_mgmt_v3_pre_validate (glusterd_op_t op, dict_t *req_dict,
         }
 
         ret = args.op_ret;
+        *op_errno = args.op_errno;
 
         gf_msg_debug (this->name, 0, "Sent pre valaidation req for %s "
                 "to %d peers. Returning %d", gd_op_list[op], peer_cnt, ret);
@@ -1191,7 +1198,8 @@ out:
 
 int
 glusterd_mgmt_v3_commit (glusterd_op_t op, dict_t *op_ctx, dict_t *req_dict,
-                         char **op_errstr, uint32_t txn_generation)
+                         char **op_errstr, uint32_t *op_errno,
+                         uint32_t txn_generation)
 {
         int32_t              ret        = -1;
         int32_t              peer_cnt   = 0;
@@ -1210,6 +1218,7 @@ glusterd_mgmt_v3_commit (glusterd_op_t op, dict_t *op_ctx, dict_t *req_dict,
         GF_ASSERT (op_ctx);
         GF_ASSERT (req_dict);
         GF_ASSERT (op_errstr);
+        GF_VALIDATE_OR_GOTO (this->name, op_errno, out);
 
         rsp_dict = dict_new ();
         if (!rsp_dict) {
@@ -1221,7 +1230,7 @@ glusterd_mgmt_v3_commit (glusterd_op_t op, dict_t *op_ctx, dict_t *req_dict,
 
         /* Commit on local node */
         ret = gd_mgmt_v3_commit_fn (op, req_dict, op_errstr,
-                                   rsp_dict);
+                                    op_errno, rsp_dict);
 
         if (ret) {
                 gf_msg (this->name, GF_LOG_ERROR, 0,
@@ -1298,6 +1307,7 @@ glusterd_mgmt_v3_commit (glusterd_op_t op, dict_t *op_ctx, dict_t *req_dict,
         }
 
         ret = args.op_ret;
+        *op_errno = args.op_errno;
 
         gf_msg_debug (this->name, 0, "Sent commit req for %s to %d "
                 "peers. Returning %d", gd_op_list[op], peer_cnt, ret);
@@ -1801,7 +1811,7 @@ glusterd_mgmt_v3_initiate_all_phases (rpcsvc_request_t *req, glusterd_op_t op,
 
         /* PRE-COMMIT VALIDATE PHASE */
         ret = glusterd_mgmt_v3_pre_validate (op, req_dict, &op_errstr,
-                                             txn_generation);
+                                             &op_errno, txn_generation);
         if (ret) {
                 gf_msg (this->name, GF_LOG_ERROR, 0,
                         GD_MSG_PRE_VALIDATION_FAIL, "Pre Validation Failed");
@@ -1810,7 +1820,7 @@ glusterd_mgmt_v3_initiate_all_phases (rpcsvc_request_t *req, glusterd_op_t op,
 
         /* COMMIT OP PHASE */
         ret = glusterd_mgmt_v3_commit (op, dict, req_dict, &op_errstr,
-                                       txn_generation);
+                                       &op_errno, txn_generation);
         if (ret) {
                 gf_msg (this->name, GF_LOG_ERROR, 0,
                         GD_MSG_COMMIT_OP_FAIL, "Commit Op Failed");
@@ -1850,8 +1860,8 @@ out:
                 }
         }
 
-        if (ret && (op_errno == 0))
-                op_errno = EINTRNL;
+        if (op_ret && (op_errno == 0))
+                op_errno = EG_INTRNL;
 
         /* SEND CLI RESPONSE */
         glusterd_op_send_cli_response (op, op_ret, op_errno, req,
@@ -2035,7 +2045,7 @@ glusterd_mgmt_v3_initiate_snap_phases (rpcsvc_request_t *req, glusterd_op_t op,
 
         /* PRE-COMMIT VALIDATE PHASE */
         ret = glusterd_mgmt_v3_pre_validate (op, req_dict, &op_errstr,
-                                             txn_generation);
+                                             &op_errno, txn_generation);
         if (ret) {
                 gf_msg (this->name, GF_LOG_ERROR, 0,
                         GD_MSG_PRE_VALIDATION_FAIL, "Pre Validation Failed");
@@ -2043,7 +2053,8 @@ glusterd_mgmt_v3_initiate_snap_phases (rpcsvc_request_t *req, glusterd_op_t op,
         }
 
         /* quorum check of the volume is done here */
-        ret = glusterd_snap_quorum_check (req_dict, _gf_false, &op_errstr);
+        ret = glusterd_snap_quorum_check (req_dict, _gf_false, &op_errstr,
+                                          &op_errno);
         if (ret) {
                 gf_msg (this->name, GF_LOG_WARNING, 0,
                         GD_MSG_QUORUM_CHECK_FAIL, "Volume quorum check failed");
@@ -2095,7 +2106,7 @@ glusterd_mgmt_v3_initiate_snap_phases (rpcsvc_request_t *req, glusterd_op_t op,
         }
 
         ret = glusterd_mgmt_v3_commit (op, dict, req_dict, &op_errstr,
-                                       txn_generation);
+                                       &op_errno, txn_generation);
         if (ret) {
                 gf_msg (this->name, GF_LOG_ERROR, 0,
                         GD_MSG_COMMIT_OP_FAIL,  "Commit Op Failed");
@@ -2134,7 +2145,8 @@ unbarrier:
         /*Do a quorum check if the commit phase is successful*/
         if (success) {
                 //quorum check of the snapshot volume
-                ret = glusterd_snap_quorum_check (dict, _gf_true, &op_errstr);
+                ret = glusterd_snap_quorum_check (dict, _gf_true, &op_errstr,
+                                                  &op_errno);
                 if (ret) {
                         gf_msg (this->name, GF_LOG_WARNING, 0,
                                 GD_MSG_QUORUM_CHECK_FAIL,
@@ -2189,8 +2201,8 @@ out:
                 }
         }
 
-        if (ret && (op_errno == 0))
-                op_errno = EINTRNL;
+        if (op_ret && (op_errno == 0))
+                op_errno = EG_INTRNL;
 
         /* SEND CLI RESPONSE */
         glusterd_op_send_cli_response (op, op_ret, op_errno, req,
diff --git a/xlators/mgmt/glusterd/src/glusterd-mgmt.h b/xlators/mgmt/glusterd/src/glusterd-mgmt.h
index 894bd19..a9812a4 100644
--- a/xlators/mgmt/glusterd/src/glusterd-mgmt.h
+++ b/xlators/mgmt/glusterd/src/glusterd-mgmt.h
@@ -21,7 +21,8 @@ void gd_mgmt_v3_collate_errors (struct syncargs *args, int op_ret, int op_errno,
 
 int32_t
 gd_mgmt_v3_pre_validate_fn (glusterd_op_t op, dict_t *dict,
-                           char **op_errstr, dict_t *rsp_dict);
+                            char **op_errstr, dict_t *rsp_dict,
+                            uint32_t *op_errno);
 
 int32_t
 gd_mgmt_v3_brick_op_fn (glusterd_op_t op, dict_t *dict,
@@ -29,7 +30,8 @@ gd_mgmt_v3_brick_op_fn (glusterd_op_t op, dict_t *dict,
 
 int32_t
 gd_mgmt_v3_commit_fn (glusterd_op_t op, dict_t *dict,
-                     char **op_errstr, dict_t *rsp_dict);
+                      char **op_errstr, uint32_t *op_errno,
+                      dict_t *rsp_dict);
 
 int32_t
 gd_mgmt_v3_post_validate_fn (glusterd_op_t op, int32_t op_ret, dict_t *dict,
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c b/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c
index f666d4c..294758b 100644
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c
@@ -33,6 +33,7 @@
 #include "glusterd-snapshot-utils.h"
 #include "glusterd-server-quorum.h"
 #include "glusterd-messages.h"
+#include "glusterd-errno.h"
 
 /*
  *  glusterd_snap_geo_rep_restore:
@@ -2620,7 +2621,8 @@ gf_boolean_t
 glusterd_volume_quorum_calculate (glusterd_volinfo_t *volinfo, dict_t *dict,
                                   int down_count, gf_boolean_t first_brick_on,
                                   int8_t snap_force, int quorum_count,
-                                  char *quorum_type, char **op_errstr)
+                                  char *quorum_type, char **op_errstr,
+                                  uint32_t *op_errno)
 {
         gf_boolean_t  quorum_met        = _gf_false;
         char          err_str[PATH_MAX] = {0, };
@@ -2629,6 +2631,7 @@ glusterd_volume_quorum_calculate (glusterd_volinfo_t *volinfo, dict_t *dict,
 
         this = THIS;
         GF_ASSERT (this);
+        GF_VALIDATE_OR_GOTO (this->name, op_errno, out);
 
         if (!volinfo || !dict) {
                 gf_msg (this->name, GF_LOG_WARNING, 0,
@@ -2647,6 +2650,7 @@ glusterd_volume_quorum_calculate (glusterd_volinfo_t *volinfo, dict_t *dict,
                 gf_msg (this->name, GF_LOG_ERROR, 0,
                         GD_MSG_BRICK_DISCONNECTED, "%s", err_str);
                 *op_errstr = gf_strdup (err_str);
+                *op_errno = EG_BRCKDWN;
                 goto out;
         }
 
@@ -2678,6 +2682,7 @@ glusterd_volume_quorum_calculate (glusterd_volinfo_t *volinfo, dict_t *dict,
                 gf_msg (this->name, GF_LOG_WARNING, 0,
                         GD_MSG_SERVER_QUORUM_NOT_MET, "%s", err_str);
                 *op_errstr = gf_strdup (err_str);
+                *op_errno = EG_BRCKDWN;
         }
 
 out:
@@ -2688,7 +2693,8 @@ int32_t
 glusterd_volume_quorum_check (glusterd_volinfo_t *volinfo, int64_t index,
                               dict_t *dict, char *key_prefix,
                               int8_t snap_force, int quorum_count,
-                              char *quorum_type, char **op_errstr)
+                              char *quorum_type, char **op_errstr,
+                              uint32_t *op_errno)
 {
         int                      ret                = 0;
         xlator_t                *this               = NULL;
@@ -2707,6 +2713,7 @@ glusterd_volume_quorum_check (glusterd_volinfo_t *volinfo, int64_t index,
         GF_ASSERT (this);
         priv = this->private;
         GF_ASSERT (priv);
+        GF_VALIDATE_OR_GOTO (this->name, op_errno, out);
 
         if (!volinfo || !dict) {
                 gf_msg (this->name, GF_LOG_WARNING, 0,
@@ -2734,6 +2741,7 @@ glusterd_volume_quorum_check (glusterd_volinfo_t *volinfo, int64_t index,
                                         0, GD_MSG_SERVER_QUORUM_NOT_MET, "%s",
                                         err_str);
                                 *op_errstr = gf_strdup (err_str);
+                                *op_errno = EG_BRCKDWN;
                                 goto out;
                         }
                 }
@@ -2770,7 +2778,8 @@ glusterd_volume_quorum_check (glusterd_volinfo_t *volinfo, int64_t index,
                                                                     snap_force,
                                                                   quorum_count,
                                                                    quorum_type,
-                                                                   op_errstr);
+                                                                   op_errstr,
+                                                                   op_errno);
                         /* goto out if quorum is not met */
                         if (!quorum_met) {
                                 ret = -1;
@@ -2794,7 +2803,7 @@ out:
 
 int32_t
 glusterd_snap_quorum_check_for_create (dict_t *dict, gf_boolean_t snap_volume,
-                                       char **op_errstr)
+                                       char **op_errstr, uint32_t *op_errno)
 {
         int8_t              snap_force        = 0;
         int32_t             force             = 0;
@@ -2815,6 +2824,7 @@ glusterd_snap_quorum_check_for_create (dict_t *dict, gf_boolean_t snap_volume,
 
         this = THIS;
         GF_ASSERT (this);
+        GF_VALIDATE_OR_GOTO (this->name, op_errno, out);
 
         if (!dict) {
                 gf_msg (this->name, GF_LOG_ERROR, 0,
@@ -2855,6 +2865,7 @@ glusterd_snap_quorum_check_for_create (dict_t *dict, gf_boolean_t snap_volume,
                 gf_msg (this->name, GF_LOG_WARNING, 0,
                         GD_MSG_SERVER_QUORUM_NOT_MET, "%s", err_str);
                 *op_errstr = gf_strdup (err_str);
+                *op_errno = EG_NODEDWN;
                 ret = -1;
                 goto out;
         } else
@@ -2978,7 +2989,8 @@ glusterd_snap_quorum_check_for_create (dict_t *dict, gf_boolean_t snap_volume,
                                                     snap_force,
                                                     quorum_count,
                                                     quorum_type,
-                                                    op_errstr);
+                                                    op_errstr,
+                                                    op_errno);
                 if (ret) {
                         gf_msg (this->name, GF_LOG_WARNING, 0,
                                 GD_MSG_VOL_NOT_FOUND, "volume %s "
@@ -2992,7 +3004,7 @@ out:
 
 int32_t
 glusterd_snap_quorum_check (dict_t *dict, gf_boolean_t snap_volume,
-                            char **op_errstr)
+                            char **op_errstr, uint32_t *op_errno)
 {
         int32_t             ret               = -1;
         xlator_t           *this              = NULL;
@@ -3001,6 +3013,7 @@ glusterd_snap_quorum_check (dict_t *dict, gf_boolean_t snap_volume,
 
         this = THIS;
         GF_ASSERT (this);
+        GF_VALIDATE_OR_GOTO (this->name, op_errno, out);
 
         if (!dict) {
                 gf_msg (this->name, GF_LOG_ERROR, 0,
@@ -3008,7 +3021,6 @@ glusterd_snap_quorum_check (dict_t *dict, gf_boolean_t snap_volume,
                 goto out;
         }
 
-
         ret = dict_get_int32 (dict, "type", &snap_command);
         if (ret) {
                 gf_msg (this->name, GF_LOG_ERROR, 0,
@@ -3020,7 +3032,8 @@ glusterd_snap_quorum_check (dict_t *dict, gf_boolean_t snap_volume,
         switch (snap_command) {
         case GF_SNAP_OPTION_TYPE_CREATE:
                 ret = glusterd_snap_quorum_check_for_create (dict, snap_volume,
-                                                             op_errstr);
+                                                             op_errstr,
+                                                             op_errno);
                 if (ret) {
                         gf_msg (this->name, GF_LOG_WARNING, 0,
                                 GD_MSG_QUORUM_CHECK_FAIL, "Quorum check"
@@ -3038,6 +3051,7 @@ glusterd_snap_quorum_check (dict_t *dict, gf_boolean_t snap_volume,
                                 GD_MSG_SERVER_QUORUM_NOT_MET, "%s",
                                 err_str);
                         *op_errstr = gf_strdup (err_str);
+                        *op_errno = EG_NODEDWN;
                         goto out;
                 }
 
@@ -3054,6 +3068,7 @@ glusterd_snap_quorum_check (dict_t *dict, gf_boolean_t snap_volume,
                                 GD_MSG_SERVER_QUORUM_NOT_MET, "%s",
                                 err_str);
                         *op_errstr = gf_strdup (err_str);
+                        *op_errno = EG_NODEDWN;
                         goto out;
                 }
 
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.h b/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.h
index 68906dc..ce8d7d4 100644
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.h
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.h
@@ -120,11 +120,7 @@ gd_import_volume_snap_details (dict_t *dict, glusterd_volinfo_t *volinfo,
 
 int32_t
 glusterd_snap_quorum_check (dict_t *dict, gf_boolean_t snap_volume,
-                            char **op_errstr);
-
-int32_t
-glusterd_snap_quorum_check_for_create (dict_t *dict, gf_boolean_t snap_volume,
-                                       char **op_errstr);
+                            char **op_errstr, uint32_t *op_errno);
 
 int32_t
 glusterd_snap_brick_create (glusterd_volinfo_t *snap_volinfo,
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
index e5a7cac..668c26e 100644
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
@@ -20,6 +20,7 @@
 #include <sys/mount.h>
 #include <signal.h>
 #include "glusterd-messages.h"
+#include "glusterd-errno.h"
 
 #if defined(GF_LINUX_HOST_OS)
 #include <mntent.h>
@@ -932,7 +933,7 @@ out:
  */
 int32_t
 glusterd_snapshot_restore_prevalidate (dict_t *dict, char **op_errstr,
-                                       dict_t *rsp_dict)
+                                       uint32_t *op_errno, dict_t *rsp_dict)
 {
         int                     ret             = -1;
         int32_t                 i               = 0;
@@ -952,6 +953,7 @@ glusterd_snapshot_restore_prevalidate (dict_t *dict, char **op_errstr,
         GF_ASSERT (this);
         GF_ASSERT (dict);
         GF_ASSERT (op_errstr);
+        GF_VALIDATE_OR_GOTO (this->name, op_errno, out);
         GF_ASSERT (rsp_dict);
 
         ret = dict_get_str (dict, "snapname", &snapname);
@@ -966,6 +968,7 @@ glusterd_snapshot_restore_prevalidate (dict_t *dict, char **op_errstr,
         if (NULL == snap) {
                 ret = gf_asprintf (op_errstr, "Snapshot (%s) does not exist",
                                 snapname);
+                *op_errno = EG_SNAPEXST;
                 if (ret < 0) {
                         goto out;
                 }
@@ -1021,6 +1024,7 @@ glusterd_snapshot_restore_prevalidate (dict_t *dict, char **op_errstr,
                 if (ret) {
                         ret = gf_asprintf (op_errstr, "Volume (%s) "
                                            "does not exist", volname);
+                        *op_errno = EG_NOVOL;
                         if (ret < 0) {
                                 goto out;
                         }
@@ -1034,6 +1038,7 @@ glusterd_snapshot_restore_prevalidate (dict_t *dict, char **op_errstr,
                         ret = gf_asprintf (op_errstr, "Volume (%s) has been "
                         "started. Volume needs to be stopped before restoring "
                         "a snapshot.", volname);
+                        *op_errno = EG_VOLRUN;
                         if (ret < 0) {
                                 goto out;
                         }
@@ -1214,7 +1219,8 @@ out:
 }
 
 int
-glusterd_snapshot_config_prevalidate (dict_t *dict, char **op_errstr)
+glusterd_snapshot_config_prevalidate (dict_t *dict, char **op_errstr,
+                                      uint32_t *op_errno)
 {
         char               *volname             = NULL;
         glusterd_volinfo_t *volinfo             = NULL;
@@ -1237,6 +1243,7 @@ glusterd_snapshot_config_prevalidate (dict_t *dict, char **op_errstr)
         GF_ASSERT (this);
         GF_ASSERT (dict);
         GF_ASSERT (op_errstr);
+        GF_VALIDATE_OR_GOTO (this->name, op_errno, out);
 
         conf = this->private;
 
@@ -1260,6 +1267,7 @@ glusterd_snapshot_config_prevalidate (dict_t *dict, char **op_errstr)
                 if (ret) {
                         snprintf (err_str, sizeof (err_str),
                                   "Volume (%s) does not exist.", volname);
+                        *op_errno = EG_NOVOL;
                         goto out;
                 }
         }
@@ -1278,6 +1286,7 @@ glusterd_snapshot_config_prevalidate (dict_t *dict, char **op_errstr)
                         gf_msg (this->name, GF_LOG_ERROR, 0,
                                 GD_MSG_HARD_LIMIT_SET_FAIL,
                                 "snap-max-hard-limit validation failed.");
+                        *op_errno = EINVAL;
                         goto out;
                 }
         }
@@ -1290,6 +1299,7 @@ glusterd_snapshot_config_prevalidate (dict_t *dict, char **op_errstr)
                                  "snap-max-soft-limit ""%"
                                  PRIu64 ". Expected range 1 - %"PRIu64,
                                  soft_limit, max_limit);
+                        *op_errno = EINVAL;
                         goto out;
                 }
         }
@@ -1307,6 +1317,7 @@ glusterd_snapshot_config_prevalidate (dict_t *dict, char **op_errstr)
                         ret = -1;
                         snprintf (err_str, sizeof (err_str), "Please enter a "
                                   "valid boolean value for auto-delete");
+                        *op_errno = EINVAL;
                         goto out;
                 }
 
@@ -1324,6 +1335,7 @@ glusterd_snapshot_config_prevalidate (dict_t *dict, char **op_errstr)
                         else
                                 snprintf (err_str, sizeof (err_str),
                                           "auto-delete is already disabled");
+                        *op_errno = EINVAL;
                         goto out;
                 }
         } else if (dict_get(dict, GLUSTERD_STORE_KEY_SNAP_ACTIVATE)) {
@@ -1334,6 +1346,7 @@ glusterd_snapshot_config_prevalidate (dict_t *dict, char **op_errstr)
                         ret = -1;
                         snprintf (err_str, sizeof (err_str), "Please enter a "
                                   "valid boolean value for activate-on-create");
+                        *op_errno = EINVAL;
                         goto out;
                 }
 
@@ -1351,11 +1364,13 @@ glusterd_snapshot_config_prevalidate (dict_t *dict, char **op_errstr)
                         else
                                 snprintf (err_str, sizeof (err_str),
                                       "activate-on-create is already disabled");
+                        *op_errno = EINVAL;
                         goto out;
                 }
         } else {
                 ret = -1;
                 snprintf (err_str, sizeof (err_str), "Invalid option");
+                *op_errno = EINVAL;
                 goto out;
         }
 
@@ -1871,7 +1886,7 @@ out:
  * @return              _gf_true if LV is thin else _gf_false
  */
 gf_boolean_t
-glusterd_is_thinp_brick (char *device)
+glusterd_is_thinp_brick (char *device, uint32_t *op_errno)
 {
         int             ret                     = -1;
         char            msg [1024]              = "";
@@ -1885,6 +1900,7 @@ glusterd_is_thinp_brick (char *device)
 
         GF_VALIDATE_OR_GOTO ("glusterd", this, out);
         GF_VALIDATE_OR_GOTO (this->name, device, out);
+        GF_VALIDATE_OR_GOTO (this->name, op_errno, out);
 
         snprintf (msg, sizeof (msg), "Get thin pool name for device %s",
                   device);
@@ -1929,14 +1945,21 @@ glusterd_is_thinp_brick (char *device)
         }
 
 out:
+        if (!is_thin)
+                *op_errno = EG_NOTTHINP;
+
         return is_thin;
 }
 
 int
 glusterd_snap_create_clone_common_prevalidate (dict_t *rsp_dict, int flags,
-            char *snapname, char *err_str, char *snap_volname, int64_t volcount,
-            glusterd_volinfo_t *volinfo, gf_loglevel_t *loglevel, int clone)  {
-
+                                               char *snapname, char *err_str,
+                                               char *snap_volname,
+                                               int64_t volcount,
+                                               glusterd_volinfo_t *volinfo,
+                                               gf_loglevel_t *loglevel,
+                                               int clone, uint32_t *op_errno)
+{
         char                  *device            = NULL;
         char                   key[PATH_MAX]     = "";
         int                    ret               = -1;
@@ -1950,6 +1973,7 @@ glusterd_snap_create_clone_common_prevalidate (dict_t *rsp_dict, int flags,
         this = THIS;
         conf = this->private;
         GF_ASSERT (conf);
+        GF_VALIDATE_OR_GOTO (this->name, op_errno, out);
 
         if (!snapname || !volinfo) {
                 gf_msg (this->name, GF_LOG_ERROR, EINVAL,
@@ -1996,6 +2020,7 @@ glusterd_snap_create_clone_common_prevalidate (dict_t *rsp_dict, int flags,
                                   "and then issue snapshot clone "
                                   "command ");
                         }
+                        *op_errno = EG_BRCKDWN;
                         ret = -1;
                         goto out;
                 }
@@ -2012,7 +2037,7 @@ glusterd_snap_create_clone_common_prevalidate (dict_t *rsp_dict, int flags,
                         goto out;
                 }
                 if (!clone) {
-                     if (!glusterd_is_thinp_brick (device)) {
+                     if (!glusterd_is_thinp_brick (device, op_errno)) {
                                 snprintf (err_str, PATH_MAX,
                                           "Snapshot is supported only for "
                                           "thin provisioned LV. Ensure that "
@@ -2138,7 +2163,7 @@ out:
 
 int
 glusterd_snapshot_clone_prevalidate (dict_t *dict, char **op_errstr,
-                                      dict_t *rsp_dict)
+                                     dict_t *rsp_dict, uint32_t *op_errno)
 {
         char                  *clonename         = NULL;
         char                  *snapname          = NULL;
@@ -2155,6 +2180,7 @@ glusterd_snapshot_clone_prevalidate (dict_t *dict, char **op_errstr,
         this = THIS;
         GF_ASSERT (op_errstr);
         GF_ASSERT (dict);
+        GF_VALIDATE_OR_GOTO (this->name, op_errno, out);
 
         ret = dict_get_str (dict, "clonename", &clonename);
         if (ret) {
@@ -2173,6 +2199,7 @@ glusterd_snapshot_clone_prevalidate (dict_t *dict, char **op_errstr,
                 ret = -1;
                 snprintf (err_str, sizeof (err_str), "Volume with name:%s "
                           "already exists", clonename);
+                *op_errno = EG_VOLEXST;
                 goto out;
         }
         /* need to find snap volinfo*/
@@ -2205,14 +2232,19 @@ glusterd_snapshot_clone_prevalidate (dict_t *dict, char **op_errstr,
                 goto out;
         }
 
-
         /* Adding snap bricks mount paths to the dict */
         ret = glusterd_snap_create_clone_common_prevalidate (rsp_dict, 0,
-                        snapname, err_str, clonename, 1, snap_vol,
-                        &loglevel, 1);
+                                                             snapname, err_str,
+                                                             clonename, 1,
+                                                             snap_vol,
+                                                             &loglevel,
+                                                             1, op_errno);
         if (ret) {
+                gf_msg (this->name, GF_LOG_ERROR, 0,
+                        GD_MSG_PRE_VALIDATION_FAIL, "Failed to pre validate");
                 goto out;
         }
+
         ret = dict_set_int64 (rsp_dict, "volcount", volcount);
         if (ret) {
                 gf_msg (this->name, GF_LOG_ERROR, 0,
@@ -2236,7 +2268,7 @@ out:
 
 int
 glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr,
-                                      dict_t *rsp_dict)
+                                      dict_t *rsp_dict, uint32_t *op_errno)
 {
         char                  *volname           = NULL;
         char                  *snapname          = NULL;
@@ -2259,6 +2291,7 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr,
         GF_ASSERT (op_errstr);
         conf = this->private;
         GF_ASSERT (conf);
+        GF_VALIDATE_OR_GOTO (this->name, op_errno, out);
 
         ret = dict_get_int64 (dict, "volcount", &volcount);
         if (ret) {
@@ -2290,6 +2323,7 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr,
                 ret = -1;
                 snprintf (err_str, sizeof (err_str), "Snapshot %s already "
                           "exists", snapname);
+                *op_errno = EG_SNAPEXST;
                 goto out;
         }
 
@@ -2305,6 +2339,7 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr,
                 if (ret) {
                         snprintf (err_str, sizeof (err_str),
                                   "Volume (%s) does not exist ", volname);
+                        *op_errno = EG_NOVOL;
                         goto out;
                 }
 
@@ -2313,6 +2348,7 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr,
                         snprintf (err_str, sizeof (err_str), "volume %s is "
                                   "not started", volinfo->volname);
                         loglevel = GF_LOG_WARNING;
+                        *op_errno = EG_VOLSTP;
                         goto out;
                 }
 
@@ -2321,6 +2357,7 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr,
                                   "rebalance process is running for the "
                                   "volume %s", volname);
                         loglevel = GF_LOG_WARNING;
+                        *op_errno = EG_RBALRUN;
                         goto out;
                 }
 
@@ -2331,6 +2368,7 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr,
                                    "stopped before taking a snapshot.",
                                    volname);
                          loglevel = GF_LOG_WARNING;
+                         *op_errno = EG_GEOREPRUN;
                          goto out;
                 }
 
@@ -2338,6 +2376,7 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr,
                         snprintf (err_str, sizeof (err_str),
                                   "Volume %s is a snap volume", volname);
                         loglevel = GF_LOG_WARNING;
+                         *op_errno = EG_ISSNAP;
                         goto out;
                 }
 
@@ -2369,6 +2408,7 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr,
                                   "snapshots before taking further snapshots.",
                                   effective_max_limit, volname);
                         loglevel = GF_LOG_WARNING;
+                        *op_errno = EG_HRDLMT;
                         goto out;
                 }
 
@@ -2387,8 +2427,14 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr,
                 GLUSTERD_GET_UUID_NOHYPHEN (snap_volname, *snap_volid);
 
                 ret = glusterd_snap_create_clone_common_prevalidate (rsp_dict,
-                                flags, snapname, err_str, snap_volname, i,
-                                volinfo, &loglevel, 0);
+                                                                        flags,
+                                                                     snapname,
+                                                                      err_str,
+                                                                 snap_volname,
+                                                                            i,
+                                                                      volinfo,
+                                                                    &loglevel,
+                                                                 0, op_errno);
                 if (ret) {
                         gf_msg (this->name, GF_LOG_ERROR, 0,
                                 GD_MSG_PRE_VALIDATION_FAIL,
@@ -3718,7 +3764,8 @@ out:
 
 int
 glusterd_handle_snapshot_list (rpcsvc_request_t *req, glusterd_op_t op,
-                               dict_t *dict, char *err_str, size_t len)
+                               dict_t *dict, char *err_str, size_t len,
+                               uint32_t *op_errno)
 {
         int                 ret             = -1;
         char               *volname         = NULL;
@@ -3729,6 +3776,7 @@ glusterd_handle_snapshot_list (rpcsvc_request_t *req, glusterd_op_t op,
 
         GF_VALIDATE_OR_GOTO (this->name, req, out);
         GF_VALIDATE_OR_GOTO (this->name, dict, out);
+        GF_VALIDATE_OR_GOTO (this->name, op_errno, out);
 
         /* Ignore error for getting volname as it is optional */
         ret = dict_get_str (dict, "volname", &volname);
@@ -3749,6 +3797,7 @@ glusterd_handle_snapshot_list (rpcsvc_request_t *req, glusterd_op_t op,
                         gf_msg (this->name, GF_LOG_ERROR, EINVAL,
                                 GD_MSG_VOL_NOT_FOUND,
                                 "%s", err_str);
+                        *op_errno = EG_NOVOL;
                         goto out;
                 }
 
@@ -4183,7 +4232,8 @@ out:
  */
 int
 glusterd_handle_snapshot_restore (rpcsvc_request_t *req, glusterd_op_t op,
-                               dict_t *dict, char *err_str, size_t len)
+                                  dict_t *dict, char *err_str,
+                                  uint32_t *op_errno, size_t len)
 {
         int                     ret             = -1;
         char                    *snapname       = NULL;
@@ -4216,6 +4266,7 @@ glusterd_handle_snapshot_restore (rpcsvc_request_t *req, glusterd_op_t op,
         if (!snap) {
                 snprintf (err_str, len, "Snapshot (%s) does not exist",
                           snapname);
+                *op_errno = EG_NOSNAP;
                 gf_msg (this->name, GF_LOG_ERROR, EINVAL,
                         GD_MSG_SNAP_NOT_FOUND, "%s", err_str);
                 ret = -1;
@@ -5153,7 +5204,10 @@ out:
  * */
 int
 glusterd_snapshot_activate_deactivate_prevalidate (dict_t *dict,
-                char **op_errstr, dict_t *rsp_dict, gf_boolean_t is_op_activate)
+                                                   char **op_errstr,
+                                                   uint32_t *op_errno,
+                                                   dict_t *rsp_dict,
+                                                   gf_boolean_t is_op_activate)
 {
         int32_t                 ret                   = -1;
         char                    *snapname             = NULL;
@@ -5166,6 +5220,8 @@ glusterd_snapshot_activate_deactivate_prevalidate (dict_t *dict,
         int                     flags                 = 0;
 
         this = THIS;
+        GF_VALIDATE_OR_GOTO ("glusterd", this, out);
+        GF_VALIDATE_OR_GOTO (this->name, op_errno, out);
 
         if (!dict || !op_errstr) {
                 gf_msg (this->name, GF_LOG_ERROR, 0,
@@ -5185,6 +5241,7 @@ glusterd_snapshot_activate_deactivate_prevalidate (dict_t *dict,
         if (!snap) {
                 snprintf (err_str, sizeof (err_str), "Snapshot (%s) does not "
                           "exist.", snapname);
+                *op_errno = EG_NOSNAP;
                 ret = -1;
                 goto out;
         }
@@ -5231,11 +5288,13 @@ glusterd_snapshot_activate_deactivate_prevalidate (dict_t *dict,
                                 snprintf (err_str, sizeof (err_str),
                                           "Snapshot %s is already activated.",
                                           snapname);
+                                *op_errno = EINVAL;
                                 ret = -1;
                         }
                 } else {
                         snprintf (err_str, sizeof (err_str),
                                "Snapshot %s is already deactivated.", snapname);
+                        *op_errno = EINVAL;
                         ret = -1;
                 }
                 goto out;
@@ -5253,7 +5312,8 @@ out:
 }
 
 int32_t
-glusterd_handle_snapshot_delete_vol (dict_t *dict, char *err_str, int len)
+glusterd_handle_snapshot_delete_vol (dict_t *dict, char *err_str,
+                                     uint32_t *op_errno, int len)
 {
         int32_t                 ret             = -1;
         int32_t                 i               = 0;
@@ -5267,6 +5327,7 @@ glusterd_handle_snapshot_delete_vol (dict_t *dict, char *err_str, int len)
         this = THIS;
         GF_ASSERT (this);
         GF_ASSERT (dict);
+        GF_VALIDATE_OR_GOTO (this->name, op_errno, out);
 
         ret = dict_get_str (dict, "volname", &volname);
         if (ret) {
@@ -5279,6 +5340,7 @@ glusterd_handle_snapshot_delete_vol (dict_t *dict, char *err_str, int len)
         ret = glusterd_volinfo_find (volname, &volinfo);
         if (ret) {
                 snprintf (err_str, len, "Volume (%s) does not exist", volname);
+                *op_errno = EG_NOVOL;
                 gf_msg (this->name, GF_LOG_ERROR, EINVAL,
                         GD_MSG_VOL_NOT_FOUND, "Failed to get volinfo of "
                         "volume %s", volname);
@@ -5354,7 +5416,7 @@ int32_t
 glusterd_handle_snapshot_delete_type_snap (rpcsvc_request_t *req,
                                            glusterd_op_t op,
                                            dict_t *dict, char *err_str,
-                                           size_t len)
+                                           uint32_t *op_errno, size_t len)
 {
         int32_t                 ret             = -1;
         int64_t                  volcount       = 0;
@@ -5384,6 +5446,7 @@ glusterd_handle_snapshot_delete_type_snap (rpcsvc_request_t *req,
         if (!snap) {
                 snprintf (err_str, len, "Snapshot (%s) does not exist",
                           snapname);
+                *op_errno = EG_NOSNAP;
                 gf_msg (this->name, GF_LOG_ERROR, EINVAL,
                         GD_MSG_SNAP_NOT_FOUND, "%s", err_str);
                 ret = -1;
@@ -5448,7 +5511,8 @@ out :
  */
 int
 glusterd_handle_snapshot_delete (rpcsvc_request_t *req, glusterd_op_t op,
-                                 dict_t *dict, char *err_str, size_t len)
+                                 dict_t *dict, char *err_str,
+                                 uint32_t *op_errno, size_t len)
 {
         int                      ret            = -1;
         xlator_t                *this           = NULL;
@@ -5461,6 +5525,7 @@ glusterd_handle_snapshot_delete (rpcsvc_request_t *req, glusterd_op_t op,
         GF_ASSERT (req);
         GF_ASSERT (dict);
         GF_ASSERT (err_str);
+        GF_VALIDATE_OR_GOTO (this->name, op_errno, out);
 
         ret = dict_get_int32 (dict, "delete-cmd", &delete_cmd);
         if (ret) {
@@ -5472,7 +5537,8 @@ glusterd_handle_snapshot_delete (rpcsvc_request_t *req, glusterd_op_t op,
         switch (delete_cmd) {
         case GF_SNAP_DELETE_TYPE_SNAP:
                 ret = glusterd_handle_snapshot_delete_type_snap (req, op, dict,
-                                                                 err_str, len);
+                                                                 err_str,
+                                                                 op_errno, len);
                 if (ret) {
                         gf_msg (this->name, GF_LOG_ERROR, 0,
                                 GD_MSG_SNAP_REMOVE_FAIL, "Failed to handle "
@@ -5492,7 +5558,8 @@ glusterd_handle_snapshot_delete (rpcsvc_request_t *req, glusterd_op_t op,
                 break;
 
         case GF_SNAP_DELETE_TYPE_VOL:
-                ret = glusterd_handle_snapshot_delete_vol (dict, err_str, len);
+                ret = glusterd_handle_snapshot_delete_vol (dict, err_str,
+                                                           op_errno, len);
                 if (ret) {
                         gf_msg (this->name, GF_LOG_ERROR, 0,
                                 GD_MSG_SNAP_REMOVE_FAIL, "Failed to handle "
@@ -5502,6 +5569,7 @@ glusterd_handle_snapshot_delete (rpcsvc_request_t *req, glusterd_op_t op,
                 break;
 
         default:
+                *op_errno = EINVAL;
                 gf_msg (this->name, GF_LOG_ERROR, EINVAL,
                         GD_MSG_INVALID_ENTRY, "Wrong snapshot delete type");
                 break;
@@ -5525,7 +5593,7 @@ out:
 
 int
 glusterd_snapshot_remove_prevalidate (dict_t *dict, char **op_errstr,
-                                      dict_t *rsp_dict)
+                                      uint32_t *op_errno, dict_t *rsp_dict)
 {
         int32_t             ret         = -1;
         char               *snapname    = NULL;
@@ -5533,6 +5601,8 @@ glusterd_snapshot_remove_prevalidate (dict_t *dict, char **op_errstr,
         glusterd_snap_t    *snap        = NULL;
 
         this = THIS;
+        GF_VALIDATE_OR_GOTO ("glusterd", this, out);
+        GF_VALIDATE_OR_GOTO (this->name, op_errno, out);
 
         if (!dict || !op_errstr) {
                 gf_msg (this->name, GF_LOG_ERROR, 0,
@@ -5553,6 +5623,7 @@ glusterd_snapshot_remove_prevalidate (dict_t *dict, char **op_errstr,
                 gf_msg (this->name, GF_LOG_ERROR, EINVAL,
                         GD_MSG_SNAP_NOT_FOUND,
                         "Snapshot (%s) does not exist", snapname);
+                *op_errno = EG_NOSNAP;
                 ret = -1;
                 goto out;
         }
@@ -5574,7 +5645,7 @@ out:
 
 int
 glusterd_snapshot_status_prevalidate (dict_t *dict, char **op_errstr,
-                                      dict_t *rsp_dict)
+                                      uint32_t *op_errno, dict_t *rsp_dict)
 {
         int                     ret             =       -1;
         char                    *snapname       =       NULL;
@@ -5587,9 +5658,10 @@ glusterd_snapshot_status_prevalidate (dict_t *dict, char **op_errstr,
         this = THIS;
         GF_ASSERT (this);
         conf = this->private;
-
         GF_ASSERT (conf);
         GF_ASSERT (op_errstr);
+        GF_VALIDATE_OR_GOTO (this->name, op_errno, out);
+
         if (!dict) {
                 gf_msg (this->name, GF_LOG_ERROR, 0,
                         GD_MSG_INVALID_ENTRY, "Input dict is NULL");
@@ -5622,6 +5694,7 @@ glusterd_snapshot_status_prevalidate (dict_t *dict, char **op_errstr,
                         if (!glusterd_find_snap_by_name (snapname)) {
                                 ret = gf_asprintf (op_errstr, "Snapshot (%s) "
                                                   "does not exist", snapname);
+                                *op_errno = EG_NOSNAP;
                                 if (ret < 0) {
                                         goto out;
                                 }
@@ -5648,6 +5721,7 @@ glusterd_snapshot_status_prevalidate (dict_t *dict, char **op_errstr,
                         if (ret) {
                                 ret = gf_asprintf (op_errstr, "Volume (%s) "
                                                   "does not exist", volname);
+                                *op_errno = EG_NOVOL;
                                 if (ret < 0) {
                                         goto out;
                                 }
@@ -5664,6 +5738,7 @@ glusterd_snapshot_status_prevalidate (dict_t *dict, char **op_errstr,
                 {
                         gf_msg (this->name, GF_LOG_ERROR, EINVAL,
                                 GD_MSG_COMMAND_NOT_FOUND, "Invalid command");
+                        *op_errno = EINVAL;
                         break;
                 }
         }
@@ -6440,7 +6515,7 @@ out:
 
 int32_t
 glusterd_snapshot_create_commit (dict_t *dict, char **op_errstr,
-                                 dict_t *rsp_dict)
+                                 uint32_t *op_errno, dict_t *rsp_dict)
 {
         int                     ret                     = -1;
         int64_t                 i                       = 0;
@@ -6461,6 +6536,7 @@ glusterd_snapshot_create_commit (dict_t *dict, char **op_errstr,
         GF_ASSERT(this);
         GF_ASSERT(dict);
         GF_ASSERT(op_errstr);
+        GF_VALIDATE_OR_GOTO (this->name, op_errno, out);
         GF_ASSERT(rsp_dict);
         priv = this->private;
         GF_ASSERT(priv);
@@ -7859,7 +7935,8 @@ out:
 }
 
 int32_t
-glusterd_snapshot (dict_t *dict, char **op_errstr, dict_t *rsp_dict)
+glusterd_snapshot (dict_t *dict, char **op_errstr,
+                   uint32_t *op_errno, dict_t *rsp_dict)
 {
 
         xlator_t        *this           = NULL;
@@ -7874,6 +7951,7 @@ glusterd_snapshot (dict_t *dict, char **op_errstr, dict_t *rsp_dict)
         GF_ASSERT (this);
         GF_ASSERT (dict);
         GF_ASSERT (rsp_dict);
+        GF_VALIDATE_OR_GOTO (this->name, op_errno, out);
 
         priv = this->private;
         GF_ASSERT (priv);
@@ -7890,7 +7968,7 @@ glusterd_snapshot (dict_t *dict, char **op_errstr, dict_t *rsp_dict)
 
         case (GF_SNAP_OPTION_TYPE_CREATE):
                 ret = glusterd_snapshot_create_commit (dict, op_errstr,
-                                                       rsp_dict);
+                                                       op_errno, rsp_dict);
                 if (ret) {
                         gf_msg (this->name, GF_LOG_ERROR, 0,
                                 GD_MSG_SNAP_CREATION_FAIL, "Failed to "
@@ -8120,7 +8198,7 @@ out:
 
 int
 glusterd_snapshot_prevalidate (dict_t *dict, char **op_errstr,
-                               dict_t *rsp_dict)
+                               dict_t *rsp_dict, uint32_t *op_errno)
 {
         int                snap_command          = 0;
         xlator_t           *this                 = NULL;
@@ -8131,6 +8209,7 @@ glusterd_snapshot_prevalidate (dict_t *dict, char **op_errstr,
         GF_ASSERT (this);
         GF_ASSERT (dict);
         GF_ASSERT (rsp_dict);
+        GF_VALIDATE_OR_GOTO (this->name, op_errno, out);
 
         ret = dict_get_int32 (dict, "type", &snap_command);
         if (ret) {
@@ -8143,7 +8222,7 @@ glusterd_snapshot_prevalidate (dict_t *dict, char **op_errstr,
         switch (snap_command) {
         case (GF_SNAP_OPTION_TYPE_CREATE):
                 ret = glusterd_snapshot_create_prevalidate (dict, op_errstr,
-                                                            rsp_dict);
+                                                            rsp_dict, op_errno);
                 if (ret) {
                         gf_msg (this->name, GF_LOG_WARNING, 0,
                                 GD_MSG_SNAP_CREATION_FAIL, "Snapshot create "
@@ -8154,7 +8233,7 @@ glusterd_snapshot_prevalidate (dict_t *dict, char **op_errstr,
 
         case (GF_SNAP_OPTION_TYPE_CLONE):
                 ret = glusterd_snapshot_clone_prevalidate (dict, op_errstr,
-                                                            rsp_dict);
+                                                           rsp_dict, op_errno);
                 if (ret) {
                         gf_msg (this->name, GF_LOG_WARNING, 0,
                                 GD_MSG_SNAP_CLONE_PREVAL_FAILED,
@@ -8166,7 +8245,8 @@ glusterd_snapshot_prevalidate (dict_t *dict, char **op_errstr,
 
 
         case (GF_SNAP_OPTION_TYPE_CONFIG):
-                ret = glusterd_snapshot_config_prevalidate (dict, op_errstr);
+                ret = glusterd_snapshot_config_prevalidate (dict, op_errstr,
+                                                            op_errno);
                 if (ret) {
                         gf_msg (this->name, GF_LOG_WARNING, 0,
                                 GD_MSG_SNAP_CONFIG_FAIL, "Snapshot config "
@@ -8177,6 +8257,7 @@ glusterd_snapshot_prevalidate (dict_t *dict, char **op_errstr,
 
         case GF_SNAP_OPTION_TYPE_RESTORE:
                 ret = glusterd_snapshot_restore_prevalidate (dict, op_errstr,
+                                                             op_errno,
                                                              rsp_dict);
                 if (ret) {
                         gf_msg (this->name, GF_LOG_WARNING, 0,
@@ -8188,7 +8269,10 @@ glusterd_snapshot_prevalidate (dict_t *dict, char **op_errstr,
 
         case  GF_SNAP_OPTION_TYPE_ACTIVATE:
                 ret = glusterd_snapshot_activate_deactivate_prevalidate (dict,
-                                                op_errstr, rsp_dict, _gf_true);
+                                                                    op_errstr,
+                                                                     op_errno,
+                                                                     rsp_dict,
+                                                                    _gf_true);
                 if (ret) {
                         gf_msg (this->name, GF_LOG_WARNING, 0,
                                 GD_MSG_SNAP_ACTIVATE_FAIL, "Snapshot activate "
@@ -8198,7 +8282,10 @@ glusterd_snapshot_prevalidate (dict_t *dict, char **op_errstr,
                 break;
         case GF_SNAP_OPTION_TYPE_DEACTIVATE:
                 ret = glusterd_snapshot_activate_deactivate_prevalidate (dict,
-                                                op_errstr, rsp_dict, _gf_false);
+                                                                    op_errstr,
+                                                                     op_errno,
+                                                                     rsp_dict,
+                                                                   _gf_false);
                 if (ret) {
                         gf_msg (this->name, GF_LOG_WARNING, 0,
                                 GD_MSG_SNAP_DEACTIVATE_FAIL,
@@ -8208,7 +8295,7 @@ glusterd_snapshot_prevalidate (dict_t *dict, char **op_errstr,
                 break;
         case GF_SNAP_OPTION_TYPE_DELETE:
                 ret = glusterd_snapshot_remove_prevalidate (dict, op_errstr,
-                                                            rsp_dict);
+                                                            op_errno, rsp_dict);
                 if (ret) {
                         gf_msg (this->name, GF_LOG_WARNING, 0,
                                 GD_MSG_SNAP_REMOVE_FAIL, "Snapshot remove "
@@ -8219,7 +8306,7 @@ glusterd_snapshot_prevalidate (dict_t *dict, char **op_errstr,
 
         case GF_SNAP_OPTION_TYPE_STATUS:
                 ret = glusterd_snapshot_status_prevalidate (dict, op_errstr,
-                                                            rsp_dict);
+                                                            op_errno, rsp_dict);
                 if (ret) {
                         gf_msg (this->name, GF_LOG_WARNING, 0,
                                 GD_MSG_SNAP_STATUS_FAIL, "Snapshot status "
@@ -8231,6 +8318,7 @@ glusterd_snapshot_prevalidate (dict_t *dict, char **op_errstr,
         default:
                 gf_msg (this->name, GF_LOG_WARNING, EINVAL,
                         GD_MSG_COMMAND_NOT_FOUND, "invalid snap command");
+                *op_errno = EINVAL;
                 goto out;
         }
 
@@ -8709,6 +8797,7 @@ glusterd_handle_snapshot_fn (rpcsvc_request_t *req)
         char                 *host_uuid      = NULL;
         char                  err_str[2048]  = {0,};
         xlator_t             *this           = NULL;
+        uint32_t              op_errno       = 0;
 
         GF_ASSERT (req);
 
@@ -8768,6 +8857,7 @@ glusterd_handle_snapshot_fn (rpcsvc_request_t *req)
                 snprintf (err_str, sizeof (err_str), "Cluster operating version"
                           " is lesser than the supported version "
                           "for a snapshot");
+                op_errno = EG_OPNOTSUP;
                 gf_msg (this->name, GF_LOG_ERROR, 0,
                         GD_MSG_UNSUPPORTED_VERSION,
                         "%s (%d < %d)", err_str,
@@ -8816,7 +8906,8 @@ glusterd_handle_snapshot_fn (rpcsvc_request_t *req)
 
         case GF_SNAP_OPTION_TYPE_RESTORE:
                 ret = glusterd_handle_snapshot_restore (req, cli_op, dict,
-                                                err_str, sizeof (err_str));
+                                                        err_str, &op_errno,
+                                                        sizeof (err_str));
                 if (ret) {
                         gf_msg (this->name, GF_LOG_WARNING, 0,
                                 GD_MSG_SNAP_RESTORE_FAIL,
@@ -8835,7 +8926,8 @@ glusterd_handle_snapshot_fn (rpcsvc_request_t *req)
                 break;
         case GF_SNAP_OPTION_TYPE_LIST:
                 ret = glusterd_handle_snapshot_list (req, cli_op, dict,
-                                                err_str, sizeof (err_str));
+                                                     err_str, sizeof (err_str),
+                                                     &op_errno);
                 if (ret) {
                         gf_msg (this->name, GF_LOG_WARNING, 0,
                                 GD_MSG_SNAP_LIST_GET_FAIL,
@@ -8853,7 +8945,7 @@ glusterd_handle_snapshot_fn (rpcsvc_request_t *req)
                 break;
         case GF_SNAP_OPTION_TYPE_DELETE:
                 ret = glusterd_handle_snapshot_delete (req, cli_op, dict,
-                                                       err_str,
+                                                       err_str, &op_errno,
                                                        sizeof (err_str));
                 if (ret) {
                         gf_msg (this->name, GF_LOG_WARNING, 0,
@@ -8901,7 +8993,11 @@ out:
                 if (err_str[0] == '\0')
                         snprintf (err_str, sizeof (err_str),
                                   "Operation failed");
-                ret = glusterd_op_send_cli_response (cli_op, ret, 0, req,
+
+                if (ret && (op_errno == 0))
+                        op_errno = EG_INTRNL;
+
+                ret = glusterd_op_send_cli_response (cli_op, ret, op_errno, req,
                                                      dict, err_str);
         }
 
diff --git a/xlators/mgmt/glusterd/src/glusterd-syncop.c b/xlators/mgmt/glusterd/src/glusterd-syncop.c
index d7d75bb..da12cba 100644
--- a/xlators/mgmt/glusterd/src/glusterd-syncop.c
+++ b/xlators/mgmt/glusterd/src/glusterd-syncop.c
@@ -22,6 +22,7 @@
 #include "glusterd-locks.h"
 #include "glusterd-snapshot-utils.h"
 #include "glusterd-messages.h"
+#include "glusterd-errno.h"
 
 extern glusterd_op_info_t opinfo;
 
@@ -1883,8 +1884,8 @@ out:
                                 uuid_utoa (*txn_id));
         }
 
-        if (ret && (op_errno == 0))
-                op_errno = -1;
+        if (op_ret && (op_errno == 0))
+                op_errno = EG_INTRNL;
 
         glusterd_op_send_cli_response (op, op_ret, op_errno, req,
                                        op_ctx, op_errstr);
diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h
index 5b5edfd..59234bc 100644
--- a/xlators/mgmt/glusterd/src/glusterd.h
+++ b/xlators/mgmt/glusterd/src/glusterd.h
@@ -1096,11 +1096,12 @@ glusterd_find_snap_by_id (uuid_t snap_id);
 
 int
 glusterd_snapshot_prevalidate (dict_t *dict, char **op_errstr,
-                               dict_t *rsp_dict);
+                               dict_t *rsp_dict, uint32_t *op_errno);
 int
 glusterd_snapshot_brickop (dict_t *dict, char **op_errstr, dict_t *rsp_dict);
 int
-glusterd_snapshot (dict_t *dict, char **op_errstr, dict_t *rsp_dict);
+glusterd_snapshot (dict_t *dict, char **op_errstr,
+                   uint32_t *op_errno, dict_t *rsp_dict);
 int
 glusterd_snapshot_postvalidate (dict_t *dict, int32_t op_ret, char **op_errstr,
                                 dict_t *rsp_dict);
-- 
1.7.1