From 7cb421717399a7e88f83a156cbc75d4429742484 Mon Sep 17 00:00:00 2001
From: Nikita Staroverov <nsforth@gmail.com>
Date: Wed, 11 Jul 2012 13:24:30 -0700
Subject: [PATCH] Add support for -cpu option in KVM

This adds supports for the (non-validated) cpu parameter to KVM.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 lib/constants.py         |  3 +++
 lib/hypervisor/hv_kvm.py |  5 +++++
 lib/query.py             |  1 +
 man/gnt-instance.rst     | 13 +++++++++++++
 4 files changed, 22 insertions(+)

diff --git a/lib/constants.py b/lib/constants.py
index 540eb1fb2..af3df19d0 100644
--- a/lib/constants.py
+++ b/lib/constants.py
@@ -773,6 +773,7 @@ HV_MEM_PATH = "mem_path"
 HV_PASSTHROUGH = "pci_pass"
 HV_BLOCKDEV_PREFIX = "blockdev_prefix"
 HV_REBOOT_BEHAVIOR = "reboot_behavior"
+HV_CPU_TYPE = "cpu_type"
 
 HVS_PARAMETER_TYPES = {
   HV_BOOT_ORDER: VTYPE_STRING,
@@ -828,6 +829,7 @@ HVS_PARAMETER_TYPES = {
   HV_PASSTHROUGH: VTYPE_STRING,
   HV_BLOCKDEV_PREFIX: VTYPE_STRING,
   HV_REBOOT_BEHAVIOR: VTYPE_STRING,
+  HV_CPU_TYPE: VTYPE_STRING,
   }
 
 HVS_PARAMETERS = frozenset(HVS_PARAMETER_TYPES.keys())
@@ -1812,6 +1814,7 @@ HVC_DEFAULTS = {
     HV_MEM_PATH: "",
     HV_REBOOT_BEHAVIOR: INSTANCE_REBOOT_ALLOWED,
     HV_CPU_MASK: CPU_PINNING_ALL,
+    HV_CPU_TYPE: "",
     },
   HT_FAKE: {
     },
diff --git a/lib/hypervisor/hv_kvm.py b/lib/hypervisor/hv_kvm.py
index 087939e95..a3b4f92bc 100644
--- a/lib/hypervisor/hv_kvm.py
+++ b/lib/hypervisor/hv_kvm.py
@@ -493,6 +493,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
     constants.HV_REBOOT_BEHAVIOR:
       hv_base.ParamInSet(True, constants.REBOOT_BEHAVIORS),
     constants.HV_CPU_MASK: hv_base.OPT_MULTI_CPU_MASK_CHECK,
+    constants.HV_CPU_TYPE: hv_base.NO_CHECK
     }
 
   _MIGRATION_STATUS_RE = re.compile("Migration\s+status:\s+(\w+)",
@@ -1243,6 +1244,10 @@ class KVMHypervisor(hv_base.BaseHypervisor):
     if hvp[constants.HV_KVM_USE_CHROOT]:
       kvm_cmd.extend(["-chroot", self._InstanceChrootDir(instance.name)])
 
+    # Add qemu-KVM -cpu param
+    if hvp[constants.HV_CPU_TYPE]:
+      kvm_cmd.extend(["-cpu", hvp[constants.HV_CPU_TYPE]])
+
     # Save the current instance nics, but defer their expansion as parameters,
     # as we'll need to generate executable temp files for them.
     kvm_nics = instance.nics
diff --git a/lib/query.py b/lib/query.py
index 190b1542c..db2030eb8 100644
--- a/lib/query.py
+++ b/lib/query.py
@@ -1773,6 +1773,7 @@ def _GetInstanceParameterFields():
     constants.HV_PAE: "PAE",
     constants.HV_VNC_BIND_ADDRESS: "VNC_bind_address",
     constants.HV_PASSTHROUGH: "pci_pass",
+    constants.HV_CPU_TYPE: "cpu_type",
     }
 
   fields = [
diff --git a/man/gnt-instance.rst b/man/gnt-instance.rst
index b71643a15..dfb6ed439 100644
--- a/man/gnt-instance.rst
+++ b/man/gnt-instance.rst
@@ -385,6 +385,19 @@ spice\_use\_vdagent
 
     Enables or disables passing mouse events via SPICE vdagent.
 
+cpu\_type
+    Valid for the KVM hypervisor.
+
+    This parameter determines the emulated cpu for the instance. If this
+    parameter is empty (which is the default configuration), it will not
+    be passed to KVM.
+
+    Be aware of setting this parameter to ``"host"`` if you have nodes
+    with different CPUs from each other. Live migration may stop working
+    in this situation.
+
+    For more information please refer to the KVM manual.
+
 acpi
     Valid for the Xen HVM and KVM hypervisors.
 
-- 
GitLab