Skip to content

Commit

Permalink
Nonce in get subsystems
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Indenbaum <[email protected]>
  • Loading branch information
Alexander Indenbaum committed Jan 13, 2024
1 parent e060418 commit 2c92446
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -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
25 changes: 22 additions & 3 deletions control/grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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):
Expand All @@ -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:
Expand Down Expand Up @@ -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}")
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions control/proto/gateway.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion spdk

0 comments on commit 2c92446

Please sign in to comment.