summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cli/src/Makefile.am2
-rw-r--r--cli/src/cli-cmd-log.c96
-rw-r--r--cli/src/cli-cmd-misc.c3
-rw-r--r--cli/src/cli-cmd-parser.c135
-rw-r--r--cli/src/cli-cmd-volume.c145
-rw-r--r--cli/src/cli-cmd.c4
-rw-r--r--cli/src/cli-cmd.h1
-rw-r--r--cli/src/cli.h7
-rw-r--r--cli/src/cli3_1-cops.c198
-rw-r--r--libglusterfs/src/logging.c7
-rw-r--r--libglusterfs/src/logging.h8
-rw-r--r--rpc/rpc-lib/src/protocol-common.h6
-rw-r--r--rpc/xdr/src/cli1-xdr.c71
-rw-r--r--rpc/xdr/src/cli1-xdr.h54
-rw-r--r--rpc/xdr/src/cli1.c88
-rw-r--r--rpc/xdr/src/cli1.h39
-rw-r--r--rpc/xdr/src/cli1.x34
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-handler.c180
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-mem-types.h3
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-op-sm.c336
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-op-sm.h9
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.c23
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-volgen.c9
-rw-r--r--xlators/mgmt/glusterd/src/glusterd.c9
-rw-r--r--xlators/mgmt/glusterd/src/glusterd.h31
-rw-r--r--xlators/mgmt/glusterd/src/glusterd3_1-mops.c16
26 files changed, 1372 insertions, 142 deletions
diff --git a/cli/src/Makefile.am b/cli/src/Makefile.am
index e8cabfb8c8b..fbbf44dd080 100644
--- a/cli/src/Makefile.am
+++ b/cli/src/Makefile.am
@@ -2,7 +2,7 @@ sbin_PROGRAMS = gluster
gluster_SOURCES = cli.c registry.c input.c cli-cmd.c cli-rl.c \
cli-cmd-volume.c cli-cmd-peer.c cli3_1-cops.c cli-cmd-parser.c\
- cli-cmd-misc.c cli-cmd-log.c
+ cli-cmd-misc.c
gluster_LDADD = $(top_builddir)/libglusterfs/src/libglusterfs.la $(GF_LDADD)\
$(RLLIBS) $(top_builddir)/rpc/xdr/src/libgfxdr.la \
diff --git a/cli/src/cli-cmd-log.c b/cli/src/cli-cmd-log.c
deleted file mode 100644
index e67f28091e8..00000000000
--- a/cli/src/cli-cmd-log.c
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com>
- This file is part of GlusterFS.
-
- GlusterFS is free software; you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation; either version 3 of the License,
- or (at your option) any later version.
-
- GlusterFS is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see
- <http://www.gnu.org/licenses/>.
-*/
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <pthread.h>
-
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
-
-#include "cli.h"
-#include "cli-cmd.h"
-#include "cli-mem-types.h"
-#include "protocol-common.h"
-
-extern struct rpc_clnt *global_rpc;
-
-extern rpc_clnt_prog_t *cli_rpc_prog;
-
-int cli_cmd_log_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word,
- const char **words, int wordcount);
-
-int
-cli_cmd_log_cbk (struct cli_state *state, struct cli_cmd_word *word,
- const char **words, int wordcount)
-{
- cli_cmd_broadcast_response (0);
- return 0;
-}
-
-struct cli_cmd cli_log_cmds[] = {
- { "log <VOLNAME> ...",
- cli_cmd_log_cbk,
- "set log level for <VOLNAME>"},
-
- { "log --help",
- cli_cmd_log_help_cbk,
- "help command for log"},
-
- { NULL, NULL, NULL }
-};
-
-int
-cli_cmd_log_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word,
- const char **words, int wordcount)
-{
- struct cli_cmd *cmd = NULL;
-
-
-
- for (cmd = cli_log_cmds; cmd->pattern; cmd++)
- cli_out ("%s - %s", cmd->pattern, cmd->desc);
-
-
-
- if (!state->rl_enabled)
- exit (0);
-
- return 0;
-}
-
-int
-cli_cmd_log_register (struct cli_state *state)
-{
- int ret = 0;
- struct cli_cmd *cmd = NULL;
-
- for (cmd = cli_log_cmds; cmd->pattern; cmd++) {
- ret = cli_cmd_register (&state->tree, cmd->pattern, cmd->cbk,
- cmd->desc);
- if (ret)
- goto out;
- }
-out:
- return ret;
-}
diff --git a/cli/src/cli-cmd-misc.c b/cli/src/cli-cmd-misc.c
index 52be1d94ed1..306a7628faa 100644
--- a/cli/src/cli-cmd-misc.c
+++ b/cli/src/cli-cmd-misc.c
@@ -61,9 +61,6 @@ cli_cmd_display_help (struct cli_state *state, struct cli_cmd_word *in_word,
for (cmd = cli_probe_cmds; cmd->pattern; cmd++)
cli_out ("%s - %s", cmd->pattern, cmd->desc);
- for (cmd = cli_log_cmds; cmd->pattern; cmd++)
- cli_out ("%s - %s", cmd->pattern, cmd->desc);
-
for (cmd = cli_misc_cmds; cmd->pattern; cmd++)
cli_out ("%s - %s", cmd->pattern, cmd->desc);
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
index 79f56e2d4b6..48c4a4fd9ef 100644
--- a/cli/src/cli-cmd-parser.c
+++ b/cli/src/cli-cmd-parser.c
@@ -642,3 +642,138 @@ out:
return ret;
}
+
+int32_t
+cli_cmd_log_filename_parse (const char **words, int wordcount, dict_t **options)
+{
+ dict_t *dict = NULL;
+ char *volname = NULL;
+ char *str = NULL;
+ int ret = -1;
+
+ GF_ASSERT (words);
+ GF_ASSERT (options);
+
+ GF_ASSERT ((strcmp (words[0], "volume")) == 0);
+ GF_ASSERT ((strcmp (words[1], "log")) == 0);
+ GF_ASSERT ((strcmp (words[2], "filename")) == 0);
+
+ dict = dict_new ();
+ if (!dict)
+ goto out;
+
+ volname = (char *)words[3];
+ GF_ASSERT (volname);
+
+ ret = dict_set_str (dict, "volname", volname);
+ if (ret)
+ goto out;
+
+ str = (char *)words[4];
+ if (strchr (str, ':')) {
+ ret = dict_set_str (dict, "brick", str);
+ if (ret)
+ goto out;
+ /* Path */
+ str = (char *)words[5];
+ ret = dict_set_str (dict, "path", str);
+ if (ret)
+ goto out;
+ } else {
+ ret = dict_set_str (dict, "path", str);
+ if (ret)
+ goto out;
+ }
+
+ *options = dict;
+
+out:
+ if (ret && dict)
+ dict_destroy (dict);
+
+ return ret;
+}
+
+int32_t
+cli_cmd_log_locate_parse (const char **words, int wordcount, dict_t **options)
+{
+ dict_t *dict = NULL;
+ char *volname = NULL;
+ char *str = NULL;
+ int ret = -1;
+
+ GF_ASSERT (words);
+ GF_ASSERT (options);
+
+ GF_ASSERT ((strcmp (words[0], "volume")) == 0);
+ GF_ASSERT ((strcmp (words[1], "log")) == 0);
+ GF_ASSERT ((strcmp (words[2], "locate")) == 0);
+
+ dict = dict_new ();
+ if (!dict)
+ goto out;
+
+ volname = (char *)words[3];
+ GF_ASSERT (volname);
+
+ ret = dict_set_str (dict, "volname", volname);
+ if (ret)
+ goto out;
+
+ str = (char *)words[4];
+ if (str && strchr (str, ':')) {
+ ret = dict_set_str (dict, "brick", str);
+ if (ret)
+ goto out;
+ }
+
+ *options = dict;
+
+out:
+ if (ret && dict)
+ dict_destroy (dict);
+
+ return ret;
+}
+
+int32_t
+cli_cmd_log_rotate_parse (const char **words, int wordcount, dict_t **options)
+{
+ dict_t *dict = NULL;
+ char *volname = NULL;
+ char *str = NULL;
+ int ret = -1;
+
+ GF_ASSERT (words);
+ GF_ASSERT (options);
+
+ GF_ASSERT ((strcmp (words[0], "volume")) == 0);
+ GF_ASSERT ((strcmp (words[1], "log")) == 0);
+ GF_ASSERT ((strcmp (words[2], "rotate")) == 0);
+
+ dict = dict_new ();
+ if (!dict)
+ goto out;
+
+ volname = (char *)words[3];
+ GF_ASSERT (volname);
+
+ ret = dict_set_str (dict, "volname", volname);
+ if (ret)
+ goto out;
+
+ str = (char *)words[4];
+ if (str && strchr (str, ':')) {
+ ret = dict_set_str (dict, "brick", str);
+ if (ret)
+ goto out;
+ }
+
+ *options = dict;
+
+out:
+ if (ret && dict)
+ dict_destroy (dict);
+
+ return ret;
+}
diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c
index 1421157c89a..3bbccc900cf 100644
--- a/cli/src/cli-cmd-volume.c
+++ b/cli/src/cli-cmd-volume.c
@@ -515,6 +515,140 @@ cli_cmd_volume_set_transport_cbk (struct cli_state *state,
return 0;
}
+void
+cli_cmd_log_filename_usage ()
+{
+ cli_out ("Usage: volume log filename <VOLNAME> [BRICK] <PATH>");
+}
+
+int
+cli_cmd_log_filename_cbk (struct cli_state *state, struct cli_cmd_word *word,
+ const char **words, int wordcount)
+{
+ int ret = -1;
+ rpc_clnt_procedure_t *proc = NULL;
+ call_frame_t *frame = NULL;
+ dict_t *options = NULL;
+
+ if (!((wordcount == 5) || (wordcount == 6))) {
+ cli_cmd_log_filename_usage ();
+ goto out;
+ }
+
+ proc = &cli_rpc_prog->proctable[GF1_CLI_LOG_FILENAME];
+
+ frame = create_frame (THIS, THIS->ctx->pool);
+ if (!frame)
+ goto out;
+
+ ret = cli_cmd_log_filename_parse (words, wordcount, &options);
+ if (ret)
+ goto out;
+
+ if (proc->fn) {
+ ret = proc->fn (frame, THIS, options);
+ }
+
+out:
+ if (ret)
+ cli_out ("setting log filename failed");
+
+ if (options)
+ dict_destroy (options);
+
+ return ret;
+}
+
+
+void
+cli_cmd_log_locate_usage ()
+{
+ cli_out ("Usage: volume log locate <VOLNAME> [BRICK]");
+}
+
+int
+cli_cmd_log_locate_cbk (struct cli_state *state, struct cli_cmd_word *word,
+ const char **words, int wordcount)
+{
+ int ret = -1;
+ rpc_clnt_procedure_t *proc = NULL;
+ call_frame_t *frame = NULL;
+ dict_t *options = NULL;
+
+ if (!((wordcount == 4) || (wordcount == 5))) {
+ cli_cmd_log_locate_usage ();
+ goto out;
+ }
+
+ proc = &cli_rpc_prog->proctable[GF1_CLI_LOG_LOCATE];
+
+ frame = create_frame (THIS, THIS->ctx->pool);
+ if (!frame)
+ goto out;
+
+ ret = cli_cmd_log_locate_parse (words, wordcount, &options);
+ if (ret)
+ goto out;
+
+ if (proc->fn) {
+ ret = proc->fn (frame, THIS, options);
+ }
+
+out:
+ if (ret)
+ cli_out ("getting log file location information failed");
+
+ if (options)
+ dict_destroy (options);
+
+
+ return ret;
+}
+
+void
+cli_cmd_log_rotate_usage ()
+{
+ cli_out ("Usage: volume log rotate <VOLNAME> [BRICK]");
+}
+
+int
+cli_cmd_log_rotate_cbk (struct cli_state *state, struct cli_cmd_word *word,
+ const char **words, int wordcount)
+{
+ int ret = -1;
+ rpc_clnt_procedure_t *proc = NULL;
+ call_frame_t *frame = NULL;
+ dict_t *options = NULL;
+
+ if (!((wordcount == 4) || (wordcount == 5))) {
+ cli_cmd_log_rotate_usage ();
+ goto out;
+ }
+
+ proc = &cli_rpc_prog->proctable[GF1_CLI_LOG_ROTATE];
+
+ frame = create_frame (THIS, THIS->ctx->pool);
+ if (!frame)
+ goto out;
+
+ ret = cli_cmd_log_rotate_parse (words, wordcount, &options);
+ if (ret)
+ goto out;
+
+ if (proc->fn) {
+ ret = proc->fn (frame, THIS, options);
+ }
+
+out:
+ if (ret)
+ cli_out ("getting log file location information failed");
+
+ if (options)
+ dict_destroy (options);
+
+ return ret;
+}
+
struct cli_cmd volume_cmds[] = {
{ "volume info [all|<VOLNAME>]",
@@ -577,6 +711,17 @@ struct cli_cmd volume_cmds[] = {
cli_cmd_volume_help_cbk,
"display help for the volume command"},
+ { "volume log filename <VOLNAME> [BRICK] <PATH>",
+ cli_cmd_log_filename_cbk,
+ "set the log file for corresponding volume/brick"},
+
+ { "volume log locate <VOLNAME> [BRICK]",
+ cli_cmd_log_locate_cbk,
+ "locate the log file for corresponding volume/brick"},
+
+ { "volume log rotate <VOLNAME> [BRICK]",
+ cli_cmd_log_rotate_cbk,
+ "rotate the log file for corresponding volume/brick"},
{ NULL, NULL, NULL }
};
diff --git a/cli/src/cli-cmd.c b/cli/src/cli-cmd.c
index ae4e2db2c1f..934936af92d 100644
--- a/cli/src/cli-cmd.c
+++ b/cli/src/cli-cmd.c
@@ -203,10 +203,6 @@ cli_cmds_register (struct cli_state *state)
if (ret)
goto out;
- ret = cli_cmd_log_register (state);
- if (ret)
- goto out;
-
out:
return ret;
}
diff --git a/cli/src/cli-cmd.h b/cli/src/cli-cmd.h
index ce5f426c66a..42d5316ac97 100644
--- a/cli/src/cli-cmd.h
+++ b/cli/src/cli-cmd.h
@@ -38,7 +38,6 @@ int cli_cmd_volume_register (struct cli_state *state);
int cli_cmd_probe_register (struct cli_state *state);
int cli_cmd_misc_register (struct cli_state *state);
-int cli_cmd_log_register (struct cli_state *state);
struct cli_cmd_word *cli_cmd_nextword (struct cli_cmd_word *word,
const char *text);
diff --git a/cli/src/cli.h b/cli/src/cli.h
index 22159025e5e..257bb140257 100644
--- a/cli/src/cli.h
+++ b/cli/src/cli.h
@@ -176,6 +176,13 @@ int32_t
cli_cmd_volume_replace_brick_parse (const char **words, int wordcount,
dict_t **options);
+int32_t
+cli_cmd_log_rotate_parse (const char **words, int wordcount, dict_t **options);
+int32_t
+cli_cmd_log_locate_parse (const char **words, int wordcount, dict_t **options);
+int32_t
+cli_cmd_log_filename_parse (const char **words, int wordcount, dict_t **options);
+
cli_local_t * cli_local_get ();
void
diff --git a/cli/src/cli3_1-cops.c b/cli/src/cli3_1-cops.c
index d07df994e24..9b977cc3b67 100644
--- a/cli/src/cli3_1-cops.c
+++ b/cli/src/cli3_1-cops.c
@@ -856,6 +856,90 @@ out:
return ret;
}
+static int
+gf_cli3_1_log_filename_cbk (struct rpc_req *req, struct iovec *iov,
+ int count, void *myframe)
+{
+ gf1_cli_log_filename_rsp rsp = {0,};
+ int ret = -1;
+
+ if (-1 == req->rpc_status) {
+ goto out;
+ }
+
+ ret = gf_xdr_to_cli_log_filename_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ goto out;
+ }
+
+ gf_log ("cli", GF_LOG_DEBUG, "Received resp to log filename");
+ cli_out ("log filename : %s",
+ (rsp.op_ret) ? "unsuccessful": "successful");
+
+ ret = rsp.op_ret;
+
+out:
+ cli_cmd_broadcast_response (ret);
+ return ret;
+}
+
+static int
+gf_cli3_1_log_locate_cbk (struct rpc_req *req, struct iovec *iov,
+ int count, void *myframe)
+{
+ gf1_cli_log_locate_rsp rsp = {0,};
+ int ret = -1;
+
+ if (-1 == req->rpc_status) {
+ goto out;
+ }
+
+ ret = gf_xdr_to_cli_log_locate_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ goto out;
+ }
+
+ gf_log ("cli", GF_LOG_DEBUG, "Received resp to log locate");
+ cli_out ("log file location: %s", rsp.path);
+
+ ret = rsp.op_ret;
+
+out:
+ cli_cmd_broadcast_response (ret);
+ return ret;
+}
+
+static int
+gf_cli3_1_log_rotate_cbk (struct rpc_req *req, struct iovec *iov,
+ int count, void *myframe)
+{
+ gf1_cli_log_rotate_rsp rsp = {0,};
+ int ret = -1;
+
+ if (-1 == req->rpc_status) {
+ goto out;
+ }
+
+ ret = gf_xdr_to_cli_log_rotate_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ goto out;
+ }
+
+ gf_log ("cli", GF_LOG_DEBUG, "Received resp to log rotate");
+ cli_out ("log rotate %s", (rsp.op_ret) ? "unsuccessful": "successful");
+
+ ret = rsp.op_ret;
+
+out:
+ cli_cmd_broadcast_response (ret);
+ return ret;
+}
+
+
+
int32_t
gf_cli3_1_probe (call_frame_t *frame, xlator_t *this,
void *data)
@@ -1472,6 +1556,115 @@ out:
return ret;
}
+int32_t
+gf_cli3_1_log_filename (call_frame_t *frame, xlator_t *this,
+ void *data)
+{
+ gf1_cli_log_filename_req req = {0,};
+ int ret = 0;
+ dict_t *dict = NULL;
+
+ if (!frame || !this || !data) {
+ ret = -1;
+ goto out;
+ }
+
+ dict = data;
+
+ ret = dict_get_str (dict, "volname", &req.volname);
+ if (ret)
+ goto out;
+
+ ret = dict_get_str (dict, "brick", &req.brick);
+ if (ret)
+ req.brick = "";
+
+ ret = dict_get_str (dict, "path", &req.path);
+ if (ret)
+ goto out;
+
+ ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
+ GD_MGMT_CLI_LOG_FILENAME, NULL,
+ gf_xdr_from_cli_log_filename_req,
+ this, gf_cli3_1_log_filename_cbk);
+
+out:
+ gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);
+
+ return ret;
+}
+
+
+int32_t
+gf_cli3_1_log_locate (call_frame_t *frame, xlator_t *this,
+ void *data)
+{
+ gf1_cli_log_locate_req req = {0,};
+ int ret = 0;
+ dict_t *dict = NULL;
+
+ if (!frame || !this || !data) {
+ ret = -1;
+ goto out;
+ }
+
+ dict = data;
+
+ ret = dict_get_str (dict, "volname", &req.volname);
+ if (ret)
+ goto out;
+
+ ret = dict_get_str (dict, "brick", &req.brick);
+ if (ret)
+ req.brick = "";
+
+ ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
+ GD_MGMT_CLI_LOG_LOCATE, NULL,
+ gf_xdr_from_cli_log_locate_req,
+ this, gf_cli3_1_log_locate_cbk);
+
+out:
+ gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);
+
+ return ret;
+}
+
+int32_t
+gf_cli3_1_log_rotate (call_frame_t *frame, xlator_t *this,
+ void *data)
+{
+ gf1_cli_log_locate_req req = {0,};
+ int ret = 0;
+ dict_t *dict = NULL;
+
+ if (!frame || !this || !data) {
+ ret = -1;
+ goto out;
+ }
+
+ dict = data;
+
+ ret = dict_get_str (dict, "volname", &req.volname);
+ if (ret)
+ goto out;
+
+ ret = dict_get_str (dict, "brick", &req.brick);
+ if (ret)
+ req.brick = "";
+
+ ret = cli_cmd_submit (&req, frame, cli_rpc_prog,
+ GD_MGMT_CLI_LOG_ROTATE, NULL,
+ gf_xdr_from_cli_log_rotate_req,
+ this, gf_cli3_1_log_rotate_cbk);
+
+
+out:
+ gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);
+
+ return ret;
+}
+
+
struct rpc_clnt_procedure gluster3_1_cli_actors[GF1_CLI_MAXVALUE] = {
[GF1_CLI_NULL] = {"NULL", NULL },
[GF1_CLI_PROBE] = { "PROBE_QUERY", gf_cli3_1_probe},
@@ -1488,12 +1681,15 @@ struct rpc_clnt_procedure gluster3_1_cli_actors[GF1_CLI_MAXVALUE] = {
[GF1_CLI_ADD_BRICK] = {"ADD_BRICK", gf_cli3_1_add_brick},
[GF1_CLI_REMOVE_BRICK] = {"REMOVE_BRICK", gf_cli3_1_remove_brick},
[GF1_CLI_REPLACE_BRICK] = {"REPLACE_BRICK", gf_cli3_1_replace_brick},
+ [GF1_CLI_LOG_FILENAME] = {"LOG FILENAME", gf_cli3_1_log_filename},
+ [GF1_CLI_LOG_LOCATE] = {"LOG LOCATE", gf_cli3_1_log_locate},
+ [GF1_CLI_LOG_ROTATE] = {"LOG ROTATE", gf_cli3_1_log_rotate},
};
struct rpc_clnt_program cli3_1_prog = {
.progname = "CLI 3.1",
.prognum = GLUSTER3_1_CLI_PROGRAM,
.progver = GLUSTER3_1_CLI_VERSION,
- .proctable = gluster3_1_cli_actors,
+ .proctable = gluster3_1_cli_actors,
.numproc = GLUSTER3_1_CLI_PROCCNT,
};
diff --git a/libglusterfs/src/logging.c b/libglusterfs/src/logging.c
index c152e4a28e4..4493b05c7cd 100644
--- a/libglusterfs/src/logging.c
+++ b/libglusterfs/src/logging.c
@@ -43,11 +43,11 @@
static pthread_mutex_t logfile_mutex;
static char *filename = NULL;
static uint8_t logrotate = 0;
-
static FILE *logfile = NULL;
static gf_loglevel_t loglevel = GF_LOG_MAX;
static int gf_log_syslog = 0;
+char gf_log_xl_log_set;
gf_loglevel_t gf_log_loglevel; /* extern'd */
FILE *gf_log_logfile;
@@ -100,6 +100,7 @@ gf_log_set_xl_loglevel (void *this, gf_loglevel_t level)
xlator_t *xl = this;
if (!xl)
return;
+ gf_log_xl_log_set = 1;
xl->loglevel = level;
}
@@ -261,10 +262,6 @@ log:
tm = localtime (&tv.tv_sec);
- if (level > xlator_loglevel) {
- goto out;
- }
-
pthread_mutex_lock (&logfile_mutex);
{
va_start (ap, fmt);
diff --git a/libglusterfs/src/logging.h b/libglusterfs/src/logging.h
index 39b5938502f..e440d597549 100644
--- a/libglusterfs/src/logging.h
+++ b/libglusterfs/src/logging.h
@@ -73,14 +73,14 @@ typedef enum {
#define GF_LOG_MAX GF_LOG_DEBUG
extern gf_loglevel_t gf_log_loglevel;
+extern char gf_log_xl_log_set;
#define gf_log(dom, levl, fmt...) do { \
+ if ((levl > gf_log_loglevel) && !gf_log_xl_log_set) \
+ break; \
_gf_log (dom, __FILE__, __FUNCTION__, __LINE__, \
levl, ##fmt); \
- if (0) { \
- printf (fmt); \
- } \
-} while (0)
+ } while (0)
/* Log once in GF_UNIVERSAL_ANSWER times */
#define GF_LOG_OCCASIONALLY(var, args...) if (!(var++%GF_UNIVERSAL_ANSWER)) { \
diff --git a/rpc/rpc-lib/src/protocol-common.h b/rpc/rpc-lib/src/protocol-common.h
index fdb42dfe663..14b81faba3c 100644
--- a/rpc/rpc-lib/src/protocol-common.h
+++ b/rpc/rpc-lib/src/protocol-common.h
@@ -99,6 +99,9 @@ enum gf_mgmt_procnum_ {
GD_MGMT_CLI_ADD_BRICK,
GD_MGMT_CLI_REMOVE_BRICK,
GD_MGMT_CLI_REPLACE_BRICK,
+ GD_MGMT_CLI_LOG_FILENAME,
+ GD_MGMT_CLI_LOG_LOCATE,
+ GD_MGMT_CLI_LOG_ROTATE,
GD_MGMT_MAXVALUE,
};
@@ -120,6 +123,9 @@ enum gf_cli_procnum {
GF1_CLI_ADD_BRICK,
GF1_CLI_REMOVE_BRICK,
GF1_CLI_REPLACE_BRICK,
+ GF1_CLI_LOG_FILENAME,
+ GF1_CLI_LOG_LOCATE,
+ GF1_CLI_LOG_ROTATE,
GF1_CLI_MAXVALUE,
};
diff --git a/rpc/xdr/src/cli1-xdr.c b/rpc/xdr/src/cli1-xdr.c
index 64112c1797a..c0d488e7f9d 100644
--- a/rpc/xdr/src/cli1-xdr.c
+++ b/rpc/xdr/src/cli1-xdr.c
@@ -467,3 +467,74 @@ xdr_gf1_cli_set_vol_rsp (XDR *xdrs, gf1_cli_set_vol_rsp *objp)
return FALSE;
return TRUE;
}
+
+
+bool_t
+xdr_gf1_cli_log_filename_req (XDR *xdrs, gf1_cli_log_filename_req *objp)
+{
+ if (!xdr_string (xdrs, &objp->volname, ~0))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->brick, ~0))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->path, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gf1_cli_log_filename_rsp (XDR *xdrs, gf1_cli_log_filename_rsp *objp)
+{
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->errstr, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+
+bool_t
+xdr_gf1_cli_log_locate_req (XDR *xdrs, gf1_cli_log_locate_req *objp)
+{
+ if (!xdr_string (xdrs, &objp->volname, ~0))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->brick, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gf1_cli_log_locate_rsp (XDR *xdrs, gf1_cli_log_locate_rsp *objp)
+{
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->path, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+
+bool_t
+xdr_gf1_cli_log_rotate_req (XDR *xdrs, gf1_cli_log_rotate_req *objp)
+{
+ if (!xdr_string (xdrs, &objp->volname, ~0))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->brick, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gf1_cli_log_rotate_rsp (XDR *xdrs, gf1_cli_log_rotate_rsp *objp)
+{
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->errstr, ~0))
+ return FALSE;
+ return TRUE;
+}
diff --git a/rpc/xdr/src/cli1-xdr.h b/rpc/xdr/src/cli1-xdr.h
index 55060bf693d..64bae26f4ef 100644
--- a/rpc/xdr/src/cli1-xdr.h
+++ b/rpc/xdr/src/cli1-xdr.h
@@ -286,6 +286,47 @@ struct gf1_cli_set_vol_rsp {
};
typedef struct gf1_cli_set_vol_rsp gf1_cli_set_vol_rsp;
+struct gf1_cli_log_filename_req {
+ char *volname;
+ char *brick;
+ char *path;
+};
+typedef struct gf1_cli_log_filename_req gf1_cli_log_filename_req;
+
+struct gf1_cli_log_filename_rsp {
+ int op_ret;
+ int op_errno;
+ char *errstr;
+};
+typedef struct gf1_cli_log_filename_rsp gf1_cli_log_filename_rsp;
+
+struct gf1_cli_log_locate_req {
+ char *volname;
+ char *brick;
+};
+typedef struct gf1_cli_log_locate_req gf1_cli_log_locate_req;
+
+struct gf1_cli_log_locate_rsp {
+ int op_ret;
+ int op_errno;
+ char *path;
+};
+typedef struct gf1_cli_log_locate_rsp gf1_cli_log_locate_rsp;
+
+struct gf1_cli_log_rotate_req {
+ char *volname;
+ char *brick;
+};
+typedef struct gf1_cli_log_rotate_req gf1_cli_log_rotate_req;
+
+struct gf1_cli_log_rotate_rsp {
+ int op_ret;
+ int op_errno;
+ char *errstr;
+};
+typedef struct gf1_cli_log_rotate_rsp gf1_cli_log_rotate_rsp;
+
+
/* the xdr functions */
#if defined(__STDC__) || defined(__cplusplus)
@@ -322,6 +363,13 @@ extern bool_t xdr_gf1_cli_replace_brick_req (XDR *, gf1_cli_replace_brick_req*)
extern bool_t xdr_gf1_cli_replace_brick_rsp (XDR *, gf1_cli_replace_brick_rsp*);
extern bool_t xdr_gf1_cli_set_vol_req (XDR *, gf1_cli_set_vol_req*);
extern bool_t xdr_gf1_cli_set_vol_rsp (XDR *, gf1_cli_set_vol_rsp*);
+extern bool_t xdr_gf1_cli_log_filename_req (XDR *, gf1_cli_log_filename_req*);
+extern bool_t xdr_gf1_cli_log_filename_rsp (XDR *, gf1_cli_log_filename_rsp*);
+extern bool_t xdr_gf1_cli_log_locate_req (XDR *, gf1_cli_log_locate_req*);
+extern bool_t xdr_gf1_cli_log_locate_rsp (XDR *, gf1_cli_log_locate_rsp*);
+extern bool_t xdr_gf1_cli_log_rotate_req (XDR *, gf1_cli_log_rotate_req*);
+extern bool_t xdr_gf1_cli_log_rotate_rsp (XDR *, gf1_cli_log_rotate_rsp*);
+
#else /* K&R C */
extern bool_t xdr_gf1_cluster_type ();
@@ -357,6 +405,12 @@ extern bool_t xdr_gf1_cli_replace_brick_req ();
extern bool_t xdr_gf1_cli_replace_brick_rsp ();
extern bool_t xdr_gf1_cli_set_vol_req ();
extern bool_t xdr_gf1_cli_set_vol_rsp ();
+extern bool_t xdr_gf1_cli_log_filename_req ();
+extern bool_t xdr_gf1_cli_log_filename_rsp ();
+extern bool_t xdr_gf1_cli_log_locate_req ();
+extern bool_t xdr_gf1_cli_log_locate_rsp ();
+extern bool_t xdr_gf1_cli_log_rotate_req ();
+extern bool_t xdr_gf1_cli_log_rotate_rsp ();
#endif /* K&R C */
diff --git a/rpc/xdr/src/cli1.c b/rpc/xdr/src/cli1.c
index 317bbd7f1b3..d7ba91aea89 100644
--- a/rpc/xdr/src/cli1.c
+++ b/rpc/xdr/src/cli1.c
@@ -435,3 +435,91 @@ gf_xdr_from_cli_set_vol_req (struct iovec outmsg, void *req)
return xdr_serialize_generic (outmsg, (void *)req,
(xdrproc_t)xdr_gf1_cli_set_vol_req);
}
+
+/* log */
+ssize_t
+gf_xdr_serialize_cli_log_filename_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gf1_cli_log_filename_rsp);
+
+}
+
+ssize_t
+gf_xdr_to_cli_log_filename_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gf1_cli_log_filename_req);
+}
+
+ssize_t
+gf_xdr_to_cli_log_filename_rsp (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gf1_cli_log_filename_rsp);
+}
+
+ssize_t
+gf_xdr_from_cli_log_filename_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gf1_cli_log_filename_req);
+}
+
+ssize_t
+gf_xdr_serialize_cli_log_locate_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gf1_cli_log_locate_rsp);
+
+}
+
+ssize_t
+gf_xdr_to_cli_log_locate_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gf1_cli_log_locate_req);
+}
+
+ssize_t
+gf_xdr_to_cli_log_locate_rsp (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gf1_cli_log_locate_rsp);
+}
+
+ssize_t
+gf_xdr_from_cli_log_locate_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gf1_cli_log_locate_req);
+}
+
+ssize_t
+gf_xdr_serialize_cli_log_rotate_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gf1_cli_log_rotate_rsp);
+
+}
+
+ssize_t
+gf_xdr_to_cli_log_rotate_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gf1_cli_log_rotate_req);
+}
+
+ssize_t
+gf_xdr_to_cli_log_rotate_rsp (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gf1_cli_log_rotate_rsp);
+}
+
+ssize_t
+gf_xdr_from_cli_log_rotate_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gf1_cli_log_rotate_req);
+}
diff --git a/rpc/xdr/src/cli1.h b/rpc/xdr/src/cli1.h
index 288253dc677..31b2c9b75c6 100644
--- a/rpc/xdr/src/cli1.h
+++ b/rpc/xdr/src/cli1.h
@@ -197,4 +197,43 @@ gf_xdr_to_cli_get_vol_rsp (struct iovec inmsg, void *args);
ssize_t
gf_xdr_from_cli_get_vol_req (struct iovec outmsg, void *req);
+ssize_t
+gf_xdr_serialize_cli_log_filename_rsp (struct iovec outmsg, void *rsp);
+
+ssize_t
+gf_xdr_to_cli_log_filename_req (struct iovec inmsg, void *args);
+
+ssize_t
+gf_xdr_to_cli_log_filename_rsp (struct iovec inmsg, void *args);
+
+ssize_t
+gf_xdr_from_cli_log_filename_req (struct iovec outmsg, void *req);
+
+
+ssize_t
+gf_xdr_serialize_cli_log_locate_rsp (struct iovec outmsg, void *rsp);
+
+ssize_t
+gf_xdr_to_cli_log_locate_req (struct iovec inmsg, void *args);
+
+ssize_t
+gf_xdr_to_cli_log_locate_rsp (struct iovec inmsg, void *args);
+
+ssize_t
+gf_xdr_from_cli_log_locate_req (struct iovec outmsg, void *req);
+
+ssize_t
+gf_xdr_serialize_cli_log_rotate_rsp (struct iovec outmsg, void *rsp);
+
+ssize_t
+gf_xdr_to_cli_log_rotate_req (struct iovec inmsg, void *args);
+
+ssize_t
+gf_xdr_to_cli_log_rotate_rsp (struct iovec inmsg, void *args);
+
+ssize_t
+gf_xdr_from_cli_log_rotate_req (struct iovec outmsg, void *req);
+
+
+
#endif /* !_CLI1_H */
diff --git a/rpc/xdr/src/cli1.x b/rpc/xdr/src/cli1.x
index d3383147268..0c4cbf83359 100644
--- a/rpc/xdr/src/cli1.x
+++ b/rpc/xdr/src/cli1.x
@@ -195,3 +195,37 @@ struct gf1_cli_set_vol_req {
int op_errno;
string volname<>;
} ;
+
+struct gf1_cli_log_filename_req {
+ string volname<>;
+ string brick<>;
+ string path<>;
+};
+
+struct gf1_cli_log_filename_rsp {
+ int op_ret;
+ int op_errno;
+ string errstr<>;
+};
+
+struct gf1_cli_log_locate_req {
+ string volname<>;
+ string brick<>;
+};
+
+struct gf1_cli_log_locate_rsp {
+ int op_ret;
+ int op_errno;
+ string path<>;
+};
+
+struct gf1_cli_log_rotate_req {
+ string volname<>;
+ string brick<>;
+};
+
+struct gf1_cli_log_rotate_rsp {
+ int op_ret;
+ int op_errno;
+ string errstr<>;
+};
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
index 503d390c30a..02b5ed57638 100644
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
@@ -54,7 +54,6 @@
#include "defaults.c"
#include "common-utils.h"
-
static int
glusterd_friend_find_by_hostname (const char *hoststr,
glusterd_peerinfo_t **peerinfo)
@@ -515,7 +514,7 @@ glusterd_handle_cli_probe (rpcsvc_request_t *req)
if (!gf_xdr_to_cli_probe_req (req->msg[0], &cli_req)) {
//failed to decode msg;
- gf_log ("", 1, "error");
+ gf_log ("", GF_LOG_ERROR, "xdr decoding error");
req->rpc_err = GARBAGE_ARGS;
goto out;
}
@@ -1156,6 +1155,7 @@ out:
return ret;
}
+
int
glusterd_handle_cli_stop_volume (rpcsvc_request_t *req)
{
@@ -1562,6 +1562,144 @@ out:
}
int
+glusterd_handle_log_filename (rpcsvc_request_t *req)
+{
+ int32_t ret = -1;
+ gf1_cli_log_filename_req cli_req = {0,};
+ dict_t *dict = NULL;
+
+ GF_ASSERT (req);
+
+ if (!gf_xdr_to_cli_log_filename_req (req->msg[0], &cli_req)) {
+ //failed to decode msg;
+ req->rpc_err = GARBAGE_ARGS;
+ goto out;
+ }
+
+ gf_log ("glusterd", GF_LOG_NORMAL, "Received log filename req "
+ "for volume %s", cli_req.volname);
+
+ dict = dict_new ();
+ if (!dict)
+ goto out;
+
+ ret = dict_set_str (dict, "volname", cli_req.volname);
+ if (ret)
+ goto out;
+ ret = dict_set_str (dict, "brick", cli_req.brick);
+ if (ret)
+ goto out;
+ ret = dict_set_str (dict, "path", cli_req.path);
+ if (ret)
+ goto out;
+
+ ret = glusterd_log_filename (req, dict);
+
+out:
+ return ret;
+}
+
+int
+glusterd_handle_log_locate (rpcsvc_request_t *req)
+{
+ int32_t ret = -1;
+ gf1_cli_log_locate_req cli_req = {0,};
+ gf1_cli_log_locate_rsp rsp = {0,};
+ dict_t *dict = NULL;
+ glusterd_volinfo_t *volinfo = NULL;
+ glusterd_brickinfo_t *brickinfo = NULL;
+ char *tmp_str = NULL;
+
+ GF_ASSERT (req);
+
+ if (!gf_xdr_to_cli_log_locate_req (req->msg[0], &cli_req)) {
+ //failed to decode msg;
+ req->rpc_err = GARBAGE_ARGS;
+ goto out;
+ }
+
+ gf_log ("glusterd", GF_LOG_NORMAL, "Received log locate req "
+ "for volume %s", cli_req.volname);
+
+ dict = dict_new ();
+ if (!dict)
+ goto out;
+
+ if (strchr (cli_req.brick, ':')) {
+ /* TODO: need to get info of only that brick and then
+ tell what is the exact location */
+ gf_log ("", GF_LOG_DEBUG, "brick : %s", cli_req.brick);
+ }
+
+ ret = glusterd_volinfo_find (cli_req.volname, &volinfo);
+ if (ret) {
+ rsp.path = "request sent on non-existent volume";
+ goto out;
+ }
+
+ list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) {
+ tmp_str = gf_strdup (brickinfo->logfile);
+ rsp.path = dirname (tmp_str);
+ break;
+ }
+
+ ret = 0;
+out:
+ rsp.op_ret = ret;
+ if (!rsp.path)
+ rsp.path = "";
+
+ ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,
+ gf_xdr_serialize_cli_log_locate_rsp);
+
+ if (tmp_str)
+ GF_FREE (tmp_str);
+
+ return ret;
+}
+
+int
+glusterd_handle_log_rotate (rpcsvc_request_t *req)
+{
+ int32_t ret = -1;
+ gf1_cli_log_rotate_req cli_req = {0,};
+ dict_t *dict = NULL;
+
+ GF_ASSERT (req);
+
+ if (!gf_xdr_to_cli_log_rotate_req (req->msg[0], &cli_req)) {
+ //failed to decode msg;
+ req->rpc_err = GARBAGE_ARGS;
+ goto out;
+ }
+
+ gf_log ("glusterd", GF_LOG_NORMAL, "Received log rotate req "
+ "for volume %s", cli_req.volname);
+
+ dict = dict_new ();
+ if (!dict)
+ goto out;
+
+ ret = dict_set_str (dict, "volname", cli_req.volname);
+ if (ret)
+ goto out;
+
+ ret = dict_set_str (dict, "brick", cli_req.brick);
+ if (ret)
+ goto out;
+
+ ret = dict_set_uint64 (dict, "rotate-key", (uint64_t)time (NULL));
+ if (ret)
+ goto out;
+
+ ret = glusterd_log_rotate (req, dict);
+
+out:
+ return ret;
+}
+
+
+int
glusterd_op_lock_send_resp (rpcsvc_request_t *req, int32_t status)
{
@@ -2437,6 +2575,44 @@ glusterd_remove_brick (rpcsvc_request_t *req, dict_t *dict)
}
int32_t
+glusterd_log_filename (rpcsvc_request_t *req, dict_t *dict)
+{
+ int32_t ret = -1;
+
+ GF_ASSERT (req);
+ GF_ASSERT (dict);
+
+ glusterd_op_set_op (GD_OP_LOG_FILENAME);
+ glusterd_op_set_ctx (GD_OP_LOG_FILENAME, dict);
+ glusterd_op_set_ctx_free (GD_OP_LOG_FILENAME, _gf_true);
+ glusterd_op_set_req (req);
+
+ ret = glusterd_op_txn_begin ();
+
+ return ret;
+}
+
+
+int32_t
+glusterd_log_rotate (rpcsvc_request_t *req, dict_t *dict)
+{
+ int32_t ret = -1;
+
+ GF_ASSERT (req);
+ GF_ASSERT (dict);
+
+ glusterd_op_set_op (GD_OP_LOG_ROTATE);
+ glusterd_op_set_ctx (GD_OP_LOG_ROTATE, dict);
+ glusterd_op_set_ctx_free (GD_OP_LOG_ROTATE, _gf_true);
+ glusterd_op_set_req (req);
+
+ ret = glusterd_op_txn_begin ();
+
+ return ret;
+}
+
+
+int32_t
glusterd_list_friends (rpcsvc_request_t *req, dict_t *dict, int32_t flags)
{
int32_t ret = -1;
diff --git a/xlators/mgmt/glusterd/src/glusterd-mem-types.h b/xlators/mgmt/glusterd/src/glusterd-mem-types.h
index 13da58e6739..5db1e0d7915 100644
--- a/xlators/mgmt/glusterd/src/glusterd-mem-types.h
+++ b/xlators/mgmt/glusterd/src/glusterd-mem-types.h
@@ -55,6 +55,9 @@ enum gf_gld_mem_types_ {
gf_gld_mt_store_handle_t,
gf_gld_mt_store_iter_t,
gf_gld_mt_defrag_info,
+ gf_gld_mt_log_filename_ctx_t,
+ gf_gld_mt_log_locate_ctx_t,
+ gf_gld_mt_log_rotate_ctx_t,
gf_gld_mt_end
};
#endif
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
index 8db3e37869a..3f819515a3f 100644
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
@@ -250,6 +250,34 @@ glusterd_op_build_payload (glusterd_op_t op, gd1_mgmt_stage_op_req **req)
}
break;
+ case GD_OP_LOG_FILENAME:
+ {
+ dict_t *dict = NULL;
+ dict = glusterd_op_get_ctx (op);
+ GF_ASSERT (dict);
+ ret = dict_allocate_and_serialize (dict,
+ &stage_req->buf.buf_val,
+ (size_t *)&stage_req->buf.buf_len);
+ if (ret) {
+ goto out;
+ }
+ }
+ break;
+
+ case GD_OP_LOG_ROTATE:
+ {
+ dict_t *dict = NULL;
+ dict = glusterd_op_get_ctx (op);
+ GF_ASSERT (dict);
+ ret = dict_allocate_and_serialize (dict,
+ &stage_req->buf.buf_val,
+ (size_t *)&stage_req->buf.buf_len);
+ if (ret) {
+ goto out;
+ }
+ }
+ break;
+
default:
break;
}
@@ -704,6 +732,86 @@ out:
}
static int
+glusterd_op_stage_log_filename (gd1_mgmt_stage_op_req *req)
+{
+ int ret = 0;
+ dict_t *dict = NULL;
+ char *volname = NULL;
+ gf_boolean_t exists = _gf_false;
+
+ GF_ASSERT (req);
+
+ dict = dict_new ();
+ if (!dict)
+ goto out;
+
+ ret = dict_unserialize (req->buf.buf_val, req->buf.buf_len, &dict);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Unable to unserialize dict");
+ goto out;
+ }
+
+ ret = dict_get_str (dict, "volname", &volname);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Unable to get volume name");
+ goto out;
+ }
+
+ exists = glusterd_check_volume_exists (volname);
+ if (!exists) {
+ gf_log ("", GF_LOG_ERROR, "Volume with name: %s not exists",
+ volname);
+ ret = -1;
+ goto out;
+ }
+
+out:
+ gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
+
+ return ret;
+}
+
+static int
+glusterd_op_stage_log_rotate (gd1_mgmt_stage_op_req *req)
+{
+ int ret = 0;
+ dict_t *dict = NULL;
+ char *volname = NULL;
+ gf_boolean_t exists = _gf_false;
+
+ GF_ASSERT (req);
+
+ dict = dict_new ();
+ if (!dict)
+ goto out;
+
+ ret = dict_unserialize (req->buf.buf_val, req->buf.buf_len, &dict);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Unable to unserialize dict");
+ goto out;
+ }
+
+ ret = dict_get_str (dict, "volname", &volname);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Unable to get volume name");
+ goto out;
+ }
+
+ exists = glusterd_check_volume_exists (volname);
+ if (!exists) {
+ gf_log ("", GF_LOG_ERROR, "Volume with name: %s not exists",
+ volname);
+ ret = -1;
+ goto out;
+ }
+
+out:
+ gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
+
+ return ret;
+}
+
+static int
glusterd_op_stage_remove_brick (gd1_mgmt_stage_op_req *req)
{
int ret = 0;
@@ -2069,6 +2177,195 @@ out:
}
static int
+glusterd_op_log_filename (gd1_mgmt_stage_op_req *req)
+{
+ int ret = 0;
+ dict_t *dict = NULL;
+ glusterd_conf_t *priv = NULL;
+ glusterd_volinfo_t *volinfo = NULL;
+ glusterd_brickinfo_t *brickinfo = NULL;
+ xlator_t *this = NULL;
+ char *volname = NULL;
+ char *brick = NULL;
+ char *path = NULL;
+ char logfile[PATH_MAX] = {0,};
+ char exp_path[PATH_MAX] = {0,};
+ struct stat stbuf = {0,};
+
+ GF_ASSERT (req);
+
+ this = THIS;
+ GF_ASSERT (this);
+ priv = this->private;
+ GF_ASSERT (priv);
+
+ dict = dict_new ();
+ if (!dict) {
+ gf_log ("", GF_LOG_ERROR, "ENOMEM, !dict");
+ goto out;
+ }
+
+ ret = dict_unserialize (req->buf.buf_val, req->buf.buf_len, &dict);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Unable to unserialize dict");
+ goto out;
+ }
+
+ ret = dict_get_str (dict, "volname", &volname);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "volname not found");
+ goto out;
+ }
+ ret = dict_get_str (dict, "path", &path);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "path not found");
+ goto out;
+ }
+
+ ret = stat (path, &stbuf);
+ if (!S_ISDIR (stbuf.st_mode)) {
+ ret = -1;
+ gf_log ("", GF_LOG_ERROR, "not a directory");
+ goto out;
+ }
+
+ ret = dict_get_str (dict, "brick", &brick);
+ if (ret)
+ goto out;
+
+ if (!strchr (brick, ':'))
+ brick = NULL;
+
+ ret = glusterd_volinfo_find (volname, &volinfo);
+ if (ret)
+ goto out;
+
+ list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) {
+ if (brick && strcmp (brickinfo->path, brick))
+ continue;
+
+ GLUSTERD_REMOVE_SLASH_FROM_PATH (brickinfo->path, exp_path);
+
+ snprintf (logfile, PATH_MAX, "%s/%s.log", path, exp_path);
+
+ if (brickinfo->logfile)
+ GF_FREE (brickinfo->logfile);
+ brickinfo->logfile = gf_strdup (logfile);
+ }
+
+ ret = 0;
+
+out:
+ return ret;
+}
+
+static int
+glusterd_op_log_rotate (gd1_mgmt_stage_op_req *req)
+{
+ int ret = 0;
+ dict_t *dict = NULL;
+ glusterd_conf_t *priv = NULL;
+ glusterd_volinfo_t *volinfo = NULL;
+ glusterd_brickinfo_t *brickinfo = NULL;
+ xlator_t *this = NULL;
+ char *volname = NULL;
+ char *brick = NULL;
+ char path[PATH_MAX] = {0,};
+ char logfile[PATH_MAX] = {0,};
+ char pidfile[PATH_MAX] = {0,};
+ FILE *file = NULL;
+ pid_t pid = 0;
+ uint64_t key = 0;
+
+ GF_ASSERT (req);
+
+ this = THIS;
+ GF_ASSERT (this);
+ priv = this->private;
+ GF_ASSERT (priv);
+
+ dict = dict_new ();
+ if (!dict) {
+ gf_log ("", GF_LOG_ERROR, "ENOMEM, !dict");
+ goto out;
+ }
+
+ ret = dict_unserialize (req->buf.buf_val, req->buf.buf_len, &dict);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Unable to unserialize dict");
+ goto out;
+ }
+
+ ret = dict_get_str (dict, "volname", &volname);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "volname not found");
+ goto out;
+ }
+
+ ret = dict_get_uint64 (dict, "rotate-key", &key);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "rotate key not found");
+ goto out;
+ }
+
+ ret = dict_get_str (dict, "brick", &brick);
+ if (ret)
+ goto out;
+
+ if (!strchr (brick, ':'))
+ brick = NULL;
+
+ ret = glusterd_volinfo_find (volname, &volinfo);
+ if (ret)
+ goto out;
+
+ list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) {
+ if (brick && strcmp (brickinfo->path, brick))
+ continue;
+
+ GLUSTERD_GET_VOLUME_DIR (path, volinfo, priv);
+ GLUSTERD_GET_BRICK_PIDFILE (pidfile, path, brickinfo->hostname,
+ brickinfo->path);
+
+ file = fopen (pidfile, "r+");
+ if (!file) {
+ gf_log ("", GF_LOG_ERROR, "Unable to open pidfile: %s",
+ pidfile);
+ ret = -1;
+ goto out;
+ }
+
+ ret = fscanf (file, "%d", &pid);
+ if (ret <= 0) {
+ gf_log ("", GF_LOG_ERROR, "Unable to read pidfile: %s",
+ pidfile);
+ ret = -1;
+ goto out;
+ }
+ fclose (file);
+ file = NULL;
+
+ snprintf (logfile, PATH_MAX, "%s.%"PRIu64,
+ brickinfo->logfile, key);
+
+ ret = rename (brickinfo->logfile, logfile);
+ if (ret)
+ gf_log ("", GF_LOG_WARNING, "rename failed");
+
+ ret = kill (pid, SIGHUP);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Unable to SIGHUP to %d", pid);
+ goto out;
+ }
+ }
+
+ ret = 0;
+
+out:
+ return ret;
+}
+
+static int
glusterd_op_stop_volume (gd1_mgmt_stage_op_req *req)
{
int ret = 0;
@@ -2480,8 +2777,28 @@ glusterd_op_send_cli_response (int32_t op, int32_t op_ret,
sfunc = gf_xdr_serialize_cli_remove_brick_rsp;
break;
}
- }
+ case GD_MGMT_CLI_LOG_FILENAME:
+ {
+ gf1_cli_log_filename_rsp rsp = {0,};
+ rsp.op_ret = op_ret;
+ rsp.op_errno = op_errno;
+ rsp.errstr = "";
+ cli_rsp = &rsp;
+ sfunc = gf_xdr_serialize_cli_log_filename_rsp;
+ break;
+ }
+ case GD_MGMT_CLI_LOG_ROTATE:
+ {
+ gf1_cli_log_rotate_rsp rsp = {0,};
+ rsp.op_ret = op_ret;
+ rsp.op_errno = op_errno;
+ rsp.errstr = "";
+ cli_rsp = &rsp;
+ sfunc = gf_xdr_serialize_cli_log_rotate_rsp;
+ break;
+ }
+ }
ret = glusterd_submit_reply (req, cli_rsp, NULL, 0, NULL,
sfunc);
@@ -2666,11 +2983,18 @@ glusterd_op_stage_validate (gd1_mgmt_stage_op_req *req)
ret = glusterd_op_stage_replace_brick (req);
break;
-
case GD_OP_REMOVE_BRICK:
ret = glusterd_op_stage_remove_brick (req);
break;
+ case GD_OP_LOG_FILENAME:
+ ret = glusterd_op_stage_log_filename (req);
+ break;
+
+ case GD_OP_LOG_ROTATE:
+ ret = glusterd_op_stage_log_rotate (req);
+ break;
+
default:
gf_log ("", GF_LOG_ERROR, "Unknown op %d",
req->op);
@@ -2718,6 +3042,14 @@ glusterd_op_commit_perform (gd1_mgmt_stage_op_req *req)
ret = glusterd_op_remove_brick (req);
break;
+ case GD_OP_LOG_FILENAME:
+ ret = glusterd_op_log_filename (req);
+ break;
+
+ case GD_OP_LOG_ROTATE:
+ ret = glusterd_op_log_rotate (req);
+ break;
+
default:
gf_log ("", GF_LOG_ERROR, "Unknown op %d",
req->op);
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.h b/xlators/mgmt/glusterd/src/glusterd-op-sm.h
index ed824cc6a9a..00b38721739 100644
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.h
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.h
@@ -96,6 +96,9 @@ typedef enum glusterd_op_ {
GD_OP_REMOVE_BRICK,
GD_OP_REPLACE_BRICK,
GD_OP_SYNC_VOLUME,
+ GD_OP_LOG_FILENAME,
+ GD_OP_LOG_LOCATE,
+ GD_OP_LOG_ROTATE,
GD_OP_MAX,
} glusterd_op_t;
@@ -130,6 +133,12 @@ struct glusterd_op_start_volume_ctx_ {
typedef struct glusterd_op_start_volume_ctx_ glusterd_op_start_volume_ctx_t;
typedef struct glusterd_op_start_volume_ctx_ glusterd_op_delete_volume_ctx_t;
+struct glusterd_op_log_filename_ctx_ {
+ char volume_name[GD_VOLUME_NAME_MAX];
+ char brick[GD_VOLUME_NAME_MAX];
+ char path[PATH_MAX];
+};
+typedef struct glusterd_op_log_filename_ctx_ glusterd_op_log_filename_ctx_t;
struct glusterd_op_lock_ctx_ {
uuid_t uuid;
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index 024f5e5fa1f..1866a9904ec 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -765,8 +765,8 @@ glusterd_volume_start_glusterfs (glusterd_volinfo_t *volinfo,
char cmd_str[8192] = {0,};
char rundir[PATH_MAX] = {0,};
char exp_path[PATH_MAX] = {0,};
+ char logfile[PATH_MAX] = {0,};
int port = 0;
- int i = 0;
GF_ASSERT (volinfo);
GF_ASSERT (brickinfo);
@@ -792,19 +792,23 @@ glusterd_volume_start_glusterfs (glusterd_volinfo_t *volinfo,
GLUSTERD_GET_BRICK_PIDFILE (pidfile, path, brickinfo->hostname,
brickinfo->path);
- for (i = 1; i < strlen (brickinfo->path); i++) {
- exp_path[i-1] = brickinfo->path[i];
- if (exp_path[i-1] == '/')
- exp_path[i-1] = '-';
- }
+
+ GLUSTERD_REMOVE_SLASH_FROM_PATH (brickinfo->path, exp_path);
snprintf (volfile, PATH_MAX, "%s.%s.%s", volinfo->volname,
brickinfo->hostname, exp_path);
+ if (!brickinfo->logfile) {
+ snprintf (logfile, PATH_MAX, "%s/logs/%s.log",
+ priv->workdir, exp_path);
+ brickinfo->logfile = gf_strdup (logfile);
+ }
+
snprintf (cmd_str, 8192,
"%s/sbin/glusterfs --xlator-option %s-server.listen-port=%d "
"-s localhost --volfile-id %s -p %s --brick-name %s "
- "--brick-port %d", GFS_PREFIX, volinfo->volname,
- port, volfile, pidfile, brickinfo->path, port);
+ "--brick-port %d -l %s", GFS_PREFIX, volinfo->volname,
+ port, volfile, pidfile, brickinfo->path, port,
+ brickinfo->logfile);
ret = gf_system (cmd_str);
if (ret == 0) {
@@ -957,6 +961,9 @@ glusterd_is_cli_op_req (int32_t op)
case GD_MGMT_CLI_DEFRAG_VOLUME:
case GD_MGMT_CLI_ADD_BRICK:
case GD_MGMT_CLI_REMOVE_BRICK:
+ case GD_MGMT_CLI_LOG_FILENAME:
+ case GD_MGMT_CLI_LOG_LOCATE:
+ case GD_MGMT_CLI_LOG_ROTATE:
return _gf_true;
break;
}
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c
index 2f4ab6cd4bd..3e8e6177dfd 100644
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.c
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c
@@ -1543,19 +1543,12 @@ get_brick_filename (glusterd_volinfo_t *volinfo,
char *ret = NULL;
char brick[PATH_MAX] = {0,};
char *filename = NULL;
- int i = 0;
filename = GF_CALLOC (1, PATH_MAX, gf_gld_mt_char);
if (!filename)
goto out;
- /* TODO: make this part a macro, so everyone uses same thing */
- for (i = 1; i < strlen (brickinfo->path); i++) {
- brick[i-1] = brickinfo->path[i];
- if (brick[i-1] == '/')
- brick[i-1] = '-';
- }
-
+ GLUSTERD_REMOVE_SLASH_FROM_PATH (brickinfo->path, brick);
VOLGEN_GET_VOLUME_DIR (path, volinfo);
snprintf (filename, PATH_MAX, "%s/%s.%s.%s.vol",
diff --git a/xlators/mgmt/glusterd/src/glusterd.c b/xlators/mgmt/glusterd/src/glusterd.c
index a038bc69817..7653f69008c 100644
--- a/xlators/mgmt/glusterd/src/glusterd.c
+++ b/xlators/mgmt/glusterd/src/glusterd.c
@@ -304,6 +304,15 @@ init (xlator_t *this)
exit (1);
}
+ snprintf (voldir, PATH_MAX, "%s/logs", dirname);
+ ret = mkdir (voldir, 0777);
+ if ((-1 == ret) && (errno != EEXIST)) {
+ gf_log (this->name, GF_LOG_CRITICAL,
+ "Unable to create logs directory %s"
+ " ,errno = %d", voldir, errno);
+ exit (1);
+ }
+
rpc = rpcsvc_init (this->ctx, this->options);
if (rpc == NULL) {
gf_log (this->name, GF_LOG_ERROR,
diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h
index 50348cf1326..d52f713054d 100644
--- a/xlators/mgmt/glusterd/src/glusterd.h
+++ b/xlators/mgmt/glusterd/src/glusterd.h
@@ -28,6 +28,7 @@
#include <sys/types.h>
#include <dirent.h>
#include <pthread.h>
+#include <libgen.h>
#include "uuid.h"
@@ -79,6 +80,7 @@ struct glusterd_brickinfo {
struct list_head brick_list;
uuid_t uuid;
int port;
+ char *logfile;
glusterd_store_handle_t *shandle;
};
@@ -181,14 +183,18 @@ typedef ssize_t (*gd_serialize_t) (struct iovec outmsg, void *args);
GLUSTERD_VOLUME_DIR_PREFIX, volinfo->volname, \
GLUSTERD_BRICK_INFO_DIR);
-#define GLUSTERD_GET_BRICK_PIDFILE(pidfile,volpath,hostname,brickpath) { \
+#define GLUSTERD_REMOVE_SLASH_FROM_PATH(path,string) do { \
int i = 0; \
- char exp_path[PATH_MAX] = {0,}; \
- for (i = 0; i < strlen (brickpath); i++) { \
- exp_path[i] = brickpath[i]; \
- if (exp_path[i] == '/') \
- exp_path[i] = '-'; \
+ for (i = 1; i < strlen (path); i++) { \
+ string[i-1] = path[i]; \
+ if (string[i-1] == '/') \
+ string[i-1] = '-'; \
} \
+ } while (0)
+
+#define GLUSTERD_GET_BRICK_PIDFILE(pidfile,volpath,hostname,brickpath) { \
+ char exp_path[PATH_MAX] = {0,}; \
+ GLUSTERD_REMOVE_SLASH_FROM_PATH (brickpath, exp_path); \
snprintf (pidfile, PATH_MAX, "%s/run/%s-%s.pid", \
volpath, hostname, exp_path); \
}
@@ -322,7 +328,6 @@ glusterd_add_brick (rpcsvc_request_t *req, dict_t *dict);
int
glusterd_handle_add_brick (rpcsvc_request_t *req);
-
int32_t
glusterd_replace_brick (rpcsvc_request_t *req, dict_t *dict);
@@ -332,6 +337,18 @@ glusterd_handle_replace_brick (rpcsvc_request_t *req);
int
glusterd_handle_remove_brick (rpcsvc_request_t *req);
+int
+glusterd_handle_log_filename (rpcsvc_request_t *req);
+int
+glusterd_handle_log_locate (rpcsvc_request_t *req);
+int
+glusterd_handle_log_rotate (rpcsvc_request_t *req);
+
+int32_t
+glusterd_log_filename (rpcsvc_request_t *req, dict_t *dict);
+int32_t
+glusterd_log_rotate (rpcsvc_request_t *req, dict_t *dict);
+
int32_t
glusterd_remove_brick (rpcsvc_request_t *req, dict_t *dict);
diff --git a/xlators/mgmt/glusterd/src/glusterd3_1-mops.c b/xlators/mgmt/glusterd/src/glusterd3_1-mops.c
index 5196055b3e1..3777e699268 100644
--- a/xlators/mgmt/glusterd/src/glusterd3_1-mops.c
+++ b/xlators/mgmt/glusterd/src/glusterd3_1-mops.c
@@ -1193,6 +1193,19 @@ glusterd_handle_rpc_msg (rpcsvc_request_t *req)
case GD_MGMT_CLI_REMOVE_BRICK:
ret = glusterd_handle_remove_brick (req);
break;
+
+ case GD_MGMT_CLI_LOG_FILENAME:
+ ret = glusterd_handle_log_filename (req);
+ break;
+
+ case GD_MGMT_CLI_LOG_LOCATE:
+ ret = glusterd_handle_log_locate (req);
+ break;
+
+ case GD_MGMT_CLI_LOG_ROTATE:
+ ret = glusterd_handle_log_rotate (req);
+ break;
+
default:
GF_ASSERT (0);
}
@@ -1231,6 +1244,9 @@ rpcsvc_actor_t glusterd1_mgmt_actors[] = {
[GD_MGMT_CLI_ADD_BRICK] = { "ADD_BRICK", GD_MGMT_CLI_ADD_BRICK, glusterd_handle_rpc_msg, NULL, NULL},
[GD_MGMT_CLI_REPLACE_BRICK] = { "REPLACE_BRICK", GD_MGMT_CLI_REPLACE_BRICK, glusterd_handle_rpc_msg, NULL, NULL},
[GD_MGMT_CLI_REMOVE_BRICK] = { "REMOVE_BRICK", GD_MGMT_CLI_REMOVE_BRICK, glusterd_handle_rpc_msg, NULL, NULL},
+ [GD_MGMT_CLI_LOG_FILENAME] = { "LOG FILENAME", GD_MGMT_CLI_LOG_FILENAME, glusterd_handle_rpc_msg, NULL, NULL},
+ [GD_MGMT_CLI_LOG_LOCATE] = { "LOG LOCATE", GD_MGMT_CLI_LOG_LOCATE, glusterd_handle_log_locate, NULL, NULL},
+ [GD_MGMT_CLI_LOG_ROTATE] = { "LOG FILENAME", GD_MGMT_CLI_LOG_ROTATE, glusterd_handle_rpc_msg, NULL, NULL},
};
/*rpcsvc_actor_t glusterd1_mgmt_actors[] = {