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

Martin Kletzander mkletzan at redhat.com
Thu Jun 7 13:54:26 UTC 2018


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

Signed-off-by: Martin Kletzander <mkletzan at redhat.com>
---
 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




More information about the libvir-list mailing list