]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: introduce readonly attribute to virPCIDeviceConfigOpenInternal
authorJán Tomko <jtomko@redhat.com>
Tue, 13 Aug 2019 13:11:14 +0000 (15:11 +0200)
committerJán Tomko <jtomko@redhat.com>
Wed, 14 Aug 2019 14:28:34 +0000 (16:28 +0200)
Allow wrappers to open PCI config as read-only.

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

index c1dad1e69f17091efd4be6e0ec6a25bfd847ffd4..e45dfbc6315bce63252bf5deed8482e998a708ff 100644 (file)
@@ -291,11 +291,11 @@ virPCIDeviceGetDriverPathAndName(virPCIDevicePtr dev, char **path, char **name)
 
 
 static int
-virPCIDeviceConfigOpenInternal(virPCIDevicePtr dev, bool fatal)
+virPCIDeviceConfigOpenInternal(virPCIDevicePtr dev, bool readonly, bool fatal)
 {
     int fd;
 
-    fd = open(dev->path, O_RDWR);
+    fd = open(dev->path, readonly ? O_RDONLY : O_RDWR);
 
     if (fd < 0) {
         if (fatal) {
@@ -317,13 +317,13 @@ virPCIDeviceConfigOpenInternal(virPCIDevicePtr dev, bool fatal)
 static int
 virPCIDeviceConfigOpen(virPCIDevicePtr dev, bool fatal)
 {
-    return virPCIDeviceConfigOpenInternal(dev, fatal);
+    return virPCIDeviceConfigOpenInternal(dev, false, fatal);
 }
 
 static int
 virPCIDeviceConfigOpenWrite(virPCIDevicePtr dev)
 {
-    return virPCIDeviceConfigOpenInternal(dev, true);
+    return virPCIDeviceConfigOpenInternal(dev, false, true);
 }
 
 static void