Skip to content

Commit

Permalink
Merge pull request #836 from gbregman/devel
Browse files Browse the repository at this point in the history
Unlock OMAP on exit
  • Loading branch information
gbregman authored Aug 29, 2024
2 parents 2d77886 + b7d76cf commit de77dac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
7 changes: 4 additions & 3 deletions control/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def __init__(self, config: GatewayConfig):
self.group_id = 0
self.monitor_client = '/usr/bin/ceph-nvmeof-monitor-client'
self.omap_state = None
self.omap_lock = None

self.name = self.config.get("gateway", "name")
if not self.name:
Expand Down Expand Up @@ -120,7 +121,7 @@ def __exit__(self, exc_type, exc_value, traceback):
self._stop_discovery()

if self.omap_state:
self.omap_state.cleanup_omap()
self.omap_state.cleanup_omap(self.omap_lock)
self.omap_state = None

if logger:
Expand Down Expand Up @@ -172,8 +173,8 @@ def serve(self):

# Register service implementation with server
gateway_state = GatewayStateHandler(self.config, local_state, omap_state, self.gateway_rpc_caller, f"gateway-{self.name}")
omap_lock = OmapLock(omap_state, gateway_state, self.rpc_lock)
self.gateway_rpc = GatewayService(self.config, gateway_state, self.rpc_lock, omap_lock, self.group_id, self.spdk_rpc_client, self.ceph_utils)
self.omap_lock = OmapLock(omap_state, gateway_state, self.rpc_lock)
self.gateway_rpc = GatewayService(self.config, gateway_state, self.rpc_lock, self.omap_lock, self.group_id, self.spdk_rpc_client, self.ceph_utils)
self.server = self._grpc_server(self._gateway_address())
pb2_grpc.add_GatewayServicer_to_server(self.gateway_rpc, self.server)

Expand Down
14 changes: 10 additions & 4 deletions control/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,17 +327,18 @@ def unlock_omap(self):
return

if not self.omap_state.ioctx:
self.is_locked = False
return

try:
self.omap_state.ioctx.unlock(self.omap_state.omap_name, self.OMAP_FILE_LOCK_NAME, self.OMAP_FILE_LOCK_COOKIE)
self.is_locked = False
except rados.ObjectNotFound as ex:
self.logger.warning(f"No such lock, the lock duration might have passed")
self.is_locked = False
if self.is_locked:
self.logger.warning(f"No such lock, the lock duration might have passed")
except Exception:
self.logger.exception(f"Unable to unlock OMAP file")
pass
self.is_locked = False

def locked(self):
return self.is_locked
Expand Down Expand Up @@ -543,7 +544,7 @@ def _watcher_callback(notify_id, notifier_id, watch_id, data):
else:
self.logger.info(f"Watch already exists.")

def cleanup_omap(self):
def cleanup_omap(self, omap_lock = None):
self.logger.info(f"Cleanup OMAP on exit ({self.id_text})")
if self.watch:
try:
Expand All @@ -552,6 +553,11 @@ def cleanup_omap(self):
self.watch = None
except Exception:
pass
if omap_lock and omap_lock.omap_file_lock_duration > 0:
try:
omap_lock.unlock_omap()
except Exceprion:
pass
if self.ioctx:
try:
self.ioctx.close()
Expand Down

0 comments on commit de77dac

Please sign in to comment.