mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
conf,qemu: Use type-aware switches where possible
The compiler can warn us if we add a value to the virDomainChrSerialTargetType enumeration but forget to handle it properly in the code. Let's take advantage of that. This commit is best viewed with 'git diff -w'. Signed-off-by: Andrea Bolognani <abologna@redhat.com> Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
parent
593639ffff
commit
18dfc00145
@ -4037,26 +4037,39 @@ virDomainDefAddConsoleCompat(virDomainDefPtr def)
|
|||||||
def->consoles[0]->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL;
|
def->consoles[0]->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL;
|
||||||
}
|
}
|
||||||
} else if (def->os.type == VIR_DOMAIN_OSTYPE_HVM && def->nserials > 0 &&
|
} else if (def->os.type == VIR_DOMAIN_OSTYPE_HVM && def->nserials > 0 &&
|
||||||
def->serials[0]->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL &&
|
def->serials[0]->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL) {
|
||||||
def->serials[0]->targetType == VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA) {
|
|
||||||
/* Create a stub console to match the serial port.
|
|
||||||
* console[0] either does not exist
|
|
||||||
* or has a different type than SERIAL or NONE.
|
|
||||||
*/
|
|
||||||
virDomainChrDefPtr chr;
|
|
||||||
if (!(chr = virDomainChrDefNew(NULL)))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (VIR_INSERT_ELEMENT(def->consoles,
|
switch ((virDomainChrSerialTargetType) def->serials[0]->targetType) {
|
||||||
0,
|
case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA: {
|
||||||
def->nconsoles,
|
|
||||||
chr) < 0) {
|
/* Create a stub console to match the serial port.
|
||||||
virDomainChrDefFree(chr);
|
* console[0] either does not exist
|
||||||
return -1;
|
* or has a different type than SERIAL or NONE.
|
||||||
|
*/
|
||||||
|
virDomainChrDefPtr chr;
|
||||||
|
if (!(chr = virDomainChrDefNew(NULL)))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (VIR_INSERT_ELEMENT(def->consoles,
|
||||||
|
0,
|
||||||
|
def->nconsoles,
|
||||||
|
chr) < 0) {
|
||||||
|
virDomainChrDefFree(chr);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
def->consoles[0]->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE;
|
||||||
|
def->consoles[0]->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL;
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
def->consoles[0]->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE;
|
case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_PCI:
|
||||||
def->consoles[0]->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL;
|
case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB:
|
||||||
|
case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_LAST:
|
||||||
|
/* Nothing to do */
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -10251,7 +10251,7 @@ qemuBuildSerialChrDeviceStr(char **deviceStr,
|
|||||||
serial->info.alias);
|
serial->info.alias);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch (serial->targetType) {
|
switch ((virDomainChrSerialTargetType) serial->targetType) {
|
||||||
case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB:
|
case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB:
|
||||||
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_USB_SERIAL)) {
|
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_USB_SERIAL)) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
@ -10290,6 +10290,11 @@ qemuBuildSerialChrDeviceStr(char **deviceStr,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_LAST:
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
_("Invalid target type for serial device"));
|
||||||
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
virBufferAsprintf(&cmd, "%s,chardev=char%s,id=%s",
|
virBufferAsprintf(&cmd, "%s,chardev=char%s,id=%s",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user