Blob Blame History Raw
From 658994a4914d8134c4c9f5a9273706c46d88360d Mon Sep 17 00:00:00 2001
From: Mohamed Ashiq <ashiq333@gmail.com>
Date: Tue, 19 May 2015 15:46:01 +0530
Subject: [PATCH 180/190] mem-pool,stack,store,syncop,timer/libglusterfs : Porting to a new logging framework

Change-Id: Idd3dcaf7eeea5207b3a5210676ce3df64153197f
BUG: 1231792
Signed-off-by: Mohamed Ashiq Liyazudeen <mliyazud@redhat.com>
Reviewed-on: http://review.gluster.org/10827
Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
Tested-by: NetBSD Build System <jenkins@build.gluster.org>
Reviewed-on: https://code.engineering.redhat.com/gerrit/51751
Tested-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
---
 libglusterfs/src/client_t.c              |   10 +-
 libglusterfs/src/libglusterfs-messages.h |    6 +-
 libglusterfs/src/mem-pool.c              |   36 +++++---
 libglusterfs/src/stack.c                 |   11 ++-
 libglusterfs/src/stack.h                 |   14 ++--
 libglusterfs/src/store.c                 |  139 ++++++++++++++++--------------
 libglusterfs/src/syncop-utils.c          |   21 +++--
 libglusterfs/src/syncop.c                |   91 +++++++++++---------
 libglusterfs/src/timer.c                 |   29 ++++--
 9 files changed, 202 insertions(+), 155 deletions(-)

diff --git a/libglusterfs/src/client_t.c b/libglusterfs/src/client_t.c
index b7462fc..035658f 100644
--- a/libglusterfs/src/client_t.c
+++ b/libglusterfs/src/client_t.c
@@ -595,7 +595,7 @@ clienttable_dump (clienttable_t *clienttable, char *prefix)
         {
                 if (ret) {
                         gf_msg ("client_t", GF_LOG_WARNING, 0,
-                                LG_MSG_LOCK_GAIN_FAILED,
+                                LG_MSG_LOCK_FAILED,
                                 "Unable to acquire lock");
                         return;
                 }
@@ -693,7 +693,7 @@ gf_client_dump_fdtables_to_dict (xlator_t *this, dict_t *dict)
         {
                 if (ret) {
                         gf_msg ("client_t", GF_LOG_WARNING, 0,
-                                LG_MSG_LOCK_GAIN_FAILED,
+                                LG_MSG_LOCK_FAILED,
                                 "Unable to acquire lock");
                         return -1;
                 }
@@ -736,7 +736,7 @@ gf_client_dump_fdtables (xlator_t *this)
         {
                 if (ret) {
                         gf_msg ("client_t", GF_LOG_WARNING, 0,
-                                LG_MSG_LOCK_GAIN_FAILED,
+                                LG_MSG_LOCK_FAILED,
                                 "Unable to acquire lock");
                         return -1;
                 }
@@ -802,7 +802,7 @@ gf_client_dump_inodes_to_dict (xlator_t *this, dict_t *dict)
         {
                 if (ret) {
                         gf_msg ("client_t", GF_LOG_WARNING, 0,
-                                LG_MSG_LOCK_GAIN_FAILED,
+                                LG_MSG_LOCK_FAILED,
                                 "Unable to acquire lock");
                         return -1;
                 }
@@ -864,7 +864,7 @@ gf_client_dump_inodes (xlator_t *this)
         {
                 if (ret) {
                         gf_msg ("client_t", GF_LOG_WARNING, 0,
-                                LG_MSG_LOCK_GAIN_FAILED,
+                                LG_MSG_LOCK_FAILED,
                                 "Unable to acquire lock");
                         goto out;
                 }
diff --git a/libglusterfs/src/libglusterfs-messages.h b/libglusterfs/src/libglusterfs-messages.h
index 8b8af36..25cca8b 100644
--- a/libglusterfs/src/libglusterfs-messages.h
+++ b/libglusterfs/src/libglusterfs-messages.h
@@ -145,7 +145,7 @@
  * @recommendedaction
  *
  */
-#define LG_MSG_LOCK_GAIN_FAILED                           (GLFS_LG_BASE + 14)
+#define LG_MSG_LOCK_FAILED                               (GLFS_LG_BASE + 14)
 
 /*!
  * @messageid
@@ -153,7 +153,7 @@
  * @recommendedaction
  *
  */
-#define LG_MSG_LOCK_RELEASE_FAILED                        (GLFS_LG_BASE + 15)
+#define LG_MSG_UNLOCK_FAILED                             (GLFS_LG_BASE + 15)
 
 /*!
  * @messageid
@@ -1198,7 +1198,7 @@
  *
  */
 
-#define LG_MSG_SWAP_FAILED                               (GLFS_LG_BASE + 137)
+#define LG_MSG_SWAPCONTEXT_FAILED                        (GLFS_LG_BASE + 137)
 
 /*!
  * @messageid
diff --git a/libglusterfs/src/mem-pool.c b/libglusterfs/src/mem-pool.c
index 7d95364..1ed1aba 100644
--- a/libglusterfs/src/mem-pool.c
+++ b/libglusterfs/src/mem-pool.c
@@ -25,6 +25,7 @@
 #define GLUSTERFS_ENV_MEM_ACCT_STR  "GLUSTERFS_DISABLE_MEM_ACCT"
 
 #include "unittest/unittest.h"
+#include "libglusterfs-messages.h"
 
 void
 gf_mem_acct_enable_set (void *data)
@@ -350,7 +351,8 @@ mem_pool_new_fn (unsigned long sizeof_type,
         glusterfs_ctx_t  *ctx = NULL;
 
         if (!sizeof_type || !count) {
-                gf_log_callingfn ("mem-pool", GF_LOG_ERROR, "invalid argument");
+                gf_msg_callingfn ("mem-pool", GF_LOG_ERROR, EINVAL,
+                                  LG_MSG_INVALID_ARG, "invalid argument");
                 return NULL;
         }
         padded_sizeof_type = sizeof_type + GF_MEM_POOL_PAD_BOUNDARY;
@@ -411,7 +413,8 @@ mem_get0 (struct mem_pool *mem_pool)
         void             *ptr = NULL;
 
         if (!mem_pool) {
-                gf_log_callingfn ("mem-pool", GF_LOG_ERROR, "invalid argument");
+                gf_msg_callingfn ("mem-pool", GF_LOG_ERROR, EINVAL,
+                                  LG_MSG_INVALID_ARG, "invalid argument");
                 return NULL;
         }
 
@@ -432,7 +435,8 @@ mem_get (struct mem_pool *mem_pool)
         struct mem_pool **pool_ptr = NULL;
 
         if (!mem_pool) {
-                gf_log_callingfn ("mem-pool", GF_LOG_ERROR, "invalid argument");
+                gf_msg_callingfn ("mem-pool", GF_LOG_ERROR, EINVAL,
+                                  LG_MSG_INVALID_ARG, "invalid argument");
                 return NULL;
         }
 
@@ -503,7 +507,8 @@ static int
 __is_member (struct mem_pool *pool, void *ptr)
 {
         if (!pool || !ptr) {
-                gf_log_callingfn ("mem-pool", GF_LOG_ERROR, "invalid argument");
+                gf_msg_callingfn ("mem-pool", GF_LOG_ERROR, EINVAL,
+                                  LG_MSG_INVALID_ARG, "invalid argument");
                 return -1;
         }
 
@@ -528,21 +533,24 @@ mem_put (void *ptr)
         struct mem_pool *pool = NULL;
 
         if (!ptr) {
-                gf_log_callingfn ("mem-pool", GF_LOG_ERROR, "invalid argument");
+                gf_msg_callingfn ("mem-pool", GF_LOG_ERROR, EINVAL,
+                                  LG_MSG_INVALID_ARG, "invalid argument");
                 return;
         }
 
         list = head = mem_pool_ptr2chunkhead (ptr);
         tmp = mem_pool_from_ptr (head);
         if (!tmp) {
-                gf_log_callingfn ("mem-pool", GF_LOG_ERROR,
+                gf_msg_callingfn ("mem-pool", GF_LOG_ERROR, 0,
+                                  LG_MSG_PTR_HEADER_CORRUPTED,
                                   "ptr header is corrupted");
                 return;
         }
 
         pool = *tmp;
         if (!pool) {
-                gf_log_callingfn ("mem-pool", GF_LOG_ERROR,
+                gf_msg_callingfn ("mem-pool", GF_LOG_ERROR, 0,
+                                  LG_MSG_MEMPOOL_PTR_NULL,
                                   "mem-pool ptr is NULL");
                 return;
         }
@@ -555,9 +563,12 @@ mem_put (void *ptr)
                         in_use = (head + GF_MEM_POOL_LIST_BOUNDARY +
                                   GF_MEM_POOL_PTR);
                         if (!is_mem_chunk_in_use(in_use)) {
-                                gf_log_callingfn ("mem-pool", GF_LOG_CRITICAL,
-                                                  "mem_put called on freed ptr %p of mem "
-                                                  "pool %p", ptr, pool);
+                                gf_msg_callingfn ("mem-pool", GF_LOG_CRITICAL,
+                                                  0,
+                                                  LG_MSG_MEMPOOL_INVALID_FREE,
+                                                  "mem_put called on freed ptr"
+                                                  " %p of mem pool %p", ptr,
+                                                  pool);
                                 break;
                         }
                         pool->hot_count--;
@@ -600,8 +611,9 @@ mem_pool_destroy (struct mem_pool *pool)
         if (!pool)
                 return;
 
-        gf_log (THIS->name, GF_LOG_INFO, "size=%lu max=%d total=%"PRIu64,
-                pool->padded_sizeof_type, pool->max_alloc, pool->alloc_count);
+        gf_msg (THIS->name, GF_LOG_INFO, 0, LG_MSG_MEM_POOL_DESTROY, "size=%lu "
+                "max=%d total=%"PRIu64, pool->padded_sizeof_type,
+                pool->max_alloc, pool->alloc_count);
 
         list_del (&pool->global_list);
 
diff --git a/libglusterfs/src/stack.c b/libglusterfs/src/stack.c
index a7fb951..12d5759 100644
--- a/libglusterfs/src/stack.c
+++ b/libglusterfs/src/stack.c
@@ -10,6 +10,7 @@
 
 #include "statedump.h"
 #include "stack.h"
+#include "libglusterfs-messages.h"
 
 static inline
 int call_frames_count (call_frame_t *call_frame)
@@ -46,8 +47,9 @@ create_frame (xlator_t *xl, call_pool_t *pool)
 
         if (stack->ctx->measure_latency) {
                 if (gettimeofday (&stack->tv, NULL) == -1)
-                        gf_log ("stack", GF_LOG_ERROR, "gettimeofday () failed."
-                                " (%s)", strerror (errno));
+                        gf_msg ("stack", GF_LOG_ERROR, errno,
+                                LG_MSG_GETTIMEOFDAY_FAILED,
+                                "gettimeofday () failed");
                 memcpy (&stack->frames.begin, &stack->tv, sizeof (stack->tv));
         }
 
@@ -399,8 +401,9 @@ gf_proc_dump_pending_frames_to_dict (call_pool_t *call_pool, dict_t *dict)
 
         ret = TRY_LOCK (&call_pool->lock);
         if (ret) {
-                gf_log (THIS->name, GF_LOG_WARNING, "Unable to dump call pool"
-                        " to dict. errno: %d", errno);
+                gf_msg (THIS->name, GF_LOG_WARNING, errno,
+                        LG_MSG_LOCK_FAILURE, "Unable to dump call "
+                        "pool to dict.");
                 return;
         }
 
diff --git a/libglusterfs/src/stack.h b/libglusterfs/src/stack.h
index f2d2ef9..38ca3ee 100644
--- a/libglusterfs/src/stack.h
+++ b/libglusterfs/src/stack.h
@@ -37,6 +37,7 @@ typedef struct call_pool call_pool_t;
 #include "globals.h"
 #include "lkowner.h"
 #include "client_t.h"
+#include "libglusterfs-messages.h"
 
 #define NFS_PID 1
 #define LOW_PRIO_PROC_PID -1
@@ -233,7 +234,6 @@ STACK_RESET (call_stack_t *stack)
                                                                         \
                 _new = mem_get0 (frame->root->pool->frame_mem_pool);    \
                 if (!_new) {                                            \
-                        gf_log ("stack", GF_LOG_ERROR, "alloc failed"); \
                         break;                                          \
                 }                                                       \
                 typeof(fn##_cbk) tmp_cbk = rfn;                         \
@@ -288,7 +288,6 @@ STACK_RESET (call_stack_t *stack)
                                                                         \
                 _new = mem_get0 (frame->root->pool->frame_mem_pool);    \
                 if (!_new) {                                            \
-                        gf_log ("stack", GF_LOG_ERROR, "alloc failed"); \
                         break;                                          \
                 }                                                       \
                 typeof(fn##_cbk) tmp_cbk = rfn;                         \
@@ -328,7 +327,8 @@ STACK_RESET (call_stack_t *stack)
                 call_frame_t *_parent = NULL;                           \
                 xlator_t     *old_THIS = NULL;                          \
                 if (!frame) {                                           \
-                        gf_log ("stack", GF_LOG_CRITICAL, "!frame");    \
+                        gf_msg ("stack", GF_LOG_CRITICAL, 0,            \
+                                LG_MSG_FRAME_ERROR, "!frame");          \
                         break;                                          \
                 }                                                       \
                 fn = frame->ret;                                        \
@@ -357,7 +357,8 @@ STACK_RESET (call_stack_t *stack)
                 xlator_t     *old_THIS = NULL;                          \
                                                                         \
                 if (!frame) {                                           \
-                        gf_log ("stack", GF_LOG_CRITICAL, "!frame");    \
+                        gf_msg ("stack", GF_LOG_CRITICAL, 0,            \
+                                LG_MSG_FRAME_ERROR, "!frame");          \
                         break;                                          \
                 }                                                       \
                 fn = (fop_##op##_cbk_t )frame->ret;                     \
@@ -435,8 +436,9 @@ copy_frame (call_frame_t *frame)
 
         if (newstack->ctx->measure_latency) {
                 if (gettimeofday (&newstack->tv, NULL) == -1)
-                        gf_log ("stack", GF_LOG_ERROR, "gettimeofday () failed."
-                                " (%s)", strerror (errno));
+                        gf_msg ("stack", GF_LOG_ERROR, errno,
+                                LG_MSG_GETTIMEOFDAY_FAILED,
+                                "gettimeofday () failed.");
                 memcpy (&newstack->frames.begin, &newstack->tv,
                         sizeof (newstack->tv));
         }
diff --git a/libglusterfs/src/store.c b/libglusterfs/src/store.c
index 351741f..7c8b29d 100644
--- a/libglusterfs/src/store.c
+++ b/libglusterfs/src/store.c
@@ -20,7 +20,7 @@
 #include "store.h"
 #include "dict.h"
 #include "xlator.h"
-
+#include "libglusterfs-messages.h"
 int32_t
 gf_store_mkdir (char *path)
 {
@@ -29,8 +29,8 @@ gf_store_mkdir (char *path)
         ret = mkdir (path, 0777);
 
         if ((-1 == ret) && (EEXIST != errno)) {
-                gf_log ("", GF_LOG_ERROR, "mkdir() failed on path %s,"
-                        "errno: %s", path, strerror (errno));
+                gf_msg ("", GF_LOG_ERROR, errno, LG_MSG_DIR_OP_FAILED, "mkdir()"
+                        " failed on path %s.", path);
         } else {
                 ret = 0;
         }
@@ -49,8 +49,9 @@ gf_store_handle_create_on_absence (gf_store_handle_t **shandle,
                 ret = gf_store_handle_new (path, shandle);
 
                 if (ret) {
-                        gf_log ("", GF_LOG_ERROR, "Unable to create store"
-                                " handle for path: %s", path);
+                        gf_msg ("", GF_LOG_ERROR, 0,
+                                LG_MSG_STORE_HANDLE_CREATE_FAILED, "Unable to"
+                                " create store handle for path: %s", path);
                 }
         }
         return ret;
@@ -67,8 +68,8 @@ gf_store_mkstemp (gf_store_handle_t *shandle)
         snprintf (tmppath, sizeof (tmppath), "%s.tmp", shandle->path);
         shandle->tmp_fd = open (tmppath, O_RDWR | O_CREAT | O_TRUNC, 0600);
         if (shandle->tmp_fd < 0) {
-                gf_log ("", GF_LOG_ERROR, "Failed to open %s, error: %s",
-                        tmppath, strerror (errno));
+                gf_msg ("", GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED,
+                        "Failed to open %s.", tmppath);
         }
 out:
         return shandle->tmp_fd;
@@ -92,15 +93,15 @@ gf_store_sync_direntry (char *path)
         pdir = dirname (dir);
         dirfd = open (pdir, O_RDONLY);
         if (dirfd == -1) {
-                gf_log (this->name, GF_LOG_ERROR, "Failed to open directory "
-                        "%s, due to %s", pdir, strerror (errno));
+                gf_msg (this->name, GF_LOG_ERROR, errno, LG_MSG_DIR_OP_FAILED,
+                        "Failed to open directory %s.", pdir);
                 goto out;
         }
 
         ret = fsync (dirfd);
         if (ret) {
-                gf_log (this->name, GF_LOG_ERROR, "Failed to fsync %s, due to "
-                        "%s", pdir, strerror (errno));
+                gf_msg (this->name, GF_LOG_ERROR, errno,
+                        LG_MSG_DIR_OP_FAILED, "Failed to fsync %s.", pdir);
                 goto out;
         }
 
@@ -109,8 +110,9 @@ out:
         if (dirfd >= 0) {
                 ret = close (dirfd);
                 if (ret) {
-                        gf_log (this->name, GF_LOG_ERROR, "Failed to close "
-                                "%s, due to %s", pdir, strerror (errno));
+                        gf_msg (this->name, GF_LOG_ERROR, errno,
+                                LG_MSG_DIR_OP_FAILED, "Failed to close %s",
+                                pdir);
                 }
         }
 
@@ -131,15 +133,16 @@ gf_store_rename_tmppath (gf_store_handle_t *shandle)
 
         ret = fsync (shandle->tmp_fd);
         if (ret) {
-                gf_log (THIS->name, GF_LOG_ERROR, "Failed to fsync %s, "
-                        "error: %s", shandle->path, strerror (errno));
+                gf_msg (THIS->name, GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED,
+                        "Failed to fsync %s", shandle->path);
                 goto out;
         }
         snprintf (tmppath, sizeof (tmppath), "%s.tmp", shandle->path);
         ret = rename (tmppath, shandle->path);
         if (ret) {
-                gf_log (THIS->name, GF_LOG_ERROR, "Failed to rename %s to %s, "
-                        "error: %s", tmppath, shandle->path, strerror (errno));
+                gf_msg (THIS->name, GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED,
+                        "Failed to rename %s to %s", tmppath,
+                        shandle->path);
                 goto out;
         }
 
@@ -164,8 +167,9 @@ gf_store_unlink_tmppath (gf_store_handle_t *shandle)
         snprintf (tmppath, sizeof (tmppath), "%s.tmp", shandle->path);
         ret = unlink (tmppath);
         if (ret && (errno != ENOENT)) {
-                gf_log ("", GF_LOG_ERROR, "Failed to mv %s to %s, error: %s",
-                        tmppath, shandle->path, strerror (errno));
+                gf_msg ("", GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED,
+                        "Failed to mv %s to %s", tmppath,
+                        shandle->path);
         } else {
                 ret = 0;
         }
@@ -248,8 +252,8 @@ gf_store_retrieve_value (gf_store_handle_t *handle, char *key, char **value)
                 lseek (handle->fd, 0, SEEK_SET);
 
         if (handle->fd == -1) {
-                gf_log ("", GF_LOG_ERROR, "Unable to open file %s errno: %s",
-                        handle->path, strerror (errno));
+                gf_msg ("", GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED,
+                        "Unable to open file %s", handle->path);
                 goto out;
         }
         if (!handle->read)
@@ -258,15 +262,15 @@ gf_store_retrieve_value (gf_store_handle_t *handle, char *key, char **value)
                 fseek (handle->read, 0, SEEK_SET);
 
         if (!handle->read) {
-                gf_log ("", GF_LOG_ERROR, "Unable to open file %s errno: %s",
-                        handle->path, strerror (errno));
+                gf_msg ("", GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED,
+                        "Unable to open file %s", handle->path);
                 goto out;
         }
 
         ret = fstat (handle->fd, &st);
         if (ret < 0) {
-                gf_log ("", GF_LOG_WARNING, "stat on file %s failed",
-                        handle->path);
+                gf_msg ("", GF_LOG_WARNING, errno, LG_MSG_FILE_OP_FAILED,
+                        "stat on file %s failed", handle->path);
                 ret = -1;
                 store_errno = GD_STORE_STAT_FAILED;
                 goto out;
@@ -292,16 +296,16 @@ gf_store_retrieve_value (gf_store_handle_t *handle, char *key, char **value)
                                                   &iter_key, &iter_val,
                                                   &store_errno);
                 if (ret < 0) {
-                        gf_log ("", GF_LOG_TRACE, "error while reading key "
-                                "'%s': %s", key,
-                                gf_store_strerror (store_errno));
+                        gf_msg_trace ("", 0, "error while reading key '%s': "
+                                      "%s", key,
+                                      gf_store_strerror (store_errno));
                         goto out;
                 }
 
-                gf_log ("", GF_LOG_TRACE, "key %s read", iter_key);
+                gf_msg_trace ("", 0, "key %s read", iter_key);
 
                 if (!strcmp (key, iter_key)) {
-                        gf_log ("", GF_LOG_DEBUG, "key %s found", key);
+                        gf_msg_debug ("", 0, "key %s found", key);
                         ret = 0;
                         if (iter_val)
                                 *value = gf_strdup (iter_val);
@@ -341,25 +345,25 @@ gf_store_save_value (int fd, char *key, char *value)
 
         fp = fdopen (dup_fd, "a+");
         if (fp == NULL) {
-                gf_log ("", GF_LOG_WARNING, "fdopen failed.");
+                gf_msg ("", GF_LOG_WARNING, errno, LG_MSG_FILE_OP_FAILED,
+                        "fdopen failed.");
                 ret = -1;
                 goto out;
         }
 
         ret = fprintf (fp, "%s=%s\n", key, value);
         if (ret < 0) {
-                gf_log ("", GF_LOG_WARNING, "Unable to store key: %s,"
-                        "value: %s, error: %s", key, value,
-                        strerror (errno));
+                gf_msg ("", GF_LOG_WARNING, errno, LG_MSG_FILE_OP_FAILED,
+                        "Unable to store key: %s, value: %s.",
+                        key, value);
                 ret = -1;
                 goto out;
         }
 
         ret = fflush (fp);
         if (feof (fp)) {
-                gf_log ("", GF_LOG_WARNING,
-                        "fflush failed, error: %s",
-                        strerror (errno));
+                gf_msg ("", GF_LOG_WARNING, errno, LG_MSG_FILE_OP_FAILED,
+                        "fflush failed.");
                 ret = -1;
                 goto out;
         }
@@ -369,7 +373,7 @@ out:
         if (fp)
                 fclose (fp);
 
-        gf_log ("", GF_LOG_DEBUG, "returning: %d", ret);
+        gf_msg_debug ("", 0, "returning: %d", ret);
         return ret;
 }
 
@@ -391,8 +395,8 @@ gf_store_handle_new (const char *path, gf_store_handle_t **handle)
 
         fd = open (path, O_RDWR | O_CREAT | O_APPEND, 0600);
         if (fd < 0) {
-                gf_log ("", GF_LOG_ERROR, "Failed to open file: %s, error: %s",
-                        path, strerror (errno));
+                gf_msg ("", GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED,
+                        "Failed to open file: %s.", path);
                 goto out;
         }
 
@@ -415,7 +419,7 @@ out:
                 GF_FREE (shandle);
         }
 
-        gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
+        gf_msg_debug ("", 0, "Returning %d", ret);
         return ret;
 }
 
@@ -427,14 +431,13 @@ gf_store_handle_retrieve (char *path, gf_store_handle_t **handle)
 
         ret = stat (path, &statbuf);
         if (ret) {
-                gf_log ("", GF_LOG_ERROR, "Path corresponding to "
-                        "%s, returned error: (%s)",
-                        path, strerror (errno));
+                gf_msg ("", GF_LOG_ERROR, errno, LG_MSG_PATH_NOT_FOUND, "Path "
+                        "corresponding to %s.", path);
                 goto out;
         }
         ret =  gf_store_handle_new (path, handle);
 out:
-        gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
+        gf_msg_debug ("", 0, "Returning %d", ret);
         return ret;
 }
 
@@ -455,7 +458,7 @@ gf_store_handle_destroy (gf_store_handle_t *handle)
         ret = 0;
 
 out:
-        gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
+        gf_msg_debug ("", 0, "Returning %d", ret);
 
         return ret;
 }
@@ -472,8 +475,8 @@ gf_store_iter_new (gf_store_handle_t  *shandle, gf_store_iter_t  **iter)
 
         fp = fopen (shandle->path, "r");
         if (!fp) {
-                gf_log ("", GF_LOG_ERROR, "Unable to open file %s errno: %d",
-                        shandle->path, errno);
+                gf_msg ("", GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED,
+                        "Unable to open file %s", shandle->path);
                 goto out;
         }
 
@@ -496,7 +499,7 @@ out:
 
         GF_FREE (tmp_iter);
 
-        gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret);
+        gf_msg_debug ("", 0, "Returning with %d", ret);
         return ret;
 }
 
@@ -511,19 +514,21 @@ gf_store_validate_key_value (char *storepath, char *key, char *val,
 
         if ((key == NULL) && (val == NULL)) {
                 ret = -1;
-                gf_log ("", GF_LOG_ERROR, "Glusterd store may be corrupted, "
-                        "Invalid key and value (null) in %s", storepath);
+                gf_msg ("", GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "Glusterd "
+                        "store may be corrupted, Invalid key and value (null)"
+                        " in %s", storepath);
                 *op_errno = GD_STORE_KEY_VALUE_NULL;
         } else if (key == NULL) {
                 ret = -1;
-                gf_log ("", GF_LOG_ERROR, "Glusterd store may be corrupted, "
-                        "Invalid key (null) in %s", storepath);
+                gf_msg ("", GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "Glusterd "
+                        "store may be corrupted, Invalid key (null) in %s",
+                        storepath);
                 *op_errno = GD_STORE_KEY_NULL;
         } else if (val == NULL) {
                 ret = -1;
-                gf_log ("", GF_LOG_ERROR, "Glusterd store may be corrupted, "
-                        "Invalid value (null) for key %s in %s", key,
-                        storepath);
+                gf_msg ("", GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "Glusterd "
+                        "store may be corrupted, Invalid value (null) for key"
+                        " %s in %s", key, storepath);
                 *op_errno = GD_STORE_VALUE_NULL;
         } else {
                 ret = 0;
@@ -550,7 +555,8 @@ gf_store_iter_get_next (gf_store_iter_t *iter, char  **key, char **value,
 
         ret = stat (iter->filepath, &st);
         if (ret < 0) {
-                gf_log ("", GF_LOG_WARNING, "stat on file failed");
+                gf_msg ("", GF_LOG_WARNING, errno, LG_MSG_FILE_OP_FAILED,
+                        "stat on file failed");
                 ret = -1;
                 store_errno = GD_STORE_STAT_FAILED;
                 goto out;
@@ -605,7 +611,7 @@ out:
         if (op_errno)
                 *op_errno = store_errno;
 
-        gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret);
+        gf_msg_debug ("", 0, "Returning with %d", ret);
         return ret;
 }
 
@@ -646,8 +652,9 @@ gf_store_iter_destroy (gf_store_iter_t *iter)
          * being NULL*/
         ret = fclose (iter->file);
         if (ret)
-                gf_log ("", GF_LOG_ERROR, "Unable to close file: %s, ret: %d, "
-                        "errno: %d" ,iter->filepath, ret, errno);
+                gf_msg ("", GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED, "Unable"
+                        " to close file: %s, ret: %d" ,
+                        iter->filepath, ret);
 
         GF_FREE (iter);
         return ret;
@@ -685,15 +692,15 @@ gf_store_lock (gf_store_handle_t *sh)
 
         sh->fd = open (sh->path, O_RDWR);
         if (sh->fd == -1) {
-                gf_log ("", GF_LOG_ERROR, "Failed to open '%s': %s", sh->path,
-                        strerror (errno));
+                gf_msg ("", GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED,
+                        "Failed to open '%s'", sh->path);
                 return -1;
         }
 
         ret = lockf (sh->fd, F_LOCK, 0);
         if (ret)
-                gf_log ("", GF_LOG_ERROR, "Failed to gain lock on '%s': %s",
-                        sh->path, strerror (errno));
+                gf_msg ("", GF_LOG_ERROR, errno, LG_MSG_LOCK_FAILED,
+                        "Failed to gain lock on '%s'", sh->path);
         else
                 /* sh->locked is protected by the lockf(sh->fd) above */
                 sh->locked = F_LOCK;
@@ -711,8 +718,8 @@ gf_store_unlock (gf_store_handle_t *sh)
 
         /* does not matter if this fails, locks are released on close anyway */
         if (lockf (sh->fd, F_ULOCK, 0) == -1)
-                gf_log ("", GF_LOG_ERROR, "Failed to release lock on '%s': %s",
-                        sh->path, strerror (errno));
+                gf_msg ("", GF_LOG_ERROR, errno, LG_MSG_UNLOCK_FAILED,
+                        "Failed to release lock on '%s'", sh->path);
 
         close (sh->fd);
 }
diff --git a/libglusterfs/src/syncop-utils.c b/libglusterfs/src/syncop-utils.c
index 349fa92..8ab6bef 100644
--- a/libglusterfs/src/syncop-utils.c
+++ b/libglusterfs/src/syncop-utils.c
@@ -15,6 +15,7 @@
 
 #include "syncop.h"
 #include "common-utils.h"
+#include "libglusterfs-messages.h"
 
 int
 syncop_dirfd (xlator_t *subvol, loc_t *loc, fd_t **fd, int pid)
@@ -27,9 +28,9 @@ syncop_dirfd (xlator_t *subvol, loc_t *loc, fd_t **fd, int pid)
 
         dirfd = fd_create (loc->inode, pid);
         if (!dirfd) {
-                gf_log (subvol->name, GF_LOG_ERROR,
-                        "fd_create of %s failed: %s",
-                        uuid_utoa (loc->gfid), strerror(errno));
+                gf_msg (subvol->name, GF_LOG_ERROR, errno,
+                        LG_MSG_FD_CREATE_FAILED, "fd_create of %s",
+                        uuid_utoa (loc->gfid));
                 ret = -errno;
                 goto out;
         }
@@ -49,18 +50,18 @@ syncop_dirfd (xlator_t *subvol, loc_t *loc, fd_t **fd, int pid)
                 fd_unref (dirfd);
                 dirfd = fd_anonymous (loc->inode);
                 if (!dirfd) {
-                        gf_log(subvol->name, GF_LOG_ERROR,
-                               "fd_anonymous of %s failed: %s",
-                               uuid_utoa (loc->gfid), strerror(errno));
+                        gf_msg (subvol->name, GF_LOG_ERROR, errno,
+                                LG_MSG_FD_ANONYMOUS_FAILED, "fd_anonymous of "
+                                "%s", uuid_utoa (loc->gfid));
                         ret = -errno;
                         goto out;
                 }
                 ret = 0;
 #else /* GF_LINUX_HOST_OS */
                 fd_unref (dirfd);
-                gf_log (subvol->name, GF_LOG_ERROR,
-                        "opendir of %s failed: %s",
-                        uuid_utoa (loc->gfid), strerror(errno));
+                gf_msg (subvol->name, GF_LOG_ERROR, errno,
+                        LG_MSG_DIR_OP_FAILED, "opendir of %s",
+                        uuid_utoa (loc->gfid));
                 goto out;
 #endif /* GF_LINUX_HOST_OS */
         }
@@ -304,7 +305,7 @@ syncop_is_subvol_local (xlator_t *this, loc_t *loc, gf_boolean_t *is_local)
 
         ret = glusterfs_is_local_pathinfo (pathinfo, is_local);
 
-        gf_log (this->name, GF_LOG_DEBUG, "subvol %s is %slocal",
+        gf_msg_debug (this->name, 0, "subvol %s is %slocal",
                 this->name, is_local ? "" : "not ");
 
 out:
diff --git a/libglusterfs/src/syncop.c b/libglusterfs/src/syncop.c
index 48daa32..26a4737 100644
--- a/libglusterfs/src/syncop.c
+++ b/libglusterfs/src/syncop.c
@@ -14,6 +14,7 @@
 #endif
 
 #include "syncop.h"
+#include "libglusterfs-messages.h"
 
 int
 syncopctx_setfsuid (void *uid)
@@ -262,20 +263,21 @@ __run (struct synctask *task)
         case SYNCTASK_SUSPEND:
                 break;
         case SYNCTASK_RUN:
-                gf_log (task->xl->name, GF_LOG_DEBUG,
-                        "re-running already running task");
+                gf_msg_debug (task->xl->name, 0, "re-running already running"
+                              " task");
                 env->runcount--;
                 break;
         case SYNCTASK_WAIT:
                 env->waitcount--;
                 break;
         case SYNCTASK_DONE:
-                gf_log (task->xl->name, GF_LOG_WARNING,
-                        "running completed task");
+                gf_msg (task->xl->name, GF_LOG_WARNING, 0,
+                        LG_MSG_COMPLETED_TASK, "running completed task");
 		return;
 	case SYNCTASK_ZOMBIE:
-		gf_log (task->xl->name, GF_LOG_WARNING,
-			"attempted to wake up zombie!!");
+		gf_msg (task->xl->name, GF_LOG_WARNING, 0,
+                        LG_MSG_WAKE_UP_ZOMBIE, "attempted to wake up "
+                        "zombie!!");
 		return;
         }
 
@@ -301,16 +303,19 @@ __wait (struct synctask *task)
                 env->runcount--;
                 break;
         case SYNCTASK_WAIT:
-                gf_log (task->xl->name, GF_LOG_WARNING,
-                        "re-waiting already waiting task");
+                gf_msg (task->xl->name, GF_LOG_WARNING, 0,
+                        LG_MSG_REWAITING_TASK, "re-waiting already waiting "
+                        "task");
                 env->waitcount--;
                 break;
         case SYNCTASK_DONE:
-                gf_log (task->xl->name, GF_LOG_WARNING,
+                gf_msg (task->xl->name, GF_LOG_WARNING, 0,
+                        LG_MSG_COMPLETED_TASK,
                         "running completed task");
                 return;
 	case SYNCTASK_ZOMBIE:
-		gf_log (task->xl->name, GF_LOG_WARNING,
+		gf_msg (task->xl->name, GF_LOG_WARNING, 0,
+                        LG_MSG_SLEEP_ZOMBIE,
 			"attempted to sleep a zombie!!");
 		return;
         }
@@ -336,8 +341,9 @@ synctask_yield (struct synctask *task)
                 (void) gf_backtrace_save (task->btbuf);
         }
         if (swapcontext (&task->ctx, &task->proc->sched) < 0) {
-                gf_log ("syncop", GF_LOG_ERROR,
-                        "swapcontext failed (%s)", strerror (errno));
+                gf_msg ("syncop", GF_LOG_ERROR, errno,
+                        LG_MSG_SWAPCONTEXT_FAILED, "swapcontext failed (%s)",
+                        strerror (errno));
         }
 
         THIS = oldTHIS;
@@ -488,16 +494,14 @@ synctask_create (struct syncenv *env, synctask_fn_t fn, synctask_cbk_t cbk,
         INIT_LIST_HEAD (&newtask->waitq);
 
         if (getcontext (&newtask->ctx) < 0) {
-                gf_log ("syncop", GF_LOG_ERROR,
-                        "getcontext failed (%s)",
+                gf_msg ("syncop", GF_LOG_ERROR, errno,
+                        LG_MSG_GETCONTEXT_FAILED, "getcontext failed (%s)",
                         strerror (errno));
                 goto err;
         }
 
         newtask->stack = CALLOC (1, env->stacksize);
         if (!newtask->stack) {
-                gf_log ("syncop", GF_LOG_ERROR,
-                        "out of memory for stack");
                 goto err;
         }
 
@@ -648,8 +652,8 @@ synctask_switchto (struct synctask *task)
 #endif
 
         if (swapcontext (&task->proc->sched, &task->ctx) < 0) {
-                gf_log ("syncop", GF_LOG_ERROR,
-                        "swapcontext failed (%s)", strerror (errno));
+                gf_msg ("syncop", GF_LOG_ERROR, errno,
+                        LG_MSG_SWAPCONTEXT_FAILED, "swapcontext failed");
         }
 
         if (task->state == SYNCTASK_DONE) {
@@ -874,22 +878,25 @@ __synclock_lock (struct synclock *lock)
                 case LOCK_TASK:
                         if (task == lock->owner) {
                                 lock->lock++;
-                                gf_log ("", GF_LOG_TRACE, "Recursive lock called by "
-                                        "sync task.owner= %p,lock=%d", lock->owner, lock->lock);
+                                gf_msg_trace ("", 0, "Recursive lock called by"
+                                              " sync task.owner= %p,lock=%d",
+                                              lock->owner, lock->lock);
                                 return 0;
                         }
                         break;
                 case LOCK_THREAD:
                         if (pthread_self () == lock->owner_tid) {
                                 lock->lock++;
-                                gf_log ("", GF_LOG_TRACE, "Recursive lock called by "
-                                        "thread ,owner=%u lock=%d", (unsigned int) lock->owner_tid,
-                                         lock->lock);
+                                gf_msg_trace ("", 0, "Recursive lock called by"
+                                              " thread ,owner=%u lock=%d",
+                                              (unsigned int) lock->owner_tid,
+                                              lock->lock);
                                 return 0;
                         }
                         break;
                 default:
-                        gf_log ("", GF_LOG_CRITICAL, "unknown lock type");
+                        gf_msg ("", GF_LOG_CRITICAL, 0,
+                                LG_MSG_UNKNOWN_LOCK_TYPE, "unknown lock type");
                         break;
                 }
         }
@@ -974,7 +981,8 @@ __synclock_unlock (synclock_t *lock)
                return -1;
 
         if (lock->lock == 0) {
-                gf_log ("", GF_LOG_CRITICAL, "Unlock called  before lock ");
+                gf_msg ("", GF_LOG_CRITICAL, 0, LG_MSG_UNLOCK_BEFORE_LOCK,
+                        "Unlock called  before lock ");
                 return -1;
         }
         curr = synctask_get ();
@@ -986,23 +994,27 @@ __synclock_unlock (synclock_t *lock)
         case LOCK_TASK:
                 if (curr == lock->owner) {
                         lock->lock--;
-                        gf_log ("", GF_LOG_TRACE, "Unlock success %p, remaining"
-                                " locks=%d", lock->owner, lock->lock);
+                        gf_msg_trace ("", 0, "Unlock success %p, remaining"
+                                      " locks=%d", lock->owner, lock->lock);
                 } else {
-                        gf_log ("", GF_LOG_WARNING, "Unlock called by %p, but"
-                               " lock held by %p", curr, lock->owner);
+                        gf_msg ("", GF_LOG_WARNING, 0, LG_MSG_LOCK_OWNER_ERROR,
+                                "Unlock called by %p, but lock held by %p",
+                                curr, lock->owner);
                 }
 
                 break;
         case LOCK_THREAD:
                 if (pthread_self () == lock->owner_tid) {
                         lock->lock--;
-                        gf_log ("", GF_LOG_TRACE, "Unlock success %u, remaining"
-                                " locks=%d", (unsigned int)lock->owner_tid, lock->lock);
+                        gf_msg_trace ("", 0, "Unlock success %u, remaining "
+                                      "locks=%d",
+                                      (unsigned int)lock->owner_tid,
+                                      lock->lock);
                 } else {
-                        gf_log ("", GF_LOG_WARNING, "Unlock called by %u, but"
-                                " lock held by %u", (unsigned int) pthread_self(),
-                                 (unsigned int) lock->owner_tid);
+                        gf_msg ("", GF_LOG_WARNING, 0, LG_MSG_LOCK_OWNER_ERROR,
+                                "Unlock called by %u, but lock held by %u",
+                                (unsigned int) pthread_self(),
+                                (unsigned int) lock->owner_tid);
                 }
 
                 break;
@@ -1244,9 +1256,8 @@ syncop_readdirp_cbk (call_frame_t *frame,
         if (op_ret >= 0) {
                 list_for_each_entry (entry, &entries->list, list) {
                         tmp = entry_copy (entry);
-                        gf_log (this->name, GF_LOG_TRACE,
-                                "adding entry=%s, count=%d",
-                                tmp->d_name, count);
+                        gf_msg_trace (this->name, 0, "adding entry=%s, "
+                                      "count=%d", tmp->d_name, count);
                         list_add_tail (&tmp->list, &(args->entries.list));
                         count++;
                 }
@@ -1313,9 +1324,9 @@ syncop_readdir_cbk (call_frame_t *frame,
         if (op_ret >= 0) {
                 list_for_each_entry (entry, &entries->list, list) {
                         tmp = entry_copy (entry);
-                        gf_log (this->name, GF_LOG_TRACE,
-                                "adding entry=%s, count=%d",
-                                tmp->d_name, count);
+                        gf_msg_trace (this->name, 0, "adding "
+                                      "entry=%s, count=%d", tmp->d_name,
+                                      count);
                         list_add_tail (&tmp->list, &(args->entries.list));
                         count++;
                 }
diff --git a/libglusterfs/src/timer.c b/libglusterfs/src/timer.c
index 0d845cd..8344c9b 100644
--- a/libglusterfs/src/timer.c
+++ b/libglusterfs/src/timer.c
@@ -18,6 +18,7 @@
 #include "common-utils.h"
 #include "globals.h"
 #include "timespec.h"
+#include "libglusterfs-messages.h"
 
 gf_timer_t *
 gf_timer_call_after (glusterfs_ctx_t *ctx,
@@ -32,7 +33,8 @@ gf_timer_call_after (glusterfs_ctx_t *ctx,
 
         if (ctx == NULL)
         {
-                gf_log_callingfn ("timer", GF_LOG_ERROR, "invalid argument");
+                gf_msg_callingfn ("timer", GF_LOG_ERROR, EINVAL,
+                                  LG_MSG_INVALID_ARG, "invalid argument");
                 return NULL;
         }
 
@@ -41,14 +43,17 @@ gf_timer_call_after (glusterfs_ctx_t *ctx,
          * when cleanup_started is set after checking for it
          */
         if (ctx->cleanup_started) {
-                gf_log_callingfn ("timer", GF_LOG_INFO, "ctx cleanup started");
+                gf_msg_callingfn ("timer", GF_LOG_INFO, 0,
+                                  LG_MSG_CTX_CLEANUP_STARTED, "ctx cleanup "
+                                  "started");
                 return NULL;
         }
 
         reg = gf_timer_registry_init (ctx);
 
         if (!reg) {
-                gf_log_callingfn ("timer", GF_LOG_ERROR, "!reg");
+                gf_msg_callingfn ("timer", GF_LOG_ERROR, 0,
+                                  LG_MSG_TIMER_REGISTER_ERROR, "!reg");
                 return NULL;
         }
 
@@ -85,7 +90,8 @@ gf_timer_call_stale (gf_timer_registry_t *reg,
 {
         if (reg == NULL || event == NULL)
         {
-                gf_log_callingfn ("timer", GF_LOG_ERROR, "invalid argument");
+                gf_msg_callingfn ("timer", GF_LOG_ERROR, EINVAL,
+                                  LG_MSG_INVALID_ARG, "invalid argument");
                 return 0;
         }
 
@@ -107,13 +113,15 @@ gf_timer_call_cancel (glusterfs_ctx_t *ctx,
 
         if (ctx == NULL || event == NULL)
         {
-                gf_log_callingfn ("timer", GF_LOG_ERROR, "invalid argument");
+                gf_msg_callingfn ("timer", GF_LOG_ERROR, EINVAL,
+                                  LG_MSG_INVALID_ARG, "invalid argument");
                 return 0;
         }
 
         reg = gf_timer_registry_init (ctx);
         if (!reg) {
-                gf_log ("timer", GF_LOG_ERROR, "!reg");
+                gf_msg ("timer", GF_LOG_ERROR, 0, LG_MSG_INIT_TIMER_FAILED,
+                        "!reg");
                 GF_FREE (event);
                 return 0;
         }
@@ -145,13 +153,15 @@ gf_timer_proc (void *ctx)
 
         if (ctx == NULL)
         {
-                gf_log_callingfn ("timer", GF_LOG_ERROR, "invalid argument");
+                gf_msg_callingfn ("timer", GF_LOG_ERROR, EINVAL,
+                                  LG_MSG_INVALID_ARG, "invalid argument");
                 return NULL;
         }
 
         reg = gf_timer_registry_init (ctx);
         if (!reg) {
-                gf_log ("timer", GF_LOG_ERROR, "!reg");
+                gf_msg ("timer", GF_LOG_ERROR, 0, LG_MSG_INIT_TIMER_FAILED,
+                        "!reg");
                 return NULL;
         }
 
@@ -223,7 +233,8 @@ gf_timer_registry_t *
 gf_timer_registry_init (glusterfs_ctx_t *ctx)
 {
         if (ctx == NULL) {
-                gf_log_callingfn ("timer", GF_LOG_ERROR, "invalid argument");
+                gf_msg_callingfn ("timer", GF_LOG_ERROR, EINVAL,
+                                  LG_MSG_INVALID_ARG, "invalid argument");
                 return NULL;
         }
 
-- 
1.7.1