Bug 2166411

Summary: 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
Product: Red Hat Enterprise Linux 9 Reporter: Martin Pitt <mpitt>
Component: libvirtAssignee: Peter Krempa <pkrempa>
libvirt sub component: General QA Contact: Han Han <hhan>
Status: CLOSED ERRATA Docs Contact:
Severity: urgent    
Priority: high CC: berrange, chwen, crobinso, extras-qa, hongzliu, jdenemar, jjongsma, juzhou, khanicov, lmen, mprivozn, philip.wyett, pkrempa, smitterl, tyan, tzheng, virt-maint, xchen
Version: 9.2Keywords: Regression, Triaged
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Unspecified   
Whiteboard: CockpitTest
Fixed In Version: libvirt-9.0.0-4.el9 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: 2163117 Environment:
Last Closed: 2023-05-09 07:27:45 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:
Embargoed:
Bug Depends On: 2163117    
Bug Blocks:    

Description Martin Pitt 2023-02-01 18:32:15 UTC
This bug now went into C9S, thus very soon in RHEL 9.2 as well:
https://artifacts.dev.testing-farm.io/10d58214-9b49-42af-97a5-58d21280555a/

+++ This bug was initially created as a clone of Bug #2163117 +++

Description of problem: In recent Fedora (and also Arch Linux [1]) there is a regression with trying to insert/change a virtual CD-ROM medium.


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

virt-install-4.1.0-1.fc37.noarch
libvirt-daemon-9.0.0-1.fc38.x86_64
qemu-system-x86-core-7.2.0-4.fc38.x86_64
kernel-core-6.2.0-0.rc4.20230118gitc1649ec55708.33.fc38.x86_64

How reproducible: Always


Steps to Reproduce:

systemctl start virtqemud virtnetworkd
virsh net-start default || true  # may already be running
touch /var/lib/libvirt/bogus.iso
virt-install --memory 50 --pxe --virt-type qemu --graphics none --os-variant alpinelinux3.8 --disk device=cdrom,bus=scsi --wait 0 --name test1
virt-xml test1 --edit target.dev=sda --disk source.file=/var/lib/libvirt/bogus.iso,type=file --update

Actual results: Last command fails with

ERROR    Error attempting device update: internal error: unable to execute QEMU command 'blockdev-remove-medium': Tray of device 'scsi0-0-0' is not open


Expected results: command succeeds, and turns the previous

    <disk type='file' device='cdrom'>
      <driver name='qemu'/>
      <target dev='sda' bus='scsi'/>
      <readonly/>
      <alias name='scsi0-0-0'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>

into

    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <source file='/var/lib/libvirt/bogus.iso' index='2'/>
      <backingStore/>
      <target dev='sda' bus='scsi'/>
      <readonly/>
      <alias name='scsi0-0-0'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>

Additional info: This could very well be a regression in QEMU. If so, please reassign. Thanks!

Comment 1 Jonathon Jongsma 2023-02-01 20:45:28 UTC
This appears to be a bug in libvirt. 

According to git bisect, 5ef2582646eb98af208ce37355f82bdef39931fa is the first bad commit, which makes sense becuase the the commit is related to disk tray events. So the regression was first included in libvirt 9.0.

Comment 2 Peter Krempa 2023-02-02 08:00:57 UTC
*** Bug 2166503 has been marked as a duplicate of this bug. ***

Comment 5 smitterl 2023-02-09 08:36:00 UTC
I'd like to highlight that because of this issue we can't exchange cdroms in a VM while it's running, this looks like a critical functionality and I'm not aware of any workaround, I might be wrong of course.

Comment 6 Peter Krempa 2023-02-09 08:47:13 UTC
The aforementioned commit causes this regression by 'continue'-ing the for loop extracting disk information if the disk tray state didn't change. That unfortunately skipped over the assignment of whether the device is removable and has a tray into disk private data, which is the primary task the function does.

I'll post a patch soon.

Comment 7 Peter Krempa 2023-02-09 09:29:25 UTC
Fixed upstream:

commit 86cfe93ef7fdc2d665a2fc88b79af89e7978ba78
Author: Peter Krempa <pkrempa>
Date:   Thu Feb 9 09:40:32 2023 +0100

    qemuProcessRefreshDisks: Don't skip filling of disk information if tray state didn't change
    
    Commit 5ef2582646eb98 added emitting of even when refreshign disk state,
    where it wanted to avoid sending the event if disk state didn't change.
    This was achieved by using 'continue' in the loop filling the
    information. Unfortunately this skips extraction of whether the device
    has a tray which is propagated into internal structures, which in turn
    broke cdrom media change as the code thought there's no tray for the
    device.
    
    Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2166411
    Fixes: 5ef2582646eb98af208ce37355f82bdef39931fa
    Signed-off-by: Peter Krempa <pkrempa>
    Reviewed-by: Kristina Hanicova <khanicov>

Comment 8 smitterl 2023-02-09 09:31:15 UTC
Thanks for bringing the good news Peter!

Comment 11 Han Han 2023-02-14 12:18:27 UTC
Tested on libvirt-9.0.0-5.el9.x86_64 qemu-kvm-7.2.0-8.el9.x86_64. PASS

Comment 14 Han Han 2023-02-16 06:29:41 UTC
Test pass on libvirt-9.0.0-5.el9.x86_64 qemu-kvm-7.2.0-8.el9.x86_64
Covered by the tests of libvirt-RHEL-9.2-runtest-x86_64-function-attach_detach_media

Comment 16 errata-xmlrpc 2023-05-09 07:27:45 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