summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src/glusterd-snapshot.c
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 /xlators/mgmt/glusterd/src/glusterd-snapshot.c
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>
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-snapshot.c')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-snapshot.c127
1 files changed, 81 insertions, 46 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
index 66fdf4178..e9b887745 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;
}