summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/store.c
diff options
context:
space:
mode:
authorMohamed Ashiq <ashiq333@gmail.com>2015-05-19 15:46:01 +0530
committerNiels de Vos <ndevos@redhat.com>2015-07-14 02:35:13 -0700
commit2ab34a9c675a6167caed3326b6973854e8529843 (patch)
treeeb72424b707ccf82866b9e1e6e55a576d02e5b65 /libglusterfs/src/store.c
parent8e19c820dc1427d6bf552562c5df18a5884fd02b (diff)
mem-pool,stack,store,syncop,timer/libglusterfs : Porting to a new logging framework
Backport of http://review.gluster.org/10827 Cherry picked from 2b9b3ef3b646989bbc0412dca187b3f5fcad3283 >Change-Id: Idd3dcaf7eeea5207b3a5210676ce3df64153197f >BUG: 1194640 >Signed-off-by: Mohamed Ashiq <ashiq333@gmail.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> Change-Id: Idd3dcaf7eeea5207b3a5210676ce3df64153197f BUG: 1217722 Signed-off-by: Mohamed Ashiq <ashiq333@gmail.com> Reviewed-on: http://review.gluster.org/11478 Tested-by: NetBSD Build System <jenkins@build.gluster.org> Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Niels de Vos <ndevos@redhat.com>
Diffstat (limited to 'libglusterfs/src/store.c')
-rw-r--r--libglusterfs/src/store.c138
1 files changed, 72 insertions, 66 deletions
diff --git a/libglusterfs/src/store.c b/libglusterfs/src/store.c
index 351741f4297..08479776c96 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,8 @@ 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 +132,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 +166,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 +251,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 +261,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 +295,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 +344,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 +372,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 +394,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 +418,7 @@ out:
GF_FREE (shandle);
}
- gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_msg_debug ("", 0, "Returning %d", ret);
return ret;
}
@@ -427,14 +430,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 +457,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 +474,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 +498,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 +513,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 +554,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 +610,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 +651,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 +691,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 +717,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);
}