[libvirt] [PATCH 4/6] normalize_xml: New internal API to format device XML

Osier Yang jyang at redhat.com
Mon Jan 9 14:29:12 UTC 2012


---
 src/conf/domain_conf.c   |   70 ++++++++++++++++++++++++++++++++++++++++++++++
 src/conf/domain_conf.h   |    2 +
 src/libvirt_private.syms |    1 +
 3 files changed, 73 insertions(+), 0 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 0190a81..f0ed479 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -11832,6 +11832,76 @@ virDomainDefFormat(virDomainDefPtr def, unsigned int flags)
     return virBufferContentAndReset(&buf);
 }
 
+char *
+virDomainDeviceDefFormat(virDomainDeviceDefPtr dev, unsigned int flags)
+{
+    virBuffer buf = VIR_BUFFER_INITIALIZER;
+
+    virCheckFlags(DUMPXML_FLAGS, NULL);
+
+    switch(dev->type) {
+        case VIR_DOMAIN_DEVICE_DISK:
+            if (virDomainDiskDefFormat(&buf, dev->data.disk, flags) < 0)
+                goto cleanup;
+            break;
+        case VIR_DOMAIN_DEVICE_LEASE:
+            if (virDomainLeaseDefFormat(&buf, dev->data.lease) < 0)
+                goto cleanup;
+            break;
+        case VIR_DOMAIN_DEVICE_FS:
+            if (virDomainFSDefFormat(&buf, dev->data.fs, flags) < 0)
+                goto cleanup;
+            break;
+        case VIR_DOMAIN_DEVICE_NET:
+            if (virDomainNetDefFormat(&buf, dev->data.net, flags) < 0)
+                goto cleanup;
+            break;
+        case VIR_DOMAIN_DEVICE_INPUT:
+            if (virDomainInputDefFormat(&buf, dev->data.input, flags) < 0)
+                goto cleanup;
+            break;
+        case VIR_DOMAIN_DEVICE_SOUND:
+            if (virDomainSoundDefFormat(&buf, dev->data.sound, flags) < 0)
+                goto cleanup;
+            break;
+        case VIR_DOMAIN_DEVICE_VIDEO:
+            if (virDomainVideoDefFormat(&buf, dev->data.video, flags) < 0)
+                goto cleanup;
+            break;
+        case VIR_DOMAIN_DEVICE_HOSTDEV:
+            if (virDomainHostdevDefFormat(&buf, dev->data.hostdev, flags) < 0)
+                goto cleanup;
+            break;
+        case VIR_DOMAIN_DEVICE_WATCHDOG:
+            if (virDomainWatchdogDefFormat(&buf, dev->data.watchdog, flags) < 0)
+                goto cleanup;
+            break;
+        case VIR_DOMAIN_DEVICE_CONTROLLER:
+            if (virDomainControllerDefFormat(&buf, dev->data.controller, flags) < 0)
+                goto cleanup;
+            break;
+        case VIR_DOMAIN_DEVICE_GRAPHICS:
+            if (virDomainGraphicsDefFormat(&buf, dev->data.graphics, flags) < 0)
+                goto cleanup;
+            break;
+        case VIR_DOMAIN_DEVICE_HUB:
+            if (virDomainHubDefFormat(&buf, dev->data.hub, flags) < 0)
+                goto cleanup;
+            break;
+        case VIR_DOMAIN_DEVICE_REDIRDEV:
+            if (virDomainRedirdevDefFormat(&buf, dev->data.redirdev, flags) < 0)
+                goto cleanup;
+            break;
+        default:
+            /* Shouldn't hit here. */
+            break;
+    }
+    return virBufferContentAndReset(&buf);
+
+cleanup:
+    virBufferFreeAndReset(&buf);
+    return NULL;
+}
 
 static char *virDomainObjFormat(virCapsPtr caps,
                                 virDomainObjPtr obj,
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 03aa5b6..9d726b2 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1780,6 +1780,8 @@ int virDomainDefFormatInternal(virDomainDefPtr def,
                                unsigned int flags,
                                virBufferPtr buf);
 
+char *virDomainDeviceDefFormat(virDomainDeviceDefPtr def,
+                               unsigned int flags);
 int virDomainCpuSetParse(const char *str,
                          char sep,
                          char *cpuset,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index ac2c52e..5dd4006 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -282,6 +282,7 @@ virDomainDeviceAddressIsValid;
 virDomainDeviceAddressPciMultiTypeFromString;
 virDomainDeviceAddressPciMultiTypeToString;
 virDomainDeviceAddressTypeToString;
+virDomainDeviceDefFormat;
 virDomainDeviceDefFree;
 virDomainDeviceDefParse;
 virDomainDeviceInfoIterate;
-- 
1.7.7.3




More information about the libvir-list mailing list