[PATCH v2 05/11] domain: Expand virDomainDefFormatInternal with snapshots

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

 



Make it possible to grab all snapshot XMLs via a single API
call, by adding a new internal flag.  All callers are adjusted,
for now passing NULL and not using the new flag. A new wrapper
virDomainDefFormatFull() is added to make it easier for the
next patch to add a few callers without having to revisit all
existing clients of virDomainDefFormat().

Signed-off-by: Eric Blake <eblake@xxxxxxxxxx>
---
 src/conf/domain_conf.h      |  8 +++++
 src/conf/domain_conf.c      | 58 +++++++++++++++++++++++++++++++------
 src/conf/snapshot_conf.c    |  4 +--
 src/network/bridge_driver.c |  3 +-
 src/qemu/qemu_domain.c      |  2 +-
 5 files changed, 62 insertions(+), 13 deletions(-)

diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 9bccd8bcd1..9b13c147da 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -3047,6 +3047,7 @@ typedef enum {
     VIR_DOMAIN_DEF_FORMAT_ALLOW_ROM       = 1 << 6,
     VIR_DOMAIN_DEF_FORMAT_ALLOW_BOOT      = 1 << 7,
     VIR_DOMAIN_DEF_FORMAT_CLOCK_ADJUST    = 1 << 8,
+    VIR_DOMAIN_DEF_FORMAT_SNAPSHOTS       = 1 << 9,
 } virDomainDefFormatFlags;

 /* Use these flags to skip specific domain ABI consistency checks done
@@ -3124,12 +3125,19 @@ unsigned int virDomainDefFormatConvertXMLFlags(unsigned int flags);
 char *virDomainDefFormat(virDomainDefPtr def,
                          virCapsPtr caps,
                          unsigned int flags);
+char *virDomainDefFormatFull(virDomainDefPtr def,
+                             virCapsPtr caps,
+                             virDomainSnapshotObjListPtr snapshots,
+                             virDomainSnapshotObjPtr current_snapshot,
+                             unsigned int flags);
 char *virDomainObjFormat(virDomainXMLOptionPtr xmlopt,
                          virDomainObjPtr obj,
                          virCapsPtr caps,
                          unsigned int flags);
 int virDomainDefFormatInternal(virDomainDefPtr def,
                                virCapsPtr caps,
+                               virDomainSnapshotObjListPtr snapshots,
+                               virDomainSnapshotObjPtr current_snapshot,
                                unsigned int flags,
                                virBufferPtr buf,
                                virDomainXMLOptionPtr xmlopt);
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index ceeb247ef4..46ae79e738 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1,7 +1,7 @@
 /*
  * domain_conf.c: domain XML processing
  *
- * Copyright (C) 2006-2016 Red Hat, Inc.
+ * Copyright (C) 2006-2019 Red Hat, Inc.
  * Copyright (C) 2006-2008 Daniel P. Berrange
  * Copyright (c) 2015 SUSE LINUX Products GmbH, Nuernberg, Germany.
  *
@@ -28212,6 +28212,8 @@ virDomainVsockDefFormat(virBufferPtr buf,
 int
 virDomainDefFormatInternal(virDomainDefPtr def,
                            virCapsPtr caps,
+                           virDomainSnapshotObjListPtr snapshots,
+                           virDomainSnapshotObjPtr current_snapshot,
                            unsigned int flags,
                            virBufferPtr buf,
                            virDomainXMLOptionPtr xmlopt)
@@ -28229,9 +28231,16 @@ virDomainDefFormatInternal(virDomainDefPtr def,
                   VIR_DOMAIN_DEF_FORMAT_STATUS |
                   VIR_DOMAIN_DEF_FORMAT_ACTUAL_NET |
                   VIR_DOMAIN_DEF_FORMAT_PCI_ORIG_STATES |
-                  VIR_DOMAIN_DEF_FORMAT_CLOCK_ADJUST,
+                  VIR_DOMAIN_DEF_FORMAT_CLOCK_ADJUST |
+                  VIR_DOMAIN_DEF_FORMAT_SNAPSHOTS,
                   -1);

+    if ((flags & VIR_DOMAIN_DEF_FORMAT_SNAPSHOTS) && !snapshots) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("snapshots requested but not provided"));
+        goto error;
+    }
+
     if (!(type = virDomainVirtTypeToString(def->virtType))) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("unexpected domain type %d"), def->virtType);
@@ -29016,6 +29025,23 @@ virDomainDefFormatInternal(virDomainDefPtr def,

     virDomainSEVDefFormat(buf, def->sev);

+    if (flags & VIR_DOMAIN_DEF_FORMAT_SNAPSHOTS) {
+        unsigned int snapflags = flags & VIR_DOMAIN_DEF_FORMAT_SECURE ?
+            VIR_DOMAIN_SNAPSHOT_FORMAT_SECURE : 0;
+
+        virBufferAddLit(buf, "<snapshots");
+        if (current_snapshot)
+            virBufferEscapeString(buf, " current='%s'",
+                                  current_snapshot->def->name);
+        virBufferAddLit(buf, ">\n");
+        virBufferAdjustIndent(buf, 2);
+        if (virDomainSnapshotObjListFormat(buf, uuidstr, snapshots, caps,
+                                           xmlopt, snapflags))
+            goto error;
+        virBufferAdjustIndent(buf, -2);
+        virBufferAddLit(buf, "</snapshots>\n");
+    }
+
     virBufferAdjustIndent(buf, -2);
     virBufferAddLit(buf, "</domain>\n");

@@ -29051,16 +29077,29 @@ unsigned int virDomainDefFormatConvertXMLFlags(unsigned int flags)
 }


+char *
+virDomainDefFormatFull(virDomainDefPtr def, virCapsPtr caps,
+                       virDomainSnapshotObjListPtr snapshots,
+                       virDomainSnapshotObjPtr current_snapshot,
+                       unsigned int flags)
+{
+    virBuffer buf = VIR_BUFFER_INITIALIZER;
+
+    virCheckFlags(VIR_DOMAIN_DEF_FORMAT_COMMON_FLAGS |
+                  VIR_DOMAIN_DEF_FORMAT_SNAPSHOTS, NULL);
+    if (virDomainDefFormatInternal(def, caps, snapshots, current_snapshot,
+                                   flags, &buf, NULL) < 0)
+        return NULL;
+
+    return virBufferContentAndReset(&buf);
+}
+
+
 char *
 virDomainDefFormat(virDomainDefPtr def, virCapsPtr caps, unsigned int flags)
 {
-    virBuffer buf = VIR_BUFFER_INITIALIZER;
-
     virCheckFlags(VIR_DOMAIN_DEF_FORMAT_COMMON_FLAGS, NULL);
-    if (virDomainDefFormatInternal(def, caps, flags, &buf, NULL) < 0)
-        return NULL;
-
-    return virBufferContentAndReset(&buf);
+    return virDomainDefFormatFull(def, caps, NULL, NULL, flags);
 }


@@ -29092,7 +29131,8 @@ virDomainObjFormat(virDomainXMLOptionPtr xmlopt,
         xmlopt->privateData.format(&buf, obj) < 0)
         goto error;

-    if (virDomainDefFormatInternal(obj->def, caps, flags, &buf, xmlopt) < 0)
+    if (virDomainDefFormatInternal(obj->def, caps, NULL, NULL, flags, &buf,
+                                   xmlopt) < 0)
         goto error;

     virBufferAdjustIndent(&buf, -2);
diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c
index a572da5b58..963dc10247 100644
--- a/src/conf/snapshot_conf.c
+++ b/src/conf/snapshot_conf.c
@@ -754,8 +754,8 @@ virDomainSnapshotDefFormatInternal(virBufferPtr buf,
     }

     if (def->dom) {
-        if (virDomainDefFormatInternal(def->dom, caps, domainflags, buf,
-                                       xmlopt) < 0)
+        if (virDomainDefFormatInternal(def->dom, caps, NULL, NULL, domainflags,
+                                       buf, xmlopt) < 0)
             goto error;
     } else if (uuidstr) {
         virBufferAddLit(buf, "<domain>\n");
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index b3ca5b8a15..bf2045a753 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -226,7 +226,8 @@ networkRunHook(virNetworkObjPtr obj,
             goto cleanup;
         if (virNetworkDefFormatBuf(&buf, def, 0) < 0)
             goto cleanup;
-        if (dom && virDomainDefFormatInternal(dom, NULL, 0, &buf, NULL) < 0)
+        if (dom && virDomainDefFormatInternal(dom, NULL, NULL, NULL, 0, &buf,
+                                              NULL) < 0)
             goto cleanup;

         virBufferAdjustIndent(&buf, -2);
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 84b923fbbb..cb1665c8f9 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -7881,7 +7881,7 @@ qemuDomainDefFormatBufInternal(virQEMUDriverPtr driver,
     }

  format:
-    ret = virDomainDefFormatInternal(def, caps,
+    ret = virDomainDefFormatInternal(def, caps, NULL, NULL,
                                      virDomainDefFormatConvertXMLFlags(flags),
                                      buf, driver->xmlopt);

-- 
2.20.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]

  Powered by Linux