Bug 1155887

Summary: [Doc]Only expose managed attribute for PCI hostdev
Product: Red Hat Enterprise Linux 7 Reporter: Hu Jianwei <jiahu>
Component: libvirtAssignee: Erik Skultety <eskultet>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 7.1CC: dyuan, eskultet, honzhang, mzhan, rbalakri
Target Milestone: rcKeywords: Reopened
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-1.2.14-1.el7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-11-19 05:54:25 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 Hu Jianwei 2014-10-23 05:59:08 UTC
Description
libvirt should only use managed='yes/no' on PCI host device in <hostdev>
managed option is meaningless for usb and scsi type

Version:
libvirt-1.2.8-5.el7.x86_64

How reproducible:
100%

Steps to Reproduce:
[root@localhost ~]# lsusb| grep SanDisk
Bus 002 Device 004: ID 0781:5580 SanDisk Corp. SDCZ80 Flash Drive
[root@localhost ~]#
[root@localhost ~]# virsh dumpxml r7 |grep "/hostdev" -B6
    <hostdev mode='subsystem' type='usb' managed='no'>
      <source>
        <vendor id='0x0781'/>
        <product id='0x5580'/>
        <address bus='2' device='4'/>
      </source>
    </hostdev>
[root@localhost ~]# virsh start r7
Domain r7 started

In guest:
[root@oolong ~]# lsusb
Bus 001 Device 002: ID 0781:5580 SanDisk Corp. SDCZ80 Flash Drive
...

Actual results:
As above shown steps.

Expected results:
For usb and scsi type in <hostdev>, should remove meaningless managed option from XML at least.

Additional info:
I found libvirt only check the "managed=yes/no" on PCI host device.

such as in virHostdevPreparePCIDevices():
    /* Loop 2: detach managed devices (i.e. bind to appropriate stub driver) */
    for (i = 0; i < virPCIDeviceListCount(pcidevs); i++) {
        virPCIDevicePtr dev = virPCIDeviceListGet(pcidevs, i);
        if (virPCIDeviceGetManaged(dev) &&
            virPCIDeviceDetach(dev, hostdev_mgr->activePCIHostdevs, NULL) < 0)
            goto reattachdevs;
    }

Comment 2 Erik Skultety 2015-02-24 12:10:01 UTC
Host devices (like most types of devices) are formatted into the XML description uniformly. That means, they're represented by certain internal structures which have all the relevant elements defined and all the irrelevant elements cleared and formatting behaves accordingly.
Now fixing this issue would not only require tweaking conditions in formatting, but more importantly switching from simple Boolean logic to ternary logic.
If the user's not 100% sure, http://libvirt.org/formatdomain.html#elementsHostDevSubsys describes the meaning of attributes and elements. Even if there's 'managed' attribute set to 'yes' when dealing with USB/SCSI devices, it will be ignored silently, no unexpected behaviour.

Comment 3 Hu Jianwei 2015-02-27 02:59:55 UTC
(In reply to Erik Skultety from comment #2)
> Host devices (like most types of devices) are formatted into the XML
> description uniformly. That means, they're represented by certain internal
> structures which have all the relevant elements defined and all the
> irrelevant elements cleared and formatting behaves accordingly.
Based on your above explanation, I think libvirt should remove "managed" attribute from XML layer for USB/SCSI devices during using "dumpxml" command at least, like:

[root@localhost ~]# virsh dumpxml r71
...
    <hostdev mode='subsystem' type='usb'>
      <source>
        <vendor id='0x0781'/>
        <product id='0x5580'/>
        <address bus='4' device='2'/>
      </source>
      <alias name='hostdev0'/>
    </hostdev>
...
Contrarily, dumpxml can leave it on after adding some relevant codes if it's possible.

> Now fixing this issue would not only require tweaking conditions in
> formatting, but more importantly switching from simple Boolean logic to
> ternary logic.
> If the user's not 100% sure,
> http://libvirt.org/formatdomain.html#elementsHostDevSubsys describes the
> meaning of attributes and elements. Even if there's 'managed' attribute set
> to 'yes' when dealing with USB/SCSI devices, it will be ignored silently, no
> unexpected behaviour.
Consumer saw it from dumpxml's output, so people will believe it's a useful attribute, but it's useless for USB/SCSI in background, it's hard to understand.

Comment 4 Erik Skultety 2015-02-27 12:00:04 UTC
Rather than special casing hostdev device types and attributes (both of which might as well grow in count sometime in the future), I proposed an upstream patch https://www.redhat.com/archives/libvir-list/2015-February/msg01210.html to update the documentation to make the usage/appearance of 'managed' attribute more clear.

Comment 5 Hu Jianwei 2015-02-28 01:54:52 UTC
Thanks, I changed it as a doc bug, reassigned it to you, please help me fix it.

Comment 6 Erik Skultety 2015-03-02 11:13:57 UTC
Fixed upstream:

commit ccfe9e480986c075a6a04f7792a5b30350396d83
Author: Erik Skultety <eskultet>
Date:   Fri Feb 27 12:45:57 2015 +0100

    docs: add a note that attr 'managed' is only used by PCI devices
    
    Our documentation isn't 100% clear about hostdev 'managed' attribute usage,
    because it only makes sense to use it with PCI devices, yet we format
    this attribute to all hostdev devices. By adding a note into the docs,
    we can possibly avoid confusion from customer's side and also avoid a solution
    using ternary logic.

v1.2.13-22-gccfe9e4

Comment 10 hongming 2015-07-13 07:39:57 UTC
Verify it as follows.The result is expected. Move its status to VERIFIED.


# rpm -q libvirt libvirt-debuginfo
libvirt-1.2.17-1.el7.x86_64
libvirt-debuginfo-1.2.15-2.el7.x86_64


# vim /usr/share/doc/libvirt-docs-1.2.17/html/formatdomain.html

2909         <p>
2910           Note: The <code>managed</code> attribute is only used with PCI devices
2911           and is ignored by all the other device types, thus setting
2912           <code>managed</code> explicitly with other than PCI device has the same
2913           effect as omitting it.
2914         </p>

Comment 12 errata-xmlrpc 2015-11-19 05:54:25 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