diff options
Diffstat (limited to 'cli/src/cli-rpc-ops.c')
| -rw-r--r-- | cli/src/cli-rpc-ops.c | 3757 |
1 files changed, 1280 insertions, 2477 deletions
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", ¤t_count); + ret = dict_get_int32_sizen(dict, "fuse-count", ¤t_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", ¤t_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", ¤t_count); + ret = dict_get_int32_sizen(dict, "gfapi-count", ¤t_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", ¤t_count); + ret = dict_get_int32_sizen(dict, "rebalance-count", + ¤t_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", ¤t_count); + ret = dict_get_int32_sizen(dict, "glustershd-count", + ¤t_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", ¤t_count); + ret = dict_get_int32_sizen(dict, "quotad-count", + ¤t_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", ¤t_count); + ret = dict_get_int32_sizen(dict, "snapd-count", ¤t_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}, |
