Add support for cpu mode attribute and cpu host-passthrough

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

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

Signed-off-by: Ken ICHIKAWA <ichikawa.ken@jp.fujitsu.com>
Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>

(crobinso: Add Hu Tao to AUTHORS)
This commit is contained in:
Ken ICHIKAWA 2013-04-11 13:45:45 +08:00 committed by Cole Robinson
parent a0e07c0f92
commit 2a72d50477
2 changed files with 23 additions and 1 deletions

View File

@ -160,6 +160,7 @@ Further patches have been submitted by:
Tom Lanyon <tom@oneshoeco.com> Tom Lanyon <tom@oneshoeco.com>
Eric Blake <eblake@redhat.com> Eric Blake <eblake@redhat.com>
Gene Czarcinski <gene@czarc.net> Gene Czarcinski <gene@czarc.net>
Hu Tao <hutao@cn.fujitsu.com>
<...send a patch & get your name here...> <...send a patch & get your name here...>

View File

@ -83,6 +83,7 @@ class CPU(XMLBuilderDomain.XMLBuilderDomain):
self._model = None self._model = None
self._match = None self._match = None
self._vendor = None self._vendor = None
self._mode = None
self._features = [] self._features = []
self._sockets = None self._sockets = None
@ -132,6 +133,8 @@ class CPU(XMLBuilderDomain.XMLBuilderDomain):
def _get_model(self): def _get_model(self):
return self._model return self._model
def _set_model(self, val): def _set_model(self, val):
if val:
self.mode = "custom"
if val and not self.match: if val and not self.match:
self.match = "exact" self.match = "exact"
self._model = val self._model = val
@ -152,6 +155,13 @@ class CPU(XMLBuilderDomain.XMLBuilderDomain):
vendor = _xml_property(_get_vendor, _set_vendor, vendor = _xml_property(_get_vendor, _set_vendor,
xpath="./cpu/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 # Topology properties
def _get_sockets(self): def _get_sockets(self):
return self._sockets return self._sockets
@ -186,6 +196,7 @@ class CPU(XMLBuilderDomain.XMLBuilderDomain):
if not cpu.model: if not cpu.model:
raise ValueError(_("No host CPU reported in capabilities")) raise ValueError(_("No host CPU reported in capabilities"))
self.mode = "custom"
self.match = "exact" self.match = "exact"
self.model = cpu.model self.model = cpu.model
self.vendor = cpu.vendor self.vendor = cpu.vendor
@ -263,16 +274,26 @@ class CPU(XMLBuilderDomain.XMLBuilderDomain):
def _get_xml_config(self): def _get_xml_config(self):
top_xml = self._get_topology_xml() top_xml = self._get_topology_xml()
feature_xml = self._get_feature_xml() feature_xml = self._get_feature_xml()
mode_xml = ""
match_xml = "" match_xml = ""
if self.match: if self.match:
match_xml = " match='%s'" % self.match match_xml = " match='%s'" % self.match
xml = "" xml = ""
if self.model == "host-passthrough":
self.mode = "host-passthrough"
mode_xml = " mode='%s'" % self.mode
xml += " <cpu%s/>" % mode_xml
return xml
else:
self.mode = "custom"
mode_xml = " mode='%s'" % self.mode
if not (self.model or top_xml or feature_xml): if not (self.model or top_xml or feature_xml):
return "" return ""
# Simple topology XML mode # Simple topology XML mode
xml += " <cpu%s>\n" % match_xml xml += " <cpu%s%s>\n" % (mode_xml, match_xml)
if self.model: if self.model:
xml += " <model>%s</model>\n" % self.model xml += " <model>%s</model>\n" % self.model
if self.vendor: if self.vendor: