[virt-tools-list] [virt-manager PATCH 1/2] hostdev: add support for specify driver name when adding host device

Chen Hanxiao chen_han_xiao at 126.com
Fri Mar 3 10:39:06 UTC 2017


From: Chen Hanxiao <chenhanxiao at gmail.com>

When adding host device, we could specify driver names,
such as vfio, xen, etc.

Signed-off-by: Chen Hanxiao <chenhanxiao at gmail.com>
---
 ui/addhardware.ui          | 38 ++++++++++++++++++++++++++++++++++++--
 virtManager/addhardware.py | 17 +++++++++++++++++
 virtinst/devicehostdev.py  |  1 +
 3 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/ui/addhardware.ui b/ui/addhardware.ui
index 92e72c7..12c5aff 100644
--- a/ui/addhardware.ui
+++ b/ui/addhardware.ui
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.19.0 -->
+<!-- Generated with glade 3.20.0 -->
 <interface>
   <requires lib="gtk+" version="3.14"/>
   <object class="GtkAdjustment" id="adjustment1">
@@ -674,7 +674,7 @@
                           <object class="GtkTable" id="table3">
                             <property name="visible">True</property>
                             <property name="can_focus">False</property>
-                            <property name="n_rows">2</property>
+                            <property name="n_rows">3</property>
                             <property name="column_spacing">6</property>
                             <property name="row_spacing">6</property>
                             <child>
@@ -714,6 +714,40 @@
                                 <property name="bottom_attach">2</property>
                               </packing>
                             </child>
+                            <child>
+                              <object class="GtkBox">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <child>
+                                  <object class="GtkLabel" id="host-device-drvtname-label">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="label" translatable="yes">Driver Name:</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">0</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkComboBox" id="host-device-drvname">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">1</property>
+                                  </packing>
+                                </child>
+                              </object>
+                              <packing>
+                                <property name="top_attach">2</property>
+                                <property name="bottom_attach">3</property>
+                                <property name="y_options"/>
+                              </packing>
+                            </child>
                           </object>
                           <packing>
                             <property name="position">7</property>
diff --git a/virtManager/addhardware.py b/virtManager/addhardware.py
index 7645cf9..0115361 100644
--- a/virtManager/addhardware.py
+++ b/virtManager/addhardware.py
@@ -250,6 +250,8 @@ class vmmAddHardware(vmmGObjectUI):
         host_col.add_attribute(text, 'text', 0)
         host_dev_model.set_sort_column_id(0, Gtk.SortType.ASCENDING)
         host_dev.append_column(host_col)
+        host_dev_drvname = self.widget("host-device-drvname")
+        self.build_host_device_drvname_combo(self.vm, host_dev_drvname)
 
         # Video device
         video_dev = self.widget("video-model")
@@ -689,6 +691,17 @@ class vmmAddHardware(vmmGObjectUI):
         combo.set_active(-1)
 
     @staticmethod
+    def build_host_device_drvname_combo(vm, combo):
+        ignore = vm
+        model = Gtk.ListStore(str)
+        combo.set_model(model)
+        uiutil.init_combo_text_column(combo, 0)
+        model.set_sort_column_id(0, Gtk.SortType.ASCENDING)
+
+        for m in virtinst.VirtualHostDevice.DRIVER_TYPE:
+            model.append([m])
+
+    @staticmethod
     def populate_disk_bus_combo(vm, devtype, model):
         # try to get supported disk bus types from domain capabilities
         domcaps = vm.get_domain_capabilities()
@@ -1587,6 +1600,8 @@ class vmmAddHardware(vmmGObjectUI):
 
     def _validate_page_hostdev(self):
         nodedev = uiutil.get_list_selection(self.widget("host-device"), 1)
+        driver_type = uiutil.get_list_selection(
+            self.widget("host-device-drvname"))
         if nodedev is None:
             return self.err.val_err(_("Physical Device Required"),
                                     _("A device must be selected."))
@@ -1607,6 +1622,8 @@ class vmmAddHardware(vmmGObjectUI):
                 if not res:
                     return False
             dev.set_from_nodedev(nodedev)
+            if driver_type is not None:
+                dev.driver_name = driver_type
             self._dev = dev
         except Exception, e:
             return self.err.val_err(_("Host device parameter error"), e)
diff --git a/virtinst/devicehostdev.py b/virtinst/devicehostdev.py
index 34c00b0..3955fd4 100644
--- a/virtinst/devicehostdev.py
+++ b/virtinst/devicehostdev.py
@@ -24,6 +24,7 @@ from .xmlbuilder import XMLProperty
 
 class VirtualHostDevice(VirtualDevice):
     virtual_device_type = VirtualDevice.VIRTUAL_DEV_HOSTDEV
+    DRIVER_TYPE = [None, "kvm", "vfio", "xen"]
 
     def set_from_nodedev(self, nodedev):
         """
-- 
2.7.4





More information about the virt-tools-list mailing list