]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: Introduce virPCIDeviceConfigOpenWrite
authorJán Tomko <jtomko@redhat.com>
Tue, 13 Aug 2019 13:07:53 +0000 (15:07 +0200)
committerJán Tomko <jtomko@redhat.com>
Wed, 14 Aug 2019 14:28:34 +0000 (16:28 +0200)
Only a handful of function need write access to the PCI config
space. Create a wrapper function for those so that we can
open it read only by default.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/util/virpci.c

index f4be907a1049ffe2148ae1c17378bb0521c31d2e..c1dad1e69f17091efd4be6e0ec6a25bfd847ffd4 100644 (file)
@@ -320,6 +320,12 @@ virPCIDeviceConfigOpen(virPCIDevicePtr dev, bool fatal)
     return virPCIDeviceConfigOpenInternal(dev, fatal);
 }
 
+static int
+virPCIDeviceConfigOpenWrite(virPCIDevicePtr dev)
+{
+    return virPCIDeviceConfigOpenInternal(dev, true);
+}
+
 static void
 virPCIDeviceConfigClose(virPCIDevicePtr dev, int cfgfd)
 {
@@ -808,7 +814,7 @@ virPCIDeviceTrySecondaryBusReset(virPCIDevicePtr dev,
                        dev->name);
         return -1;
     }
-    if ((parentfd = virPCIDeviceConfigOpen(parent, true)) < 0)
+    if ((parentfd = virPCIDeviceConfigOpenWrite(parent)) < 0)
         goto out;
 
     VIR_DEBUG("%s %s: doing a secondary bus reset", dev->id, dev->name);
@@ -957,7 +963,7 @@ virPCIDeviceReset(virPCIDevicePtr dev,
     }
     VIR_DEBUG("Resetting device %s", dev->name);
 
-    if ((fd = virPCIDeviceConfigOpen(dev, true)) < 0)
+    if ((fd = virPCIDeviceConfigOpenWrite(dev)) < 0)
         goto cleanup;
 
     if (virPCIDeviceInit(dev, fd) < 0)