summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGaurav <gaurav@gluster.com>2011-01-31 04:25:23 +0000
committerAnand V. Avati <avati@dev.gluster.com>2011-02-04 00:39:20 -0800
commitf3648c88ebc6d58a10854d564d3fc2c82290ce13 (patch)
treebf7d14ba0ae498e96d39fdd35d0f47c75b860acc
parentba40a3ece0a0b5b381e7d05c74d09cdd1818b817 (diff)
Logging : New uuid to string conversion functions.
Signed-off-by: Gaurav <gaurav@gluster.com> Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 2308 (Threadsafe uuid to string conversion function) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2308
-rw-r--r--libglusterfs/src/common-utils.c20
-rw-r--r--libglusterfs/src/common-utils.h12
-rw-r--r--libglusterfs/src/globals.c40
-rw-r--r--libglusterfs/src/globals.h5
4 files changed, 72 insertions, 5 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
index 727983d..38623dc 100644
--- a/libglusterfs/src/common-utils.c
+++ b/libglusterfs/src/common-utils.c
@@ -46,11 +46,11 @@
#include "revision.h"
#include "glusterfs.h"
#include "stack.h"
+#include "globals.h"
typedef int32_t (*rw_op_t)(int32_t fd, char *buf, int32_t size);
typedef int32_t (*rwv_op_t)(int32_t fd, const struct iovec *buf, int32_t size);
-
struct dnscache6 {
struct addrinfo *first;
struct addrinfo *next;
@@ -1693,3 +1693,21 @@ out:
return ret;
}
+/*Thread safe conversion function*/
+char *
+uuid_utoa (uuid_t uuid)
+{
+ char *uuid_buffer = glusterfs_uuid_buf_get();
+ uuid_unparse (uuid, uuid_buffer);
+ return uuid_buffer;
+}
+
+/*Re-entrant conversion function*/
+char *
+uuid_utoa_r (uuid_t uuid, char *dst)
+{
+ if(!dst)
+ return NULL;
+ uuid_unparse (uuid, dst);
+ return dst;
+}
diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h
index ca0990a..ec14919 100644
--- a/libglusterfs/src/common-utils.h
+++ b/libglusterfs/src/common-utils.h
@@ -34,7 +34,7 @@
#include <pthread.h>
#ifndef GF_BSD_HOST_OS
#include <alloca.h>
-#endif
+#endif
void trap (void);
@@ -47,6 +47,7 @@ void trap (void);
#include "glusterfs.h"
#include "locking.h"
#include "mem-pool.h"
+#include "uuid.h"
#define min(a,b) ((a)<(b)?(a):(b))
@@ -68,9 +69,9 @@ void trap (void);
#define GF_UNIT_PB_STRING "PB"
-enum _gf_boolean
+enum _gf_boolean
{
- _gf_false = 0,
+ _gf_false = 0,
_gf_true = 1
};
@@ -292,7 +293,7 @@ memdup (const void *ptr, size_t size)
char *gf_trim (char *string);
-int gf_strsplit (const char *str, const char *delim,
+int gf_strsplit (const char *str, const char *delim,
char ***tokens, int *token_count);
int gf_volume_name_validate (const char *volume_name);
@@ -343,5 +344,8 @@ char valid_host_name (char *address, int length);
char valid_ipv4_address (char *address, int length);
char valid_ipv6_address (char *address, int length);
char valid_internet_address (char *address);
+
+char *uuid_utoa (uuid_t uuid);
+char *uuid_utoa_r (uuid_t uuid, char *dst);
#endif /* _COMMON_UTILS_H */
diff --git a/libglusterfs/src/globals.c b/libglusterfs/src/globals.c
index 979f84e..3121a1f 100644
--- a/libglusterfs/src/globals.c
+++ b/libglusterfs/src/globals.c
@@ -305,6 +305,42 @@ synctask_set (void *synctask)
return ret;
}
+//UUID_BUFFER
+
+static pthread_key_t uuid_buf_key;
+static char global_uuid_buf[GF_UUID_BUF_SIZE];
+void
+glusterfs_uuid_buf_destroy (void *ptr)
+{
+ if (ptr)
+ FREE (ptr);
+}
+
+int
+glusterfs_uuid_buf_init ()
+{
+ int ret = 0;
+
+ ret = pthread_key_create (&uuid_buf_key,
+ glusterfs_uuid_buf_destroy);
+ return ret;
+}
+
+char *
+glusterfs_uuid_buf_get ()
+{
+ char *buf;
+ int ret = 0;
+
+ buf = pthread_getspecific (uuid_buf_key);
+ if(!buf) {
+ buf = MALLOC (GF_UUID_BUF_SIZE);
+ ret = pthread_setspecific (uuid_buf_key, (void *) buf);
+ if(ret)
+ buf = global_uuid_buf;
+ }
+ return buf;
+}
int
glusterfs_globals_init ()
@@ -325,6 +361,10 @@ glusterfs_globals_init ()
if (ret)
goto out;
+ ret = glusterfs_uuid_buf_init ();
+ if(ret)
+ goto out;
+
gf_mem_acct_enable_set ();
ret = synctask_init ();
diff --git a/libglusterfs/src/globals.h b/libglusterfs/src/globals.h
index 96a1136..665ec55 100644
--- a/libglusterfs/src/globals.h
+++ b/libglusterfs/src/globals.h
@@ -40,6 +40,8 @@ glusterfs_ctx_t *glusterfs_ctx_get ();
/* THIS */
#define THIS (*__glusterfs_this_location())
+#define GF_UUID_BUF_SIZE 50
+
xlator_t **__glusterfs_this_location ();
xlator_t *glusterfs_this_get ();
int glusterfs_this_set (xlator_t *);
@@ -54,6 +56,9 @@ void glusterfs_central_log_flag_unset ();
void *synctask_get ();
int synctask_set (void *);
+/* uuid_buf */
+char *glusterfs_uuid_buf_get();
+
/* init */
int glusterfs_globals_init (void);