Bug 2160435 - A hot-plugged scsi CDROM can't be ejected
Summary: A hot-plugged scsi CDROM can't be ejected
Keywords:
Status: VERIFIED
Alias: None
Product: Red Hat Enterprise Linux 9
Classification: Red Hat
Component: libvirt
Version: 9.2
Hardware: Unspecified
OS: Unspecified
unspecified
medium
Target Milestone: rc
: ---
Assignee: Peter Krempa
QA Contact: Han Han
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2023-01-12 12:19 UTC by Xianghua Chen
Modified: 2023-08-10 03:48 UTC (History)
11 users (show)

Fixed In Version: libvirt-9.3.0-1.el9
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed:
Type: Bug
Target Upstream Version: 9.3.0
Embargoed:


Attachments (Terms of Use)
scripts for reproducing (2.78 KB, application/gzip)
2023-04-03 10:25 UTC, Han Han
no flags Details


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker RHELPLAN-144934 0 None None None 2023-01-12 12:20:50 UTC

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


Note You need to log in before you can comment on or make changes to this bug.