Revert "Adjust lock acquiring logic"
This reverts commit cbb9121a28
.
Reason for revert: reverting as this caused issues in DC upgrade
Change-Id: Ie665b9c4e4d1280d7c8a0821cb7995c9374ce02f
This commit is contained in:
parent
cbb9121a28
commit
ca6a15adff
|
@ -34,6 +34,7 @@ Commands (from conductors) are received via RPC calls.
|
|||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
import errno
|
||||
from eventlet.green import subprocess
|
||||
import fcntl
|
||||
import fileinput
|
||||
|
@ -582,7 +583,25 @@ class AgentManager(service.PeriodicService):
|
|||
"""
|
||||
lock_file_fd = os.open(
|
||||
constants.NETWORK_CONFIG_LOCK_FILE, os.O_CREAT | os.O_RDONLY)
|
||||
return utils.acquire_file_lock(lock_file_fd)
|
||||
count = 1
|
||||
delay = 5
|
||||
max_count = 5
|
||||
while count <= max_count:
|
||||
try:
|
||||
fcntl.flock(lock_file_fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
return lock_file_fd
|
||||
except IOError as e:
|
||||
# raise on unrelated IOErrors
|
||||
if e.errno != errno.EAGAIN:
|
||||
raise
|
||||
else:
|
||||
LOG.info("Could not acquire lock({}): {} ({}/{}), "
|
||||
"will retry".format(lock_file_fd, str(e),
|
||||
count, max_count))
|
||||
time.sleep(delay)
|
||||
count += 1
|
||||
LOG.error("Failed to acquire lock (fd={})".format(lock_file_fd))
|
||||
return 0
|
||||
|
||||
def _release_network_config_lock(self, lockfd):
|
||||
""" Release the lock guarding apply_network_config.sh """
|
||||
|
|
|
@ -1372,34 +1372,6 @@ def _get_cinder_device_info(dbapi, forihostid):
|
|||
return cinder_device, cinder_size_gib
|
||||
|
||||
|
||||
def acquire_file_lock(lockfd, max_retry=5, wait_interval=5):
|
||||
"""
|
||||
This method is to acquire a lock for the given file descriptor to
|
||||
avoid conflict with other processes trying accessing the same file.
|
||||
|
||||
:returns: fd of the lock, if successful. 0 on error.
|
||||
"""
|
||||
count = 1
|
||||
while count <= max_retry:
|
||||
try:
|
||||
fcntl.flock(lockfd, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
LOG.debug("Successfully acquired lock (fd={})".format(lockfd))
|
||||
return lockfd
|
||||
except IOError as e:
|
||||
# raise on unrelated IOErrors
|
||||
if e.errno != errno.EAGAIN:
|
||||
raise
|
||||
else:
|
||||
LOG.info("Could not acquire lock({}): {} ({}/{}), "
|
||||
"will retry".format(lockfd, str(e),
|
||||
count, max_retry))
|
||||
time.sleep(wait_interval)
|
||||
count += 1
|
||||
|
||||
LOG.error("Failed to acquire lock (fd={}). Stop trying...".format(lockfd))
|
||||
return 0
|
||||
|
||||
|
||||
def skip_udev_partition_probe(function):
|
||||
def wrapper(*args, **kwargs):
|
||||
"""Decorator to skip partition rescanning in udev
|
||||
|
@ -1427,7 +1399,7 @@ def skip_udev_partition_probe(function):
|
|||
device_node = kwargs.get('device_node', None)
|
||||
if device_node:
|
||||
with open(device_node, 'r') as f:
|
||||
acquire_file_lock(f)
|
||||
fcntl.flock(f, fcntl.LOCK_SH | fcntl.LOCK_NB)
|
||||
try:
|
||||
return function(*args, **kwargs)
|
||||
finally:
|
||||
|
|
Loading…
Reference in New Issue