summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/dict.c
diff options
context:
space:
mode:
authorAtin Mukherjee <amukherj@redhat.com>2014-09-04 21:47:50 +0530
committerKaushal M <kaushal@redhat.com>2014-10-15 03:02:40 -0700
commit6c13daed1d601df76cfd1973d3ce800afa877fd2 (patch)
treedd739590b1b07d49c04f1da658b779b2f3e81922 /libglusterfs/src/dict.c
parent7e8eefca2caaaa61e1b31b747384f660c595d9c9 (diff)
glusterd: statedump support
Although glusterd currently has statedump support but it doesn't dump its context information. Implementing glusterd_dump_priv function to export per-node glusterd information would be useful for debugging bugs. Once implemented, we could enhance sos-report to fetch this information. This would potentially reduce our time to root cause and data needed for debugability can be dumped gradually. Following is the main items of the dump list targeted in this patch : * Supported max/min op-version and current op-version * Information about peer list * Information about peer list involved while a transaction is going on (xaction_peers) * option dictionary in glusterd_conf_t * mgmt_v3_lock in glusterd_conf_t * List of connected clients * uuid of glusterd * A section of rpc related information like live connections and their statistics There are couple of issues which were found during implementation and testing phase: - xaction_peers of glusterd_conf_t was not initialized in init because of which traversing through this list head was crashing when there was no active transaction - gf_free was not setting the typestr to NULL if the the alloc count becomes 0 for a mem-type earlier allocated. Change-Id: Ic9bce2d57682fc1771cd2bc6af0b7316ecbc761f BUG: 1139682 Signed-off-by: Atin Mukherjee <amukherj@redhat.com> Reviewed-on: http://review.gluster.org/8665 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Kaushal M <kaushal@redhat.com>
Diffstat (limited to 'libglusterfs/src/dict.c')
-rw-r--r--libglusterfs/src/dict.c77
1 files changed, 53 insertions, 24 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;
}