Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 2160435

Summary: A hot-plugged scsi CDROM can't be ejected
Product: Red Hat Enterprise Linux 9 Reporter: Xianghua Chen <xchen>
Component: libvirtAssignee: Peter Krempa <pkrempa>
libvirt sub component: Storage QA Contact: Han Han <hhan>
Status: CLOSED ERRATA Docs Contact:
Severity: medium    
Priority: unspecified CC: dzheng, jdenemar, kkoukiou, lmen, mkletzan, pkrempa, qzhang, virt-maint, wshi, ymao, yunyang
Version: 9.2Keywords: Triaged
Target Milestone: rcFlags: pm-rhel: mirror+
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libvirt-9.3.0-1.el9 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-11-07 08:30:47 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.3.0
Embargoed:
Attachments:
Description Flags
scripts for reproducing none

Description Xianghua Chen 2023-01-12 12:19:15 UTC
Description of problem:
[Machines] "Force eject" don't take effect when "Eject disc from running VM"

Packages:
cockpit-machines-280-1.el9.noarch
cockpit-282-1.el9.x86_64
libvirt-dbus-1.4.1-5.el9.x86_64
libvirt-8.10.0-2.el9.x86_64
How reproducible:
100%

Steps:
1. Create a running vm on RHEL9, enter vm details page
2. Prepare a iso like:
# touch /var/lib/libvirt/images/fake1.iso
3. Click "Add disk", choose "Custom path"
Custom path: /var/lib/libvirt/images/fake1.iso
Device: CD/DVD disc
Click "Add"
4. Click "Eject" after the new added disk , and click Eject on the dialog:
Media could not be ejected from cirros
internal error: unable to execute QEMU command 'blockdev-remove-medium': Tray of device 'scsi0-0-0-0' is not open
5. Click "Force eject" , no effect


Actual results:
As show in step.

Expected results:
1) Could eject in step 4.
It may related to bug https://bugzilla.redhat.com/show_bug.cgi?id=1824722 , will try again after it got fixed
2) In step5, the force eject should take effect, related issue for virt-manager upstream is here https://github.com/virt-manager/virt-manager/issues/442 

Additional info:

Comment 1 Xianghua Chen 2023-02-08 08:09:14 UTC
Tried again since https://bugzilla.redhat.com/show_bug.cgi?id=1824722 is fixed now, problem is still there.
Related to libvirt bug: https://bugzilla.redhat.com/show_bug.cgi?id=2166411

Comment 2 Xianghua Chen 2023-02-21 07:58:05 UTC
Since bug 2166411 is fixed, Tried again with :
cockpit-machines-283-1.el9.noarch
libvirt-9.0.0-6.el9.x86_64
qemu-kvm-7.2.0-8.el9.x86_64

Steps:
1. Create a running vm on RHEL9, enter vm details page
2. Prepare a iso like:
# touch /var/lib/libvirt/images/fake1.iso
3. Click "Add disk", choose "Custom path"
Custom path: /var/lib/libvirt/images/fake1.iso
Device: CD/DVD disc
Click "Add"
4. Click "Eject" after the new added disk , and click Eject on the dialog:
Media could not be ejected from cirros
internal error: unable to execute QEMU command 'blockdev-remove-medium': Tray of device 'scsi0-0-0-0' is not open
5. Click "Force eject" , no effect

The problem is still there .

Comment 3 Katerina Koukiou 2023-03-28 18:20:00 UTC
This is reproduceable from CLI with:

$  virsh change-media $VM_NAME 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

Assuming that the media we are ejecting has target='sda' in the domain XML. Moving libvirt component for investigation as this is not specific to cockpit-machines.

Comment 4 Han Han 2023-03-29 07:12:12 UTC
It looks like the Bug 2166411 - virt-xml: Updating cdrom device file: Error attempting device update: internal error: unable to execute QEMU command 'blockdev-remove-medium': Tray of device 'scsi0-0-0' is not open. 
Please help check the results on libvirt-9.0.0-4.el9 or the later versions.

Comment 5 Martin Kletzander 2023-03-30 13:00:29 UTC
I cannot reproduce this with libvirt-9.0.0-10.el9_2.x86_64 so it might be a duplicate of Bug 2166411, testing cockpit-machines with the newer one would be beneficial.  Also what is the guest OS in this case?

Comment 10 Han Han 2023-04-03 10:14:20 UTC
Th

Comment 11 Han Han 2023-04-03 10:20:24 UTC
It has been confirmed that the reproducing steps are:
1. Start a VM
2. Hot-plug the SCSI cdrom with media
3. Eject the cdrom by `virsh change-media --eject`

If the VM starts with  SCSI cdrom. Ejecting media by `virsh change-media --eject` will not meet the bug.

BTW, such the SCSI cdrom hot-plug is supported since 3078799fef(v8.10.0). And the test cannot work on that version.

Comment 12 Han Han 2023-04-03 10:25:31 UTC
Created attachment 1955433 [details]
scripts for reproducing

Comment 13 Peter Krempa 2023-04-03 11:15:10 UTC
Ah, that makes sense. On hotplug of the cdrom we don't seem to refresh the state of the drive and thus we don't probe that it actually has a tray that needs to be ejected first.

That's the reason it has exactly the same behaviour as what was fixed in bug 2166411

Comment 14 Peter Krempa 2023-04-24 11:06:06 UTC
Fixed upstream:

commit fb1bfad7ad994756aa5bd821e03b89df7c1a5b23
Author: Peter Krempa <pkrempa>
Date:   Wed Apr 19 16:49:52 2023 +0200

    qemu: hotplug: Update disk private data after hotplug
    
    The disk private data contain information about the tray and
    removability of the disk. Until recently we didn't support hotplug of
    removable disks thus it wasn't a problem but now when you can hotplug a
    CDROM you would not be able to open its tray.
    
    Fix it by updating the hotplugged disk the same way we do at startup.
    
    Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2160435
    Signed-off-by: Peter Krempa <pkrempa>
    Reviewed-by: Ján Tomko <jtomko>

v9.2.0-284-gfb1bfad7ad

Comment 15 Han Han 2023-04-25 07:45:16 UTC
Works on libvirt-v9.2.0-296-g0eebdce995 qemu-kvm-7.2.0-14.el9_2.x86_64:
+ /root/libvirt/build/tools/virsh create /root/scsi-cdrom-hotplug-eject/rhel.xml
Domain 'rhel' created from /root/scsi-cdrom-hotplug-eject/rhel.xml

+ /root/libvirt/build/tools/virsh event --domain rhel --event agent-lifecycle
event 'agent-lifecycle' for domain 'rhel': state: 'connected' reason: 'channel event'
events received: 1

+ /root/libvirt/build/tools/virsh attach-device rhel /root/scsi-cdrom-hotplug-eject/cdrom.xml
Device attached successfully

+ sleep 1
++ xmllint --xpath 'string(/disk/target/@dev)' /root/scsi-cdrom-hotplug-eject/cdrom.xml
+ /root/libvirt/build/tools/virsh change-media rhel sdc --eject
Successfully ejected media.
+ check_failure 'Fail to eject cdrom' 1
+ '[' 0 -ne 0 ']'
+ clean
+ /root/libvirt/build/tools/virsh destroy rhel
Domain 'rhel' destroyed

Comment 19 Han Han 2023-05-24 09:34:28 UTC
Tested as comment12 on qemu-kvm-8.0.0-4.el9.x86_64 libvirt-9.3.0-2.el9.x86_64:
+ virsh create /root/scsi-cdrom-hotplug-eject/rhel.xml
Domain 'rhel' created from /root/scsi-cdrom-hotplug-eject/rhel.xml

+ virsh event --domain rhel --event agent-lifecycle
event 'agent-lifecycle' for domain 'rhel': state: 'connected' reason: 'channel event'
events received: 1

+ virsh attach-device rhel /root/scsi-cdrom-hotplug-eject/cdrom.xml
Device attached successfully

+ sleep 1
++ xmllint --xpath 'string(/disk/target/@dev)' /root/scsi-cdrom-hotplug-eject/cdrom.xml
+ virsh change-media rhel sdc --eject
Successfully ejected media.
+ check_failure 'Fail to eject cdrom' 1
+ '[' 0 -ne 0 ']'
+ clean
+ virsh destroy rhel
Domain 'rhel' destroyed

Comment 21 errata-xmlrpc 2023-11-07 08:30:47 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 (Moderate: libvirt security, 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/RHSA-2023:6409