提交 22480cf9 编写于 作者: P Peter Krempa

qemu: hotplug: Extract legacy disk media changing bits

Prepare for the -blockdev implementation of ejectable media changing by
splitting up the old bits.

Additionally since both callers make sure that the device is a cdrom or
floppy the check is no longer necessary.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 36e9b1ec
...@@ -192,7 +192,7 @@ qemuHotplugWaitForTrayEject(virQEMUDriverPtr driver, ...@@ -192,7 +192,7 @@ qemuHotplugWaitForTrayEject(virQEMUDriverPtr driver,
/** /**
* qemuDomainChangeEjectableMedia: * qemuDomainChangeMediaLegacy:
* @driver: qemu driver structure * @driver: qemu driver structure
* @vm: domain definition * @vm: domain definition
* @disk: disk definition to change the source of * @disk: disk definition to change the source of
...@@ -206,12 +206,12 @@ qemuHotplugWaitForTrayEject(virQEMUDriverPtr driver, ...@@ -206,12 +206,12 @@ qemuHotplugWaitForTrayEject(virQEMUDriverPtr driver,
* *
* Returns 0 on success, -1 on error and reports libvirt error * Returns 0 on success, -1 on error and reports libvirt error
*/ */
int static int
qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver, qemuDomainChangeMediaLegacy(virQEMUDriverPtr driver,
virDomainObjPtr vm, virDomainObjPtr vm,
virDomainDiskDefPtr disk, virDomainDiskDefPtr disk,
virStorageSourcePtr newsrc, virStorageSourcePtr newsrc,
bool force) bool force)
{ {
int ret = -1, rc; int ret = -1, rc;
char *driveAlias = NULL; char *driveAlias = NULL;
...@@ -231,19 +231,8 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver, ...@@ -231,19 +231,8 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
if (srcPriv) if (srcPriv)
secinfo = srcPriv->secinfo; secinfo = srcPriv->secinfo;
if (disk->device != VIR_DOMAIN_DISK_DEVICE_FLOPPY &&
disk->device != VIR_DOMAIN_DISK_DEVICE_CDROM) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Removable media not supported for %s device"),
virDomainDiskDeviceTypeToString(disk->device));
goto cleanup;
}
if (qemuHotplugPrepareDiskAccess(driver, vm, disk, newsrc, false) < 0)
goto cleanup;
if (!(driveAlias = qemuAliasDiskDriveFromDisk(disk))) if (!(driveAlias = qemuAliasDiskDriveFromDisk(disk)))
goto error; goto cleanup;
qemuDomainObjEnterMonitor(driver, vm); qemuDomainObjEnterMonitor(driver, vm);
rc = qemuMonitorEjectMedia(priv->mon, driveAlias, force); rc = qemuMonitorEjectMedia(priv->mon, driveAlias, force);
...@@ -255,16 +244,16 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver, ...@@ -255,16 +244,16 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE_TRAY_MOVED)) { virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE_TRAY_MOVED)) {
rc = qemuHotplugWaitForTrayEject(driver, vm, disk, driveAlias); rc = qemuHotplugWaitForTrayEject(driver, vm, disk, driveAlias);
if (rc < 0) if (rc < 0)
goto error; goto cleanup;
} else { } else {
/* otherwise report possible errors from the attempt to eject the media*/ /* otherwise report possible errors from the attempt to eject the media*/
if (rc < 0) if (rc < 0)
goto error; goto cleanup;
} }
if (!virStorageSourceIsEmpty(newsrc)) { if (!virStorageSourceIsEmpty(newsrc)) {
if (qemuGetDriveSourceString(newsrc, secinfo, &sourcestr) < 0) if (qemuGetDriveSourceString(newsrc, secinfo, &sourcestr) < 0)
goto error; goto cleanup;
if (virStorageSourceGetActualType(newsrc) != VIR_STORAGE_TYPE_DIR) { if (virStorageSourceGetActualType(newsrc) != VIR_STORAGE_TYPE_DIR) {
if (newsrc->format > 0) { if (newsrc->format > 0) {
...@@ -283,29 +272,15 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver, ...@@ -283,29 +272,15 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
goto cleanup; goto cleanup;
} }
virDomainAuditDisk(vm, disk->src, newsrc, "update", rc >= 0);
if (rc < 0) if (rc < 0)
goto error; goto cleanup;
/* remove the old source from shared device list */
ignore_value(qemuRemoveSharedDisk(driver, disk, vm->def->name));
ignore_value(qemuHotplugPrepareDiskAccess(driver, vm, disk, NULL, true));
virStorageSourceFree(disk->src);
disk->src = newsrc;
newsrc = NULL;
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(driveAlias); VIR_FREE(driveAlias);
VIR_FREE(sourcestr); VIR_FREE(sourcestr);
return ret; return ret;
error:
virDomainAuditDisk(vm, disk->src, newsrc, "update", false);
ignore_value(qemuHotplugPrepareDiskAccess(driver, vm, disk, newsrc, true));
goto cleanup;
} }
...@@ -592,6 +567,56 @@ qemuHotplugDiskSourceRemove(qemuMonitorPtr mon, ...@@ -592,6 +567,56 @@ qemuHotplugDiskSourceRemove(qemuMonitorPtr mon,
} }
/**
* qemuDomainChangeEjectableMedia:
* @driver: qemu driver structure
* @vm: domain definition
* @disk: disk definition to change the source of
* @newsrc: new disk source to change to
* @force: force the change of media
*
* Change the media in an ejectable device to the one described by
* @newsrc. This function also removes the old source from the
* shared device table if appropriate. Note that newsrc is consumed
* on success and the old source is freed on success.
*
* Returns 0 on success, -1 on error and reports libvirt error
*/
int
qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
virDomainObjPtr vm,
virDomainDiskDefPtr disk,
virStorageSourcePtr newsrc,
bool force)
{
int ret = -1;
int rc;
if (qemuHotplugPrepareDiskAccess(driver, vm, disk, newsrc, false) < 0)
goto cleanup;
rc = qemuDomainChangeMediaLegacy(driver, vm, disk, newsrc, force);
virDomainAuditDisk(vm, disk->src, newsrc, "update", rc >= 0);
if (rc < 0) {
ignore_value(qemuHotplugPrepareDiskAccess(driver, vm, disk, newsrc, true));
goto cleanup;
}
/* remove the old source from shared device list */
ignore_value(qemuRemoveSharedDisk(driver, disk, vm->def->name));
ignore_value(qemuHotplugPrepareDiskAccess(driver, vm, disk, NULL, true));
virStorageSourceFree(disk->src);
VIR_STEAL_PTR(disk->src, newsrc);
ret = 0;
cleanup:
return ret;
}
/** /**
* qemuDomainAttachDiskGeneric: * qemuDomainAttachDiskGeneric:
* *
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册