[PATCH 05/10] util: Use virFileFlock() in virresctrl

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



That way we get rid of the last preprocessor conditional so the code compiles on
all platforms.

Signed-off-by: Martin Kletzander <mkletzan@xxxxxxxxxx>
---
 src/util/virresctrl.c | 31 ++++---------------------------
 1 file changed, 4 insertions(+), 27 deletions(-)

diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
index 787db31b6126..ef649a08bf73 100644
--- a/src/util/virresctrl.c
+++ b/src/util/virresctrl.c
@@ -289,9 +289,8 @@ virResctrlAllocNew(void)
 
 
 /* Common functions */
-#ifdef __linux__
 static int
-virResctrlLockInternal(int op)
+virResctrlLockWrite(void)
 {
     int fd = open(SYSFS_RESCTRL_PATH, O_DIRECTORY | O_CLOEXEC);
 
@@ -300,7 +299,7 @@ virResctrlLockInternal(int op)
         return -1;
     }
 
-    if (flock(fd, op) < 0) {
+    if (virFileFlock(fd, true, true) < 0) {
         virReportSystemError(errno, "%s", _("Cannot lock resctrl"));
         VIR_FORCE_CLOSE(fd);
         return -1;
@@ -310,45 +309,23 @@ virResctrlLockInternal(int op)
 }
 
 
-static inline int
-virResctrlLockWrite(void)
-{
-    return virResctrlLockInternal(LOCK_EX);
-}
-
-#else
-
-static inline int
-virResctrlLockWrite(void)
-{
-    virReportSystemError(ENOSYS, "%s",
-                         _("resctrl not supported on this platform"));
-    return -1;
-}
-
-#endif
-
-
-
-
 static int
 virResctrlUnlock(int fd)
 {
     if (fd == -1)
         return 0;
 
-#ifdef __linux__
     /* The lock gets unlocked by closing the fd, which we need to do anyway in
      * order to clean up properly */
     if (VIR_CLOSE(fd) < 0) {
         virReportSystemError(errno, "%s", _("Cannot close resctrl"));
 
         /* Trying to save the already broken */
-        if (flock(fd, LOCK_UN) < 0)
+        if (virFileFlock(fd, false, false) < 0)
             virReportSystemError(errno, "%s", _("Cannot unlock resctrl"));
+
         return -1;
     }
-#endif /* ! __linux__ */
 
     return 0;
 }
-- 
2.17.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux