diff options
-rw-r--r-- | rpc/xdr/src/glusterd1-xdr.c | 49 | ||||
-rw-r--r-- | rpc/xdr/src/glusterd1-xdr.h | 4 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-handler.c | 70 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-op-sm.c | 34 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd3_1-mops.c | 65 |
5 files changed, 218 insertions, 4 deletions
diff --git a/rpc/xdr/src/glusterd1-xdr.c b/rpc/xdr/src/glusterd1-xdr.c index 82d9830c97f..3ddd5568826 100644 --- a/rpc/xdr/src/glusterd1-xdr.c +++ b/rpc/xdr/src/glusterd1-xdr.c @@ -17,7 +17,6 @@ <http://www.gnu.org/licenses/>. */ - /* * Please do not edit this file. * It was generated using rpcgen. @@ -28,7 +27,6 @@ bool_t xdr_glusterd_volume_status (XDR *xdrs, glusterd_volume_status *objp) { - if (!xdr_enum (xdrs, (enum_t *) objp)) return FALSE; return TRUE; @@ -223,6 +221,51 @@ xdr_gd1_mgmt_commit_op_req (XDR *xdrs, gd1_mgmt_commit_op_req *objp) bool_t xdr_gd1_mgmt_commit_op_rsp (XDR *xdrs, gd1_mgmt_commit_op_rsp *objp) { + register int32_t *buf; + + if (xdrs->x_op == XDR_ENCODE) { + if (!xdr_vector (xdrs, (char *)objp->uuid, 16, + sizeof (u_char), (xdrproc_t) xdr_u_char)) + return FALSE; + buf = XDR_INLINE (xdrs, 3 * BYTES_PER_XDR_UNIT); + if (buf == NULL) { + if (!xdr_int (xdrs, &objp->op)) + return FALSE; + if (!xdr_int (xdrs, &objp->op_ret)) + return FALSE; + if (!xdr_int (xdrs, &objp->op_errno)) + return FALSE; + + } else { + IXDR_PUT_LONG(buf, objp->op); + IXDR_PUT_LONG(buf, objp->op_ret); + IXDR_PUT_LONG(buf, objp->op_errno); + } + if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) + return FALSE; + return TRUE; + } else if (xdrs->x_op == XDR_DECODE) { + if (!xdr_vector (xdrs, (char *)objp->uuid, 16, + sizeof (u_char), (xdrproc_t) xdr_u_char)) + return FALSE; + buf = XDR_INLINE (xdrs, 3 * BYTES_PER_XDR_UNIT); + if (buf == NULL) { + if (!xdr_int (xdrs, &objp->op)) + return FALSE; + if (!xdr_int (xdrs, &objp->op_ret)) + return FALSE; + if (!xdr_int (xdrs, &objp->op_errno)) + return FALSE; + + } else { + objp->op = IXDR_GET_LONG(buf); + objp->op_ret = IXDR_GET_LONG(buf); + objp->op_errno = IXDR_GET_LONG(buf); + } + if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) + return FALSE; + return TRUE; + } if (!xdr_vector (xdrs, (char *)objp->uuid, 16, sizeof (u_char), (xdrproc_t) xdr_u_char)) @@ -233,6 +276,8 @@ xdr_gd1_mgmt_commit_op_rsp (XDR *xdrs, gd1_mgmt_commit_op_rsp *objp) return FALSE; if (!xdr_int (xdrs, &objp->op_errno)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) + return FALSE; return TRUE; } diff --git a/rpc/xdr/src/glusterd1-xdr.h b/rpc/xdr/src/glusterd1-xdr.h index 7b208ee5f11..0c738d00c3e 100644 --- a/rpc/xdr/src/glusterd1-xdr.h +++ b/rpc/xdr/src/glusterd1-xdr.h @@ -148,6 +148,10 @@ struct gd1_mgmt_commit_op_rsp { int op; int op_ret; int op_errno; + struct { + u_int dict_len; + char *dict_val; + } dict; }; typedef struct gd1_mgmt_commit_op_rsp gd1_mgmt_commit_op_rsp; diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c index 6b5b01c770d..86e0ab5a303 100644 --- a/xlators/mgmt/glusterd/src/glusterd-handler.c +++ b/xlators/mgmt/glusterd/src/glusterd-handler.c @@ -2008,24 +2008,90 @@ glusterd_op_stage_send_resp (rpcsvc_request_t *req, return ret; } +static int +glusterd_fill_rb_commit_rsp (dict_t *rsp_dict) +{ + dict_t *dict = NULL; + int32_t port_no = 0; + int ret = 0; + + dict = glusterd_op_get_ctx (GD_OP_REPLACE_BRICK); + if (!dict) { + gf_log ("", GF_LOG_ERROR, + "Operation Context is not present"); + ret = 0; + goto out; + } + + ret = dict_get_int32 (dict, "src-brick-port", &port_no); + if (ret) { + gf_log ("", GF_LOG_DEBUG, + "Could not get src-brick-port => this must " + "be a non-source glusterd process"); + ret = 0; + goto out; + } + + gf_log ("", GF_LOG_DEBUG, + "This is the source glusterd => fill the src port"); + + ret = dict_set_int32 (rsp_dict, "src-brick-port", port_no); + if (ret) { + gf_log ("", GF_LOG_DEBUG, + "Could not set commit rsp dict"); + goto out; + } + +out: + return ret; +} + int glusterd_op_commit_send_resp (rpcsvc_request_t *req, int32_t op, int32_t status) { - gd1_mgmt_commit_op_rsp rsp = {{0}, }; - int ret = -1; + dict_t *rsp_dict = NULL; + gd1_mgmt_commit_op_rsp rsp = {{0}, }; + int ret = -1; GF_ASSERT (req); rsp.op_ret = status; glusterd_get_uuid (&rsp.uuid); rsp.op = op; + rsp_dict = dict_new (); + if (!rsp_dict) { + gf_log ("", GF_LOG_DEBUG, + "Out of memory"); + ret = -1; + goto out; + } + + if (op == GD_OP_REPLACE_BRICK) { + ret = glusterd_fill_rb_commit_rsp (rsp_dict); + if (ret) + goto out; + } + + ret = dict_allocate_and_serialize (rsp_dict, + &rsp.dict.dict_val, + (size_t *)&rsp.dict.dict_len); + if (ret < 0) { + gf_log ("", GF_LOG_DEBUG, + "failed to get serialized length of dict"); + goto out; + } + + ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL, gd_xdr_serialize_mgmt_commit_op_rsp); gf_log ("glusterd", GF_LOG_NORMAL, "Responded to commit, ret: %d", ret); +out: + if (rsp_dict) + dict_unref (rsp_dict); return ret; } diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c index a70df3ed364..7a063f64bc3 100644 --- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c +++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c @@ -2028,6 +2028,7 @@ glusterd_op_replace_brick (gd1_mgmt_stage_op_req *req) { int ret = 0; dict_t *dict = NULL; + dict_t *ctx = NULL; gf1_cli_replace_op replace_op; glusterd_volinfo_t *volinfo = NULL; char *volname = NULL; @@ -2106,6 +2107,30 @@ glusterd_op_replace_brick (gd1_mgmt_stage_op_req *req) goto out; } + /* Set src-brick's port number to be used in the maintainance mount + * after all commit acks are received. + */ + if (!glusterd_is_local_addr (src_brickinfo->hostname)) { + gf_log ("", GF_LOG_NORMAL, + "adding src-brick port no"); + + ctx = glusterd_op_get_ctx (GD_OP_REPLACE_BRICK); + if (!ctx) { + gf_log ("", GF_LOG_ERROR, + "Operation Context is not present"); + ret = -1; + goto out; + } + + ret = dict_set_int32 (ctx, "src-brick-port", + src_brickinfo->port); + if (ret) { + gf_log ("", GF_LOG_DEBUG, + "Could not set src-brick port no"); + goto out; + } + } + switch (replace_op) { case GF_REPLACE_OP_START: { @@ -2892,6 +2917,7 @@ glusterd_op_ac_rcvd_commit_op_acc (glusterd_op_sm_event_t *event, void *ctx) { glusterd_volinfo_t *volinfo = NULL; int32_t op = 0; + int32_t src_port = 0; dict_t *dict = NULL; char *src_brick = NULL; char *dst_brick = NULL; @@ -2961,6 +2987,14 @@ glusterd_op_ac_rcvd_commit_op_acc (glusterd_op_sm_event_t *event, void *ctx) goto out; } + ret = dict_get_int32 (dict, "src-brick-port", &src_port); + if (ret) { + gf_log ("", GF_LOG_ERROR, "Unable to get src-brick port"); + goto out; + } + + src_brickinfo->port = src_port; + switch (op) { case GF_REPLACE_OP_START: ret = rb_do_operation_start (volinfo, src_brickinfo, dst_brickinfo); diff --git a/xlators/mgmt/glusterd/src/glusterd3_1-mops.c b/xlators/mgmt/glusterd/src/glusterd3_1-mops.c index 9d9dc385a1c..c9c1493ffe4 100644 --- a/xlators/mgmt/glusterd/src/glusterd3_1-mops.c +++ b/xlators/mgmt/glusterd/src/glusterd3_1-mops.c @@ -521,6 +521,48 @@ out: return ret; } +static int32_t +glusterd_rb_use_rsp_dict (dict_t *rsp_dict) +{ + int32_t src_port = 0; + int ret = 0; + dict_t *ctx = NULL; + + GF_ASSERT (rsp_dict); + + if (rsp_dict) { + ret = dict_get_int32 (rsp_dict, "src-brick-port", &src_port); + if (ret) { + gf_log ("", GF_LOG_DEBUG, + "src-brick-port not present"); + ret = 0; + goto out; + } + + if (src_port) { + ctx = glusterd_op_get_ctx (GD_OP_REPLACE_BRICK); + if (!ctx) { + gf_log ("", GF_LOG_ERROR, + "Operation Context is not present"); + ret = 0; + goto out; + } + + ret = dict_set_int32 (ctx, "src-brick-port", + src_port); + if (ret) { + gf_log ("", GF_LOG_DEBUG, + "Could not set src-brick"); + goto out; + } + } + } + +out: + return ret; + +} + int32_t glusterd3_1_commit_op_cbk (struct rpc_req *req, struct iovec *iov, int count, void *myframe) @@ -531,6 +573,7 @@ glusterd3_1_commit_op_cbk (struct rpc_req *req, struct iovec *iov, glusterd_op_sm_event_type_t event_type = GD_OP_EVENT_NONE; glusterd_peerinfo_t *peerinfo = NULL; char str[50] = {0,}; + dict_t *dict = NULL; GF_ASSERT (req); @@ -550,6 +593,21 @@ glusterd3_1_commit_op_cbk (struct rpc_req *req, struct iovec *iov, } uuid_unparse (rsp.uuid, str); + 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) { + gf_log ("glusterd", GF_LOG_ERROR, + "failed to " + "unserialize rsp-buffer to dictionary"); + goto out; + } + } + op_ret = rsp.op_ret; gf_log ("glusterd", GF_LOG_NORMAL, @@ -566,6 +624,11 @@ glusterd3_1_commit_op_cbk (struct rpc_req *req, struct iovec *iov, event_type = GD_OP_EVENT_RCVD_RJT; opinfo.op_ret = op_ret; } else { + if (rsp.op == GD_OP_REPLACE_BRICK) { + ret = glusterd_rb_use_rsp_dict (dict); + if (ret) + goto out; + } event_type = GD_OP_EVENT_RCVD_ACC; } @@ -580,6 +643,8 @@ glusterd3_1_commit_op_cbk (struct rpc_req *req, struct iovec *iov, out: + if (dict) + dict_unref (dict); return ret; } |