diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index c4485d4ab57c6a765d5310305e29e260f52e1801..b94b73eaa23cb878661e13d9db50ece538ec5f0d 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -2904,3 +2904,48 @@ qemuDomainReleaseDeviceAddress(virDomainObjPtr vm, VIR_WARN("Unable to release USB address on %s", NULLSTR(devstr)); } + + +int +qemuDomainEnsureVirtioAddress(bool *releaseAddr, + virDomainObjPtr vm, + virDomainDeviceDefPtr dev, + const char *devicename) +{ + virDomainDeviceInfoPtr info = virDomainDeviceGetInfo(dev); + qemuDomainObjPrivatePtr priv = vm->privateData; + virDomainCCWAddressSetPtr ccwaddrs = NULL; + virQEMUDriverPtr driver = priv->driver; + int ret = -1; + + if (!info->type) { + if (qemuDomainIsS390CCW(vm->def) && + virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_VIRTIO_CCW)) + info->type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW; + else if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_VIRTIO_S390)) + info->type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390; + } else { + if (!qemuDomainCheckCCWS390AddressSupport(vm->def, *info, priv->qemuCaps, + devicename)) + return -1; + } + + if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW) { + if (!(ccwaddrs = qemuDomainCCWAddrSetCreateFromDomain(vm->def))) + goto cleanup; + if (virDomainCCWAddressAssign(info, ccwaddrs, + !info->addr.ccw.assigned) < 0) + goto cleanup; + } else if (!info->type || + info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) { + if (qemuDomainEnsurePCIAddress(vm, dev, driver) < 0) + goto cleanup; + *releaseAddr = true; + } + + ret = 0; + + cleanup: + virDomainCCWAddressSetFree(ccwaddrs); + return ret; +} diff --git a/src/qemu/qemu_domain_address.h b/src/qemu/qemu_domain_address.h index b5644fa9c240d8f93511947a7012cde16f1bb541..e951a4c884901f8fdfe7462bd56217f4fb5ded22 100644 --- a/src/qemu/qemu_domain_address.h +++ b/src/qemu/qemu_domain_address.h @@ -59,6 +59,10 @@ qemuDomainCCWAddrSetCreateFromDomain(virDomainDefPtr def) int qemuDomainAssignMemoryDeviceSlot(virDomainDefPtr def, virDomainMemoryDefPtr mem); +int qemuDomainEnsureVirtioAddress(bool *releaseAddr, + virDomainObjPtr vm, + virDomainDeviceDefPtr dev, + const char *devicename); # define __QEMU_DOMAIN_ADDRESS_H__ diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 1885123c692ff9171bca3806f491445fe9c8263e..e7de8095366e8aca2aea226e755da4c1536bf442 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -363,7 +363,6 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn, bool driveAdded = false; bool secobjAdded = false; bool encobjAdded = false; - virDomainCCWAddressSetPtr ccwaddrs = NULL; virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); const char *src = virDomainDiskGetSource(disk); virJSONValuePtr secobjProps = NULL; @@ -372,33 +371,12 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn, qemuDomainSecretInfoPtr secinfo; qemuDomainSecretInfoPtr encinfo; - if (!disk->info.type) { - if (qemuDomainIsS390CCW(vm->def) && - virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_VIRTIO_CCW)) - disk->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW; - else if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_VIRTIO_S390)) - disk->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390; - } else { - if (!qemuDomainCheckCCWS390AddressSupport(vm->def, disk->info, priv->qemuCaps, - disk->dst)) - goto cleanup; - } - if (qemuDomainPrepareDisk(driver, vm, disk, NULL, false) < 0) goto cleanup; - if (disk->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW) { - if (!(ccwaddrs = qemuDomainCCWAddrSetCreateFromDomain(vm->def))) - goto error; - if (virDomainCCWAddressAssign(&disk->info, ccwaddrs, - !disk->info.addr.ccw.assigned) < 0) - goto error; - } else if (!disk->info.type || - disk->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) { - if (qemuDomainEnsurePCIAddress(vm, &dev, driver) < 0) - goto error; - } - releaseaddr = true; + if (qemuDomainEnsureVirtioAddress(&releaseaddr, vm, &dev, disk->dst) < 0) + goto error; + if (qemuAssignDeviceDiskAlias(vm->def, disk, priv->qemuCaps) < 0) goto error; @@ -477,7 +455,6 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn, virJSONValueFree(secobjProps); virJSONValueFree(encobjProps); qemuDomainSecretDiskDestroy(disk); - virDomainCCWAddressSetFree(ccwaddrs); VIR_FREE(devstr); VIR_FREE(drivestr); VIR_FREE(drivealias);