Bug 2166235

Summary: vm start successfully even there is a pre-created tap device with the same name (type="direct")
Product: Red Hat Enterprise Linux 9 Reporter: Michal Privoznik <mprivozn>
Component: libvirtAssignee: Michal Privoznik <mprivozn>
libvirt sub component: General QA Contact: yalzhang <yalzhang>
Status: CLOSED ERRATA Docs Contact:
Severity: unspecified    
Priority: unspecified CC: dyuan, jdenemar, jsuchane, laine, lmen, mprivozn, virt-maint, yalzhang
Version: 9.3Keywords: AutomationTriaged, Triaged, Upstream
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libvirt-9.1.0-1.el9 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: 2144738 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.1.0
Embargoed:
Bug Depends On: 2144738    
Bug Blocks:    

Description Michal Privoznik 2023-02-01 09:01:59 UTC
+++ This bug was initially created as a clone of Bug #2144738 +++

Scenario 2: direct type interface

1. create a macvtap device:
# ip l add l eno1 name test type macvtap mode bridge
# ip l show test 
13: test@eno1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 500
    link/ether f2:dc:83:ac:a5:fb brd ff:ff:ff:ff:ff:ff

# virsh dumpxml rhel --xpath //interface 
<interface type="direct">
  <mac address="52:54:00:55:34:bc"/>
  <source dev="eno1" mode="bridge"/>
  <target dev="test"/>
  <model type="virtio"/>
  <address type="pci" domain="0x0000" bus="0x01" slot="0x00" function="0x0"/>
</interface>

# virsh start rhel 
error: Failed to start domain 'rhel'
error: error creating macvtap interface test@eno1 (52:54:00:55:34:bc): File exists

# ip l show test 
Device "test" does not exist.

Try to start the vm the 2nd time, as the pre-created tap device is deleted, the vm start successfully:
# virsh start rhel 
Domain 'rhel' started

--- Additional comment from Michal Privoznik on 2023-01-30 10:40:46 CET ---

(In reply to yalzhang from comment #14) 
> Test on libvirt-9.0.0-2.el9.x86_64, for network interface, the result is as
> expected; 
> but for direct type interface, the pre-created tap device will be deleted,
> please check the scenario 2 below. Thank you.

Yeah, this type isn't fixed. Let me write and post patches.

--- Additional comment from Michal Privoznik on 2023-02-01 09:59:02 CET ---

Alright, so after I started working on patches, I came up with a wide variety of cleanup patches which would need to be backported as well. So let us track that issue in a separate bug and leave this one only for <interface type="network"/>.

Comment 1 Michal Privoznik 2023-02-01 13:50:08 UTC
Patches posted on the list:

https://listman.redhat.com/archives/libvir-list/2023-February/237479.html

Comment 2 Michal Privoznik 2023-02-01 14:52:54 UTC
Merged upstream as:

61d1b9e659 qemu: Don't remove macvtaps on failed start
db4ea3986a conf: Format and parse private data for virDomainNetDef
c0f671e7c9 virnetdevmacvlan: Drop G_GNUC_WARN_UNUSED_RESULT annotation for virNetDevMacVLanDeleteWithVPortProfile()
714af1a50c domain_conf: Rewrite virDomainChrSourceModeTypeFromString() using VIR_ENUM_IMPL()
69db3bd954 domain_conf: Move virDomainNetVhostuserMode enum declaration

v9.0.0-147-g61d1b9e659

Comment 4 yalzhang@redhat.com 2023-03-15 02:27:34 UTC
Test on libvirt-9.1.0-1.el9.x86_64, the result is as expected:
# ip l add l eno1 name test type macvtap mode bridge
# ip l show test 
10: test@eno1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 500
    link/ether 72:54:a0:4b:b6:e5 brd ff:ff:ff:ff:ff:ff
# virsh dumpxml rhel --xpath //interface 
<interface type="direct">
  <mac address="52:54:00:55:34:bc"/>
  <source dev="eno1" mode="bridge"/>
  <target dev="test"/>
  <model type="virtio"/>
  <address type="pci" domain="0x0000" bus="0x01" slot="0x00" function="0x0"/>
</interface>
# virsh start rhel 
error: Failed to start domain 'rhel'
error: error creating macvtap interface test@eno1 (52:54:00:55:34:bc): File exists
# ip l show test
10: test@eno1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 500
    link/ether 72:54:a0:4b:b6:e5 brd ff:ff:ff:ff:ff:ff
# virsh start rhel 
error: Failed to start domain 'rhel'
error: error creating macvtap interface test@eno1 (52:54:00:55:34:bc): File exists
# ip l show test
10: test@eno1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 500
    link/ether 72:54:a0:4b:b6:e5 brd ff:ff:ff:ff:ff:ff

Comment 8 yalzhang@redhat.com 2023-05-19 02:17:27 UTC
Test on libvirt-9.3.0-2.el9.x86_64 with the scenario in comment 4, the result is the same as comment 4, which is as expected.

Comment 10 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