diff options
author | Avra Sengupta <asengupt@redhat.com> | 2013-09-30 16:26:33 +0530 |
---|---|---|
committer | Avra Sengupta <asengupt@redhat.com> | 2013-10-10 14:35:36 +0530 |
commit | 4b466674ebf6c192cb1ce17b367fb9845c68129d (patch) | |
tree | 51cfa823b8892e5a26e452f0c5897bc79a4860ae /cli/src/cli-rpc-ops.c | |
parent | 5380fc6df4d7b5735e86e46f20c5d9e2254e9774 (diff) |
cli: snapshot create cli interface.
$ gluster snapshot help
snapshot help - display help for snapshot commands
snapshot create <volnames> [-n <snap-name/cg-name>] [-d <description>] - Snapshot Create.
$ gluster snapshot create vol1
snapshot create: ???: snap created successfully
$ gluster snapshot create vol1 vol2
snapshot create: ???: consistency group created successfully
(The ??? will be replaced by the glusterd snap create command with the
generated snap-name or cg-name)
$ gluster snapshot create vol1 vol2 -n CG1
snapshot create: CG1: consistency group created successfully
$ gluster snapshot create vol1 -n snap1 -d Description
snapshot create: snap1: snap created successfully
$ gluster snapshot create vol1 -n snap1 -d "Description can have -d within quotes"
snapshot create: snap1: snap created successfully
$ gluster snapshot create vol1 -n snap1 -d Description cant have -d without quotes
snapshot create: failed: Options(-n/-d) are not valid descriptions
Usage: snapshot create <volnames> [-n <snap-name/cg-name>] [-d <description>]
$ gluster snapshot create vol1 -n "Multi word snap name" -d Description
snapshot create: failed: Invalid snap name
Usage: snapshot create <volnames> [-n <snap-name/cg-name>] [-d <description>]
$ gluster snapshot create vol1 -d Description -n "-d"
snapshot create: failed: Options(-n/-d) are not valid snap names
Usage: snapshot create <volnames> [-n <snap-name/cg-name>] [-d <description>]
$ gluster snapshot create vol1 -d -n snap1
snapshot create: failed: No description provided
Usage: snapshot create <volnames> [-n <snap-name/cg-name>] [-d <description>]
Change-Id: I74b5a8406d72282fbb7ba7d07e0c7fe395148d38
Signed-off-by: Avra Sengupta <asengupt@redhat.com>
Diffstat (limited to 'cli/src/cli-rpc-ops.c')
-rw-r--r-- | cli/src/cli-rpc-ops.c | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c index fe3db41b6..c8c3a7bfb 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -7392,6 +7392,127 @@ out: } int +gf_cli_snapshot_cbk (struct rpc_req *req, struct iovec *iov, + int count, void *myframe) +{ + int ret = -1; + gf_cli_rsp rsp = {0, }; + dict_t *dict = NULL; + char *snap_name = NULL; + char *cg_name = NULL; + int32_t type = 0; + int32_t volcount = 0; + call_frame_t *frame = NULL; + + if (req->rpc_status == -1) { + ret = -1; + goto out; + } + + frame = myframe; + + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp); + if (ret < 0) { + gf_log (frame->this->name, GF_LOG_ERROR, + "Failed to decode xdr response"); + goto out; + } + + dict = dict_new (); + + if (!dict) { + ret = -1; + goto out; + } + + ret = dict_unserialize (rsp.dict.dict_val, rsp.dict.dict_len, &dict); + + if (ret) + goto out; + + ret = dict_get_int32 (dict, "type", &type); + if (ret) { + gf_log (frame->this->name, GF_LOG_ERROR, "failed to get type"); + goto out; + } + + switch (type) { + case GF_SNAP_OPTION_TYPE_CREATE: + if (rsp.op_ret) { + cli_err("snapshot create: failed: %s", + rsp.op_errstr ? rsp.op_errstr : + "Please check log file for details"); + ret = rsp.op_ret; + goto out; + } + + ret = dict_get_int32 (dict, "volcount", &volcount); + if (ret) { + gf_log (frame->this->name, GF_LOG_ERROR, + "failed to get volcount"); + goto out; + } + + if (volcount > 1) { + if (dict_get_str (dict, "cg-name", + &cg_name) != 0) + cg_name = "???"; + + cli_out ("snapshot create: %s: consistency " + "group created successfully", + cg_name); + } else { + if (dict_get_str (dict, "snap-name", + &snap_name) != 0) + snap_name = "???"; + + cli_out ("snapshot create: %s: " + "snap created successfully", + snap_name); + } + break; + + default: + cli_err ("Unknown command executed"); + ret = -1; + goto out; + } + +out: + if (dict) + dict_unref (dict); + cli_cmd_broadcast_response (ret); + + free (rsp.dict.dict_val); + + return ret; +} + +int32_t +gf_cli_snapshot (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_snapshot_cbk, + (xdrproc_t) xdr_gf_cli_req, options, + GLUSTER_CLI_SNAP, this, cli_rpc_prog, + NULL); +out: + gf_log ("cli", GF_LOG_ERROR, "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, int procnum, xlator_t *this, rpc_clnt_prog_t *prog, @@ -7505,6 +7626,7 @@ struct rpc_clnt_procedure gluster_cli_actors[GLUSTER_CLI_MAXVALUE] = { #ifdef HAVE_BD_XLATOR [GLUSTER_CLI_BD_OP] = {"BD_OP", gf_cli_bd_op}, #endif + [GLUSTER_CLI_SNAP] = {"SNAP", gf_cli_snapshot}, }; struct rpc_clnt_program cli_prog = { |