self.fn = fn
self.fd = None
- def acquire(self):
+ def __enter__(self):
assert not self.fd
self.fd = os.open(self.fn, os.O_WRONLY | os.O_CREAT)
fcntl.lockf(self.fd, fcntl.LOCK_EX)
- def release(self):
+ def __exit__(self, exc_type, exc_val, exc_tb):
assert self.fd
fcntl.lockf(self.fd, fcntl.LOCK_UN)
os.close(self.fd)
return parser
def prepare(self):
- prepare_lock.acquire()
- self.prepare_locked()
- prepare_lock.release()
+ with prepare_lock:
+ self.prepare_locked()
@staticmethod
def factory(args):
LOG.info('suppressed activate request on %s', args.path)
return
- activate_lock.acquire() # noqa
- try:
+ with activate_lock:
mode = os.stat(args.path).st_mode
if stat.S_ISBLK(mode):
if (is_partition(args.path) and
osd_id=osd_id,
)
- finally:
- activate_lock.release() # noqa
-
def main_activate_lockbox(args):
- activate_lock.acquire() # noqa
- try:
+ with activate_lock:
main_activate_lockbox_protected(args)
- finally:
- activate_lock.release() # noqa
def main_activate_lockbox_protected(args):
def main_deactivate(args):
- activate_lock.acquire() # noqa
- try:
+ with activate_lock:
main_deactivate_locked(args)
- finally:
- activate_lock.release() # noqa
def main_deactivate_locked(args):
def main_destroy(args):
- activate_lock.acquire() # noqa
- try:
+ with activate_lock:
main_destroy_locked(args)
- finally:
- activate_lock.release() # noqa
def main_destroy_locked(args):
osd_id = None
osd_uuid = None
dev = None
- activate_lock.acquire() # noqa
- try:
+ with activate_lock:
if args.dmcrypt:
dev = dmcrypt_map(args.dev, args.dmcrypt_key_dir)
else:
osd_id=osd_id,
)
- finally:
- activate_lock.release() # noqa
-
###########################
continue
LOG.info('Activating %s', path)
- activate_lock.acquire() # noqa
- try:
- # never map dmcrypt cyphertext devices
- (cluster, osd_id) = mount_activate(
- dev=path,
- activate_key_template=args.activate_key_template,
- init=args.mark_init,
- dmcrypt=False,
- dmcrypt_key_dir='',
- )
- start_daemon(
- cluster=cluster,
- osd_id=osd_id,
- )
-
- except Exception as e:
- print(
- '{prog}: {msg}'.format(prog=args.prog, msg=e),
- file=sys.stderr
- )
-
- err = True
+ with activate_lock:
+ try:
+ # never map dmcrypt cyphertext devices
+ (cluster, osd_id) = mount_activate(
+ dev=path,
+ activate_key_template=args.activate_key_template,
+ init=args.mark_init,
+ dmcrypt=False,
+ dmcrypt_key_dir='',
+ )
+ start_daemon(
+ cluster=cluster,
+ osd_id=osd_id,
+ )
+
+ except Exception as e:
+ print(
+ '{prog}: {msg}'.format(prog=args.prog, msg=e),
+ file=sys.stderr
+ )
+
+ err = True
- finally:
- activate_lock.release() # noqa
if err:
raise Error('One or more partitions failed to activate')
def main_list(args):
- activate_lock.acquire() # noqa
- try:
+ with activate_lock:
main_list_protected(args)
- finally:
- activate_lock.release() # noqa
def main_list_protected(args):