diff options
Diffstat (limited to 'libglusterfs/src')
-rw-r--r-- | libglusterfs/src/dict.c | 77 | ||||
-rw-r--r-- | libglusterfs/src/dict.h | 8 | ||||
-rw-r--r-- | libglusterfs/src/mem-pool.c | 4 |
3 files changed, 64 insertions, 25 deletions
diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c index 5062f509940..d55495c1ad2 100644 --- a/libglusterfs/src/dict.c +++ b/libglusterfs/src/dict.c @@ -29,6 +29,7 @@ #include "compat.h" #include "byte-order.h" #include "globals.h" +#include "statedump.h" data_t * get_new_data () @@ -2807,39 +2808,67 @@ out: return ret; } +int +dict_dump_to_str (dict_t *dict, char *dump, int dumpsize, char *format) +{ + int ret = 0; + int dumplen = 0; + data_pair_t *trav = NULL; + + for (trav = dict->members_list; trav; trav = trav->next) { + ret = snprintf (&dump[dumplen], dumpsize - dumplen, + format, trav->key, trav->value->data); + if ((ret == -1) || !ret) + return ret; + + dumplen += ret; + } + return 0; +} + void -dict_dump (dict_t *this) +dict_dump_to_log (dict_t *dict) { - int ret = 0; - int dumplen = 0; - data_pair_t *trav = NULL; - char dump[64*1024]; /* This is debug only, hence - performance should not matter */ + int ret = -1; + char dump[64*1024] = {0,}; + char *format = "(%s:%s)"; - if (!this) { - gf_log_callingfn ("dict", GF_LOG_WARNING, "dict NULL"); - goto out; + if (!dict) { + gf_log_callingfn ("dict", GF_LOG_WARNING, "dict is NULL"); + return; } - dump[0] = '\0'; /* the array is not initialized to '\0' */ + ret = dict_dump_to_str (dict, dump, sizeof(dump), format); + if (ret) { + gf_log ("dict", GF_LOG_WARNING, "Failed to log dictionary"); + return; + } + gf_log_callingfn ("dict", GF_LOG_INFO, "dict=%p (%s)", dict, dump); - /* There is a possibility of issues if data is binary, ignore it - for now as debugging is more important */ - for (trav = this->members_list; trav; trav = trav->next) { - ret = snprintf (&dump[dumplen], ((64*1024) - dumplen - 1), - "(%s:%s)", trav->key, trav->value->data); - if ((ret == -1) || !ret) - break; + return; +} - dumplen += ret; - /* snprintf doesn't append a trailing '\0', add it here */ - dump[dumplen] = '\0'; +void +dict_dump_to_statedump (dict_t *dict, char *dict_name, char *domain) +{ + int ret = -1; + char dump[64*1024] = {0,}; + char key[4096] = {0,}; + char *format = "\n\t%s:%s"; + + if (!dict) { + gf_log_callingfn (domain, GF_LOG_WARNING, "dict is NULL"); + return; } - if (dumplen) - gf_log_callingfn ("dict", GF_LOG_INFO, - "dict=%p (%s)", this, dump); + ret = dict_dump_to_str (dict, dump, sizeof(dump), format); + if (ret) { + gf_log (domain, GF_LOG_WARNING, "Failed to log dictionary %s", + dict_name); + return; + } + gf_proc_dump_build_key (key, domain, dict_name); + gf_proc_dump_write (key, "%s", dump); -out: return; } diff --git a/libglusterfs/src/dict.h b/libglusterfs/src/dict.h index 7fd45e1cf34..148eb0ef7ea 100644 --- a/libglusterfs/src/dict.h +++ b/libglusterfs/src/dict.h @@ -234,6 +234,12 @@ GF_MUST_CHECK int dict_get_str (dict_t *this, char *key, char **str); GF_MUST_CHECK int dict_get_str_boolean (dict_t *this, char *key, int default_val); GF_MUST_CHECK int dict_serialize_value_with_delim (dict_t *this, char *buf, int32_t *serz_len, char delimiter); +void +dict_dump_to_statedump (dict_t *dict, char *dict_name, char *domain); -void dict_dump (dict_t *dict); +void +dict_dump_to_log (dict_t *dict); + +int +dict_dump_to_str (dict_t *dict, char *dump, int dumpsize, char *format); #endif diff --git a/libglusterfs/src/mem-pool.c b/libglusterfs/src/mem-pool.c index 093592ec056..019be95e37e 100644 --- a/libglusterfs/src/mem-pool.c +++ b/libglusterfs/src/mem-pool.c @@ -279,6 +279,10 @@ __gf_free (void *free_ptr) { xl->mem_acct.rec[type].size -= req_size; xl->mem_acct.rec[type].num_allocs--; + /* If all the instaces are freed up then ensure typestr is + * set to NULL */ + if (!xl->mem_acct.rec[type].num_allocs) + xl->mem_acct.rec[type].typestr = NULL; } UNLOCK (&xl->mem_acct.rec[type].lock); free: |