all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH manager 0/2] add virtual function support to network-interface-pinning
@ 2025-07-22 14:52 Stefan Hanreich
  2025-07-22 14:52 ` [pve-devel] [PATCH pve-manager 1/2] configs: add udev helper for pinning virtual function names Stefan Hanreich
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Stefan Hanreich @ 2025-07-22 14:52 UTC (permalink / raw)
  To: pve-devel

Instead of generating a .link file for every virtual function, with this patch
series proxmox-network-interface-pinning now includes a udev rule that
dynamically changes the name of virtual functions according to the pinned name
of its parent device.

pve-manager:

Stefan Hanreich (2):
  configs: add udev helper for pinning virtual function names
  network-interface-pinning: do not generate link files for vfs

 PVE/CLI/proxmox_network_interface_pinning.pm |  9 ++++-
 configs/Makefile                             |  4 ++-
 configs/virtual-function-pinning-helper      | 37 ++++++++++++++++++++
 configs/virtual-function-pinning.rules       |  1 +
 4 files changed, 49 insertions(+), 2 deletions(-)
 create mode 100644 configs/virtual-function-pinning-helper
 create mode 100644 configs/virtual-function-pinning.rules


Summary over all repositories:
  4 files changed, 49 insertions(+), 2 deletions(-)

-- 
Generated by git-murpp 0.8.0

_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pve-devel] [PATCH pve-manager 1/2] configs: add udev helper for pinning virtual function names
  2025-07-22 14:52 [pve-devel] [PATCH manager 0/2] add virtual function support to network-interface-pinning Stefan Hanreich
@ 2025-07-22 14:52 ` Stefan Hanreich
  2025-07-22 14:52 ` [pve-devel] [PATCH pve-manager 2/2] network-interface-pinning: do not generate link files for vfs Stefan Hanreich
  2025-07-23 17:31 ` [pve-devel] applied: [PATCH manager 0/2] add virtual function support to network-interface-pinning Thomas Lamprecht
  2 siblings, 0 replies; 4+ messages in thread
From: Stefan Hanreich @ 2025-07-22 14:52 UTC (permalink / raw)
  To: 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/<iface>/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 <s.hanreich@proxmox.com>
---
 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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pve-devel] [PATCH pve-manager 2/2] network-interface-pinning: do not generate link files for vfs
  2025-07-22 14:52 [pve-devel] [PATCH manager 0/2] add virtual function support to network-interface-pinning Stefan Hanreich
  2025-07-22 14:52 ` [pve-devel] [PATCH pve-manager 1/2] configs: add udev helper for pinning virtual function names Stefan Hanreich
@ 2025-07-22 14:52 ` Stefan Hanreich
  2025-07-23 17:31 ` [pve-devel] applied: [PATCH manager 0/2] add virtual function support to network-interface-pinning Thomas Lamprecht
  2 siblings, 0 replies; 4+ messages in thread
From: Stefan Hanreich @ 2025-07-22 14:52 UTC (permalink / raw)
  To: pve-devel

Since the renaming of virtual functions is now handled dynamically via
a custom udev rule, proxmox-network-interface-pinning needs to
additionally filter all existing virtual functions when pinning
network interface names, since otherwise they would also get a pinned
name.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
 PVE/CLI/proxmox_network_interface_pinning.pm | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/PVE/CLI/proxmox_network_interface_pinning.pm b/PVE/CLI/proxmox_network_interface_pinning.pm
index 382e2d94b..01b94af2a 100644
--- a/PVE/CLI/proxmox_network_interface_pinning.pm
+++ b/PVE/CLI/proxmox_network_interface_pinning.pm
@@ -304,12 +304,19 @@ sub get_ip_link_mac {
     return $ip_link->{link_info}->{info_slave_data}->{perm_hwaddr} // $ip_link->{address};
 }
 
+sub iface_is_vf {
+    my ($iface_name) = @_;
+
+    return -l "/sys/class/net/$iface_name/device/physfn";
+}
+
 sub get_ip_links {
     my $ip_links = PVE::Network::ip_link_details();
 
     for my $iface_name (keys $ip_links->%*) {
         delete $ip_links->{$iface_name}
-            if !PVE::Network::ip_link_is_physical($ip_links->{$iface_name});
+            if !PVE::Network::ip_link_is_physical($ip_links->{$iface_name})
+            || iface_is_vf($iface_name);
     }
 
     return $ip_links;
-- 
2.39.5


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pve-devel] applied: [PATCH manager 0/2] add virtual function support to network-interface-pinning
  2025-07-22 14:52 [pve-devel] [PATCH manager 0/2] add virtual function support to network-interface-pinning Stefan Hanreich
  2025-07-22 14:52 ` [pve-devel] [PATCH pve-manager 1/2] configs: add udev helper for pinning virtual function names Stefan Hanreich
  2025-07-22 14:52 ` [pve-devel] [PATCH pve-manager 2/2] network-interface-pinning: do not generate link files for vfs Stefan Hanreich
@ 2025-07-23 17:31 ` Thomas Lamprecht
  2 siblings, 0 replies; 4+ messages in thread
From: Thomas Lamprecht @ 2025-07-23 17:31 UTC (permalink / raw)
  To: pve-devel, Stefan Hanreich

On Tue, 22 Jul 2025 16:52:21 +0200, Stefan Hanreich wrote:
> Instead of generating a .link file for every virtual function, with this patch
> series proxmox-network-interface-pinning now includes a udev rule that
> dynamically changes the name of virtual functions according to the pinned name
> of its parent device.
> 
> pve-manager:
> 
> [...]

Applied, thanks!

[1/2] configs: add udev helper for pinning virtual function names
      commit: 017359f376a78fc2754482207cfdf07a5fd58248
[2/2] network-interface-pinning: do not generate link files for vfs
      commit: 73ae711ff01a3934ac745fdef61b0c3b9f28ac03


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-07-23 17:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-07-22 14:52 [pve-devel] [PATCH manager 0/2] add virtual function support to network-interface-pinning Stefan Hanreich
2025-07-22 14:52 ` [pve-devel] [PATCH pve-manager 1/2] configs: add udev helper for pinning virtual function names Stefan Hanreich
2025-07-22 14:52 ` [pve-devel] [PATCH pve-manager 2/2] network-interface-pinning: do not generate link files for vfs Stefan Hanreich
2025-07-23 17:31 ` [pve-devel] applied: [PATCH manager 0/2] add virtual function support to network-interface-pinning Thomas Lamprecht

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal