]> xenbits.xensource.com Git - libvirt.git/commitdiff
snapshot: Give virDomainSnapshotDefFormat its own flags
authorEric Blake <eblake@redhat.com>
Fri, 15 Feb 2019 20:43:43 +0000 (14:43 -0600)
committerEric Blake <eblake@redhat.com>
Thu, 7 Mar 2019 23:31:40 +0000 (17:31 -0600)
virDomainSnapshotDefFormat currently takes two sets of knobs:
an 'unsigned int flags' argument that can currently just be
VIR_DOMAIN_DEF_FORMAT_SECURE, and an 'int internal' argument used as
a bool to determine whether to output an additional element.  It
then reuses the 'flags' knob to call into virDomainDefFormatInternal(),
which takes a different set of flags. In fact, prior to commit 0ecd6851
(1.2.12), the 'flags' argument actually took the public
VIR_DOMAIN_XML_SECURE, which was even more confusing.  Let's borrow
from the style of that earlier commit, by introducing a function
for translating from the public flags (VIR_DOMAIN_SNAPSHOT_XML_SECURE
was just recently introduced) into a new enum specific to snapshot
formatting, and adjust all callers to use snapshot-specific enum
values when formatting, and where the formatter now uses a new
variable 'domainflags' to make it obvious when we are translating
from snapshot flags back to domain flags.  We don't even have to
use the conversion function for drivers that don't accept the
public VIR_DOMAIN_SNAPSHOT_XML_SECURE flag.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
src/conf/snapshot_conf.c
src/conf/snapshot_conf.h
src/esx/esx_driver.c
src/libvirt_private.syms
src/qemu/qemu_domain.c
src/qemu/qemu_driver.c
src/test/test_driver.c
src/vbox/vbox_common.c
src/vz/vz_driver.c
tests/domainsnapshotxml2xmltest.c

index 054721012cad839bf45c1f094de3e670a17f23a8..9f97a9efac6d2c16ef1d8101cfd00b26586fef50 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * snapshot_conf.c: domain snapshot XML processing
  *
- * Copyright (C) 2006-2014 Red Hat, Inc.
+ * Copyright (C) 2006-2019 Red Hat, Inc.
  * Copyright (C) 2006-2008 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -652,6 +652,22 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def,
     return ret;
 }
 
+
+/* Converts public VIR_DOMAIN_SNAPSHOT_XML_* into
+ * VIR_DOMAIN_SNAPSHOT_FORMAT_* flags, and silently ignores any other
+ * flags. */
+unsigned int
+virDomainSnapshotFormatConvertXMLFlags(unsigned int flags)
+{
+    unsigned int formatFlags = 0;
+
+    if (flags & VIR_DOMAIN_SNAPSHOT_XML_SECURE)
+        formatFlags |= VIR_DOMAIN_SNAPSHOT_FORMAT_SECURE;
+
+    return formatFlags;
+}
+
+
 static int
 virDomainSnapshotDiskDefFormat(virBufferPtr buf,
                                virDomainSnapshotDiskDefPtr disk,
@@ -692,15 +708,17 @@ virDomainSnapshotDefFormat(const char *uuidstr,
                            virDomainSnapshotDefPtr def,
                            virCapsPtr caps,
                            virDomainXMLOptionPtr xmlopt,
-                           unsigned int flags,
-                           int internal)
+                           unsigned int flags)
 {
     virBuffer buf = VIR_BUFFER_INITIALIZER;
     size_t i;
+    int domainflags = VIR_DOMAIN_DEF_FORMAT_INACTIVE;
 
-    virCheckFlags(VIR_DOMAIN_DEF_FORMAT_SECURE, NULL);
+    virCheckFlags(VIR_DOMAIN_SNAPSHOT_FORMAT_SECURE |
+                  VIR_DOMAIN_SNAPSHOT_FORMAT_INTERNAL, NULL);
 
-    flags |= VIR_DOMAIN_DEF_FORMAT_INACTIVE;
+    if (flags & VIR_DOMAIN_SNAPSHOT_FORMAT_SECURE)
+        domainflags |= VIR_DOMAIN_DEF_FORMAT_SECURE;
 
     virBufferAddLit(&buf, "<domainsnapshot>\n");
     virBufferAdjustIndent(&buf, 2);
@@ -742,7 +760,8 @@ virDomainSnapshotDefFormat(const char *uuidstr,
     }
 
     if (def->dom) {
-        if (virDomainDefFormatInternal(def->dom, caps, flags, &buf, xmlopt) < 0)
+        if (virDomainDefFormatInternal(def->dom, caps, domainflags, &buf,
+                                       xmlopt) < 0)
             goto error;
     } else if (uuidstr) {
         virBufferAddLit(&buf, "<domain>\n");
@@ -756,7 +775,7 @@ virDomainSnapshotDefFormat(const char *uuidstr,
                                virDomainXMLOptionGetSaveCookie(xmlopt)) < 0)
         goto error;
 
-    if (internal)
+    if (flags & VIR_DOMAIN_SNAPSHOT_FORMAT_INTERNAL)
         virBufferAsprintf(&buf, "<active>%d</active>\n", def->current);
 
     virBufferAdjustIndent(&buf, -2);
index 5f2cda8848d90eca7a397d17ea1163bc761f1fe0..3577f7654382363283711e18f2b1a4a08c64fb10 100644 (file)
@@ -116,6 +116,13 @@ typedef enum {
     VIR_DOMAIN_SNAPSHOT_PARSE_OFFLINE  = 1 << 3,
 } virDomainSnapshotParseFlags;
 
+typedef enum {
+    VIR_DOMAIN_SNAPSHOT_FORMAT_SECURE   = 1 << 0,
+    VIR_DOMAIN_SNAPSHOT_FORMAT_INTERNAL = 1 << 1,
+} virDomainSnapshotFormatFlags;
+
+unsigned int virDomainSnapshotFormatConvertXMLFlags(unsigned int flags);
+
 virDomainSnapshotDefPtr virDomainSnapshotDefParseString(const char *xmlStr,
                                                         virCapsPtr caps,
                                                         virDomainXMLOptionPtr xmlopt,
@@ -130,8 +137,7 @@ char *virDomainSnapshotDefFormat(const char *uuidstr,
                                  virDomainSnapshotDefPtr def,
                                  virCapsPtr caps,
                                  virDomainXMLOptionPtr xmlopt,
-                                 unsigned int flags,
-                                 int internal);
+                                 unsigned int flags);
 int virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr snapshot,
                                 int default_snapshot,
                                 bool require_match);
index afebd785663bb49c1e87aeecf2eda42b212779b5..c6d112268fca9634a6f1ea2a12fdb34e650ecb34 100644 (file)
@@ -4204,7 +4204,6 @@ esxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
     virUUIDFormat(snapshot->domain->uuid, uuid_string);
 
     xml = virDomainSnapshotDefFormat(uuid_string, &def, priv->caps, priv->xmlopt,
-                                     virDomainDefFormatConvertXMLFlags(flags),
                                      0);
 
  cleanup:
index d2a240fc7a10359f1c8666592527169e51d9557d..b5d65c99c995f5b24971e68dc9ab9574eea7c7a1 100644 (file)
@@ -891,6 +891,7 @@ virDomainSnapshotFindByName;
 virDomainSnapshotForEach;
 virDomainSnapshotForEachChild;
 virDomainSnapshotForEachDescendant;
+virDomainSnapshotFormatConvertXMLFlags;
 virDomainSnapshotIsExternal;
 virDomainSnapshotLocationTypeFromString;
 virDomainSnapshotLocationTypeToString;
index 3756ff309ad1864f172945f4c505645cb4a67582..0cfb52971e8ce96fb767dbab353e4f9912718903 100644 (file)
@@ -8410,8 +8410,7 @@ qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm,
     virUUIDFormat(vm->def->uuid, uuidstr);
     newxml = virDomainSnapshotDefFormat(
         uuidstr, snapshot->def, caps, xmlopt,
-        virDomainDefFormatConvertXMLFlags(QEMU_DOMAIN_FORMAT_LIVE_FLAGS),
-        1);
+        VIR_DOMAIN_SNAPSHOT_FORMAT_SECURE | VIR_DOMAIN_SNAPSHOT_FORMAT_INTERNAL);
     if (newxml == NULL)
         return -1;
 
index bde3f9b8df0c8c1192b6cf7c2ca7ba6ccdddc93e..205e544d92535850be185dc8688512568356a247 100644 (file)
@@ -16266,8 +16266,7 @@ qemuDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
 
     xml = virDomainSnapshotDefFormat(uuidstr, snap->def,
                                      driver->caps, driver->xmlopt,
-                                     virDomainDefFormatConvertXMLFlags(flags),
-                                     0);
+                                     virDomainSnapshotFormatConvertXMLFlags(flags));
 
  cleanup:
     virDomainObjEndAPI(&vm);
index 490a423b9697cb94fe028a9340a6c06b7525123a..ef754658f3e5df6643587e5bb871b9ccf817c17a 100644 (file)
@@ -6209,8 +6209,7 @@ testDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
 
     xml = virDomainSnapshotDefFormat(uuidstr, snap->def, privconn->caps,
                                      privconn->xmlopt,
-                                     virDomainDefFormatConvertXMLFlags(flags),
-                                     0);
+                                     virDomainSnapshotFormatConvertXMLFlags(flags));
 
  cleanup:
     virDomainObjEndAPI(&vm);
index f8ae23bafb11f007bb7e7a0b6c8a1eb31c5d0efe..c410514d370b6abcd44bba82dfca280679ab5b40 100644 (file)
@@ -5375,7 +5375,10 @@ vboxSnapshotRedefine(virDomainPtr dom,
         VIR_FREE(currentSnapshotXmlFilePath);
         if (virAsprintf(&currentSnapshotXmlFilePath, "%s%s.xml", machineLocationPath, snapshotMachineDesc->currentSnapshot) < 0)
             goto cleanup;
-        char *snapshotContent = virDomainSnapshotDefFormat(NULL, def, data->caps, data->xmlopt, VIR_DOMAIN_DEF_FORMAT_SECURE, 0);
+        char *snapshotContent = virDomainSnapshotDefFormat(NULL, def,
+                                                           data->caps,
+                                                           data->xmlopt,
+                                                           VIR_DOMAIN_SNAPSHOT_FORMAT_SECURE);
         if (snapshotContent == NULL) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("Unable to get snapshot content"));
@@ -6322,9 +6325,7 @@ static char *vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
 
     virUUIDFormat(dom->uuid, uuidstr);
     memcpy(def->dom->uuid, dom->uuid, VIR_UUID_BUFLEN);
-    ret = virDomainSnapshotDefFormat(uuidstr, def, data->caps, data->xmlopt,
-                                      virDomainDefFormatConvertXMLFlags(flags),
-                                      0);
+    ret = virDomainSnapshotDefFormat(uuidstr, def, data->caps, data->xmlopt, 0);
 
  cleanup:
     virDomainSnapshotDefFree(def);
index 2d2eaf88a67b6015e0f3de8d818841a147d1edc2..066d6175242ea021298528744578cf743d0e4b02 100644 (file)
@@ -2291,8 +2291,7 @@ vzDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot, unsigned int flags)
 
     xml = virDomainSnapshotDefFormat(uuidstr, snap->def, privconn->driver->caps,
                                      privconn->driver->xmlopt,
-                                     virDomainDefFormatConvertXMLFlags(flags),
-                                     0);
+                                     virDomainSnapshotFormatConvertXMLFlags(flags));
 
  cleanup:
     virDomainSnapshotObjListFree(snapshots);
index 2a07fe0789f1d823e1f181fa071c33015d2798f4..9eb71780fcfcfe84884aef3734d31914853dd698 100644 (file)
@@ -78,13 +78,16 @@ testCompareXMLToXMLFiles(const char *inxml,
     char *actual = NULL;
     int ret = -1;
     virDomainSnapshotDefPtr def = NULL;
-    unsigned int flags = VIR_DOMAIN_SNAPSHOT_PARSE_DISKS;
+    unsigned int parseflags = VIR_DOMAIN_SNAPSHOT_PARSE_DISKS;
+    unsigned int formatflags = VIR_DOMAIN_SNAPSHOT_FORMAT_SECURE;
 
-    if (internal)
-        flags |= VIR_DOMAIN_SNAPSHOT_PARSE_INTERNAL;
+    if (internal) {
+        parseflags |= VIR_DOMAIN_SNAPSHOT_PARSE_INTERNAL;
+        formatflags |= VIR_DOMAIN_SNAPSHOT_FORMAT_INTERNAL;
+    }
 
     if (redefine)
-        flags |= VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE;
+        parseflags |= VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE;
 
     if (virTestLoadFile(inxml, &inXmlData) < 0)
         goto cleanup;
@@ -94,13 +97,12 @@ testCompareXMLToXMLFiles(const char *inxml,
 
     if (!(def = virDomainSnapshotDefParseString(inXmlData, driver.caps,
                                                 driver.xmlopt,
-                                                flags)))
+                                                parseflags)))
         goto cleanup;
 
     if (!(actual = virDomainSnapshotDefFormat(uuid, def, driver.caps,
                                               driver.xmlopt,
-                                              VIR_DOMAIN_DEF_FORMAT_SECURE,
-                                              internal)))
+                                              formatflags)))
         goto cleanup;
 
     if (!redefine) {