Blame SOURCES/libvirt-snapshot-conf-Use-common-parsing-and-formatting-functions-for-source.patch

c401cc
From c64b72d5c96a79b141f59a6ca7412cef10b18325 Mon Sep 17 00:00:00 2001
c401cc
Message-Id: <c64b72d5c96a79b141f59a6ca7412cef10b18325@dist-git>
c401cc
From: Peter Krempa <pkrempa@redhat.com>
c401cc
Date: Wed, 26 Feb 2014 14:54:47 +0100
c401cc
Subject: [PATCH] snapshot: conf: Use common parsing and formatting functions
c401cc
 for source
c401cc
c401cc
https://bugzilla.redhat.com/show_bug.cgi?id=1032370
c401cc
c401cc
Disk source elements for snapshots were using separate code from our
c401cc
config parser. As snapshots can be stored on more than just regular
c401cc
files, we will need the universal parser to allow us to expose a variety
c401cc
of snapshot disk targets. This patch reuses the config parsers and
c401cc
formatters to do the job.
c401cc
c401cc
This initial support only changes the code without any visible XML
c401cc
change.
c401cc
c401cc
(cherry picked from commit 43f2ccdc73090bd03f64de4d58d46ffa0134d705)
c401cc
c401cc
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c401cc
---
c401cc
 src/conf/snapshot_conf.c | 67 ++++++++++++++++++++++++++++++++----------------
c401cc
 src/conf/snapshot_conf.h |  1 +
c401cc
 2 files changed, 46 insertions(+), 22 deletions(-)
c401cc
c401cc
diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c
c401cc
index 2a52418..29e12b7 100644
c401cc
--- a/src/conf/snapshot_conf.c
c401cc
+++ b/src/conf/snapshot_conf.c
c401cc
@@ -128,27 +128,42 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node,
c401cc
         }
c401cc
     }
c401cc
 
c401cc
-    cur = node->children;
c401cc
-    while (cur) {
c401cc
-        if (cur->type == XML_ELEMENT_NODE) {
c401cc
-            if (!def->file &&
c401cc
-                xmlStrEqual(cur->name, BAD_CAST "source")) {
c401cc
-                def->file = virXMLPropString(cur, "file");
c401cc
-            } else if (!def->format &&
c401cc
-                       xmlStrEqual(cur->name, BAD_CAST "driver")) {
c401cc
-                char *driver = virXMLPropString(cur, "type");
c401cc
-                def->format = virStorageFileFormatTypeFromString(driver);
c401cc
-                if (def->format <= 0) {
c401cc
-                    virReportError(VIR_ERR_INTERNAL_ERROR,
c401cc
-                                   _("unknown disk snapshot driver '%s'"),
c401cc
-                                   driver);
c401cc
-                    VIR_FREE(driver);
c401cc
-                    goto cleanup;
c401cc
-                }
c401cc
+    def->type = -1;
c401cc
+
c401cc
+    for (cur = node->children; cur; cur = cur->next) {
c401cc
+        if (cur->type != XML_ELEMENT_NODE)
c401cc
+            continue;
c401cc
+
c401cc
+        if (!def->file &&
c401cc
+            xmlStrEqual(cur->name, BAD_CAST "source")) {
c401cc
+
c401cc
+            int backingtype = def->type;
c401cc
+
c401cc
+            if (backingtype < 0)
c401cc
+                backingtype = VIR_DOMAIN_DISK_TYPE_FILE;
c401cc
+
c401cc
+            if (virDomainDiskSourceDefParse(cur,
c401cc
+                                            backingtype,
c401cc
+                                            &def->file,
c401cc
+                                            NULL,
c401cc
+                                            NULL,
c401cc
+                                            NULL,
c401cc
+                                            NULL) < 0)
c401cc
+                goto cleanup;
c401cc
+
c401cc
+        } else if (!def->format &&
c401cc
+                   xmlStrEqual(cur->name, BAD_CAST "driver")) {
c401cc
+            char *driver = virXMLPropString(cur, "type");
c401cc
+            def->format = virStorageFileFormatTypeFromString(driver);
c401cc
+            if (def->format <= 0) {
c401cc
+                virReportError(VIR_ERR_INTERNAL_ERROR,
c401cc
+                               _("unknown disk snapshot driver '%s'"),
c401cc
+                               driver);
c401cc
                 VIR_FREE(driver);
c401cc
+                goto cleanup;
c401cc
             }
c401cc
+            VIR_FREE(driver);
c401cc
         }
c401cc
-        cur = cur->next;
c401cc
     }
c401cc
 
c401cc
     if (!def->snapshot && (def->file || def->format))
c401cc
@@ -540,6 +555,8 @@ static void
c401cc
 virDomainSnapshotDiskDefFormat(virBufferPtr buf,
c401cc
                                virDomainSnapshotDiskDefPtr disk)
c401cc
 {
c401cc
+    int type = disk->type;
c401cc
+
c401cc
     if (!disk->name)
c401cc
         return;
c401cc
 
c401cc
@@ -547,6 +564,10 @@ virDomainSnapshotDiskDefFormat(virBufferPtr buf,
c401cc
     if (disk->snapshot > 0)
c401cc
         virBufferAsprintf(buf, " snapshot='%s'",
c401cc
                           virDomainSnapshotLocationTypeToString(disk->snapshot));
c401cc
+
c401cc
+    if (type < 0)
c401cc
+        type = VIR_DOMAIN_DISK_TYPE_FILE;
c401cc
+
c401cc
     if (!disk->file && disk->format == 0) {
c401cc
         virBufferAddLit(buf, "/>\n");
c401cc
         return;
c401cc
@@ -554,12 +575,14 @@ virDomainSnapshotDiskDefFormat(virBufferPtr buf,
c401cc
 
c401cc
     virBufferAddLit(buf, ">\n");
c401cc
 
c401cc
-    virBufferAdjustIndent(buf, 6);
c401cc
     if (disk->format > 0)
c401cc
-        virBufferEscapeString(buf, "<driver type='%s'/>\n",
c401cc
+        virBufferEscapeString(buf, "      <driver type='%s'/>\n",
c401cc
                               virStorageFileFormatTypeToString(disk->format));
c401cc
-    virBufferEscapeString(buf, "<source file='%s'/>\n", disk->file);
c401cc
-    virBufferAdjustIndent(buf, -6);
c401cc
+    virDomainDiskSourceDefFormatInternal(buf,
c401cc
+                                         type,
c401cc
+                                         disk->file,
c401cc
+                                         0, 0, 0, NULL, 0, NULL, NULL, 0);
c401cc
+
c401cc
     virBufferAddLit(buf, "    </disk>\n");
c401cc
 }
c401cc
 
c401cc
diff --git a/src/conf/snapshot_conf.h b/src/conf/snapshot_conf.h
c401cc
index 6d625a7..9ed80b2 100644
c401cc
--- a/src/conf/snapshot_conf.h
c401cc
+++ b/src/conf/snapshot_conf.h
c401cc
@@ -51,6 +51,7 @@ struct _virDomainSnapshotDiskDef {
c401cc
     char *name; /* name matching the 
c401cc
     int index; /* index within snapshot->dom->disks that matches name */
c401cc
     int snapshot; /* enum virDomainSnapshotLocation */
c401cc
+    int type; /* enum virDomainDiskType */
c401cc
     char *file; /* new source file when snapshot is external */
c401cc
     int format; /* enum virStorageFileFormat */
c401cc
 };
c401cc
-- 
c401cc
1.9.0
c401cc