summaryrefslogtreecommitdiffstats
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-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
9 files changed, 485 insertions, 106 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,
};