Blame SOURCES/virt-manager-domain-cpu-Add-set_defaults.patch

3d61c0
From d7fed0afad5f17449d1a9efb7e7fd35a4941cfaf Mon Sep 17 00:00:00 2001
3d61c0
Message-Id: <d7fed0afad5f17449d1a9efb7e7fd35a4941cfaf@dist-git>
3d61c0
From: Pavel Hrdina <phrdina@redhat.com>
3d61c0
Date: Sun, 2 Sep 2018 11:38:12 -0400
3d61c0
Subject: [PATCH] domain: cpu: Add set_defaults
3d61c0
3d61c0
From: Cole Robinson <crobinso@redhat.com>
3d61c0
3d61c0
(cherry picked from commit 4e7652b5484e8318cf360f0ae197c3e63975e602)
3d61c0
3d61c0
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1525337
3d61c0
3d61c0
Conflicts:
3d61c0
    - get_xml_config is renamed to get_xml in upstream
3d61c0
3d61c0
    - guest._os_object is renamed to guest.osinfo in upstream
3d61c0
3d61c0
Reviewed-by: Cole Robinson <crobinso@redhat.com>
3d61c0
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
3d61c0
---
3d61c0
 virtinst/cpu.py   | 58 +++++++++++++++++++++++++++++++++++++++++++++++
3d61c0
 virtinst/guest.py | 52 +-----------------------------------------
3d61c0
 2 files changed, 59 insertions(+), 51 deletions(-)
3d61c0
3d61c0
diff --git a/virtinst/cpu.py b/virtinst/cpu.py
3d61c0
index 70ea5647..1b8f4a96 100644
3d61c0
--- a/virtinst/cpu.py
3d61c0
+++ b/virtinst/cpu.py
3d61c0
@@ -17,6 +17,9 @@
3d61c0
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
3d61c0
 # MA 02110-1301 USA.
3d61c0
 
3d61c0
+import logging
3d61c0
+
3d61c0
+from .domcapabilities import DomainCapabilities
3d61c0
 from .xmlbuilder import XMLBuilder, XMLProperty, XMLChildProperty
3d61c0
 
3d61c0
 
3d61c0
@@ -228,3 +231,58 @@ class CPU(XMLBuilder):
3d61c0
     sockets = XMLProperty("./topology/@sockets", is_int=True)
3d61c0
     cores = XMLProperty("./topology/@cores", is_int=True)
3d61c0
     threads = XMLProperty("./topology/@threads", is_int=True)
3d61c0
+
3d61c0
+
3d61c0
+    ##################
3d61c0
+    # Default config #
3d61c0
+    ##################
3d61c0
+
3d61c0
+    def _set_cpu_x86_kvm_default(self, guest):
3d61c0
+        if guest.os.arch != self.conn.caps.host.cpu.arch:
3d61c0
+            return
3d61c0
+
3d61c0
+        self.set_special_mode(guest.x86_cpu_default)
3d61c0
+        if guest.x86_cpu_default != self.SPECIAL_MODE_HOST_MODEL_ONLY:
3d61c0
+            return
3d61c0
+        if not self.model:
3d61c0
+            return
3d61c0
+
3d61c0
+        # It's possible that the value HOST_MODEL_ONLY gets from
3d61c0
+        # <capabilities> is not actually supported by qemu/kvm
3d61c0
+        # combo which will be reported in <domainCapabilities>
3d61c0
+        domcaps = DomainCapabilities.build_from_guest(guest)
3d61c0
+        domcaps_mode = domcaps.cpu.get_mode("custom")
3d61c0
+        if not domcaps_mode:
3d61c0
+            return
3d61c0
+
3d61c0
+        cpu_model = domcaps_mode.get_model(self.model)
3d61c0
+        if cpu_model and cpu_model.usable:
3d61c0
+            return
3d61c0
+
3d61c0
+        logging.debug("Host capabilities CPU '%s' is not supported "
3d61c0
+            "according to domain capabilities. Unsetting CPU model",
3d61c0
+            self.model)
3d61c0
+        self.model = None
3d61c0
+
3d61c0
+    def set_defaults(self, guest):
3d61c0
+        self.set_topology_defaults(guest.vcpus)
3d61c0
+
3d61c0
+        if not self.conn.is_test() and not self.conn.is_qemu():
3d61c0
+            return
3d61c0
+        if (self.get_xml_config().strip() or
3d61c0
+            self.special_mode_was_set):
3d61c0
+            # User already configured CPU
3d61c0
+            return
3d61c0
+
3d61c0
+        if guest.os.is_arm_machvirt() and guest.type == "kvm":
3d61c0
+            self.mode = self.SPECIAL_MODE_HOST_PASSTHROUGH
3d61c0
+
3d61c0
+        elif guest.os.is_arm64() and guest.os.is_arm_machvirt():
3d61c0
+            # -M virt defaults to a 32bit CPU, even if using aarch64
3d61c0
+            self.model = "cortex-a57"
3d61c0
+
3d61c0
+        elif guest.os.is_x86() and guest.type == "kvm":
3d61c0
+            self._set_cpu_x86_kvm_default(guest)
3d61c0
+
3d61c0
+            if guest._os_object.broken_x2apic():
3d61c0
+                self.add_feature("x2apic", policy="disable")
3d61c0
diff --git a/virtinst/guest.py b/virtinst/guest.py
3d61c0
index bede9e86..6bf1b59a 100644
3d61c0
--- a/virtinst/guest.py
3d61c0
+++ b/virtinst/guest.py
3d61c0
@@ -785,7 +785,7 @@ class Guest(XMLBuilder):
3d61c0
 
3d61c0
         self._set_clock_defaults()
3d61c0
         self._set_emulator_defaults()
3d61c0
-        self._set_cpu_defaults()
3d61c0
+        self.cpu.set_defaults(self)
3d61c0
         self._set_feature_defaults()
3d61c0
         self._set_pm_defaults()
3d61c0
 
3d61c0
@@ -880,56 +880,6 @@ class Guest(XMLBuilder):
3d61c0
             else:
3d61c0
                 self.emulator = "/usr/lib/xen/bin/qemu-dm"
3d61c0
 
3d61c0
-    def _set_cpu_x86_kvm_default(self):
3d61c0
-        if self.os.arch != self.conn.caps.host.cpu.arch:
3d61c0
-            return
3d61c0
-
3d61c0
-        self.cpu.set_special_mode(self.x86_cpu_default)
3d61c0
-        if self.x86_cpu_default != self.cpu.SPECIAL_MODE_HOST_MODEL_ONLY:
3d61c0
-            return
3d61c0
-        if not self.cpu.model:
3d61c0
-            return
3d61c0
-
3d61c0
-        # It's possible that the value HOST_MODEL_ONLY gets from
3d61c0
-        # <capabilities> is not actually supported by qemu/kvm
3d61c0
-        # combo which will be reported in <domainCapabilities>
3d61c0
-        domcaps = DomainCapabilities.build_from_guest(self)
3d61c0
-        domcaps_mode = domcaps.cpu.get_mode("custom")
3d61c0
-        if not domcaps_mode:
3d61c0
-            return
3d61c0
-
3d61c0
-        cpu_model = domcaps_mode.get_model(self.cpu.model)
3d61c0
-        if cpu_model and cpu_model.usable:
3d61c0
-            return
3d61c0
-
3d61c0
-        logging.debug("Host capabilities CPU '%s' is not supported "
3d61c0
-            "according to domain capabilities. Unsetting CPU model",
3d61c0
-            self.cpu.model)
3d61c0
-        self.cpu.model = None
3d61c0
-
3d61c0
-    def _set_cpu_defaults(self):
3d61c0
-        self.cpu.set_topology_defaults(self.vcpus)
3d61c0
-
3d61c0
-        if not self.conn.is_test() and not self.conn.is_qemu():
3d61c0
-            return
3d61c0
-        if (self.cpu.get_xml_config().strip() or
3d61c0
-            self.cpu.special_mode_was_set):
3d61c0
-            # User already configured CPU
3d61c0
-            return
3d61c0
-
3d61c0
-        if self.os.is_arm_machvirt() and self.type == "kvm":
3d61c0
-            self.cpu.mode = self.cpu.SPECIAL_MODE_HOST_PASSTHROUGH
3d61c0
-
3d61c0
-        elif self.os.is_arm64() and self.os.is_arm_machvirt():
3d61c0
-            # -M virt defaults to a 32bit CPU, even if using aarch64
3d61c0
-            self.cpu.model = "cortex-a57"
3d61c0
-
3d61c0
-        elif self.os.is_x86() and self.type == "kvm":
3d61c0
-            self._set_cpu_x86_kvm_default()
3d61c0
-
3d61c0
-            if self._os_object.broken_x2apic():
3d61c0
-                self.cpu.add_feature("x2apic", policy="disable")
3d61c0
-
3d61c0
     def _hyperv_supported(self):
3d61c0
         if (self.os.loader_type == "pflash" and
3d61c0
             self.os_variant in ("win2k8r2", "win7")):
3d61c0
-- 
3d61c0
2.20.1
3d61c0