/*
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>
#include <stdint.h>
#include <pthread.h>
#include <sys/socket.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <netinet/in.h>
#ifndef _CONFIG_H
#define _CONFIG_H
#include "config.h"
#endif
#include "cli.h"
#include "cli-cmd.h"
#include "cli-mem-types.h"
#include "cli1-xdr.h"
#include "run.h"
#include "syscall.h"
#include "common-utils.h"
extern struct rpc_clnt *global_rpc;
extern struct rpc_clnt *global_quotad_rpc;
extern rpc_clnt_prog_t *cli_rpc_prog;
extern rpc_clnt_prog_t cli_quotad_clnt;
int
cli_cmd_volume_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word,
const char **words, int wordcount);
int
cli_cmd_volume_info_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;
cli_cmd_volume_get_ctx_t ctx = {0,};
cli_local_t *local = NULL;
int sent = 0;
int parse_error = 0;
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_GET_VOLUME];
frame = create_frame (THIS, THIS->ctx->pool);
if (!frame)
goto out;
if ((wordcount == 2) || (wordcount == 3 &&
!strcmp (words[2], "all"))) {
ctx.flags = GF_CLI_GET_NEXT_VOLUME;
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_GET_NEXT_VOLUME];
} else if (wordcount == 3) {
ctx.flags = GF_CLI_GET_VOLUME;
ctx.volname = (char *)words[2];
if (strlen (ctx.volname) > GD_VOLUME_NAME_MAX) {
cli_out ("Invalid volume name");
goto out;
}
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_GET_VOLUME];
} else {
cli_usage_out (word->pattern);
parse_error = 1;
return -1;
}
local = cli_local_get ();
if (!local)
goto out;
local->get_vol.flags = ctx.flags;
if (ctx.volname)
local->get_vol.volname = gf_strdup (ctx.volname);
frame->local = local;
if (proc->fn) {
ret = proc->fn (frame, THIS, &ctx);
}
out:
if (ret) {
cli_cmd_sent_status_get (&sent);
if ((sent == 0) && (parse_error == 0))
cli_out ("Getting Volume information failed!");
}
CLI_STACK_DESTROY (frame);
return ret;
}
int
cli_cmd_sync_volume_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;
int sent = 0;
int parse_error = 0;
dict_t *dict = NULL;
cli_local_t *local = NULL;
gf_answer_t answer = GF_ANSWER_NO;
const char *question = "Sync volume may make data "
"inaccessible while the sync "
"is in progress. Do you want "
"to continue?";
if ((wordcount < 3) || (wordcount > 4)) {
cli_usage_out (word->pattern);
parse_error = 1;
goto out;
}
dict = dict_new ();
if (!dict)
goto out;
if ((wordcount == 3) || !strcmp(words[3], "all")) {
ret = dict_set_int32 (dict, "flags", (int32_t)
GF_CLI_SYNC_ALL);
if (ret) {
gf_log (THIS->name, GF_LOG_ERROR, "failed to set"
"flag");
goto out;
}
} else {
ret = dict_set_str (dict, "volname", (char *) words[3]);
if (ret) {
gf_log (THIS->name, GF_LOG_ERROR, "failed to set "
"volume");
goto out;
}
}
ret = dict_set_str (dict, "hostname", (char *) words[2]);
if (ret) {
gf_log (THIS->name, GF_LOG_ERROR, "failed to set hostname");
goto out;
}
if (!(state->mode & GLUSTER_MODE_SCRIPT)) {
answer = cli_cmd_get_confirmation (state, question);
if (GF_ANSWER_NO == answer) {
ret = 0;
goto out;
}
}
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_SYNC_VOLUME];
frame = create_frame (THIS, THIS->ctx->pool);
if (!frame)
goto out;
CLI_LOCAL_INIT (local, words, frame, dict);
if (proc->fn) {
ret = proc->fn (frame, THIS, dict);
}
out:
if (ret) {
cli_cmd_sent_status_get (&sent);
if ((sent == 0) && (parse_error == 0))
cli_out ("Volume sync failed");
}
CLI_STACK_DESTROY (frame);
return ret;
}
int
cli_cmd_volume_create_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;
int sent = 0;
int parse_error = 0;
char *brick_list = NULL;
int32_t brick_count = 0;
int32_t sub_count = 0;
int32_t type = GF_CLUSTER_TYPE_NONE;
cli_local_t *local = NULL;
char *trans_type = NULL;
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_CREATE_VOLUME];
frame = create_frame (THIS, THIS->ctx->pool);
if (!frame)
goto out;
ret = cli_cmd_volume_create_parse (state, words, wordcount, &options);
if (ret) {
cli_usage_out (word->pattern);
parse_error = 1;
goto out;
}
ret = dict_get_str (options, "transport", &trans_type);
if (ret) {
|