From 4bd4b0a9437189cef439833a0ed70005db9f8409 Mon Sep 17 00:00:00 2001 From: Atin Mukherjee Date: Wed, 3 Apr 2019 08:27:05 +0530 Subject: glusterd: remove redundant glusterd_check_volume_exists () calls A pattern of following was found in multiple places where both glusterd_check_volume_exists and glusterd_volinfo_find do the same job. We just need one of them not both. In a scaled environment having many volumes this is a bottleneck to iterate over the volume list to find a volume twice! exists = glusterd_check_volume_exists(volname); ret = glusterd_volinfo_find(volname, &volinfo); if ((ret) || (!exists)) { Credits: ykaul@redhat.com for finding this out Updates: bz#1193929 Change-Id: Ie116fe5c93e261a2bddd267c28ccb20a2884a36f Signed-off-by: Atin Mukherjee --- xlators/mgmt/glusterd/src/glusterd-volume-ops.c | 32 +------------------------ 1 file changed, 1 insertion(+), 31 deletions(-) (limited to 'xlators/mgmt/glusterd/src/glusterd-volume-ops.c') diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c index f9c7a2d70e9..5e8673640b6 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c +++ b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c @@ -1173,8 +1173,6 @@ glusterd_op_stage_create_volume(dict_t *dict, char **op_errstr, snprintf(msg, sizeof(msg), "Volume %s already exists", volname); ret = -1; goto out; - } else { - ret = 0; } ret = dict_get_int32n(dict, "count", SLEN("count"), &brick_count); @@ -1428,7 +1426,6 @@ glusterd_op_stage_start_volume(dict_t *dict, char **op_errstr, dict_t *rsp_dict) int flags = 0; int32_t brick_count = 0; int32_t local_brick_count = 0; - gf_boolean_t exists = _gf_false; glusterd_volinfo_t *volinfo = NULL; glusterd_brickinfo_t *brickinfo = NULL; char msg[2048] = { @@ -1458,16 +1455,9 @@ glusterd_op_stage_start_volume(dict_t *dict, char **op_errstr, dict_t *rsp_dict) if (ret) goto out; - exists = glusterd_check_volume_exists(volname); - - if (!exists) { - snprintf(msg, sizeof(msg), FMTSTR_CHECK_VOL_EXISTS, volname); - ret = -1; - goto out; - } - ret = glusterd_volinfo_find(volname, &volinfo); if (ret) { + snprintf(msg, sizeof(msg), FMTSTR_CHECK_VOL_EXISTS, volname); gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_VOLINFO_GET_FAIL, FMTSTR_CHECK_VOL_EXISTS, volname); goto out; @@ -1637,7 +1627,6 @@ glusterd_op_stage_stop_volume(dict_t *dict, char **op_errstr) int ret = -1; char *volname = NULL; int flags = 0; - gf_boolean_t exists = _gf_false; glusterd_volinfo_t *volinfo = NULL; char msg[2048] = {0}; xlator_t *this = NULL; @@ -1652,15 +1641,6 @@ glusterd_op_stage_stop_volume(dict_t *dict, char **op_errstr) if (ret) goto out; - exists = glusterd_check_volume_exists(volname); - - if (!exists) { - snprintf(msg, sizeof(msg), FMTSTR_CHECK_VOL_EXISTS, volname); - gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_VOL_NOT_FOUND, "%s", msg); - ret = -1; - goto out; - } - ret = glusterd_volinfo_find(volname, &volinfo); if (ret) { snprintf(msg, sizeof(msg), FMTSTR_CHECK_VOL_EXISTS, volname); @@ -1717,7 +1697,6 @@ glusterd_op_stage_delete_volume(dict_t *dict, char **op_errstr) { int ret = 0; char *volname = NULL; - gf_boolean_t exists = _gf_false; glusterd_volinfo_t *volinfo = NULL; char msg[2048] = {0}; xlator_t *this = NULL; @@ -1732,15 +1711,6 @@ glusterd_op_stage_delete_volume(dict_t *dict, char **op_errstr) goto out; } - exists = glusterd_check_volume_exists(volname); - if (!exists) { - snprintf(msg, sizeof(msg), FMTSTR_CHECK_VOL_EXISTS, volname); - ret = -1; - goto out; - } else { - ret = 0; - } - ret = glusterd_volinfo_find(volname, &volinfo); if (ret) { snprintf(msg, sizeof(msg), FMTSTR_CHECK_VOL_EXISTS, volname); -- cgit