提交 f16600ff 编写于 作者: J Ján Tomko

Split out qemuDomainEnsureVirtioAddress

Split out the common code responsible for reserving/assigning
PCI/CCW addresses for virtio disks into a helper function
for reuse by other virtio devices.
上级 5ec76b0c
......@@ -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;
}
......@@ -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__
......
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册