Use flock() instead of fcntl()

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

 



Hi,

we are interested in using virtlockd on an OCFS2 shared filesystem.
We are now facing the problem that virtlockd uses fcntl() locks which 
aren't supported by OCFS2 with the o2cb cluster stack and we want 
to avoid using indirect leases.

OCFS2 instead supports flock() which is quite similar to fcntl(). I 
attached a patch which makes libvirt use flock() *instead* of fcntl() 
and it seems to work.

NFS on the contrast only supports fcntl() so it should be configurable 
which lock type to use.

I'm not very experienced with locking, so would such a patch be
acceptable or do you see possible problems with it?

Cheers,
David



>From b823a9a9bd60a870d64341c4273c42d4eeba8d9b Mon Sep 17 00:00:00 2001
From: David Weber <wb@xxxxxxxxxxxx>
Date: Thu, 25 Jul 2013 08:20:20 +0000
Subject: [PATCH] Use flock() instead of fcntl()

---
 src/util/virfile.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/util/virfile.c b/src/util/virfile.c
index 8f0eec3..e243c26 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
                    int virFileLock(int fd, bool shared, off_t start, off_t len)
         .l_len = len,
     };
 
-    if (fcntl(fd, F_SETLK, &fl) < 0)
+    if (flock(fd, LOCK_EX | LOCK_NB) < 0)
         return -errno;
 
     return 0;
                    int virFileUnlock(int fd, off_t start, off_t len)
         .l_len = len,
     };
 
-    if (fcntl(fd, F_SETLK, &fl) < 0)
+    if (flock(fd, LOCK_UN) < 0)
         return -errno;
 
     return 0;
-- 
1.8.1.5

Attachment: 0001-Use-flock-instead-of-fcntl.patch
Description: Binary data

--
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]