[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 7/7] Fix default console type setting



From: "Daniel P. Berrange" <berrange redhat com>

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
---
 src/conf/capabilities.h      |    2 +-
 src/conf/domain_conf.c       |   32 ++++++++++++++++++++++++--------
 src/conf/domain_conf.h       |    2 ++
 src/esx/esx_driver.c         |    6 ++++++
 src/libxl/libxl_conf.c       |   11 ++++++++++-
 src/lxc/lxc_conf.c           |    8 ++++++++
 src/openvz/openvz_conf.c     |    6 ++++++
 src/phyp/phyp_driver.c       |    9 +++++++++
 src/qemu/qemu_capabilities.c |    8 +++++++-
 src/uml/uml_conf.c           |    9 ++++++++-
 src/vbox/vbox_tmpl.c         |   10 ++++++++++
 src/vmware/vmware_conf.c     |    9 +++++++++
 src/xen/xen_hypervisor.c     |   10 +++++++++-
 src/xenapi/xenapi_driver.c   |   12 ++++++++++++
 14 files changed, 121 insertions(+), 13 deletions(-)

diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h
index e2fa1d6..dd4a827 100644
--- a/src/conf/capabilities.h
+++ b/src/conf/capabilities.h
@@ -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 *);
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index a4d91ed..c48a224 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -285,7 +285,9 @@ VIR_ENUM_IMPL(virDomainChrConsoleTarget,
               "serial",
               "xen",
               "uml",
-              "virtio")
+              "virtio",
+              "lxc",
+              "openvz")
 
 VIR_ENUM_IMPL(virDomainChrDevice, VIR_DOMAIN_CHR_DEVICE_TYPE_LAST,
               "parallel",
@@ -3473,7 +3475,9 @@ error:
 }
 
 static int
-virDomainChrDefaultTargetType(virCapsPtr caps, int devtype) {
+virDomainChrDefaultTargetType(virCapsPtr caps,
+                              virDomainDefPtr def,
+                              int devtype) {
 
     int target = -1;
 
@@ -3485,7 +3489,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:
@@ -3501,6 +3510,7 @@ virDomainChrDefaultTargetType(virCapsPtr caps, int devtype) {
 
 static int
 virDomainChrTargetTypeFromString(virCapsPtr caps,
+                                 virDomainDefPtr def,
                                  int devtype,
                                  const char *targetType)
 {
@@ -3508,7 +3518,7 @@ virDomainChrTargetTypeFromString(virCapsPtr caps,
     int target = 0;
 
     if (!targetType) {
-        target = virDomainChrDefaultTargetType(caps, devtype);
+        target = virDomainChrDefaultTargetType(caps, def, devtype);
         goto out;
     }
 
@@ -3535,6 +3545,7 @@ out:
 
 static int
 virDomainChrDefParseTargetXML(virCapsPtr caps,
+                              virDomainDefPtr vmdef,
                               virDomainChrDefPtr def,
                               xmlNodePtr cur)
 {
@@ -3545,8 +3556,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;
     }
 
@@ -3884,6 +3895,7 @@ virDomainChrDefNew(void) {
  */
 static virDomainChrDefPtr
 virDomainChrDefParseXML(virCapsPtr caps,
+                        virDomainDefPtr vmdef,
                         xmlNodePtr node,
                         unsigned int flags)
 {
@@ -3914,7 +3926,7 @@ virDomainChrDefParseXML(virCapsPtr caps,
     }
 
     /* Initialize this now, in case there is no actual 'target' element at all */
-    def->targetType = virDomainChrDefaultTargetType(caps, def->deviceType);
+    def->targetType = virDomainChrDefaultTargetType(caps, vmdef, def->deviceType);
 
     cur = node->children;
     remaining = virDomainChrSourceDefParseXML(&def->source, cur, flags);
@@ -3924,7 +3936,7 @@ virDomainChrDefParseXML(virCapsPtr caps,
         while (cur != NULL) {
             if (cur->type == XML_ELEMENT_NODE) {
                 if (xmlStrEqual(cur->name, BAD_CAST "target")) {
-                    if (virDomainChrDefParseTargetXML(caps, def, cur) < 0) {
+                    if (virDomainChrDefParseTargetXML(caps, vmdef, def, cur) < 0) {
                         goto error;
                     }
                 }
@@ -7020,6 +7032,7 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
 
     for (i = 0 ; i < n ; i++) {
         virDomainChrDefPtr chr = virDomainChrDefParseXML(caps,
+                                                         def,
                                                          nodes[i],
                                                          flags);
         if (!chr)
@@ -7046,6 +7059,7 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
 
     for (i = 0 ; i < n ; i++) {
         virDomainChrDefPtr chr = virDomainChrDefParseXML(caps,
+                                                         def,
                                                          nodes[i],
                                                          flags);
         if (!chr)
@@ -7074,6 +7088,7 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
 
     for (i = 0 ; i < n ; i++) {
         virDomainChrDefPtr chr = virDomainChrDefParseXML(caps,
+                                                         def,
                                                          nodes[i],
                                                          flags);
         if (!chr)
@@ -7138,6 +7153,7 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
 
     for (i = 0 ; i < n ; i++) {
         virDomainChrDefPtr chr = virDomainChrDefParseXML(caps,
+                                                         def,
                                                          nodes[i],
                                                          flags);
         if (!chr)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index a78b3ab..4ad860c 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -554,6 +554,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,
 };
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index 41086ef..33e8e7d 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -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;
diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index b9bce14..e94e06b 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -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;
 
diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c
index b2586eb..52e99ca 100644
--- a/src/lxc/lxc_conf.c
+++ b/src/lxc/lxc_conf.c
@@ -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
diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c
index c60a97f..c0517db 100644
--- a/src/openvz/openvz_conf.c
+++ b/src/openvz/openvz_conf.c
@@ -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:
diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
index ff16aae..5873624 100644
--- a/src/phyp/phyp_driver.c
+++ b/src/phyp/phyp_driver.c
@@ -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:
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 5f0356c..37990ec 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -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;
 
diff --git a/src/uml/uml_conf.c b/src/uml/uml_conf.c
index 4459a2a..f2bdd74 100644
--- a/src/uml/uml_conf.c
+++ b/src/uml/uml_conf.c
@@ -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;
 
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index bc19b63..73ef2de 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -823,6 +823,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;
@@ -856,6 +863,9 @@ static virCapsPtr vboxCapsInit(void) {
                                       0,
                                       NULL) == NULL)
         goto no_memory;
+
+    caps->defaultConsoleTargetType = vboxDefaultConsoleType;
+
     return caps;
 
 no_memory:
diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c
index efefab4..3680ca0 100644
--- a/src/vmware/vmware_conf.c
+++ b/src/vmware/vmware_conf.c
@@ -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);
diff --git a/src/xen/xen_hypervisor.c b/src/xen/xen_hypervisor.c
index 58ae6a3..3054267 100644
--- a/src/xen/xen_hypervisor.c
+++ b/src/xen/xen_hypervisor.c
@@ -2277,6 +2277,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,
@@ -2406,7 +2414,7 @@ xenHypervisorBuildCapabilities(virConnectPtr conn,
 
     }
 
-    caps->defaultConsoleTargetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_XEN;
+    caps->defaultConsoleTargetType = xenDefaultConsoleType;
 
     return caps;
 
diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c
index 3946455..8648aee 100644
--- a/src/xenapi/xenapi_driver.c
+++ b/src/xenapi/xenapi_driver.c
@@ -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:
-- 
1.7.6.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]