[PATCH 6/6] qemu: Remove the shared disk entry if the operation is ejecting

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

 



For both qemuDomainAttachDeviceDiskLive and qemuDomainChangeDiskMediaLive.
---
 src/qemu/qemu_driver.c  |   40 +++++++++++++++++++++++++++++++++++-----
 src/qemu/qemu_hotplug.c |   10 +++++++++-
 src/qemu/qemu_hotplug.h |    3 ++-
 3 files changed, 46 insertions(+), 7 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 48852ad..f362027 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -5827,7 +5827,10 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
                                virDomainDeviceDefPtr dev)
 {
     virDomainDiskDefPtr disk = dev->data.disk;
+    virDomainDeviceDefPtr dev_copy = NULL;
     virCgroupPtr cgroup = NULL;
+    virCapsPtr caps = NULL;
+    int eject;
     int ret = -1;
 
     if (disk->driverName != NULL && !STREQ(disk->driverName, "qemu")) {
@@ -5860,7 +5863,13 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
     switch (disk->device)  {
     case VIR_DOMAIN_DISK_DEVICE_CDROM:
     case VIR_DOMAIN_DISK_DEVICE_FLOPPY:
-        ret = qemuDomainChangeEjectableMedia(driver, vm, disk, false);
+        if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
+            goto end;
+
+        if (!(dev_copy = virDomainDeviceDefCopy(caps, vm->def, dev)))
+            goto end;
+
+        ret = qemuDomainChangeEjectableMedia(driver, vm, disk, false, &eject);
         break;
     case VIR_DOMAIN_DISK_DEVICE_DISK:
     case VIR_DOMAIN_DISK_DEVICE_LUN:
@@ -5889,8 +5898,12 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
         break;
     }
 
-    if (ret != 0 && cgroup) {
-        if (qemuTeardownDiskCgroup(vm, cgroup, disk) < 0)
+    if (ret == 0) {
+        if (eject)
+            ignore_value(qemuRemoveSharedDisk(driver, dev_copy->data.disk,
+                                              vm->def->name));
+    } else {
+        if (cgroup && qemuTeardownDiskCgroup(vm, cgroup, disk) < 0)
             VIR_WARN("Failed to teardown cgroup for disk path %s",
                      NULLSTR(disk->src));
     }
@@ -5900,6 +5913,8 @@ end:
         ignore_value(qemuRemoveSharedDisk(driver, disk, vm->def->name));
     if (cgroup)
         virCgroupFree(&cgroup);
+    virObjectUnref(caps);
+    virDomainDeviceDefFree(dev_copy);
     return ret;
 }
 
@@ -6079,6 +6094,9 @@ qemuDomainChangeDiskMediaLive(virDomainObjPtr vm,
 {
     virDomainDiskDefPtr disk = dev->data.disk;
     virCgroupPtr cgroup = NULL;
+    virDomainDeviceDefPtr dev_copy = NULL;
+    virCapsPtr caps = NULL;
+    int eject;
     int ret = -1;
 
     if (qemuDomainDetermineDiskChain(driver, disk, false) < 0)
@@ -6099,9 +6117,19 @@ qemuDomainChangeDiskMediaLive(virDomainObjPtr vm,
     switch (disk->device) {
     case VIR_DOMAIN_DISK_DEVICE_CDROM:
     case VIR_DOMAIN_DISK_DEVICE_FLOPPY:
-        ret = qemuDomainChangeEjectableMedia(driver, vm, disk, force);
-        if (ret == 0)
+        if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
+            goto end;
+
+        if (!(dev_copy = virDomainDeviceDefCopy(caps, vm->def, dev)))
+            goto end;
+
+        ret = qemuDomainChangeEjectableMedia(driver, vm, disk, force, &eject);
+        if (ret == 0) {
             dev->data.disk = NULL;
+            if (eject)
+                ignore_value(qemuRemoveSharedDisk(driver, dev_copy->data.disk,
+                                                  vm->def->name));
+        }
         break;
     default:
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -6118,6 +6146,8 @@ qemuDomainChangeDiskMediaLive(virDomainObjPtr vm,
 end:
     if (cgroup)
         virCgroupFree(&cgroup);
+    virObjectUnref(caps);
+    virDomainDeviceDefFree(dev_copy);
     return ret;
 }
 
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 0c28a6a..e54cf09 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -53,7 +53,8 @@
 int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
                                    virDomainObjPtr vm,
                                    virDomainDiskDefPtr disk,
-                                   bool force)
+                                   bool force,
+                                   int *eject)
 {
     virDomainDiskDefPtr origdisk = NULL;
     int i;
@@ -93,6 +94,13 @@ int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
         goto cleanup;
     }
 
+    if (eject) {
+        if (origdisk->src && !disk->src)
+            *eject = 1;
+        else
+            *eject = 0;
+    }
+
     if (virDomainLockDiskAttach(driver->lockManager, cfg->uri,
                                 vm, disk) < 0)
         goto cleanup;
diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h
index 8f01d23..fc0532a 100644
--- a/src/qemu/qemu_hotplug.h
+++ b/src/qemu/qemu_hotplug.h
@@ -31,7 +31,8 @@
 int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
                                    virDomainObjPtr vm,
                                    virDomainDiskDefPtr disk,
-                                   bool force);
+                                   bool force,
+                                   int *eject);
 int qemuDomainCheckEjectableMedia(virQEMUDriverPtr driver,
                                   virDomainObjPtr vm,
                                   enum qemuDomainAsyncJob asyncJob);
-- 
1.7.7.6

--
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]