]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Fix default console type setting
authorDaniel P. Berrange <berrange@redhat.com>
Thu, 20 Oct 2011 13:56:20 +0000 (14:56 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Thu, 3 Nov 2011 12:01:48 +0000 (12:01 +0000)
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

19 files changed:
src/conf/capabilities.h
src/conf/domain_conf.c
src/conf/domain_conf.h
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/test/test_driver.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
tests/testutilsqemu.c
tests/testutilsxen.c
tests/vmx2xmltest.c
tests/xml2vmxtest.c

index e2fa1d654071b107c46af1baadad7eff5d981beb..dd4a8279b38c2ac5661a26f408576a715a8eb55c 100644 (file)
@@ -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 *);
index 84743c19524ad07a58b8981cb6d9159c7c59a244..238edfd8bf769f55b68d9f3b69c99c0ae07191eb 100644 (file)
@@ -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)
index c33e25321376326e7a51beb8451f3a78f711873f..5ebb4411965bc1fa60987a3893c15d1c561b5011 100644 (file)
@@ -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,
 };
index 92b56d8bb67a8413fa733608dc35fb9713f32d55..01b9cec6d2e879e0621d9d725d2ea3decb5fb8c3 100644 (file)
@@ -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;
index b9bce144c8687c9862f6f1043ab4d55d21bee278..e94e06b5eca551af35b3c3bf1e390870b2a6cead 100644 (file)
@@ -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;
 
index b2586eb42656e403362e8775ba44c6d33fafc05b..52e99ca1c214567410fd81d3bc2c5c185091ff53 100644 (file)
 
 #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
index c60a97fcb9168afa63402434c07411cb47baa6a9..c0517db0b1c01a2c65f2adfd7349f618f61cf472 100644 (file)
@@ -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:
index ff16aae072e86102e97b061fb9aa5a7b0fb03f02..5873624788c4d75bdf7e2c22fa6a13518417b61a 100644 (file)
@@ -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:
index b4ab55bf7cc53bd5b60bf25239bd9610126d5a2e..26a7f11a677fbde261d40287dde7f39185e7eb84 100644 (file)
@@ -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;
 
index 3dbce1837699aec3bb4155d6ac88a1c7a70fa6fe..e6ff696f69502c35cb16755edb224600b2e80d5b 100644 (file)
@@ -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)
index 4459a2a3edfe72bb5bd693a304616b8339736f3d..f2bdd747940acc47212688ba12d363cd5ac986e5 100644 (file)
 #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;
 
index 3601842778a833e5cd1cf964eacc8b55790a1f8c..3f3353f1d3b18307af664db3f323ad054d32a44c 100644 (file)
@@ -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:
index efefab40486fdd990a6a89725b91e93c0ce44907..3680ca0d4f61d11b47bc34c186f6bed65c070790 100644 (file)
@@ -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);
index 634b23b39e19942745976d86637141351b1b9386..870bc4f910a304616b3fbbfd1ce08a36dbb0e570 100644 (file)
@@ -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;
 
index 975fd4713533d512a654b75eafe5294010fefc7f..d4545891d72fc8a5309bfc92c8b23aaa49fe4dda 100644 (file)
         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:
index e3f3696ead65bf5ee40f40ed17c21749991cd7a2..857f5daed9ab998e85653e9a3944c538b72f1b50 100644 (file)
@@ -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;
index 94c423f87282621ef9f504be43bef330a605a382..7d5a872a8eafef49d7cfb0752e0cc6ce874e73a1 100644 (file)
@@ -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;
index 92dc7d424d64742e0c669cc1759d42fd38735f6f..5c0018a5c8fc5c8862e43a2fe89eda93fb0c849d 100644 (file)
 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");
 
index 77b1611b9b4fb39beaf56540c589be31e2d64760..5530b45a8fe7c6d6cd32a136b3f1c74cb9798824 100644 (file)
 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");