Auto-add disk controllers based on defined disks

Existing applications using libvirt are not aware of the disk
controller concept. Thus, after parsing the <disk> definitions
in the XML, it is neccessary to create <controller> elements
to satisfy all requested disks, as per their defined drive
addresses

* src/conf/domain_conf.c, src/conf/domain_conf.h,
  src/libvirt_private.syms: Add virDomainDefAddDiskControllers()
  method for populating disk controllers, and call it after
  parsing disk definitions.
* src/qemu/qemu_conf.c: Call virDomainDefAddDiskControllers()
  when doing ARGV -> XML conversion
* tests/qemuxml2argvdata/qemuxml2argv*.xml: Add disk controller
  data to all data files which don't have it already
This commit is contained in:
Daniel P. Berrange 2010-01-05 13:31:20 +00:00
parent 2224989c39
commit b030084f07
80 changed files with 181 additions and 0 deletions

View File

@ -3547,6 +3547,12 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
}
VIR_FREE(nodes);
/* Auto-add any further disk controllers implied by declared <disk>
* elements, but not present as <controller> elements
*/
if (virDomainDefAddDiskControllers(def) < 0)
goto error;
/* analysis of the filesystems */
if ((n = virXPathNodeSet(conn, "./devices/filesystem", ctxt, &nodes)) < 0) {
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
@ -4147,6 +4153,96 @@ cleanup:
return obj;
}
static int virDomainDefMaybeAddDiskController(virDomainDefPtr def,
int type,
int idx)
{
int found = 0;
int i;
virDomainControllerDefPtr cont;
for (i = 0 ; (i < def->ncontrollers) && !found; i++) {
if (def->controllers[i]->type == type &&
def->controllers[i]->idx == idx)
found = 1;
}
if (found)
return 0;
if (VIR_ALLOC(cont) < 0) {
virReportOOMError(NULL);
return -1;
}
cont->type = type;
cont->idx = idx;
if (VIR_REALLOC_N(def->controllers, def->ncontrollers+1) < 0) {
VIR_FREE(cont);
virReportOOMError(NULL);
return -1;
}
def->controllers[def->ncontrollers] = cont;
def->ncontrollers++;
return 0;
}
static int virDomainDefAddDiskControllersForType(virDomainDefPtr def,
int controllerType,
int diskBus)
{
int i;
int maxController = -1;
for (i = 0 ; i < def->ndisks ; i++) {
if (def->disks[i]->bus != diskBus)
continue;
if (def->disks[i]->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE)
continue;
if ((int)def->disks[i]->info.addr.drive.controller > maxController)
maxController = def->disks[i]->info.addr.drive.controller;
}
for (i = 0 ; i <= maxController ; i++) {
if (virDomainDefMaybeAddDiskController(def, controllerType, i) < 0)
return -1;
}
return 0;
}
/*
* Based on the declared <address type=drive> info for any disks,
* add neccessary drive controllers which are not already present
* in the XML. This is for compat with existing apps which will
* not know/care about <controller> info in the XML
*/
int virDomainDefAddDiskControllers(virDomainDefPtr def)
{
if (virDomainDefAddDiskControllersForType(def,
VIR_DOMAIN_CONTROLLER_TYPE_SCSI,
VIR_DOMAIN_DISK_BUS_SCSI) < 0)
return -1;
if (virDomainDefAddDiskControllersForType(def,
VIR_DOMAIN_CONTROLLER_TYPE_FDC,
VIR_DOMAIN_DISK_BUS_FDC) < 0)
return -1;
if (virDomainDefAddDiskControllersForType(def,
VIR_DOMAIN_CONTROLLER_TYPE_IDE,
VIR_DOMAIN_DISK_BUS_IDE) < 0)
return -1;
return 0;
}
#endif /* ! PROXY */
/************************************************************************

View File

@ -776,6 +776,8 @@ virDomainObjPtr virDomainObjParseNode(virConnectPtr conn,
xmlDocPtr xml,
xmlNodePtr root);
int virDomainDefAddDiskControllers(virDomainDefPtr def);
#endif
char *virDomainDefFormat(virConnectPtr conn,
virDomainDefPtr def,

View File

@ -186,6 +186,7 @@ virDomainDeviceAddressClear;
virDomainControllerTypeToString;
virDomainControllerDefFree;
virDomainDeviceAddressTypeToString;
virDomainDefAddDiskControllers;
# domain_event.h

View File

@ -4450,6 +4450,9 @@ virDomainDefPtr qemuParseCommandLine(virConnectPtr conn,
goto no_memory;
}
if (virDomainDefAddDiskControllers(def) < 0)
goto error;
return def;
no_memory:

View File

@ -20,5 +20,6 @@
<readonly/>
<address type='drive' controller='0' bus='1' unit='0'/>
</disk>
<controller type='ide' index='0'/>
</devices>
</domain>

View File

@ -24,5 +24,7 @@
<target dev='fda' bus='fdc'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='fdc' index='0'/>
<controller type='ide' index='0'/>
</devices>
</domain>

View File

@ -19,5 +19,6 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
</devices>
</domain>

View File

@ -20,5 +20,6 @@
<readonly/>
<address type='drive' controller='0' bus='1' unit='0'/>
</disk>
<controller type='ide' index='0'/>
</devices>
</domain>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<channel type='pipe'>
<source path='/tmp/guestfwd'/>
<target type='guestfwd' address='10.0.2.1' port='4600'/>

View File

@ -19,5 +19,6 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
</devices>
</domain>

View File

@ -19,5 +19,6 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
</devices>
</domain>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<serial type='pty'>
<target port='0'/>
</serial>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<serial type='pty'>
<target port='0'/>
</serial>

View File

@ -24,5 +24,6 @@
<readonly/>
<address type='drive' controller='0' bus='1' unit='0'/>
</disk>
<controller type='ide' index='0'/>
</devices>
</domain>

View File

@ -25,5 +25,6 @@
<readonly/>
<address type='drive' controller='0' bus='1' unit='0'/>
</disk>
<controller type='ide' index='0'/>
</devices>
</domain>

View File

@ -24,5 +24,6 @@
<target dev='hdc' bus='ide'/>
<address type='drive' controller='0' bus='1' unit='0'/>
</disk>
<controller type='ide' index='0'/>
</devices>
</domain>

View File

@ -24,5 +24,6 @@
<target dev='hdc' bus='ide'/>
<address type='drive' controller='0' bus='1' unit='0'/>
</disk>
<controller type='ide' index='0'/>
</devices>
</domain>

View File

@ -27,5 +27,6 @@
<readonly/>
<address type='drive' controller='0' bus='1' unit='0'/>
</disk>
<controller type='ide' index='0'/>
</devices>
</domain>

View File

@ -27,5 +27,6 @@
<readonly/>
<address type='drive' controller='0' bus='1' unit='0'/>
</disk>
<controller type='ide' index='0'/>
</devices>
</domain>

View File

@ -27,5 +27,6 @@
<readonly/>
<address type='drive' controller='0' bus='1' unit='0'/>
</disk>
<controller type='ide' index='0'/>
</devices>
</domain>

View File

@ -27,5 +27,6 @@
<readonly/>
<address type='drive' controller='0' bus='1' unit='0'/>
</disk>
<controller type='ide' index='0'/>
</devices>
</domain>

View File

@ -27,5 +27,6 @@
<readonly/>
<address type='drive' controller='0' bus='1' unit='0'/>
</disk>
<controller type='ide' index='0'/>
</devices>
</domain>

View File

@ -27,5 +27,6 @@
<readonly/>
<address type='drive' controller='0' bus='1' unit='0'/>
</disk>
<controller type='ide' index='0'/>
</devices>
</domain>

View File

@ -21,5 +21,6 @@
<readonly/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
</devices>
</domain>

View File

@ -27,5 +27,6 @@
<readonly/>
<address type='drive' controller='0' bus='1' unit='0'/>
</disk>
<controller type='ide' index='0'/>
</devices>
</domain>

View File

@ -29,5 +29,6 @@
<readonly/>
<address type='drive' controller='0' bus='1' unit='0'/>
</disk>
<controller type='ide' index='0'/>
</devices>
</domain>

View File

@ -29,5 +29,7 @@
<target dev='fdb' bus='fdc'/>
<address type='drive' controller='0' bus='0' unit='1'/>
</disk>
<controller type='fdc' index='0'/>
<controller type='ide' index='0'/>
</devices>
</domain>

View File

@ -34,5 +34,6 @@
<target dev='hdd' bus='ide'/>
<address type='drive' controller='0' bus='1' unit='1'/>
</disk>
<controller type='ide' index='0'/>
</devices>
</domain>

View File

@ -23,5 +23,6 @@
<source file='/tmp/usbdisk.img'/>
<target dev='sda' bus='usb'/>
</disk>
<controller type='ide' index='0'/>
</devices>
</domain>

View File

@ -33,5 +33,6 @@
<source file='/tmp/logs.img'/>
<target dev='vdb' bus='virtio'/>
</disk>
<controller type='ide' index='0'/>
</devices>
</domain>

View File

@ -33,5 +33,6 @@
<source file='/tmp/logs.img'/>
<target dev='xvdg' bus='xen'/>
</disk>
<controller type='ide' index='0'/>
</devices>
</domain>

View File

@ -21,5 +21,7 @@
<readonly/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<controller type='fdc' index='0'/>
</devices>
</domain>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<input type='mouse' bus='ps2'/>
<graphics type='sdl' display=':0.1' xauth='/root/.Xauthority' fullscreen='yes'/>
<video>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<input type='mouse' bus='ps2'/>
<graphics type='sdl' display=':0.1' xauth='/root/.Xauthority'/>
<video>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<input type='mouse' bus='ps2'/>
<graphics type='vnc' port='5903' autoport='no' listen='127.0.0.1'/>
<video>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<input type='mouse' bus='ps2'/>
<graphics type='vnc' port='5903' autoport='no' listen='127.0.0.1'/>
<video>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<input type='mouse' bus='ps2'/>
<graphics type='vnc' port='5903' autoport='no' listen='127.0.0.1'/>
<video>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<hostdev mode='subsystem' type='pci' managed='yes'>
<source>
<address domain='0x0000' bus='0x06' slot='0x12' function='0x5'/>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<hostdev mode='subsystem' type='usb' managed='no'>
<source>
<address bus='14' device='6'/>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<hostdev mode='subsystem' type='usb' managed='no'>
<source>
<vendor id='0x0204'/>

View File

@ -22,5 +22,6 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
</devices>
</domain>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<input type='mouse' bus='usb'/>
</devices>
</domain>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<input type='tablet' bus='usb'/>
</devices>
</domain>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<input type='mouse' bus='xen'/>
<graphics type='vnc' port='5903' autoport='no' listen='127.0.0.1'/>
<video>

View File

@ -19,5 +19,6 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
</devices>
</domain>

View File

@ -19,5 +19,6 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
</devices>
</domain>

View File

@ -19,5 +19,6 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
</devices>
</domain>

View File

@ -19,5 +19,6 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
</devices>
</domain>

View File

@ -22,5 +22,6 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
</devices>
</domain>

View File

@ -19,5 +19,6 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
</devices>
</domain>

View File

@ -22,5 +22,6 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
</devices>
</domain>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<interface type='ethernet'>
<mac address='00:11:22:33:44:55'/>
<script path='/etc/qemu-ifup'/>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<interface type='ethernet'>
<mac address='00:11:22:33:44:55'/>
<script path='/etc/qemu-ifup'/>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<interface type='ethernet'>
<mac address='00:11:22:33:44:55'/>
<script path='/etc/qemu-ifup'/>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<interface type='user'>
<mac address='00:11:22:33:44:55'/>
</interface>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<interface type='user'>
<mac address='00:11:22:33:44:55'/>
<model type='virtio'/>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<parallel type='tcp'>
<source mode='bind' host='127.0.0.1' service='9999'/>
<protocol type='raw'/>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<parallel type='tcp'>
<source mode='bind' host='127.0.0.1' service='9999'/>
<protocol type='raw'/>

View File

@ -19,5 +19,6 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
</devices>
</domain>

View File

@ -19,5 +19,6 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
</devices>
</domain>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<serial type='dev'>
<source path='/dev/ttyS2'/>
<target port='0'/>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<serial type='dev'>
<source path='/dev/ttyS2'/>
<target port='0'/>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<serial type='file'>
<source path='/tmp/serial.log'/>
<target port='0'/>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<serial type='file'>
<source path='/tmp/serial.log'/>
<target port='0'/>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<serial type='pty'>
<target port='0'/>
</serial>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<serial type='pty'>
<target port='0'/>
</serial>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<serial type='pty'>
<target port='0'/>
</serial>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<serial type='pty'>
<target port='0'/>
</serial>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<serial type='tcp'>
<source mode='connect' host='127.0.0.1' service='9999'/>
<protocol type='raw'/>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<serial type='tcp'>
<source mode='bind' host='127.0.0.1' service='9999'/>
<protocol type='telnet'/>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<serial type='tcp'>
<source mode='bind' host='127.0.0.1' service='9999'/>
<protocol type='telnet'/>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<serial type='tcp'>
<source mode='connect' host='127.0.0.1' service='9999'/>
<protocol type='raw'/>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<serial type='udp'>
<source mode='bind' host='127.0.0.1' service='9999'/>
<source mode='connect' host='127.0.0.1' service='9998'/>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<serial type='udp'>
<source mode='bind' host='127.0.0.1' service='9999'/>
<source mode='connect' host='127.0.0.1' service='9998'/>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<serial type='unix'>
<source mode='connect' path='/tmp/serial.sock'/>
<target port='0'/>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<serial type='unix'>
<source mode='connect' path='/tmp/serial.sock'/>
<target port='0'/>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<serial type='vc'>
<target port='0'/>
</serial>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<serial type='vc'>
<target port='0'/>
</serial>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<sound model='pcspk'/>
<sound model='es1370'/>
<sound model='sb16'/>

View File

@ -19,6 +19,7 @@
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
<watchdog model='ib700' action='poweroff'/>
</devices>
</domain>