Disk devices in QEMU have two parts, the guest device and the host backend driver. Historically these two parts have had the same "unique" name. With the switch to using -device though, they now have separate names. Thus when changing CDROM media, for guests using -device syntax, we need to prepend the QEMU_DRIVE_HOST_PREFIX constant * src/qemu/qemu_conf.c, src/qemu/qemu_conf.h: Add helper function qemuDeviceDriveHostAlias() for building a host backend alias * src/qemu/qemu_driver.c: Use qemuDeviceDriveHostAlias() to determine the host backend alias for performing eject/change commands in the monitor --- src/qemu/qemu_conf.c | 20 ++++++++++++++++++++ src/qemu/qemu_conf.h | 3 +++ src/qemu/qemu_driver.c | 18 +++++++++++++----- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 5b5cdb0..e1cfbbb 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 574709e..b2820f0 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 df1d435..25257df 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6567,11 +6567,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++) { @@ -6609,6 +6611,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) { @@ -6620,10 +6625,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); @@ -6640,11 +6645,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) @@ -7443,7 +7451,7 @@ 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; @@ -7688,7 +7696,7 @@ 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; -- 1.6.6.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list