int cli_cmd_volume_rename_cbk (struct cli_state *state, struct cli_cmd_word *word, const char **words, int wordcount) { int ret = -1; rpc_clnt_procedure_t *proc = NULL; call_frame_t *frame = NULL; dict_t *dict = NULL; 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; } ret = dict_set_str (dict, "old-volname", (char *)words[2]); if (ret) goto out; ret = dict_set_str (dict, "new-volname", (char *)words[3]); if (ret) goto out; proc = &cli_rpc_prog->proctable[GLUSTER_CLI_RENAME_VOLUME]; if (proc->fn) { ret = proc->fn (frame, THIS, dict); } out: if (dict) dict_destroy (dict); if (ret) { cli_cmd_sent_status_get (&sent); if ((sent == 0) && (parse_error == 0)) cli_out ("Volume rename on '%s' failed", (char *)words[2]); } return ret; }
int32_t cli_cmd_log_locate_parse (const char **words, int wordcount, dict_t **options) { dict_t *dict = NULL; char *volname = NULL; char *str = NULL; int ret = -1; char *delimiter = NULL; GF_ASSERT (words); GF_ASSERT (options); GF_ASSERT ((strcmp (words[0], "volume")) == 0); GF_ASSERT ((strcmp (words[1], "log")) == 0); GF_ASSERT ((strcmp (words[2], "locate")) == 0); dict = dict_new (); if (!dict) goto out; volname = (char *)words[3]; GF_ASSERT (volname); ret = dict_set_str (dict, "volname", volname); if (ret) goto out; if (words[4]) { delimiter = strchr (words[4], ':'); if (!delimiter || delimiter == words[4] || *(delimiter+1) != '/') { cli_out ("wrong brick type: %s, use <HOSTNAME>:" "<export-dir-abs-path>", words[4]); ret = -1; goto out; } else { cli_path_strip_trailing_slashes (delimiter + 1); } str = (char *)words[4]; ret = dict_set_str (dict, "brick", str); if (ret) goto out; } *options = dict; out: if (ret && dict) dict_destroy (dict); return ret; }
int cli_cmd_peer_probe_cbk (struct cli_state *state, struct cli_cmd_word *word, const char **words, int wordcount) { int ret = -1; rpc_clnt_procedure_t *proc = NULL; call_frame_t *frame = NULL; dict_t *dict = NULL; int sent = 0; int parse_error = 0; if (!(wordcount == 3)) { cli_usage_out (word->pattern); parse_error = 1; goto out; } 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; ret = dict_set_str (dict, "hostname", (char *)words[2]); if (ret) goto out; ret = valid_internet_address ((char *) words[2], _gf_false); if (ret == 1) { ret = 0; } else { cli_usage_out (word->pattern); parse_error = 1; goto out; } /* if (words[3]) { ret = dict_set_str (dict, "port", (char *)words[3]); if (ret) goto out; } */ if (proc->fn) { ret = proc->fn (frame, THIS, dict); } out: if (ret) { cli_cmd_sent_status_get (&sent); if ((sent == 0) && (parse_error == 0)) cli_out ("Peer probe failed"); } if (frame) STACK_DESTROY (frame->root); return ret; }
static dict_t * make_seq_dict (int argc, char **argv) { char index[] = "4294967296"; // 1<<32 int i = 0; int ret = 0; dict_t *dict = dict_new (); if (!dict) return NULL; for (i = 0; i < argc; i++) { snprintf(index, sizeof(index), "%d", i); ret = dict_set_str (dict, index, argv[i]); if (ret == -1) break; } if (ret) { dict_destroy (dict); dict = NULL; } return dict; }
int glusterd_conn_init (glusterd_conn_t *conn, char *sockpath, int frame_timeout, glusterd_conn_notify_t notify) { int ret = -1; dict_t *options = NULL; struct rpc_clnt *rpc = NULL; xlator_t *this = THIS; glusterd_svc_t *svc = NULL; if (!this) goto out; svc = glusterd_conn_get_svc_object (conn); if (!svc) { gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_SVC_GET_FAIL, "Failed to get the service"); goto out; } ret = rpc_transport_unix_options_build (&options, sockpath, frame_timeout); if (ret) goto out; ret = dict_set_str (options, "transport.socket.ignore-enoent", "on"); if (ret) goto out; /* @options is free'd by rpc_transport when destroyed */ rpc = rpc_clnt_new (options, this->ctx, (char *)svc->name, 16); if (!rpc) { ret = -1; goto out; } ret = rpc_clnt_register_notify (rpc, glusterd_conn_common_notify, conn); if (ret) goto out; ret = snprintf (conn->sockpath, sizeof (conn->sockpath), "%s", sockpath); if (ret < 0) goto out; else ret = 0; conn->frame_timeout = frame_timeout; conn->rpc = rpc; conn->notify = notify; out: if (ret) { if (rpc) { rpc_clnt_unref (rpc); rpc = NULL; } } return ret; }
int cli_cmd_copy_file_cbk (struct cli_state *state, struct cli_cmd_word *word, const char **words, int wordcount) { int ret = -1; rpc_clnt_procedure_t *proc = NULL; call_frame_t *frame = NULL; char *filename = ""; dict_t *dict = NULL; cli_local_t *local = NULL; if (wordcount != 4) { cli_usage_out (word->pattern); goto out; } dict = dict_new (); if (!dict) goto out; filename = (char*)words[3]; ret = dict_set_str (dict, "source", filename); if (ret) gf_log ("", GF_LOG_ERROR, "Unable to set filename in dict"); ret = dict_set_str (dict, "volname", "N/A"); if (ret) gf_log ("", GF_LOG_ERROR, "Unable to set volname in dict"); proc = &cli_rpc_prog->proctable[GLUSTER_CLI_COPY_FILE]; if (proc && proc->fn) { frame = create_frame (THIS, THIS->ctx->pool); if (!frame) goto out; CLI_LOCAL_INIT (local, words, frame, dict); ret = proc->fn (frame, THIS, (void*)dict); } out: return ret; }
int32_t cli_cmd_volume_profile_parse (const char **words, int wordcount, dict_t **options) { dict_t *dict = NULL; char *volname = NULL; int ret = -1; gf1_cli_stats_op op = GF_CLI_STATS_NONE; GF_ASSERT (words); GF_ASSERT (options); GF_ASSERT ((strcmp (words[0], "volume")) == 0); GF_ASSERT ((strcmp (words[1], "profile")) == 0); dict = dict_new (); if (!dict) goto out; if (wordcount != 4) goto out; volname = (char *)words[2]; ret = dict_set_str (dict, "volname", volname); if (ret) goto out; if (strcmp (words[3], "start") == 0) { op = GF_CLI_STATS_START; } else if (strcmp (words[3], "stop") == 0) { op = GF_CLI_STATS_STOP; } else if (strcmp (words[3], "info") == 0) { op = GF_CLI_STATS_INFO; } else { ret = -1; goto out; } ret = dict_set_int32 (dict, "op", (int32_t)op); *options = dict; out: if (ret && dict) dict_destroy (dict); return ret; }
int32_t cli_cmd_volume_reset_parse (const char **words, int wordcount, dict_t **options) { dict_t *dict = NULL; char *volname = NULL; int ret = -1; GF_ASSERT (words); GF_ASSERT (options); GF_ASSERT ((strcmp (words[0], "volume")) == 0); GF_ASSERT ((strcmp (words[1], "reset")) == 0); dict = dict_new (); if (!dict) goto out; if (wordcount < 3) goto out; volname = (char *)words[2]; if (!volname) { ret = -1; goto out; } ret = dict_set_str (dict, "volname", volname); if (ret) goto out; *options = dict; out: if (ret) { if (dict) dict_destroy (dict); } return ret; }
int cli_cmd_umount_cbk (struct cli_state *state, struct cli_cmd_word *word, const char **words, int wordcount) { rpc_clnt_procedure_t *proc = NULL; call_frame_t *frame = NULL; int ret = -1; dict_t *dict = NULL; if (!(wordcount == 3 || (wordcount == 4 && strcmp (words[3], "lazy") == 0))) { cli_usage_out (word->pattern); goto out; } dict = dict_new (); if (!dict) goto out; ret = dict_set_str (dict, "path", (char *)words[2]); if (ret != 0) goto out; ret = dict_set_int32 (dict, "lazy", wordcount == 4); if (ret != 0) goto out; proc = &cli_rpc_prog->proctable[GLUSTER_CLI_UMOUNT]; if (proc && proc->fn) { frame = create_frame (THIS, THIS->ctx->pool); if (!frame) goto out; ret = proc->fn (frame, THIS, dict); } out: if (dict) dict_unref (dict); if (!proc && ret) cli_out ("Umount command failed"); return ret; }
int cli_cmd_pmap_b2p_cbk (struct cli_state *state, struct cli_cmd_word *word, const char **words, int wordcount) { int ret = -1; rpc_clnt_procedure_t *proc = NULL; call_frame_t *frame = NULL; dict_t *dict = NULL; 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); 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) { ret = proc->fn (frame, THIS, dict); } out: if (!proc && ret) { if (dict) dict_destroy (dict); if (wordcount > 1) cli_out ("Fetching spec for volume %s failed", (char *)words[3]); } return ret; }
int32_t cli_cmd_volume_add_brick_parse (const char **words, int wordcount, dict_t **options) { dict_t *dict = NULL; char *volname = NULL; int ret = -1; int brick_count = 0, brick_index = 0; char *bricks = NULL; GF_ASSERT (words); GF_ASSERT (options); GF_ASSERT ((strcmp (words[0], "volume")) == 0); GF_ASSERT ((strcmp (words[1], "add-brick")) == 0); dict = dict_new (); if (!dict) goto out; if (wordcount < 3) goto out; volname = (char *)words[2]; GF_ASSERT (volname); ret = dict_set_str (dict, "volname", volname); if (ret) goto out; if (wordcount < 4) { ret = -1; goto out; } brick_index = 3; ret = cli_cmd_bricks_parse (words, wordcount, brick_index, &bricks, &brick_count); if (ret) goto out; ret = dict_set_dynstr (dict, "bricks", bricks); if (ret) goto out; ret = dict_set_int32 (dict, "count", brick_count); if (ret) goto out; *options = dict; out: if (ret) { gf_log ("cli", GF_LOG_ERROR, "Unable to parse add-brick CLI"); if (dict) dict_destroy (dict); } return ret; }
int32_t cli_cmd_gsync_set_parse (const char **words, int wordcount, dict_t **options) { int32_t ret = 0; int32_t config_type = 0; dict_t *dict = NULL; gf1_cli_gsync_set type = GF_GSYNC_OPTION_TYPE_NONE; GF_ASSERT (words); GF_ASSERT (options); GF_ASSERT ((strcmp (words[0], "volume")) == 0); GF_ASSERT ((strcmp (words[1], "gsync")) == 0); dict = dict_new (); if (!dict) goto out; if (wordcount < 5) goto out; ret = dict_set_str (dict, "master", (char *)words[3]); if (ret < 0) goto out; ret = dict_set_str (dict, "slave", (char *)words[4]); if (ret < 0) goto out; if ((strcmp (words[2], "start")) == 0) { type = GF_GSYNC_OPTION_TYPE_START; goto set_type; } if ((strcmp (words[2], "stop")) == 0) { type = GF_GSYNC_OPTION_TYPE_STOP; goto set_type; } if ((strcmp (words[2], "configure")) == 0) { type = GF_GSYNC_OPTION_TYPE_CONFIGURE; if (strcmp (words [5], "config-set") == 0) { config_type = GF_GSYNC_OPTION_TYPE_CONFIG_SET; ret = dict_set_str (dict, "op_name", (char *)words[6]); if (ret < 0) goto out; ret = dict_set_str (dict, "op_value", (char *)words[7]); if (ret < 0) goto out; } if ((strcmp (words [5], "config-del")) == 0) { config_type = GF_GSYNC_OPTION_TYPE_CONFIG_DEL; ret = dict_set_str (dict, "op_name", (char *)words[6]); if (ret < 0) goto out; } if ((strcmp (words [5], "config-get")) == 0) { config_type = GF_GSYNC_OPTION_TYPE_CONFIG_GET; ret = dict_set_str (dict, "op_name", (char *)words[6]); if (ret < 0) goto out; } if ((strcmp (words [5], "config-get-all")) == 0) { config_type = GF_GSYNC_OPTION_TYPE_CONFIG_GET_ALL; } ret = dict_set_int32 (dict, "config_type", config_type); if (ret < 0) goto out; } set_type: ret = dict_set_int32 (dict, "type", type); if (ret < 0) goto out; *options = dict; out: if (ret) if (dict) dict_destroy (dict); return ret; }
int cli_cmd_volume_defrag_cbk (struct cli_state *state, struct cli_cmd_word *word, const char **words, int wordcount) { int ret = -1; rpc_clnt_procedure_t *proc = NULL; call_frame_t *frame = NULL; dict_t *dict = NULL; int sent = 0; int parse_error = 0; int index = 0; #ifdef GF_SOLARIS_HOST_OS cli_out ("Command not supported on Solaris"); goto out; #endif frame = create_frame (THIS, THIS->ctx->pool); if (!frame) goto out; dict = dict_new (); if (!dict) goto out; if (!((wordcount == 4) || (wordcount == 5))) { cli_usage_out (word->pattern); parse_error = 1; goto out; } if (wordcount == 4) { index = 3; } else { if (strcmp (words[3], "fix-layout") && strcmp (words[3], "migrate-data")) { cli_usage_out (word->pattern); parse_error = 1; goto out; } index = 4; } if (strcmp (words[index], "start") && strcmp (words[index], "stop") && strcmp (words[index], "status")) { cli_usage_out (word->pattern); parse_error = 1; goto out; } ret = dict_set_str (dict, "volname", (char *)words[2]); if (ret) goto out; if (wordcount == 4) { ret = dict_set_str (dict, "command", (char *)words[3]); if (ret) goto out; } if (wordcount == 5) { ret = dict_set_str (dict, "start-type", (char *)words[3]); if (ret) goto out; ret = dict_set_str (dict, "command", (char *)words[4]); if (ret) goto out; } proc = &cli_rpc_prog->proctable[GLUSTER_CLI_DEFRAG_VOLUME]; if (proc->fn) { ret = proc->fn (frame, THIS, dict); } out: if (dict) dict_destroy (dict); if (ret) { cli_cmd_sent_status_get (&sent); if ((sent == 0) && (parse_error == 0)) cli_out ("Volume rebalance failed"); } return ret; }
int cli_cmd_sys_exec_cbk (struct cli_state *state, struct cli_cmd_word *word, const char **words, int wordcount) { char cmd_arg_name[PATH_MAX] = ""; char *command = NULL; char *saveptr = NULL; char *tmp = NULL; int ret = -1; int i = -1; int cmd_args_count = 0; int in_cmd_args_count = 0; rpc_clnt_procedure_t *proc = NULL; call_frame_t *frame = NULL; dict_t *dict = NULL; cli_local_t *local = NULL; if (wordcount < 3) { cli_usage_out (word->pattern); goto out; } dict = dict_new (); if (!dict) goto out; command = strtok_r ((char *)words[2], " ", &saveptr); do { tmp = strtok_r (NULL, " ", &saveptr); if (tmp) { in_cmd_args_count++; memset (cmd_arg_name, '\0', sizeof(cmd_arg_name)); snprintf (cmd_arg_name, sizeof(cmd_arg_name), "cmd_arg_%d", in_cmd_args_count); ret = dict_set_str (dict, cmd_arg_name, tmp); if (ret) { gf_log ("", GF_LOG_ERROR, "Unable to set " "%s in dict", cmd_arg_name); goto out; } } } while (tmp); cmd_args_count = wordcount - 3; ret = dict_set_str (dict, "command", command); if (ret) { gf_log ("", GF_LOG_ERROR, "Unable to set command in dict"); goto out; } for (i=1; i <= cmd_args_count; i++) { in_cmd_args_count++; memset (cmd_arg_name, '\0', sizeof(cmd_arg_name)); 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]); if (ret) { gf_log ("", GF_LOG_ERROR, "Unable to set %s in dict", cmd_arg_name); goto out; } } ret = dict_set_int32 (dict, "cmd_args_count", in_cmd_args_count); if (ret) { gf_log ("", GF_LOG_ERROR, "Unable to set cmd_args_count in dict"); goto out; } ret = dict_set_str (dict, "volname", "N/A"); if (ret) { gf_log ("", GF_LOG_ERROR, "Unable to set volname in dict"); goto out; } proc = &cli_rpc_prog->proctable[GLUSTER_CLI_SYS_EXEC]; if (proc && proc->fn) { frame = create_frame (THIS, THIS->ctx->pool); if (!frame) goto out; CLI_LOCAL_INIT (local, words, frame, dict); ret = proc->fn (frame, THIS, (void*)dict); } out: return ret; }
int32_t cli_cmd_volume_top_parse (const char **words, int wordcount, dict_t **options) { dict_t *dict = NULL; char *volname = NULL; char *value = NULL; char *key = NULL; int ret = -1; gf1_cli_stats_op op = GF_CLI_STATS_NONE; gf1_cli_top_op top_op = GF_CLI_TOP_NONE; int32_t list_cnt = -1; int index = 0; int perf = 0; int32_t blk_size = 0; int32_t count = 0; char *delimiter = NULL; GF_ASSERT (words); GF_ASSERT (options); GF_ASSERT ((strcmp (words[0], "volume")) == 0); GF_ASSERT ((strcmp (words[1], "top")) == 0); dict = dict_new (); if (!dict) goto out; if (wordcount < 4) goto out; volname = (char *)words[2]; ret = dict_set_str (dict, "volname", volname); if (ret) goto out; op = GF_CLI_STATS_TOP; ret = dict_set_int32 (dict, "op", (int32_t)op); if (ret) goto out; if (strcmp (words[3], "open") == 0) { top_op = GF_CLI_TOP_OPEN; } else if (strcmp (words[3], "read") == 0) { top_op = GF_CLI_TOP_READ; } else if (strcmp (words[3], "write") == 0) { top_op = GF_CLI_TOP_WRITE; } else if (strcmp (words[3], "opendir") == 0) { top_op = GF_CLI_TOP_OPENDIR; } else if (strcmp (words[3], "readdir") == 0) { top_op = GF_CLI_TOP_READDIR; } else if (strcmp (words[3], "read-perf") == 0) { top_op = GF_CLI_TOP_READ_PERF; perf = 1; } else if (strcmp (words[3], "write-perf") == 0) { top_op = GF_CLI_TOP_WRITE_PERF; perf = 1; } else { ret = -1; goto out; } ret = dict_set_int32 (dict, "top-op", (int32_t)top_op); if (ret) goto out; for (index = 4; index < wordcount; index+=2) { key = (char *) words[index]; value = (char *) words[index+1]; if ( key && !value ) { ret = -1; goto out; } if (!strcmp (key, "brick")) { delimiter = strchr (value, ':'); if (!delimiter || delimiter == value || *(delimiter+1) != '/') { cli_out ("wrong brick type: %s, use <HOSTNAME>:" "<export-dir-abs-path>", value); ret = -1; goto out; } else { cli_path_strip_trailing_slashes (delimiter + 1); } ret = dict_set_str (dict, "brick", value); } else if (!strcmp (key, "list-cnt")) { ret = gf_is_str_int (value); if (!ret) list_cnt = atoi (value); if (ret || (list_cnt < 0) || (list_cnt > 100)) { cli_out ("list-cnt should be between 0 to 100"); ret = -1; goto out; } } else if (perf && !strcmp (key, "bs")) { ret = gf_is_str_int (value); if (!ret) blk_size = atoi (value); if (ret || (blk_size < 0)) { cli_out ("block size should be an integer " "greater than zero"); ret = -1; goto out; } ret = dict_set_int32 (dict, "blk-size", blk_size); } else if (perf && !strcmp (key, "count")) { ret = gf_is_str_int (value); if (!ret) count = atoi(value); if (ret || (count < 0)) { cli_out ("count should be an integer greater " "zero"); ret = -1; goto out; } ret = dict_set_int32 (dict, "blk-cnt", count); } else { ret = -1; goto out; } if (ret) { gf_log ("", GF_LOG_WARNING, "Dict set failed for " "key %s", key); goto out; } } if (list_cnt == -1) list_cnt = 100; ret = dict_set_int32 (dict, "list-cnt", list_cnt); if (ret) { gf_log ("", GF_LOG_WARNING, "Dict set failed for list_cnt"); goto out; } *options = dict; out: if (ret && dict) dict_destroy (dict); return ret; }
int32_t cli_cmd_volume_create_parse (const char **words, int wordcount, dict_t **options) { dict_t *dict = NULL; char *volname = NULL; int ret = -1; gf1_cluster_type type = GF_CLUSTER_TYPE_NONE; int count = 1; int brick_index = 0; int i = 0; char *trans_type = NULL; int32_t index = 0; char *bricks = NULL; int32_t brick_count = 0; GF_ASSERT (words); GF_ASSERT (options); GF_ASSERT ((strcmp (words[0], "volume")) == 0); GF_ASSERT ((strcmp (words[1], "create")) == 0); dict = dict_new (); if (!dict) goto out; if (wordcount < 3) goto out; volname = (char *)words[2]; GF_ASSERT (volname); /* Validate the volume name here itself */ { if (volname[0] == '-') goto out; if (!strcmp (volname, "all")) { cli_out ("\"all\" cannot be the name of a volume."); goto out; } if (strchr (volname, '/')) goto out; if (strlen (volname) > 512) goto out; for (i = 0; i < strlen (volname); i++) if (!isalnum (volname[i]) && (volname[i] != '_') && (volname[i] != '-')) goto out; } ret = dict_set_str (dict, "volname", volname); if (ret) goto out; if (wordcount < 4) { ret = -1; goto out; } if ((strcasecmp (words[3], "replica")) == 0) { type = GF_CLUSTER_TYPE_REPLICATE; if (wordcount < 5) { ret = -1; goto out; } count = strtol (words[4], NULL, 0); if (!count || (count < 2)) { cli_out ("replica count should be greater than 1"); ret = -1; goto out; } ret = dict_set_int32 (dict, "replica-count", count); if (ret) goto out; brick_index = 5; } else if ((strcasecmp (words[3], "stripe")) == 0) { type = GF_CLUSTER_TYPE_STRIPE; if (wordcount < 5) { ret = -1; goto out; } count = strtol (words[4], NULL, 0); if (!count || (count < 2)) { cli_out ("stripe count should be greater than 1"); ret = -1; goto out; } ret = dict_set_int32 (dict, "stripe-count", count); if (ret) goto out; brick_index = 5; } else { type = GF_CLUSTER_TYPE_NONE; brick_index = 3; } ret = dict_set_int32 (dict, "type", type); if (ret) goto out; if (type) index = 5; else index = 3; if (wordcount < (index + 1)) { ret = -1; goto out; } if (strcasecmp(words[index], "transport") == 0) { brick_index = index+2; if (wordcount < (index + 2)) { ret = -1; goto out; } if ((strcasecmp (words[index+1], "tcp") == 0)) { trans_type = gf_strdup ("tcp"); } else if ((strcasecmp (words[index+1], "rdma") == 0)) { trans_type = gf_strdup ("rdma"); } else if ((strcasecmp (words[index+1], "tcp,rdma") == 0) || (strcasecmp (words[index+1], "rdma,tcp") == 0)) { trans_type = gf_strdup ("tcp,rdma"); } else { gf_log ("", GF_LOG_ERROR, "incorrect transport" " protocol specified"); ret = -1; goto out; } } else { trans_type = gf_strdup ("tcp"); } ret = dict_set_dynstr (dict, "transport", trans_type); if (ret) goto out; ret = cli_cmd_bricks_parse (words, wordcount, brick_index, &bricks, &brick_count); if (ret) goto out; /* If brick-count is not valid when replica or stripe is given, exit here */ if (!brick_count) { cli_out ("No bricks specified"); ret = -1; goto out; } if (brick_count % count) { if (type == GF_CLUSTER_TYPE_STRIPE) cli_out ("number of bricks is not a multiple of " "stripe count"); else if (type == GF_CLUSTER_TYPE_REPLICATE) cli_out ("number of bricks is not a multiple of " "replica count"); ret = -1; goto out; } ret = dict_set_dynstr (dict, "bricks", bricks); if (ret) goto out; ret = dict_set_int32 (dict, "count", brick_count); if (ret) goto out; *options = dict; out: if (ret) { gf_log ("cli", GF_LOG_ERROR, "Unable to parse create volume CLI"); if (dict) dict_destroy (dict); } return ret; }
int32_t cli_cmd_quota_parse (const char **words, int wordcount, dict_t **options) { dict_t *dict = NULL; char *volname = NULL; int ret = -1; int i = 0; char key[20] = {0, }; gf_quota_type type = GF_QUOTA_OPTION_TYPE_NONE; GF_ASSERT (words); GF_ASSERT (options); GF_ASSERT ((strcmp (words[0], "volume")) == 0); GF_ASSERT ((strcmp (words[1], "quota")) == 0); dict = dict_new (); if (!dict) goto out; if (wordcount < 4) goto out; volname = (char *)words[2]; if (!volname) { ret = -1; goto out; } /* Validate the volume name here itself */ { if (volname[0] == '-') goto out; if (!strcmp (volname, "all")) { cli_out ("\"all\" cannot be the name of a volume."); goto out; } if (strchr (volname, '/')) goto out; if (strlen (volname) > 512) goto out; for (i = 0; i < strlen (volname); i++) if (!isalnum (volname[i]) && (volname[i] != '_') && (volname[i] != '-')) goto out; } ret = dict_set_str (dict, "volname", volname); if (ret) goto out; if ((strcasecmp (words[3], "enable")) == 0) { type = GF_QUOTA_OPTION_TYPE_ENABLE; goto set_type; } if (strcasecmp (words[3], "disable") == 0) { type = GF_QUOTA_OPTION_TYPE_DISABLE; goto set_type; } if (strcasecmp (words[3], "limit-usage") == 0) { if (wordcount != 6) { ret = -1; goto out; } type = GF_QUOTA_OPTION_TYPE_LIMIT_USAGE; if (words[4][0] != '/') { cli_out ("Please enter absolute path"); return -2; } ret = dict_set_str (dict, "path", (char *) words[4]); if (ret) goto out; if (!words[5]) { gf_log ("cli", GF_LOG_ERROR, "Please enter the limit value " "to be set"); return -2; } ret = dict_set_str (dict, "limit", (char *) words[5]); if (ret) goto out; goto set_type; } if (strcasecmp (words[3], "remove") == 0) { if (wordcount != 5) { ret = -1; goto out; } type = GF_QUOTA_OPTION_TYPE_REMOVE; if (words[4][0] != '/') { cli_out ("Please enter absolute path"); return -2; } ret = dict_set_str (dict, "path", (char *) words[4]); if (ret) goto out; goto set_type; } if (strcasecmp (words[3], "list") == 0) { if (wordcount < 4) { ret = -1; goto out; } type = GF_QUOTA_OPTION_TYPE_LIST; i = 4; while (i < wordcount) { snprintf (key, 20, "path%d", i-4); ret = dict_set_str (dict, key, (char *) words [i++]); if (ret < 0) goto out; } ret = dict_set_int32 (dict, "count", i - 4); if (ret < 0) goto out; goto set_type; } if (strcasecmp (words[3], "version") == 0) { type = GF_QUOTA_OPTION_TYPE_VERSION; } else { ret = -1; goto out; } set_type: ret = dict_set_int32 (dict, "type", type); if (ret) goto out; *options = dict; out: if (ret) { if (dict) dict_destroy (dict); } return ret; }
int32_t cli_cmd_volume_replace_brick_parse (const char **words, int wordcount, dict_t **options) { dict_t *dict = NULL; char *volname = NULL; int ret = -1; char *op = NULL; int op_index = 0; char *delimiter = NULL; gf1_cli_replace_op replace_op = GF_REPLACE_OP_NONE; GF_ASSERT (words); GF_ASSERT (options); GF_ASSERT ((strcmp (words[0], "volume")) == 0); GF_ASSERT ((strcmp (words[1], "replace-brick")) == 0); dict = dict_new (); if (!dict) goto out; if (wordcount < 3) goto out; volname = (char *)words[2]; GF_ASSERT (volname); ret = dict_set_str (dict, "volname", volname); if (ret) goto out; if (wordcount < 4) { ret = -1; goto out; } delimiter = strchr ((char *)words[3], ':'); if (!delimiter || delimiter == words[3] || *(delimiter+1) != '/') { cli_out ("wrong brick type: %s, use " "<HOSTNAME>:<export-dir-abs-path>", words[3]); ret = -1; goto out; } else { cli_path_strip_trailing_slashes (delimiter + 1); } ret = dict_set_str (dict, "src-brick", (char *)words[3]); if (ret) goto out; if (wordcount < 5) { ret = -1; goto out; } delimiter = strchr ((char *)words[4], ':'); if (!delimiter || delimiter == words[4] || *(delimiter+1) != '/') { cli_out ("wrong brick type: %s, use " "<HOSTNAME>:<export-dir-abs-path>", words[4]); ret = -1; goto out; } else { cli_path_strip_trailing_slashes (delimiter + 1); } ret = dict_set_str (dict, "dst-brick", (char *)words[4]); if (ret) goto out; op_index = 5; if ((wordcount < (op_index + 1))) { ret = -1; goto out; } op = (char *) words[op_index]; if (!strcasecmp ("start", op)) { replace_op = GF_REPLACE_OP_START; } else if (!strcasecmp ("commit", op)) { replace_op = GF_REPLACE_OP_COMMIT; } else if (!strcasecmp ("pause", op)) { replace_op = GF_REPLACE_OP_PAUSE; } else if (!strcasecmp ("abort", op)) { replace_op = GF_REPLACE_OP_ABORT; } else if (!strcasecmp ("status", op)) { replace_op = GF_REPLACE_OP_STATUS; } /* commit force option */ op_index = 6; if (wordcount > (op_index + 1)) { ret = -1; goto out; } if (wordcount == (op_index + 1)) { op = (char *) words[op_index]; if (!strcasecmp ("force", op)) { replace_op = GF_REPLACE_OP_COMMIT_FORCE; } } if (replace_op == GF_REPLACE_OP_NONE) { ret = -1; goto out; } ret = dict_set_int32 (dict, "operation", (int32_t) replace_op); if (ret) goto out; *options = dict; out: if (ret) { gf_log ("cli", GF_LOG_ERROR, "Unable to parse remove-brick CLI"); if (dict) dict_destroy (dict); } return ret; }
int32_t cli_cmd_volume_set_parse (const char **words, int wordcount, dict_t **options) { dict_t *dict = NULL; char *volname = NULL; int ret = -1; int count = 0; char *key = NULL; char *value = NULL; int i = 0; char str[50] = {0,}; GF_ASSERT (words); GF_ASSERT (options); GF_ASSERT ((strcmp (words[0], "volume")) == 0); GF_ASSERT ((strcmp (words[1], "set")) == 0); dict = dict_new (); if (!dict) goto out; if (wordcount < 4) goto out; volname = (char *)words[2]; GF_ASSERT (volname); ret = dict_set_str (dict, "volname", volname); if (ret) goto out; for (i = 3; i < wordcount; i+=2) { key = (char *) words[i]; value = (char *) words[i+1]; if ( !key || !value) { ret = -1; goto out; } count++; sprintf (str, "key%d", count); ret = dict_set_str (dict, str, key); if (ret) goto out; sprintf (str, "value%d", count); ret = dict_set_str (dict, str, value); if (ret) goto out; } ret = dict_set_int32 (dict, "count", wordcount-3); if (ret) goto out; *options = dict; out: if (ret) { if (dict) dict_destroy (dict); } return ret; }
transport_t * transport_load (dict_t *options, xlator_t *xl) { struct transport *trans = NULL, *return_trans = NULL; char *name = NULL; void *handle = NULL; char *type = NULL; char str[] = "ERROR"; int32_t ret = -1; int8_t is_tcp = 0, is_unix = 0, is_ibsdp = 0; volume_opt_list_t *vol_opt = NULL; GF_VALIDATE_OR_GOTO("transport", options, fail); GF_VALIDATE_OR_GOTO("transport", xl, fail); trans = GF_CALLOC (1, sizeof (struct transport), gf_common_mt_transport); GF_VALIDATE_OR_GOTO("transport", trans, fail); trans->xl = xl; type = str; /* Backward compatibility */ ret = dict_get_str (options, "transport-type", &type); if (ret < 0) { ret = dict_set_str (options, "transport-type", "socket"); if (ret < 0) gf_log ("dict", GF_LOG_DEBUG, "setting transport-type failed"); gf_log ("transport", GF_LOG_WARNING, "missing 'option transport-type'. defaulting to " "\"socket\""); } else { { /* Backword compatibility to handle * /client, * * /server. */ char *tmp = strchr (type, '/'); if (tmp) *tmp = '\0'; } is_tcp = strcmp (type, "tcp"); is_unix = strcmp (type, "unix"); is_ibsdp = strcmp (type, "ib-sdp"); if ((is_tcp == 0) || (is_unix == 0) || (is_ibsdp == 0)) { if (is_unix == 0) ret = dict_set_str (options, "transport.address-family", "unix"); if (is_ibsdp == 0) ret = dict_set_str (options, "transport.address-family", "inet-sdp"); if (ret < 0) gf_log ("dict", GF_LOG_DEBUG, "setting address-family failed"); ret = dict_set_str (options, "transport-type", "socket"); if (ret < 0) gf_log ("dict", GF_LOG_DEBUG, "setting transport-type failed"); } } ret = dict_get_str (options, "transport-type", &type); if (ret < 0) { GF_FREE (trans); gf_log ("transport", GF_LOG_ERROR, "'option transport-type <xx>' missing in volume '%s'", xl->name); goto fail; } ret = gf_asprintf (&name, "%s/%s.so", TRANSPORTDIR, type); if (-1 == ret) { gf_log ("transport", GF_LOG_ERROR, "asprintf failed"); goto fail; } gf_log ("transport", GF_LOG_DEBUG, "attempt to load file %s", name); handle = dlopen (name, RTLD_NOW|RTLD_GLOBAL); if (handle == NULL) { gf_log ("transport", GF_LOG_ERROR, "%s", dlerror ()); gf_log ("transport", GF_LOG_ERROR, "volume '%s': transport-type '%s' is not valid or " "not found on this machine", xl->name, type); GF_FREE (name); GF_FREE (trans); goto fail; } GF_FREE (name); trans->ops = dlsym (handle, "tops"); if (trans->ops == NULL) { gf_log ("transport", GF_LOG_ERROR, "dlsym (transport_ops) on %s", dlerror ()); GF_FREE (trans); goto fail; } trans->init = dlsym (handle, "init"); if (trans->init == NULL) { gf_log ("transport", GF_LOG_ERROR, "dlsym (gf_transport_init) on %s", dlerror ()); GF_FREE (trans); goto fail; } trans->fini = dlsym (handle, "fini"); if (trans->fini == NULL) { gf_log ("transport", GF_LOG_ERROR, "dlsym (gf_transport_fini) on %s", dlerror ()); GF_FREE (trans); goto fail; } vol_opt = GF_CALLOC (1, sizeof (volume_opt_list_t), gf_common_mt_volume_opt_list_t); vol_opt->given_opt = dlsym (handle, "options"); if (vol_opt->given_opt == NULL) { gf_log ("transport", GF_LOG_DEBUG, "volume option validation not specified"); } else { list_add_tail (&vol_opt->list, &xl->volume_options); if (-1 == validate_xlator_volume_options (xl, vol_opt->given_opt)) { gf_log ("transport", GF_LOG_ERROR, "volume option validation failed"); GF_FREE (trans); goto fail; } } ret = trans->init (trans); if (ret != 0) { gf_log ("transport", GF_LOG_ERROR, "'%s' initialization failed", type); GF_FREE (trans); goto fail; } pthread_mutex_init (&trans->lock, NULL); return_trans = trans; fail: return return_trans; }
int cli_cmd_peer_deprobe_cbk (struct cli_state *state, struct cli_cmd_word *word, const char **words, int wordcount) { int ret = -1; rpc_clnt_procedure_t *proc = NULL; call_frame_t *frame = NULL; dict_t *dict = NULL; int flags = 0; int sent = 0; int parse_error = 0; if ((wordcount < 3) || (wordcount > 4)) { cli_usage_out (word->pattern); parse_error = 1; goto out; } 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]); if (ret) goto out; /* if (words[3]) { ret = dict_set_str (dict, "port", (char *)words[3]); if (ret) goto out; } */ if (wordcount == 4) { if (!strcmp("force", words[3])) flags |= GF_CLI_FLAG_OP_FORCE; else { ret = -1; cli_usage_out (word->pattern); parse_error = 1; goto out; } } ret = dict_set_int32 (dict, "flags", flags); if (ret) goto out; if (proc->fn) { ret = proc->fn (frame, THIS, dict); } out: if (ret) { cli_cmd_sent_status_get (&sent); if ((sent == 0) && (parse_error == 0)) cli_out ("Peer detach failed"); } return ret; }
int32_t cli_cmd_volume_remove_brick_parse (const char **words, int wordcount, dict_t **options) { dict_t *dict = NULL; char *volname = NULL; char *delimiter = NULL; int ret = -1; char key[50]; int brick_count = 0, brick_index = 0; int32_t tmp_index = 0; int32_t j = 0; char *tmp_brick = NULL; char *tmp_brick1 = NULL; GF_ASSERT (words); GF_ASSERT (options); GF_ASSERT ((strcmp (words[0], "volume")) == 0); GF_ASSERT ((strcmp (words[1], "remove-brick")) == 0); dict = dict_new (); if (!dict) goto out; if (wordcount < 3) goto out; volname = (char *)words[2]; GF_ASSERT (volname); ret = dict_set_str (dict, "volname", volname); if (ret) goto out; if (wordcount < 4) { ret = -1; goto out; } brick_index = 3; if (ret) goto out; tmp_index = brick_index; tmp_brick = GF_MALLOC(2048 * sizeof(*tmp_brick), gf_common_mt_char); if (!tmp_brick) { gf_log ("",GF_LOG_ERROR,"cli_cmd_volume_remove_brick_parse: " "Unable to get memory"); ret = -1; goto out; } tmp_brick1 = GF_MALLOC(2048 * sizeof(*tmp_brick1), gf_common_mt_char); if (!tmp_brick1) { gf_log ("",GF_LOG_ERROR,"cli_cmd_volume_remove_brick_parse: " "Unable to get memory"); ret = -1; goto out; } while (brick_index < wordcount) { delimiter = strchr(words[brick_index], ':'); if (!delimiter || delimiter == words[brick_index] || *(delimiter+1) != '/') { cli_out ("wrong brick type: %s, use <HOSTNAME>:" "<export-dir-abs-path>", words[brick_index]); ret = -1; goto out; } else { cli_path_strip_trailing_slashes (delimiter + 1); } j = tmp_index; strcpy(tmp_brick, words[brick_index]); while ( j < brick_index) { strcpy(tmp_brick1, words[j]); if (!(strcmp (tmp_brick, tmp_brick1))) { gf_log("",GF_LOG_ERROR, "Duplicate bricks" " found %s", words[brick_index]); cli_out("Duplicate bricks found %s", words[brick_index]); ret = -1; goto out; } j++; } snprintf (key, 50, "brick%d", ++brick_count); ret = dict_set_str (dict, key, (char *)words[brick_index++]); if (ret) goto out; } ret = dict_set_int32 (dict, "count", brick_count); if (ret) goto out; *options = dict; out: if (ret) { gf_log ("cli", GF_LOG_ERROR, "Unable to parse remove-brick CLI"); if (dict) dict_destroy (dict); } if (tmp_brick) GF_FREE (tmp_brick); if (tmp_brick1) GF_FREE (tmp_brick1); return ret; }