[virt-tools-list] [PATCH 1/2] Add support for cpu mode attribute and cpu host-passthrough

Hu Tao hutao at cn.fujitsu.com
Fri Mar 29 07:09:26 UTC 2013


From: Ken ICHIKAWA <ichikawa.ken at jp.fujitsu.com>

With this patch, users can use cpu host-passthrough like this:

  virt-install --cpu host-passthrough ...

Signed-off-by: Ken ICHIKAWA <ichikawa.ken at jp.fujitsu.com>
Signed-off-by: Hu Tao <hutao at cn.fujitsu.com>
---
 virtinst/CPU.py | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/virtinst/CPU.py b/virtinst/CPU.py
index 6ada5bc..33e8886 100644
--- a/virtinst/CPU.py
+++ b/virtinst/CPU.py
@@ -81,6 +81,7 @@ class CPU(XMLBuilderDomain.XMLBuilderDomain):
         self._model = None
         self._match = None
         self._vendor = None
+        self._mode = None
         self._features = []
 
         self._sockets = None
@@ -130,6 +131,8 @@ class CPU(XMLBuilderDomain.XMLBuilderDomain):
     def _get_model(self):
         return self._model
     def _set_model(self, val):
+        if val:
+            self.mode = "custom"
         if val and not self.match:
             self.match = "exact"
         self._model = val
@@ -150,6 +153,13 @@ class CPU(XMLBuilderDomain.XMLBuilderDomain):
     vendor = _xml_property(_get_vendor, _set_vendor,
                            xpath="./cpu/vendor")
 
+    def _get_mode(self):
+        return self._mode
+    def _set_mode(self, val):
+        self._mode = val
+    mode = _xml_property(_get_mode, _set_mode,
+                         xpath="./cpu/@mode")
+
     # Topology properties
     def _get_sockets(self):
         return self._sockets
@@ -184,6 +194,7 @@ class CPU(XMLBuilderDomain.XMLBuilderDomain):
         if not cpu.model:
             raise ValueError(_("No host CPU reported in capabilities"))
 
+        self.mode = "custom"
         self.match = "exact"
         self.model = cpu.model
         self.vendor = cpu.vendor
@@ -261,16 +272,23 @@ class CPU(XMLBuilderDomain.XMLBuilderDomain):
     def _get_xml_config(self):
         top_xml = self._get_topology_xml()
         feature_xml = self._get_feature_xml()
+        mode_xml = ""
         match_xml = ""
         if self.match:
             match_xml = " match='%s'" % self.match
         xml = ""
 
+        if self.model == "host-passthrough":
+            self.mode = "host-passthrough"
+            mode_xml = " mode='%s'" % self.mode
+            xml += "  <cpu%s/>" % mode_xml
+            return xml
+
         if not (self.model or top_xml or feature_xml):
             return ""
 
         # Simple topology XML mode
-        xml += "  <cpu%s>\n" % match_xml
+        xml += "  <cpu%s%s>\n" % (mode_xml, match_xml)
         if self.model:
             xml += "    <model>%s</model>\n" % self.model
         if self.vendor:
-- 
1.8.1.4




More information about the virt-tools-list mailing list