From d68e426263708334945dff69b88218ed71a48033 Mon Sep 17 00:00:00 2001 From: Yaniv Kaul Date: Sat, 8 Jun 2019 01:22:27 +0300 Subject: Multiple files: get trivial stuff done before lock Initialize a dictionary for example seems to be prefectly fine to be done before taking a lock. Change-Id: Ib29516c4efa8f0e2b526d512beab488fcd16d2e7 updates: bz#1193929 Signed-off-by: Yaniv Kaul --- xlators/cluster/afr/src/afr-common.c | 10 ++++------ xlators/cluster/dht/src/dht-rebalance.c | 2 +- xlators/features/barrier/src/barrier.c | 2 +- xlators/features/quiesce/src/quiesce.c | 3 ++- xlators/features/quota/src/quota.c | 9 ++++----- xlators/storage/posix/src/posix-helpers.c | 22 ++++++++++++++-------- 6 files changed, 26 insertions(+), 22 deletions(-) (limited to 'xlators') diff --git a/xlators/cluster/afr/src/afr-common.c b/xlators/cluster/afr/src/afr-common.c index bce0af5791a..a1d9148915b 100644 --- a/xlators/cluster/afr/src/afr-common.c +++ b/xlators/cluster/afr/src/afr-common.c @@ -5052,20 +5052,18 @@ __afr_launch_notify_timer(xlator_t *this, afr_private_t *priv) } } -int +static int __get_heard_from_all_status(xlator_t *this) { afr_private_t *priv = this->private; - int heard_from_all = 1; - int i = 0; + int i; for (i = 0; i < priv->child_count; i++) { if (!priv->last_event[i]) { - heard_from_all = 0; - break; + return 0; } } - return heard_from_all; + return 1; } static int diff --git a/xlators/cluster/dht/src/dht-rebalance.c b/xlators/cluster/dht/src/dht-rebalance.c index ea63c3c5e74..ab4b7715b66 100644 --- a/xlators/cluster/dht/src/dht-rebalance.c +++ b/xlators/cluster/dht/src/dht-rebalance.c @@ -4787,9 +4787,9 @@ out: dht_send_rebalance_event(this, defrag->cmd, defrag->defrag_status); + status = dict_new(); LOCK(&defrag->lock); { - status = dict_new(); gf_defrag_status_get(conf, status); if (ctx && ctx->notify) ctx->notify(GF_EN_DEFRAG_STATUS, status); diff --git a/xlators/features/barrier/src/barrier.c b/xlators/features/barrier/src/barrier.c index a601c7fa04f..852bbacb99d 100644 --- a/xlators/features/barrier/src/barrier.c +++ b/xlators/features/barrier/src/barrier.c @@ -729,10 +729,10 @@ barrier_dump_priv(xlator_t *this) gf_proc_dump_build_key(key, "xlator.features.barrier", "priv"); gf_proc_dump_add_section("%s", key); + gf_proc_dump_build_key(key, "barrier", "enabled"); LOCK(&priv->lock); { - gf_proc_dump_build_key(key, "barrier", "enabled"); gf_proc_dump_write(key, "%d", priv->barrier_enabled); gf_proc_dump_build_key(key, "barrier", "timeout"); gf_proc_dump_write(key, "%ld", priv->timeout.tv_sec); diff --git a/xlators/features/quiesce/src/quiesce.c b/xlators/features/quiesce/src/quiesce.c index 5b24f181eff..0e5eb60a16f 100644 --- a/xlators/features/quiesce/src/quiesce.c +++ b/xlators/features/quiesce/src/quiesce.c @@ -89,11 +89,12 @@ gf_quiesce_populate_failover_hosts(xlator_t *this, quiesce_priv_t *priv, if (!dup_val) goto out; + addr_tok = strtok_r(dup_val, ",", &save_ptr); LOCK(&priv->lock); { if (!list_empty(&priv->failover_list)) __gf_quiesce_cleanup_failover_hosts(this, priv); - addr_tok = strtok_r(dup_val, ",", &save_ptr); + while (addr_tok) { if (!valid_internet_address(addr_tok, _gf_true, _gf_false)) { gf_msg(this->name, GF_LOG_INFO, 0, QUIESCE_MSG_INVAL_HOST, diff --git a/xlators/features/quota/src/quota.c b/xlators/features/quota/src/quota.c index c014c99cbd2..34dac481a64 100644 --- a/xlators/features/quota/src/quota.c +++ b/xlators/features/quota/src/quota.c @@ -560,15 +560,14 @@ quota_handle_validate_error(call_frame_t *frame, int32_t op_ret, if (local == NULL) goto out; - LOCK(&local->lock); - { - if (op_ret < 0) { + if (op_ret < 0) { + LOCK(&local->lock); + { local->op_ret = op_ret; local->op_errno = op_errno; } + UNLOCK(&local->lock); } - UNLOCK(&local->lock); - /* we abort checking limits on this path to root */ quota_link_count_decrement(frame); out: diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c index bb20a93f797..f35a992ffca 100644 --- a/xlators/storage/posix/src/posix-helpers.c +++ b/xlators/storage/posix/src/posix-helpers.c @@ -2956,7 +2956,7 @@ posix_check_internal_writes(xlator_t *this, fd_t *fd, int sysfd, dict_t *xdata) LOCK(&fd->inode->lock); { - val = dict_get(xdata, GF_PROTECT_FROM_EXTERNAL_WRITES); + val = dict_get_sizen(xdata, GF_PROTECT_FROM_EXTERNAL_WRITES); if (val) { ret = sys_fsetxattr(sysfd, GF_PROTECT_FROM_EXTERNAL_WRITES, val->data, val->len, 0); @@ -2969,7 +2969,7 @@ posix_check_internal_writes(xlator_t *this, fd_t *fd, int sysfd, dict_t *xdata) goto out; } - if (dict_get(xdata, GF_AVOID_OVERWRITE)) { + if (dict_get_sizen(xdata, GF_AVOID_OVERWRITE)) { xattrsize = sys_fgetxattr(sysfd, GF_PROTECT_FROM_EXTERNAL_WRITES, NULL, 0); if ((xattrsize == -1) && @@ -3344,14 +3344,20 @@ posix_cs_maintenance(xlator_t *this, fd_t *fd, loc_t *loc, int *pfd, { gf_cs_obj_state state = GF_CS_ERROR; int ret = 0; + gf_boolean_t is_cs_obj_status = _gf_false; + gf_boolean_t is_cs_obj_repair = _gf_false; - if (!(dict_get(xattr_req, GF_CS_OBJECT_STATUS) || - dict_get(xattr_req, GF_CS_OBJECT_REPAIR))) + if (dict_get_sizen(xattr_req, GF_CS_OBJECT_STATUS)) + is_cs_obj_status = _gf_true; + if (dict_get_sizen(xattr_req, GF_CS_OBJECT_REPAIR)) + is_cs_obj_repair = _gf_true; + + if (!(is_cs_obj_status || is_cs_obj_repair)) return 0; if (fd) { LOCK(&fd->inode->lock); - if (dict_get(xattr_req, GF_CS_OBJECT_STATUS)) { + if (is_cs_obj_status) { state = posix_cs_check_status(this, NULL, pfd, buf); gf_msg_debug(this->name, 0, "state : %d", state); ret = posix_cs_set_state(this, xattr_rsp, state, NULL, pfd); @@ -3371,7 +3377,7 @@ posix_cs_maintenance(xlator_t *this, fd_t *fd, loc_t *loc, int *pfd, } } - if (dict_get(xattr_req, GF_CS_OBJECT_REPAIR)) { + if (is_cs_obj_repair) { state = posix_cs_check_status(this, NULL, pfd, buf); gf_msg_debug(this->name, 0, "state : %d", state); @@ -3402,7 +3408,7 @@ posix_cs_maintenance(xlator_t *this, fd_t *fd, loc_t *loc, int *pfd, } LOCK(&loc->inode->lock); - if (dict_get(xattr_req, GF_CS_OBJECT_STATUS)) { + if (is_cs_obj_status) { state = posix_cs_check_status(this, realpath, NULL, buf); gf_msg_debug(this->name, 0, "state : %d", state); ret = posix_cs_set_state(this, xattr_rsp, state, realpath, NULL); @@ -3422,7 +3428,7 @@ posix_cs_maintenance(xlator_t *this, fd_t *fd, loc_t *loc, int *pfd, } } - if (dict_get(xattr_req, GF_CS_OBJECT_REPAIR)) { + if (is_cs_obj_repair) { state = posix_cs_check_status(this, realpath, NULL, buf); gf_msg_debug(this->name, 0, "state : %d", state); -- cgit