Bug 1230039

Summary: cannot attach a virtio channel device
Product: Red Hat Enterprise Linux 7 Reporter: Luyao Huang <lhuang>
Component: libvirtAssignee: Ján Tomko <jtomko>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.2CC: dyuan, honzhang, jtomko, mzhan, rbalakri, shyu, zhwang
Target Milestone: rcKeywords: Regression
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-1.2.17-1.el7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-11-19 06:41:00 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:

Description Luyao Huang 2015-06-10 07:41:41 UTC
description of problem:
cannot attach a channel device

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

How reproducible:
100%

Steps to Reproduce:

1. prepare a running vm

# virsh list
 Id    Name                           State
----------------------------------------------------
 2     rhel7.0                        running


2. attach channel device:

# cat channel-file.xml
    <channel type='file'>
      <source path='/tmp/file'/>
      <target type='virtio' name='123'/>
    </channel>


# virsh attach-device rhel7.0 channel-file.xml
error: Failed to attach device from channel-file.xml
error: internal error: virtio serial device has invalid address type

4. add virtio-serial address
# cat channel-file.xml
    <channel type='file'>
      <source path='/tmp/file'/>
      <target type='virtio' name='123'/>
<address type='virtio-serial' controller='0' bus='0' port='2'/>
    </channel>

# virsh attach-device rhel7.0 channel-file.xml
error: Failed to attach device from channel-file.xml
error: internal error: virtio serial device has invalid address type


Actual results:
cannot attach a channel device

Expected results:
attach success , test with 1.2.15-2 attach success

Additional info:

seems because this patches:

commit 9807c47147a92a423f632e799137a31acd3ac41e
Author: Michal Privoznik <mprivozn>
Date:   Mon May 11 15:20:54 2015 +0200

    qemuDomainAttachChrDevice: Fix chardev hotplug

This need a check for the device type(channel, console, serial). Not all the chardev device type is serial.

    if (chr->targetType == VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_PCI) {
        if (virDomainPCIAddressEnsureAddr(priv->pciaddrs, &chr->info) < 0)
            goto cleanup;
    } else if (chr->targetType == VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB) {
        /* XXX */
    } else {
        if (virDomainVirtioSerialAddrAutoAssign(NULL,
                                                priv->vioserialaddrs,
                                                &chr->info,
                                                allowZero) < 0)
            goto cleanup;
    }

Comment 2 Luyao Huang 2015-06-10 14:58:55 UTC
First try(send a patch to upstream):

https://www.redhat.com/archives/libvir-list/2015-June/msg00480.html

Comment 3 Ján Tomko 2015-06-30 14:28:25 UTC
Another version:
https://www.redhat.com/archives/libvir-list/2015-June/msg01661.html

Comment 4 Ján Tomko 2015-07-01 06:15:23 UTC
Now pushed upstream:
commit f967e7a6690ed20478623b0707b846f81f469ff4
Author:     Luyao Huang <lhuang>
AuthorDate: 2015-06-10 22:49:37 +0800
Commit:     Ján Tomko <jtomko>
CommitDate: 2015-07-01 08:09:43 +0200

    qemu: fix address allocation on chardev attach
    
    Also check the device type when deciding what type the address should
    be. Commit 9807c47 (aiming to fix another error in address allocation)
    only checked the target type, but its value is different for different
    device types. This resulted in an error when trying to attach
    a channel with target type 'virtio':
    
    error: Failed to attach device from channel-file.xml
    error: internal error: virtio serial device has invalid address type
    
    Make the logic for releasing the address dependent only on
    * the address type
    * whether it was allocated earlier
    to avoid copying the device and target type checks.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1230039
    
    Signed-off-by: Luyao Huang <lhuang>
    Signed-off-by: Ján Tomko <jtomko>

git describe: v1.2.17-rc1-20-gf967e7a

Comment 6 Shanzhi Yu 2015-07-13 09:53:06 UTC
Verify this bug with libvirt-1.2.17-2.el7.x86_64 

1. Prepare a running guest 
# virsh list 
 Id    Name                           State
----------------------------------------------------
 21    r7                             running


2. Attach/detach file type channel without address element

# cat channel-1.xml 
    <channel type='file'>
      <source path='/tmp/file'/>
      <target type='virtio' name='123'/>
    </channel>

# virsh attach-device r7 channel-1.xml 
Device attached successfully

# virsh dumpxml r7|grep channel -A 4 
    <channel type='file'>
      <source path='/tmp/file'/>
      <target type='virtio' name='123'/>
      <alias name='channel0'/>
      <address type='virtio-serial' controller='0' bus='0' port='1'/>
    </channel>

# virsh detach-device r7 channel-1.xml 
Device detached successfully

# virsh dumpxml r7|grep channel -A 4 

3. Attach/detach file type channel with address element

# cat channel-2.xml 
    <channel type='file'>
      <source path='/tmp/file'/>
      <target type='virtio' name='123'/>
      <address type='virtio-serial' controller='0' bus='0' port='2'/>
    </channel>

# virsh attach-device r7 channel-2.xml 
Device attached successfully


# virsh dumpxml r7|grep channel -A 4 
    <channel type='file'>
      <source path='/tmp/file'/>
      <target type='virtio' name='123'/>
      <alias name='channel0'/>
      <address type='virtio-serial' controller='0' bus='0' port='2'/>
    </channel>

# virsh detach-device r7 channel-2.xml 
Device detached successfully

# virsh dumpxml r7|grep channel -A 4 

So, this bug can be verified.

Comment 8 errata-xmlrpc 2015-11-19 06:41:00 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://rhn.redhat.com/errata/RHBA-2015-2202.html