diff options
author | Avra Sengupta <asengupt@redhat.com> | 2013-09-30 16:26:33 +0530 |
---|---|---|
committer | shishir gowda <sgowda@redhat.com> | 2013-11-15 12:37:02 +0530 |
commit | f8a158134d89b25063b059cd4241ffc84c48f469 (patch) | |
tree | 954e36a3c85b0ed3fef9a437aca1d0967d9b4080 /xlators/mgmt/glusterd/src/glusterd-snapshot.c | |
parent | 83417fbfeb4262eaed78b6c086f9d249361ebb65 (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 'xlators/mgmt/glusterd/src/glusterd-snapshot.c')
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-snapshot.c | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c index 528308831..0b84a5075 100644 --- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c +++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c @@ -337,3 +337,102 @@ glusterd_remove_snap_cg_by_id (glusterd_conf_t *conf, uuid_t cg_id) out: return entry; } + +int +glusterd_handle_snapshot_fn (rpcsvc_request_t *req) +{ + int32_t ret = 0; + dict_t *dict = NULL; + gf_cli_req cli_req = {{0},}; + glusterd_op_t cli_op = GD_OP_SNAP; + char operation[256] = {0,}; + int type = 0; + glusterd_conf_t *priv = NULL; + char *host_uuid = NULL; + char err_str[2048] = {0,}; + xlator_t *this = NULL; + + GF_ASSERT (req); + + this = THIS; + GF_ASSERT (this); + priv = this->private; + GF_ASSERT (priv); + + ret = xdr_to_generic (req->msg[0], &cli_req, + (xdrproc_t)xdr_gf_cli_req); + if (ret < 0) { + req->rpc_err = GARBAGE_ARGS; + goto out; + } + + if (cli_req.dict.dict_len) { + dict = dict_new (); + if (!dict) + goto out; + + ret = dict_unserialize (cli_req.dict.dict_val, + cli_req.dict.dict_len, + &dict); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "failed to " + "unserialize req-buffer to dictionary"); + snprintf (err_str, sizeof (err_str), "Unable to decode " + "the command"); + goto out; + } else { + dict->extra_stdfree = cli_req.dict.dict_val; + } + + host_uuid = gf_strdup (uuid_utoa(MY_UUID)); + if (host_uuid == NULL) { + snprintf (err_str, sizeof (err_str), "Failed to get " + "the uuid of local glusterd"); + ret = -1; + goto out; + } + ret = dict_set_dynstr (dict, "host-uuid", host_uuid); + if (ret) + goto out; + + } + + ret = dict_get_int32 (dict, "type", &type); + if (ret < 0) { + snprintf (err_str, sizeof (err_str), "Command type not found"); + gf_log (this->name, GF_LOG_ERROR, "%s", err_str); + goto out; + } + + switch (type) { + case GF_SNAP_OPTION_TYPE_CREATE: + strncpy (operation, "create", sizeof (operation)); + break; + } + + //ret = glusterd_op_begin_synctask (req, cli_op, dict); + +out: + + /* Temporary Will be removed by the glusterd syncop framework */ + ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, + dict, err_str); + +/* Commenting out the code coz the syncop framework + should take care of this. + if (ret) { + if (err_str[0] == '\0') + snprintf (err_str, sizeof (err_str), + "Operation failed"); + ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, + dict, err_str); + } +*/ + return ret; +} + +int +glusterd_handle_snapshot (rpcsvc_request_t *req) +{ + return glusterd_big_locked_handler (req, glusterd_handle_snapshot_fn); +} |