From 6a966aac9decb35df6199d0084622ee241cfbc16 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Tue, 13 Aug 2019 11:05:35 +0200 Subject: [PATCH] virpcimock: Create PCI devices under /sys/devices/pci* So far, we are creating devices directly under /sys/bus/pci/devices/*. There is not much problem with it, but if we really want to model kernel behaviour we need to create them under /sys/devices/pciDDDD:BB and then only symlink them from the old location. Signed-off-by: Michal Privoznik Tested-by: Daniel Henrique Barboza Reviewed-by: Daniel Henrique Barboza --- tests/virpcimock.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/tests/virpcimock.c b/tests/virpcimock.c index 1d707148aa..80ef4809ab 100644 --- a/tests/virpcimock.c +++ b/tests/virpcimock.c @@ -384,12 +384,17 @@ pci_device_get_path(const struct pciDevice *dev, if (!(devid = pci_address_format(&dev->addr))) return NULL; + /* PCI devices really do live under /sys/devices/pciDDDD:BB + * and then they are just symlinked to /sys/bus/pci/devices/ + */ if (file) { - ignore_value(virAsprintfQuiet(&ret, "%s" SYSFS_PCI_PREFIX "devices/%s/%s", - prefix, devid, file)); + ignore_value(virAsprintfQuiet(&ret, "%s/sys/devices/pci%04x:%02x/%s/%s", + prefix, dev->addr.domain, dev->addr.bus, + devid, file)); } else { - ignore_value(virAsprintfQuiet(&ret, "%s" SYSFS_PCI_PREFIX "devices/%s", - prefix, devid)); + ignore_value(virAsprintfQuiet(&ret, "%s/sys/devices/pci%04x:%02x/%s", + prefix, dev->addr.domain, dev->addr.bus, + devid)); } return ret; @@ -401,6 +406,7 @@ pci_device_new_from_stub(const struct pciDevice *data) { struct pciDevice *dev; VIR_AUTOFREE(char *) devpath = NULL; + VIR_AUTOFREE(char *) devsympath = NULL; VIR_AUTOFREE(char *) id = NULL; VIR_AUTOFREE(char *) devid = NULL; char *c; @@ -489,6 +495,17 @@ pci_device_new_from_stub(const struct pciDevice *data) } make_symlink(devpath, "iommu_group", tmp); + if (snprintf(tmp, sizeof(tmp), + "../../../devices/pci%04x:%02x/%s", + dev->addr.domain, dev->addr.bus, devid) < 0) { + ABORT("@tmp overflow"); + } + + if (virAsprintfQuiet(&devsympath, "%s" SYSFS_PCI_PREFIX "devices", fakerootdir) < 0) + ABORT_OOM(); + + make_symlink(devsympath, devid, tmp); + if (pci_device_autobind(dev) < 0) ABORT("Unable to bind: %s", devid); -- GitLab