From 99b778cbe179104af602b6eedebd31695bec16ae Mon Sep 17 00:00:00 2001 From: Dan Lambright Date: Mon, 13 Apr 2015 02:42:12 +0100 Subject: glusterd: support for tier volumes 'detach start' and 'detach commit' Back port of http://review.gluster.org/10108 These commands work in a manner analagous to rebalancing when removing a brick. The existing migration daemon detects "detach start" and switches to moving data off the hot tier. While in this state all lookups are directed to the cold tier. gluster v detach-tier start gluster v detach-tier commit The status and stop cli commands shall be submitted separately. >Change-Id: I24fda5cc3ba74f5fb8aa9a3234ad51f18b80a8a0 >BUG: 1205540 >Signed-off-by: Dan Lambright >Signed-off-by: root >Signed-off-by: Dan Lambright >Reviewed-on: http://review.gluster.org/10108 >Reviewed-by: Kaleb KEITHLEY Change-Id: I212d748d077fb5870ee84b316c653acbafbea3f7 BUG: 1220047 Signed-off-by: Mohammed Rafi KC Reviewed-on: http://review.gluster.org/10708 Reviewed-by: Dan Lambright Tested-by: Gluster Build System Reviewed-by: Vijay Bellur --- cli/src/cli-cmd-parser.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ cli/src/cli-cmd-volume.c | 17 ++++---------- cli/src/cli-rpc-ops.c | 33 ++++++++------------------ cli/src/cli.h | 4 ++++ 4 files changed, 77 insertions(+), 37 deletions(-) (limited to 'cli') diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 38b3bbde13d..e5fb4089dab 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -1647,6 +1647,66 @@ out: return ret; } +int32_t +cli_cmd_volume_detach_tier_parse (const char **words, int wordcount, + dict_t **options) +{ + int ret = -1; + char *word = NULL; + dict_t *dict = NULL; + int32_t command = GF_OP_CMD_NONE; + int force = 0; + + if (!((wordcount == 4) || (wordcount == 5))) + goto out; + + dict = dict_new (); + if (!dict) + goto out; + + ret = dict_set_str (dict, "volname", (char *)words[2]); + if (ret) + goto out; + + if (wordcount == 5) { + word = (char *)words[4]; + if (!strcmp(word, "force")) + force = 1; + } + + word = (char *)words[3]; + + ret = -1; + + if (!strcmp(word, "start")) { + command = GF_OP_CMD_DETACH_START; + } else if (!strcmp(word, "commit")) { + if (force) + command = GF_OP_CMD_DETACH_COMMIT_FORCE; + else + command = GF_OP_CMD_DETACH_COMMIT; + } else if (!strcmp(word, "stop")) + command = GF_DEFRAG_CMD_STOP_DETACH_TIER; + else if (!strcmp(word, "status")) + command = GF_DEFRAG_CMD_STATUS; + else + goto out; + + ret = dict_set_int32 (dict, "command", command); + if (ret) + goto out; + + *options = dict; + ret = 0; +out: + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "Unable to parse detach-tier CLI"); + if (dict) + dict_unref (dict); + } + + return ret; +} int32_t cli_cmd_volume_remove_brick_parse (const char **words, int wordcount, diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index f9d4041f3ca..91b2a1988d9 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -924,26 +924,16 @@ cli_cmd_volume_detach_tier_cbk (struct cli_state *state, const char *question = "Removing tier can result in data loss. " "Do you want to Continue?"; - if (wordcount != 3) - goto out; - frame = create_frame (THIS, THIS->ctx->pool); if (!frame) goto out; - options = dict_new (); - if (!options) - goto out; + ret = cli_cmd_volume_detach_tier_parse(words, wordcount, &options); - ret = dict_set_int32 (options, "force", 1); if (ret) goto out; - ret = dict_set_int32 (options, "command", GF_OP_CMD_DETACH); - if (ret) - goto out; - - ret = dict_set_str (options, "volname", (char *)words[2]); + ret = dict_set_int32 (options, "force", 1); if (ret) goto out; @@ -2523,7 +2513,8 @@ struct cli_cmd volume_cmds[] = { cli_cmd_volume_attach_tier_cbk, "attach tier to volume "}, - { "volume detach-tier ", + { "volume detach-tier " + " ", cli_cmd_volume_detach_tier_cbk, "detach tier from volume "}, diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c index 5361e83a1f6..932fe5f8cb7 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -56,6 +56,10 @@ extern rpc_clnt_prog_t *cli_rpc_prog; extern int cli_op_ret; extern int connected; +int32_t +gf_cli_remove_brick (call_frame_t *frame, xlator_t *this, + void *data); + char *cli_vol_type_str[] = {"Distribute", "Stripe", "Replicate", @@ -1355,11 +1359,14 @@ gf_cli_print_rebalance_status (dict_t *dict, enum gf_task_types task_type) /* Check if status is NOT_STARTED, and continue early */ memset (key, 0, 256); snprintf (key, 256, "status-%d", i); + ret = dict_get_int32 (dict, key, (int32_t *)&status_rcd); if (ret) { + gf_log ("cli", GF_LOG_TRACE, "count %d %d", count, i); gf_log ("cli", GF_LOG_TRACE, "failed to get status"); goto out; } + if (GF_DEFRAG_STATUS_NOT_STARTED == status_rcd) continue; @@ -2245,6 +2252,7 @@ gf_cli_remove_brick_cbk (struct rpc_req *req, struct iovec *iov, } switch (cmd) { + case GF_OP_CMD_DETACH_START: case GF_OP_CMD_START: cmd_str = "start"; @@ -3835,30 +3843,7 @@ int32_t gf_cli_detach_tier (call_frame_t *frame, xlator_t *this, void *data) { - gf_cli_req req = {{0,} }; - int ret = 0; - dict_t *dict = NULL; - char *volname = NULL; - - if (!frame || !this || !data) { - ret = -1; - goto out; - } - - dict = data; - - ret = cli_to_glusterd (&req, frame, gf_cli_remove_brick_cbk, - (xdrproc_t) xdr_gf_cli_req, dict, - GLUSTER_CLI_DETACH_TIER, this, - cli_rpc_prog, NULL); - - -out: - gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); - - GF_FREE (req.dict.dict_val); - - return ret; + return gf_cli_remove_brick(frame, this, data); } diff --git a/cli/src/cli.h b/cli/src/cli.h index 71bf3add3d2..3da58dd22d8 100644 --- a/cli/src/cli.h +++ b/cli/src/cli.h @@ -258,6 +258,10 @@ int32_t cli_cmd_volume_add_brick_parse (const char **words, int wordcount, dict_t **options, int *type); +int32_t +cli_cmd_volume_detach_tier_parse (const char **words, int wordcount, + dict_t **options); + int32_t cli_cmd_volume_remove_brick_parse (const char **words, int wordcount, dict_t **options, int *question); -- cgit