diff options
author | Anand Avati <avati@redhat.com> | 2014-03-29 04:45:17 -0700 |
---|---|---|
committer | Anand Avati <avati@redhat.com> | 2014-05-05 17:27:37 -0700 |
commit | 9021be1fc1a9460438ce74dc5df091834a0bdae0 (patch) | |
tree | a8f98a22979035aec96c8868a690d974b0e18b9b /libglusterfs/src/statedump.c | |
parent | 3a35f975fceb89c5ae0e8e3e189545f6fceaf6e5 (diff) |
statedump: strfd based APIs
Expose strfd based APIs for extracing various types of xlator
state information.
Change-Id: Ibbb6594b6fb31206bc6a1b1ea6514ed41889583b
BUG: 1089216
Signed-off-by: Anand Avati <avati@redhat.com>
Reviewed-on: http://review.gluster.org/7540
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Harshavardhana <harsha@harshavardhana.net>
Diffstat (limited to 'libglusterfs/src/statedump.c')
-rw-r--r-- | libglusterfs/src/statedump.c | 149 |
1 files changed, 141 insertions, 8 deletions
diff --git a/libglusterfs/src/statedump.c b/libglusterfs/src/statedump.c index 8175faba49b..5b41e86791a 100644 --- a/libglusterfs/src/statedump.c +++ b/libglusterfs/src/statedump.c @@ -16,6 +16,7 @@ #include "stack.h" #include "common-utils.h" + #ifdef HAVE_MALLOC_H #include <malloc.h> #endif /* MALLOC_H */ @@ -39,6 +40,7 @@ static pthread_mutex_t gf_proc_dump_mutex; static int gf_dump_fd = -1; gf_dump_options_t dump_options; +static strfd_t *gf_dump_strfd = NULL; static void gf_proc_dump_lock (void) @@ -114,20 +116,17 @@ out: } int -gf_proc_dump_add_section (char *key, ...) +gf_proc_dump_add_section_fd (char *key, va_list ap) { char buf[GF_DUMP_MAX_BUF_LEN]; - va_list ap; GF_ASSERT(key); memset (buf, 0, sizeof(buf)); snprintf (buf, GF_DUMP_MAX_BUF_LEN, "\n["); - va_start (ap, key); vsnprintf (buf + strlen(buf), GF_DUMP_MAX_BUF_LEN - strlen (buf), key, ap); - va_end (ap); snprintf (buf + strlen(buf), GF_DUMP_MAX_BUF_LEN - strlen (buf), "]\n"); return write (gf_dump_fd, buf, strlen (buf)); @@ -135,12 +134,41 @@ gf_proc_dump_add_section (char *key, ...) int -gf_proc_dump_write (char *key, char *value,...) +gf_proc_dump_add_section_strfd (char *key, va_list ap) +{ + int ret = 0; + + ret += strprintf (gf_dump_strfd, "["); + ret += strvprintf (gf_dump_strfd, key, ap); + ret += strprintf (gf_dump_strfd, "]\n"); + + return ret; +} + + +int +gf_proc_dump_add_section (char *key, ...) +{ + va_list ap; + int ret = 0; + + va_start (ap, key); + if (gf_dump_strfd) + ret = gf_proc_dump_add_section_strfd (key, ap); + else + ret = gf_proc_dump_add_section_fd (key, ap); + va_end (ap); + + return ret; +} + + +int +gf_proc_dump_write_fd (char *key, char *value, va_list ap) { char buf[GF_DUMP_MAX_BUF_LEN]; int offset = 0; - va_list ap; GF_ASSERT (key); @@ -150,15 +178,44 @@ gf_proc_dump_write (char *key, char *value,...) snprintf (buf, GF_DUMP_MAX_BUF_LEN, "%s", key); snprintf (buf + offset, GF_DUMP_MAX_BUF_LEN - offset, "="); offset += 1; - va_start (ap, value); vsnprintf (buf + offset, GF_DUMP_MAX_BUF_LEN - offset, value, ap); - va_end (ap); offset = strlen (buf); snprintf (buf + offset, GF_DUMP_MAX_BUF_LEN - offset, "\n"); return write (gf_dump_fd, buf, strlen (buf)); } + +int +gf_proc_dump_write_strfd (char *key, char *value, va_list ap) +{ + int ret = 0; + + ret += strprintf (gf_dump_strfd, "%s = ", key); + ret += strvprintf (gf_dump_strfd, value, ap); + ret += strprintf (gf_dump_strfd, "\n"); + + return ret; +} + + +int +gf_proc_dump_write (char *key, char *value, ...) +{ + int ret = 0; + va_list ap; + + va_start (ap, value); + if (gf_dump_strfd) + ret = gf_proc_dump_write_strfd (key, value, ap); + else + ret = gf_proc_dump_write_fd (key, value, ap); + va_end (ap); + + return ret; +} + + static void gf_proc_dump_xlator_mem_info (xlator_t *xl) { @@ -831,3 +888,79 @@ gf_proc_dump_cleanup (void) { pthread_mutex_destroy (&gf_proc_dump_mutex); } + + +void +gf_proc_dump_xlator_private (xlator_t *this, strfd_t *strfd) +{ + gf_proc_dump_lock (); + { + gf_dump_strfd = strfd; + + if (this->dumpops && this->dumpops->priv) + this->dumpops->priv (this); + + gf_dump_strfd = NULL; + } + gf_proc_dump_unlock (); +} + + +void +gf_proc_dump_mallinfo (strfd_t *strfd) +{ + gf_proc_dump_lock (); + { + gf_dump_strfd = strfd; + + gf_proc_dump_mem_info (); + + gf_dump_strfd = NULL; + } + gf_proc_dump_unlock (); +} + + +void +gf_proc_dump_xlator_history (xlator_t *this, strfd_t *strfd) +{ + gf_proc_dump_lock (); + { + gf_dump_strfd = strfd; + + if (this->dumpops && this->dumpops->history) + this->dumpops->history (this); + + gf_dump_strfd = NULL; + } + gf_proc_dump_unlock (); +} + + +void +gf_proc_dump_xlator_itable (xlator_t *this, strfd_t *strfd) +{ + gf_proc_dump_lock (); + { + gf_dump_strfd = strfd; + + + gf_dump_strfd = NULL; + } + gf_proc_dump_unlock (); +} + + +void +gf_proc_dump_xlator_meminfo (xlator_t *this, strfd_t *strfd) +{ + gf_proc_dump_lock (); + { + gf_dump_strfd = strfd; + + gf_proc_dump_xlator_mem_info (this); + + gf_dump_strfd = NULL; + } + gf_proc_dump_unlock (); +} |