]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virpcimock: Create symlink in /sys/kernel/iommu_groups/N/devices dir
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 13 Aug 2019 15:10:50 +0000 (17:10 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Sat, 17 Aug 2019 10:24:34 +0000 (12:24 +0200)
So far, we don't need to create anything under
/sys/kernel/iommu_groups/N/devices directory (which is symlinked
from /sys/bus/pci/devices/DDDD:BB:DD.F/iommu_group directory)
because virhostdevtest still tests the old KVM assignment and
thus has no notion of IOMMU groups. This will change in near
future though. And in order to discover devices belonging to the
same IOMMU group we need to do what kernel does - create symlinks
to devices.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Tested-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
tests/virpcimock.c

index 80ef4809abc3e269992284584c9bbde365eb9e99..09a6c648af56152f9239ce725c6b18b47950ca32 100644 (file)
@@ -401,6 +401,30 @@ pci_device_get_path(const struct pciDevice *dev,
 }
 
 
+static void
+pci_device_create_iommu(const struct pciDevice *dev,
+                        const char *devid)
+{
+    VIR_AUTOFREE(char *) iommuPath = NULL;
+    char tmp[256];
+
+    if (virAsprintfQuiet(&iommuPath, "%s/sys/kernel/iommu_groups/%d/devices/",
+                         fakerootdir, dev->iommuGroup) < 0)
+        ABORT_OOM();
+
+    if (virFileMakePath(iommuPath) < 0)
+        ABORT("Unable to create: %s", iommuPath);
+
+    if (snprintf(tmp, sizeof(tmp),
+                 "../../../../devices/pci%04x:%02x/%s",
+                 dev->addr.domain, dev->addr.bus, devid) < 0) {
+        ABORT("@tmp overflow");
+    }
+
+    make_symlink(iommuPath, devid, tmp);
+}
+
+
 static void
 pci_device_new_from_stub(const struct pciDevice *data)
 {
@@ -481,13 +505,7 @@ pci_device_new_from_stub(const struct pciDevice *data)
 
     make_file(devpath, "driver_override", NULL, -1);
 
-    if (snprintf(tmp, sizeof(tmp),
-                 "%s/../../../kernel/iommu_groups/%d",
-                 devpath, dev->iommuGroup) < 0) {
-        ABORT("@tmp overflow");
-    }
-    if (virFileMakePath(tmp) < 0)
-        ABORT("Unable to create %s", tmp);
+    pci_device_create_iommu(dev, devid);
 
     if (snprintf(tmp, sizeof(tmp),
                  "../../../kernel/iommu_groups/%d", dev->iommuGroup) < 0) {