From: Michal Privoznik <mprivozn@redhat.com> A PCI device that is a network interface card also has 'net/' subdir with interface name it corresponds to. For instance: # ls -l /sys/bus/pci/devices/0000\:00\:1f.6/net/ total 0 drwxr-xr-x 5 root root 0 Feb 26 16:51 eth0 Allow setting interface name for PCI devices. Now, in real life the net/$IFNAME/ is a directory, but since our code opens net/ dir and then just reads dentries creating file instead of full blown dir is okay. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/virpcimock.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/tests/virpcimock.c b/tests/virpcimock.c index c59359b889..22d2354ebe 100644 --- a/tests/virpcimock.c +++ b/tests/virpcimock.c @@ -144,6 +144,7 @@ struct pciDevice { int sriovTotalvfs; unsigned int virtfnCount; const char *physfn; + const char *netName; struct pciDriver *driver; /* Driver attached. NULL if attached to no driver */ struct pciVPD vpd; }; @@ -590,6 +591,18 @@ pci_device_new_from_stub(const struct pciDevice *data) register_vf(dev); } + if (dev->netName) { + if (g_snprintf(tmp, sizeof(tmp), "%s/net", devpath) < 0) { + ABORT("@tmp overflow"); + } + + if (g_mkdir_with_parents(tmp, 0777) < 0) + ABORT("Unable to create: %s", tmp); + + /* In real sysfs this is a dir, but for test purposes a file is okay. */ + make_file(tmp, dev->netName, dev->netName, -1); + } + if (dev->vpd.data && dev->vpd.vpd_len) make_file(devpath, "vpd", dev->vpd.data, dev->vpd.vpd_len); @@ -1072,8 +1085,10 @@ init_env(void) pci_device_new_from_stub(&dev); \ } while (0) - MAKE_PCI_DEVICE("0000:00:00.0", 0x8086, 0x0044, 0); - MAKE_PCI_DEVICE("0000:00:01.0", 0x8086, 0x0044, 1); + MAKE_PCI_DEVICE("0000:00:00.0", 0x8086, 0x0044, 0, + .netName = "wlan0"); + MAKE_PCI_DEVICE("0000:00:01.0", 0x8086, 0x0044, 1, + .netName = "wlan1"); MAKE_PCI_DEVICE("0000:00:02.0", 0x8086, 0x0046, 2); MAKE_PCI_DEVICE("0000:00:03.0", 0x8086, 0x0048, 3); MAKE_PCI_DEVICE("0001:00:00.0", 0x1014, 0x03b9, 4, .klass = 0x060400); @@ -1088,15 +1103,18 @@ init_env(void) MAKE_PCI_DEVICE("0000:0a:02.0", 0x8286, 0x0048, 8); MAKE_PCI_DEVICE("0000:0a:03.0", 0x8386, 0x0048, 8); MAKE_PCI_DEVICE("0000:06:12.0", 0x8086, 0x0047, 9, - .sriovTotalvfs = 7); + .sriovTotalvfs = 7, .netName = "enp1s0f0"); MAKE_PCI_DEVICE("0000:06:12.1", 0x8086, 0x0047, 10, - .physfn = "0000:06:12.0"); /* Virtual Function */ + .physfn = "0000:06:12.0", /* Virtual Function */ + .netName = "enp1s0f1"); MAKE_PCI_DEVICE("0000:06:12.2", 0x8086, 0x0047, 11, - .physfn = "0000:06:12.0"); /* Virtual Function */ + .physfn = "0000:06:12.0", /* Virtual Function */ + .netName = "enp1s0f2"); MAKE_PCI_DEVICE("0021:de:1f.0", 0x8086, 0x0047, 12, - .sriovTotalvfs = 7); + .sriovTotalvfs = 7, .netName = "enp2s0f0"); MAKE_PCI_DEVICE("0021:de:1f.1", 0x8086, 0x0047, 13, - .physfn = "0021:de:1f.0"); /* Virtual Function */ + .physfn = "0021:de:1f.0", /* Virtual Function */ + .netName = "enp2s0f1"); MAKE_PCI_DEVICE("0000:01:00.0", 0x1cc1, 0x8201, 14, .klass = 0x010802); MAKE_PCI_DEVICE("0000:02:00.0", 0x1cc1, 0x8201, 15, .klass = 0x010802); -- 2.52.0