Patched with nm-disk-lock.patch provided by dhozac. Closes (or attempts to) [ticket...
authorFaiyaz Ahmed <faiyaza@cs.princeton.edu>
Wed, 17 Oct 2007 17:30:39 +0000 (17:30 +0000)
committerFaiyaz Ahmed <faiyaza@cs.princeton.edu>
Wed, 17 Oct 2007 17:30:39 +0000 (17:30 +0000)
sliver_vs.py
tools.py

index ca538c0..270f112 100644 (file)
@@ -18,7 +18,6 @@ don't have to guess if there is a running process or not.
 
 import errno
 import os
-import threading
 import time
 import vserver
 
@@ -43,7 +42,7 @@ class Sliver_VS(accounts.Account, vserver.VServer):
 
     SHELL = '/bin/vsh'
     TYPE = 'sliver.VServer'
-    _init_disk_info_sem = threading.Semaphore(1)
+    _init_disk_info_sem = tools.NMLock("/var/run/nm-disk-info.lock")
 
     def __init__(self, rec):
         try:
index f41f981..f4496e1 100644 (file)
--- a/tools.py
+++ b/tools.py
@@ -6,6 +6,7 @@ import os
 import pwd
 import tempfile
 import threading
+import fcntl
 
 import logger
 
@@ -88,3 +89,17 @@ def write_temp_file(do_write, mode=None, uidgid=None):
     try: do_write(f)
     finally: f.close()
     return temporary_filename
+
+
+class NMLock:
+    def __init__(self, file):
+        self.fd = os.open(file, os.O_RDWR|os.O_CREAT, 0600)
+        flags = fcntl.fcntl(self.fd, fcntl.F_GETFD)
+        flags |= fcntl.FD_CLOEXEC
+        fcntl.fcntl(self.fd, fcntl.F_SETFD, flags)
+    def __del__(self):
+        os.close(self.fd)
+    def acquire(self):
+        fcntl.lockf(self.fd, fcntl.LOCK_EX)
+    def release(self):
+        fcntl.lockf(self.fd, fcntl.LOCK_UN)