Skip to content

Commit

Permalink
initial controller id range in omap
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Indenbaum <[email protected]>
  • Loading branch information
Alexander Indenbaum committed Sep 10, 2023
1 parent bf23372 commit 69db8d8
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 85 deletions.
31 changes: 16 additions & 15 deletions control/grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ def __init__(self, config: GatewayConfig, gateway_state: GatewayStateHandler,
self.config = config
self.gateway_state = gateway_state
self.spdk_rpc_client = spdk_rpc_client

self.gateway_name = self.config.get("gateway", "name")
if not self.gateway_name:
self.gateway_name = socket.gethostname()

self.min_cntlid, self.max_cntlid = gateway_state.state.ranges.controllerid_range(self.gateway_name)
self.logger.info(f"Created GatewayService {self.gateway_name}"
f" {self.min_cntlid=} {self.max_cntlid=}")

def create_bdev(self, request, context=None):
"""Creates a bdev from an RBD image."""

Expand Down Expand Up @@ -86,7 +89,7 @@ def create_bdev(self, request, context=None):
try:
json_req = json_format.MessageToJson(
request, preserving_proto_field_name=True)
self.gateway_state.omap.add_bdev(bdev_name, json_req)
self.gateway_state.state.spdk.add_bdev(bdev_name, json_req)
except Exception as ex:
self.logger.error(
f"Error persisting create_bdev {bdev_name}: {ex}")
Expand Down Expand Up @@ -145,7 +148,7 @@ def delete_bdev(self, request, context=None):
if context:
# Update gateway state
try:
self.gateway_state.omap.remove_bdev(request.bdev_name)
self.gateway_state.state.spdk.remove_bdev(request.bdev_name)
except Exception as ex:
self.logger.error(
f"Error persisting delete_bdev {request.bdev_name}: {ex}")
Expand All @@ -158,8 +161,6 @@ def create_subsystem(self, request, context=None):

self.logger.info(
f"Received request to create subsystem {request.subsystem_nqn}")
min_cntlid = self.config.getint_with_default("gateway", "min_controller_id", 1)
max_cntlid = self.config.getint_with_default("gateway", "max_controller_id", 65519)
if not request.serial_number:
random.seed()
randser = random.randint(2, 99999999999999)
Expand All @@ -170,8 +171,8 @@ def create_subsystem(self, request, context=None):
nqn=request.subsystem_nqn,
serial_number=request.serial_number,
max_namespaces=request.max_namespaces,
min_cntlid=min_cntlid,
max_cntlid=max_cntlid,
min_cntlid=self.min_cntlid,
max_cntlid=self.max_cntlid,
)
self.logger.info(f"create_subsystem {request.subsystem_nqn}: {ret}")
except Exception as ex:
Expand All @@ -186,7 +187,7 @@ def create_subsystem(self, request, context=None):
try:
json_req = json_format.MessageToJson(
request, preserving_proto_field_name=True)
self.gateway_state.omap.add_subsystem(request.subsystem_nqn,
self.gateway_state.state.spdk.add_subsystem(request.subsystem_nqn,
json_req)
except Exception as ex:
self.logger.error(f"Error persisting create_subsystem"
Expand Down Expand Up @@ -216,7 +217,7 @@ def delete_subsystem(self, request, context=None):
if context:
# Update gateway state
try:
self.gateway_state.omap.remove_subsystem(request.subsystem_nqn)
self.gateway_state.state.spdk.remove_subsystem(request.subsystem_nqn)
except Exception as ex:
self.logger.error(f"Error persisting delete_subsystem"
f" {request.subsystem_nqn}: {ex}")
Expand Down Expand Up @@ -251,7 +252,7 @@ def add_namespace(self, request, context=None):
request.nsid = nsid
json_req = json_format.MessageToJson(
request, preserving_proto_field_name=True)
self.gateway_state.omap.add_namespace(request.subsystem_nqn,
self.gateway_state.state.spdk.add_namespace(request.subsystem_nqn,
str(nsid), json_req)
except Exception as ex:
self.logger.error(
Expand Down Expand Up @@ -282,7 +283,7 @@ def remove_namespace(self, request, context=None):
if context:
# Update gateway state
try:
self.gateway_state.omap.remove_namespace(request.subsystem_nqn,
self.gateway_state.state.spdk.remove_namespace(request.subsystem_nqn,
str(request.nsid))
except Exception as ex:
self.logger.error(
Expand Down Expand Up @@ -326,7 +327,7 @@ def add_host(self, request, context=None):
try:
json_req = json_format.MessageToJson(
request, preserving_proto_field_name=True)
self.gateway_state.omap.add_host(request.subsystem_nqn,
self.gateway_state.state.spdk.add_host(request.subsystem_nqn,
request.host_nqn, json_req)
except Exception as ex:
self.logger.error(
Expand Down Expand Up @@ -369,7 +370,7 @@ def remove_host(self, request, context=None):
if context:
# Update gateway state
try:
self.gateway_state.omap.remove_host(request.subsystem_nqn,
self.gateway_state.state.spdk.remove_host(request.subsystem_nqn,
request.host_nqn)
except Exception as ex:
self.logger.error(f"Error persisting remove_host: {ex}")
Expand Down Expand Up @@ -410,7 +411,7 @@ def create_listener(self, request, context=None):
try:
json_req = json_format.MessageToJson(
request, preserving_proto_field_name=True)
self.gateway_state.omap.add_listener(request.nqn,
self.gateway_state.state.spdk.add_listener(request.nqn,
request.gateway_name,
request.trtype, request.traddr,
request.trsvcid, json_req)
Expand Down Expand Up @@ -452,7 +453,7 @@ def delete_listener(self, request, context=None):
if context:
# Update gateway state
try:
self.gateway_state.omap.remove_listener(request.nqn,
self.gateway_state.state.spdk.remove_listener(request.nqn,
request.gateway_name,
request.trtype,
request.traddr,
Expand Down
26 changes: 21 additions & 5 deletions control/omap.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,33 @@
import logging
import rados
from typing import Dict
from collections import defaultdict


class OmapObject:
"""Class representing versioned omap object"""
"""Class representing a versioned OMAP object
Methods:
get(): Returns dict of all OMAP keys and values
delete(): Deletes OMAP object contents
add_key(): Adds key and value to the OMAP
remove_key(): Removes key from the OMAP
register_watch(): Sets a watch on the OMAP object for changes
"""
OMAP_VERSION_KEY = "omap_version"

"""
Instance attributes:
name: OMAP object name
version: OMAP object version
cached_object: last read cache copy of the object
logger: Logger instance to track OMAP access events
ioctx: I/O context which allows OMAP access
watch: OMAP change notification
"""
def __init__(self, name, ioctx) -> None:
self.version = 1
self.watch = None
self.cached_object = defaultdict(dict)
self.cached = {}
self.name = name
self.logger = logging.getLogger(__name__)
self.ioctx = ioctx
Expand Down Expand Up @@ -78,8 +94,8 @@ def add_key(self, key: str, val: str) -> None:
self.ioctx.operate_write_op(write_op, self.name)
self.version = version_update
self.logger.debug(f"omap_key generated: {key}")
except Exception as ex:
self.logger.error(f"Unable to add key to omap: {ex}. Exiting!")
except Exception:
self.logger.exception(f"Unable to add {key=} {val=} to omap:")
raise

self._notify()
Expand Down
Loading

0 comments on commit 69db8d8

Please sign in to comment.