diff options
author | Sachin Pandit <spandit@redhat.com> | 2013-10-15 15:41:56 +0530 |
---|---|---|
committer | shishir gowda <sgowda@redhat.com> | 2013-11-15 12:38:59 +0530 |
commit | da3a265c36b1326405dafce98b29d7c72001a7e9 (patch) | |
tree | 6b1cd92cd5d3ec24b499d1f4140be7af26e50f77 /cli/src/cli-rpc-ops.c | |
parent | b1e9fab5de8ab45987b2eed9bfd12a1eb188707b (diff) |
CLI : snapshot list cli interface
$gluster snapshot list
*prints snaps of all volume*
$gluster snapshot list -d
*prints snaps of all volume with details*
$gluster snapshot list vol1
*prints snaps of volume "vol1"*
$gluster snapshot list vol1 -d
*prints snaps of volume "vol1" with details*
$gluster snapshot list vol1 vol2
*prints snaps of volume "vol1" & "vol2"
$gluster snapshot list vol1 vol2 -d
*prints snaps of volume "vol1" & "vol2" with details*
$gluster snapshot list -c cgname
*prints snaps of all volume present in the group "cgname"*
$gluster snapshot list -c cgname -d
*prints snaps of all volume present in the group "cgname" with details*
** As of now you wont be able to see any output as actual snap create is not integrated **
Change-Id: I60eeafc715a51f1c564a270bb4124368038012b1
Signed-off-by: Sachin Pandit <spandit@redhat.com>
Diffstat (limited to 'cli/src/cli-rpc-ops.c')
-rw-r--r-- | cli/src/cli-rpc-ops.c | 369 |
1 files changed, 330 insertions, 39 deletions
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c index b100f2d62..50eeda3d2 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -7518,18 +7518,282 @@ out: return ret; } + +/*Function to list the snap "gluster snapshot list" */ +static int +list_snap_of_volume (dict_t *dict_n, char *prefix_str) { + int64_t snapcount = -1 ; + char buffer[PATH_MAX] = "" ; + char *get_buffer = NULL; + int8_t detail = 0 ; + int64_t i = 0 ; + int ret = -1 ; + + GF_ASSERT (dict_n); + GF_ASSERT (prefix_str); + + if (!dict_n) { + ret = -1; + goto out; + } + + /* Check if volname is present. + * if volume not present then display that volume doesnot exist + * and try to fetch next volume mentioned + */ + ret = snprintf (buffer, sizeof(buffer), "%s.vol_name", prefix_str); + if (ret < 0) { /* Negative value is an error */ + goto out; + } + ret = dict_get_str (dict_n, buffer, &get_buffer); + if (get_buffer == NULL){ + cli_out ("Volume doesnot exist"); + goto out; + } + cli_out ("Vol Name : %s", get_buffer); + /* if Volume is present then get the snapcount. + * string is "snaplist.vol{0..}.snap_count. + */ + ret = snprintf (buffer, sizeof(buffer), + "%s.snap_count", prefix_str); + if (ret < 0) { /* Negative value is an error */ + goto out; + } + ret = dict_get_int64 (dict_n, buffer, &snapcount); + if (ret) { + gf_log("", GF_LOG_ERROR, "Could not fetch snapcount"); + goto out; + } + + /* To check if the user has given "-d" option */ + ret = dict_get_int8 (dict_n, "snap_details", &detail); + if (ret) { + gf_log ("",GF_LOG_ERROR, "could not get snap_details status"); + goto out; + } + + cli_out ("Number of Snaps Taken : %ld", snapcount); + for (i = 0 ; i < snapcount; i++) { + /* get snapname "snaplist.vol{0..}.snap{0..}.snap_name" */ + ret = snprintf (buffer, sizeof(buffer), + "%s.snap%ld.snap_name", prefix_str,i); + if (ret < 0) { /* Negative value is an error */ + goto out; + } + ret = dict_get_str (dict_n, buffer, &get_buffer); + if (!ret) + cli_out ("\tSnap Name : %s",get_buffer); + else + cli_out ("\tSnap Name : %s","Does not exist"); + + ret = snprintf (buffer, sizeof(buffer), + "%s.snap%ld.snap_time", prefix_str, i); + if (ret < 0) { /* Negative value is an error */ + goto out; + } + ret = dict_get_str (dict_n, buffer, &get_buffer); + if (!ret) + cli_out ("\tSnap Time : %s",get_buffer); + else + cli_out ("\tSnap Time : %s","Does not exist"); + + + ret = snprintf (buffer, sizeof(buffer), "%s.snap%ld.snap_id" + , prefix_str, i); + if (ret < 0) { /* Negative value is an error */ + goto out; + } + ret = dict_get_str (dict_n, buffer, &get_buffer); + if (!ret) + cli_out("\tSnap ID : %s",get_buffer); + else + cli_out("\tSnap ID : %s","Does not exist"); + + if(detail == 0) { + /* if snap_details is set to zero + * then we can skip the additional information part + */ + continue; + } + ret = snprintf (buffer, sizeof(buffer), + "%s.snap%ld.cg_name", prefix_str, i); + if (ret < 0) { /* Negative value is an error */ + goto out; + } + ret = dict_get_str (dict_n, buffer, &get_buffer); + if (!ret) + cli_out("\tCG Name : %s",get_buffer); + else + cli_out("\tCG Name : %s","Does not exist"); + + ret = snprintf (buffer, sizeof(buffer), + "%s.snap%ld.cg_id", prefix_str, i); + if (ret < 0) { /* Negative value is an error */ + goto out; + } + ret = dict_get_str (dict_n, buffer, &get_buffer); + if (!ret) + cli_out("\tCG ID : %s",get_buffer); + else + cli_out("\tCG ID : %s","Does not exist"); + + ret = snprintf (buffer, sizeof(buffer), + "%s.snap%ld.snap_desc", prefix_str, i); + if (ret < 0) { /* Negative value is an error */ + goto out; + } + ret = dict_get_str (dict_n, buffer, &get_buffer); + if (!ret) + cli_out ("\tSnap Description : %s",get_buffer); + else + cli_out ("\tSnap Description : %s", + "Description not present"); + + ret = snprintf (buffer, sizeof(buffer), + "%s.snap%ld.snap_status", prefix_str, i); + if (ret < 0) { /* Negative value is an error */ + goto out; + } + ret = dict_get_str (dict_n, buffer, &get_buffer); + if (!ret) + cli_out ("\tSnap Status : %s",get_buffer); + else + cli_out ("\tSnap Status : %s","Does not exist"); + ret = 0; + } + +out : + return ret; +} + +/* Function to list snap present in CG */ +static int +list_snap_of_cg (dict_t *dict) { + int ret = -1 ; + int8_t detail = 0 ; + char *get_buffer = NULL; + char cg_name_list[PATH_MAX] = "" ; + int64_t cg_volcount = -1 ; + int64_t i = -1 ; + + GF_ASSERT(dict); + + /* As listing snaps of single CG is supported as of now + * the string "snaplist.cg0" is directly included + * or else we can keep that string in some variable + * and use the same variable every where + */ + ret = dict_get_int8 (dict, "snap_details", &detail); + if (ret) { + gf_log ("", GF_LOG_ERROR, "could not get snap_details status"); + goto out; + } + + ret = dict_get_str (dict, "snaplist.cg0.cg_name", &get_buffer); + if (ret) { + /* if cg_name is not present then exit, it is not necessary + * to check other details if cg_name is not present + */ + cli_out ("CG Name : %s","Does not exist"); + gf_log ("", GF_LOG_ERROR, "Could not get cg_name"); + goto out; + } + cli_out ("CG Name : %s", get_buffer); + + ret = dict_get_str (dict, "snaplist.cg0.cg_id", &get_buffer); + if (!ret) + cli_out ("CG ID : %s",get_buffer); + else + cli_out ("CG ID : %s","Does not exist"); + + if (detail == 1) { + ret = dict_get_str (dict, "snaplist.cg0.cg_desc", &get_buffer); + if (!ret) + cli_out ("CG Description : %s", + get_buffer); + else + cli_out ("CG Description : %s", + "Does not exist"); + + ret = dict_get_str (dict, "snaplist.cg0.cg_status", + &get_buffer); + if (!ret) + cli_out ("CG Status : %s", get_buffer); + else + cli_out ("CG Status : %s", + "Does not exist"); + + } + + ret = dict_get_int64 (dict, "snaplist.cg0.vol_count", &cg_volcount); + if (ret) { + gf_log ("", GF_LOG_ERROR, "Could not fetch cg_volcount"); + goto out; + } + /* list the snaps of each volume present in a CG*/ + for (i = 0 ; i < cg_volcount ; i++){ + ret = snprintf (cg_name_list, sizeof(cg_name_list), + "snaplist.cg0.vol%ld",i); + if (ret < 0) { /* Negative value is an error */ + goto out; + } + ret = list_snap_of_volume (dict, cg_name_list); + if (ret) { + gf_log("", GF_LOG_ERROR, "Failed to list the" + " information of snaps of volume present in CG"); + } + } +out : + return ret; +} + +/* This function calls list_snap_of_volume */ +static int +call_list_snap_of_volume(dict_t *dict){ + int ret = -1; + int64_t volcount = -1; + int i = -1; + char vol_name_prefix[PATH_MAX] = ""; + + ret = dict_get_int64 (dict, "snaplist.vol_count", &volcount); + if (ret) { + gf_log ("", GF_LOG_ERROR, "Could not fetch volcount"); + goto out; + } + for (i = 0 ; i < volcount ; i++) { + /* list the snap of each volume + * vol_name_prefix = "snaplist.vol{0..}" + */ + ret = snprintf (vol_name_prefix, sizeof(vol_name_prefix), + "snaplist.vol%d", i); + if (ret < 0) { /* Negative value is an error */ + goto out; + } + ret = list_snap_of_volume (dict, vol_name_prefix); + if (ret) { + gf_log("", GF_LOG_ERROR, + "Failed to list information of snaps of volume"); + } + /* If we fail to print information of one volume + * then try to fetch information of next volume + */ + } +out : + return ret; +} + 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; + int ret = -1; + gf_cli_rsp rsp = {0, }; + dict_t *dict = NULL; + char *snap_name = NULL; + char *cg_name = NULL; + int32_t type = 0; + int64_t volcount = -1; + call_frame_t *frame = NULL; if (req->rpc_status == -1) { ret = -1; @@ -7564,47 +7828,74 @@ gf_cli_snapshot_cbk (struct rpc_req *req, struct iovec *iov, } 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; - } + 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; - } + ret = dict_get_int64 (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 = "???"; + 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: 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); + cli_out ("snapshot create: %s: " + "snap created successfully", + snap_name); } break; - default: - cli_err ("Unknown command executed"); + case GF_SNAP_OPTION_TYPE_LIST: + if (rsp.op_ret) { + cli_err ("Snapshot list : failed: %s", + rsp.op_errstr ? rsp.op_errstr : + "Please check log file for details"); + ret = rsp.op_ret; + goto out; + } + + /* get the vol_count + * if vol_count = 0, then there must be presence of CG + */ + ret = dict_get_int64 (dict, "snaplist.vol_count", &volcount); + if (ret){ + gf_log("", GF_LOG_ERROR, "Could not fetch volcount"); ret = -1; goto out; - } + } + if (volcount >= 1) { + ret = call_list_snap_of_volume (dict); + } else { + /* get the volumes present in CG + * and list snap of each volume + */ + ret = list_snap_of_cg (dict); + } + break; + default: + cli_err ("Unknown command executed"); + ret = -1; + goto out; + } out: if (dict) dict_unref (dict); |