From 5e4a5a4c27f120102d4c2e3c7d558a20d838cf24 Mon Sep 17 00:00:00 2001 From: Kaushal M Date: Tue, 11 Feb 2014 10:07:24 +0530 Subject: cli: Add a cli command to enable/disable barrier This patch adds a new 'gluster volume barrier {enable|disable}' cli command. This helps in testing the brick op code path when testing the barrier xlator. This patch can be reverted later if not required for end users. Change-Id: Icd86a2d13e7f276dda1ecbb2593d60638ece7dcd BUG: 1060002 Signed-off-by: Kaushal M Reviewed-on: http://review.gluster.org/6958 Reviewed-by: Krishnan Parthasarathi Tested-by: Gluster Build System Reviewed-by: Vijay Bellur --- cli/src/cli-cmd-volume.c | 57 +++++++++++++++++++++++++++++++++++++++++++ cli/src/cli-rpc-ops.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+) (limited to 'cli') diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index 53c94c68779..83b923e360a 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -2264,6 +2264,60 @@ out: return ret; } +int +cli_cmd_volume_barrier_cbk (struct cli_state *state, struct cli_cmd_word *word, + const char **words, int wordcount) +{ + int ret = -1; + rpc_clnt_procedure_t *proc = NULL; + call_frame_t *frame = NULL; + dict_t *options = NULL; + int sent = 0; + int parse_error = 0; + cli_local_t *local = NULL; + + frame = create_frame (THIS, THIS->ctx->pool); + if (!frame) + goto out; + + if (wordcount != 4) { + cli_usage_out (word->pattern); + parse_error = 1; + goto out; + } + + options = dict_new(); + if (!options) { + ret = -1; + goto out; + } + ret = dict_set_str(options, "volname", (char *)words[2]); + if (ret) + goto out; + + ret = dict_set_str (options, "barrier", (char *)words[3]); + if (ret) + goto out; + + proc = &cli_rpc_prog->proctable[GLUSTER_CLI_BARRIER_VOLUME]; + + CLI_LOCAL_INIT (local, words, frame, options); + + if (proc->fn) + ret = proc->fn (frame, THIS, options); + +out: + if (ret) { + cli_cmd_sent_status_get (&sent); + if ((sent == 0) && (parse_error == 0)) + cli_err ("Volume barrier failed"); + } + CLI_STACK_DESTROY (frame); + if (options) + dict_unref (options); + + return ret; +} struct cli_cmd volume_cmds[] = { { "volume info [all|]", cli_cmd_volume_info_cbk, @@ -2387,6 +2441,9 @@ struct cli_cmd volume_cmds[] = { cli_cmd_volume_clearlocks_cbk, "Clear locks held on path" }, + {"volume barrier {enable|disable}", + cli_cmd_volume_barrier_cbk, + "Barrier/unbarrier file operations on a volume"}, { NULL, NULL, NULL } }; diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c index 8481d468cfa..987f9f16f48 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -8657,6 +8657,68 @@ out: return ret; } +int32_t +gf_cli_barrier_volume_cbk (struct rpc_req *req, struct iovec *iov, + int count, void *myframe) +{ + gf_cli_rsp rsp = {0,}; + int ret = -1; + dict_t *dict = NULL; + + if (-1 == req->rpc_status) + goto out; + ret = xdr_to_generic (*iov, &rsp, + (xdrproc_t)xdr_gf_cli_rsp); + if (ret < 0) { + gf_log (((call_frame_t *) myframe)->this->name, GF_LOG_ERROR, + "Failed to decode xdr response"); + goto out; + } + gf_log ("cli", GF_LOG_DEBUG, "Received response to barrier"); + + if (rsp.op_ret) { + if (rsp.op_errstr && (strlen (rsp.op_errstr) > 1)) { + cli_err ("volume barrier: command unsuccessful : %s", + rsp.op_errstr); + } else { + cli_err ("volume barrier: command unsuccessful"); + } + } else { + cli_out ("volume barrier: command successful"); + } + ret = rsp.op_ret; + +out: + if (dict) + dict_unref (dict); + free (rsp.op_errstr); + free (rsp.dict.dict_val); + cli_cmd_broadcast_response (ret); + return ret; +} +int +gf_cli_barrier_volume (call_frame_t *frame, xlator_t *this, void *data) +{ + gf_cli_req req = {{0,}}; + dict_t *options = NULL; + int ret = -1; + + if (!frame || !this || !data) + goto out; + + options = data; + + ret = cli_to_glusterd (&req, frame, gf_cli_barrier_volume_cbk, + (xdrproc_t) xdr_gf_cli_req, options, + GLUSTER_CLI_BARRIER_VOLUME, this, cli_rpc_prog, + NULL); +out: + gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); + + GF_FREE (req.dict.dict_val); + return ret; +} + int cli_to_glusterd (gf_cli_req *req, call_frame_t *frame, fop_cbk_fn_t cbkfn, xdrproc_t xdrproc, dict_t *dict, @@ -8769,6 +8831,7 @@ struct rpc_clnt_procedure gluster_cli_actors[GLUSTER_CLI_MAXVALUE] = { [GLUSTER_CLI_COPY_FILE] = {"COPY_FILE", gf_cli_copy_file}, [GLUSTER_CLI_SYS_EXEC] = {"SYS_EXEC", gf_cli_sys_exec}, [GLUSTER_CLI_SNAP] = {"SNAP", gf_cli_snapshot}, + [GLUSTER_CLI_BARRIER_VOLUME] = {"BARRIER VOLUME", gf_cli_barrier_volume}, }; struct rpc_clnt_program cli_prog = { -- cgit