Bug 982304

Summary: virsh attach-device XML error with valid XML
Product: Red Hat Enterprise Linux 6 Reporter: Chris Evich <cevich>
Component: libvirtAssignee: Michal Privoznik <mprivozn>
Status: CLOSED NEXTRELEASE QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 6.4CC: acathrow, bili, dyuan, honzhang, mprivozn, xuzhang
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 983616 (view as bug list) Environment:
Last Closed: 2013-07-11 14:32: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:
Bug Depends On:    
Bug Blocks: 983616    

Description Chris Evich 2013-07-08 15:39:43 UTC
Description of problem:
With valid XML, attaching a device with 'virsh attach-device' gives inaccurate & confusing error, or doesn't work when virt-manager does.

error: Failed to attach device from /tmp/serial.xml
error: XML error: unknown device type


Version-Release number of selected component (if applicable):
libvirt-0.10.2-18.el6_4.8.x86_64

How reproducible:
Very

Steps to Reproduce:

Scenario A-
1. Create qemu-kvm domain, OS doesn't matter.
2. Start domain
3. virsh attach-device foobar /tmp/serial.xml

Scenario B-
1. Shutdown/destroy qemu-kvm domain.
2. Confirm domain is NOT running.
3. virsh attach-device foobar /tmp/serial.xml --config

Scenario C-
1. start qemu-kvm domain, OS doesn't matter
2. Open domain in virt-manager, click add device
3. Manually add file-backed serial device as in XML.
4. Review error in 'details' box of error dialog.
5. Click Yes, restart domain.
6. Device attached and working as expected.


Actual results:

Scenario A- "error: XML error: unknown device type" suggests XML parsing problem, but XML is valid though device is not hot-plugable.

Scenario B- "error: XML error: unknown device type" when device is known, XML is valid, and supported for off-line attachment (Scenario C)

Scenario C- Error dialog, offering to perform off-line device addition.  Detail box concludes with: "error: XML error: unknown device type".


Expected results:

Scenario A- An error message indicating device could not be hotplugged.

Scenario B- Serial device is successfully attached to off-line domain.

Scenario C- Any device attachable via virt-manager, should be attachable in similar way through virsh attach-device command.

Additional info:

Mailing list thread: https://www.redhat.com/archives/libvir-list/2013-July/msg00202.html

XML used was:

<serial type='file'>
  <source path='/tmp/serialfile'/>
  <target port='1'/>
</serial>

where /tmp/serialfile does not already exist.

Comment 1 Michal Privoznik 2013-07-11 06:58:04 UTC
(In reply to Chris Evich from comment #0)
> Description of problem:
> With valid XML, attaching a device with 'virsh attach-device' gives
> inaccurate & confusing error, or doesn't work when virt-manager does.
> 
> error: Failed to attach device from /tmp/serial.xml
> error: XML error: unknown device type
> 
> 
> Version-Release number of selected component (if applicable):
> libvirt-0.10.2-18.el6_4.8.x86_64
> 
> How reproducible:
> Very
> 
> Steps to Reproduce:
> 
> Scenario A-
> 1. Create qemu-kvm domain, OS doesn't matter.
> 2. Start domain
> 3. virsh attach-device foobar /tmp/serial.xml
> 
> Scenario B-
> 1. Shutdown/destroy qemu-kvm domain.
> 2. Confirm domain is NOT running.
> 3. virsh attach-device foobar /tmp/serial.xml --config
> 
> Scenario C-
> 1. start qemu-kvm domain, OS doesn't matter
> 2. Open domain in virt-manager, click add device
> 3. Manually add file-backed serial device as in XML.
> 4. Review error in 'details' box of error dialog.
> 5. Click Yes, restart domain.
> 6. Device attached and working as expected.
> 
> 
> Actual results:
> 
> Scenario A- "error: XML error: unknown device type" suggests XML parsing
> problem, but XML is valid though device is not hot-plugable.
> 
> Scenario B- "error: XML error: unknown device type" when device is known,
> XML is valid, and supported for off-line attachment (Scenario C)
> 
> Scenario C- Error dialog, offering to perform off-line device addition. 
> Detail box concludes with: "error: XML error: unknown device type".
> 

I think the real bug is confusing error message.

> 
> Expected results:
> 
> Scenario A- An error message indicating device could not be hotplugged.
> 
> Scenario B- Serial device is successfully attached to off-line domain.
> 
> Scenario C- Any device attachable via virt-manager, should be attachable in
> similar way through virsh attach-device command.

I think when coldplugging a device, virt-manager just dumps domain XML, inserts the device XML snip and re-define domain. Question is - do we want virsh attach-device --config to do the same?

> 
> Additional info:
> 
> Mailing list thread:
> https://www.redhat.com/archives/libvir-list/2013-July/msg00202.html
> 
> XML used was:
> 
> <serial type='file'>
>   <source path='/tmp/serialfile'/>
>   <target port='1'/>
> </serial>
> 
> where /tmp/serialfile does not already exist.

Comment 2 Michal Privoznik 2013-07-11 11:46:30 UTC
Patch proposed upstream:

https://www.redhat.com/archives/libvir-list/2013-July/msg00679.html

Comment 3 Michal Privoznik 2013-07-11 14:32:25 UTC
I've just pushed patches upstream:

commit 95ff6a3993436daa3d1bb46ffc9d3be3530c00a6
Author:     Michal Privoznik <mprivozn>
AuthorDate: Thu Jul 11 13:24:20 2013 +0200
Commit:     Michal Privoznik <mprivozn>
CommitDate: Thu Jul 11 16:19:10 2013 +0200

    qemu: Fix hot (un-)plug error codes and messages
    
    With current code, error reporting for unsupported devices for hot plug,
    unplug and update is total mess. The VIR_ERR_CONFIG_UNSUPPORTED error
    code is reported instead of VIR_ERR_OPERATION_UNSUPPORTED. Moreover, the
    error messages are not helping to find the root cause (lack of
    implementation).

commit 38f151fe9b2e3f235fa8537b06f21ee7d42aed72
Author:     Michal Privoznik <mprivozn>
AuthorDate: Thu Jul 11 12:18:36 2013 +0200
Commit:     Michal Privoznik <mprivozn>
CommitDate: Thu Jul 11 16:19:00 2013 +0200

    conf: Rework virDomainDeviceDefParse
    
    When adding a new domain device, it is fairly easy to forget to add
    corresponding piece into virDomainDeviceDefParse. However, if the
    internal structure is changed to one bit switch() the compiler will warn
    about not handled enum item.

commit b63ea467617e3cbee4282ab2e5e780b4119cef3d
Author:     Michal Privoznik <mprivozn>
AuthorDate: Thu Jul 11 11:20:34 2013 +0200
Commit:     Michal Privoznik <mprivozn>
CommitDate: Thu Jul 11 16:07:04 2013 +0200

    conf: Extend device types handled by virDomainDeviceDefParse
    
    Not all device types are currently parsed in virDomainDeviceDefParse,
    Since all needed functions do exist, nothing holds us back to make the
    implementation complete. Similarly, the virDomainDeviceDefFree needs to
    be updated as well.

CVE-2013-2230-49-gb0cb524

Comment 4 Chris Evich 2013-07-11 14:35:56 UTC
Oh yes, good error message here is certainly first step to make this much better:

    error: Operation not supported: persistent detach
        of device 'memballoon' is not supported

This is much more helpful!

Comment 5 Chris Evich 2013-07-11 14:42:28 UTC
(In reply to Michal Privoznik from comment #1)
> (In reply to Chris Evich from comment #0)
> > Expected results:
> > 
> > Scenario A- An error message indicating device could not be hotplugged.
> > 
> > Scenario B- Serial device is successfully attached to off-line domain.
> > 
> > Scenario C- Any device attachable via virt-manager, should be attachable in
> > similar way through virsh attach-device command.
> 
> I think when coldplugging a device, virt-manager just dumps domain XML,
> inserts the device XML snip and re-define domain. Question is - do we want
> virsh attach-device --config to do the same?

I cloned just this part into Bug 983616 since it's a separate problem.