mirror of
https://github.com/kvcache-ai/AgentENV.git
synced 2026-11-05 01:17:36 +00:00
[PR #389] feat(ublk): add an NBD block device backend for hosts without ublk #398
Labels
No labels
bug
documentation
enhancement
enhancement
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
kvcache-ai/AgentENV#398
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/kvcache-ai/AgentENV/pull/389
Author: @yingdi-shan
Created: 10/18/2026
Status: 🔄 Open
Base:
main← Head:feat/nbd-device-backend📝 Commits (2)
88e2c2afix(ublk-daemon): drop cached pages when reusing a pooled device3f9eb1bfeat(ublk): add an NBD block device backend for hosts without ublk📊 Changes
34 files changed (+2661 additions, -458 deletions)
View changed files
📝
Cargo.lock(+14 -0)📝
Cargo.toml(+1 -0)📝
Makefile(+2 -2)📝
config/default.toml(+3 -0)📝
deploy/docker-compose.yml(+1 -0)📝
docs/src/configuration/env-vars.md(+1 -0)📝
docs/src/configuration/reference.md(+11 -0)📝
docs/src/deployment/docker-compose.md(+5 -1)📝
docs/src/deployment/docker.md(+5 -2)📝
docs/src/getting-started/quickstart.md(+8 -4)📝
scripts/docker-setup.sh(+64 -19)📝
scripts/install.sh(+57 -7)📝
src/cfg.rs(+23 -0)📝
src/sandbox/ublk/device.rs(+4 -0)📝
src/setup/mod.rs(+17 -5)➕
src/setup/nbd.rs(+61 -0)📝
src/setup/ublk.rs(+16 -62)➕
src/setup/udev.rs(+66 -0)➕
storage/nbd/Cargo.toml(+14 -0)➕
storage/nbd/src/kernel.rs(+576 -0)...and 14 more files
📄 Description
What
Adds NBD as a second kernel frontend for OverlayBD devices, next to ublk, and lets the installer and docker setup script choose between them.
This PR is based directly on
mainand is independent of #388. It has two commits:88e2c2a fix(ublk-daemon): drop cached pages when reusing a pooled device(Refs #302). This is a standalone 5-line commit that can be cherry-picked on its own.89ab4cc feat(ublk): add an NBD block device backend for hosts without ublkWhy
OverlayBD devices currently require
ublk_drv(Linux 6.0+, and in practice 6.8+). That rules out older distro kernels. The kernel NBD client is available almost everywhere and is enough to serve the sameOverlaybdTarget. FUSE adds no benefit over NBD here, and vhost-user-blk / NVMe-oF would break Firecracker'sMAP_PRIVATEmemory restore and drive model.Related issue
Refs #302. The pool fix in
88e2c2aaddresses the stale placeholder pages that #342 reproduces. NBD made the bug easy to hit. It narrows the race but does not prove it closed; see the Risks section.Scope and non-goals
Included:
storage/nbd(uvm-nbd). It implements the NBD transmission phase (READ/WRITE/TRIM/DISC) and attaches devices through the generic-netlinknbdfamily over a Unix socketpair. There is no handshake and no TCP.OverlaybdTargetimplementsNbdExport. Reads still feed the startup-pack recorder.--device-backend ublk|nbdthrough a sharedDeviceBackend/BlockDevice. The ublk-specific helpers moved fromserver.rstodevice.rswithout behavior changes.[ublk] device_backend/AENV_UBLK_DEVICE_BACKEND, wired into the daemon spawn and intoserver --setup-host/ startup checks (src/setup/nbd.rs).scripts/install.shandscripts/docker-setup.shtakeAENV_UBLK_DEVICE_BACKEND=auto|ublk|nbd, defaulting toauto.Not included:
automode. The server default staysublk; the scripts make the choice.Design and behavior changes
UBLK_ATTR_VOLATILE_CACHE, so the kernel never sends it FLUSH. NBD exports are likewise write-through: the server never advertisesSEND_FLUSH/SEND_FUAand rejects FLUSH with EINVAL. Read-only OverlayBD images rejectsync(), and advertising flush caused EIO on pool release (BLKFLSBUF).NBD_CMD_CONNECT.disconnectsendsNBD_CMD_DISCONNECTand waits up to 5 s for the server, then aborts it.Dropdisconnects best-effort. No I/O timeout is set, matching ublk's behavior of never timing out against a slow lazy-loading image.UBLK_F_UPDATE_SIZE, soGetFeaturesreturns 0. The pool therefore reuses only same-size devices, and it does not prewarm unlessstartup_prewarmis set.autokeeps ublk whenublk_drvis loaded or installable (modinfo, thenlinux-modules-extravia apt) and otherwise falls back to nbd.install.shrecords the result in/etc/default/aenvnext toAENV_VIRTUALIZATION_MODEand passes it to--setup-only/--setup-host.docker-setup.shloads the matching module and prints the-e AENV_UBLK_DEVICE_BACKEND=nbd/AENV_UBLK_DEVICE_BACKEND=nbd make deploy-uphint.deploy/docker-compose.ymlforwards the variable.Compatibility and operations
--device-backendflag, and its existing constructors keep their signatures.[ublk] device_backend(defaultublk) andAENV_UBLK_DEVICE_BACKEND. Installers default toauto, which resolves toublkon every host that works today.install.shon an existing ublk host selectsublkand addsAENV_UBLK_DEVICE_BACKEND="ublk"to/etc/default/aenv. To roll back, drop that line.nbdmodule (CONFIG_BLK_DEV_NBD) andCAP_SYS_ADMINfor netlink, which the service already has.--setup-hostinstalls/etc/udev/rules.d/99-agentenv-nbd.rulesand/etc/modules-load.d/aenv-nbd.conf.Validation
make fmtmake clippymake test-unit(ran the affected crates individually; see below)make -C services test(required whenservices/changes)maketargetCommands and results:
Skipped checks and reasons:
make test-unit/make testas aggregate targets were not run. The affected crates and theagentenvlib suite were run directly.88e2c2a(1 in 12 runs) and passed 25 of 25 after it. The ublk path is covered only by the existing suites. #342's reproducer was not run against this branch.services/is unchanged.Risks and reviewer notes
clear_page_cacheafter the target swap drops pages cached while the device was idle. A placeholder read already in flight during the swap, or a reader holding the device open across reuse, could still repopulate the cache. Treat the fix as narrowing the window.storage/nbd/src/kernel.rs(netlink attach/detach and Drop),storage/nbd/src/server.rs(request concurrency, disconnect draining) andstorage/ublk-daemon/src/device.rs./etc/default/aenvtakes precedence overconfig.toml, the same asAENV_VIRTUALIZATION_MODE. This is documented in the configuration reference.Checklist
device.rsis required by the backend split.)🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.