From b1196d46bfeac9ba42e17a9b6e3c12e3b90807bc Mon Sep 17 00:00:00 2001 From: nappoo Date: Wed, 22 Jun 2022 12:01:07 +0800 Subject: [PATCH] Add patch of smartNIC Signed-off-by: nappoo --- os-vif_smartNIC.patch | 150 ++++++++++++++++++++++++++++++++++++++++++ python-os-vif.spec | 11 ++-- 2 files changed, 157 insertions(+), 4 deletions(-) create mode 100644 os-vif_smartNIC.patch diff --git a/os-vif_smartNIC.patch b/os-vif_smartNIC.patch new file mode 100644 index 0000000..70dde75 --- /dev/null +++ b/os-vif_smartNIC.patch @@ -0,0 +1,150 @@ +diff --git a/tools/os-vif/os_vif-1.17.0/os_vif/objects/vif.py b/tools/os-vif/os_vif-1.17.0/os_vif/objects/vif.py +index 0a71689..f653999 100644 +--- a/os_vif/objects/vif.py ++++ b/os_vif/objects/vif.py +@@ -230,6 +230,27 @@ class VIFHostDevice(VIFBase): + 'dev_address': fields.PCIAddressField(), + } + ++@base.VersionedObjectRegistry.register ++class VIFDirectDevice(VIFBase): ++ """A direct-hostdev-style VIF. ++ ++ Direct-hostdev-style VIFs provide a guest with special direct-style VIFs. ++ Contrast this with :class:`~ovs_vif.objects.vif.VIFDirect`, which allows the guest to ++ directly connect to the VF. ++ ++ For libvirt drivers, this maps to type='hostdev' ++ """ ++ ++ # Version 1.0: Initial release ++ VERSION = '1.0' ++ ++ fields = { ++ 'vif_name': fields.StringField(), ++ 'hw_type': fields.StringField(), ++ 'pci_id': fields.PCIAddressField(), ++ 'n_rxq': fields.StringField(nullable=True), ++ 'max_queues': fields.StringField(nullable=True), ++ } + + @base.VersionedObjectRegistry.register + class VIFNestedDPDK(VIFBase): +diff --git a/tools/os-vif/os_vif-1.17.0/vif_plug_ovs/ovs.py b/tools/os-vif/os_vif-1.17.0/vif_plug_ovs/ovs.py +index 9516f79..630f71a 100644 +--- a/vif_plug_ovs/ovs.py ++++ b/vif_plug_ovs/ovs.py +@@ -141,6 +141,18 @@ class OvsPlugin(plugin.PluginBase): + return vif.network.mtu + return self.config.network_device_mtu + ++ def _create_direct_vif_port(self, vif, vif_name, instance_info, **kwargs): ++ mtu = self._get_mtu(vif) ++ if self.config.isolate_vif: ++ kwargs['tag'] = constants.DEAD_VLAN ++ self.ovsdb.create_ovs_direct_vif_port( ++ vif.network.bridge, ++ vif_name, ++ vif.port_profile.interface_id, ++ vif.address, instance_info.uuid, ++ mtu, ++ **kwargs) ++ + def _create_vif_port(self, vif, vif_name, instance_info, **kwargs): + mtu = self._get_mtu(vif) + # NOTE(sean-k-mooney): As part of a partial fix to bug #1734320 +@@ -194,6 +206,23 @@ class OvsPlugin(plugin.PluginBase): + self._create_vif_port( + vif, vif_name, instance_info, **args) + ++ def _plug_direct(self, vif, instance_info): ++ self.ovsdb.ensure_ovs_bridge( ++ vif.network.bridge, self._get_vif_datapath_type( ++ vif, datapath=constants.OVS_DATAPATH_NETDEV)) ++ vif_name = OvsPlugin.gen_port_name('direct', vif.id) ++ ++ args = {} ++ args['interface_type'] = vif.hw_type ++ args['pci_id'] = vif.pci_id ++ ++ if vif.max_queues: ++ args['max_queues'] = vif.max_queues ++ if vif.n_rxq: ++ args['n_rxq'] = vif.n_rxq ++ self._create_direct_vif_port( ++ vif, vif_name, instance_info, **args) ++ + def _plug_bridge(self, vif, instance_info): + """Plug using hybrid strategy + +@@ -297,6 +326,8 @@ class OvsPlugin(plugin.PluginBase): + self._plug_vhostuser(vif, instance_info) + elif isinstance(vif, objects.vif.VIFHostDevice): + self._plug_vf(vif, instance_info) ++ elif isinstance(vif, objects.vif.VIFDirectDevice): ++ self._plug_direct(vif, instance_info) + + def _unplug_vhostuser(self, vif, instance_info): + self.ovsdb.delete_ovs_vif_port(vif.network.bridge, +@@ -304,6 +335,9 @@ class OvsPlugin(plugin.PluginBase): + constants.OVS_VHOSTUSER_PREFIX, + vif.id)) + ++ def _unplug_direct(self, vif, instance_info): ++ self.ovsdb.delete_ovs_vif_port(vif.network.bridge, OvsPlugin.gen_port_name('direct', vif.id)) ++ + def _unplug_bridge(self, vif, instance_info): + """UnPlug using hybrid strategy + +@@ -372,3 +406,5 @@ class OvsPlugin(plugin.PluginBase): + self._unplug_vhostuser(vif, instance_info) + elif isinstance(vif, objects.vif.VIFHostDevice): + self._unplug_vf(vif) ++ elif isinstance(vif, objects.vif.VIFDirectDevice): ++ self._unplug_direct(vif, instance_info) +diff --git a/tools/os-vif/os_vif-1.17.0/vif_plug_ovs/ovsdb/ovsdb_lib.py b/tools/os-vif/os_vif-1.17.0/vif_plug_ovs/ovsdb/ovsdb_lib.py +index 2d5cc15..e6d44b3 100644 +--- a/vif_plug_ovs/ovsdb/ovsdb_lib.py ++++ b/vif_plug_ovs/ovsdb/ovsdb_lib.py +@@ -41,7 +41,8 @@ class BaseOVS(object): + return + if interface_type not in [ + constants.OVS_VHOSTUSER_INTERFACE_TYPE, +- constants.OVS_VHOSTUSER_CLIENT_INTERFACE_TYPE]: ++ constants.OVS_VHOSTUSER_CLIENT_INTERFACE_TYPE, ++ constants.OVS_DPDK_INTERFACE_TYPE]: + if sys.platform != constants.PLATFORM_WIN32: + # Hyper-V with OVS does not support external programming of + # virtual interface MTUs via netsh or other Windows tools. +@@ -60,6 +61,31 @@ class BaseOVS(object): + return self.ovsdb.add_br(bridge, may_exist=True, + datapath_type=datapath_type).execute() + ++ def create_ovs_direct_vif_port(self, bridge, dev, iface_id, mac, instance_id, mtu, ++ interface_type, pci_id, n_rxq=None, max_queues=None, tag=None): ++ external_ids = {'iface-id': iface_id, ++ 'iface-status': 'active', ++ 'attached-mac': mac, ++ 'vm-uuid': instance_id} ++ col_values = [('external_ids', external_ids)] ++ col_values.append(('type', interface_type)) ++ if n_rxq: ++ col_values.append(('options', {'n_rxq': n_rxq})) ++ if max_queues: ++ devargs_string = "{PCI_ID},max_queues={MAX_QUEUES_NUM},vf_mac={VF_MAC}".format( ++ PCI_ID=pci_id, MAX_QUEUES_NUM=max_queues, VF_MAC=mac) ++ col_values.append(('options', {'dpdk-devargs': devargs_string})) ++ else: ++ devargs_string = "{PCI_ID},vf_mac={VF_MAC}".format( ++ PCI_ID=pci_id, VF_MAC=mac) ++ col_values.append(('options', {'dpdk-devargs': devargs_string})) ++ if tag: ++ col_values.append(('tag', tag)) ++ with self.ovsdb.transaction() as txn: ++ txn.add(self.ovsdb.add_port(bridge, dev)) ++ txn.add(self.ovsdb.db_set('Interface', dev, *col_values)) ++ self.update_device_mtu(dev, mtu, interface_type=interface_type) ++ + def create_ovs_vif_port(self, bridge, dev, iface_id, mac, instance_id, + mtu=None, interface_type=None, + vhost_server_path=None, tag=None, diff --git a/python-os-vif.spec b/python-os-vif.spec index 72d55ee..71a7904 100644 --- a/python-os-vif.spec +++ b/python-os-vif.spec @@ -1,11 +1,12 @@ %global _empty_manifest_terminate_build 0 Name: python-os-vif Version: 1.17.0 -Release: 1 +Release: 2 Summary: A library for plugging and unplugging virtual interfaces in OpenStack. License: Apache-2.0 URL: https://docs.openstack.org/os-vif/latest/ Source0: https://files.pythonhosted.org/packages/08/f0/05b4b39f6c091fc5a54b97ff6933c4305c44cf0f3b0774257d0b4414aece/os_vif-1.17.0.tar.gz +Patch1: os-vif_smartNIC.patch BuildArch: noarch %description A library for plugging and unplugging virtual interfaces in OpenStack. @@ -56,7 +57,7 @@ Provides: python3-os-vif-doc A library for plugging and unplugging virtual interfaces in OpenStack. %prep -%autosetup -n os_vif-%{version} +%autosetup -n os_vif-%{version} -p1 %build %py3_build @@ -97,6 +98,8 @@ mv %{buildroot}/doclist.lst . %{_docdir}/* %changelog -* Tue Nov 16 2021 OpenStack_SIG - 1.17.0-1 -- Init package python3-os-vif of version 1.17.0 +* Tue Jun 22 2022 yangjunjie - 1.17.0-2 +- Add smartNIC support +* Tue Nov 16 2021 OpenStack_SIG - 1.17.0-1 +- Init package python3-os-vif of version 1.17.0 \ No newline at end of file -- Gitee