Changing CD ROM medium sometimes fails with 'Tray of device is not open'
Host environment
- Operating system: Fedora-34/35/36, CentOS Stream 8/9
- OS/kernel version: 5.14.18-200.fc34.x86_64 (but can be reproduced with 5.14.10-300.fc35.x86_64 too)
- Architecture: x86
- QEMU flavor: qemu-system-x86_64
- QEMU version: 6.1.0 (but can be reproduced with v7.0.0-rc1 too!)
- QEMU command line: see the attached logs for full command line libvirt generated
Emulated/Virtualized environment
- Operating system: Fedora 34
- OS/kernel version: 5.14.18-200.fc34.x86_64
- Architecture: x86
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:
- eject medium that the machine was started with
- insert a different medium into the CD ROM
Translating the above to QEMU QMP commands this is what the test exercises:
- blockdev-open-tray
- blockdev-remove-medium
- blockdev-del
- blockdev-close-tray
- blockdev-open-tray
- blockdev-remove-medium
- blockdev-add
- blockdev-insert-medium <<< This is where the test fails
- 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: 55adb3c4
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