diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 1a8b4aabb254e77b0549c77a5e20b1619fdacf1f..0cbedf257d3e8fb5f50027ef0bbf9d0c8431f960 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1699,6 +1699,26 @@ static int qemuAssignDeviceDiskAliasLegacy(virDomainDiskDefPtr disk) } +char *qemuDeviceDriveHostAlias(virDomainDiskDefPtr disk, + unsigned long long qemudCmdFlags) +{ + char *ret; + + if (qemudCmdFlags & QEMUD_CMD_FLAG_DEVICE) { + if (virAsprintf(&ret, "%s%s", QEMU_DRIVE_HOST_PREFIX, disk->info.alias) < 0) { + virReportOOMError(); + return NULL; + } + } else { + if (!(ret = strdup(disk->info.alias))) { + virReportOOMError(); + return NULL; + } + } + return ret; +} + + /* Names used before -drive supported the id= option */ static int qemuAssignDeviceDiskAliasFixed(virDomainDiskDefPtr disk) { diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 574709eb07a7ec97824463054244359835bc6f93..b2820f0fa2c1ca33d6fe2ffb10ce526edd63f9e4 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -220,6 +220,9 @@ char * qemuBuildNicStr(virDomainNetDefPtr net, char * qemuBuildNicDevStr(virDomainNetDefPtr net, int vlan); +char *qemuDeviceDriveHostAlias(virDomainDiskDefPtr disk, + unsigned long long qemudCmdFlags); + /* Both legacy & current support */ char *qemuBuildDriveStr(virDomainDiskDefPtr disk, int bootable, diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 0189dcf010970ec055b020b7f31f9cdf58f651c9..7d2f3ef518d38bee571bfa01c7dc71e181a1d92b 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6552,11 +6552,13 @@ cleanup: static int qemudDomainChangeEjectableMedia(struct qemud_driver *driver, virDomainObjPtr vm, - virDomainDiskDefPtr disk) + virDomainDiskDefPtr disk, + unsigned long long qemuCmdFlags) { virDomainDiskDefPtr origdisk = NULL; int i; int ret; + char *driveAlias = NULL; origdisk = NULL; for (i = 0 ; i < vm->def->ndisks ; i++) { @@ -6594,6 +6596,9 @@ static int qemudDomainChangeEjectableMedia(struct qemud_driver *driver, driver->securityDriver->domainSetSecurityImageLabel(vm, disk) < 0) return -1; + if (!(driveAlias = qemuDeviceDriveHostAlias(origdisk, qemuCmdFlags))) + goto error; + qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjEnterMonitorWithDriver(driver, vm); if (disk->src) { @@ -6605,10 +6610,10 @@ static int qemudDomainChangeEjectableMedia(struct qemud_driver *driver, format = origdisk->driverType; } ret = qemuMonitorChangeMedia(priv->mon, - origdisk->info.alias, + driveAlias, disk->src, format); } else { - ret = qemuMonitorEjectMedia(priv->mon, origdisk->info.alias); + ret = qemuMonitorEjectMedia(priv->mon, driveAlias); } qemuDomainObjExitMonitorWithDriver(driver, vm); @@ -6625,11 +6630,14 @@ static int qemudDomainChangeEjectableMedia(struct qemud_driver *driver, disk->src = NULL; origdisk->type = disk->type; + VIR_FREE(driveAlias); + virDomainDiskDefFree(disk); return ret; error: + VIR_FREE(driveAlias); if (driver->securityDriver && driver->securityDriver->domainRestoreSecurityImageLabel && driver->securityDriver->domainRestoreSecurityImageLabel(vm, disk) < 0) @@ -7434,7 +7442,9 @@ static int qemudDomainAttachDevice(virDomainPtr dom, switch (dev->data.disk->device) { case VIR_DOMAIN_DISK_DEVICE_CDROM: case VIR_DOMAIN_DISK_DEVICE_FLOPPY: - ret = qemudDomainChangeEjectableMedia(driver, vm, dev->data.disk); + ret = qemudDomainChangeEjectableMedia(driver, vm, + dev->data.disk, + qemuCmdFlags); if (ret == 0) dev->data.disk = NULL; break; @@ -7679,7 +7689,9 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr dom, switch (dev->data.disk->device) { case VIR_DOMAIN_DISK_DEVICE_CDROM: case VIR_DOMAIN_DISK_DEVICE_FLOPPY: - ret = qemudDomainChangeEjectableMedia(driver, vm, dev->data.disk); + ret = qemudDomainChangeEjectableMedia(driver, vm, + dev->data.disk, + qemuCmdFlags); if (ret == 0) dev->data.disk = NULL; break;