mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 06:35:24 +00:00
qemu: Introduce qemuBuildControllerDevCommandLine
Add new function to manage adding the controller -device options to the command line removing that task from the mainline qemuBuildCommandLine. Also adjust to using const virDomainDef instead of virDomainDefPtr. This causes collateral damage in order to modify called APIs to use the const virDomainDef instead as well. Signed-off-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
73379375c8
commit
4908772e15
@ -13500,8 +13500,9 @@ void virDomainControllerInsertPreAlloced(virDomainDefPtr def,
|
||||
}
|
||||
|
||||
int
|
||||
virDomainControllerFind(virDomainDefPtr def,
|
||||
int type, int idx)
|
||||
virDomainControllerFind(const virDomainDef *def,
|
||||
int type,
|
||||
int idx)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
@ -13529,8 +13530,9 @@ virDomainControllerFindUnusedIndex(virDomainDefPtr def, int type)
|
||||
|
||||
|
||||
const char *
|
||||
virDomainControllerAliasFind(virDomainDefPtr def,
|
||||
int type, int idx)
|
||||
virDomainControllerAliasFind(const virDomainDef *def,
|
||||
int type,
|
||||
int idx)
|
||||
{
|
||||
int contIndex;
|
||||
const char *contTypeStr = virDomainControllerTypeToString(type);
|
||||
|
@ -2835,12 +2835,12 @@ int virDomainControllerInsert(virDomainDefPtr def,
|
||||
ATTRIBUTE_RETURN_CHECK;
|
||||
void virDomainControllerInsertPreAlloced(virDomainDefPtr def,
|
||||
virDomainControllerDefPtr controller);
|
||||
int virDomainControllerFind(virDomainDefPtr def, int type, int idx);
|
||||
int virDomainControllerFind(const virDomainDef *def, int type, int idx);
|
||||
int virDomainControllerFindByType(virDomainDefPtr def, int type);
|
||||
int virDomainControllerFindByPCIAddress(virDomainDefPtr def,
|
||||
virDevicePCIAddressPtr addr);
|
||||
virDomainControllerDefPtr virDomainControllerRemove(virDomainDefPtr def, size_t i);
|
||||
const char *virDomainControllerAliasFind(virDomainDefPtr def,
|
||||
const char *virDomainControllerAliasFind(const virDomainDef *def,
|
||||
int type, int idx)
|
||||
ATTRIBUTE_NONNULL(1);
|
||||
|
||||
|
@ -330,7 +330,7 @@ char *qemuDeviceDriveHostAlias(virDomainDiskDefPtr disk,
|
||||
|
||||
static int
|
||||
qemuBuildDeviceAddressStr(virBufferPtr buf,
|
||||
virDomainDefPtr domainDef,
|
||||
const virDomainDef *domainDef,
|
||||
virDomainDeviceInfoPtr info,
|
||||
virQEMUCapsPtr qemuCaps)
|
||||
{
|
||||
@ -979,7 +979,7 @@ qemuCheckDiskConfig(virDomainDiskDefPtr disk)
|
||||
* an error and return false; otherwise, return true.
|
||||
*/
|
||||
bool
|
||||
qemuCheckCCWS390AddressSupport(virDomainDefPtr def,
|
||||
qemuCheckCCWS390AddressSupport(const virDomainDef *def,
|
||||
virDomainDeviceInfo info,
|
||||
virQEMUCapsPtr qemuCaps,
|
||||
const char *devicename)
|
||||
@ -1958,7 +1958,7 @@ qemuControllerModelUSBToCaps(int model)
|
||||
|
||||
|
||||
static int
|
||||
qemuBuildUSBControllerDevStr(virDomainDefPtr domainDef,
|
||||
qemuBuildUSBControllerDevStr(const virDomainDef *domainDef,
|
||||
virDomainControllerDefPtr def,
|
||||
virQEMUCapsPtr qemuCaps,
|
||||
virBuffer *buf)
|
||||
@ -1996,7 +1996,7 @@ qemuBuildUSBControllerDevStr(virDomainDefPtr domainDef,
|
||||
}
|
||||
|
||||
char *
|
||||
qemuBuildControllerDevStr(virDomainDefPtr domainDef,
|
||||
qemuBuildControllerDevStr(const virDomainDef *domainDef,
|
||||
virDomainControllerDefPtr def,
|
||||
virQEMUCapsPtr qemuCaps,
|
||||
int *nusbcontroller)
|
||||
@ -2354,6 +2354,120 @@ qemuBuildControllerDevStr(virDomainDefPtr domainDef,
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
qemuBuildControllerDevCommandLine(virCommandPtr cmd,
|
||||
const virDomainDef *def,
|
||||
virQEMUCapsPtr qemuCaps)
|
||||
{
|
||||
size_t i, j;
|
||||
int usbcontroller = 0;
|
||||
bool usblegacy = false;
|
||||
int contOrder[] = {
|
||||
/*
|
||||
* List of controller types that we add commandline args for,
|
||||
* *in the order we want to add them*.
|
||||
*
|
||||
* The floppy controller is implicit on PIIX4 and older Q35
|
||||
* machines. For newer Q35 machines it is added out of the
|
||||
* controllers loop, after the floppy drives.
|
||||
*
|
||||
* We don't add PCI/PCIe root controller either, because it's
|
||||
* implicit, but we do add PCI bridges and other PCI
|
||||
* controllers, so we leave that in to check each
|
||||
* one. Likewise, we don't do anything for the primary IDE
|
||||
* controller on an i440fx machine or primary SATA on q35, but
|
||||
* we do add those beyond these two exceptions.
|
||||
*/
|
||||
VIR_DOMAIN_CONTROLLER_TYPE_PCI,
|
||||
VIR_DOMAIN_CONTROLLER_TYPE_USB,
|
||||
VIR_DOMAIN_CONTROLLER_TYPE_SCSI,
|
||||
VIR_DOMAIN_CONTROLLER_TYPE_IDE,
|
||||
VIR_DOMAIN_CONTROLLER_TYPE_SATA,
|
||||
VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL,
|
||||
VIR_DOMAIN_CONTROLLER_TYPE_CCID,
|
||||
};
|
||||
|
||||
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE))
|
||||
goto check_add_usb;
|
||||
|
||||
for (j = 0; j < ARRAY_CARDINALITY(contOrder); j++) {
|
||||
for (i = 0; i < def->ncontrollers; i++) {
|
||||
virDomainControllerDefPtr cont = def->controllers[i];
|
||||
char *devstr;
|
||||
|
||||
if (cont->type != contOrder[j])
|
||||
continue;
|
||||
|
||||
/* skip USB controllers with type none.*/
|
||||
if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_USB &&
|
||||
cont->model == VIR_DOMAIN_CONTROLLER_MODEL_USB_NONE) {
|
||||
usbcontroller = -1; /* mark we don't want a controller */
|
||||
continue;
|
||||
}
|
||||
|
||||
/* skip pci-root/pcie-root */
|
||||
if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI &&
|
||||
(cont->model == VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT ||
|
||||
cont->model == VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT))
|
||||
continue;
|
||||
|
||||
/* first SATA controller on Q35 machines is implicit */
|
||||
if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_SATA &&
|
||||
cont->idx == 0 && qemuDomainMachineIsQ35(def))
|
||||
continue;
|
||||
|
||||
/* first IDE controller is implicit on various machines */
|
||||
if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_IDE &&
|
||||
cont->idx == 0 && qemuDomainMachineHasBuiltinIDE(def))
|
||||
continue;
|
||||
|
||||
if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_USB &&
|
||||
cont->model == -1 &&
|
||||
!qemuDomainMachineIsQ35(def)) {
|
||||
bool need_legacy = false;
|
||||
|
||||
/* We're not using legacy usb controller for q35 */
|
||||
if (ARCH_IS_PPC64(def->os.arch)) {
|
||||
/* For ppc64 the legacy was OHCI */
|
||||
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_PCI_OHCI))
|
||||
need_legacy = true;
|
||||
} else {
|
||||
/* For anything else, we used PIIX3_USB_UHCI */
|
||||
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_PIIX3_USB_UHCI))
|
||||
need_legacy = true;
|
||||
}
|
||||
|
||||
if (need_legacy) {
|
||||
if (usblegacy) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||
_("Multiple legacy USB controllers are "
|
||||
"not supported"));
|
||||
return -1;
|
||||
}
|
||||
usblegacy = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
virCommandAddArg(cmd, "-device");
|
||||
if (!(devstr = qemuBuildControllerDevStr(def, cont, qemuCaps,
|
||||
&usbcontroller)))
|
||||
return -1;
|
||||
virCommandAddArg(cmd, devstr);
|
||||
VIR_FREE(devstr);
|
||||
}
|
||||
}
|
||||
|
||||
check_add_usb:
|
||||
if (usbcontroller == 0 &&
|
||||
!qemuDomainMachineIsQ35(def) &&
|
||||
!ARCH_IS_S390(def->os.arch))
|
||||
virCommandAddArg(cmd, "-usb");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* qemuBuildMemoryBackendStr:
|
||||
* @size: size of the memory device in kibibytes
|
||||
@ -7596,33 +7710,7 @@ qemuBuildCommandLine(virConnectPtr conn,
|
||||
int last_good_net = -1;
|
||||
virCommandPtr cmd = NULL;
|
||||
bool emitBootindex = false;
|
||||
int usbcontroller = 0;
|
||||
int actualSerials = 0;
|
||||
bool usblegacy = false;
|
||||
int contOrder[] = {
|
||||
/*
|
||||
* List of controller types that we add commandline args for,
|
||||
* *in the order we want to add them*.
|
||||
*
|
||||
* The floppy controller is implicit on PIIX4 and older Q35
|
||||
* machines. For newer Q35 machines it is added out of the
|
||||
* controllers loop, after the floppy drives.
|
||||
*
|
||||
* We don't add PCI/PCIe root controller either, because it's
|
||||
* implicit, but we do add PCI bridges and other PCI
|
||||
* controllers, so we leave that in to check each
|
||||
* one. Likewise, we don't do anything for the primary IDE
|
||||
* controller on an i440fx machine or primary SATA on q35, but
|
||||
* we do add those beyond these two exceptions.
|
||||
*/
|
||||
VIR_DOMAIN_CONTROLLER_TYPE_PCI,
|
||||
VIR_DOMAIN_CONTROLLER_TYPE_USB,
|
||||
VIR_DOMAIN_CONTROLLER_TYPE_SCSI,
|
||||
VIR_DOMAIN_CONTROLLER_TYPE_IDE,
|
||||
VIR_DOMAIN_CONTROLLER_TYPE_SATA,
|
||||
VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL,
|
||||
VIR_DOMAIN_CONTROLLER_TYPE_CCID,
|
||||
};
|
||||
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
||||
virBuffer fdc_opts = VIR_BUFFER_INITIALIZER;
|
||||
char *fdc_opts_str = NULL;
|
||||
@ -7733,80 +7821,8 @@ qemuBuildCommandLine(virConnectPtr conn,
|
||||
if (qemuBuildGlobalControllerCommandLine(cmd, def, qemuCaps) < 0)
|
||||
goto error;
|
||||
|
||||
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) {
|
||||
for (j = 0; j < ARRAY_CARDINALITY(contOrder); j++) {
|
||||
for (i = 0; i < def->ncontrollers; i++) {
|
||||
virDomainControllerDefPtr cont = def->controllers[i];
|
||||
char *devstr;
|
||||
|
||||
if (cont->type != contOrder[j])
|
||||
continue;
|
||||
|
||||
/* skip USB controllers with type none.*/
|
||||
if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_USB &&
|
||||
cont->model == VIR_DOMAIN_CONTROLLER_MODEL_USB_NONE) {
|
||||
usbcontroller = -1; /* mark we don't want a controller */
|
||||
continue;
|
||||
}
|
||||
|
||||
/* skip pci-root/pcie-root */
|
||||
if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI &&
|
||||
(cont->model == VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT ||
|
||||
cont->model == VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT))
|
||||
continue;
|
||||
|
||||
/* first SATA controller on Q35 machines is implicit */
|
||||
if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_SATA &&
|
||||
cont->idx == 0 && qemuDomainMachineIsQ35(def))
|
||||
continue;
|
||||
|
||||
/* first IDE controller is implicit on various machines */
|
||||
if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_IDE &&
|
||||
cont->idx == 0 && qemuDomainMachineHasBuiltinIDE(def))
|
||||
continue;
|
||||
|
||||
if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_USB &&
|
||||
cont->model == -1 &&
|
||||
!qemuDomainMachineIsQ35(def)) {
|
||||
bool need_legacy = false;
|
||||
|
||||
/* We're not using legacy usb controller for q35 */
|
||||
if (ARCH_IS_PPC64(def->os.arch)) {
|
||||
/* For ppc64 the legacy was OHCI */
|
||||
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_PCI_OHCI))
|
||||
need_legacy = true;
|
||||
} else {
|
||||
/* For anything else, we used PIIX3_USB_UHCI */
|
||||
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_PIIX3_USB_UHCI))
|
||||
need_legacy = true;
|
||||
}
|
||||
|
||||
if (need_legacy) {
|
||||
if (usblegacy) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||
_("Multiple legacy USB controllers are "
|
||||
"not supported"));
|
||||
goto error;
|
||||
}
|
||||
usblegacy = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
virCommandAddArg(cmd, "-device");
|
||||
if (!(devstr = qemuBuildControllerDevStr(def, cont, qemuCaps,
|
||||
&usbcontroller)))
|
||||
goto error;
|
||||
virCommandAddArg(cmd, devstr);
|
||||
VIR_FREE(devstr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (usbcontroller == 0 &&
|
||||
!qemuDomainMachineIsQ35(def) &&
|
||||
!ARCH_IS_S390(def->os.arch))
|
||||
virCommandAddArg(cmd, "-usb");
|
||||
if (qemuBuildControllerDevCommandLine(cmd, def, qemuCaps) < 0)
|
||||
goto error;
|
||||
|
||||
for (i = 0; i < def->nhubs; i++) {
|
||||
virDomainHubDefPtr hub = def->hubs[i];
|
||||
|
@ -129,7 +129,7 @@ char *qemuBuildFSDevStr(virDomainDefPtr domainDef,
|
||||
virDomainFSDefPtr fs,
|
||||
virQEMUCapsPtr qemuCaps);
|
||||
/* Current, best practice */
|
||||
char *qemuBuildControllerDevStr(virDomainDefPtr domainDef,
|
||||
char *qemuBuildControllerDevStr(const virDomainDef *domainDef,
|
||||
virDomainControllerDefPtr def,
|
||||
virQEMUCapsPtr qemuCaps,
|
||||
int *nusbcontroller);
|
||||
@ -228,7 +228,7 @@ int qemuCheckDiskConfig(virDomainDiskDefPtr disk);
|
||||
bool
|
||||
qemuCheckFips(void);
|
||||
|
||||
bool qemuCheckCCWS390AddressSupport(virDomainDefPtr def,
|
||||
bool qemuCheckCCWS390AddressSupport(const virDomainDef *def,
|
||||
virDomainDeviceInfo info,
|
||||
virQEMUCapsPtr qemuCaps,
|
||||
const char *devicename);
|
||||
|
@ -40,7 +40,7 @@ VIR_LOG_INIT("qemu.qemu_domain_address");
|
||||
|
||||
|
||||
int
|
||||
qemuDomainSetSCSIControllerModel(virDomainDefPtr def,
|
||||
qemuDomainSetSCSIControllerModel(const virDomainDef *def,
|
||||
virQEMUCapsPtr qemuCaps,
|
||||
int *model)
|
||||
{
|
||||
|
@ -27,7 +27,7 @@
|
||||
# include "domain_conf.h"
|
||||
# include "qemu_capabilities.h"
|
||||
|
||||
int qemuDomainSetSCSIControllerModel(virDomainDefPtr def,
|
||||
int qemuDomainSetSCSIControllerModel(const virDomainDef *def,
|
||||
virQEMUCapsPtr qemuCaps,
|
||||
int *model);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user