diff options
Diffstat (limited to 'libglusterfs/src')
-rw-r--r-- | libglusterfs/src/common-utils.c | 18 | ||||
-rw-r--r-- | libglusterfs/src/common-utils.h | 13 | ||||
-rw-r--r-- | libglusterfs/src/glusterfs.h | 1 | ||||
-rw-r--r-- | libglusterfs/src/statedump.c | 112 | ||||
-rw-r--r-- | libglusterfs/src/statedump.h | 5 |
5 files changed, 94 insertions, 55 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index 6ee32cac7..b2e91608b 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -1877,4 +1877,22 @@ get_path_name (char *word, char **path) return *path; } +void +gf_path_strip_trailing_slashes (char *path) +{ + int i = 0; + int len = 0; + if (!path) + return; + + len = strlen (path); + for (i = len - 1; i > 0; i--) + if (path[i] != '/') + break; + + if (i < (len -1)) + path [i+1] = '\0'; + + return; +} diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h index c7d784ca8..82e499b39 100644 --- a/libglusterfs/src/common-utils.h +++ b/libglusterfs/src/common-utils.h @@ -133,6 +133,18 @@ extern char *gf_mgmt_list[GF_MGMT_MAXVALUE]; } \ } while (0); +#define GF_REMOVE_SLASH_FROM_PATH(path, string) \ + do { \ + int i = 0; \ + for (i = 1; i < strlen (path); i++) { \ + string[i-1] = path[i]; \ + if (string[i-1] == '/') \ + string[i-1] = '-'; \ + } \ + } while (0); \ + + + #define GF_FILE_CONTENT_REQUESTED(_xattr_req,_content_limit) \ (dict_get_uint64 (_xattr_req, "glusterfs.content", _content_limit) == 0) @@ -386,4 +398,5 @@ char *gf_uint64_2human_readable (uint64_t); int validate_brick_name (char *brick); char *get_host_name (char *word, char **host); char *get_path_name (char *word, char **path); +void gf_path_strip_trailing_slashes (char *path); #endif /* _COMMON_UTILS_H */ diff --git a/libglusterfs/src/glusterfs.h b/libglusterfs/src/glusterfs.h index 8247c60fb..57a542bb3 100644 --- a/libglusterfs/src/glusterfs.h +++ b/libglusterfs/src/glusterfs.h @@ -352,6 +352,7 @@ struct _glusterfs_ctx { struct list_head mempool_list; /* used to keep a global list of mempools, used to log details of mempool in statedump */ + char *statedump_path; }; typedef struct _glusterfs_ctx glusterfs_ctx_t; diff --git a/libglusterfs/src/statedump.c b/libglusterfs/src/statedump.c index cf947996b..525980bfa 100644 --- a/libglusterfs/src/statedump.c +++ b/libglusterfs/src/statedump.c @@ -23,6 +23,7 @@ #include "iobuf.h" #include "statedump.h" #include "stack.h" +#include "common-utils.h" #ifdef HAVE_MALLOC_H #include <malloc.h> @@ -62,13 +63,13 @@ gf_proc_dump_unlock (void) static int -gf_proc_dump_open (void) +gf_proc_dump_open (char *dump_dir, char *brickname) { - char path[256]; + char path[PATH_MAX] = {0,}; int dump_fd = -1; - memset (path, 0, sizeof (path)); - snprintf (path, sizeof (path), "%s.%d", GF_DUMP_LOGFILE_ROOT, getpid ()); + snprintf (path, sizeof (path), "%s/%s.%d.dump", (dump_dir ? + dump_dir : "/tmp"), brickname, getpid()); dump_fd = open (path, O_CREAT|O_RDWR|O_TRUNC|O_APPEND, 0600); if (dump_fd < 0) @@ -356,6 +357,41 @@ gf_proc_dump_oldgraph_xlator_info (xlator_t *top) } static int +gf_proc_dump_enable_all_options () +{ + + GF_PROC_DUMP_SET_OPTION (dump_options.dump_mem, _gf_true); + GF_PROC_DUMP_SET_OPTION (dump_options.dump_iobuf, _gf_true); + GF_PROC_DUMP_SET_OPTION (dump_options.dump_callpool, _gf_true); + GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_priv, _gf_true); + GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_inode, _gf_true); + GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_fd, _gf_true); + GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_inodectx, + _gf_true); + GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_fdctx, _gf_true); + + return 0; +} + +static int +gf_proc_dump_disable_all_options () +{ + + GF_PROC_DUMP_SET_OPTION (dump_options.dump_mem, _gf_false); + GF_PROC_DUMP_SET_OPTION (dump_options.dump_iobuf, _gf_false); + GF_PROC_DUMP_SET_OPTION (dump_options.dump_callpool, _gf_false); + GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_priv, _gf_false); + GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_inode, + _gf_false); + GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_fd, _gf_false); + GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_inodectx, + _gf_false); + GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_fdctx, _gf_false); + + return 0; +} + +static int gf_proc_dump_parse_set_option (char *key, char *value) { gf_boolean_t *opt_key = NULL; @@ -363,7 +399,10 @@ gf_proc_dump_parse_set_option (char *key, char *value) char buf[GF_DUMP_MAX_BUF_LEN]; int ret = -1; - if (!strncasecmp (key, "mem", 3)) { + if (!strncasecmp (key, "all", 3)) { + (void)gf_proc_dump_enable_all_options (); + return 0; + } else if (!strncasecmp (key, "mem", 3)) { opt_key = &dump_options.dump_mem; } else if (!strncasecmp (key, "iobuf", 5)) { opt_key = &dump_options.dump_iobuf; @@ -398,44 +437,8 @@ gf_proc_dump_parse_set_option (char *key, char *value) return 0; } - static int -gf_proc_dump_enable_all_options () -{ - - GF_PROC_DUMP_SET_OPTION (dump_options.dump_mem, _gf_true); - GF_PROC_DUMP_SET_OPTION (dump_options.dump_iobuf, _gf_true); - GF_PROC_DUMP_SET_OPTION (dump_options.dump_callpool, _gf_true); - GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_priv, _gf_true); - GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_inode, _gf_true); - GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_fd, _gf_true); - GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_inodectx, - _gf_true); - GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_fdctx, _gf_true); - - return 0; -} - -static int -gf_proc_dump_disable_all_options () -{ - - GF_PROC_DUMP_SET_OPTION (dump_options.dump_mem, _gf_false); - GF_PROC_DUMP_SET_OPTION (dump_options.dump_iobuf, _gf_false); - GF_PROC_DUMP_SET_OPTION (dump_options.dump_callpool, _gf_false); - GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_priv, _gf_false); - GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_inode, - _gf_false); - GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_fd, _gf_false); - GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_inodectx, - _gf_false); - GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_fdctx, _gf_false); - - return 0; -} - -static int -gf_proc_dump_options_init () +gf_proc_dump_options_init (char *dump_name) { int ret = -1; FILE *fp = NULL; @@ -443,9 +446,12 @@ gf_proc_dump_options_init () char dumpbuf[GF_DUMP_MAX_BUF_LEN]; char *key = NULL, *value = NULL; char *saveptr = NULL; + char dump_option_file[PATH_MAX]; + snprintf (dump_option_file, sizeof (dump_option_file), + "/tmp/glusterdump.%d.options", getpid ()); - fp = fopen (GF_DUMP_OPTIONFILE, "r"); + fp = fopen (dump_option_file, "r"); if (!fp) { //ENOENT, return success @@ -489,19 +495,26 @@ gf_proc_dump_info (int signum) int ret = -1; glusterfs_ctx_t *ctx = NULL; glusterfs_graph_t *trav = NULL; + char brick_name[PATH_MAX] = {0,}; gf_proc_dump_lock (); - ret = gf_proc_dump_open (); - if (ret < 0) + + ctx = glusterfs_ctx_get (); + if (!ctx) goto out; - ret = gf_proc_dump_options_init (); + if (ctx->cmd_args.brick_name) { + GF_REMOVE_SLASH_FROM_PATH (ctx->cmd_args.brick_name, brick_name); + } else + strncpy (brick_name, "glusterdump", sizeof (brick_name)); + + ret = gf_proc_dump_options_init (brick_name); if (ret < 0) goto out; - ctx = glusterfs_ctx_get (); - if (!ctx) - goto close; + ret = gf_proc_dump_open (ctx->statedump_path, brick_name); + if (ret < 0) + goto out; if (GF_PROC_DUMP_IS_OPTION_ENABLED (mem)) { gf_proc_dump_mem_info (); @@ -534,7 +547,6 @@ gf_proc_dump_info (int signum) i++; } -close: gf_proc_dump_close (); out: gf_proc_dump_unlock (); diff --git a/libglusterfs/src/statedump.h b/libglusterfs/src/statedump.h index 43330b37c..fb07f5927 100644 --- a/libglusterfs/src/statedump.h +++ b/libglusterfs/src/statedump.h @@ -26,11 +26,6 @@ #define GF_DUMP_MAX_BUF_LEN 4096 -#define GF_DUMP_LOGFILE_ROOT "/tmp/glusterdump" -#define GF_DUMP_LOGFILE_ROOT_LEN 256 - -#define GF_DUMP_OPTIONFILE "/tmp/glusterdump.input" - typedef struct gf_dump_xl_options_ { gf_boolean_t dump_priv; gf_boolean_t dump_inode; |