Browse Source

Merge "Revert "Adjust lock acquiring logic""

changes/87/786287/5
Zuul 2 months ago
committed by Gerrit Code Review
parent
commit
664ac9f621
2 changed files with 21 additions and 30 deletions
  1. +20
    -1
      sysinv/sysinv/sysinv/sysinv/agent/manager.py
  2. +1
    -29
      sysinv/sysinv/sysinv/sysinv/common/utils.py

+ 20
- 1
sysinv/sysinv/sysinv/sysinv/agent/manager.py View File

@ -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 """


+ 1
- 29
sysinv/sysinv/sysinv/sysinv/common/utils.py View File

@ -1370,34 +1370,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
@ -1425,7 +1397,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…
Cancel
Save