[libvirt] [PATCH 5/9] conf: snapshot: dump/parse persistent domain config

Nikolay Shirokovskiy nshirokovskiy at virtuozzo.com
Thu Dec 13 08:03:55 UTC 2018


Persistent in this case is a persistent config of active
persistent domain. We need it for metadata to be complete
as explained in previous patch.

Config is saved like this:

<domainsnapshot>
  <persistent>
    <domain>
      ...
    </domain>
  </persistent>
</domainsnapshot>

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy at virtuozzo.com>
---
 src/conf/snapshot_conf.c                           | 26 +++++++
 .../active_inactive_domain.xml                     | 85 ++++++++++++++++++++++
 tests/domainsnapshotxml2xmltest.c                  |  1 +
 3 files changed, 112 insertions(+)
 create mode 100644 tests/domainsnapshotxml2xmlout/active_inactive_domain.xml

diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c
index 2e4a0b9..34fcf64 100644
--- a/src/conf/snapshot_conf.c
+++ b/src/conf/snapshot_conf.c
@@ -283,6 +283,20 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt,
         } else {
             VIR_WARN("parsing older snapshot that lacks domain");
         }
+
+        if (def->state == VIR_DOMAIN_RUNNING ||
+            def->state == VIR_DOMAIN_PAUSED) {
+            int domainflags = VIR_DOMAIN_DEF_PARSE_INACTIVE |
+                              VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE;
+            xmlNodePtr domainNode;
+
+            if ((domainNode = virXPathNode("./persistent/domain", ctxt)) &&
+                !(def->persistDom = virDomainDefParseNode(ctxt->node->doc,
+                                                          domainNode, caps,
+                                                          xmlopt, NULL,
+                                                          domainflags)))
+                goto cleanup;
+        }
     } else {
         def->creationTime = tv.tv_sec;
     }
@@ -753,6 +767,18 @@ virDomainSnapshotDefFormat(const char *domain_uuid,
         virBufferAddLit(&buf, "</domain>\n");
     }
 
+    if (def->persistDom) {
+        virBufferAddLit(&buf, "<persistent>\n");
+        virBufferAdjustIndent(&buf, 2);
+
+        if (virDomainDefFormatInternal(def->persistDom,
+                                       caps, flags, &buf, xmlopt) < 0)
+            goto error;
+
+        virBufferAdjustIndent(&buf, -2);
+        virBufferAddLit(&buf, "</persistent>\n");
+    }
+
     if (virSaveCookieFormatBuf(&buf, def->cookie,
                                virDomainXMLOptionGetSaveCookie(xmlopt)) < 0)
         goto error;
diff --git a/tests/domainsnapshotxml2xmlout/active_inactive_domain.xml b/tests/domainsnapshotxml2xmlout/active_inactive_domain.xml
new file mode 100644
index 0000000..74025a3
--- /dev/null
+++ b/tests/domainsnapshotxml2xmlout/active_inactive_domain.xml
@@ -0,0 +1,85 @@
+<domainsnapshot>
+  <name>my snap name</name>
+  <description>!@#$%^</description>
+  <state>running</state>
+  <parent>
+    <name>earlier_snap</name>
+  </parent>
+  <creationTime>1272917631</creationTime>
+  <memory snapshot='internal'/>
+  <domain type='qemu'>
+    <name>QEMUGuest1</name>
+    <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+    <memory unit='KiB'>219100</memory>
+    <currentMemory unit='KiB'>219100</currentMemory>
+    <vcpu placement='static' cpuset='1-4,8-20,525'>1</vcpu>
+    <os>
+      <type arch='i686' machine='pc'>hvm</type>
+      <boot dev='hd'/>
+    </os>
+    <clock offset='utc'/>
+    <on_poweroff>destroy</on_poweroff>
+    <on_reboot>restart</on_reboot>
+    <on_crash>destroy</on_crash>
+    <devices>
+      <emulator>/usr/bin/qemu-system-i686</emulator>
+      <disk type='block' device='disk'>
+        <driver name='qemu' type='raw'/>
+        <source dev='/dev/HostVG/QEMUGuest1'/>
+        <target dev='hda' bus='ide'/>
+        <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+      </disk>
+      <controller type='usb' index='0'>
+        <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
+      </controller>
+      <controller type='ide' index='0'>
+        <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
+      </controller>
+      <controller type='pci' index='0' model='pci-root'/>
+      <input type='mouse' bus='ps2'/>
+      <input type='keyboard' bus='ps2'/>
+      <memballoon model='virtio'>
+        <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+      </memballoon>
+    </devices>
+  </domain>
+  <persistent>
+    <domain type='qemu'>
+      <name>QEMUGuest1</name>
+      <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+      <memory unit='KiB'>219100</memory>
+      <currentMemory unit='KiB'>219100</currentMemory>
+      <vcpu placement='static' cpuset='1-4,8-20,525'>1</vcpu>
+      <os>
+        <type arch='i686' machine='pc'>hvm</type>
+        <boot dev='hd'/>
+      </os>
+      <clock offset='utc'/>
+      <on_poweroff>destroy</on_poweroff>
+      <on_reboot>restart</on_reboot>
+      <on_crash>destroy</on_crash>
+      <devices>
+        <emulator>/usr/bin/qemu-system-i686</emulator>
+        <disk type='block' device='disk'>
+          <driver name='qemu' type='raw'/>
+          <source dev='/dev/HostVG/QEMUGuest1'/>
+          <target dev='hda' bus='ide'/>
+          <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+        </disk>
+        <controller type='usb' index='0'>
+          <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
+        </controller>
+        <controller type='ide' index='0'>
+          <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
+        </controller>
+        <controller type='pci' index='0' model='pci-root'/>
+        <input type='mouse' bus='ps2'/>
+        <input type='keyboard' bus='ps2'/>
+        <memballoon model='virtio'>
+          <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+        </memballoon>
+      </devices>
+    </domain>
+  </persistent>
+  <active>1</active>
+</domainsnapshot>
diff --git a/tests/domainsnapshotxml2xmltest.c b/tests/domainsnapshotxml2xmltest.c
index 2a07fe0..e51373d 100644
--- a/tests/domainsnapshotxml2xmltest.c
+++ b/tests/domainsnapshotxml2xmltest.c
@@ -204,6 +204,7 @@ mymain(void)
     DO_TEST_OUT("noparent", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", false);
     DO_TEST_OUT("metadata", "c7a5fdbd-edaf-9455-926a-d65c16db1809", false);
     DO_TEST_OUT("external_vm_redefine", "c7a5fdbd-edaf-9455-926a-d65c16db1809", false);
+    DO_TEST_OUT("active_inactive_domain", NULL, true);
 
     DO_TEST_INOUT("empty", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", false, false);
     DO_TEST_INOUT("noparent", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", false, false);
-- 
1.8.3.1




More information about the libvir-list mailing list