qemu: hotplug: Assume QEMU_CAPS_DEVICE in qemuDomainAttachVirtioDiskDevice

After killing one of the conditionals it's now guaranteed to have
@drivealias populated when calling the monitor, so the code attempting
to cleanup can be simplified.
This commit is contained in:
Peter Krempa 2016-04-26 13:51:41 +02:00
parent c01f4e9e55
commit 375a3d7585

View File

@ -333,7 +333,6 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
virDomainDiskDefPtr disk) virDomainDiskDefPtr disk)
{ {
int ret = -1; int ret = -1;
const char* type = virDomainDiskBusTypeToString(disk->bus);
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
char *devstr = NULL; char *devstr = NULL;
char *drivestr = NULL; char *drivestr = NULL;
@ -357,59 +356,45 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
if (qemuDomainPrepareDisk(driver, vm, disk, NULL, false) < 0) if (qemuDomainPrepareDisk(driver, vm, disk, NULL, false) < 0)
goto cleanup; goto cleanup;
if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) { if (disk->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW) {
if (disk->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW) { if (virDomainCCWAddressAssign(&disk->info, priv->ccwaddrs,
if (virDomainCCWAddressAssign(&disk->info, priv->ccwaddrs, !disk->info.addr.ccw.assigned) < 0)
!disk->info.addr.ccw.assigned) < 0)
goto error;
} else if (!disk->info.type ||
disk->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
if (virDomainPCIAddressEnsureAddr(priv->pciaddrs, &disk->info) < 0)
goto error;
}
releaseaddr = true;
if (qemuAssignDeviceDiskAlias(vm->def, disk, priv->qemuCaps) < 0)
goto error; goto error;
} else if (!disk->info.type ||
if (!(drivestr = qemuBuildDriveStr(conn, disk, false, priv->qemuCaps))) disk->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
goto error; if (virDomainPCIAddressEnsureAddr(priv->pciaddrs, &disk->info) < 0)
if (!(drivealias = qemuDeviceDriveHostAlias(disk, priv->qemuCaps)))
goto error;
if (!(devstr = qemuBuildDriveDevStr(vm->def, disk, 0, priv->qemuCaps)))
goto error; goto error;
} }
releaseaddr = true;
if (qemuAssignDeviceDiskAlias(vm->def, disk, priv->qemuCaps) < 0)
goto error;
if (!(drivestr = qemuBuildDriveStr(conn, disk, false, priv->qemuCaps)))
goto error;
if (!(drivealias = qemuDeviceDriveHostAlias(disk, priv->qemuCaps)))
goto error;
if (!(devstr = qemuBuildDriveDevStr(vm->def, disk, 0, priv->qemuCaps)))
goto error;
if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks+1) < 0) if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks+1) < 0)
goto error; goto error;
qemuDomainObjEnterMonitor(driver, vm); qemuDomainObjEnterMonitor(driver, vm);
if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) { ret = qemuMonitorAddDrive(priv->mon, drivestr);
ret = qemuMonitorAddDrive(priv->mon, drivestr); if (ret == 0) {
if (ret == 0) { ret = qemuMonitorAddDevice(priv->mon, devstr);
ret = qemuMonitorAddDevice(priv->mon, devstr); if (ret < 0) {
if (ret < 0) { virErrorPtr orig_err = virSaveLastError();
virErrorPtr orig_err = virSaveLastError(); if (qemuMonitorDriveDel(priv->mon, drivealias) < 0) {
if (!drivealias || VIR_WARN("Unable to remove drive %s (%s) after failed "
qemuMonitorDriveDel(priv->mon, drivealias) < 0) { "qemuMonitorAddDevice", drivealias, drivestr);
VIR_WARN("Unable to remove drive %s (%s) after failed " }
"qemuMonitorAddDevice", if (orig_err) {
NULLSTR(drivealias), drivestr); virSetError(orig_err);
} virFreeError(orig_err);
if (orig_err) {
virSetError(orig_err);
virFreeError(orig_err);
}
} }
}
} else if (!disk->info.type ||
disk->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
virDevicePCIAddress guestAddr = disk->info.addr.pci;
ret = qemuMonitorAddPCIDisk(priv->mon, src, type, &guestAddr);
if (ret == 0) {
disk->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI;
memcpy(&disk->info.addr.pci, &guestAddr, sizeof(guestAddr));
} }
} }
if (qemuDomainObjExitMonitor(driver, vm) < 0) { if (qemuDomainObjExitMonitor(driver, vm) < 0) {