735c6b
From b53d7b7150f81ee6f014815fa7ee3f1106c491d5 Mon Sep 17 00:00:00 2001
735c6b
Message-Id: <b53d7b7150f81ee6f014815fa7ee3f1106c491d5@dist-git>
735c6b
From: Peter Krempa <pkrempa@redhat.com>
735c6b
Date: Thu, 9 Feb 2023 09:40:32 +0100
735c6b
Subject: [PATCH] qemuProcessRefreshDisks: Don't skip filling of disk
735c6b
 information if tray state didn't change
735c6b
735c6b
Commit 5ef2582646eb98 added emitting of even when refreshign disk state,
735c6b
where it wanted to avoid sending the event if disk state didn't change.
735c6b
This was achieved by using 'continue' in the loop filling the
735c6b
information. Unfortunately this skips extraction of whether the device
735c6b
has a tray which is propagated into internal structures, which in turn
735c6b
broke cdrom media change as the code thought there's no tray for the
735c6b
device.
735c6b
735c6b
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2166411
735c6b
Fixes: 5ef2582646eb98af208ce37355f82bdef39931fa
735c6b
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
735c6b
Reviewed-by: Kristina Hanicova <khanicov@redhat.com>
735c6b
(cherry picked from commit 86cfe93ef7fdc2d665a2fc88b79af89e7978ba78)
735c6b
---
735c6b
 src/qemu/qemu_process.c | 11 +++++------
735c6b
 1 file changed, 5 insertions(+), 6 deletions(-)
735c6b
735c6b
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
735c6b
index 32083de563..7ae859d68f 100644
735c6b
--- a/src/qemu/qemu_process.c
735c6b
+++ b/src/qemu/qemu_process.c
735c6b
@@ -8713,16 +8713,13 @@ qemuProcessRefreshDisks(virDomainObj *vm,
735c6b
             continue;
735c6b
 
735c6b
         if (info->removable) {
735c6b
-            virObjectEvent *event = NULL;
735c6b
+            bool emitEvent = info->tray_open != disk->tray_status;
735c6b
             int reason;
735c6b
 
735c6b
             if (info->empty)
735c6b
                 virDomainDiskEmptySource(disk);
735c6b
 
735c6b
             if (info->tray) {
735c6b
-                if (info->tray_open == disk->tray_status)
735c6b
-                    continue;
735c6b
-
735c6b
                 if (info->tray_open) {
735c6b
                     reason = VIR_DOMAIN_EVENT_TRAY_CHANGE_OPEN;
735c6b
                     disk->tray_status = VIR_DOMAIN_DISK_TRAY_OPEN;
735c6b
@@ -8731,8 +8728,10 @@ qemuProcessRefreshDisks(virDomainObj *vm,
735c6b
                     disk->tray_status = VIR_DOMAIN_DISK_TRAY_CLOSED;
735c6b
                 }
735c6b
 
735c6b
-                event = virDomainEventTrayChangeNewFromObj(vm, disk->info.alias, reason);
735c6b
-                virObjectEventStateQueue(driver->domainEventState, event);
735c6b
+                if (emitEvent) {
735c6b
+                    virObjectEvent *event = virDomainEventTrayChangeNewFromObj(vm, disk->info.alias, reason);
735c6b
+                    virObjectEventStateQueue(driver->domainEventState, event);
735c6b
+                }
735c6b
             }
735c6b
         }
735c6b
 
735c6b
-- 
735c6b
2.39.1
735c6b