From bbd9e4b56780e4107504883d0d8c25fa28e796cd Mon Sep 17 00:00:00 2001 From: Gil Bregman Date: Thu, 29 Aug 2024 10:49:48 +0300 Subject: [PATCH] Unlock OMAP on exit. Fixes #598 Signed-off-by: Gil Bregman --- control/server.py | 7 ++++--- control/state.py | 7 ++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/control/server.py b/control/server.py index 2899a210..2f3f4e3a 100644 --- a/control/server.py +++ b/control/server.py @@ -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: @@ -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: @@ -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) diff --git a/control/state.py b/control/state.py index 5bd38901..0d026234 100644 --- a/control/state.py +++ b/control/state.py @@ -543,7 +543,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: @@ -552,6 +552,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()