Bug 1780508

Summary: passthrough input device disappeared in the namespace when trying to attach the device to the guest twice
Product: Red Hat Enterprise Linux Advanced Virtualization Reporter: yafu <yafu>
Component: libvirtAssignee: khanicov
Status: CLOSED ERRATA QA Contact: Lili Zhu <lizhu>
Severity: low Docs Contact:
Priority: low    
Version: 8.2CC: jdenemar, jsuchane, khanicov, lizhu, lmen, mprivozn, xuzhang
Target Milestone: rcKeywords: Triaged, Upstream
Target Release: 8.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libvirt-7.6.0-1.module+el8.5.0+12097+2c77910b Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-11-16 07:49:56 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: 7.6.0
Embargoed:

Description yafu 2019-12-06 08:50:26 UTC
Description of problem:
passthrough input device disappeared in the namespace when trying to attach the device to the guest twice

Version-Release number of selected component (if applicable):
libvirt-5.10.0-1.el8.x86_64

How reproducible:
100%

Steps to Reproduce:
1.Prepare the passthrough input device xml:
#cat input.xml
<input type='passthrough' bus='virtio'>
    <source evdev='/dev/input/event1'/>
</input>

2.Attach the input device to a guest:
# virsh attach-device vm2 input.xml 
Device attached successfully

3.Check the input device in the qemu namespace:
# nsenter -t `pidof qemu-kvm` -m ls -l /dev/input
total 0
crw-rw----. 1 qemu qemu 13, 65 Dec  6 03:20 event1

4.Attach the input device to the same guest again:
#virsh attach-device vm2 input.xml
error: Failed to attach device from dev.xml
error: internal error: unable to execute QEMU command 'device_add': /dev/input/event1: failed to get exclusive access: Device or resource bus

5.Check the input device in the qemu namespace:
# nsenter -t `pidof qemu-kvm` -m ls -l /dev/input
total 0

Actual results:
passthrough input device disappeared in the namespace when trying to attach the device to the guest twice

Expected results:
passthrough input device should not disappeare in the namespace when trying to attach the device to the guest twice

Additional info:

Comment 3 khanicov 2021-07-07 10:49:32 UTC
Patches proposed on the list:
https://listman.redhat.com/archives/libvir-list/2021-July/msg00129.html

Comment 4 khanicov 2021-07-15 13:17:31 UTC
Merged upstream as:

b0ef407c65 qemu: Check for existing file in namespace
cbcde4df3b virprocess: Return retval of the child on success, not 0
c39757f700 qemu: Do not erase duplicate devices from namespace if error occurs

v7.5.0-92-gc39757f700

Comment 5 Lili Zhu 2021-07-30 01:50:25 UTC
Pre-verified on libvirt v7.6.0-rc1-8-gf5c022a389 according to Comment 0

Comment 9 Lili Zhu 2021-08-05 04:54:54 UTC
Verify this bug with:
libvirt-daemon-7.6.0-1.module+el8.5.0+12097+2c77910b.x86_64

Testing result matches with expected result, mark the bug as verified.

Comment 11 errata-xmlrpc 2021-11-16 07:49:56 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 (virt:av 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-2021:4684