Bug 1543775

Summary: 'update-device' with alias in disk did not work actually and 'cold-plug' device with alias to running VM will fail in dumpxml file
Product: Red Hat Enterprise Linux 7 Reporter: jiyan <jiyan>
Component: libvirtAssignee: Michal Privoznik <mprivozn>
Status: CLOSED ERRATA QA Contact: Han Han <hhan>
Severity: urgent Docs Contact:
Priority: urgent    
Version: 7.5CC: dyuan, hhan, jdenemar, jherrman, jiyan, jsuchane, lmen, meili, mtessun, salmy, xuzhang, yalzhang, yisun
Target Milestone: rcKeywords: Upstream, ZStream
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-4.3.0-1.el7 Doc Type: Bug Fix
Doc Text:
Previously, the libvirt service used the incorrect XML configuration when checking for a duplicate user alias. As a consequence, hot-plugging a device with a unique alias to a guest virtual machine in some cases failed with a "non unique alias" error message. With this update, libvirt uses the correct XML files for verifying the device alias, which prevents the problem from occurring.
Story Points: ---
Clone Of:
: 1554928 (view as bug list) Environment:
Last Closed: 2018-10-30 09:52:39 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:    
Bug Blocks: 1553075, 1554928    

Description jiyan 2018-02-09 10:04:35 UTC
This bug is trying to track some issues in BZ#1434451 (https://bugzilla.redhat.com/show_bug.cgi?id=1434451#c34) that are not be fixed in RHEL7.5

Description of problem:
1. 'update-deive' with alias in disk did not work actually
2. 'cold-plug' device with alias to running VM will fail in dumpxml file while succeed in cmd

Version-Release number of selected component (if applicable):
libvirt-3.9.0-12.virtcov.el7.x86_64
qemu-kvm-rhev-2.10.0-20.el7.x86_64
kernel-3.10.0-847.el7.x86_64

How reproducible:
100%

Steps to Reproduce:
Issue1: Prepare a VM with virtual disk in it and xml file describing virtual disk with different alias from original disk in VM, then update device 
# virsh domstate test
shut off

# virsh start test
Domain test started

# virsh dumpxml test |grep "<disk" -A8
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/RHEL-7.5-x86_64-latest.qcow2'/>
      <backingStore/>
      <target dev='hda' bus='virtio'/>
      <alias name='virtio-disk0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/var/lib/libvirt/images/one.raw'/>
      <backingStore/>
      <target dev='hdb' bus='virtio'/>
      <alias name='virtio-disk1'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
    </disk>

# cat hdb.xml 
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/var/lib/libvirt/images/one.raw'/>
      <target dev='hdb' bus='virtio'/>
      <alias name='ua-disk-update1'/>
    </disk>

# virsh update-device test hdb.xml 
Device updated successfully

# virsh dumpxml test |grep "<disk" -A8
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/RHEL-7.5-x86_64-latest.qcow2'/>
      <backingStore/>
      <target dev='hda' bus='virtio'/>
      <alias name='virtio-disk0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/var/lib/libvirt/images/one.raw'/>
      <backingStore/>
      <target dev='hdb' bus='virtio'/>
      <alias name='virtio-disk1'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
    </disk>

Issue2: Prepare a running VM with the following alias configuration, and xml file describing interface device, cold-plug interface device to running VM
# virsh domstate test
running

# virsh dumpxml test |grep alias
      <alias name='virtio-disk0'/>
      <alias name='virtio-disk1'/>
      <alias name='usb'/>
      <alias name='usb'/>
      <alias name='usb'/>
      <alias name='usb'/>
      <alias name='pci.0'/>
      <alias name='ua-IDE1'/>
      <alias name='virtio-serial0'/>
      <alias name='fdc0'/>
      <alias name='net0'/>
      <alias name='ua-myinterface'/>
      <alias name='serial0'/>
      <alias name='serial0'/>
      <alias name='channel0'/>
      <alias name='input0'/>
      <alias name='input1'/>
      <alias name='input2'/>
      <alias name='sound0'/>
      <alias name='video0'/>
      <alias name='redir0'/>
      <alias name='redir1'/>
      <alias name='balloon0'/>

# cat interface.xml 
 <interface type='network'>
  <source network='default' bridge='virbr0'/>
 <alias name='ua-myinterface'/>
 </interface>

# virsh attach-device test interface.xml --config
error: Failed to attach device from interface.xml
error: XML error: non unique alias detected: usb


Actual results:
As steps above show

Expected results:
1. 'update-deive' with alias in disk should succeed
2. 'cold-plug' device with alias to running VM should succeed in both dumpxml file and cmd


Additional info:

Comment 2 Michal Privoznik 2018-02-12 13:48:23 UTC
(In reply to jiyan from comment #0)
> This bug is trying to track some issues in BZ#1434451
> (https://bugzilla.redhat.com/show_bug.cgi?id=1434451#c34) that are not be
> fixed in RHEL7.5
> 
> Description of problem:
> 1. 'update-deive' with alias in disk did not work actually
> 2. 'cold-plug' device with alias to running VM will fail in dumpxml file
> while succeed in cmd
> 
> Version-Release number of selected component (if applicable):
> libvirt-3.9.0-12.virtcov.el7.x86_64
> qemu-kvm-rhev-2.10.0-20.el7.x86_64
> kernel-3.10.0-847.el7.x86_64
> 
> How reproducible:
> 100%
> 
> Steps to Reproduce:
> Issue1: Prepare a VM with virtual disk in it and xml file describing virtual
> disk with different alias from original disk in VM, then update device 
> # virsh domstate test
> shut off
> 
> # virsh start test
> Domain test started
> 
> # virsh dumpxml test |grep "<disk" -A8
>     <disk type='file' device='disk'>
>       <driver name='qemu' type='qcow2'/>
>       <source file='/var/lib/libvirt/images/RHEL-7.5-x86_64-latest.qcow2'/>
>       <backingStore/>
>       <target dev='hda' bus='virtio'/>
>       <alias name='virtio-disk0'/>
>       <address type='pci' domain='0x0000' bus='0x00' slot='0x08'
> function='0x0'/>
>     </disk>
>     <disk type='file' device='disk'>
>       <driver name='qemu' type='raw'/>
>       <source file='/var/lib/libvirt/images/one.raw'/>
>       <backingStore/>
>       <target dev='hdb' bus='virtio'/>
>       <alias name='virtio-disk1'/>
>       <address type='pci' domain='0x0000' bus='0x00' slot='0x09'
> function='0x0'/>
>     </disk>
> 
> # cat hdb.xml 
>     <disk type='file' device='disk'>
>       <driver name='qemu' type='raw'/>
>       <source file='/var/lib/libvirt/images/one.raw'/>
>       <target dev='hdb' bus='virtio'/>
>       <alias name='ua-disk-update1'/>
>     </disk>
> 
> # virsh update-device test hdb.xml 
> Device updated successfully

This should be fixed upstream by:

commit d0204e373d8aec51b1fd63783eeaa9a2015832ac
Author:     Michal Privoznik <mprivozn>
AuthorDate: Wed Dec 13 15:12:01 2017 +0100
Commit:     Michal Privoznik <mprivozn>
CommitDate: Fri Jan 5 14:22:45 2018 +0100

    qemuDomainDiskChangeSupported: Forbid alias change
    
    Since we have user aliases it may happen that users want to
    change it using 'update-device'. Instead of ignoring it silently,
    error out loudly. Note that we don't limit the check just for
    "ua-" prefixes because users might try to change libvirt
    generated aliases too.
    
    Signed-off-by: Michal Privoznik <mprivozn>
    Reviewed-by: John Ferlan <jferlan>

> 
> Issue2: Prepare a running VM with the following alias configuration, and xml
> file describing interface device, cold-plug interface device to running VM
> # virsh domstate test
> running
> 
> # virsh dumpxml test |grep alias
>       <alias name='virtio-disk0'/>
>       <alias name='virtio-disk1'/>
>       <alias name='usb'/>
>       <alias name='usb'/>
>       <alias name='usb'/>
>       <alias name='usb'/>
>       <alias name='pci.0'/>
>       <alias name='ua-IDE1'/>
>       <alias name='virtio-serial0'/>
>       <alias name='fdc0'/>
>       <alias name='net0'/>
>       <alias name='ua-myinterface'/>
>       <alias name='serial0'/>
>       <alias name='serial0'/>
>       <alias name='channel0'/>
>       <alias name='input0'/>
>       <alias name='input1'/>
>       <alias name='input2'/>
>       <alias name='sound0'/>
>       <alias name='video0'/>
>       <alias name='redir0'/>
>       <alias name='redir1'/>
>       <alias name='balloon0'/>
> 
> # cat interface.xml 
>  <interface type='network'>
>   <source network='default' bridge='virbr0'/>
>  <alias name='ua-myinterface'/>
>  </interface>
> 
> # virsh attach-device test interface.xml --config
> error: Failed to attach device from interface.xml
> error: XML error: non unique alias detected: usb

I think this is fixed by the following proposed patch:

https://www.redhat.com/archives/libvir-list/2018-February/msg00282.html

I've created a scratch build with those patches applied if you want to give it a try:

https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=15264067

Comment 3 Michal Privoznik 2018-03-12 12:31:06 UTC
*** Bug 1553162 has been marked as a duplicate of this bug. ***

Comment 4 Michal Privoznik 2018-03-12 12:31:58 UTC
I've merged the fix upstream:

commit e5673ed44465edcfccdd906158136ad8dcb94b9b
Author:     Michal Privoznik <mprivozn>
AuthorDate: Fri Mar 9 08:31:44 2018 +0100
Commit:     Michal Privoznik <mprivozn>
CommitDate: Mon Mar 12 13:27:24 2018 +0100

    virDomainDeviceValidateAliasForHotplug: Use correct domain defintion
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1553075
    
    For some weird reason this function is getting live and
    persistent def for domain but then accesses vm->def and
    vm->newDef directly. This is rather unsafe as we can be
    accessing NULL pointer.
    
    Signed-off-by: Michal Privoznik <mprivozn>

v4.1.0-91-ge5673ed44

Comment 9 Han Han 2018-07-10 08:28:14 UTC
Verified on: libvirt-4.5.0-2.virtcov.el7.x86_64 qemu-kvm-rhev-2.12.0-7.el7.x86_64:
I. Try to update device alias lively:
1. Prepare a running VM, two device XMLs only their aliases differ
# virsh list
 Id    Name                           State
----------------------------------------------------
 74    usb                            running

# cat /tmp/nic.xml 
    <interface type='network'>
      <mac address='52:54:00:72:7a:34'/>
      <source network='default'/>
      <model type='virtio'/>
      <alias name='ua-09f558d3-1223-4e82-9334-87b1eeb26925'/>
    </interface>

# cat /tmp/nic-alias1.xml 
    <interface type='network'>
      <mac address='52:54:00:72:7a:34'/>
      <source network='default'/>
      <model type='virtio'/>
      <alias name='ua-Alias'/>
    </interface>

2.Attach device, then try to change alias via update-device
# virsh attach-device usb /tmp/nic.xml       
Device attached successfully

# virsh update-device usb /tmp/nic-alias1.xml
error: Failed to update device from /tmp/nic-alias1.xml
error: operation forbidden: changing device alias is not allowed


II. Try to update device alias inactively:
# virsh attach-device usb /tmp/nic.xml  --config                                
Device attached successfully

# virsh update-device usb /tmp/nic-alias1.xml --config
Device updated successfully

# virsh dumpxml usb --inactive|awk '/<inter/,/<\/inter/'|grep ua
      <alias name='ua-Alias'/>

Alias changed.

Comment 11 errata-xmlrpc 2018-10-30 09:52:39 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, 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-2018:3113