/**
- * qemuDomainChangeEjectableMedia:
+ * qemuDomainChangeMediaLegacy:
* @driver: qemu driver structure
* @vm: domain definition
* @disk: disk definition to change the source of
*
* Returns 0 on success, -1 on error and reports libvirt error
*/
-int
-qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
- virDomainObjPtr vm,
- virDomainDiskDefPtr disk,
- virStorageSourcePtr newsrc,
- bool force)
+static int
+qemuDomainChangeMediaLegacy(virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
+ virDomainDiskDefPtr disk,
+ virStorageSourcePtr newsrc,
+ bool force)
{
int ret = -1, rc;
char *driveAlias = NULL;
if (srcPriv)
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)))
- goto error;
+ goto cleanup;
qemuDomainObjEnterMonitor(driver, vm);
rc = qemuMonitorEjectMedia(priv->mon, driveAlias, force);
virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE_TRAY_MOVED)) {
rc = qemuHotplugWaitForTrayEject(driver, vm, disk, driveAlias);
if (rc < 0)
- goto error;
+ goto cleanup;
} else {
/* otherwise report possible errors from the attempt to eject the media*/
if (rc < 0)
- goto error;
+ goto cleanup;
}
if (!virStorageSourceIsEmpty(newsrc)) {
if (qemuGetDriveSourceString(newsrc, secinfo, &sourcestr) < 0)
- goto error;
+ goto cleanup;
if (virStorageSourceGetActualType(newsrc) != VIR_STORAGE_TYPE_DIR) {
if (newsrc->format > 0) {
goto cleanup;
}
- virDomainAuditDisk(vm, disk->src, newsrc, "update", rc >= 0);
-
if (rc < 0)
- goto error;
-
- /* remove the old source from shared device list */
- ignore_value(qemuRemoveSharedDisk(driver, disk, vm->def->name));
- ignore_value(qemuHotplugPrepareDiskAccess(driver, vm, disk, NULL, true));
+ goto cleanup;
- virStorageSourceFree(disk->src);
- disk->src = newsrc;
- newsrc = NULL;
ret = 0;
cleanup:
VIR_FREE(driveAlias);
VIR_FREE(sourcestr);
return ret;
-
- error:
- virDomainAuditDisk(vm, disk->src, newsrc, "update", false);
- ignore_value(qemuHotplugPrepareDiskAccess(driver, vm, disk, newsrc, true));
- goto cleanup;
}
}
+/**
+ * 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:
*