[PATCH 2/3] snapshot: save domain description with snapshot

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Save the domain description with the XML snapshot data.
TODOs:
- XML file is no longer nicely indented
- Fix esx driver
- Fix vbox driver

Signed-off-by: Philipp Hahn <hahn@xxxxxxxxxxxxx>
---
 src/conf/domain_conf.c |   27 +++++++++++++++++++++++----
 src/conf/domain_conf.h |    4 +++-
 src/esx/esx_driver.c   |    2 +-
 src/qemu/qemu_driver.c |    4 ++--
 src/vbox/vbox_tmpl.c   |    2 +-
 5 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 16e1291..d568c43 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -8564,6 +8564,7 @@ void virDomainSnapshotDefFree(virDomainSnapshotDefPtr def)
     if (!def)
         return;
 
+    virDomainDefFree(def->dom);
     VIR_FREE(def->name);
     VIR_FREE(def->description);
     VIR_FREE(def->parent);
@@ -8571,7 +8572,8 @@ void virDomainSnapshotDefFree(virDomainSnapshotDefPtr def)
 }
 
 virDomainSnapshotDefPtr virDomainSnapshotDefParseString(const char *xmlStr,
-                                                        int newSnapshot)
+                                                        int newSnapshot,
+                                                        virCapsPtr caps)
 {
     xmlXPathContextPtr ctxt = NULL;
     xmlDocPtr xml = NULL;
@@ -8661,6 +8663,14 @@ virDomainSnapshotDefPtr virDomainSnapshotDefParseString(const char *xmlStr,
     else
         def->creationTime = tv.tv_sec;
 
+    xmlNodePtr domainNode = virXPathNode("./domain", ctxt);
+    if (domainNode == NULL) {
+        virDomainReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                _("missing domain from existing snapshot"));
+        def->dom = NULL;
+    } else
+        def->dom = virDomainDefParseNode(caps, xml, domainNode, VIR_DOMAIN_XML_INACTIVE);
+
     ret = def;
 
 cleanup:
@@ -8678,6 +8688,7 @@ char *virDomainSnapshotDefFormat(char *domain_uuid,
                                  virDomainSnapshotDefPtr def,
                                  int internal)
 {
+    char *xml = NULL;
     virBuffer buf = VIR_BUFFER_INITIALIZER;
 
     virBufferAddLit(&buf, "<domainsnapshot>\n");
@@ -8694,9 +8705,17 @@ char *virDomainSnapshotDefFormat(char *domain_uuid,
     }
     virBufferVSprintf(&buf, "  <creationTime>%ld</creationTime>\n",
                       def->creationTime);
-    virBufferAddLit(&buf, "  <domain>\n");
-    virBufferVSprintf(&buf, "    <uuid>%s</uuid>\n", domain_uuid);
-    virBufferAddLit(&buf, "  </domain>\n");
+    if (def->dom != NULL) {
+        xml = virDomainDefFormat(def->dom, VIR_DOMAIN_XML_INACTIVE | VIR_DOMAIN_XML_SECURE);
+    }
+    if (xml != NULL) {
+        virBufferVSprintf(&buf, "  %s", xml);
+        VIR_FREE(xml);
+    } else {
+        virBufferAddLit(&buf, "  <domain>\n");
+        virBufferVSprintf(&buf, "    <uuid>%s</uuid>\n", domain_uuid);
+        virBufferAddLit(&buf, "  </domain>\n");
+    }
     if (internal)
         virBufferVSprintf(&buf, "  <active>%ld</active>\n", def->active);
     virBufferAddLit(&buf, "</domainsnapshot>\n");
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 9e7e1ee..c8c64ed 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1083,6 +1083,7 @@ struct _virDomainSnapshotDef {
     int state;
 
     long active;
+    virDomainDefPtr dom;
 };
 
 typedef struct _virDomainSnapshotObj virDomainSnapshotObj;
@@ -1102,7 +1103,8 @@ struct _virDomainSnapshotObjList {
 };
 
 virDomainSnapshotDefPtr virDomainSnapshotDefParseString(const char *xmlStr,
-                                                        int newSnapshot);
+                                                        int newSnapshot,
+                                                        virCapsPtr caps);
 void virDomainSnapshotDefFree(virDomainSnapshotDefPtr def);
 char *virDomainSnapshotDefFormat(char *domain_uuid,
                                  virDomainSnapshotDefPtr def,
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index 4f013e8..25c95c9 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -4058,7 +4058,7 @@ esxDomainSnapshotCreateXML(virDomainPtr domain, const char *xmlDesc,
         return NULL;
     }
 
-    def = virDomainSnapshotDefParseString(xmlDesc, 1);
+    def = virDomainSnapshotDefParseString(xmlDesc, 1, NULL); /* TODO:caps */
 
     if (def == NULL) {
         return NULL;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 4481261..5041d32 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -330,7 +330,7 @@ static void qemuDomainSnapshotLoad(void *payload,
             continue;
         }
 
-        def = virDomainSnapshotDefParseString(xmlStr, 0);
+        def = virDomainSnapshotDefParseString(xmlStr, 0, qemu_driver->caps);
         if (def == NULL) {
             /* Nothing we can do here, skip this one */
             VIR_ERROR(_("Failed to parse snapshot XML from file '%s'"), fullpath);
@@ -6308,7 +6308,7 @@ static virDomainSnapshotPtr qemuDomainSnapshotCreateXML(virDomainPtr domain,
     if (!qemuDomainSnapshotIsAllowed(vm))
         goto cleanup;
 
-    if (!(def = virDomainSnapshotDefParseString(xmlDesc, 1)))
+    if (!(def = virDomainSnapshotDefParseString(xmlDesc, 1, qemu_driver->caps)))
         goto cleanup;
 
     if (!(snap = virDomainSnapshotAssignDef(&vm->snapshots, def)))
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index e8ac48f..a8c8570 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -5547,7 +5547,7 @@ vboxDomainSnapshotCreateXML(virDomainPtr dom,
 
     virCheckFlags(0, NULL);
 
-    if (!(def = virDomainSnapshotDefParseString(xmlDesc, 1)))
+    if (!(def = virDomainSnapshotDefParseString(xmlDesc, 1, NULL))) /* TODO:caps */
         goto cleanup;
 
     vboxIIDFromUUID(&domiid, dom->uuid);
-- 
1.7.1


--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]