From: Masayoshi Mizuma <m.mizuma@xxxxxxxxxxxxxx> Add asynJob argument to some disk hotplug utilities so that they can work before CPUs start. Signed-off-by: Masayoshi Mizuma <m.mizuma@xxxxxxxxxxxxxx> --- src/qemu/qemu_hotplug.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 04b76db5e3..366ebeaa7c 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -693,7 +693,8 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver, static int qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, virDomainObjPtr vm, - virDomainDiskDefPtr disk) + virDomainDiskDefPtr disk, + qemuDomainAsyncJob asyncJob) { g_autoptr(qemuBlockStorageSourceChainData) data = NULL; int ret = -1; @@ -742,7 +743,8 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, if (qemuHotplugAttachManagedPR(driver, vm, disk->src, QEMU_ASYNC_JOB_NONE) < 0) goto cleanup; - qemuDomainObjEnterMonitor(driver, vm); + if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0) + goto cleanup; if (qemuBlockStorageSourceChainAttach(priv->mon, data) < 0) goto exit_monitor; @@ -813,7 +815,8 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, static int qemuDomainAttachVirtioDiskDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, - virDomainDiskDefPtr disk) + virDomainDiskDefPtr disk, + qemuDomainAsyncJob asyncJob) { virDomainDeviceDef dev = { VIR_DOMAIN_DEVICE_DISK, { .disk = disk } }; bool releaseaddr = false; @@ -822,7 +825,7 @@ qemuDomainAttachVirtioDiskDevice(virQEMUDriverPtr driver, if (qemuDomainEnsureVirtioAddress(&releaseaddr, vm, &dev, disk->dst) < 0) return -1; - if ((rv = qemuDomainAttachDiskGeneric(driver, vm, disk)) < 0) { + if ((rv = qemuDomainAttachDiskGeneric(driver, vm, disk, asyncJob)) < 0) { if (rv == -1 && releaseaddr) qemuDomainReleaseDeviceAddress(vm, &disk->info); @@ -970,7 +973,8 @@ qemuDomainFindOrCreateSCSIDiskController(virQEMUDriverPtr driver, static int qemuDomainAttachSCSIDisk(virQEMUDriverPtr driver, virDomainObjPtr vm, - virDomainDiskDefPtr disk) + virDomainDiskDefPtr disk, + qemuDomainAsyncJob asyncJob) { size_t i; @@ -1000,7 +1004,7 @@ qemuDomainAttachSCSIDisk(virQEMUDriverPtr driver, return -1; } - if (qemuDomainAttachDiskGeneric(driver, vm, disk) < 0) + if (qemuDomainAttachDiskGeneric(driver, vm, disk, asyncJob) < 0) return -1; return 0; @@ -1017,7 +1021,7 @@ qemuDomainAttachUSBMassStorageDevice(virQEMUDriverPtr driver, if (virDomainUSBAddressEnsure(priv->usbaddrs, &disk->info) < 0) return -1; - if (qemuDomainAttachDiskGeneric(driver, vm, disk) < 0) { + if (qemuDomainAttachDiskGeneric(driver, vm, disk, QEMU_ASYNC_JOB_NONE) < 0) { virDomainUSBAddressRelease(priv->usbaddrs, &disk->info); return -1; } @@ -1076,6 +1080,7 @@ static int qemuHotplugDiskPrepareOneDiskTransient(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainDeviceDefPtr dev, + qemuDomainAsyncJob asyncJob, bool *created) { g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver); @@ -1121,7 +1126,7 @@ qemuHotplugDiskPrepareOneDiskTransient(virQEMUDriverPtr driver, return -1; if (qemuHotplugDiskPrepareOneBlockdev(driver, vm, cfg, disk, transrc, - QEMU_ASYNC_JOB_NONE, created) < 0) + asyncJob, created) < 0) return -1; if (origsrc->shared) @@ -1137,7 +1142,8 @@ qemuHotplugDiskPrepareOneDiskTransient(virQEMUDriverPtr driver, static int qemuDomainAttachDeviceDiskLiveInternal(virQEMUDriverPtr driver, virDomainObjPtr vm, - virDomainDeviceDefPtr dev) + virDomainDeviceDefPtr dev, + qemuDomainAsyncJob asyncJob) { size_t i; virDomainDiskDefPtr disk = dev->data.disk; @@ -1175,6 +1181,7 @@ qemuDomainAttachDeviceDiskLiveInternal(virQEMUDriverPtr driver, } if (qemuHotplugDiskPrepareOneDiskTransient(driver, vm, dev, + asyncJob, &transientDiskCreated) < 0) goto cleanup; } @@ -1195,11 +1202,11 @@ qemuDomainAttachDeviceDiskLiveInternal(virQEMUDriverPtr driver, break; case VIR_DOMAIN_DISK_BUS_VIRTIO: - ret = qemuDomainAttachVirtioDiskDevice(driver, vm, disk); + ret = qemuDomainAttachVirtioDiskDevice(driver, vm, disk, asyncJob); break; case VIR_DOMAIN_DISK_BUS_SCSI: - ret = qemuDomainAttachSCSIDisk(driver, vm, disk); + ret = qemuDomainAttachSCSIDisk(driver, vm, disk, asyncJob); break; case VIR_DOMAIN_DISK_BUS_IDE: @@ -1261,7 +1268,7 @@ qemuDomainAttachDeviceDiskLive(virQEMUDriverPtr driver, return 0; } - return qemuDomainAttachDeviceDiskLiveInternal(driver, vm, dev); + return qemuDomainAttachDeviceDiskLiveInternal(driver, vm, dev, QEMU_ASYNC_JOB_NONE); } @@ -4416,7 +4423,8 @@ static bool qemuIsMultiFunctionDevice(virDomainDefPtr def, static int qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, - virDomainDiskDefPtr disk) + virDomainDiskDefPtr disk, + qemuDomainAsyncJob asyncJob) { qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk); g_autoptr(qemuBlockStorageSourceChainData) diskBackend = NULL; @@ -4466,7 +4474,8 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver, } } - qemuDomainObjEnterMonitor(driver, vm); + if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0) + goto cleanup; if (corAlias) ignore_value(qemuMonitorBlockdevDel(priv->mon, corAlias)); @@ -5214,7 +5223,8 @@ qemuDomainRemoveDevice(virQEMUDriverPtr driver, * into this function. */ case VIR_DOMAIN_DEVICE_DISK: - if (qemuDomainRemoveDiskDevice(driver, vm, dev->data.disk) < 0) + if (qemuDomainRemoveDiskDevice(driver, vm, dev->data.disk, + QEMU_ASYNC_JOB_NONE) < 0) return -1; break; case VIR_DOMAIN_DEVICE_CONTROLLER: -- 2.27.0