Blame SOURCES/virt-manager-domcapabilities-add-caching-of-CPU-security-features.patch

3d61c0
From 260fe211977de7bcd6c5b9163b9562eb2f39f266 Mon Sep 17 00:00:00 2001
3d61c0
Message-Id: <260fe211977de7bcd6c5b9163b9562eb2f39f266@dist-git>
3d61c0
From: Pavel Hrdina <phrdina@redhat.com>
3d61c0
Date: Wed, 3 Apr 2019 15:17:08 +0200
3d61c0
Subject: [PATCH] domcapabilities: add caching of CPU security features
3d61c0
MIME-Version: 1.0
3d61c0
Content-Type: text/plain; charset=UTF-8
3d61c0
Content-Transfer-Encoding: 8bit
3d61c0
3d61c0
We will call this function multiple times so it makes sense to cache the
3d61c0
result so we don't have to call libvirt APIs every time we will check
3d61c0
what security features are available on the host.
3d61c0
3d61c0
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
3d61c0
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
3d61c0
(cherry picked from commit 00f8dea370ae0874dc655d3718978a6a8e397a34)
3d61c0
3d61c0
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1582667
3d61c0
3d61c0
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
3d61c0
Reviewed-by: Cole Robinson <crobinso@redhat.com>
3d61c0
---
3d61c0
 virtinst/domcapabilities.py | 11 ++++++++---
3d61c0
 1 file changed, 8 insertions(+), 3 deletions(-)
3d61c0
3d61c0
diff --git a/virtinst/domcapabilities.py b/virtinst/domcapabilities.py
3d61c0
index beab7374..ba774532 100644
3d61c0
--- a/virtinst/domcapabilities.py
3d61c0
+++ b/virtinst/domcapabilities.py
3d61c0
@@ -238,6 +238,8 @@ class DomainCapabilities(XMLBuilder):
3d61c0
 
3d61c0
         return CPU(self.conn, expandedXML)
3d61c0
 
3d61c0
+    _features = None
3d61c0
+
3d61c0
     def get_cpu_security_features(self):
3d61c0
         sec_features = [
3d61c0
                 'spec-ctrl',
3d61c0
@@ -245,7 +247,10 @@ class DomainCapabilities(XMLBuilder):
3d61c0
                 'ibpb',
3d61c0
                 'virt-ssbd']
3d61c0
 
3d61c0
-        features = []
3d61c0
+        if self._features:
3d61c0
+            return self._features
3d61c0
+
3d61c0
+        self._features = []
3d61c0
 
3d61c0
         for m in self.cpu.modes:
3d61c0
             if m.name != "host-model" or not m.supported:
3d61c0
@@ -259,9 +264,9 @@ class DomainCapabilities(XMLBuilder):
3d61c0
 
3d61c0
             for feature in cpu.features:
3d61c0
                 if feature.name in sec_features:
3d61c0
-                    features.append(feature.name)
3d61c0
+                    self._features.append(feature.name)
3d61c0
 
3d61c0
-        return features
3d61c0
+        return self._features
3d61c0
 
3d61c0
 
3d61c0
     _XML_ROOT_NAME = "domainCapabilities"
3d61c0
-- 
3d61c0
2.20.1
3d61c0