diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c index c3469eec9f23821a1ddd30374e65a60fe88b3a45..9148ca65fa1b89c2786f27a52f5345bbd22deab9 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 ce949812dd45c90e4a102fd4bc5084d3fda5903c..4584e0a7c4f169edad97f62ba949543bc66031d9 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 9396c4eb1be655d0f062afede78f0f54b68ad877..6b548129da556095c27af9aaf542392b8ade2032 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 787b357d8268183161e2c6cdfe55b5c455d4756e..2bd095fe1fc0f27adecd8f01ab67691192d97e8e 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");