Bug 1824722

Summary: cdrom tray state is not updated on VM reset
Product: Red Hat Enterprise Linux 9 Reporter: Peter Krempa <pkrempa>
Component: libvirtAssignee: khanicov
libvirt sub component: Storage QA Contact: Han Han <hhan>
Status: CLOSED ERRATA Docs Contact:
Severity: low    
Priority: high CC: chwen, dzheng, hhan, janorel, jdenemar, jsuchane, khanicov, lmen, mprivozn, rjoyce, vgoyal, virt-maint, xchen, xuzhang
Version: 9.0Keywords: Reopened, Triaged
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libvirt-9.0.0-1.el9 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-05-09 07:26:10 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version: 9.0.0
Embargoed:
Attachments:
Description Flags
the libvirtd log of step4
none
the xml of VM in each step none

Description Peter Krempa 2020-04-16 12:16:12 UTC
Description of problem:
state of cdrom tray is not updated (changed to 'closed') when resetting a VM, but the internal tray state in qemu is actually changed to 'closed' without emission of the tray-changed event.

Version-Release number of selected component (if applicable):
6.2.0/upstream

How reproducible:
always

Steps to Reproduce:
1. boot VM with cdrom
2. issue 'eject' in the guest OS on the cdrom
3. virsh reset VM
4. check tray state in qemu and in libvirt:

Actual results:

$ virsh dumpxml upstream | grep tray
      <target dev='sda' bus='scsi' tray='open'/>
$ virsh qemu-monitor-command --hmp upstream info block
libvirt-3-format: /var/lib/libvirt/images/systemrescuecd-amd64-6.1.2.iso (raw, read-only)
    Attached to:      ide0-0-0
    Removable device: locked, tray closed
    Cache mode:       writeback

libvirt-2-format: /tmp/blocktest/cd.iso (raw, read-only)
    Attached to:      scsi0-0-0
    Removable device: not locked, tray open
    Cache mode:       writeback

$ virsh reset upstream
Domain upstream-bj was reset

$ virsh dumpxml upstream | grep tray
      <target dev='sda' bus='scsi' tray='open'/>
$  virsh qemu-monitor-command --hmp upstream info block
libvirt-3-format: /var/lib/libvirt/images/systemrescuecd-amd64-6.1.2.iso (raw, read-only)
    Attached to:      ide0-0-0
    Removable device: not locked, tray closed
    Cache mode:       writeback

libvirt-2-format: /tmp/blocktest/cd.iso (raw, read-only)
    Attached to:      scsi0-0-0
    Removable device: not locked, tray closed
    Cache mode:       writeback

Expected results:
Tray state in the XML matches the tray state in qemu.

Additional info:
Same situation happens on 'reboot' initiated from the guest OS.

Comment 1 Han Han 2020-09-10 09:27:19 UTC
Created attachment 1714397 [details]
the libvirtd log of step4

Hello, I found the cdrom media cannot be updated or eject after retore
Version:
libvirt-6.6.0-4.module+el8.3.0+7883+3d717aa8.x86_64
qemu-kvm-5.1.0-5.module+el8.3.0+7975+b80d25f1.x86_64
or
libvirt-6.0.0-25.2.module+el8.2.1+7722+a9e38cf3.x86_64
qemu-kvm-4.2.0-29.module+el8.2.1+7990+27f1e480.4.x86_6

Steps:
1. Start an VM with cdrom
2. Save it by virsh save
3. Restore it from the saved file by virsh restore
4. Try to eject or update the media
➜  ~ virsh change-media ide sda --eject
error: Failed to complete action eject on media
error: internal error: unable to execute QEMU command 'blockdev-remove-medium': Tray of device 'scsi0-0-0-0' is not open                                                                                                                   

➜  ~ virsh change-media ide sda --update /var/lib/libvirt/images/BOOT.iso
error: Failed to complete action update on media
error: internal error: unable to execute QEMU command 'blockdev-remove-medium': Tray of device 'scsi0-0-0-0' is not open                                                                                                                   

➜  ~
➜  ~ virsh qemu-monitor-command ide --hmp info block
libvirt-2-format: /var/lib/libvirt/images/ide.qcow2 (qcow2)
    Attached to:      ide0-0-0
    Cache mode:       writeback

libvirt-1-format: /var/lib/libvirt/images/boot.iso (raw, read-only)
    Attached to:      scsi0-0-0-0
    Removable device: locked, tray closed
    Cache mode:       writeback

Comment 2 Han Han 2020-09-10 09:28:42 UTC
Please help check if comment1 is the same issue of this bug

Comment 3 Peter Krempa 2020-09-10 13:55:23 UTC
Possibly. You didn't attach the state in the XML along with the 'info block' output and also didn't check it prior to issuing 'virsh change-media', so I'm not sure whether the root cause is similar.

Comment 4 Han Han 2020-09-11 10:53:02 UTC
Created attachment 1714549 [details]
the xml of VM in each step

Detailed Steps:
➜  ~ virsh qemu-monitor-command ide --hmp info block
libvirt-2-format: /var/lib/libvirt/images/ide.qcow2 (qcow2)
    Attached to:      ide0-0-0                             
    Cache mode:       writeback                            
                               
libvirt-1-format: /var/lib/libvirt/images/boot.iso (raw, read-only)
    Attached to:      scsi0-0-0-0
    Removable device: locked, tray closed
    Cache mode:       writeback
                                                       
                                                           
➜  ~ virsh save ide /tmp/ide  
                               
Domain ide saved to /tmp/ide
                          
➜  ~ virsh restore /tmp/ide             
Domain restored from /tmp/ide
                                        
➜  ~ virsh qemu-monitor-command ide --hmp info block
libvirt-2-format: /var/lib/libvirt/images/ide.qcow2 (qcow2)
    Attached to:      ide0-0-0 
    Cache mode:       writeback
                          
libvirt-1-format: /var/lib/libvirt/images/boot.iso (raw, read-only)
    Attached to:      scsi0-0-0-0
    Removable device: locked, tray closed
    Cache mode:       writeback
                                                                   
                                 
➜  ~ virsh change-media ide sda --eject                  
error: Failed to complete action eject on media                                                                                                                                                                                            
error: internal error: unable to execute QEMU command 'blockdev-remove-medium': Tray of device 'scsi0-0-0-0' is not open
       
➜  ~ virsh qemu-monitor-command ide --hmp info block   
libvirt-2-format: /var/lib/libvirt/images/ide.qcow2 (qcow2)        
    Attached to:      ide0-0-0         
    Cache mode:       writeback
                                                          
libvirt-1-format: /var/lib/libvirt/images/boot.iso (raw, read-only)
    Attached to:      scsi0-0-0-0                       
    Removable device: locked, tray closed                  
    Cache mode:       writeback

Comment 6 John Ferlan 2021-09-08 13:31:26 UTC
Bulk update: Move RHEL-AV bugs to RHEL9. If necessary to resolve in RHEL8, then clone to the current RHEL8 release.

Comment 8 Klaus Heinrich Kiwi 2022-04-13 11:37:54 UTC
Bug 2013523 which seems similar is describing it as a regression, but this bug seems to be around at least for a year. Can we please clarify?

Tentatively assigning it a high-priority for now

Comment 9 Michal Privoznik 2022-04-13 12:46:17 UTC
This bug describes reset, which is not that common (although when implemented in libvirt it would probably be tied to RESET event coming from QEMU which is emitted not only on plain 'virsh reset' but also on reboot). Whereas bug 2013523 describes a different behavior: QEMU mysteriously locks tray on incoming migration (restore from a file). While they might look similar they are different bugs.

Comment 10 RHEL Program Management 2022-04-16 07:27:32 UTC
After evaluating this issue, there are no plans to address it further or fix it in an upcoming release.  Therefore, it is being closed.  If plans change such that this issue will be fixed in an upcoming release, then the bug can be reopened.

Comment 11 Han Han 2022-04-18 02:33:48 UTC
(In reply to Michal Privoznik from comment #9)
> This bug describes reset, which is not that common (although when
> implemented in libvirt it would probably be tied to RESET event coming from
> QEMU which is emitted not only on plain 'virsh reset' but also on reboot).
> Whereas bug 2013523 describes a different behavior: QEMU mysteriously locks
> tray on incoming migration (restore from a file). While they might look
> similar they are different bugs.

That means this bug is duplicated to bug 2013523?

Comment 12 Michal Privoznik 2022-04-19 11:34:22 UTC
(In reply to Han Han from comment #11)
> (In reply to Michal Privoznik from comment #9)
> > This bug describes reset, which is not that common (although when
> > implemented in libvirt it would probably be tied to RESET event coming from
> > QEMU which is emitted not only on plain 'virsh reset' but also on reboot).
> > Whereas bug 2013523 describes a different behavior: QEMU mysteriously locks
> > tray on incoming migration (restore from a file). While they might look
> > similar they are different bugs.
> 
> That means this bug is duplicated to bug 2013523?

No, as I say these are two different bugs.

Comment 14 Michal Privoznik 2022-07-25 08:42:08 UTC
This seems to be the same issue: https://gitlab.com/qemu-project/qemu/-/issues/933

Comment 19 khanicov 2022-12-08 14:11:26 UTC
Patches merged into upstream as:

f47af66624f qemu: refresh internal domain state after reset
75952d18740 qemu: refresh state after reboot initiated from the guest

v8.10.0-71-g75952d1874

Comment 20 Han Han 2022-12-13 02:46:51 UTC
tested on qemu v8.10.0-87-ga2ae3d299c and qemu-kvm-7.1.0-6.el9.x86_64
1. Start VM and then eject the CDROM in guest. Check the tray status:
# virsh qemu-monitor-command rhel-9.2 --hmp info block
libvirt-2-format: /var/lib/libvirt/images/rhel-9.2.qcow2 (qcow2)
    Attached to:      /machine/peripheral/virtio-disk0/virtio-backend
    Cache mode:       writeback

libvirt-1-format: /var/lib/libvirt/images/boot.iso (raw, read-only)
    Attached to:      scsi0-0-0-2
    Removable device: not locked, tray open
    Cache mode:       writeback


2. Reboot the VM by guest, `virsh reset`, `virsh reboot`. Then check the tray status:
# virsh qemu-monitor-command rhel-9.2 --hmp info block
libvirt-2-format: /var/lib/libvirt/images/rhel-9.2.qcow2 (qcow2)
    Attached to:      /machine/peripheral/virtio-disk0/virtio-backend
    Cache mode:       writeback

libvirt-1-format: /var/lib/libvirt/images/boot.iso (raw, read-only)
    Attached to:      scsi0-0-0-2
    Removable device: locked, tray closed
    Cache mode:       writeback

The tray status is reset to locked, tray closed.
However, no tray-change event is emitted. Expect to emit the tray-change event with the reason TRAY_CLOSE.

Comment 21 khanicov 2022-12-13 12:43:36 UTC
I did not consider emitting an event as part of the bug, but I found the issue and fixed it.

Proposed patch on the list:
https://listman.redhat.com/archives/libvir-list/2022-December/236300.html

Comment 22 Han Han 2022-12-14 09:12:12 UTC
(In reply to khanicov from comment #21)
> I did not consider emitting an event as part of the bug, but I found the
> issue and fixed it.
> 
> Proposed patch on the list:
> https://listman.redhat.com/archives/libvir-list/2022-December/236300.html

Tested on v8.10.0-118-g5ef2582646 and qemu-kvm-7.1.0-6.el9.x86_64:
1. Start VM and then eject the CDROM in guest.
2. Reboot VM by `virsh reset`, `virsh reboot` or guest, the tray-change event is emitted as expected

Check tray-changed event without tray status change
1. Start VM
2. Reboot VM by `virsh reset`, `virsh reboot` or guest, the tray-change event is NOT emitted as expected

Comment 26 Han Han 2023-02-17 04:19:32 UTC
Tested as comment20 and comment22 on libvirt-9.0.0-5.el9.x86_64 qemu-kvm-7.2.0-8.el9.x86_64. PASS

Comment 28 errata-xmlrpc 2023-05-09 07:26:10 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (libvirt bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2023:2171