From f3648c88ebc6d58a10854d564d3fc2c82290ce13 Mon Sep 17 00:00:00 2001 From: Gaurav Date: Mon, 31 Jan 2011 04:25:23 +0000 Subject: Logging : New uuid to string conversion functions. Signed-off-by: Gaurav Signed-off-by: Anand V. Avati BUG: 2308 (Threadsafe uuid to string conversion function) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2308 --- libglusterfs/src/common-utils.c | 20 +++++++++++++++++++- libglusterfs/src/common-utils.h | 12 ++++++++---- libglusterfs/src/globals.c | 40 ++++++++++++++++++++++++++++++++++++++++ libglusterfs/src/globals.h | 5 +++++ 4 files changed, 72 insertions(+), 5 deletions(-) diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index 727983d06..38623dc79 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 ca0990aa5..ec14919b4 100644 --- a/libglusterfs/src/common-utils.h +++ b/libglusterfs/src/common-utils.h @@ -34,7 +34,7 @@ #include #ifndef GF_BSD_HOST_OS #include -#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 979f84e32..3121a1f14 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 96a113623..665ec55e4 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); -- cgit