[PATCH 1/3] qemuProcessRefreshDisks: Properly compare tray status

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

 



The code compares the 'tray_open' boolean from 'struct
qemuDomainDiskInfo' directly against 'disk->tray_status' which is
declared as virDomainDiskTray (enum). Now the logic works correctly
because the _OPEN enum has value '1'.

Separate the event emission code from the update code and remember the
old tray state in a separate variable rather than having the sneaky
logic we have today.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_process.c | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index b9e9a7d320..0dc49b87d8 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -8695,6 +8695,7 @@ qemuProcessRefreshDisks(virDomainObj *vm,
         qemuDomainDiskPrivate *diskpriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
         struct qemuDomainDiskInfo *info;
         const char *entryname = disk->info.alias;
+        virDomainDiskTray old_tray_status = disk->tray_status;

         if (diskpriv->qomName)
             entryname = diskpriv->qomName;
@@ -8703,31 +8704,32 @@ qemuProcessRefreshDisks(virDomainObj *vm,
             continue;

         if (info->removable) {
-            bool emitEvent = info->tray_open != disk->tray_status;
-            int reason;
-
             if (info->empty)
                 virDomainDiskEmptySource(disk);

             if (info->tray) {
-                if (info->tray_open) {
-                    reason = VIR_DOMAIN_EVENT_TRAY_CHANGE_OPEN;
+                if (info->tray_open)
                     disk->tray_status = VIR_DOMAIN_DISK_TRAY_OPEN;
-                } else {
-                    reason = VIR_DOMAIN_EVENT_TRAY_CHANGE_CLOSE;
+                else
                     disk->tray_status = VIR_DOMAIN_DISK_TRAY_CLOSED;
-                }
-
-                if (emitEvent) {
-                    virObjectEvent *event = virDomainEventTrayChangeNewFromObj(vm, disk->info.alias, reason);
-                    virObjectEventStateQueue(driver->domainEventState, event);
-                }
             }
         }

         /* fill in additional data */
         diskpriv->removable = info->removable;
         diskpriv->tray = info->tray;
+
+        if (diskpriv->tray &&
+            old_tray_status != disk->tray_status) {
+            virDomainEventTrayChangeReason reason = VIR_DOMAIN_EVENT_TRAY_CHANGE_OPEN;
+            virObjectEvent *event;
+
+            if (disk->tray_status == VIR_DOMAIN_DISK_TRAY_CLOSED)
+                reason = VIR_DOMAIN_EVENT_TRAY_CHANGE_CLOSE;
+
+            event = virDomainEventTrayChangeNewFromObj(vm, disk->info.alias, reason);
+            virObjectEventStateQueue(driver->domainEventState, event);
+        }
     }

     return 0;
-- 
2.39.2




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

  Powered by Linux