WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-4.0-testing] Remus: add file locking and modprobe u

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-4.0-testing] Remus: add file locking and modprobe utility functions
From: "Xen patchbot-4.0-testing" <patchbot-4.0-testing@xxxxxxxxxxxxxxxxxxx>
Date: Mon, 21 Jun 2010 23:35:31 -0700
Delivery-date: Mon, 21 Jun 2010 23:37:09 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1277188199 -3600
# Node ID 95f9be32fabfe33b05c2c7cbffabf1f1e3d67db9
# Parent  1d09d8eecc3aa002d51a9ffd0bc5c1bd0ce67ad3
Remus: add file locking and modprobe utility functions

Signed-off-by: Brendan Cully <brendan@xxxxxxxxx>
xen-unstable changeset:   21243:ca9519f09563
xen-unstable date:        Tue May 04 09:35:42 2010 +0100
---
 tools/python/xen/remus/util.py |   51 ++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 50 insertions(+), 1 deletion(-)

diff -r 1d09d8eecc3a -r 95f9be32fabf tools/python/xen/remus/util.py
--- a/tools/python/xen/remus/util.py    Tue Jun 22 07:29:26 2010 +0100
+++ b/tools/python/xen/remus/util.py    Tue Jun 22 07:29:59 2010 +0100
@@ -1,6 +1,6 @@
 # utility functions
 
-import os, subprocess
+import fcntl, os, subprocess
 
 class PipeException(Exception):
     def __init__(self, message, errno):
@@ -8,8 +8,49 @@ class PipeException(Exception):
         message = '%s: %d, %s' % (message, errno, os.strerror(errno))
         Exception.__init__(self, message)
 
+class Lock(object):
+    """advisory lock"""
+
+    def __init__(self, filename):
+        """lock using filename for synchronization"""
+        self.filename = filename + '.lock'
+
+        self.fd = None
+
+        self.lock()
+
+    def __del__(self):
+        self.unlock()
+
+    def lock(self):
+        if self.fd:
+            return
+
+        self.fd = open(self.filename, 'w')
+        fcntl.lockf(self.fd, fcntl.LOCK_EX)
+
+    def unlock(self):
+        if not self.fd:
+            return
+
+        fcntl.lockf(self.fd, fcntl.LOCK_UN)
+        self.fd = None
+        try:
+            os.remove(self.filename)
+        except OSError:
+            # harmless race
+            pass
+
 def canonifymac(mac):
     return ':'.join(['%02x' % int(field, 16) for field in mac.split(':')])
+
+def checkpid(pid):
+    """return True if pid is live"""
+    try:
+        os.kill(pid, 0)
+        return True
+    except OSError:
+        return False
 
 def runcmd(args, cwd=None):
     # TODO: stdin handling
@@ -29,3 +70,11 @@ def runcmd(args, cwd=None):
         return stdout
     except (OSError, IOError), inst:
         raise PipeException('could not run %s' % args[0], inst.errno)
+
+def modprobe(modname):
+    """attempt to load kernel module modname"""
+    try:
+        runcmd(['modprobe', '-q', modname])
+        return True
+    except PipeException:
+        return False

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-4.0-testing] Remus: add file locking and modprobe utility functions, Xen patchbot-4.0-testing <=