Skip to content

orchestrator: add inspect-nbd CLI tool and DevicePool.Status() - #3547

Open
AdaAibaby wants to merge 4 commits into
e2b-dev:mainfrom
AdaAibaby:feat/inspect-nbd-tool
Open

orchestrator: add inspect-nbd CLI tool and DevicePool.Status()#3547
AdaAibaby wants to merge 4 commits into
e2b-dev:mainfrom
AdaAibaby:feat/inspect-nbd-tool

Conversation

@AdaAibaby

Copy link
Copy Markdown
Contributor

Fixes #3546.

Summary

  • cmd/inspect-nbd: new operator tool that shows only the NBD devices currently connected on the host, instead of all 4096 pre-allocated ones
  • DevicePool.maxDevices: stored at construction to avoid re-reading /sys/module/nbd/parameters/nbds_max on each call
  • DevicePool.Status(): returns PoolStatus{Max, Used, PreWarmed} from the in-memory bitset without scanning sysfs — for future debug endpoints

Motivation

The nbd module is loaded with nbds_max=4096 (start-client.sh), pre-creating 4096 /dev/nbdX block devices. lsblk | grep nbd produces 4096 lines of noise even with zero sandboxes running. When kernel errors like block nbd316: Receive control failed appear in dmesg, there is no way to identify which sandbox is involved.

ConnectedDevices() already had the right logic (scans /sys/block/nbdX/pid), but was only used internally for startup reclaim. This PR exposes it as a standalone tool.

Usage

# human-readable
$ inspect-nbd
NBD devices: 1 connected / 4096 configured

SLOT  DEVICE     SIZE (MB)  PID
1     /dev/nbd1  22691      3321246

# machine-readable
$ inspect-nbd -json
{
  "nbds_max": 4096,
  "connected": 1,
  "devices": [
    {
      "slot": 1,
      "path": "/dev/nbd1",
      "size_mb": 22691,
      "pid": "3321246"
    }
  ]
}

Verified on dev sandbox node (192.168.162.80, nbds_max=4096, 1 sandbox running at test time).

Not in scope

Slot → sandbox ID mapping (requires threading sandboxID through GetDevice call sites) — tracked in #3546 as follow-up.

Fixes e2b-dev#3546.

The nbd kernel module is loaded with nbds_max=4096, pre-creating 4096
/dev/nbdX block devices on every sandbox node. `lsblk | grep nbd`
produces 4096 lines of noise even when zero sandboxes are running,
making it impossible to quickly identify which devices are actively
connected.

ConnectedDevices() in pool.go already scans /sys/block/nbdX/pid to
find connected slots, but was not exposed via any operator-facing tool.

Changes:
- Add cmd/inspect-nbd: reads ConnectedDevices() and prints a table of
  active NBD slots with device path, size, and PID. Supports -json for
  machine-readable output. Linux-only (//go:build linux).
- Add DevicePool.maxDevices field: stored at construction to avoid
  re-reading /sys/module/nbd/parameters/nbds_max on each call.
- Add DevicePool.Status() -> PoolStatus: returns Max/Used/PreWarmed
  counts from the in-memory bitset without scanning sysfs — usable by
  future debug endpoints.

Example output on a node with 4096 configured but only 1 connected:

  NBD devices: 1 connected / 4096 configured

  SLOT  DEVICE     SIZE (MB)  PID
  1     /dev/nbd1  22691      3321246

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5ec3453053

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/orchestrator/cmd/inspect-nbd/main.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

orchestrator: no CLI to inspect active NBD devices; lsblk shows 4096 pre-allocated noise

2 participants