From 2c9244668becc0dc1c5f7c05cd441995486fa2bd Mon Sep 17 00:00:00 2001 From: Alexander Indenbaum Date: Mon, 8 Jan 2024 23:59:27 +0200 Subject: [PATCH] Nonce in get subsystems Signed-off-by: Alexander Indenbaum --- .gitmodules | 2 +- control/grpc.py | 25 ++++++++++++++++++++++--- control/proto/gateway.proto | 1 + spdk | 2 +- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/.gitmodules b/.gitmodules index 909aa148..b0f45b43 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ [submodule "spdk"] path = spdk - url = https://github.com/ceph/spdk.git + url = https://github.com/baum/spdk.git branch = ceph-nvmeof diff --git a/control/grpc.py b/control/grpc.py index 9e830400..93eb9ec8 100644 --- a/control/grpc.py +++ b/control/grpc.py @@ -120,6 +120,10 @@ def __init__(self, config: GatewayConfig, gateway_state: GatewayStateHandler, om self.spdk_rpc_client = spdk_rpc_client self.gateway_name = self.config.get("gateway", "name") self.ana_map = defaultdict(dict) + self.cluster_nonce = {} + self.bdev_cluster = {} + self.subsystem_nsid_bdev = defaultdict(dict) + self.subsystem_nsid_anagrp = defaultdict(dict) if not self.gateway_name: self.gateway_name = socket.gethostname() @@ -157,13 +161,14 @@ def _get_cluster(self) -> str: def _alloc_cluster(self) -> str: """Allocates a new Rados cluster context""" name = f"cluster_context_{len(self.clusters)}" - self.logger.info(f"Allocating cluster {name=}") - rpc_bdev.bdev_rbd_register_cluster( + nonce = rpc_bdev.bdev_rbd_register_cluster( self.spdk_rpc_client, name = name, user = self.rados_id, core_mask = self.librbd_core_mask, ) + self.logger.info(f"Allocated cluster {name=} {nonce=}") + self.cluster_nonce[name] = nonce return name def _grpc_function_with_lock(self, func, request, context): @@ -189,16 +194,19 @@ def create_bdev_safe(self, request, context=None): f" with block size {request.block_size}, context: {context}") with self.omap_lock(context=context): try: + cluster_name=self._get_cluster() bdev_name = rpc_bdev.bdev_rbd_create( self.spdk_rpc_client, name=name, - cluster_name=self._get_cluster(), + cluster_name=cluster_name, pool_name=request.rbd_pool_name, rbd_name=request.rbd_image_name, block_size=request.block_size, uuid=request.uuid, ) + self.bdev_cluster[name] = cluster_name self.logger.info(f"create_bdev: {bdev_name}") + except Exception as ex: self.logger.error(f"create_bdev failed with: \n {ex}") if context: @@ -474,6 +482,8 @@ def add_namespace_safe(self, request, context=None): nsid=request.nsid, anagrpid=request.anagrpid, ) + self.subsystem_nsid_bdev[request.subsystem_nqn][nsid] = request.bdev_name + self.subsystem_nsid_anagrp[request.subsystem_nqn][nsid] = request.anagrpid self.logger.info(f"add_namespace: {nsid}") except Exception as ex: self.logger.error(f"add_namespace failed with: \n {ex}") @@ -956,6 +966,15 @@ def get_subsystems_safe(self, request, context): addr["adrfam"] = addr["adrfam"].lower() except Exception: pass + ns_key = "namespaces" + if ns_key in s: + for n in s[ns_key]: + nqn = s["nqn"] + nsid = n["nsid"] + n["anagrpid"] = self.subsystem_nsid_anagrp[nqn][nsid] + bdev = self.subsystem_nsid_bdev[nqn][nsid] + nonce = self.cluster_nonce[self.bdev_cluster[bdev]] + n["nonce"] = nonce # Parse the JSON dictionary into the protobuf message subsystem = pb2.subsystem() json_format.Parse(json.dumps(s), subsystem) diff --git a/control/proto/gateway.proto b/control/proto/gateway.proto index 4095d728..708054e5 100644 --- a/control/proto/gateway.proto +++ b/control/proto/gateway.proto @@ -281,6 +281,7 @@ message namespace { optional string nguid = 4; optional string uuid = 5; optional uint32 anagrpid = 6; + optional string nonce = 7; } message spdk_nvmf_log_flags_and_level_info { diff --git a/spdk b/spdk index 668268f7..6769b6f5 160000 --- a/spdk +++ b/spdk @@ -1 +1 @@ -Subproject commit 668268f74ea147f3343b9f8136df3e6fcc61f4cf +Subproject commit 6769b6f51c9508981243042396ec2b2f097a5745