From 08086c1c631bc8c1336452c9cd270f1191721b18 Mon Sep 17 00:00:00 2001 From: Nandaja Varma Date: Thu, 12 Mar 2015 16:55:20 +0530 Subject: handshake,locks,mountbroker,syncop/glusterd:New logging framework Backport of http://review.gluster.org/#/c/9864/ (cherry picked from commit 40795d95697068a0beb52364b97818dc80e49440) >Change-Id: If491a6945b7a0afa10165ff9f9874a244aece36f >BUG: 1194640 >Signed-off-by: Nandaja Varma >Reviewed-on: http://review.gluster.org/9864 >Tested-by: Gluster Build System >Tested-by: NetBSD Build System >Reviewed-by: Atin Mukherjee Change-Id: If491a6945b7a0afa10165ff9f9874a244aece36f BUG: 1217722 Signed-off-by: Nandaja Varma Reviewed-on: http://review.gluster.org/11192 Tested-by: Gluster Build System Reviewed-by: Atin Mukherjee Tested-by: Atin Mukherjee --- xlators/mgmt/glusterd/src/glusterd-locks.c | 105 ++++++++++++++++++----------- 1 file changed, 65 insertions(+), 40 deletions(-) (limited to 'xlators/mgmt/glusterd/src/glusterd-locks.c') diff --git a/xlators/mgmt/glusterd/src/glusterd-locks.c b/xlators/mgmt/glusterd/src/glusterd-locks.c index bafdc537122..a16e499df68 100644 --- a/xlators/mgmt/glusterd/src/glusterd-locks.c +++ b/xlators/mgmt/glusterd/src/glusterd-locks.c @@ -24,6 +24,7 @@ #include "glusterd-errno.h" #include "run.h" #include "syscall.h" +#include "glusterd-messages.h" #include @@ -113,7 +114,8 @@ glusterd_get_mgmt_v3_lock_owner (char *key, uuid_t *uuid) GF_ASSERT (priv); if (!key || !uuid) { - gf_log (this->name, GF_LOG_ERROR, "key or uuid is null."); + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + GD_MSG_INVALID_ENTRY, "key or uuid is null."); ret = -1; goto out; } @@ -126,7 +128,7 @@ glusterd_get_mgmt_v3_lock_owner (char *key, uuid_t *uuid) ret = 0; out: - gf_log (this->name, GF_LOG_TRACE, "Returning %d", ret); + gf_msg_trace (this->name, 0, "Returning %d", ret); return ret; } @@ -150,7 +152,7 @@ glusterd_release_multiple_locks_per_entity (dict_t *dict, uuid_t uuid, GF_ASSERT (type); if (locked_count == 0) { - gf_log (this->name, GF_LOG_DEBUG, + gf_msg_debug (this->name, 0, "No %s locked as part of this transaction", type); goto out; @@ -165,7 +167,8 @@ glusterd_release_multiple_locks_per_entity (dict_t *dict, uuid_t uuid, * as key in the dict snapname2 */ ret = dict_get_str (dict, name_buf, &name); if (ret) { - gf_log (this->name, GF_LOG_ERROR, + gf_msg (this->name, GF_LOG_ERROR, 0, + GD_MSG_DICT_GET_FAILED, "Unable to get %s locked_count = %d", name_buf, locked_count); op_ret = ret; @@ -174,7 +177,8 @@ glusterd_release_multiple_locks_per_entity (dict_t *dict, uuid_t uuid, ret = glusterd_mgmt_v3_unlock (name, uuid, type); if (ret) { - gf_log (this->name, GF_LOG_ERROR, + gf_msg (this->name, GF_LOG_ERROR, 0, + GD_MSG_MGMTV3_UNLOCK_FAIL, "Failed to release lock for %s.", name); op_ret = ret; @@ -182,7 +186,7 @@ glusterd_release_multiple_locks_per_entity (dict_t *dict, uuid_t uuid, } out: - gf_log (this->name, GF_LOG_TRACE, "Returning %d", op_ret); + gf_msg_trace (this->name, 0, "Returning %d", op_ret); return op_ret; } @@ -216,7 +220,8 @@ glusterd_acquire_multiple_locks_per_entity (dict_t *dict, uuid_t uuid, * as key in the dict snapname2 */ ret = dict_get_str (dict, name_buf, &name); if (ret) { - gf_log (this->name, GF_LOG_ERROR, + gf_msg (this->name, GF_LOG_ERROR, 0, + GD_MSG_DICT_GET_FAILED, "Unable to get %s count = %d", name_buf, count); break; @@ -224,7 +229,8 @@ glusterd_acquire_multiple_locks_per_entity (dict_t *dict, uuid_t uuid, ret = glusterd_mgmt_v3_lock (name, uuid, op_errno, type); if (ret) { - gf_log (this->name, GF_LOG_ERROR, + gf_msg (this->name, GF_LOG_ERROR, 0, + GD_MSG_MGMTV3_LOCK_GET_FAIL, "Failed to acquire lock for %s %s " "on behalf of %s. Reversing " "this transaction", type, name, @@ -245,13 +251,14 @@ glusterd_acquire_multiple_locks_per_entity (dict_t *dict, uuid_t uuid, locked_count, type); if (ret) { - gf_log (this->name, GF_LOG_ERROR, + gf_msg (this->name, GF_LOG_ERROR, 0, + GD_MSG_MULTIPLE_LOCK_RELEASE_FAIL, "Failed to release multiple %s locks", type); } ret = -1; out: - gf_log (this->name, GF_LOG_TRACE, "Returning %d", ret); + gf_msg_trace (this->name, 0, "Returning %d", ret); return ret; } @@ -295,14 +302,16 @@ glusterd_mgmt_v3_unlock_entity (dict_t *dict, uuid_t uuid, char *type, type); ret = dict_get_str (dict, name_buf, &name); if (ret) { - gf_log (this->name, GF_LOG_ERROR, + gf_msg (this->name, GF_LOG_ERROR, 0, + GD_MSG_DICT_GET_FAILED, "Unable to fetch %sname", type); goto out; } ret = glusterd_mgmt_v3_unlock (name, uuid, type); if (ret) { - gf_log (this->name, GF_LOG_ERROR, + gf_msg (this->name, GF_LOG_ERROR, 0, + GD_MSG_MGMTV3_UNLOCK_FAIL, "Failed to release lock for %s %s " "on behalf of %s.", type, name, uuid_utoa(uuid)); @@ -315,7 +324,8 @@ glusterd_mgmt_v3_unlock_entity (dict_t *dict, uuid_t uuid, char *type, count, type); if (ret) { - gf_log (this->name, GF_LOG_ERROR, + gf_msg (this->name, GF_LOG_ERROR, 0, + GD_MSG_MULTIPLE_LOCK_RELEASE_FAIL, "Failed to release all %s locks", type); goto out; } @@ -323,7 +333,7 @@ glusterd_mgmt_v3_unlock_entity (dict_t *dict, uuid_t uuid, char *type, ret = 0; out: - gf_log (this->name, GF_LOG_TRACE, "Returning %d", ret); + gf_msg_trace (this->name, 0, "Returning %d", ret); return ret; } @@ -366,14 +376,16 @@ glusterd_mgmt_v3_lock_entity (dict_t *dict, uuid_t uuid, uint32_t *op_errno, type); ret = dict_get_str (dict, name_buf, &name); if (ret) { - gf_log (this->name, GF_LOG_ERROR, + gf_msg (this->name, GF_LOG_ERROR, 0, + GD_MSG_DICT_GET_FAILED, "Unable to fetch %sname", type); goto out; } ret = glusterd_mgmt_v3_lock (name, uuid, op_errno, type); if (ret) { - gf_log (this->name, GF_LOG_ERROR, + gf_msg (this->name, GF_LOG_ERROR, 0, + GD_MSG_MGMTV3_LOCK_GET_FAIL, "Failed to acquire lock for %s %s " "on behalf of %s.", type, name, uuid_utoa(uuid)); @@ -387,7 +399,8 @@ glusterd_mgmt_v3_lock_entity (dict_t *dict, uuid_t uuid, uint32_t *op_errno, count, type); if (ret) { - gf_log (this->name, GF_LOG_ERROR, + gf_msg (this->name, GF_LOG_ERROR, 0, + GD_MSG_MULTIPLE_LOCK_ACQUIRE_FAIL, "Failed to acquire all %s locks", type); goto out; } @@ -395,7 +408,7 @@ glusterd_mgmt_v3_lock_entity (dict_t *dict, uuid_t uuid, uint32_t *op_errno, ret = 0; out: - gf_log (this->name, GF_LOG_TRACE, "Returning %d", ret); + gf_msg_trace (this->name, 0, "Returning %d", ret); return ret; } @@ -413,7 +426,8 @@ glusterd_multiple_mgmt_v3_unlock (dict_t *dict, uuid_t uuid) GF_ASSERT(this); if (!dict) { - gf_log (this->name, GF_LOG_ERROR, "dict is null."); + gf_msg (this->name, GF_LOG_ERROR, 0, + GD_MSG_DICT_EMPTY, "dict is null."); ret = -1; goto out; } @@ -424,7 +438,8 @@ glusterd_multiple_mgmt_v3_unlock (dict_t *dict, uuid_t uuid) valid_types[i].type, valid_types[i].default_value); if (ret) { - gf_log (this->name, GF_LOG_ERROR, + gf_msg (this->name, GF_LOG_ERROR, 0, + GD_MSG_MULTIPLE_LOCK_RELEASE_FAIL, "Unable to unlock all %s", valid_types[i].type); op_ret = ret; @@ -433,7 +448,7 @@ glusterd_multiple_mgmt_v3_unlock (dict_t *dict, uuid_t uuid) ret = op_ret; out: - gf_log (this->name, GF_LOG_DEBUG, "Returning %d", ret); + gf_msg_debug (this->name, 0, "Returning %d", ret); return ret; } @@ -451,7 +466,8 @@ glusterd_multiple_mgmt_v3_lock (dict_t *dict, uuid_t uuid, uint32_t *op_errno) GF_ASSERT(this); if (!dict) { - gf_log (this->name, GF_LOG_ERROR, "dict is null."); + gf_msg (this->name, GF_LOG_ERROR, 0, + GD_MSG_DICT_EMPTY, "dict is null."); ret = -1; goto out; } @@ -463,7 +479,8 @@ glusterd_multiple_mgmt_v3_lock (dict_t *dict, uuid_t uuid, uint32_t *op_errno) valid_types[i].type, valid_types[i].default_value); if (ret) { - gf_log (this->name, GF_LOG_ERROR, + gf_msg (this->name, GF_LOG_ERROR, 0, + GD_MSG_MULTIPLE_LOCK_ACQUIRE_FAIL, "Unable to lock all %s", valid_types[i].type); break; @@ -484,14 +501,15 @@ glusterd_multiple_mgmt_v3_lock (dict_t *dict, uuid_t uuid, uint32_t *op_errno) valid_types[i].type, valid_types[i].default_value); if (ret) { - gf_log (this->name, GF_LOG_ERROR, + gf_msg (this->name, GF_LOG_ERROR, 0, + GD_MSG_MULTIPLE_LOCK_RELEASE_FAIL, "Unable to unlock all %s", valid_types[i].type); } } ret = -1; out: - gf_log (this->name, GF_LOG_DEBUG, "Returning %d", ret); + gf_msg_debug (this->name, 0, "Returning %d", ret); return ret; } @@ -515,7 +533,8 @@ glusterd_mgmt_v3_lock (const char *name, uuid_t uuid, uint32_t *op_errno, GF_ASSERT (priv); if (!name || !type) { - gf_log (this->name, GF_LOG_ERROR, "name or type is null."); + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + GD_MSG_INVALID_ENTRY, "name or type is null."); ret = -1; goto out; } @@ -532,17 +551,18 @@ glusterd_mgmt_v3_lock (const char *name, uuid_t uuid, uint32_t *op_errno, ret = snprintf (key, sizeof(key), "%s_%s", name, type); if (ret != strlen(name) + 1 + strlen(type)) { ret = -1; - gf_log (this->name, GF_LOG_ERROR, "Unable to create key"); + gf_msg (this->name, GF_LOG_ERROR, 0, + GD_MSG_CREATE_KEY_FAIL, "Unable to create key"); goto out; } - gf_log (this->name, GF_LOG_DEBUG, + gf_msg_debug (this->name, 0, "Trying to acquire lock of %s %s for %s as %s", type, name, uuid_utoa (uuid), key); ret = glusterd_get_mgmt_v3_lock_owner (key, &owner); if (ret) { - gf_log (this->name, GF_LOG_DEBUG, + gf_msg_debug (this->name, 0, "Unable to get mgmt_v3 lock owner"); goto out; } @@ -570,7 +590,8 @@ glusterd_mgmt_v3_lock (const char *name, uuid_t uuid, uint32_t *op_errno, ret = dict_set_bin (priv->mgmt_v3_lock, key, lock_obj, sizeof(glusterd_mgmt_v3_lock_obj)); if (ret) { - gf_log (this->name, GF_LOG_ERROR, + gf_msg (this->name, GF_LOG_ERROR, 0, + GD_MSG_DICT_SET_FAILED, "Unable to set lock owner in mgmt_v3 lock"); if (lock_obj) GF_FREE (lock_obj); @@ -583,19 +604,20 @@ glusterd_mgmt_v3_lock (const char *name, uuid_t uuid, uint32_t *op_errno, name, type); ret = dict_set_dynstr_with_alloc (priv->mgmt_v3_lock, key, bt); if (ret) - gf_log (this->name, GF_LOG_WARNING, "Failed to save " + gf_msg (this->name, GF_LOG_WARNING, 0, + GD_MSG_DICT_SET_FAILED, "Failed to save " "the back trace for lock %s-%s granted to %s", name, type, uuid_utoa (uuid)); ret = 0; } - gf_log (this->name, GF_LOG_DEBUG, + gf_msg_debug (this->name, 0, "Lock for %s %s successfully held by %s", type, name, uuid_utoa (uuid)); ret = 0; out: - gf_log (this->name, GF_LOG_TRACE, "Returning %d", ret); + gf_msg_trace (this->name, 0, "Returning %d", ret); return ret; } @@ -615,7 +637,8 @@ glusterd_mgmt_v3_unlock (const char *name, uuid_t uuid, char *type) GF_ASSERT (priv); if (!name || !type) { - gf_log (this->name, GF_LOG_ERROR, "name is null."); + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + GD_MSG_INVALID_ENTRY, "name is null."); ret = -1; goto out; } @@ -632,18 +655,19 @@ glusterd_mgmt_v3_unlock (const char *name, uuid_t uuid, char *type) ret = snprintf (key, sizeof(key), "%s_%s", name, type); if (ret != strlen(name) + 1 + strlen(type)) { - gf_log (this->name, GF_LOG_ERROR, "Unable to create key"); + gf_msg (this->name, GF_LOG_ERROR, 0, + GD_MSG_CREATE_KEY_FAIL, "Unable to create key"); ret = -1; goto out; } - gf_log (this->name, GF_LOG_DEBUG, + gf_msg_debug (this->name, 0, "Trying to release lock of %s %s for %s as %s", type, name, uuid_utoa (uuid), key); ret = glusterd_get_mgmt_v3_lock_owner (key, &owner); if (ret) { - gf_log (this->name, GF_LOG_DEBUG, + gf_msg_debug (this->name, 0, "Unable to get mgmt_v3 lock owner"); goto out; } @@ -672,19 +696,20 @@ glusterd_mgmt_v3_unlock (const char *name, uuid_t uuid, char *type) type); if (ret != strlen ("debug.last-success-bt-") + strlen (name) + strlen (type) + 1) { - gf_log (this->name, GF_LOG_ERROR, "Unable to create backtrace " + gf_msg (this->name, GF_LOG_ERROR, 0, + GD_MSG_CREATE_KEY_FAIL, "Unable to create backtrace " "key"); ret = -1; goto out; } dict_del (priv->mgmt_v3_lock, key); - gf_log (this->name, GF_LOG_DEBUG, + gf_msg_debug (this->name, 0, "Lock for %s %s successfully released", type, name); ret = 0; out: - gf_log (this->name, GF_LOG_TRACE, "Returning %d", ret); + gf_msg_trace (this->name, 0, "Returning %d", ret); return ret; } -- cgit