Allow deleting a host without disconnecting its connections. #1893
removed.update(keep_connection) mixes added CONNECTED_HOST_PREFIX keys (injected via keep_connection) with actually removed keys from removed_keys. When a connected-host key is deleted from OMAP (e.g. host deletion without --keep-connections, or when the key is cleared), it will still be processed as a “removal” RPC, which (via control/server.py) calls set_keep_host_connected and can re-enable the flag on other gateways unexpectedly. Consider filtering out real CONNECTED_HOST_PREFIX removals from removed (or adding an explicit “clear” RPC/flag) so that only newly-added indications are applied before the host removal update.
CONNECTED_HOST_PREFIX handling only runs when not is_add_req, and calls set_keep_host_connected. This means a connected-host key being removed from OMAP will also trigger set_keep_host_connected (re-setting the indication) even though the signal is being cleared. Either ignore removals for this prefix, or support clearing (e.g., add a boolean to the request / add a reset RPC) and call the appropriate action based on is_add_req.
add_host() scans the entire state (for key in list(state.keys())) just to delete a single exact key (build_connected_host_key(...)). This is unnecessarily expensive and harder to read than a direct membership check. Prefer computing the key once and removing it if present (e.g., key = build_connected_host_key(...); if key in state: _remove_key(key)).
This block removes PSK/DHCHAP host info unconditionally before (re)adding the host, but the connected-host OMAP key cleanup is handled twice: GatewayState.add_host() now removes the connected-host key, and then this code calls gateway_state.remove_connected_host(...) again. Consider dropping one of these paths to avoid redundant OMAP/local updates and extra RADOS operations.
The test greps for exact log lines including the Python context representation (e.g. context: <grpc._server...>). That formatting can vary across grpc/python versions and may make this HA test flaky even if behavior is correct. Prefer grepping for a stable substring (e.g. only keep connections: True/False) or validating the behavior via API output / OMAP state rather than log formatting details.
Pull request overview
This PR implements the “delete host without disconnecting active connections” workflow (Issue #1885) to enable practical PSK rotation by deleting and re-adding a host while keeping existing sessions alive.
Changes:
keep_connections support to remove_host and propagate the intent across gateways via an OMAP “connected host” indication + new gRPC RPC.host_deleted flag and surface it in CLI output.keep_connection) and run it in the GitHub Actions HA matrix.Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.
<details>
<summary>Show a summary per file</summary>
| File | Description |
| ---- | ----------- |
| tests/ha/keep_connection.sh | New HA scenario covering “delete host but keep connection”, plus PSK rotation via delete+readd. |
| control/proto/gateway.proto | Adds keep_connections to remove_host_req, introduces set_keep_host_connected RPC + host_deleted on connections. |
| control/grpc.py | Implements keep-connections behavior, connected-host indication tracking, and host_deleted reporting. |
| control/state.py | Adds OMAP key prefix + persistence helpers for connected-host indication; tweaks update flow ordering. |
| control/server.py | Applies connected-host indication updates by calling the new RPC. |
| control/cli.py | Adds --keep-connections to host del and marks deleted hosts in connection list output. |
| lib/go/nvmeof/gateway.pb.go | Regenerated Go protobuf bindings reflecting proto changes. |
| lib/go/nvmeof/gateway_grpc.pb.go | Regenerated Go gRPC bindings including set_keep_host_connected. |
| .github/workflows/build-container.yml | Adds keep_connection to the HA test matrix. |
</details>
---
💡 <a href="/ceph/ceph-nvmeof/new/devel?filename=.github/instructions/*.instructions.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add Copilot custom instructions</a> for smarter, more guided reviews. <a href="https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn how to get started</a>.
changed
this was handled
changed
changed
this is OK
In remove_host_safe(), the decision to persist the CONNECTED_HOST_PREFIX/"keep host connected" indication is based on request.keep_connections, but the actual behavior is controlled by keep_conn (which is forced to False when the host isn’t currently connected). This can leave stale connected-del-host_* keys in OMAP even when there were no connections to keep (and can cause other gateways to set the in-memory indication unnecessarily, including on restart when no matching host removal follows). Use the effective keep_conn when deciding whether to add/remove the connected-host indication (and consider logging the effective value as well).
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
---
💡 <a href="/ceph/ceph-nvmeof/new/devel?filename=.github/instructions/*.instructions.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add Copilot custom instructions</a> for smarter, more guided reviews. <a href="https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn how to get started</a>.
This is OK. We only set the OMAP in one gateway. This gateway might not be connected to the host while another gateway is.
Minor docstring formatting: there’s an extra space before the period in "Set a connected host indication .". Consider tightening it to avoid stray whitespace in generated docs/help.
if key in state.keys() is equivalent to if key in state but does an extra keys-view lookup and is less idiomatic. Since this code runs on every host add / connected-host cleanup, prefer if key in state: here (and similarly in remove_connected_host).
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
---
💡 <a href="/ceph/ceph-nvmeof/new/devel?filename=.github/instructions/*.instructions.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add Copilot custom instructions</a> for smarter, more guided reviews. <a href="https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn how to get started</a>.
changed
changed
The “Verify connection list is empty after second host delete” assertion checks .connections[1] == null, which can still pass if one connection remains at index 0. To ensure the list is empty, assert .connections[0] is null (or use .connections | length == 0).
The “Verify host list is empty after host delete” assertion checks .hosts[1] == null, which will still pass if there is exactly one remaining host entry at index 0. To actually verify the list is empty, check .hosts[0] is null (or assert .hosts | length == 0).
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
---
💡 <a href="/ceph/ceph-nvmeof/new/devel?filename=.github/instructions/*.instructions.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add Copilot custom instructions</a> for smarter, more guided reviews. <a href="https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn how to get started</a>.
changed
changed
The comment text is grammatically incorrect ("no need in...") which makes the intent harder to read. Please rephrase it (e.g., "no need for a connected-host indication for this host").
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
<details>
<summary>Comments suppressed due to low confidence (1)</summary>
control/state.py:327
if key in state.keys() is less idiomatic and does an unnecessary keys-view lookup; if key in state is equivalent and clearer. state = self.get_state()
key = GatewayState.build_host_key(subsystem_nqn, host_nqn)
if key in state.keys():
self._remove_key(key)
</details>
---
💡 <a href="/ceph/ceph-nvmeof/new/devel?filename=.github/instructions/.instructions.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add Copilot custom instructions</a> for smarter, more guided reviews. <a href="https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn how to get started</a>.
changed
In cephnvmf_func1/2, using $@ unquoted will do word-splitting and glob expansion on arguments (e.g., host NQNs like "*" if passed through these wrappers), which can lead to accidental argument mangling. Prefer forwarding args as "$@" so each original argument is preserved exactly.
keep_connection is derived from added_keys, but the same CONNECTED_HOST_PREFIX keys remain in added/grouped_added, so _update_call_rpc(..., is_add_req=True) will still iterate over them (and control/server.py will effectively no-op). Consider removing these keys from added once extracted into keep_connection (or otherwise documenting the intentional no-op) to avoid redundant work and make the special-case handling clearer.
For CONNECTED_HOST_PREFIX updates, the is_add_req path currently falls through without an explicit no-op, even though additions for this prefix are intentionally ignored (the signal is handled via the removal phase). Adding an explicit else: pass (or a short comment explaining why add-events are ignored) would make the intent clearer and reduce the chance of future regressions when this block is modified.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
---
💡 <a href="/ceph/ceph-nvmeof/new/devel?filename=.github/instructions/*.instructions.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add Copilot custom instructions</a> for smarter, more guided reviews. <a href="https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn how to get started</a>.
Maybe this is clearer? wdyt?
self.cli.parser.error("Can only keep existing connections for specific host NQNs, not '*'.")
changed
changed
keep_connection keys (CONNECTED_HOST_PREFIX) are still included in the normal added/grouped_added flow, but are also injected into removed via removed.update(keep_connection) so they get handled during the removal phase. Since the add-phase handler for this prefix is a deliberate no-op, this results in redundant processing (and can introduce unnecessary break_update_interval delays) and makes the update logic harder to follow. Consider removing/popping CONNECTED_HOST_PREFIX keys from added once they’re captured in keep_connection, and add a short comment explaining that these “added” keys are intentionally applied during the removal phase to ensure ordering before host removal updates.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
---
💡 <a href="/ceph/ceph-nvmeof/new/devel?filename=.github/instructions/*.instructions.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add Copilot custom instructions</a> for smarter, more guided reviews. <a href="https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn how to get started</a>.
this is fine. adding the code is not worth it as the usage of this will be quite rare
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.
---
💡 <a href="/ceph/ceph-nvmeof/new/devel?filename=.github/instructions/*.instructions.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add Copilot custom instructions</a> for smarter, more guided reviews. <a href="https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn how to get started</a>.
Approved these changes.
Approved these changes.
@gbregman @baum hi Gil and Alexander, sorry for commenting on a merged pull request, but in this commit, we updated the spdk submodule to 611b10960d08a97d8d20863f176951ded8595fdb, which is not included in the ceph/spdk repo. but this commit is included a pull request not yet merged, see https://github.com/ceph/spdk/pull/17/commits . IMHO, this is not expected. i ran into this issue, when trying to package ceph, but consistenly ran into:
$ git submodule update --init --recursive
fatal: remote error: upload-pack: not our ref 611b10960d08a97d8d20863f176951ded8595fdb
fatal: Fetched in submodule path 'spdk', but it did not contain 611b10960d08a97d8d20863f176951ded8595fdb. Direct fetching of that commit failed.
@tchaikov yes, somehow I missed pushing this commit. Anyway, this doesn't seem relevant any more as we have two commits to the SPDK after that. So, if you take the latest version you should be OK.
Hezko
gbregman
Fixes #1885