From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 368FF1FF18A for ; Tue, 22 Jul 2025 16:51:13 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B4317C939; Tue, 22 Jul 2025 16:52:26 +0200 (CEST) From: Stefan Hanreich To: pve-devel@lists.proxmox.com Date: Tue, 22 Jul 2025 16:52:22 +0200 Message-Id: <20250722145223.351778-2-s.hanreich@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250722145223.351778-1-s.hanreich@proxmox.com> References: <20250722145223.351778-1-s.hanreich@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 2 AWL -2.698 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods KAM_SOMETLD_ARE_BAD_TLD 5 .bar, .beauty, .buzz, .cam, .casa, .cfd, .club, .date, .guru, .link, .live, .monster, .online, .press, .pw, .quest, .rest, .sbs, .shop, .stream, .top, .trade, .wiki, .work, .xyz TLD abuse RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RDNS_NONE 0.793 Delivered to internal network by a host with no rDNS SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [country.pl, proxmox-ve-default.link] Subject: [pve-devel] [PATCH pve-manager 1/2] configs: add udev helper for pinning virtual function names X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" This commmit adds a udev rule that triggers for every network device that gets added. It checks if the network device is a VF and if the parent device is pinned. If it is pinned, then generate a new name for the VF which consists of the pinned name of the parent device, as well as the index of the VF. It relies on the network device driver exposing the information via sysfs, which was the case in my tests for mlx5_core, igb and bnxt_en. Specifically it checks if a device is a virtual function by checking for the existence of: /sys/class/net//device/physfn It then follows that symlink and infers the vf index by looking at the virtfnX symlinks in the folder above. Signed-off-by: Stefan Hanreich --- configs/Makefile | 4 ++- configs/virtual-function-pinning-helper | 37 +++++++++++++++++++++++++ configs/virtual-function-pinning.rules | 1 + 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 configs/virtual-function-pinning-helper create mode 100644 configs/virtual-function-pinning.rules diff --git a/configs/Makefile b/configs/Makefile index 57d61a0bd..6b89e8b3a 100644 --- a/configs/Makefile +++ b/configs/Makefile @@ -6,7 +6,7 @@ country.dat: country.pl ./country.pl > country.dat .PHONY: install -install: country.dat vzdump.conf pve-sources.sources pve-initramfs.conf pve-blacklist.conf pve.logrotate +install: country.dat vzdump.conf pve-sources.sources pve-initramfs.conf pve-blacklist.conf pve.logrotate virtual-function-pinning.rules virtual-function-pinning-helper install -D -m 0644 pve.logrotate $(DESTDIR)/etc/logrotate.d/pve install -D -m 0644 pve-sources.sources $(DESTDIR)/etc/apt/sources.list.d/pve-enterprise.sources install -D -m 0644 pve-blacklist.conf $(DESTDIR)/etc/modprobe.d/pve-blacklist.conf @@ -14,6 +14,8 @@ install: country.dat vzdump.conf pve-sources.sources pve-initramfs.conf pve-blac install -D -m 0644 pve-initramfs.conf $(DESTDIR)/etc/initramfs-tools/conf.d/pve-initramfs.conf install -D -m 0644 country.dat $(DESTDIR)/usr/share/$(PACKAGE)/country.dat install -D -m 0644 proxmox-ve-default.link $(DESTDIR)/usr/lib/systemd/network/99-default.link.d/proxmox-mac-address-policy.conf + install -D -m 0644 virtual-function-pinning.rules $(DESTDIR)/usr/lib/udev/rules.d/70-virtual-function-pinning.rules + install -D -m 0755 virtual-function-pinning-helper $(DESTDIR)/usr/lib/udev/virtual-function-naming-helper clean: rm -f country.dat diff --git a/configs/virtual-function-pinning-helper b/configs/virtual-function-pinning-helper new file mode 100644 index 000000000..9a8a95b54 --- /dev/null +++ b/configs/virtual-function-pinning-helper @@ -0,0 +1,37 @@ +#!/bin/sh +set -eu + +DEVICE_SYSFS_PCI_PATH=$(realpath "/sys${DEVPATH}/../.."); + +if [ ! -L "$DEVICE_SYSFS_PCI_PATH/physfn" ]; then + exit; +fi + +PHYSFN_SYSFS_PCI_PATH=$(realpath "${DEVICE_SYSFS_PCI_PATH}/physfn"); +PHYSFN_IFACE_NAME=$(ls "${PHYSFN_SYSFS_PCI_PATH}/net") + +# interface is not pinned +if [ ! -f "/usr/local/lib/systemd/network/50-pve-${PHYSFN_IFACE_NAME}.link" ]; then + exit; +fi + +# pin is not applied - or interface doesn't exist +if ! ip link show "$PHYSFN_IFACE_NAME" > /dev/null 2>&1 ; then + exit; +fi + +DEVICE_PCI_ID=$(basename "$DEVICE_SYSFS_PCI_PATH"); + +for file in $(find "${PHYSFN_SYSFS_PCI_PATH=$}/" -maxdepth 1 -type l -name 'virtfn*' ); do + VF_PCI_ID=$(basename "$(realpath "$file")"); + + if [ "$DEVICE_PCI_ID" = "$VF_PCI_ID" ]; then + VF_INDEX=$(basename "$file" | grep -Eo '[[:digit:]]+$' -); + echo "${PHYSFN_IFACE_NAME}v${VF_INDEX}"; + exit; + fi +done + +echo "interface seems to be a VF of ${PHYSFN_IFACE_NAME}, but could not find the VF index" 1>&2; +exit; + diff --git a/configs/virtual-function-pinning.rules b/configs/virtual-function-pinning.rules new file mode 100644 index 000000000..dc2224886 --- /dev/null +++ b/configs/virtual-function-pinning.rules @@ -0,0 +1 @@ +SUBSYSTEM=="net",ACTION=="add",PROGRAM=="/usr/lib/udev/virtual-function-naming-helper",NAME="%c" -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel