[virt-tools-list] [virt-manager PATCH V3 3/3] network: add support to create SR-IOV VF pool

Lin Ma lma at suse.com
Fri Mar 31 12:12:01 UTC 2017


Create a network with a device pool containing all the VFs of an SR-IOV device.

Signed-off-by: Lin Ma <lma at suse.com>
---
 ui/createnet.ui          | 96 ++++++++++++++++++++++++++++++++++++++++++++++--
 virtManager/createnet.py | 68 ++++++++++++++++++++++++++++++++--
 2 files changed, 157 insertions(+), 7 deletions(-)

diff --git a/ui/createnet.ui b/ui/createnet.ui
index 161056b..3457aed 100644
--- a/ui/createnet.ui
+++ b/ui/createnet.ui
@@ -1091,6 +1091,94 @@
                     <property name="can_focus">False</property>
                     <property name="spacing">6</property>
                     <child>
+                      <object class="GtkAlignment" id="alignment5">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="left_padding">15</property>
+                        <child>
+                          <object class="GtkBox" id="box14">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="orientation">vertical</property>
+                            <property name="spacing">6</property>
+                            <child>
+                              <object class="GtkRadioButton" id="net-forward-mode-hostdev">
+                                <property name="label" translatable="yes">_Pool containing all of VFs of a SR-IOV device</property>
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="receives_default">False</property>
+                                <property name="valign">start</property>
+                                <property name="use_underline">True</property>
+                                <property name="draw_indicator">True</property>
+                                <property name="group">net-forward-dev</property>
+                                <signal name="toggled" handler="on_net_forward_toggled" swapped="no"/>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">True</property>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkAlignment" id="alignment8">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="left_padding">25</property>
+                                <child>
+                                  <object class="GtkGrid" id="net-forward-hostdev-table">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="row_spacing">4</property>
+                                    <property name="column_spacing">6</property>
+                                    <child>
+                                      <object class="GtkLabel" id="label393">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="halign">start</property>
+                                        <property name="xalign">1</property>
+                                        <property name="label" translatable="yes">Device _List:</property>
+                                        <property name="use_underline">True</property>
+                                        <property name="mnemonic_widget">net-forward</property>
+                                      </object>
+                                      <packing>
+                                        <property name="left_attach">0</property>
+                                        <property name="top_attach">0</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkComboBox" id="pf-list">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                      </object>
+                                      <packing>
+                                        <property name="left_attach">1</property>
+                                        <property name="top_attach">0</property>
+                                      </packing>
+                                    </child>
+                                  </object>
+                                </child>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">True</property>
+                                <property name="position">1</property>
+                              </packing>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">True</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="expand">True</property>
+                        <property name="fill">True</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
                       <object class="GtkLabel" id="label205">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
@@ -1103,7 +1191,7 @@
                       <packing>
                         <property name="expand">False</property>
                         <property name="fill">False</property>
-                        <property name="position">0</property>
+                        <property name="position">1</property>
                       </packing>
                     </child>
                     <child>
@@ -1256,7 +1344,7 @@
                               </packing>
                             </child>
                             <child>
-                              <object class="GtkBox" id="box13">
+                              <object class="GtkBox" id="net-enable-ipv6-networking-box">
                                 <property name="visible">True</property>
                                 <property name="can_focus">False</property>
                                 <property name="orientation">vertical</property>
@@ -1308,7 +1396,7 @@
                               </packing>
                             </child>
                             <child>
-                              <object class="GtkHBox" id="hbox6">
+                              <object class="GtkHBox" id="dns-domain-name-box">
                                 <property name="visible">True</property>
                                 <property name="can_focus">False</property>
                                 <property name="spacing">6</property>
@@ -1354,7 +1442,7 @@
                       <packing>
                         <property name="expand">True</property>
                         <property name="fill">True</property>
-                        <property name="position">1</property>
+                        <property name="position">2</property>
                       </packing>
                     </child>
                   </object>
diff --git a/virtManager/createnet.py b/virtManager/createnet.py
index 9fdbc45..b670b09 100644
--- a/virtManager/createnet.py
+++ b/virtManager/createnet.py
@@ -120,6 +120,12 @@ class vmmCreateNetwork(vmmGObjectUI):
         self.widget("header").modify_bg(Gtk.StateType.NORMAL, blue)
 
         # [ label, dev name ]
+        pf_list = self.widget("pf-list")
+        pf_model = Gtk.ListStore(str, str)
+        pf_list.set_model(pf_model)
+        uiutil.init_combo_text_column(pf_list, 0)
+
+        # [ label, dev name ]
         fw_list = self.widget("net-forward")
         fw_model = Gtk.ListStore(str, str)
         fw_list.set_model(fw_model)
@@ -167,6 +173,9 @@ class vmmCreateNetwork(vmmGObjectUI):
 
         self.widget("net-enable-ipv6-networking").set_active(False)
 
+        pf_model = self.widget("pf-list").get_model()
+        pf_model.clear()
+
         fw_model = self.widget("net-forward").get_model()
         fw_model.clear()
         fw_model.append([_("Any physical device"), None])
@@ -181,6 +190,28 @@ class vmmCreateNetwork(vmmGObjectUI):
         for name in devnames:
             fw_model.append([_("Physical device %s") % name, name])
 
+        devprettynames = []
+        ifnames = []
+        for pcidev in self.conn.filter_nodedevs("pci"):
+            if pcidev.xmlobj.capability_type != "virt_functions":
+                continue
+            devdesc = pcidev.xmlobj.pretty_name()
+            for netdev in self.conn.filter_nodedevs("net"):
+                if pcidev.xmlobj.name != netdev.xmlobj.parent:
+                    continue
+                ifname = netdev.xmlobj.interface
+                devprettyname = "%s (%s)" % (ifname, devdesc)
+                devprettynames.append(devprettyname)
+                ifnames.append(ifname)
+                break
+        if not devprettynames:
+            pf_model.append([_("No available device"), None])
+        else:
+            for devprettyname, ifname in zip(devprettynames, ifnames):
+                pf_model.append([_("%s") % devprettyname, ifname])
+
+        self.widget("pf-list").set_active(0)
+
         self.widget("net-forward").set_active(0)
         self.widget("net-forward-mode").set_active(0)
         self.widget("net-forward-none").set_active(True)
@@ -223,6 +254,11 @@ class vmmCreateNetwork(vmmGObjectUI):
         return self._get_network_helper("net-dhcpv6-end")
 
     def get_config_forwarding(self):
+        if self.widget("net-forward-mode-hostdev").get_active():
+            name = uiutil.get_list_selection(self.widget("pf-list"), column=1)
+            mode = "hostdev"
+            return [name, mode]
+
         if self.widget("net-forward-none").get_active():
             return [None, None]
 
@@ -481,10 +517,27 @@ class vmmCreateNetwork(vmmGObjectUI):
             self.widget("create-finish").grab_focus()
 
     def change_forward_type(self, ignore):
-        skip_fwd = self.widget("net-forward-none").get_active()
+        index = self.widget("pf-list").get_active()
+        model = self.widget("pf-list").get_model()
+        item = model[index]
+        if item[1] is None:
+            sriov_capable = False
+        else:
+            sriov_capable = True
+        self.widget("net-forward-mode-hostdev").set_sensitive(sriov_capable)
+        vf_pool = self.widget("net-forward-mode-hostdev").get_active()
+        if not vf_pool:
+            skip_fwd = self.widget("net-forward-none").get_active()
+
+            self.widget("net-forward-mode").set_sensitive(not skip_fwd)
+            self.widget("net-forward").set_sensitive(not skip_fwd)
+        else:
+            self.widget("net-forward-mode").set_sensitive(False)
+            self.widget("net-forward").set_sensitive(False)
 
-        self.widget("net-forward-mode").set_sensitive(not skip_fwd)
-        self.widget("net-forward").set_sensitive(not skip_fwd)
+        self.widget("net-forward-hostdev-table").set_sensitive(vf_pool)
+        self.widget("net-enable-ipv6-networking-box").set_sensitive(not vf_pool)
+        self.widget("dns-domain-name-box").set_sensitive(not vf_pool)
 
     def change_ipv4_enable(self, ignore):
         enabled = self.get_config_ipv4_enable()
@@ -686,6 +739,15 @@ class vmmCreateNetwork(vmmGObjectUI):
             net.forward.mode = mode
             net.forward.dev = dev or None
 
+        if net.forward.mode == "hostdev":
+            net.forward.managed = "yes"
+            pfobj = net.forward.add_pf()
+            pfobj.dev = net.forward.dev
+            net.forward.dev = None
+            net.domain_name = None
+            net.ipv6 = None
+            return net
+
         if self.get_config_ipv4_enable():
             ip = self.get_config_ip4()
             ipobj = net.add_ip()
-- 
2.9.2




More information about the virt-tools-list mailing list