Bug 1136182

Summary: Libvirt should not support more than 1 IDE controller that have no virtual disk
Product: Red Hat Enterprise Linux 6 Reporter: Hu Jianwei <jiahu>
Component: libvirtAssignee: John Ferlan <jferlan>
Status: CLOSED NOTABUG QA Contact: Virtualization Bugs <virt-bugs>
Severity: low Docs Contact:
Priority: medium    
Version: 6.6CC: dyuan, honzhang, jdenemar, mzhan, rbalakri, tzheng, xuzhang
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 1165477 (view as bug list) Environment:
Last Closed: 2015-01-20 13:34:12 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:
Bug Depends On:    
Bug Blocks: 1165477    

Description Hu Jianwei 2014-09-02 06:12:19 UTC
Description of problem:
Libvirt should not support more than 1 IDE controller that have no disks, libvirt should not display the second IDE controller using dumpxml command.

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
<1> Start domain with more than 1 ide controller
[root@rhel6 ~]# virsh dumpxml r7 | grep -i " type='ide'" -b2
1207-      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
1289-    </controller>
1307:    <controller type='ide' index='0'>
1345-      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
1427-    </controller>
1445:    <controller type='ide' index='1'>
1483-      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
1565-    </controller>
[root@rhel6 ~]# virsh start r7
Domain r7 started

<2> Only have 1 ide controller in qemu commands:
[root@rhel6 ~]# ps aux | grep qemu-kvm | grep -v grep | sed -e 's/-device/\n-device/g'
qemu     24747 88.3  0.4 1703180 34412 ?       Sl   21:54   0:05 /usr/libexec/qemu-kvm -name r7 -S -M rhel6.5.0 -enable-kvm -m 1024 -realtime mlock=off -smp 3,sockets=3,cores=1,threads=1 -uuid 727bfa08-3937-aee7-8b61-13a6ec1c398e -nodefconfig -nodefaults -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/r7.monitor,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc -no-shutdown
-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2  
-device virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x5 -drive file=/var/lib/libvirt/images/r7.img,if=none,id=drive-ide0-0-0,format=raw,cache=none
-device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 -netdev tap,fd=23,id=hostnet0,vhost=on,vhostfd=24
-device virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:6b:d6:c8,bus=pci.0,multifunction=on,addr=0x3.0x3 -chardev pty,id=charserial0
-device isa-serial,chardev=charserial0,id=serial0 -vnc -vga qxl -global qxl-vga.ram_size=67107840 -global qxl-vga.vram_size=67108864
-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x6 -msg timestamp=on

<3> But if we insert 1 disk on that controller:
[root@rhel6 ~]# virsh dumpxml r7 | grep -i "disk4" -b5
761-      <target dev='hda' bus='ide'/>
797-      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
870-    </disk>
882-    <disk type='file' device='disk'>
919-      <driver name='qemu' type='raw' cache='none'/>
971:      <source file='/var/lib/libvirt/images/disk4.img'/>
1028-      <target dev='hde' bus='ide'/>
1064-      <address type='drive' controller='1' bus='0' target='0' unit='0'/>
1137-    </disk>
1149-    <controller type='usb' index='0'>
1187-      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>

[root@rhel6 ~]# virsh start r7
error: Failed to start domain r7
error: internal error Only 1 ide controller is supported

Actual results:
As shown above steps, libvirt can not start domain with a disk that has a non-zero IDE controller, but if we only add a new IDE controller without disk inserted on it, libvirt can start.

Expected results:
Libvirt should not add a new IDE controller, only have 1 IDE controller supported by now.

Additional info:
vim ./src/qemu/qemu_command.c +2297
2288     case VIR_DOMAIN_DISK_BUS_IDE:
2289         if (disk->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE) {
2290             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
2291                            _("unexpected address type for ide disk"));
2292             goto error;
2293         }
2294         /* We can only have 1 IDE controller (currently) */
2295         if (disk->info.addr.drive.controller != 0) {
2296             virReportError(VIR_ERR_INTERNAL_ERROR,
2297                            _("Only 1 %s controller is supported"), bus);
2298             goto error;
2299         }
2300         busid = disk->info.addr.drive.bus;
2301         unitid = disk->info.addr.drive.unit;
2302         break;

Comment 2 John Ferlan 2015-01-16 20:43:06 UTC
ugh... lost a lengthy response to an inadvertent <ctrl>Q from firefix (sigh) - self inflicted wound.

In any case, I don't believe this is a bug; however, I will leave this unclosed short term to continue any dialog or answer questions.

Essentially, QEMU supports 1 implicit IDE controller in it's PIIX3 definition.  Since only 1 IDE implicit controller is supported, any extra defined IDE controllers in the XML are ignored (for now). The code you pointed out above is in qemuBuildDriveStr which is used to generate the QEMU command line for the guest where if a disk in the XML uses an IDE that's not using the default index='0' IDE controller, then it's flagged as being bad (note the 'currently' in the comment). 

Deciding to ignore extra IDE definitions is a non issue. If we started flagging them now and causing an error, then those guests would "disappear" on future restarts or reloads after a new installation. Also, since other hypervisors (like perhaps HyperV) can support more than 1 IDE controller, why force someone to remove it just because QEMU is going to ignore it. 

NB: If you removed all IDE's from your XML, started your guest, and executed an 'lspci | grep IDE' inside the guest, then you'd see a PIIX3 IDE controller listed. But yet that isn't shown in the qemu command line for the same guest. 

In the long it's up to the underlying hypervisor to decide what it supports based on the machine type (<os> ... <type... machine=''...> </os> and emulator as defined in the XML. Causing errors vs. ignoring unsupported "things" is a design decision made long ago.

Since you found that code - search around the same module for " IDE " and read the comments - I think they tell a good story. There's some history that you can read in libvirt.git commits 'fcbfd584', '877bc089', and 'd78554d8' (where the above code was added).