diff options
author | Sage Weil <sage@inktank.com> | 2013-06-19 17:27:49 -0700 |
---|---|---|
committer | Sage Weil <sage@inktank.com> | 2013-06-26 18:42:29 -0700 |
commit | b2fb48762f32279e73feb83b220339fea31275e9 (patch) | |
tree | 2d8db619a491df9522645e10f52e3a9849c577b2 | |
parent | 26e7a6fffde4abcb685f34247e8491c05ee2a68d (diff) | |
download | ceph-b2fb48762f32279e73feb83b220339fea31275e9.tar.gz |
ceph-disk: use unix lock instead of lockfile class
The lockfile class relies on file system trickery to get safe mutual
exclusion. However, the unix syscalls do this for us. More
importantly, the unix locks go away when the owning process dies, which
is behavior that we want here.
Fixes: #5387
Backport: cuttlefish
Signed-off-by: Sage Weil <sage@inktank.com>
Reviewed-by: Dan Mick <dan.mick@inktank.com>
(cherry picked from commit 2a4953b697a3464862fd3913336edfd7eede2487)
-rwxr-xr-x | src/ceph-disk | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/ceph-disk b/src/ceph-disk index f13ab88d8df..0c1ffb965af 100755 --- a/src/ceph-disk +++ b/src/ceph-disk @@ -2,6 +2,7 @@ import argparse import errno +import fcntl import logging import os import os.path @@ -12,7 +13,6 @@ import stat import sys import tempfile import uuid -import lockfile """ Prepare: @@ -110,8 +110,30 @@ if LOG_NAME == '__main__': LOG_NAME = os.path.basename(sys.argv[0]) LOG = logging.getLogger(LOG_NAME) -prepare_lock = lockfile.FileLock('/var/lib/ceph/tmp/ceph-disk.prepare.lock') -activate_lock = lockfile.FileLock('/var/lib/ceph/tmp/ceph-disk.activate.lock') + + + +###### lock ######## + +class filelock(object): + def __init__(self, fn): + self.fn = fn + self.fd = None + + def acquire(self): + assert not self.fd + self.fd = file(self.fn, 'w') + fcntl.lockf(self.fd, fcntl.LOCK_EX) + + def release(self): + assert self.fd + fcntl.lockf(self.fd, fcntl.LOCK_UN) + self.fd = None + + +prepare_lock = filelock('/var/lib/ceph/tmp/ceph-disk.prepare.lock') +activate_lock = filelock('/var/lib/ceph/tmp/ceph-disk.activate.lock') + ###### exceptions ######## |