mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
Fix default console type setting
The default console type may vary based on the OS type. ie a Xen paravirt guests wants a 'xen' console, while a fullvirt guests wants a 'serial' console. A plain integer default console type in the capabilities does not suffice. Instead introduce a callback that is passed the OS type. * src/conf/capabilities.h: Use a callback for default console type * src/conf/domain_conf.c, src/conf/domain_conf.h: Use callback for default console type. Add missing LXC/OpenVZ console types. * src/esx/esx_driver.c, src/libxl/libxl_conf.c, src/lxc/lxc_conf.c, src/openvz/openvz_conf.c, src/phyp/phyp_driver.c, src/qemu/qemu_capabilities.c, src/uml/uml_conf.c, src/vbox/vbox_tmpl.c, src/vmware/vmware_conf.c, src/xen/xen_hypervisor.c, src/xenapi/xenapi_driver.c: Set default console type callback
This commit is contained in:
parent
8866eed097
commit
209c2880b9
@ -144,7 +144,7 @@ struct _virCaps {
|
||||
unsigned int emulatorRequired : 1;
|
||||
const char *defaultDiskDriverName;
|
||||
const char *defaultDiskDriverType;
|
||||
int defaultConsoleTargetType;
|
||||
int (*defaultConsoleTargetType)(const char *ostype);
|
||||
void *(*privateDataAllocFunc)(void);
|
||||
void (*privateDataFreeFunc)(void *);
|
||||
int (*privateDataXMLFormat)(virBufferPtr, void *);
|
||||
|
@ -295,7 +295,9 @@ VIR_ENUM_IMPL(virDomainChrConsoleTarget,
|
||||
"serial",
|
||||
"xen",
|
||||
"uml",
|
||||
"virtio")
|
||||
"virtio",
|
||||
"lxc",
|
||||
"openvz")
|
||||
|
||||
VIR_ENUM_IMPL(virDomainChrDevice, VIR_DOMAIN_CHR_DEVICE_TYPE_LAST,
|
||||
"parallel",
|
||||
@ -3578,7 +3580,9 @@ error:
|
||||
}
|
||||
|
||||
static int
|
||||
virDomainChrDefaultTargetType(virCapsPtr caps, int devtype) {
|
||||
virDomainChrDefaultTargetType(virCapsPtr caps,
|
||||
virDomainDefPtr def,
|
||||
int devtype) {
|
||||
|
||||
int target = -1;
|
||||
|
||||
@ -3590,7 +3594,12 @@ virDomainChrDefaultTargetType(virCapsPtr caps, int devtype) {
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE:
|
||||
target = caps->defaultConsoleTargetType;
|
||||
if (!caps->defaultConsoleTargetType) {
|
||||
virDomainReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Driver does not have a default console type set"));
|
||||
return -1;
|
||||
}
|
||||
target = caps->defaultConsoleTargetType(def->os.type);
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL:
|
||||
@ -3606,6 +3615,7 @@ virDomainChrDefaultTargetType(virCapsPtr caps, int devtype) {
|
||||
|
||||
static int
|
||||
virDomainChrTargetTypeFromString(virCapsPtr caps,
|
||||
virDomainDefPtr def,
|
||||
int devtype,
|
||||
const char *targetType)
|
||||
{
|
||||
@ -3613,7 +3623,7 @@ virDomainChrTargetTypeFromString(virCapsPtr caps,
|
||||
int target = 0;
|
||||
|
||||
if (!targetType) {
|
||||
target = virDomainChrDefaultTargetType(caps, devtype);
|
||||
target = virDomainChrDefaultTargetType(caps, def, devtype);
|
||||
goto out;
|
||||
}
|
||||
|
||||
@ -3640,6 +3650,7 @@ out:
|
||||
|
||||
static int
|
||||
virDomainChrDefParseTargetXML(virCapsPtr caps,
|
||||
virDomainDefPtr vmdef,
|
||||
virDomainChrDefPtr def,
|
||||
xmlNodePtr cur)
|
||||
{
|
||||
@ -3650,8 +3661,8 @@ virDomainChrDefParseTargetXML(virCapsPtr caps,
|
||||
const char *portStr = NULL;
|
||||
|
||||
if ((def->targetType =
|
||||
virDomainChrTargetTypeFromString(caps,
|
||||
def->deviceType, targetType)) < 0) {
|
||||
virDomainChrTargetTypeFromString(caps, vmdef,
|
||||
def->deviceType, targetType)) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
@ -3989,6 +4000,7 @@ virDomainChrDefNew(void) {
|
||||
*/
|
||||
static virDomainChrDefPtr
|
||||
virDomainChrDefParseXML(virCapsPtr caps,
|
||||
virDomainDefPtr vmdef,
|
||||
xmlNodePtr node,
|
||||
unsigned int flags)
|
||||
{
|
||||
@ -4028,7 +4040,7 @@ virDomainChrDefParseXML(virCapsPtr caps,
|
||||
if (cur->type == XML_ELEMENT_NODE) {
|
||||
if (xmlStrEqual(cur->name, BAD_CAST "target")) {
|
||||
seenTarget = true;
|
||||
if (virDomainChrDefParseTargetXML(caps, def, cur) < 0) {
|
||||
if (virDomainChrDefParseTargetXML(caps, vmdef, def, cur) < 0) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
@ -4038,7 +4050,7 @@ virDomainChrDefParseXML(virCapsPtr caps,
|
||||
}
|
||||
|
||||
if (!seenTarget &&
|
||||
((def->targetType = virDomainChrDefaultTargetType(caps, def->deviceType)) < 0))
|
||||
((def->targetType = virDomainChrDefaultTargetType(caps, vmdef, def->deviceType)) < 0))
|
||||
goto cleanup;
|
||||
|
||||
if (def->source.type == VIR_DOMAIN_CHR_TYPE_SPICEVMC) {
|
||||
@ -7167,6 +7179,7 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
|
||||
|
||||
for (i = 0 ; i < n ; i++) {
|
||||
virDomainChrDefPtr chr = virDomainChrDefParseXML(caps,
|
||||
def,
|
||||
nodes[i],
|
||||
flags);
|
||||
if (!chr)
|
||||
@ -7193,6 +7206,7 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
|
||||
|
||||
for (i = 0 ; i < n ; i++) {
|
||||
virDomainChrDefPtr chr = virDomainChrDefParseXML(caps,
|
||||
def,
|
||||
nodes[i],
|
||||
flags);
|
||||
if (!chr)
|
||||
@ -7221,6 +7235,7 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
|
||||
|
||||
for (i = 0 ; i < n ; i++) {
|
||||
virDomainChrDefPtr chr = virDomainChrDefParseXML(caps,
|
||||
def,
|
||||
nodes[i],
|
||||
flags);
|
||||
if (!chr)
|
||||
@ -7285,6 +7300,7 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
|
||||
|
||||
for (i = 0 ; i < n ; i++) {
|
||||
virDomainChrDefPtr chr = virDomainChrDefParseXML(caps,
|
||||
def,
|
||||
nodes[i],
|
||||
flags);
|
||||
if (!chr)
|
||||
|
@ -605,6 +605,8 @@ enum virDomainChrConsoleTargetType {
|
||||
VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_XEN,
|
||||
VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_UML,
|
||||
VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_VIRTIO,
|
||||
VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_LXC,
|
||||
VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_OPENVZ,
|
||||
|
||||
VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_LAST,
|
||||
};
|
||||
|
@ -588,6 +588,11 @@ esxLookupHostSystemBiosUuid(esxPrivate *priv, unsigned char *uuid)
|
||||
}
|
||||
|
||||
|
||||
static int esxDefaultConsoleType(const char *ostype ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL;
|
||||
}
|
||||
|
||||
|
||||
static virCapsPtr
|
||||
esxCapsInit(esxPrivate *priv)
|
||||
@ -615,6 +620,7 @@ esxCapsInit(esxPrivate *priv)
|
||||
virCapabilitiesAddHostMigrateTransport(caps, "vpxmigr");
|
||||
|
||||
caps->hasWideScsiBus = true;
|
||||
caps->defaultConsoleTargetType = esxDefaultConsoleType;
|
||||
|
||||
if (esxLookupHostSystemBiosUuid(priv, caps->host.host_uuid) < 0) {
|
||||
goto failure;
|
||||
|
@ -114,6 +114,15 @@ libxlNextFreeVncPort(libxlDriverPrivatePtr driver, int startPort)
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
static int libxlDefaultConsoleType(const char *ostype)
|
||||
{
|
||||
if (STREQ(ostype, "hvm"))
|
||||
return VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL;
|
||||
else
|
||||
return VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_XEN;
|
||||
}
|
||||
|
||||
static virCapsPtr
|
||||
libxlBuildCapabilities(const char *hostmachine,
|
||||
int host_pae,
|
||||
@ -206,7 +215,7 @@ libxlBuildCapabilities(const char *hostmachine,
|
||||
}
|
||||
}
|
||||
|
||||
caps->defaultConsoleTargetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_XEN;
|
||||
caps->defaultConsoleTargetType = libxlDefaultConsoleType;
|
||||
|
||||
return caps;
|
||||
|
||||
|
@ -40,6 +40,12 @@
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_LXC
|
||||
|
||||
static int lxcDefaultConsoleType(const char *ostype ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_LXC;
|
||||
}
|
||||
|
||||
|
||||
/* Functions */
|
||||
virCapsPtr lxcCapsInit(void)
|
||||
{
|
||||
@ -54,6 +60,8 @@ virCapsPtr lxcCapsInit(void)
|
||||
0, 0)) == NULL)
|
||||
goto error;
|
||||
|
||||
caps->defaultConsoleTargetType = lxcDefaultConsoleType;
|
||||
|
||||
/* Some machines have problematic NUMA toplogy causing
|
||||
* unexpected failures. We don't want to break the QEMU
|
||||
* driver in this scenario, so log errors & carry on
|
||||
|
@ -129,6 +129,11 @@ int openvzExtractVersion(struct openvz_driver *driver)
|
||||
}
|
||||
|
||||
|
||||
static int openvzDefaultConsoleType(const char *ostype ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_OPENVZ;
|
||||
}
|
||||
|
||||
virCapsPtr openvzCapsInit(void)
|
||||
{
|
||||
struct utsname utsname;
|
||||
@ -165,6 +170,7 @@ virCapsPtr openvzCapsInit(void)
|
||||
goto no_memory;
|
||||
|
||||
caps->defaultInitPath = "/sbin/init";
|
||||
caps->defaultConsoleTargetType = openvzDefaultConsoleType;
|
||||
|
||||
return caps;
|
||||
no_memory:
|
||||
|
@ -291,6 +291,13 @@ phypGetVIOSPartitionID(virConnectPtr conn)
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
static int phypDefaultConsoleType(const char *ostype ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL;
|
||||
}
|
||||
|
||||
|
||||
static virCapsPtr
|
||||
phypCapsInit(void)
|
||||
{
|
||||
@ -328,6 +335,8 @@ phypCapsInit(void)
|
||||
"phyp", NULL, NULL, 0, NULL) == NULL)
|
||||
goto no_memory;
|
||||
|
||||
caps->defaultConsoleTargetType = phypDefaultConsoleType;
|
||||
|
||||
return caps;
|
||||
|
||||
no_memory:
|
||||
|
@ -807,6 +807,12 @@ error:
|
||||
}
|
||||
|
||||
|
||||
static int qemuDefaultConsoleType(const char *ostype ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL;
|
||||
}
|
||||
|
||||
|
||||
virCapsPtr qemuCapsInit(virCapsPtr old_caps)
|
||||
{
|
||||
struct utsname utsname;
|
||||
@ -874,7 +880,7 @@ virCapsPtr qemuCapsInit(virCapsPtr old_caps)
|
||||
/* QEMU Requires an emulator in the XML */
|
||||
virCapabilitiesSetEmulatorRequired(caps);
|
||||
|
||||
caps->defaultConsoleTargetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL;
|
||||
caps->defaultConsoleTargetType = qemuDefaultConsoleType;
|
||||
|
||||
return caps;
|
||||
|
||||
|
@ -152,6 +152,11 @@ static void testDomainObjPrivateFree(void *data)
|
||||
}
|
||||
|
||||
|
||||
static int testDefaultConsoleType(const char *ostype ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL;
|
||||
}
|
||||
|
||||
static virCapsPtr
|
||||
testBuildCapabilities(virConnectPtr conn) {
|
||||
testConnPtr privconn = conn->privateData;
|
||||
@ -163,6 +168,8 @@ testBuildCapabilities(virConnectPtr conn) {
|
||||
if ((caps = virCapabilitiesNew(TEST_MODEL, 0, 0)) == NULL)
|
||||
goto no_memory;
|
||||
|
||||
caps->defaultConsoleTargetType = testDefaultConsoleType;
|
||||
|
||||
if (virCapabilitiesAddHostFeature(caps, "pae") < 0)
|
||||
goto no_memory;
|
||||
if (virCapabilitiesAddHostFeature(caps ,"nonpae") < 0)
|
||||
|
@ -54,6 +54,13 @@
|
||||
#define umlLog(level, msg, ...) \
|
||||
virLogMessage(__FILE__, level, 0, msg, __VA_ARGS__)
|
||||
|
||||
|
||||
static int umlDefaultConsoleType(const char *ostype ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_UML;
|
||||
}
|
||||
|
||||
|
||||
virCapsPtr umlCapsInit(void) {
|
||||
struct utsname utsname;
|
||||
virCapsPtr caps;
|
||||
@ -99,7 +106,7 @@ virCapsPtr umlCapsInit(void) {
|
||||
NULL) == NULL)
|
||||
goto error;
|
||||
|
||||
caps->defaultConsoleTargetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_UML;
|
||||
caps->defaultConsoleTargetType = umlDefaultConsoleType;
|
||||
|
||||
return caps;
|
||||
|
||||
|
@ -825,6 +825,13 @@ cleanup:
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static int vboxDefaultConsoleType(const char *ostype ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL;
|
||||
}
|
||||
|
||||
|
||||
static virCapsPtr vboxCapsInit(void) {
|
||||
struct utsname utsname;
|
||||
virCapsPtr caps;
|
||||
@ -858,6 +865,9 @@ static virCapsPtr vboxCapsInit(void) {
|
||||
0,
|
||||
NULL) == NULL)
|
||||
goto no_memory;
|
||||
|
||||
caps->defaultConsoleTargetType = vboxDefaultConsoleType;
|
||||
|
||||
return caps;
|
||||
|
||||
no_memory:
|
||||
|
@ -49,6 +49,13 @@ vmwareFreeDriver(struct vmware_driver *driver)
|
||||
VIR_FREE(driver);
|
||||
}
|
||||
|
||||
|
||||
static int vmwareDefaultConsoleType(const char *ostype ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL;
|
||||
}
|
||||
|
||||
|
||||
virCapsPtr
|
||||
vmwareCapsInit(void)
|
||||
{
|
||||
@ -117,6 +124,8 @@ vmwareCapsInit(void)
|
||||
goto error;
|
||||
}
|
||||
|
||||
caps->defaultConsoleTargetType = vmwareDefaultConsoleType;
|
||||
|
||||
cleanup:
|
||||
virCPUDefFree(cpu);
|
||||
cpuDataFree(utsname.machine, data);
|
||||
|
@ -2276,6 +2276,14 @@ struct guest_arch {
|
||||
};
|
||||
|
||||
|
||||
static int xenDefaultConsoleType(const char *ostype)
|
||||
{
|
||||
if (STREQ(ostype, "hvm"))
|
||||
return VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL;
|
||||
else
|
||||
return VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_XEN;
|
||||
}
|
||||
|
||||
static virCapsPtr
|
||||
xenHypervisorBuildCapabilities(virConnectPtr conn,
|
||||
const char *hostmachine,
|
||||
@ -2405,7 +2413,7 @@ xenHypervisorBuildCapabilities(virConnectPtr conn,
|
||||
|
||||
}
|
||||
|
||||
caps->defaultConsoleTargetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_XEN;
|
||||
caps->defaultConsoleTargetType = xenDefaultConsoleType;
|
||||
|
||||
return caps;
|
||||
|
||||
|
@ -48,6 +48,16 @@
|
||||
virReportErrorHelper(VIR_FROM_THIS, code, __FILE__, \
|
||||
__FUNCTION__, __LINE__, __VA_ARGS__)
|
||||
|
||||
|
||||
static int xenapiDefaultConsoleType(const char *ostype)
|
||||
{
|
||||
if (STREQ(ostype, "hvm"))
|
||||
return VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL;
|
||||
else
|
||||
return VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_XEN;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* getCapsObject
|
||||
*
|
||||
@ -78,6 +88,8 @@ getCapsObject (void)
|
||||
if (!domain2)
|
||||
goto error_cleanup;
|
||||
|
||||
caps->defaultConsoleTargetType = xenapiDefaultConsoleType;
|
||||
|
||||
return caps;
|
||||
|
||||
error_cleanup:
|
||||
|
@ -55,6 +55,11 @@ static virCapsGuestMachinePtr *testQemuAllocNewerMachines(int *nmachines)
|
||||
return machines;
|
||||
}
|
||||
|
||||
static int testQemuDefaultConsoleType(const char *ostype ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL;
|
||||
}
|
||||
|
||||
virCapsPtr testQemuCapsInit(void) {
|
||||
virCapsPtr caps;
|
||||
virCapsGuestPtr guest;
|
||||
@ -96,6 +101,8 @@ virCapsPtr testQemuCapsInit(void) {
|
||||
0, 0)) == NULL)
|
||||
return NULL;
|
||||
|
||||
caps->defaultConsoleTargetType = testQemuDefaultConsoleType;
|
||||
|
||||
if ((caps->host.cpu = virCPUDefCopy(&host_cpu)) == NULL ||
|
||||
(machines = testQemuAllocMachines(&nmachines)) == NULL)
|
||||
goto cleanup;
|
||||
|
@ -4,6 +4,15 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "testutilsxen.h"
|
||||
#include "domain_conf.h"
|
||||
|
||||
static int testXenDefaultConsoleType(const char *ostype ATTRIBUTE_UNUSED)
|
||||
{
|
||||
if (STREQ(ostype, "hvm"))
|
||||
return VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL;
|
||||
else
|
||||
return VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_XEN;
|
||||
}
|
||||
|
||||
virCapsPtr testXenCapsInit(void) {
|
||||
struct utsname utsname;
|
||||
@ -23,6 +32,8 @@ virCapsPtr testXenCapsInit(void) {
|
||||
0, 0)) == NULL)
|
||||
return NULL;
|
||||
|
||||
caps->defaultConsoleTargetType = testXenDefaultConsoleType;
|
||||
|
||||
nmachines = ARRAY_CARDINALITY(x86_machines);
|
||||
if ((machines = virCapabilitiesAllocMachines(x86_machines, nmachines)) == NULL)
|
||||
goto cleanup;
|
||||
|
@ -14,6 +14,11 @@
|
||||
static virCapsPtr caps;
|
||||
static virVMXContext ctx;
|
||||
|
||||
static int testDefaultConsoleType(const char *ostype ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL;
|
||||
}
|
||||
|
||||
static void
|
||||
testCapsInit(void)
|
||||
{
|
||||
@ -25,6 +30,8 @@ testCapsInit(void)
|
||||
return;
|
||||
}
|
||||
|
||||
caps->defaultConsoleTargetType = testDefaultConsoleType;
|
||||
|
||||
virCapabilitiesSetMacPrefix(caps, (unsigned char[]){ 0x00, 0x0c, 0x29 });
|
||||
virCapabilitiesAddHostMigrateTransport(caps, "esx");
|
||||
|
||||
|
@ -14,6 +14,11 @@
|
||||
static virCapsPtr caps;
|
||||
static virVMXContext ctx;
|
||||
|
||||
static int testDefaultConsoleType(const char *ostype ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL;
|
||||
}
|
||||
|
||||
static void
|
||||
testCapsInit(void)
|
||||
{
|
||||
@ -25,6 +30,8 @@ testCapsInit(void)
|
||||
return;
|
||||
}
|
||||
|
||||
caps->defaultConsoleTargetType = testDefaultConsoleType;
|
||||
|
||||
virCapabilitiesSetMacPrefix(caps, (unsigned char[]){ 0x00, 0x0c, 0x29 });
|
||||
virCapabilitiesAddHostMigrateTransport(caps, "esx");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user