diff options
author | Avra Sengupta <asengupt@redhat.com> | 2015-05-05 18:08:25 +0530 |
---|---|---|
committer | Krishnan Parthasarathi <kparthas@redhat.com> | 2015-06-02 02:59:34 -0700 |
commit | 2df57ab7dc7b9d7deb0eebad96036149760d607b (patch) | |
tree | 9bf8673e338dca506add2d00011fdc4fa2e186a0 | |
parent | 59981aeb1cd02dcc534ec43ec4ec5bca5cbbd1fb (diff) |
glusterd/snapshot: Return correct errno in events of failure - PATCH 2
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: 1212413
Signed-off-by: Avra Sengupta <asengupt@redhat.com>
Reviewed-on: http://review.gluster.org/10588
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Rajesh Joseph <rjoseph@redhat.com>
Reviewed-by: Krishnan Parthasarathi <kparthas@redhat.com>
-rwxr-xr-x | tests/basic/op_errnos.t | 38 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-errno.h | 18 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-locks.c | 2 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-mgmt-handler.c | 29 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-mgmt.c | 48 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-mgmt.h | 6 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c | 31 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-snapshot-utils.h | 6 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-snapshot.c | 176 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-syncop.c | 5 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd.h | 5 |
11 files changed, 272 insertions, 92 deletions
diff --git a/tests/basic/op_errnos.t b/tests/basic/op_errnos.t new file mode 100755 index 00000000000..8b16267cb50 --- /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 435b050c7da..55d44a5c6a1 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 394df68a0da..5a4e00f6774 100644 --- a/xlators/mgmt/glusterd/src/glusterd-locks.c +++ b/xlators/mgmt/glusterd/src/glusterd-locks.c @@ -549,7 +549,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 9ebaf00d32f..5b7f0fa3c25 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 954ff039085..f8e65acd2b5 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 e2eb94f86fd..a1f2d61686f 100644 --- a/xlators/mgmt/glusterd/src/glusterd-mgmt.h +++ b/xlators/mgmt/glusterd/src/glusterd-mgmt.h @@ -16,7 +16,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, @@ -24,7 +25,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 a2dbe0e5738..f0b4b815c16 100644 --- a/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c @@ -29,6 +29,7 @@ #include "glusterd-snapshot-utils.h" #include "glusterd-server-quorum.h" #include "glusterd-messages.h" +#include "glusterd-errno.h" /* * glusterd_snap_geo_rep_restore: @@ -2616,7 +2617,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, }; @@ -2625,6 +2627,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, @@ -2643,6 +2646,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; } @@ -2674,6 +2678,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: @@ -2684,7 +2689,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; @@ -2703,6 +2709,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, @@ -2730,6 +2737,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; } } @@ -2766,7 +2774,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; @@ -2790,7 +2799,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; @@ -2811,6 +2820,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, @@ -2851,6 +2861,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 @@ -2974,7 +2985,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 " @@ -2988,7 +3000,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; @@ -2997,6 +3009,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, @@ -3004,7 +3017,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, @@ -3016,7 +3028,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" @@ -3034,6 +3047,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; } @@ -3050,6 +3064,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 68906dcf59e..ce8d7d40731 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 d0216c0f82b..ce63bd2079b 100644 --- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c +++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c @@ -15,6 +15,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> @@ -927,7 +928,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; @@ -947,6 +948,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); @@ -961,6 +963,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; } @@ -1016,6 +1019,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; } @@ -1029,6 +1033,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; } @@ -1209,7 +1214,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; @@ -1232,6 +1238,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; @@ -1255,6 +1262,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; } } @@ -1273,6 +1281,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; } } @@ -1285,6 +1294,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; } } @@ -1302,6 +1312,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; } @@ -1319,6 +1330,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)) { @@ -1329,6 +1341,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; } @@ -1346,11 +1359,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; } @@ -1866,7 +1881,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] = ""; @@ -1880,6 +1895,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); @@ -1924,14 +1940,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; @@ -1945,6 +1968,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, @@ -1991,6 +2015,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; } @@ -2007,7 +2032,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 " @@ -2133,7 +2158,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; @@ -2150,6 +2175,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) { @@ -2168,6 +2194,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*/ @@ -2200,14 +2227,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, @@ -2231,7 +2263,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; @@ -2254,6 +2286,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) { @@ -2285,6 +2318,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; } @@ -2300,6 +2334,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; } @@ -2308,6 +2343,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; } @@ -2316,6 +2352,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; } @@ -2326,6 +2363,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; } @@ -2333,6 +2371,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; } @@ -2364,6 +2403,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; } @@ -2382,8 +2422,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, @@ -3713,7 +3759,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; @@ -3724,6 +3771,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); @@ -3744,6 +3792,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; } @@ -4178,7 +4227,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; @@ -4211,6 +4261,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; @@ -5148,7 +5199,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; @@ -5161,6 +5215,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, @@ -5180,6 +5236,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; } @@ -5226,11 +5283,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; @@ -5248,7 +5307,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; @@ -5262,6 +5322,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) { @@ -5274,6 +5335,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); @@ -5349,7 +5411,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; @@ -5379,6 +5441,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; @@ -5443,7 +5506,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; @@ -5456,6 +5520,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) { @@ -5467,7 +5532,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 " @@ -5487,7 +5553,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 " @@ -5497,6 +5564,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; @@ -5520,7 +5588,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; @@ -5528,6 +5596,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, @@ -5548,6 +5618,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; } @@ -5569,7 +5640,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; @@ -5582,9 +5653,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"); @@ -5617,6 +5689,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; } @@ -5643,6 +5716,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; } @@ -5659,6 +5733,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; } } @@ -6435,7 +6510,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; @@ -6456,6 +6531,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); @@ -7854,7 +7930,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; @@ -7869,6 +7946,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); @@ -7885,7 +7963,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 " @@ -8115,7 +8193,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; @@ -8126,6 +8204,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) { @@ -8138,7 +8217,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 " @@ -8149,7 +8228,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, @@ -8161,7 +8240,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 " @@ -8172,6 +8252,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, @@ -8183,7 +8264,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 " @@ -8193,7 +8277,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, @@ -8203,7 +8290,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 " @@ -8214,7 +8301,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 " @@ -8226,6 +8313,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; } @@ -8704,6 +8792,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); @@ -8763,6 +8852,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, @@ -8811,7 +8901,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, @@ -8830,7 +8921,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, @@ -8848,7 +8940,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, @@ -8896,7 +8988,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 d7d75bbc1f1..da12cba39da 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 8dc0500a36d..a4b0bfdf1a1 100644 --- a/xlators/mgmt/glusterd/src/glusterd.h +++ b/xlators/mgmt/glusterd/src/glusterd.h @@ -1088,11 +1088,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); |