Blob Blame History Raw
From 0ccff60cdb2a049d9c54745e0935a67e7eda73e1 Mon Sep 17 00:00:00 2001
From: Mohammed Rafi KC <rkavunga@redhat.com>
Date: Tue, 31 Mar 2015 10:54:10 +0530
Subject: [PATCH 305/361] Snapshot/xml:xml output for snapshot clone

Snapshot clone is used to create a regular volume from snapshot.
Currently snapshot clone is not supporting xml outout.

This change introduce a xml output for snapshot clone command

mainline:
> BUG: 1207604
> Reviewed-on: http://review.gluster.org/10065
> Smoke: Gluster Build System <jenkins@build.gluster.org>
> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
> Reviewed-by: Avra Sengupta <asengupt@redhat.com>
> Reviewed-by: Rajesh Joseph <rjoseph@redhat.com>
> Tested-by: Avra Sengupta <asengupt@redhat.com>
(cherry picked from commit 2c51208197e1043c84c04d3b37a325b84831f56b)

BUG: 1167252
Change-Id: I417b480d36f9d84ee088004999b041c9619edd50
Signed-off-by: Mohammed Rafi KC <rkavunga@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/101281
Tested-by: Milind Changire <mchangir@redhat.com>
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
---
 cli/src/cli-xml-output.c                      | 79 ++++++++++++++++++++++++---
 xlators/mgmt/glusterd/src/glusterd-snapshot.c |  2 +-
 2 files changed, 73 insertions(+), 8 deletions(-)

diff --git a/cli/src/cli-xml-output.c b/cli/src/cli-xml-output.c
index f249e40..063e171 100644
--- a/cli/src/cli-xml-output.c
+++ b/cli/src/cli-xml-output.c
@@ -4578,6 +4578,65 @@ out:
         return ret;
 }
 
+/* This function will generate snapshot clone output in xml format.
+ *
+ * @param writer        xmlTextWriterPtr
+ * @param doc           xmlDocPtr
+ * @param dict          dict containing create output
+ *
+ * @return 0 on success and -1 on failure
+ */
+static int
+cli_xml_snapshot_clone (xmlTextWriterPtr writer, xmlDocPtr doc, dict_t *dict)
+{
+        int     ret             = -1;
+        char   *str_value       = NULL;
+
+        GF_VALIDATE_OR_GOTO ("cli", writer, out);
+        GF_VALIDATE_OR_GOTO ("cli", doc, out);
+        GF_VALIDATE_OR_GOTO ("cli", dict, out);
+
+        /* <CloneCreate> */
+        ret = xmlTextWriterStartElement (writer, (xmlChar *)"CloneCreate");
+        XML_RET_CHECK_AND_GOTO (ret, out);
+
+        /* <volume> */
+        ret = xmlTextWriterStartElement (writer, (xmlChar *)"volume");
+        XML_RET_CHECK_AND_GOTO (ret, out);
+
+        ret = dict_get_str (dict, "clonename", &str_value);
+        if (ret) {
+                gf_log ("cli", GF_LOG_ERROR, "Failed to get clone name");
+                goto out;
+        }
+        ret = xmlTextWriterWriteFormatElement (writer, (xmlChar *) "name",
+                                               "%s", str_value);
+        XML_RET_CHECK_AND_GOTO (ret, out);
+
+
+        ret = dict_get_str (dict, "snapuuid", &str_value);
+        if (ret) {
+                gf_log ("cli", GF_LOG_ERROR, "Failed to get clone uuid");
+                goto out;
+        }
+
+        ret = xmlTextWriterWriteFormatElement (writer, (xmlChar *) "uuid",
+                                               "%s", str_value);
+        XML_RET_CHECK_AND_GOTO (ret, out);
+
+        /* </volume> */
+        ret = xmlTextWriterEndElement (writer);
+        XML_RET_CHECK_AND_GOTO (ret, out);
+
+        /* </CloneCreate> */
+        ret = xmlTextWriterEndElement (writer);
+        XML_RET_CHECK_AND_GOTO (ret, out);
+
+        ret = 0;
+out:
+        return ret;
+}
+
 
 /* This function will generate snapshot restore output in xml format.
  *
@@ -5162,14 +5221,12 @@ cli_xml_snapshot_volume_status (xmlTextWriterPtr writer, xmlDocPtr doc,
 
                 ret = dict_get_str (dict, key, &buffer);
                 if (ret) {
-                        gf_log ("cli", GF_LOG_ERROR,
+                        gf_log ("cli", GF_LOG_INFO,
                                 "Unable to get Brick Running");
-                        ret = xmlTextWriterWriteFormatElement (writer,
-                                            (xmlChar *) "brick_running", "N/A");
-                } else
-                        ret = xmlTextWriterWriteFormatElement (writer,
-                                     (xmlChar *) "brick_running", "%s", buffer);
-
+                        strcpy (buffer, "N/A");
+                }
+                ret = xmlTextWriterWriteFormatElement (writer,
+                                    (xmlChar *) "BrickRunning", "%s", buffer);
                 XML_RET_CHECK_AND_GOTO (ret, out);
 
                 snprintf (key, sizeof (key), "%s.brick%d.pid", keyprefix, i);
@@ -6023,6 +6080,14 @@ cli_xml_output_snapshot (int cmd_type, dict_t *dict, int op_ret,
                         goto out;
                 }
                 break;
+        case GF_SNAP_OPTION_TYPE_CLONE:
+                ret = cli_xml_snapshot_clone (writer, doc, dict);
+                if (ret) {
+                        gf_log ("cli", GF_LOG_ERROR, "Failed to create "
+                                "xml output for snapshot clone command");
+                        goto out;
+                }
+                break;
         case GF_SNAP_OPTION_TYPE_RESTORE:
                 ret = cli_xml_snapshot_restore (writer, doc, dict);
                 if (ret) {
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
index 47835a8..425fa07 100644
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
@@ -6864,7 +6864,7 @@ glusterd_snapshot_clone_commit (dict_t *dict, char **op_errstr,
 
        cds_list_del_init (&snap_vol->vol_list);
        ret = dict_set_dynstr_with_alloc (rsp_dict, "snapuuid",
-                                         uuid_utoa (snap->snap_id));
+                                         uuid_utoa (snap_vol->volume_id));
        if (ret) {
                gf_msg (this->name, GF_LOG_ERROR, 0,
                        GD_MSG_DICT_SET_FAILED, "Failed to set snap "
-- 
1.8.3.1