提交 1f39218e 编写于 作者: P Peter Krempa

qemu: hotplug: Change arguments for qemuDomainChangeEjectableMedia

Pass the source of the changed media instead of a complete disk
definition.

Note that the @disk argument now contains what @olddisk would contain.
The new source is passed as a virStorageSource struct.
上级 ca91ba78
...@@ -6639,6 +6639,7 @@ qemuDomainChangeDiskMediaLive(virConnectPtr conn, ...@@ -6639,6 +6639,7 @@ qemuDomainChangeDiskMediaLive(virConnectPtr conn,
virDomainDiskDefPtr orig_disk = NULL; virDomainDiskDefPtr orig_disk = NULL;
virDomainDiskDefPtr tmp = NULL; virDomainDiskDefPtr tmp = NULL;
virDomainDeviceDefPtr dev_copy = NULL; virDomainDeviceDefPtr dev_copy = NULL;
virStorageSourcePtr newsrc;
virCapsPtr caps = NULL; virCapsPtr caps = NULL;
int ret = -1; int ret = -1;
...@@ -6677,7 +6678,10 @@ qemuDomainChangeDiskMediaLive(virConnectPtr conn, ...@@ -6677,7 +6678,10 @@ qemuDomainChangeDiskMediaLive(virConnectPtr conn,
if (qemuAddSharedDevice(driver, dev, vm->def->name) < 0) if (qemuAddSharedDevice(driver, dev, vm->def->name) < 0)
goto end; goto end;
ret = qemuDomainChangeEjectableMedia(driver, vm, disk, orig_disk, force); newsrc = disk->src;
disk->src = NULL;
ret = qemuDomainChangeEjectableMedia(driver, vm, orig_disk, newsrc, force);
/* 'disk' must not be accessed now - it has been freed. /* 'disk' must not be accessed now - it has been freed.
* 'orig_disk' now points to the new disk, while 'dev_copy' * 'orig_disk' now points to the new disk, while 'dev_copy'
* now points to the old disk */ * now points to the old disk */
......
...@@ -141,34 +141,33 @@ qemuDomainPrepareDisk(virQEMUDriverPtr driver, ...@@ -141,34 +141,33 @@ qemuDomainPrepareDisk(virQEMUDriverPtr driver,
int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver, int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
virDomainObjPtr vm, virDomainObjPtr vm,
virDomainDiskDefPtr disk, virDomainDiskDefPtr disk,
virDomainDiskDefPtr origdisk, virStorageSourcePtr newsrc,
bool force) bool force)
{ {
int ret = -1; int ret = -1;
char *driveAlias = NULL; char *driveAlias = NULL;
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
int retries = CHANGE_MEDIA_RETRIES; int retries = CHANGE_MEDIA_RETRIES;
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); const char *format = NULL;
const char *src = NULL;
if (!origdisk->info.alias) { if (!disk->info.alias) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("missing disk device alias name for %s"), origdisk->dst); _("missing disk device alias name for %s"), disk->dst);
goto cleanup; goto cleanup;
} }
if (origdisk->device != VIR_DOMAIN_DISK_DEVICE_FLOPPY && if (disk->device != VIR_DOMAIN_DISK_DEVICE_FLOPPY &&
origdisk->device != VIR_DOMAIN_DISK_DEVICE_CDROM) { disk->device != VIR_DOMAIN_DISK_DEVICE_CDROM) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Removable media not supported for %s device"), _("Removable media not supported for %s device"),
virDomainDiskDeviceTypeToString(disk->device)); virDomainDiskDeviceTypeToString(disk->device));
goto cleanup; goto cleanup;
} }
if (qemuDomainPrepareDisk(driver, vm, disk, NULL, false) < 0) if (qemuDomainPrepareDisk(driver, vm, disk, newsrc, false) < 0)
goto cleanup; goto cleanup;
if (!(driveAlias = qemuDeviceDriveHostAlias(origdisk, priv->qemuCaps))) if (!(driveAlias = qemuDeviceDriveHostAlias(disk, priv->qemuCaps)))
goto error; goto error;
qemuDomainObjEnterMonitor(driver, vm); qemuDomainObjEnterMonitor(driver, vm);
...@@ -181,7 +180,7 @@ int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver, ...@@ -181,7 +180,7 @@ int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
virObjectRef(vm); virObjectRef(vm);
/* we don't want to report errors from media tray_open polling */ /* we don't want to report errors from media tray_open polling */
while (retries) { while (retries) {
if (origdisk->tray_status == VIR_DOMAIN_DISK_TRAY_OPEN) if (disk->tray_status == VIR_DOMAIN_DISK_TRAY_OPEN)
break; break;
retries--; retries--;
...@@ -199,53 +198,42 @@ int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver, ...@@ -199,53 +198,42 @@ int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
goto error; goto error;
} }
src = virDomainDiskGetSource(disk); if (newsrc->path) {
if (src) { if (virStorageSourceGetActualType(newsrc) != VIR_STORAGE_TYPE_DIR) {
/* deliberately don't depend on 'ret' as 'eject' may have failed the if (newsrc->format > 0) {
* first time and we are going to check the drive state anyway */ format = virStorageFileFormatTypeToString(newsrc->format);
const char *format = NULL;
int type = virDomainDiskGetType(disk);
int diskFormat = virDomainDiskGetFormat(disk);
if (type != VIR_STORAGE_TYPE_DIR) {
if (diskFormat > 0) {
format = virStorageFileFormatTypeToString(diskFormat);
} else { } else {
diskFormat = virDomainDiskGetFormat(origdisk); if (disk->src->format > 0)
if (diskFormat > 0) format = virStorageFileFormatTypeToString(disk->src->format);
format = virStorageFileFormatTypeToString(diskFormat);
} }
} }
qemuDomainObjEnterMonitor(driver, vm); qemuDomainObjEnterMonitor(driver, vm);
ret = qemuMonitorChangeMedia(priv->mon, ret = qemuMonitorChangeMedia(priv->mon,
driveAlias, driveAlias,
src, format); newsrc->path,
format);
qemuDomainObjExitMonitor(driver, vm); qemuDomainObjExitMonitor(driver, vm);
} }
virDomainAuditDisk(vm, origdisk->src, disk->src, "update", ret >= 0); virDomainAuditDisk(vm, disk->src, newsrc, "update", ret >= 0);
if (ret < 0) if (ret < 0)
goto error; goto error;
ignore_value(qemuDomainPrepareDisk(driver, vm, origdisk, NULL, true)); ignore_value(qemuDomainPrepareDisk(driver, vm, disk, NULL, true));
if (virDomainDiskSetSource(origdisk, src) < 0)
goto error;
virDomainDiskSetType(origdisk, virDomainDiskGetType(disk));
virDomainDiskDefFree(disk); virStorageSourceFree(disk->src);
disk->src = newsrc;
newsrc = NULL;
cleanup: cleanup:
virStorageSourceFree(newsrc);
VIR_FREE(driveAlias); VIR_FREE(driveAlias);
virObjectUnref(cfg);
return ret; return ret;
error: error:
virDomainAuditDisk(vm, origdisk->src, disk->src, "update", false); virDomainAuditDisk(vm, disk->src, newsrc, "update", false);
ignore_value(qemuDomainPrepareDisk(driver, vm, disk, newsrc, true));
ignore_value(qemuDomainPrepareDisk(driver, vm, disk, NULL, true));
goto cleanup; goto cleanup;
} }
...@@ -747,6 +735,7 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn, ...@@ -747,6 +735,7 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
virDomainDiskDefPtr disk = dev->data.disk; virDomainDiskDefPtr disk = dev->data.disk;
virDomainDiskDefPtr orig_disk = NULL; virDomainDiskDefPtr orig_disk = NULL;
virDomainDeviceDefPtr dev_copy = NULL; virDomainDeviceDefPtr dev_copy = NULL;
virStorageSourcePtr newsrc;
virDomainDiskDefPtr tmp = NULL; virDomainDiskDefPtr tmp = NULL;
virCapsPtr caps = NULL; virCapsPtr caps = NULL;
int ret = -1; int ret = -1;
...@@ -789,6 +778,7 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn, ...@@ -789,6 +778,7 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
if (!(caps = virQEMUDriverGetCapabilities(driver, false))) if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
goto end; goto end;
tmp = dev->data.disk; tmp = dev->data.disk;
dev->data.disk = orig_disk; dev->data.disk = orig_disk;
...@@ -799,8 +789,11 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn, ...@@ -799,8 +789,11 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
} }
dev->data.disk = tmp; dev->data.disk = tmp;
ret = qemuDomainChangeEjectableMedia(driver, vm, disk, orig_disk, false); newsrc = disk->src;
/* 'disk' must not be accessed now - it has been free'd. disk->src = NULL;
ret = qemuDomainChangeEjectableMedia(driver, vm, orig_disk, newsrc, false);
/* 'newsrc' must not be accessed now - it has been free'd.
* 'orig_disk' now points to the new disk, while 'dev_copy' * 'orig_disk' now points to the new disk, while 'dev_copy'
* now points to the old disk */ * now points to the old disk */
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver, int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
virDomainObjPtr vm, virDomainObjPtr vm,
virDomainDiskDefPtr disk, virDomainDiskDefPtr disk,
virDomainDiskDefPtr orig_disk, virStorageSourcePtr newsrc,
bool force); bool force);
int qemuDomainCheckEjectableMedia(virQEMUDriverPtr driver, int qemuDomainCheckEjectableMedia(virQEMUDriverPtr driver,
virDomainObjPtr vm, virDomainObjPtr vm,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册