From 78a2e27ec7d85ed5e915817c9bcc080919791b7b Mon Sep 17 00:00:00 2001 From: Krutika Dhananjay Date: Tue, 7 May 2013 15:58:45 +0530 Subject: glusterd: Log peer op status at the appropriate time Change-Id: Ia8e1af082078f2f791708ba4faa4992bf291dd6e BUG: 961339 Signed-off-by: Krutika Dhananjay Reviewed-on: http://review.gluster.org/5023 Reviewed-by: Amar Tumballi Tested-by: Gluster Build System Reviewed-by: Vijay Bellur --- cli/src/cli-cmd-peer.c | 7 + cli/src/cli-rpc-ops.c | 180 +++----------- rpc/xdr/src/cli1-xdr.c | 107 -------- rpc/xdr/src/cli1-xdr.h | 38 --- rpc/xdr/src/cli1-xdr.x | 26 -- xlators/mgmt/glusterd/src/glusterd-handler.c | 331 ++++++++++++++++++++----- xlators/mgmt/glusterd/src/glusterd-handshake.c | 1 + xlators/mgmt/glusterd/src/glusterd-rpc-ops.c | 10 +- xlators/mgmt/glusterd/src/glusterd-sm.c | 3 +- xlators/mgmt/glusterd/src/glusterd-sm.h | 2 + xlators/mgmt/glusterd/src/glusterd.h | 9 +- 11 files changed, 329 insertions(+), 385 deletions(-) diff --git a/cli/src/cli-cmd-peer.c b/cli/src/cli-cmd-peer.c index 263f419a6..551312411 100644 --- a/cli/src/cli-cmd-peer.c +++ b/cli/src/cli-cmd-peer.c @@ -41,6 +41,7 @@ cli_cmd_peer_probe_cbk (struct cli_state *state, struct cli_cmd_word *word, dict_t *dict = NULL; int sent = 0; int parse_error = 0; + cli_local_t *local = NULL; if (!(wordcount == 3)) { cli_usage_out (word->pattern); @@ -78,6 +79,9 @@ cli_cmd_peer_probe_cbk (struct cli_state *state, struct cli_cmd_word *word, goto out; } */ + + CLI_LOCAL_INIT (local, words, frame, dict); + if (proc->fn) { ret = proc->fn (frame, THIS, dict); } @@ -106,6 +110,7 @@ cli_cmd_peer_deprobe_cbk (struct cli_state *state, struct cli_cmd_word *word, int flags = 0; int sent = 0; int parse_error = 0; + cli_local_t *local = NULL; if ((wordcount < 3) || (wordcount > 4)) { cli_usage_out (word->pattern); @@ -145,6 +150,8 @@ cli_cmd_peer_deprobe_cbk (struct cli_state *state, struct cli_cmd_word *word, if (ret) goto out; + CLI_LOCAL_INIT (local, words, frame, dict); + if (proc->fn) { ret = proc->fn (frame, THIS, dict); } diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c index a89e6b78b..1ef23a327 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -87,47 +87,11 @@ rpc_clnt_prog_t cli_pmap_prog = { .progver = GLUSTER_PMAP_VERSION, }; -void -gf_cli_probe_strerror (gf1_cli_probe_rsp *rsp, char *msg, size_t len) -{ - switch (rsp->op_errno) { - case GF_PROBE_ANOTHER_CLUSTER: - snprintf (msg, len, "%s is already part of another cluster", - rsp->hostname); - break; - case GF_PROBE_VOLUME_CONFLICT: - snprintf (msg, len, "Atleast one volume on %s conflicts with " - "existing volumes in the cluster", rsp->hostname); - break; - case GF_PROBE_UNKNOWN_PEER: - snprintf (msg, len, "%s responded with 'unknown peer' error, " - "this could happen if %s doesn't have localhost in " - "its peer database", rsp->hostname, rsp->hostname); - break; - case GF_PROBE_ADD_FAILED: - snprintf (msg, len, "Failed to add peer information on %s" , - rsp->hostname); - break; - case GF_PROBE_SAME_UUID: - snprintf (msg, len, "Peer uuid (host %s) is same as local uuid", - rsp->hostname); - break; - case GF_PROBE_QUORUM_NOT_MET: - snprintf (msg, len, "Cluster quorum is not met. Changing " - "peers is not allowed in this state"); - break; - default: - snprintf (msg, len, "Probe returned with unknown " - "errno %d", rsp->op_errno); - break; - } -} - int gf_cli_probe_cbk (struct rpc_req *req, struct iovec *iov, int count, void *myframe) { - gf1_cli_probe_rsp rsp = {0,}; + gf_cli_rsp rsp = {0,}; int ret = -1; char msg[1024] = {0,}; @@ -135,7 +99,7 @@ gf_cli_probe_cbk (struct rpc_req *req, struct iovec *iov, goto out; } - ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gf1_cli_probe_rsp); + 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"); @@ -145,38 +109,11 @@ gf_cli_probe_cbk (struct rpc_req *req, struct iovec *iov, } gf_log ("cli", GF_LOG_INFO, "Received resp to probe"); - if (!rsp.op_ret) { - switch (rsp.op_errno) { - case GF_PROBE_SUCCESS: - snprintf (msg, sizeof (msg), - "success"); - break; - case GF_PROBE_LOCALHOST: - snprintf (msg, sizeof (msg), - "success: on localhost not needed"); - break; - case GF_PROBE_FRIEND: - snprintf (msg, sizeof (msg), - "success: host %s port %d already" - " in peer list", rsp.hostname, - rsp.port); - break; - default: - rsp.op_ret = -1; - snprintf (msg, sizeof (msg), - "Probe returned with unknown errno" - " %d", rsp.op_errno); - break; - } - } - if (rsp.op_ret) { - if (rsp.op_errstr && (strlen (rsp.op_errstr) > 0)) { - snprintf (msg, sizeof (msg), "%s", rsp.op_errstr); - } else { - gf_cli_probe_strerror (&rsp, msg, sizeof (msg)); - } - gf_log ("cli", GF_LOG_ERROR, "%s", msg); + if (rsp.op_errstr && (strlen (rsp.op_errstr) > 0)) { + snprintf (msg, sizeof (msg), "%s", rsp.op_errstr); + if (rsp.op_ret) + gf_log ("cli", GF_LOG_ERROR, "%s", msg); } if (global_state->mode & GLUSTER_MODE_XML) { @@ -191,7 +128,7 @@ gf_cli_probe_cbk (struct rpc_req *req, struct iovec *iov, } if (!rsp.op_ret) - cli_out ("peer probe: %s", msg); + cli_out ("peer probe: success. %s", msg); else cli_err ("peer probe: failed: %s", msg); @@ -206,15 +143,15 @@ int gf_cli_deprobe_cbk (struct rpc_req *req, struct iovec *iov, int count, void *myframe) { - gf1_cli_deprobe_rsp rsp = {0,}; + gf_cli_rsp rsp = {0,}; int ret = -1; - char msg[1024] = {0,}; + char msg[1024] = {0,}; if (-1 == req->rpc_status) { goto out; } - ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gf1_cli_deprobe_rsp); + 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"); @@ -224,48 +161,11 @@ gf_cli_deprobe_cbk (struct rpc_req *req, struct iovec *iov, } gf_log ("cli", GF_LOG_INFO, "Received resp to deprobe"); + if (rsp.op_ret) { if (strlen (rsp.op_errstr) > 0) { snprintf (msg, sizeof (msg), "%s", rsp.op_errstr); gf_log ("cli", GF_LOG_ERROR, "%s", rsp.op_errstr); - } else { - switch (rsp.op_errno) { - case GF_DEPROBE_LOCALHOST: - snprintf (msg, sizeof (msg), - "%s is localhost", - rsp.hostname); - break; - case GF_DEPROBE_NOT_FRIEND: - snprintf (msg, sizeof (msg), - "%s is not part of cluster", - rsp.hostname); - break; - case GF_DEPROBE_BRICK_EXIST: - snprintf (msg, sizeof (msg), - "Brick(s) with the peer %s " - "exist in cluster", - rsp.hostname); - break; - case GF_DEPROBE_FRIEND_DOWN: - snprintf (msg, sizeof (msg), - "One of the peers is probably" - " down. Check with 'peer " - "status'."); - break; - case GF_DEPROBE_QUORUM_NOT_MET: - snprintf (msg, sizeof (msg), "Cluster " - "quorum is not met. Changing " - "peers is not allowed in this" - " state"); - break; - default: - snprintf (msg, sizeof (msg), - "Detach returned with unknown" - " errno %d", rsp.op_errno); - break; - } - gf_log ("cli", GF_LOG_ERROR,"Detach failed with op_ret " - "%d and op_errno %d", rsp.op_ret, rsp.op_errno); } } else { snprintf (msg, sizeof (msg), "success"); @@ -2750,10 +2650,9 @@ int32_t gf_cli_probe (call_frame_t *frame, xlator_t *this, void *data) { - gf1_cli_probe_req req = {0,}; + gf_cli_req req = {{0,},}; int ret = 0; dict_t *dict = NULL; - char *hostname = NULL; int port = 0; if (!frame || !this || !data) { @@ -2762,24 +2661,22 @@ gf_cli_probe (call_frame_t *frame, xlator_t *this, } dict = data; - ret = dict_get_str (dict, "hostname", &hostname); - if (ret) - goto out; ret = dict_get_int32 (dict, "port", &port); - if (ret) - port = CLI_GLUSTERD_PORT; - - req.hostname = hostname; - req.port = port; + if (ret) { + ret = dict_set_int32 (dict, "port", CLI_GLUSTERD_PORT); + if (ret) + goto out; + } - ret = cli_cmd_submit (&req, frame, cli_rpc_prog, - GLUSTER_CLI_PROBE, NULL, - this, gf_cli_probe_cbk, - (xdrproc_t)xdr_gf1_cli_probe_req); + ret = cli_to_glusterd (&req, frame, gf_cli_probe_cbk, + (xdrproc_t) xdr_gf_cli_req, dict, + GLUSTER_CLI_PROBE, this, cli_rpc_prog, NULL); out: + GF_FREE (req.dict.dict_val); gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); + return ret; } @@ -2787,10 +2684,9 @@ int32_t gf_cli_deprobe (call_frame_t *frame, xlator_t *this, void *data) { - gf1_cli_deprobe_req req = {0,}; + gf_cli_req req = {{0,},}; int ret = 0; dict_t *dict = NULL; - char *hostname = NULL; int port = 0; int flags = 0; @@ -2800,28 +2696,28 @@ gf_cli_deprobe (call_frame_t *frame, xlator_t *this, } dict = data; - ret = dict_get_str (dict, "hostname", &hostname); - if (ret) - goto out; - ret = dict_get_int32 (dict, "port", &port); - if (ret) - port = CLI_GLUSTERD_PORT; + if (ret) { + ret = dict_set_int32 (dict, "port", CLI_GLUSTERD_PORT); + if (ret) + goto out; + } ret = dict_get_int32 (dict, "flags", &flags); - if (ret) - flags = 0; + if (ret) { + ret = dict_set_int32 (dict, "flags", 0); + if (ret) + goto out; + } - req.hostname = hostname; - req.port = port; - req.flags = flags; - ret = cli_cmd_submit (&req, frame, cli_rpc_prog, - GLUSTER_CLI_DEPROBE, NULL, - this, gf_cli_deprobe_cbk, - (xdrproc_t)xdr_gf1_cli_deprobe_req); + ret = cli_to_glusterd (&req, frame, gf_cli_deprobe_cbk, + (xdrproc_t)xdr_gf_cli_req, dict, + GLUSTER_CLI_DEPROBE, this, cli_rpc_prog, NULL); out: + GF_FREE (req.dict.dict_val); gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); + return ret; } diff --git a/rpc/xdr/src/cli1-xdr.c b/rpc/xdr/src/cli1-xdr.c index b8780af91..7d85b43c1 100644 --- a/rpc/xdr/src/cli1-xdr.c +++ b/rpc/xdr/src/cli1-xdr.c @@ -206,113 +206,6 @@ xdr_gf_cli_rsp (XDR *xdrs, gf_cli_rsp *objp) return TRUE; } -bool_t -xdr_gf1_cli_probe_req (XDR *xdrs, gf1_cli_probe_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_string (xdrs, &objp->hostname, ~0)) - return FALSE; - if (!xdr_int (xdrs, &objp->port)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_probe_rsp (XDR *xdrs, gf1_cli_probe_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - - if (xdrs->x_op == XDR_ENCODE) { - buf = XDR_INLINE (xdrs, 3 * BYTES_PER_XDR_UNIT); - if (buf == NULL) { - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_int (xdrs, &objp->port)) - return FALSE; - - } else { - IXDR_PUT_LONG(buf, objp->op_ret); - IXDR_PUT_LONG(buf, objp->op_errno); - IXDR_PUT_LONG(buf, objp->port); - } - if (!xdr_string (xdrs, &objp->hostname, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->op_errstr, ~0)) - return FALSE; - return TRUE; - } else if (xdrs->x_op == XDR_DECODE) { - buf = XDR_INLINE (xdrs, 3 * BYTES_PER_XDR_UNIT); - if (buf == NULL) { - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_int (xdrs, &objp->port)) - return FALSE; - - } else { - objp->op_ret = IXDR_GET_LONG(buf); - objp->op_errno = IXDR_GET_LONG(buf); - objp->port = IXDR_GET_LONG(buf); - } - if (!xdr_string (xdrs, &objp->hostname, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->op_errstr, ~0)) - return FALSE; - return TRUE; - } - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_int (xdrs, &objp->port)) - return FALSE; - if (!xdr_string (xdrs, &objp->hostname, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->op_errstr, ~0)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_deprobe_req (XDR *xdrs, gf1_cli_deprobe_req *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_string (xdrs, &objp->hostname, ~0)) - return FALSE; - if (!xdr_int (xdrs, &objp->port)) - return FALSE; - if (!xdr_int (xdrs, &objp->flags)) - return FALSE; - return TRUE; -} - -bool_t -xdr_gf1_cli_deprobe_rsp (XDR *xdrs, gf1_cli_deprobe_rsp *objp) -{ - register int32_t *buf; - buf = NULL; - - if (!xdr_int (xdrs, &objp->op_ret)) - return FALSE; - if (!xdr_int (xdrs, &objp->op_errno)) - return FALSE; - if (!xdr_string (xdrs, &objp->hostname, ~0)) - return FALSE; - if (!xdr_string (xdrs, &objp->op_errstr, ~0)) - return FALSE; - return TRUE; -} - bool_t xdr_gf1_cli_peer_list_req (XDR *xdrs, gf1_cli_peer_list_req *objp) { diff --git a/rpc/xdr/src/cli1-xdr.h b/rpc/xdr/src/cli1-xdr.h index 9aeee2a6c..e80d6f70c 100644 --- a/rpc/xdr/src/cli1-xdr.h +++ b/rpc/xdr/src/cli1-xdr.h @@ -181,36 +181,6 @@ struct gf_cli_rsp { }; typedef struct gf_cli_rsp gf_cli_rsp; -struct gf1_cli_probe_req { - char *hostname; - int port; -}; -typedef struct gf1_cli_probe_req gf1_cli_probe_req; - -struct gf1_cli_probe_rsp { - int op_ret; - int op_errno; - int port; - char *hostname; - char *op_errstr; -}; -typedef struct gf1_cli_probe_rsp gf1_cli_probe_rsp; - -struct gf1_cli_deprobe_req { - char *hostname; - int port; - int flags; -}; -typedef struct gf1_cli_deprobe_req gf1_cli_deprobe_req; - -struct gf1_cli_deprobe_rsp { - int op_ret; - int op_errno; - char *hostname; - char *op_errstr; -}; -typedef struct gf1_cli_deprobe_rsp gf1_cli_deprobe_rsp; - struct gf1_cli_peer_list_req { int flags; struct { @@ -305,10 +275,6 @@ extern bool_t xdr_gf1_cli_top_op (XDR *, gf1_cli_top_op*); extern bool_t xdr_gf_cli_status_type (XDR *, gf_cli_status_type*); extern bool_t xdr_gf_cli_req (XDR *, gf_cli_req*); extern bool_t xdr_gf_cli_rsp (XDR *, gf_cli_rsp*); -extern bool_t xdr_gf1_cli_probe_req (XDR *, gf1_cli_probe_req*); -extern bool_t xdr_gf1_cli_probe_rsp (XDR *, gf1_cli_probe_rsp*); -extern bool_t xdr_gf1_cli_deprobe_req (XDR *, gf1_cli_deprobe_req*); -extern bool_t xdr_gf1_cli_deprobe_rsp (XDR *, gf1_cli_deprobe_rsp*); extern bool_t xdr_gf1_cli_peer_list_req (XDR *, gf1_cli_peer_list_req*); extern bool_t xdr_gf1_cli_peer_list_rsp (XDR *, gf1_cli_peer_list_rsp*); extern bool_t xdr_gf1_cli_fsm_log_req (XDR *, gf1_cli_fsm_log_req*); @@ -337,10 +303,6 @@ extern bool_t xdr_gf1_cli_top_op (); extern bool_t xdr_gf_cli_status_type (); extern bool_t xdr_gf_cli_req (); extern bool_t xdr_gf_cli_rsp (); -extern bool_t xdr_gf1_cli_probe_req (); -extern bool_t xdr_gf1_cli_probe_rsp (); -extern bool_t xdr_gf1_cli_deprobe_req (); -extern bool_t xdr_gf1_cli_deprobe_rsp (); extern bool_t xdr_gf1_cli_peer_list_req (); extern bool_t xdr_gf1_cli_peer_list_rsp (); extern bool_t xdr_gf1_cli_fsm_log_req (); diff --git a/rpc/xdr/src/cli1-xdr.x b/rpc/xdr/src/cli1-xdr.x index cb22080cc..0bee19679 100644 --- a/rpc/xdr/src/cli1-xdr.x +++ b/rpc/xdr/src/cli1-xdr.x @@ -125,32 +125,6 @@ enum gf_cli_status_type { opaque dict<>; } ; - struct gf1_cli_probe_req { - string hostname<>; - int port; -} ; - - struct gf1_cli_probe_rsp { - int op_ret; - int op_errno; - int port; - string hostname<>; - string op_errstr<>; -} ; - - struct gf1_cli_deprobe_req { - string hostname<>; - int port; - int flags; -} ; - - struct gf1_cli_deprobe_rsp { - int op_ret; - int op_errno; - string hostname<>; - string op_errstr<>; -} ; - struct gf1_cli_peer_list_req { int flags; opaque dict<>; diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c index cf3170c0a..dd9e248cf 100644 --- a/xlators/mgmt/glusterd/src/glusterd-handler.c +++ b/xlators/mgmt/glusterd/src/glusterd-handler.c @@ -748,17 +748,19 @@ int __glusterd_handle_cli_probe (rpcsvc_request_t *req) { int32_t ret = -1; - gf1_cli_probe_req cli_req = {0,}; - glusterd_peerinfo_t *peerinfo = NULL; - gf_boolean_t run_fsm = _gf_true; - xlator_t *this = NULL; - char *bind_name = NULL; + gf_cli_req cli_req = {{0,},}; + glusterd_peerinfo_t *peerinfo = NULL; + gf_boolean_t run_fsm = _gf_true; + xlator_t *this = NULL; + char *bind_name = NULL; + dict_t *dict = NULL; + char *hostname = NULL; + int port = 0; GF_ASSERT (req); this = THIS; - ret = xdr_to_generic (req->msg[0], &cli_req, - (xdrproc_t)xdr_gf1_cli_probe_req); + ret = xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req); if (ret < 0) { //failed to decode msg; gf_log ("", GF_LOG_ERROR, "xdr decoding error"); @@ -766,63 +768,80 @@ __glusterd_handle_cli_probe (rpcsvc_request_t *req) goto out; } + if (cli_req.dict.dict_len) { + dict = dict_new (); + + ret = dict_unserialize (cli_req.dict.dict_val, + cli_req.dict.dict_len, &dict); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "Failed to " + "unserialize req-buffer to dictionary"); + goto out; + } + } + + ret = dict_get_str (dict, "hostname", &hostname); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, "Failed to get hostname"); + goto out; + } + + ret = dict_get_int32 (dict, "port", &port); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, "Failed to get port"); + goto out; + } + if (glusterd_is_any_volume_in_server_quorum (this) && !does_gd_meet_server_quorum (this)) { glusterd_xfer_cli_probe_resp (req, -1, GF_PROBE_QUORUM_NOT_MET, - NULL, - cli_req.hostname, cli_req.port); + NULL, hostname, port, dict); gf_log (this->name, GF_LOG_ERROR, "Quorum does not meet, " "rejecting operation"); ret = 0; goto out; } - gf_cmd_log ("peer probe", " on host %s:%d", cli_req.hostname, - cli_req.port); gf_log ("glusterd", GF_LOG_INFO, "Received CLI probe req %s %d", - cli_req.hostname, cli_req.port); + hostname, port); if (dict_get_str(this->options,"transport.socket.bind-address", &bind_name) == 0) { gf_log ("glusterd", GF_LOG_DEBUG, "only checking probe address vs. bind address"); - ret = glusterd_is_same_address(bind_name,cli_req.hostname); + ret = glusterd_is_same_address (bind_name, hostname); } else { - ret = glusterd_is_local_addr(cli_req.hostname); + ret = glusterd_is_local_addr (hostname); } if (ret) { - glusterd_xfer_cli_probe_resp (req, 0, GF_PROBE_LOCALHOST, NULL, - cli_req.hostname, cli_req.port); + glusterd_xfer_cli_probe_resp (req, 0, GF_PROBE_LOCALHOST, + NULL, hostname, port, dict); ret = 0; goto out; } - if (!(ret = glusterd_friend_find_by_hostname(cli_req.hostname, - &peerinfo))) { - if (strcmp (peerinfo->hostname, cli_req.hostname) == 0) { + if (!(ret = glusterd_friend_find_by_hostname (hostname, &peerinfo))) { + if (strcmp (peerinfo->hostname, hostname) == 0) { gf_log ("glusterd", GF_LOG_DEBUG, "Probe host %s port " - "%d already a peer", cli_req.hostname, - cli_req.port); + "%d already a peer", hostname, port); glusterd_xfer_cli_probe_resp (req, 0, GF_PROBE_FRIEND, - NULL, cli_req.hostname, - cli_req.port); + NULL, hostname, port, + dict); goto out; } } - ret = glusterd_probe_begin (req, cli_req.hostname, cli_req.port); - - gf_cmd_log ("peer probe","on host %s:%d %s",cli_req.hostname, - cli_req.port, (ret) ? "FAILED" : "SUCCESS"); + ret = glusterd_probe_begin (req, hostname, port, dict); if (ret == GLUSTERD_CONNECTION_AWAITED) { //fsm should be run after connection establishes run_fsm = _gf_false; ret = 0; } + out: - free (cli_req.hostname);//its malloced by xdr + free (cli_req.dict.dict_val); if (run_fsm) { glusterd_friend_sm (); @@ -842,11 +861,15 @@ int __glusterd_handle_cli_deprobe (rpcsvc_request_t *req) { int32_t ret = -1; - gf1_cli_deprobe_req cli_req = {0,}; - uuid_t uuid = {0}; - int op_errno = 0; - xlator_t *this = NULL; - glusterd_conf_t *priv = NULL; + gf_cli_req cli_req = {{0,},}; + uuid_t uuid = {0}; + int op_errno = 0; + xlator_t *this = NULL; + glusterd_conf_t *priv = NULL; + dict_t *dict = NULL; + char *hostname = NULL; + int port = 0; + int flags = 0; this = THIS; GF_ASSERT (this); @@ -855,16 +878,46 @@ __glusterd_handle_cli_deprobe (rpcsvc_request_t *req) GF_ASSERT (req); ret = xdr_to_generic (req->msg[0], &cli_req, - (xdrproc_t)xdr_gf1_cli_deprobe_req); + (xdrproc_t)xdr_gf_cli_req); if (ret < 0) { //failed to decode msg; req->rpc_err = GARBAGE_ARGS; goto out; } + if (cli_req.dict.dict_len) { + dict = dict_new (); + + ret = dict_unserialize (cli_req.dict.dict_val, + cli_req.dict.dict_len, &dict); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "Failed to " + "unserialize req-buffer to dictionary"); + goto out; + } + } + gf_log ("glusterd", GF_LOG_INFO, "Received CLI deprobe req"); - ret = glusterd_hostname_to_uuid (cli_req.hostname, uuid); + ret = dict_get_str (dict, "hostname", &hostname); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, "Failed to get hostname"); + goto out; + } + + ret = dict_get_int32 (dict, "port", &port); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, "Failed to get port"); + goto out; + } + + ret = dict_get_int32 (dict, "flags", &flags); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, "Failed to get flags"); + goto out; + } + + ret = glusterd_hostname_to_uuid (hostname, uuid); if (ret) { op_errno = GF_DEPROBE_NOT_FRIEND; goto out; @@ -876,7 +929,7 @@ __glusterd_handle_cli_deprobe (rpcsvc_request_t *req) goto out; } - if (!(cli_req.flags & GF_CLI_FLAG_OP_FORCE)) { + if (!(flags & GF_CLI_FLAG_OP_FORCE)) { if (!uuid_is_null (uuid)) { /* Check if peers are connected, except peer being detached*/ if (!glusterd_chk_peers_connected_befriended (uuid)) { @@ -904,23 +957,19 @@ __glusterd_handle_cli_deprobe (rpcsvc_request_t *req) } if (!uuid_is_null (uuid)) { - ret = glusterd_deprobe_begin (req, cli_req.hostname, - cli_req.port, uuid); + ret = glusterd_deprobe_begin (req, hostname, port, uuid, dict); } else { - ret = glusterd_deprobe_begin (req, cli_req.hostname, - cli_req.port, NULL); + ret = glusterd_deprobe_begin (req, hostname, port, NULL, dict); } - gf_cmd_log ("peer deprobe", "on host %s:%d %s", cli_req.hostname, - cli_req.port, (ret) ? "FAILED" : "SUCCESS"); out: + free (cli_req.dict.dict_val); + if (ret) { ret = glusterd_xfer_cli_deprobe_resp (req, ret, op_errno, NULL, - cli_req.hostname); + hostname, dict); } - free (cli_req.hostname);//malloced by xdr - glusterd_friend_sm (); glusterd_op_sm (); @@ -2823,7 +2872,8 @@ out: } int -glusterd_probe_begin (rpcsvc_request_t *req, const char *hoststr, int port) +glusterd_probe_begin (rpcsvc_request_t *req, const char *hoststr, int port, + dict_t *dict) { int ret = -1; glusterd_peerinfo_t *peerinfo = NULL; @@ -2839,6 +2889,7 @@ glusterd_probe_begin (rpcsvc_request_t *req, const char *hoststr, int port) " for host: %s (%d)", hoststr, port); args.mode = GD_MODE_ON; args.req = req; + args.dict = dict; ret = glusterd_friend_add ((char *)hoststr, port, GD_FRIEND_STATE_DEFAULT, NULL, &peerinfo, 0, &args); @@ -2860,11 +2911,11 @@ glusterd_probe_begin (rpcsvc_request_t *req, const char *hoststr, int port) ret = glusterd_friend_sm_inject_event (event); glusterd_xfer_cli_probe_resp (req, 0, GF_PROBE_SUCCESS, NULL, (char*)hoststr, - port); + port, dict); } } else { glusterd_xfer_cli_probe_resp (req, 0, GF_PROBE_FRIEND, NULL, - (char*)hoststr, port); + (char*)hoststr, port, dict); } out: @@ -2874,7 +2925,7 @@ out: int glusterd_deprobe_begin (rpcsvc_request_t *req, const char *hoststr, int port, - uuid_t uuid) + uuid_t uuid, dict_t *dict) { int ret = -1; glusterd_peerinfo_t *peerinfo = NULL; @@ -2915,6 +2966,7 @@ glusterd_deprobe_begin (rpcsvc_request_t *req, const char *hoststr, int port, ctx->hostname = gf_strdup (hoststr); ctx->port = port; ctx->req = req; + ctx->dict = dict; event->ctx = ctx; @@ -2993,49 +3045,199 @@ glusterd_xfer_friend_add_resp (rpcsvc_request_t *req, char *myhostname, return ret; } +static void +get_probe_error_str (int op_ret, int op_errno, char *errstr, size_t len, + char *hostname, int port) +{ + + if (!op_ret) { + switch (op_errno) { + case GF_PROBE_LOCALHOST: + snprintf (errstr, len, "Probe on localhost not " + "needed"); + break; + + case GF_PROBE_FRIEND: + snprintf (errstr, len, "Host %s port %d already" + " in peer list", hostname, port); + break; + + default: + if (op_errno != 0) + snprintf (errstr, len, "Probe returned " + "with unknown errno %d", + op_errno); + break; + } + } else { + switch (op_errno) { + case GF_PROBE_ANOTHER_CLUSTER: + snprintf (errstr, len, "%s is already part of " + "another cluster", hostname); + break; + + case GF_PROBE_VOLUME_CONFLICT: + snprintf (errstr, len, "Atleast one volume on " + "%s conflicts with existing volumes " + "in the cluster", hostname); + break; + + case GF_PROBE_UNKNOWN_PEER: + snprintf (errstr, len, "%s responded with " + "'unknown peer' error, this could " + "happen if %s doesn't have localhost " + "in its peer database", hostname, + hostname); + break; + + case GF_PROBE_ADD_FAILED: + snprintf (errstr, len, "Failed to add peer " + "information on %s", hostname); + break; + + case GF_PROBE_SAME_UUID: + snprintf (errstr, len, "Peer uuid (host %s) is " + "same as local uuid", hostname); + break; + + case GF_PROBE_QUORUM_NOT_MET: + snprintf (errstr, len, "Cluster quorum is not " + "met. Changing peers is not allowed " + "in this state"); + break; + + default: + snprintf (errstr, len, "Probe returned with " + "unknown errno %d", op_errno); + break; + } + } +} + int glusterd_xfer_cli_probe_resp (rpcsvc_request_t *req, int32_t op_ret, int32_t op_errno, char *op_errstr, char *hostname, - int port) + int port, dict_t *dict) { - gf1_cli_probe_rsp rsp = {0, }; + gf_cli_rsp rsp = {0,}; int32_t ret = -1; + char errstr[2048] = {0,}; + char *cmd_str = NULL; + xlator_t *this = THIS; GF_ASSERT (req); + GF_ASSERT (this); + + if (op_errstr == NULL) + (void) get_probe_error_str (op_ret, op_errno, errstr, + sizeof (errstr), hostname, port); + else + snprintf (errstr, sizeof (errstr), "%s", op_errstr); + + if (dict) { + ret = dict_get_str (dict, "cmd-str", &cmd_str); + if (ret) + gf_log (this->name, GF_LOG_ERROR, "Failed to get " + "command string"); + } rsp.op_ret = op_ret; rsp.op_errno = op_errno; - rsp.op_errstr = op_errstr ? op_errstr : ""; - rsp.hostname = hostname; - rsp.port = port; + rsp.op_errstr = (errstr[0] != '\0') ? errstr : ""; + + gf_cmd_log ("", "%s : %s %s %s", cmd_str, + (op_ret) ? "FAILED" : "SUCCESS", + (errstr[0] != '\0') ? ":" : " ", + (errstr[0] != '\0') ? errstr : " "); ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL, - (xdrproc_t)xdr_gf1_cli_probe_rsp); + (xdrproc_t)xdr_gf_cli_rsp); - gf_log ("glusterd", GF_LOG_INFO, "Responded to CLI, ret: %d",ret); + if (dict) + dict_unref (dict); + gf_log (this->name, GF_LOG_DEBUG, "Responded to CLI, ret: %d",ret); return ret; } +static void +get_deprobe_error_str (int op_ret, int op_errno, char *errstr, size_t len, + char *hostname) +{ + if (op_ret) { + switch (op_errno) { + case GF_DEPROBE_LOCALHOST: + snprintf (errstr, len, "%s is localhost", + hostname); + break; + + case GF_DEPROBE_NOT_FRIEND: + snprintf (errstr, len, "%s is not part of " + "cluster", hostname); + break; + + case GF_DEPROBE_BRICK_EXIST: + snprintf (errstr, len, "Brick(s) with the peer " + "%s exist in cluster", hostname); + break; + + case GF_DEPROBE_FRIEND_DOWN: + snprintf (errstr, len, "One of the peers is " + "probably down. Check with " + "'peer status'"); + break; + + case GF_DEPROBE_QUORUM_NOT_MET: + snprintf (errstr, len, "Cluster quorum is not " + "met. Changing peers is not allowed " + "in this state"); + break; + + default: + snprintf (errstr, len, "Detach returned with " + "unknown errno %d", op_errno); + break; + + } + } +} + + int glusterd_xfer_cli_deprobe_resp (rpcsvc_request_t *req, int32_t op_ret, int32_t op_errno, char *op_errstr, - char *hostname) + char *hostname, dict_t *dict) { - gf1_cli_deprobe_rsp rsp = {0, }; + gf_cli_rsp rsp = {0,}; int32_t ret = -1; + char *cmd_str = NULL; + char errstr[2048] = {0,}; GF_ASSERT (req); + (void) get_deprobe_error_str (op_ret, op_errno, errstr, sizeof (errstr), + hostname); + + if (dict) { + ret = dict_get_str (dict, "cmd-str", &cmd_str); + if (ret) + gf_log (THIS->name, GF_LOG_ERROR, "Failed to get " + "command string"); + } + rsp.op_ret = op_ret; rsp.op_errno = op_errno; - rsp.op_errstr = op_errstr ? op_errstr : ""; - rsp.hostname = hostname; + rsp.op_errstr = (errstr[0] != '\0') ? errstr : ""; + + gf_cmd_log ("", "%s : %s %s %s", cmd_str, + (op_ret) ? "FAILED" : "SUCCESS", + (errstr[0] != '\0') ? ":" : " ", + (errstr[0] != '\0') ? errstr : " "); ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL, - (xdrproc_t)xdr_gf1_cli_deprobe_rsp); + (xdrproc_t)xdr_gf_cli_rsp); - gf_log ("glusterd", GF_LOG_INFO, "Responded to CLI, ret: %d",ret); + gf_log (THIS->name, GF_LOG_DEBUG, "Responded to CLI, ret: %d",ret); return ret; } @@ -3529,11 +3731,13 @@ glusterd_friend_remove_notify (glusterd_peerctx_t *peerctx) glusterd_peerinfo_t *peerinfo = peerctx->peerinfo; rpcsvc_request_t *req = peerctx->args.req; char *errstr = peerctx->errstr; + dict_t *dict = NULL; GF_ASSERT (peerctx); peerinfo = peerctx->peerinfo; req = peerctx->args.req; + dict = peerctx->args.dict; errstr = peerctx->errstr; ret = glusterd_friend_sm_new_event (GD_FRIEND_EVENT_REMOVE_FRIEND, @@ -3547,7 +3751,8 @@ glusterd_friend_remove_notify (glusterd_peerctx_t *peerctx) } glusterd_xfer_cli_probe_resp (req, -1, ENOTCONN, errstr, - peerinfo->hostname, peerinfo->port); + peerinfo->hostname, + peerinfo->port, dict); new_event->peerinfo = peerinfo; ret = glusterd_friend_sm_inject_event (new_event); diff --git a/xlators/mgmt/glusterd/src/glusterd-handshake.c b/xlators/mgmt/glusterd/src/glusterd-handshake.c index 9124c46ee..05c3012e4 100644 --- a/xlators/mgmt/glusterd/src/glusterd-handshake.c +++ b/xlators/mgmt/glusterd/src/glusterd-handshake.c @@ -677,6 +677,7 @@ glusterd_event_connected_inject (glusterd_peerctx_t *peerctx) ctx->hostname = gf_strdup (peerinfo->hostname); ctx->port = peerinfo->port; ctx->req = peerctx->args.req; + ctx->dict = peerctx->args.dict; event->peerinfo = peerinfo; event->ctx = ctx; diff --git a/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c b/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c index 01fb77775..18a743494 100644 --- a/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c +++ b/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c @@ -233,7 +233,8 @@ __glusterd_probe_cbk (struct rpc_req *req, struct iovec *iov, glusterd_xfer_cli_probe_resp (ctx->req, rsp.op_ret, rsp.op_errno, rsp.op_errstr, - ctx->hostname, ctx->port); + ctx->hostname, ctx->port, + ctx->dict); } glusterd_destroy_probe_ctx (ctx); @@ -261,7 +262,8 @@ __glusterd_probe_cbk (struct rpc_req *req, struct iovec *iov, glusterd_xfer_cli_probe_resp (ctx->req, rsp.op_ret, rsp.op_errno, rsp.op_errstr, - ctx->hostname, ctx->port); + ctx->hostname, ctx->port, + ctx->dict); } glusterd_destroy_probe_ctx (ctx); @@ -390,7 +392,7 @@ out: if (ctx->req)//reverse probe doesn't have req ret = glusterd_xfer_cli_probe_resp (ctx->req, op_ret, op_errno, NULL, ctx->hostname, - ctx->port); + ctx->port, ctx->dict); if (!ret) { glusterd_friend_sm (); glusterd_op_sm (); @@ -488,7 +490,7 @@ inject: respond: ret = glusterd_xfer_cli_deprobe_resp (ctx->req, op_ret, op_errno, NULL, - ctx->hostname); + ctx->hostname, ctx->dict); if (!ret && move_sm_now) { glusterd_friend_sm (); glusterd_op_sm (); diff --git a/xlators/mgmt/glusterd/src/glusterd-sm.c b/xlators/mgmt/glusterd/src/glusterd-sm.c index 86ce86a3e..c671edf68 100644 --- a/xlators/mgmt/glusterd/src/glusterd-sm.c +++ b/xlators/mgmt/glusterd/src/glusterd-sm.c @@ -400,7 +400,8 @@ glusterd_ac_send_friend_remove_req (glusterd_friend_sm_event_t *event, if (ctx) ret = glusterd_xfer_cli_deprobe_resp (ctx->req, ret, 0, NULL, - ctx->hostname); + ctx->hostname, + ctx->dict); glusterd_friend_sm (); glusterd_op_sm (); diff --git a/xlators/mgmt/glusterd/src/glusterd-sm.h b/xlators/mgmt/glusterd/src/glusterd-sm.h index 99eabfa86..9861a48a5 100644 --- a/xlators/mgmt/glusterd/src/glusterd-sm.h +++ b/xlators/mgmt/glusterd/src/glusterd-sm.h @@ -123,6 +123,7 @@ typedef enum glusterd_ev_gen_mode_ { typedef struct glusterd_peer_ctx_args_ { rpcsvc_request_t *req; glusterd_ev_gen_mode_t mode; + dict_t *dict; } glusterd_peerctx_args_t; typedef struct glusterd_peer_ctx_ { @@ -189,6 +190,7 @@ typedef struct glusterd_probe_ctx_ { char *hostname; rpcsvc_request_t *req; int port; + dict_t *dict; } glusterd_probe_ctx_t; int glusterd_friend_sm_new_event (glusterd_friend_sm_event_type_t event_type, diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h index b466ac20c..e3b1884eb 100644 --- a/xlators/mgmt/glusterd/src/glusterd.h +++ b/xlators/mgmt/glusterd/src/glusterd.h @@ -446,7 +446,8 @@ int32_t glusterd_brick_from_brickinfo (glusterd_brickinfo_t *brickinfo, char **new_brick); int -glusterd_probe_begin (rpcsvc_request_t *req, const char *hoststr, int port); +glusterd_probe_begin (rpcsvc_request_t *req, const char *hoststr, int port, + dict_t *dict); int glusterd_xfer_friend_add_resp (rpcsvc_request_t *req, char *myhostname, @@ -520,7 +521,7 @@ glusterd_handle_defrag_volume_v2 (rpcsvc_request_t *req); int glusterd_xfer_cli_probe_resp (rpcsvc_request_t *req, int32_t op_ret, int32_t op_errno, char *op_errstr, char *hostname, - int port); + int port, dict_t *dict); int glusterd_op_commit_send_resp (rpcsvc_request_t *req, @@ -532,7 +533,7 @@ glusterd_xfer_friend_remove_resp (rpcsvc_request_t *req, char *hostname, int por int glusterd_deprobe_begin (rpcsvc_request_t *req, const char *hoststr, int port, - uuid_t uuid); + uuid_t uuid, dict_t *dict); int glusterd_handle_cli_deprobe (rpcsvc_request_t *req); @@ -618,7 +619,7 @@ glusterd_handle_fsm_log (rpcsvc_request_t *req); int glusterd_xfer_cli_deprobe_resp (rpcsvc_request_t *req, int32_t op_ret, int32_t op_errno, char *op_errstr, - char *hostname); + char *hostname, dict_t *dict); int glusterd_fetchspec_notify (xlator_t *this); -- cgit