From c6be2d18442274f7f6f989c333a4a72008f05ad7 Mon Sep 17 00:00:00 2001 From: Gil Bregman Date: Mon, 14 Oct 2024 12:02:16 +0300 Subject: [PATCH] Limit number of not-visible namespaces to 1000. Fixes #896 Signed-off-by: Gil Bregman --- control/grpc.py | 14 +++++++------- tests/test_cli.py | 9 ++++----- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/control/grpc.py b/control/grpc.py index 41c35c16..ff0994d8 100644 --- a/control/grpc.py +++ b/control/grpc.py @@ -1120,14 +1120,14 @@ def create_namespace(self, subsystem_nqn, bdev_name, nsid, anagrpid, uuid, no_au nsid_msg = "" if nsid: - nsid_msg = f" using NSID {nsid} " + nsid_msg = f" using NSID {nsid}" if not subsystem_nqn: errmsg = f"Failure adding namespace, missing subsystem NQN" self.logger.error(f"{errmsg}") return pb2.nsid_status(status=errno.EINVAL, error_message = errmsg) - add_namespace_error_prefix = f"Failure adding namespace{nsid_msg}to {subsystem_nqn}" + add_namespace_error_prefix = f"Failure adding namespace{nsid_msg} to {subsystem_nqn}" peer_msg = self.get_peer_message(context) self.logger.info(f"Received request to add {bdev_name} to {subsystem_nqn} with ANA group id {anagrpid}{nsid_msg}, no_auto_visible: {no_auto_visible}, context: {context}{peer_msg}") @@ -1142,6 +1142,11 @@ def create_namespace(self, subsystem_nqn, bdev_name, nsid, anagrpid, uuid, no_au self.logger.error(errmsg) return pb2.nsid_status(status=errno.EINVAL, error_message=errmsg) + if self.subsystem_nsid_bdev_and_uuid.get_namespace_count(subsystem_nqn, True, 0) >= self.max_namespaces_with_netmask: + errmsg = f"Failure adding namespace{nsid_msg} to {subsystem_nqn}, maximal number of namespaces which are not auto visible ({self.max_namespaces_with_netmask}) was already reached" + self.logger.error(f"{errmsg}") + return pb2.req_status(status=errno.E2BIG, error_message=errmsg) + try: nsid = rpc_nvmf.nvmf_subsystem_add_ns( self.spdk_rpc_client, @@ -2054,11 +2059,6 @@ def namespace_add_host_safe(self, request, context): self.logger.error(f"{errmsg}") return pb2.req_status(status=errno.EINVAL, error_message=errmsg) - if self.subsystem_nsid_bdev_and_uuid.get_namespace_count(request.subsystem_nqn, True, 1) >= self.max_namespaces_with_netmask: - errmsg = f"Failure adding host {request.host_nqn} to namespace {request.nsid} on {request.subsystem_nqn}, maximal number of namespaces with a host list ({self.max_namespaces_with_netmask}) was already reached" - self.logger.error(f"{errmsg}") - return pb2.req_status(status=errno.E2BIG, error_message=errmsg) - find_ret = self.subsystem_nsid_bdev_and_uuid.find_namespace(request.subsystem_nqn, request.nsid) if not find_ret.empty(): if not find_ret.no_auto_visible: diff --git a/tests/test_cli.py b/tests/test_cli.py index 0f209fcb..a7fc976c 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -18,6 +18,7 @@ image5 = "mytestdevimage5" image6 = "mytestdevimage6" image7 = "mytestdevimage7" +image8 = "mytestdevimage8" pool = "rbd" subsystem = "nqn.2016-06.io.spdk:cnode1" subsystem2 = "nqn.2016-06.io.spdk:cnode2" @@ -53,7 +54,7 @@ def gateway(config): addr = config.get("gateway", "addr") port = config.getint("gateway", "port") config.config["gateway"]["group"] = group_name - config.config["gateway"]["max_namespaces_with_netmask"] = "2" + config.config["gateway"]["max_namespaces_with_netmask"] = "3" config.config["gateway-logs"]["log_level"] = "debug" ceph_utils = CephUtils(config) @@ -491,10 +492,8 @@ def test_add_host_to_wrong_namespace(self, caplog, gateway): def test_add_too_many_namespaces_with_hosts(self, caplog, gateway): caplog.clear() - cli(["namespace", "add_host", "--subsystem", subsystem, "--nsid", "9", "--host-nqn", "nqn.2016-06.io.spdk:host11"]) - assert f"Adding host nqn.2016-06.io.spdk:host11 to namespace 9 on {subsystem}: Successful" in caplog.text - cli(["namespace", "add_host", "--subsystem", subsystem, "--nsid", "10", "--host-nqn", "nqn.2016-06.io.spdk:host12"]) - assert f"Failure adding host nqn.2016-06.io.spdk:host12 to namespace 10 on {subsystem}, maximal number of namespaces with a host list (2) was already reached" in caplog.text + cli(["namespace", "add", "--subsystem", subsystem, "--rbd-pool", pool, "--rbd-image", image8, "--size", "16MB", "--rbd-create-image", "--no-auto-visible"]) + assert f"Failure adding namespace to {subsystem}, maximal number of namespaces which are not auto visible (3) was already reached" in caplog.text def test_list_namespace_with_hosts(self, caplog, gateway): caplog.clear()