Bug 675030

Summary: misleading error message from libvirt on bad xml
Product: Red Hat Enterprise Linux 6 Reporter: Eric Blake <eblake>
Component: libvirtAssignee: Eric Blake <eblake>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: low Docs Contact:
Priority: low    
Version: 6.1CC: ccui, dyuan, eblake, hutao, jyang, llim, mzhan, veillard, xen-maint, yoyzhang
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libvirt-0.8.7-5.el6 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2011-05-19 13:26:42 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Eric Blake 2011-02-03 23:34:12 UTC
Description of problem:
upstream commit cdbba1c4960a22b5f8c034dd9257bec2d5fa38d6
Author: Hu Tao <hutao.com>
Date:   Thu Jan 27 15:21:42 2011 +0800

    qemu: Report more accurate error on failure to attach device.

    When attaching device from a xml file and the device is mis-configured,
    virsh gives mis-leading message "out of memory". This patch fixes this.

    Signed-off-by: Eric Blake <eblake>


Version-Release number of selected component (if applicable):
libvirt-0.8.7-4.el6

How reproducible:
100%

Steps to Reproduce:
1. Not quite sure how Hu reproduced it, but probably by creating xml with a <controller> type set to 'ide'
  
Actual results:
out of memory error when the code path detects the bad controller type

Expected results:
proper message about the unknown type

Additional info:

Comment 4 Cui Chun 2011-02-15 07:33:52 UTC
Hi Eric,

I tried to verify this bug in libvirt-0.8.7-6.el6. 
But I am not sure if your updated code was covered. Please check the following steps.

Steps:

1.Start a guest
# virsh start rhel6

2.Create a device with 'ide' controller and attach it to guest
# cat c1.xml 
<controller type='ide' index='0'>
      <alias name='ide0'/>
    </controller>

# virsh attach-device rhel6 c1.xml 
error: Failed to attach device from c1.xml
error: unsupported configuration: disk controller bus 'ide' cannot be hotplugged.

3.Recreate a device with the invaild controller and attach it to guest
# cat c2.xml 
<controller type='fdsfside' index='0'>
      <alias name='ide0'/>
    </controller>

# virsh attach-device rhel6 c1.xml 
error: Failed to attach device from c2.xml
error: internal error Unknown controller type 'fdsfside'


** In step3, ("Unknown controller type: %s") error message can be shown.

Unfortunately, the same error message (in step3) also can be shown in libvirt-0.8.7-4.el6. 

 
Would you please give some suggestions on this bugs?


Thanks,
Chun Cui

Comment 5 Eric Blake 2011-02-15 16:36:59 UTC
(In reply to comment #4)
> I tried to verify this bug in libvirt-0.8.7-6.el6. 
> But I am not sure if your updated code was covered. Please check the following
> steps.

I've asked the original reporter, Hu Tao, for how he tested his upstream patch.

Meanwhile, note that:

> 3.Recreate a device with the invaild controller and attach it to guest
> # cat c2.xml 
> <controller type='fdsfside' index='0'>
>       <alias name='ide0'/>
>     </controller>
> 
> # virsh attach-device rhel6 c1.xml 
> error: Failed to attach device from c2.xml
> error: internal error Unknown controller type 'fdsfside'

There are two different error messages:

src/conf/domain_conf.c:                                 _("Unknown controller type '%s'"), type);
src/qemu/qemu_command.c:                        _("Unknown controller type: %s"),

You hit the pre-existing one in domain_conf.c (no colon), not the new message in qemu_command.c (with a colon), so this test did not tickle the changed code path.  So I think it has to be a known existing controller type to get past the parsing in domain_conf.c, which leaves 'ide', 'fdc', 'scsi', 'sata', 'virtio-serial', and 'ccid'.  Then, in qemu_command.c, the new message can only be triggered if you hit the 'ide' or default: case label; your testing showed that 'ide' got filtered early, and the switch statement covers 'scsi', 'virtio-serial', and 'ccid', but that leaves 'fdc' and 'sata'.  So maybe trying your step 2, but with 'sata' or 'fdc' instead of 'ide', will trigger things?

Comment 6 Hu Tao 2011-02-16 02:49:15 UTC
Have a try with this xml:

<controller type='scsi' index='1'>
  <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x1'/>
</controller>

where slot 0x09 is an unused slot, you can specify any unused slot.

With commit cdbba1c4960a2 the error message is:
error: internal error Only PCI device addresses with function=0 are supported

Without commit cdbba1c4960a2 the error message is:
error: out of memory

Comment 7 Cui Chun 2011-02-17 03:29:02 UTC
Tried the xml mentioned in comment6. The error message is same with first error (commit cdbba1c4960a2 the error message)

Test environment:
libvirt-0.8.7-6.el6
qemu-kvm-0.12.1.2-2.144.el6
kernel-2.6.32-113.el6

cat c3.xml 
<controller type='scsi' index='1'>
  <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x1'/>
</controller>


# virsh attach-device rhel6 c3.xml 
error: Failed to attach device from c3.xml
error: internal error Only PCI device addresses with function=0 are supported

Comment 8 Hu Tao 2011-02-17 03:48:28 UTC
That error message should be fine.

Have you tried the xml with commit cdbba1c4960a2 reverted? If you do not use git, you can manually edit c source file to remove changes introduced by commit cdbba1c4960a2 then rebuild libvirt-0.8.7-6.el6 then repeat steps in comment 7. If you get 'error: out of memory', then commit cdbba1c4960a2 is in effect. Because we're not actually out of memory, but don't support PCI device addresses with function=1.

Comment 9 Cui Chun 2011-02-17 05:08:40 UTC
(In reply to comment #8)
> That error message should be fine.
> 
> Have you tried the xml with commit cdbba1c4960a2 reverted? If you do not use
> git, you can manually edit c source file to remove changes introduced by commit
> cdbba1c4960a2 then rebuild libvirt-0.8.7-6.el6 then repeat steps in comment 7.
> If you get 'error: out of memory', then commit cdbba1c4960a2 is in effect.
> Because we're not actually out of memory, but don't support PCI device
> addresses with function=1.

Yes, I have checked on libvirt-0.8.7-4.el6.x86_64 without commit cdbba1c4960a2 and get "error: out of memory".

-------
# virsh attach-device rhel6 c3.xml 
error: Failed to attach device from c3.xml
error: out of memory
------

So this bug is fixed. Can I change it's status?

Comment 10 Hu Tao 2011-02-17 05:54:57 UTC
Fine. Thanks for your verification.

Comment 11 Cui Chun 2011-02-17 06:00:25 UTC
Thanks for Hu Tao's great help.

Changed it to verified status.

Comment 12 zhanghaiyan 2011-04-20 12:16:17 UTC
Adding the following xml to a shutoff guest xml, then start the guest will causes 'out of memory' error. For this issue, I report a separate bug 698197 
<controller type='scsi' index='1'>
  <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x1'/>
</controller>

Comment 15 errata-xmlrpc 2011-05-19 13:26:42 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2011-0596.html