From ad234382336a6f2dafb4cb698dfabbf7957b498b Mon Sep 17 00:00:00 2001 From: Pranith Kumar K Date: Mon, 20 Sep 2010 09:54:12 +0000 Subject: cli, mgmt/glusterd: volume sync command Signed-off-by: Pranith Kumar K Signed-off-by: Vijay Bellur BUG: 1310 () URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1310 --- cli/src/cli-cmd-volume.c | 50 ++++++++++++++++++++++++++++++++++++++++++++ cli/src/cli3_1-cops.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 103 insertions(+), 1 deletion(-) (limited to 'cli') diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index fc7fda9dfc2..28104c18704 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -131,6 +131,52 @@ out: } + +void +cli_cmd_sync_volume_usage () +{ + cli_out ("Usage: volume sync [all|]"); +} + +int +cli_cmd_sync_volume_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; + gf1_cli_sync_volume_req req = {0,}; + + if ((wordcount < 3) || (wordcount > 4)) { + cli_cmd_sync_volume_usage (); + goto out; + } + + if ((wordcount == 3) || !strcmp(words[3], "all")) { + req.flags = GF_CLI_SYNC_ALL; + req.volname = ""; + } else { + req.volname = (char *)words[3]; + } + + req.hostname = (char *)words[2]; + + proc = &cli_rpc_prog->proctable[GF1_CLI_SYNC_VOLUME]; + + frame = create_frame (THIS, THIS->ctx->pool); + if (!frame) + goto out; + + if (proc->fn) { + ret = proc->fn (frame, THIS, &req); + } + +out: + if (ret) + cli_out ("Volume sync failed"); + + return ret; +} void cli_cmd_volume_create_usage () { @@ -826,6 +872,10 @@ struct cli_cmd volume_cmds[] = { cli_cmd_log_rotate_cbk, "rotate the log file for corresponding volume/brick"}, + { "volume sync [all|]", + cli_cmd_sync_volume_cbk, + "sync the volume information from a peer"}, + { NULL, NULL, NULL } }; diff --git a/cli/src/cli3_1-cops.c b/cli/src/cli3_1-cops.c index 0898f2b943a..832618c2446 100644 --- a/cli/src/cli3_1-cops.c +++ b/cli/src/cli3_1-cops.c @@ -1032,6 +1032,36 @@ out: return ret; } +static int +gf_cli3_1_sync_volume_cbk (struct rpc_req *req, struct iovec *iov, + int count, void *myframe) +{ + gf1_cli_sync_volume_rsp rsp = {0,}; + int ret = -1; + + if (-1 == req->rpc_status) { + goto out; + } + + ret = gf_xdr_to_cli_sync_volume_rsp (*iov, &rsp); + if (ret < 0) { + gf_log ("", GF_LOG_ERROR, "error"); + goto out; + } + + gf_log ("cli", GF_LOG_DEBUG, "Received resp to sync"); + cli_out ("volume sync: %s", + (rsp.op_ret) ? "unsuccessful": "successful"); + + if (rsp.op_ret && rsp.op_errstr) + cli_out (rsp.op_errstr); + ret = rsp.op_ret; + +out: + cli_cmd_broadcast_response (ret); + return ret; +} + int gf_cli3_1_getspec_cbk (struct rpc_req *req, struct iovec *iov, int count, void *myframe) @@ -1880,6 +1910,28 @@ out: return ret; } +int32_t +gf_cli3_1_sync_volume (call_frame_t *frame, xlator_t *this, + void *data) +{ + int ret = 0; + + if (!frame || !this || !data) { + ret = -1; + goto out; + } + + ret = cli_cmd_submit ((gf1_cli_sync_volume_req*)data, frame, + cli_rpc_prog, GD_MGMT_CLI_SYNC_VOLUME, + NULL, gf_xdr_from_cli_sync_volume_req, + this, gf_cli3_1_sync_volume_cbk); + +out: + gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); + + return ret; +} + int32_t gf_cli3_1_getspec (call_frame_t *frame, xlator_t *this, void *data) @@ -1939,7 +1991,6 @@ out: return ret; } - struct rpc_clnt_procedure gluster3_1_cli_actors[GF1_CLI_MAXVALUE] = { [GF1_CLI_NULL] = {"NULL", NULL }, [GF1_CLI_PROBE] = { "PROBE_QUERY", gf_cli3_1_probe}, @@ -1962,6 +2013,7 @@ struct rpc_clnt_procedure gluster3_1_cli_actors[GF1_CLI_MAXVALUE] = { [GF1_CLI_LOG_ROTATE] = {"LOG ROTATE", gf_cli3_1_log_rotate}, [GF1_CLI_GETSPEC] = {"GETSPEC", gf_cli3_1_getspec}, [GF1_CLI_PMAP_PORTBYBRICK] = {"PMAP PORTBYBRICK", gf_cli3_1_pmap_b2p}, + [GF1_CLI_SYNC_VOLUME] = {"SYNC_VOLUME", gf_cli3_1_sync_volume}, }; struct rpc_clnt_program cli3_1_prog = { -- cgit