On 09/16/2015 05:15 AM, Michal Privoznik wrote:
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/qemu/qemu_domain.c | 1 -
src/qemu/qemu_driver.c | 29 ++++++++++++++++++++---------
2 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index ed92d8a..fb8ab30 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -3157,7 +3157,6 @@ qemuDomainDiskChangeSupported(virDomainDiskDefPtr disk,
CHECK_EQ(event_idx, "event_idx", true);
CHECK_EQ(copy_on_read, "copy_on_read", true);
CHECK_EQ(snapshot, "snapshot", true);
- CHECK_EQ(startupPolicy, "startupPolicy", true);
Perhaps leave a comment indicating that startupPolicy is special so that
someone doesn't come along one day and say - oh look startupPolicy is
missing, I'm going to add it here... Assuming one reads comments ;-)
It's really too bad there isn't some "simple mechanism" to ensure new
fields are listed here too.
CHECK_EQ(transient, "transient", true);
CHECK_EQ(info.bootIndex, "boot order", true);
CHECK_EQ(rawio, "rawio", true);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 1a189cc..d74255b 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7922,6 +7922,7 @@ qemuDomainChangeDiskLive(virConnectPtr conn,
{
virDomainDiskDefPtr disk = dev->data.disk;
virDomainDiskDefPtr orig_disk = NULL;
+ int startupPolicy;
int ret = -1;
if (virStorageTranslateDiskSourcePool(conn, disk) < 0)
@@ -7939,23 +7940,29 @@ qemuDomainChangeDiskLive(virConnectPtr conn,
goto cleanup;
}
+ startupPolicy = orig_disk->startupPolicy;
+
switch ((virDomainDiskDevice) disk->device) {
case VIR_DOMAIN_DISK_DEVICE_CDROM:
case VIR_DOMAIN_DISK_DEVICE_FLOPPY:
if (!qemuDomainDiskChangeSupported(disk, orig_disk))
goto cleanup;
- /* Add the new disk src into shared disk hash table */
- if (qemuAddSharedDevice(driver, dev, vm->def->name) < 0)
- goto cleanup;
+ orig_disk->startupPolicy = dev->data.disk->startupPolicy;
- if (qemuDomainChangeEjectableMedia(driver, conn, vm,
- orig_disk, disk->src, force) < 0) {
- ignore_value(qemuRemoveSharedDisk(driver, disk, vm->def->name));
- goto cleanup;
+ if (qemuDomainDiskSourceDiffers(conn, disk, orig_disk)) {
+ /* Add the new disk src into shared disk hash table */
+ if (qemuAddSharedDevice(driver, dev, vm->def->name) < 0)
+ goto cleanup;
+
+ if (qemuDomainChangeEjectableMedia(driver, conn, vm,
+ orig_disk, dev->data.disk->src,
force) < 0) {
+ ignore_value(qemuRemoveSharedDisk(driver, dev->data.disk,
vm->def->name));
+ goto rollback;
+ }
+
+ dev->data.disk->src = NULL;
}
-
- disk->src = NULL;
break;
case VIR_DOMAIN_DISK_DEVICE_DISK:
@@ -7974,6 +7981,10 @@ qemuDomainChangeDiskLive(virConnectPtr conn,
ret = 0;
cleanup:
return ret;
+
+ rollback:
+ orig_disk->startupPolicy = startupPolicy;
+ goto cleanup;
}
static int