Skip to content

Commit

Permalink
Merge pull request #629 from gbregman/devel
Browse files Browse the repository at this point in the history
Fail namespace creation if passed load balancing group doesn't exist
  • Loading branch information
gbregman authored May 9, 2024
2 parents 8fecf04 + 296afde commit f44f2ab
Show file tree
Hide file tree
Showing 10 changed files with 272 additions and 156 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
strategy:
fail-fast: false
matrix:
test: ["cli", "state", "multi_gateway", "server", "grpc", "omap_lock", "old_omap", "log_files", "nsid", "namespaces"]
test: ["cli", "cli_change_lb", "state", "multi_gateway", "server", "grpc", "omap_lock", "old_omap", "log_files", "nsid", "namespaces"]
runs-on: ubuntu-latest
env:
HUGEPAGES: 512 # for multi gateway test, approx 256 per gateway instance
Expand Down
2 changes: 2 additions & 0 deletions control/cephutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ def __init__(self, config):
self.last_sent = time.time()

def execute_ceph_monitor_command(self, cmd):
self.logger.debug(f"Execute monitor command: {cmd}")
with rados.Rados(conffile=self.ceph_conf, rados_id=self.rados_id) as cluster:
rply = cluster.mon_command(cmd, b'')
self.logger.debug(f"Monitor reply: {rply}")
return rply

def get_number_created_gateways(self, pool, group):
Expand Down
21 changes: 18 additions & 3 deletions control/grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ def create_subsystem_safe(self, request, context):
peer_msg = self.get_peer_message(context)

self.logger.info(
f"Received request to create subsystem {request.subsystem_nqn}, enable_ha: {request.enable_ha}, context: {context}{peer_msg}")
f"Received request to create subsystem {request.subsystem_nqn}, enable_ha: {request.enable_ha}, max_namespaces: {request.max_namespaces}, context: {context}{peer_msg}")

if not request.enable_ha:
errmsg = f"{create_subsystem_error_prefix}: HA must be enabled for subsystems"
Expand Down Expand Up @@ -592,7 +592,7 @@ def create_subsystem_safe(self, request, context):
ana_reporting = enable_ha,
)
self.subsys_ha[request.subsystem_nqn] = enable_ha
self.subsys_max_ns[request.subsystem_nqn] = request.max_namespaces if request.max_namespaces is not None else 32
self.subsys_max_ns[request.subsystem_nqn] = request.max_namespaces if request.max_namespaces else 32
self.logger.debug(f"create_subsystem {request.subsystem_nqn}: {ret}")
except Exception as ex:
self.logger.exception(create_subsystem_error_prefix)
Expand Down Expand Up @@ -957,8 +957,17 @@ def namespace_add_safe(self, request, context):
if not context:
create_image = False
else: # new namespace
if request.anagrpid == 0:
# If an explicit load balancing group was passed, make sure it exists
if request.anagrpid != 0:
grps_list = self.ceph_utils.get_number_created_gateways(self.gateway_pool, self.gateway_group)
if request.anagrpid not in grps_list:
self.logger.debug(f"ANA groups: {grps_list}")
errmsg = f"Failure adding namespace {nsid_msg}to {request.subsystem_nqn}: Load balancing group {request.anagrpid} doesn't exist"
self.logger.error(errmsg)
return pb2.req_status(status=errno.ENODEV, error_message=errmsg)
else:
anagrp = self.choose_anagrpid_for_namespace(request.nsid)
assert anagrp != 0
# if anagrp == 0:
# errmsg = f"Failure adding namespace with automatic ana group load balancing {nsid_msg} to {request.subsystem_nqn}"
# self.logger.error(errmsg)
Expand Down Expand Up @@ -1036,6 +1045,12 @@ def namespace_change_load_balancing_group_safe(self, request, context):
self.logger.info(f"Received request to change load balancing group for namespace {nsid_msg}in {request.subsystem_nqn} to {request.anagrpid}, context: {context}{peer_msg}")

with self.omap_lock(context=context):
grps_list = self.ceph_utils.get_number_created_gateways(self.gateway_pool, self.gateway_group)
if request.anagrpid not in grps_list:
self.logger.debug(f"ANA groups: {grps_list}")
errmsg = f"Failure changing load balancing group for namespace {nsid_msg}in {request.subsystem_nqn}: Load balancing group {request.anagrpid} doesn't exist"
self.logger.error(errmsg)
return pb2.req_status(status=errno.ENODEV, error_message=errmsg)
find_ret = self.find_namespace_and_bdev_name(request.subsystem_nqn, request.nsid, request.uuid, False,
f"Failure changing load balancing group for namespace {nsid_msg}in {request.subsystem_nqn}")
if not find_ret[0]:
Expand Down
Loading

0 comments on commit f44f2ab

Please sign in to comment.