跳转到: 导航, 搜索

SR-IOV-直通-用于-网络-Liberty

OpenStack Liberty 中的 SR-IOV 网络

OpenStack Juno 添加了内置支持,用于通过 SR-IOV NIC 请求虚拟机访问虚拟网络。 随着基于 SR-IOV 的 NIC 的引入,不再需要传统的虚拟桥接器。 每个 SR-IOV 端口都与一个虚拟功能 (VF) 相关联。 SR-IOV 端口可以由基于硬件的虚拟以太网桥接 (HW VEB) 提供;或者它们可以扩展到上游物理交换机 (IEEE 802.1br)。 SR-IOV 端口可以通过两种方式连接

  • 直接连接到其VF
  • 通过驻留在主机上的macvtap设备连接,然后连接到相应的VF

Nova

Nova 对 SR-IOV 的支持能够根据其网络连接性调度具有 SR-IOV 端口的实例。 在做出调度决策时,必须考虑 neutron 端口关联的物理网络。 PCI 白名单已得到增强,允许将标签与 PCI 设备关联。 适用于 SR-IOV 网络的 PCI 设备应标记为 physical_network 标签。

对于 SR-IOV 网络,使用预定义的标签“physical_network”来定义设备连接到的物理网络。 白名单条目定义如下

   ["vendor_id": "<id>",] ["product_id": "<id>",]
   ["address": "[[[[<domain>]:]<bus>]:][<slot>][.[<function>]]" |
   "devname": "Ethernet Interface Name",]  
   "physical_network":"name string of the physical network"

<id> 可以是星号 (*) 或 Linux 实用程序 lspci 显示的有效 vendor/product ID。 地址使用与 lspci 中相同的语法。 devname 可以是有效的 PCI 设备名称。 支持的唯一设备名称是 Linux 实用程序 ifconfig -a 显示的名称,并且对应于 vNIC 上的 PF 或 VF。

如果地址或 devname 定义的设备对应于 SR-IOV PF,则 PF 下的所有 VF 都将匹配该条目。

支持每个主机上的多个白名单条目。

Neutron

Neutron 对 SR-IOV 的支持需要 ML2 插件以及支持 SR-IOV 的机制驱动程序。 当前有 ML2 机制驱动程序用于基于 SR-IOV 的 NIC 的交换 (HW VEB)。 不同供应商的网络适配器在支持各种功能方面有所不同。 如果供应商网络适配器支持 VF 链路状态更新,则应部署 SR-IOV NIC L2 agent 以利用此功能。

使用 SR-IOV vNIC 的虚拟机创建流程

  • 创建一个或多个 neutron 端口。 运行
  neutron port-create <net-id> --binding:vnic-type <direct | macvtap | normal>
  • 使用一个或多个 neutron 端口启动 VM。 运行
  nova boot --flavor m1.large --image <image>
         --nic port-id=<port1> --nic port-id=<port2> <vm name>

请注意,在 nova boot API 中,用户可以指定 port-ID 或 net-ID。 如果指定 net-ID,则假定用户正在请求常规虚拟端口(不是 SR-IOV 端口)。

SR-IOV 配置

控制器节点

Nova Scheduler

启用 PciPassthroughFilter 修改 /etc/nova/nova.conf

 scheduler_available_filters = nova.scheduler.filters.all_filters
 scheduler_default_filters = RetryFilter, AvailabilityZoneFilter, RamFilter, ComputeFilter, ComputeCapabilitiesFilter, ImagePropertiesFilter, PciPassthroughFilter

Neutron 服务器

使用 ML2 Neutron 插件修改 /etc/neutron/plugins/ml2/ml2_conf.ini

[ml2]
tenant_network_types = vlan
type_drivers = vlan
mechanism_drivers = openvswitch,sriovnicswitch
[ml2_type_vlan]
network_vlan_ranges = physnet1:2:100

添加受支持的 PCI vendor VF 设备(仅在非 Mellanox/Intel HCA 上需要),根据 PCI ID Repository 在 /etc/neutron/plugins/ml2/ml2_conf_sriov.ini 中定义

[ml2_sriov]
# (ListOpt) Comma-separated list of
# supported Vendor PCI Devices, in format vendor_id:product_id
#
# supported_pci_vendor_devs = 15b3:1004, 8086:10ca
# Example: supported_pci_vendor_devs = 15b3:1004
supported_pci_vendor_devs = vendor_id:product_id

如果 SR-IOV 网络适配器支持 VF 链路状态设置,并且希望启用管理状态管理,请确保在 /etc/neutron/plugins/ml2/ml2_conf_sriov.ini 中添加 [ml2_sriov] 部分的以下设置(Liberty 中已弃用,从 Mitaka 开始将默认启用

agent_required = True

注意:通常 agent_required 应该为 True,除非您使用的是不支持管理状态更改的 Intel NIC。

编辑 neutron-server 服务(通常位于:/usr/lib/systemd/system/neutron-server.service)Neutron 服务器应使用配置文件 /etc/neutron/plugins/ml2/ml2_conf_sriov.ini 运行

neutron-server --config-file /usr/share/neutron/neutron-dist.conf --config-dir /usr/share/neutron/server --config-file /etc/neutron/neutron.conf --config-file /etc/neutron/plugin.ini --config-file /etc/neutron/plugins/ml2/ml2_conf_sriov.ini --config-dir /etc/neutron/conf.d/common --config-dir /etc/neutron/conf.d/neutron-server --log-file /var/log/neutron/server.log

重新加载 systemctl daemon

systemctl daemon-reload

重新启动 neutron-server

systemctl restart neutron-server.service

计算节点

启用网络适配器上的 SR-IOV

默认情况下 SRIOV 已禁用,您必须在应支持 SRIOV 功能的每个计算主机上启用 SRIOV 并创建 VF。 目前已知特定的 Intel 和 Mellanox 卡支持 SRIOV。 以下资源包含有关如何启用和创建 VF 的信息

nova-compute

Nova-compute 需要知道哪些 PCI 设备允许传递给虚拟机。 同样,对于 SRIOV PCI 设备,它需要知道 VF 属于哪个物理网络。 这通过在 /etc/nova/nova.conf 的默认部分下的 pci_passthrough_whitelist 参数来完成。 例如,如果我们想通过其 PCI 地址来白名单和标记 VF,我们将使用以下设置

pci_passthrough_whitelist = {"address":"*:0a:00.*","physical_network":"physnet1"}

这将使任何包含地址中包含“:0a:00.” 的 VF 与物理网络 physnet1 关联。

或者,我们也可以使用接口名称并说:“从 eth2 创建的所有 VF 都允许通过并属于物理网络 physnet1”,在这种情况下 eth2 是 PF。 例如

pci_passthrough_whitelist = {"devname": "eth2", "physical_network": "physnet1"}

配置白名单后,您必须重新启动 nova-compute 服务。

systemctl restart openstack-nova-compute.service

在使用 devstack 时,pci_passthrough_whitelist 可以在 local.conf 文件中配置,例如

[[post-config|$NOVA_CONF]]
[DEFAULT]
pci_passthrough_whitelist = {"'"address"'":"'"*:02:00.*"'","'"physical_network"'":"'"default"'"}

SR-IOV neutron agent(可选)

仅当硬件支持并且您希望启用更改端口 admin_state 时,才需要运行 Neutron SR-IOV agent。 否则建议使用 agent_required = False。

注意:如果您在 Neutron 服务器上配置了 agent_required=True,则必须在每个计算节点上运行 Agent。

安装 openstack-neutron-sriov-nic-agent.noarch

yum install -y openstack-neutron-sriov-nic-agent.noarch

修改 /etc/neutron/plugins/ml2/sriov_agent.ini 中的“physical_device_mappings”:其中

  • physnet1 是物理网络
  • eth1 是物理功能 (PF)
  • exclude_devices 为空,因此与 eth1 关联的所有 VF 都可以由 agent 配置
[sriov_nic]
# (ListOpt) Comma-separated list of <physical_network>:<network_device>
# tuples mapping physical network names to the agent's node-specific
# physical network device interfaces of SR-IOV physical function to be used
# for VLAN networks. All physical networks listed in network_vlan_ranges on
# the server should have mappings to appropriate interfaces on each agent.
#
# physical_device_mappings =
# Example: physical_device_mappings = physnet1:eth1
#
physical_device_mappings = default:p2p1

在文件末尾添加/修改以下行。

[securitygroup]
firewall_driver = neutron.agent.firewall.NoopFirewallDriver

注意:SR-IOV agent 仅在使用 NoopFirewallDriver 启用安全组时才有效,但您仍然可以通过更新其配置来为其他 Agent 使用其他 firewall_driver。

启用 Neutron SR-IOV agent。 运行

systemctl enable neutron-sriov-nic-agent.service

启动 Neutron SR-IOV agent。 运行

systemctl start neutron-sriov-nic-agent.service

排除 VF

如果您想排除某些 VF,以便 agent 不配置它们,则需要在 sriov_nic 部分中列出它们

示例: exclude_devices = eth1:0000:07:00.2; 0000:07:00.3, eth2:0000:05:00.1; 0000:05:00.2