Blob Blame History Raw
From b53d7b7150f81ee6f014815fa7ee3f1106c491d5 Mon Sep 17 00:00:00 2001
Message-Id: <b53d7b7150f81ee6f014815fa7ee3f1106c491d5@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Thu, 9 Feb 2023 09:40:32 +0100
Subject: [PATCH] qemuProcessRefreshDisks: Don't skip filling of disk
 information if tray state didn't change

Commit 5ef2582646eb98 added emitting of even when refreshign disk state,
where it wanted to avoid sending the event if disk state didn't change.
This was achieved by using 'continue' in the loop filling the
information. Unfortunately this skips extraction of whether the device
has a tray which is propagated into internal structures, which in turn
broke cdrom media change as the code thought there's no tray for the
device.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2166411
Fixes: 5ef2582646eb98af208ce37355f82bdef39931fa
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Kristina Hanicova <khanicov@redhat.com>
(cherry picked from commit 86cfe93ef7fdc2d665a2fc88b79af89e7978ba78)
---
 src/qemu/qemu_process.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 32083de563..7ae859d68f 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -8713,16 +8713,13 @@ qemuProcessRefreshDisks(virDomainObj *vm,
             continue;
 
         if (info->removable) {
-            virObjectEvent *event = NULL;
+            bool emitEvent = info->tray_open != disk->tray_status;
             int reason;
 
             if (info->empty)
                 virDomainDiskEmptySource(disk);
 
             if (info->tray) {
-                if (info->tray_open == disk->tray_status)
-                    continue;
-
                 if (info->tray_open) {
                     reason = VIR_DOMAIN_EVENT_TRAY_CHANGE_OPEN;
                     disk->tray_status = VIR_DOMAIN_DISK_TRAY_OPEN;
@@ -8731,8 +8728,10 @@ qemuProcessRefreshDisks(virDomainObj *vm,
                     disk->tray_status = VIR_DOMAIN_DISK_TRAY_CLOSED;
                 }
 
-                event = virDomainEventTrayChangeNewFromObj(vm, disk->info.alias, reason);
-                virObjectEventStateQueue(driver->domainEventState, event);
+                if (emitEvent) {
+                    virObjectEvent *event = virDomainEventTrayChangeNewFromObj(vm, disk->info.alias, reason);
+                    virObjectEventStateQueue(driver->domainEventState, event);
+                }
             }
         }
 
-- 
2.39.1