Coverage for drivers/lock : 69%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# # Copyright (C) Citrix Systems Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published # by the Free Software Foundation; version 2.1 only. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
"""Simple file-based lock on a local FS. With shared reader/writer attributes."""
else:
# These are required to pacify pylint as it doesn't understand the __new__ raise NotImplementedError("Lock methods implemented in LockImplementation")
raise NotImplementedError("Lock methods implemented in LockImplementation")
raise NotImplementedError("Lock methods implemented in LockImplementation")
raise NotImplementedError("Lock methods implemented in LockImplementation")
def clearAll(): """ Drop all lock instances, to be used when forking, but not execing """ Lock.INSTANCES = {} Lock.BASE_INSTANCES = {}
if name in Lock.INSTANCES[ns]: del Lock.INSTANCES[ns][name] if len(Lock.INSTANCES[ns]) == 0: del Lock.INSTANCES[ns] elif name in Lock.BASE_INSTANCES: del Lock.BASE_INSTANCES[name]
Lock._unlink(path)
ns = Lock._mknamespace(ns) nspath = os.path.join(Lock.BASE_DIR, ns)
if not os.path.exists(nspath): return
for file in os.listdir(nspath): path = os.path.join(nspath, file) Lock._unlink(path)
Lock._rmdir(nspath)
# # Lock and attribute file management #
"""Concurrent makedirs() catching EEXIST.""" except OSError, e: if e.errno != errno.EEXIST: raise LockException("Failed to makedirs(%s)" % path)
"""Non-raising unlink().""" util.SMlog("lock: unlinking lock file %s" % path) try: os.unlink(path) except Exception, e: util.SMlog("Failed to unlink(%s): %s" % (path, e))
"""Non-raising rmdir().""" util.SMlog("lock: removing lock dir %s" % path) try: os.rmdir(path) except Exception, e: util.SMlog("Failed to rmdir(%s): %s" % (path, e))
"""Create and open the lockable attribute base, if it doesn't exist. (But don't lock it yet.)"""
# one directory per namespace
# the lockfile inside that namespace directory per namespace
# If another lock within the namespace has already # cleaned up the namespace by removing the directory, # _open_lockfile raises an ENOENT, in this case we retry. raise
"""Provide a seam, so extreme situations could be tested"""
"""Close the lock, which implies releasing the lock.""" # drop all reference counts self.count = 0 self.release()
Lock.cleanup(name, ns)
Lock.cleanupAll(ns)
# # Actual Locking #
"""Blocking lock aquisition, with warnings. We don't expect to lock a lot. If so, not to collide. Coarse log statements should be ok and aid debugging.""" util.SMlog("Failed to lock %s on first attempt, " % self.lockpath + "blocked by PID %d" % self.lock.test()) self.lock.lock()
"""Acquire lock if possible, or return false if lock already held""" (self.lockpath, ret, exists)) else:
"""True if @self acquired the lock, False otherwise."""
"""Release a previously acquired lock."""
|