From 931a59e2b9130c6e748f2b7193cd0c2ac5a557bf Mon Sep 17 00:00:00 2001 From: Vijay Bellur Date: Sun, 25 Jul 2010 00:38:01 +0000 Subject: DVM: bug fixes in cli and glusterd for probe, start volume Signed-off-by: Vijay Bellur Signed-off-by: Anand V. Avati BUG: 1187 () URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1187 --- cli/src/cli-mem-types.h | 1 + cli/src/cli.c | 10 + cli/src/cli.h | 43 ++- cli/src/cli3_1-cops.c | 194 +++++++++--- cli/src/input.c | 1 + rpc/rpc-lib/src/protocol-common.h | 4 +- xlators/mgmt/glusterd/src/glusterd-handler.c | 417 ++----------------------- xlators/mgmt/glusterd/src/glusterd-mem-types.h | 1 + xlators/mgmt/glusterd/src/glusterd-op-sm.c | 238 +++++++++++--- xlators/mgmt/glusterd/src/glusterd-op-sm.h | 21 +- xlators/mgmt/glusterd/src/glusterd-sm.c | 3 +- xlators/mgmt/glusterd/src/glusterd-sm.h | 1 + xlators/mgmt/glusterd/src/glusterd-utils.c | 85 ++++- xlators/mgmt/glusterd/src/glusterd-utils.h | 7 +- xlators/mgmt/glusterd/src/glusterd.c | 12 + xlators/mgmt/glusterd/src/glusterd.h | 4 + xlators/mgmt/glusterd/src/glusterd3_1-mops.c | 137 ++++---- 17 files changed, 617 insertions(+), 562 deletions(-) diff --git a/cli/src/cli-mem-types.h b/cli/src/cli-mem-types.h index 279e5e908..b064a9659 100644 --- a/cli/src/cli-mem-types.h +++ b/cli/src/cli-mem-types.h @@ -30,6 +30,7 @@ enum cli_mem_types_ { cli_mt_xlator_cmdline_option_t, cli_mt_char, cli_mt_call_pool_t, + cli_mt_cli_local_t, cli_mt_end }; diff --git a/cli/src/cli.c b/cli/src/cli.c index b31e9feda..d70c67f85 100644 --- a/cli/src/cli.c +++ b/cli/src/cli.c @@ -424,6 +424,16 @@ out: return rpc; } +cli_local_t * +cli_local_get () +{ + cli_local_t *local = NULL; + + local = GF_CALLOC (1, sizeof (*local), cli_mt_cli_local_t); + + return local; +} + struct cli_state *global_state; int diff --git a/cli/src/cli.h b/cli/src/cli.h index 808e92360..140a1af13 100644 --- a/cli/src/cli.h +++ b/cli/src/cli.h @@ -95,6 +95,31 @@ struct cli_state { int remote_port; }; +struct cli_local { + union { + struct { + dict_t *dict; + } create_vol; + + struct { + char *volname; + } start_vol; + + struct { + char *volname; + } stop_vol; + + struct { + char *volname; + } delete_vol; + + struct { + char *volname; + } defrag_vol; + } u; +}; + +typedef struct cli_local cli_local_t; typedef ssize_t (*cli_serialize_t) (struct iovec outmsg, void *args); @@ -115,29 +140,31 @@ int cli_rl_out (struct cli_state *state, const char *fmt, va_list ap); int cli_out (const char *fmt, ...); int -cli_submit_request (void *req, call_frame_t *frame, - rpc_clnt_prog_t *prog, - int procnum, struct iobref *iobref, +cli_submit_request (void *req, call_frame_t *frame, + rpc_clnt_prog_t *prog, + int procnum, struct iobref *iobref, cli_serialize_t sfunc, xlator_t *this, fop_cbk_fn_t cbkfn); int32_t -cli_cmd_volume_create_parse (const char **words, int wordcount, +cli_cmd_volume_create_parse (const char **words, int wordcount, dict_t **options); int32_t -cli_cmd_volume_set_parse (const char **words, int wordcount, +cli_cmd_volume_set_parse (const char **words, int wordcount, dict_t **options); int32_t -cli_cmd_volume_add_brick_parse (const char **words, int wordcount, +cli_cmd_volume_add_brick_parse (const char **words, int wordcount, dict_t **options); int32_t -cli_cmd_volume_remove_brick_parse (const char **words, int wordcount, +cli_cmd_volume_remove_brick_parse (const char **words, int wordcount, dict_t **options); int32_t -cli_cmd_volume_replace_brick_parse (const char **words, int wordcount, +cli_cmd_volume_replace_brick_parse (const char **words, int wordcount, dict_t **options); + +cli_local_t * cli_local_get (); #endif /* __CLI_H__ */ diff --git a/cli/src/cli3_1-cops.c b/cli/src/cli3_1-cops.c index 444c0031d..d76485734 100644 --- a/cli/src/cli3_1-cops.c +++ b/cli/src/cli3_1-cops.c @@ -54,13 +54,13 @@ gf_cli3_1_probe_cbk (struct rpc_req *req, struct iovec *iov, } gf_log ("cli", GF_LOG_NORMAL, "Received resp to probe"); - cli_out ("Probe %s", (rsp.op_ret) ? "Unsuccessful": "Successful"); + cli_out ("Probe %s", (rsp.op_ret) ? "unsuccessful": "successful"); - cli_cmd_broadcast_response (); - ret = 0; + ret = rsp.op_ret; out: + cli_cmd_broadcast_response (); return ret; } @@ -84,13 +84,13 @@ gf_cli3_1_deprobe_cbk (struct rpc_req *req, struct iovec *iov, } gf_log ("cli", GF_LOG_NORMAL, "Received resp to deprobe"); - cli_out ("Detach %s", (rsp.op_ret) ? "Unsuccessful": "Successful"); + cli_out ("Detach %s", (rsp.op_ret) ? "unsuccessful": "successful"); - cli_cmd_broadcast_response (); - ret = 0; + ret = rsp.op_ret; out: + cli_cmd_broadcast_response (); return ret; } @@ -191,6 +191,7 @@ gf_cli3_1_list_friends_cbk (struct rpc_req *req, struct iovec *iov, ret = 0; out: + cli_cmd_broadcast_response (); if (ret) cli_out ("Command Execution Failed"); @@ -313,6 +314,9 @@ gf_cli3_1_create_volume_cbk (struct rpc_req *req, struct iovec *iov, { gf1_cli_create_vol_rsp rsp = {0,}; int ret = 0; + cli_local_t *local = NULL; + char *volname = NULL; + dict_t *dict = NULL; if (-1 == req->rpc_status) { goto out; @@ -324,14 +328,20 @@ gf_cli3_1_create_volume_cbk (struct rpc_req *req, struct iovec *iov, goto out; } + local = ((call_frame_t *) (myframe))->local; + + dict = local->u.create_vol.dict; + + ret = dict_get_str (dict, "volname", &volname); gf_log ("cli", GF_LOG_NORMAL, "Received resp to create volume"); - cli_out ("Create Volume %s", (rsp.op_ret) ? "Unsuccessful": - "Successful"); + cli_out ("Creation of volume %s has been %s", volname, + (rsp.op_ret) ? "unsuccessful": "successful"); - ret = 0; + ret = rsp.op_ret; out: + cli_cmd_broadcast_response (); return ret; } @@ -341,6 +351,9 @@ gf_cli3_1_delete_volume_cbk (struct rpc_req *req, struct iovec *iov, { gf1_cli_delete_vol_rsp rsp = {0,}; int ret = 0; + cli_local_t *local = NULL; + char *volname = NULL; + call_frame_t *frame = NULL; if (-1 == req->rpc_status) { goto out; @@ -352,14 +365,22 @@ gf_cli3_1_delete_volume_cbk (struct rpc_req *req, struct iovec *iov, goto out; } + frame = myframe; + local = frame->local; + + if (local) + volname = local->u.delete_vol.volname; + gf_log ("cli", GF_LOG_NORMAL, "Received resp to delete volume"); - cli_out ("Delete Volume %s", (rsp.op_ret) ? "Unsuccessful": - "Successful"); + cli_out ("Deleting volume %s has been %s", volname, + (rsp.op_ret) ? "unsuccessful": "successful"); - ret = 0; + ret = rsp.op_ret; out: + cli_cmd_broadcast_response (); + gf_log ("", GF_LOG_NORMAL, "Returning with %d", ret); return ret; } @@ -367,8 +388,11 @@ int gf_cli3_1_start_volume_cbk (struct rpc_req *req, struct iovec *iov, int count, void *myframe) { - gf1_cli_start_vol_rsp rsp = {0,}; + gf1_cli_start_vol_rsp rsp = {0,}; int ret = 0; + cli_local_t *local = NULL; + char *volname = NULL; + call_frame_t *frame = NULL; if (-1 == req->rpc_status) { goto out; @@ -380,14 +404,22 @@ gf_cli3_1_start_volume_cbk (struct rpc_req *req, struct iovec *iov, goto out; } + frame = myframe; + + if (frame) + local = frame->local; + + if (local) + volname = local->u.start_vol.volname; gf_log ("cli", GF_LOG_NORMAL, "Received resp to start volume"); - cli_out ("Start Volume %s", (rsp.op_ret) ? "Unsuccessful": - "Successful"); + cli_out ("Starting volume %s has been %s", volname, + (rsp.op_ret) ? "unsuccessful": "successful"); - ret = 0; + ret = rsp.op_ret; out: + cli_cmd_broadcast_response (); return ret; } @@ -397,6 +429,9 @@ gf_cli3_1_stop_volume_cbk (struct rpc_req *req, struct iovec *iov, { gf1_cli_stop_vol_rsp rsp = {0,}; int ret = 0; + cli_local_t *local = NULL; + char *volname = NULL; + call_frame_t *frame = NULL; if (-1 == req->rpc_status) { goto out; @@ -408,14 +443,22 @@ gf_cli3_1_stop_volume_cbk (struct rpc_req *req, struct iovec *iov, goto out; } + frame = myframe; + + if (frame) + local = frame->local; + + if (local) + volname = local->u.start_vol.volname; gf_log ("cli", GF_LOG_NORMAL, "Received resp to stop volume"); - cli_out ("Delete Volume %s", (rsp.op_ret) ? "Unsuccessful": - "Successful"); + cli_out ("Stopping volume %s has been %s", volname, + (rsp.op_ret) ? "unsuccessful": "successful"); - ret = 0; + ret = rsp.op_ret; out: + cli_cmd_broadcast_response (); return ret; } @@ -425,6 +468,9 @@ gf_cli3_1_defrag_volume_cbk (struct rpc_req *req, struct iovec *iov, { gf1_cli_defrag_vol_rsp rsp = {0,}; int ret = 0; + cli_local_t *local = NULL; + char *volname = NULL; + call_frame_t *frame = NULL; if (-1 == req->rpc_status) { goto out; @@ -436,14 +482,22 @@ gf_cli3_1_defrag_volume_cbk (struct rpc_req *req, struct iovec *iov, goto out; } + frame = myframe; + + if (frame) + local = frame->local; + + if (local) + volname = local->u.start_vol.volname; gf_log ("cli", GF_LOG_NORMAL, "Received resp to probe"); - cli_out ("Defrag Volume %s", (rsp.op_ret) ? "Unsuccessful": - "Successful"); + cli_out ("Defrag of volume %s has been %s", volname, + (rsp.op_ret) ? "unsuccessful": "successful"); - ret = 0; + ret = rsp.op_ret; out: + cli_cmd_broadcast_response (); return ret; } @@ -466,10 +520,10 @@ gf_cli3_1_rename_volume_cbk (struct rpc_req *req, struct iovec *iov, gf_log ("cli", GF_LOG_NORMAL, "Received resp to probe"); - cli_out ("Rename Volume %s", (rsp.op_ret) ? "Unsuccessful": - "Successful"); + cli_out ("Rename volume %s", (rsp.op_ret) ? "unsuccessful": + "successful"); - ret = 0; + ret = rsp.op_ret; out: return ret; @@ -494,10 +548,10 @@ gf_cli3_1_set_volume_cbk (struct rpc_req *req, struct iovec *iov, gf_log ("cli", GF_LOG_NORMAL, "Received resp to set"); - cli_out ("Set Volume %s", (rsp.op_ret) ? "Unsuccessful": - "Successful"); + cli_out ("Set volume %s", (rsp.op_ret) ? "unsuccessful": + "successful"); - ret = 0; + ret = rsp.op_ret; out: return ret; @@ -522,12 +576,13 @@ gf_cli3_1_add_brick_cbk (struct rpc_req *req, struct iovec *iov, gf_log ("cli", GF_LOG_NORMAL, "Received resp to add brick"); - cli_out ("Add Brick %s", (rsp.op_ret) ? "Unsuccessful": - "Successful"); + cli_out ("Add Brick %s", (rsp.op_ret) ? "unsuccessful": + "successful"); - ret = 0; + ret = rsp.op_ret; out: + cli_cmd_broadcast_response (); return ret; } @@ -550,10 +605,10 @@ gf_cli3_1_remove_brick_cbk (struct rpc_req *req, struct iovec *iov, } gf_log ("cli", GF_LOG_NORMAL, "Received resp to remove brick"); - cli_out ("Remove Brick %s", (rsp.op_ret) ? "Unsuccessful": - "Successful"); + cli_out ("Remove Brick %s", (rsp.op_ret) ? "unsuccessful": + "successful"); - ret = 0; + ret = rsp.op_ret; out: return ret; @@ -579,10 +634,10 @@ gf_cli3_1_replace_brick_cbk (struct rpc_req *req, struct iovec *iov, gf_log ("cli", GF_LOG_NORMAL, "Received resp to replace brick"); - cli_out ("Replace Brick %s", (rsp.op_ret) ? "Unsuccessful": - "Successful"); + cli_out ("Replace Brick %s", (rsp.op_ret) ? "unsuccessful": + "successful"); - ret = 0; + ret = rsp.op_ret; out: return ret; @@ -620,7 +675,7 @@ gf_cli3_1_probe (call_frame_t *frame, xlator_t *this, this, gf_cli3_1_probe_cbk); if (!ret) { - //ret = cli_cmd_await_response (); + ret = cli_cmd_await_response (); } out: gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); @@ -660,7 +715,7 @@ gf_cli3_1_deprobe (call_frame_t *frame, xlator_t *this, this, gf_cli3_1_deprobe_cbk); if (!ret) { - //ret = cli_cmd_await_response (); + ret = cli_cmd_await_response (); } out: gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); @@ -687,7 +742,7 @@ gf_cli3_1_list_friends (call_frame_t *frame, xlator_t *this, this, gf_cli3_1_list_friends_cbk); if (!ret) { - //ret = cli_cmd_await_response (); + ret = cli_cmd_await_response (); } out: gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); @@ -728,13 +783,14 @@ gf_cli3_1_create_volume (call_frame_t *frame, xlator_t *this, gf1_cli_create_vol_req req = {0,}; int ret = 0; dict_t *dict = NULL; + cli_local_t *local = NULL; if (!frame || !this || !data) { ret = -1; goto out; } - dict = data; + dict = dict_ref ((dict_t *)data); ret = dict_get_str (dict, "volname", &req.volname); @@ -759,13 +815,20 @@ gf_cli3_1_create_volume (call_frame_t *frame, xlator_t *this, goto out; } + local = cli_local_get (); + + if (local) { + local->u.create_vol.dict = dict; + frame->local = local; + } + ret = cli_submit_request (&req, frame, cli_rpc_prog, GD_MGMT_CLI_CREATE_VOLUME, NULL, gf_xdr_from_cli_create_vol_req, this, gf_cli3_1_create_volume_cbk); if (!ret) { - //ret = cli_cmd_await_response (); + ret = cli_cmd_await_response (); } @@ -785,18 +848,29 @@ gf_cli3_1_delete_volume (call_frame_t *frame, xlator_t *this, { gf1_cli_delete_vol_req req = {0,}; int ret = 0; + cli_local_t *local = NULL; if (!frame || !this || !data) { ret = -1; goto out; } + local = cli_local_get (); + + if (local) { + local->u.delete_vol.volname = data; + frame->local = local; + } + req.volname = data; ret = cli_submit_request (&req, frame, cli_rpc_prog, GD_MGMT_CLI_DELETE_VOLUME, NULL, gf_xdr_from_cli_delete_vol_req, this, gf_cli3_1_delete_volume_cbk); + if (!ret) { + ret = cli_cmd_await_response (); + } out: gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); @@ -810,12 +884,20 @@ gf_cli3_1_start_volume (call_frame_t *frame, xlator_t *this, { gf1_cli_start_vol_req req = {0,}; int ret = 0; + cli_local_t *local = NULL; if (!frame || !this || !data) { ret = -1; goto out; } + local = cli_local_get (); + + if (local) { + local->u.start_vol.volname = data; + frame->local = local; + } + req.volname = data; ret = cli_submit_request (&req, frame, cli_rpc_prog, @@ -823,6 +905,9 @@ gf_cli3_1_start_volume (call_frame_t *frame, xlator_t *this, gf_xdr_from_cli_start_vol_req, this, gf_cli3_1_start_volume_cbk); + if (!ret) { + ret = cli_cmd_await_response (); + } out: gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); @@ -835,6 +920,7 @@ gf_cli3_1_stop_volume (call_frame_t *frame, xlator_t *this, { gf1_cli_stop_vol_req req = {0,}; int ret = 0; + cli_local_t *local = NULL; if (!frame || !this || !data) { ret = -1; @@ -843,11 +929,21 @@ gf_cli3_1_stop_volume (call_frame_t *frame, xlator_t *this, req.volname = data; + local = cli_local_get (); + + if (local) { + local->u.stop_vol.volname = data; + frame->local = local; + } + ret = cli_submit_request (&req, frame, cli_rpc_prog, GD_MGMT_CLI_STOP_VOLUME, NULL, gf_xdr_from_cli_stop_vol_req, this, gf_cli3_1_stop_volume_cbk); + if (!ret) { + ret = cli_cmd_await_response (); + } out: gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); @@ -860,12 +956,20 @@ gf_cli3_1_defrag_volume (call_frame_t *frame, xlator_t *this, { gf1_cli_defrag_vol_req req = {0,}; int ret = 0; + cli_local_t *local = NULL; if (!frame || !this || !data) { ret = -1; goto out; } + local = cli_local_get (); + + if (local) { + local->u.defrag_vol.volname = data; + frame->local = local; + } + req.volname = data; ret = cli_submit_request (&req, frame, cli_rpc_prog, @@ -873,6 +977,9 @@ gf_cli3_1_defrag_volume (call_frame_t *frame, xlator_t *this, gf_xdr_from_cli_defrag_vol_req, this, gf_cli3_1_defrag_volume_cbk); + if (!ret) { + ret = cli_cmd_await_response (); + } out: gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); @@ -995,6 +1102,9 @@ gf_cli3_1_add_brick (call_frame_t *frame, xlator_t *this, gf_xdr_from_cli_add_brick_req, this, gf_cli3_1_add_brick_cbk); + if (!ret) { + ret = cli_cmd_await_response (); + } out: gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); diff --git a/cli/src/input.c b/cli/src/input.c index 314058e05..a577a0f4c 100644 --- a/cli/src/input.c +++ b/cli/src/input.c @@ -42,6 +42,7 @@ cli_batch (void *d) state = d; ret = cli_cmd_process (state, state->argc, state->argv); + gf_log ("", GF_LOG_NORMAL, "Exiting with: %d", ret); exit (ret); return NULL; diff --git a/rpc/rpc-lib/src/protocol-common.h b/rpc/rpc-lib/src/protocol-common.h index 5b6a2c349..7cff79be3 100644 --- a/rpc/rpc-lib/src/protocol-common.h +++ b/rpc/rpc-lib/src/protocol-common.h @@ -75,7 +75,7 @@ enum gf_handshake_procnum { GF_HNDSK_MAXVALUE, }; -enum gf_mgmt_procnum { +enum gf_mgmt_procnum_ { GD_MGMT_NULL, /* 0 */ GD_MGMT_PROBE_QUERY, GD_MGMT_FRIEND_ADD, @@ -102,6 +102,8 @@ enum gf_mgmt_procnum { GD_MGMT_MAXVALUE, }; +typedef enum gf_mgmt_procnum_ gf_mgmt_procnum; + enum gf_cli_procnum { GF1_CLI_NULL = GD_MGMT_MAXVALUE+1, /* 0 */ GF1_CLI_PROBE, diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c index d3e70321f..c1ab57119 100644 --- a/xlators/mgmt/glusterd/src/glusterd-handler.c +++ b/xlators/mgmt/glusterd/src/glusterd-handler.c @@ -367,7 +367,6 @@ glusterd_handle_cluster_lock (rpcsvc_request_t *req) gd1_mgmt_cluster_lock_req lock_req = {{0},}; int32_t ret = -1; char str[50] = {0,}; - glusterd_op_sm_event_t *event = NULL; glusterd_op_lock_ctx_t *ctx = NULL; GF_ASSERT (req); @@ -382,12 +381,6 @@ glusterd_handle_cluster_lock (rpcsvc_request_t *req) gf_log ("glusterd", GF_LOG_NORMAL, "Received LOCK from uuid: %s", str); - ret = glusterd_op_sm_new_event (GD_OP_EVENT_LOCK, &event); - - if (ret) { - //respond back here - return ret; - } ctx = GF_CALLOC (1, sizeof (*ctx), gf_gld_mt_op_stage_ctx_t); @@ -398,9 +391,8 @@ glusterd_handle_cluster_lock (rpcsvc_request_t *req) uuid_copy (ctx->uuid, lock_req.uuid); ctx->req = req; - event->ctx = ctx; - ret = glusterd_op_sm_inject_event (event); + ret = glusterd_op_sm_inject_event (GD_OP_EVENT_LOCK, ctx); out: gf_log ("", GF_LOG_NORMAL, "Returning %d", ret); @@ -412,9 +404,8 @@ int glusterd_handle_stage_op (rpcsvc_request_t *req) { int32_t ret = -1; - char str[50]; + char str[50] = {0,}; gd1_mgmt_stage_op_req stage_req = {{0,}}; - glusterd_op_sm_event_t *event = NULL; glusterd_op_stage_ctx_t *ctx = NULL; GF_ASSERT (req); @@ -429,13 +420,6 @@ glusterd_handle_stage_op (rpcsvc_request_t *req) gf_log ("glusterd", GF_LOG_NORMAL, "Received stage op from uuid: %s", str); - ret = glusterd_op_sm_new_event (GD_OP_EVENT_STAGE_OP, &event); - - if (ret) { - //respond back here - return ret; - } - ctx = GF_CALLOC (1, sizeof (*ctx), gf_gld_mt_op_stage_ctx_t); if (!ctx) { @@ -455,11 +439,9 @@ glusterd_handle_stage_op (rpcsvc_request_t *req) memcpy (ctx->stage_req.buf.buf_val, stage_req.buf.buf_val, stage_req.buf.buf_len); - ctx->req = req; - event->ctx = ctx; - ret = glusterd_op_sm_inject_event (event); + ret = glusterd_op_sm_inject_event (GD_OP_EVENT_STAGE_OP, ctx); out: return ret; @@ -469,8 +451,7 @@ int glusterd_handle_commit_op (rpcsvc_request_t *req) { int32_t ret = -1; - char str[50]; - glusterd_op_sm_event_t *event = NULL; + char str[50] = {0,}; gd1_mgmt_commit_op_req commit_req = {{0},}; glusterd_op_commit_ctx_t *ctx = NULL; @@ -487,13 +468,6 @@ glusterd_handle_commit_op (rpcsvc_request_t *req) gf_log ("glusterd", GF_LOG_NORMAL, "Received commit op from uuid: %s", str); - ret = glusterd_op_sm_new_event (GD_OP_EVENT_COMMIT_OP, &event); - - if (ret) { - //respond back here - return ret; - } - ctx = GF_CALLOC (1, sizeof (*ctx), gf_gld_mt_op_commit_ctx_t); if (!ctx) { @@ -513,9 +487,8 @@ glusterd_handle_commit_op (rpcsvc_request_t *req) memcpy (ctx->stage_req.buf.buf_val, commit_req.buf.buf_val, commit_req.buf.buf_len); - event->ctx = ctx; - ret = glusterd_op_sm_inject_event (event); + ret = glusterd_op_sm_inject_event (GD_OP_EVENT_COMMIT_OP, ctx); out: return ret; @@ -889,7 +862,6 @@ glusterd_handle_cluster_unlock (rpcsvc_request_t *req) int32_t ret = -1; char str[50] = {0, }; glusterd_op_lock_ctx_t *ctx = NULL; - glusterd_op_sm_event_t *event = NULL; GF_ASSERT (req); @@ -904,24 +876,16 @@ glusterd_handle_cluster_unlock (rpcsvc_request_t *req) gf_log ("glusterd", GF_LOG_NORMAL, "Received UNLOCK from uuid: %s", str); - ret = glusterd_op_sm_new_event (GD_OP_EVENT_UNLOCK, &event); - - if (ret) { - //respond back here - return ret; - } - ctx = GF_CALLOC (1, sizeof (*ctx), gf_gld_mt_op_lock_ctx_t); if (!ctx) { //respond here return -1; } - event->ctx = ctx; uuid_copy (ctx->uuid, unlock_req.uuid); ctx->req = req; - ret = glusterd_op_sm_inject_event (event); + ret = glusterd_op_sm_inject_event (GD_OP_EVENT_UNLOCK, ctx); out: return ret; @@ -1171,332 +1135,6 @@ out: return ret; } -/*int -glusterd_handle_friend_req_resp (call_frame_t *frame, - gf_hdr_common_t *rsp_hdr, size_t hdrlen) -{ - gf_mop_probe_rsp_t *rsp = NULL; - int32_t ret = -1; - char str[50]; - glusterd_peerinfo_t *peerinfo = NULL; - int32_t op_ret = -1; - glusterd_friend_sm_event_type_t event_type = GD_FRIEND_EVENT_NONE; - glusterd_friend_sm_event_t *event = NULL; - - GF_ASSERT (rsp_hdr); - - rsp = gf_param (rsp_hdr); - uuid_unparse (rsp->uuid, str); - - op_ret = rsp_hdr->rsp.op_ret; - - gf_log ("glusterd", GF_LOG_NORMAL, - "Received %s from uuid: %s, host: %s", - (op_ret)?"RJT":"ACC", str, rsp->hostname); - - ret = glusterd_friend_find (rsp->uuid, rsp->hostname, &peerinfo); - - if (ret) { - GF_ASSERT (0); - } - - if (op_ret) - event_type = GD_FRIEND_EVENT_RCVD_ACC; - else - event_type = GD_FRIEND_EVENT_RCVD_RJT; - - ret = glusterd_friend_sm_new_event (event_type, &event); - - if (ret) { - gf_log ("glusterd", GF_LOG_ERROR, - "Unable to get event"); - return ret; - } - - event->peerinfo = peerinfo; - ret = glusterd_friend_sm_inject_event (event); - - gf_log ("glusterd", GF_LOG_NORMAL, "Received resp to friend req"); - - return 0; -}*/ - -/*int -glusterd_handle_probe_resp (call_frame_t *frame, gf_hdr_common_t *rsp_hdr, - size_t hdrlen) -{ - gf_mop_probe_rsp_t *rsp = NULL; - int32_t ret = -1; - char str[50]; - glusterd_peerinfo_t *peerinfo = NULL; - glusterd_friend_sm_event_t *event = NULL; - glusterd_peerinfo_t *dup_peerinfo = NULL; - - GF_ASSERT (rsp_hdr); - - rsp = gf_param (rsp_hdr); - uuid_unparse (rsp->uuid, str); - - gf_log ("glusterd", GF_LOG_NORMAL, - "Received probe resp from uuid: %s, host: %s", - str, rsp->hostname); - - ret = glusterd_friend_find (rsp->uuid, rsp->hostname, &peerinfo); - - if (ret) { - GF_ASSERT (0); - } - - if (!peerinfo->hostname) { - glusterd_friend_find_by_hostname (rsp->hostname, &dup_peerinfo); - GF_ASSERT (dup_peerinfo); - GF_ASSERT (dup_peerinfo->hostname); - peerinfo->hostname = gf_strdup (rsp->hostname); - peerinfo->trans = dup_peerinfo->trans; - list_del_init (&dup_peerinfo->uuid_list); - GF_FREE (dup_peerinfo->hostname); - GF_FREE (dup_peerinfo); - } - GF_ASSERT (peerinfo->hostname); - uuid_copy (peerinfo->uuid, rsp->uuid); - - ret = glusterd_friend_sm_new_event - (GD_FRIEND_EVENT_INIT_FRIEND_REQ, &event); - - if (ret) { - gf_log ("glusterd", GF_LOG_ERROR, - "Unable to get event"); - return ret; - } - - event->peerinfo = peerinfo; - ret = glusterd_friend_sm_inject_event (event); - - return 0; -}*/ - -/* -static glusterd_mop_t glusterd_ops[GF_MOP_MAXVALUE] = { - [GF_MOP_PROBE_QUERY] = glusterd_handle_probe_query, - [GF_MOP_FRIEND_REQ] = glusterd_handle_incoming_friend_req, - [GF_MOP_STAGE_OP] = glusterd_handle_stage_op, - [GF_MOP_COMMIT_OP] = glusterd_handle_commit_op, - [GF_MOP_CLUSTER_LOCK] = glusterd_handle_cluster_lock, - [GF_MOP_CLUSTER_UNLOCK] = glusterd_handle_cluster_unlock, -}; - -static glusterd_mop_t glusterd_resp_ops [GF_MOP_MAXVALUE] = { - [GF_MOP_PROBE_QUERY] = glusterd_handle_probe_resp, - [GF_MOP_FRIEND_REQ] = glusterd_handle_friend_req_resp, -}; -*/ - -/*int -glusterd_xfer_probe_msg (glusterd_peerinfo_t *peerinfo, xlator_t *this) -{ - gf_hdr_common_t *hdr = NULL; - gf_mop_probe_req_t *req = NULL; - size_t hdrlen = -1; - int ret = -1; - glusterd_conf_t *priv = NULL; - call_frame_t *dummy_frame = NULL; - int len = 0; - - GF_ASSERT (peerinfo); - GF_ASSERT (this); - - priv = this->private; - GF_ASSERT (priv); - - len = STRLEN_0 (peerinfo->hostname); - hdrlen = gf_hdr_len (req, len); - hdr = gf_hdr_new (req, len); - - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - memcpy (&req->uuid, &priv->uuid, sizeof(uuid_t)); - strncpy (req->hostname, peerinfo->hostname, len); - - dummy_frame = create_frame (this, this->ctx->pool); - - if (!dummy_frame) - goto unwind; - - dummy_frame->local = peerinfo->trans; - - ret = glusterd_xfer (dummy_frame, this, - peerinfo->trans, - GF_OP_TYPE_MOP_REQUEST, GF_MOP_PROBE_QUERY, - hdr, hdrlen, NULL, 0, NULL); - - return ret; - -unwind: - if (hdr) - GF_FREE (hdr); - - return 0; -}*/ - -/*int -glusterd_xfer_friend_req_msg (glusterd_peerinfo_t *peerinfo, xlator_t *this) -{ - gf_hdr_common_t *hdr = NULL; - gf_mop_probe_req_t *req = NULL; - size_t hdrlen = -1; - int ret = -1; - glusterd_conf_t *priv = NULL; - call_frame_t *dummy_frame = NULL; - int len = 0; - - GF_ASSERT (peerinfo); - GF_ASSERT (this); - - priv = this->private; - GF_ASSERT (priv); - - len = STRLEN_0 (peerinfo->hostname); - hdrlen = gf_hdr_len (req, len); - hdr = gf_hdr_new (req, len); - - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - memcpy (&req->uuid, &priv->uuid, sizeof(uuid_t)); - strncpy (req->hostname, peerinfo->hostname, len); - - dummy_frame = create_frame (this, this->ctx->pool); - - if (!dummy_frame) - goto unwind; - - dummy_frame->local = peerinfo->trans; - - ret = glusterd_xfer (dummy_frame, this, - peerinfo->trans, - GF_OP_TYPE_MOP_REQUEST, GF_MOP_FRIEND_REQ, - hdr, hdrlen, NULL, 0, NULL); - - return ret; - -unwind: - if (hdr) - GF_FREE (hdr); - - //STACK_UNWIND (frame, -1, EINVAL, NULL); - return 0; -}*/ - -/*int -glusterd_xfer_cluster_lock_req (xlator_t *this, int32_t *lock_count) -{ - gd1_mgmt_cluster_lock_req req = {{0},}; - int ret = -1; - glusterd_conf_t *priv = NULL; - call_frame_t *dummy_frame = NULL; - glusterd_peerinfo_t *peerinfo = NULL; - int pending_lock = 0; - rpc_clnt_procedure_t *proc = NULL; - - GF_ASSERT (this); - GF_ASSERT (lock_count); - - priv = this->private; - GF_ASSERT (priv); - - uuid_copy (req.uuid, priv->uuid); - - dummy_frame = create_frame (this, this->ctx->pool); - - if (!dummy_frame) - goto unwind; - - - list_for_each_entry (peerinfo, &priv->peers, uuid_list) { - GF_ASSERT (peerinfo); - - if (peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED) - continue; - - - ret = glusterd_submit_request (peerinfo, &req, dummy_frame, - prog, GD_MGMT_PROBE_QUERY, - NULL, gd_xdr_from_mgmt_probe_req, - this); - if (!ret) - pending_lock++; - } - - gf_log ("glusterd", GF_LOG_NORMAL, "Sent lock req to %d peers", - pending_lock); - *lock_count = pending_lock; - -unwind: - - return ret; -}*/ - -/*int -glusterd_xfer_cluster_unlock_req (xlator_t *this, int32_t *pending_count) -{ - gf_hdr_common_t *hdr = NULL; - gf_mop_cluster_unlock_req_t *req = NULL; - size_t hdrlen = -1; - int ret = -1; - glusterd_conf_t *priv = NULL; - call_frame_t *dummy_frame = NULL; - glusterd_peerinfo_t *peerinfo = NULL; - int pending_unlock = 0; - - GF_ASSERT (this); - GF_ASSERT (pending_count); - - priv = this->private; - GF_ASSERT (priv); - - hdrlen = gf_hdr_len (req, 0); - hdr = gf_hdr_new (req, 0); - - GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - - req = gf_param (hdr); - uuid_copy (req->uuid, priv->uuid); - - dummy_frame = create_frame (this, this->ctx->pool); - - if (!dummy_frame) - goto unwind; - - - list_for_each_entry (peerinfo, &priv->peers, uuid_list) { - GF_ASSERT (peerinfo); - - if (peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED) - continue; - - - ret = glusterd_xfer (dummy_frame, this, - peerinfo->trans, - GF_OP_TYPE_MOP_REQUEST, - GF_MOP_CLUSTER_UNLOCK, - hdr, hdrlen, NULL, 0, NULL); - if (!ret) - pending_unlock++; - } - - gf_log ("glusterd", GF_LOG_NORMAL, "Sent unlock req to %d peers", - pending_unlock); - *pending_count = pending_unlock; - -unwind: - if (hdr) - GF_FREE (hdr); - - return ret; -}*/ - - int glusterd_friend_add (const char *hoststr, int port, glusterd_friend_sm_state_t state, @@ -1638,6 +1276,11 @@ glusterd_probe_begin (rpcsvc_request_t *req, const char *hoststr, int port) return ret; } + if (!peerinfo->connected) { + return GLUSTERD_CONNECTION_AWAITED; + } + + return ret; } @@ -1781,7 +1424,6 @@ glusterd_op_txn_begin () { int32_t ret = -1; glusterd_conf_t *priv = NULL; - glusterd_op_sm_event_t *event = NULL; int32_t locked = 0; priv = THIS->private; @@ -1798,15 +1440,7 @@ glusterd_op_txn_begin () locked = 1; gf_log ("glusterd", GF_LOG_NORMAL, "Acquired local lock"); - ret = glusterd_op_sm_new_event (GD_OP_EVENT_START_LOCK, &event); - - if (ret) { - gf_log ("glusterd", GF_LOG_ERROR, - "Unable to get event, ret: %d", ret); - goto out; - } - - ret = glusterd_op_sm_inject_event (event); + ret = glusterd_op_sm_inject_event (GD_OP_EVENT_START_LOCK, NULL); gf_log ("glusterd", GF_LOG_NORMAL, "Returning %d", ret); @@ -1829,6 +1463,8 @@ glusterd_create_volume (rpcsvc_request_t *req, dict_t *dict) glusterd_op_set_ctx (GD_OP_CREATE_VOLUME, dict); + glusterd_op_set_req (req); + data = dict_get (dict, "volname"); if (!data) goto out; @@ -1870,6 +1506,7 @@ glusterd_start_volume (rpcsvc_request_t *req, char *volname, int flags) glusterd_op_set_op (GD_OP_START_VOLUME); glusterd_op_set_ctx (GD_OP_START_VOLUME, ctx); + glusterd_op_set_req (req); ret = glusterd_op_txn_begin (); @@ -1896,6 +1533,7 @@ glusterd_stop_volume (rpcsvc_request_t *req, char *volname, int flags) glusterd_op_set_op (GD_OP_STOP_VOLUME); glusterd_op_set_ctx (GD_OP_STOP_VOLUME, ctx); + glusterd_op_set_req (req); ret = glusterd_op_txn_begin (); @@ -1922,6 +1560,7 @@ glusterd_delete_volume (rpcsvc_request_t *req, char *volname, int flags) glusterd_op_set_op (GD_OP_DELETE_VOLUME); glusterd_op_set_ctx (GD_OP_DELETE_VOLUME, ctx); + glusterd_op_set_req (req); ret = glusterd_op_txn_begin (); @@ -1940,6 +1579,7 @@ glusterd_add_brick (rpcsvc_request_t *req, dict_t *dict) glusterd_op_set_op (GD_OP_ADD_BRICK); glusterd_op_set_ctx (GD_OP_ADD_BRICK, dict); + glusterd_op_set_req (req); ret = glusterd_op_txn_begin (); @@ -2074,26 +1714,28 @@ int glusterd_rpc_notify (struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event, void *data) { - xlator_t *this = NULL; - char *handshake = NULL; - glusterd_conf_t *conf = NULL; - int ret = 0; + xlator_t *this = NULL; + char *handshake = "on"; + glusterd_conf_t *conf = NULL; + int ret = 0; + glusterd_peerinfo_t *peerinfo = NULL; - this = mydata; + peerinfo = mydata; + this = THIS; conf = this->private; switch (event) { case RPC_CLNT_CONNECT: { - // connect happened, send 'get_supported_versions' mop - ret = dict_get_str (this->options, "disable-handshake", - &handshake); gf_log (this->name, GF_LOG_TRACE, "got RPC_CLNT_CONNECT"); + peerinfo->connected = 1; + glusterd_friend_sm (); + glusterd_op_sm (); if ((ret < 0) || (strcasecmp (handshake, "on"))) { - //ret = client_handshake (this, conf->rpc); + //ret = glusterd_handshake (this, peerinfo->rpc); } else { //conf->rpc->connected = 1; @@ -2107,6 +1749,7 @@ glusterd_rpc_notify (struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event, //Inject friend disconnected here gf_log (this->name, GF_LOG_TRACE, "got RPC_CLNT_DISCONNECT"); + peerinfo->connected = 0; //default_notify (this, GF_EVENT_CHILD_DOWN, NULL); break; diff --git a/xlators/mgmt/glusterd/src/glusterd-mem-types.h b/xlators/mgmt/glusterd/src/glusterd-mem-types.h index 4d3655be2..2cbdf22ab 100644 --- a/xlators/mgmt/glusterd/src/glusterd-mem-types.h +++ b/xlators/mgmt/glusterd/src/glusterd-mem-types.h @@ -51,6 +51,7 @@ enum gf_gld_mem_types_ { gf_gld_mt_glusterd_volinfo_t, gf_gld_mt_glusterd_brickinfo_t, gf_gld_mt_peer_hostname_t, + gf_gld_mt_ifreq, gf_gld_mt_end }; #endif diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c index 7418f63e4..3010f6646 100644 --- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c +++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c @@ -103,16 +103,9 @@ glusterd_op_get_len (glusterd_op_t op) static int glusterd_op_sm_inject_all_acc () { - glusterd_op_sm_event_t *event = NULL; int32_t ret = -1; - - ret = glusterd_op_sm_new_event (GD_OP_EVENT_ALL_ACC, &event); - - if (ret) - goto out; - - ret = glusterd_op_sm_inject_event (event); -out: + ret = glusterd_op_sm_inject_event (GD_OP_EVENT_ALL_ACC, NULL); + gf_log ("", GF_LOG_DEBUG, "Returning %d", ret); return ret; } @@ -660,6 +653,7 @@ glusterd_op_add_brick (gd1_mgmt_stage_op_req *req) char *brick_list = NULL; char *saveptr = NULL; gf_boolean_t glfs_started = _gf_false; + int32_t mybrick = 0; GF_ASSERT (req); @@ -733,13 +727,14 @@ glusterd_op_add_brick (gd1_mgmt_stage_op_req *req) " for brick %s:%s", brickinfo->hostname, brickinfo->path); ret = glusterd_volume_start_glusterfs - (volinfo, brickinfo); + (volinfo, brickinfo, mybrick); if (ret) { gf_log ("", GF_LOG_ERROR, "Unable to start " "glusterfs, ret: %d", ret); goto out; } glfs_started = _gf_true; + mybrick++; } brick = strtok_r (NULL, " \n", &saveptr); @@ -809,6 +804,7 @@ glusterd_op_start_volume (gd1_mgmt_stage_op_req *req) glusterd_volinfo_t *volinfo = NULL; glusterd_brickinfo_t *brickinfo = NULL; xlator_t *this = NULL; + int32_t mybrick = 0; GF_ASSERT (req); @@ -830,12 +826,13 @@ glusterd_op_start_volume (gd1_mgmt_stage_op_req *req) " for brick %s:%s", brickinfo->hostname, brickinfo->path); ret = glusterd_volume_start_glusterfs - (volinfo, brickinfo); + (volinfo, brickinfo, mybrick); if (ret) { gf_log ("", GF_LOG_ERROR, "Unable to start " "glusterfs, ret: %d", ret); goto out; } + mybrick++; } } @@ -938,10 +935,11 @@ glusterd_op_ac_send_unlock (glusterd_op_sm_event_t *event, void *ctx) this = THIS; priv = this->private; - ret = glusterd_unlock (priv->uuid); + /*ret = glusterd_unlock (priv->uuid); if (ret) goto out; + */ proc = &priv->mgmt->proctable[GD_MGMT_CLUSTER_UNLOCK]; if (proc->fn) { @@ -1010,7 +1008,6 @@ static int glusterd_op_ac_rcvd_lock_acc (glusterd_op_sm_event_t *event, void *ctx) { int ret = 0; - glusterd_op_sm_event_t *new_event = NULL; GF_ASSERT (event); @@ -1019,12 +1016,7 @@ glusterd_op_ac_rcvd_lock_acc (glusterd_op_sm_event_t *event, void *ctx) if (opinfo.pending_count) goto out; - ret = glusterd_op_sm_new_event (GD_OP_EVENT_ALL_ACC, &new_event); - - if (ret) - goto out; - - ret = glusterd_op_sm_inject_event (new_event); + ret = glusterd_op_sm_inject_event (GD_OP_EVENT_ALL_ACC, NULL); gf_log ("", GF_LOG_DEBUG, "Returning %d", ret); @@ -1100,7 +1092,6 @@ static int glusterd_op_ac_rcvd_stage_op_acc (glusterd_op_sm_event_t *event, void *ctx) { int ret = 0; - glusterd_op_sm_event_t *new_event = NULL; GF_ASSERT (event); @@ -1109,12 +1100,7 @@ glusterd_op_ac_rcvd_stage_op_acc (glusterd_op_sm_event_t *event, void *ctx) if (opinfo.pending_count) goto out; - ret = glusterd_op_sm_new_event (GD_OP_EVENT_STAGE_ACC, &new_event); - - if (ret) - goto out; - - ret = glusterd_op_sm_inject_event (new_event); + ret = glusterd_op_sm_inject_event (GD_OP_EVENT_STAGE_ACC, NULL); out: gf_log ("", GF_LOG_DEBUG, "Returning %d", ret); @@ -1126,7 +1112,6 @@ static int glusterd_op_ac_rcvd_commit_op_acc (glusterd_op_sm_event_t *event, void *ctx) { int ret = 0; - glusterd_op_sm_event_t *new_event = NULL; GF_ASSERT (event); @@ -1135,12 +1120,7 @@ glusterd_op_ac_rcvd_commit_op_acc (glusterd_op_sm_event_t *event, void *ctx) if (opinfo.pending_count) goto out; - ret = glusterd_op_sm_new_event (GD_OP_EVENT_COMMIT_ACC, &new_event); - - if (ret) - goto out; - - ret = glusterd_op_sm_inject_event (new_event); + ret = glusterd_op_sm_inject_event (GD_OP_EVENT_COMMIT_ACC, NULL); gf_log ("", GF_LOG_DEBUG, "Returning %d", ret); @@ -1152,7 +1132,6 @@ static int glusterd_op_ac_rcvd_unlock_acc (glusterd_op_sm_event_t *event, void *ctx) { int ret = 0; - glusterd_op_sm_event_t *new_event = NULL; GF_ASSERT (event); @@ -1161,19 +1140,150 @@ glusterd_op_ac_rcvd_unlock_acc (glusterd_op_sm_event_t *event, void *ctx) if (opinfo.pending_count) goto out; - ret = glusterd_op_sm_new_event (GD_OP_EVENT_ALL_ACC, &new_event); + ret = glusterd_op_sm_inject_event (GD_OP_EVENT_ALL_ACC, NULL); + + gf_log ("", GF_LOG_DEBUG, "Returning %d", ret); + +out: + return ret; +} + + +int32_t +glusterd_op_send_cli_response (int32_t op, int32_t op_ret, + int32_t op_errno, rpcsvc_request_t *req) +{ + int32_t ret = -1; + gd_serialize_t sfunc = NULL; + void *cli_rsp = NULL; + + switch (op) { + case GD_MGMT_CLI_CREATE_VOLUME: + { + gf1_cli_create_vol_rsp rsp = {0,}; + rsp.op_ret = op_ret; + rsp.op_errno = op_errno; + rsp.volname = ""; + cli_rsp = &rsp; + sfunc = gf_xdr_serialize_cli_create_vol_rsp; + break; + } + + case GD_MGMT_CLI_START_VOLUME: + { + gf1_cli_start_vol_rsp rsp = {0,}; + rsp.op_ret = op_ret; + rsp.op_errno = op_errno; + rsp.volname = ""; + cli_rsp = &rsp; + sfunc = gf_xdr_serialize_cli_start_vol_rsp; + break; + } + + case GD_MGMT_CLI_STOP_VOLUME: + { + gf1_cli_stop_vol_rsp rsp = {0,}; + rsp.op_ret = op_ret; + rsp.op_errno = op_errno; + rsp.volname = ""; + cli_rsp = &rsp; + sfunc = gf_xdr_serialize_cli_stop_vol_rsp; + break; + } + + case GD_MGMT_CLI_DELETE_VOLUME: + { + gf1_cli_delete_vol_rsp rsp = {0,}; + rsp.op_ret = op_ret; + rsp.op_errno = op_errno; + rsp.volname = ""; + cli_rsp = &rsp; + sfunc = gf_xdr_serialize_cli_delete_vol_rsp; + break; + } + + case GD_MGMT_CLI_DEFRAG_VOLUME: + { + gf1_cli_defrag_vol_rsp rsp = {0,}; + rsp.op_ret = op_ret; + rsp.op_errno = op_errno; + //rsp.volname = ""; + cli_rsp = &rsp; + sfunc = gf_xdr_serialize_cli_defrag_vol_rsp; + break; + } + + case GD_MGMT_CLI_ADD_BRICK: + { + gf1_cli_add_brick_rsp rsp = {0,}; + rsp.op_ret = op_ret; + rsp.op_errno = op_errno; + rsp.volname = ""; + cli_rsp = &rsp; + sfunc = gf_xdr_serialize_cli_add_brick_rsp; + break; + } + } + + + ret = glusterd_submit_reply (req, cli_rsp, NULL, 0, NULL, + sfunc); if (ret) goto out; - ret = glusterd_op_sm_inject_event (new_event); +out: + pthread_mutex_unlock (&opinfo.lock); + gf_log ("", GF_LOG_NORMAL, "Returning %d", ret); + return ret; +} - gf_log ("", GF_LOG_DEBUG, "Returning %d", ret); +int32_t +glusterd_op_txn_complete () +{ + int32_t ret = -1; + glusterd_conf_t *priv = NULL; + + priv = THIS->private; + GF_ASSERT (priv); + + ret = glusterd_unlock (priv->uuid); + + if (ret) { + gf_log ("glusterd", GF_LOG_CRITICAL, + "Unable to clear local lock, ret: %d", ret); + goto out; + } + + gf_log ("glusterd", GF_LOG_NORMAL, "Cleared local lock"); + + ret = glusterd_op_send_cli_response (opinfo.cli_op, opinfo.op_ret, + opinfo.op_errno, opinfo.req); + + opinfo.op_ret = 0; + opinfo.op_errno = 0; out: + pthread_mutex_unlock (&opinfo.lock); + gf_log ("glusterd", GF_LOG_NORMAL, "Returning %d", ret); + return ret; +} + +static int +glusterd_op_ac_unlocked_all (glusterd_op_sm_event_t *event, void *ctx) +{ + int ret = 0; + + GF_ASSERT (event); + + ret = glusterd_op_txn_complete (); + + gf_log ("", GF_LOG_DEBUG, "Returning %d", ret); + return ret; } + static int glusterd_op_ac_commit_error (glusterd_op_sm_event_t *event, void *ctx) { @@ -1441,7 +1551,7 @@ glusterd_op_sm_t glusterd_op_state_unlock_sent [] = { {GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_none},//EVENT_START_LOCK {GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_none}, //EVENT_LOCK {GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_rcvd_unlock_acc}, //EVENT_RCVD_ACC - {GD_OP_STATE_DEFAULT, glusterd_op_ac_none}, //EVENT_ALL_ACC + {GD_OP_STATE_DEFAULT, glusterd_op_ac_unlocked_all}, //EVENT_ALL_ACC {GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_none}, //EVENT_STAGE_ACC {GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_none}, //EVENT_COMMIT_ACC {GD_OP_STATE_UNLOCK_SENT, glusterd_op_ac_none}, //EVENT_RCVD_RJT @@ -1486,14 +1596,28 @@ glusterd_op_sm_new_event (glusterd_op_sm_event_type_t event_type, } int -glusterd_op_sm_inject_event (glusterd_op_sm_event_t *event) +glusterd_op_sm_inject_event (glusterd_op_sm_event_type_t event_type, + void *ctx) { - GF_ASSERT (event); + int32_t ret = -1; + glusterd_op_sm_event_t *event = NULL; + + GF_ASSERT (event_type < GD_OP_EVENT_MAX && + event_type >= GD_OP_EVENT_NONE); + + ret = glusterd_op_sm_new_event (event_type, &event); + + if (ret) + goto out; + + event->ctx = ctx; + gf_log ("glusterd", GF_LOG_NORMAL, "Enqueuing event: %d", event->event); list_add_tail (&event->list, &gd_op_sm_queue); - return 0; +out: + return ret; } @@ -1505,7 +1629,7 @@ glusterd_op_sm () int ret = -1; glusterd_op_sm_ac_fn handler = NULL; glusterd_op_sm_t *state = NULL; - glusterd_op_sm_event_type_t event_type = 0; + glusterd_op_sm_event_type_t event_type = GD_OP_EVENT_NONE; while (!list_empty (&gd_op_sm_queue)) { @@ -1527,7 +1651,8 @@ glusterd_op_sm () if (ret) { gf_log ("glusterd", GF_LOG_ERROR, "handler returned: %d", ret); - return ret; + GF_FREE (event); + continue; } ret = glusterd_op_sm_transition_state (&opinfo, state, @@ -1567,6 +1692,33 @@ glusterd_op_set_op (glusterd_op_t op) } +int32_t +glusterd_op_set_cli_op (gf_mgmt_procnum op) +{ + + int32_t ret; + + ret = pthread_mutex_trylock (&opinfo.lock); + + if (ret) + goto out; + + opinfo.cli_op = op; + +out: + gf_log ("", GF_LOG_NORMAL, "Returning %d", ret); + return ret; +} + +int32_t +glusterd_op_set_req (rpcsvc_request_t *req) +{ + + GF_ASSERT (req); + opinfo.req = req; + return 0; +} + int32_t glusterd_op_clear_pending_op (glusterd_op_t op) { diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.h b/xlators/mgmt/glusterd/src/glusterd-op-sm.h index 500d0ebc3..4a619ba3a 100644 --- a/xlators/mgmt/glusterd/src/glusterd-op-sm.h +++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.h @@ -35,6 +35,7 @@ #include "fd.h" #include "byte-order.h" #include "glusterd.h" +#include "protocol-common.h" #define GD_VOLUME_NAME_MAX 256 @@ -112,6 +113,11 @@ struct glusterd_op_info_ { glusterd_op_t commit_op[GD_OP_MAX]; struct list_head op_peers; void *op_ctx[GD_OP_MAX]; + rpcsvc_request_t *req; + int32_t op_ret; + int32_t op_errno; + pthread_mutex_t lock; + int32_t cli_op; }; typedef struct glusterd_op_info_ glusterd_op_info_t; @@ -148,9 +154,10 @@ typedef struct glusterd_op_commit_ctx_ glusterd_op_commit_ctx_t; int glusterd_op_sm_new_event (glusterd_op_sm_event_type_t event_type, - glusterd_op_sm_event_t **new_event); + glusterd_op_sm_event_t **new_event); int -glusterd_op_sm_inject_event (glusterd_op_sm_event_t *event); +glusterd_op_sm_inject_event (glusterd_op_sm_event_type_t event_type, + void *ctx); int glusterd_op_sm_init (); @@ -181,4 +188,14 @@ glusterd_op_commit_perform (gd1_mgmt_stage_op_req *req); void * glusterd_op_get_ctx (glusterd_op_t op); + +int32_t +glusterd_op_set_req (rpcsvc_request_t *req); + +int32_t +glusterd_op_set_cli_op (gf_mgmt_procnum op); + +int32_t +glusterd_op_send_cli_response (int32_t op, int32_t op_ret, + int32_t op_errno, rpcsvc_request_t *req); #endif diff --git a/xlators/mgmt/glusterd/src/glusterd-sm.c b/xlators/mgmt/glusterd/src/glusterd-sm.c index 817d520e1..b1a4c0d8a 100644 --- a/xlators/mgmt/glusterd/src/glusterd-sm.c +++ b/xlators/mgmt/glusterd/src/glusterd-sm.c @@ -563,7 +563,8 @@ glusterd_friend_sm () if (ret) { gf_log ("glusterd", GF_LOG_ERROR, "handler returned: " "%d", ret); - return ret; + GF_FREE (event); + continue; } ret = glusterd_friend_sm_transition_state (peerinfo, state, event_type); diff --git a/xlators/mgmt/glusterd/src/glusterd-sm.h b/xlators/mgmt/glusterd/src/glusterd-sm.h index 72fc811e7..3d54c4e9d 100644 --- a/xlators/mgmt/glusterd/src/glusterd-sm.h +++ b/xlators/mgmt/glusterd/src/glusterd-sm.h @@ -70,6 +70,7 @@ struct glusterd_peerinfo_ { struct list_head op_peers_list; struct list_head hostnames; struct rpc_clnt *rpc; + int connected; }; typedef struct glusterd_peerinfo_ glusterd_peerinfo_t; diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index e06128107..7c8a67ec3 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-utils.c @@ -44,6 +44,9 @@ #include #include #include +#include +#include +#include static glusterd_lock_t lock; @@ -77,10 +80,11 @@ glusterd_is_local_addr (char *hostname) struct addrinfo *result = NULL; struct addrinfo *res = NULL; int32_t found = 0; + struct ifconf buf = {0,}; if ((!strcmp (hostname, "localhost")) || (!strcmp (hostname, "127.0.0.1"))) { - found = 0; + found = 1; goto out; } @@ -108,10 +112,64 @@ glusterd_is_local_addr (char *hostname) } } + if (!found) { + int sd = -1; + struct ifreq *ifr = NULL; + int32_t size = 0; + int32_t num_req = 0; + struct sockaddr_in sa = {0,}; + + sd = socket (AF_LOCAL, SOCK_DGRAM, 0); + if (sd == -1) + goto out; + + buf.ifc_len = sizeof (struct ifreq); + buf.ifc_req = GF_CALLOC (1, sizeof (struct ifreq), + gf_gld_mt_ifreq); + size = buf.ifc_len; + + ret = ioctl (sd, SIOCGIFCONF, &buf); + if (ret) { + close (sd); + goto out; + } + + while (size <= buf.ifc_len) { + size += sizeof (struct ifreq); + buf.ifc_len = size; + buf.ifc_req = GF_REALLOC (buf.ifc_req, size); + ret = ioctl (sd, SIOCGIFCONF, &buf); + if (ret) { + close (sd); + goto out; + } + } + + ifr = buf.ifc_req; + num_req = size / sizeof (struct ifreq) - 1; + + while (num_req--) { + char *addr = inet_ntoa ( *(struct in_addr *) + &ifr->ifr_addr.sa_data[sizeof(sa.sin_port)]); + if (!strcmp (addr, hostname)) { + gf_log ("", GF_LOG_DEBUG, "%s found as local", + addr); + found = 1; + } + ifr++; + } + } + + + + out: //if (result) // freeaddrinfo (result); + if (buf.ifc_req) + GF_FREE (buf.ifc_req); + return !found; } @@ -613,7 +671,8 @@ glusterd_volinfo_find (char *volname, glusterd_volinfo_t **volinfo) int32_t glusterd_volume_start_glusterfs (glusterd_volinfo_t *volinfo, - glusterd_brickinfo_t *brickinfo) + glusterd_brickinfo_t *brickinfo, + int32_t count) { int32_t ret = -1; xlator_t *this = NULL; @@ -643,8 +702,8 @@ glusterd_volume_start_glusterfs (glusterd_volinfo_t *volinfo, } GLUSTERD_GET_BRICK_PIDFILE (pidfile, path, brickinfo->hostname); - snprintf (volfile, PATH_MAX, "%s/%s-%s-export.vol", path, - brickinfo->hostname, volinfo->volname); + snprintf (volfile, PATH_MAX, "%s/%s-%s-%d.vol", path, + brickinfo->hostname, volinfo->volname, count); snprintf (cmd_str, 8192, "glusterfs -f %s -p %s", volfile, pidfile); ret = system (cmd_str); @@ -769,3 +828,21 @@ glusterd_peer_destroy (glusterd_peerinfo_t *peerinfo) out: return ret; } + + +gf_boolean_t +glusterd_is_cli_op_req (int32_t op) +{ + switch (op) { + case GD_MGMT_CLI_CREATE_VOLUME: + case GD_MGMT_CLI_START_VOLUME: + case GD_MGMT_CLI_STOP_VOLUME: + case GD_MGMT_CLI_DELETE_VOLUME: + case GD_MGMT_CLI_DEFRAG_VOLUME: + case GD_MGMT_CLI_ADD_BRICK: + return _gf_true; + break; + } + + return _gf_false; +} diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h index f21971a59..041ecca67 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.h +++ b/xlators/mgmt/glusterd/src/glusterd-utils.h @@ -36,6 +36,7 @@ #include "byte-order.h" #include "glusterd.h" #include "rpc-clnt.h" +#include "protocol-common.h" struct glusterd_lock_ { uuid_t owner; @@ -94,7 +95,8 @@ glusterd_resolve_brick (glusterd_brickinfo_t *brickinfo); int32_t glusterd_volume_start_glusterfs (glusterd_volinfo_t *volinfo, - glusterd_brickinfo_t *brickinfo); + glusterd_brickinfo_t *brickinfo, + int32_t count); int32_t glusterd_volume_stop_glusterfs (glusterd_volinfo_t *volinfo, @@ -105,4 +107,7 @@ glusterd_volinfo_delete (glusterd_volinfo_t *volinfo); int32_t glusterd_brickinfo_delete (glusterd_brickinfo_t *brickinfo); + +gf_boolean_t +glusterd_is_cli_op_req (int32_t op); #endif diff --git a/xlators/mgmt/glusterd/src/glusterd.c b/xlators/mgmt/glusterd/src/glusterd.c index 7e886f17a..cfd07433b 100644 --- a/xlators/mgmt/glusterd/src/glusterd.c +++ b/xlators/mgmt/glusterd/src/glusterd.c @@ -48,6 +48,7 @@ static uuid_t glusterd_uuid; extern struct rpcsvc_program glusterd1_mop_prog; extern struct rpcsvc_program gluster_handshake_prog; extern struct rpc_clnt_program glusterd3_1_mgmt_prog; +extern glusterd_op_info_t opinfo; static int glusterd_retrieve_uuid () @@ -61,6 +62,16 @@ glusterd_store_uuid () return 0; } +static int +glusterd_opinfo_init () +{ + int32_t ret = -1; + + ret = pthread_mutex_init (&opinfo.lock, NULL); + + return ret; +} + static int glusterd_uuid_init () { @@ -276,6 +287,7 @@ init (xlator_t *this) glusterd_friend_sm_init (); glusterd_op_sm_init (); + glusterd_opinfo_init (); memcpy(conf->uuid, glusterd_uuid, sizeof (uuid_t)); diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h index 670ab73c8..f140bd9f7 100644 --- a/xlators/mgmt/glusterd/src/glusterd.h +++ b/xlators/mgmt/glusterd/src/glusterd.h @@ -79,6 +79,9 @@ struct glusterd_volinfo_ { typedef struct glusterd_volinfo_ glusterd_volinfo_t; +enum glusterd_op_ret { + GLUSTERD_CONNECTION_AWAITED = 100, +}; #define GLUSTERD_DEFAULT_WORKDIR "/etc/glusterd" #define GLUSTERD_DEFAULT_PORT 6969 @@ -91,6 +94,7 @@ typedef ssize_t (*gd_serialize_t) (struct iovec outmsg, void *args); #define GLUSTERD_GET_BRICK_PIDFILE(pidfile, volpath, hostname)\ snprintf (pidfile, PATH_MAX, "%s/run/%s.pid", volpath, hostname); + int glusterd_probe_begin (rpcsvc_request_t *req, const char *hoststr, int port); diff --git a/xlators/mgmt/glusterd/src/glusterd3_1-mops.c b/xlators/mgmt/glusterd/src/glusterd3_1-mops.c index 81cdad65e..9b44465cf 100644 --- a/xlators/mgmt/glusterd/src/glusterd3_1-mops.c +++ b/xlators/mgmt/glusterd/src/glusterd3_1-mops.c @@ -342,8 +342,7 @@ glusterd3_1_cluster_lock_cbk (struct rpc_req *req, struct iovec *iov, gd1_mgmt_cluster_lock_rsp rsp = {{0},}; int ret = -1; int32_t op_ret = -1; - glusterd_op_sm_event_t *event = NULL; - glusterd_op_sm_event_type_t event_type = GD_OP_EVENT_NONE; + glusterd_op_sm_event_type_t event_type = GD_OP_EVENT_NONE; glusterd_peerinfo_t *peerinfo = NULL; char str[50] = {0,}; @@ -375,20 +374,14 @@ glusterd3_1_cluster_lock_cbk (struct rpc_req *req, struct iovec *iov, GF_ASSERT (0); } - if (op_ret) + if (op_ret) { event_type = GD_OP_EVENT_RCVD_RJT; - else + opinfo.op_ret = op_ret; + } else { event_type = GD_OP_EVENT_RCVD_ACC; - - ret = glusterd_op_sm_new_event (event_type, &event); - - if (ret) { - gf_log ("glusterd", GF_LOG_ERROR, - "Unable to get event"); - goto out; } - ret = glusterd_op_sm_inject_event (event); + ret = glusterd_op_sm_inject_event (event_type, NULL); if (!ret) { glusterd_friend_sm (); @@ -409,8 +402,7 @@ glusterd3_1_cluster_unlock_cbk (struct rpc_req *req, struct iovec *iov, gd1_mgmt_cluster_lock_rsp rsp = {{0},}; int ret = -1; int32_t op_ret = -1; - glusterd_op_sm_event_t *event = NULL; - glusterd_op_sm_event_type_t event_type = GD_OP_EVENT_NONE; + glusterd_op_sm_event_type_t event_type = GD_OP_EVENT_NONE; glusterd_peerinfo_t *peerinfo = NULL; char str[50] = {0,}; @@ -443,20 +435,15 @@ glusterd3_1_cluster_unlock_cbk (struct rpc_req *req, struct iovec *iov, GF_ASSERT (0); } - if (op_ret) + if (op_ret) { event_type = GD_OP_EVENT_RCVD_RJT; - else + opinfo.op_ret = op_ret; + } else { event_type = GD_OP_EVENT_RCVD_ACC; - - ret = glusterd_op_sm_new_event (event_type, &event); - - if (ret) { - gf_log ("glusterd", GF_LOG_ERROR, - "Unable to get event"); - goto out; } - ret = glusterd_op_sm_inject_event (event); + + ret = glusterd_op_sm_inject_event (event_type, NULL); if (!ret) { glusterd_friend_sm (); @@ -477,8 +464,7 @@ glusterd3_1_stage_op_cbk (struct rpc_req *req, struct iovec *iov, gd1_mgmt_stage_op_rsp rsp = {{0},}; int ret = -1; int32_t op_ret = -1; - glusterd_op_sm_event_t *event = NULL; - glusterd_op_sm_event_type_t event_type = GD_OP_EVENT_NONE; + glusterd_op_sm_event_type_t event_type = GD_OP_EVENT_NONE; glusterd_peerinfo_t *peerinfo = NULL; char str[50] = {0,}; @@ -511,20 +497,14 @@ glusterd3_1_stage_op_cbk (struct rpc_req *req, struct iovec *iov, GF_ASSERT (0); } - if (op_ret) + if (op_ret) { event_type = GD_OP_EVENT_RCVD_RJT; - else + opinfo.op_ret = op_ret; + } else { event_type = GD_OP_EVENT_RCVD_ACC; - - ret = glusterd_op_sm_new_event (event_type, &event); - - if (ret) { - gf_log ("glusterd", GF_LOG_ERROR, - "Unable to get event"); - goto out; } - ret = glusterd_op_sm_inject_event (event); + ret = glusterd_op_sm_inject_event (event_type, NULL); if (!ret) { glusterd_friend_sm (); @@ -545,8 +525,7 @@ glusterd3_1_commit_op_cbk (struct rpc_req *req, struct iovec *iov, gd1_mgmt_commit_op_rsp rsp = {{0},}; int ret = -1; int32_t op_ret = -1; - glusterd_op_sm_event_t *event = NULL; - glusterd_op_sm_event_type_t event_type = GD_OP_EVENT_NONE; + glusterd_op_sm_event_type_t event_type = GD_OP_EVENT_NONE; glusterd_peerinfo_t *peerinfo = NULL; char str[50] = {0,}; @@ -579,20 +558,14 @@ glusterd3_1_commit_op_cbk (struct rpc_req *req, struct iovec *iov, GF_ASSERT (0); } - if (op_ret) + if (op_ret) { event_type = GD_OP_EVENT_RCVD_RJT; - else + opinfo.op_ret = op_ret; + } else { event_type = GD_OP_EVENT_RCVD_ACC; - - ret = glusterd_op_sm_new_event (event_type, &event); - - if (ret) { - gf_log ("glusterd", GF_LOG_ERROR, - "Unable to get event"); - goto out; } - ret = glusterd_op_sm_inject_event (event); + ret = glusterd_op_sm_inject_event (event_type, NULL); if (!ret) { glusterd_friend_sm (); @@ -951,15 +924,8 @@ glusterd3_1_stage_op (call_frame_t *frame, xlator_t *this, //No pending ops, inject stage_acc - glusterd_op_sm_event_t *event = NULL; - - ret = glusterd_op_sm_new_event (GD_OP_EVENT_STAGE_ACC, - &event); - - if (ret) - goto out; - - ret = glusterd_op_sm_inject_event (event); + ret = glusterd_op_sm_inject_event + (GD_OP_EVENT_STAGE_ACC, NULL); return ret; } @@ -1006,6 +972,14 @@ glusterd3_1_stage_op (call_frame_t *frame, xlator_t *this, opinfo.pending_count = pending_peer; out: + if (ret) { + glusterd_op_sm_inject_event (GD_OP_EVENT_RCVD_RJT, NULL); + opinfo.op_ret = ret; + } + if (req) { + GF_FREE (req->buf.buf_val); + GF_FREE (req); + } gf_log ("glusterd", GF_LOG_DEBUG, "Returning %d", ret); return ret; } @@ -1040,15 +1014,8 @@ glusterd3_1_commit_op (call_frame_t *frame, xlator_t *this, //No pending ops, inject stage_acc - glusterd_op_sm_event_t *event = NULL; - - ret = glusterd_op_sm_new_event (GD_OP_EVENT_COMMIT_ACC, - &event); - - if (ret) - goto out; - - ret = glusterd_op_sm_inject_event (event); + ret = glusterd_op_sm_inject_event + (GD_OP_EVENT_COMMIT_ACC, NULL); return ret; } @@ -1094,6 +1061,14 @@ glusterd3_1_commit_op (call_frame_t *frame, xlator_t *this, opinfo.pending_count = pending_peer; out: + if (ret) { + glusterd_op_sm_inject_event (GD_OP_EVENT_RCVD_RJT, NULL); + opinfo.op_ret = ret; + } + if (req) { + GF_FREE (req->buf.buf_val); + GF_FREE (req); + } gf_log ("glusterd", GF_LOG_DEBUG, "Returning %d", ret); return ret; } @@ -1102,11 +1077,22 @@ out: int glusterd_handle_rpc_msg (rpcsvc_request_t *req) { - int ret = -1; + int ret = -1; + gf_boolean_t is_cli_req = _gf_false; + GF_ASSERT (req); - //ret = glusterd1_mgmt_actors[req->procnum].actor (req); - // + is_cli_req = glusterd_is_cli_op_req (req->procnum); + + if (is_cli_req) { + ret = glusterd_op_set_cli_op (req->procnum); + + if (ret) { + gf_log ("", GF_LOG_ERROR, "Unable to set cli op: %d", + ret); + goto out; + } + } switch (req->procnum) { case GD_MGMT_PROBE_QUERY: @@ -1135,6 +1121,8 @@ glusterd_handle_rpc_msg (rpcsvc_request_t *req) case GD_MGMT_CLI_PROBE: ret = glusterd_handle_cli_probe (req); + if (ret == GLUSTERD_CONNECTION_AWAITED) + return 0; break; case GD_MGMT_CLI_CREATE_VOLUME: @@ -1185,11 +1173,14 @@ glusterd_handle_rpc_msg (rpcsvc_request_t *req) GF_ASSERT (0); } - if (!ret) { - glusterd_friend_sm (); - glusterd_op_sm (); - } + glusterd_friend_sm (); + glusterd_op_sm (); +out: + if (ret) { + glusterd_op_send_cli_response (req->procnum, ret, 0, req); + } + gf_log ("", GF_LOG_NORMAL, "Returning %d", ret); return ret; } -- cgit