21ab4e
From 0ccff60cdb2a049d9c54745e0935a67e7eda73e1 Mon Sep 17 00:00:00 2001
21ab4e
From: Mohammed Rafi KC <rkavunga@redhat.com>
21ab4e
Date: Tue, 31 Mar 2015 10:54:10 +0530
21ab4e
Subject: [PATCH 305/361] Snapshot/xml:xml output for snapshot clone
21ab4e
21ab4e
Snapshot clone is used to create a regular volume from snapshot.
21ab4e
Currently snapshot clone is not supporting xml outout.
21ab4e
21ab4e
This change introduce a xml output for snapshot clone command
21ab4e
21ab4e
mainline:
21ab4e
> BUG: 1207604
21ab4e
> Reviewed-on: http://review.gluster.org/10065
21ab4e
> Smoke: Gluster Build System <jenkins@build.gluster.org>
21ab4e
> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
21ab4e
> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
21ab4e
> Reviewed-by: Avra Sengupta <asengupt@redhat.com>
21ab4e
> Reviewed-by: Rajesh Joseph <rjoseph@redhat.com>
21ab4e
> Tested-by: Avra Sengupta <asengupt@redhat.com>
21ab4e
(cherry picked from commit 2c51208197e1043c84c04d3b37a325b84831f56b)
21ab4e
21ab4e
BUG: 1167252
21ab4e
Change-Id: I417b480d36f9d84ee088004999b041c9619edd50
21ab4e
Signed-off-by: Mohammed Rafi KC <rkavunga@redhat.com>
21ab4e
Reviewed-on: https://code.engineering.redhat.com/gerrit/101281
21ab4e
Tested-by: Milind Changire <mchangir@redhat.com>
21ab4e
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
21ab4e
---
21ab4e
 cli/src/cli-xml-output.c                      | 79 ++++++++++++++++++++++++---
21ab4e
 xlators/mgmt/glusterd/src/glusterd-snapshot.c |  2 +-
21ab4e
 2 files changed, 73 insertions(+), 8 deletions(-)
21ab4e
21ab4e
diff --git a/cli/src/cli-xml-output.c b/cli/src/cli-xml-output.c
21ab4e
index f249e40..063e171 100644
21ab4e
--- a/cli/src/cli-xml-output.c
21ab4e
+++ b/cli/src/cli-xml-output.c
21ab4e
@@ -4578,6 +4578,65 @@ out:
21ab4e
         return ret;
21ab4e
 }
21ab4e
 
21ab4e
+/* This function will generate snapshot clone output in xml format.
21ab4e
+ *
21ab4e
+ * @param writer        xmlTextWriterPtr
21ab4e
+ * @param doc           xmlDocPtr
21ab4e
+ * @param dict          dict containing create output
21ab4e
+ *
21ab4e
+ * @return 0 on success and -1 on failure
21ab4e
+ */
21ab4e
+static int
21ab4e
+cli_xml_snapshot_clone (xmlTextWriterPtr writer, xmlDocPtr doc, dict_t *dict)
21ab4e
+{
21ab4e
+        int     ret             = -1;
21ab4e
+        char   *str_value       = NULL;
21ab4e
+
21ab4e
+        GF_VALIDATE_OR_GOTO ("cli", writer, out);
21ab4e
+        GF_VALIDATE_OR_GOTO ("cli", doc, out);
21ab4e
+        GF_VALIDATE_OR_GOTO ("cli", dict, out);
21ab4e
+
21ab4e
+        /* <CloneCreate> */
21ab4e
+        ret = xmlTextWriterStartElement (writer, (xmlChar *)"CloneCreate");
21ab4e
+        XML_RET_CHECK_AND_GOTO (ret, out);
21ab4e
+
21ab4e
+        /* <volume> */
21ab4e
+        ret = xmlTextWriterStartElement (writer, (xmlChar *)"volume");
21ab4e
+        XML_RET_CHECK_AND_GOTO (ret, out);
21ab4e
+
21ab4e
+        ret = dict_get_str (dict, "clonename", &str_value);
21ab4e
+        if (ret) {
21ab4e
+                gf_log ("cli", GF_LOG_ERROR, "Failed to get clone name");
21ab4e
+                goto out;
21ab4e
+        }
21ab4e
+        ret = xmlTextWriterWriteFormatElement (writer, (xmlChar *) "name",
21ab4e
+                                               "%s", str_value);
21ab4e
+        XML_RET_CHECK_AND_GOTO (ret, out);
21ab4e
+
21ab4e
+
21ab4e
+        ret = dict_get_str (dict, "snapuuid", &str_value);
21ab4e
+        if (ret) {
21ab4e
+                gf_log ("cli", GF_LOG_ERROR, "Failed to get clone uuid");
21ab4e
+                goto out;
21ab4e
+        }
21ab4e
+
21ab4e
+        ret = xmlTextWriterWriteFormatElement (writer, (xmlChar *) "uuid",
21ab4e
+                                               "%s", str_value);
21ab4e
+        XML_RET_CHECK_AND_GOTO (ret, out);
21ab4e
+
21ab4e
+        /* </volume> */
21ab4e
+        ret = xmlTextWriterEndElement (writer);
21ab4e
+        XML_RET_CHECK_AND_GOTO (ret, out);
21ab4e
+
21ab4e
+        /* </CloneCreate> */
21ab4e
+        ret = xmlTextWriterEndElement (writer);
21ab4e
+        XML_RET_CHECK_AND_GOTO (ret, out);
21ab4e
+
21ab4e
+        ret = 0;
21ab4e
+out:
21ab4e
+        return ret;
21ab4e
+}
21ab4e
+
21ab4e
 
21ab4e
 /* This function will generate snapshot restore output in xml format.
21ab4e
  *
21ab4e
@@ -5162,14 +5221,12 @@ cli_xml_snapshot_volume_status (xmlTextWriterPtr writer, xmlDocPtr doc,
21ab4e
 
21ab4e
                 ret = dict_get_str (dict, key, &buffer);
21ab4e
                 if (ret) {
21ab4e
-                        gf_log ("cli", GF_LOG_ERROR,
21ab4e
+                        gf_log ("cli", GF_LOG_INFO,
21ab4e
                                 "Unable to get Brick Running");
21ab4e
-                        ret = xmlTextWriterWriteFormatElement (writer,
21ab4e
-                                            (xmlChar *) "brick_running", "N/A");
21ab4e
-                } else
21ab4e
-                        ret = xmlTextWriterWriteFormatElement (writer,
21ab4e
-                                     (xmlChar *) "brick_running", "%s", buffer);
21ab4e
-
21ab4e
+                        strcpy (buffer, "N/A");
21ab4e
+                }
21ab4e
+                ret = xmlTextWriterWriteFormatElement (writer,
21ab4e
+                                    (xmlChar *) "BrickRunning", "%s", buffer);
21ab4e
                 XML_RET_CHECK_AND_GOTO (ret, out);
21ab4e
 
21ab4e
                 snprintf (key, sizeof (key), "%s.brick%d.pid", keyprefix, i);
21ab4e
@@ -6023,6 +6080,14 @@ cli_xml_output_snapshot (int cmd_type, dict_t *dict, int op_ret,
21ab4e
                         goto out;
21ab4e
                 }
21ab4e
                 break;
21ab4e
+        case GF_SNAP_OPTION_TYPE_CLONE:
21ab4e
+                ret = cli_xml_snapshot_clone (writer, doc, dict);
21ab4e
+                if (ret) {
21ab4e
+                        gf_log ("cli", GF_LOG_ERROR, "Failed to create "
21ab4e
+                                "xml output for snapshot clone command");
21ab4e
+                        goto out;
21ab4e
+                }
21ab4e
+                break;
21ab4e
         case GF_SNAP_OPTION_TYPE_RESTORE:
21ab4e
                 ret = cli_xml_snapshot_restore (writer, doc, dict);
21ab4e
                 if (ret) {
21ab4e
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
21ab4e
index 47835a8..425fa07 100644
21ab4e
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c
21ab4e
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
21ab4e
@@ -6864,7 +6864,7 @@ glusterd_snapshot_clone_commit (dict_t *dict, char **op_errstr,
21ab4e
 
21ab4e
        cds_list_del_init (&snap_vol->vol_list);
21ab4e
        ret = dict_set_dynstr_with_alloc (rsp_dict, "snapuuid",
21ab4e
-                                         uuid_utoa (snap->snap_id));
21ab4e
+                                         uuid_utoa (snap_vol->volume_id));
21ab4e
        if (ret) {
21ab4e
                gf_msg (this->name, GF_LOG_ERROR, 0,
21ab4e
                        GD_MSG_DICT_SET_FAILED, "Failed to set snap "
21ab4e
-- 
21ab4e
1.8.3.1
21ab4e