summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSachin Pandit <spandit@redhat.com>2014-03-07 05:16:02 +0530
committerRajesh Joseph <rjoseph@redhat.com>2014-03-10 06:21:06 -0700
commit9fe1f24e42fa54b58616cd846fce76ab60d7e4e8 (patch)
treeb1089265bb7dfea9c03351a419ac05d0c7a01b22
parent3a7fdc198ada9621333b560c8911a05844413751 (diff)
glusterd/snapshot : Introduced a macro for snapshot info command.
Also populated the error message in case of snapshot create, list, info and delete failure. When snapshot list, info or delete is issued, if the entered snapname/volname does not exist then populate error string along with logging. Change-Id: I632d25110bc63ff0e4ac98b27e2f410f7ccbb990 Signed-off-by: Sachin Pandit <spandit@redhat.com> Reviewed-on: http://review.gluster.org/7203 Reviewed-by: Vijaikumar Mallikarjuna <vmallika@redhat.com> Reviewed-by: Rajesh Joseph <rjoseph@redhat.com> Tested-by: Rajesh Joseph <rjoseph@redhat.com>
-rw-r--r--cli/src/cli-cmd-parser.c12
-rw-r--r--cli/src/cli-rpc-ops.c8
-rw-r--r--rpc/xdr/src/cli1-xdr.h7
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-snapshot.c127
4 files changed, 107 insertions, 47 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
index adfb85e..2ad5d43 100644
--- a/cli/src/cli-cmd-parser.c
+++ b/cli/src/cli-cmd-parser.c
@@ -2780,7 +2780,7 @@ cli_snap_create_desc_parse (dict_t *dict, const char **words,
desc[desc_len] = '\0';
/* Calculating the size of the description as given by the user */
- ret = dict_set_dynstr (dict, "snap-description", desc);
+ ret = dict_set_dynstr (dict, "description", desc);
if (ret) {
gf_log ("cli", GF_LOG_ERROR, "Unable to save snap "
"description");
@@ -3008,6 +3008,7 @@ cli_snap_info_parse (dict_t *dict, const char **words, int wordcount,
unsigned int cmdi) {
int ret = -1;
+ int32_t cmd = GF_SNAP_INFO_TYPE_ALL;
GF_ASSERT (words);
GF_ASSERT (dict);
@@ -3044,6 +3045,7 @@ cli_snap_info_parse (dict_t *dict, const char **words, int wordcount,
goto out;
}
+ cmd = GF_SNAP_INFO_TYPE_SNAP;
ret = 0;
goto out;
/* No need to continue the parsing once we
@@ -3067,7 +3069,15 @@ cli_snap_info_parse (dict_t *dict, const char **words, int wordcount,
"volume name %s", words[wordcount - 1]);
goto out;
}
+ cmd = GF_SNAP_INFO_TYPE_VOL;
out :
+ if (ret == 0) {
+ ret = dict_set_int32 (dict, "cmd", cmd);
+ if (ret) {
+ gf_log ("cli", GF_LOG_ERROR, "Could not save "
+ "type of snapshot info");
+ }
+ }
return ret;
}
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c
index 0447e5b..60abfc1 100644
--- a/cli/src/cli-rpc-ops.c
+++ b/cli/src/cli-rpc-ops.c
@@ -8147,6 +8147,14 @@ gf_cli_snapshot_cbk (struct rpc_req *req, struct iovec *iov,
break;
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;
+ }
+
ret = cli_snapshot_list (dict);
if (ret) {
gf_log ("cli", GF_LOG_ERROR, "Failed to display "
diff --git a/rpc/xdr/src/cli1-xdr.h b/rpc/xdr/src/cli1-xdr.h
index 598ddbd..0cfa6de 100644
--- a/rpc/xdr/src/cli1-xdr.h
+++ b/rpc/xdr/src/cli1-xdr.h
@@ -183,6 +183,13 @@ enum gf1_cli_snapshot {
};
typedef enum gf1_cli_snapshot gf1_cli_snapshot;
+enum gf1_cli_snapshot_info {
+ GF_SNAP_INFO_TYPE_ALL = 0,
+ GF_SNAP_INFO_TYPE_SNAP = 1,
+ GF_SNAP_INFO_TYPE_VOL = 2,
+};
+typedef enum gf1_cli_snapshot_info gf1_cli_snapshot_info;
+
enum gf1_cli_snapshot_config {
GF_SNAP_CONFIG_TYPE_NONE = 0,
GF_SNAP_CONFIG_TYPE_SET = 0 + 1,
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
index 66fdf41..e9b8877 100644
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
@@ -595,8 +595,7 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr,
ret = glusterd_volinfo_find (volname, &volinfo);
if (ret) {
snprintf (err_str, sizeof (err_str),
- "failed to get the volinfo for the volume "
- "%s", volname);
+ "Volume (%s) does not exist ", volname);
goto out;
}
@@ -1670,7 +1669,8 @@ out:
}
int
-glusterd_snapshot_get_info_by_volume (dict_t *dict, char *volname)
+glusterd_snapshot_get_info_by_volume (dict_t *dict, char *volname,
+ char *err_str, size_t len)
{
int ret = -1;
int snapcount = 0;
@@ -1692,8 +1692,8 @@ glusterd_snapshot_get_info_by_volume (dict_t *dict, char *volname)
ret = glusterd_volinfo_find (volname, &volinfo);
if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "failed to get the volinfo "
- "for the volume %s", volname);
+ snprintf (err_str, len, "Volume (%s) does not exist", volname);
+ gf_log (this->name, GF_LOG_ERROR, "%s", err_str);
goto out;
}
@@ -1778,11 +1778,12 @@ glusterd_handle_snapshot_info (rpcsvc_request_t *req, glusterd_op_t op,
dict_t *dict, char *err_str, size_t len)
{
int ret = -1;
- int8_t snap_driven = 0;
+ int8_t snap_driven = 1;
char *volname = NULL;
char *snapname = NULL;
glusterd_snap_t *snap = NULL;
xlator_t *this = NULL;
+ int32_t cmd = GF_SNAP_INFO_TYPE_ALL;
this = THIS;
GF_ASSERT (this);
@@ -1790,55 +1791,86 @@ glusterd_handle_snapshot_info (rpcsvc_request_t *req, glusterd_op_t op,
GF_VALIDATE_OR_GOTO (this->name, req, out);
GF_VALIDATE_OR_GOTO (this->name, dict, out);
- /* Get the request key-pair from the dictionary */
-
- /* All these options are optonal. Therefore ignore
- * error returned by following dictionary operations
- */
- ret = dict_get_str (dict, "snapname", &snapname);
- ret = dict_get_str (dict, "volname", &volname);
- if (snapname && volname) {
- gf_log (this->name, GF_LOG_ERROR, "Option volname and snapname "
- "are mutually exclusive");
- ret = -1;
+ ret = dict_get_int32 (dict, "cmd", &cmd);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "Failed to get type "
+ "of snapshot info");
goto out;
}
- if (!volname)
- snap_driven = 1;
+ switch (cmd) {
+ case GF_SNAP_INFO_TYPE_ALL :
+ {
+ ret = glusterd_snapshot_get_all_snap_info (dict);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "Failed to get info of all snaps");
+ goto out;
+ }
+ break;
+ }
- ret = dict_set_int8 (dict, "snap-driven", snap_driven);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to set snap-driven");
- goto out;
- }
+ case GF_SNAP_INFO_TYPE_SNAP :
+ {
+ ret = dict_get_str (dict, "snapname", &snapname);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "Failed to get snap name");
+ goto out;
+ }
- if (snapname) {
- ret = dict_set_int32 (dict, "snap-count", 1);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR,
- "Failed to set snapcount");
- goto out;
+ ret = dict_set_int32 (dict, "snap-count", 1);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "Failed to set snapcount");
+ goto out;
+ }
+
+ snap = glusterd_find_snap_by_name (snapname);
+ if (!snap) {
+ snprintf (err_str, len,
+ "Snap (%s) does not exist", snapname);
+ gf_log (this->name, GF_LOG_ERROR,
+ "%s", err_str);
+ ret = -1;
+ goto out;
+ }
+ ret = glusterd_snapshot_get_snap_detail (dict, snap,
+ "snap1", NULL);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "Failed to get snap detail of snap "
+ "%s", snap->snapname);
+ goto out;
+ }
+ break;
}
- snap = glusterd_find_snap_by_name (snapname);
- if (!snap) {
- gf_log (this->name, GF_LOG_ERROR, "Snap %s doen't "
- "exist", snapname);
- ret = -1;
- goto out;
+ case GF_SNAP_INFO_TYPE_VOL :
+ {
+ ret = dict_get_str (dict, "volname", &volname);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "Failed to get volname");
+ goto out;
+ }
+ ret = glusterd_snapshot_get_info_by_volume (dict,
+ volname, err_str, len);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "Failed to get volume info of volume "
+ "%s", volname);
+ goto out;
+ }
+ snap_driven = 0;
+ break;
}
- ret = glusterd_snapshot_get_snap_detail (dict, snap, "snap1",
- NULL);
- } else if (volname) {
- ret = glusterd_snapshot_get_info_by_volume (dict, volname);
- } else {
- ret = glusterd_snapshot_get_all_snap_info (dict);
}
+ ret = dict_set_int8 (dict, "snap-driven", snap_driven);
if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to get snap info");
+ gf_log (this->name, GF_LOG_ERROR, "Failed to set snap-driven");
goto out;
}
@@ -1982,8 +2014,10 @@ glusterd_handle_snapshot_list (rpcsvc_request_t *req, glusterd_op_t op,
} else {
ret = glusterd_volinfo_find (volname, &volinfo);
if (ret) {
+ snprintf (err_str, len,
+ "Volume (%s) does not exist", volname);
gf_log (this->name, GF_LOG_ERROR,
- "Volume %s doesn't exists", volname);
+ "%s", err_str);
goto out;
}
@@ -3053,8 +3087,9 @@ glusterd_handle_snapshot_remove (rpcsvc_request_t *req, glusterd_op_t op,
snap = glusterd_find_snap_by_name (snapname);
if (!snap){
- gf_log (this->name, GF_LOG_ERROR, "Snap %s does not exist",
- snapname);
+ snprintf (err_str, len, "Snap (%s) does not exist", snapname);
+ gf_log (this->name, GF_LOG_ERROR,
+ "%s", err_str);
ret = -1;
goto out;
}