[PATCH 1/8] domain_conf: Introduce virDomainDeviceDefFormat

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

 



While we already have virDomainDeviceDefParse() we are still missing the
format counterpart. It's not the end the world for now, but the function
is going to be handy in next patches.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/conf/domain_conf.c   | 141 +++++++++++++++++++++++++----------------------
 src/conf/domain_conf.h   |   2 +
 src/libvirt_private.syms |   1 +
 3 files changed, 79 insertions(+), 65 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 05c1de4..7c92e51 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -18126,6 +18126,79 @@ virDomainNetFind(virDomainDefPtr def, const char *device)
     return net;
 }
 
+char *
+virDomainDeviceDefFormat(virDomainDeviceDefPtr def,
+                         unsigned int flags)
+{
+    int rc = -1;
+    virBuffer buf = VIR_BUFFER_INITIALIZER;
+
+    virCheckFlags(DUMPXML_FLAGS, NULL);
+
+    switch ((virDomainDeviceType) def->type) {
+    case VIR_DOMAIN_DEVICE_DISK:
+        rc = virDomainDiskDefFormat(&buf, def->data.disk, flags);
+        break;
+    case VIR_DOMAIN_DEVICE_LEASE:
+        rc = virDomainLeaseDefFormat(&buf, def->data.lease);
+        break;
+    case VIR_DOMAIN_DEVICE_FS:
+        rc = virDomainFSDefFormat(&buf, def->data.fs, flags);
+        break;
+    case VIR_DOMAIN_DEVICE_NET:
+        rc = virDomainNetDefFormat(&buf, def->data.net, flags);
+        break;
+    case VIR_DOMAIN_DEVICE_INPUT:
+        rc = virDomainInputDefFormat(&buf, def->data.input, flags);
+        break;
+    case VIR_DOMAIN_DEVICE_SOUND:
+        rc = virDomainSoundDefFormat(&buf, def->data.sound, flags);
+        break;
+    case VIR_DOMAIN_DEVICE_VIDEO:
+        rc = virDomainVideoDefFormat(&buf, def->data.video, flags);
+        break;
+    case VIR_DOMAIN_DEVICE_HOSTDEV:
+        rc = virDomainHostdevDefFormat(&buf, def->data.hostdev, flags);
+        break;
+    case VIR_DOMAIN_DEVICE_WATCHDOG:
+        rc = virDomainWatchdogDefFormat(&buf, def->data.watchdog, flags);
+        break;
+    case VIR_DOMAIN_DEVICE_CONTROLLER:
+        rc = virDomainControllerDefFormat(&buf, def->data.controller, flags);
+        break;
+    case VIR_DOMAIN_DEVICE_GRAPHICS:
+        rc = virDomainGraphicsDefFormat(&buf, def->data.graphics, flags);
+        break;
+    case VIR_DOMAIN_DEVICE_HUB:
+        rc = virDomainHubDefFormat(&buf, def->data.hub, flags);
+        break;
+    case VIR_DOMAIN_DEVICE_REDIRDEV:
+        rc = virDomainRedirdevDefFormat(&buf, def->data.redirdev, flags);
+        break;
+    case VIR_DOMAIN_DEVICE_RNG:
+        rc = virDomainRNGDefFormat(&buf, def->data.rng, flags);
+        break;
+    case VIR_DOMAIN_DEVICE_CHR:
+        rc = virDomainChrDefFormat(&buf, def->data.chr, flags);
+        break;
+    case VIR_DOMAIN_DEVICE_NONE:
+    case VIR_DOMAIN_DEVICE_SMARTCARD:
+    case VIR_DOMAIN_DEVICE_MEMBALLOON:
+    case VIR_DOMAIN_DEVICE_NVRAM:
+    case VIR_DOMAIN_DEVICE_LAST:
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Formatting XML of '%d' type "
+                         "is not implemented yet."),
+                       def->type);
+        return NULL;
+    }
+
+    if (rc < 0)
+        return NULL;
+
+    return virBufferContentAndReset(&buf);
+}
+
 /**
  * virDomainDeviceDefCopy:
  * @caps: Capabilities
@@ -18147,76 +18220,14 @@ virDomainDeviceDefCopy(virDomainDeviceDefPtr src,
                        virDomainXMLOptionPtr xmlopt)
 {
     virDomainDeviceDefPtr ret = NULL;
-    virBuffer buf = VIR_BUFFER_INITIALIZER;
-    int flags = VIR_DOMAIN_XML_INACTIVE;
+    unsigned int flags = VIR_DOMAIN_XML_INACTIVE;
     char *xmlStr = NULL;
-    int rc = -1;
 
-    switch ((virDomainDeviceType) src->type) {
-    case VIR_DOMAIN_DEVICE_DISK:
-        rc = virDomainDiskDefFormat(&buf, src->data.disk, flags);
-        break;
-    case VIR_DOMAIN_DEVICE_LEASE:
-        rc = virDomainLeaseDefFormat(&buf, src->data.lease);
-        break;
-    case VIR_DOMAIN_DEVICE_FS:
-        rc = virDomainFSDefFormat(&buf, src->data.fs, flags);
-        break;
-    case VIR_DOMAIN_DEVICE_NET:
-        rc = virDomainNetDefFormat(&buf, src->data.net, flags);
-        break;
-    case VIR_DOMAIN_DEVICE_INPUT:
-        rc = virDomainInputDefFormat(&buf, src->data.input, flags);
-        break;
-    case VIR_DOMAIN_DEVICE_SOUND:
-        rc = virDomainSoundDefFormat(&buf, src->data.sound, flags);
-        break;
-    case VIR_DOMAIN_DEVICE_VIDEO:
-        rc = virDomainVideoDefFormat(&buf, src->data.video, flags);
-        break;
-    case VIR_DOMAIN_DEVICE_HOSTDEV:
-        rc = virDomainHostdevDefFormat(&buf, src->data.hostdev, flags);
-        break;
-    case VIR_DOMAIN_DEVICE_WATCHDOG:
-        rc = virDomainWatchdogDefFormat(&buf, src->data.watchdog, flags);
-        break;
-    case VIR_DOMAIN_DEVICE_CONTROLLER:
-        rc = virDomainControllerDefFormat(&buf, src->data.controller, flags);
-        break;
-    case VIR_DOMAIN_DEVICE_GRAPHICS:
-        rc = virDomainGraphicsDefFormat(&buf, src->data.graphics, flags);
-        break;
-    case VIR_DOMAIN_DEVICE_HUB:
-        rc = virDomainHubDefFormat(&buf, src->data.hub, flags);
-        break;
-    case VIR_DOMAIN_DEVICE_REDIRDEV:
-        rc = virDomainRedirdevDefFormat(&buf, src->data.redirdev, flags);
-        break;
-    case VIR_DOMAIN_DEVICE_RNG:
-        rc = virDomainRNGDefFormat(&buf, src->data.rng, flags);
-        break;
-    case VIR_DOMAIN_DEVICE_CHR:
-        rc = virDomainChrDefFormat(&buf, src->data.chr, flags);
-        break;
-    case VIR_DOMAIN_DEVICE_NONE:
-    case VIR_DOMAIN_DEVICE_SMARTCARD:
-    case VIR_DOMAIN_DEVICE_MEMBALLOON:
-    case VIR_DOMAIN_DEVICE_NVRAM:
-    case VIR_DOMAIN_DEVICE_LAST:
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Copying definition of '%d' type "
-                         "is not implemented yet."),
-                       src->type);
-        goto cleanup;
-    }
+    if (!(xmlStr = virDomainDeviceDefFormat(src, flags)))
+        return ret;
 
-    if (rc < 0)
-        goto cleanup;
-
-    xmlStr = virBufferContentAndReset(&buf);
     ret = virDomainDeviceDefParse(xmlStr, def, caps, xmlopt, flags);
 
-cleanup:
     VIR_FREE(xmlStr);
     return ret;
 }
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 9414ebf..a65ee3e 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2310,6 +2310,8 @@ virDomainDeviceDefPtr virDomainDeviceDefParse(const char *xmlStr,
                                               virCapsPtr caps,
                                               virDomainXMLOptionPtr xmlopt,
                                               unsigned int flags);
+char * virDomainDeviceDefFormat(virDomainDeviceDefPtr def,
+                                unsigned int flags);
 virDomainDefPtr virDomainDefParseString(const char *xmlStr,
                                         virCapsPtr caps,
                                         virDomainXMLOptionPtr xmlopt,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 50e2f48..34c1b17 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -173,6 +173,7 @@ virDomainDeleteConfig;
 virDomainDeviceAddressIsValid;
 virDomainDeviceAddressTypeToString;
 virDomainDeviceDefCopy;
+virDomainDeviceDefFormat;
 virDomainDeviceDefFree;
 virDomainDeviceDefParse;
 virDomainDeviceFindControllerModel;
-- 
1.8.1.5

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