Fix CDROM media change for QEMU when using -device syntax

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
This commit is contained in:
Daniel P. Berrange 2010-04-15 11:35:07 +01:00
parent db336caa58
commit c4896d378b
3 changed files with 40 additions and 5 deletions

View File

@ -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)
{

View File

@ -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,

View File

@ -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;