summaryrefslogtreecommitdiffstats
path: root/libglusterfs
diff options
context:
space:
mode:
authorAmar Tumballi <amarts@redhat.com>2012-03-14 15:10:48 +0530
committerAnand Avati <avati@redhat.com>2012-03-21 12:01:38 -0700
commit11be645bb84ade2c5c9f42baec5ca6c6d1dc1d2c (patch)
treeca627bd37866b73c8655553e2f1f68d418f8ff91 /libglusterfs
parentebb5c6cc1e0d47513edb851128e424e747bb9166 (diff)
dict: add a dict_dump() function to dump the dictionary contents
helps for debugging some functionalities where we have to understand what we send from one end point to another is properly received on the other endpoint without any errors. Change-Id: I9b802f12ae542e499161a1f3b9a5602f7b93b0ee Signed-off-by: Amar Tumballi <amarts@redhat.com> BUG: 782265 Reviewed-on: http://review.gluster.com/2959 Reviewed-by: Jeff Darcy <jdarcy@redhat.com> Reviewed-by: Raghavendra Bhat <raghavendrabhat@gluster.com> Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Anand Avati <avati@redhat.com>
Diffstat (limited to 'libglusterfs')
-rw-r--r--libglusterfs/src/dict.c37
-rw-r--r--libglusterfs/src/dict.h3
2 files changed, 40 insertions, 0 deletions
diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c
index 67bac435fa3..ed89f236a30 100644
--- a/libglusterfs/src/dict.c
+++ b/libglusterfs/src/dict.c
@@ -2850,3 +2850,40 @@ dict_serialize_value_with_delim (dict_t *this, char *buf, int32_t *serz_len,
out:
return ret;
}
+
+void
+dict_dump (dict_t *this)
+{
+ int ret = 0;
+ int dumplen = 0;
+ data_pair_t *trav = NULL;
+ char dump[64*1024]; /* This is debug only, hence
+ performance should not matter */
+
+ if (!this) {
+ gf_log_callingfn ("dict", GF_LOG_WARNING, "dict NULL");
+ goto out;
+ }
+
+ dump[0] = '\0'; /* the array is not initialized to '\0' */
+
+ /* 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;
+
+ dumplen += ret;
+ /* snprintf doesn't append a trailing '\0', add it here */
+ dump[dumplen] = '\0';
+ }
+
+ if (dumplen)
+ gf_log_callingfn ("dict", GF_LOG_INFO,
+ "dict=%p (%s)", this, dump);
+
+out:
+ return;
+}
diff --git a/libglusterfs/src/dict.h b/libglusterfs/src/dict.h
index 8e81e539b74..68579ad7b4f 100644
--- a/libglusterfs/src/dict.h
+++ b/libglusterfs/src/dict.h
@@ -237,4 +237,7 @@ 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 (dict_t *dict);
+
#endif