From 40c284f0a6b53a182af7b12173bcb5dd3eb0c826 Mon Sep 17 00:00:00 2001 From: Tomasz Flendrich Date: Sat, 23 Jul 2016 03:47:06 +0200 Subject: [PATCH] add virDomainVirtioSerialAddrSetCreateFromDomain The address sets (pci, ccw, virtio serial) are currently cached in qemu private data, but all the information required to recreate these sets is in the domain definition. Therefore I am removing the redundant data and adding a way to recalculate these sets. Add a function that calculates the virtio serial address set from the domain definition. Credit goes to Cole Robinson. --- src/conf/domain_addr.c | 31 +++++++++++++++++++++++++++++++ src/conf/domain_addr.h | 3 +++ src/libvirt_private.syms | 1 + src/qemu/qemu_domain_address.c | 9 +-------- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c index c3469eec9f..9148ca65fa 100644 --- a/src/conf/domain_addr.c +++ b/src/conf/domain_addr.c @@ -975,6 +975,37 @@ virDomainVirtioSerialAddrSetFree(virDomainVirtioSerialAddrSetPtr addrs) } } + +/* 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 = NULL; + 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; + addrs = NULL; + cleanup: + virDomainVirtioSerialAddrSetFree(addrs); + return ret; +} + static int virDomainVirtioSerialAddrSetAutoaddController(virDomainDefPtr def, virDomainVirtioSerialAddrSetPtr addrs, diff --git a/src/conf/domain_addr.h b/src/conf/domain_addr.h index ce949812dd..4584e0a7c4 100644 --- a/src/conf/domain_addr.h +++ b/src/conf/domain_addr.h @@ -208,6 +208,9 @@ virDomainVirtioSerialAddrSetAddControllers(virDomainVirtioSerialAddrSetPtr addrs ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); void virDomainVirtioSerialAddrSetFree(virDomainVirtioSerialAddrSetPtr addrs); +virDomainVirtioSerialAddrSetPtr +virDomainVirtioSerialAddrSetCreateFromDomain(virDomainDefPtr def) + ATTRIBUTE_NONNULL(1); bool virDomainVirtioSerialAddrIsComplete(virDomainDeviceInfoPtr info); int diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 9396c4eb1b..6b548129da 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -126,6 +126,7 @@ virDomainVirtioSerialAddrRelease; virDomainVirtioSerialAddrReserve; virDomainVirtioSerialAddrSetAddControllers; virDomainVirtioSerialAddrSetCreate; +virDomainVirtioSerialAddrSetCreateFromDomain; virDomainVirtioSerialAddrSetFree; diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 787b357d82..2bd095fe1f 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -114,14 +114,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"); -- GitLab