803fb7
From bd1bb4504d1afe264fd3f739614b97aac8d62bf0 Mon Sep 17 00:00:00 2001
803fb7
From: Tom Gundersen <teg@jklm.no>
803fb7
Date: Tue, 25 Aug 2015 14:12:19 +0200
803fb7
Subject: [PATCH] udev: net_id - support predictable ifnames on virtio buses
803fb7
803fb7
Virtio buses are undeterministically enumerated, so we cannot use them as a basis
803fb7
for deterministic naming (see bf81e792f3c0). However, we are guaranteed that there
803fb7
is only ever one virtio bus for every parent device, so we can simply skip over
803fb7
the virtio buses when naming the devices.
803fb7
803fb7
Cherry-picked from: 54683f0f9b97a8f88aaf4fbb45b4d729057b101c
803fb7
Resolves: #1259015
803fb7
---
803fb7
 src/udev/udev-builtin-net_id.c | 8 ++++++++
803fb7
 1 file changed, 8 insertions(+)
803fb7
803fb7
diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c
803fb7
index dd2886caf..ddd83d4f1 100644
803fb7
--- a/src/udev/udev-builtin-net_id.c
803fb7
+++ b/src/udev/udev-builtin-net_id.c
803fb7
@@ -283,8 +283,16 @@ static int names_pci(struct udev_device *dev, struct netnames *names) {
803fb7
         struct udev_device *parent;
803fb7
 
803fb7
         parent = udev_device_get_parent(dev);
803fb7
+
803fb7
+        /* there can only ever be one virtio bus per parent device, so we can
803fb7
+           safely ignore any virtio buses. see
803fb7
+           <http://lists.linuxfoundation.org/pipermail/virtualization/2015-August/030331.html> */
803fb7
+        while (parent && streq_ptr("virtio", udev_device_get_subsystem(parent)))
803fb7
+                parent = udev_device_get_parent(parent);
803fb7
+
803fb7
         if (!parent)
803fb7
                 return -ENOENT;
803fb7
+
803fb7
         /* check if our direct parent is a PCI device with no other bus in-between */
803fb7
         if (streq_ptr("pci", udev_device_get_subsystem(parent))) {
803fb7
                 names->type = NET_PCI;