qemu: define virDomainDevAddUSBController()

This new function will add a single controller of the given model,
except the case of ich9-usb-ehci1 (the master controller for a USB2
controller set) in which case a set of related controllers will be
added (EHCI1, UHCI1, UHCI2, UHCI3). These controllers will not be
given PCI addresses, but should be otherwise ready to use.

"-1" is allowed for controller model, and means "default for this
machinetype". This matches the existing practice in
qemuDomainDefPostParse(), which always adds the default controller
with model = -1, and relies on the commandline builder to set a model
(that is wrong, but will be fixed later).
This commit is contained in:
Laine Stump 2015-11-05 15:16:50 -05:00
parent ed64d92bea
commit 8ebca27bb7
3 changed files with 57 additions and 0 deletions

View File

@ -14290,6 +14290,60 @@ virDomainDefAddController(virDomainDefPtr def, int type, int idx, int model)
}
/**
* virDomainDefAddUSBController:
* @def: the domain
* @idx: index for new controller (or -1 for "lowest unused index")
* @model: VIR_DOMAIN_CONTROLLER_MODEL_USB_* or -1
*
* Add a USB controller of the specified model (or default model for
* current machinetype if model == -1). If model is ich9-usb-ehci,
* also add companion uhci1, uhci2, and uhci3 controllers at the same
* index.
*
* Returns 0 on success, -1 on failure.
*/
int
virDomainDefAddUSBController(virDomainDefPtr def, int idx, int model)
{
virDomainControllerDefPtr cont; /* this is a *copy* of the DefPtr */
cont = virDomainDefAddController(def, VIR_DOMAIN_CONTROLLER_TYPE_USB,
idx, model);
if (!cont)
return -1;
if (model != VIR_DOMAIN_CONTROLLER_MODEL_USB_ICH9_EHCI1)
return 0;
/* When the initial controller is ich9-usb-ehci, also add the
* companion controllers
*/
idx = cont->idx; /* in case original request was "-1" */
if (!(cont = virDomainDefAddController(def, VIR_DOMAIN_CONTROLLER_TYPE_USB,
idx, VIR_DOMAIN_CONTROLLER_MODEL_USB_ICH9_UHCI1)))
return -1;
cont->info.mastertype = VIR_DOMAIN_CONTROLLER_MASTER_USB;
cont->info.master.usb.startport = 0;
if (!(cont = virDomainDefAddController(def, VIR_DOMAIN_CONTROLLER_TYPE_USB,
idx, VIR_DOMAIN_CONTROLLER_MODEL_USB_ICH9_UHCI2)))
return -1;
cont->info.mastertype = VIR_DOMAIN_CONTROLLER_MASTER_USB;
cont->info.master.usb.startport = 2;
if (!(cont = virDomainDefAddController(def, VIR_DOMAIN_CONTROLLER_TYPE_USB,
idx, VIR_DOMAIN_CONTROLLER_MODEL_USB_ICH9_UHCI3)))
return -1;
cont->info.mastertype = VIR_DOMAIN_CONTROLLER_MASTER_USB;
cont->info.master.usb.startport = 4;
return 0;
}
int
virDomainDefMaybeAddController(virDomainDefPtr def,
int type,

View File

@ -3089,6 +3089,8 @@ VIR_ENUM_DECL(virDomainCpuPlacementMode)
VIR_ENUM_DECL(virDomainStartupPolicy)
int
virDomainDefAddUSBController(virDomainDefPtr def, int idx, int model);
int
virDomainDefMaybeAddController(virDomainDefPtr def,
int type,

View File

@ -198,6 +198,7 @@ virDomainControllerTypeToString;
virDomainCpuPlacementModeTypeFromString;
virDomainCpuPlacementModeTypeToString;
virDomainDefAddImplicitControllers;
virDomainDefAddUSBController;
virDomainDefCheckABIStability;
virDomainDefCheckDuplicateDiskInfo;
virDomainDefCheckUnsupportedMemoryHotplug;