diff options
Diffstat (limited to 'cli/src/cli.c')
| -rw-r--r-- | cli/src/cli.c | 117 |
1 files changed, 84 insertions, 33 deletions
diff --git a/cli/src/cli.c b/cli/src/cli.c index 380a57f48..91b315ff1 100644 --- a/cli/src/cli.c +++ b/cli/src/cli.c @@ -1,22 +1,12 @@ /* - Copyright (c) 2010-2011 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 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 - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. -*/ + Copyright (c) 2010-2012 Red Hat, Inc. <http://www.redhat.com> + This file is part of GlusterFS. + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. +*/ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -178,7 +168,8 @@ logging_init (glusterfs_ctx_t *ctx, struct cli_state *state) char *log_file = state->log_file ? state->log_file : DEFAULT_CLI_LOG_FILE_DIRECTORY "/cli.log"; - if (gf_log_init (ctx, log_file) == -1) { + /* passing ident as NULL means to use default ident for syslog */ + if (gf_log_init (ctx, log_file, NULL) == -1) { fprintf (stderr, "ERROR: failed to open logfile %s\n", log_file); return -1; @@ -293,18 +284,41 @@ cli_rpc_notify (struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event, return ret; } + +/* + * ret: 0: option successfully processed + * 1: signalling end of option list + * -1: unknown option or other issue + */ int cli_opt_parse (char *opt, struct cli_state *state) { char *oarg; + if (strcmp (opt, "") == 0) + return 1; + if (strcmp (opt, "version") == 0) { - puts (argp_program_version); + cli_out ("%s", argp_program_version); + exit (0); + } + + if (strcmp (opt, "print-logdir") == 0) { + cli_out ("%s", DEFAULT_LOG_FILE_DIRECTORY); + exit (0); + } + + if (strcmp (opt, "print-statedumpdir") == 0) { + cli_out ("%s", DEFAULT_VAR_RUN_DIRECTORY); exit (0); } if (strcmp (opt, "xml") == 0) { +#if (HAVE_LIB_XML) state->mode |= GLUSTER_MODE_XML; +#else + cli_err ("XML output not supported. Ignoring '--xml' option"); +#endif return 0; } @@ -339,6 +353,12 @@ cli_opt_parse (char *opt, struct cli_state *state) return 0; } + oarg = strtail (opt, "glusterd-sock="); + if (oarg) { + state->glusterd_sock = oarg; + return 0; + } + return -1; } @@ -366,9 +386,16 @@ parse_cmdline (int argc, char *argv[], struct cli_state *state) state->argc--; /* argv shifted, next check should be at i again */ i--; + if (ret == 1) { + /* end of cli options */ + ret = 0; + break; + } } } + state->argv[state->argc] = NULL; + return ret; } @@ -393,7 +420,6 @@ cli_state_init (struct cli_state *state) int ret = 0; - state->remote_host = "localhost"; state->log_level = -1; tree = &state->tree; @@ -480,23 +506,46 @@ cli_rpc_init (struct cli_state *state) if (!options) goto out; - ret = dict_set_str (options, "remote-host", state->remote_host); - if (ret) - goto out; + /* Connect using to glusterd using the specified method, giving + * preference to unix socket connection. If nothing is specified connect + * to the default glusterd socket + */ + if (state->glusterd_sock) { + gf_log ("cli", GF_LOG_INFO, "Connecting to glusterd using " + "sockfile %s", state->glusterd_sock); + ret = rpc_transport_unix_options_build (&options, + state->glusterd_sock, + 0); + if (ret) + goto out; + } else if (state->remote_host) { + gf_log ("cli", GF_LOG_INFO, "Connecting to remote glusterd at " + "%s", state->remote_host); + ret = dict_set_str (options, "remote-host", state->remote_host); + if (ret) + goto out; - if (state->remote_port) - port = state->remote_port; + if (state->remote_port) + port = state->remote_port; - ret = dict_set_int32 (options, "remote-port", port); - if (ret) - goto out; + ret = dict_set_int32 (options, "remote-port", port); + if (ret) + goto out; - ret = dict_set_str (options, "transport.address-family", "inet"); - if (ret) - goto out; + ret = dict_set_str (options, "transport.address-family", + "inet"); + if (ret) + goto out; + } else { + gf_log ("cli", GF_LOG_DEBUG, "Connecting to glusterd using " + "default socket"); + ret = rpc_transport_unix_options_build + (&options, DEFAULT_GLUSTERD_SOCKFILE, 0); + if (ret) + goto out; + } rpc = rpc_clnt_new (options, this->ctx, this->name, 16); - if (!rpc) goto out; @@ -506,7 +555,7 @@ cli_rpc_init (struct cli_state *state) goto out; } - rpc_clnt_start (rpc); + ret = rpc_clnt_start (rpc); out: if (ret) { if (rpc) @@ -552,7 +601,9 @@ main (int argc, char *argv[]) if (!ctx) return ENOMEM; +#ifdef DEBUG gf_mem_acct_enable_set (ctx); +#endif ret = glusterfs_globals_init (ctx); if (ret) |
