qemu: Simplify modelName stringification

There's no need to perform checks before conversion, we can just
call virDomainControllerPCIModelNameTypeToString() and check the
results later on.

Since the variables involved are only used for PCI controllers,
we can declare them in the 'case' scope rather than in the
function scope to make everything a bit nicer while at it.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
This commit is contained in:
Andrea Bolognani 2018-02-12 18:55:04 +01:00
parent 35e9c02cbe
commit cbd1eba8b7

View File

@ -2625,8 +2625,6 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
{ {
virBuffer buf = VIR_BUFFER_INITIALIZER; virBuffer buf = VIR_BUFFER_INITIALIZER;
int address_type = def->info.type; int address_type = def->info.type;
const virDomainPCIControllerOpts *pciopts;
const char *modelName = NULL;
*devstr = NULL; *devstr = NULL;
@ -2726,11 +2724,9 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
break; break;
case VIR_DOMAIN_CONTROLLER_TYPE_PCI: case VIR_DOMAIN_CONTROLLER_TYPE_PCI: {
pciopts = &def->opts.pciopts; const virDomainPCIControllerOpts *pciopts = &def->opts.pciopts;
if (def->model != VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT && const char *modelName = virDomainControllerPCIModelNameTypeToString(pciopts->modelName);
def->model != VIR_DOMAIN_CONTROLLER_MODEL_PCI_LAST)
modelName = virDomainControllerPCIModelNameTypeToString(pciopts->modelName);
/* Skip the implicit PHB for pSeries guests */ /* Skip the implicit PHB for pSeries guests */
if (def->model == VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT && if (def->model == VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT &&
@ -2739,6 +2735,13 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
goto done; goto done;
} }
if (!modelName) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unknown virDomainControllerPCIModelName value: %d"),
pciopts->modelName);
return -1;
}
switch ((virDomainControllerModelPCI) def->model) { switch ((virDomainControllerModelPCI) def->model) {
case VIR_DOMAIN_CONTROLLER_MODEL_PCI_BRIDGE: case VIR_DOMAIN_CONTROLLER_MODEL_PCI_BRIDGE:
virBufferAsprintf(&buf, "%s,chassis_nr=%d,id=%s", virBufferAsprintf(&buf, "%s,chassis_nr=%d,id=%s",
@ -2780,6 +2783,7 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
goto error; goto error;
} }
break; break;
}
case VIR_DOMAIN_CONTROLLER_TYPE_IDE: case VIR_DOMAIN_CONTROLLER_TYPE_IDE:
case VIR_DOMAIN_CONTROLLER_TYPE_FDC: case VIR_DOMAIN_CONTROLLER_TYPE_FDC: