performance: 0.885 device: 0.852 graphic: 0.814 PID: 0.776 files: 0.749 architecture: 0.700 socket: 0.697 network: 0.685 register: 0.680 ppc: 0.677 semantic: 0.663 kernel: 0.648 vnc: 0.640 assembly: 0.620 peripherals: 0.614 x86: 0.597 hypervisor: 0.584 permissions: 0.581 i386: 0.560 risc-v: 0.560 VMM: 0.515 KVM: 0.487 TCG: 0.473 boot: 0.464 arm: 0.426 debug: 0.421 user-level: 0.391 virtual: 0.337 mistranslation: 0.266 Changing CD ROM medium sometimes fails with 'Tray of device is not open' Description of problem: QEMU reports that a CD ROM tray is not open when exchanging media: `unable to execute QEMU command 'blockdev-remove-medium': Tray of device 'ide0-1-0' is not open` We see the issue in upstream libvirt integration tests. However, this issue is a race and the reproducibility rate is <15%. Steps to reproduce: On the high level this is what we do: 1. eject medium that the machine was started with 2. insert a different medium into the CD ROM Translating the above to QEMU QMP commands this is what the test exercises: 1. blockdev-open-tray 2. blockdev-remove-medium 3. blockdev-del 4. blockdev-close-tray 5. blockdev-open-tray 6. blockdev-remove-medium 7. blockdev-add 8. blockdev-insert-medium <<< This is where the test fails 9. blockdev-close-tray Additional information: I bisected the code (3 times just to be sure since it's a race) and the following commit fell out of it: 55adb3c45620c31f29978f209e2a44a08d34e2da I'm attaching QEMU trace events and a bunch of libvirt test logs (good and bad for comparison). If you think of anything else I should provide in order to help with the issue analysis, please let me know what other option should be turned on.[qemu_traces.tar.gz](/uploads/32e48c92efce3484e552df063795af4d/qemu_traces.tar.gz)