From 83eb392c410394be09c234d74bba44eb9ade9331 Mon Sep 17 00:00:00 2001 Message-Id: <83eb392c410394be09c234d74bba44eb9ade9331@dist-git> From: Pavel Hrdina Date: Sat, 13 Oct 2018 17:47:31 -0400 Subject: [PATCH] cpu: Have host-copy use domcaps if qemu is new enough (bz 1637767) From: Cole Robinson capabilities is known problematic. Use domcaps if libvirt+qemu reports working host-model https://bugzilla.redhat.com/show_bug.cgi?id=1637767 (cherry picked from commit b051b6c95d8adca7f7ec6a8d582e62d6427d28e3) Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1525337 Conflicts: - _XML_ROOT_NAME is renamed to XML_NAME in upstream Reviewed-by: Cole Robinson Signed-off-by: Pavel Hrdina --- .../virt-install-kvm-hostcopy-fallback.xml | 157 ++++++++++++++++++ .../virt-install-singleton-config-1.xml | 16 +- tests/clitest.py | 3 +- tests/xmlparse.py | 2 +- virtinst/cpu.py | 30 +++- virtinst/domcapabilities.py | 12 +- 6 files changed, 207 insertions(+), 13 deletions(-) create mode 100644 tests/cli-test-xml/compare/virt-install-kvm-hostcopy-fallback.xml diff --git a/tests/cli-test-xml/compare/virt-install-kvm-hostcopy-fallback.xml b/tests/cli-test-xml/compare/virt-install-kvm-hostcopy-fallback.xml new file mode 100644 index 00000000..7ca064e2 --- /dev/null +++ b/tests/cli-test-xml/compare/virt-install-kvm-hostcopy-fallback.xml @@ -0,0 +1,157 @@ + + foobar + 00000000-1111-2222-3333-444444444444 + 65536 + 65536 + 1 + + hvm + + + + + + + + + Opteron_G4 + AMD + + + + + + + + + + + + + + + + + + + + + + + + + + destroy + + + + + + /usr/bin/qemu-kvm + + + + + + + + + + + + + + + + + + + + + + + + + + + + + foobar + 00000000-1111-2222-3333-444444444444 + 65536 + 65536 + 1 + + hvm + + + + + + + + + Opteron_G4 + AMD + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + /usr/bin/qemu-kvm + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/cli-test-xml/compare/virt-install-singleton-config-1.xml b/tests/cli-test-xml/compare/virt-install-singleton-config-1.xml index fc22e0ac..40041451 100644 --- a/tests/cli-test-xml/compare/virt-install-singleton-config-1.xml +++ b/tests/cli-test-xml/compare/virt-install-singleton-config-1.xml @@ -23,7 +23,21 @@ - + + Broadwell + Intel + + + + + + + + + + + + diff --git a/tests/clitest.py b/tests/clitest.py index 23d4f109..eb608769 100644 --- a/tests/clitest.py +++ b/tests/clitest.py @@ -389,7 +389,7 @@ c = vinst.add_category("xml-comparsion", "--connect %(URI-KVM)s --noautoconsole c.add_compare(""" \ --memory 1024 \ --vcpus 4 --cpuset=1,3-5 \ ---cpu host \ +--cpu host-copy \ --description \"foobar & baz\" \ --boot uefi \ --security type=dynamic \ @@ -806,6 +806,7 @@ c.add_compare("--disk none --location nfs:example.com/fake --nonetworks", "locat c.add_compare("--disk %(EXISTIMG1)s --pxe --os-variant rhel6.4", "kvm-rhel6") # RHEL6 defaults c.add_compare("--disk %(EXISTIMG1)s --pxe --os-variant rhel7.0", "kvm-rhel7") # RHEL7 defaults c.add_compare("--connect " + utils.uri_kvm_nodomcaps + " --disk %(EXISTIMG1)s --pxe --os-variant rhel7.0", "kvm-cpu-default-fallback") # No domcaps, so mode=host-model isn't safe, so we fallback to host-model-only +c.add_compare("--connect " + utils.uri_kvm_nodomcaps + " --cpu host-copy --disk none --pxe", "kvm-hostcopy-fallback") # No domcaps so need to use capabilities for CPU host-copy c.add_compare("--disk %(EXISTIMG1)s --pxe --os-variant centos7.0", "kvm-centos7") # Centos 7 defaults c.add_compare("--os-variant win7 --cdrom %(EXISTIMG2)s --boot loader_type=pflash,loader=CODE.fd,nvram_template=VARS.fd --disk %(EXISTIMG1)s", "win7-uefi") # no HYPER-V with UEFI c.add_compare("--machine q35 --cdrom %(EXISTIMG2)s --disk %(EXISTIMG1)s", "q35-defaults") # proper q35 disk defaults diff --git a/tests/xmlparse.py b/tests/xmlparse.py index 35b237ea..e7d291f3 100644 --- a/tests/xmlparse.py +++ b/tests/xmlparse.py @@ -1362,7 +1362,7 @@ class XMLParseTest(unittest.TestCase): outfile = "tests/xmlparse-xml/%s-out.xml" % basename guest = virtinst.Guest(kvmconn, parsexml=open(infile).read()) - guest.cpu.copy_host_cpu() + guest.cpu.copy_host_cpu(guest) guest.cpu.clear() utils.diff_compare(guest.get_xml_config(), outfile) diff --git a/virtinst/cpu.py b/virtinst/cpu.py index 356df206..f109445c 100644 --- a/virtinst/cpu.py +++ b/virtinst/cpu.py @@ -118,7 +118,7 @@ class CPU(XMLBuilder): self.remove_feature(f) self.mode = val elif val == self.SPECIAL_MODE_HOST_COPY: - self.copy_host_cpu() + self.copy_host_cpu(guest) elif (val == self.SPECIAL_MODE_HV_DEFAULT or val == self.SPECIAL_MODE_CLEAR): self.clear() @@ -154,24 +154,36 @@ class CPU(XMLBuilder): self.add_child(obj) return obj - def copy_host_cpu(self): + def copy_host_cpu(self, guest): """ - Enact the equivalent of qemu -cpu host, pulling all info - from capabilities about the host CPU + Try to manually mimic host-model, copying all the info + preferably out of domcapabilities, but capabilities as fallback. """ - cpu = self.conn.caps.host.cpu - if not cpu.model: - raise ValueError(_("No host CPU reported in capabilities")) + domcaps = guest.lookup_domcaps() + if domcaps.supports_safe_host_model(): + logging.debug("Using domcaps for host-copy") + cpu = domcaps.cpu.get_mode("host-model") + model = cpu.models[0].model + fallback = cpu.models[0].fallback + else: + cpu = self.conn.caps.host.cpu + model = cpu.model + fallback = None + if not model: + raise ValueError(_("No host CPU reported in capabilities")) self.mode = "custom" self.match = "exact" - self.model = cpu.model + self.model = model + if fallback: + self.model_fallback = fallback self.vendor = cpu.vendor for feature in self.features: self.remove_feature(feature) for feature in cpu.features: - self.add_feature(feature.name) + policy = getattr(feature, "policy", "require") + self.add_feature(feature.name, policy) def vcpus_from_topology(self): """ diff --git a/virtinst/domcapabilities.py b/virtinst/domcapabilities.py index 7d7e2af7..ddc8b17c 100644 --- a/virtinst/domcapabilities.py +++ b/virtinst/domcapabilities.py @@ -80,19 +80,29 @@ class _CPUModel(XMLBuilder): _XML_ROOT_NAME = "model" model = XMLProperty(".") usable = XMLProperty("./@usable", is_yesno=True) + fallback = XMLProperty("./@fallback") + + +class _CPUFeature(XMLBuilder): + _XML_ROOT_NAME = "feature" + name = XMLProperty("./@name") + policy = XMLProperty("./@policy") class _CPUMode(XMLBuilder): _XML_ROOT_NAME = "mode" name = XMLProperty("./@name") supported = XMLProperty("./@supported", is_yesno=True) + vendor = XMLProperty("./vendor") + models = XMLChildProperty(_CPUModel) - def get_model(self, name): for model in self.models: if model.model == name: return model + features = XMLChildProperty(_CPUFeature) + class _CPU(XMLBuilder): _XML_ROOT_NAME = "cpu" -- 2.20.1