summaryrefslogtreecommitdiffstats
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/src/Makefile.am15
-rw-r--r--cli/src/cli-cmd-global.c71
-rw-r--r--cli/src/cli-cmd-misc.c21
-rw-r--r--cli/src/cli-cmd-parser.c798
-rw-r--r--cli/src/cli-cmd-peer.c42
-rw-r--r--cli/src/cli-cmd-snapshot.c14
-rw-r--r--cli/src/cli-cmd-system.c92
-rw-r--r--cli/src/cli-cmd-volume.c902
-rw-r--r--cli/src/cli-cmd.c46
-rw-r--r--cli/src/cli-cmd.h5
-rw-r--r--cli/src/cli-mem-types.h2
-rw-r--r--cli/src/cli-quotad-client.c18
-rw-r--r--cli/src/cli-quotad-client.h4
-rw-r--r--cli/src/cli-rl.c16
-rw-r--r--cli/src/cli-rpc-ops.c3757
-rw-r--r--cli/src/cli-xml-output.c581
-rw-r--r--cli/src/cli.c229
-rw-r--r--cli/src/cli.h66
-rw-r--r--cli/src/input.c3
19 files changed, 2546 insertions, 4136 deletions
diff --git a/cli/src/Makefile.am b/cli/src/Makefile.am
index 6be070f6ff7..16063f27c7f 100644
--- a/cli/src/Makefile.am
+++ b/cli/src/Makefile.am
@@ -1,12 +1,11 @@
-if WITH_SERVER
sbin_PROGRAMS = gluster
-endif
gluster_SOURCES = cli.c registry.c input.c cli-cmd.c cli-rl.c cli-cmd-global.c \
cli-cmd-volume.c cli-cmd-peer.c cli-rpc-ops.c cli-cmd-parser.c\
cli-cmd-system.c cli-cmd-misc.c cli-xml-output.c cli-quotad-client.c cli-cmd-snapshot.c
gluster_LDADD = $(top_builddir)/libglusterfs/src/libglusterfs.la $(GF_LDADD) \
+ $(top_builddir)/libglusterd/src/libglusterd.la \
$(RLLIBS) $(top_builddir)/rpc/xdr/src/libgfxdr.la \
$(top_builddir)/rpc/rpc-lib/src/libgfrpc.la \
$(XML_LIBS)
@@ -15,13 +14,14 @@ gluster_LDFLAGS = $(GF_LDFLAGS)
noinst_HEADERS = cli.h cli-mem-types.h cli-cmd.h cli-quotad-client.h
AM_CPPFLAGS = $(GF_CPPFLAGS) \
- -I$(top_srcdir)/libglusterfs/src -I$(top_srcdir)/rpc/rpc-lib/src\
- -I$(top_srcdir)/rpc/xdr/src\
- -I$(top_builddir)/rpc/xdr/src\
+ -I$(top_srcdir)/libglusterfs/src -I$(top_srcdir)/rpc/rpc-lib/src \
+ -I$(top_srcdir)/rpc/xdr/src -I$(top_srcdir)/libglusterd/src \
+ -I$(top_builddir)/rpc/xdr/src \
-DDATADIR=\"$(localstatedir)\" \
-DCONFDIR=\"$(sysconfdir)/glusterfs\" \
-DGSYNCD_PREFIX=\"$(GLUSTERFS_LIBEXECDIR)\"\
- -DSYNCDAEMON_COMPILE=$(SYNCDAEMON_COMPILE) -DSBIN_DIR=\"$(sbindir)\"
+ -DGLFSHEAL_PREFIX=\"$(GLUSTERFS_LIBEXECDIR)\"\
+ -DSYNCDAEMON_COMPILE=$(SYNCDAEMON_COMPILE)
AM_CFLAGS = -Wall $(GF_CFLAGS) $(XML_CFLAGS)
@@ -30,5 +30,8 @@ CLEANFILES =
$(top_builddir)/libglusterfs/src/libglusterfs.la:
$(MAKE) -C $(top_builddir)/libglusterfs/src/ all
+$(top_builddir)/libglusterd/src/libglusterd.la:
+ $(MAKE) -C $(top_builddir)/libglusterd/src/ all
+
install-data-hook:
$(mkdir_p) $(DESTDIR)$(localstatedir)/run/gluster
diff --git a/cli/src/cli-cmd-global.c b/cli/src/cli-cmd-global.c
index e1bedf13542..2c9a5f01bb1 100644
--- a/cli/src/cli-cmd-global.c
+++ b/cli/src/cli-cmd-global.c
@@ -23,11 +23,9 @@
#include "cli-cmd.h"
#include "cli-mem-types.h"
#include "cli1-xdr.h"
-#include "run.h"
-#include "syscall.h"
-#include "common-utils.h"
-
-extern rpc_clnt_prog_t *cli_rpc_prog;
+#include <glusterfs/run.h>
+#include <glusterfs/syscall.h>
+#include <glusterfs/common-utils.h>
int
cli_cmd_global_help_cbk(struct cli_state *state, struct cli_cmd_word *in_word,
@@ -36,6 +34,10 @@ int
cli_cmd_get_state_cbk(struct cli_state *state, struct cli_cmd_word *word,
const char **words, int wordcount);
+int
+cli_cmd_ganesha_cbk(struct cli_state *state, struct cli_cmd_word *word,
+ const char **words, int wordcount);
+
struct cli_cmd global_cmds[] = {
{
"global help",
@@ -48,6 +50,11 @@ struct cli_cmd global_cmds[] = {
cli_cmd_get_state_cbk,
"Get local state representation of mentioned daemon",
},
+ {
+ "nfs-ganesha {enable| disable} ",
+ cli_cmd_ganesha_cbk,
+ "Enable/disable NFS-Ganesha support",
+ },
{NULL, NULL, NULL}};
int
@@ -89,8 +96,9 @@ out:
}
int
-cli_cmd_get_state_cbk(struct cli_state *state, struct cli_cmd_word *word,
- const char **words, int wordcount)
+cli_cmd_ganesha_cbk(struct cli_state *state, struct cli_cmd_word *word,
+ const char **words, int wordcount)
+
{
int sent = 0;
int parse_error = 0;
@@ -101,10 +109,53 @@ cli_cmd_get_state_cbk(struct cli_state *state, struct cli_cmd_word *word,
cli_local_t *local = NULL;
char *op_errstr = NULL;
+ proc = &cli_rpc_prog->proctable[GLUSTER_CLI_GANESHA];
+
frame = create_frame(THIS, THIS->ctx->pool);
if (!frame)
goto out;
+ ret = cli_cmd_ganesha_parse(state, words, wordcount, &options, &op_errstr);
+ if (ret) {
+ if (op_errstr) {
+ cli_err("%s", op_errstr);
+ GF_FREE(op_errstr);
+ } else
+ cli_usage_out(word->pattern);
+ parse_error = 1;
+ goto out;
+ }
+
+ CLI_LOCAL_INIT(local, words, frame, options);
+
+ if (proc->fn) {
+ ret = proc->fn(frame, THIS, options);
+ }
+
+out:
+ if (ret) {
+ cli_cmd_sent_status_get(&sent);
+ if ((sent == 0) && (parse_error == 0))
+ cli_out("Setting global option failed");
+ }
+
+ CLI_STACK_DESTROY(frame);
+ return ret;
+}
+
+int
+cli_cmd_get_state_cbk(struct cli_state *state, struct cli_cmd_word *word,
+ const char **words, int wordcount)
+{
+ int sent = 0;
+ int parse_error = 0;
+ int ret = -1;
+ rpc_clnt_procedure_t *proc = NULL;
+ call_frame_t *frame = NULL;
+ dict_t *options = NULL;
+ cli_local_t *local = NULL;
+ char *op_errstr = NULL;
+
ret = cli_cmd_get_state_parse(state, words, wordcount, &options,
&op_errstr);
@@ -120,6 +171,12 @@ cli_cmd_get_state_cbk(struct cli_state *state, struct cli_cmd_word *word,
goto out;
}
+ frame = create_frame(THIS, THIS->ctx->pool);
+ if (!frame) {
+ ret = -1;
+ goto out;
+ }
+
CLI_LOCAL_INIT(local, words, frame, options);
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_GET_STATE];
diff --git a/cli/src/cli-cmd-misc.c b/cli/src/cli-cmd-misc.c
index 04dd2efc220..e961d88da86 100644
--- a/cli/src/cli-cmd-misc.c
+++ b/cli/src/cli-cmd-misc.c
@@ -18,14 +18,9 @@
#include "cli-mem-types.h"
#include "protocol-common.h"
-extern struct rpc_clnt *global_rpc;
-
-extern rpc_clnt_prog_t *cli_rpc_prog;
-
extern struct cli_cmd volume_cmds[];
extern struct cli_cmd bitrot_cmds[];
extern struct cli_cmd quota_cmds[];
-extern struct cli_cmd tier_cmds[];
extern struct cli_cmd cli_probe_cmds[];
extern struct cli_cmd cli_log_cmds[];
extern struct cli_cmd cli_system_cmds[];
@@ -58,19 +53,9 @@ int
cli_cmd_display_help(struct cli_state *state, struct cli_cmd_word *in_word,
const char **words, int wordcount)
{
- struct cli_cmd *cmd[] = {
- cli_misc_cmds,
- cli_probe_cmds,
- volume_cmds,
- bitrot_cmds,
- quota_cmds,
-#if !defined(__NetBSD__)
- tier_cmds,
-#endif
- snapshot_cmds,
- global_cmds,
- NULL
- };
+ static struct cli_cmd *cmd[] = {
+ cli_misc_cmds, cli_probe_cmds, volume_cmds, bitrot_cmds,
+ quota_cmds, snapshot_cmds, global_cmds, NULL};
struct cli_cmd *cmd_ind = NULL;
int i = 0;
gf_boolean_t list_all = _gf_false;
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
index 3f9056b5d9e..34620b4a31b 100644
--- a/cli/src/cli-cmd-parser.c
+++ b/cli/src/cli-cmd-parser.c
@@ -18,15 +18,15 @@
#include "cli.h"
#include "cli-cmd.h"
#include "cli-mem-types.h"
-#include "dict.h"
-#include "list.h"
+#include <glusterfs/dict.h>
+#include <glusterfs/list.h>
#include "protocol-common.h"
#include "cli1-xdr.h"
#define MAX_SNAP_DESCRIPTION_LEN 1024
-struct snap_config_opt_vals_ snap_confopt_vals[] = {
+static struct snap_config_opt_vals_ snap_confopt_vals[] = {
{.op_name = "snap-max-hard-limit",
.question = "Changing snapshot-max-hard-limit "
"will limit the creation of new snapshots "
@@ -80,6 +80,95 @@ str_getunamb(const char *tok, char **opwords)
}
int32_t
+cli_cmd_ta_brick_parse(const char **words, int wordcount, char **ta_brick)
+{
+ char *host_name = NULL;
+ char *tmp_host = NULL;
+ char *delimiter = NULL;
+ cli_brick_t *brick = NULL;
+ int ret = 0;
+
+ GF_ASSERT(words);
+ GF_ASSERT(wordcount);
+
+ if (validate_brick_name((char *)words[wordcount - 1])) {
+ cli_err(
+ "Wrong brick type: %s, use <HOSTNAME>:"
+ "<export-dir-abs-path>",
+ words[wordcount - 1]);
+ ret = -1;
+ goto out;
+ } else {
+ delimiter = strrchr(words[wordcount - 1], ':');
+ ret = gf_canonicalize_path(delimiter + 1);
+ if (ret)
+ goto out;
+ }
+
+ tmp_host = gf_strdup((char *)words[wordcount - 1]);
+ if (!tmp_host) {
+ gf_log("cli", GF_LOG_ERROR, "Out of memory");
+ ret = -1;
+ goto out;
+ }
+ get_host_name(tmp_host, &host_name);
+ if (!host_name) {
+ ret = -1;
+ gf_log("cli", GF_LOG_ERROR,
+ "Unable to retrieve "
+ "hostname");
+ goto out;
+ }
+
+ if (!(strcmp(host_name, "localhost") && strcmp(host_name, "127.0.0.1") &&
+ strncmp(host_name, "0.", 2))) {
+ cli_err(
+ "Please provide a valid hostname/ip other "
+ "than localhost, 127.0.0.1 or loopback "
+ "address (0.0.0.0 to 0.255.255.255).");
+ ret = -1;
+ goto out;
+ }
+ if (!valid_internet_address(host_name, _gf_false, _gf_false)) {
+ cli_err(
+ "internet address '%s' does not conform to "
+ "standards",
+ host_name);
+ }
+
+ brick = GF_MALLOC(sizeof(cli_brick_t), gf_common_list_node);
+ if (brick == NULL) {
+ ret = -1;
+ gf_log("cli", GF_LOG_ERROR, "Out of memory");
+ goto out;
+ }
+
+ brick->name = words[wordcount - 1];
+ brick->len = strlen(words[wordcount - 1]);
+ *ta_brick = GF_MALLOC(brick->len + 3, gf_common_mt_char);
+ if (*ta_brick == NULL) {
+ ret = -1;
+ gf_log("cli", GF_LOG_ERROR, "Out of memory");
+ goto out;
+ }
+
+ strcat(*ta_brick, " ");
+ strcat(*ta_brick, brick->name);
+ strcat(*ta_brick, " ");
+out:
+ if (tmp_host) {
+ GF_FREE(tmp_host);
+ tmp_host = NULL;
+ }
+ if (brick) {
+ GF_FREE(brick);
+ brick = NULL;
+ }
+
+ return ret;
+}
+
+int32_t
cli_cmd_bricks_parse(const char **words, int wordcount, int brick_index,
char **bricks, int *brick_count)
{
@@ -144,7 +233,7 @@ cli_cmd_bricks_parse(const char **words, int wordcount, int brick_index,
GF_FREE(tmp_host);
goto out;
}
- if (!valid_internet_address(host_name, _gf_false)) {
+ if (!valid_internet_address(host_name, _gf_false, _gf_false)) {
cli_err(
"internet address '%s' does not conform to "
"standards",
@@ -310,10 +399,10 @@ cli_cmd_create_disperse_check(struct cli_state *state, int *disperse,
tmp = *disperse - *redundancy;
}
- if (*redundancy > (*disperse - 1) / 2) {
+ if ((*redundancy < 1) || (*redundancy > (*disperse - 1) / 2)) {
cli_err(
- "redundancy must be less than %d for a "
- "disperse %d volume",
+ "redundancy must be greater than or equal to 1 and "
+ "less than %d for a disperse %d volume",
(*disperse + 1) / 2, *disperse);
return -1;
@@ -392,21 +481,6 @@ cli_validate_disperse_volume(char *word, gf1_cluster_type type,
ret = 2;
}
break;
- case GF_CLUSTER_TYPE_STRIPE_REPLICATE:
- cli_err(
- "striped-replicated-dispersed volume "
- "is not supported");
- goto out;
- case GF_CLUSTER_TYPE_TIER:
- cli_err(
- "tier-dispersed volume is not "
- "supported");
- goto out;
- case GF_CLUSTER_TYPE_STRIPE:
- cli_err(
- "striped-dispersed volume is not "
- "supported");
- goto out;
case GF_CLUSTER_TYPE_REPLICATE:
cli_err(
"replicated-dispersed volume is not "
@@ -491,14 +565,17 @@ cli_cmd_volume_create_parse(struct cli_state *state, const char **words,
char *trans_type = NULL;
int32_t index = 0;
char *bricks = NULL;
+ char *ta_brick = NULL;
int32_t brick_count = 0;
- char *opwords[] = {"replica", "stripe", "transport", "disperse",
- "redundancy", "disperse-data", "arbiter", NULL};
+ static char *opwords[] = {"replica", "stripe", "transport",
+ "disperse", "redundancy", "disperse-data",
+ "arbiter", "thin-arbiter", NULL};
char *w = NULL;
int op_count = 0;
int32_t replica_count = 1;
int32_t arbiter_count = 0;
+ int32_t thin_arbiter_count = 0;
int32_t stripe_count = 1;
int32_t disperse_count = -1;
int32_t redundancy_count = -1;
@@ -550,14 +627,8 @@ cli_cmd_volume_create_parse(struct cli_state *state, const char **words,
type = GF_CLUSTER_TYPE_REPLICATE;
break;
case GF_CLUSTER_TYPE_STRIPE:
- type = GF_CLUSTER_TYPE_STRIPE_REPLICATE;
- break;
- case GF_CLUSTER_TYPE_TIER:
- cli_err(
- "replicated-tiered volume is not "
- "supported");
+ cli_err("stripe option not supported");
goto out;
- break;
case GF_CLUSTER_TYPE_DISPERSE:
cli_err(
"replicated-dispersed volume is not "
@@ -602,6 +673,26 @@ cli_cmd_volume_create_parse(struct cli_state *state, const char **words,
if (ret)
goto out;
index += 2;
+ } else if (!strcmp(words[index], "thin-arbiter")) {
+ ret = gf_string2int(words[index + 1], &thin_arbiter_count);
+ if ((ret == -1) || (thin_arbiter_count != 1) ||
+ (replica_count != 2)) {
+ cli_err(
+ "For thin-arbiter "
+ "configuration, "
+ "replica count must be"
+ " 2 and thin-arbiter count "
+ "must be 1. The 3rd "
+ "brick of the replica "
+ "will be the thin-arbiter brick");
+ ret = -1;
+ goto out;
+ }
+ ret = dict_set_int32(dict, "thin-arbiter-count",
+ thin_arbiter_count);
+ if (ret)
+ goto out;
+ index += 2;
}
}
@@ -610,7 +701,7 @@ cli_cmd_volume_create_parse(struct cli_state *state, const char **words,
if ((arbiter_count == 1) && (replica_count == 2))
replica_count += arbiter_count;
- if (replica_count == 2) {
+ if (replica_count == 2 && thin_arbiter_count == 0) {
if (strcmp(words[wordcount - 1], "force")) {
question =
"Replica 2 volumes are prone"
@@ -637,49 +728,8 @@ cli_cmd_volume_create_parse(struct cli_state *state, const char **words,
goto out;
} else if ((strcmp(w, "stripe")) == 0) {
- switch (type) {
- case GF_CLUSTER_TYPE_STRIPE_REPLICATE:
- case GF_CLUSTER_TYPE_STRIPE:
- cli_err("stripe option given twice");
- goto out;
- case GF_CLUSTER_TYPE_NONE:
- type = GF_CLUSTER_TYPE_STRIPE;
- break;
- case GF_CLUSTER_TYPE_REPLICATE:
- type = GF_CLUSTER_TYPE_STRIPE_REPLICATE;
- break;
- case GF_CLUSTER_TYPE_DISPERSE:
- cli_err(
- "striped-dispersed volume is not "
- "supported");
- goto out;
- case GF_CLUSTER_TYPE_TIER:
- cli_err(
- "striped-tier volume is not "
- "supported");
- goto out;
- default:
- cli_err("Invalid type given");
- goto out;
- }
- if (wordcount < (index + 2)) {
- ret = -1;
- goto out;
- }
- stripe_count = strtol(words[index + 1], NULL, 0);
- if (stripe_count < 2) {
- cli_err(
- "stripe count should be greater"
- " than 1");
- ret = -1;
- goto out;
- }
- ret = dict_set_int32(dict, "stripe-count", stripe_count);
- if (ret)
- goto out;
-
- index += 2;
-
+ cli_err("stripe option not supported");
+ goto out;
} else if ((strcmp(w, "transport")) == 0) {
if (trans_type) {
cli_err(
@@ -719,6 +769,12 @@ cli_cmd_volume_create_parse(struct cli_state *state, const char **words,
"option.");
ret = -1;
goto out;
+ } else if ((strcmp(w, "thin-arbiter") == 0)) {
+ cli_err(
+ "thin-arbiter option must be preceded by replica "
+ "option.");
+ ret = -1;
+ goto out;
} else {
GF_ASSERT(!"opword mismatch");
ret = -1;
@@ -742,7 +798,20 @@ cli_cmd_volume_create_parse(struct cli_state *state, const char **words,
wc = wordcount - 1;
}
- ret = cli_cmd_bricks_parse(words, wc, brick_index, &bricks, &brick_count);
+ // Exclude the thin-arbiter-brick i.e. last brick in the bricks list
+ if (thin_arbiter_count == 1) {
+ ret = cli_cmd_bricks_parse(words, wc - 1, brick_index, &bricks,
+ &brick_count);
+ if (ret)
+ goto out;
+
+ ret = cli_cmd_ta_brick_parse(words, wc, &ta_brick);
+
+ } else {
+ ret = cli_cmd_bricks_parse(words, wc, brick_index, &bricks,
+ &brick_count);
+ }
+
if (ret)
goto out;
@@ -801,6 +870,12 @@ cli_cmd_volume_create_parse(struct cli_state *state, const char **words,
if (ret)
goto out;
+ if (thin_arbiter_count == 1) {
+ ret = dict_set_dynstr(dict, "ta-brick", ta_brick);
+ if (ret)
+ goto out;
+ }
+
ret = dict_set_int32(dict, "count", brick_count);
if (ret)
goto out;
@@ -813,6 +888,8 @@ cli_cmd_volume_create_parse(struct cli_state *state, const char **words,
*brick_list = bricks;
out:
if (ret) {
+ GF_FREE(bricks);
+ GF_FREE(ta_brick);
gf_log("cli", GF_LOG_ERROR, "Unable to parse create volume CLI");
if (dict)
dict_unref(dict);
@@ -1118,19 +1195,19 @@ cli_cmd_quota_parse(const char **words, int wordcount, dict_t **options)
};
int64_t value = 0;
gf_quota_type type = GF_QUOTA_OPTION_TYPE_NONE;
- char *opwords[] = {"enable",
- "disable",
- "limit-usage",
- "remove",
- "list",
- "alert-time",
- "soft-timeout",
- "hard-timeout",
- "default-soft-limit",
- "limit-objects",
- "list-objects",
- "remove-objects",
- NULL};
+ static char *opwords[] = {"enable",
+ "disable",
+ "limit-usage",
+ "remove",
+ "list",
+ "alert-time",
+ "soft-timeout",
+ "hard-timeout",
+ "default-soft-limit",
+ "limit-objects",
+ "list-objects",
+ "remove-objects",
+ NULL};
char *w = NULL;
uint32_t time = 0;
double percent = 0;
@@ -1483,6 +1560,8 @@ cli_add_key_group_value(dict_t *dict, const char *name, const char *value,
}
data = gf_strdup(value);
if (data == NULL) {
+ gf_log(THIS->name, GF_LOG_ERROR, "Failed to allocate memory for data");
+ ret = -1;
goto out;
}
@@ -1544,6 +1623,11 @@ cli_add_key_group(dict_t *dict, char *key, char *value, char **op_errstr)
}
goto out;
}
+
+ /* Treat line that start with "#" as comments */
+ if ('#' == line[0])
+ continue;
+
opt_count++;
tok_key = strtok_r(line, "=", &saveptr);
tok_val = strtok_r(NULL, "\r\n", &saveptr);
@@ -1769,7 +1853,7 @@ cli_cmd_volume_add_brick_parse(struct cli_state *state, const char **words,
int ret = -1;
int brick_count = 0, brick_index = 0;
char *bricks = NULL;
- char *opwords_cl[] = {"replica", "stripe", NULL};
+ static char *opwords_cl[] = {"replica", "stripe", NULL};
gf1_cluster_type type = GF_CLUSTER_TYPE_NONE;
int count = 1;
int arbiter_count = 0;
@@ -1849,7 +1933,7 @@ cli_cmd_volume_add_brick_parse(struct cli_state *state, const char **words,
question =
"Replica 2 volumes are prone to "
"split-brain. Use Arbiter or "
- "Replica 3 to avaoid this. See: "
+ "Replica 3 to avoid this. See: "
"http://docs.gluster.org/en/latest/Administrator%20Guide/"
"Split%20brain%20and%20ways%20to%20deal%20with%20it/."
"\nDo you still want to continue?\n";
@@ -1864,17 +1948,8 @@ cli_cmd_volume_add_brick_parse(struct cli_state *state, const char **words,
}
}
} else if ((strcmp(w, "stripe")) == 0) {
- type = GF_CLUSTER_TYPE_STRIPE;
- count = strtol(words[4], NULL, 0);
- if (!count || (count < 2)) {
- cli_err("stripe count should be greater than 1");
- ret = -1;
- goto out;
- }
- ret = dict_set_int32(dict, "stripe-count", count);
- if (ret)
- goto out;
- index = 5;
+ cli_err("stripe option not supported");
+ goto out;
} else {
GF_ASSERT(!"opword mismatch");
ret = -1;
@@ -1923,146 +1998,6 @@ out:
}
int32_t
-cli_cmd_volume_tier_parse(const char **words, int wordcount, dict_t **options)
-{
- dict_t *dict = NULL;
- char *volname = NULL;
- int ret = -1;
- int32_t command = GF_DEFRAG_CMD_NONE;
- int32_t is_force = 0;
-
- GF_ASSERT(words);
- GF_ASSERT(options);
-
- dict = dict_new();
-
- if (!dict)
- goto out;
-
- if (!(wordcount == 4 || wordcount == 5)) {
- gf_log("cli", GF_LOG_ERROR, "Invalid Syntax");
- ret = -1;
- goto out;
- }
-
- volname = (char *)words[2];
-
- GF_ASSERT(volname);
-
- ret = cli_cmd_validate_volume(volname);
- if (ret) {
- gf_log("cli", GF_LOG_ERROR, "Failed to validate volume name");
- goto out;
- }
-
- ret = dict_set_str(dict, "volname", volname);
-
- if (ret)
- goto out;
-
- volname = (char *)words[2];
- if (wordcount == 4) {
- if (!strcmp(words[3], "status"))
- command = GF_DEFRAG_CMD_STATUS_TIER;
- else if (!strcmp(words[3], "start"))
- command = GF_DEFRAG_CMD_START_TIER;
- else if (!strcmp(words[3], "stop"))
- command = GF_DEFRAG_CMD_STOP_TIER;
- else {
- ret = -1;
- goto out;
- }
- } else if (wordcount == 5) {
- if ((!strcmp(words[3], "start")) && (!strcmp(words[4], "force"))) {
- command = GF_DEFRAG_CMD_START_TIER;
- is_force = 1;
- ret = dict_set_int32(dict, "force", is_force);
- if (ret)
- goto out;
- } else {
- ret = -1;
- goto out;
- }
- }
-
- ret = dict_set_int32(dict, "rebalance-command", command);
- if (ret)
- goto out;
-
- *options = dict;
-out:
-
- if (ret) {
- gf_log("cli", GF_LOG_ERROR, "Unable to parse tier CLI");
- if (dict)
- dict_unref(dict);
- }
-
- return ret;
-}
-
-int32_t
-cli_cmd_volume_detach_tier_parse(const char **words, int wordcount,
- dict_t **options, int *question)
-{
- int ret = -1;
- char *word = NULL;
- dict_t *dict = NULL;
- int32_t command = GF_DEFRAG_CMD_NONE;
-
- dict = dict_new();
- if (!dict)
- goto out;
-
- ret = dict_set_str(dict, "volname", (char *)words[2]);
- if (ret)
- goto out;
-
- if (wordcount == 3 && !strcmp((char *)words[2], "help")) {
- return -1;
- }
-
- if (wordcount != 4) {
- ret = -1;
- goto out;
- }
-
- word = (char *)words[3];
-
- ret = -1;
-
- if (!strcmp(word, "start")) {
- command = GF_DEFRAG_CMD_DETACH_START;
- } else if (!strcmp(word, "commit")) {
- *question = 1;
- command = GF_DEFRAG_CMD_DETACH_COMMIT;
- } else if (!strcmp(word, "force")) {
- *question = 1;
- command = GF_DEFRAG_CMD_DETACH_COMMIT_FORCE;
- } else if (!strcmp(word, "stop"))
- command = GF_DEFRAG_CMD_DETACH_STOP;
- else if (!strcmp(word, "status"))
- command = GF_DEFRAG_CMD_DETACH_STATUS;
- else
- goto out;
-
- ret = dict_set_int32(dict, "command", command);
- if (ret)
- goto out;
-
- *options = dict;
- ret = 0;
-out:
- if (ret) {
- gf_log("cli", GF_LOG_ERROR, "Unable to parse detach tier CLI");
- if (dict)
- dict_unref(dict);
- }
-
- return ret;
-}
-
-int32_t
cli_cmd_volume_remove_brick_parse(struct cli_state *state, const char **words,
int wordcount, dict_t **options,
int *question, int *brick_count,
@@ -2078,8 +2013,9 @@ cli_cmd_volume_remove_brick_parse(struct cli_state *state, const char **words,
int32_t j = 0;
char *tmp_brick = NULL;
char *tmp_brick1 = NULL;
- char *type_opword[] = {"replica", NULL};
- char *opwords[] = {"start", "commit", "stop", "status", "force", NULL};
+ static char *type_opword[] = {"replica", NULL};
+ static char *opwords[] = {"start", "commit", "stop",
+ "status", "force", NULL};
char *w = NULL;
int32_t command = GF_OP_CMD_NONE;
long count = 0;
@@ -2125,7 +2061,7 @@ cli_cmd_volume_remove_brick_parse(struct cli_state *state, const char **words,
ques =
"Replica 2 volumes are prone to "
"split-brain. Use Arbiter or Replica 3 "
- "to avaoid this. See: "
+ "to avoid this. See: "
"http://docs.gluster.org/en/latest/Administrator%20Guide/"
"Split%20brain%20and%20ways%20to%20deal%20with%20it/."
"\nDo you still want to continue?\n";
@@ -2650,8 +2586,6 @@ cli_cmd_log_rotate_parse(const char **words, int wordcount, dict_t **options)
if (strcmp("rotate", words[3]) == 0)
volname = (char *)words[2];
- else if (strcmp("rotate", words[2]) == 0)
- volname = (char *)words[3];
GF_ASSERT(volname);
ret = dict_set_str(dict, "volname", volname);
@@ -2694,6 +2628,17 @@ gsyncd_url_check(const char *w)
}
static gf_boolean_t
+valid_slave_gsyncd_url(const char *w)
+{
+ if (strstr(w, ":::"))
+ return _gf_false;
+ else if (strstr(w, "::"))
+ return _gf_true;
+ else
+ return _gf_false;
+}
+
+static gf_boolean_t
gsyncd_glob_check(const char *w)
{
return !!strpbrk(w, "*?[");
@@ -2743,7 +2688,10 @@ config_parse(const char **words, int wordcount, dict_t *dict, unsigned cmdi,
/* trailing strcat will add two bytes, make space for that */
append_len++;
- append_str = GF_MALLOC(append_len, cli_mt_append_str);
+ /* strcat is used on this allocation and hence expected to be
+ * initiatlized to 0. So GF_CALLOC is used.
+ */
+ append_str = GF_CALLOC(1, append_len, cli_mt_append_str);
if (!append_str) {
ret = -1;
goto out;
@@ -2778,7 +2726,7 @@ config_parse(const char **words, int wordcount, dict_t *dict, unsigned cmdi,
ret_chkpt = strptime(append_str, "%Y-%m-%d %H:%M:%S",
&checkpoint_time);
- if (ret_chkpt == NULL) {
+ if (ret_chkpt == NULL || *ret_chkpt != '\0') {
ret = -1;
cli_err(
"Invalid Checkpoint label. Use format "
@@ -2879,7 +2827,7 @@ force_push_pem_no_verify_parse(const char **words, int wordcount, dict_t *dict,
ret = -1;
goto out;
}
- ret = dict_set_uint32(dict, "force", _gf_true);
+ ret = dict_set_int32n(dict, "force", SLEN("force"), 1);
if (ret)
goto out;
(*cmdi)++;
@@ -2913,7 +2861,8 @@ out:
}
int32_t
-cli_cmd_gsync_set_parse(const char **words, int wordcount, dict_t **options)
+cli_cmd_gsync_set_parse(struct cli_state *state, const char **words,
+ int wordcount, dict_t **options, char **errstr)
{
int32_t ret = -1;
dict_t *dict = NULL;
@@ -2923,13 +2872,16 @@ cli_cmd_gsync_set_parse(const char **words, int wordcount, dict_t **options)
unsigned slavei = 0;
unsigned glob = 0;
unsigned cmdi = 0;
- char *opwords[] = {"create", "status", "start", "stop", "config",
- "force", "delete", "ssh-port", "no-verify", "push-pem",
- "detail", "pause", "resume", NULL};
+ static char *opwords[] = {"create", "status", "start", "stop",
+ "config", "force", "delete", "ssh-port",
+ "no-verify", "push-pem", "detail", "pause",
+ "resume", NULL};
char *w = NULL;
char *save_ptr = NULL;
char *slave_temp = NULL;
char *token = NULL;
+ gf_answer_t answer = GF_ANSWER_NO;
+ const char *question = NULL;
GF_ASSERT(words);
GF_ASSERT(options);
@@ -3002,8 +2954,11 @@ cli_cmd_gsync_set_parse(const char **words, int wordcount, dict_t **options)
if (masteri && gsyncd_url_check(words[masteri]))
goto out;
- if (slavei && !glob && !gsyncd_url_check(words[slavei]))
+
+ if (slavei && !glob && !valid_slave_gsyncd_url(words[slavei])) {
+ gf_asprintf(errstr, "Invalid slave url: %s", words[slavei]);
goto out;
+ }
w = str_getunamb(words[cmdi], opwords);
if (!w)
@@ -3080,8 +3035,10 @@ cli_cmd_gsync_set_parse(const char **words, int wordcount, dict_t **options)
cmdi++;
}
- if (type != GF_GSYNC_OPTION_TYPE_CONFIG && (cmdi < wordcount - 1 || glob))
+ if (type != GF_GSYNC_OPTION_TYPE_CONFIG && (cmdi < wordcount - 1 || glob)) {
+ ret = -1;
goto out;
+ }
/* If got so far, input is valid, assemble the message */
@@ -3111,16 +3068,36 @@ cli_cmd_gsync_set_parse(const char **words, int wordcount, dict_t **options)
}
if (!ret)
ret = dict_set_int32(dict, "type", type);
- if (!ret && type == GF_GSYNC_OPTION_TYPE_CONFIG)
+ if (!ret && type == GF_GSYNC_OPTION_TYPE_CONFIG) {
+ if (!strcmp((char *)words[wordcount - 2], "ignore-deletes") &&
+ !strcmp((char *)words[wordcount - 1], "true")) {
+ question =
+ "There exists ~15 seconds delay for the option to take"
+ " effect from stime of the corresponding brick. Please"
+ " check the log for the time, the option is effective."
+ " Proceed";
+
+ answer = cli_cmd_get_confirmation(state, question);
+
+ if (GF_ANSWER_NO == answer) {
+ gf_log("cli", GF_LOG_INFO,
+ "Operation "
+ "cancelled, exiting");
+ *errstr = gf_strdup("Aborted by user.");
+ ret = -1;
+ goto out;
+ }
+ }
+
ret = config_parse(words, wordcount, dict, cmdi, glob);
+ }
out:
if (slave_temp)
GF_FREE(slave_temp);
- if (ret) {
- if (dict)
- dict_unref(dict);
- } else
+ if (ret && dict)
+ dict_unref(dict);
+ else
*options = dict;
return ret;
@@ -3137,7 +3114,7 @@ cli_cmd_volume_profile_parse(const char **words, int wordcount,
gf1_cli_info_op info_op = GF_CLI_INFO_NONE;
gf_boolean_t is_peek = _gf_false;
- char *opwords[] = {"start", "stop", "info", NULL};
+ static char *opwords[] = {"start", "stop", "info", NULL};
char *w = NULL;
GF_ASSERT(words);
@@ -3162,11 +3139,15 @@ cli_cmd_volume_profile_parse(const char **words, int wordcount,
goto out;
}
- if ((strcmp(w, "start") == 0 || strcmp(w, "stop") == 0) && wordcount > 5)
+ if ((strcmp(w, "start") == 0 || strcmp(w, "stop") == 0) && wordcount > 5) {
+ ret = -1;
goto out;
+ }
- if (strcmp(w, "info") == 0 && wordcount > 7)
+ if (strcmp(w, "info") == 0 && wordcount > 7) {
+ ret = -1;
goto out;
+ }
if (strcmp(w, "start") == 0) {
op = GF_CLI_STATS_START;
@@ -3234,8 +3215,9 @@ cli_cmd_volume_top_parse(const char **words, int wordcount, dict_t **options)
int count = 0;
gf_boolean_t nfs = _gf_false;
char *delimiter = NULL;
- char *opwords[] = {"open", "read", "write", "opendir", "readdir",
- "read-perf", "write-perf", "clear", NULL};
+ static char *opwords[] = {"open", "read", "write",
+ "opendir", "readdir", "read-perf",
+ "write-perf", "clear", NULL};
char *w = NULL;
GF_ASSERT(words);
@@ -3414,9 +3396,9 @@ cli_cmd_get_statusop(const char *arg)
int i = 0;
uint32_t ret = GF_CLI_STATUS_NONE;
char *w = NULL;
- char *opwords[] = {"detail", "mem", "clients", "fd", "inode",
- "callpool", "tasks", "client-list", NULL};
- struct {
+ static char *opwords[] = {"detail", "mem", "clients", "fd", "inode",
+ "callpool", "tasks", "client-list", NULL};
+ static struct {
char *opname;
uint32_t opcode;
} optable[] = {{"detail", GF_CLI_STATUS_DETAIL},
@@ -3503,8 +3485,6 @@ cli_cmd_volume_status_parse(const char **words, int wordcount, dict_t **options)
cmd |= GF_CLI_STATUS_QUOTAD;
} else if (!strcmp(words[3], "snapd")) {
cmd |= GF_CLI_STATUS_SNAPD;
- } else if (!strcmp(words[3], "tierd")) {
- cmd |= GF_CLI_STATUS_TIERD;
} else if (!strcmp(words[3], "bitd")) {
cmd |= GF_CLI_STATUS_BITD;
} else if (!strcmp(words[3], "scrub")) {
@@ -3580,16 +3560,6 @@ cli_cmd_volume_status_parse(const char **words, int wordcount, dict_t **options)
goto out;
}
cmd |= GF_CLI_STATUS_SNAPD;
- } else if (!strcmp(words[3], "tierd")) {
- if (cmd == GF_CLI_STATUS_FD || cmd == GF_CLI_STATUS_CLIENTS ||
- cmd == GF_CLI_STATUS_DETAIL || cmd == GF_CLI_STATUS_INODE) {
- cli_err(
- "Detail/FD/Clients/Inode status not "
- "available for tier daemon");
- ret = -1;
- goto out;
- }
- cmd |= GF_CLI_STATUS_TIERD;
} else {
if (cmd == GF_CLI_STATUS_TASKS) {
cli_err(
@@ -3626,9 +3596,9 @@ out:
gf_boolean_t
cli_cmd_validate_dumpoption(const char *arg, char **option)
{
- char *opwords[] = {"all", "nfs", "mem", "iobuf", "callpool",
- "priv", "fd", "inode", "history", "inodectx",
- "fdctx", "quotad", NULL};
+ static char *opwords[] = {"all", "nfs", "mem", "iobuf", "callpool",
+ "priv", "fd", "inode", "history", "inodectx",
+ "fdctx", "quotad", NULL};
char *w = NULL;
w = str_getunamb(arg, opwords);
@@ -3663,7 +3633,7 @@ cli_cmd_volume_statedump_options_parse(const char **words, int wordcount,
}
ip_addr = strtok(tmp, ":");
pid = strtok(NULL, ":");
- if (valid_internet_address(ip_addr, _gf_true) && pid &&
+ if (valid_internet_address(ip_addr, _gf_true, _gf_false) && pid &&
gf_valid_pid(pid, strlen(pid))) {
ret = gf_asprintf(&option_str, "%s %s %s", words[3], ip_addr, pid);
if (ret < 0) {
@@ -3857,7 +3827,7 @@ extract_hostname_path_from_token(const char *tmp_words, char **hostname,
ret = -1;
goto out;
}
- if (!valid_internet_address(host_name, _gf_false)) {
+ if (!valid_internet_address(host_name, _gf_false, _gf_false)) {
cli_err(
"internet address '%s' does not conform to "
"standards",
@@ -3936,8 +3906,6 @@ heal_command_type_get(const char *command)
[GF_SHD_OP_HEAL_INDEX] = NULL,
[GF_SHD_OP_HEAL_FULL] = "full",
[GF_SHD_OP_INDEX_SUMMARY] = "info",
- [GF_SHD_OP_HEALED_FILES] = NULL,
- [GF_SHD_OP_HEAL_FAILED_FILES] = NULL,
[GF_SHD_OP_SPLIT_BRAIN_FILES] = NULL,
[GF_SHD_OP_STATISTICS] = "statistics",
[GF_SHD_OP_STATISTICS_HEAL_COUNT] = NULL,
@@ -3965,8 +3933,11 @@ cli_cmd_volume_heal_options_parse(const char **words, int wordcount,
gf_xl_afr_op_t op = GF_SHD_OP_INVALID;
dict = dict_new();
- if (!dict)
+ if (!dict) {
+ gf_log(THIS->name, GF_LOG_ERROR, "Failed to create the dict");
+ ret = -1;
goto out;
+ }
ret = dict_set_str(dict, "volname", (char *)words[2]);
if (ret) {
@@ -4112,55 +4083,6 @@ out:
}
int
-cli_cmd_volume_old_tier_parse(const char **words, int wordcount,
- dict_t **options)
-{
- dict_t *dict = NULL;
- int ret = -1;
- char *volname = NULL;
- gf_cli_defrag_type cmd = 0;
-
- GF_ASSERT(words);
- GF_ASSERT(options);
-
- dict = dict_new();
- if (!dict)
- goto out;
-
- if (wordcount != 4)
- goto out;
-
- if ((strcmp(words[1], "tier") == 0) && (strcmp(words[3], "start") == 0)) {
- cmd = GF_DEFRAG_CMD_START_TIER;
- } else
- goto out;
-
- volname = (char *)words[2];
-
- ret = dict_set_str(dict, "volname", volname);
-
- if (ret) {
- gf_log(THIS->name, GF_LOG_ERROR, "failed to set dict");
- goto out;
- }
-
- ret = dict_set_int32(dict, "rebalance-command", (int32_t)cmd);
-
- if (ret) {
- gf_log(THIS->name, GF_LOG_ERROR, "failed to set dict");
- goto out;
- }
-
- *options = dict;
-
-out:
- if (ret && dict)
- dict_unref(dict);
-
- return ret;
-}
-
-int
cli_cmd_volume_defrag_parse(const char **words, int wordcount, dict_t **options)
{
dict_t *dict = NULL;
@@ -4509,7 +4431,7 @@ cli_snap_create_parse(dict_t *dict, const char **words, int wordcount)
}
if (strcmp(words[i], "no-timestamp") == 0) {
- ret = dict_set_str(dict, "no-timestamp", "true");
+ ret = dict_set_int32n(dict, "no-timestamp", SLEN("no-timestamp"), 1);
if (ret) {
gf_log("cli", GF_LOG_ERROR,
"Could not save "
@@ -5325,24 +5247,25 @@ cli_cmd_snapshot_parse(const char **words, int wordcount, dict_t **options,
dict_t *dict = NULL;
gf1_cli_snapshot type = GF_SNAP_OPTION_TYPE_NONE;
char *w = NULL;
- char *opwords[] = {"create", "delete", "restore", "activate",
- "deactivate", "list", "status", "config",
- "info", "clone", NULL};
- char *invalid_snapnames[] = {"description", "force", "volume", "all", NULL};
- char *invalid_volnames[] = {"volume",
- "type",
- "subvolumes",
- "option",
- "end-volume",
- "all",
- "volume_not_in_ring",
- "description",
- "force",
- "snap-max-hard-limit",
- "snap-max-soft-limit",
- "auto-delete",
- "activate-on-create",
- NULL};
+ static char *opwords[] = {"create", "delete", "restore", "activate",
+ "deactivate", "list", "status", "config",
+ "info", "clone", NULL};
+ static char *invalid_snapnames[] = {"description", "force", "volume", "all",
+ NULL};
+ static char *invalid_volnames[] = {"volume",
+ "type",
+ "subvolumes",
+ "option",
+ "end-volume",
+ "all",
+ "volume_not_in_ring",
+ "description",
+ "force",
+ "snap-max-hard-limit",
+ "snap-max-soft-limit",
+ "auto-delete",
+ "activate-on-create",
+ NULL};
GF_ASSERT(words);
GF_ASSERT(options);
@@ -5591,6 +5514,7 @@ cli_cmd_snapshot_parse(const char **words, int wordcount, dict_t **options,
break;
default:
+ ret = -1;
gf_log("", GF_LOG_ERROR, "Opword Mismatch");
goto out;
}
@@ -5661,16 +5585,18 @@ cli_cmd_bitrot_parse(const char **words, int wordcount, dict_t **options)
int32_t ret = -1;
char *w = NULL;
char *volname = NULL;
- char *opwords[] = {
- "enable", "disable", "scrub-throttle", "scrub-frequency", "scrub",
- "signing-time", NULL};
- char *scrub_throt_values[] = {"lazy", "normal", "aggressive", NULL};
- char *scrub_freq_values[] = {"hourly", "daily", "weekly", "biweekly",
- "monthly", "minute", NULL};
- char *scrub_values[] = {"pause", "resume", "status", "ondemand", NULL};
+ static char *opwords[] = {"enable", "disable", "scrub-throttle",
+ "scrub-frequency", "scrub", "signing-time",
+ "signer-threads", NULL};
+ static char *scrub_throt_values[] = {"lazy", "normal", "aggressive", NULL};
+ static char *scrub_freq_values[] = {
+ "hourly", "daily", "weekly", "biweekly", "monthly", "minute", NULL};
+ static char *scrub_values[] = {"pause", "resume", "status", "ondemand",
+ NULL};
dict_t *dict = NULL;
gf_bitrot_type type = GF_BITROT_OPTION_TYPE_NONE;
int32_t expiry_time = 0;
+ int32_t signer_th_count = 0;
GF_ASSERT(words);
GF_ASSERT(options);
@@ -5851,6 +5777,31 @@ cli_cmd_bitrot_parse(const char **words, int wordcount, dict_t **options)
}
goto set_type;
}
+ } else if (!strcmp(words[3], "signer-threads")) {
+ if (!words[4]) {
+ cli_err(
+ "Missing signer-thread value for bitrot "
+ "option");
+ ret = -1;
+ goto out;
+ } else {
+ type = GF_BITROT_OPTION_TYPE_SIGNER_THREADS;
+
+ signer_th_count = strtol(words[4], NULL, 0);
+ if (signer_th_count < 1) {
+ cli_err("signer-thread count should not be less than 1");
+ ret = -1;
+ goto out;
+ }
+
+ ret = dict_set_uint32(dict, "signer-threads",
+ (unsigned int)signer_th_count);
+ if (ret) {
+ cli_out("Failed to set dict for bitrot");
+ goto out;
+ }
+ goto set_type;
+ }
} else {
cli_err(
"Invalid option %s for bitrot. Please enter valid "
@@ -5859,7 +5810,6 @@ cli_cmd_bitrot_parse(const char **words, int wordcount, dict_t **options)
ret = -1;
goto out;
}
-
set_type:
ret = dict_set_int32(dict, "type", type);
if (ret < 0)
@@ -5876,3 +5826,121 @@ out:
return ret;
}
+
+/* Parsing global option for NFS-Ganesha config
+ * gluster nfs-ganesha enable/disable */
+
+int32_t
+cli_cmd_ganesha_parse(struct cli_state *state, const char **words,
+ int wordcount, dict_t **options, char **op_errstr)
+{
+ dict_t *dict = NULL;
+ int ret = -1;
+ char *key = NULL;
+ char *value = NULL;
+ char *w = NULL;
+ static char *opwords[] = {"enable", "disable", NULL};
+ const char *question = NULL;
+ gf_answer_t answer = GF_ANSWER_NO;
+
+ GF_ASSERT(words);
+ GF_ASSERT(options);
+
+ dict = dict_new();
+
+ if (!dict)
+ goto out;
+
+ if (wordcount != 2)
+ goto out;
+
+ key = (char *)words[0];
+ value = (char *)words[1];
+
+ if (!key || !value) {
+ cli_out("Usage : nfs-ganesha <enable/disable>");
+ ret = -1;
+ goto out;
+ }
+
+ ret = gf_strip_whitespace(value, strlen(value));
+ if (ret == -1)
+ goto out;
+
+ if (strcmp(key, "nfs-ganesha")) {
+ gf_asprintf(op_errstr,
+ "Global option: error: ' %s '"
+ "is not a valid global option.",
+ key);
+ ret = -1;
+ goto out;
+ }
+
+ w = str_getunamb(value, opwords);
+ if (!w) {
+ cli_out(
+ "Invalid global option \n"
+ "Usage : nfs-ganesha <enable/disable>");
+ ret = -1;
+ goto out;
+ }
+
+ if (strcmp(value, "enable") == 0) {
+ question =
+ "Enabling NFS-Ganesha requires Gluster-NFS to be "
+ "disabled across the trusted pool. Do you "
+ "still want to continue?\n";
+ } else if (strcmp(value, "disable") == 0) {
+ question =
+ "Disabling NFS-Ganesha will tear down the entire "
+ "ganesha cluster across the trusted pool. Do you "
+ "still want to continue?\n";
+ } else {
+ ret = -1;
+ goto out;
+ }
+ answer = cli_cmd_get_confirmation(state, question);
+ if (GF_ANSWER_NO == answer) {
+ gf_log("cli", GF_LOG_ERROR,
+ "Global operation "
+ "cancelled, exiting");
+ ret = -1;
+ goto out;
+ }
+ cli_out("This will take a few minutes to complete. Please wait ..");
+
+ ret = dict_set_str(dict, "key", key);
+ if (ret) {
+ gf_log(THIS->name, GF_LOG_ERROR, "dict set on key failed");
+ goto out;
+ }
+
+ ret = dict_set_str(dict, "value", value);
+ if (ret) {
+ gf_log(THIS->name, GF_LOG_ERROR, "dict set on value failed");
+ goto out;
+ }
+
+ ret = dict_set_str(dict, "globalname", "All");
+ if (ret) {
+ gf_log(THIS->name, GF_LOG_ERROR,
+ "dict set on global"
+ " key failed.");
+ goto out;
+ }
+
+ ret = dict_set_int32(dict, "hold_global_locks", _gf_true);
+ if (ret) {
+ gf_log(THIS->name, GF_LOG_ERROR,
+ "dict set on global key "
+ "failed.");
+ goto out;
+ }
+
+ *options = dict;
+out:
+ if (ret)
+ dict_unref(dict);
+
+ return ret;
+}
diff --git a/cli/src/cli-cmd-peer.c b/cli/src/cli-cmd-peer.c
index e0a38904a81..084998701d8 100644
--- a/cli/src/cli-cmd-peer.c
+++ b/cli/src/cli-cmd-peer.c
@@ -18,11 +18,7 @@
#include "cli-mem-types.h"
#include "cli1-xdr.h"
#include "protocol-common.h"
-#include "events.h"
-
-extern struct rpc_clnt *global_rpc;
-
-extern rpc_clnt_prog_t *cli_rpc_prog;
+#include <glusterfs/events.h>
int
cli_cmd_peer_help_cbk(struct cli_state *state, struct cli_cmd_word *in_word,
@@ -48,10 +44,6 @@ cli_cmd_peer_probe_cbk(struct cli_state *state, struct cli_cmd_word *word,
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_PROBE];
- frame = create_frame(THIS, THIS->ctx->pool);
- if (!frame)
- goto out;
-
dict = dict_new();
if (!dict)
goto out;
@@ -60,7 +52,7 @@ cli_cmd_peer_probe_cbk(struct cli_state *state, struct cli_cmd_word *word,
if (ret)
goto out;
- ret = valid_internet_address((char *)words[2], _gf_false);
+ ret = valid_internet_address((char *)words[2], _gf_false, _gf_false);
if (ret == 1) {
ret = 0;
} else {
@@ -77,6 +69,12 @@ cli_cmd_peer_probe_cbk(struct cli_state *state, struct cli_cmd_word *word,
}
*/
+ frame = create_frame(THIS, THIS->ctx->pool);
+ if (!frame) {
+ ret = -1;
+ goto out;
+ }
+
CLI_LOCAL_INIT(local, words, frame, dict);
if (proc->fn) {
@@ -111,19 +109,22 @@ cli_cmd_peer_deprobe_cbk(struct cli_state *state, struct cli_cmd_word *word,
int sent = 0;
int parse_error = 0;
cli_local_t *local = NULL;
+ gf_answer_t answer = GF_ANSWER_NO;
+ const char *question = NULL;
if ((wordcount < 3) || (wordcount > 4)) {
cli_usage_out(word->pattern);
parse_error = 1;
goto out;
}
-
+ question =
+ "All clients mounted through the peer which is getting detached need "
+ "to be remounted using one of the other active peers in the trusted "
+ "storage pool to ensure client gets notification on any changes done "
+ "on the gluster configuration and if the same has been done do you "
+ "want to proceed?";
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_DEPROBE];
- frame = create_frame(THIS, THIS->ctx->pool);
- if (!frame)
- goto out;
-
dict = dict_new();
ret = dict_set_str(dict, "hostname", (char *)words[2]);
@@ -149,6 +150,17 @@ cli_cmd_peer_deprobe_cbk(struct cli_state *state, struct cli_cmd_word *word,
ret = dict_set_int32(dict, "flags", flags);
if (ret)
goto out;
+ answer = cli_cmd_get_confirmation(state, question);
+ if (GF_ANSWER_NO == answer) {
+ ret = 0;
+ goto out;
+ }
+
+ frame = create_frame(THIS, THIS->ctx->pool);
+ if (!frame) {
+ ret = -1;
+ goto out;
+ }
CLI_LOCAL_INIT(local, words, frame, dict);
diff --git a/cli/src/cli-cmd-snapshot.c b/cli/src/cli-cmd-snapshot.c
index 814ab82f6eb..859d6b2e40d 100644
--- a/cli/src/cli-cmd-snapshot.c
+++ b/cli/src/cli-cmd-snapshot.c
@@ -17,8 +17,6 @@
#include "cli-cmd.h"
#include "cli-mem-types.h"
-extern rpc_clnt_prog_t *cli_rpc_prog;
-
int
cli_cmd_snapshot_help_cbk(struct cli_state *state, struct cli_cmd_word *in_word,
const char **words, int wordcount);
@@ -36,12 +34,6 @@ cli_cmd_snapshot_cbk(struct cli_state *state, struct cli_cmd_word *word,
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_SNAP];
- frame = create_frame(THIS, THIS->ctx->pool);
- if (frame == NULL) {
- ret = -1;
- goto out;
- }
-
/* Parses the command entered by the user */
ret = cli_cmd_snapshot_parse(words, wordcount, &options, state);
if (ret) {
@@ -55,6 +47,12 @@ cli_cmd_snapshot_cbk(struct cli_state *state, struct cli_cmd_word *word,
goto out;
}
+ frame = create_frame(THIS, THIS->ctx->pool);
+ if (frame == NULL) {
+ ret = -1;
+ goto out;
+ }
+
CLI_LOCAL_INIT(local, words, frame, options);
if (proc->fn)
diff --git a/cli/src/cli-cmd-system.c b/cli/src/cli-cmd-system.c
index 96b229582fb..801e8f4efed 100644
--- a/cli/src/cli-cmd-system.c
+++ b/cli/src/cli-cmd-system.c
@@ -18,10 +18,6 @@
#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_system_help_cbk(struct cli_state *state, struct cli_cmd_word *in_word,
const char **words, int wordcount);
@@ -43,36 +39,39 @@ cli_cmd_getspec_cbk(struct cli_state *state, struct cli_cmd_word *word,
call_frame_t *frame = NULL;
dict_t *dict = NULL;
- frame = create_frame(THIS, THIS->ctx->pool);
- if (!frame)
+ if (wordcount != 3) {
+ cli_usage_out(word->pattern);
goto out;
+ }
dict = dict_new();
if (!dict)
goto out;
- if (wordcount != 3) {
- cli_usage_out(word->pattern);
- goto out;
- }
-
ret = dict_set_str(dict, "volid", (char *)words[2]);
if (ret)
goto out;
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_GETSPEC];
if (proc->fn) {
+ frame = create_frame(THIS, THIS->ctx->pool);
+ if (!frame) {
+ ret = -1;
+ goto out;
+ }
ret = proc->fn(frame, THIS, dict);
}
out:
if (!proc && ret) {
- if (dict)
- dict_unref(dict);
if (wordcount > 1)
cli_out("Fetching spec for volume %s failed", (char *)words[2]);
}
+ if (dict)
+ dict_unref(dict);
+
+ CLI_STACK_DESTROY(frame);
return ret;
}
@@ -85,36 +84,39 @@ cli_cmd_pmap_b2p_cbk(struct cli_state *state, struct cli_cmd_word *word,
call_frame_t *frame = NULL;
dict_t *dict = NULL;
- frame = create_frame(THIS, THIS->ctx->pool);
- if (!frame)
+ if (wordcount != 4) {
+ cli_usage_out(word->pattern);
goto out;
+ }
dict = dict_new();
if (!dict)
goto out;
- if (wordcount != 4) {
- cli_usage_out(word->pattern);
- goto out;
- }
-
ret = dict_set_str(dict, "brick", (char *)words[3]);
if (ret)
goto out;
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_PMAP_PORTBYBRICK];
if (proc->fn) {
+ frame = create_frame(THIS, THIS->ctx->pool);
+ if (!frame) {
+ ret = -1;
+ goto out;
+ }
ret = proc->fn(frame, THIS, dict);
}
out:
if (!proc && ret) {
- if (dict)
- dict_unref(dict);
if (wordcount > 1)
cli_out("Fetching spec for volume %s failed", (char *)words[3]);
}
+ if (dict)
+ dict_unref(dict);
+
+ CLI_STACK_DESTROY(frame);
return ret;
}
@@ -174,6 +176,7 @@ make_seq_dict(int argc, char **argv)
{
char index[] = "4294967296"; // 1<<32
int i = 0;
+ int len;
int ret = 0;
dict_t *dict = dict_new();
@@ -181,8 +184,8 @@ make_seq_dict(int argc, char **argv)
return NULL;
for (i = 0; i < argc; i++) {
- snprintf(index, sizeof(index), "%d", i);
- ret = dict_set_str(dict, index, argv[i]);
+ len = snprintf(index, sizeof(index), "%d", i);
+ ret = dict_set_strn(dict, index, len, argv[i]);
if (ret == -1)
break;
}
@@ -264,8 +267,11 @@ cli_cmd_umount_cbk(struct cli_state *state, struct cli_cmd_word *word,
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_UMOUNT];
if (proc && proc->fn) {
frame = create_frame(THIS, THIS->ctx->pool);
- if (!frame)
+ if (!frame) {
+ gf_log(THIS->name, GF_LOG_ERROR, "failed to create frame");
+ ret = -1;
goto out;
+ }
ret = proc->fn(frame, THIS, dict);
}
@@ -319,6 +325,9 @@ out:
cli_out("uuid get failed");
}
+ if (dict)
+ dict_unref(dict);
+
CLI_STACK_DESTROY(frame);
return ret;
}
@@ -380,12 +389,15 @@ out:
cli_out("uuid reset failed");
}
+ if (dict)
+ dict_unref(dict);
+
CLI_STACK_DESTROY(frame);
return ret;
}
-struct cli_cmd cli_system_cmds[] = {
+static struct cli_cmd cli_system_cmds[] = {
{"system:: getspec <VOLNAME>", cli_cmd_getspec_cbk,
"fetch the volume file for the volume <VOLNAME>"},
@@ -429,6 +441,7 @@ cli_cmd_sys_exec_cbk(struct cli_state *state, struct cli_cmd_word *word,
char *tmp = NULL;
int ret = -1;
int i = -1;
+ int len;
int cmd_args_count = 0;
int in_cmd_args_count = 0;
rpc_clnt_procedure_t *proc = NULL;
@@ -436,20 +449,21 @@ cli_cmd_sys_exec_cbk(struct cli_state *state, struct cli_cmd_word *word,
dict_t *dict = NULL;
cli_local_t *local = NULL;
- if (wordcount < 3) {
+ if ((wordcount < 3) || (words[2] == NULL)) {
cli_usage_out(word->pattern);
goto out;
}
- dict = dict_new();
- if (!dict)
- goto out;
-
command = strtok_r((char *)words[2], " ", &saveptr);
if (command == NULL) {
gf_log("cli", GF_LOG_ERROR, "Failed to parse command");
goto out;
}
+
+ dict = dict_new();
+ if (!dict)
+ goto out;
+
do {
tmp = strtok_r(NULL, " ", &saveptr);
if (tmp) {
@@ -477,9 +491,9 @@ cli_cmd_sys_exec_cbk(struct cli_state *state, struct cli_cmd_word *word,
for (i = 1; i <= cmd_args_count; i++) {
in_cmd_args_count++;
- snprintf(cmd_arg_name, sizeof(cmd_arg_name), "cmd_arg_%d",
- in_cmd_args_count);
- ret = dict_set_str(dict, cmd_arg_name, (char *)words[2 + i]);
+ len = snprintf(cmd_arg_name, sizeof(cmd_arg_name), "cmd_arg_%d",
+ in_cmd_args_count);
+ ret = dict_set_strn(dict, cmd_arg_name, len, (char *)words[2 + i]);
if (ret) {
gf_log("", GF_LOG_ERROR, "Unable to set %s in dict", cmd_arg_name);
goto out;
@@ -501,8 +515,11 @@ cli_cmd_sys_exec_cbk(struct cli_state *state, struct cli_cmd_word *word,
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_SYS_EXEC];
if (proc->fn) {
frame = create_frame(THIS, THIS->ctx->pool);
- if (!frame)
+ if (!frame) {
+ gf_log(THIS->name, GF_LOG_ERROR, "failed to create frame");
+ ret = -1;
goto out;
+ }
CLI_LOCAL_INIT(local, words, frame, dict);
ret = proc->fn(frame, THIS, (void *)dict);
@@ -559,8 +576,11 @@ cli_cmd_copy_file_cbk(struct cli_state *state, struct cli_cmd_word *word,
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_COPY_FILE];
if (proc && proc->fn) {
frame = create_frame(THIS, THIS->ctx->pool);
- if (!frame)
+ if (!frame) {
+ gf_log(THIS->name, GF_LOG_ERROR, "failed to create frame");
+ ret = -1;
goto out;
+ }
CLI_LOCAL_INIT(local, words, frame, dict);
ret = proc->fn(frame, THIS, (void *)dict);
}
diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c
index ac3718f6230..f238851586e 100644
--- a/cli/src/cli-cmd-volume.c
+++ b/cli/src/cli-cmd-volume.c
@@ -23,17 +23,16 @@
#include "cli-cmd.h"
#include "cli-mem-types.h"
#include "cli1-xdr.h"
-#include "run.h"
-#include "syscall.h"
-#include "common-utils.h"
-#include "events.h"
+#include <glusterfs/run.h>
+#include <glusterfs/syscall.h>
+#include <glusterfs/common-utils.h>
+#include <glusterfs/events.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;
+static int
+gf_asprintf_append(char **string_ptr, const char *format, ...);
+
int
cli_cmd_volume_help_cbk(struct cli_state *state, struct cli_cmd_word *in_word,
const char **words, int wordcount);
@@ -47,10 +46,6 @@ cli_cmd_quota_help_cbk(struct cli_state *state, struct cli_cmd_word *in_word,
const char **words, int wordcount);
int
-cli_cmd_tier_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)
{
@@ -66,10 +61,6 @@ cli_cmd_volume_info_cbk(struct cli_state *state, struct cli_cmd_word *word,
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];
@@ -92,6 +83,10 @@ cli_cmd_volume_info_cbk(struct cli_state *state, struct cli_cmd_word *word,
if (!local)
goto out;
+ frame = create_frame(THIS, THIS->ctx->pool);
+ if (!frame)
+ goto out;
+
local->get_vol.flags = ctx.flags;
if (ctx.volname)
local->get_vol.volname = gf_strdup(ctx.volname);
@@ -177,8 +172,11 @@ cli_cmd_sync_volume_cbk(struct cli_state *state, struct cli_cmd_word *word,
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_SYNC_VOLUME];
frame = create_frame(THIS, THIS->ctx->pool);
- if (!frame)
+ if (!frame) {
+ gf_log(THIS->name, GF_LOG_ERROR, "failed to create frame");
+ ret = -1;
goto out;
+ }
CLI_LOCAL_INIT(local, words, frame, dict);
@@ -214,10 +212,6 @@ cli_cmd_volume_create_cbk(struct cli_state *state, struct cli_cmd_word *word,
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,
&bricks);
@@ -243,6 +237,12 @@ cli_cmd_volume_create_cbk(struct cli_state *state, struct cli_cmd_word *word,
}
}
+ frame = create_frame(THIS, THIS->ctx->pool);
+ if (!frame) {
+ ret = -1;
+ goto out;
+ }
+
CLI_LOCAL_INIT(local, words, frame, options);
if (proc->fn) {
@@ -285,14 +285,6 @@ cli_cmd_volume_delete_cbk(struct cli_state *state, struct cli_cmd_word *word,
"Do you want to continue?";
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_DELETE_VOLUME];
- frame = create_frame(THIS, THIS->ctx->pool);
- if (!frame)
- goto out;
-
- dict = dict_new();
- if (!dict)
- goto out;
-
if (wordcount != 3) {
cli_usage_out(word->pattern);
parse_error = 1;
@@ -301,6 +293,10 @@ cli_cmd_volume_delete_cbk(struct cli_state *state, struct cli_cmd_word *word,
volname = (char *)words[2];
+ dict = dict_new();
+ if (!dict)
+ goto out;
+
ret = dict_set_str(dict, "volname", volname);
if (ret) {
gf_log(THIS->name, GF_LOG_WARNING, "dict set failed");
@@ -322,6 +318,12 @@ cli_cmd_volume_delete_cbk(struct cli_state *state, struct cli_cmd_word *word,
goto out;
}
+ frame = create_frame(THIS, THIS->ctx->pool);
+ if (!frame) {
+ ret = -1;
+ goto out;
+ }
+
CLI_LOCAL_INIT(local, words, frame, dict);
if (proc->fn) {
@@ -357,30 +359,15 @@ cli_cmd_volume_start_cbk(struct cli_state *state, struct cli_cmd_word *word,
int flags = 0;
cli_local_t *local = NULL;
- frame = create_frame(THIS, THIS->ctx->pool);
- if (!frame)
- goto out;
-
if (wordcount < 3 || wordcount > 4) {
cli_usage_out(word->pattern);
parse_error = 1;
goto out;
}
- dict = dict_new();
- if (!dict) {
- goto out;
- }
-
if (!words[2])
goto out;
- ret = dict_set_str(dict, "volname", (char *)words[2]);
- if (ret) {
- gf_log(THIS->name, GF_LOG_ERROR, "dict set failed");
- goto out;
- }
-
if (wordcount == 4) {
if (!strcmp("force", words[3])) {
flags |= GF_CLI_FLAG_OP_FORCE;
@@ -391,6 +378,18 @@ cli_cmd_volume_start_cbk(struct cli_state *state, struct cli_cmd_word *word,
goto out;
}
}
+
+ dict = dict_new();
+ if (!dict) {
+ goto out;
+ }
+
+ ret = dict_set_str(dict, "volname", (char *)words[2]);
+ if (ret) {
+ gf_log(THIS->name, GF_LOG_ERROR, "dict set failed");
+ goto out;
+ }
+
ret = dict_set_int32(dict, "flags", flags);
if (ret) {
gf_log(THIS->name, GF_LOG_ERROR, "dict set failed");
@@ -399,6 +398,12 @@ cli_cmd_volume_start_cbk(struct cli_state *state, struct cli_cmd_word *word,
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_START_VOLUME];
+ frame = create_frame(THIS, THIS->ctx->pool);
+ if (!frame) {
+ ret = -1;
+ goto out;
+ }
+
CLI_LOCAL_INIT(local, words, frame, dict);
if (proc->fn) {
@@ -485,10 +490,6 @@ cli_cmd_volume_stop_cbk(struct cli_state *state, struct cli_cmd_word *word,
"Stopping volume will make its data inaccessible. "
"Do you want to continue?";
- frame = create_frame(THIS, THIS->ctx->pool);
- if (!frame)
- goto out;
-
if (wordcount < 3 || wordcount > 4) {
cli_usage_out(word->pattern);
parse_error = 1;
@@ -539,6 +540,12 @@ cli_cmd_volume_stop_cbk(struct cli_state *state, struct cli_cmd_word *word,
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_STOP_VOLUME];
+ frame = create_frame(THIS, THIS->ctx->pool);
+ if (!frame) {
+ ret = -1;
+ goto out;
+ }
+
CLI_LOCAL_INIT(local, words, frame, dict);
if (proc->fn) {
@@ -553,6 +560,8 @@ out:
}
CLI_STACK_DESTROY(frame);
+ if (dict)
+ dict_unref(dict);
if (ret == 0 && GF_ANSWER_YES == answer) {
gf_event(EVENT_VOLUME_STOP, "name=%s;force=%d", (char *)words[2],
@@ -573,20 +582,16 @@ cli_cmd_volume_rename_cbk(struct cli_state *state, struct cli_cmd_word *word,
int sent = 0;
int parse_error = 0;
- frame = create_frame(THIS, THIS->ctx->pool);
- if (!frame)
- goto out;
-
- dict = dict_new();
- if (!dict)
- goto out;
-
if (wordcount != 4) {
cli_usage_out(word->pattern);
parse_error = 1;
goto out;
}
+ dict = dict_new();
+ if (!dict)
+ goto out;
+
ret = dict_set_str(dict, "old-volname", (char *)words[2]);
if (ret)
@@ -600,6 +605,11 @@ cli_cmd_volume_rename_cbk(struct cli_state *state, struct cli_cmd_word *word,
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_RENAME_VOLUME];
if (proc->fn) {
+ frame = create_frame(THIS, THIS->ctx->pool);
+ if (!frame) {
+ ret = -1;
+ goto out;
+ }
ret = proc->fn(frame, THIS, dict);
}
@@ -638,10 +648,6 @@ cli_cmd_volume_defrag_cbk(struct cli_state *state, struct cli_cmd_word *word,
goto out;
#endif
- frame = create_frame(THIS, THIS->ctx->pool);
- if (!frame)
- goto out;
-
ret = cli_cmd_volume_defrag_parse(words, wordcount, &dict);
if (ret) {
@@ -651,6 +657,12 @@ cli_cmd_volume_defrag_cbk(struct cli_state *state, struct cli_cmd_word *word,
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_DEFRAG_VOLUME];
+ frame = create_frame(THIS, THIS->ctx->pool);
+ if (!frame) {
+ ret = -1;
+ goto out;
+ }
+
CLI_LOCAL_INIT(local, words, frame, dict);
if (proc->fn) {
@@ -699,10 +711,6 @@ cli_cmd_volume_reset_cbk(struct cli_state *state, struct cli_cmd_word *word,
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_RESET_VOLUME];
- frame = create_frame(THIS, THIS->ctx->pool);
- if (!frame)
- goto out;
-
ret = cli_cmd_volume_reset_parse(words, wordcount, &options);
if (ret) {
cli_usage_out(word->pattern);
@@ -710,6 +718,12 @@ cli_cmd_volume_reset_cbk(struct cli_state *state, struct cli_cmd_word *word,
goto out;
}
+ frame = create_frame(THIS, THIS->ctx->pool);
+ if (!frame) {
+ ret = -1;
+ goto out;
+ }
+
CLI_LOCAL_INIT(local, words, frame, options);
if (proc->fn) {
@@ -763,8 +777,11 @@ cli_cmd_volume_profile_cbk(struct cli_state *state, struct cli_cmd_word *word,
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_PROFILE_VOLUME];
frame = create_frame(THIS, THIS->ctx->pool);
- if (!frame)
+ if (!frame) {
+ gf_log(THIS->name, GF_LOG_ERROR, "failed to create frame");
+ ret = -1;
goto out;
+ }
CLI_LOCAL_INIT(local, words, frame, options);
@@ -811,10 +828,6 @@ cli_cmd_volume_set_cbk(struct cli_state *state, struct cli_cmd_word *word,
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_SET_VOLUME];
- frame = create_frame(THIS, THIS->ctx->pool);
- if (!frame)
- goto out;
-
ret = cli_cmd_volume_set_parse(state, words, wordcount, &options,
&op_errstr);
if (ret) {
@@ -828,6 +841,12 @@ cli_cmd_volume_set_cbk(struct cli_state *state, struct cli_cmd_word *word,
goto out;
}
+ frame = create_frame(THIS, THIS->ctx->pool);
+ if (!frame) {
+ ret = -1;
+ goto out;
+ }
+
CLI_LOCAL_INIT(local, words, frame, options);
if (proc->fn) {
@@ -844,13 +863,21 @@ out:
#if (USE_EVENTS)
if (ret == 0 && strcmp(words[2], "help") != 0) {
ret1 = dict_get_int32(options, "count", &num_options);
- if (ret1)
+ if (ret1) {
num_options = 0;
- else
+ goto end;
+ } else {
num_options = num_options / 2;
+ }
+ char *free_list_key[num_options];
+ char *free_list_val[num_options];
+ for (i = 0; i < num_options; i++) {
+ free_list_key[i] = NULL;
+ free_list_val[i] = NULL;
+ }
/* Initialize opts_str */
- opts_str = gf_strdup("");
+ opts_str = "";
/* Prepare String in format options=KEY1,VALUE1,KEY2,VALUE2 */
for (i = 1; i <= num_options; i++) {
@@ -860,6 +887,7 @@ out:
tmp_opt = "";
gf_asprintf(&opts_str, "%s,%s", opts_str, tmp_opt);
+ free_list_key[i - 1] = opts_str;
sprintf(dict_key, "value%d", i);
ret1 = dict_get_str(options, dict_key, &tmp_opt);
@@ -867,16 +895,21 @@ out:
tmp_opt = "";
gf_asprintf(&opts_str, "%s,%s", opts_str, tmp_opt);
+ free_list_val[i - 1] = opts_str;
}
gf_event(EVENT_VOLUME_SET, "name=%s;options=%s", (char *)words[2],
opts_str);
/* Allocated by gf_strdup and gf_asprintf */
- GF_FREE(opts_str);
+ for (i = 0; i < num_options; i++) {
+ GF_FREE(free_list_key[i]);
+ GF_FREE(free_list_val[i]);
+ }
}
#endif
+end:
CLI_STACK_DESTROY(frame);
return ret;
@@ -960,6 +993,10 @@ cli_event_remove_brick_str(dict_t *options, char **event_str,
bricklist = GF_CALLOC(eventstrlen, sizeof(char), gf_common_mt_char);
if (!bricklist) {
+ gf_log(THIS->name, GF_LOG_ERROR,
+ "memory allocation failed for"
+ "bricklist");
+ ret = -1;
goto out;
}
@@ -1017,10 +1054,6 @@ cli_cmd_volume_add_brick_cbk(struct cli_state *state, struct cli_cmd_word *word,
"filesystem operations on the volume after the change. Do you "
"really want to continue with 'stripe' count option ? ";
- frame = create_frame(THIS, THIS->ctx->pool);
- if (!frame)
- goto out;
-
ret = cli_cmd_volume_add_brick_parse(state, words, wordcount, &options, 0);
if (ret) {
cli_usage_out(word->pattern);
@@ -1065,6 +1098,12 @@ cli_cmd_volume_add_brick_cbk(struct cli_state *state, struct cli_cmd_word *word,
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_ADD_BRICK];
+ frame = create_frame(THIS, THIS->ctx->pool);
+ if (!frame) {
+ ret = -1;
+ goto out;
+ }
+
CLI_LOCAL_INIT(local, words, frame, options);
if (proc->fn) {
@@ -1090,332 +1129,6 @@ out:
}
int
-cli_tier_validate_replica_type(dict_t *dict, int type)
-{
- int brick_count = -1;
- int replica_count = 1;
- int ret = -1;
-
- ret = dict_get_int32(dict, "count", &brick_count);
- if (ret) {
- gf_log("cli", GF_LOG_ERROR, "Failed to get brick count");
- goto out;
- }
-
- ret = dict_get_int32(dict, "replica-count", &replica_count);
- if (ret) {
- gf_log("cli", GF_LOG_DEBUG,
- "Failed to get replica count. "
- "Defaulting to one");
- replica_count = 1;
- }
-
- /*
- * Change the calculation of sub_count once attach-tier support
- * disperse volume.
- * sub_count = disperse_count for disperse volume
- * */
-
- if (brick_count % replica_count) {
- if (type == GF_CLUSTER_TYPE_REPLICATE)
- cli_err(
- "number of bricks is not a multiple of "
- "replica count");
- else if (type == GF_CLUSTER_TYPE_DISPERSE)
- cli_err(
- "number of bricks is not a multiple of "
- "disperse count");
- else
- cli_err(
- "number of bricks given doesn't match "
- "required count");
-
- ret = -1;
- goto out;
- }
- ret = 0;
-out:
- return ret;
-}
-
-int
-do_cli_cmd_volume_attach_tier(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;
- cli_local_t *local = NULL;
- int type = 0;
-
- frame = create_frame(THIS, THIS->ctx->pool);
- if (!frame)
- goto out;
-
- ret = cli_cmd_volume_add_brick_parse(state, words, wordcount, &options,
- &type);
- if (ret) {
- cli_usage_out(word->pattern);
- parse_error = 1;
- goto out;
- }
-
- /*
- * Merge this check when attach-tier has it's own cli parse function.
- */
- ret = cli_tier_validate_replica_type(options, type);
- if (ret) {
- cli_usage_out(word->pattern);
- parse_error = 1;
- goto out;
- }
-
- if (state->mode & GLUSTER_MODE_WIGNORE) {
- ret = dict_set_int32(options, "force", _gf_true);
- if (ret) {
- gf_log("cli", GF_LOG_ERROR,
- "Failed to set force "
- "option");
- goto out;
- }
- }
-
- ret = dict_set_int32(options, "attach-tier", 1);
- if (ret)
- goto out;
-
- ret = dict_set_int32(options, "hot-type", type);
- if (ret)
- goto out;
-
- proc = &cli_rpc_prog->proctable[GLUSTER_CLI_ADD_TIER_BRICK];
-
- CLI_LOCAL_INIT(local, words, frame, options);
-
- if (proc->fn) {
- ret = proc->fn(frame, THIS, options);
- }
-
-out:
- if (ret) {
- cli_cmd_sent_status_get(&sent);
- if ((sent == 0) && (parse_error == 0))
- cli_out("attach-tier failed");
- }
-
- CLI_STACK_DESTROY(frame);
-
- return ret;
-}
-
-int
-do_cli_cmd_volume_detach_tier(struct cli_state *state,
- struct cli_cmd_word *word, const char **words,
- int wordcount, gf_boolean_t *aborted)
-{
- 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;
- gf_answer_t answer = GF_ANSWER_NO;
- cli_local_t *local = NULL;
- int need_question = 0;
-
- const char *question =
- "Removing tier can result in data loss. "
- "Do you want to Continue?";
-
- frame = create_frame(THIS, THIS->ctx->pool);
- if (!frame)
- goto out;
-
- ret = cli_cmd_volume_detach_tier_parse(words, wordcount, &options,
- &need_question);
- if (ret) {
- cli_usage_out(word->pattern);
- parse_error = 1;
- goto out;
- }
-
- ret = dict_set_int32(options, "force", 1);
- if (ret)
- goto out;
-
- ret = dict_set_int32(options, "count", 0);
- if (ret)
- goto out;
-
- *aborted = _gf_false;
-
- if (!(state->mode & GLUSTER_MODE_SCRIPT) && need_question) {
- /* we need to ask question only in case of 'commit or force' */
- answer = cli_cmd_get_confirmation(state, question);
- if (GF_ANSWER_NO == answer) {
- ret = 0;
- *aborted = _gf_true;
- goto out;
- }
- }
-
- proc = &cli_rpc_prog->proctable[GLUSTER_CLI_REMOVE_TIER_BRICK];
-
- CLI_LOCAL_INIT(local, words, frame, options);
-
- if (proc->fn) {
- ret = proc->fn(frame, THIS, options);
- }
-
-out:
- if (ret) {
- cli_cmd_sent_status_get(&sent);
- if ((sent == 0) && (parse_error == 0))
- cli_out("Volume detach tier failed");
- }
-
- CLI_STACK_DESTROY(frame);
-
- return ret;
-}
-
-int
-cli_cmd_volume_tier_cbk(struct cli_state *state, struct cli_cmd_word *word,
- const char **words, int wordcount)
-{
- int ret = -1;
- call_frame_t *frame = NULL;
- dict_t *options = NULL;
- rpc_clnt_procedure_t *proc = NULL;
- cli_local_t *local = NULL;
- int i = 0;
- eventtypes_t event = EVENT_LAST;
- gf_boolean_t aborted = _gf_false;
- gf_answer_t answer = GF_ANSWER_NO;
-
- const char *detach_question =
- "gluster volume detach-tier <VOLNAME> "
- "<start|stop|status|commit|force> is "
- "deprecated. Use the new command \'"
- "gluster volume tier <VOLNAME> detach <start|"
- "stop|status|commit|force>\'\n"
- "Do you want to Continue?";
-
- const char *attach_question =
- "gluster volume attach-tier <VOLNAME> "
- "[<replica COUNT>] <NEW-BRICK>... is "
- "deprecated. Use the new command \'"
- "gluster volume tier <VOLNAME> attach [<replica"
- " COUNT>] <NEW-BRICK>... [force]\'\n"
- "Do you want to Continue?";
-
- if (wordcount < 4) {
- if (wordcount == 3 && !strcmp(words[2], "help")) {
- cli_cmd_tier_help_cbk(state, word, words, wordcount);
- ret = 0;
- } else {
- cli_usage_out(word->pattern);
- }
- goto out;
- }
-
- if (!strcmp(words[1], "detach-tier")) {
- /* we need to ask question when older command is used */
- answer = cli_cmd_get_confirmation(state, detach_question);
- if (GF_ANSWER_NO == answer) {
- ret = 0;
- goto out;
- }
- ret = do_cli_cmd_volume_detach_tier(state, word, words, wordcount,
- &aborted);
- goto out;
- } else if (!strcmp(words[3], "detach")) {
- for (i = 3; i < wordcount; i++)
- words[i] = words[i + 1];
-
- ret = do_cli_cmd_volume_detach_tier(state, word, words, wordcount - 1,
- &aborted);
- if (!aborted) {
- if (!strcmp(words[wordcount - 2], "commit")) {
- event = EVENT_TIER_DETACH_COMMIT;
- } else if (!strcmp(words[wordcount - 2], "start")) {
- event = EVENT_TIER_DETACH_START;
- } else if (!strcmp(words[wordcount - 2], "stop")) {
- event = EVENT_TIER_DETACH_STOP;
- } else if (!strcmp(words[wordcount - 2], "force")) {
- event = EVENT_TIER_DETACH_FORCE;
- }
- }
- goto out;
-
- } else if (!strcmp(words[1], "attach-tier")) {
- /* we need to ask question when the older command is used */
- answer = cli_cmd_get_confirmation(state, attach_question);
- if (GF_ANSWER_NO == answer) {
- ret = 0;
- goto out;
- }
- ret = do_cli_cmd_volume_attach_tier(state, word, words, wordcount);
- goto out;
- } else if (!strcmp(words[3], "attach")) {
- for (i = 3; i < wordcount; i++)
- words[i] = words[i + 1];
-
- ret = do_cli_cmd_volume_attach_tier(state, word, words, wordcount - 1);
- if (!strcmp(words[wordcount - 2], "force")) {
- event = EVENT_TIER_ATTACH_FORCE;
- } else {
- event = EVENT_TIER_ATTACH;
- }
- goto out;
- }
-
- ret = cli_cmd_volume_tier_parse(words, wordcount, &options);
- if (ret) {
- cli_usage_out(word->pattern);
- goto out;
- }
-
- if (!strcmp(words[wordcount - 1], "start")) {
- event = EVENT_TIER_START;
- } else {
- if (!strcmp(words[wordcount - 2], "start") &&
- !strcmp(words[wordcount - 1], "force")) {
- event = EVENT_TIER_START_FORCE;
- }
- }
-
- proc = &cli_rpc_prog->proctable[GLUSTER_CLI_TIER];
-
- frame = create_frame(THIS, THIS->ctx->pool);
- if (!frame)
- goto out;
-
- CLI_LOCAL_INIT(local, words, frame, options);
-
- if (proc->fn) {
- ret = proc->fn(frame, THIS, options);
- }
-
-out:
- if (ret) {
- cli_out("Tier command failed");
- } else {
- if (event != EVENT_LAST) {
- gf_event(event, "vol=%s", words[2]);
- }
- }
- if (options)
- dict_unref(options);
-
- return ret;
-}
-
-int
cli_get_soft_limit(dict_t *options, const char **words, dict_t *xdata)
{
call_frame_t *frame = NULL;
@@ -1528,7 +1241,7 @@ cli_cmd_quota_handle_list_all(const char **words, dict_t *options)
cli_local_t *local = NULL;
call_frame_t *frame = NULL;
dict_t *xdata = NULL;
- char *gfid_str = NULL;
+ char gfid_str[UUID_CANONICAL_FORM_LEN + 1];
char *volname = NULL;
char *volname_dup = NULL;
unsigned char buf[16] = {0};
@@ -1592,12 +1305,6 @@ cli_cmd_quota_handle_list_all(const char **words, dict_t *options)
goto out;
}
- frame = create_frame(THIS, THIS->ctx->pool);
- if (!frame) {
- ret = -1;
- goto out;
- }
-
volname_dup = gf_strdup(volname);
if (!volname_dup) {
ret = -1;
@@ -1629,15 +1336,15 @@ cli_cmd_quota_handle_list_all(const char **words, dict_t *options)
if (ret)
goto out;
- CLI_LOCAL_INIT(local, words, frame, xdata);
- proc = &cli_quotad_clnt.proctable[GF_AGGREGATOR_GETLIMIT];
-
- gfid_str = GF_CALLOC(1, gf_common_mt_char, 64);
- if (!gfid_str) {
+ frame = create_frame(THIS, THIS->ctx->pool);
+ if (!frame) {
ret = -1;
goto out;
}
+ CLI_LOCAL_INIT(local, words, frame, xdata);
+ proc = &cli_quotad_clnt.proctable[GF_AGGREGATOR_GETLIMIT];
+
for (count = 0;; count++) {
ret = quota_conf_read_gfid(fd, buf, &gfid_type, version);
if (ret == 0) {
@@ -1736,12 +1443,13 @@ out:
"xml format");
}
}
+ if (xdata)
+ dict_unref(xdata);
if (fd != -1) {
sys_close(fd);
}
- GF_FREE(gfid_str);
if (ret) {
gf_log("cli", GF_LOG_ERROR,
"Could not fetch and display quota"
@@ -1768,6 +1476,7 @@ cli_cmd_bitrot_cbk(struct cli_state *state, struct cli_cmd_word *word,
int event_type = -1;
char *tmp = NULL;
char *events_str = NULL;
+ char *volname = NULL;
#endif
ret = cli_cmd_bitrot_parse(words, wordcount, &options);
@@ -1813,10 +1522,9 @@ out:
if (ret1)
cmd_type = -1;
else {
- ret1 = dict_get_str(options, "volname", &tmp);
+ ret1 = dict_get_str(options, "volname", &volname);
if (ret1)
- tmp = "";
- gf_asprintf(&events_str, "name=%s", tmp);
+ volname = "";
}
switch (cmd_type) {
@@ -1834,21 +1542,21 @@ out:
ret1 = dict_get_str(options, "scrub-throttle-value", &tmp);
if (ret1)
tmp = "";
- gf_asprintf(&events_str, "%s;value=%s", events_str, tmp);
+ gf_asprintf(&events_str, "name=%s;value=%s", volname, tmp);
break;
case GF_BITROT_OPTION_TYPE_SCRUB_FREQ:
event_type = EVENT_BITROT_SCRUB_FREQ;
ret1 = dict_get_str(options, "scrub-frequency-value", &tmp);
if (ret1)
tmp = "";
- gf_asprintf(&events_str, "%s;value=%s", events_str, tmp);
+ gf_asprintf(&events_str, "name=%s;value=%s", volname, tmp);
break;
case GF_BITROT_OPTION_TYPE_SCRUB:
event_type = EVENT_BITROT_SCRUB_OPTION;
ret1 = dict_get_str(options, "scrub-value", &tmp);
if (ret1)
tmp = "";
- gf_asprintf(&events_str, "%s;value=%s", events_str, tmp);
+ gf_asprintf(&events_str, "name=%s;value=%s", volname, tmp);
break;
default:
break;
@@ -1957,6 +1665,8 @@ out:
"Quota command failed. Please check the cli "
"logs for more details");
}
+ if (options)
+ dict_unref(options);
/* Events for Quota */
if (ret == 0) {
@@ -2044,10 +1754,6 @@ cli_cmd_volume_remove_brick_cbk(struct cli_state *state,
int32_t command = GF_OP_CMD_NONE;
char *question = NULL;
- frame = create_frame(THIS, THIS->ctx->pool);
- if (!frame)
- goto out;
-
ret = cli_cmd_volume_remove_brick_parse(state, words, wordcount, &options,
&need_question, &brick_count,
&command);
@@ -2064,14 +1770,15 @@ cli_cmd_volume_remove_brick_cbk(struct cli_state *state,
" on the volume.\nDo you want to continue?";
} else if (command == GF_OP_CMD_START) {
question =
- "Running remove-brick with cluster.force-migration"
- " enabled can result in data corruption. It is safer"
- " to disable this option so that files that receive "
- "writes during migration are not migrated.\nFiles "
- "that are not migrated can then be manually copied "
- "after the remove-brick commit operation.\nDo you "
- "want to continue with your current "
- "cluster.force-migration settings?";
+ "It is recommended that remove-brick be run with"
+ " cluster.force-migration option disabled to prevent"
+ " possible data corruption. Doing so will ensure that"
+ " files that receive writes during migration will not"
+ " be migrated and will need to be manually copied"
+ " after the remove-brick commit operation. Please"
+ " check the value of the option and update accordingly."
+ " \nDo you want to continue with your current"
+ " cluster.force-migration settings?";
}
if (!brick_count) {
@@ -2112,6 +1819,12 @@ cli_cmd_volume_remove_brick_cbk(struct cli_state *state,
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_REMOVE_BRICK];
+ frame = create_frame(THIS, THIS->ctx->pool);
+ if (!frame) {
+ ret = -1;
+ goto out;
+ }
+
CLI_LOCAL_INIT(local, words, frame, options);
if (proc->fn) {
@@ -2133,6 +1846,8 @@ out:
#endif
CLI_STACK_DESTROY(frame);
+ if (options)
+ dict_unref(options);
return ret;
}
@@ -2156,10 +1871,6 @@ cli_cmd_volume_reset_brick_cbk(struct cli_state *state,
#endif
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_RESET_BRICK];
- frame = create_frame(THIS, THIS->ctx->pool);
- if (!frame)
- goto out;
-
ret = cli_cmd_volume_reset_brick_parse(words, wordcount, &options);
if (ret) {
@@ -2178,6 +1889,12 @@ cli_cmd_volume_reset_brick_cbk(struct cli_state *state,
}
}
+ frame = create_frame(THIS, THIS->ctx->pool);
+ if (!frame) {
+ ret = -1;
+ goto out;
+ }
+
CLI_LOCAL_INIT(local, words, frame, options);
if (proc->fn) {
@@ -2224,10 +1941,6 @@ cli_cmd_volume_replace_brick_cbk(struct cli_state *state,
#endif
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_REPLACE_BRICK];
- frame = create_frame(THIS, THIS->ctx->pool);
- if (!frame)
- goto out;
-
ret = cli_cmd_volume_replace_brick_parse(words, wordcount, &options);
if (ret) {
@@ -2236,6 +1949,12 @@ cli_cmd_volume_replace_brick_cbk(struct cli_state *state,
goto out;
}
+ frame = create_frame(THIS, THIS->ctx->pool);
+ if (!frame) {
+ ret = -1;
+ goto out;
+ }
+
CLI_LOCAL_INIT(local, words, frame, options);
if (proc->fn) {
@@ -2289,8 +2008,11 @@ cli_cmd_volume_top_cbk(struct cli_state *state, struct cli_cmd_word *word,
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_TOP_VOLUME];
frame = create_frame(THIS, THIS->ctx->pool);
- if (!frame)
+ if (!frame) {
+ gf_log(THIS->name, GF_LOG_ERROR, "failed to create frame");
+ ret = -1;
goto out;
+ }
CLI_LOCAL_INIT(local, words, frame, options);
@@ -2328,8 +2050,7 @@ cli_cmd_log_rotate_cbk(struct cli_state *state, struct cli_cmd_word *word,
goto out;
}
- if (!((strcmp("rotate", words[2]) == 0) ||
- (strcmp("rotate", words[3]) == 0))) {
+ if (!(strcmp("rotate", words[3]) == 0)) {
cli_usage_out(word->pattern);
parse_error = 1;
goto out;
@@ -2337,14 +2058,17 @@ cli_cmd_log_rotate_cbk(struct cli_state *state, struct cli_cmd_word *word,
proc = &cli_rpc_prog->proctable[GLUSTER_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;
+ frame = create_frame(THIS, THIS->ctx->pool);
+ if (!frame) {
+ gf_log(THIS->name, GF_LOG_ERROR, "failed to create frame");
+ ret = -1;
+ goto out;
+ }
+
CLI_LOCAL_INIT(local, words, frame, options);
if (proc->fn) {
@@ -2434,6 +2158,7 @@ cli_cmd_volume_gsync_set_cbk(struct cli_state *state, struct cli_cmd_word *word,
rpc_clnt_procedure_t *proc = NULL;
call_frame_t *frame = NULL;
cli_local_t *local = NULL;
+ char *errstr = NULL;
#if (USE_EVENTS)
int ret1 = -1;
int cmd_type = -1;
@@ -2445,16 +2170,21 @@ cli_cmd_volume_gsync_set_cbk(struct cli_state *state, struct cli_cmd_word *word,
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_GSYNC_SET];
- frame = create_frame(THIS, THIS->ctx->pool);
- if (frame == NULL) {
- ret = -1;
+ ret = cli_cmd_gsync_set_parse(state, words, wordcount, &options, &errstr);
+ if (ret) {
+ if (errstr) {
+ cli_err("%s", errstr);
+ GF_FREE(errstr);
+ } else {
+ cli_usage_out(word->pattern);
+ }
+ parse_err = 1;
goto out;
}
- ret = cli_cmd_gsync_set_parse(words, wordcount, &options);
- if (ret) {
- cli_usage_out(word->pattern);
- parse_err = 1;
+ frame = create_frame(THIS, THIS->ctx->pool);
+ if (frame == NULL) {
+ ret = -1;
goto out;
}
@@ -2510,13 +2240,15 @@ out:
if (ret1)
tmp = "";
- gf_asprintf(&events_str, "%soption=%s;", events_str, tmp);
+ gf_asprintf_append(&events_str, "%soption=%s;", events_str,
+ tmp);
ret1 = dict_get_str(options, "op_value", &tmp);
if (ret1)
tmp = "";
- gf_asprintf(&events_str, "%svalue=%s;", events_str, tmp);
+ gf_asprintf_append(&events_str, "%svalue=%s;", events_str,
+ tmp);
} else if (strcmp(tmp, "del") == 0) {
event_type = EVENT_GEOREP_CONFIG_RESET;
@@ -2524,7 +2256,8 @@ out:
if (ret1)
tmp = "";
- gf_asprintf(&events_str, "%soption=%s;", events_str, tmp);
+ gf_asprintf_append(&events_str, "%soption=%s;", events_str,
+ tmp);
}
break;
default:
@@ -2534,42 +2267,49 @@ out:
if (event_type > -1) {
/* Capture all optional arguments used */
ret1 = dict_get_int32(options, "force", &tmpi);
- if (ret1 == 0)
- gf_asprintf(&events_str, "%sforce=%d;", events_str, tmpi);
-
+ if (ret1 == 0) {
+ gf_asprintf_append(&events_str, "%sforce=%d;", events_str,
+ tmpi);
+ }
ret1 = dict_get_int32(options, "push_pem", &tmpi);
- if (ret1 == 0)
- gf_asprintf(&events_str, "%spush_pem=%d;", events_str, tmpi);
-
+ if (ret1 == 0) {
+ gf_asprintf_append(&events_str, "%spush_pem=%d;", events_str,
+ tmpi);
+ }
ret1 = dict_get_int32(options, "no_verify", &tmpi);
- if (ret1 == 0)
- gf_asprintf(&events_str, "%sno_verify=%d;", events_str, tmpi);
+ if (ret1 == 0) {
+ gf_asprintf_append(&events_str, "%sno_verify=%d;", events_str,
+ tmpi);
+ }
ret1 = dict_get_int32(options, "ssh_port", &tmpi);
- if (ret1 == 0)
- gf_asprintf(&events_str, "%sssh_port=%d;", events_str, tmpi);
+ if (ret1 == 0) {
+ gf_asprintf_append(&events_str, "%sssh_port=%d;", events_str,
+ tmpi);
+ }
ret1 = dict_get_int32(options, "reset-sync-time", &tmpi);
- if (ret1 == 0)
- gf_asprintf(&events_str, "%sreset_sync_time=%d;", events_str,
- tmpi);
-
+ if (ret1 == 0) {
+ gf_asprintf_append(&events_str, "%sreset_sync_time=%d;",
+ events_str, tmpi);
+ }
/* Capture Master and Slave Info */
ret1 = dict_get_str(options, "master", &tmp);
if (ret1)
tmp = "";
- gf_asprintf(&events_str, "%smaster=%s;", events_str, tmp);
+ gf_asprintf_append(&events_str, "%smaster=%s;", events_str, tmp);
ret1 = dict_get_str(options, "slave", &tmp);
if (ret1)
tmp = "";
- gf_asprintf(&events_str, "%sslave=%s", events_str, tmp);
+ gf_asprintf_append(&events_str, "%sslave=%s", events_str, tmp);
gf_event(event_type, "%s", events_str);
}
/* Allocated by gf_strdup and gf_asprintf */
- GF_FREE(events_str);
+ if (events_str)
+ GF_FREE(events_str);
}
#endif
@@ -2608,12 +2348,17 @@ cli_cmd_volume_status_cbk(struct cli_state *state, struct cli_cmd_word *word,
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_STATUS_ALL];
}
- if (!proc->fn)
+ if (!proc->fn) {
+ ret = -1;
goto out;
+ }
frame = create_frame(THIS, THIS->ctx->pool);
- if (!frame)
+ if (!frame) {
+ gf_log(THIS->name, GF_LOG_ERROR, "failed to create frame");
+ ret = -1;
goto out;
+ }
CLI_LOCAL_INIT(local, words, frame, dict);
@@ -2814,7 +2559,7 @@ cli_launch_glfs_heal(int heal_op, dict_t *options)
runinit(&runner);
ret = dict_get_str(options, "volname", &volname);
- runner_add_args(&runner, SBIN_DIR "/glfsheal", volname, NULL);
+ runner_add_args(&runner, GLFSHEAL_PREFIX "/glfsheal", volname, NULL);
runner_redir(&runner, STDOUT_FILENO, RUN_PIPE);
switch (heal_op) {
@@ -2889,9 +2634,6 @@ cli_cmd_volume_heal_cbk(struct cli_state *state, struct cli_cmd_word *word,
int heal_op = 0;
this = THIS;
- frame = create_frame(this, this->ctx->pool);
- if (!frame)
- goto out;
if (wordcount < 3) {
cli_usage_out(word->pattern);
@@ -2918,6 +2660,12 @@ cli_cmd_volume_heal_cbk(struct cli_state *state, struct cli_cmd_word *word,
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_HEAL_VOLUME];
+ frame = create_frame(this, this->ctx->pool);
+ if (!frame) {
+ ret = -1;
+ goto out;
+ }
+
CLI_LOCAL_INIT(local, words, frame, options);
if (proc->fn) {
@@ -2932,6 +2680,9 @@ out:
}
}
+ if (options)
+ dict_unref(options);
+
CLI_STACK_DESTROY(frame);
return ret;
@@ -2949,10 +2700,6 @@ cli_cmd_volume_statedump_cbk(struct cli_state *state, struct cli_cmd_word *word,
int parse_error = 0;
cli_local_t *local = NULL;
- frame = create_frame(THIS, THIS->ctx->pool);
- if (!frame)
- goto out;
-
if (wordcount < 3) {
cli_usage_out(word->pattern);
parse_error = 1;
@@ -2978,6 +2725,12 @@ cli_cmd_volume_statedump_cbk(struct cli_state *state, struct cli_cmd_word *word,
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_STATEDUMP_VOLUME];
+ frame = create_frame(THIS, THIS->ctx->pool);
+ if (!frame) {
+ ret = -1;
+ goto out;
+ }
+
CLI_LOCAL_INIT(local, words, frame, options);
if (proc->fn) {
@@ -3005,12 +2758,11 @@ cli_cmd_volume_list_cbk(struct cli_state *state, struct cli_cmd_word *word,
rpc_clnt_procedure_t *proc = NULL;
int sent = 0;
- frame = create_frame(THIS, THIS->ctx->pool);
- if (!frame)
- goto out;
-
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_LIST_VOLUME];
if (proc->fn) {
+ frame = create_frame(THIS, THIS->ctx->pool);
+ if (!frame)
+ goto out;
ret = proc->fn(frame, THIS, NULL);
}
@@ -3039,10 +2791,6 @@ cli_cmd_volume_clearlocks_cbk(struct cli_state *state,
int parse_error = 0;
cli_local_t *local = NULL;
- frame = create_frame(THIS, THIS->ctx->pool);
- if (!frame)
- goto out;
-
if (wordcount < 7 || wordcount > 8) {
cli_usage_out(word->pattern);
parse_error = 1;
@@ -3069,6 +2817,12 @@ cli_cmd_volume_clearlocks_cbk(struct cli_state *state,
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_CLRLOCKS_VOLUME];
+ frame = create_frame(THIS, THIS->ctx->pool);
+ if (!frame) {
+ ret = -1;
+ goto out;
+ }
+
CLI_LOCAL_INIT(local, words, frame, options);
if (proc->fn) {
@@ -3099,10 +2853,6 @@ cli_cmd_volume_barrier_cbk(struct cli_state *state, struct cli_cmd_word *word,
int parse_error = 0;
cli_local_t *local = NULL;
- frame = create_frame(THIS, THIS->ctx->pool);
- if (!frame)
- goto out;
-
if (wordcount != 4) {
cli_usage_out(word->pattern);
parse_error = 1;
@@ -3124,6 +2874,12 @@ cli_cmd_volume_barrier_cbk(struct cli_state *state, struct cli_cmd_word *word,
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_BARRIER_VOLUME];
+ frame = create_frame(THIS, THIS->ctx->pool);
+ if (!frame) {
+ ret = -1;
+ goto out;
+ }
+
CLI_LOCAL_INIT(local, words, frame, options);
if (proc->fn)
@@ -3158,10 +2914,6 @@ cli_cmd_volume_getopt_cbk(struct cli_state *state, struct cli_cmd_word *word,
goto out;
}
- frame = create_frame(THIS, THIS->ctx->pool);
- if (!frame)
- goto out;
-
options = dict_new();
if (!options)
goto out;
@@ -3176,6 +2928,12 @@ cli_cmd_volume_getopt_cbk(struct cli_state *state, struct cli_cmd_word *word,
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_GET_VOL_OPT];
+ frame = create_frame(THIS, THIS->ctx->pool);
+ if (!frame) {
+ ret = -1;
+ goto out;
+ }
+
CLI_LOCAL_INIT(local, words, frame, options);
if (proc->fn)
@@ -3205,6 +2963,16 @@ struct cli_cmd bitrot_cmds[] = {
{"volume bitrot <VOLNAME> {enable|disable}", NULL, /*cli_cmd_bitrot_cbk,*/
"Enable/disable bitrot for volume <VOLNAME>"},
+ {"volume bitrot <VOLNAME> signing-time <time-in-secs>",
+ NULL, /*cli_cmd_bitrot_cbk,*/
+ "Waiting time for an object after last fd is closed to start signing "
+ "process"},
+
+ {"volume bitrot <VOLNAME> signer-threads <count>",
+ NULL, /*cli_cmd_bitrot_cbk,*/
+ "Number of signing process threads. Usually set to number of available "
+ "cores"},
+
{"volume bitrot <VOLNAME> scrub-throttle {lazy|normal|aggressive}",
NULL, /*cli_cmd_bitrot_cbk,*/
"Set the speed of the scrubber for volume <VOLNAME>"},
@@ -3220,6 +2988,8 @@ struct cli_cmd bitrot_cmds[] = {
"the scrubber. ondemand starts the scrubber immediately."},
{"volume bitrot <VOLNAME> {enable|disable}\n"
+ "volume bitrot <VOLNAME> signing-time <time-in-secs>\n"
+ "volume bitrot <VOLNAME> signer-threads <count>\n"
"volume bitrot <volname> scrub-throttle {lazy|normal|aggressive}\n"
"volume bitrot <volname> scrub-frequency {hourly|daily|weekly|biweekly"
"|monthly}\n"
@@ -3262,50 +3032,6 @@ struct cli_cmd quota_cmds[] = {
{NULL, NULL, NULL}};
-struct cli_cmd tier_cmds[] = {
-
- {"volume tier help", cli_cmd_tier_help_cbk,
- "display help for volume tier commands"},
-
- {"volume tier <VOLNAME> status", cli_cmd_volume_tier_cbk,
- "Display tier status for <VOLNAME>"},
-
- {"volume tier <VOLNAME> start [force]", cli_cmd_volume_tier_cbk,
- "Start the tier service for <VOLNAME>"},
-
- {"volume tier <VOLNAME> stop [force]", cli_cmd_volume_tier_cbk,
- "Stop the tier service for <VOLNAME>"},
-
- {"volume tier <VOLNAME> attach [<replica COUNT>] <NEW-BRICK>... [force]",
- cli_cmd_volume_tier_cbk, "Attach a hot tier to <VOLNAME>"},
-
- {"volume tier <VOLNAME> detach <start|stop|status|commit|[force]>",
- cli_cmd_volume_tier_cbk, "Detach the hot tier from <VOLNAME>"},
-
- {"volume attach-tier <VOLNAME> [<replica COUNT>] <NEW-BRICK>...",
- cli_cmd_volume_tier_cbk,
- "NOTE: this is old syntax, will be deprecated in next release. "
- "Please use gluster volume tier <vol> attach "
- "[<replica COUNT>] <NEW-BRICK>..."},
-
- {"volume detach-tier <VOLNAME> "
- "<start|stop|status|commit|force>",
- cli_cmd_volume_tier_cbk,
- "NOTE: this is old syntax, will be deprecated in next release. "
- "Please use gluster volume tier <vol> detach "
- "{start|stop|commit} [force]"},
-
- {"volume tier <VOLNAME> status\n"
- "volume tier <VOLNAME> start [force]\n"
- "volume tier <VOLNAME> stop\n"
- "volume tier <VOLNAME> attach [<replica COUNT>] <NEW-BRICK>... [force]\n"
- "volume tier <VOLNAME> detach <start|stop|status|commit|[force]>\n",
- cli_cmd_volume_tier_cbk, NULL},
-
- {NULL, NULL, NULL}
-
-};
-
struct cli_cmd volume_cmds[] = {
{"volume help", cli_cmd_volume_help_cbk,
"display help for volume commands"},
@@ -3314,12 +3040,9 @@ struct cli_cmd volume_cmds[] = {
"list information of all volumes"},
{"volume create <NEW-VOLNAME> [stripe <COUNT>] "
- "[replica <COUNT> [arbiter <COUNT>]] "
+ "[[replica <COUNT> [arbiter <COUNT>]]|[replica 2 thin-arbiter 1]] "
"[disperse [<COUNT>]] [disperse-data <COUNT>] [redundancy <COUNT>] "
- "[transport <tcp|rdma|tcp,rdma>] <NEW-BRICK>"
-#ifdef HAVE_BD_XLATOR
- "?<vg_name>"
-#endif
+ "[transport <tcp|rdma|tcp,rdma>] <NEW-BRICK> <TA-BRICK>"
"... [force]",
cli_cmd_volume_create_cbk,
@@ -3361,13 +3084,14 @@ struct cli_cmd volume_cmds[] = {
{"volume set <VOLNAME> <KEY> <VALUE>", cli_cmd_volume_set_cbk,
"set options for volume <VOLNAME>"},
+ {"volume set <VOLNAME> group <GROUP>", cli_cmd_volume_set_cbk,
+ "This option can be used for setting multiple pre-defined volume options "
+ "where group_name is a file under /var/lib/glusterd/groups containing one "
+ "key value pair per line"},
+
{"volume log <VOLNAME> rotate [BRICK]", cli_cmd_log_rotate_cbk,
"rotate 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"
- " NOTE: This is an old syntax, will be deprecated from next release."},
-
{"volume sync <HOSTNAME> [all|<VOLNAME>]", cli_cmd_sync_volume_cbk,
"sync the volume information from a peer"},
@@ -3375,10 +3099,12 @@ struct cli_cmd volume_cmds[] = {
"reset all the reconfigured options"},
#if (SYNCDAEMON_COMPILE)
- {"volume " GEOREP " [<VOLNAME>] [<SLAVE-URL>] {create [[ssh-port n] "
- "[[no-verify]|[push-pem]]] [force]"
- "|start [force]|stop [force]|pause [force]|resume [force]|config|status "
- "[detail]|delete [reset-sync-time]} [options...]",
+ {"volume " GEOREP " [<MASTER-VOLNAME>] [<SLAVE-IP>]::[<SLAVE-VOLNAME>] {"
+ "\\\n create [[ssh-port n] [[no-verify] \\\n | [push-pem]]] [force] \\\n"
+ " | start [force] \\\n | stop [force] \\\n | pause [force] \\\n | resume "
+ "[force] \\\n"
+ " | config [[[\\!]<option>] [<value>]] \\\n | status "
+ "[detail] \\\n | delete [reset-sync-time]} ",
cli_cmd_volume_gsync_set_cbk, "Geo-sync operations",
cli_cmd_check_gsync_exists_cbk},
#endif
@@ -3388,12 +3114,12 @@ struct cli_cmd volume_cmds[] = {
cli_cmd_volume_profile_cbk, "volume profile operations"},
{"volume top <VOLNAME> {open|read|write|opendir|readdir|clear} [nfs|brick "
- "<brick>] [list-cnt <value>] |\n"
- "volume top <VOLNAME> {read-perf|write-perf} [bs <size> count <count>] "
+ "<brick>] [list-cnt <value>] | "
+ "{read-perf|write-perf} [bs <size> count <count>] "
"[brick <brick>] [list-cnt <value>]",
cli_cmd_volume_top_cbk, "volume top operations"},
- {"volume status [all | <VOLNAME> [nfs|shd|<BRICK>|quotad|tierd]]"
+ {"volume status [all | <VOLNAME> [nfs|shd|<BRICK>|quotad]]"
" [detail|clients|mem|inode|fd|callpool|tasks|client-list]",
cli_cmd_volume_status_cbk,
"display status of all or specified volume(s)/brick"},
@@ -3482,32 +3208,6 @@ cli_cmd_bitrot_help_cbk(struct cli_state *state, struct cli_cmd_word *in_word,
}
int
-cli_cmd_tier_help_cbk(struct cli_state *state, struct cli_cmd_word *in_word,
- const char **words, int wordcount)
-{
- struct cli_cmd *cmd = NULL;
- struct cli_cmd *tier_cmd = NULL;
- int count = 0;
-
- cmd = GF_MALLOC(sizeof(tier_cmds), cli_mt_cli_cmd);
- memcpy(cmd, tier_cmds, sizeof(tier_cmds));
- count = (sizeof(tier_cmds) / sizeof(struct cli_cmd));
- cli_cmd_sort(cmd, count);
-
- cli_out("\ngluster tier commands");
- cli_out("======================\n");
-
- for (tier_cmd = cmd; tier_cmd->pattern; tier_cmd++) {
- if ((_gf_false == tier_cmd->disable) && tier_cmd->desc) {
- cli_out("%s - %s", tier_cmd->pattern, tier_cmd->desc);
- }
- }
- cli_out("\n");
- GF_FREE(cmd);
- return 0;
-}
-
-int
cli_cmd_volume_help_cbk(struct cli_state *state, struct cli_cmd_word *in_word,
const char **words, int wordcount)
{
@@ -3556,15 +3256,23 @@ cli_cmd_volume_register(struct cli_state *state)
goto out;
}
-#if !defined(__NetBSD__)
- for (cmd = tier_cmds; cmd->pattern; cmd++) {
- ret = cli_cmd_register(&state->tree, cmd);
- if (ret)
- goto out;
- }
-
-#endif
-
out:
return ret;
}
+
+static int
+gf_asprintf_append(char **string_ptr, const char *format, ...)
+{
+ va_list arg;
+ int rv = 0;
+ char *tmp = *string_ptr;
+
+ va_start(arg, format);
+ rv = gf_vasprintf(string_ptr, format, arg);
+ va_end(arg);
+
+ if (tmp)
+ GF_FREE(tmp);
+
+ return rv;
+}
diff --git a/cli/src/cli-cmd.c b/cli/src/cli-cmd.c
index 396cabebbbe..2d458b16a56 100644
--- a/cli/src/cli-cmd.c
+++ b/cli/src/cli-cmd.c
@@ -28,11 +28,7 @@ static pthread_cond_t conn = PTHREAD_COND_INITIALIZER;
static pthread_mutex_t conn_mutex = PTHREAD_MUTEX_INITIALIZER;
int cli_op_ret = 0;
-int connected = 0;
-
-int
-cli_cmd_log_help_cbk(struct cli_state *state, struct cli_cmd_word *in_word,
- const char **words, int wordcount);
+static gf_boolean_t connected = _gf_false;
static unsigned
cli_cmd_needs_connection(struct cli_cmd_word *word)
@@ -108,12 +104,14 @@ cli_cmd_process(struct cli_state *state, int argc, char **argv)
}
if (!word) {
- cli_out("unrecognized word: %s (position %d)", argv[i], i);
+ cli_out("unrecognized word: %s (position %d)\n", argv[i], i);
+ usage();
return -1;
}
if (!word->cbkfn) {
- cli_out("unrecognized command");
+ cli_out("unrecognized command\n");
+ usage();
return -1;
}
@@ -234,18 +232,6 @@ out:
}
int
-cli_cmd_cond_init()
-{
- pthread_mutex_init(&cond_mutex, NULL);
- pthread_cond_init(&cond, NULL);
-
- pthread_mutex_init(&conn_mutex, NULL);
- pthread_cond_init(&conn, NULL);
-
- return 0;
-}
-
-int
cli_cmd_lock()
{
pthread_mutex_lock(&cond_mutex);
@@ -342,19 +328,32 @@ cli_cmd_await_connected(unsigned conn_timo)
}
int32_t
-cli_cmd_broadcast_connected()
+cli_cmd_broadcast_connected(gf_boolean_t status)
{
pthread_mutex_lock(&conn_mutex);
{
- connected = 1;
+ connected = status;
pthread_cond_broadcast(&conn);
}
-
pthread_mutex_unlock(&conn_mutex);
return 0;
}
+gf_boolean_t
+cli_cmd_connected(void)
+{
+ gf_boolean_t status;
+
+ pthread_mutex_lock(&conn_mutex);
+ {
+ status = connected;
+ }
+ pthread_mutex_unlock(&conn_mutex);
+
+ return status;
+}
+
int
cli_cmd_submit(struct rpc_clnt *rpc, void *req, call_frame_t *frame,
rpc_clnt_prog_t *prog, int procnum, struct iobref *iobref,
@@ -364,7 +363,8 @@ cli_cmd_submit(struct rpc_clnt *rpc, void *req, call_frame_t *frame,
unsigned timeout = 0;
if ((GLUSTER_CLI_PROFILE_VOLUME == procnum) ||
- (GLUSTER_CLI_HEAL_VOLUME == procnum))
+ (GLUSTER_CLI_HEAL_VOLUME == procnum) ||
+ (GLUSTER_CLI_GANESHA == procnum))
timeout = cli_ten_minutes_timeout;
else
timeout = cli_default_conn_timeout;
diff --git a/cli/src/cli-cmd.h b/cli/src/cli-cmd.h
index 70c864eae30..c1c068c7085 100644
--- a/cli/src/cli-cmd.h
+++ b/cli/src/cli-cmd.h
@@ -13,7 +13,7 @@
#include <netdb.h>
#include "cli.h"
-#include "list.h"
+#include <glusterfs/list.h>
#define GLUSTER_SHARED_STORAGE "gluster_shared_storage"
@@ -102,9 +102,6 @@ int
cli_cmd_broadcast_response(int32_t status);
int
-cli_cmd_cond_init();
-
-int
cli_cmd_lock();
int
diff --git a/cli/src/cli-mem-types.h b/cli/src/cli-mem-types.h
index a762b685f0a..b42b4dd86c2 100644
--- a/cli/src/cli-mem-types.h
+++ b/cli/src/cli-mem-types.h
@@ -10,7 +10,7 @@
#ifndef __CLI_MEM_TYPES_H__
#define __CLI_MEM_TYPES_H__
-#include "mem-types.h"
+#include <glusterfs/mem-types.h>
#define CLI_MEM_TYPE_START (gf_common_mt_end + 1)
diff --git a/cli/src/cli-quotad-client.c b/cli/src/cli-quotad-client.c
index fbd2c0391ab..772b8f75bd9 100644
--- a/cli/src/cli-quotad-client.c
+++ b/cli/src/cli-quotad-client.c
@@ -10,9 +10,6 @@
#include "cli-quotad-client.h"
-extern struct rpc_clnt global_quotad_rpc;
-extern struct rpc_clnt_program cli_quotad_clnt;
-
int
cli_quotad_submit_request(void *req, call_frame_t *frame, rpc_clnt_prog_t *prog,
int procnum, struct iobref *iobref, xlator_t *this,
@@ -60,7 +57,7 @@ cli_quotad_submit_request(void *req, call_frame_t *frame, rpc_clnt_prog_t *prog,
}
/* Send the msg */
- ret = rpc_clnt_submit(&global_quotad_rpc, prog, procnum, cbkfn, &iov, count,
+ ret = rpc_clnt_submit(global_quotad_rpc, prog, procnum, cbkfn, &iov, count,
NULL, 0, iobref, frame, NULL, 0, NULL, 0, NULL);
ret = 0;
@@ -109,16 +106,21 @@ cli_quotad_clnt_init(xlator_t *this, dict_t *options)
struct rpc_clnt *rpc = NULL;
int ret = -1;
- ret = dict_set_str(options, "transport.address-family", "unix");
+ ret = dict_set_nstrn(options, "transport.address-family",
+ SLEN("transport.address-family"), "unix",
+ SLEN("unix"));
if (ret)
goto out;
- ret = dict_set_str(options, "transport-type", "socket");
+ ret = dict_set_nstrn(options, "transport-type", SLEN("transport-type"),
+ "socket", SLEN("socket"));
if (ret)
goto out;
- ret = dict_set_str(options, "transport.socket.connect-path",
- "/var/run/gluster/quotad.socket");
+ ret = dict_set_nstrn(options, "transport.socket.connect-path",
+ SLEN("transport.socket.connect-path"),
+ "/var/run/gluster/quotad.socket",
+ SLEN("/var/run/gluster/quotad.socket"));
if (ret)
goto out;
diff --git a/cli/src/cli-quotad-client.h b/cli/src/cli-quotad-client.h
index 57a998c913c..71a44e5916b 100644
--- a/cli/src/cli-quotad-client.h
+++ b/cli/src/cli-quotad-client.h
@@ -8,8 +8,8 @@
cases as published by the Free Software Foundation.
*/
#include "cli.h"
-#include "compat-errno.h"
-#include "compat.h"
+#include <glusterfs/compat-errno.h>
+#include <glusterfs/compat.h>
#include "cli-cmd.h"
#include "cli1-xdr.h"
#include "xdr-generic.h"
diff --git a/cli/src/cli-rl.c b/cli/src/cli-rl.c
index 495f9391a1a..7a38a0b882a 100644
--- a/cli/src/cli-rl.c
+++ b/cli/src/cli-rl.c
@@ -17,7 +17,7 @@
#include "cli-cmd.h"
#include "cli-mem-types.h"
-#include "gf-event.h"
+#include <glusterfs/gf-event.h>
#include <fnmatch.h>
@@ -104,7 +104,7 @@ cli_rl_process_line(char *line)
void
cli_rl_stdin(int fd, int idx, int gen, void *data, int poll_out, int poll_in,
- int poll_err)
+ int poll_err, char event_thread_died)
{
struct cli_state *state = NULL;
@@ -112,7 +112,7 @@ cli_rl_stdin(int fd, int idx, int gen, void *data, int poll_out, int poll_in,
rl_callback_read_char();
- event_handled(state->ctx->event_pool, fd, idx, gen);
+ gf_event_handled(state->ctx->event_pool, fd, idx, gen);
return;
}
@@ -281,11 +281,9 @@ cli_rl_autocomplete_prepare(struct cli_state *state, const char *text)
break;
}
- if (!word)
+ if (!word || !token)
goto out;
- if (!token)
- return 0;
matches = cli_rl_get_matches(state, word, token);
state->matches = matches;
@@ -348,6 +346,9 @@ cli_rl_input(void *_data)
state = _data;
+ fprintf(stderr,
+ "Welcome to gluster prompt, type 'help' to see the available "
+ "commands.\n");
for (;;) {
line = readline(state->prompt);
if (!line)
@@ -378,7 +379,8 @@ cli_rl_enable(struct cli_state *state)
goto out;
}
- ret = event_register(state->ctx->event_pool, 0, cli_rl_stdin, state, 1, 0);
+ ret = gf_event_register(state->ctx->event_pool, 0, cli_rl_stdin, state, 1,
+ 0, 0);
if (ret == -1)
goto out;
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c
index fea74667e05..9b6b0c7fa50 100644
--- a/cli/src/cli-rpc-ops.c
+++ b/cli/src/cli-rpc-ops.c
@@ -19,42 +19,37 @@
#define INDENT_MAIN_HEAD "%-25s %s "
+#define RETURNING "Returning %d"
+#define XML_ERROR "Error outputting to xml"
+#define XDR_DECODE_FAIL "Failed to decode xdr response"
+#define DICT_SERIALIZE_FAIL "Failed to serialize to data to dictionary"
+#define DICT_UNSERIALIZE_FAIL "Failed to unserialize the dictionary"
+
/* Do not show estimates if greater than this number */
#define REBAL_ESTIMATE_SEC_UPPER_LIMIT (60 * 24 * 3600)
#define REBAL_ESTIMATE_START_TIME 600
#include "cli.h"
-#include "compat-errno.h"
+#include <glusterfs/compat-errno.h>
#include "cli-cmd.h"
#include <sys/uio.h>
#include <stdlib.h>
#include <sys/mount.h>
-#include "cli1-xdr.h"
-#include "xdr-generic.h"
-#include "protocol-common.h"
+#include <glusterfs/compat.h>
#include "cli-mem-types.h"
-#include "compat.h"
-#include "upcall-utils.h"
-
-#include "syscall.h"
+#include <glusterfs/syscall.h>
#include "glusterfs3.h"
#include "portmap-xdr.h"
-#include "byte-order.h"
+#include <glusterfs/byte-order.h>
-#include "cli-quotad-client.h"
-#include "run.h"
-#include "quota-common-utils.h"
-#include "events.h"
+#include <glusterfs/run.h>
+#include <glusterfs/events.h>
enum gf_task_types { GF_TASK_TYPE_REBALANCE, GF_TASK_TYPE_REMOVE_BRICK };
-extern struct rpc_clnt *global_quotad_rpc;
-extern rpc_clnt_prog_t cli_quotad_clnt;
-extern rpc_clnt_prog_t *cli_rpc_prog;
-extern int cli_op_ret;
-extern int connected;
+rpc_clnt_prog_t cli_quotad_clnt;
-int32_t
+static int32_t
gf_cli_remove_brick(call_frame_t *frame, xlator_t *this, void *data);
char *cli_vol_status_str[] = {
@@ -74,33 +69,66 @@ char *cli_vol_task_status_str[] = {"not started",
"fix-layout failed",
"unknown"};
-int32_t
+static int32_t
gf_cli_snapshot(call_frame_t *frame, xlator_t *this, void *data);
-int32_t
+static int32_t
gf_cli_get_volume(call_frame_t *frame, xlator_t *this, void *data);
-int
+static int
cli_to_glusterd(gf_cli_req *req, call_frame_t *frame, fop_cbk_fn_t cbkfn,
xdrproc_t xdrproc, dict_t *dict, int procnum, xlator_t *this,
rpc_clnt_prog_t *prog, struct iobref *iobref);
-int
+static int
add_cli_cmd_timeout_to_dict(dict_t *dict);
-rpc_clnt_prog_t cli_handshake_prog = {
+static rpc_clnt_prog_t cli_handshake_prog = {
.progname = "cli handshake",
.prognum = GLUSTER_HNDSK_PROGRAM,
.progver = GLUSTER_HNDSK_VERSION,
};
-rpc_clnt_prog_t cli_pmap_prog = {
+static rpc_clnt_prog_t cli_pmap_prog = {
.progname = "cli portmap",
.prognum = GLUSTER_PMAP_PROGRAM,
.progver = GLUSTER_PMAP_VERSION,
};
-int
+static void
+gf_free_xdr_cli_rsp(gf_cli_rsp rsp)
+{
+ if (rsp.dict.dict_val) {
+ free(rsp.dict.dict_val);
+ }
+ if (rsp.op_errstr) {
+ free(rsp.op_errstr);
+ }
+}
+
+static void
+gf_free_xdr_getspec_rsp(gf_getspec_rsp rsp)
+{
+ if (rsp.spec) {
+ free(rsp.spec);
+ }
+ if (rsp.xdata.xdata_val) {
+ free(rsp.xdata.xdata_val);
+ }
+}
+
+static void
+gf_free_xdr_fsm_log_rsp(gf1_cli_fsm_log_rsp rsp)
+{
+ if (rsp.op_errstr) {
+ free(rsp.op_errstr);
+ }
+ if (rsp.fsm_log.fsm_log_val) {
+ free(rsp.fsm_log.fsm_log_val);
+ }
+}
+
+static int
gf_cli_probe_cbk(struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
@@ -108,9 +136,7 @@ gf_cli_probe_cbk(struct rpc_req *req, struct iovec *iov, int count,
0,
};
int ret = -1;
- char msg[1024] = {
- 0,
- };
+ char msg[1024] = "success";
GF_ASSERT(myframe);
@@ -121,7 +147,7 @@ gf_cli_probe_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ XDR_DECODE_FAIL);
// rsp.op_ret = -1;
// rsp.op_errno = EINVAL;
goto out;
@@ -129,22 +155,23 @@ gf_cli_probe_cbk(struct rpc_req *req, struct iovec *iov, int count,
gf_log("cli", GF_LOG_INFO, "Received resp to probe");
- if (rsp.op_errstr && (strlen(rsp.op_errstr) > 0)) {
+ if (rsp.op_errstr && rsp.op_errstr[0] != '\0') {
snprintf(msg, sizeof(msg), "%s", rsp.op_errstr);
- if (rsp.op_ret)
+ if (rsp.op_ret) {
gf_log("cli", GF_LOG_ERROR, "%s", msg);
+ }
}
if (global_state->mode & GLUSTER_MODE_XML) {
ret = cli_xml_output_str(NULL, (rsp.op_ret) ? NULL : msg, rsp.op_ret,
rsp.op_errno, (rsp.op_ret) ? msg : NULL);
if (ret)
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
goto out;
}
if (!rsp.op_ret)
- cli_out("peer probe: success. %s", msg);
+ cli_out("peer probe: %s", msg);
else
cli_err("peer probe: failed: %s", msg);
@@ -152,10 +179,11 @@ gf_cli_probe_cbk(struct rpc_req *req, struct iovec *iov, int count,
out:
cli_cmd_broadcast_response(ret);
+ gf_free_xdr_cli_rsp(rsp);
return ret;
}
-int
+static int
gf_cli_deprobe_cbk(struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
@@ -163,9 +191,7 @@ gf_cli_deprobe_cbk(struct rpc_req *req, struct iovec *iov, int count,
0,
};
int ret = -1;
- char msg[1024] = {
- 0,
- };
+ char msg[1024] = "success";
GF_ASSERT(myframe);
@@ -176,7 +202,7 @@ gf_cli_deprobe_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ XDR_DECODE_FAIL);
// rsp.op_ret = -1;
// rsp.op_errno = EINVAL;
goto out;
@@ -185,19 +211,17 @@ gf_cli_deprobe_cbk(struct rpc_req *req, struct iovec *iov, int count,
gf_log("cli", GF_LOG_INFO, "Received resp to deprobe");
if (rsp.op_ret) {
- if (strlen(rsp.op_errstr) > 0) {
+ if (rsp.op_errstr[0] != '\0') {
snprintf(msg, sizeof(msg), "%s", rsp.op_errstr);
gf_log("cli", GF_LOG_ERROR, "%s", rsp.op_errstr);
}
- } else {
- snprintf(msg, sizeof(msg), "success");
}
if (global_state->mode & GLUSTER_MODE_XML) {
ret = cli_xml_output_str(NULL, (rsp.op_ret) ? NULL : msg, rsp.op_ret,
rsp.op_errno, (rsp.op_ret) ? msg : NULL);
if (ret)
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
goto out;
}
@@ -210,14 +234,15 @@ gf_cli_deprobe_cbk(struct rpc_req *req, struct iovec *iov, int count,
out:
cli_cmd_broadcast_response(ret);
+ gf_free_xdr_cli_rsp(rsp);
return ret;
}
-int
-gf_cli_output_peer_hostnames(dict_t *dict, int count, char *prefix)
+static int
+gf_cli_output_peer_hostnames(dict_t *dict, int count, const char *prefix)
{
int ret = -1;
- char key[256] = {
+ char key[512] = {
0,
};
int i = 0;
@@ -228,8 +253,8 @@ gf_cli_output_peer_hostnames(dict_t *dict, int count, char *prefix)
* as friend.hostname
*/
for (i = 1; i < count; i++) {
- snprintf(key, sizeof(key), "%s.hostname%d", prefix, i);
- ret = dict_get_str(dict, key, &hostname);
+ ret = snprintf(key, sizeof(key), "%s.hostname%d", prefix, i);
+ ret = dict_get_strn(dict, key, ret, &hostname);
if (ret)
break;
cli_out("%s", hostname);
@@ -239,7 +264,7 @@ gf_cli_output_peer_hostnames(dict_t *dict, int count, char *prefix)
return ret;
}
-int
+static int
gf_cli_output_peer_status(dict_t *dict, int count)
{
int ret = -1;
@@ -249,26 +274,27 @@ gf_cli_output_peer_status(dict_t *dict, int count)
char key[256] = {
0,
};
+ int keylen;
char *state = NULL;
int32_t connected = 0;
- char *connected_str = NULL;
+ const char *connected_str = NULL;
int hostname_count = 0;
cli_out("Number of Peers: %d", count);
i = 1;
while (i <= count) {
- snprintf(key, 256, "friend%d.uuid", i);
- ret = dict_get_str(dict, key, &uuid_buf);
+ keylen = snprintf(key, sizeof(key), "friend%d.uuid", i);
+ ret = dict_get_strn(dict, key, keylen, &uuid_buf);
if (ret)
goto out;
- snprintf(key, 256, "friend%d.hostname", i);
- ret = dict_get_str(dict, key, &hostname_buf);
+ keylen = snprintf(key, sizeof(key), "friend%d.hostname", i);
+ ret = dict_get_strn(dict, key, keylen, &hostname_buf);
if (ret)
goto out;
- snprintf(key, 256, "friend%d.connected", i);
- ret = dict_get_int32(dict, key, &connected);
+ keylen = snprintf(key, sizeof(key), "friend%d.connected", i);
+ ret = dict_get_int32n(dict, key, keylen, &connected);
if (ret)
goto out;
if (connected)
@@ -276,16 +302,16 @@ gf_cli_output_peer_status(dict_t *dict, int count)
else
connected_str = "Disconnected";
- snprintf(key, 256, "friend%d.state", i);
- ret = dict_get_str(dict, key, &state);
+ keylen = snprintf(key, sizeof(key), "friend%d.state", i);
+ ret = dict_get_strn(dict, key, keylen, &state);
if (ret)
goto out;
cli_out("\nHostname: %s\nUuid: %s\nState: %s (%s)", hostname_buf,
uuid_buf, state, connected_str);
- snprintf(key, sizeof(key), "friend%d.hostname_count", i);
- ret = dict_get_int32(dict, key, &hostname_count);
+ keylen = snprintf(key, sizeof(key), "friend%d.hostname_count", i);
+ ret = dict_get_int32n(dict, key, keylen, &hostname_count);
/* Print other addresses only if there are more than 1.
*/
if ((ret == 0) && (hostname_count > 1)) {
@@ -305,7 +331,7 @@ out:
return ret;
}
-int
+static int
gf_cli_output_pool_list(dict_t *dict, int count)
{
int ret = -1;
@@ -313,18 +339,19 @@ gf_cli_output_pool_list(dict_t *dict, int count)
char *hostname_buf = NULL;
int32_t hostname_len = 8; /*min len 8 chars*/
int32_t i = 1;
- char key[256] = {
+ char key[64] = {
0,
};
+ int keylen;
int32_t connected = 0;
- char *connected_str = NULL;
+ const char *connected_str = NULL;
if (count <= 0)
goto out;
while (i <= count) {
- snprintf(key, 256, "friend%d.hostname", i);
- ret = dict_get_str(dict, key, &hostname_buf);
+ keylen = snprintf(key, sizeof(key), "friend%d.hostname", i);
+ ret = dict_get_strn(dict, key, keylen, &hostname_buf);
if (ret)
goto out;
@@ -339,18 +366,18 @@ gf_cli_output_pool_list(dict_t *dict, int count)
i = 1;
while (i <= count) {
- snprintf(key, 256, "friend%d.uuid", i);
- ret = dict_get_str(dict, key, &uuid_buf);
+ keylen = snprintf(key, sizeof(key), "friend%d.uuid", i);
+ ret = dict_get_strn(dict, key, keylen, &uuid_buf);
if (ret)
goto out;
- snprintf(key, 256, "friend%d.hostname", i);
- ret = dict_get_str(dict, key, &hostname_buf);
+ keylen = snprintf(key, sizeof(key), "friend%d.hostname", i);
+ ret = dict_get_strn(dict, key, keylen, &hostname_buf);
if (ret)
goto out;
- snprintf(key, 256, "friend%d.connected", i);
- ret = dict_get_int32(dict, key, &connected);
+ keylen = snprintf(key, sizeof(key), "friend%d.connected", i);
+ ret = dict_get_int32n(dict, key, keylen, &connected);
if (ret)
goto out;
if (connected)
@@ -371,7 +398,7 @@ out:
/* function pointer for gf_cli_output_{pool_list,peer_status} */
typedef int (*cli_friend_output_fn)(dict_t *, int);
-int
+static int
gf_cli_list_friends_cbk(struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
@@ -383,11 +410,15 @@ gf_cli_list_friends_cbk(struct rpc_req *req, struct iovec *iov, int count,
char msg[1024] = {
0,
};
- char *cmd = NULL;
+ const char *cmd = NULL;
cli_friend_output_fn friend_output_fn;
call_frame_t *frame = NULL;
unsigned long flags = 0;
+ if (-1 == req->rpc_status) {
+ goto out;
+ }
+
GF_ASSERT(myframe);
frame = myframe;
@@ -405,14 +436,9 @@ gf_cli_list_friends_cbk(struct rpc_req *req, struct iovec *iov, int count,
/* 'free' the flags set by gf_cli_list_friends */
frame->local = NULL;
- if (-1 == req->rpc_status) {
- goto out;
- }
-
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf1_cli_peer_list_rsp);
if (ret < 0) {
- gf_log(frame->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ gf_log(frame->this->name, GF_LOG_ERROR, XDR_DECODE_FAIL);
// rsp.op_ret = -1;
// rsp.op_errno = EINVAL;
goto out;
@@ -427,7 +453,7 @@ gf_cli_list_friends_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = cli_xml_output_peer_status(dict, rsp.op_ret, rsp.op_errno,
msg);
if (ret)
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
goto out;
}
cli_err("%s", msg);
@@ -446,7 +472,7 @@ gf_cli_list_friends_cbk(struct rpc_req *req, struct iovec *iov, int count,
&dict);
if (ret) {
- gf_log("", GF_LOG_ERROR, "Unable to allocate memory");
+ gf_log("", GF_LOG_ERROR, DICT_UNSERIALIZE_FAIL);
goto out;
}
@@ -454,11 +480,11 @@ gf_cli_list_friends_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = cli_xml_output_peer_status(dict, rsp.op_ret, rsp.op_errno,
msg);
if (ret)
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
goto out;
}
- ret = dict_get_int32(dict, "count", &count);
+ ret = dict_get_int32_sizen(dict, "count", &count);
if (ret) {
goto out;
}
@@ -472,7 +498,7 @@ gf_cli_list_friends_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = cli_xml_output_peer_status(dict, rsp.op_ret, rsp.op_errno,
NULL);
if (ret)
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
} else {
ret = -1;
}
@@ -490,10 +516,13 @@ out:
if (dict)
dict_unref(dict);
+ if (rsp.friends.friends_val) {
+ free(rsp.friends.friends_val);
+ }
return ret;
}
-int
+static int
gf_cli_get_state_cbk(struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
@@ -513,7 +542,7 @@ gf_cli_get_state_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ XDR_DECODE_FAIL);
goto out;
}
@@ -536,11 +565,11 @@ gf_cli_get_state_cbk(struct rpc_req *req, struct iovec *iov, int count,
"Failed to get daemon state. Check glusterd"
" log file for more details");
} else {
- ret = dict_get_str(dict, "daemon", &daemon_name);
+ ret = dict_get_str_sizen(dict, "daemon", &daemon_name);
if (ret)
gf_log("cli", GF_LOG_ERROR, "Couldn't get daemon name");
- ret = dict_get_str(dict, "ofilepath", &ofilepath);
+ ret = dict_get_str_sizen(dict, "ofilepath", &ofilepath);
if (ret)
gf_log("cli", GF_LOG_ERROR, "Couldn't get filepath");
@@ -551,18 +580,16 @@ gf_cli_get_state_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = rsp.op_ret;
out:
- free(rsp.dict.dict_val);
- free(rsp.op_errstr);
-
if (dict)
dict_unref(dict);
cli_cmd_broadcast_response(ret);
+ gf_free_xdr_cli_rsp(rsp);
return ret;
}
-void
+static void
cli_out_options(char *substr, char *optstr, char *valstr)
{
char *ptr1 = NULL;
@@ -613,25 +640,24 @@ static int
print_brick_details(dict_t *dict, int volcount, int start_index, int end_index,
int replica_count)
{
- char key[1024] = {
+ char key[64] = {
0,
};
+ int keylen;
int index = start_index;
int isArbiter = 0;
int ret = -1;
char *brick = NULL;
-#ifdef HAVE_BD_XLATOR
- char *caps = NULL;
-#endif
while (index <= end_index) {
- snprintf(key, 1024, "volume%d.brick%d", volcount, index);
- ret = dict_get_str(dict, key, &brick);
+ keylen = snprintf(key, sizeof(key), "volume%d.brick%d", volcount,
+ index);
+ ret = dict_get_strn(dict, key, keylen, &brick);
if (ret)
goto out;
- snprintf(key, sizeof(key), "volume%d.brick%d.isArbiter", volcount,
- index);
- if (dict_get(dict, key))
+ keylen = snprintf(key, sizeof(key), "volume%d.brick%d.isArbiter",
+ volcount, index);
+ if (dict_getn(dict, key, keylen))
isArbiter = 1;
else
isArbiter = 0;
@@ -640,35 +666,20 @@ print_brick_details(dict_t *dict, int volcount, int start_index, int end_index,
cli_out("Brick%d: %s (arbiter)", index, brick);
else
cli_out("Brick%d: %s", index, brick);
-#ifdef HAVE_BD_XLATOR
- snprintf(key, 1024, "volume%d.vg%d", volcount, index);
- ret = dict_get_str(dict, key, &caps);
- if (!ret)
- cli_out("Brick%d VG: %s", index, caps);
-#endif
index++;
}
ret = 0;
out:
return ret;
}
-void
+
+static void
gf_cli_print_number_of_bricks(int type, int brick_count, int dist_count,
int stripe_count, int replica_count,
int disperse_count, int redundancy_count,
int arbiter_count)
{
- if (type == GF_CLUSTER_TYPE_STRIPE_REPLICATE) {
- if (arbiter_count == 0) {
- cli_out("Number of Bricks: %d x %d x %d = %d",
- (brick_count / dist_count), stripe_count, replica_count,
- brick_count);
- } else {
- cli_out("Number of Bricks: %d x %d x (%d + %d) = %d",
- (brick_count / dist_count), stripe_count,
- replica_count - arbiter_count, arbiter_count, brick_count);
- }
- } else if (type == GF_CLUSTER_TYPE_NONE || type == GF_CLUSTER_TYPE_TIER) {
+ if (type == GF_CLUSTER_TYPE_NONE) {
cli_out("Number of Bricks: %d", brick_count);
} else if (type == GF_CLUSTER_TYPE_DISPERSE) {
cli_out("Number of Bricks: %d x (%d + %d) = %d",
@@ -688,108 +699,7 @@ gf_cli_print_number_of_bricks(int type, int brick_count, int dist_count,
}
}
-int
-gf_cli_print_tier_info(dict_t *dict, int i, int brick_count)
-{
- int hot_brick_count = -1;
- int cold_type = 0;
- int cold_brick_count = 0;
- int cold_replica_count = 0;
- int cold_arbiter_count = 0;
- int cold_disperse_count = 0;
- int cold_redundancy_count = 0;
- int cold_dist_count = 0;
- int hot_type = 0;
- int hot_replica_count = 0;
- int hot_dist_count = 0;
- int ret = -1;
- int vol_type = -1;
- char key[256] = {
- 0,
- };
-
- GF_ASSERT(dict);
-
- snprintf(key, sizeof(key), "volume%d.cold_brick_count", i);
- ret = dict_get_int32(dict, key, &cold_brick_count);
- if (ret)
- goto out;
-
- snprintf(key, sizeof(key), "volume%d.cold_type", i);
- ret = dict_get_int32(dict, key, &cold_type);
- if (ret)
- goto out;
-
- snprintf(key, sizeof(key), "volume%d.cold_dist_count", i);
- ret = dict_get_int32(dict, key, &cold_dist_count);
- if (ret)
- goto out;
-
- snprintf(key, sizeof(key), "volume%d.cold_replica_count", i);
- ret = dict_get_int32(dict, key, &cold_replica_count);
- if (ret)
- goto out;
-
- snprintf(key, sizeof(key), "volume%d.cold_arbiter_count", i);
- ret = dict_get_int32(dict, key, &cold_arbiter_count);
- if (ret)
- goto out;
-
- snprintf(key, sizeof(key), "volume%d.cold_disperse_count", i);
- ret = dict_get_int32(dict, key, &cold_disperse_count);
- if (ret)
- goto out;
-
- snprintf(key, sizeof(key), "volume%d.cold_redundancy_count", i);
- ret = dict_get_int32(dict, key, &cold_redundancy_count);
- if (ret)
- goto out;
-
- snprintf(key, sizeof(key), "volume%d.hot_brick_count", i);
- ret = dict_get_int32(dict, key, &hot_brick_count);
- if (ret)
- goto out;
-
- snprintf(key, sizeof(key), "volume%d.hot_type", i);
- ret = dict_get_int32(dict, key, &hot_type);
- if (ret)
- goto out;
- snprintf(key, sizeof(key), "volume%d.hot_replica_count", i);
- ret = dict_get_int32(dict, key, &hot_replica_count);
- if (ret)
- goto out;
-
- cli_out("Hot Tier :");
- hot_dist_count = (hot_replica_count ? hot_replica_count : 1);
-
- vol_type = get_vol_type(hot_type, hot_dist_count, hot_brick_count);
- cli_out("Hot Tier Type : %s", vol_type_str[vol_type]);
-
- gf_cli_print_number_of_bricks(hot_type, hot_brick_count, hot_dist_count, 0,
- hot_replica_count, 0, 0, 0);
-
- ret = print_brick_details(dict, i, 1, hot_brick_count, hot_replica_count);
- if (ret)
- goto out;
-
- cli_out("Cold Tier:");
-
- vol_type = get_vol_type(cold_type, cold_dist_count, cold_brick_count);
- cli_out("Cold Tier Type : %s", vol_type_str[vol_type]);
-
- gf_cli_print_number_of_bricks(cold_type, cold_brick_count, cold_dist_count,
- 0, cold_replica_count, cold_disperse_count,
- cold_redundancy_count, cold_arbiter_count);
-
- ret = print_brick_details(dict, i, hot_brick_count + 1, brick_count,
- cold_replica_count);
- if (ret)
- goto out;
-out:
- return ret;
-}
-
-int
+static int
gf_cli_get_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
@@ -807,13 +717,16 @@ gf_cli_get_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
int32_t redundancy_count = 0;
int32_t arbiter_count = 0;
int32_t snap_count = 0;
+ int32_t thin_arbiter_count = 0;
int32_t vol_type = 0;
int32_t transport = 0;
char *volume_id_str = NULL;
char *volname = NULL;
+ char *ta_brick = NULL;
dict_t *dict = NULL;
cli_local_t *local = NULL;
- char key[1024] = {0};
+ char key[64] = {0};
+ int keylen;
char err_str[2048] = {0};
gf_cli_rsp rsp = {0};
char *caps __attribute__((unused)) = NULL;
@@ -833,8 +746,7 @@ gf_cli_get_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
- gf_log(frame->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ gf_log(frame->this->name, GF_LOG_ERROR, XDR_DECODE_FAIL);
goto out;
}
@@ -858,11 +770,11 @@ gf_cli_get_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = dict_unserialize(rsp.dict.dict_val, rsp.dict.dict_len, &dict);
if (ret) {
- gf_log("cli", GF_LOG_ERROR, "Unable to allocate memory");
+ gf_log("cli", GF_LOG_ERROR, DICT_UNSERIALIZE_FAIL);
goto out;
}
- ret = dict_get_int32(dict, "count", &count);
+ ret = dict_get_int32_sizen(dict, "count", &count);
if (ret)
goto out;
@@ -899,7 +811,7 @@ xml_output:
ret = cli_xml_output_vol_info_begin(local, rsp.op_ret, rsp.op_errno,
rsp.op_errstr);
if (ret) {
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
goto out;
}
}
@@ -907,7 +819,7 @@ xml_output:
if (dict) {
ret = cli_xml_output_vol_info(local, dict);
if (ret) {
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
goto out;
}
}
@@ -915,75 +827,80 @@ xml_output:
if (local->get_vol.flags == GF_CLI_GET_VOLUME) {
ret = cli_xml_output_vol_info_end(local);
if (ret)
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
}
goto out;
}
while (i < count) {
cli_out(" ");
- snprintf(key, 256, "volume%d.name", i);
- ret = dict_get_str(dict, key, &volname);
+ keylen = snprintf(key, sizeof(key), "volume%d.name", i);
+ ret = dict_get_strn(dict, key, keylen, &volname);
if (ret)
goto out;
- snprintf(key, 256, "volume%d.type", i);
- ret = dict_get_int32(dict, key, &type);
+ keylen = snprintf(key, sizeof(key), "volume%d.type", i);
+ ret = dict_get_int32n(dict, key, keylen, &type);
if (ret)
goto out;
- snprintf(key, 256, "volume%d.status", i);
- ret = dict_get_int32(dict, key, &status);
+ keylen = snprintf(key, sizeof(key), "volume%d.status", i);
+ ret = dict_get_int32n(dict, key, keylen, &status);
+ if (ret)
+ goto out;
+
+ keylen = snprintf(key, sizeof(key), "volume%d.brick_count", i);
+ ret = dict_get_int32n(dict, key, keylen, &brick_count);
if (ret)
goto out;
- snprintf(key, 256, "volume%d.brick_count", i);
- ret = dict_get_int32(dict, key, &brick_count);
+ keylen = snprintf(key, sizeof(key), "volume%d.dist_count", i);
+ ret = dict_get_int32n(dict, key, keylen, &dist_count);
if (ret)
goto out;
- snprintf(key, 256, "volume%d.dist_count", i);
- ret = dict_get_int32(dict, key, &dist_count);
+ keylen = snprintf(key, sizeof(key), "volume%d.stripe_count", i);
+ ret = dict_get_int32n(dict, key, keylen, &stripe_count);
if (ret)
goto out;
- snprintf(key, 256, "volume%d.stripe_count", i);
- ret = dict_get_int32(dict, key, &stripe_count);
+ keylen = snprintf(key, sizeof(key), "volume%d.replica_count", i);
+ ret = dict_get_int32n(dict, key, keylen, &replica_count);
if (ret)
goto out;
- snprintf(key, 256, "volume%d.replica_count", i);
- ret = dict_get_int32(dict, key, &replica_count);
+ keylen = snprintf(key, sizeof(key), "volume%d.disperse_count", i);
+ ret = dict_get_int32n(dict, key, keylen, &disperse_count);
if (ret)
goto out;
- snprintf(key, 256, "volume%d.disperse_count", i);
- ret = dict_get_int32(dict, key, &disperse_count);
+ keylen = snprintf(key, sizeof(key), "volume%d.redundancy_count", i);
+ ret = dict_get_int32n(dict, key, keylen, &redundancy_count);
if (ret)
goto out;
- snprintf(key, 256, "volume%d.redundancy_count", i);
- ret = dict_get_int32(dict, key, &redundancy_count);
+ keylen = snprintf(key, sizeof(key), "volume%d.arbiter_count", i);
+ ret = dict_get_int32n(dict, key, keylen, &arbiter_count);
if (ret)
goto out;
- snprintf(key, sizeof(key), "volume%d.arbiter_count", i);
- ret = dict_get_int32(dict, key, &arbiter_count);
+ keylen = snprintf(key, sizeof(key), "volume%d.transport", i);
+ ret = dict_get_int32n(dict, key, keylen, &transport);
if (ret)
goto out;
- snprintf(key, 256, "volume%d.transport", i);
- ret = dict_get_int32(dict, key, &transport);
+ keylen = snprintf(key, sizeof(key), "volume%d.volume_id", i);
+ ret = dict_get_strn(dict, key, keylen, &volume_id_str);
if (ret)
goto out;
- snprintf(key, 256, "volume%d.volume_id", i);
- ret = dict_get_str(dict, key, &volume_id_str);
+ keylen = snprintf(key, sizeof(key), "volume%d.snap_count", i);
+ ret = dict_get_int32n(dict, key, keylen, &snap_count);
if (ret)
goto out;
- snprintf(key, 256, "volume%d.snap_count", i);
- ret = dict_get_int32(dict, key, &snap_count);
+ keylen = snprintf(key, sizeof(key), "volume%d.thin_arbiter_count", i);
+ ret = dict_get_int32n(dict, key, keylen, &thin_arbiter_count);
if (ret)
goto out;
@@ -996,32 +913,6 @@ xml_output:
cli_out("Status: %s", cli_vol_status_str[status]);
cli_out("Snapshot Count: %d", snap_count);
-#ifdef HAVE_BD_XLATOR
- k = 0;
- snprintf(key, sizeof(key), "volume%d.xlator%d", i, k);
- ret = dict_get_str(dict, key, &caps);
- if (ret)
- goto next;
- do {
- j = 0;
- cli_out("Xlator %d: %s", k + 1, caps);
- do {
- snprintf(key, sizeof(key), "volume%d.xlator%d.caps%d", i, k,
- j++);
- ret = dict_get_str(dict, key, &caps);
- if (ret)
- break;
- cli_out("Capability %d: %s", j, caps);
- } while (1);
-
- snprintf(key, sizeof(key), "volume%d.xlator%d", i, ++k);
- ret = dict_get_str(dict, key, &caps);
- if (ret)
- break;
- } while (1);
-
- next:
-#endif
gf_cli_print_number_of_bricks(
type, brick_count, dist_count, stripe_count, replica_count,
disperse_count, redundancy_count, arbiter_count);
@@ -1034,19 +925,20 @@ xml_output:
GF_FREE(local->get_vol.volname);
local->get_vol.volname = gf_strdup(volname);
- if (type == GF_CLUSTER_TYPE_TIER) {
- ret = gf_cli_print_tier_info(dict, i, brick_count);
- if (ret)
- goto out;
+ cli_out("Bricks:");
+ ret = print_brick_details(dict, i, j, brick_count, replica_count);
+ if (ret)
+ goto out;
- } else {
- cli_out("Bricks:");
- ret = print_brick_details(dict, i, j, brick_count, replica_count);
+ if (thin_arbiter_count) {
+ snprintf(key, sizeof(key), "volume%d.thin_arbiter_brick", i);
+ ret = dict_get_str(dict, key, &ta_brick);
if (ret)
goto out;
+ cli_out("Thin-arbiter-path: %s", ta_brick);
}
- snprintf(key, 256, "volume%d.opt_count", i);
+ snprintf(key, sizeof(key), "volume%d.opt_count", i);
ret = dict_get_int32(dict, key, &opt_count);
if (ret)
goto out;
@@ -1056,7 +948,7 @@ xml_output:
cli_out("Options Reconfigured:");
- snprintf(key, 256, "volume%d.option.", i);
+ snprintf(key, sizeof(key), "volume%d.option.", i);
ret = dict_foreach(dict, _gf_cli_output_volinfo_opts, key);
if (ret)
@@ -1075,15 +967,13 @@ out:
if (dict)
dict_unref(dict);
- free(rsp.dict.dict_val);
-
- free(rsp.op_errstr);
+ gf_free_xdr_cli_rsp(rsp);
- gf_log("cli", GF_LOG_DEBUG, "Returning: %d", ret);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
return ret;
}
-int
+static int
gf_cli_create_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
@@ -1110,24 +1000,19 @@ gf_cli_create_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
- gf_log(frame->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ gf_log(frame->this->name, GF_LOG_ERROR, XDR_DECODE_FAIL);
goto out;
}
gf_log("cli", GF_LOG_INFO, "Received resp to create volume");
- ret = dict_get_str(local->dict, "volname", &volname);
- if (ret)
- goto out;
-
if (global_state->mode & GLUSTER_MODE_XML) {
if (rsp.op_ret == 0) {
rsp_dict = dict_new();
ret = dict_unserialize(rsp.dict.dict_val, rsp.dict.dict_len,
&rsp_dict);
if (ret) {
- gf_log("cli", GF_LOG_ERROR, "Failed rsp_dict unserialization");
+ gf_log("cli", GF_LOG_ERROR, DICT_UNSERIALIZE_FAIL);
goto out;
}
}
@@ -1135,10 +1020,14 @@ gf_cli_create_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = cli_xml_output_vol_create(rsp_dict, rsp.op_ret, rsp.op_errno,
rsp.op_errstr);
if (ret)
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
goto out;
}
+ ret = dict_get_str_sizen(local->dict, "volname", &volname);
+ if (ret)
+ goto out;
+
if (rsp.op_ret && strcmp(rsp.op_errstr, ""))
cli_err("volume create: %s: failed: %s", volname, rsp.op_errstr);
else if (rsp.op_ret)
@@ -1153,12 +1042,14 @@ gf_cli_create_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
out:
cli_cmd_broadcast_response(ret);
- free(rsp.dict.dict_val);
- free(rsp.op_errstr);
+ gf_free_xdr_cli_rsp(rsp);
+
+ if (rsp_dict)
+ dict_unref(rsp_dict);
return ret;
}
-int
+static int
gf_cli_delete_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
@@ -1171,12 +1062,11 @@ gf_cli_delete_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
call_frame_t *frame = NULL;
dict_t *rsp_dict = NULL;
- GF_ASSERT(myframe);
-
if (-1 == req->rpc_status) {
goto out;
}
+ GF_ASSERT(myframe);
frame = myframe;
GF_ASSERT(frame->local);
@@ -1185,14 +1075,7 @@ gf_cli_delete_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
- gf_log(frame->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
- goto out;
- }
-
- ret = dict_get_str(local->dict, "volname", &volname);
- if (ret) {
- gf_log(frame->this->name, GF_LOG_ERROR, "dict get failed");
+ gf_log(frame->this->name, GF_LOG_ERROR, XDR_DECODE_FAIL);
goto out;
}
@@ -1204,7 +1087,7 @@ gf_cli_delete_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = dict_unserialize(rsp.dict.dict_val, rsp.dict.dict_len,
&rsp_dict);
if (ret) {
- gf_log("cli", GF_LOG_ERROR, "Failed rsp_dict unserialization");
+ gf_log("cli", GF_LOG_ERROR, DICT_UNSERIALIZE_FAIL);
goto out;
}
}
@@ -1212,7 +1095,13 @@ gf_cli_delete_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = cli_xml_output_generic_volume("volDelete", rsp_dict, rsp.op_ret,
rsp.op_errno, rsp.op_errstr);
if (ret)
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
+ goto out;
+ }
+
+ ret = dict_get_str_sizen(local->dict, "volname", &volname);
+ if (ret) {
+ gf_log(frame->this->name, GF_LOG_ERROR, "dict get failed");
goto out;
}
@@ -1227,13 +1116,15 @@ gf_cli_delete_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
out:
cli_cmd_broadcast_response(ret);
- free(rsp.dict.dict_val);
+ gf_free_xdr_cli_rsp(rsp);
- gf_log("", GF_LOG_DEBUG, "Returning with %d", ret);
+ if (rsp_dict)
+ dict_unref(rsp_dict);
+ gf_log("", GF_LOG_DEBUG, RETURNING, ret);
return ret;
}
-int
+static int
gf_cli3_1_uuid_get_cbk(struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
@@ -1259,8 +1150,7 @@ gf_cli3_1_uuid_get_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
- gf_log(frame->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ gf_log(frame->this->name, GF_LOG_ERROR, XDR_DECODE_FAIL);
goto out;
}
@@ -1276,17 +1166,7 @@ gf_cli3_1_uuid_get_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = dict_unserialize(rsp.dict.dict_val, rsp.dict.dict_len, &dict);
if (ret) {
- gf_log("cli", GF_LOG_ERROR,
- "Failed to unserialize "
- "response for uuid get");
- goto out;
- }
-
- ret = dict_get_str(dict, "uuid", &uuid_str);
- if (ret) {
- gf_log("cli", GF_LOG_ERROR,
- "Failed to get uuid "
- "from dictionary");
+ gf_log("cli", GF_LOG_ERROR, DICT_UNSERIALIZE_FAIL);
goto out;
}
@@ -1294,7 +1174,7 @@ gf_cli3_1_uuid_get_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = cli_xml_output_dict("uuidGenerate", dict, rsp.op_ret,
rsp.op_errno, rsp.op_errstr);
if (ret)
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
goto out;
}
@@ -1305,6 +1185,11 @@ gf_cli3_1_uuid_get_cbk(struct rpc_req *req, struct iovec *iov, int count,
cli_err("%s", rsp.op_errstr);
} else {
+ ret = dict_get_str_sizen(dict, "uuid", &uuid_str);
+ if (ret) {
+ gf_log("cli", GF_LOG_ERROR, "Failed to get uuid from dictionary");
+ goto out;
+ }
cli_out("UUID: %s", uuid_str);
}
ret = rsp.op_ret;
@@ -1312,14 +1197,16 @@ gf_cli3_1_uuid_get_cbk(struct rpc_req *req, struct iovec *iov, int count,
out:
cli_cmd_broadcast_response(ret);
cli_local_wipe(local);
- if (rsp.dict.dict_val)
- free(rsp.dict.dict_val);
+ gf_free_xdr_cli_rsp(rsp);
- gf_log("", GF_LOG_DEBUG, "Returning with %d", ret);
+ if (dict)
+ dict_unref(dict);
+
+ gf_log("", GF_LOG_DEBUG, RETURNING, ret);
return ret;
}
-int
+static int
gf_cli3_1_uuid_reset_cbk(struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
@@ -1344,8 +1231,7 @@ gf_cli3_1_uuid_reset_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
- gf_log(frame->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ gf_log(frame->this->name, GF_LOG_ERROR, XDR_DECODE_FAIL);
goto out;
}
@@ -1357,7 +1243,7 @@ gf_cli3_1_uuid_reset_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = cli_xml_output_dict("uuidReset", NULL, rsp.op_ret, rsp.op_errno,
rsp.op_errstr);
if (ret)
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
goto out;
}
@@ -1371,14 +1257,13 @@ gf_cli3_1_uuid_reset_cbk(struct rpc_req *req, struct iovec *iov, int count,
out:
cli_cmd_broadcast_response(ret);
cli_local_wipe(local);
- if (rsp.dict.dict_val)
- free(rsp.dict.dict_val);
+ gf_free_xdr_cli_rsp(rsp);
- gf_log("", GF_LOG_DEBUG, "Returning with %d", ret);
+ gf_log("", GF_LOG_DEBUG, RETURNING, ret);
return ret;
}
-int
+static int
gf_cli_start_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
@@ -1405,14 +1290,7 @@ gf_cli_start_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
- gf_log(frame->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
- goto out;
- }
-
- ret = dict_get_str(local->dict, "volname", &volname);
- if (ret) {
- gf_log("cli", GF_LOG_ERROR, "dict get failed");
+ gf_log(frame->this->name, GF_LOG_ERROR, XDR_DECODE_FAIL);
goto out;
}
@@ -1424,7 +1302,7 @@ gf_cli_start_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = dict_unserialize(rsp.dict.dict_val, rsp.dict.dict_len,
&rsp_dict);
if (ret) {
- gf_log("cli", GF_LOG_ERROR, "Failed rsp_dict unserialization");
+ gf_log("cli", GF_LOG_ERROR, DICT_UNSERIALIZE_FAIL);
goto out;
}
}
@@ -1432,7 +1310,13 @@ gf_cli_start_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = cli_xml_output_generic_volume("volStart", rsp_dict, rsp.op_ret,
rsp.op_errno, rsp.op_errstr);
if (ret)
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
+ goto out;
+ }
+
+ ret = dict_get_str_sizen(local->dict, "volname", &volname);
+ if (ret) {
+ gf_log("cli", GF_LOG_ERROR, "dict get failed");
goto out;
}
@@ -1447,12 +1331,14 @@ gf_cli_start_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
out:
cli_cmd_broadcast_response(ret);
- free(rsp.dict.dict_val);
- free(rsp.op_errstr);
+ gf_free_xdr_cli_rsp(rsp);
+
+ if (rsp_dict)
+ dict_unref(rsp_dict);
return ret;
}
-int
+static int
gf_cli_stop_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
@@ -1479,15 +1365,7 @@ gf_cli_stop_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
- gf_log(frame->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
- goto out;
- }
-
- ret = dict_get_str(local->dict, "volname", &volname);
- if (ret) {
- gf_log(frame->this->name, GF_LOG_ERROR,
- "Unable to get volname from dict");
+ gf_log(frame->this->name, GF_LOG_ERROR, XDR_DECODE_FAIL);
goto out;
}
@@ -1499,7 +1377,7 @@ gf_cli_stop_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = dict_unserialize(rsp.dict.dict_val, rsp.dict.dict_len,
&rsp_dict);
if (ret) {
- gf_log("cli", GF_LOG_ERROR, "Failed rsp_dict unserialization");
+ gf_log("cli", GF_LOG_ERROR, DICT_UNSERIALIZE_FAIL);
goto out;
}
}
@@ -1507,7 +1385,14 @@ gf_cli_stop_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = cli_xml_output_generic_volume("volStop", rsp_dict, rsp.op_ret,
rsp.op_errno, rsp.op_errstr);
if (ret)
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
+ goto out;
+ }
+
+ ret = dict_get_str_sizen(local->dict, "volname", &volname);
+ if (ret) {
+ gf_log(frame->this->name, GF_LOG_ERROR,
+ "Unable to get volname from dict");
goto out;
}
@@ -1522,22 +1407,24 @@ gf_cli_stop_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
out:
cli_cmd_broadcast_response(ret);
- free(rsp.op_errstr);
- free(rsp.dict.dict_val);
+ gf_free_xdr_cli_rsp(rsp);
+
+ if (rsp_dict)
+ dict_unref(rsp_dict);
return ret;
}
-int
-gf_cli_print_rebalance_status(dict_t *dict, enum gf_task_types task_type,
- gf_boolean_t is_tier)
+static int
+gf_cli_print_rebalance_status(dict_t *dict, enum gf_task_types task_type)
{
int ret = -1;
int count = 0;
int i = 1;
- char key[256] = {
+ char key[64] = {
0,
};
+ int keylen;
gf_defrag_status_t status_rcd = GF_DEFRAG_STATUS_NOT_STARTED;
uint64_t files = 0;
uint64_t size = 0;
@@ -1551,26 +1438,32 @@ gf_cli_print_rebalance_status(dict_t *dict, enum gf_task_types task_type,
int32_t hrs = 0;
uint32_t min = 0;
uint32_t sec = 0;
- gf_boolean_t down = _gf_false;
gf_boolean_t fix_layout = _gf_false;
uint64_t max_time = 0;
uint64_t max_elapsed = 0;
uint64_t time_left = 0;
gf_boolean_t show_estimates = _gf_false;
- ret = dict_get_int32(dict, "count", &count);
+ ret = dict_get_int32_sizen(dict, "count", &count);
if (ret) {
gf_log("cli", GF_LOG_ERROR, "count not set");
goto out;
}
- snprintf(key, sizeof(key), "status-1");
-
- ret = dict_get_int32(dict, key, (int32_t *)&status_rcd);
- if (ret) {
- gf_log("cli", GF_LOG_TRACE, "count %d %d", count, 1);
- gf_log("cli", GF_LOG_TRACE, "failed to get status");
- goto out;
+ for (i = 1; i <= count; i++) {
+ keylen = snprintf(key, sizeof(key), "status-%d", i);
+ ret = dict_get_int32n(dict, key, keylen, (int32_t *)&status_rcd);
+ /* If information from a node is missing we should skip
+ * the node and try to fetch information of other nodes.
+ * If information is not found for all nodes, we should
+ * error out.
+ */
+ if (!ret)
+ break;
+ if (ret && i == count) {
+ gf_log("cli", GF_LOG_TRACE, "failed to get status");
+ goto out;
+ }
}
/* Fix layout will be sent to all nodes for the volume
@@ -1609,16 +1502,13 @@ gf_cli_print_rebalance_status(dict_t *dict, enum gf_task_types task_type,
time_left = 0;
/* Check if status is NOT_STARTED, and continue early */
- snprintf(key, sizeof(key), "status-%d", i);
+ keylen = snprintf(key, sizeof(key), "status-%d", i);
- ret = dict_get_int32(dict, key, (int32_t *)&status_rcd);
+ ret = dict_get_int32n(dict, key, keylen, (int32_t *)&status_rcd);
if (ret == -ENOENT) {
gf_log("cli", GF_LOG_TRACE, "count %d %d", count, i);
gf_log("cli", GF_LOG_TRACE, "failed to get status");
- gf_log("cli", GF_LOG_ERROR,
- "node down and has failed"
- " to set dict");
- down = _gf_true;
+ gf_log("cli", GF_LOG_ERROR, "node down and has failed to set dict");
continue;
/* skip this node if value not available*/
} else if (ret) {
@@ -1634,8 +1524,8 @@ gf_cli_print_rebalance_status(dict_t *dict, enum gf_task_types task_type,
if (GF_DEFRAG_STATUS_STARTED == status_rcd)
show_estimates = _gf_true;
- snprintf(key, 256, "node-name-%d", i);
- ret = dict_get_str(dict, key, &node_name);
+ keylen = snprintf(key, sizeof(key), "node-name-%d", i);
+ ret = dict_get_strn(dict, key, keylen, &node_name);
if (ret)
gf_log("cli", GF_LOG_TRACE, "failed to get node-name");
@@ -1719,12 +1609,6 @@ gf_cli_print_rebalance_status(dict_t *dict, enum gf_task_types task_type,
}
GF_FREE(size_str);
}
- if (is_tier && down)
- cli_out(
- "WARNING: glusterd might be down on one or more nodes."
- " Please check the nodes that are down using \'gluster"
- " peer status\' and start the glusterd on those nodes,"
- " else tier detach commit might fail!");
/* Max time will be non-zero if rebalance is still running */
if (max_time) {
@@ -1765,113 +1649,7 @@ out:
return ret;
}
-int
-gf_cli_print_tier_status(dict_t *dict, enum gf_task_types task_type)
-{
- int ret = -1;
- int count = 0;
- int i = 1;
- uint64_t promoted = 0;
- uint64_t demoted = 0;
- char key[256] = {
- 0,
- };
- char *node_name = NULL;
- gf_defrag_status_t status_rcd = GF_DEFRAG_STATUS_NOT_STARTED;
- char *status_str = NULL;
- gf_boolean_t down = _gf_false;
- double elapsed = 0;
- int hrs = 0;
- int min = 0;
- int sec = 0;
-
- ret = dict_get_int32(dict, "count", &count);
- if (ret) {
- gf_log("cli", GF_LOG_ERROR, "count not set");
- goto out;
- }
-
- cli_out("%-20s %-20s %-20s %-20s %-20s", "Node", "Promoted files",
- "Demoted files", "Status", "run time in h:m:s");
- cli_out("%-20s %-20s %-20s %-20s %-20s", "---------", "---------",
- "---------", "---------", "---------");
-
- for (i = 1; i <= count; i++) {
- /* Reset the variables to prevent carryover of values */
- node_name = NULL;
- promoted = 0;
- demoted = 0;
-
- /* Check if status is NOT_STARTED, and continue early */
- snprintf(key, sizeof(key), "status-%d", i);
-
- ret = dict_get_int32(dict, key, (int32_t *)&status_rcd);
- if (ret == -ENOENT) {
- gf_log("cli", GF_LOG_TRACE,
- "count: %d, %d,"
- "failed to get status",
- count, i);
- gf_log("cli", GF_LOG_ERROR,
- "node down and has failed"
- " to set dict");
- down = _gf_true;
- continue;
- /*skipping this node as value unavailable*/
- } else if (ret) {
- gf_log("cli", GF_LOG_TRACE,
- "count: %d, %d,"
- "failed to get status",
- count, i);
- continue;
- }
-
- if (GF_DEFRAG_STATUS_NOT_STARTED == status_rcd)
- continue;
-
- snprintf(key, sizeof(key), "node-name-%d", i);
- ret = dict_get_str(dict, key, &node_name);
- if (ret)
- gf_log("cli", GF_LOG_TRACE, "failed to get node-name");
-
- snprintf(key, sizeof(key), "promoted-%d", i);
- ret = dict_get_uint64(dict, key, &promoted);
- if (ret)
- gf_log("cli", GF_LOG_TRACE, "failed to get promoted count");
-
- snprintf(key, sizeof(key), "demoted-%d", i);
- ret = dict_get_uint64(dict, key, &demoted);
- if (ret)
- gf_log("cli", GF_LOG_TRACE, "failed to get demoted count");
-
- snprintf(key, sizeof(key), "run-time-%d", i);
- ret = dict_get_double(dict, key, &elapsed);
- if (ret)
- gf_log("cli", GF_LOG_TRACE, "failed to get run-time");
-
- /* Check for array bound */
- if (status_rcd >= GF_DEFRAG_STATUS_MAX)
- status_rcd = GF_DEFRAG_STATUS_MAX;
-
- hrs = elapsed / 3600;
- min = ((int)elapsed % 3600) / 60;
- sec = ((int)elapsed % 3600) % 60;
-
- status_str = cli_vol_task_status_str[status_rcd];
- cli_out("%-20s %-20" PRIu64 " %-20" PRIu64
- " %-20s"
- " %d:%d:%d",
- node_name, promoted, demoted, status_str, hrs, min, sec);
- }
- if (down)
- cli_out(
- "WARNING: glusterd might be down on one or more nodes."
- " Please check the nodes that are down using \'gluster"
- " peer status\' and start the glusterd on those nodes.");
-out:
- return ret;
-}
-
-int
+static int
gf_cli_defrag_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
@@ -1903,18 +1681,18 @@ gf_cli_defrag_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
- gf_log(frame->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ gf_log(frame->this->name, GF_LOG_ERROR, XDR_DECODE_FAIL);
goto out;
}
- ret = dict_get_str(local->dict, "volname", &volname);
+ ret = dict_get_str_sizen(local->dict, "volname", &volname);
if (ret) {
gf_log(frame->this->name, GF_LOG_ERROR, "Failed to get volname");
goto out;
}
- ret = dict_get_int32(local->dict, "rebalance-command", (int32_t *)&cmd);
+ ret = dict_get_int32_sizen(local->dict, "rebalance-command",
+ (int32_t *)&cmd);
if (ret) {
gf_log("cli", GF_LOG_ERROR, "Failed to get command");
goto out;
@@ -1926,21 +1704,17 @@ gf_cli_defrag_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = dict_unserialize(rsp.dict.dict_val, rsp.dict.dict_len, &dict);
if (ret < 0) {
- gf_log("glusterd", GF_LOG_ERROR,
- "failed to "
- "unserialize req-buffer to dictionary");
+ gf_log("glusterd", GF_LOG_ERROR, DICT_UNSERIALIZE_FAIL);
goto out;
}
}
- if (!((cmd == GF_DEFRAG_CMD_STOP) || (cmd == GF_DEFRAG_CMD_STATUS) ||
- (cmd == GF_DEFRAG_CMD_STATUS_TIER)) &&
+ if (!((cmd == GF_DEFRAG_CMD_STOP) || (cmd == GF_DEFRAG_CMD_STATUS)) &&
!(global_state->mode & GLUSTER_MODE_XML)) {
- ret = dict_get_str(dict, GF_REBALANCE_TID_KEY, &task_id_str);
+ ret = dict_get_str_sizen(dict, GF_REBALANCE_TID_KEY, &task_id_str);
if (ret) {
gf_log("cli", GF_LOG_WARNING, "failed to get %s from dict",
GF_REBALANCE_TID_KEY);
- goto out;
}
if (rsp.op_ret && strcmp(rsp.op_errstr, "")) {
snprintf(msg, sizeof(msg), "%s", rsp.op_errstr);
@@ -1950,26 +1724,13 @@ gf_cli_defrag_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
* case since unlock failures can be highlighted
* event though rebalance command was successful
*/
- if (cmd == GF_DEFRAG_CMD_START_TIER) {
- snprintf(msg, sizeof(msg),
- "Tier "
- "start is successful on %s.",
- volname);
- } else if (cmd == GF_DEFRAG_CMD_STOP_TIER) {
- snprintf(msg, sizeof(msg),
- "Tier "
- "daemon stopped "
- "on %s.",
- volname);
- } else {
- snprintf(msg, sizeof(msg),
- "Rebalance on %s has been "
- "started successfully. Use "
- "rebalance status command to"
- " check status of the "
- "rebalance process.\nID: %s",
- volname, task_id_str);
- }
+ snprintf(msg, sizeof(msg),
+ "Rebalance on %s has been "
+ "started successfully. Use "
+ "rebalance status command to"
+ " check status of the "
+ "rebalance process.\nID: %s",
+ volname, task_id_str);
} else {
snprintf(msg, sizeof(msg),
"Starting rebalance on volume %s has "
@@ -2002,14 +1763,13 @@ gf_cli_defrag_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
rsp.op_errstr);
}
}
- if (cmd == GF_DEFRAG_CMD_STATUS || cmd == GF_DEFRAG_CMD_STATUS_TIER) {
+ if (cmd == GF_DEFRAG_CMD_STATUS) {
if (rsp.op_ret == -1) {
if (strcmp(rsp.op_errstr, ""))
snprintf(msg, sizeof(msg), "%s", rsp.op_errstr);
else
snprintf(msg, sizeof(msg),
- "Failed to get the status of "
- "rebalance process");
+ "Failed to get the status of rebalance process");
goto done;
} else {
snprintf(msg, sizeof(msg), "%s", rsp.op_errstr);
@@ -2022,15 +1782,7 @@ gf_cli_defrag_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
goto out;
}
- if (cmd == GF_DEFRAG_CMD_STATUS_TIER)
- ret = gf_cli_print_tier_status(dict, GF_TASK_TYPE_REBALANCE);
- else if (cmd == GF_DEFRAG_CMD_DETACH_STATUS)
- ret = gf_cli_print_rebalance_status(dict, GF_TASK_TYPE_REBALANCE,
- _gf_true);
- else
- ret = gf_cli_print_rebalance_status(dict, GF_TASK_TYPE_REBALANCE,
- _gf_false);
-
+ ret = gf_cli_print_rebalance_status(dict, GF_TASK_TYPE_REBALANCE);
if (ret)
gf_log("cli", GF_LOG_ERROR, "Failed to print rebalance status");
@@ -2040,38 +1792,23 @@ done:
rsp.op_errstr);
else {
if (rsp.op_ret)
-
- if (cmd == GF_DEFRAG_CMD_START_TIER ||
- cmd == GF_DEFRAG_CMD_STATUS_TIER) {
- cli_err(
- "Tiering Migration Functionality: %s:"
- " failed%s%s",
- volname, strlen(msg) ? ": " : "", msg);
- } else
- cli_err("volume rebalance: %s: failed%s%s", volname,
- strlen(msg) ? ": " : "", msg);
- else if (cmd == GF_DEFRAG_CMD_START_TIER ||
- cmd == GF_DEFRAG_CMD_STATUS_TIER) {
- cli_out(
- "Tiering Migration Functionality: %s:"
- " success%s%s",
- volname, strlen(msg) ? ": " : "", msg);
- } else
+ cli_err("volume rebalance: %s: failed%s%s", volname,
+ strlen(msg) ? ": " : "", msg);
+ else
cli_out("volume rebalance: %s: success%s%s", volname,
strlen(msg) ? ": " : "", msg);
}
ret = rsp.op_ret;
out:
- free(rsp.op_errstr); // malloced by xdr
- free(rsp.dict.dict_val); // malloced by xdr
+ gf_free_xdr_cli_rsp(rsp);
if (dict)
dict_unref(dict);
cli_cmd_broadcast_response(ret);
return ret;
}
-int
+static int
gf_cli_rename_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
@@ -2092,7 +1829,7 @@ gf_cli_rename_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ XDR_DECODE_FAIL);
goto out;
}
@@ -2104,7 +1841,7 @@ gf_cli_rename_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = cli_xml_output_str("volRename", msg, rsp.op_ret, rsp.op_errno,
rsp.op_errstr);
if (ret)
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
goto out;
}
@@ -2117,10 +1854,11 @@ gf_cli_rename_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
out:
cli_cmd_broadcast_response(ret);
+ gf_free_xdr_cli_rsp(rsp);
return ret;
}
-int
+static int
gf_cli_reset_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
@@ -2141,7 +1879,7 @@ gf_cli_reset_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ XDR_DECODE_FAIL);
goto out;
}
@@ -2157,7 +1895,7 @@ gf_cli_reset_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = cli_xml_output_str("volReset", msg, rsp.op_ret, rsp.op_errno,
rsp.op_errstr);
if (ret)
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
goto out;
}
@@ -2170,10 +1908,67 @@ gf_cli_reset_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
out:
cli_cmd_broadcast_response(ret);
+ gf_free_xdr_cli_rsp(rsp);
+ return ret;
+}
+
+static int
+gf_cli_ganesha_cbk(struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ gf_cli_rsp rsp = {
+ 0,
+ };
+ int ret = -1;
+ dict_t *dict = NULL;
+
+ GF_ASSERT(myframe);
+
+ if (-1 == req->rpc_status) {
+ goto out;
+ }
+
+ ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
+ if (ret < 0) {
+ gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
+ XDR_DECODE_FAIL);
+ goto out;
+ }
+
+ gf_log("cli", GF_LOG_DEBUG, "Received resp to ganesha");
+
+ dict = dict_new();
+
+ if (!dict) {
+ ret = -1;
+ goto out;
+ }
+
+ ret = dict_unserialize(rsp.dict.dict_val, rsp.dict.dict_len, &dict);
+ if (ret)
+ goto out;
+
+ if (rsp.op_ret) {
+ if (strcmp(rsp.op_errstr, ""))
+ cli_err("nfs-ganesha: failed: %s", rsp.op_errstr);
+ else
+ cli_err("nfs-ganesha: failed");
+ }
+
+ else {
+ cli_out("nfs-ganesha : success ");
+ }
+
+ ret = rsp.op_ret;
+
+out:
+ if (dict)
+ dict_unref(dict);
+ cli_cmd_broadcast_response(ret);
return ret;
}
-char *
+static char *
is_server_debug_xlator(void *myframe)
{
call_frame_t *frame = NULL;
@@ -2218,7 +2013,7 @@ is_server_debug_xlator(void *myframe)
return debug_xlator;
}
-int
+static int
gf_cli_set_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
@@ -2245,7 +2040,7 @@ gf_cli_set_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ XDR_DECODE_FAIL);
goto out;
}
@@ -2260,8 +2055,7 @@ gf_cli_set_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = dict_unserialize(rsp.dict.dict_val, rsp.dict.dict_len, &dict);
if (ret) {
- gf_log("cli", GF_LOG_ERROR,
- "failed to unserialize volume set respone dict");
+ gf_log("cli", GF_LOG_ERROR, DICT_UNSERIALIZE_FAIL);
goto out;
}
@@ -2272,7 +2066,7 @@ gf_cli_set_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
*/
debug_xlator = is_server_debug_xlator(myframe);
- if (dict_get_str(dict, "help-str", &help_str) && !msg[0])
+ if (dict_get_str_sizen(dict, "help-str", &help_str) && !msg[0])
snprintf(msg, sizeof(msg), "Set volume %s",
(rsp.op_ret) ? "unsuccessful" : "successful");
if (rsp.op_ret == 0 && debug_xlator) {
@@ -2287,7 +2081,7 @@ gf_cli_set_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = cli_xml_output_str("volSet", msg, rsp.op_ret, rsp.op_errno,
rsp.op_errstr);
if (ret)
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
goto out;
}
@@ -2314,409 +2108,7 @@ out:
dict_unref(dict);
GF_FREE(debug_xlator);
cli_cmd_broadcast_response(ret);
- return ret;
-}
-
-int
-gf_cli_add_tier_brick_cbk(struct rpc_req *req, struct iovec *iov, int count,
- void *myframe)
-{
- gf_cli_rsp rsp = {
- 0,
- };
- int ret = -1;
- char msg[1024] = {
- 0,
- };
-
- GF_VALIDATE_OR_GOTO("cli", myframe, out);
-
- if (-1 == req->rpc_status) {
- goto out;
- }
-
- ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
- if (ret < 0) {
- gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
- goto out;
- }
-
- gf_log("cli", GF_LOG_INFO, "Received resp to attach tier");
-
- if (rsp.op_ret && strcmp(rsp.op_errstr, ""))
- snprintf(msg, sizeof(msg), "%s", rsp.op_errstr);
- else
- snprintf(msg, sizeof(msg), "Attach tier %s",
- (rsp.op_ret) ? "unsuccessful" : "successful");
-
- if (global_state->mode & GLUSTER_MODE_XML) {
- ret = cli_xml_output_str("volAttachTier", msg, rsp.op_ret, rsp.op_errno,
- rsp.op_errstr);
- if (ret)
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
- goto out;
- }
-
- if (rsp.op_ret)
- cli_err("volume attach-tier: failed: %s", msg);
- else
- cli_out("volume attach-tier: success");
- ret = rsp.op_ret;
-
-out:
- cli_cmd_broadcast_response(ret);
- free(rsp.dict.dict_val);
- free(rsp.op_errstr);
- return ret;
-}
-
-int
-gf_cli_attach_tier_cbk(struct rpc_req *req, struct iovec *iov, int count,
- void *myframe)
-{
- gf_cli_rsp rsp = {
- 0,
- };
- int ret = -1;
- char msg[1024] = {
- 0,
- };
-
- GF_VALIDATE_OR_GOTO("cli", myframe, out);
-
- if (-1 == req->rpc_status) {
- goto out;
- }
-
- ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
- if (ret < 0) {
- gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
- goto out;
- }
-
- gf_log("cli", GF_LOG_INFO, "Received resp to attach tier");
-
- if (rsp.op_ret && strcmp(rsp.op_errstr, ""))
- snprintf(msg, sizeof(msg), "%s", rsp.op_errstr);
- else
- snprintf(msg, sizeof(msg), "Attach tier %s",
- (rsp.op_ret) ? "unsuccessful" : "successful");
-
- if (global_state->mode & GLUSTER_MODE_XML) {
- ret = cli_xml_output_str("volAttachTier", msg, rsp.op_ret, rsp.op_errno,
- rsp.op_errstr);
- if (ret)
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
- goto out;
- }
-
- if (rsp.op_ret)
- cli_err("volume attach-tier: failed: %s", msg);
- else
- cli_out("volume attach-tier: success");
- ret = rsp.op_ret;
-
-out:
- cli_cmd_broadcast_response(ret);
- free(rsp.dict.dict_val);
- free(rsp.op_errstr);
- return ret;
-}
-
-int
-gf_cli_remove_tier_brick_cbk(struct rpc_req *req, struct iovec *iov, int count,
- void *myframe)
-{
- gf_cli_rsp rsp = {
- 0,
- };
- int ret = -1;
- char msg[1024] = {
- 0,
- };
- char *cmd_str = "unknown";
- cli_local_t *local = NULL;
- call_frame_t *frame = NULL;
- char *task_id_str = NULL;
- dict_t *rsp_dict = NULL;
- int32_t command = 0;
-
- GF_ASSERT(myframe);
-
- if (-1 == req->rpc_status) {
- goto out;
- }
-
- frame = myframe;
-
- GF_ASSERT(frame->local);
-
- local = frame->local;
-
- ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
- if (ret < 0) {
- gf_log(frame->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
- goto out;
- }
-
- ret = dict_get_int32(local->dict, "command", &command);
- if (ret) {
- gf_log("", GF_LOG_ERROR, "failed to get command");
- goto out;
- }
-
- if (rsp.dict.dict_len) {
- rsp_dict = dict_new();
- if (!rsp_dict) {
- ret = -1;
- goto out;
- }
-
- ret = dict_unserialize(rsp.dict.dict_val, rsp.dict.dict_len, &rsp_dict);
- if (ret) {
- gf_log("cli", GF_LOG_ERROR, "Failed to unserialize rsp_dict");
- goto out;
- }
- }
-
- switch (command) {
- case GF_DEFRAG_CMD_DETACH_START:
- cmd_str = "start";
-
- ret = dict_get_str(rsp_dict, GF_REMOVE_BRICK_TID_KEY, &task_id_str);
- if (ret) {
- gf_log("cli", GF_LOG_ERROR,
- "remove-brick-id is not present in dict");
- }
- break;
- case GF_DEFRAG_CMD_DETACH_COMMIT:
- cmd_str = "commit";
- break;
- case GF_DEFRAG_CMD_DETACH_COMMIT_FORCE:
- cmd_str = "commit force";
- break;
- case GF_DEFRAG_CMD_DETACH_STOP:
- cmd_str = "stop";
- break;
- case GF_DEFRAG_CMD_DETACH_STATUS:
- cmd_str = "status";
- break;
-
- default:
- cmd_str = "unknown";
- break;
- }
-
- gf_log("cli", GF_LOG_INFO, "Received resp to detach tier");
-
- if (rsp.op_ret && strcmp(rsp.op_errstr, ""))
- snprintf(msg, sizeof(msg), "%s", rsp.op_errstr);
- else
- snprintf(msg, sizeof(msg), "Detach tier %s %s", cmd_str,
- (rsp.op_ret) ? "unsuccessful" : "successful");
-
- ret = rsp.op_ret;
- if (global_state->mode & GLUSTER_MODE_XML) {
- ret = cli_xml_output_vol_remove_brick_detach_tier(
- _gf_true, rsp_dict, rsp.op_ret, rsp.op_errno, msg, "volDetachTier");
-
- if (ret)
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
- goto out;
- } else {
- if (rsp.op_ret) {
- if (strcmp(rsp.op_errstr, ""))
- snprintf(msg, sizeof(msg),
- "volume tier "
- "detach %s: failed: %s",
- cmd_str, rsp.op_errstr);
- else
- snprintf(msg, sizeof(msg),
- "volume tier "
- "detach %s: failed",
- cmd_str);
-
- cli_err("%s", msg);
- goto out;
-
- } else {
- cli_out("volume detach tier %s: success", cmd_str);
- if (GF_DEFRAG_CMD_DETACH_START == command && task_id_str != NULL)
- cli_out("ID: %s", task_id_str);
- if (GF_DEFRAG_CMD_DETACH_COMMIT == command)
- cli_out(
- "Check the detached bricks to ensure "
- "all files are migrated.\nIf files "
- "with data are found on the brick "
- "path, copy them via a gluster mount "
- "point before re-purposing the "
- "removed brick. ");
- }
- }
- if (command == GF_DEFRAG_CMD_DETACH_STOP ||
- command == GF_DEFRAG_CMD_DETACH_STATUS)
- ret = gf_cli_print_rebalance_status(rsp_dict, GF_TASK_TYPE_REMOVE_BRICK,
- _gf_true);
- if (ret) {
- gf_log("cli", GF_LOG_ERROR,
- "Failed to print remove-brick "
- "rebalance status");
- goto out;
- }
-
- if ((command == GF_DEFRAG_CMD_DETACH_STOP) && (rsp.op_ret == 0)) {
- cli_out(
- "'detach tier' process may be in the middle of a "
- "file migration.\nThe process will be fully stopped "
- "once the migration of the file is complete.\nPlease "
- "check detach tier process for completion before "
- "doing any further brick related tasks on the "
- "volume.");
- }
- ret = rsp.op_ret;
-
-out:
- cli_cmd_broadcast_response(ret);
- free(rsp.dict.dict_val);
- free(rsp.op_errstr);
-
- return ret;
-}
-
-int
-gf_cli_detach_tier_status_cbk(struct rpc_req *req, struct iovec *iov, int count,
- void *myframe)
-{
- gf_cli_rsp rsp = {
- 0,
- };
- int ret = -1;
- dict_t *dict = NULL;
- char msg[1024] = {
- 0,
- };
- int32_t command = 0;
- gf1_op_commands cmd = GF_OP_CMD_NONE;
- cli_local_t *local = NULL;
- call_frame_t *frame = NULL;
- char *cmd_str = "unknown";
-
- GF_ASSERT(myframe);
-
- if (-1 == req->rpc_status) {
- goto out;
- }
-
- frame = myframe;
-
- GF_ASSERT(frame->local);
-
- local = frame->local;
-
- ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
- if (ret < 0) {
- gf_log(frame->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
- goto out;
- }
-
- ret = dict_get_int32(local->dict, "command", &command);
- if (ret)
- goto out;
-
- cmd = command;
-
- switch (cmd) {
- case GF_OP_CMD_STOP_DETACH_TIER:
- cmd_str = "stop";
- break;
- case GF_OP_CMD_STATUS:
- cmd_str = "status";
- break;
- default:
- break;
- }
-
- ret = rsp.op_ret;
- if (rsp.op_ret == -1) {
- if (strcmp(rsp.op_errstr, ""))
- snprintf(msg, sizeof(msg),
- "volume tier detach %s: "
- "failed: %s",
- cmd_str, rsp.op_errstr);
- else
- snprintf(msg, sizeof(msg),
- "volume tier detach %s: "
- "failed",
- cmd_str);
-
- if (global_state->mode & GLUSTER_MODE_XML)
- goto xml_output;
-
- cli_err("%s", msg);
- goto out;
- }
-
- if (rsp.dict.dict_len) {
- /* Unserialize the dictionary */
- dict = dict_new();
-
- ret = dict_unserialize(rsp.dict.dict_val, rsp.dict.dict_len, &dict);
- if (ret < 0) {
- strncpy(msg,
- "failed to unserialize req-buffer to "
- "dictionary",
- sizeof(msg));
-
- if (global_state->mode & GLUSTER_MODE_XML) {
- rsp.op_ret = -1;
- goto xml_output;
- }
-
- gf_log("cli", GF_LOG_ERROR, "%s", msg);
- goto out;
- }
- }
-xml_output:
- if (global_state->mode & GLUSTER_MODE_XML) {
- if (strcmp(rsp.op_errstr, "")) {
- ret = cli_xml_output_vol_remove_brick_detach_tier(
- _gf_true, dict, rsp.op_ret, rsp.op_errno, rsp.op_errstr,
- "volDetachTier");
- } else {
- ret = cli_xml_output_vol_remove_brick_detach_tier(
- _gf_true, dict, rsp.op_ret, rsp.op_errno, msg, "volDetachTier");
- }
- goto out;
- }
-
- ret = gf_cli_print_rebalance_status(dict, GF_TASK_TYPE_REMOVE_BRICK,
- _gf_true);
- if (ret) {
- gf_log("cli", GF_LOG_ERROR,
- "Failed to print remove-brick "
- "rebalance status");
- goto out;
- }
-
- if ((cmd == GF_OP_CMD_STOP_DETACH_TIER) && (rsp.op_ret == 0)) {
- cli_out(
- "'detach tier' process may be in the middle of a "
- "file migration.\nThe process will be fully stopped "
- "once the migration of the file is complete.\nPlease "
- "check detach tier process for completion before "
- "doing any further brick related tasks on the "
- "volume.");
- }
-
-out:
- free(rsp.dict.dict_val); /* malloced by xdr */
- if (dict)
- dict_unref(dict);
- cli_cmd_broadcast_response(ret);
+ gf_free_xdr_cli_rsp(rsp);
return ret;
}
@@ -2741,7 +2133,7 @@ gf_cli_add_brick_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ XDR_DECODE_FAIL);
goto out;
}
@@ -2757,7 +2149,7 @@ gf_cli_add_brick_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = cli_xml_output_str("volAddBrick", msg, rsp.op_ret, rsp.op_errno,
rsp.op_errstr);
if (ret)
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
goto out;
}
@@ -2769,12 +2161,11 @@ gf_cli_add_brick_cbk(struct rpc_req *req, struct iovec *iov, int count,
out:
cli_cmd_broadcast_response(ret);
- free(rsp.dict.dict_val);
- free(rsp.op_errstr);
+ gf_free_xdr_cli_rsp(rsp);
return ret;
}
-int
+static int
gf_cli3_remove_brick_status_cbk(struct rpc_req *req, struct iovec *iov,
int count, void *myframe)
{
@@ -2790,7 +2181,7 @@ gf_cli3_remove_brick_status_cbk(struct rpc_req *req, struct iovec *iov,
gf1_op_commands cmd = GF_OP_CMD_NONE;
cli_local_t *local = NULL;
call_frame_t *frame = NULL;
- char *cmd_str = "unknown";
+ const char *cmd_str;
GF_ASSERT(myframe);
@@ -2806,12 +2197,11 @@ gf_cli3_remove_brick_status_cbk(struct rpc_req *req, struct iovec *iov,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
- gf_log(frame->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ gf_log(frame->this->name, GF_LOG_ERROR, XDR_DECODE_FAIL);
goto out;
}
- ret = dict_get_int32(local->dict, "command", &command);
+ ret = dict_get_int32_sizen(local->dict, "command", &command);
if (ret)
goto out;
@@ -2825,20 +2215,17 @@ gf_cli3_remove_brick_status_cbk(struct rpc_req *req, struct iovec *iov,
cmd_str = "status";
break;
default:
+ cmd_str = "unknown";
break;
}
ret = rsp.op_ret;
if (rsp.op_ret == -1) {
if (strcmp(rsp.op_errstr, ""))
- snprintf(msg, sizeof(msg),
- "volume remove-brick %s: "
- "failed: %s",
+ snprintf(msg, sizeof(msg), "volume remove-brick %s: failed: %s",
cmd_str, rsp.op_errstr);
else
- snprintf(msg, sizeof(msg),
- "volume remove-brick %s: "
- "failed",
+ snprintf(msg, sizeof(msg), "volume remove-brick %s: failed",
cmd_str);
if (global_state->mode & GLUSTER_MODE_XML)
@@ -2854,10 +2241,7 @@ gf_cli3_remove_brick_status_cbk(struct rpc_req *req, struct iovec *iov,
ret = dict_unserialize(rsp.dict.dict_val, rsp.dict.dict_len, &dict);
if (ret < 0) {
- strncpy(msg,
- "failed to unserialize req-buffer to "
- "dictionary",
- sizeof(msg));
+ strncpy(msg, DICT_UNSERIALIZE_FAIL, sizeof(msg));
if (global_state->mode & GLUSTER_MODE_XML) {
rsp.op_ret = -1;
@@ -2872,23 +2256,21 @@ gf_cli3_remove_brick_status_cbk(struct rpc_req *req, struct iovec *iov,
xml_output:
if (global_state->mode & GLUSTER_MODE_XML) {
if (strcmp(rsp.op_errstr, "")) {
- ret = cli_xml_output_vol_remove_brick_detach_tier(
- _gf_true, dict, rsp.op_ret, rsp.op_errno, rsp.op_errstr,
- "volRemoveBrick");
+ ret = cli_xml_output_vol_remove_brick(_gf_true, dict, rsp.op_ret,
+ rsp.op_errno, rsp.op_errstr,
+ "volRemoveBrick");
} else {
- ret = cli_xml_output_vol_remove_brick_detach_tier(
- _gf_true, dict, rsp.op_ret, rsp.op_errno, msg,
- "volRemoveBrick");
+ ret = cli_xml_output_vol_remove_brick(_gf_true, dict, rsp.op_ret,
+ rsp.op_errno, msg,
+ "volRemoveBrick");
}
goto out;
}
- ret = gf_cli_print_rebalance_status(dict, GF_TASK_TYPE_REMOVE_BRICK,
- _gf_false);
+ ret = gf_cli_print_rebalance_status(dict, GF_TASK_TYPE_REMOVE_BRICK);
if (ret) {
gf_log("cli", GF_LOG_ERROR,
- "Failed to print remove-brick "
- "rebalance status");
+ "Failed to print remove-brick rebalance status");
goto out;
}
@@ -2903,14 +2285,14 @@ xml_output:
}
out:
- free(rsp.dict.dict_val); // malloced by xdr
if (dict)
dict_unref(dict);
cli_cmd_broadcast_response(ret);
+ gf_free_xdr_cli_rsp(rsp);
return ret;
}
-int
+static int
gf_cli_remove_brick_cbk(struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
@@ -2942,12 +2324,11 @@ gf_cli_remove_brick_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
- gf_log(frame->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ gf_log(frame->this->name, GF_LOG_ERROR, XDR_DECODE_FAIL);
goto out;
}
- ret = dict_get_int32(local->dict, "command", (int32_t *)&cmd);
+ ret = dict_get_int32_sizen(local->dict, "command", (int32_t *)&cmd);
if (ret) {
gf_log("", GF_LOG_ERROR, "failed to get command");
goto out;
@@ -2962,7 +2343,7 @@ gf_cli_remove_brick_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = dict_unserialize(rsp.dict.dict_val, rsp.dict.dict_len, &rsp_dict);
if (ret) {
- gf_log("cli", GF_LOG_ERROR, "Failed to unserialize rsp_dict");
+ gf_log("cli", GF_LOG_ERROR, DICT_UNSERIALIZE_FAIL);
goto out;
}
}
@@ -2972,7 +2353,8 @@ gf_cli_remove_brick_cbk(struct rpc_req *req, struct iovec *iov, int count,
case GF_OP_CMD_START:
cmd_str = "start";
- ret = dict_get_str(rsp_dict, GF_REMOVE_BRICK_TID_KEY, &task_id_str);
+ ret = dict_get_str_sizen(rsp_dict, GF_REMOVE_BRICK_TID_KEY,
+ &task_id_str);
if (ret) {
gf_log("cli", GF_LOG_ERROR,
"remove-brick-id is not present in dict");
@@ -2998,11 +2380,11 @@ gf_cli_remove_brick_cbk(struct rpc_req *req, struct iovec *iov, int count,
(rsp.op_ret) ? "unsuccessful" : "successful");
if (global_state->mode & GLUSTER_MODE_XML) {
- ret = cli_xml_output_vol_remove_brick_detach_tier(
- _gf_false, rsp_dict, rsp.op_ret, rsp.op_errno, msg,
- "volRemoveBrick");
+ ret = cli_xml_output_vol_remove_brick(_gf_false, rsp_dict, rsp.op_ret,
+ rsp.op_errno, msg,
+ "volRemoveBrick");
if (ret)
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
goto out;
}
@@ -3025,13 +2407,15 @@ gf_cli_remove_brick_cbk(struct rpc_req *req, struct iovec *iov, int count,
out:
cli_cmd_broadcast_response(ret);
- free(rsp.dict.dict_val);
- free(rsp.op_errstr);
+ gf_free_xdr_cli_rsp(rsp);
+
+ if (rsp_dict)
+ dict_unref(rsp_dict);
return ret;
}
-int
+static int
gf_cli_reset_brick_cbk(struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
@@ -3041,7 +2425,7 @@ gf_cli_reset_brick_cbk(struct rpc_req *req, struct iovec *iov, int count,
int ret = -1;
cli_local_t *local = NULL;
call_frame_t *frame = NULL;
- char *rb_operation_str = NULL;
+ const char *rb_operation_str = NULL;
dict_t *rsp_dict = NULL;
char msg[1024] = {
0,
@@ -3062,80 +2446,53 @@ gf_cli_reset_brick_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
- gf_log(frame->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ gf_log(frame->this->name, GF_LOG_ERROR, XDR_DECODE_FAIL);
goto out;
}
- ret = dict_get_str(local->dict, "operation", &reset_op);
+ ret = dict_get_str_sizen(local->dict, "operation", &reset_op);
if (ret) {
gf_log(frame->this->name, GF_LOG_ERROR, "dict_get on operation failed");
goto out;
}
+ if (strcmp(reset_op, "GF_RESET_OP_START") &&
+ strcmp(reset_op, "GF_RESET_OP_COMMIT") &&
+ strcmp(reset_op, "GF_RESET_OP_COMMIT_FORCE")) {
+ ret = -1;
+ goto out;
+ }
+
if (rsp.dict.dict_len) {
/* Unserialize the dictionary */
rsp_dict = dict_new();
ret = dict_unserialize(rsp.dict.dict_val, rsp.dict.dict_len, &rsp_dict);
if (ret < 0) {
- gf_log(frame->this->name, GF_LOG_ERROR,
- "failed to "
- "unserialize rsp buffer to dictionary");
+ gf_log(frame->this->name, GF_LOG_ERROR, DICT_UNSERIALIZE_FAIL);
goto out;
}
}
- if (strcmp(reset_op, "GF_RESET_OP_START") &&
- strcmp(reset_op, "GF_RESET_OP_COMMIT") &&
- strcmp(reset_op, "GF_RESET_OP_COMMIT_FORCE")) {
- rb_operation_str = gf_strdup("Unknown operation");
- ret = -1;
- goto out;
- }
-
if (rsp.op_ret && (strcmp(rsp.op_errstr, ""))) {
- rb_operation_str = gf_strdup(rsp.op_errstr);
+ rb_operation_str = rsp.op_errstr;
} else {
if (!strcmp(reset_op, "GF_RESET_OP_START")) {
if (rsp.op_ret)
- rb_operation_str = gf_strdup(
- "reset-brick "
- "start "
- "operation "
- "failed");
+ rb_operation_str = "reset-brick start operation failed";
else
- rb_operation_str = gf_strdup(
- "reset-brick "
- "start "
- "operation "
- "successful");
+ rb_operation_str = "reset-brick start operation successful";
} else if (!strcmp(reset_op, "GF_RESET_OP_COMMIT")) {
if (rsp.op_ret)
- rb_operation_str = gf_strdup(
- "reset-brick "
- "commit "
- "operation "
- "failed");
+ rb_operation_str = "reset-brick commit operation failed";
else
- rb_operation_str = gf_strdup(
- "reset-brick "
- "commit "
- "operation "
- "successful");
+ rb_operation_str = "reset-brick commit operation successful";
} else if (!strcmp(reset_op, "GF_RESET_OP_COMMIT_FORCE")) {
if (rsp.op_ret)
- rb_operation_str = gf_strdup(
- "reset-brick "
- "commit "
- "force operation "
- "failed");
+ rb_operation_str = "reset-brick commit force operation failed";
else
- rb_operation_str = gf_strdup(
- "reset-brick "
- "commit "
- "force operation "
- "successful");
+ rb_operation_str =
+ "reset-brick commit force operation successful";
}
}
@@ -3147,7 +2504,7 @@ gf_cli_reset_brick_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = cli_xml_output_vol_replace_brick(rsp_dict, rsp.op_ret,
rsp.op_errno, msg);
if (ret)
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
goto out;
}
@@ -3164,17 +2521,14 @@ out:
if (local)
cli_local_wipe(local);
- if (rb_operation_str)
- GF_FREE(rb_operation_str);
-
cli_cmd_broadcast_response(ret);
- free(rsp.dict.dict_val);
+ gf_free_xdr_cli_rsp(rsp);
if (rsp_dict)
dict_unref(rsp_dict);
return ret;
}
-int
+static int
gf_cli_replace_brick_cbk(struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
@@ -3184,7 +2538,7 @@ gf_cli_replace_brick_cbk(struct rpc_req *req, struct iovec *iov, int count,
int ret = -1;
cli_local_t *local = NULL;
call_frame_t *frame = NULL;
- char *rb_operation_str = NULL;
+ const char *rb_operation_str = NULL;
dict_t *rsp_dict = NULL;
char msg[1024] = {
0,
@@ -3205,12 +2559,11 @@ gf_cli_replace_brick_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
- gf_log(frame->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ gf_log(frame->this->name, GF_LOG_ERROR, XDR_DECODE_FAIL);
goto out;
}
- ret = dict_get_str(local->dict, "operation", &replace_op);
+ ret = dict_get_str_sizen(local->dict, "operation", &replace_op);
if (ret) {
gf_log(frame->this->name, GF_LOG_ERROR, "dict_get on operation failed");
goto out;
@@ -3222,29 +2575,23 @@ gf_cli_replace_brick_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = dict_unserialize(rsp.dict.dict_val, rsp.dict.dict_len, &rsp_dict);
if (ret < 0) {
- gf_log(frame->this->name, GF_LOG_ERROR,
- "failed to "
- "unserialize rsp buffer to dictionary");
+ gf_log(frame->this->name, GF_LOG_ERROR, DICT_UNSERIALIZE_FAIL);
goto out;
}
}
if (!strcmp(replace_op, "GF_REPLACE_OP_COMMIT_FORCE")) {
if (rsp.op_ret || ret)
- rb_operation_str = gf_strdup(
- "replace-brick commit "
- "force operation failed");
+ rb_operation_str = "replace-brick commit force operation failed";
else
- rb_operation_str = gf_strdup(
- "replace-brick commit "
- "force operation "
- "successful");
+ rb_operation_str =
+ "replace-brick commit force operation successful";
} else {
gf_log(frame->this->name, GF_LOG_DEBUG, "Unknown operation");
}
if (rsp.op_ret && (strcmp(rsp.op_errstr, ""))) {
- rb_operation_str = gf_strdup(rsp.op_errstr);
+ rb_operation_str = rsp.op_errstr;
}
gf_log("cli", GF_LOG_INFO, "Received resp to replace brick");
@@ -3255,7 +2602,7 @@ gf_cli_replace_brick_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = cli_xml_output_vol_replace_brick(rsp_dict, rsp.op_ret,
rsp.op_errno, msg);
if (ret)
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
goto out;
}
@@ -3272,11 +2619,8 @@ out:
if (local)
cli_local_wipe(local);
- if (rb_operation_str)
- GF_FREE(rb_operation_str);
-
cli_cmd_broadcast_response(ret);
- free(rsp.dict.dict_val);
+ gf_free_xdr_cli_rsp(rsp);
if (rsp_dict)
dict_unref(rsp_dict);
@@ -3304,7 +2648,7 @@ gf_cli_log_rotate_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ XDR_DECODE_FAIL);
goto out;
}
@@ -3320,7 +2664,7 @@ gf_cli_log_rotate_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = cli_xml_output_str("volLogRotate", msg, rsp.op_ret, rsp.op_errno,
rsp.op_errstr);
if (ret)
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
goto out;
}
@@ -3332,7 +2676,7 @@ gf_cli_log_rotate_cbk(struct rpc_req *req, struct iovec *iov, int count,
out:
cli_cmd_broadcast_response(ret);
- free(rsp.dict.dict_val);
+ gf_free_xdr_cli_rsp(rsp);
return ret;
}
@@ -3358,7 +2702,7 @@ gf_cli_sync_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ XDR_DECODE_FAIL);
goto out;
}
@@ -3374,7 +2718,7 @@ gf_cli_sync_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = cli_xml_output_str("volSync", msg, rsp.op_ret, rsp.op_errno,
rsp.op_errstr);
if (ret)
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
goto out;
}
@@ -3386,6 +2730,7 @@ gf_cli_sync_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
out:
cli_cmd_broadcast_response(ret);
+ gf_free_xdr_cli_rsp(rsp);
return ret;
}
@@ -3402,29 +2747,23 @@ print_quota_list_usage_output(cli_local_t *local, char *path, int64_t avail,
char *hl_str = NULL;
char *sl_val = NULL;
- used_str = gf_uint64_2human_readable(used_space->size);
-
- if (limit_set) {
- hl_str = gf_uint64_2human_readable(limits->hl);
- avail_str = gf_uint64_2human_readable(avail);
-
- sl_val = gf_uint64_2human_readable(sl_num);
- }
-
if (global_state->mode & GLUSTER_MODE_XML) {
ret = cli_quota_xml_output(local, path, limits->hl, sl_str, sl_num,
used_space->size, avail, sl ? "Yes" : "No",
hl ? "Yes" : "No", limit_set);
if (ret) {
gf_log("cli", GF_LOG_ERROR,
- "Failed to "
- "output in xml format for quota "
- "list command");
+ "Failed to output in xml format for quota list command");
}
goto out;
}
+ used_str = gf_uint64_2human_readable(used_space->size);
+
if (limit_set) {
+ hl_str = gf_uint64_2human_readable(limits->hl);
+ sl_val = gf_uint64_2human_readable(sl_num);
+
if (!used_str) {
cli_out("%-40s %7s %7s(%s) %8" PRIu64 "%9" PRIu64
""
@@ -3432,6 +2771,7 @@ print_quota_list_usage_output(cli_local_t *local, char *path, int64_t avail,
path, hl_str, sl_str, sl_val, used_space->size, avail,
sl ? "Yes" : "No", hl ? "Yes" : "No");
} else {
+ avail_str = gf_uint64_2human_readable(avail);
cli_out("%-40s %7s %7s(%s) %8s %7s %15s %20s", path, hl_str, sl_str,
sl_val, used_str, avail_str, sl ? "Yes" : "No",
hl ? "Yes" : "No");
@@ -3467,9 +2807,7 @@ print_quota_list_object_output(cli_local_t *local, char *path, int64_t avail,
hl ? "Yes" : "No", limit_set);
if (ret) {
gf_log("cli", GF_LOG_ERROR,
- "Failed to "
- "output in xml format for quota "
- "list command");
+ "Failed to output in xml format for quota list command");
}
goto out;
}
@@ -3515,16 +2853,17 @@ print_quota_list_output(cli_local_t *local, char *path, char *default_sl,
ret = gf_string2percent(default_sl, &sl_num);
if (ret) {
gf_log("cli", GF_LOG_ERROR,
- "could not convert default soft limit"
- " to percent");
+ "could not convert default soft limit to percent");
goto out;
}
sl_num = (sl_num * limits->hl) / 100;
sl_final = default_sl;
} else {
sl_num = (limits->sl * limits->hl) / 100;
- snprintf(percent_str, sizeof(percent_str), "%" PRIu64 "%%",
- limits->sl);
+ ret = snprintf(percent_str, sizeof(percent_str), "%" PRIu64 "%%",
+ limits->sl);
+ if (ret < 0)
+ goto out;
sl_final = percent_str;
}
if (type == GF_QUOTA_OPTION_TYPE_LIST)
@@ -3584,9 +2923,8 @@ print_quota_list_from_mountdir(cli_local_t *local, char *mountdir,
ret = sys_lgetxattr(mountdir, key, (void *)&limits, sizeof(limits));
if (ret < 0) {
gf_log("cli", GF_LOG_ERROR,
- "Failed to get the xattr %s "
- "on %s. Reason : %s",
- key, mountdir, strerror(errno));
+ "Failed to get the xattr %s on %s. Reason : %s", key, mountdir,
+ strerror(errno));
switch (errno) {
#if defined(ENODATA)
@@ -3645,9 +2983,7 @@ enoattr:
}
if (ret < 0) {
- gf_log("cli", GF_LOG_ERROR,
- "Failed to get quota size "
- "on path %s: %s",
+ gf_log("cli", GF_LOG_ERROR, "Failed to get quota size on path %s: %s",
mountdir, strerror(errno));
print_quota_list_empty(path, type);
goto out;
@@ -3663,7 +2999,7 @@ out:
return ret;
}
-int
+static int
gluster_remove_auxiliary_mount(char *volname)
{
int ret = -1;
@@ -3678,25 +3014,24 @@ gluster_remove_auxiliary_mount(char *volname)
GLUSTERD_GET_QUOTA_LIST_MOUNT_PATH(mountdir, volname, "/");
ret = gf_umount_lazy(this->name, mountdir, 1);
if (ret) {
- gf_log("cli", GF_LOG_ERROR,
- "umount on %s failed, "
- "reason : %s",
+ gf_log("cli", GF_LOG_ERROR, "umount on %s failed, reason : %s",
mountdir, strerror(errno));
}
return ret;
}
-int
+static int
gf_cli_print_limit_list_from_dict(cli_local_t *local, char *volname,
dict_t *dict, char *default_sl, int count,
int op_ret, int op_errno, char *op_errstr)
{
int ret = -1;
int i = 0;
- char key[1024] = {
+ char key[32] = {
0,
};
+ int keylen;
char mountdir[PATH_MAX] = {
0,
};
@@ -3706,7 +3041,7 @@ gf_cli_print_limit_list_from_dict(cli_local_t *local, char *volname,
if (!dict || count <= 0)
goto out;
- ret = dict_get_int32(dict, "type", &type);
+ ret = dict_get_int32_sizen(dict, "type", &type);
if (ret) {
gf_log("cli", GF_LOG_ERROR, "Failed to get quota type");
goto out;
@@ -3716,7 +3051,7 @@ gf_cli_print_limit_list_from_dict(cli_local_t *local, char *volname,
ret = cli_xml_output_vol_quota_limit_list_begin(local, op_ret, op_errno,
op_errstr);
if (ret) {
- gf_log("cli", GF_LOG_ERROR, "Error outputting xml begin");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
goto out;
}
} else {
@@ -3724,13 +3059,11 @@ gf_cli_print_limit_list_from_dict(cli_local_t *local, char *volname,
}
while (count--) {
- snprintf(key, sizeof(key), "path%d", i++);
+ keylen = snprintf(key, sizeof(key), "path%d", i++);
- ret = dict_get_str(dict, key, &path);
+ ret = dict_get_strn(dict, key, keylen, &path);
if (ret < 0) {
- gf_log("cli", GF_LOG_DEBUG,
- "Path not present in limit"
- " list");
+ gf_log("cli", GF_LOG_DEBUG, "Path not present in limit list");
continue;
}
@@ -3746,7 +3079,7 @@ out:
return ret;
}
-int
+static int
print_quota_list_from_quotad(call_frame_t *frame, dict_t *rsp_dict)
{
char *path = NULL;
@@ -3769,25 +3102,22 @@ print_quota_list_from_quotad(call_frame_t *frame, dict_t *rsp_dict)
local = frame->local;
gd_rsp_dict = local->dict;
- ret = dict_get_int32(rsp_dict, "type", &type);
+ ret = dict_get_int32_sizen(rsp_dict, "type", &type);
if (ret) {
gf_log("cli", GF_LOG_ERROR, "Failed to get type");
goto out;
}
- ret = dict_get_str(rsp_dict, GET_ANCESTRY_PATH_KEY, &path);
+ ret = dict_get_str_sizen(rsp_dict, GET_ANCESTRY_PATH_KEY, &path);
if (ret) {
- gf_log("cli", GF_LOG_WARNING,
- "path key is not present "
- "in dict");
+ gf_log("cli", GF_LOG_WARNING, "path key is not present in dict");
goto out;
}
- ret = dict_get_str(gd_rsp_dict, "default-soft-limit", &default_sl);
+ ret = dict_get_str_sizen(gd_rsp_dict, "default-soft-limit", &default_sl);
if (ret) {
gf_log(frame->this->name, GF_LOG_ERROR,
- "failed to "
- "get default soft limit");
+ "failed to get default soft limit");
goto out;
}
@@ -3812,9 +3142,11 @@ print_quota_list_from_quotad(call_frame_t *frame, dict_t *rsp_dict)
limits.sl = ntoh64(size_limits->sl);
if (type == GF_QUOTA_OPTION_TYPE_LIST)
- ret = quota_dict_get_meta(rsp_dict, QUOTA_SIZE_KEY, &used_space);
+ ret = quota_dict_get_meta(rsp_dict, QUOTA_SIZE_KEY,
+ SLEN(QUOTA_SIZE_KEY), &used_space);
else
- ret = quota_dict_get_inode_meta(rsp_dict, QUOTA_SIZE_KEY, &used_space);
+ ret = quota_dict_get_inode_meta(rsp_dict, QUOTA_SIZE_KEY,
+ SLEN(QUOTA_SIZE_KEY), &used_space);
if (ret < 0) {
gf_log("cli", GF_LOG_WARNING, "size key not present in dict");
@@ -3824,19 +3156,18 @@ print_quota_list_from_quotad(call_frame_t *frame, dict_t *rsp_dict)
LOCK(&local->lock);
{
- ret = dict_get_int32(gd_rsp_dict, "quota-list-success-count",
- &success_count);
+ ret = dict_get_int32_sizen(gd_rsp_dict, "quota-list-success-count",
+ &success_count);
if (ret)
success_count = 0;
- ret = dict_set_int32(gd_rsp_dict, "quota-list-success-count",
- success_count + 1);
+ ret = dict_set_int32_sizen(gd_rsp_dict, "quota-list-success-count",
+ success_count + 1);
}
UNLOCK(&local->lock);
if (ret) {
gf_log("cli", GF_LOG_ERROR,
- "Failed to set "
- "quota-list-success-count in dict");
+ "Failed to set quota-list-success-count in dict");
goto out;
}
@@ -3846,9 +3177,7 @@ print_quota_list_from_quotad(call_frame_t *frame, dict_t *rsp_dict)
} else {
ret = cli_xml_output_vol_quota_limit_list_begin(local, 0, 0, NULL);
if (ret) {
- gf_log("cli", GF_LOG_ERROR,
- "Error in "
- "printing xml output");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
goto out;
}
}
@@ -3860,7 +3189,7 @@ out:
return ret;
}
-void *
+static void *
cli_cmd_broadcast_response_detached(void *opaque)
{
int32_t ret = 0;
@@ -3871,7 +3200,7 @@ cli_cmd_broadcast_response_detached(void *opaque)
return NULL;
}
-int32_t
+static int32_t
cli_quota_compare_path(struct list_head *list1, struct list_head *list2)
{
struct list_node *node1 = NULL;
@@ -3888,18 +3217,18 @@ cli_quota_compare_path(struct list_head *list1, struct list_head *list2)
dict1 = node1->ptr;
dict2 = node2->ptr;
- ret = dict_get_str(dict1, GET_ANCESTRY_PATH_KEY, &path1);
+ ret = dict_get_str_sizen(dict1, GET_ANCESTRY_PATH_KEY, &path1);
if (ret < 0)
return 0;
- ret = dict_get_str(dict2, GET_ANCESTRY_PATH_KEY, &path2);
+ ret = dict_get_str_sizen(dict2, GET_ANCESTRY_PATH_KEY, &path2);
if (ret < 0)
return 0;
return strcmp(path1, path2);
}
-int
+static int
cli_quotad_getlimit_cbk(struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
@@ -3929,19 +3258,18 @@ cli_quotad_getlimit_cbk(struct rpc_req *req, struct iovec *iov, int count,
LOCK(&local->lock);
{
- ret = dict_get_int32(local->dict, "quota-list-count", &list_count);
+ ret = dict_get_int32_sizen(local->dict, "quota-list-count",
+ &list_count);
if (ret)
list_count = 0;
list_count++;
- ret = dict_set_int32(local->dict, "quota-list-count", list_count);
+ ret = dict_set_int32_sizen(local->dict, "quota-list-count", list_count);
}
UNLOCK(&local->lock);
if (ret) {
- gf_log("cli", GF_LOG_ERROR,
- "Failed to set "
- "quota-list-count in dict");
+ gf_log("cli", GF_LOG_ERROR, "Failed to set quota-list-count in dict");
goto out;
}
@@ -3956,8 +3284,7 @@ cli_quotad_getlimit_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
- gf_log(frame->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ gf_log(frame->this->name, GF_LOG_ERROR, XDR_DECODE_FAIL);
goto out;
}
@@ -3976,9 +3303,7 @@ cli_quotad_getlimit_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = dict_unserialize(rsp.dict.dict_val, rsp.dict.dict_len, &dict);
if (ret < 0) {
- gf_log("cli", GF_LOG_ERROR,
- "failed to "
- "unserialize req-buffer to dictionary");
+ gf_log("cli", GF_LOG_ERROR, DICT_UNSERIALIZE_FAIL);
goto out;
}
@@ -3987,11 +3312,12 @@ cli_quotad_getlimit_cbk(struct rpc_req *req, struct iovec *iov, int count,
if (node == NULL) {
gf_log("cli", GF_LOG_ERROR, "failed to add node to the list");
dict_unref(dict);
+ ret = -1;
goto out;
}
}
- ret = dict_get_int32(local->dict, "max_count", &max_count);
+ ret = dict_get_int32_sizen(local->dict, "max_count", &max_count);
if (ret < 0) {
gf_log("cli", GF_LOG_ERROR, "failed to get max_count");
goto out;
@@ -4027,19 +3353,17 @@ out:
ret = pthread_create(&th_id, NULL, cli_cmd_broadcast_response_detached,
(void *)-1);
if (ret)
- gf_log("cli", GF_LOG_ERROR,
- "pthread_create failed: "
- "%s",
+ gf_log("cli", GF_LOG_ERROR, "pthread_create failed: %s",
strerror(errno));
} else {
cli_cmd_broadcast_response(ret);
}
+ gf_free_xdr_cli_rsp(rsp);
- free(rsp.dict.dict_val);
return ret;
}
-int
+static int
cli_quotad_getlimit(call_frame_t *frame, xlator_t *this, void *data)
{
gf_cli_req req = {{
@@ -4059,7 +3383,7 @@ cli_quotad_getlimit(call_frame_t *frame, xlator_t *this, void *data)
ret = dict_allocate_and_serialize(dict, &req.dict.dict_val,
&req.dict.dict_len);
if (ret < 0) {
- gf_log(this->name, GF_LOG_ERROR, "failed to serialize the data");
+ gf_log(this->name, GF_LOG_ERROR, DICT_SERIALIZE_FAIL);
goto out;
}
@@ -4069,28 +3393,30 @@ cli_quotad_getlimit(call_frame_t *frame, xlator_t *this, void *data)
cli_quotad_getlimit_cbk, (xdrproc_t)xdr_gf_cli_req);
out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ GF_FREE(req.dict.dict_val);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
return ret;
}
-void
+static void
gf_cli_quota_list(cli_local_t *local, char *volname, dict_t *dict,
char *default_sl, int count, int op_ret, int op_errno,
char *op_errstr)
{
- GF_VALIDATE_OR_GOTO("cli", volname, out);
-
- if (!connected)
+ if (!cli_cmd_connected())
goto out;
- if (count > 0)
+ if (count > 0) {
+ GF_VALIDATE_OR_GOTO("cli", volname, out);
+
gf_cli_print_limit_list_from_dict(local, volname, dict, default_sl,
count, op_ret, op_errno, op_errstr);
+ }
out:
return;
}
-int
+static int
gf_cli_quota_cbk(struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
@@ -4121,8 +3447,7 @@ gf_cli_quota_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
- gf_log(frame->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ gf_log(frame->this->name, GF_LOG_ERROR, XDR_DECODE_FAIL);
goto out;
}
@@ -4134,9 +3459,7 @@ gf_cli_quota_cbk(struct rpc_req *req, struct iovec *iov, int count,
if (strcmp(rsp.op_errstr, "")) {
cli_err("quota command failed : %s", rsp.op_errstr);
if (rsp.op_ret == -ENOENT)
- cli_err(
- "please enter the path relative to "
- "the volume");
+ cli_err("please enter the path relative to the volume");
} else {
cli_err("quota command : failed");
}
@@ -4150,24 +3473,17 @@ gf_cli_quota_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = dict_unserialize(rsp.dict.dict_val, rsp.dict.dict_len, &dict);
if (ret < 0) {
- gf_log("cli", GF_LOG_ERROR,
- "failed to "
- "unserialize req-buffer to dictionary");
+ gf_log("cli", GF_LOG_ERROR, DICT_UNSERIALIZE_FAIL);
goto out;
}
}
gf_log("cli", GF_LOG_DEBUG, "Received resp to quota command");
- ret = dict_get_str(dict, "volname", &volname);
- if (ret)
- gf_log(frame->this->name, GF_LOG_ERROR, "failed to get volname");
-
- ret = dict_get_str(dict, "default-soft-limit", &default_sl);
+ ret = dict_get_str_sizen(dict, "default-soft-limit", &default_sl);
if (ret)
gf_log(frame->this->name, GF_LOG_TRACE,
- "failed to get "
- "default soft limit");
+ "failed to get default soft limit");
// default-soft-limit is part of rsp_dict only iff we sent
// GLUSTER_CLI_QUOTA with type being GF_QUOTA_OPTION_TYPE_LIST
@@ -4177,8 +3493,8 @@ gf_cli_quota_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = -1;
goto out;
}
- ret = dict_set_dynstr(local->dict, "default-soft-limit",
- default_sl_dup);
+ ret = dict_set_dynstr_sizen(local->dict, "default-soft-limit",
+ default_sl_dup);
if (ret) {
gf_log(frame->this->name, GF_LOG_TRACE,
"failed to set default soft limit");
@@ -4186,11 +3502,15 @@ gf_cli_quota_cbk(struct rpc_req *req, struct iovec *iov, int count,
}
}
- ret = dict_get_int32(dict, "type", &type);
+ ret = dict_get_str_sizen(dict, "volname", &volname);
+ if (ret)
+ gf_log(frame->this->name, GF_LOG_ERROR, "failed to get volname");
+
+ ret = dict_get_int32_sizen(dict, "type", &type);
if (ret)
gf_log(frame->this->name, GF_LOG_TRACE, "failed to get type");
- ret = dict_get_int32(dict, "count", &entry_count);
+ ret = dict_get_int32_sizen(dict, "count", &entry_count);
if (ret)
gf_log(frame->this->name, GF_LOG_TRACE, "failed to get count");
@@ -4203,9 +3523,7 @@ gf_cli_quota_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = cli_xml_output_vol_quota_limit_list_end(local);
if (ret < 0) {
ret = -1;
- gf_log("cli", GF_LOG_ERROR,
- "Error in printing"
- " xml output");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
}
goto out;
}
@@ -4217,7 +3535,7 @@ xml_output:
ret = cli_xml_output_str("volQuota", NULL, rsp.op_ret, rsp.op_errno,
rsp.op_errstr);
if (ret)
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
goto out;
}
@@ -4237,12 +3555,12 @@ out:
if (dict)
dict_unref(dict);
- free(rsp.dict.dict_val);
+ gf_free_xdr_cli_rsp(rsp);
return ret;
}
-int
+static int
gf_cli_getspec_cbk(struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
@@ -4261,13 +3579,14 @@ gf_cli_getspec_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_getspec_rsp);
if (ret < 0) {
gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ XDR_DECODE_FAIL);
goto out;
}
if (rsp.op_ret == -1) {
gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
"getspec failed");
+ ret = -1;
goto out;
}
@@ -4276,6 +3595,7 @@ gf_cli_getspec_cbk(struct rpc_req *req, struct iovec *iov, int count,
spec = GF_MALLOC(rsp.op_ret + 1, cli_mt_char);
if (!spec) {
gf_log("", GF_LOG_ERROR, "out of memory");
+ ret = -1;
goto out;
}
memcpy(spec, rsp.spec, rsp.op_ret);
@@ -4287,10 +3607,11 @@ gf_cli_getspec_cbk(struct rpc_req *req, struct iovec *iov, int count,
out:
cli_cmd_broadcast_response(ret);
+ gf_free_xdr_getspec_rsp(rsp);
return ret;
}
-int
+static int
gf_cli_pmap_b2p_cbk(struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
@@ -4309,13 +3630,14 @@ gf_cli_pmap_b2p_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_pmap_port_by_brick_rsp);
if (ret < 0) {
gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ XDR_DECODE_FAIL);
goto out;
}
if (rsp.op_ret == -1) {
gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
"pump_b2p failed");
+ ret = -1;
goto out;
}
@@ -4331,7 +3653,7 @@ out:
return ret;
}
-int32_t
+static int32_t
gf_cli_probe(call_frame_t *frame, xlator_t *this, void *data)
{
gf_cli_req req = {
@@ -4350,9 +3672,9 @@ gf_cli_probe(call_frame_t *frame, xlator_t *this, void *data)
dict = data;
- ret = dict_get_int32(dict, "port", &port);
+ ret = dict_get_int32_sizen(dict, "port", &port);
if (ret) {
- ret = dict_set_int32(dict, "port", CLI_GLUSTERD_PORT);
+ ret = dict_set_int32_sizen(dict, "port", CLI_GLUSTERD_PORT);
if (ret)
goto out;
}
@@ -4363,12 +3685,12 @@ gf_cli_probe(call_frame_t *frame, xlator_t *this, void *data)
out:
GF_FREE(req.dict.dict_val);
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
return ret;
}
-int32_t
+static int32_t
gf_cli_deprobe(call_frame_t *frame, xlator_t *this, void *data)
{
gf_cli_req req = {
@@ -4387,16 +3709,16 @@ gf_cli_deprobe(call_frame_t *frame, xlator_t *this, void *data)
}
dict = data;
- ret = dict_get_int32(dict, "port", &port);
+ ret = dict_get_int32_sizen(dict, "port", &port);
if (ret) {
- ret = dict_set_int32(dict, "port", CLI_GLUSTERD_PORT);
+ ret = dict_set_int32_sizen(dict, "port", CLI_GLUSTERD_PORT);
if (ret)
goto out;
}
- ret = dict_get_int32(dict, "flags", &flags);
+ ret = dict_get_int32_sizen(dict, "flags", &flags);
if (ret) {
- ret = dict_set_int32(dict, "flags", 0);
+ ret = dict_set_int32_sizen(dict, "flags", 0);
if (ret)
goto out;
}
@@ -4407,12 +3729,12 @@ gf_cli_deprobe(call_frame_t *frame, xlator_t *this, void *data)
out:
GF_FREE(req.dict.dict_val);
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
return ret;
}
-int32_t
+static int32_t
gf_cli_list_friends(call_frame_t *frame, xlator_t *this, void *data)
{
gf1_cli_peer_list_req req = {
@@ -4445,11 +3767,11 @@ out:
*/
frame->local = NULL;
}
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
return ret;
}
-int32_t
+static int32_t
gf_cli_get_state(call_frame_t *frame, xlator_t *this, void *data)
{
gf_cli_req req = {
@@ -4460,23 +3782,18 @@ gf_cli_get_state(call_frame_t *frame, xlator_t *this, void *data)
int ret = 0;
dict_t *dict = NULL;
- if (!frame || !this || !data) {
- ret = -1;
- goto out;
- }
-
dict = data;
ret = cli_to_glusterd(&req, frame, gf_cli_get_state_cbk,
(xdrproc_t)xdr_gf_cli_req, dict,
GLUSTER_CLI_GET_STATE, this, cli_rpc_prog, NULL);
-out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
+ GF_FREE(req.dict.dict_val);
return ret;
}
-int32_t
+static int32_t
gf_cli_get_next_volume(call_frame_t *frame, xlator_t *this, void *data)
{
int ret = 0;
@@ -4494,7 +3811,7 @@ gf_cli_get_next_volume(call_frame_t *frame, xlator_t *this, void *data)
if (global_state->mode & GLUSTER_MODE_XML) {
ret = cli_xml_output_vol_info_begin(local, 0, 0, "");
if (ret) {
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
goto out;
}
}
@@ -4522,15 +3839,15 @@ end_xml:
if (global_state->mode & GLUSTER_MODE_XML) {
ret = cli_xml_output_vol_info_end(local);
if (ret)
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
}
out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
return ret;
}
-int32_t
+static int32_t
gf_cli_get_volume(call_frame_t *frame, xlator_t *this, void *data)
{
gf_cli_req req = {{
@@ -4541,7 +3858,7 @@ gf_cli_get_volume(call_frame_t *frame, xlator_t *this, void *data)
dict_t *dict = NULL;
int32_t flags = 0;
- if (!frame || !this || !data) {
+ if (!this || !data) {
ret = -1;
goto out;
}
@@ -4549,17 +3866,20 @@ gf_cli_get_volume(call_frame_t *frame, xlator_t *this, void *data)
ctx = data;
dict = dict_new();
- if (!dict)
+ if (!dict) {
+ gf_log(THIS->name, GF_LOG_ERROR, "Failed to create the dict");
+ ret = -1;
goto out;
+ }
if (ctx->volname) {
- ret = dict_set_str(dict, "volname", ctx->volname);
+ ret = dict_set_str_sizen(dict, "volname", ctx->volname);
if (ret)
goto out;
}
flags = ctx->flags;
- ret = dict_set_int32(dict, "flags", flags);
+ ret = dict_set_int32_sizen(dict, "flags", flags);
if (ret) {
gf_log(frame->this->name, GF_LOG_ERROR, "failed to set flags");
goto out;
@@ -4568,7 +3888,7 @@ gf_cli_get_volume(call_frame_t *frame, xlator_t *this, void *data)
ret = dict_allocate_and_serialize(dict, &req.dict.dict_val,
&req.dict.dict_len);
if (ret) {
- gf_log(frame->this->name, GF_LOG_ERROR, "failed to serialize dict");
+ gf_log(frame->this->name, GF_LOG_ERROR, DICT_SERIALIZE_FAIL);
goto out;
}
@@ -4582,11 +3902,11 @@ out:
GF_FREE(req.dict.dict_val);
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
return ret;
}
-int32_t
+static int32_t
gf_cli3_1_uuid_get(call_frame_t *frame, xlator_t *this, void *data)
{
gf_cli_req req = {{
@@ -4595,21 +3915,16 @@ gf_cli3_1_uuid_get(call_frame_t *frame, xlator_t *this, void *data)
int ret = 0;
dict_t *dict = NULL;
- if (!frame || !this || !data) {
- ret = -1;
- goto out;
- }
-
dict = data;
ret = cli_to_glusterd(&req, frame, gf_cli3_1_uuid_get_cbk,
(xdrproc_t)xdr_gf_cli_req, dict, GLUSTER_CLI_UUID_GET,
this, cli_rpc_prog, NULL);
-out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
+ GF_FREE(req.dict.dict_val);
return ret;
}
-int32_t
+static int32_t
gf_cli3_1_uuid_reset(call_frame_t *frame, xlator_t *this, void *data)
{
gf_cli_req req = {{
@@ -4618,21 +3933,16 @@ gf_cli3_1_uuid_reset(call_frame_t *frame, xlator_t *this, void *data)
int ret = 0;
dict_t *dict = NULL;
- if (!frame || !this || !data) {
- ret = -1;
- goto out;
- }
-
dict = data;
ret = cli_to_glusterd(&req, frame, gf_cli3_1_uuid_reset_cbk,
(xdrproc_t)xdr_gf_cli_req, dict,
GLUSTER_CLI_UUID_RESET, this, cli_rpc_prog, NULL);
-out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
+ GF_FREE(req.dict.dict_val);
return ret;
}
-int32_t
+static int32_t
gf_cli_create_volume(call_frame_t *frame, xlator_t *this, void *data)
{
gf_cli_req req = {{
@@ -4641,26 +3951,19 @@ gf_cli_create_volume(call_frame_t *frame, xlator_t *this, void *data)
int ret = 0;
dict_t *dict = NULL;
- if (!frame || !this || !data) {
- ret = -1;
- goto out;
- }
-
dict = data;
ret = cli_to_glusterd(&req, frame, gf_cli_create_volume_cbk,
(xdrproc_t)xdr_gf_cli_req, dict,
GLUSTER_CLI_CREATE_VOLUME, this, cli_rpc_prog, NULL);
-
-out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
GF_FREE(req.dict.dict_val);
return ret;
}
-int32_t
+static int32_t
gf_cli_delete_volume(call_frame_t *frame, xlator_t *this, void *data)
{
gf_cli_req req = {{
@@ -4669,25 +3972,18 @@ gf_cli_delete_volume(call_frame_t *frame, xlator_t *this, void *data)
int ret = 0;
dict_t *dict = NULL;
- if (!frame || !this || !data) {
- ret = -1;
- goto out;
- }
-
dict = data;
ret = cli_to_glusterd(&req, frame, gf_cli_delete_volume_cbk,
(xdrproc_t)xdr_gf_cli_req, dict,
GLUSTER_CLI_DELETE_VOLUME, this, cli_rpc_prog, NULL);
-
-out:
GF_FREE(req.dict.dict_val);
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
return ret;
}
-int32_t
+static int32_t
gf_cli_start_volume(call_frame_t *frame, xlator_t *this, void *data)
{
gf_cli_req req = {{
@@ -4696,24 +3992,19 @@ gf_cli_start_volume(call_frame_t *frame, xlator_t *this, void *data)
int ret = 0;
dict_t *dict = NULL;
- if (!frame || !this || !data) {
- ret = -1;
- goto out;
- }
-
dict = data;
ret = cli_to_glusterd(&req, frame, gf_cli_start_volume_cbk,
(xdrproc_t)xdr_gf_cli_req, dict,
GLUSTER_CLI_START_VOLUME, this, cli_rpc_prog, NULL);
-out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
+ GF_FREE(req.dict.dict_val);
return ret;
}
-int32_t
+static int32_t
gf_cli_stop_volume(call_frame_t *frame, xlator_t *this, void *data)
{
gf_cli_req req = {{
@@ -4722,24 +4013,18 @@ gf_cli_stop_volume(call_frame_t *frame, xlator_t *this, void *data)
int ret = 0;
dict_t *dict = data;
- if (!frame || !this || !data) {
- ret = -1;
- goto out;
- }
-
dict = data;
ret = cli_to_glusterd(&req, frame, gf_cli_stop_volume_cbk,
(xdrproc_t)xdr_gf_cli_req, dict,
GLUSTER_CLI_STOP_VOLUME, this, cli_rpc_prog, NULL);
-
-out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
+ GF_FREE(req.dict.dict_val);
return ret;
}
-int32_t
+static int32_t
gf_cli_defrag_volume(call_frame_t *frame, xlator_t *this, void *data)
{
gf_cli_req req = {{
@@ -4748,24 +4033,18 @@ gf_cli_defrag_volume(call_frame_t *frame, xlator_t *this, void *data)
int ret = 0;
dict_t *dict = NULL;
- if (!frame || !this || !data) {
- ret = -1;
- goto out;
- }
-
dict = data;
ret = cli_to_glusterd(&req, frame, gf_cli_defrag_volume_cbk,
(xdrproc_t)xdr_gf_cli_req, dict,
GLUSTER_CLI_DEFRAG_VOLUME, this, cli_rpc_prog, NULL);
-
-out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
+ GF_FREE(req.dict.dict_val);
return ret;
}
-int32_t
+static int32_t
gf_cli_rename_volume(call_frame_t *frame, xlator_t *this, void *data)
{
gf_cli_req req = {{
@@ -4784,7 +4063,7 @@ gf_cli_rename_volume(call_frame_t *frame, xlator_t *this, void *data)
ret = dict_allocate_and_serialize(dict, &req.dict.dict_val,
&req.dict.dict_len);
if (ret < 0) {
- gf_log(this->name, GF_LOG_ERROR, "failed to serialize the data");
+ gf_log(this->name, GF_LOG_ERROR, DICT_SERIALIZE_FAIL);
goto out;
}
@@ -4794,12 +4073,13 @@ gf_cli_rename_volume(call_frame_t *frame, xlator_t *this, void *data)
gf_cli_rename_volume_cbk, (xdrproc_t)xdr_gf_cli_req);
out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ GF_FREE(req.dict.dict_val);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
return ret;
}
-int32_t
+static int32_t
gf_cli_reset_volume(call_frame_t *frame, xlator_t *this, void *data)
{
gf_cli_req req = {{
@@ -4808,123 +4088,37 @@ gf_cli_reset_volume(call_frame_t *frame, xlator_t *this, void *data)
int ret = 0;
dict_t *dict = NULL;
- if (!frame || !this || !data) {
- ret = -1;
- goto out;
- }
-
dict = data;
ret = cli_to_glusterd(&req, frame, gf_cli_reset_volume_cbk,
(xdrproc_t)xdr_gf_cli_req, dict,
GLUSTER_CLI_RESET_VOLUME, this, cli_rpc_prog, NULL);
-
-out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
- return ret;
-}
-
-int32_t
-gf_cli_set_volume(call_frame_t *frame, xlator_t *this, void *data)
-{
- gf_cli_req req = {{
- 0,
- }};
- int ret = 0;
- dict_t *dict = NULL;
-
- if (!frame || !this || !data) {
- ret = -1;
- goto out;
- }
-
- dict = data;
-
- ret = cli_to_glusterd(&req, frame, gf_cli_set_volume_cbk,
- (xdrproc_t)xdr_gf_cli_req, dict,
- GLUSTER_CLI_SET_VOLUME, this, cli_rpc_prog, NULL);
-
-out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
-
- return ret;
-}
-
-int32_t
-gf_cli_add_brick(call_frame_t *frame, xlator_t *this, void *data)
-{
- gf_cli_req req = {{
- 0,
- }};
- int ret = 0;
- dict_t *dict = NULL;
- char *volname = NULL;
- int32_t count = 0;
-
- if (!frame || !this || !data) {
- ret = -1;
- goto out;
- }
-
- dict = data;
-
- ret = dict_get_str(dict, "volname", &volname);
-
- if (ret)
- goto out;
-
- ret = dict_get_int32(dict, "count", &count);
- if (ret)
- goto out;
-
- ret = cli_to_glusterd(&req, frame, gf_cli_add_brick_cbk,
- (xdrproc_t)xdr_gf_cli_req, dict,
- GLUSTER_CLI_ADD_BRICK, this, cli_rpc_prog, NULL);
-
-out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
-
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
GF_FREE(req.dict.dict_val);
-
return ret;
}
-int32_t
-gf_cli_tier(call_frame_t *frame, xlator_t *this, void *data)
+static int32_t
+gf_cli_ganesha(call_frame_t *frame, xlator_t *this, void *data)
{
- int ret = 0;
- int32_t command = 0;
gf_cli_req req = {{
0,
}};
+ int ret = 0;
dict_t *dict = NULL;
- if (!frame || !this || !data) {
- ret = -1;
- goto out;
- }
dict = data;
- ret = dict_get_int32(dict, "rebalance-command", &command);
- if (ret) {
- gf_log("cli", GF_LOG_ERROR, "Failed to get rebalance-command");
- goto out;
- }
-
- ret = cli_to_glusterd(&req, frame, gf_cli_defrag_volume_cbk,
- (xdrproc_t)xdr_gf_cli_req, dict, GLUSTER_CLI_TIER,
+ ret = cli_to_glusterd(&req, frame, gf_cli_ganesha_cbk,
+ (xdrproc_t)xdr_gf_cli_req, dict, GLUSTER_CLI_GANESHA,
this, cli_rpc_prog, NULL);
-
-out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
-
- GF_FREE(req.dict.dict_val);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
return ret;
}
-int32_t
-gf_cli_add_tier_brick(call_frame_t *frame, xlator_t *this, void *data)
+static int32_t
+gf_cli_set_volume(call_frame_t *frame, xlator_t *this, void *data)
{
gf_cli_req req = {{
0,
@@ -4932,140 +4126,40 @@ gf_cli_add_tier_brick(call_frame_t *frame, xlator_t *this, void *data)
int ret = 0;
dict_t *dict = NULL;
- if (!frame || !this || !data) {
- ret = -1;
- goto out;
- }
-
dict = data;
- ret = cli_to_glusterd(&req, frame, gf_cli_add_tier_brick_cbk,
+ ret = cli_to_glusterd(&req, frame, gf_cli_set_volume_cbk,
(xdrproc_t)xdr_gf_cli_req, dict,
- GLUSTER_CLI_ADD_TIER_BRICK, this, cli_rpc_prog, NULL);
- if (ret) {
- gf_log("cli", GF_LOG_ERROR,
- "Failed to send request to "
- "glusterd");
- goto out;
- }
-
-out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
-
+ GLUSTER_CLI_SET_VOLUME, this, cli_rpc_prog, NULL);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
GF_FREE(req.dict.dict_val);
+
return ret;
}
int32_t
-gf_cli_attach_tier(call_frame_t *frame, xlator_t *this, void *data)
+gf_cli_add_brick(call_frame_t *frame, xlator_t *this, void *data)
{
gf_cli_req req = {{
0,
}};
int ret = 0;
dict_t *dict = NULL;
- dict_t *newdict = NULL;
- char *tierwords[] = {"volume", "tier", "", "start", NULL};
- const char **words = (const char **)tierwords;
- char *volname = NULL;
- cli_local_t *local = NULL;
- cli_local_t *oldlocal = NULL;
-
- if (!frame || !this || !data) {
- ret = -1;
- goto out;
- }
dict = data;
- ret = cli_to_glusterd(&req, frame, gf_cli_attach_tier_cbk,
+ ret = cli_to_glusterd(&req, frame, gf_cli_add_brick_cbk,
(xdrproc_t)xdr_gf_cli_req, dict,
- GLUSTER_CLI_ATTACH_TIER, this, cli_rpc_prog, NULL);
- if (ret)
- goto out;
- ret = dict_get_str(dict, "volname", &volname);
- if (ret) {
- gf_log("cli", GF_LOG_ERROR, "Failed to get volume name");
- goto notify_cli;
- }
-
- words[2] = volname;
- ret = cli_cmd_volume_old_tier_parse((const char **)words, 4, &newdict);
- if (ret) {
- gf_log("cli", GF_LOG_ERROR,
- "Failed to parse tier start "
- "command");
- goto notify_cli;
- }
-
- gf_log("cli", GF_LOG_DEBUG, "Sending tier start");
-
- oldlocal = frame->local;
- CLI_LOCAL_INIT(local, words, frame, newdict);
- ret = gf_cli_tier(frame, this, newdict);
- frame->local = oldlocal;
- cli_local_wipe(local);
-
-notify_cli:
- if (ret) {
- cli_out(
- "Failed to run tier start. Please execute tier start "
- "command explicitly");
- cli_out("Usage : gluster volume tier <volname> start");
- }
+ GLUSTER_CLI_ADD_BRICK, this, cli_rpc_prog, NULL);
-out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
GF_FREE(req.dict.dict_val);
- return ret;
-}
-
-int32_t
-gf_cli_remove_tier_brick(call_frame_t *frame, xlator_t *this, void *data)
-{
- gf_cli_req status_req = {{
- 0,
- }};
- int ret = 0;
- dict_t *dict = NULL;
- int32_t command = 0;
- char *volname = NULL;
-
- if (!frame || !this || !data) {
- ret = -1;
- goto out;
- }
-
- dict = data;
-
- ret = dict_get_str(dict, "volname", &volname);
- if (ret)
- goto out;
-
- ret = dict_get_int32(dict, "command", &command);
- if (ret)
- goto out;
-
- ret = dict_set_int32(dict, "rebalance-command", (int32_t)command);
- if (ret) {
- gf_log(this->name, GF_LOG_ERROR, "Failed to set dict");
- goto out;
- }
-
- ret = cli_to_glusterd(&status_req, frame, gf_cli_remove_tier_brick_cbk,
- (xdrproc_t)xdr_gf_cli_req, dict, GLUSTER_CLI_TIER,
- this, cli_rpc_prog, NULL);
-
-out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
-
- GF_FREE(status_req.dict.dict_val);
return ret;
}
-int32_t
+static int32_t
gf_cli_remove_brick(call_frame_t *frame, xlator_t *this, void *data)
{
gf_cli_req req = {{
@@ -5079,21 +4173,16 @@ gf_cli_remove_brick(call_frame_t *frame, xlator_t *this, void *data)
int ret = 0;
dict_t *dict = NULL;
int32_t command = 0;
- char *volname = NULL;
int32_t cmd = 0;
- if (!frame || !this || !data) {
+ if (!frame || !this) {
ret = -1;
goto out;
}
dict = data;
- ret = dict_get_str(dict, "volname", &volname);
- if (ret)
- goto out;
-
- ret = dict_get_int32(dict, "command", &command);
+ ret = dict_get_int32_sizen(dict, "command", &command);
if (ret)
goto out;
@@ -5108,7 +4197,7 @@ gf_cli_remove_brick(call_frame_t *frame, xlator_t *this, void *data)
else
cmd |= GF_DEFRAG_CMD_STOP;
- ret = dict_set_int32(dict, "rebalance-command", (int32_t)cmd);
+ ret = dict_set_int32_sizen(dict, "rebalance-command", (int32_t)cmd);
if (ret) {
gf_log(this->name, GF_LOG_ERROR, "Failed to set dict");
goto out;
@@ -5121,7 +4210,7 @@ gf_cli_remove_brick(call_frame_t *frame, xlator_t *this, void *data)
}
out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
GF_FREE(req.dict.dict_val);
@@ -5130,7 +4219,7 @@ out:
return ret;
}
-int32_t
+static int32_t
gf_cli_reset_brick(call_frame_t *frame, xlator_t *this, void *data)
{
gf_cli_req req = {{
@@ -5139,8 +4228,6 @@ gf_cli_reset_brick(call_frame_t *frame, xlator_t *this, void *data)
int ret = 0;
dict_t *dict = NULL;
char *dst_brick = NULL;
- char *src_brick = NULL;
- char *volname = NULL;
char *op = NULL;
if (!frame || !this || !data) {
@@ -5150,49 +4237,34 @@ gf_cli_reset_brick(call_frame_t *frame, xlator_t *this, void *data)
dict = data;
- ret = dict_get_str(dict, "operation", &op);
+ ret = dict_get_str_sizen(dict, "operation", &op);
if (ret) {
gf_log(this->name, GF_LOG_DEBUG, "dict_get on operation failed");
goto out;
}
- ret = dict_get_str(dict, "volname", &volname);
- if (ret) {
- gf_log(this->name, GF_LOG_DEBUG, "dict_get on volname failed");
- goto out;
- }
-
- ret = dict_get_str(dict, "src-brick", &src_brick);
- if (ret) {
- gf_log(this->name, GF_LOG_DEBUG, "dict_get on src-brick failed");
- goto out;
- }
-
if (!strcmp(op, "GF_RESET_OP_COMMIT") ||
!strcmp(op, "GF_RESET_OP_COMMIT_FORCE")) {
- ret = dict_get_str(dict, "dst-brick", &dst_brick);
+ ret = dict_get_str_sizen(dict, "dst-brick", &dst_brick);
if (ret) {
gf_log(this->name, GF_LOG_DEBUG, "dict_get on dst-brick failed");
goto out;
}
}
- gf_log(this->name, GF_LOG_DEBUG, "Received command reset-brick %s on %s.",
- op, src_brick);
-
ret = cli_to_glusterd(&req, frame, gf_cli_reset_brick_cbk,
(xdrproc_t)xdr_gf_cli_req, dict,
GLUSTER_CLI_RESET_BRICK, this, cli_rpc_prog, NULL);
out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
GF_FREE(req.dict.dict_val);
return ret;
}
-int32_t
+static int32_t
gf_cli_replace_brick(call_frame_t *frame, xlator_t *this, void *data)
{
gf_cli_req req = {{
@@ -5200,9 +4272,6 @@ gf_cli_replace_brick(call_frame_t *frame, xlator_t *this, void *data)
}};
int ret = 0;
dict_t *dict = NULL;
- char *src_brick = NULL;
- char *dst_brick = NULL;
- char *volname = NULL;
int32_t op = 0;
if (!frame || !this || !data) {
@@ -5212,47 +4281,25 @@ gf_cli_replace_brick(call_frame_t *frame, xlator_t *this, void *data)
dict = data;
- ret = dict_get_int32(dict, "operation", &op);
+ ret = dict_get_int32_sizen(dict, "operation", &op);
if (ret) {
gf_log(this->name, GF_LOG_DEBUG, "dict_get on operation failed");
goto out;
}
- ret = dict_get_str(dict, "volname", &volname);
- if (ret) {
- gf_log(this->name, GF_LOG_DEBUG, "dict_get on volname failed");
- goto out;
- }
-
- ret = dict_get_str(dict, "src-brick", &src_brick);
- if (ret) {
- gf_log(this->name, GF_LOG_DEBUG, "dict_get on src-brick failed");
- goto out;
- }
-
- ret = dict_get_str(dict, "dst-brick", &dst_brick);
- if (ret) {
- gf_log(this->name, GF_LOG_DEBUG, "dict_get on dst-brick failed");
- goto out;
- }
-
- gf_log(this->name, GF_LOG_DEBUG,
- "Received command replace-brick %s with "
- "%s with operation=%d",
- src_brick, dst_brick, op);
ret = cli_to_glusterd(&req, frame, gf_cli_replace_brick_cbk,
(xdrproc_t)xdr_gf_cli_req, dict,
GLUSTER_CLI_REPLACE_BRICK, this, cli_rpc_prog, NULL);
out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
GF_FREE(req.dict.dict_val);
return ret;
}
-int32_t
+static int32_t
gf_cli_log_rotate(call_frame_t *frame, xlator_t *this, void *data)
{
gf_cli_req req = {{
@@ -5261,25 +4308,18 @@ gf_cli_log_rotate(call_frame_t *frame, xlator_t *this, void *data)
int ret = 0;
dict_t *dict = NULL;
- if (!frame || !this || !data) {
- ret = -1;
- goto out;
- }
-
dict = data;
ret = cli_to_glusterd(&req, frame, gf_cli_log_rotate_cbk,
(xdrproc_t)xdr_gf_cli_req, dict,
GLUSTER_CLI_LOG_ROTATE, this, cli_rpc_prog, NULL);
-
-out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
GF_FREE(req.dict.dict_val);
return ret;
}
-int32_t
+static int32_t
gf_cli_sync_volume(call_frame_t *frame, xlator_t *this, void *data)
{
int ret = 0;
@@ -5288,25 +4328,18 @@ gf_cli_sync_volume(call_frame_t *frame, xlator_t *this, void *data)
}};
dict_t *dict = NULL;
- if (!frame || !this || !data) {
- ret = -1;
- goto out;
- }
-
dict = data;
ret = cli_to_glusterd(&req, frame, gf_cli_sync_volume_cbk,
(xdrproc_t)xdr_gf_cli_req, dict,
GLUSTER_CLI_SYNC_VOLUME, this, cli_rpc_prog, NULL);
-
-out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
GF_FREE(req.dict.dict_val);
return ret;
}
-int32_t
+static int32_t
gf_cli_getspec(call_frame_t *frame, xlator_t *this, void *data)
{
gf_getspec_req req = {
@@ -5316,14 +4349,14 @@ gf_cli_getspec(call_frame_t *frame, xlator_t *this, void *data)
dict_t *dict = NULL;
dict_t *op_dict = NULL;
- if (!frame || !this || !data) {
+ if (!frame || !this) {
ret = -1;
goto out;
}
dict = data;
- ret = dict_get_str(dict, "volid", &req.key);
+ ret = dict_get_str_sizen(dict, "volid", &req.key);
if (ret)
goto out;
@@ -5335,26 +4368,24 @@ gf_cli_getspec(call_frame_t *frame, xlator_t *this, void *data)
// Set the supported min and max op-versions, so glusterd can make a
// decision
- ret = dict_set_int32(op_dict, "min-op-version", GD_OP_VERSION_MIN);
+ ret = dict_set_int32_sizen(op_dict, "min-op-version", GD_OP_VERSION_MIN);
if (ret) {
gf_log(THIS->name, GF_LOG_ERROR,
- "Failed to set min-op-version"
- " in request dict");
+ "Failed to set min-op-version in request dict");
goto out;
}
- ret = dict_set_int32(op_dict, "max-op-version", GD_OP_VERSION_MAX);
+ ret = dict_set_int32_sizen(op_dict, "max-op-version", GD_OP_VERSION_MAX);
if (ret) {
gf_log(THIS->name, GF_LOG_ERROR,
- "Failed to set max-op-version"
- " in request dict");
+ "Failed to set max-op-version in request dict");
goto out;
}
ret = dict_allocate_and_serialize(op_dict, &req.xdata.xdata_val,
&req.xdata.xdata_len);
if (ret < 0) {
- gf_log(THIS->name, GF_LOG_ERROR, "Failed to serialize dictionary");
+ gf_log(THIS->name, GF_LOG_ERROR, DICT_SERIALIZE_FAIL);
goto out;
}
@@ -5366,12 +4397,13 @@ out:
if (op_dict) {
dict_unref(op_dict);
}
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ GF_FREE(req.xdata.xdata_val);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
return ret;
}
-int32_t
+static int32_t
gf_cli_quota(call_frame_t *frame, xlator_t *this, void *data)
{
gf_cli_req req = {{
@@ -5380,24 +4412,17 @@ gf_cli_quota(call_frame_t *frame, xlator_t *this, void *data)
int ret = 0;
dict_t *dict = NULL;
- if (!frame || !this || !data) {
- ret = -1;
- goto out;
- }
-
dict = data;
ret = cli_to_glusterd(&req, frame, gf_cli_quota_cbk,
(xdrproc_t)xdr_gf_cli_req, dict, GLUSTER_CLI_QUOTA,
this, cli_rpc_prog, NULL);
-
-out:
GF_FREE(req.dict.dict_val);
-
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
return ret;
}
-int32_t
+static int32_t
gf_cli_pmap_b2p(call_frame_t *frame, xlator_t *this, void *data)
{
pmap_port_by_brick_req req = {
@@ -5406,14 +4431,14 @@ gf_cli_pmap_b2p(call_frame_t *frame, xlator_t *this, void *data)
int ret = 0;
dict_t *dict = NULL;
- if (!frame || !this || !data) {
+ if (!frame || !this) {
ret = -1;
goto out;
}
dict = data;
- ret = dict_get_str(dict, "brick", &req.brick);
+ ret = dict_get_str_sizen(dict, "brick", &req.brick);
if (ret)
goto out;
@@ -5422,7 +4447,7 @@ gf_cli_pmap_b2p(call_frame_t *frame, xlator_t *this, void *data)
(xdrproc_t)xdr_pmap_port_by_brick_req);
out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
return ret;
}
@@ -5437,7 +4462,8 @@ gf_cli_fsm_log_cbk(struct rpc_req *req, struct iovec *iov, int count,
int ret = -1;
dict_t *dict = NULL;
int tr_count = 0;
- char key[256] = {0};
+ char key[64] = {0};
+ int keylen;
int i = 0;
char *old_state = NULL;
char *new_state = NULL;
@@ -5453,7 +4479,7 @@ gf_cli_fsm_log_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf1_cli_fsm_log_rsp);
if (ret < 0) {
gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ XDR_DECODE_FAIL);
goto out;
}
@@ -5475,33 +4501,33 @@ gf_cli_fsm_log_cbk(struct rpc_req *req, struct iovec *iov, int count,
&dict);
if (ret) {
- cli_err("bad response");
+ cli_err(DICT_UNSERIALIZE_FAIL);
goto out;
}
- ret = dict_get_int32(dict, "count", &tr_count);
- if (tr_count)
+ ret = dict_get_int32_sizen(dict, "count", &tr_count);
+ if (!ret && tr_count)
cli_out("number of transitions: %d", tr_count);
else
cli_err("No transitions");
for (i = 0; i < tr_count; i++) {
- snprintf(key, sizeof(key), "log%d-old-state", i);
- ret = dict_get_str(dict, key, &old_state);
+ keylen = snprintf(key, sizeof(key), "log%d-old-state", i);
+ ret = dict_get_strn(dict, key, keylen, &old_state);
if (ret)
goto out;
- snprintf(key, sizeof(key), "log%d-event", i);
- ret = dict_get_str(dict, key, &event);
+ keylen = snprintf(key, sizeof(key), "log%d-event", i);
+ ret = dict_get_strn(dict, key, keylen, &event);
if (ret)
goto out;
- snprintf(key, sizeof(key), "log%d-new-state", i);
- ret = dict_get_str(dict, key, &new_state);
+ keylen = snprintf(key, sizeof(key), "log%d-new-state", i);
+ ret = dict_get_strn(dict, key, keylen, &new_state);
if (ret)
goto out;
- snprintf(key, sizeof(key), "log%d-time", i);
- ret = dict_get_str(dict, key, &time);
+ keylen = snprintf(key, sizeof(key), "log%d-time", i);
+ ret = dict_get_strn(dict, key, keylen, &time);
if (ret)
goto out;
cli_out(
@@ -5516,10 +4542,15 @@ gf_cli_fsm_log_cbk(struct rpc_req *req, struct iovec *iov, int count,
out:
cli_cmd_broadcast_response(ret);
+ if (dict) {
+ dict_unref(dict);
+ }
+ gf_free_xdr_fsm_log_rsp(rsp);
+
return ret;
}
-int32_t
+static int32_t
gf_cli_fsm_log(call_frame_t *frame, xlator_t *this, void *data)
{
int ret = -1;
@@ -5539,12 +4570,12 @@ gf_cli_fsm_log(call_frame_t *frame, xlator_t *this, void *data)
(xdrproc_t)xdr_gf1_cli_fsm_log_req);
out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
return ret;
}
-int
+static int
gf_cli_gsync_config_command(dict_t *dict)
{
runner_t runner = {
@@ -5559,7 +4590,7 @@ gf_cli_gsync_config_command(dict_t *dict)
int ret = -1;
char conf_path[PATH_MAX] = "";
- if (dict_get_str(dict, "subop", &subop) != 0)
+ if (dict_get_str_sizen(dict, "subop", &subop) != 0)
return -1;
if (strcmp(subop, "get") != 0 && strcmp(subop, "get-all") != 0) {
@@ -5567,16 +4598,16 @@ gf_cli_gsync_config_command(dict_t *dict)
return 0;
}
- if (dict_get_str(dict, "glusterd_workdir", &gwd) != 0 ||
- dict_get_str(dict, "slave", &slave) != 0)
+ if (dict_get_str_sizen(dict, "glusterd_workdir", &gwd) != 0 ||
+ dict_get_str_sizen(dict, "slave", &slave) != 0)
return -1;
- if (dict_get_str(dict, "master", &master) != 0)
+ if (dict_get_str_sizen(dict, "master", &master) != 0)
master = NULL;
- if (dict_get_str(dict, "op_name", &op_name) != 0)
+ if (dict_get_str_sizen(dict, "op_name", &op_name) != 0)
op_name = NULL;
- ret = dict_get_str(dict, "conf_path", &confpath);
+ ret = dict_get_str_sizen(dict, "conf_path", &confpath);
if (ret || !confpath) {
ret = snprintf(conf_path, sizeof(conf_path) - 1,
"%s/" GEOREP "/gsyncd_template.conf", gwd);
@@ -5598,7 +4629,7 @@ gf_cli_gsync_config_command(dict_t *dict)
return runner_run(&runner);
}
-int
+static int
gf_cli_print_status(char **title_values, gf_gsync_status_t **sts_vals,
int *spacing, int gsync_count, int number_of_fields,
int is_detail)
@@ -5627,7 +4658,7 @@ gf_cli_print_status(char **title_values, gf_gsync_status_t **sts_vals,
total_spacing += 4; /* For the spacing between the fields */
/* char pointers for each field */
- output_values = GF_CALLOC(number_of_fields, sizeof(char *),
+ output_values = GF_MALLOC(number_of_fields * sizeof(char *),
gf_common_mt_char);
if (!output_values) {
ret = -1;
@@ -5642,12 +4673,6 @@ gf_cli_print_status(char **title_values, gf_gsync_status_t **sts_vals,
}
}
- hyphens = GF_CALLOC(total_spacing + 1, sizeof(char), gf_common_mt_char);
- if (!hyphens) {
- ret = -1;
- goto out;
- }
-
cli_out(" ");
/* setting the title "NODE", "MASTER", etc. from title_values[]
@@ -5670,6 +4695,12 @@ gf_cli_print_status(char **title_values, gf_gsync_status_t **sts_vals,
output_values[10], output_values[11], output_values[12],
output_values[13], output_values[14], output_values[15]);
+ hyphens = GF_MALLOC((total_spacing + 1) * sizeof(char), gf_common_mt_char);
+ if (!hyphens) {
+ ret = -1;
+ goto out;
+ }
+
/* setting and printing the hyphens */
memset(hyphens, '-', total_spacing);
hyphens[total_spacing] = '\0';
@@ -5734,7 +4765,7 @@ gf_gsync_status_t_comparator(const void *p, const void *q)
return strcmp(slavekey1, slavekey2);
}
-int
+static int
gf_cli_read_status_data(dict_t *dict, gf_gsync_status_t **sts_vals,
int *spacing, int gsync_count, int number_of_fields)
{
@@ -5774,7 +4805,7 @@ out:
return ret;
}
-int
+static int
gf_cli_gsync_status_output(dict_t *dict, gf_boolean_t is_detail)
{
int gsync_count = 0;
@@ -5785,47 +4816,43 @@ gf_cli_gsync_status_output(dict_t *dict, gf_boolean_t is_detail)
char errmsg[1024] = "";
char *master = NULL;
char *slave = NULL;
- char *title_values[] = {"MASTER NODE",
- "MASTER VOL",
- "MASTER BRICK",
- "SLAVE USER",
- "SLAVE",
- "SLAVE NODE",
- "STATUS",
- "CRAWL STATUS",
- "LAST_SYNCED",
- "ENTRY",
- "DATA",
- "META",
- "FAILURES",
- "CHECKPOINT TIME",
- "CHECKPOINT COMPLETED",
- "CHECKPOINT COMPLETION TIME"};
+ static char *title_values[] = {"MASTER NODE",
+ "MASTER VOL",
+ "MASTER BRICK",
+ "SLAVE USER",
+ "SLAVE",
+ "SLAVE NODE",
+ "STATUS",
+ "CRAWL STATUS",
+ "LAST_SYNCED",
+ "ENTRY",
+ "DATA",
+ "META",
+ "FAILURES",
+ "CHECKPOINT TIME",
+ "CHECKPOINT COMPLETED",
+ "CHECKPOINT COMPLETION TIME"};
gf_gsync_status_t **sts_vals = NULL;
/* Checks if any session is active or not */
- ret = dict_get_int32(dict, "gsync-count", &gsync_count);
+ ret = dict_get_int32_sizen(dict, "gsync-count", &gsync_count);
if (ret) {
- ret = dict_get_str(dict, "master", &master);
+ ret = dict_get_str_sizen(dict, "master", &master);
- ret = dict_get_str(dict, "slave", &slave);
+ ret = dict_get_str_sizen(dict, "slave", &slave);
if (master) {
if (slave)
snprintf(errmsg, sizeof(errmsg),
- "No active "
- "geo-replication sessions between %s"
+ "No active geo-replication sessions between %s"
" and %s",
master, slave);
else
snprintf(errmsg, sizeof(errmsg),
- "No active "
- "geo-replication sessions for %s",
- master);
+ "No active geo-replication sessions for %s", master);
} else
snprintf(errmsg, sizeof(errmsg),
- "No active "
- "geo-replication sessions");
+ "No active geo-replication sessions");
gf_log("cli", GF_LOG_INFO, "%s", errmsg);
cli_out("%s", errmsg);
@@ -5845,14 +4872,6 @@ gf_cli_gsync_status_output(dict_t *dict, gf_boolean_t is_detail)
ret = -1;
goto out;
}
- for (i = 0; i < gsync_count; i++) {
- sts_vals[i] = GF_CALLOC(1, sizeof(gf_gsync_status_t),
- gf_common_mt_char);
- if (!sts_vals[i]) {
- ret = -1;
- goto out;
- }
- }
ret = gf_cli_read_status_data(dict, sts_vals, spacing, gsync_count,
num_of_fields);
@@ -5881,13 +4900,13 @@ write_contents_to_common_pem_file(dict_t *dict, int output_count)
char *workdir = NULL;
char common_pem_file[PATH_MAX] = "";
char *output = NULL;
- char output_name[PATH_MAX] = "";
+ char output_name[32] = "";
int bytes_written = 0;
int fd = -1;
int ret = -1;
int i = -1;
- ret = dict_get_str(dict, "glusterd_workdir", &workdir);
+ ret = dict_get_str_sizen(dict, "glusterd_workdir", &workdir);
if (ret || !workdir) {
gf_log("", GF_LOG_ERROR, "Unable to fetch workdir");
ret = -1;
@@ -5901,17 +4920,15 @@ write_contents_to_common_pem_file(dict_t *dict, int output_count)
fd = open(common_pem_file, O_WRONLY | O_CREAT, 0600);
if (fd == -1) {
- gf_log("", GF_LOG_ERROR,
- "Failed to open %s"
- " Error : %s",
+ gf_log("", GF_LOG_ERROR, "Failed to open %s Error : %s",
common_pem_file, strerror(errno));
ret = -1;
goto out;
}
for (i = 1; i <= output_count; i++) {
- snprintf(output_name, sizeof(output_name), "output_%d", i);
- ret = dict_get_str(dict, output_name, &output);
+ ret = snprintf(output_name, sizeof(output_name), "output_%d", i);
+ ret = dict_get_strn(dict, output_name, ret, &output);
if (ret) {
gf_log("", GF_LOG_ERROR, "Failed to get %s.", output_name);
cli_out("Unable to fetch output.");
@@ -5919,9 +4936,7 @@ write_contents_to_common_pem_file(dict_t *dict, int output_count)
if (output) {
bytes_written = sys_write(fd, output, strlen(output));
if (bytes_written != strlen(output)) {
- gf_log("", GF_LOG_ERROR,
- "Failed to write "
- "to %s",
+ gf_log("", GF_LOG_ERROR, "Failed to write to %s",
common_pem_file);
ret = -1;
goto out;
@@ -5943,11 +4958,11 @@ out:
if (fd >= 0)
sys_close(fd);
- gf_log("", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log("", GF_LOG_DEBUG, RETURNING, ret);
return ret;
}
-int
+static int
gf_cli_sys_exec_cbk(struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
@@ -5956,7 +4971,7 @@ gf_cli_sys_exec_cbk(struct rpc_req *req, struct iovec *iov, int count,
int i = -1;
char *output = NULL;
char *command = NULL;
- char output_name[PATH_MAX] = "";
+ char output_name[32] = "";
gf_cli_rsp rsp = {
0,
};
@@ -5971,7 +4986,7 @@ gf_cli_sys_exec_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ XDR_DECODE_FAIL);
goto out;
}
@@ -5993,14 +5008,14 @@ gf_cli_sys_exec_cbk(struct rpc_req *req, struct iovec *iov, int count,
goto out;
}
- ret = dict_get_int32(dict, "output_count", &output_count);
+ ret = dict_get_int32_sizen(dict, "output_count", &output_count);
if (ret) {
cli_out("Command executed successfully.");
ret = 0;
goto out;
}
- ret = dict_get_str(dict, "command", &command);
+ ret = dict_get_str_sizen(dict, "command", &command);
if (ret) {
gf_log("", GF_LOG_ERROR, "Unable to get command from dict");
goto out;
@@ -6013,8 +5028,8 @@ gf_cli_sys_exec_cbk(struct rpc_req *req, struct iovec *iov, int count,
}
for (i = 1; i <= output_count; i++) {
- snprintf(output_name, sizeof(output_name), "output_%d", i);
- ret = dict_get_str(dict, output_name, &output);
+ ret = snprintf(output_name, sizeof(output_name), "output_%d", i);
+ ret = dict_get_strn(dict, output_name, ret, &output);
if (ret) {
gf_log("", GF_LOG_ERROR, "Failed to get %s.", output_name);
cli_out("Unable to fetch output.");
@@ -6030,13 +5045,11 @@ out:
if (dict)
dict_unref(dict);
cli_cmd_broadcast_response(ret);
-
- free(rsp.dict.dict_val);
-
+ gf_free_xdr_cli_rsp(rsp);
return ret;
}
-int
+static int
gf_cli_copy_file_cbk(struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
@@ -6055,7 +5068,7 @@ gf_cli_copy_file_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ XDR_DECODE_FAIL);
goto out;
}
@@ -6083,13 +5096,11 @@ out:
if (dict)
dict_unref(dict);
cli_cmd_broadcast_response(ret);
-
- free(rsp.dict.dict_val);
-
+ gf_free_xdr_cli_rsp(rsp);
return ret;
}
-int
+static int
gf_cli_gsync_set_cbk(struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
@@ -6113,7 +5124,7 @@ gf_cli_gsync_set_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ XDR_DECODE_FAIL);
goto out;
}
@@ -6133,7 +5144,7 @@ gf_cli_gsync_set_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = cli_xml_output_vol_gsync(dict, rsp.op_ret, rsp.op_errno,
rsp.op_errstr);
if (ret)
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
goto out;
}
@@ -6144,11 +5155,11 @@ gf_cli_gsync_set_cbk(struct rpc_req *req, struct iovec *iov, int count,
goto out;
}
- ret = dict_get_str(dict, "gsync-status", &gsync_status);
+ ret = dict_get_str_sizen(dict, "gsync-status", &gsync_status);
if (!ret)
cli_out("%s", gsync_status);
- ret = dict_get_int32(dict, "type", &type);
+ ret = dict_get_int32_sizen(dict, "type", &type);
if (ret) {
gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
"failed to get type");
@@ -6158,29 +5169,25 @@ gf_cli_gsync_set_cbk(struct rpc_req *req, struct iovec *iov, int count,
switch (type) {
case GF_GSYNC_OPTION_TYPE_START:
case GF_GSYNC_OPTION_TYPE_STOP:
- if (dict_get_str(dict, "master", &master) != 0)
+ if (dict_get_str_sizen(dict, "master", &master) != 0)
master = "???";
- if (dict_get_str(dict, "slave", &slave) != 0)
+ if (dict_get_str_sizen(dict, "slave", &slave) != 0)
slave = "???";
cli_out(
- "%s " GEOREP
- " session between %s & %s"
- " has been successful",
+ "%s " GEOREP " session between %s & %s has been successful",
type == GF_GSYNC_OPTION_TYPE_START ? "Starting" : "Stopping",
master, slave);
break;
case GF_GSYNC_OPTION_TYPE_PAUSE:
case GF_GSYNC_OPTION_TYPE_RESUME:
- if (dict_get_str(dict, "master", &master) != 0)
+ if (dict_get_str_sizen(dict, "master", &master) != 0)
master = "???";
- if (dict_get_str(dict, "slave", &slave) != 0)
+ if (dict_get_str_sizen(dict, "slave", &slave) != 0)
slave = "???";
- cli_out("%s " GEOREP
- " session between %s & %s"
- " has been successful",
+ cli_out("%s " GEOREP " session between %s & %s has been successful",
type == GF_GSYNC_OPTION_TYPE_PAUSE ? "Pausing" : "Resuming",
master, slave);
break;
@@ -6196,24 +5203,22 @@ gf_cli_gsync_set_cbk(struct rpc_req *req, struct iovec *iov, int count,
break;
case GF_GSYNC_OPTION_TYPE_DELETE:
- if (dict_get_str(dict, "master", &master) != 0)
+ if (dict_get_str_sizen(dict, "master", &master) != 0)
master = "???";
- if (dict_get_str(dict, "slave", &slave) != 0)
+ if (dict_get_str_sizen(dict, "slave", &slave) != 0)
slave = "???";
cli_out("Deleting " GEOREP
- " session between %s & %s"
- " has been successful",
+ " session between %s & %s has been successful",
master, slave);
break;
case GF_GSYNC_OPTION_TYPE_CREATE:
- if (dict_get_str(dict, "master", &master) != 0)
+ if (dict_get_str_sizen(dict, "master", &master) != 0)
master = "???";
- if (dict_get_str(dict, "slave", &slave) != 0)
+ if (dict_get_str_sizen(dict, "slave", &slave) != 0)
slave = "???";
cli_out("Creating " GEOREP
- " session between %s & %s"
- " has been successful",
+ " session between %s & %s has been successful",
master, slave);
break;
@@ -6225,13 +5230,11 @@ out:
if (dict)
dict_unref(dict);
cli_cmd_broadcast_response(ret);
-
- free(rsp.dict.dict_val);
-
+ gf_free_xdr_cli_rsp(rsp);
return ret;
}
-int32_t
+static int32_t
gf_cli_sys_exec(call_frame_t *frame, xlator_t *this, void *data)
{
int ret = 0;
@@ -6240,23 +5243,22 @@ gf_cli_sys_exec(call_frame_t *frame, xlator_t *this, void *data)
0,
}};
- if (!frame || !this || !data) {
- ret = -1;
- gf_log("cli", GF_LOG_ERROR, "Invalid data");
- goto out;
- }
-
dict = data;
ret = cli_to_glusterd(&req, frame, gf_cli_sys_exec_cbk,
(xdrproc_t)xdr_gf_cli_req, dict, GLUSTER_CLI_SYS_EXEC,
this, cli_rpc_prog, NULL);
-out:
+ if (ret)
+ if (!frame || !this || !data) {
+ ret = -1;
+ gf_log("cli", GF_LOG_ERROR, "Invalid data");
+ }
+
GF_FREE(req.dict.dict_val);
return ret;
}
-int32_t
+static int32_t
gf_cli_copy_file(call_frame_t *frame, xlator_t *this, void *data)
{
int ret = 0;
@@ -6265,23 +5267,22 @@ gf_cli_copy_file(call_frame_t *frame, xlator_t *this, void *data)
0,
}};
- if (!frame || !this || !data) {
- ret = -1;
- gf_log("cli", GF_LOG_ERROR, "Invalid data");
- goto out;
- }
-
dict = data;
ret = cli_to_glusterd(&req, frame, gf_cli_copy_file_cbk,
(xdrproc_t)xdr_gf_cli_req, dict,
GLUSTER_CLI_COPY_FILE, this, cli_rpc_prog, NULL);
-out:
+ if (ret)
+ if (!frame || !this || !data) {
+ ret = -1;
+ gf_log("cli", GF_LOG_ERROR, "Invalid data");
+ }
+
GF_FREE(req.dict.dict_val);
return ret;
}
-int32_t
+static int32_t
gf_cli_gsync_set(call_frame_t *frame, xlator_t *this, void *data)
{
int ret = 0;
@@ -6290,18 +5291,11 @@ gf_cli_gsync_set(call_frame_t *frame, xlator_t *this, void *data)
0,
}};
- if (!frame || !this || !data) {
- ret = -1;
- goto out;
- }
-
dict = data;
ret = cli_to_glusterd(&req, frame, gf_cli_gsync_set_cbk,
(xdrproc_t)xdr_gf_cli_req, dict,
GLUSTER_CLI_GSYNC_SET, this, cli_rpc_prog, NULL);
-
-out:
GF_FREE(req.dict.dict_val);
return ret;
@@ -6312,20 +5306,18 @@ cli_profile_info_percentage_cmp(void *a, void *b)
{
cli_profile_info_t *ia = NULL;
cli_profile_info_t *ib = NULL;
- int ret = 0;
ia = a;
ib = b;
if (ia->percentage_avg_latency < ib->percentage_avg_latency)
- ret = -1;
+ return -1;
else if (ia->percentage_avg_latency > ib->percentage_avg_latency)
- ret = 1;
- else
- ret = 0;
- return ret;
+ return 1;
+
+ return 0;
}
-void
+static void
cmd_profile_volume_brick_out(dict_t *dict, int count, int interval)
{
char key[256] = {0};
@@ -6349,7 +5341,8 @@ cmd_profile_volume_brick_out(dict_t *dict, int count, int interval)
double total_percentage_latency = 0;
for (i = 0; i < 32; i++) {
- snprintf(key, sizeof(key), "%d-%d-read-%d", count, interval, (1 << i));
+ snprintf(key, sizeof(key), "%d-%d-read-%" PRIu32, count, interval,
+ (1U << i));
ret = dict_get_uint64(dict, key, &rb_counts[i]);
if (ret) {
gf_log("cli", GF_LOG_DEBUG, "failed to get %s from dict", key);
@@ -6357,7 +5350,8 @@ cmd_profile_volume_brick_out(dict_t *dict, int count, int interval)
}
for (i = 0; i < 32; i++) {
- snprintf(key, sizeof(key), "%d-%d-write-%d", count, interval, (1 << i));
+ snprintf(key, sizeof(key), "%d-%d-write-%" PRIu32, count, interval,
+ (1U << i));
ret = dict_get_uint64(dict, key, &wb_counts[i]);
if (ret) {
gf_log("cli", GF_LOG_DEBUG, "failed to get %s from dict", key);
@@ -6443,7 +5437,8 @@ cmd_profile_volume_brick_out(dict_t *dict, int count, int interval)
if ((rb_counts[i] == 0) && (wb_counts[i] == 0))
continue;
per_line++;
- snprintf(output + index, sizeof(output) - index, "%19db+ ", (1 << i));
+ snprintf(output + index, sizeof(output) - index, "%19" PRIu32 "b+ ",
+ (1U << i));
if (rb_counts[i]) {
snprintf(read_blocks + index, sizeof(read_blocks) - index,
"%21" PRId64 " ", rb_counts[i]);
@@ -6520,7 +5515,7 @@ cmd_profile_volume_brick_out(dict_t *dict, int count, int interval)
cli_out(" ");
}
-int32_t
+static int32_t
gf_cli_profile_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
@@ -6530,7 +5525,8 @@ gf_cli_profile_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
int ret = -1;
dict_t *dict = NULL;
gf1_cli_stats_op op = GF_CLI_STATS_NONE;
- char key[256] = {0};
+ char key[64] = {0};
+ int len;
int interval = 0;
int i = 1;
int32_t brick_count = 0;
@@ -6552,7 +5548,7 @@ gf_cli_profile_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ XDR_DECODE_FAIL);
goto out;
}
@@ -6566,25 +5562,23 @@ gf_cli_profile_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = dict_unserialize(rsp.dict.dict_val, rsp.dict.dict_len, &dict);
if (ret) {
- gf_log("", GF_LOG_ERROR, "Unable to allocate memory");
+ gf_log("", GF_LOG_ERROR, DICT_UNSERIALIZE_FAIL);
goto out;
- } else {
- dict->extra_stdfree = rsp.dict.dict_val;
}
if (global_state->mode & GLUSTER_MODE_XML) {
ret = cli_xml_output_vol_profile(dict, rsp.op_ret, rsp.op_errno,
rsp.op_errstr);
if (ret)
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
goto out;
}
- ret = dict_get_str(dict, "volname", &volname);
+ ret = dict_get_int32_sizen(dict, "op", (int32_t *)&op);
if (ret)
goto out;
- ret = dict_get_int32(dict, "op", (int32_t *)&op);
+ ret = dict_get_str_sizen(dict, "volname", &volname);
if (ret)
goto out;
@@ -6619,11 +5613,7 @@ gf_cli_profile_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
goto out;
}
- ret = dict_get_int32(dict, "info-op", (int32_t *)&info_op);
- if (ret)
- goto out;
-
- ret = dict_get_int32(dict, "count", &brick_count);
+ ret = dict_get_int32_sizen(dict, "count", &brick_count);
if (ret)
goto out;
@@ -6632,9 +5622,13 @@ gf_cli_profile_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
goto out;
}
+ ret = dict_get_int32_sizen(dict, "info-op", (int32_t *)&info_op);
+ if (ret)
+ goto out;
+
while (i <= brick_count) {
- snprintf(key, sizeof(key), "%d-brick", i);
- ret = dict_get_str(dict, key, &brick);
+ len = snprintf(key, sizeof(key), "%d-brick", i);
+ ret = dict_get_strn(dict, key, len, &brick);
if (ret) {
gf_log("cli", GF_LOG_ERROR, "Couldn't get brick name");
goto out;
@@ -6643,28 +5637,28 @@ gf_cli_profile_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = dict_get_str_boolean(dict, "nfs", _gf_false);
if (ret)
- snprintf(str, sizeof(str), "NFS Server : %s", brick);
+ len = snprintf(str, sizeof(str), "NFS Server : %s", brick);
else
- snprintf(str, sizeof(str), "Brick: %s", brick);
+ len = snprintf(str, sizeof(str), "Brick: %s", brick);
cli_out("%s", str);
- memset(str, '-', strlen(str));
+ memset(str, '-', len);
cli_out("%s", str);
if (GF_CLI_INFO_CLEAR == info_op) {
- snprintf(key, sizeof(key), "%d-stats-cleared", i);
- ret = dict_get_int32(dict, key, &stats_cleared);
+ len = snprintf(key, sizeof(key), "%d-stats-cleared", i);
+ ret = dict_get_int32n(dict, key, len, &stats_cleared);
if (ret)
goto out;
cli_out(stats_cleared ? "Cleared stats."
: "Failed to clear stats.");
} else {
- snprintf(key, sizeof(key), "%d-cumulative", i);
- ret = dict_get_int32(dict, key, &interval);
+ len = snprintf(key, sizeof(key), "%d-cumulative", i);
+ ret = dict_get_int32n(dict, key, len, &interval);
if (ret == 0)
cmd_profile_volume_brick_out(dict, i, interval);
- snprintf(key, sizeof(key), "%d-interval", i);
- ret = dict_get_int32(dict, key, &interval);
+ len = snprintf(key, sizeof(key), "%d-interval", i);
+ ret = dict_get_int32n(dict, key, len, &interval);
if (ret == 0)
cmd_profile_volume_brick_out(dict, i, interval);
}
@@ -6675,12 +5669,12 @@ gf_cli_profile_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
out:
if (dict)
dict_unref(dict);
- free(rsp.op_errstr);
cli_cmd_broadcast_response(ret);
+ gf_free_xdr_cli_rsp(rsp);
return ret;
}
-int32_t
+static int32_t
gf_cli_profile_volume(call_frame_t *frame, xlator_t *this, void *data)
{
int ret = -1;
@@ -6693,22 +5687,18 @@ gf_cli_profile_volume(call_frame_t *frame, xlator_t *this, void *data)
GF_ASSERT(this);
GF_ASSERT(data);
- if (!frame || !this || !data)
- goto out;
dict = data;
ret = cli_to_glusterd(&req, frame, gf_cli_profile_volume_cbk,
(xdrproc_t)xdr_gf_cli_req, dict,
GLUSTER_CLI_PROFILE_VOLUME, this, cli_rpc_prog, NULL);
-
-out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
GF_FREE(req.dict.dict_val);
return ret;
}
-int32_t
+static int32_t
gf_cli_top_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
@@ -6719,6 +5709,7 @@ gf_cli_top_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
dict_t *dict = NULL;
gf1_cli_stats_op op = GF_CLI_STATS_NONE;
char key[256] = {0};
+ int keylen;
int i = 0;
int32_t brick_count = 0;
char brick[1024];
@@ -6734,7 +5725,7 @@ gf_cli_top_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
double time = 0;
int32_t time_sec = 0;
long int time_usec = 0;
- char timestr[256] = {
+ char timestr[GF_TIMESTR_SIZE] = {
0,
};
char *openfd_str = NULL;
@@ -6752,7 +5743,7 @@ gf_cli_top_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ XDR_DECODE_FAIL);
goto out;
}
@@ -6774,11 +5765,11 @@ gf_cli_top_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = dict_unserialize(rsp.dict.dict_val, rsp.dict.dict_len, &dict);
if (ret) {
- gf_log("", GF_LOG_ERROR, "Unable to allocate memory");
+ gf_log("", GF_LOG_ERROR, DICT_UNSERIALIZE_FAIL);
goto out;
}
- ret = dict_get_int32(dict, "op", (int32_t *)&op);
+ ret = dict_get_int32_sizen(dict, "op", (int32_t *)&op);
if (op != GF_CLI_STATS_TOP) {
ret = 0;
@@ -6789,16 +5780,16 @@ gf_cli_top_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = cli_xml_output_vol_top(dict, rsp.op_ret, rsp.op_errno,
rsp.op_errstr);
if (ret) {
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
}
goto out;
}
- ret = dict_get_int32(dict, "count", &brick_count);
+ ret = dict_get_int32_sizen(dict, "count", &brick_count);
if (ret)
goto out;
- snprintf(key, sizeof(key), "%d-top-op", 1);
- ret = dict_get_int32(dict, key, (int32_t *)&top_op);
+ keylen = snprintf(key, sizeof(key), "%d-top-op", 1);
+ ret = dict_get_int32n(dict, key, keylen, (int32_t *)&top_op);
if (ret)
goto out;
@@ -6806,16 +5797,16 @@ gf_cli_top_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
while (i < brick_count) {
i++;
- snprintf(brick, sizeof(brick), "%d-brick", i);
- ret = dict_get_str(dict, brick, &bricks);
+ keylen = snprintf(brick, sizeof(brick), "%d-brick", i);
+ ret = dict_get_strn(dict, brick, keylen, &bricks);
if (ret)
goto out;
nfs = dict_get_str_boolean(dict, "nfs", _gf_false);
if (clear_stats) {
- snprintf(key, sizeof(key), "%d-stats-cleared", i);
- ret = dict_get_int32(dict, key, &stats_cleared);
+ keylen = snprintf(key, sizeof(key), "%d-stats-cleared", i);
+ ret = dict_get_int32n(dict, key, keylen, &stats_cleared);
if (ret)
goto out;
cli_out(stats_cleared ? "Cleared stats for %s %s"
@@ -6829,8 +5820,8 @@ gf_cli_top_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
else
cli_out("Brick: %s", bricks);
- snprintf(key, sizeof(key), "%d-members", i);
- ret = dict_get_int32(dict, key, &members);
+ keylen = snprintf(key, sizeof(key), "%d-members", i);
+ ret = dict_get_int32n(dict, key, keylen, &members);
switch (top_op) {
case GF_CLI_TOP_OPEN:
@@ -6842,13 +5833,12 @@ gf_cli_top_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = dict_get_uint64(dict, key, &max_nr_open);
if (ret)
goto out;
- snprintf(key, sizeof(key), "%d-max-openfd-time", i);
- ret = dict_get_str(dict, key, &openfd_str);
+ keylen = snprintf(key, sizeof(key), "%d-max-openfd-time", i);
+ ret = dict_get_strn(dict, key, keylen, &openfd_str);
if (ret)
goto out;
- cli_out("Current open fds: %" PRIu64
- ", Max open"
- " fds: %" PRIu64 ", Max openfd time: %s",
+ cli_out("Current open fds: %" PRIu64 ", Max open fds: %" PRIu64
+ ", Max openfd time: %s",
nr_open, max_nr_open, openfd_str);
case GF_CLI_TOP_READ:
case GF_CLI_TOP_WRITE:
@@ -6886,8 +5876,8 @@ gf_cli_top_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
}
for (j = 1; j <= members; j++) {
- snprintf(key, sizeof(key), "%d-filename-%d", i, j);
- ret = dict_get_str(dict, key, &filename);
+ keylen = snprintf(key, sizeof(key), "%d-filename-%d", i, j);
+ ret = dict_get_strn(dict, key, keylen, &filename);
if (ret)
break;
snprintf(key, sizeof(key), "%d-value-%d", i, j);
@@ -6896,12 +5886,12 @@ gf_cli_top_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
goto out;
if (top_op == GF_CLI_TOP_READ_PERF ||
top_op == GF_CLI_TOP_WRITE_PERF) {
- snprintf(key, sizeof(key), "%d-time-sec-%d", i, j);
- ret = dict_get_int32(dict, key, (int32_t *)&time_sec);
+ keylen = snprintf(key, sizeof(key), "%d-time-sec-%d", i, j);
+ ret = dict_get_int32n(dict, key, keylen, (int32_t *)&time_sec);
if (ret)
goto out;
- snprintf(key, sizeof(key), "%d-time-usec-%d", i, j);
- ret = dict_get_int32(dict, key, (int32_t *)&time_usec);
+ keylen = snprintf(key, sizeof(key), "%d-time-usec-%d", i, j);
+ ret = dict_get_int32n(dict, key, keylen, (int32_t *)&time_usec);
if (ret)
goto out;
gf_time_fmt(timestr, sizeof timestr, time_sec, gf_timefmt_FT);
@@ -6931,11 +5921,11 @@ out:
if (dict)
dict_unref(dict);
- free(rsp.dict.dict_val);
+ gf_free_xdr_cli_rsp(rsp);
return ret;
}
-int32_t
+static int32_t
gf_cli_top_volume(call_frame_t *frame, xlator_t *this, void *data)
{
int ret = -1;
@@ -6948,21 +5938,17 @@ gf_cli_top_volume(call_frame_t *frame, xlator_t *this, void *data)
GF_ASSERT(this);
GF_ASSERT(data);
- if (!frame || !this || !data)
- goto out;
dict = data;
ret = cli_to_glusterd(&req, frame, gf_cli_top_volume_cbk,
(xdrproc_t)xdr_gf_cli_req, dict,
GLUSTER_CLI_PROFILE_VOLUME, this, cli_rpc_prog, NULL);
-
-out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
GF_FREE(req.dict.dict_val);
return ret;
}
-int
+static int
gf_cli_getwd_cbk(struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
@@ -6980,7 +5966,7 @@ gf_cli_getwd_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf1_cli_getwd_rsp);
if (ret < 0) {
gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ XDR_DECODE_FAIL);
goto out;
}
@@ -6998,10 +5984,14 @@ gf_cli_getwd_cbk(struct rpc_req *req, struct iovec *iov, int count,
out:
cli_cmd_broadcast_response(ret);
+ if (rsp.wd) {
+ free(rsp.wd);
+ }
+
return ret;
}
-int32_t
+static int32_t
gf_cli_getwd(call_frame_t *frame, xlator_t *this, void *data)
{
int ret = -1;
@@ -7020,12 +6010,12 @@ gf_cli_getwd(call_frame_t *frame, xlator_t *this, void *data)
(xdrproc_t)xdr_gf1_cli_getwd_req);
out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
return ret;
}
-void
+static void
cli_print_volume_status_mempool(dict_t *dict, char *prefix)
{
int ret = -1;
@@ -7038,16 +6028,18 @@ cli_print_volume_status_mempool(dict_t *dict, char *prefix)
int32_t maxalloc = 0;
uint64_t pool_misses = 0;
int32_t maxstdalloc = 0;
- char key[1024] = {
+ char key[128] = {
+ /* prefix is really small 'brick%d' really */
0,
};
+ int keylen;
int i = 0;
GF_ASSERT(dict);
GF_ASSERT(prefix);
- snprintf(key, sizeof(key), "%s.mempool-count", prefix);
- ret = dict_get_int32(dict, key, &mempool_count);
+ keylen = snprintf(key, sizeof(key), "%s.mempool-count", prefix);
+ ret = dict_get_int32n(dict, key, keylen, &mempool_count);
if (ret)
goto out;
@@ -7060,18 +6052,18 @@ cli_print_volume_status_mempool(dict_t *dict, char *prefix)
"------------");
for (i = 0; i < mempool_count; i++) {
- snprintf(key, sizeof(key), "%s.pool%d.name", prefix, i);
- ret = dict_get_str(dict, key, &name);
+ keylen = snprintf(key, sizeof(key), "%s.pool%d.name", prefix, i);
+ ret = dict_get_strn(dict, key, keylen, &name);
if (ret)
goto out;
- snprintf(key, sizeof(key), "%s.pool%d.hotcount", prefix, i);
- ret = dict_get_int32(dict, key, &hotcount);
+ keylen = snprintf(key, sizeof(key), "%s.pool%d.hotcount", prefix, i);
+ ret = dict_get_int32n(dict, key, keylen, &hotcount);
if (ret)
goto out;
- snprintf(key, sizeof(key), "%s.pool%d.coldcount", prefix, i);
- ret = dict_get_int32(dict, key, &coldcount);
+ keylen = snprintf(key, sizeof(key), "%s.pool%d.coldcount", prefix, i);
+ ret = dict_get_int32n(dict, key, keylen, &coldcount);
if (ret)
goto out;
@@ -7085,13 +6077,14 @@ cli_print_volume_status_mempool(dict_t *dict, char *prefix)
if (ret)
goto out;
- snprintf(key, sizeof(key), "%s.pool%d.max_alloc", prefix, i);
- ret = dict_get_int32(dict, key, &maxalloc);
+ keylen = snprintf(key, sizeof(key), "%s.pool%d.max_alloc", prefix, i);
+ ret = dict_get_int32n(dict, key, keylen, &maxalloc);
if (ret)
goto out;
- snprintf(key, sizeof(key), "%s.pool%d.max-stdalloc", prefix, i);
- ret = dict_get_int32(dict, key, &maxstdalloc);
+ keylen = snprintf(key, sizeof(key), "%s.pool%d.max-stdalloc", prefix,
+ i);
+ ret = dict_get_int32n(dict, key, keylen, &maxstdalloc);
if (ret)
goto out;
@@ -7110,7 +6103,7 @@ out:
return;
}
-void
+static void
cli_print_volume_status_mem(dict_t *dict, gf_boolean_t notbrick)
{
int ret = -1;
@@ -7118,7 +6111,7 @@ cli_print_volume_status_mem(dict_t *dict, gf_boolean_t notbrick)
char *hostname = NULL;
char *path = NULL;
int online = -1;
- char key[1024] = {
+ char key[64] = {
0,
};
int brick_index_max = -1;
@@ -7129,15 +6122,15 @@ cli_print_volume_status_mem(dict_t *dict, gf_boolean_t notbrick)
GF_ASSERT(dict);
- ret = dict_get_str(dict, "volname", &volname);
+ ret = dict_get_str_sizen(dict, "volname", &volname);
if (ret)
goto out;
cli_out("Memory status for volume : %s", volname);
- ret = dict_get_int32(dict, "brick-index-max", &brick_index_max);
+ ret = dict_get_int32_sizen(dict, "brick-index-max", &brick_index_max);
if (ret)
goto out;
- ret = dict_get_int32(dict, "other-count", &other_count);
+ ret = dict_get_int32_sizen(dict, "other-count", &other_count);
if (ret)
goto out;
@@ -7242,14 +6235,14 @@ out:
return;
}
-void
+static void
cli_print_volume_status_client_list(dict_t *dict, gf_boolean_t notbrick)
{
int ret = -1;
char *volname = NULL;
int client_count = 0;
int current_count = 0;
- char key[1024] = {
+ char key[64] = {
0,
};
int i = 0;
@@ -7257,7 +6250,6 @@ cli_print_volume_status_client_list(dict_t *dict, gf_boolean_t notbrick)
char *name = NULL;
gf_boolean_t is_fuse_done = _gf_false;
gf_boolean_t is_gfapi_done = _gf_false;
- gf_boolean_t is_tierd_done = _gf_false;
gf_boolean_t is_rebalance_done = _gf_false;
gf_boolean_t is_glustershd_done = _gf_false;
gf_boolean_t is_quotad_done = _gf_false;
@@ -7265,12 +6257,12 @@ cli_print_volume_status_client_list(dict_t *dict, gf_boolean_t notbrick)
GF_ASSERT(dict);
- ret = dict_get_str(dict, "volname", &volname);
+ ret = dict_get_str_sizen(dict, "volname", &volname);
if (ret)
goto out;
cli_out("Client connections for volume %s", volname);
- ret = dict_get_int32(dict, "client-count", &client_count);
+ ret = dict_get_int32_sizen(dict, "client-count", &client_count);
if (ret)
goto out;
@@ -7284,7 +6276,7 @@ cli_print_volume_status_client_list(dict_t *dict, gf_boolean_t notbrick)
if (!strncmp(name, "fuse", 4)) {
if (!is_fuse_done) {
is_fuse_done = _gf_true;
- ret = dict_get_int32(dict, "fuse-count", &current_count);
+ ret = dict_get_int32_sizen(dict, "fuse-count", &current_count);
if (ret)
goto out;
total = total + current_count;
@@ -7294,17 +6286,7 @@ cli_print_volume_status_client_list(dict_t *dict, gf_boolean_t notbrick)
} else if (!strncmp(name, "gfapi", 5)) {
if (!is_gfapi_done) {
is_gfapi_done = _gf_true;
- ret = dict_get_int32(dict, "gfapi-count", &current_count);
- if (ret)
- goto out;
- total = total + current_count;
- goto print;
- }
- continue;
- } else if (!strcmp(name, "tierd")) {
- if (!is_tierd_done) {
- is_tierd_done = _gf_true;
- ret = dict_get_int32(dict, "tierd-count", &current_count);
+ ret = dict_get_int32_sizen(dict, "gfapi-count", &current_count);
if (ret)
goto out;
total = total + current_count;
@@ -7314,7 +6296,8 @@ cli_print_volume_status_client_list(dict_t *dict, gf_boolean_t notbrick)
} else if (!strcmp(name, "rebalance")) {
if (!is_rebalance_done) {
is_rebalance_done = _gf_true;
- ret = dict_get_int32(dict, "rebalance-count", &current_count);
+ ret = dict_get_int32_sizen(dict, "rebalance-count",
+ &current_count);
if (ret)
goto out;
total = total + current_count;
@@ -7324,7 +6307,8 @@ cli_print_volume_status_client_list(dict_t *dict, gf_boolean_t notbrick)
} else if (!strcmp(name, "glustershd")) {
if (!is_glustershd_done) {
is_glustershd_done = _gf_true;
- ret = dict_get_int32(dict, "glustershd-count", &current_count);
+ ret = dict_get_int32_sizen(dict, "glustershd-count",
+ &current_count);
if (ret)
goto out;
total = total + current_count;
@@ -7334,7 +6318,8 @@ cli_print_volume_status_client_list(dict_t *dict, gf_boolean_t notbrick)
} else if (!strcmp(name, "quotad")) {
if (!is_quotad_done) {
is_quotad_done = _gf_true;
- ret = dict_get_int32(dict, "quotad-count", &current_count);
+ ret = dict_get_int32_sizen(dict, "quotad-count",
+ &current_count);
if (ret)
goto out;
total = total + current_count;
@@ -7344,7 +6329,7 @@ cli_print_volume_status_client_list(dict_t *dict, gf_boolean_t notbrick)
} else if (!strcmp(name, "snapd")) {
if (!is_snapd_done) {
is_snapd_done = _gf_true;
- ret = dict_get_int32(dict, "snapd-count", &current_count);
+ ret = dict_get_int32_sizen(dict, "snapd-count", &current_count);
if (ret)
goto out;
total = total + current_count;
@@ -7363,7 +6348,7 @@ out:
return;
}
-void
+static void
cli_print_volume_status_clients(dict_t *dict, gf_boolean_t notbrick)
{
int ret = -1;
@@ -7379,7 +6364,7 @@ cli_print_volume_status_clients(dict_t *dict, gf_boolean_t notbrick)
uint64_t bytesread = 0;
uint64_t byteswrite = 0;
uint32_t opversion = 0;
- char key[1024] = {
+ char key[128] = {
0,
};
int i = 0;
@@ -7387,15 +6372,15 @@ cli_print_volume_status_clients(dict_t *dict, gf_boolean_t notbrick)
GF_ASSERT(dict);
- ret = dict_get_str(dict, "volname", &volname);
+ ret = dict_get_str_sizen(dict, "volname", &volname);
if (ret)
goto out;
cli_out("Client connections for volume %s", volname);
- ret = dict_get_int32(dict, "brick-index-max", &brick_index_max);
+ ret = dict_get_int32_sizen(dict, "brick-index-max", &brick_index_max);
if (ret)
goto out;
- ret = dict_get_int32(dict, "other-count", &other_count);
+ ret = dict_get_int32_sizen(dict, "other-count", &other_count);
if (ret)
goto out;
@@ -7468,7 +6453,8 @@ out:
return;
}
-void
+#ifdef DEBUG /* this function is only used in debug */
+static void
cli_print_volume_status_inode_entry(dict_t *dict, char *prefix)
{
int ret = -1;
@@ -7537,8 +6523,9 @@ cli_print_volume_status_inode_entry(dict_t *dict, char *prefix)
out:
return;
}
+#endif
-void
+static void
cli_print_volume_status_itables(dict_t *dict, char *prefix)
{
int ret = -1;
@@ -7548,15 +6535,25 @@ cli_print_volume_status_itables(dict_t *dict, char *prefix)
uint32_t active_size = 0;
uint32_t lru_size = 0;
uint32_t purge_size = 0;
+ uint32_t lru_limit = 0;
+#ifdef DEBUG
int i = 0;
-
+#endif
GF_ASSERT(dict);
GF_ASSERT(prefix);
+ snprintf(key, sizeof(key), "%s.lru_limit", prefix);
+ ret = dict_get_uint32(dict, key, &lru_limit);
+ if (ret)
+ goto out;
+ cli_out("LRU limit : %u", lru_limit);
+
snprintf(key, sizeof(key), "%s.active_size", prefix);
ret = dict_get_uint32(dict, key, &active_size);
if (ret)
goto out;
+
+#ifdef DEBUG
if (active_size != 0) {
cli_out("Active inodes:");
cli_out("%-40s %14s %14s %9s", "GFID", "Lookups", "Ref", "IA type");
@@ -7567,11 +6564,17 @@ cli_print_volume_status_itables(dict_t *dict, char *prefix)
cli_print_volume_status_inode_entry(dict, key);
}
cli_out(" ");
+#else
+ cli_out("Active Inodes : %u", active_size);
+
+#endif
snprintf(key, sizeof(key), "%s.lru_size", prefix);
ret = dict_get_uint32(dict, key, &lru_size);
if (ret)
goto out;
+
+#ifdef DEBUG
if (lru_size != 0) {
cli_out("LRU inodes:");
cli_out("%-40s %14s %14s %9s", "GFID", "Lookups", "Ref", "IA type");
@@ -7582,11 +6585,15 @@ cli_print_volume_status_itables(dict_t *dict, char *prefix)
cli_print_volume_status_inode_entry(dict, key);
}
cli_out(" ");
+#else
+ cli_out("LRU Inodes : %u", lru_size);
+#endif
snprintf(key, sizeof(key), "%s.purge_size", prefix);
ret = dict_get_uint32(dict, key, &purge_size);
if (ret)
goto out;
+#ifdef DEBUG
if (purge_size != 0) {
cli_out("Purged inodes:");
cli_out("%-40s %14s %14s %9s", "GFID", "Lookups", "Ref", "IA type");
@@ -7596,12 +6603,15 @@ cli_print_volume_status_itables(dict_t *dict, char *prefix)
snprintf(key, sizeof(key), "%s.purge%d", prefix, i);
cli_print_volume_status_inode_entry(dict, key);
}
+#else
+ cli_out("Purge Inodes : %u", purge_size);
+#endif
out:
return;
}
-void
+static void
cli_print_volume_status_inode(dict_t *dict, gf_boolean_t notbrick)
{
int ret = -1;
@@ -7613,7 +6623,7 @@ cli_print_volume_status_inode(dict_t *dict, gf_boolean_t notbrick)
char *path = NULL;
int online = -1;
int conn_count = 0;
- char key[1024] = {
+ char key[64] = {
0,
};
int i = 0;
@@ -7621,15 +6631,15 @@ cli_print_volume_status_inode(dict_t *dict, gf_boolean_t notbrick)
GF_ASSERT(dict);
- ret = dict_get_str(dict, "volname", &volname);
+ ret = dict_get_str_sizen(dict, "volname", &volname);
if (ret)
goto out;
cli_out("Inode tables for volume %s", volname);
- ret = dict_get_int32(dict, "brick-index-max", &brick_index_max);
+ ret = dict_get_int32_sizen(dict, "brick-index-max", &brick_index_max);
if (ret)
goto out;
- ret = dict_get_int32(dict, "other-count", &other_count);
+ ret = dict_get_int32_sizen(dict, "other-count", &other_count);
if (ret)
goto out;
@@ -7686,7 +6696,7 @@ void
cli_print_volume_status_fdtable(dict_t *dict, char *prefix)
{
int ret = -1;
- char key[1024] = {
+ char key[256] = {
0,
};
int refcount = 0;
@@ -7754,7 +6764,7 @@ out:
return;
}
-void
+static void
cli_print_volume_status_fd(dict_t *dict, gf_boolean_t notbrick)
{
int ret = -1;
@@ -7766,7 +6776,7 @@ cli_print_volume_status_fd(dict_t *dict, gf_boolean_t notbrick)
char *path = NULL;
int online = -1;
int conn_count = 0;
- char key[1024] = {
+ char key[64] = {
0,
};
int i = 0;
@@ -7774,15 +6784,15 @@ cli_print_volume_status_fd(dict_t *dict, gf_boolean_t notbrick)
GF_ASSERT(dict);
- ret = dict_get_str(dict, "volname", &volname);
+ ret = dict_get_str_sizen(dict, "volname", &volname);
if (ret)
goto out;
cli_out("FD tables for volume %s", volname);
- ret = dict_get_int32(dict, "brick-index-max", &brick_index_max);
+ ret = dict_get_int32_sizen(dict, "brick-index-max", &brick_index_max);
if (ret)
goto out;
- ret = dict_get_int32(dict, "other-count", &other_count);
+ ret = dict_get_int32_sizen(dict, "other-count", &other_count);
if (ret)
goto out;
@@ -7835,7 +6845,7 @@ out:
return;
}
-void
+static void
cli_print_volume_status_call_frame(dict_t *dict, char *prefix)
{
int ret = -1;
@@ -7899,11 +6909,11 @@ cli_print_volume_status_call_frame(dict_t *dict, char *prefix)
cli_out(" Unwind To = %s", unwind_to);
}
-void
+static void
cli_print_volume_status_call_stack(dict_t *dict, char *prefix)
{
int ret = -1;
- char key[1024] = {
+ char key[256] = {
0,
};
int uid = 0;
@@ -7914,7 +6924,7 @@ cli_print_volume_status_call_stack(dict_t *dict, char *prefix)
int count = 0;
int i = 0;
- if (!dict || !prefix)
+ if (!prefix)
return;
snprintf(key, sizeof(key), "%s.uid", prefix);
@@ -7966,7 +6976,7 @@ cli_print_volume_status_call_stack(dict_t *dict, char *prefix)
cli_out(" ");
}
-void
+static void
cli_print_volume_status_callpool(dict_t *dict, gf_boolean_t notbrick)
{
int ret = -1;
@@ -7978,7 +6988,7 @@ cli_print_volume_status_callpool(dict_t *dict, gf_boolean_t notbrick)
char *path = NULL;
int online = -1;
int call_count = 0;
- char key[1024] = {
+ char key[64] = {
0,
};
int i = 0;
@@ -7986,15 +6996,15 @@ cli_print_volume_status_callpool(dict_t *dict, gf_boolean_t notbrick)
GF_ASSERT(dict);
- ret = dict_get_str(dict, "volname", &volname);
+ ret = dict_get_str_sizen(dict, "volname", &volname);
if (ret)
goto out;
cli_out("Pending calls for volume %s", volname);
- ret = dict_get_int32(dict, "brick-index-max", &brick_index_max);
+ ret = dict_get_int32_sizen(dict, "brick-index-max", &brick_index_max);
if (ret)
goto out;
- ret = dict_get_int32(dict, "other-count", &other_count);
+ ret = dict_get_int32_sizen(dict, "other-count", &other_count);
if (ret)
goto out;
@@ -8071,16 +7081,16 @@ cli_print_volume_status_tasks(dict_t *dict)
};
char *brick = NULL;
- ret = dict_get_str(dict, "volname", &volname);
- if (ret)
- goto out;
-
- ret = dict_get_int32(dict, "tasks", &task_count);
+ ret = dict_get_int32_sizen(dict, "tasks", &task_count);
if (ret) {
gf_log("cli", GF_LOG_ERROR, "Failed to get tasks count");
return;
}
+ ret = dict_get_str_sizen(dict, "volname", &volname);
+ if (ret)
+ goto out;
+
cli_out("Task Status of Volume %s", volname);
cli_print_line(CLI_BRICK_STATUS_LINE_LEN);
@@ -8149,7 +7159,7 @@ gf_cli_status_cbk(struct rpc_req *req, struct iovec *iov, int count,
int pid = -1;
uint32_t cmd = 0;
gf_boolean_t notbrick = _gf_false;
- char key[1024] = {
+ char key[64] = {
0,
};
char *hostname = NULL;
@@ -8174,7 +7184,7 @@ gf_cli_status_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ XDR_DECODE_FAIL);
goto out;
}
@@ -8196,8 +7206,7 @@ gf_cli_status_cbk(struct rpc_req *req, struct iovec *iov, int count,
snprintf(msg, sizeof(msg), "%s", rsp.op_errstr);
else
snprintf(msg, sizeof(msg),
- "Unable to obtain volume "
- "status information.");
+ "Unable to obtain volume status information.");
if (global_state->mode & GLUSTER_MODE_XML) {
if (!local->all)
@@ -8218,8 +7227,11 @@ gf_cli_status_cbk(struct rpc_req *req, struct iovec *iov, int count,
}
dict = dict_new();
- if (!dict)
+ if (!dict) {
+ gf_log(THIS->name, GF_LOG_ERROR, "Failed to create the dict");
+ ret = -1;
goto out;
+ }
ret = dict_unserialize(rsp.dict.dict_val, rsp.dict.dict_len, &dict);
if (ret)
@@ -8241,33 +7253,25 @@ gf_cli_status_cbk(struct rpc_req *req, struct iovec *iov, int count,
goto out;
}
- if ((cmd & GF_CLI_STATUS_NFS) || (cmd & GF_CLI_STATUS_SHD) ||
- (cmd & GF_CLI_STATUS_QUOTAD) || (cmd & GF_CLI_STATUS_SNAPD) ||
- (cmd & GF_CLI_STATUS_BITD) || (cmd & GF_CLI_STATUS_SCRUB) ||
- (cmd & GF_CLI_STATUS_TIERD))
- notbrick = _gf_true;
-
if (global_state->mode & GLUSTER_MODE_XML) {
if (!local->all) {
ret = cli_xml_output_vol_status_begin(local, rsp.op_ret,
rsp.op_errno, rsp.op_errstr);
if (ret) {
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
goto xml_end;
}
}
if (cmd & GF_CLI_STATUS_TASKS) {
ret = cli_xml_output_vol_status_tasks_detail(local, dict);
if (ret) {
- gf_log("cli", GF_LOG_ERROR,
- "Error outputting "
- "to xml");
+ gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
goto xml_end;
}
} else {
ret = cli_xml_output_vol_status(local, dict);
if (ret) {
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
goto xml_end;
}
}
@@ -8276,18 +7280,17 @@ gf_cli_status_cbk(struct rpc_req *req, struct iovec *iov, int count,
if (!local->all) {
ret = cli_xml_output_vol_status_end(local);
if (ret) {
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
}
}
goto out;
}
- status.brick = GF_MALLOC(PATH_MAX + 256, gf_common_mt_strdup);
- if (!status.brick) {
- errno = ENOMEM;
- ret = -1;
- goto out;
- }
+ if ((cmd & GF_CLI_STATUS_NFS) || (cmd & GF_CLI_STATUS_SHD) ||
+ (cmd & GF_CLI_STATUS_QUOTAD) || (cmd & GF_CLI_STATUS_SNAPD) ||
+ (cmd & GF_CLI_STATUS_BITD) || (cmd & GF_CLI_STATUS_SCRUB))
+ notbrick = _gf_true;
+
switch (cmd & GF_CLI_STATUS_MASK) {
case GF_CLI_STATUS_MEM:
cli_print_volume_status_mem(dict, notbrick);
@@ -8321,25 +7324,25 @@ gf_cli_status_cbk(struct rpc_req *req, struct iovec *iov, int count,
break;
}
- ret = dict_get_str(dict, "volname", &volname);
+ ret = dict_get_str_sizen(dict, "volname", &volname);
if (ret)
goto out;
- ret = dict_get_int32(dict, "brick-index-max", &brick_index_max);
+ ret = dict_get_int32_sizen(dict, "brick-index-max", &brick_index_max);
if (ret)
goto out;
- ret = dict_get_int32(dict, "other-count", &other_count);
+ ret = dict_get_int32_sizen(dict, "other-count", &other_count);
if (ret)
goto out;
index_max = brick_index_max + other_count;
- ret = dict_get_int32(dict, "type", &type);
+ ret = dict_get_int32_sizen(dict, "type", &type);
if (ret)
goto out;
- ret = dict_get_int32(dict, "hot_brick_count", &hot_brick_count);
+ ret = dict_get_int32_sizen(dict, "hot_brick_count", &hot_brick_count);
if (ret)
goto out;
@@ -8350,13 +7353,15 @@ gf_cli_status_cbk(struct rpc_req *req, struct iovec *iov, int count,
"Gluster process", "TCP Port", "RDMA Port", "Online", "Pid");
cli_print_line(CLI_BRICK_STATUS_LINE_LEN);
}
- if (type == GF_CLUSTER_TYPE_TIER) {
- cli_out("Hot Bricks:");
+
+ status.brick = GF_MALLOC(PATH_MAX + 256, gf_common_mt_strdup);
+ if (!status.brick) {
+ errno = ENOMEM;
+ ret = -1;
+ goto out;
}
+
for (i = 0; i <= index_max; i++) {
- if (type == GF_CLUSTER_TYPE_TIER && i == hot_brick_count) {
- cli_out("Cold Bricks:");
- }
status.rdma_port = 0;
snprintf(key, sizeof(key), "brick%d.hostname", i);
@@ -8372,14 +7377,13 @@ gf_cli_status_cbk(struct rpc_req *req, struct iovec *iov, int count,
/* Brick/not-brick is handled separately here as all
* types of nodes are contained in the default output
*/
- memset(status.brick, 0, PATH_MAX + 255);
+ status.brick[0] = '\0';
if (!strcmp(hostname, "NFS Server") ||
!strcmp(hostname, "Self-heal Daemon") ||
!strcmp(hostname, "Quota Daemon") ||
!strcmp(hostname, "Snapshot Daemon") ||
!strcmp(hostname, "Scrubber Daemon") ||
- !strcmp(hostname, "Bitrot Daemon") ||
- !strcmp(hostname, "Tier Daemon"))
+ !strcmp(hostname, "Bitrot Daemon"))
snprintf(status.brick, PATH_MAX + 255, "%s on %s", hostname, path);
else {
snprintf(key, sizeof(key), "brick%d.rdma_port", i);
@@ -8421,6 +7425,9 @@ gf_cli_status_cbk(struct rpc_req *req, struct iovec *iov, int count,
} else {
cli_print_brick_status(&status);
}
+
+ /* Allocatated memory using gf_asprintf*/
+ GF_FREE(status.pid_str);
}
cli_out(" ");
@@ -8438,10 +7445,11 @@ out:
}
cli_cmd_broadcast_response(ret);
+ gf_free_xdr_cli_rsp(rsp);
return ret;
}
-int32_t
+static int32_t
gf_cli_status_volume(call_frame_t *frame, xlator_t *this, void *data)
{
gf_cli_req req = {{
@@ -8450,20 +7458,17 @@ gf_cli_status_volume(call_frame_t *frame, xlator_t *this, void *data)
int ret = -1;
dict_t *dict = NULL;
- if (!frame || !this || !data)
- goto out;
-
dict = data;
ret = cli_to_glusterd(&req, frame, gf_cli_status_cbk,
(xdrproc_t)xdr_gf_cli_req, dict,
GLUSTER_CLI_STATUS_VOLUME, this, cli_rpc_prog, NULL);
-out:
- gf_log("cli", GF_LOG_DEBUG, "Returning: %d", ret);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
+ GF_FREE(req.dict.dict_val);
return ret;
}
-int
+static int
gf_cli_status_volume_all(call_frame_t *frame, xlator_t *this, void *data)
{
int i = 0;
@@ -8499,7 +7504,7 @@ gf_cli_status_volume_all(call_frame_t *frame, xlator_t *this, void *data)
if (ret)
goto out;
- ret = dict_get_int32((dict_t *)vol_dict, "vol_count", &vol_count);
+ ret = dict_get_int32_sizen((dict_t *)vol_dict, "vol_count", &vol_count);
if (ret) {
cli_err("Failed to get names of volumes");
goto out;
@@ -8513,7 +7518,7 @@ gf_cli_status_volume_all(call_frame_t *frame, xlator_t *this, void *data)
// TODO: Pass proper op_* values
ret = cli_xml_output_vol_status_begin(local, 0, 0, NULL);
if (ret) {
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
goto xml_end;
}
}
@@ -8529,12 +7534,12 @@ gf_cli_status_volume_all(call_frame_t *frame, xlator_t *this, void *data)
if (!dict)
goto out;
- snprintf(key, sizeof(key), "vol%d", i);
- ret = dict_get_str(vol_dict, key, &volname);
+ ret = snprintf(key, sizeof(key), "vol%d", i);
+ ret = dict_get_strn(vol_dict, key, ret, &volname);
if (ret)
goto out;
- ret = dict_set_str(dict, "volname", volname);
+ ret = dict_set_str_sizen(dict, "volname", volname);
if (ret)
goto out;
@@ -8591,7 +7596,7 @@ gf_cli_mount_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf1_cli_mount_rsp);
if (ret < 0) {
gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ XDR_DECODE_FAIL);
goto out;
}
@@ -8609,10 +7614,13 @@ gf_cli_mount_cbk(struct rpc_req *req, struct iovec *iov, int count,
out:
cli_cmd_broadcast_response(ret);
+ if (rsp.path) {
+ free(rsp.path);
+ }
return ret;
}
-int32_t
+static int32_t
gf_cli_mount(call_frame_t *frame, xlator_t *this, void *data)
{
gf1_cli_mount_req req = {
@@ -8642,7 +7650,8 @@ gf_cli_mount(call_frame_t *frame, xlator_t *this, void *data)
(xdrproc_t)xdr_gf1_cli_mount_req);
out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ GF_FREE(req.dict.dict_val);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
return ret;
}
@@ -8664,7 +7673,7 @@ gf_cli_umount_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf1_cli_umount_rsp);
if (ret < 0) {
gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ XDR_DECODE_FAIL);
goto out;
}
@@ -8682,7 +7691,7 @@ out:
return ret;
}
-int32_t
+static int32_t
gf_cli_umount(call_frame_t *frame, xlator_t *this, void *data)
{
gf1_cli_umount_req req = {
@@ -8696,9 +7705,9 @@ gf_cli_umount(call_frame_t *frame, xlator_t *this, void *data)
dict = data;
- ret = dict_get_str(dict, "path", &req.path);
+ ret = dict_get_str_sizen(dict, "path", &req.path);
if (ret == 0)
- ret = dict_get_int32(dict, "lazy", &req.lazy);
+ ret = dict_get_int32_sizen(dict, "lazy", &req.lazy);
if (ret) {
ret = -1;
@@ -8710,11 +7719,11 @@ gf_cli_umount(call_frame_t *frame, xlator_t *this, void *data)
(xdrproc_t)xdr_gf1_cli_umount_req);
out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
return ret;
}
-void
+static void
cmd_heal_volume_statistics_out(dict_t *dict, int brick)
{
uint64_t num_entries = 0;
@@ -8795,18 +7804,18 @@ out:
return;
}
-void
+static void
cmd_heal_volume_brick_out(dict_t *dict, int brick)
{
uint64_t num_entries = 0;
int ret = 0;
- char key[256] = {0};
+ char key[64] = {0};
char *hostname = NULL;
char *path = NULL;
char *status = NULL;
uint64_t i = 0;
uint32_t time = 0;
- char timestr[32] = {0};
+ char timestr[GF_TIMESTR_SIZE] = {0};
char *shd_status = NULL;
snprintf(key, sizeof key, "%d-hostname", brick);
@@ -8821,7 +7830,7 @@ cmd_heal_volume_brick_out(dict_t *dict, int brick)
snprintf(key, sizeof key, "%d-status", brick);
ret = dict_get_str(dict, key, &status);
- if (status && strlen(status))
+ if (status && status[0] != '\0')
cli_out("Status: %s", status);
snprintf(key, sizeof key, "%d-shd-status", brick);
@@ -8857,12 +7866,12 @@ out:
return;
}
-void
+static void
cmd_heal_volume_statistics_heal_count_out(dict_t *dict, int brick)
{
uint64_t num_entries = 0;
int ret = 0;
- char key[256] = {0};
+ char key[64] = {0};
char *hostname = NULL;
char *path = NULL;
char *status = NULL;
@@ -8899,18 +7908,16 @@ out:
return;
}
-int
+static int
gf_is_cli_heal_get_command(gf_xl_afr_op_t heal_op)
{
/* If the command is get command value is 1 otherwise 0, for
invalid commands -1 */
- int get_cmds[GF_SHD_OP_HEAL_DISABLE + 1] = {
+ static int get_cmds[GF_SHD_OP_HEAL_DISABLE + 1] = {
[GF_SHD_OP_INVALID] = -1,
[GF_SHD_OP_HEAL_INDEX] = 0,
[GF_SHD_OP_HEAL_FULL] = 0,
[GF_SHD_OP_INDEX_SUMMARY] = 1,
- [GF_SHD_OP_HEALED_FILES] = 1,
- [GF_SHD_OP_HEAL_FAILED_FILES] = 1,
[GF_SHD_OP_SPLIT_BRAIN_FILES] = 1,
[GF_SHD_OP_STATISTICS] = 1,
[GF_SHD_OP_STATISTICS_HEAL_COUNT] = 1,
@@ -8939,9 +7946,9 @@ gf_cli_heal_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
int brick_count = 0;
int i = 0;
gf_xl_afr_op_t heal_op = GF_SHD_OP_INVALID;
- char *operation = NULL;
- char *substr = NULL;
- char *heal_op_str = NULL;
+ const char *operation = NULL;
+ const char *substr = NULL;
+ const char *heal_op_str = NULL;
GF_ASSERT(myframe);
@@ -8957,25 +7964,23 @@ gf_cli_heal_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
- gf_log(frame->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ gf_log(frame->this->name, GF_LOG_ERROR, XDR_DECODE_FAIL);
goto out;
}
- ret = dict_get_int32(local->dict, "heal-op", (int32_t *)&heal_op);
+ ret = dict_get_int32_sizen(local->dict, "heal-op", (int32_t *)&heal_op);
// TODO: Proper XML output
//#if (HAVE_LIB_XML)
// if (global_state->mode & GLUSTER_MODE_XML) {
// ret = cli_xml_output_dict ("volHeal", dict, rsp.op_ret,
// rsp.op_errno, rsp.op_errstr);
// if (ret)
- // gf_log ("cli", GF_LOG_ERROR,
- // "Error outputting to xml");
+ // gf_log ("cli", GF_LOG_ERROR, XML_ERROR);
// goto out;
// }
//#endif
- ret = dict_get_str(local->dict, "volname", &volname);
+ ret = dict_get_str_sizen(local->dict, "volname", &volname);
if (ret) {
gf_log(frame->this->name, GF_LOG_ERROR, "failed to get volname");
goto out;
@@ -8989,26 +7994,16 @@ gf_cli_heal_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
case GF_SHD_OP_HEAL_INDEX:
operation = "Launching heal operation ";
heal_op_str = "to perform index self heal";
- substr =
- "\nUse heal info commands to check"
- " status.";
+ substr = "\nUse heal info commands to check status.";
break;
case GF_SHD_OP_HEAL_FULL:
operation = "Launching heal operation ";
heal_op_str = "to perform full self heal";
- substr =
- "\nUse heal info commands to check"
- " status.";
+ substr = "\nUse heal info commands to check status.";
break;
case GF_SHD_OP_INDEX_SUMMARY:
heal_op_str = "list of entries to be healed";
break;
- case GF_SHD_OP_HEALED_FILES:
- heal_op_str = "list of healed entries";
- break;
- case GF_SHD_OP_HEAL_FAILED_FILES:
- heal_op_str = "list of heal failed entries";
- break;
case GF_SHD_OP_SPLIT_BRAIN_FILES:
heal_op_str = "list of split brain entries";
break;
@@ -9021,12 +8016,14 @@ gf_cli_heal_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
case GF_SHD_OP_STATISTICS_HEAL_COUNT_PER_REPLICA:
heal_op_str = "count of entries to be healed per replica";
break;
- /* The below 4 cases are never hit; they're coded only to make
- * compiler warnings go away.*/
case GF_SHD_OP_SBRAIN_HEAL_FROM_BIGGER_FILE:
case GF_SHD_OP_SBRAIN_HEAL_FROM_LATEST_MTIME:
case GF_SHD_OP_SBRAIN_HEAL_FROM_BRICK:
case GF_SHD_OP_HEAL_SUMMARY:
+ case GF_SHD_OP_HEALED_FILES:
+ case GF_SHD_OP_HEAL_FAILED_FILES:
+ /* These cases are never hit; they're coded just to silence the
+ * compiler warnings.*/
break;
case GF_SHD_OP_INVALID:
@@ -9076,17 +8073,17 @@ gf_cli_heal_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = dict_unserialize(rsp.dict.dict_val, rsp.dict.dict_len, &dict);
if (ret) {
- gf_log("", GF_LOG_ERROR, "Unable to allocate memory");
+ gf_log("", GF_LOG_ERROR, DICT_UNSERIALIZE_FAIL);
goto out;
- } else {
- dict->extra_stdfree = rsp.dict.dict_val;
}
- ret = dict_get_int32(dict, "count", &brick_count);
+
+ ret = dict_get_int32_sizen(dict, "count", &brick_count);
if (ret)
goto out;
if (!brick_count) {
cli_err("All bricks of volume %s are down.", volname);
+ ret = -1;
goto out;
}
@@ -9101,8 +8098,6 @@ gf_cli_heal_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
cmd_heal_volume_statistics_heal_count_out(dict, i);
break;
case GF_SHD_OP_INDEX_SUMMARY:
- case GF_SHD_OP_HEALED_FILES:
- case GF_SHD_OP_HEAL_FAILED_FILES:
case GF_SHD_OP_SPLIT_BRAIN_FILES:
for (i = 0; i < brick_count; i++)
cmd_heal_volume_brick_out(dict, i);
@@ -9115,13 +8110,13 @@ gf_cli_heal_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
out:
cli_cmd_broadcast_response(ret);
- free(rsp.op_errstr);
+ gf_free_xdr_cli_rsp(rsp);
if (dict)
dict_unref(dict);
return ret;
}
-int32_t
+static int32_t
gf_cli_heal_volume(call_frame_t *frame, xlator_t *this, void *data)
{
gf_cli_req req = {{
@@ -9130,26 +8125,20 @@ gf_cli_heal_volume(call_frame_t *frame, xlator_t *this, void *data)
int ret = 0;
dict_t *dict = NULL;
- if (!frame || !this || !data) {
- ret = -1;
- goto out;
- }
-
dict = data;
ret = cli_to_glusterd(&req, frame, gf_cli_heal_volume_cbk,
(xdrproc_t)xdr_gf_cli_req, dict,
GLUSTER_CLI_HEAL_VOLUME, this, cli_rpc_prog, NULL);
-out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
GF_FREE(req.dict.dict_val);
return ret;
}
-int32_t
+static int32_t
gf_cli_statedump_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
@@ -9157,9 +8146,7 @@ gf_cli_statedump_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
0,
};
int ret = -1;
- char msg[1024] = {
- 0,
- };
+ char msg[1024] = "Volume statedump successful";
GF_ASSERT(myframe);
@@ -9169,20 +8156,18 @@ gf_cli_statedump_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ XDR_DECODE_FAIL);
goto out;
}
gf_log("cli", GF_LOG_DEBUG, "Received response to statedump");
if (rsp.op_ret)
snprintf(msg, sizeof(msg), "%s", rsp.op_errstr);
- else
- snprintf(msg, sizeof(msg), "Volume statedump successful");
if (global_state->mode & GLUSTER_MODE_XML) {
ret = cli_xml_output_str("volStatedump", msg, rsp.op_ret, rsp.op_errno,
rsp.op_errstr);
if (ret)
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
goto out;
}
@@ -9194,10 +8179,11 @@ gf_cli_statedump_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
out:
cli_cmd_broadcast_response(ret);
+ gf_free_xdr_cli_rsp(rsp);
return ret;
}
-int32_t
+static int32_t
gf_cli_statedump_volume(call_frame_t *frame, xlator_t *this, void *data)
{
gf_cli_req req = {{
@@ -9206,23 +8192,18 @@ gf_cli_statedump_volume(call_frame_t *frame, xlator_t *this, void *data)
dict_t *options = NULL;
int ret = -1;
- if (!frame || !this || !data)
- goto out;
-
options = data;
ret = cli_to_glusterd(
&req, frame, gf_cli_statedump_volume_cbk, (xdrproc_t)xdr_gf_cli_req,
options, GLUSTER_CLI_STATEDUMP_VOLUME, this, cli_rpc_prog, NULL);
-
-out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
GF_FREE(req.dict.dict_val);
return ret;
}
-int32_t
+static int32_t
gf_cli_list_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
@@ -9247,7 +8228,7 @@ gf_cli_list_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ XDR_DECODE_FAIL);
goto out;
}
@@ -9259,7 +8240,7 @@ gf_cli_list_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = dict_unserialize(rsp.dict.dict_val, rsp.dict.dict_len, &dict);
if (ret) {
- gf_log("cli", GF_LOG_ERROR, "Unable to allocate memory");
+ gf_log("cli", GF_LOG_ERROR, DICT_UNSERIALIZE_FAIL);
goto out;
}
@@ -9267,14 +8248,14 @@ gf_cli_list_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = cli_xml_output_vol_list(dict, rsp.op_ret, rsp.op_errno,
rsp.op_errstr);
if (ret)
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
goto out;
}
if (rsp.op_ret)
cli_err("%s", rsp.op_errstr);
else {
- ret = dict_get_int32(dict, "count", &vol_count);
+ ret = dict_get_int32_sizen(dict, "count", &vol_count);
if (ret)
goto out;
@@ -9283,8 +8264,8 @@ gf_cli_list_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
goto out;
}
for (i = 0; i < vol_count; i++) {
- snprintf(key, sizeof(key), "volume%d", i);
- ret = dict_get_str(dict, key, &volname);
+ ret = snprintf(key, sizeof(key), "volume%d", i);
+ ret = dict_get_strn(dict, key, ret, &volname);
if (ret)
goto out;
cli_out("%s", volname);
@@ -9295,10 +8276,14 @@ gf_cli_list_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
out:
cli_cmd_broadcast_response(ret);
+ gf_free_xdr_cli_rsp(rsp);
+
+ if (dict)
+ dict_unref(dict);
return ret;
}
-int32_t
+static int32_t
gf_cli_list_volume(call_frame_t *frame, xlator_t *this, void *data)
{
int ret = -1;
@@ -9306,19 +8291,14 @@ gf_cli_list_volume(call_frame_t *frame, xlator_t *this, void *data)
0,
}};
- if (!frame || !this)
- goto out;
-
ret = cli_cmd_submit(NULL, &req, frame, cli_rpc_prog,
GLUSTER_CLI_LIST_VOLUME, NULL, this,
gf_cli_list_volume_cbk, (xdrproc_t)xdr_gf_cli_req);
-
-out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
return ret;
}
-int32_t
+static int32_t
gf_cli_clearlocks_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
@@ -9327,7 +8307,6 @@ gf_cli_clearlocks_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
};
int ret = -1;
char *lk_summary = NULL;
- char *volname = NULL;
dict_t *dict = NULL;
GF_ASSERT(myframe);
@@ -9338,7 +8317,7 @@ gf_cli_clearlocks_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ XDR_DECODE_FAIL);
goto out;
}
gf_log("cli", GF_LOG_DEBUG, "Received response to clear-locks");
@@ -9364,24 +8343,14 @@ gf_cli_clearlocks_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = dict_unserialize(rsp.dict.dict_val, rsp.dict.dict_len, &dict);
if (ret) {
- gf_log("cli", GF_LOG_ERROR,
- "Unable to serialize response dictionary");
- goto out;
- }
-
- ret = dict_get_str(dict, "volname", &volname);
- if (ret) {
- gf_log("cli", GF_LOG_ERROR,
- "Unable to get volname "
- "from dictionary");
+ gf_log("cli", GF_LOG_ERROR, DICT_UNSERIALIZE_FAIL);
goto out;
}
ret = dict_get_str(dict, "lk-summary", &lk_summary);
if (ret) {
gf_log("cli", GF_LOG_ERROR,
- "Unable to get lock "
- "summary from dictionary");
+ "Unable to get lock summary from dictionary");
goto out;
}
cli_out("Volume clear-locks successful");
@@ -9394,10 +8363,11 @@ out:
if (dict)
dict_unref(dict);
cli_cmd_broadcast_response(ret);
+ gf_free_xdr_cli_rsp(rsp);
return ret;
}
-int32_t
+static int32_t
gf_cli_clearlocks_volume(call_frame_t *frame, xlator_t *this, void *data)
{
gf_cli_req req = {{
@@ -9406,22 +8376,18 @@ gf_cli_clearlocks_volume(call_frame_t *frame, xlator_t *this, void *data)
dict_t *options = NULL;
int ret = -1;
- if (!frame || !this || !data)
- goto out;
-
options = data;
ret = cli_to_glusterd(
&req, frame, gf_cli_clearlocks_volume_cbk, (xdrproc_t)xdr_gf_cli_req,
options, GLUSTER_CLI_CLRLOCKS_VOLUME, this, cli_rpc_prog, NULL);
-out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
GF_FREE(req.dict.dict_val);
return ret;
}
-int32_t
+static int32_t
cli_snapshot_remove_reply(gf_cli_rsp *rsp, dict_t *dict, call_frame_t *frame)
{
int32_t ret = -1;
@@ -9435,7 +8401,7 @@ cli_snapshot_remove_reply(gf_cli_rsp *rsp, dict_t *dict, call_frame_t *frame)
local = frame->local;
- ret = dict_get_int32(dict, "sub-cmd", &delete_cmd);
+ ret = dict_get_int32_sizen(dict, "sub-cmd", &delete_cmd);
if (ret) {
gf_log("cli", GF_LOG_ERROR, "Could not get sub-cmd");
goto end;
@@ -9447,8 +8413,7 @@ cli_snapshot_remove_reply(gf_cli_rsp *rsp, dict_t *dict, call_frame_t *frame)
rsp->op_errno, rsp->op_errstr);
if (ret) {
gf_log("cli", GF_LOG_ERROR,
- "Failed to create "
- "xml output for delete");
+ "Failed to create xml output for delete");
goto end;
}
}
@@ -9484,8 +8449,7 @@ cli_snapshot_remove_reply(gf_cli_rsp *rsp, dict_t *dict, call_frame_t *frame)
ret = cli_xml_snapshot_delete(local, dict, rsp);
if (ret) {
gf_log("cli", GF_LOG_ERROR,
- "Failed to create "
- "xml output for snapshot delete command");
+ "Failed to create xml output for snapshot delete command");
goto out;
}
/* Error out in case of the op already failed */
@@ -9494,7 +8458,7 @@ cli_snapshot_remove_reply(gf_cli_rsp *rsp, dict_t *dict, call_frame_t *frame)
goto out;
}
} else {
- ret = dict_get_str(dict, "snapname", &snap_name);
+ ret = dict_get_str_sizen(dict, "snapname", &snap_name);
if (ret) {
gf_log("cli", GF_LOG_ERROR, "Failed to get snapname");
goto out;
@@ -9513,7 +8477,7 @@ end:
return ret;
}
-int
+static int
cli_snapshot_config_display(dict_t *dict, gf_cli_rsp *rsp)
{
char buf[PATH_MAX] = "";
@@ -9539,26 +8503,19 @@ cli_snapshot_config_display(dict_t *dict, gf_cli_rsp *rsp)
goto out;
}
- ret = dict_get_int32(dict, "config-command", &config_command);
+ ret = dict_get_int32_sizen(dict, "config-command", &config_command);
if (ret) {
gf_log("cli", GF_LOG_ERROR, "Could not fetch config type");
goto out;
}
- ret = dict_get_str(dict, "volname", &volname);
- /* Ignore the error, as volname is optional */
-
- if (!volname) {
- volname = "System";
- }
-
ret = dict_get_uint64(dict, "snap-max-hard-limit", &hard_limit);
/* Ignore the error, as the key specified is optional */
ret = dict_get_uint64(dict, "snap-max-soft-limit", &soft_limit);
- ret = dict_get_str(dict, "auto-delete", &auto_delete);
+ ret = dict_get_str_sizen(dict, "auto-delete", &auto_delete);
- ret = dict_get_str(dict, "snap-activate-on-create", &snap_activate);
+ ret = dict_get_str_sizen(dict, "snap-activate-on-create", &snap_activate);
if (!hard_limit && !soft_limit &&
config_command != GF_SNAP_CONFIG_DISPLAY && !auto_delete &&
@@ -9568,13 +8525,19 @@ cli_snapshot_config_display(dict_t *dict, gf_cli_rsp *rsp)
goto out;
}
+ ret = dict_get_str_sizen(dict, "volname", &volname);
+ /* Ignore the error, as volname is optional */
+
+ if (!volname) {
+ volname = "System";
+ }
+
switch (config_command) {
case GF_SNAP_CONFIG_TYPE_SET:
if (hard_limit && soft_limit) {
cli_out(
"snapshot config: snap-max-hard-limit "
- "& snap-max-soft-limit for system set "
- "successfully");
+ "& snap-max-soft-limit for system set successfully");
} else if (hard_limit) {
cli_out(
"snapshot config: snap-max-hard-limit "
@@ -9586,13 +8549,9 @@ cli_snapshot_config_display(dict_t *dict, gf_cli_rsp *rsp)
"for %s set successfully",
volname);
} else if (auto_delete) {
- cli_out(
- "snapshot config: auto-delete "
- "successfully set");
+ cli_out("snapshot config: auto-delete successfully set");
} else if (snap_activate) {
- cli_out(
- "snapshot config: activate-on-create "
- "successfully set");
+ cli_out("snapshot config: activate-on-create successfully set");
}
break;
@@ -9601,9 +8560,7 @@ cli_snapshot_config_display(dict_t *dict, gf_cli_rsp *rsp)
ret = dict_get_uint64(dict, "snap-max-hard-limit", &value);
if (ret) {
gf_log("cli", GF_LOG_ERROR,
- "Could not fetch "
- "snap_max_hard_limit for %s",
- volname);
+ "Could not fetch snap_max_hard_limit for %s", volname);
ret = -1;
goto out;
}
@@ -9612,9 +8569,7 @@ cli_snapshot_config_display(dict_t *dict, gf_cli_rsp *rsp)
ret = dict_get_uint64(dict, "snap-max-soft-limit", &soft_limit);
if (ret) {
gf_log("cli", GF_LOG_ERROR,
- "Could not fetch "
- "snap-max-soft-limit for %s",
- volname);
+ "Could not fetch snap-max-soft-limit for %s", volname);
ret = -1;
goto out;
}
@@ -9634,13 +8589,11 @@ cli_snapshot_config_display(dict_t *dict, gf_cli_rsp *rsp)
}
for (i = 0; i < voldisplaycount; i++) {
- snprintf(buf, sizeof(buf), "volume%" PRIu64 "-volname", i);
- ret = dict_get_str(dict, buf, &volname);
+ ret = snprintf(buf, sizeof(buf), "volume%" PRIu64 "-volname",
+ i);
+ ret = dict_get_strn(dict, buf, ret, &volname);
if (ret) {
- gf_log("cli", GF_LOG_ERROR,
- "Could not fetch "
- " %s",
- buf);
+ gf_log("cli", GF_LOG_ERROR, "Could not fetch %s", buf);
ret = -1;
goto out;
}
@@ -9650,10 +8603,7 @@ cli_snapshot_config_display(dict_t *dict, gf_cli_rsp *rsp)
"volume%" PRIu64 "-snap-max-hard-limit", i);
ret = dict_get_uint64(dict, buf, &value);
if (ret) {
- gf_log("cli", GF_LOG_ERROR,
- "Could not fetch "
- " %s",
- buf);
+ gf_log("cli", GF_LOG_ERROR, "Could not fetch %s", buf);
ret = -1;
goto out;
}
@@ -9665,8 +8615,7 @@ cli_snapshot_config_display(dict_t *dict, gf_cli_rsp *rsp)
if (ret) {
gf_log("cli", GF_LOG_ERROR,
"Could not fetch"
- " effective snap_max_hard_limit for "
- "%s",
+ " effective snap_max_hard_limit for %s",
volname);
ret = -1;
goto out;
@@ -9677,10 +8626,7 @@ cli_snapshot_config_display(dict_t *dict, gf_cli_rsp *rsp)
"volume%" PRIu64 "-snap-max-soft-limit", i);
ret = dict_get_uint64(dict, buf, &value);
if (ret) {
- gf_log("cli", GF_LOG_ERROR,
- "Could not fetch "
- " %s",
- buf);
+ gf_log("cli", GF_LOG_ERROR, "Could not fetch %s", buf);
ret = -1;
goto out;
}
@@ -9705,7 +8651,7 @@ out:
* arg - 0, dict : Response Dictionary.
* arg - 1, prefix str : snaplist.snap{0..}.vol{0..}.*
*/
-int
+static int
cli_get_each_volinfo_in_snap(dict_t *dict, char *keyprefix,
gf_boolean_t snap_driven)
{
@@ -9792,7 +8738,7 @@ out:
* arg - 0, dict : Response dictionary.
* arg - 1, prefix_str : snaplist.snap{0..}.*
*/
-int
+static int
cli_get_volinfo_in_snap(dict_t *dict, char *keyprefix)
{
char key[PATH_MAX] = "";
@@ -9817,8 +8763,7 @@ cli_get_volinfo_in_snap(dict_t *dict, char *keyprefix)
ret = cli_get_each_volinfo_in_snap(dict, key, _gf_true);
if (ret) {
gf_log("cli", GF_LOG_ERROR,
- "Could not list "
- "details of volume in a snap");
+ "Could not list details of volume in a snap");
goto out;
}
cli_out(" ");
@@ -9828,7 +8773,7 @@ out:
return ret;
}
-int
+static int
cli_get_each_snap_info(dict_t *dict, char *prefix_str, gf_boolean_t snap_driven)
{
char key_buffer[PATH_MAX] = "";
@@ -9895,9 +8840,7 @@ cli_get_each_snap_info(dict_t *dict, char *prefix_str, gf_boolean_t snap_driven)
cli_out("%-12s", "Snap Volumes:\n");
ret = cli_get_volinfo_in_snap(dict, prefix_str);
if (ret) {
- gf_log("cli", GF_LOG_ERROR,
- "Unable to list details "
- "of the snaps");
+ gf_log("cli", GF_LOG_ERROR, "Unable to list details of the snaps");
goto out;
}
}
@@ -9908,17 +8851,17 @@ out:
/* This is a generic function to print snap related information.
* arg - 0, dict : Response Dictionary
*/
-int
+static int
cli_call_snapshot_info(dict_t *dict, gf_boolean_t bool_snap_driven)
{
int snap_count = 0;
- char key[PATH_MAX] = "";
+ char key[32] = "";
int ret = -1;
int i = 0;
GF_ASSERT(dict);
- ret = dict_get_int32(dict, "snapcount", &snap_count);
+ ret = dict_get_int32_sizen(dict, "snapcount", &snap_count);
if (ret) {
gf_log("cli", GF_LOG_ERROR, "Unable to get snapcount");
goto out;
@@ -9943,33 +8886,33 @@ out:
return ret;
}
-int
+static int
cli_get_snaps_in_volume(dict_t *dict)
{
int ret = -1;
int i = 0;
int count = 0;
int avail = 0;
- char key[PATH_MAX] = "";
+ char key[32] = "";
char *get_buffer = NULL;
GF_ASSERT(dict);
- ret = dict_get_str(dict, "origin-volname", &get_buffer);
+ ret = dict_get_str_sizen(dict, "origin-volname", &get_buffer);
if (ret) {
gf_log("cli", GF_LOG_ERROR, "Could not fetch origin-volname");
goto out;
}
cli_out(INDENT_MAIN_HEAD "%s", "Volume Name", ":", get_buffer);
- ret = dict_get_int32(dict, "snapcount", &avail);
+ ret = dict_get_int32_sizen(dict, "snapcount", &avail);
if (ret) {
gf_log("cli", GF_LOG_ERROR, "Could not fetch snapcount");
goto out;
}
cli_out(INDENT_MAIN_HEAD "%d", "Snaps Taken", ":", avail);
- ret = dict_get_int32(dict, "snaps-available", &count);
+ ret = dict_get_int32_sizen(dict, "snaps-available", &count);
if (ret) {
gf_log("cli", GF_LOG_ERROR, "Could not fetch snaps-available");
goto out;
@@ -9991,8 +8934,7 @@ cli_get_snaps_in_volume(dict_t *dict)
ret = cli_get_each_volinfo_in_snap(dict, key, _gf_false);
if (ret) {
gf_log("cli", GF_LOG_ERROR,
- "Could not get volume "
- "related information");
+ "Could not get volume related information");
goto out;
}
@@ -10002,18 +8944,18 @@ out:
return ret;
}
-int
+static int
cli_snapshot_list(dict_t *dict)
{
int snapcount = 0;
- char key[PATH_MAX] = "";
+ char key[32] = "";
int ret = -1;
int i = 0;
char *get_buffer = NULL;
GF_ASSERT(dict);
- ret = dict_get_int32(dict, "snapcount", &snapcount);
+ ret = dict_get_int32_sizen(dict, "snapcount", &snapcount);
if (ret) {
gf_log("cli", GF_LOG_ERROR, "Could not fetch snap count");
goto out;
@@ -10029,7 +8971,7 @@ cli_snapshot_list(dict_t *dict)
goto out;
}
- ret = dict_get_str(dict, key, &get_buffer);
+ ret = dict_get_strn(dict, key, ret, &get_buffer);
if (ret) {
gf_log("cli", GF_LOG_ERROR, "Could not get %s ", key);
goto out;
@@ -10041,7 +8983,7 @@ out:
return ret;
}
-int
+static int
cli_get_snap_volume_status(dict_t *dict, char *key_prefix)
{
int ret = -1;
@@ -10142,11 +9084,11 @@ out:
return ret;
}
-int
+static int
cli_get_single_snap_status(dict_t *dict, char *keyprefix)
{
int ret = -1;
- char key[PATH_MAX] = "";
+ char key[64] = ""; /* keyprefix is ""status.snap0" */
int i = 0;
int volcount = 0;
char *get_buffer = NULL;
@@ -10205,7 +9147,7 @@ out:
return ret;
}
-int32_t
+static int32_t
cli_populate_req_dict_for_delete(dict_t *snap_dict, dict_t *dict, size_t index)
{
int32_t ret = -1;
@@ -10215,11 +9157,10 @@ cli_populate_req_dict_for_delete(dict_t *snap_dict, dict_t *dict, size_t index)
GF_ASSERT(snap_dict);
GF_ASSERT(dict);
- ret = dict_set_int32(snap_dict, "sub-cmd", GF_SNAP_DELETE_TYPE_ITER);
+ ret = dict_set_int32_sizen(snap_dict, "sub-cmd", GF_SNAP_DELETE_TYPE_ITER);
if (ret) {
gf_log("cli", GF_LOG_ERROR,
- "Could not save command "
- "type in snap dictionary");
+ "Could not save command type in snap dictionary");
goto out;
}
@@ -10240,7 +9181,7 @@ cli_populate_req_dict_for_delete(dict_t *snap_dict, dict_t *dict, size_t index)
goto out;
}
- ret = dict_set_int32(snap_dict, "type", GF_SNAP_OPTION_TYPE_DELETE);
+ ret = dict_set_int32_sizen(snap_dict, "type", GF_SNAP_OPTION_TYPE_DELETE);
if (ret) {
gf_log("cli", GF_LOG_ERROR, "Failed to save command type");
goto out;
@@ -10255,7 +9196,7 @@ out:
return ret;
}
-int
+static int
cli_populate_req_dict_for_status(dict_t *snap_dict, dict_t *dict, int index)
{
int ret = -1;
@@ -10267,9 +9208,7 @@ cli_populate_req_dict_for_status(dict_t *snap_dict, dict_t *dict, int index)
ret = dict_set_uint32(snap_dict, "sub-cmd", GF_SNAP_STATUS_TYPE_ITER);
if (ret) {
- gf_log("cli", GF_LOG_ERROR,
- "Could not save command "
- "type in snap dict");
+ gf_log("cli", GF_LOG_ERROR, "Could not save command type in snap dict");
goto out;
}
@@ -10278,21 +9217,19 @@ cli_populate_req_dict_for_status(dict_t *snap_dict, dict_t *dict, int index)
goto out;
}
- ret = dict_get_str(dict, key, &buffer);
+ ret = dict_get_strn(dict, key, ret, &buffer);
if (ret) {
gf_log("cli", GF_LOG_ERROR, "Could not get snapname");
goto out;
}
- ret = dict_set_str(snap_dict, "snapname", buffer);
+ ret = dict_set_str_sizen(snap_dict, "snapname", buffer);
if (ret) {
- gf_log("cli", GF_LOG_ERROR,
- "Could not save snapname "
- "in snap dict");
+ gf_log("cli", GF_LOG_ERROR, "Could not save snapname in snap dict");
goto out;
}
- ret = dict_set_int32(snap_dict, "type", GF_SNAP_OPTION_TYPE_STATUS);
+ ret = dict_set_int32_sizen(snap_dict, "type", GF_SNAP_OPTION_TYPE_STATUS);
if (ret) {
gf_log("cli", GF_LOG_ERROR, "Could not save command type");
goto out;
@@ -10304,7 +9241,7 @@ cli_populate_req_dict_for_status(dict_t *snap_dict, dict_t *dict, int index)
goto out;
}
- ret = dict_set_int32(snap_dict, "hold_vol_locks", _gf_false);
+ ret = dict_set_int32_sizen(snap_dict, "hold_vol_locks", _gf_false);
if (ret) {
gf_log("cli", GF_LOG_ERROR, "Setting volume lock flag failed");
goto out;
@@ -10314,10 +9251,9 @@ out:
return ret;
}
-int
+static int
cli_snapshot_status(dict_t *dict, gf_cli_rsp *rsp, call_frame_t *frame)
{
- char key[PATH_MAX] = "";
int ret = -1;
int status_cmd = -1;
cli_local_t *local = NULL;
@@ -10338,8 +9274,7 @@ cli_snapshot_status(dict_t *dict, gf_cli_rsp *rsp, call_frame_t *frame)
rsp->op_errstr);
if (ret) {
gf_log("cli", GF_LOG_ERROR,
- "Failed to set "
- "op_errstr in local dictionary");
+ "Failed to set op_errstr in local dictionary");
goto out;
}
}
@@ -10347,7 +9282,7 @@ cli_snapshot_status(dict_t *dict, gf_cli_rsp *rsp, call_frame_t *frame)
goto out;
}
- ret = dict_get_int32(dict, "sub-cmd", &status_cmd);
+ ret = dict_get_int32_sizen(dict, "sub-cmd", &status_cmd);
if (ret) {
gf_log("cli", GF_LOG_ERROR, "Could not fetch status type");
goto out;
@@ -10359,35 +9294,24 @@ cli_snapshot_status(dict_t *dict, gf_cli_rsp *rsp, call_frame_t *frame)
goto out;
}
- ret = snprintf(key, sizeof(key), "status.snap0");
- if (ret < 0) {
- goto out;
- }
-
if (global_state->mode & GLUSTER_MODE_XML) {
- ret = cli_xml_snapshot_status_single_snap(local, dict, key);
+ ret = cli_xml_snapshot_status_single_snap(local, dict, "status.snap0");
if (ret) {
gf_log("cli", GF_LOG_ERROR,
- "Failed to create "
- "xml output for snapshot status");
- goto out;
+ "Failed to create xml output for snapshot status");
}
} else {
- ret = cli_get_single_snap_status(dict, key);
+ ret = cli_get_single_snap_status(dict, "status.snap0");
if (ret) {
- gf_log("cli", GF_LOG_ERROR,
- "Could not fetch "
- "status of snap");
- goto out;
+ gf_log("cli", GF_LOG_ERROR, "Could not fetch status of snap");
}
}
- ret = 0;
out:
return ret;
}
-int
+static int
gf_cli_generate_snapshot_event(gf_cli_rsp *rsp, dict_t *dict, int32_t type,
char *snap_name, char *volname, char *snap_uuid,
char *clone_name)
@@ -10437,8 +9361,7 @@ gf_cli_generate_snapshot_event(gf_cli_rsp *rsp, dict_t *dict, int32_t type,
}
gf_event(EVENT_SNAPSHOT_CREATED,
- "snapshot_name=%s;"
- "volume_name=%s;snapshot_uuid=%s",
+ "snapshot_name=%s;volume_name=%s;snapshot_uuid=%s",
snap_name, volname, snap_uuid);
ret = 0;
@@ -10465,9 +9388,7 @@ gf_cli_generate_snapshot_event(gf_cli_rsp *rsp, dict_t *dict, int32_t type,
}
gf_event(EVENT_SNAPSHOT_ACTIVATED,
- "snapshot_name=%s;"
- "snapshot_uuid=%s",
- snap_name, snap_uuid);
+ "snapshot_name=%s;snapshot_uuid=%s", snap_name, snap_uuid);
ret = 0;
break;
@@ -10493,9 +9414,7 @@ gf_cli_generate_snapshot_event(gf_cli_rsp *rsp, dict_t *dict, int32_t type,
}
gf_event(EVENT_SNAPSHOT_DEACTIVATED,
- "snapshot_name=%s;"
- "snapshot_uuid=%s",
- snap_name, snap_uuid);
+ "snapshot_name=%s;snapshot_uuid=%s", snap_name, snap_uuid);
ret = 0;
break;
@@ -10516,25 +9435,26 @@ gf_cli_generate_snapshot_event(gf_cli_rsp *rsp, dict_t *dict, int32_t type,
}
if (!snap_uuid) {
+ ret = -1;
gf_log("cli", GF_LOG_ERROR, "Failed to get snap uuid");
goto out;
}
if (!volname) {
+ ret = -1;
gf_log("cli", GF_LOG_ERROR, "Failed to get volname");
goto out;
}
gf_event(EVENT_SNAPSHOT_RESTORED,
- "snapshot_name=%s;"
- "snapshot_uuid=%s;volume_name=%s",
+ "snapshot_name=%s;snapshot_uuid=%s;volume_name=%s",
snap_name, snap_uuid, volname);
ret = 0;
break;
case GF_SNAP_OPTION_TYPE_DELETE:
- ret = dict_get_int32(dict, "sub-cmd", &delete_cmd);
+ ret = dict_get_int32_sizen(dict, "sub-cmd", &delete_cmd);
if (ret) {
gf_log("cli", GF_LOG_ERROR, "Could not get sub-cmd");
goto out;
@@ -10564,14 +9484,13 @@ gf_cli_generate_snapshot_event(gf_cli_rsp *rsp, dict_t *dict, int32_t type,
}
if (!snap_uuid) {
+ ret = -1;
gf_log("cli", GF_LOG_ERROR, "Failed to get snap uuid");
goto out;
}
gf_event(EVENT_SNAPSHOT_DELETED,
- "snapshot_name=%s;"
- "snapshot_uuid=%s",
- snap_name, snap_uuid);
+ "snapshot_name=%s;snapshot_uuid=%s", snap_name, snap_uuid);
ret = 0;
break;
@@ -10589,9 +9508,8 @@ gf_cli_generate_snapshot_event(gf_cli_rsp *rsp, dict_t *dict, int32_t type,
if (rsp->op_ret != 0) {
gf_event(EVENT_SNAPSHOT_CLONE_FAILED,
- "snapshot_name=%s;clone_name=%s;"
- "error=%s",
- snap_name, clone_name,
+ "snapshot_name=%s;clone_name=%s;error=%s", snap_name,
+ clone_name,
rsp->op_errstr ? rsp->op_errstr
: "Please check log file for details");
ret = 0;
@@ -10599,14 +9517,14 @@ gf_cli_generate_snapshot_event(gf_cli_rsp *rsp, dict_t *dict, int32_t type,
}
if (!snap_uuid) {
+ ret = -1;
gf_log("cli", GF_LOG_ERROR, "Failed to get snap uuid");
goto out;
}
gf_event(EVENT_SNAPSHOT_CLONED,
- "snapshot_name=%s;"
- "clone_name=%s;clone_uuid=%s",
- snap_name, clone_name, snap_uuid);
+ "snapshot_name=%s;clone_name=%s;clone_uuid=%s", snap_name,
+ clone_name, snap_uuid);
ret = 0;
break;
@@ -10620,7 +9538,7 @@ gf_cli_generate_snapshot_event(gf_cli_rsp *rsp, dict_t *dict, int32_t type,
break;
}
- ret = dict_get_int32(dict, "config-command", &config_command);
+ ret = dict_get_int32_sizen(dict, "config-command", &config_command);
if (ret) {
gf_log("cli", GF_LOG_ERROR, "Could not fetch config type");
goto out;
@@ -10634,8 +9552,9 @@ gf_cli_generate_snapshot_event(gf_cli_rsp *rsp, dict_t *dict, int32_t type,
/* These are optional parameters therefore ignore the error */
ret = dict_get_uint64(dict, "snap-max-hard-limit", &hard_limit);
ret = dict_get_uint64(dict, "snap-max-soft-limit", &soft_limit);
- ret = dict_get_str(dict, "auto-delete", &auto_delete);
- ret = dict_get_str(dict, "snap-activate-on-create", &snap_activate);
+ ret = dict_get_str_sizen(dict, "auto-delete", &auto_delete);
+ ret = dict_get_str_sizen(dict, "snap-activate-on-create",
+ &snap_activate);
if (!hard_limit && !soft_limit && !auto_delete && !snap_activate) {
ret = -1;
@@ -10647,9 +9566,6 @@ gf_cli_generate_snapshot_event(gf_cli_rsp *rsp, dict_t *dict, int32_t type,
goto out;
}
- volname = NULL;
- ret = dict_get_str(dict, "volname", &volname);
-
if (hard_limit || soft_limit) {
snprintf(option, sizeof(option), "%s=%" PRIu64,
hard_limit ? "hard_limit" : "soft_limit",
@@ -10660,6 +9576,9 @@ gf_cli_generate_snapshot_event(gf_cli_rsp *rsp, dict_t *dict, int32_t type,
auto_delete ? auto_delete : snap_activate);
}
+ volname = NULL;
+ ret = dict_get_str_sizen(dict, "volname", &volname);
+
snprintf(msg, sizeof(msg), "config_type=%s;%s",
volname ? "volume_config" : "system_config", option);
@@ -10683,7 +9602,7 @@ out:
* Fetch necessary data from dict at one place instead of *
* repeating the same code again and again. *
*/
-int
+static int
gf_cli_snapshot_get_data_from_dict(dict_t *dict, char **snap_name,
char **volname, char **snap_uuid,
int8_t *soft_limit_flag, char **clone_name)
@@ -10693,21 +9612,21 @@ gf_cli_snapshot_get_data_from_dict(dict_t *dict, char **snap_name,
GF_VALIDATE_OR_GOTO("cli", dict, out);
if (snap_name) {
- ret = dict_get_str(dict, "snapname", snap_name);
+ ret = dict_get_str_sizen(dict, "snapname", snap_name);
if (ret) {
gf_log("cli", GF_LOG_DEBUG, "failed to get snapname from dict");
}
}
if (volname) {
- ret = dict_get_str(dict, "volname1", volname);
+ ret = dict_get_str_sizen(dict, "volname1", volname);
if (ret) {
gf_log("cli", GF_LOG_DEBUG, "failed to get volname1 from dict");
}
}
if (snap_uuid) {
- ret = dict_get_str(dict, "snapuuid", snap_uuid);
+ ret = dict_get_str_sizen(dict, "snapuuid", snap_uuid);
if (ret) {
gf_log("cli", GF_LOG_DEBUG, "failed to get snapuuid from dict");
}
@@ -10722,7 +9641,7 @@ gf_cli_snapshot_get_data_from_dict(dict_t *dict, char **snap_name,
}
if (clone_name) {
- ret = dict_get_str(dict, "clonename", clone_name);
+ ret = dict_get_str_sizen(dict, "clonename", clone_name);
if (ret) {
gf_log("cli", GF_LOG_DEBUG, "failed to get clonename from dict");
}
@@ -10733,7 +9652,7 @@ out:
return ret;
}
-int
+static int
gf_cli_snapshot_cbk(struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
@@ -10761,8 +9680,7 @@ gf_cli_snapshot_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
- gf_log(frame->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ gf_log(frame->this->name, GF_LOG_ERROR, XDR_DECODE_FAIL);
goto out;
}
@@ -10778,7 +9696,7 @@ gf_cli_snapshot_cbk(struct rpc_req *req, struct iovec *iov, int count,
if (ret)
goto out;
- ret = dict_get_int32(dict, "type", &type);
+ ret = dict_get_int32_sizen(dict, "type", &type);
if (ret) {
gf_log(frame->this->name, GF_LOG_ERROR, "failed to get type");
goto out;
@@ -10807,7 +9725,7 @@ gf_cli_snapshot_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = cli_xml_output_snapshot(type, dict, rsp.op_ret, rsp.op_errno,
rsp.op_errstr);
if (ret) {
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
}
goto out;
@@ -10824,19 +9742,19 @@ gf_cli_snapshot_cbk(struct rpc_req *req, struct iovec *iov, int count,
}
if (!snap_name) {
+ ret = -1;
gf_log("cli", GF_LOG_ERROR, "Failed to get snap name");
goto out;
}
if (!volname) {
+ ret = -1;
gf_log("cli", GF_LOG_ERROR, "Failed to get volume name");
goto out;
}
- cli_out(
- "snapshot create: success: Snap %s created "
- "successfully",
- snap_name);
+ cli_out("snapshot create: success: Snap %s created successfully",
+ snap_name);
if (soft_limit_flag == 1) {
cli_out(
@@ -10867,10 +9785,8 @@ gf_cli_snapshot_cbk(struct rpc_req *req, struct iovec *iov, int count,
goto out;
}
- cli_out(
- "snapshot clone: success: Clone %s created "
- "successfully",
- clone_name);
+ cli_out("snapshot clone: success: Clone %s created successfully",
+ clone_name);
ret = 0;
break;
@@ -10889,10 +9805,8 @@ gf_cli_snapshot_cbk(struct rpc_req *req, struct iovec *iov, int count,
goto out;
}
- cli_out(
- "Snapshot restore: %s: Snap restored "
- "successfully",
- snap_name);
+ cli_out("Snapshot restore: %s: Snap restored successfully",
+ snap_name);
ret = 0;
break;
@@ -10910,10 +9824,8 @@ gf_cli_snapshot_cbk(struct rpc_req *req, struct iovec *iov, int count,
goto out;
}
- cli_out(
- "Snapshot activate: %s: Snap activated "
- "successfully",
- snap_name);
+ cli_out("Snapshot activate: %s: Snap activated successfully",
+ snap_name);
ret = 0;
break;
@@ -10932,10 +9844,8 @@ gf_cli_snapshot_cbk(struct rpc_req *req, struct iovec *iov, int count,
goto out;
}
- cli_out(
- "Snapshot deactivate: %s: Snap deactivated "
- "successfully",
- snap_name);
+ cli_out("Snapshot deactivate: %s: Snap deactivated successfully",
+ snap_name);
ret = 0;
break;
@@ -10968,8 +9878,7 @@ gf_cli_snapshot_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = cli_snapshot_config_display(dict, &rsp);
if (ret) {
gf_log("cli", GF_LOG_ERROR,
- "Failed to display "
- "snapshot config output.");
+ "Failed to display snapshot config output.");
goto out;
}
break;
@@ -10985,9 +9894,7 @@ gf_cli_snapshot_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = cli_snapshot_list(dict);
if (ret) {
- gf_log("cli", GF_LOG_ERROR,
- "Failed to display "
- "snapshot list");
+ gf_log("cli", GF_LOG_ERROR, "Failed to display snapshot list");
goto out;
}
break;
@@ -11004,8 +9911,7 @@ gf_cli_snapshot_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = cli_snapshot_status(dict, &rsp, frame);
if (ret) {
gf_log("cli", GF_LOG_ERROR,
- "Failed to display "
- "snapshot status output.");
+ "Failed to display snapshot status output.");
goto out;
}
break;
@@ -11049,11 +9955,9 @@ gf_cli_snapshot_for_delete(call_frame_t *frame, xlator_t *this, void *data)
local = frame->local;
- ret = dict_get_int32(local->dict, "sub-cmd", &cmd);
+ ret = dict_get_int32_sizen(local->dict, "sub-cmd", &cmd);
if (ret) {
- gf_log("cli", GF_LOG_ERROR,
- "Failed to get "
- "sub-cmd");
+ gf_log("cli", GF_LOG_ERROR, "Failed to get sub-cmd");
goto out;
}
@@ -11063,11 +9967,9 @@ gf_cli_snapshot_for_delete(call_frame_t *frame, xlator_t *this, void *data)
goto out;
}
- ret = dict_get_int32(local->dict, "snapcount", &snapcount);
+ ret = dict_get_int32_sizen(local->dict, "snapcount", &snapcount);
if (ret) {
- gf_log("cli", GF_LOG_ERROR,
- "Could not get "
- "snapcount");
+ gf_log("cli", GF_LOG_ERROR, "Could not get snapcount");
goto out;
}
@@ -11077,8 +9979,7 @@ gf_cli_snapshot_for_delete(call_frame_t *frame, xlator_t *this, void *data)
local->writer, (xmlChar *)"snapCount", "%d", snapcount);
if (ret) {
gf_log("cli", GF_LOG_ERROR,
- "Failed to write "
- "xml element \"snapCount\"");
+ "Failed to write xml element \"snapCount\"");
goto out;
}
#endif /* HAVE_LIB_XML */
@@ -11089,22 +9990,19 @@ gf_cli_snapshot_for_delete(call_frame_t *frame, xlator_t *this, void *data)
if (cmd == GF_SNAP_DELETE_TYPE_ALL) {
snprintf(question, sizeof(question),
- "System contains %d "
- "snapshot(s).\nDo you still "
+ "System contains %d snapshot(s).\nDo you still "
"want to continue and delete them? ",
snapcount);
} else {
- ret = dict_get_str(local->dict, "volname", &volname);
+ ret = dict_get_str_sizen(local->dict, "volname", &volname);
if (ret) {
gf_log("cli", GF_LOG_ERROR,
- "Failed to fetch "
- "volname from local dictionary");
+ "Failed to fetch volname from local dictionary");
goto out;
}
snprintf(question, sizeof(question),
- "Volume (%s) contains "
- "%d snapshot(s).\nDo you still want to "
+ "Volume (%s) contains %d snapshot(s).\nDo you still want to "
"continue and delete them? ",
volname, snapcount);
}
@@ -11113,8 +10011,7 @@ gf_cli_snapshot_for_delete(call_frame_t *frame, xlator_t *this, void *data)
if (GF_ANSWER_NO == answer) {
ret = 0;
gf_log("cli", GF_LOG_DEBUG,
- "User cancelled "
- "snapshot delete operation for snap delete");
+ "User cancelled snapshot delete operation for snap delete");
goto out;
}
@@ -11128,8 +10025,7 @@ gf_cli_snapshot_for_delete(call_frame_t *frame, xlator_t *this, void *data)
ret = cli_populate_req_dict_for_delete(snap_dict, local->dict, i);
if (ret) {
gf_log("cli", GF_LOG_ERROR,
- "Could not "
- "populate snap request dictionary");
+ "Could not populate snap request dictionary");
goto out;
}
@@ -11141,8 +10037,7 @@ gf_cli_snapshot_for_delete(call_frame_t *frame, xlator_t *this, void *data)
* snapshots is failed
*/
gf_log("cli", GF_LOG_ERROR,
- "cli_to_glusterd "
- "for snapshot delete failed");
+ "cli_to_glusterd for snapshot delete failed");
goto out;
}
dict_unref(snap_dict);
@@ -11152,11 +10047,12 @@ gf_cli_snapshot_for_delete(call_frame_t *frame, xlator_t *this, void *data)
out:
if (snap_dict)
dict_unref(snap_dict);
+ GF_FREE(req.dict.dict_val);
return ret;
}
-int32_t
+static int32_t
gf_cli_snapshot_for_status(call_frame_t *frame, xlator_t *this, void *data)
{
gf_cli_req req = {{
@@ -11176,7 +10072,7 @@ gf_cli_snapshot_for_status(call_frame_t *frame, xlator_t *this, void *data)
local = frame->local;
- ret = dict_get_int32(local->dict, "sub-cmd", &cmd);
+ ret = dict_get_int32_sizen(local->dict, "sub-cmd", &cmd);
if (ret) {
gf_log("cli", GF_LOG_ERROR, "Failed to get sub-cmd");
goto out;
@@ -11192,7 +10088,7 @@ gf_cli_snapshot_for_status(call_frame_t *frame, xlator_t *this, void *data)
goto out;
}
- ret = dict_get_int32(local->dict, "status.snapcount", &snapcount);
+ ret = dict_get_int32_sizen(local->dict, "status.snapcount", &snapcount);
if (ret) {
gf_log("cli", GF_LOG_ERROR, "Could not get snapcount");
goto out;
@@ -11212,8 +10108,7 @@ gf_cli_snapshot_for_status(call_frame_t *frame, xlator_t *this, void *data)
ret = cli_populate_req_dict_for_status(snap_dict, local->dict, i);
if (ret) {
gf_log("cli", GF_LOG_ERROR,
- "Could not "
- "populate snap request dictionary");
+ "Could not populate snap request dictionary");
goto out;
}
@@ -11245,11 +10140,12 @@ gf_cli_snapshot_for_status(call_frame_t *frame, xlator_t *this, void *data)
out:
if (snap_dict)
dict_unref(snap_dict);
+ GF_FREE(req.dict.dict_val);
return ret;
}
-int32_t
+static int32_t
gf_cli_snapshot(call_frame_t *frame, xlator_t *this, void *data)
{
gf_cli_req req = {{
@@ -11262,24 +10158,18 @@ gf_cli_snapshot(call_frame_t *frame, xlator_t *this, void *data)
char *err_str = NULL;
int type = -1;
- if (!frame || !this || !data)
- goto out;
-
- if (!frame->local)
+ if (!frame || !frame->local || !this || !data)
goto out;
local = frame->local;
options = data;
- ret = dict_get_int32(local->dict, "type", &type);
-
if (global_state->mode & GLUSTER_MODE_XML) {
ret = cli_xml_snapshot_begin_composite_op(local);
if (ret) {
gf_log("cli", GF_LOG_ERROR,
- "Failed to begin "
- "snapshot xml composite op");
+ "Failed to begin snapshot xml composite op");
goto out;
}
}
@@ -11288,18 +10178,17 @@ gf_cli_snapshot(call_frame_t *frame, xlator_t *this, void *data)
(xdrproc_t)xdr_gf_cli_req, options, GLUSTER_CLI_SNAP,
this, cli_rpc_prog, NULL);
if (ret) {
- gf_log("cli", GF_LOG_ERROR,
- "cli_to_glusterd for "
- "snapshot failed");
+ gf_log("cli", GF_LOG_ERROR, "cli_to_glusterd for snapshot failed");
goto xmlend;
}
+ ret = dict_get_int32_sizen(local->dict, "type", &type);
+
if (GF_SNAP_OPTION_TYPE_STATUS == type) {
ret = gf_cli_snapshot_for_status(frame, this, data);
if (ret) {
gf_log("cli", GF_LOG_ERROR,
- "cli to glusterd "
- "for snapshot status command failed");
+ "cli to glusterd for snapshot status command failed");
}
goto xmlend;
@@ -11309,8 +10198,7 @@ gf_cli_snapshot(call_frame_t *frame, xlator_t *this, void *data)
ret = gf_cli_snapshot_for_delete(frame, this, data);
if (ret) {
gf_log("cli", GF_LOG_ERROR,
- "cli to glusterd "
- "for snapshot delete command failed");
+ "cli to glusterd for snapshot delete command failed");
}
goto xmlend;
@@ -11323,25 +10211,23 @@ xmlend:
ret = cli_xml_snapshot_end_composite_op(local);
if (ret) {
gf_log("cli", GF_LOG_ERROR,
- "Failed to end "
- "snapshot xml composite op");
+ "Failed to end snapshot xml composite op");
goto out;
}
}
out:
if (ret && local && GF_SNAP_OPTION_TYPE_STATUS == type) {
- tmp_ret = dict_get_str(local->dict, "op_err_str", &err_str);
+ tmp_ret = dict_get_str_sizen(local->dict, "op_err_str", &err_str);
if (tmp_ret || !err_str) {
cli_err("Snapshot Status : failed: %s",
- "Please "
- "check log file for details");
+ "Please check log file for details");
} else {
cli_err("Snapshot Status : failed: %s", err_str);
- dict_del(local->dict, "op_err_str");
+ dict_del_sizen(local->dict, "op_err_str");
}
}
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
GF_FREE(req.dict.dict_val);
@@ -11352,7 +10238,7 @@ out:
return ret;
}
-int32_t
+static int32_t
gf_cli_barrier_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
@@ -11369,7 +10255,7 @@ gf_cli_barrier_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ XDR_DECODE_FAIL);
goto out;
}
gf_log("cli", GF_LOG_DEBUG, "Received response to barrier");
@@ -11386,13 +10272,12 @@ gf_cli_barrier_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = rsp.op_ret;
out:
- free(rsp.op_errstr);
- free(rsp.dict.dict_val);
cli_cmd_broadcast_response(ret);
+ gf_free_xdr_cli_rsp(rsp);
return ret;
}
-int
+static int
gf_cli_barrier_volume(call_frame_t *frame, xlator_t *this, void *data)
{
gf_cli_req req = {{
@@ -11401,22 +10286,18 @@ gf_cli_barrier_volume(call_frame_t *frame, xlator_t *this, void *data)
dict_t *options = NULL;
int ret = -1;
- if (!frame || !this || !data)
- goto out;
-
options = data;
ret = cli_to_glusterd(&req, frame, gf_cli_barrier_volume_cbk,
(xdrproc_t)xdr_gf_cli_req, options,
GLUSTER_CLI_BARRIER_VOLUME, this, cli_rpc_prog, NULL);
-out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
GF_FREE(req.dict.dict_val);
return ret;
}
-int32_t
+static int32_t
gf_cli_get_vol_opt_cbk(struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
@@ -11443,27 +10324,23 @@ gf_cli_get_vol_opt_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ XDR_DECODE_FAIL);
goto out;
}
gf_log("cli", GF_LOG_DEBUG, "Received response to get volume option");
if (rsp.op_ret) {
if (strcmp(rsp.op_errstr, ""))
- snprintf(msg, sizeof(msg),
- "volume get option: "
- "failed: %s",
+ snprintf(msg, sizeof(msg), "volume get option: failed: %s",
rsp.op_errstr);
else
- snprintf(msg, sizeof(msg),
- "volume get option: "
- "failed");
+ snprintf(msg, sizeof(msg), "volume get option: failed");
if (global_state->mode & GLUSTER_MODE_XML) {
ret = cli_xml_output_str("volGetopts", msg, rsp.op_ret,
rsp.op_errno, rsp.op_errstr);
if (ret) {
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
}
} else {
cli_err("%s", msg);
@@ -11480,7 +10357,7 @@ gf_cli_get_vol_opt_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = dict_unserialize(rsp.dict.dict_val, rsp.dict.dict_len, &dict);
if (ret) {
- gf_log("cli", GF_LOG_ERROR, "Failed rsp_dict unserialization");
+ gf_log("cli", GF_LOG_ERROR, DICT_UNSERIALIZE_FAIL);
goto out;
}
@@ -11488,32 +10365,26 @@ gf_cli_get_vol_opt_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = cli_xml_output_vol_getopts(dict, rsp.op_ret, rsp.op_errno,
rsp.op_errstr);
if (ret) {
- gf_log("cli", GF_LOG_ERROR,
- "xml output generation "
- "failed");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
ret = 0;
}
goto out;
}
- ret = dict_get_str(dict, "warning", &value);
+ ret = dict_get_str_sizen(dict, "warning", &value);
if (!ret) {
cli_out("%s", value);
}
- ret = dict_get_int32(dict, "count", &count);
+ ret = dict_get_int32_sizen(dict, "count", &count);
if (ret) {
gf_log("cli", GF_LOG_ERROR,
- "Failed to retrieve count "
- "from the dictionary");
+ "Failed to retrieve count from the dictionary");
goto out;
}
if (count <= 0) {
- gf_log("cli", GF_LOG_ERROR,
- "Value of count :%d is "
- "invalid",
- count);
+ gf_log("cli", GF_LOG_ERROR, "Value of count :%d is invalid", count);
ret = -1;
goto out;
}
@@ -11521,23 +10392,18 @@ gf_cli_get_vol_opt_cbk(struct rpc_req *req, struct iovec *iov, int count,
cli_out("%-40s%-40s", "Option", "Value");
cli_out("%-40s%-40s", "------", "-----");
for (i = 1; i <= count; i++) {
- snprintf(dict_key, sizeof dict_key, "key%d", i);
- ret = dict_get_str(dict, dict_key, &key);
+ ret = snprintf(dict_key, sizeof dict_key, "key%d", i);
+ ret = dict_get_strn(dict, dict_key, ret, &key);
if (ret) {
gf_log("cli", GF_LOG_ERROR,
- "Failed to"
- " retrieve %s from the "
- "dictionary",
- dict_key);
+ "Failed to retrieve %s from the dictionary", dict_key);
goto out;
}
- snprintf(dict_key, sizeof dict_key, "value%d", i);
- ret = dict_get_str(dict, dict_key, &value);
+ ret = snprintf(dict_key, sizeof dict_key, "value%d", i);
+ ret = dict_get_strn(dict, dict_key, ret, &value);
if (ret) {
gf_log("cli", GF_LOG_ERROR,
- "Failed to "
- "retrieve key value for %s from"
- "the dictionary",
+ "Failed to retrieve key value for %s from the dictionary",
dict_key);
goto out;
}
@@ -11554,13 +10420,12 @@ out:
out_nolog:
if (dict)
dict_unref(dict);
- free(rsp.op_errstr);
- free(rsp.dict.dict_val);
cli_cmd_broadcast_response(ret);
+ gf_free_xdr_cli_rsp(rsp);
return ret;
}
-int
+static int
gf_cli_get_vol_opt(call_frame_t *frame, xlator_t *this, void *data)
{
gf_cli_req req = {{
@@ -11569,22 +10434,18 @@ gf_cli_get_vol_opt(call_frame_t *frame, xlator_t *this, void *data)
dict_t *options = NULL;
int ret = -1;
- if (!frame || !this || !data)
- goto out;
-
options = data;
ret = cli_to_glusterd(&req, frame, gf_cli_get_vol_opt_cbk,
(xdrproc_t)xdr_gf_cli_req, options,
GLUSTER_CLI_GET_VOL_OPT, this, cli_rpc_prog, NULL);
-out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
GF_FREE(req.dict.dict_val);
return ret;
}
-int
+static int
add_cli_cmd_timeout_to_dict(dict_t *dict)
{
int ret = 0;
@@ -11592,15 +10453,13 @@ add_cli_cmd_timeout_to_dict(dict_t *dict)
if (cli_default_conn_timeout > 120) {
ret = dict_set_uint32(dict, "timeout", cli_default_conn_timeout);
if (ret) {
- gf_log("cli", GF_LOG_INFO,
- "Failed to save"
- "timeout to dict");
+ gf_log("cli", GF_LOG_INFO, "Failed to save timeout to dict");
}
}
return ret;
}
-int
+static int
cli_to_glusterd(gf_cli_req *req, call_frame_t *frame, fop_cbk_fn_t cbkfn,
xdrproc_t xdrproc, dict_t *dict, int procnum, xlator_t *this,
rpc_clnt_prog_t *prog, struct iobref *iobref)
@@ -11612,12 +10471,7 @@ cli_to_glusterd(gf_cli_req *req, call_frame_t *frame, fop_cbk_fn_t cbkfn,
const char **words = NULL;
cli_local_t *local = NULL;
- if (!this || !frame || !dict) {
- ret = -1;
- goto out;
- }
-
- if (!frame->local) {
+ if (!this || !frame || !frame->local || !dict) {
ret = -1;
goto out;
}
@@ -11634,12 +10488,12 @@ cli_to_glusterd(gf_cli_req *req, call_frame_t *frame, fop_cbk_fn_t cbkfn,
while (words[i])
len += strlen(words[i++]) + 1;
- cmd = GF_CALLOC(1, len, gf_common_mt_char);
-
+ cmd = GF_MALLOC(len + 1, gf_common_mt_char);
if (!cmd) {
ret = -1;
goto out;
}
+ cmd[0] = '\0';
for (i = 0; words[i]; i++) {
strncat(cmd, words[i], len - 1);
@@ -11647,9 +10501,7 @@ cli_to_glusterd(gf_cli_req *req, call_frame_t *frame, fop_cbk_fn_t cbkfn,
strncat(cmd, " ", len - 1);
}
- cmd[len - 1] = '\0';
-
- ret = dict_set_dynstr(dict, "cmd-str", cmd);
+ ret = dict_set_dynstr_sizen(dict, "cmd-str", cmd);
if (ret)
goto out;
@@ -11670,14 +10522,14 @@ out:
return ret;
}
-int
+static int
gf_cli_print_bitrot_scrub_status(dict_t *dict)
{
int i = 1;
int j = 0;
int ret = -1;
int count = 0;
- char key[256] = {
+ char key[64] = {
0,
};
char *volname = NULL;
@@ -11700,51 +10552,42 @@ gf_cli_print_bitrot_scrub_status(dict_t *dict)
int8_t scrub_running = 0;
char *scrub_state_op = NULL;
- ret = dict_get_str(dict, "volname", &volname);
+ ret = dict_get_int32_sizen(dict, "count", &count);
+ if (ret) {
+ gf_log("cli", GF_LOG_ERROR,
+ "failed to get count value from dictionary");
+ goto out;
+ }
+
+ ret = dict_get_str_sizen(dict, "volname", &volname);
if (ret)
gf_log("cli", GF_LOG_TRACE, "failed to get volume name");
- ret = dict_get_str(dict, "features.scrub", &state_scrub);
+ ret = dict_get_str_sizen(dict, "features.scrub", &state_scrub);
if (ret)
gf_log("cli", GF_LOG_TRACE, "failed to get scrub state value");
- ret = dict_get_str(dict, "features.scrub-throttle", &scrub_impact);
+ ret = dict_get_str_sizen(dict, "features.scrub-throttle", &scrub_impact);
if (ret)
- gf_log("cli", GF_LOG_TRACE,
- "failed to get scrub impact "
- "value");
+ gf_log("cli", GF_LOG_TRACE, "failed to get scrub impact value");
- ret = dict_get_str(dict, "features.scrub-freq", &scrub_freq);
+ ret = dict_get_str_sizen(dict, "features.scrub-freq", &scrub_freq);
if (ret)
gf_log("cli", GF_LOG_TRACE, "failed to get scrub -freq value");
- ret = dict_get_str(dict, "bitrot_log_file", &bitrot_log_file);
+ ret = dict_get_str_sizen(dict, "bitrot_log_file", &bitrot_log_file);
if (ret)
- gf_log("cli", GF_LOG_TRACE,
- "failed to get bitrot log file "
- "location");
+ gf_log("cli", GF_LOG_TRACE, "failed to get bitrot log file location");
- ret = dict_get_str(dict, "scrub_log_file", &scrub_log_file);
+ ret = dict_get_str_sizen(dict, "scrub_log_file", &scrub_log_file);
if (ret)
- gf_log("cli", GF_LOG_TRACE,
- "failed to get scrubber log file "
- "location");
-
- ret = dict_get_int32(dict, "count", &count);
- if (ret) {
- gf_log("cli", GF_LOG_ERROR,
- "count not get count value from"
- " dictionary");
- goto out;
- }
+ gf_log("cli", GF_LOG_TRACE, "failed to get scrubber log file location");
for (i = 1; i <= count; i++) {
- snprintf(key, 256, "scrub-running-%d", i);
+ snprintf(key, sizeof(key), "scrub-running-%d", i);
ret = dict_get_int8(dict, key, &scrub_running);
if (ret)
- gf_log("cli", GF_LOG_TRACE,
- "failed to get scrubbed "
- "files");
+ gf_log("cli", GF_LOG_TRACE, "failed to get scrubbed files");
if (scrub_running)
break;
}
@@ -11771,56 +10614,41 @@ gf_cli_print_bitrot_scrub_status(dict_t *dict)
node_name = NULL;
last_scrub = NULL;
scrub_time = 0;
- days = 0;
- hours = 0;
- minutes = 0;
- seconds = 0;
error_count = 0;
scrub_files = 0;
unsigned_files = 0;
- snprintf(key, 256, "node-name-%d", i);
+ snprintf(key, sizeof(key), "node-name-%d", i);
ret = dict_get_str(dict, key, &node_name);
if (ret)
gf_log("cli", GF_LOG_TRACE, "failed to get node-name");
- snprintf(key, 256, "scrubbed-files-%d", i);
+ snprintf(key, sizeof(key), "scrubbed-files-%d", i);
ret = dict_get_uint64(dict, key, &scrub_files);
if (ret)
- gf_log("cli", GF_LOG_TRACE,
- "failed to get scrubbed "
- "files");
+ gf_log("cli", GF_LOG_TRACE, "failed to get scrubbed files");
- snprintf(key, 256, "unsigned-files-%d", i);
+ snprintf(key, sizeof(key), "unsigned-files-%d", i);
ret = dict_get_uint64(dict, key, &unsigned_files);
if (ret)
- gf_log("cli", GF_LOG_TRACE,
- "failed to get unsigned "
- "files");
+ gf_log("cli", GF_LOG_TRACE, "failed to get unsigned files");
- snprintf(key, 256, "scrub-duration-%d", i);
+ snprintf(key, sizeof(key), "scrub-duration-%d", i);
ret = dict_get_uint64(dict, key, &scrub_time);
if (ret)
- gf_log("cli", GF_LOG_TRACE,
- "failed to get last scrub "
- "duration");
+ gf_log("cli", GF_LOG_TRACE, "failed to get last scrub duration");
- snprintf(key, 256, "last-scrub-time-%d", i);
+ snprintf(key, sizeof(key), "last-scrub-time-%d", i);
ret = dict_get_str(dict, key, &last_scrub);
if (ret)
- gf_log("cli", GF_LOG_TRACE,
- "failed to get last scrub"
- " time");
- snprintf(key, 256, "error-count-%d", i);
+ gf_log("cli", GF_LOG_TRACE, "failed to get last scrub time");
+ snprintf(key, sizeof(key), "error-count-%d", i);
ret = dict_get_uint64(dict, key, &error_count);
if (ret)
- gf_log("cli", GF_LOG_TRACE,
- "failed to get error "
- "count");
+ gf_log("cli", GF_LOG_TRACE, "failed to get error count");
cli_out("\n%s\n",
- "=========================================="
- "===============");
+ "=========================================================");
cli_out("%s: %s\n", "Node", node_name);
@@ -11849,7 +10677,7 @@ gf_cli_print_bitrot_scrub_status(dict_t *dict)
cli_out("%s:\n", "Corrupted object's [GFID]");
/* Printing list of bad file's (Corrupted object's)*/
for (j = 0; j < error_count; j++) {
- snprintf(key, 256, "quarantine-%d-%d", j, i);
+ snprintf(key, sizeof(key), "quarantine-%d-%d", j, i);
ret = dict_get_str(dict, key, &bad_file_str);
if (!ret) {
cli_out("%s\n", bad_file_str);
@@ -11858,15 +10686,14 @@ gf_cli_print_bitrot_scrub_status(dict_t *dict)
}
}
cli_out("%s\n",
- "=========================================="
- "===============");
+ "=========================================================");
out:
GF_FREE(scrub_state_op);
return 0;
}
-int
+static int
gf_cli_bitrot_cbk(struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
@@ -11890,7 +10717,7 @@ gf_cli_bitrot_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp);
if (ret < 0) {
gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
- "Failed to decode xdr response");
+ XDR_DECODE_FAIL);
goto out;
}
@@ -11919,81 +10746,67 @@ gf_cli_bitrot_cbk(struct rpc_req *req, struct iovec *iov, int count,
ret = dict_unserialize(rsp.dict.dict_val, rsp.dict.dict_len, &dict);
if (ret) {
- gf_log("cli", GF_LOG_ERROR,
- "failed to unserialize "
- "req-buffer to dictionary");
+ gf_log("cli", GF_LOG_ERROR, DICT_UNSERIALIZE_FAIL);
goto out;
}
}
gf_log("cli", GF_LOG_DEBUG, "Received resp to bit rot command");
- ret = dict_get_int32(dict, "type", &type);
+ ret = dict_get_int32_sizen(dict, "type", &type);
if (ret) {
gf_log("cli", GF_LOG_ERROR, "Failed to get command type");
goto out;
}
+ if ((type == GF_BITROT_CMD_SCRUB_STATUS) &&
+ !(global_state->mode & GLUSTER_MODE_XML)) {
+ ret = gf_cli_print_bitrot_scrub_status(dict);
+ if (ret) {
+ gf_log("cli", GF_LOG_ERROR, "Failed to print bitrot scrub status");
+ }
+ goto out;
+ }
+
/* Ignoring the error, as using dict val for cli output only */
- ret = dict_get_str(dict, "scrub-value", &scrub_cmd);
+ ret = dict_get_str_sizen(dict, "volname", &volname);
if (ret)
- gf_log("cli", GF_LOG_TRACE, "Failed to get scrub command");
+ gf_log("cli", GF_LOG_TRACE, "failed to get volume name");
- ret = dict_get_str(dict, "volname", &volname);
+ ret = dict_get_str_sizen(dict, "scrub-value", &scrub_cmd);
if (ret)
- gf_log("cli", GF_LOG_TRACE, "failed to get volume name");
+ gf_log("cli", GF_LOG_TRACE, "Failed to get scrub command");
- ret = dict_get_str(dict, "cmd-str", &cmd_str);
+ ret = dict_get_str_sizen(dict, "cmd-str", &cmd_str);
if (ret)
gf_log("cli", GF_LOG_TRACE, "failed to get command string");
if (cmd_str)
cmd_op = strrchr(cmd_str, ' ') + 1;
- if ((type == GF_BITROT_CMD_SCRUB_STATUS) &&
- !(global_state->mode & GLUSTER_MODE_XML)) {
- ret = gf_cli_print_bitrot_scrub_status(dict);
- if (ret) {
- gf_log("cli", GF_LOG_ERROR,
- "Failed to print bitrot "
- "scrub status");
- }
- goto out;
- }
-
switch (type) {
case GF_BITROT_OPTION_TYPE_ENABLE:
- cli_out(
- "volume bitrot: success bitrot enabled "
- "for volume %s",
- volname);
+ cli_out("volume bitrot: success bitrot enabled for volume %s",
+ volname);
ret = 0;
goto out;
case GF_BITROT_OPTION_TYPE_DISABLE:
- cli_out(
- "volume bitrot: success bitrot disabled "
- "for volume %s",
- volname);
+ cli_out("volume bitrot: success bitrot disabled for volume %s",
+ volname);
ret = 0;
goto out;
case GF_BITROT_CMD_SCRUB_ONDEMAND:
- cli_out(
- "volume bitrot: scrubber started ondemand "
- "for volume %s",
- volname);
+ cli_out("volume bitrot: scrubber started ondemand for volume %s",
+ volname);
ret = 0;
goto out;
case GF_BITROT_OPTION_TYPE_SCRUB:
if (!strncmp("pause", scrub_cmd, sizeof("pause")))
- cli_out(
- "volume bitrot: scrubber paused "
- "for volume %s",
- volname);
+ cli_out("volume bitrot: scrubber paused for volume %s",
+ volname);
if (!strncmp("resume", scrub_cmd, sizeof("resume")))
- cli_out(
- "volume bitrot: scrubber resumed "
- "for volume %s",
- volname);
+ cli_out("volume bitrot: scrubber resumed for volume %s",
+ volname);
ret = 0;
goto out;
case GF_BITROT_OPTION_TYPE_SCRUB_FREQ:
@@ -12017,7 +10830,7 @@ xml_output:
ret = cli_xml_output_vol_profile(dict, rsp.op_ret, rsp.op_errno,
rsp.op_errstr);
if (ret)
- gf_log("cli", GF_LOG_ERROR, "Error outputting to xml");
+ gf_log("cli", GF_LOG_ERROR, XML_ERROR);
goto out;
}
@@ -12030,15 +10843,12 @@ out:
if (dict)
dict_unref(dict);
- free(rsp.dict.dict_val);
- free(rsp.op_errstr);
-
+ gf_free_xdr_cli_rsp(rsp);
cli_cmd_broadcast_response(ret);
-
return ret;
}
-int32_t
+static int32_t
gf_cli_bitrot(call_frame_t *frame, xlator_t *this, void *data)
{
gf_cli_req req = {{
@@ -12047,30 +10857,25 @@ gf_cli_bitrot(call_frame_t *frame, xlator_t *this, void *data)
dict_t *options = NULL;
int ret = -1;
- if (!frame || !this || !data)
- goto out;
-
options = data;
ret = cli_to_glusterd(&req, frame, gf_cli_bitrot_cbk,
(xdrproc_t)xdr_gf_cli_req, options,
GLUSTER_CLI_BITROT, this, cli_rpc_prog, NULL);
if (ret) {
- gf_log("cli", GF_LOG_ERROR,
- "cli_to_glusterd for "
- "bitrot failed");
+ gf_log("cli", GF_LOG_ERROR, "cli_to_glusterd for bitrot failed");
goto out;
}
out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ gf_log("cli", GF_LOG_DEBUG, RETURNING, ret);
GF_FREE(req.dict.dict_val);
return ret;
}
-struct rpc_clnt_procedure gluster_cli_actors[GLUSTER_CLI_MAXVALUE] = {
+static struct rpc_clnt_procedure gluster_cli_actors[GLUSTER_CLI_MAXVALUE] = {
[GLUSTER_CLI_NULL] = {"NULL", NULL},
[GLUSTER_CLI_PROBE] = {"PROBE_QUERY", gf_cli_probe},
[GLUSTER_CLI_DEPROBE] = {"DEPROBE_QUERY", gf_cli_deprobe},
@@ -12116,12 +10921,10 @@ struct rpc_clnt_procedure gluster_cli_actors[GLUSTER_CLI_MAXVALUE] = {
[GLUSTER_CLI_BARRIER_VOLUME] = {"BARRIER VOLUME", gf_cli_barrier_volume},
[GLUSTER_CLI_GET_VOL_OPT] = {"GET_VOL_OPT", gf_cli_get_vol_opt},
[GLUSTER_CLI_BITROT] = {"BITROT", gf_cli_bitrot},
- [GLUSTER_CLI_ATTACH_TIER] = {"ATTACH_TIER", gf_cli_attach_tier},
- [GLUSTER_CLI_TIER] = {"TIER", gf_cli_tier},
[GLUSTER_CLI_GET_STATE] = {"GET_STATE", gf_cli_get_state},
[GLUSTER_CLI_RESET_BRICK] = {"RESET_BRICK", gf_cli_reset_brick},
- [GLUSTER_CLI_REMOVE_TIER_BRICK] = {"DETACH_TIER", gf_cli_remove_tier_brick},
- [GLUSTER_CLI_ADD_TIER_BRICK] = {"ADD_TIER_BRICK", gf_cli_add_tier_brick}};
+ [GLUSTER_CLI_GANESHA] = {"GANESHA", gf_cli_ganesha},
+};
struct rpc_clnt_program cli_prog = {
.progname = "Gluster CLI",
@@ -12131,7 +10934,7 @@ struct rpc_clnt_program cli_prog = {
.proctable = gluster_cli_actors,
};
-struct rpc_clnt_procedure cli_quotad_procs[GF_AGGREGATOR_MAXVALUE] = {
+static struct rpc_clnt_procedure cli_quotad_procs[GF_AGGREGATOR_MAXVALUE] = {
[GF_AGGREGATOR_NULL] = {"NULL", NULL},
[GF_AGGREGATOR_LOOKUP] = {"LOOKUP", NULL},
[GF_AGGREGATOR_GETLIMIT] = {"GETLIMIT", cli_quotad_getlimit},
diff --git a/cli/src/cli-xml-output.c b/cli/src/cli-xml-output.c
index 5dbf37e3d5d..069de75801c 100644
--- a/cli/src/cli-xml-output.c
+++ b/cli/src/cli-xml-output.c
@@ -10,10 +10,10 @@
#include <stdlib.h>
#include "cli.h"
#include "cli1-xdr.h"
-#include "run.h"
-#include "compat.h"
-#include "syscall.h"
-#include "upcall-utils.h"
+#include <glusterfs/run.h>
+#include <glusterfs/compat.h>
+#include <glusterfs/syscall.h>
+#include <glusterfs/upcall-utils.h>
enum gf_task_types { GF_TASK_TYPE_REBALANCE, GF_TASK_TYPE_REMOVE_BRICK };
@@ -64,7 +64,7 @@ cli_begin_xml_output(xmlTextWriterPtr *writer, xmlDocPtr *doc)
int ret = -1;
*writer = xmlNewTextWriterDoc(doc, 0);
- if (writer == NULL) {
+ if (*writer == NULL) {
ret = -1;
goto out;
}
@@ -1526,7 +1526,6 @@ cli_xml_output_vol_status(cli_local_t *local, dict_t *dict)
gf_boolean_t node_present = _gf_true;
int i;
int type = -1;
- int hot_brick_count = -1;
/* <volume> */
ret = xmlTextWriterStartElement(local->writer, (xmlChar *)"volume");
@@ -1564,23 +1563,7 @@ cli_xml_output_vol_status(cli_local_t *local, dict_t *dict)
if (ret)
goto out;
- if (type == GF_CLUSTER_TYPE_TIER) {
- ret = dict_get_int32(dict, "hot_brick_count", &hot_brick_count);
- if (ret)
- goto out;
-
- ret = xmlTextWriterStartElement(local->writer, (xmlChar *)"hotBricks");
- XML_RET_CHECK_AND_GOTO(ret, out);
- }
for (i = 0; i <= index_max; i++) {
- if (type == GF_CLUSTER_TYPE_TIER && i == hot_brick_count) {
- /* </hotBricks>*/
- ret = xmlTextWriterEndElement(local->writer);
- XML_RET_CHECK_AND_GOTO(ret, out);
- ret = xmlTextWriterStartElement(local->writer,
- (xmlChar *)"coldBricks");
- XML_RET_CHECK_AND_GOTO(ret, out);
- }
ret = cli_xml_output_vol_status_common(local->writer, dict, i, &online,
&node_present);
if (ret) {
@@ -1646,12 +1629,6 @@ cli_xml_output_vol_status(cli_local_t *local, dict_t *dict)
/* </node> was opened in cli_xml_output_vol_status_common()*/
ret = xmlTextWriterEndElement(local->writer);
XML_RET_CHECK_AND_GOTO(ret, out);
-
- /* </coldBricks>*/
- if (type == GF_CLUSTER_TYPE_TIER && i == brick_index_max) {
- ret = xmlTextWriterEndElement(local->writer);
- XML_RET_CHECK_AND_GOTO(ret, out);
- }
}
/* Tasks are only present when a normal volume status call is done on a
@@ -1684,15 +1661,15 @@ cli_xml_output_vol_top_rw_perf(xmlTextWriterPtr writer, dict_t *dict,
int ret = -1;
char *filename = NULL;
uint64_t throughput = 0;
- long int time_sec = 0;
- long int time_usec = 0;
- char timestr[256] = {
+ struct timeval tv = {
+ 0,
+ };
+ char timestr[GF_TIMESTR_SIZE] = {
0,
};
char key[1024] = {
0,
};
- int len;
/* <file> */
ret = xmlTextWriterStartElement(writer, (xmlChar *)"file");
@@ -1715,19 +1692,16 @@ cli_xml_output_vol_top_rw_perf(xmlTextWriterPtr writer, dict_t *dict,
XML_RET_CHECK_AND_GOTO(ret, out);
snprintf(key, sizeof(key), "%d-time-sec-%d", brick_index, member_index);
- ret = dict_get_int32(dict, key, (int32_t *)&time_sec);
+ ret = dict_get_int32(dict, key, (int32_t *)&tv.tv_sec);
if (ret)
goto out;
snprintf(key, sizeof(key), "%d-time-usec-%d", brick_index, member_index);
- ret = dict_get_int32(dict, key, (int32_t *)&time_usec);
+ ret = dict_get_int32(dict, key, (int32_t *)&tv.tv_usec);
if (ret)
goto out;
- gf_time_fmt(timestr, sizeof timestr, time_sec, gf_timefmt_FT);
- len = strlen(timestr);
- snprintf(timestr + len, sizeof(timestr) - len, ".%" GF_PRI_SUSECONDS,
- time_usec);
+ gf_time_fmt_tv(timestr, sizeof timestr, &tv, gf_timefmt_FT);
ret = xmlTextWriterWriteFormatElement(writer, (xmlChar *)"time", "%s",
timestr);
XML_RET_CHECK_AND_GOTO(ret, out);
@@ -1976,11 +1950,11 @@ cli_xml_output_vol_profile_stats(xmlTextWriterPtr writer, dict_t *dict,
XML_RET_CHECK_AND_GOTO(ret, out);
ret = xmlTextWriterWriteFormatElement(writer, (xmlChar *)"size",
- "%" PRIu32, (1 << i));
+ "%" PRIu32, (1U << i));
XML_RET_CHECK_AND_GOTO(ret, out);
- snprintf(key, sizeof(key), "%d-%d-read-%d", brick_index, interval,
- (1 << i));
+ snprintf(key, sizeof(key), "%d-%d-read-%" PRIu32, brick_index, interval,
+ (1U << i));
ret = dict_get_uint64(dict, key, &read_count);
if (ret)
read_count = 0;
@@ -1988,8 +1962,8 @@ cli_xml_output_vol_profile_stats(xmlTextWriterPtr writer, dict_t *dict,
"%" PRIu64, read_count);
XML_RET_CHECK_AND_GOTO(ret, out);
- snprintf(key, sizeof(key), "%d-%d-write-%d", brick_index, interval,
- (1 << i));
+ snprintf(key, sizeof(key), "%d-%d-write-%" PRIu32, brick_index,
+ interval, (1U << i));
ret = dict_get_uint64(dict, key, &write_count);
if (ret)
write_count = 0;
@@ -2471,24 +2445,6 @@ cli_xml_output_vol_info(cli_local_t *local, dict_t *dict)
int j = 1;
char *caps __attribute__((unused)) = NULL;
int k __attribute__((unused)) = 0;
- int index = 1;
- int tier_vol_type = 0;
- /* hot dist count is always zero so need for it to be
- * included in the array.*/
- int hot_dist_count = 0;
- values c = 0;
- char *keys[MAX] = {
- [COLD_BRICK_COUNT] = "volume%d.cold_brick_count",
- [COLD_TYPE] = "volume%d.cold_type",
- [COLD_DIST_COUNT] = "volume%d.cold_dist_count",
- [COLD_REPLICA_COUNT] = "volume%d.cold_replica_count",
- [COLD_ARBITER_COUNT] = "volume%d.cold_arbiter_count",
- [COLD_DISPERSE_COUNT] = "volume%d.cold_disperse_count",
- [COLD_REDUNDANCY_COUNT] = "volume%d.cold_redundancy_count",
- [HOT_BRICK_COUNT] = "volume%d.hot_brick_count",
- [HOT_TYPE] = "volume%d.hot_type",
- [HOT_REPLICA_COUNT] = "volume%d.hot_replica_count"};
- int value[MAX] = {};
ret = dict_get_int32(dict, "count", &count);
if (ret)
@@ -2548,8 +2504,9 @@ cli_xml_output_vol_info(cli_local_t *local, dict_t *dict)
ret = dict_get_int32(dict, key, &dist_count);
if (ret)
goto out;
- ret = xmlTextWriterWriteFormatElement(
- local->writer, (xmlChar *)"distCount", "%d", dist_count);
+ ret = xmlTextWriterWriteFormatElement(local->writer,
+ (xmlChar *)"distCount", "%d",
+ (brick_count / dist_count));
XML_RET_CHECK_AND_GOTO(ret, out);
snprintf(key, sizeof(key), "volume%d.stripe_count", i);
@@ -2618,297 +2575,53 @@ cli_xml_output_vol_info(cli_local_t *local, dict_t *dict)
local->writer, (xmlChar *)"transport", "%d", transport);
XML_RET_CHECK_AND_GOTO(ret, out);
-#ifdef HAVE_BD_XLATOR
- /* <xlators> */
- ret = xmlTextWriterStartElement(local->writer, (xmlChar *)"xlators");
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- for (k = 0;; k++) {
- snprintf(key, sizeof(key), "volume%d.xlator%d", i, k);
- ret = dict_get_str(dict, key, &caps);
- if (ret)
- break;
-
- /* <xlator> */
- ret = xmlTextWriterStartElement(local->writer, (xmlChar *)"xlator");
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- ret = xmlTextWriterWriteFormatElement(
- local->writer, (xmlChar *)"name", "%s", caps);
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- /* <capabilities> */
- ret = xmlTextWriterStartElement(local->writer,
- (xmlChar *)"capabilities");
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- j = 0;
- for (j = 0;; j++) {
- snprintf(key, sizeof(key), "volume%d.xlator%d.caps%d", i, k, j);
- ret = dict_get_str(dict, key, &caps);
- if (ret)
- break;
- ret = xmlTextWriterWriteFormatElement(
- local->writer, (xmlChar *)"capability", "%s", caps);
- XML_RET_CHECK_AND_GOTO(ret, out);
- }
- /* </capabilities> */
- ret = xmlTextWriterEndElement(local->writer);
- XML_RET_CHECK_AND_GOTO(ret, out);
- /* </xlator> */
- ret = xmlTextWriterEndElement(local->writer);
- XML_RET_CHECK_AND_GOTO(ret, out);
- }
- ret = xmlTextWriterFullEndElement(local->writer);
- XML_RET_CHECK_AND_GOTO(ret, out);
- /* </xlators> */
-#endif
j = 1;
/* <bricks> */
ret = xmlTextWriterStartElement(local->writer, (xmlChar *)"bricks");
XML_RET_CHECK_AND_GOTO(ret, out);
- if (type == GF_CLUSTER_TYPE_TIER) {
- /*the values for hot stripe, disperse and redundancy
- * should not be looped in here as they are zero
- * always */
- for (c = COLD_BRICK_COUNT; c < MAX; c++) {
- snprintf(key, 256, keys[c], i);
- ret = dict_get_int32(dict, key, &value[c]);
- if (ret)
- goto out;
- }
-
- hot_dist_count = (value[HOT_REPLICA_COUNT]
- ? value[HOT_REPLICA_COUNT]
- : 1);
-
- tier_vol_type = get_vol_type(value[HOT_TYPE], hot_dist_count,
- value[HOT_BRICK_COUNT]);
-
- if ((value[HOT_TYPE] != GF_CLUSTER_TYPE_TIER) &&
- (value[HOT_TYPE] > 0) &&
- (hot_dist_count < value[HOT_BRICK_COUNT]))
- tier_vol_type = value[HOT_TYPE] + GF_CLUSTER_TYPE_MAX - 1;
-
- ret = xmlTextWriterStartElement(local->writer,
- (xmlChar *)"hotBricks");
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- ret = xmlTextWriterWriteFormatElement(
- local->writer, (xmlChar *)"hotBrickType", "%s",
- vol_type_str[tier_vol_type]);
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- ret = xmlTextWriterWriteFormatElement(
- local->writer, (xmlChar *)"hotreplicaCount", "%d",
- value[HOT_REPLICA_COUNT]);
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- ret = xmlTextWriterWriteFormatElement(local->writer,
- (xmlChar *)"hotbrickCount",
- "%d", value[HOT_BRICK_COUNT]);
+ while (j <= brick_count) {
+ ret = xmlTextWriterStartElement(local->writer, (xmlChar *)"brick");
XML_RET_CHECK_AND_GOTO(ret, out);
- if (value[HOT_TYPE] == GF_CLUSTER_TYPE_NONE ||
- value[HOT_TYPE] == GF_CLUSTER_TYPE_TIER) {
- ret = xmlTextWriterWriteFormatElement(
- local->writer, (xmlChar *)"numberOfBricks", "%d",
- value[HOT_BRICK_COUNT]);
- } else {
- ret = xmlTextWriterWriteFormatElement(
- local->writer, (xmlChar *)"numberOfBricks", "%d x %d = %d",
- (value[HOT_BRICK_COUNT] / hot_dist_count), hot_dist_count,
- value[HOT_BRICK_COUNT]);
- }
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- while (index <= value[HOT_BRICK_COUNT]) {
- snprintf(key, 1024, "volume%d.brick%d", i, index);
- ret = dict_get_str(dict, key, &brick);
- if (ret)
- goto out;
-
- ret = xmlTextWriterStartElement(local->writer,
- (xmlChar *)"brick");
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- snprintf(key, sizeof(key), "volume%d.brick%d.uuid", i, index);
- ret = dict_get_str(dict, key, &uuid);
- if (ret)
- goto out;
- ret = xmlTextWriterWriteFormatAttribute(
- local->writer, (xmlChar *)"uuid", "%s", uuid);
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- ret = xmlTextWriterWriteFormatString(local->writer, "%s",
- brick);
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- ret = xmlTextWriterWriteFormatElement(
- local->writer, (xmlChar *)"name", "%s", brick);
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- ret = xmlTextWriterWriteFormatElement(
- local->writer, (xmlChar *)"hostUuid", "%s", uuid);
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- ret = xmlTextWriterEndElement(local->writer);
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- index++;
- }
- ret = xmlTextWriterEndElement(local->writer);
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- tier_vol_type = get_vol_type(value[COLD_TYPE],
- value[COLD_DIST_COUNT],
- value[COLD_BRICK_COUNT]);
-
- ret = xmlTextWriterStartElement(local->writer,
- (xmlChar *)"coldBricks");
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- ret = xmlTextWriterWriteFormatElement(
- local->writer, (xmlChar *)"coldBrickType", "%s",
- vol_type_str[tier_vol_type]);
+ snprintf(key, sizeof(key), "volume%d.brick%d.uuid", i, j);
+ ret = dict_get_str(dict, key, &uuid);
+ if (ret)
+ goto out;
+ ret = xmlTextWriterWriteFormatAttribute(
+ local->writer, (xmlChar *)"uuid", "%s", uuid);
XML_RET_CHECK_AND_GOTO(ret, out);
- ret = xmlTextWriterWriteFormatElement(
- local->writer, (xmlChar *)"coldreplicaCount", "%d",
- value[COLD_REPLICA_COUNT]);
+ snprintf(key, sizeof(key), "volume%d.brick%d", i, j);
+ ret = dict_get_str(dict, key, &brick);
+ if (ret)
+ goto out;
+ ret = xmlTextWriterWriteFormatString(local->writer, "%s", brick);
XML_RET_CHECK_AND_GOTO(ret, out);
ret = xmlTextWriterWriteFormatElement(
- local->writer, (xmlChar *)"coldarbiterCount", "%d",
- value[COLD_ARBITER_COUNT]);
+ local->writer, (xmlChar *)"name", "%s", brick);
XML_RET_CHECK_AND_GOTO(ret, out);
ret = xmlTextWriterWriteFormatElement(
- local->writer, (xmlChar *)"coldbrickCount", "%d",
- value[COLD_BRICK_COUNT]);
+ local->writer, (xmlChar *)"hostUuid", "%s", uuid);
XML_RET_CHECK_AND_GOTO(ret, out);
+ snprintf(key, sizeof(key), "volume%d.brick%d.isArbiter", i, j);
+ if (dict_get(dict, key))
+ isArbiter = 1;
+ else
+ isArbiter = 0;
ret = xmlTextWriterWriteFormatElement(
- local->writer, (xmlChar *)"colddisperseCount", "%d",
- value[COLD_DISPERSE_COUNT]);
+ local->writer, (xmlChar *)"isArbiter", "%d", isArbiter);
XML_RET_CHECK_AND_GOTO(ret, out);
- if (value[COLD_TYPE] == GF_CLUSTER_TYPE_NONE ||
- value[COLD_TYPE] == GF_CLUSTER_TYPE_TIER) {
- ret = xmlTextWriterWriteFormatElement(
- local->writer, (xmlChar *)"numberOfBricks", "%d",
- value[COLD_BRICK_COUNT]);
- } else if (value[COLD_TYPE] == GF_CLUSTER_TYPE_DISPERSE) {
- ret = xmlTextWriterWriteFormatElement(
- local->writer, (xmlChar *)"numberOfBricks",
- " %d x (%d + %d) = %d",
- (value[COLD_BRICK_COUNT] / value[COLD_DIST_COUNT]),
- value[COLD_DISPERSE_COUNT] - value[COLD_REDUNDANCY_COUNT],
- value[COLD_REDUNDANCY_COUNT], value[COLD_BRICK_COUNT]);
- } else {
- ret = xmlTextWriterWriteFormatElement(
- local->writer, (xmlChar *)"numberOfBricks", "%d x %d = %d",
- (value[COLD_BRICK_COUNT] / value[COLD_DIST_COUNT]),
- value[COLD_DIST_COUNT], value[COLD_BRICK_COUNT]);
- }
- XML_RET_CHECK_AND_GOTO(ret, out);
- index = value[HOT_BRICK_COUNT] + 1;
-
- while (index <= brick_count) {
- snprintf(key, 1024, "volume%d.brick%d", i, index);
- ret = dict_get_str(dict, key, &brick);
- if (ret)
- goto out;
-
- ret = xmlTextWriterStartElement(local->writer,
- (xmlChar *)"brick");
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- snprintf(key, sizeof(key), "volume%d.brick%d.uuid", i, index);
- ret = dict_get_str(dict, key, &uuid);
- if (ret)
- goto out;
- ret = xmlTextWriterWriteFormatAttribute(
- local->writer, (xmlChar *)"uuid", "%s", uuid);
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- ret = xmlTextWriterWriteFormatString(local->writer, "%s",
- brick);
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- ret = xmlTextWriterWriteFormatElement(
- local->writer, (xmlChar *)"name", "%s", brick);
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- ret = xmlTextWriterWriteFormatElement(
- local->writer, (xmlChar *)"hostUuid", "%s", uuid);
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- snprintf(key, sizeof(key), "volume%d.brick%d.isArbiter", i,
- index);
- if (dict_get(dict, key))
- isArbiter = 1;
- else
- isArbiter = 0;
- ret = xmlTextWriterWriteFormatElement(
- local->writer, (xmlChar *)"isArbiter", "%d", isArbiter);
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- ret = xmlTextWriterEndElement(local->writer);
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- index++;
- }
+ /* </brick> */
ret = xmlTextWriterEndElement(local->writer);
XML_RET_CHECK_AND_GOTO(ret, out);
- } else {
- while (j <= brick_count) {
- ret = xmlTextWriterStartElement(local->writer,
- (xmlChar *)"brick");
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- snprintf(key, sizeof(key), "volume%d.brick%d.uuid", i, j);
- ret = dict_get_str(dict, key, &uuid);
- if (ret)
- goto out;
- ret = xmlTextWriterWriteFormatAttribute(
- local->writer, (xmlChar *)"uuid", "%s", uuid);
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- snprintf(key, sizeof(key), "volume%d.brick%d", i, j);
- ret = dict_get_str(dict, key, &brick);
- if (ret)
- goto out;
- ret = xmlTextWriterWriteFormatString(local->writer, "%s",
- brick);
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- ret = xmlTextWriterWriteFormatElement(
- local->writer, (xmlChar *)"name", "%s", brick);
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- ret = xmlTextWriterWriteFormatElement(
- local->writer, (xmlChar *)"hostUuid", "%s", uuid);
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- snprintf(key, sizeof(key), "volume%d.brick%d.isArbiter", i, j);
- if (dict_get(dict, key))
- isArbiter = 1;
- else
- isArbiter = 0;
- ret = xmlTextWriterWriteFormatElement(
- local->writer, (xmlChar *)"isArbiter", "%d", isArbiter);
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- /* </brick> */
- ret = xmlTextWriterEndElement(local->writer);
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- j++;
- }
+ j++;
}
/* </bricks> */
ret = xmlTextWriterEndElement(local->writer);
@@ -3064,7 +2777,9 @@ cli_xml_output_peer_hostnames(xmlTextWriterPtr writer, dict_t *dict,
XML_RET_CHECK_AND_GOTO(ret, out);
for (i = 0; i < count; i++) {
- snprintf(key, sizeof(key), "%s.hostname%d", prefix, i);
+ ret = snprintf(key, sizeof(key), "%s.hostname%d", prefix, i);
+ if (ret < 0)
+ goto out;
ret = dict_get_str(dict, key, &hostname);
if (ret)
goto out;
@@ -3409,6 +3124,10 @@ cli_xml_output_vol_rebalance_status(xmlTextWriterPtr writer, dict_t *dict,
"%" PRIu64, total_skipped);
XML_RET_CHECK_AND_GOTO(ret, out);
+ if (overall_status == -1) {
+ overall_status = status_rcd;
+ }
+
ret = xmlTextWriterWriteFormatElement(writer, (xmlChar *)"status", "%d",
overall_status);
XML_RET_CHECK_AND_GOTO(ret, out);
@@ -3430,90 +3149,6 @@ out:
gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
return ret;
}
-
-int
-cli_xml_output_vol_tier_status(xmlTextWriterPtr writer, dict_t *dict,
- enum gf_task_types task_type)
-{
- int ret = -1;
- int count = 0;
- char *node_name = NULL;
- char *status_str = NULL;
- uint64_t promoted = 0;
- uint64_t demoted = 0;
- int i = 1;
- char key[1024] = {
- 0,
- };
- gf_defrag_status_t status_rcd = GF_DEFRAG_STATUS_NOT_STARTED;
-
- GF_VALIDATE_OR_GOTO("cli", dict, out);
-
- ret = dict_get_int32(dict, "count", &count);
- if (ret) {
- gf_log("cli", GF_LOG_ERROR, "count not set");
- goto out;
- }
-
- ret = xmlTextWriterWriteFormatElement(writer, (xmlChar *)"nodeCount", "%d",
- count);
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- while (i <= count) {
- promoted = 0;
- node_name = NULL;
- demoted = 0;
-
- ret = xmlTextWriterStartElement(writer, (xmlChar *)"node");
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- snprintf(key, sizeof(key), "node-name-%d", i);
- ret = dict_get_str(dict, key, &node_name);
- if (ret)
- goto out;
- ret = xmlTextWriterWriteFormatElement(writer, (xmlChar *)"nodeName",
- "%s", node_name);
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- snprintf(key, sizeof(key), "promoted-%d", i);
- ret = dict_get_uint64(dict, key, &promoted);
- if (ret)
- goto out;
- ret = xmlTextWriterWriteFormatElement (writer,
- (xmlChar *)"promoted"
- "Files", "%"PRIu64,
- promoted);
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- snprintf(key, sizeof(key), "demoted-%d", i);
- ret = dict_get_uint64(dict, key, &demoted);
- if (ret)
- goto out;
- ret = xmlTextWriterWriteFormatElement (writer,
- (xmlChar *)"demoted"
- "Files", "%"PRIu64,
- demoted);
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- snprintf(key, sizeof(key), "status-%d", i);
- ret = dict_get_int32(dict, key, (int32_t *)&status_rcd);
-
- status_str = cli_vol_task_status_str[status_rcd];
-
- ret = xmlTextWriterWriteFormatElement(writer, (xmlChar *)"statusStr",
- "%s", status_str);
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- ret = xmlTextWriterEndElement(writer);
- XML_RET_CHECK_AND_GOTO(ret, out);
-
- i++;
- }
-
-out:
- gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
- return ret;
-}
#endif
int
@@ -3548,12 +3183,6 @@ cli_xml_output_vol_rebalance(gf_cli_defrag_type op, dict_t *dict, int op_ret,
ret = xmlTextWriterWriteFormatElement(writer, (xmlChar *)"op", "%d", op);
XML_RET_CHECK_AND_GOTO(ret, out);
- if (GF_DEFRAG_CMD_STATUS_TIER == op) {
- ret = cli_xml_output_vol_tier_status(writer, dict,
- GF_TASK_TYPE_REBALANCE);
- if (ret)
- goto out;
- }
if ((GF_DEFRAG_CMD_STOP == op) || (GF_DEFRAG_CMD_STATUS == op)) {
ret = cli_xml_output_vol_rebalance_status(writer, dict,
GF_TASK_TYPE_REBALANCE);
@@ -3576,10 +3205,9 @@ out:
}
int
-cli_xml_output_vol_remove_brick_detach_tier(gf_boolean_t status_op,
- dict_t *dict, int op_ret,
- int op_errno, char *op_errstr,
- const char *op)
+cli_xml_output_vol_remove_brick(gf_boolean_t status_op, dict_t *dict,
+ int op_ret, int op_errno, char *op_errstr,
+ const char *op)
{
#if (HAVE_LIB_XML)
int ret = -1;
@@ -3949,20 +3577,21 @@ cli_xml_output_vol_gsync_status(dict_t *dict, xmlTextWriterPtr writer)
char *volume_next = NULL;
char *slave = NULL;
char *slave_next = NULL;
- char *title_values[] = {"master_node", "", "master_brick", "slave_user",
- "slave", "slave_node", "status", "crawl_status",
- /* last_synced */
- "", "entry", "data", "meta", "failures",
- /* checkpoint_time */
- "", "checkpoint_completed",
- /* checkpoint_completion_time */
- "", "master_node_uuid",
- /* last_synced_utc */
- "last_synced",
- /* checkpoint_time_utc */
- "checkpoint_time",
- /* checkpoint_completion_time_utc */
- "checkpoint_completion_time"};
+ static const char *title_values[] = {
+ "master_node", "", "master_brick", "slave_user", "slave", "slave_node",
+ "status", "crawl_status",
+ /* last_synced */
+ "", "entry", "data", "meta", "failures",
+ /* checkpoint_time */
+ "", "checkpoint_completed",
+ /* checkpoint_completion_time */
+ "", "master_node_uuid",
+ /* last_synced_utc */
+ "last_synced",
+ /* checkpoint_time_utc */
+ "checkpoint_time",
+ /* checkpoint_completion_time_utc */
+ "checkpoint_completion_time"};
GF_ASSERT(dict);
@@ -4103,6 +3732,8 @@ cli_xml_output_vol_gsync_status(dict_t *dict, xmlTextWriterPtr writer)
}
}
out:
+ if (status_values)
+ GF_FREE(status_values);
gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret);
return ret;
}
@@ -4178,6 +3809,10 @@ cli_xml_output_vol_gsync(dict_t *dict, int op_ret, int op_errno,
break;
case GF_GSYNC_OPTION_TYPE_STATUS:
ret = cli_xml_output_vol_gsync_status(dict, writer);
+ if (ret) {
+ gf_log("cli", GF_LOG_DEBUG, "Failed to get gsync status");
+ goto out;
+ }
break;
default:
ret = 0;
@@ -4567,7 +4202,9 @@ cli_xml_snapshot_info_snap_vol(xmlTextWriterPtr writer, xmlDocPtr doc,
ret = xmlTextWriterStartElement(writer, (xmlChar *)"snapVolume");
XML_RET_CHECK_AND_GOTO(ret, out);
- snprintf(key, sizeof(key), "%s.volname", keyprefix);
+ ret = snprintf(key, sizeof(key), "%s.volname", keyprefix);
+ if (ret < 0)
+ goto out;
ret = dict_get_str(dict, key, &buffer);
if (ret) {
@@ -4579,7 +4216,9 @@ cli_xml_snapshot_info_snap_vol(xmlTextWriterPtr writer, xmlDocPtr doc,
buffer);
XML_RET_CHECK_AND_GOTO(ret, out);
- snprintf(key, sizeof(key), "%s.vol-status", keyprefix);
+ ret = snprintf(key, sizeof(key), "%s.vol-status", keyprefix);
+ if (ret < 0)
+ goto out;
ret = dict_get_str(dict, key, &buffer);
if (ret) {
@@ -4594,7 +4233,10 @@ cli_xml_snapshot_info_snap_vol(xmlTextWriterPtr writer, xmlDocPtr doc,
/* If the command is snap_driven then we need to show origin volume
* info. Else this is shown in the start of info display.*/
if (snap_driven) {
- snprintf(key, sizeof(key), "%s.", keyprefix);
+ ret = snprintf(key, sizeof(key), "%s.", keyprefix);
+ if (ret < 0)
+ goto out;
+
ret = cli_xml_snapshot_info_orig_vol(writer, doc, dict, key);
if (ret) {
gf_log("cli", GF_LOG_ERROR,
@@ -4645,7 +4287,9 @@ cli_xml_snapshot_info_per_snap(xmlTextWriterPtr writer, xmlDocPtr doc,
ret = xmlTextWriterStartElement(writer, (xmlChar *)"snapshot");
XML_RET_CHECK_AND_GOTO(ret, out);
- snprintf(key_buffer, sizeof(key_buffer), "%s.snapname", keyprefix);
+ ret = snprintf(key_buffer, sizeof(key_buffer), "%s.snapname", keyprefix);
+ if (ret < 0)
+ goto out;
ret = dict_get_str(dict, key_buffer, &buffer);
if (ret) {
@@ -4657,7 +4301,9 @@ cli_xml_snapshot_info_per_snap(xmlTextWriterPtr writer, xmlDocPtr doc,
buffer);
XML_RET_CHECK_AND_GOTO(ret, out);
- snprintf(key_buffer, sizeof(key_buffer), "%s.snap-id", keyprefix);
+ ret = snprintf(key_buffer, sizeof(key_buffer), "%s.snap-id", keyprefix);
+ if (ret < 0)
+ goto out;
ret = dict_get_str(dict, key_buffer, &buffer);
if (ret) {
@@ -4669,7 +4315,9 @@ cli_xml_snapshot_info_per_snap(xmlTextWriterPtr writer, xmlDocPtr doc,
buffer);
XML_RET_CHECK_AND_GOTO(ret, out);
- snprintf(key_buffer, sizeof(key_buffer), "%s.snap-desc", keyprefix);
+ ret = snprintf(key_buffer, sizeof(key_buffer), "%s.snap-desc", keyprefix);
+ if (ret < 0)
+ goto out;
ret = dict_get_str(dict, key_buffer, &buffer);
if (!ret) {
@@ -4681,7 +4329,9 @@ cli_xml_snapshot_info_per_snap(xmlTextWriterPtr writer, xmlDocPtr doc,
}
XML_RET_CHECK_AND_GOTO(ret, out);
- snprintf(key_buffer, sizeof(key_buffer), "%s.snap-time", keyprefix);
+ ret = snprintf(key_buffer, sizeof(key_buffer), "%s.snap-time", keyprefix);
+ if (ret < 0)
+ goto out;
ret = dict_get_str(dict, key_buffer, &buffer);
if (ret) {
@@ -4693,7 +4343,10 @@ cli_xml_snapshot_info_per_snap(xmlTextWriterPtr writer, xmlDocPtr doc,
buffer);
XML_RET_CHECK_AND_GOTO(ret, out);
- snprintf(key_buffer, sizeof(key_buffer), "%s.vol-count", keyprefix);
+ ret = snprintf(key_buffer, sizeof(key_buffer), "%s.vol-count", keyprefix);
+ if (ret < 0)
+ goto out;
+
ret = dict_get_int32(dict, key_buffer, &volcount);
if (ret) {
gf_log("cli", GF_LOG_ERROR, "Fail to get snap vol count");
@@ -4707,7 +4360,10 @@ cli_xml_snapshot_info_per_snap(xmlTextWriterPtr writer, xmlDocPtr doc,
ret = dict_get_int32(dict, key_buffer, &volcount);
/* Display info of each snapshot volume */
for (i = 1; i <= volcount; i++) {
- snprintf(key_buffer, sizeof(key_buffer), "%s.vol%d", keyprefix, i);
+ ret = snprintf(key_buffer, sizeof(key_buffer), "%s.vol%d", keyprefix,
+ i);
+ if (ret < 0)
+ goto out;
ret = cli_xml_snapshot_info_snap_vol(writer, doc, dict, key_buffer,
snap_driven);
@@ -4831,7 +4487,9 @@ cli_xml_snapshot_volume_status(xmlTextWriterPtr writer, xmlDocPtr doc,
GF_ASSERT(dict);
GF_ASSERT(keyprefix);
- snprintf(key, sizeof(key), "%s.brickcount", keyprefix);
+ ret = snprintf(key, sizeof(key), "%s.brickcount", keyprefix);
+ if (ret < 0)
+ goto out;
ret = dict_get_int32(dict, key, &brickcount);
if (ret) {
@@ -4849,7 +4507,9 @@ cli_xml_snapshot_volume_status(xmlTextWriterPtr writer, xmlDocPtr doc,
ret = xmlTextWriterStartElement(writer, (xmlChar *)"brick");
XML_RET_CHECK_AND_GOTO(ret, out);
- snprintf(key, sizeof(key), "%s.brick%d.path", keyprefix, i);
+ ret = snprintf(key, sizeof(key), "%s.brick%d.path", keyprefix, i);
+ if (ret < 0)
+ goto out;
ret = dict_get_str(dict, key, &buffer);
if (ret) {
@@ -4868,7 +4528,9 @@ cli_xml_snapshot_volume_status(xmlTextWriterPtr writer, xmlDocPtr doc,
buffer);
XML_RET_CHECK_AND_GOTO(ret, out);
- snprintf(key, sizeof(key), "%s.brick%d.vgname", keyprefix, i);
+ ret = snprintf(key, sizeof(key), "%s.brick%d.vgname", keyprefix, i);
+ if (ret < 0)
+ goto out;
ret = dict_get_str(dict, key, &buffer);
if (ret) {
@@ -4881,7 +4543,9 @@ cli_xml_snapshot_volume_status(xmlTextWriterPtr writer, xmlDocPtr doc,
XML_RET_CHECK_AND_GOTO(ret, out);
- snprintf(key, sizeof(key), "%s.brick%d.status", keyprefix, i);
+ ret = snprintf(key, sizeof(key), "%s.brick%d.status", keyprefix, i);
+ if (ret < 0)
+ goto out;
ret = dict_get_str(dict, key, &buffer);
if (ret) {
@@ -4894,7 +4558,9 @@ cli_xml_snapshot_volume_status(xmlTextWriterPtr writer, xmlDocPtr doc,
XML_RET_CHECK_AND_GOTO(ret, out);
- snprintf(key, sizeof(key), "%s.brick%d.pid", keyprefix, i);
+ ret = snprintf(key, sizeof(key), "%s.brick%d.pid", keyprefix, i);
+ if (ret < 0)
+ goto out;
ret = dict_get_int32(dict, key, &pid);
if (ret) {
@@ -4907,7 +4573,9 @@ cli_xml_snapshot_volume_status(xmlTextWriterPtr writer, xmlDocPtr doc,
XML_RET_CHECK_AND_GOTO(ret, out);
- snprintf(key, sizeof(key), "%s.brick%d.data", keyprefix, i);
+ ret = snprintf(key, sizeof(key), "%s.brick%d.data", keyprefix, i);
+ if (ret < 0)
+ goto out;
ret = dict_get_str(dict, key, &buffer);
if (ret) {
@@ -4920,7 +4588,10 @@ cli_xml_snapshot_volume_status(xmlTextWriterPtr writer, xmlDocPtr doc,
XML_RET_CHECK_AND_GOTO(ret, out);
- snprintf(key, sizeof(key), "%s.brick%d.lvsize", keyprefix, i);
+ ret = snprintf(key, sizeof(key), "%s.brick%d.lvsize", keyprefix, i);
+ if (ret < 0)
+ goto out;
+
ret = dict_get_str(dict, key, &buffer);
if (ret) {
gf_log("cli", GF_LOG_ERROR, "Unable to get LV Size");
diff --git a/cli/src/cli.c b/cli/src/cli.c
index d7cd43e13df..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;
@@ -433,7 +496,6 @@ parse_cmdline(int argc, char *argv[], struct cli_state *state)
int i = 0;
int j = 0;
char *opt = NULL;
- gf_boolean_t geo_rep_config = _gf_false;
state->argc = argc - 1;
state->argv = &argv[1];
@@ -447,31 +509,33 @@ parse_cmdline(int argc, char *argv[], struct cli_state *state)
if (state->argc > GEO_REP_CMD_CONFIG_INDEX &&
strtail(state->argv[GEO_REP_CMD_INDEX], "geo") &&
strtail(state->argv[GEO_REP_CMD_CONFIG_INDEX], "co"))
- geo_rep_config = _gf_true;
+ goto done;
for (i = 0; i < state->argc; i++) {
opt = strtail(state->argv[i], "--");
- if (opt && !geo_rep_config) {
- ret = cli_opt_parse(opt, state);
- if (ret == -1) {
- cli_out("unrecognized option --%s", opt);
- return ret;
- } else if (ret == -2) {
- return ret;
- }
- for (j = i; j < state->argc - 1; j++)
- state->argv[j] = state->argv[j + 1];
- state->argc--;
- /* argv shifted, next check should be at i again */
- i--;
- if (ret == 1) {
- /* end of cli options */
- ret = 0;
- break;
- }
+ if (!opt)
+ continue;
+ ret = cli_opt_parse(opt, state);
+ if (ret == -1) {
+ cli_out("unrecognized option --%s\n", opt);
+ usage();
+ return ret;
+ } else if (ret == -2) {
+ return ret;
+ }
+ for (j = i; j < state->argc - 1; j++)
+ state->argv[j] = state->argv[j + 1];
+ state->argc--;
+ /* argv shifted, next check should be at i again */
+ i--;
+ if (ret == 1) {
+ /* end of cli options */
+ ret = 0;
+ break;
}
}
+done:
state->argv[state->argc] = NULL;
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;
}
@@ -623,10 +686,16 @@ 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.
@@ -636,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;
@@ -645,6 +714,7 @@ cli_rpc_init(struct cli_state *state)
"Connecting to remote glusterd at "
"%s",
state->remote_host);
+
ret = dict_set_str(options, "remote-host", state->remote_host);
if (ret)
goto out;
@@ -657,14 +727,13 @@ cli_rpc_init(struct cli_state *state)
goto out;
ret = dict_set_str(options, "transport.address-family", addr_family);
-
if (ret)
goto out;
} else {
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;
@@ -682,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);
@@ -726,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)
@@ -780,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);
diff --git a/cli/src/cli.h b/cli/src/cli.h
index 773297e4be8..c0d933e8f8a 100644
--- a/cli/src/cli.h
+++ b/cli/src/cli.h
@@ -11,12 +11,13 @@
#define __CLI_H__
#include "rpc-clnt.h"
-#include "glusterfs.h"
+#include <glusterfs/glusterfs.h>
#include "protocol-common.h"
-#include "logging.h"
-#include "quota-common-utils.h"
+#include <glusterfs/logging.h>
+#include <glusterfs/quota-common-utils.h>
#include "cli1-xdr.h"
+#include "gd-common-utils.h"
#if (HAVE_LIB_XML)
#include <libxml/encoding.h>
@@ -39,8 +40,8 @@ enum argp_option_keys {
ARGP_PORT_KEY = 'p',
};
-int cli_default_conn_timeout;
-int cli_ten_minutes_timeout;
+extern int cli_default_conn_timeout;
+extern int cli_ten_minutes_timeout;
typedef enum {
COLD_BRICK_COUNT,
@@ -136,6 +137,7 @@ struct cli_state {
gf_loglevel_t log_level;
char *glusterd_sock;
+ char *address_family;
};
struct cli_local {
@@ -187,6 +189,12 @@ typedef ssize_t (*cli_serialize_t)(struct iovec outmsg, void *args);
extern struct cli_state *global_state; /* use only in readline callback */
+extern struct rpc_clnt *global_quotad_rpc;
+
+extern struct rpc_clnt *global_rpc;
+
+extern rpc_clnt_prog_t *cli_rpc_prog;
+
typedef const char *(*cli_selector_t)(void *wcon);
char *
@@ -239,6 +247,19 @@ _cli_err(const char *fmt, ...);
\
} while (0)
+#define usage() \
+ do { \
+ cli_out( \
+ " Usage: gluster [options] <help> <peer>" \
+ " <pool> <volume>\n" \
+ " Options:\n" \
+ " --help Shows the help information\n" \
+ " --version Shows the version\n" \
+ " --print-logdir Shows the log directory\n" \
+ " --print-statedumpdir Shows the state dump directory\n"); \
+ \
+ } while (0)
+
int
cli_submit_request(struct rpc_clnt *rpc, void *req, call_frame_t *frame,
rpc_clnt_prog_t *prog, int procnum, struct iobref *iobref,
@@ -252,7 +273,8 @@ int32_t
cli_cmd_volume_reset_parse(const char **words, int wordcount, dict_t **opt);
int32_t
-cli_cmd_gsync_set_parse(const char **words, int wordcount, dict_t **opt);
+cli_cmd_gsync_set_parse(struct cli_state *state, const char **words,
+ int wordcount, dict_t **opt, char **errstr);
int32_t
cli_cmd_quota_parse(const char **words, int wordcount, dict_t **opt);
@@ -268,6 +290,10 @@ cli_cmd_volume_set_parse(struct cli_state *state, const char **words,
int wordcount, dict_t **options, char **op_errstr);
int32_t
+cli_cmd_ganesha_parse(struct cli_state *state, const char **words,
+ int wordcount, dict_t **options, char **op_errstr);
+
+int32_t
cli_cmd_get_state_parse(struct cli_state *state, const char **words,
int wordcount, dict_t **options, char **op_errstr);
@@ -276,17 +302,6 @@ cli_cmd_volume_add_brick_parse(struct cli_state *state, const char **words,
int wordcount, dict_t **options, int *type);
int32_t
-cli_cmd_volume_detach_tier_parse(const char **words, int wordcount,
- dict_t **options, int *question);
-
-int32_t
-cli_cmd_volume_tier_parse(const char **words, int wordcount, dict_t **options);
-
-int32_t
-cli_cmd_volume_old_tier_parse(const char **words, int wordcount,
- dict_t **options);
-
-int32_t
cli_cmd_volume_remove_brick_parse(struct cli_state *state, const char **words,
int wordcount, dict_t **options,
int *question, int *brick_count,
@@ -320,11 +335,14 @@ cli_local_get();
void
cli_local_wipe(cli_local_t *local);
+gf_boolean_t
+cli_cmd_connected();
+
int32_t
-cli_cmd_await_connected();
+cli_cmd_await_connected(unsigned timeout);
int32_t
-cli_cmd_broadcast_connected();
+cli_cmd_broadcast_connected(gf_boolean_t status);
int
cli_rpc_notify(struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event,
@@ -431,10 +449,9 @@ cli_xml_output_vol_rebalance(gf_cli_defrag_type op, dict_t *dict, int op_ret,
int op_errno, char *op_errstr);
int
-cli_xml_output_vol_remove_brick_detach_tier(gf_boolean_t status_op,
- dict_t *dict, int op_ret,
- int op_errno, char *op_errstr,
- const char *op);
+cli_xml_output_vol_remove_brick(gf_boolean_t status_op, dict_t *dict,
+ int op_ret, int op_errno, char *op_errstr,
+ const char *op);
int
cli_xml_output_vol_replace_brick(dict_t *dict, int op_ret, int op_errno,
@@ -480,9 +497,6 @@ cli_xml_output_snapshot(int cmd_type, dict_t *dict, int op_ret, int op_errno,
int
cli_xml_snapshot_status_single_snap(cli_local_t *local, dict_t *dict,
char *key);
-char *
-is_server_debug_xlator(void *myframe);
-
int32_t
cli_cmd_snapshot_parse(const char **words, int wordcount, dict_t **options,
struct cli_state *state);
diff --git a/cli/src/input.c b/cli/src/input.c
index 0583f648f95..5ac1a20edb1 100644
--- a/cli/src/input.c
+++ b/cli/src/input.c
@@ -45,6 +45,9 @@ cli_input(void *d)
state = d;
+ fprintf(stderr,
+ "Welcome to gluster prompt, type 'help' to see the available "
+ "commands.\n");
for (;;) {
printf("%s", state->prompt);