[PATCH 05/14] qemu: hotplug: Change arguments for qemuDomainChangeEjectableMedia

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.
---
 src/qemu/qemu_driver.c  |  6 ++++-
 src/qemu/qemu_hotplug.c | 71 ++++++++++++++++++++++---------------------------
 src/qemu/qemu_hotplug.h |  2 +-
 3 files changed, 38 insertions(+), 41 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 03fe96f..fc345d5 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -6623,6 +6623,7 @@ qemuDomainChangeDiskMediaLive(virConnectPtr conn,
     virDomainDiskDefPtr orig_disk = NULL;
     virDomainDiskDefPtr tmp = NULL;
     virDomainDeviceDefPtr dev_copy = NULL;
+    virStorageSourcePtr newsrc;
     virCapsPtr caps = NULL;
     int ret = -1;

@@ -6661,7 +6662,10 @@ qemuDomainChangeDiskMediaLive(virConnectPtr conn,
         if (qemuAddSharedDevice(driver, dev, vm->def->name) < 0)
             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.
          * 'orig_disk' now points to the new disk, while 'dev_copy'
          * now points to the old disk */
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 5894f43..9ad06be 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -140,34 +140,33 @@ qemuDomainPrepareDisk(virQEMUDriverPtr driver,
 int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
                                    virDomainObjPtr vm,
                                    virDomainDiskDefPtr disk,
-                                   virDomainDiskDefPtr origdisk,
+                                   virStorageSourcePtr newsrc,
                                    bool force)
 {
     int ret = -1;
     char *driveAlias = NULL;
     qemuDomainObjPrivatePtr priv = vm->privateData;
     int retries = CHANGE_MEDIA_RETRIES;
-    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
-    const char *src = NULL;
+    const char *format = NULL;

-    if (!origdisk->info.alias) {
+    if (!disk->info.alias) {
         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;
     }

-    if (origdisk->device != VIR_DOMAIN_DISK_DEVICE_FLOPPY &&
-        origdisk->device != VIR_DOMAIN_DISK_DEVICE_CDROM) {
+    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 (qemuDomainPrepareDisk(driver, vm, disk, NULL, false) < 0)
+    if (qemuDomainPrepareDisk(driver, vm, disk, newsrc, false) < 0)
         goto cleanup;

-    if (!(driveAlias = qemuDeviceDriveHostAlias(origdisk, priv->qemuCaps)))
+    if (!(driveAlias = qemuDeviceDriveHostAlias(disk, priv->qemuCaps)))
         goto error;

     qemuDomainObjEnterMonitor(driver, vm);
@@ -180,7 +179,7 @@ int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
     virObjectRef(vm);
     /* we don't want to report errors from media tray_open polling */
     while (retries) {
-        if (origdisk->tray_status == VIR_DOMAIN_DISK_TRAY_OPEN)
+        if (disk->tray_status == VIR_DOMAIN_DISK_TRAY_OPEN)
             break;

         retries--;
@@ -198,53 +197,42 @@ int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
         goto error;
     }

-    src = virDomainDiskGetSource(disk);
-    if (src) {
-        /* deliberately don't depend on 'ret' as 'eject' may have failed the
-         * first time and we are going to check the drive state anyway */
-        const char *format = NULL;
-        int type = virDomainDiskGetType(disk);
-        int diskFormat = virDomainDiskGetFormat(disk);
-
-        if (type != VIR_STORAGE_TYPE_DIR) {
-            if (diskFormat > 0) {
-                format = virStorageFileFormatTypeToString(diskFormat);
+    if (newsrc->path) {
+        if (virStorageSourceGetActualType(newsrc) != VIR_STORAGE_TYPE_DIR) {
+            if (newsrc->format > 0) {
+                format = virStorageFileFormatTypeToString(newsrc->format);
             } else {
-                diskFormat = virDomainDiskGetFormat(origdisk);
-                if (diskFormat > 0)
-                    format = virStorageFileFormatTypeToString(diskFormat);
+                if (disk->src->format > 0)
+                    format = virStorageFileFormatTypeToString(disk->src->format);
             }
         }
         qemuDomainObjEnterMonitor(driver, vm);
         ret = qemuMonitorChangeMedia(priv->mon,
                                      driveAlias,
-                                     src, format);
+                                     newsrc->path,
+                                     format);
         qemuDomainObjExitMonitor(driver, vm);
     }

-    virDomainAuditDisk(vm, origdisk->src, disk->src, "update", ret >= 0);
+    virDomainAuditDisk(vm, disk->src, newsrc, "update", ret >= 0);

     if (ret < 0)
         goto error;

-    ignore_value(qemuDomainPrepareDisk(driver, vm, origdisk, NULL, true));
-
-    if (virDomainDiskSetSource(origdisk, src) < 0)
-        goto error;
-    virDomainDiskSetType(origdisk, virDomainDiskGetType(disk));
+    ignore_value(qemuDomainPrepareDisk(driver, vm, disk, NULL, true));

-    virDomainDiskDefFree(disk);
+    virStorageSourceFree(disk->src);
+    disk->src = newsrc;
+    newsrc = NULL;

  cleanup:
+    virStorageSourceFree(newsrc);
     VIR_FREE(driveAlias);
-    virObjectUnref(cfg);
     return ret;

  error:
-    virDomainAuditDisk(vm, origdisk->src, disk->src, "update", false);
-
-    ignore_value(qemuDomainPrepareDisk(driver, vm, disk, NULL, true));
-
+    virDomainAuditDisk(vm, disk->src, newsrc, "update", false);
+    ignore_value(qemuDomainPrepareDisk(driver, vm, disk, newsrc, true));
     goto cleanup;
 }

@@ -746,6 +734,7 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
     virDomainDiskDefPtr disk = dev->data.disk;
     virDomainDiskDefPtr orig_disk = NULL;
     virDomainDeviceDefPtr dev_copy = NULL;
+    virStorageSourcePtr newsrc;
     virDomainDiskDefPtr tmp = NULL;
     virCapsPtr caps = NULL;
     int ret = -1;
@@ -788,6 +777,7 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
         if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
             goto end;

+
         tmp = dev->data.disk;
         dev->data.disk = orig_disk;

@@ -798,8 +788,11 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
         }
         dev->data.disk = tmp;

-        ret = qemuDomainChangeEjectableMedia(driver, vm, disk, orig_disk, false);
-        /* 'disk' must not be accessed now - it has been free'd.
+        newsrc = disk->src;
+        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'
          * now points to the old disk */

diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h
index 6192973..5ce8f0a 100644
--- a/src/qemu/qemu_hotplug.h
+++ b/src/qemu/qemu_hotplug.h
@@ -31,7 +31,7 @@
 int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
                                    virDomainObjPtr vm,
                                    virDomainDiskDefPtr disk,
-                                   virDomainDiskDefPtr orig_disk,
+                                   virStorageSourcePtr newsrc,
                                    bool force);
 int qemuDomainCheckEjectableMedia(virQEMUDriverPtr driver,
                                   virDomainObjPtr vm,
-- 
2.0.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]