summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStuart Hayes <stuart_hayes@dell.com>2018-01-18 15:14:56 -0500
committerStuart Hayes <stuart_hayes@dell.com>2018-03-26 14:00:43 -0400
commit6bc04997b6eab35d1cb9fa73889892702c27be09 (patch)
tree15c218df05bdfb8309b4513b56d94bc08dcecc22 /src
parent609948c7043a40008b8299529c978ed8e11de8f6 (diff)
downloadsystemd-6bc04997b6eab35d1cb9fa73889892702c27be09.tar.gz
udev: net_id: Improve predictable names for NPAR devices
NPAR is a technology that allows a single network interface to be divided into number of partitions. The partitions show up as functions on the same PCI device... when there are more than 8 functions, ARI (alternative routing-ID interpretation) is used. With ARI is enabled, the 8 bit field that normally has 5 bits for the PCI device and 3 bits for the PCI function is instead interpreted as (implicit) device 0, with 8 bits for the function number. Because the linux kernel exposes the PCI device/function numbers to userspace the same regardless of whether ARI is enabled, systemd predictable device naming can generate unpredictable names in this case, because network names using the PCI slot use the function number, but not the device number, causing systemd to generate the same name for mulitple network devices (so some will revert to the "ethX" names). With this patch, device naming code checks if ARI is enabled for a PCI network device, and uses the full 8-bit function number for naming to avoid this situation. This should improve readability and predictability of device names. Here is an example of how this change would affect naming: before patch | after patch ----------------------------- ens2f0 | ens2f0 NPAR partition 0 (in PCI slot 2) ens2f1 | ens2f1 NPAR partition 1 ... ens2f7 | ens2f7 NPAR partition 7 eth1 | ens2f8 NPAR partition 8 eth2 | ens2f9 NPAR partition 9
Diffstat (limited to 'src')
-rw-r--r--src/udev/udev-builtin-net_id.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c
index 233bdd2646..54d2ea0aaa 100644
--- a/src/udev/udev-builtin-net_id.c
+++ b/src/udev/udev-builtin-net_id.c
@@ -299,6 +299,10 @@ static bool is_pci_multifunction(struct udev_device *dev) {
return false;
}
+static bool is_pci_ari_enabled(struct udev_device *dev) {
+ return !!udev_device_get_sysattr_value(dev, "ari_enabled");
+}
+
static int dev_pci_slot(struct udev_device *dev, struct netnames *names) {
struct udev *udev = udev_device_get_udev(names->pcidev);
unsigned domain, bus, slot, func, dev_port = 0, hotplug_slot = 0;
@@ -313,6 +317,11 @@ static int dev_pci_slot(struct udev_device *dev, struct netnames *names) {
if (sscanf(udev_device_get_sysname(names->pcidev), "%x:%x:%x.%u", &domain, &bus, &slot, &func) != 4)
return -ENOENT;
+ if (is_pci_ari_enabled(names->pcidev))
+ /* ARI devices support up to 256 functions on a single device ("slot"), and interpret the
+ * traditional 5-bit slot and 3-bit function number as a single 8-bit function number,
+ * where the slot makes up the upper 5 bits. */
+ func += slot * 8;
/* kernel provided port index for multiple ports on a single PCI function */
attr = udev_device_get_sysattr_value(dev, "dev_port");