From 703dc23dd709020a28aa151db9e5c7937d1d1900 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Thu, 14 May 2009 17:00:32 +0200
Subject: [PATCH] Move HVM's device_model to a hypervisor parameter

This moves yet another hardcoded value to a hypervisor parameter. I
removed the 64/32 difference as it doesn't seem valid to me - it's more
of a local site config rather than arch config.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
(cherry picked from commit 09ea8710e47288e73746698c50f328e400c056c9)
---
 lib/constants.py         |  3 +++
 lib/hypervisor/hv_xen.py | 23 ++++++++++++++++-------
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/lib/constants.py b/lib/constants.py
index 46b519171..e5dafb174 100644
--- a/lib/constants.py
+++ b/lib/constants.py
@@ -308,6 +308,7 @@ HV_INITRD_PATH = "initrd_path"
 HV_ROOT_PATH = "root_path"
 HV_SERIAL_CONSOLE = "serial_console"
 HV_USB_MOUSE = "usb_mouse"
+HV_DEVICE_MODEL = "device_model"
 
 HVS_PARAMETER_TYPES = {
   HV_BOOT_ORDER: VTYPE_STRING,
@@ -326,6 +327,7 @@ HVS_PARAMETER_TYPES = {
   HV_ROOT_PATH: VTYPE_STRING,
   HV_SERIAL_CONSOLE: VTYPE_BOOL,
   HV_USB_MOUSE: VTYPE_STRING,
+  HV_DEVICE_MODEL: VTYPE_STRING,
   }
 
 HVS_PARAMETERS = frozenset(HVS_PARAMETER_TYPES.keys())
@@ -511,6 +513,7 @@ HVC_DEFAULTS = {
     HV_ACPI: True,
     HV_PAE: True,
     HV_KERNEL_PATH: "/usr/lib/xen/boot/hvmloader",
+    HV_DEVICE_MODEL: "/usr/lib/xen/bin/qemu-dm",
     },
   HT_KVM: {
     HV_KERNEL_PATH: "/boot/vmlinuz-2.6-kvmU",
diff --git a/lib/hypervisor/hv_xen.py b/lib/hypervisor/hv_xen.py
index dc171998b..8a29d6b70 100644
--- a/lib/hypervisor/hv_xen.py
+++ b/lib/hypervisor/hv_xen.py
@@ -519,6 +519,7 @@ class XenHvmHypervisor(XenHypervisor):
     constants.HV_PAE,
     constants.HV_VNC_BIND_ADDRESS,
     constants.HV_KERNEL_PATH,
+    constants.HV_DEVICE_MODEL,
     ]
 
   @classmethod
@@ -566,6 +567,13 @@ class XenHvmHypervisor(XenHypervisor):
     if not os.path.isabs(hvparams[constants.HV_KERNEL_PATH]):
       raise errors.HypervisorError("The kernel path must be an absolute path")
 
+    if not hvparams[constants.HV_DEVICE_MODEL]:
+      raise errors.HypervisorError("Need a device model for the instance")
+
+    if not os.path.isabs(hvparams[constants.HV_DEVICE_MODEL]):
+      raise errors.HypervisorError("The device model must be an absolute path")
+
+
   def ValidateParameters(self, hvparams):
     """Check the given parameters for validity.
 
@@ -592,6 +600,11 @@ class XenHvmHypervisor(XenHypervisor):
       raise errors.HypervisorError("Instance kernel '%s' not found or"
                                    " not a file" % kernel_path)
 
+    device_model = hvparams[constants.HV_DEVICE_MODEL]
+    if not os.path.isfile(device_model):
+      raise errors.HypervisorError("Device model '%s' not found or"
+                                   " not a file" % device_model)
+
   @classmethod
   def _WriteConfigFile(cls, instance, block_devices):
     """Create a Xen 3.1 HVM config file.
@@ -610,20 +623,16 @@ class XenHvmHypervisor(XenHypervisor):
     config.write("memory = %d\n" % instance.beparams[constants.BE_MEMORY])
     config.write("vcpus = %d\n" % instance.beparams[constants.BE_VCPUS])
     config.write("name = '%s'\n" % instance.name)
-    if instance.hvparams[constants.HV_PAE]:
+    if hvp[constants.HV_PAE]:
       config.write("pae = 1\n")
     else:
       config.write("pae = 0\n")
-    if instance.hvparams[constants.HV_ACPI]:
+    if hvp[constants.HV_ACPI]:
       config.write("acpi = 1\n")
     else:
       config.write("acpi = 0\n")
     config.write("apic = 1\n")
-    arch = os.uname()[4]
-    if '64' in arch:
-      config.write("device_model = '/usr/lib64/xen/bin/qemu-dm'\n")
-    else:
-      config.write("device_model = '/usr/lib/xen/bin/qemu-dm'\n")
+    config.write("device_model = '%s'\n" % hvp[constants.HV_DEVICE_MODEL])
     config.write("boot = '%s'\n" % hvp[constants.HV_BOOT_ORDER])
     config.write("sdl = 0\n")
     config.write("usb = 1\n")
-- 
GitLab