summaryrefslogtreecommitdiff
path: root/virtinst
diff options
context:
space:
mode:
authorCole Robinson <crobinso@redhat.com>2022-02-16 12:13:16 -0500
committerCole Robinson <crobinso@redhat.com>2022-02-16 14:03:44 -0500
commit2c477f330244e04614e174f50fbf37260c535705 (patch)
treed0d8cc0f2c5ede3e598fc0a1b55fef3263111c20 /virtinst
parentfc9a22afe0df6a9803d2510ab92aaf8ee3caf012 (diff)
downloadvirt-manager-2c477f330244e04614e174f50fbf37260c535705.tar.gz
domain: cpu: Use host-passthrough by default on x86
When libvirt and qemu are new enough, use host-passthrough for the CPU default. Nowadays this is recommended over host-model for most end user usage where migration isn't a critical feature. Signed-off-by: Cole Robinson <crobinso@redhat.com>
Diffstat (limited to 'virtinst')
-rw-r--r--virtinst/domain/cpu.py24
-rw-r--r--virtinst/domcapabilities.py22
2 files changed, 33 insertions, 13 deletions
diff --git a/virtinst/domain/cpu.py b/virtinst/domain/cpu.py
index 23ded402..d74c3ffc 100644
--- a/virtinst/domain/cpu.py
+++ b/virtinst/domain/cpu.py
@@ -260,14 +260,26 @@ class DomainCpu(XMLBuilder):
SPECIAL_MODE_HOST_COPY, SPECIAL_MODE_HOST_MODEL,
SPECIAL_MODE_HOST_PASSTHROUGH, SPECIAL_MODE_CLEAR,
SPECIAL_MODE_APP_DEFAULT]
+
+ def _get_app_default_mode(self, guest):
+ # Depending on if libvirt+qemu is new enough, we prefer
+ # host-passthrough, then host-model, and finally host-model-only
+ domcaps = guest.lookup_domcaps()
+
+ if domcaps.supports_safe_host_passthrough():
+ return self.SPECIAL_MODE_HOST_PASSTHROUGH
+
+ log.debug("Safe host-passthrough is not available")
+ if domcaps.supports_safe_host_model():
+ return self.SPECIAL_MODE_HOST_MODEL
+
+ log.debug("Safe host-model is not available")
+ return self.SPECIAL_MODE_HOST_MODEL_ONLY
+
def set_special_mode(self, guest, val):
if val == self.SPECIAL_MODE_APP_DEFAULT:
- # If libvirt is new enough to support reliable mode=host-model
- # then use it, otherwise use previous default HOST_MODEL_ONLY
- domcaps = guest.lookup_domcaps()
- val = self.SPECIAL_MODE_HOST_MODEL_ONLY
- if domcaps.supports_safe_host_model():
- val = self.SPECIAL_MODE_HOST_MODEL
+ val = self._get_app_default_mode(guest)
+ log.debug("Using default cpu mode=%s", val)
if (val == self.SPECIAL_MODE_HOST_MODEL or
val == self.SPECIAL_MODE_HOST_PASSTHROUGH):
diff --git a/virtinst/domcapabilities.py b/virtinst/domcapabilities.py
index 4a217556..99a9a518 100644
--- a/virtinst/domcapabilities.py
+++ b/virtinst/domcapabilities.py
@@ -129,10 +129,9 @@ class _CPUModel(XMLBuilder):
fallback = XMLProperty("./@fallback")
-class _CPUMode(XMLBuilder):
+class _CPUMode(_CapsBlock):
XML_NAME = "mode"
name = XMLProperty("./@name")
- supported = XMLProperty("./@supported", is_yesno=True)
models = XMLChildProperty(_CPUModel)
def get_model(self, name):
@@ -265,11 +264,20 @@ class DomainCapabilities(XMLBuilder):
host-model in fact predates this support, however it wasn't
general purpose safe prior to domcaps advertisement.
"""
- for m in self.cpu.modes:
- if (m.name == "host-model" and m.supported and
- m.models[0].fallback == "forbid"):
- return True
- return False
+ m = self.cpu.get_mode("host-model")
+ return (m and m.supported and
+ m.models[0].fallback == "forbid")
+
+ def supports_safe_host_passthrough(self):
+ """
+ Return True if host-passthrough is safe enough to use by default.
+ We limit this to domcaps new enough to report whether host-passthrough
+ is migratable or not, which also means libvirt is about new enough
+ to not taint the VM for using host-passthrough
+ """
+ m = self.cpu.get_mode("host-passthrough")
+ return (m and m.supported and
+ "on" in m.get_enum("hostPassthroughMigratable").get_values())
def get_cpu_models(self):
models = []