Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit number of not-visible namespaces to 1000 #897

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions control/grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand All @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 4 additions & 5 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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()
Expand Down
Loading