diff options
Diffstat (limited to 'cli/src/cli.c')
| -rw-r--r-- | cli/src/cli.c | 196 |
1 files changed, 131 insertions, 65 deletions
diff --git a/cli/src/cli.c b/cli/src/cli.c index 3716d2a89ca..a52b39c5fb8 100644 --- a/cli/src/cli.c +++ b/cli/src/cli.c @@ -33,35 +33,28 @@ #include <malloc.h> #endif -#ifdef HAVE_MALLOC_STATS -#ifdef DEBUG -#include <mcheck.h> -#endif -#endif - #include "cli.h" #include "cli-quotad-client.h" #include "cli-cmd.h" #include "cli-mem-types.h" -#include "xlator.h" -#include "glusterfs.h" -#include "compat.h" -#include "logging.h" -#include "dict.h" -#include "list.h" -#include "timer.h" -#include "stack.h" -#include "revision.h" -#include "common-utils.h" -#include "gf-event.h" -#include "syscall.h" -#include "call-stub.h" +#include <glusterfs/xlator.h> +#include <glusterfs/glusterfs.h> +#include <glusterfs/compat.h> +#include <glusterfs/logging.h> +#include <glusterfs/dict.h> +#include <glusterfs/list.h> +#include <glusterfs/timer.h> +#include <glusterfs/stack.h> +#include <glusterfs/revision.h> +#include <glusterfs/common-utils.h> +#include <glusterfs/gf-event.h> +#include <glusterfs/syscall.h> +#include <glusterfs/call-stub.h> #include <fnmatch.h> #include "xdr-generic.h" -extern int connected; /* using argp for command line parsing */ const char *argp_program_version = @@ -78,12 +71,16 @@ const char *argp_program_version = const char *argp_program_bug_address = "<" PACKAGE_BUGREPORT ">"; struct rpc_clnt *global_quotad_rpc; + struct rpc_clnt *global_rpc; rpc_clnt_prog_t *cli_rpc_prog; extern struct rpc_clnt_program cli_prog; +int cli_default_conn_timeout = 120; +int cli_ten_minutes_timeout = 600; + static int glusterfs_ctx_defaults_init(glusterfs_ctx_t *ctx) { @@ -94,60 +91,91 @@ glusterfs_ctx_defaults_init(glusterfs_ctx_t *ctx) call_pool_t *pool = NULL; int ret = -1; + if (!ctx) + return ret; + ret = xlator_mem_acct_init(THIS, cli_mt_end); if (ret != 0) { + gf_log("cli", GF_LOG_ERROR, "Memory accounting init failed."); return ret; } + /* Resetting ret to -1 to so in case of failure + * we can relese allocated resource. + */ + ret = -1; + ctx->process_uuid = generate_glusterfs_ctx_id(); - if (!ctx->process_uuid) - return -1; + if (!ctx->process_uuid) { + gf_log("cli", GF_LOG_ERROR, "Failed to generate uuid."); + goto out; + } ctx->page_size = 128 * GF_UNIT_KB; ctx->iobuf_pool = iobuf_pool_new(); - if (!ctx->iobuf_pool) - return -1; + if (!ctx->iobuf_pool) { + gf_log("cli", GF_LOG_ERROR, "Failed to create iobuf pool."); + goto out; + } - ctx->event_pool = event_pool_new(DEFAULT_EVENT_POOL_SIZE, - STARTING_EVENT_THREADS); - if (!ctx->event_pool) - return -1; + ctx->event_pool = gf_event_pool_new(DEFAULT_EVENT_POOL_SIZE, + STARTING_EVENT_THREADS); + if (!ctx->event_pool) { + gf_log("cli", GF_LOG_ERROR, "Failed to create event pool."); + goto out; + } pool = GF_CALLOC(1, sizeof(call_pool_t), cli_mt_call_pool_t); - if (!pool) - return -1; + if (!pool) { + gf_log("cli", GF_LOG_ERROR, "Failed to create call pool."); + goto out; + } /* frame_mem_pool size 112 * 64 */ pool->frame_mem_pool = mem_pool_new(call_frame_t, 32); - if (!pool->frame_mem_pool) - return -1; + if (!pool->frame_mem_pool) { + gf_log("cli", GF_LOG_ERROR, "Failed to create frame mem pool."); + goto out; + } /* stack_mem_pool size 256 * 128 */ pool->stack_mem_pool = mem_pool_new(call_stack_t, 16); - if (!pool->stack_mem_pool) - return -1; + if (!pool->stack_mem_pool) { + gf_log("cli", GF_LOG_ERROR, "Failed to create stack mem pool."); + goto out; + } ctx->stub_mem_pool = mem_pool_new(call_stub_t, 16); - if (!ctx->stub_mem_pool) - return -1; + if (!ctx->stub_mem_pool) { + gf_log("cli", GF_LOG_ERROR, "Failed to stub mem pool."); + goto out; + } ctx->dict_pool = mem_pool_new(dict_t, 32); - if (!ctx->dict_pool) - return -1; + if (!ctx->dict_pool) { + gf_log("cli", GF_LOG_ERROR, "Failed to create dict pool."); + goto out; + } ctx->dict_pair_pool = mem_pool_new(data_pair_t, 512); - if (!ctx->dict_pair_pool) - return -1; + if (!ctx->dict_pair_pool) { + gf_log("cli", GF_LOG_ERROR, "Failed to create dict pair pool."); + goto out; + } ctx->dict_data_pool = mem_pool_new(data_t, 512); - if (!ctx->dict_data_pool) - return -1; + if (!ctx->dict_data_pool) { + gf_log("cli", GF_LOG_ERROR, "Failed to create dict data pool."); + goto out; + } ctx->logbuf_pool = mem_pool_new(log_buf_t, 256); - if (!ctx->logbuf_pool) - return -1; + if (!ctx->logbuf_pool) { + gf_log("cli", GF_LOG_ERROR, "Failed to create logbuf pool."); + goto out; + } INIT_LIST_HEAD(&pool->all_frames); LOCK_INIT(&pool->lock); @@ -161,7 +189,25 @@ glusterfs_ctx_defaults_init(glusterfs_ctx_t *ctx) lim.rlim_max = RLIM_INFINITY; setrlimit(RLIMIT_CORE, &lim); - return 0; + ret = 0; + +out: + if (ret != 0) { + if (pool) { + mem_pool_destroy(pool->frame_mem_pool); + mem_pool_destroy(pool->stack_mem_pool); + } + GF_FREE(pool); + pool = NULL; + GF_FREE(ctx->process_uuid); + mem_pool_destroy(ctx->stub_mem_pool); + mem_pool_destroy(ctx->dict_pool); + mem_pool_destroy(ctx->dict_pair_pool); + mem_pool_destroy(ctx->dict_data_pool); + mem_pool_destroy(ctx->logbuf_pool); + } + + return ret; } static int @@ -174,7 +220,6 @@ logging_init(glusterfs_ctx_t *ctx, struct cli_state *state) /* 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; } /* CLI should not have something to DEBUG after the release, @@ -258,14 +303,14 @@ cli_rpc_notify(struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event, switch (event) { case RPC_CLNT_CONNECT: { - cli_cmd_broadcast_connected(); + cli_cmd_broadcast_connected(_gf_true); gf_log(this->name, GF_LOG_TRACE, "got RPC_CLNT_CONNECT"); break; } case RPC_CLNT_DISCONNECT: { + cli_cmd_broadcast_connected(_gf_false); gf_log(this->name, GF_LOG_TRACE, "got RPC_CLNT_DISCONNECT"); - connected = 0; if (!global_state->prompt && global_state->await_connected) { ret = 1; cli_out( @@ -320,6 +365,18 @@ cli_opt_parse(char *opt, struct cli_state *state) if (strcmp(opt, "") == 0) return 1; + if (strcmp(opt, "help") == 0) { + cli_out( + " peer help - display help for peer commands\n" + " volume help - display help for volume commands\n" + " volume bitrot help - display help for volume" + " bitrot commands\n" + " volume quota help - display help for volume" + " quota commands\n" + " snapshot help - display help for snapshot commands\n" + " global help - list global commands\n"); + exit(0); + } if (strcmp(opt, "version") == 0) { cli_out("%s", argp_program_version); @@ -379,6 +436,12 @@ cli_opt_parse(char *opt, struct cli_state *state) return 0; } + oarg = strtail(opt, "inet6"); + if (oarg) { + state->address_family = "inet6"; + return 0; + } + oarg = strtail(opt, "log-file="); if (oarg) { state->log_file = oarg; @@ -454,7 +517,8 @@ parse_cmdline(int argc, char *argv[], struct cli_state *state) continue; ret = cli_opt_parse(opt, state); if (ret == -1) { - cli_out("unrecognized option --%s", opt); + cli_out("unrecognized option --%s\n", opt); + usage(); return ret; } else if (ret == -2) { return ret; @@ -600,9 +664,8 @@ cli_quotad_clnt_rpc_init(void) global_quotad_rpc = rpc; out: - if (ret) { - if (rpc_opts) - dict_unref(rpc_opts); + if (rpc_opts) { + dict_unref(rpc_opts); } return rpc; } @@ -624,6 +687,15 @@ cli_rpc_init(struct cli_state *state) this = THIS; cli_rpc_prog = &cli_prog; + options = dict_new(); + if (!options) + goto out; + + /* If address family specified in CLI */ + if (state->address_family) { + addr_family = state->address_family; + } + /* Connect to glusterd using the specified method, giving preference * to a unix socket connection. If nothing is specified, connect to * the default glusterd socket. @@ -633,7 +705,7 @@ cli_rpc_init(struct cli_state *state) "Connecting to glusterd using " "sockfile %s", state->glusterd_sock); - ret = rpc_transport_unix_options_build(&options, state->glusterd_sock, + ret = rpc_transport_unix_options_build(options, state->glusterd_sock, 0); if (ret) goto out; @@ -643,10 +715,6 @@ cli_rpc_init(struct cli_state *state) "%s", state->remote_host); - options = dict_new(); - if (!options) - goto out; - ret = dict_set_str(options, "remote-host", state->remote_host); if (ret) goto out; @@ -665,7 +733,7 @@ cli_rpc_init(struct cli_state *state) gf_log("cli", GF_LOG_DEBUG, "Connecting to glusterd using " "default socket"); - ret = rpc_transport_unix_options_build(&options, + ret = rpc_transport_unix_options_build(options, DEFAULT_GLUSTERD_SOCKFILE, 0); if (ret) goto out; @@ -683,6 +751,9 @@ cli_rpc_init(struct cli_state *state) ret = rpc_clnt_start(rpc); out: + if (options) + dict_unref(options); + if (ret) { if (rpc) rpc_clnt_unref(rpc); @@ -727,8 +798,7 @@ main(int argc, char *argv[]) int ret = -1; glusterfs_ctx_t *ctx = NULL; - mem_pools_init_early(); - mem_pools_init_late(); + mem_pools_init(); ctx = glusterfs_ctx_new(); if (!ctx) @@ -781,15 +851,11 @@ main(int argc, char *argv[]) if (ret) goto out; - ret = cli_cmd_cond_init(); - if (ret) - goto out; - ret = cli_input_init(&state); if (ret) goto out; - ret = event_dispatch(ctx->event_pool); + ret = gf_event_dispatch(ctx->event_pool); out: // glusterfs_ctx_destroy (ctx); |
