diff options
author | Avra Sengupta <asengupt@redhat.com> | 2015-05-05 18:08:25 +0530 |
---|---|---|
committer | Krishnan Parthasarathi <kparthas@redhat.com> | 2015-06-09 07:18:38 -0700 |
commit | 952ea9ae43d7668cf9661eb694757e17a2a6ae9e (patch) | |
tree | fdf91e44d69642e1c374b0ef374ed3f978544e5d /xlators/mgmt/glusterd/src/glusterd-snapshot.c | |
parent | 4b32816d226b04066b36f569ea34bebfff25d16e (diff) |
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: 1226117
Signed-off-by: Avra Sengupta <asengupt@redhat.com>
(cherry picked from commit 2df57ab7dc7b9d7deb0eebad96036149760d607b)
Reviewed-on: http://review.gluster.org/11042
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Rajesh Joseph <rjoseph@redhat.com>
Tested-by: NetBSD Build System <jenkins@build.gluster.org>
Reviewed-by: Krishnan Parthasarathi <kparthas@redhat.com>
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-snapshot.c')
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-snapshot.c | 176 |
1 files changed, 136 insertions, 40 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c index e5a7cac413b..668c26e3ff5 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); } |