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

4gws fixes #587

Merged
merged 4 commits into from
Apr 17, 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
44 changes: 12 additions & 32 deletions control/grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,8 @@ def delete_subsystem_safe(self, request, context):
)
self.subsys_ha.pop(request.subsystem_nqn)
self.subsys_max_ns.pop(request.subsystem_nqn)
if request.subsystem_nqn in self.subsystem_listeners:
self.subsystem_listeners.pop(request.subsystem_nqn)
self.logger.debug(f"delete_subsystem {request.subsystem_nqn}: {ret}")
except Exception as ex:
self.logger.exception(delete_subsystem_error_prefix)
Expand Down Expand Up @@ -869,12 +871,11 @@ def set_ana_state_safe(self, ana_info: pb2.ana_info, context=None):
context.set_details(f"{ex}")
return pb2.req_status()
for ana_key in inaccessible_ana_groups :
with self.omap_lock(context=context):
ret_recycle = self.namespace_recycle_safe(ana_key, peer_msg)
if ret_recycle != 0:
errmsg = f"Failure recycle namespaces of ana group {ana_key} "
self.logger.error(errmsg)
return pb2.req_status(status=ret_recycle , error_message=errmsg)
ret_recycle = self.namespace_recycle_safe(ana_key, peer_msg)
if ret_recycle != 0:
errmsg = f"Failure recycle namespaces of ana group {ana_key} "
self.logger.error(errmsg)
return pb2.req_status(status=ret_recycle , error_message=errmsg)
return pb2.req_status(status=True)

def choose_anagrpid_for_namespace(self, nsid) ->int:
Expand Down Expand Up @@ -2044,30 +2045,11 @@ def get_subsystem_ha_status(self, nqn) -> bool:
self.logger.debug(f"Subsystem {nqn} enable_ha: {enable_ha}")
return enable_ha

def matching_listener_exists(self, context, nqn, traddr, trsvcid) -> bool:
if not context:
return False

state = self.gateway_state.local.get_state()
# We want to check for all the listeners for this address and port, regardless of the gateway
key_prefix = GatewayState.build_partial_listener_key(nqn)
key_suffix = GatewayState.build_listener_key_suffix(None, "TCP", traddr, trsvcid)

for key, val in state.items():
if not key.startswith(key_prefix):
continue
if not key.endswith(key_suffix):
continue
return True

return False

def create_listener_safe(self, request, context):
"""Creates a listener for a subsystem at a given IP/Port."""

ret = True
traddr = GatewayUtils.escape_address_if_ipv6(request.traddr)
create_listener_error_prefix = f"Failure adding {request.nqn} listener at {traddr}:{request.trsvcid}"
create_listener_error_prefix = f"Failure adding {request.nqn} listener at {request.traddr}:{request.trsvcid}"

adrfam = GatewayEnumUtils.get_key_from_value(pb2.AddressFamily, request.adrfam)
if adrfam == None:
Expand All @@ -2078,7 +2060,7 @@ def create_listener_safe(self, request, context):
peer_msg = self.get_peer_message(context)
self.logger.info(f"Received request to create {request.host_name}"
f" TCP {adrfam} listener for {request.nqn} at"
f" {traddr}:{request.trsvcid}, context: {context}{peer_msg}")
f" {request.traddr}:{request.trsvcid}, context: {context}{peer_msg}")

if GatewayUtils.is_discovery_nqn(request.nqn):
errmsg=f"{create_listener_error_prefix}: Can't create a listener for a discovery subsystem"
Expand All @@ -2093,10 +2075,8 @@ def create_listener_safe(self, request, context):
with self.omap_lock(context=context):
try:
if request.host_name == self.host_name:
listener_already_exist = self.matching_listener_exists(
context, request.nqn, request.traddr, request.trsvcid)
if listener_already_exist:
self.logger.error(f"{request.nqn} already listens on address {traddr}:{request.trsvcid}")
if (adrfam, request.traddr, request.trsvcid) in self.subsystem_listeners[request.nqn]:
self.logger.error(f"{request.nqn} already listens on address {request.traddr}:{request.trsvcid}")
return pb2.req_status(status=errno.EEXIST,
error_message=f"{create_listener_error_prefix}: Subsystem already listens on this address")
ret = rpc_nvmf.nvmf_subsystem_add_listener(
Expand Down Expand Up @@ -2189,7 +2169,7 @@ def create_listener_safe(self, request, context):
"TCP", request.traddr,
request.trsvcid, json_req)
except Exception as ex:
errmsg = f"Error persisting listener {traddr}:{request.trsvcid}"
errmsg = f"Error persisting listener {request.traddr}:{request.trsvcid}"
self.logger.exception(errmsg)
errmsg = f"{errmsg}:\n{ex}"
return pb2.req_status(status=errno.EINVAL, error_message=errmsg)
Expand Down
4 changes: 2 additions & 2 deletions tests/ha/setup_4gws.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ for i in $(seq $NUM_SUBSYSTEMS); do
for g in $(seq $NUM_GATEWAYS); do
GW_NAME=$(gw_name $g)
GW_IP=$(gw_ip $g)
ADDR=0.0.0.0
PORT=4420
docker-compose run --rm nvmeof-cli --server-address $GW_IP --server-port 5500 listener add --subsystem $NQN --host-name $GW_NAME --traddr $GW_IP --trsvcid $PORT
docker-compose run --rm nvmeof-cli --server-address $GW_IP --server-port 5500 listener add --subsystem $NQN --host-name $GW_NAME --traddr $ADDR --trsvcid $PORT
done
done

Expand All @@ -53,7 +54,6 @@ for g in $(seq $NUM_GATEWAYS); do
echo "Verify $i $GW_NAME $GW_IP"
GW_NAME=$(gw_name $g)
GW_IP=$(gw_ip $g)
PORT=4420
subs=$(docker-compose run --rm nvmeof-cli --server-address $GW_IP --server-port 5500 get_subsystems 2>&1 | sed 's/Get subsystems://')

# verify all resources found in get subsystems
Expand Down
Loading