From 766b1f71fb3cb779174353390a473b75fb57d00d Mon Sep 17 00:00:00 2001 From: atlas Date: Sun, 26 Jul 2026 18:15:42 +0200 Subject: [PATCH] refactor(hivectl): move quota + subvol under `agents` Both groups only ever act on a single managed agent's state dir, so they belong in the `agents` namespace rather than as top-level verbs next to `forge` / `matrix` / `wg`. Renames `quota limit` -> `quota set`: the enclosing group already carries the noun, so the bare verb matches the flat `set-parent` / `set-limits` spelling without stuttering, and it removes the `set-limits` (cpu/mem) vs `quota limit` (disk) ambiguity. Adds a cross-pointer from `set-limits` to `agents quota`. Handlers stay in their own modules; `run_agents` gains the reparenting glue. Regenerates docs/tools/hivectl-cli.md. Refs #2724 --- docs/tools/hivectl-cli.md | 318 +++++++++++++++++++------------------- hive-c0re/src/server.rs | 2 +- hive-host-sock/src/lib.rs | 16 +- hive-priv/src/main.rs | 2 +- hivectl/src/agents.rs | 17 +- hivectl/src/cli.rs | 42 ++--- hivectl/src/main.rs | 14 +- hivectl/src/quota.rs | 4 +- hivectl/src/subvol.rs | 4 +- 9 files changed, 215 insertions(+), 204 deletions(-) diff --git a/docs/tools/hivectl-cli.md b/docs/tools/hivectl-cli.md index 28aaeda4..37af3331 100644 --- a/docs/tools/hivectl-cli.md +++ b/docs/tools/hivectl-cli.md @@ -33,6 +33,16 @@ This document contains the help content for the `hivectl` command-line program. * [`hivectl agents rebuild`↴](#hivectl-agents-rebuild) * [`hivectl agents set-parent`↴](#hivectl-agents-set-parent) * [`hivectl agents set-limits`↴](#hivectl-agents-set-limits) +* [`hivectl agents quota`↴](#hivectl-agents-quota) +* [`hivectl agents quota enable`↴](#hivectl-agents-quota-enable) +* [`hivectl agents quota show`↴](#hivectl-agents-quota-show) +* [`hivectl agents quota set`↴](#hivectl-agents-quota-set) +* [`hivectl agents subvol`↴](#hivectl-agents-subvol) +* [`hivectl agents subvol upgrade`↴](#hivectl-agents-subvol-upgrade) +* [`hivectl agents subvol snapshot`↴](#hivectl-agents-subvol-snapshot) +* [`hivectl agents subvol snapshot create`↴](#hivectl-agents-subvol-snapshot-create) +* [`hivectl agents subvol snapshot delete`↴](#hivectl-agents-subvol-snapshot-delete) +* [`hivectl agents subvol snapshot send`↴](#hivectl-agents-subvol-snapshot-send) * [`hivectl approvals`↴](#hivectl-approvals) * [`hivectl approvals pending`↴](#hivectl-approvals-pending) * [`hivectl approvals approve`↴](#hivectl-approvals-approve) @@ -46,16 +56,6 @@ This document contains the help content for the `hivectl` command-line program. * [`hivectl stop`↴](#hivectl-stop) * [`hivectl start`↴](#hivectl-start) * [`hivectl restart`↴](#hivectl-restart) -* [`hivectl quota`↴](#hivectl-quota) -* [`hivectl quota enable`↴](#hivectl-quota-enable) -* [`hivectl quota show`↴](#hivectl-quota-show) -* [`hivectl quota limit`↴](#hivectl-quota-limit) -* [`hivectl subvol`↴](#hivectl-subvol) -* [`hivectl subvol upgrade`↴](#hivectl-subvol-upgrade) -* [`hivectl subvol snapshot`↴](#hivectl-subvol-snapshot) -* [`hivectl subvol snapshot create`↴](#hivectl-subvol-snapshot-create) -* [`hivectl subvol snapshot delete`↴](#hivectl-subvol-snapshot-delete) -* [`hivectl subvol snapshot send`↴](#hivectl-subvol-snapshot-send) * [`hivectl open`↴](#hivectl-open) * [`hivectl completions`↴](#hivectl-completions) @@ -79,8 +79,6 @@ Sibling to the `hive-c0re` daemon binary. Covers host-side admin operations that * `stop` — Stop containers hive-wide in one operator action * `start` — Start containers hive-wide — the inverse of `hivectl stop` * `restart` — Restart containers hive-wide — `stop` then `start` over one scope -* `quota` — Per-agent disk accounting + optional quotas via btrfs qgroups -* `subvol` — btrfs subvolume management for agent state dirs * `open` — Print (and best-effort open in a browser) a hive web surface URL * `completions` — Generate a shell completion script for `hivectl` and print it to stdout @@ -351,6 +349,8 @@ Lifecycle actions on managed agent containers. Needs the hive-c0re daemon runnin * `rebuild` — Apply pending config to a managed container * `set-parent` — Move an agent in the topology tree — under a new parent, or to root * `set-limits` — Declare an agent's CPU/memory limits, overriding the hive-wide defaults +* `quota` — Per-agent disk accounting + optional quotas via btrfs qgroups +* `subvol` — btrfs subvolume management for agent state dirs @@ -507,7 +507,7 @@ Move an agent in the topology tree — under a new parent, or to root Declare an agent's CPU/memory limits, overriding the hive-wide defaults. -Replaces the agent's whole override entry rather than merging into it: any limit you don't pass returns to the hive-wide default. To change one and keep the other, pass both. +Replaces the agent's whole override entry rather than merging into it: any limit you don't pass returns to the hive-wide default. To change one and keep the other, pass both. Disk is a separate resource with its own group — see `agents quota`. **Usage:** `hivectl agents set-limits [OPTIONS] ` @@ -523,6 +523,153 @@ Replaces the agent's whole override entry rather than merging into it: any limit +## `hivectl agents quota` + +Per-agent disk accounting + optional quotas via btrfs qgroups. + +Opt-in: enable qgroup accounting, then report per-agent usage or cap an agent. No-op on non-btrfs hosts. + +**Usage:** `hivectl agents quota ` + +###### **Subcommands:** + +* `enable` — Enable btrfs qgroup accounting on the agent-state filesystem +* `show` — Report per-agent disk usage from btrfs qgroups (all agents, or one by name) +* `set` — Set or clear an agent's disk-usage quota + + + +## `hivectl agents quota enable` + +Enable btrfs qgroup accounting on the agent-state filesystem. + +Run once before `show` / `limit`. No-op on non-btrfs hosts. + +**Usage:** `hivectl agents quota enable` + + + +## `hivectl agents quota show` + +Report per-agent disk usage from btrfs qgroups (all agents, or one by name) + +**Usage:** `hivectl agents quota show [NAME]` + +###### **Arguments:** + +* `` — Agent to show (omit for all agents with a state subvolume) + + + +## `hivectl agents quota set` + +Set or clear an agent's disk-usage quota. + +Named `set` rather than `set-quota` because the enclosing `quota` group already carries the noun — `agents quota set iris 5G`. The `set-` spelling stays for the flat verbs (`set-parent`, `set-limits`), which have no group to inherit it from. + +**Usage:** `hivectl agents quota set ` + +###### **Arguments:** + +* `` — Agent whose state subvolume to limit +* `` — Size cap (`5G`, `500M`, `1073741824`) or `none` to clear + + + +## `hivectl agents subvol` + +btrfs subvolume management for agent state dirs. + +Upgrade an existing plain-dir agent's state into a btrfs subvolume so it gains snapshots and per-subvol usage/quota. + +**Usage:** `hivectl agents subvol ` + +###### **Subcommands:** + +* `upgrade` — Convert a plain-dir agent state root into a btrfs subvolume in place, so it gains snapshots and per-subvol usage/quota +* `snapshot` — Read-only snapshots of an agent's state subvolume + + + +## `hivectl agents subvol upgrade` + +Convert a plain-dir agent state root into a btrfs subvolume in place, so it gains snapshots and per-subvol usage/quota. + +Bounces the agent to migrate its state, so it requires `--yes`. + +**Usage:** `hivectl agents subvol upgrade [OPTIONS] ` + +###### **Arguments:** + +* `` — Agent name (e.g. `damocles`, `iris`) + +###### **Options:** + +* `--yes` — Confirm: this stops the agent, migrates its state dir, and restarts it. Required — the command refuses without it + + + +## `hivectl agents subvol snapshot` + +Read-only snapshots of an agent's state subvolume + +**Usage:** `hivectl agents subvol snapshot ` + +###### **Subcommands:** + +* `create` — Create a read-only snapshot (agent must already be a subvolume) +* `delete` — Delete a snapshot created by `subvol snapshot create` +* `send` — Export a snapshot to a local file via `btrfs send` (the local-file half of inter-hive migration transport; the cross-hive `ssh ... btrfs receive` leg isn't wired up yet). Also useful standalone as a point-in-time backup: a full send with no `--parent` produces a self-contained archive of the snapshot + + + +## `hivectl agents subvol snapshot create` + +Create a read-only snapshot (agent must already be a subvolume) + +**Usage:** `hivectl agents subvol snapshot create --label