summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src/glusterd-utils.h
diff options
context:
space:
mode:
authorYaniv Kaul <ykaul@redhat.com>2019-11-03 15:21:05 +0200
committerAtin Mukherjee <amukherj@redhat.com>2019-11-29 13:38:00 +0000
commitb35f8addc6b582a2498dfae546fbb942964c66b3 (patch)
tree976334ed6816d04c62833fa1c421ef58743017e9 /xlators/mgmt/glusterd/src/glusterd-utils.h
parent1bfb0a750c6fcd0bbf4d68a1890704f0aefe6337 (diff)
glusterd-op-sm.c (and others) - improve glusterd_op_stage_set_volume()
Multiple changes to the function in the hope to make it somewhat faster. 1. Checking for key length against constant strings before calling strcmp() to save some calls. 2. Verifying if a match was already made against the key to reduce yet more checks. 3. Alignment of error message when they can fit on less lines - just makes 'grep' on the code for error messages easier and it's more readable. 4. Multiple functions where call _gd_get_vmep() one by one. Instead, extracted it to be callable (it was static) and re-used its result, instead of calling it again and again. 5. Removed some unneeded include statement. 6. Removed redundant null checks. Hopefully, no functional changes. Change-Id: Id281224e49adeca6757f96653b4cb13c7c9ba8c9 updates: bz#1193929 Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-utils.h')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.h28
1 files changed, 13 insertions, 15 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h
index c6a7545f4eb..7ee59848c5e 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.h
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.h
@@ -42,35 +42,33 @@
#define ALL_VOLUME_OPTION_CHECK(volname, get_opt, key, ret, op_errstr, label) \
do { \
gf_boolean_t _all = !strcmp("all", volname); \
+ gf_boolean_t _key_all = !strcmp(key, "all"); \
gf_boolean_t _is_valid_opt = _gf_false; \
int32_t i = 0; \
\
- if (!get_opt && (!strcmp(key, "all") || \
- !strcmp(key, GLUSTERD_MAX_OP_VERSION_KEY))) { \
+ if (!get_opt && \
+ (_key_all || !strcmp(key, GLUSTERD_MAX_OP_VERSION_KEY))) { \
ret = -1; \
*op_errstr = gf_strdup("Not a valid option to set"); \
goto out; \
} \
- \
- for (i = 0; valid_all_vol_opts[i].option; i++) { \
- if (!strcmp(key, "all") || \
- !strcmp(key, valid_all_vol_opts[i].option)) { \
- _is_valid_opt = _gf_true; \
- break; \
+ if (_key_all) { \
+ _is_valid_opt = _gf_true; \
+ } else { \
+ for (i = 0; valid_all_vol_opts[i].option; i++) { \
+ if (!strcmp(key, valid_all_vol_opts[i].option)) { \
+ _is_valid_opt = _gf_true; \
+ break; \
+ } \
} \
} \
- \
if (_all && !_is_valid_opt) { \
ret = -1; \
- *op_errstr = gf_strdup( \
- "Not a valid option for all " \
- "volumes"); \
+ *op_errstr = gf_strdup("Not a valid option for all volumes"); \
goto label; \
} else if (!_all && _is_valid_opt) { \
ret = -1; \
- *op_errstr = gf_strdup( \
- "Not a valid option for " \
- "single volume"); \
+ *op_errstr = gf_strdup("Not a valid option for single volume"); \
goto label; \
} \
} while (0)