summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/statedump.c
diff options
context:
space:
mode:
authorKaushal M <kaushal@gluster.com>2011-09-05 14:33:43 +0530
committerVijay Bellur <vijay@gluster.com>2011-09-27 06:45:10 -0700
commit45172a5415abc6b2f17eea74d51805ac85cc0072 (patch)
treee2576cf6cda22bd0f3109bc358c51fb419f3a390 /libglusterfs/src/statedump.c
parent16b7e3bf201686ca03f8c35c20295e05abe52df8 (diff)
cli : new volume statedump command
Changes: 1. Add a new 'volume statedump' command, that performs statedumps of all the bricks in the volume and saves them in a specified location. 2. Add new server option 'server.statedump-path'. 3. Remove multiple function definitions in glusterd.h Statedump Information: The 'volume statedump' command performs statedumps on all the bricks in a given volume. The syntax of the command is, gluster volume statedump <VOLNAME> [type]...... Types include, * all * mem * iobuf * callpool * priv * fd * inode Defaults to 'all' when no type is specified. The statedump files are created by default in /tmp directory of the server on which the bricks are present. This path can be changed by setting the 'server.statedump-path' option. The statedump files will be named as, <brick-name>.<pid of brick process>.dump Change-Id: I01c0e1a8aad490da818e086d89f292bd2ed06fd4 BUG: 1964 Reviewed-on: http://review.gluster.com/321 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Amar Tumballi <amar@gluster.com>
Diffstat (limited to 'libglusterfs/src/statedump.c')
-rw-r--r--libglusterfs/src/statedump.c112
1 files changed, 62 insertions, 50 deletions
diff --git a/libglusterfs/src/statedump.c b/libglusterfs/src/statedump.c
index cf947996b6b..525980bfacd 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 ();