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

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


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

We couldn't use host-passthrough mode for virtual cpu
from virt-manager so far.
This patch enables virt-manager to configure host-passthrough mode.

Signed-off-by: Ken ICHIKAWA <ichikawa.ken at jp.fujitsu.com>
Signed-off-by: Hu Tao <hutao at cn.fujitsu.com>
---
 src/virtManager/details.py | 23 ++++++++++++++++++++++-
 src/virtManager/domain.py  | 13 ++++++++++---
 src/vmm-details.ui         | 21 +++++++++++++++++++--
 3 files changed, 51 insertions(+), 6 deletions(-)

diff --git a/src/virtManager/details.py b/src/virtManager/details.py
index 2e3c8a3..02b4d62 100644
--- a/src/virtManager/details.py
+++ b/src/virtManager/details.py
@@ -422,6 +422,7 @@ class vmmDetails(vmmGObjectUI):
             "on_cpu_threads_changed": (self.enable_apply, EDIT_TOPOLOGY),
             "on_cpu_copy_host_clicked": self.config_cpu_copy_host,
             "on_cpu_topology_enable_toggled": self.config_cpu_topology_enable,
+            "on_host_passthrough_enable_toggled": self.config_host_passthrough_enable,
 
             "on_config_memory_changed": self.config_memory_changed,
             "on_config_maxmem_changed": self.config_maxmem_changed,
@@ -1833,6 +1834,13 @@ class vmmDetails(vmmGObjectUI):
         self.widget("cpu-topology-table").set_sensitive(do_enable)
         self.enable_apply(EDIT_TOPOLOGY)
 
+    def config_host_passthrough_enable(self, src):
+        do_enable = not src.get_active()
+        self.widget("cpu-copy-host").set_sensitive(do_enable)
+        self.widget("cpu-model").set_sensitive(do_enable)
+        self.widget("cpu-features").set_sensitive(do_enable)
+        self.enable_apply(EDIT_CPU)
+
     # Boot device / Autostart
     def config_bootdev_selected(self, ignore):
         boot_row = self.get_boot_selection()
@@ -2118,10 +2126,14 @@ class vmmDetails(vmmGObjectUI):
             add_hotplug(self.config_vcpu_pin_cpuset, cpuset)
 
         if self.editted(EDIT_CPU):
+            host_passthrough = self.widget("host-passthrough-enable").get_active()
+            mode = "custom"
+            if host_passthrough:
+                mode = "host-passthrough"
             model, vendor = self.get_config_cpu_model()
             features = self.get_config_cpu_features()
             add_define(self.vm.define_cpu,
-                       model, vendor, self._cpu_copy_host, features)
+                       mode, model, vendor, self._cpu_copy_host, features)
 
         if self.editted(EDIT_TOPOLOGY):
             do_top = self.widget("cpu-topology-enable").get_active()
@@ -2845,6 +2857,15 @@ class vmmDetails(vmmGObjectUI):
         self.widget("cpu-cores").set_value(cores)
         self.widget("cpu-threads").set_value(threads)
 
+        host_passthrough = False
+        if cpu.mode == "host-passthrough":
+            host_passthrough = True
+
+        self.widget("host-passthrough-enable").set_active(host_passthrough)
+        self.widget("cpu-copy-host").set_sensitive(not host_passthrough)
+        self.widget("cpu-model").set_sensitive(not host_passthrough)
+        self.widget("cpu-features").set_sensitive(not host_passthrough)
+
         def get_feature_policy(name):
             for f in cpu.features:
                 if f.name == name:
diff --git a/src/virtManager/domain.py b/src/virtManager/domain.py
index 385fdff..99b98f2 100644
--- a/src/virtManager/domain.py
+++ b/src/virtManager/domain.py
@@ -449,7 +449,8 @@ class vmmDomain(vmmLibvirtObject):
             cpu.cores = cores
             cpu.threads = threads
         return self._redefine_guest(change)
-    def define_cpu(self, model, vendor, from_host, featurelist):
+
+    def define_cpu(self, mode, model, vendor, from_host, featurelist):
         def change(guest):
             if from_host:
                 guest.cpu.copy_host_cpu()
@@ -458,8 +459,14 @@ class vmmDomain(vmmLibvirtObject):
                 # caps value
                 guest.cpu.vendor = vendor
 
-            guest.cpu.model = model or None
-            if guest.cpu.model is None:
+            guest.cpu.mode = mode
+            if mode == "custom":
+                guest.cpu.model = model or None
+            else:
+                guest.cpu.model = None
+
+            if guest.cpu.model == None:
+                guest.cpu.vendor = None
                 for f in guest.cpu.features:
                     guest.cpu.remove_feature(f)
                 return
diff --git a/src/vmm-details.ui b/src/vmm-details.ui
index f3004af..ed841ad 100644
--- a/src/vmm-details.ui
+++ b/src/vmm-details.ui
@@ -2419,6 +2419,23 @@ I/O:</property>
                                             <property name="visible">True</property>
                                             <property name="can_focus">False</property>
                                             <property name="spacing">6</property>
+					    <child>
+                                              <object class="GtkCheckButton" id="host-passthrough-enable">
+                                                <property name="label" translatable="yes">Use host-passthrough mode</property>
+                                                <property name="visible">True</property>
+                                                <property name="can_focus">True</property>
+                                                <property name="receives_default">False</property>
+                                                <property name="use_action_appearance">False</property>
+                                                <property name="active">True</property>
+                                                <property name="draw_indicator">True</property>
+                                                <signal name="toggled" handler="on_host_passthrough_enable_toggled" swapped="no"/>
+                                              </object>
+                                              <packing>
+                                                <property name="expand">True</property>
+                                                <property name="fill">True</property>
+                                                <property name="position">0</property>
+                                              </packing>
+                                            </child>
                                             <child>
                                               <object class="GtkTable" id="table15">
                                                 <property name="visible">True</property>
@@ -2522,7 +2539,7 @@ I/O:</property>
                                               <packing>
                                                 <property name="expand">True</property>
                                                 <property name="fill">True</property>
-                                                <property name="position">0</property>
+                                                <property name="position">1</property>
                                               </packing>
                                             </child>
                                             <child>
@@ -2594,7 +2611,7 @@ I/O:</property>
                                               <packing>
                                                 <property name="expand">True</property>
                                                 <property name="fill">True</property>
-                                                <property name="position">1</property>
+                                                <property name="position">2</property>
                                               </packing>
                                             </child>
                                           </object>
-- 
1.8.1.4




More information about the virt-tools-list mailing list