summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src/glusterd-utils.c
diff options
context:
space:
mode:
authorRaghavendra Bhat <raghavendrabhat@gluster.com>2012-01-04 00:08:14 +0530
committerVijay Bellur <vijay@gluster.com>2012-01-27 04:23:41 -0800
commite99cb60af1e153efd616014da6a54d2f95c119d1 (patch)
treebf6e3e92ae6d200b72fd41e0ee7fed0ff720c431 /xlators/mgmt/glusterd/src/glusterd-utils.c
parent5a8c58cf6e6c993c8665a31e6f108744ca27ccf4 (diff)
glusterd: provide option to take statedump of the nfs server
Currently the cli command for taking statedump is for glusterfs servers only. Statedump of nfs server cannot be taken. With this patch if one gives nfs as an option to the statedump command, then the nfs-server's statedump is taken. Change-Id: I4ef7a68e608da4aa2f17541d7b42cd78ce2624b6 BUG: 771587 Signed-off-by: Raghavendra Bhat <raghavendrabhat@gluster.com> Reviewed-on: http://review.gluster.com/2579 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Amar Tumballi <amar@gluster.com> Reviewed-by: Vijay Bellur <vijay@gluster.com>
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-utils.c')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.c104
1 files changed, 99 insertions, 5 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index efc7069d8d4..c0462d9c779 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -4532,13 +4532,15 @@ int
glusterd_set_dump_options (char *dumpoptions_path, char *options,
int option_cnt)
{
- int ret = -1;
+ int ret = 0;
char *dup_options = NULL;
char *option = NULL;
char *tmpptr = NULL;
FILE *fp = NULL;
+ int nfs_cnt = 0;
- if (0 == option_cnt) {
+ if (0 == option_cnt ||
+ (option_cnt == 1 && (!strcmp (options, "nfs ")))) {
ret = 0;
goto out;
}
@@ -4553,6 +4555,16 @@ glusterd_set_dump_options (char *dumpoptions_path, char *options,
dup_options);
option = strtok_r (dup_options, " ", &tmpptr);
while (option) {
+ if (!strcmp (option, "nfs")) {
+ if (nfs_cnt > 0) {
+ unlink (dumpoptions_path);
+ ret = 0;
+ goto out;
+ }
+ nfs_cnt++;
+ option = strtok_r (NULL, " ", &tmpptr);
+ continue;
+ }
fprintf (fp, "%s=yes\n", option);
option = strtok_r (NULL, " ", &tmpptr);
}
@@ -4560,13 +4572,15 @@ glusterd_set_dump_options (char *dumpoptions_path, char *options,
out:
if (fp)
fclose (fp);
+ if (dup_options)
+ GF_FREE (dup_options);
return ret;
}
int
glusterd_brick_statedump (glusterd_volinfo_t *volinfo,
glusterd_brickinfo_t *brickinfo,
- char *options, int option_cnt)
+ char *options, int option_cnt, char **op_errstr)
{
int ret = -1;
xlator_t *this = NULL;
@@ -4618,8 +4632,13 @@ glusterd_brick_statedump (glusterd_volinfo_t *volinfo,
snprintf (dumpoptions_path, sizeof (dumpoptions_path),
"/tmp/glusterdump.%d.options", pid);
- glusterd_set_dump_options (dumpoptions_path, options, option_cnt);
-
+ ret = glusterd_set_dump_options (dumpoptions_path, options, option_cnt);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error while parsing the statedump "
+ "options");
+ ret = -1;
+ goto out;
+ }
gf_log ("", GF_LOG_INFO, "Performing statedump on brick with pid %d",
pid);
@@ -4627,12 +4646,87 @@ glusterd_brick_statedump (glusterd_volinfo_t *volinfo,
kill (pid, SIGUSR1);
sleep (1);
+ ret = 0;
+out:
unlink (dumpoptions_path);
+ if (pidfile)
+ fclose (pidfile);
+ return ret;
+}
+
+int
+glusterd_nfs_statedump (char *options, int option_cnt, char **op_errstr)
+{
+ int ret = -1;
+ xlator_t *this = NULL;
+ glusterd_conf_t *conf = NULL;
+ char pidfile_path[PATH_MAX] = {0,};
+ char path[PATH_MAX] = {0,};
+ FILE *pidfile = NULL;
+ pid_t pid = -1;
+ char dumpoptions_path[PATH_MAX] = {0,};
+ char *option = NULL;
+ char *tmpptr = NULL;
+ char *dup_options = NULL;
+ char msg[256] = {0,};
+
+ this = THIS;
+ GF_ASSERT (this);
+ conf = this->private;
+ GF_ASSERT (conf);
+
+ dup_options = gf_strdup (options);
+ option = strtok_r (dup_options, " ", &tmpptr);
+ if (strcmp (option, "nfs")) {
+ snprintf (msg, sizeof (msg), "for nfs statedump, options should"
+ " be after the key nfs");
+ *op_errstr = gf_strdup (msg);
+ ret = -1;
+ goto out;
+ }
+
+ GLUSTERD_GET_NFS_DIR (path, conf);
+ GLUSTERD_GET_NFS_PIDFILE (pidfile_path, path);
+
+ pidfile = fopen (pidfile_path, "r");
+ if (!pidfile) {
+ gf_log ("", GF_LOG_ERROR, "Unable to open pidfile: %s",
+ pidfile_path);
+ ret = -1;
+ goto out;
+ }
+
+ ret = fscanf (pidfile, "%d", &pid);
+ if (ret <= 0) {
+ gf_log ("", GF_LOG_ERROR, "Unable to get pid of brick process");
+ ret = -1;
+ goto out;
+ }
+
+ snprintf (dumpoptions_path, sizeof (dumpoptions_path),
+ "/tmp/glusterdump.%d.options", pid);
+ ret = glusterd_set_dump_options (dumpoptions_path, options, option_cnt);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error while parsing the statedump "
+ "options");
+ ret = -1;
+ goto out;
+ }
+
+ gf_log ("", GF_LOG_INFO, "Performing statedump on nfs server with "
+ "pid %d", pid);
+
+ kill (pid, SIGUSR1);
+
+ sleep (1);
ret = 0;
out:
if (pidfile)
fclose (pidfile);
+ unlink (dumpoptions_path);
+ if (dup_options)
+ GF_FREE (dup_options);
return ret;
}