Bug 2036895

Summary: Update-device for interface with --live failed but with --persistent succeeded when a different alias specified
Product: Red Hat Enterprise Linux 9 Reporter: Yanqiu Zhang <yanqzhan>
Component: libvirtAssignee: Michal Privoznik <mprivozn>
libvirt sub component: Networking QA Contact: Yanqiu Zhang <yanqzhan>
Status: CLOSED ERRATA Docs Contact:
Severity: unspecified    
Priority: unspecified CC: dyuan, jdenemar, jsuchane, mprivozn, virt-maint, xuzhang, yalzhang, yanqzhan
Version: 9.0Keywords: AutomationBackLog, Triaged, Upstream
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-8.0.0-0rc1.1.el9 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-05-17 12:46:17 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: 8.0.0
Embargoed:

Description Yanqiu Zhang 2022-01-04 11:07:43 UTC
Description of problem:
Update-device for interface with --live failed but with --persistent succeeded when a different alias specified

Version-Release number of selected component (if applicable):
libvirt-7.10.0-1.el9.x86_64
qemu-kvm-6.2.0-1.el9.x86_64

How reproducible:
100%

Steps to Reproduce:
1. edit vm:
    <interface type='network'>
      <mac address='52:54:00:44:11:60'/>
      <source network='default'/>
      <model type='virtio'/>
    </interface>

2. start vm
# virsh start avocado-bios
Domain 'avocado-bios' started
# virsh dumpxml avocado-bios |grep /inter -B8
    </controller>
    <interface type='network'>
      <mac address='52:54:00:44:11:60'/>
      <source network='default' portid='0728375b-5586-451d-8bf1-193f979278a5' bridge='virbr0'/>
      <target dev='vnet4'/>
      <model type='virtio'/>
      <alias name='net0'/>
      <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
    </interface>

3. update-device
# cat iface-new.xml
    <interface type='network'>
      <mac address='52:54:00:44:11:60'/>
      <source network='default' portid='0728375b-5586-451d-8bf1-193f979278a5' bridge='virbr0'/>
      <target dev='vnet4'/>
      <model type='virtio'/>
            <link state='down'/>
      <alias name='net1'/>
      <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
    </interface>

# virsh update-device avocado-bios iface-new.xml
error: Failed to update device from iface-new.xml
error: device not found: no device found at address '0000:01:00.0' matching MAC address '52:54:00:44:11:60' and alias 'net1'

# virsh update-device avocado-bios iface-new.xml --persistent
Device updated successfully

Then get different live xml and inactive xml
# virsh dumpxml avocado-bios |grep /interface -B8
    <interface type='network'>
      <mac address='52:54:00:44:11:60'/>
      <source network='default' portid='1367e7d9-9156-4298-83aa-02c7ccba264b' bridge='virbr0'/>
      <target dev='vnet5'/>
      <model type='virtio'/>
      <link state='down'/>
      <alias name='net0'/>
      <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
    </interface>

# virsh dumpxml avocado-bios --inactive|grep /interface -B8
    </controller>
    <interface type='network'>
      <mac address='52:54:00:44:11:60'/>
      <source network='default'/>
      <model type='virtio'/>
      <link state='down'/>
      <alias name='net1'/>
      <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
    </interface>


Actual results:
As in step3, update-device --live failed, but --persistent succeeded.

Expected results:
--persistent should only succeed when both --live and --config can succeed.
The live update-device should succeed or sth.

Additional info:
In man page: 
  "For  compatibility  purposes,  --persistent behaves like --config for an offline domain, and like --live --config for a running domain."
Take an example:
  # virsh attach-device avocado-vt-vm1 filesystem.xml --persistent 
   error: Failed to attach device from filesystem.xml
   error: Operation not supported: live attach of device 'filesystem' is not supported
  # virsh attach-device avocado-vt-vm1 filesystem.xml --config 
  Device attached successfully

Comment 1 Michal Privoznik 2022-01-04 16:47:15 UTC
This is bug in qemuDomainUpdateDeviceFlags(). Using --persistent is equivalent to --live --config; and qemu implementation does a copy of parsed input XML so that the original can be fed to live attach handling function and the copy to config attach handling function. But during this copy creation the live information is not preserved (the alias is considered as live information). The fix should be trivial, just swap those two copies.

Comment 2 Michal Privoznik 2022-01-04 17:00:04 UTC
Patch posted upstream:

https://listman.redhat.com/archives/libvir-list/2022-January/msg00129.html

Comment 3 Michal Privoznik 2022-01-06 11:34:56 UTC
Merged upstream:

7d9a7fdcd4 Account for fact that virDomainDeviceDefCopy() does an inactive copy

v7.10.0-431-g7d9a7fdcd4

Comment 6 Yanqiu Zhang 2022-01-10 08:23:37 UTC
Reproduce for detach-device scenario:
libvirt-7.10.0-1.el9.x86_64
qemu-kvm-6.2.0-1.el9.x86_64

Steps:
# virsh detach-device avocado-bios iface.xml 
error: Failed to detach device from iface.xml
error: device not found: no device found at address '(<null>)' matching MAC address '52:54:00:44:11:60' and alias 'net1'

# virsh detach-device avocado-bios iface.xml  --persistent
Device detached successfully


Pre-verify on:
libvirt: v7.10.0-469-g82d514084a
qemu-kvm-6.2.0-1.fc36.x86_64

Steps:
1. update-device:
# virsh update-device vm-bios iface-new.xml 
error: Failed to update device from iface-new.xml
error: device not found: no device found at address '0000:01:00.0' matching MAC address '52:54:00:8c:f5:1c' and alias 'net1'

# virsh update-device vm-bios iface-new.xml  --live
error: Failed to update device from iface-new.xml
error: device not found: no device found at address '0000:01:00.0' matching MAC address '52:54:00:8c:f5:1c' and alias 'net1'

# virsh update-device vm-bios iface-new.xml  --persistent
error: Failed to update device from iface-new.xml
error: device not found: no device found at address '0000:01:00.0' matching MAC address '52:54:00:8c:f5:1c' and alias 'net1'

Check both live and inactive xml, neither changed:
# virsh dumpxml vm-bios |grep /inter -B8
    </controller>
    <interface type='network'>
      <mac address='52:54:00:8c:f5:1c'/>
      <source network='default' portid='40ea7af5-fb7e-4643-94c4-471d2341d2f7' bridge='virbr0'/>
      <target dev='vnet1'/>
      <model type='virtio'/>
      <alias name='net0'/>
      <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
    </interface>
# virsh dumpxml vm-bios --inactive |grep /inter -B8
    <controller type='virtio-serial' index='0'>
      <address type='pci' domain='0x0000' bus='0x03' slot='0x00' function='0x0'/>
    </controller>
    <interface type='network'>
      <mac address='52:54:00:8c:f5:1c'/>
      <source network='default'/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
    </interface>

# virsh update-device vm-bios iface-new.xml  --config
Device updated successfully

# virsh dumpxml vm-bios --inactive |grep /inter -B8
      <address type='pci' domain='0x0000' bus='0x03' slot='0x00' function='0x0'/>
    </controller>
    <interface type='network'>
      <mac address='52:54:00:8c:f5:1c'/>
      <source network='default'/>
      <model type='virtio'/>
      <link state='down'/>    <==changed
      <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
    </interface>

2. Detach-device:
# cat iface.xml
    <interface type='network'>
      <mac address='52:54:00:8c:f5:1c'/>
      <source network='default' portid='bdb8eeec-33d4-42b0-b7be-aacf84105c23' bridge='virbr0'/>
      <target dev='vnet2'/>
      <model type='virtio'/>
      <alias name='net1'/>  <==only change alias from live xml
      <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
    </interface>

# virsh detach-device vm-bios iface.xml 
error: Failed to detach device from iface.xml
error: device not found: no device found at address '0000:01:00.0' matching MAC address '52:54:00:8c:f5:1c' and alias 'net1'

# virsh detach-device vm-bios iface.xml  --live
error: Failed to detach device from iface.xml
error: device not found: no device found at address '0000:01:00.0' matching MAC address '52:54:00:8c:f5:1c' and alias 'net1'

# virsh detach-device vm-bios iface.xml  --persistent
error: Failed to detach device from iface.xml
error: device not found: no device found at address '0000:01:00.0' matching MAC address '52:54:00:8c:f5:1c' and alias 'net1'

# virsh dumpxml vm-bios |grep /interface
    </interface>
# virsh dumpxml vm-bios --inactive |grep /inter
    </interface>

# virsh detach-device vm-bios iface.xml  --config
Device detached successfully

# virsh dumpxml vm-bios |grep /interface
    </interface>

# virsh dumpxml vm-bios --inactive |grep /inter 
(nothing output)

Comment 11 Yanqiu Zhang 2022-01-25 03:40:49 UTC
Verify on:
libvirt-8.0.0-1.el9.x86_64
qemu-kvm-6.2.0-3.el9.x86_64

Steps and results are same as pre-verification in comment6.

Comment 12 Yanqiu Zhang 2022-01-25 07:29:02 UTC
Covered in existing cases' steps.

Comment 14 errata-xmlrpc 2022-05-17 12:46:17 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 (new packages: libvirt), 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-2022:2390