diff mbox

[1/3] domain: Add virDomainVirtioSerialAddrSetCreateFromDomain

Message ID c6acc5e6fccdd4077fb2ba545c8886ec974dab66.1463249776.git.crobinso@redhat.com
State New
Headers show

Commit Message

Cole Robinson May 14, 2016, 6:25 p.m. UTC
This handles all the bits needed for generating a
virDomainVirtioSerialAddrSetPtr by inspecting a virDomainDefPtr
---
 src/conf/domain_addr.c         | 35 ++++++++++++++++++++++++++++++++---
 src/conf/domain_addr.h         |  7 ++-----
 src/libvirt_private.syms       |  3 +--
 src/qemu/qemu_domain_address.c |  9 +--------
 4 files changed, 36 insertions(+), 18 deletions(-)

-- 
2.7.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
diff mbox

Patch

diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c
index acd8ce6..01a3ae1 100644
--- a/src/conf/domain_addr.c
+++ b/src/conf/domain_addr.c
@@ -845,7 +845,7 @@  virDomainCCWAddressSetCreate(void)
  *
  * Allocates an address set for virtio serial addresses
  */
-virDomainVirtioSerialAddrSetPtr
+static virDomainVirtioSerialAddrSetPtr
 virDomainVirtioSerialAddrSetCreate(void)
 {
     virDomainVirtioSerialAddrSetPtr ret = NULL;
@@ -947,7 +947,7 @@  virDomainVirtioSerialAddrSetAddController(virDomainVirtioSerialAddrSetPtr addrs,
  * Adds virtio serial ports of controllers present in the domain definition
  * to the address set.
  */
-int
+static int
 virDomainVirtioSerialAddrSetAddControllers(virDomainVirtioSerialAddrSetPtr addrs,
                                            virDomainDefPtr def)
 {
@@ -962,7 +962,6 @@  virDomainVirtioSerialAddrSetAddControllers(virDomainVirtioSerialAddrSetPtr addrs
     return 0;
 }
 
-
 void
 virDomainVirtioSerialAddrSetFree(virDomainVirtioSerialAddrSetPtr addrs)
 {
@@ -1085,6 +1084,36 @@  virDomainVirtioSerialAddrNextFromController(virDomainVirtioSerialAddrSetPtr addr
     return 0;
 }
 
+/* virDomainVirtioSerialAddrSetCreateFromDomain
+ *
+ * @def: Domain def to introspect
+ *
+ * Inspect the domain definition and return an address set containing
+ * every virtio serial address we find
+ */
+virDomainVirtioSerialAddrSetPtr
+virDomainVirtioSerialAddrSetCreateFromDomain(virDomainDefPtr def)
+{
+    virDomainVirtioSerialAddrSetPtr addrs;
+    virDomainVirtioSerialAddrSetPtr ret = NULL;
+
+    if (!(addrs = virDomainVirtioSerialAddrSetCreate()))
+        goto cleanup;
+
+    if (virDomainVirtioSerialAddrSetAddControllers(addrs, def) < 0)
+        goto cleanup;
+
+    if (virDomainDeviceInfoIterate(def, virDomainVirtioSerialAddrReserve,
+                                   addrs) < 0)
+        goto cleanup;
+
+    ret = addrs;
+ cleanup:
+    if (!ret)
+        virDomainVirtioSerialAddrSetFree(addrs);
+    return ret;
+}
+
 /* virDomainVirtioSerialAddrAutoAssign
  *
  * reserve a virtio serial address of the device (if it has one)
diff --git a/src/conf/domain_addr.h b/src/conf/domain_addr.h
index f3eda89..c29f85a 100644
--- a/src/conf/domain_addr.h
+++ b/src/conf/domain_addr.h
@@ -201,11 +201,8 @@  typedef struct _virDomainVirtioSerialAddrSet virDomainVirtioSerialAddrSet;
 typedef virDomainVirtioSerialAddrSet *virDomainVirtioSerialAddrSetPtr;
 
 virDomainVirtioSerialAddrSetPtr
-virDomainVirtioSerialAddrSetCreate(void);
-int
-virDomainVirtioSerialAddrSetAddControllers(virDomainVirtioSerialAddrSetPtr addrs,
-                                           virDomainDefPtr def)
-    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+virDomainVirtioSerialAddrSetCreateFromDomain(virDomainDefPtr def)
+    ATTRIBUTE_NONNULL(1);
 void
 virDomainVirtioSerialAddrSetFree(virDomainVirtioSerialAddrSetPtr addrs);
 bool
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index fb24808..5530e05 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -113,8 +113,7 @@  virDomainVirtioSerialAddrAutoAssign;
 virDomainVirtioSerialAddrIsComplete;
 virDomainVirtioSerialAddrRelease;
 virDomainVirtioSerialAddrReserve;
-virDomainVirtioSerialAddrSetAddControllers;
-virDomainVirtioSerialAddrSetCreate;
+virDomainVirtioSerialAddrSetCreateFromDomain;
 virDomainVirtioSerialAddrSetFree;
 
 
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index 9c8c262..e17b34b 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -115,14 +115,7 @@  qemuDomainAssignVirtioSerialAddresses(virDomainDefPtr def,
     virDomainVirtioSerialAddrSetPtr addrs = NULL;
     qemuDomainObjPrivatePtr priv = NULL;
 
-    if (!(addrs = virDomainVirtioSerialAddrSetCreate()))
-        goto cleanup;
-
-    if (virDomainVirtioSerialAddrSetAddControllers(addrs, def) < 0)
-        goto cleanup;
-
-    if (virDomainDeviceInfoIterate(def, virDomainVirtioSerialAddrReserve,
-                                   addrs) < 0)
+    if (!(addrs = virDomainVirtioSerialAddrSetCreateFromDomain(def)))
         goto cleanup;
 
     VIR_DEBUG("Finished reserving existing ports");