summaryrefslogtreecommitdiff
path: root/9ns/src/bridge.zig
Commit message (Collapse)AuthorAge
* Build with Zig 0.17Gabriel Schneider2026-10-21
|
* 9ns: a dead mount's entry is invalidated from a thread of its own, never ↵Gabriel Schneider2026-10-02
| | | | | | from the thread serving the mount, which a LOOKUP holding the parent directory's lock may be waiting on (a cat of a dead session's index hung for good) Co-Authored-By: Claude Opus 5.5 <[email protected]>
* 9ns: regular files open with FOPEN_PARALLEL_DIRECT_WRITES, so a write that ↵Gabriel Schneider2026-10-01
| | | | | | | | | | | waits on another write to the same file (an Edit filter writing the ctl its Edit came by) is not queued behind it Linux 6.2 (FUSE 7.38) takes the inode lock shared for such a write unless it appends or goes past the file's end; older kernels ignore the bit. An O_TRUNC open still takes the lock outright, so a second writer that truncates (`>`) still waits; `1<>` does not. Co-Authored-By: Claude Opus 5.5 <[email protected]>
* 9ns: a file whose stat length is 0 opens direct and nonseekable, so a splice ↵Gabriel Schneider2026-09-30
| | | | | | | | | | | | | or a cached size never ends a stream early A server's stream (pardes's log) or generated view stats 0: its length is no length. Opened with the page cache or a kernel file offset of its own, a splicing reader (coreutils cat into a pipe) could read it from the wrong offset and take the size as its end. Such a file is now opened FOPEN_DIRECT_IO | FOPEN_NONSEEKABLE whatever --no-direct-io says; every other file keeps the option's flags. Co-Authored-By: Claude Opus 5.5 <[email protected]>
* 9ns: keep many 9P requests in flight, so a parked read no longer freezes the ↵Gabriel Schneider2026-09-27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | mount 9ns served one FUSE request at a time per 9P server, so a read the server parks (pardes's log, a pane's event) held up every other operation on the mount: with 'cat log' parked, 'cat status' took 3.5-4.5 s instead of ~1 ms. nine.zig: the session is shared by threads and multiplexes by tag the way Plan 9's mount driver does (devmnt.c mountio/mountmux/mntgate/ mntflushalloc). Each thread calls through its own nine.Caller (reply buffer, wake-up eventfd, interrupt source, ename). A call writes its T-message under wlock; the first waiter with nobody reading takes the reading baton, reads for everyone and hands each R-message to the caller its tag names, then passes the baton on. Tflush is per tag: a reply that beats the Rflush is honoured, the flushed tag is not reused before the Rflush, the baton is let go before the flush is written. With every tag taken a call waits for one (starved list) instead of failing. bridge.zig: one thread (the loop) still owns the inode/handle/qid tables and serves everything that touches them. READ and WRITE are resolved to their fid on the loop and handed to transfer workers (up to 31 per bridge, started on demand), which make the 9P calls on their own Caller and reply themselves. FUSE_INTERRUPT for a worker's request: still queued -> EINTR on the spot; in flight -> its unique down the worker's pipe -> Tflush of exactly that tag. Fids are clunked only on RELEASE. mntgen mounts get the same pool (their dispatcher routes interrupts to it); the mount interrupt pipe moved into Bridge. main.zig attaches through a Caller. Tests: two multiplexing tests in nine.zig (a parked read holds up only its caller and its interrupt flushes exactly its tag; with every tag parked a call waits for a tag), and a serve()-level test driving a fake /dev/fuse (a parked READ holds up neither READs nor GETATTR; INTERRUPT -> one Tflush for the parked tag -> EINTR; RELEASE). Also de-flaked the pre-existing 'short read' test (it raced its own server reply under load). Measured (own 9ns mount on the live pardes socket, read-only): with log parked, cat status 4498 ms before, 7 ms after. Tag window: client.zig gains ClientWith(n) (Client = ClientWith(16) as before; request/result types hoisted so all instantiations share them). 9ns uses ClientWith(32): 32 is fs.zig's default slot_capacity, so one 9ns mount can never have more parked on a cloud9 fs server than it parks, and never meets its "Resource temporarily unavailable" refusal. fs.zig is unchanged (its default is also the ESP32 board's, held to 24 KiB by its budget tests). Full window: the loop keeps its tag (metadata unaffected); the 32nd READ/WRITE waits in the pool queue (blocks, interruptible, never EAGAIN/EIO). More tests (bridge.zig, serve() over a fake /dev/fuse): one open is one fid (two opens of an inode read through distinct fids, concurrently, one of them parked); FLUSH on a handle with a parked read clunks nothing and the read later completes on that fid; only RELEASE clunks; a flushed READ whose reply beats the Rflush returns the data, not EINTR.
* 9ns --mntgen: a server that never answers stalls only its own nameGabriel Schneider2026-09-22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Opening a fish (self-wrapped in `9ns --mntgen`) and running an agent in it would sometimes freeze the whole session: no input reached it and nothing under /mnt/9p answered, until the shell was killed from outside. The cause was one posted server that accepted a connection and then never spoke 9P — pardes, answering its 9P from the same loop that was walking its own mount, was the one on this machine, but any wedged or half-dead server does it. Three things conspired, and each is fixed on its own: * The dispatcher dialed. A LOOKUP of an undialed name ran connect, Tversion, Tattach and Tstat on the one thread that reads /dev/fuse, so while that server kept quiet no request for any name was read, and no FUSE_INTERRUPT either. Now the dispatcher makes a Mount without touching the network and queues the walk to the mount's worker, which dials while serving it. The dial is the request in flight, so an interrupt of the walk abandons it at once (`Session.abort_on_cancel`: nothing to flush before a session exists) and the walk answers EINTR; a failed dial leaves the mount undialed for the next walk to retry; a full listen backlog (the server stopped accepting) is retried for 5s and then EIO. Every later LOOKUP of the name goes through the same queue and is answered from the remembered root attr, so the dispatcher never holds a session at all. * Once the dispatcher had read a request the process behind it was unkillable (FUSE waits out a request userspace has taken), and an INTERRUPT for a request still sitting in a mount's queue was dropped. The dispatcher now takes a queued request out and answers EINTR itself, and forwards only in-flight ones to the worker; queue and in-flight unique are read under the mount's mutex, where the worker moves a request from one to the other. A Tflush the server never answers is given 3s (`Session.flush_grace_ms`) and then the session is declared wedged: the request answers EINTR, the mount dies, the next walk makes a new one. * The kernel serialized the directory. Without FUSE_PARALLEL_DIROPS in the INIT reply every LOOKUP and READDIR in a directory takes its inode lock, so one parked walk held up every other name under /mnt/9p however free the dispatcher was (`cat` sat in fuse_lock_inode). The flag is now negotiated when the kernel offers it. What remains is the kernel's own serialization of lookups of one *name*: a second walker into the parked name waits for the first walk to end, and only then proceeds (and can be interrupted in its turn). An adversarial review of the above found three more things, fixed here: the single-connection bridge's one-slot stash stopped polling the FUSE fd while a second request was parked, so an INTERRUPT could not arrive (and parallel dirops make a second request routine) — the stash is now a queue of copies and the fd is always watched; a dead or wedged mount kept its socket open until exit, where a late-answering single-threaded server could block on it — the session is closed when the mount dies; and teardown after DESTROY or ENODEV (the child still alive, so stop_fd says nothing) could join a worker parked on a mute server forever — the sockets are shut down before the join. The flush grace is a deadline now, not a timer restarted on every wakeup. A black-box run against the binary (hostile servers: mute, garbage, close-after-accept, full backlog, 100 mute names, interrupt storms, 300 deaths of one server) found that a dead mount kept its socket, its interrupt pipe and a megabyte of buffers until exit — three descriptors per death — so `retire` now frees all of it and keeps only the slot; descriptors, threads and RSS stay flat across 400 deaths. The 4096-slot cap per process remains and is documented. Reproduced with a socket that accepts and never writes, posted beside 9agents in a scratch registry: before, `cat /mnt/9p/agents/pid` parked behind `stat /mnt/9p/hang` and SIGINT did nothing; after, it answers at once, the parked walker dies of its signal within milliseconds, and a server that answers the handshake but ignores reads and Tflush releases its reader after the grace. mntgen.sh and adv_bridge_interrupt.sh now check exactly that; nine.zig gains unit tests for the grace and the abort. Also in this change: the uncommitted ESTALE-on-death and FUSE_NOTIFY_INVAL_ENTRY work from the working copy, which the dead-mount path here builds on. Co-Authored-By: Claude Fable 5.1 <[email protected]>
* 9ns --mntgen: registry subdirectories are mount points tooGabriel Schneider2026-09-21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A registry entry that is a directory is now served the way the root is: a synthetic directory listing the real one, dialing the sockets inside it on walk and recursing into further directories, to max_synth_depth (8) levels across max_synth_dirs (64) synthetic nodes. That is the plan9port mntgen shape and the layout zmx now posts under, so a live session reads at /mnt/9p/zmx/<name>. Before this a directory in the registry was dialed like a socket and answered EIO for good. post gains the two entry points the traversal needs: postedDir (the registry scan, against any directory) and dialPath (a dial by composed path, no name validation). Hardening, each from an attack that broke the code: - BATCH_FORGET carries entries for many owners and puts 0 in the header nodeid, so routing it by the header dropped all of them: 32 of 64 synthetic slots leaked in one close burst and the subdirectories that held them answered EIO forever. distributeForgets unpacks the body and hands each entry to its owner. - probe() and connectBlocking() copied a caller's path into the kernel address with no bound: a path past sun_path overran the 110-byte stack sockaddr (a panic in Debug, silent corruption in ReleaseFast). Both refuse it now, probe as `.live` so a claim never deletes what it could not inspect. - That bound then caught 9proc's own listener, which handed probe() the whole 108-byte sun_path array instead of the path inside it. The probe reads `.live` for anything it cannot ask about, so every stale socket became AlreadyListening and no server could ever take a dead predecessor's name back. It passes the path now. Suites: 87/87 root (+7 post/serve attack regressions), 48/48 9ns, 51+88 9ns integration (+4 traversal and slot-recycling checks), 213/0 9ns adversarial, 60/60 9proc plus its adversarial suites with a new stale-socket takeover check, freestanding green.
* post registry + 9ns --mntgen: the /srv translationGabriel Schneider2026-09-21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | cloud9.post: servers post their socket under a name in $XDG_RUNTIME_DIR/9p (post/unpost, posted, dial, Watch) and serve.Runner.listenPosted posts a server by name, unposting on stop. Names are budget-checked against the 108-byte socket path; a claim binds+listens at a private temp path and takes the name with atomic renames under flock (RENAME_NOREPLACE for free names, RENAME_EXCHANGE grab-verify-commit for stale ones): the registry path is never unlinked by a claim, live names refuse with AlreadyPosted, foreign files with NotSocket, and unpost removes only the caller's inode-matched entry. Watch surfaces inotify overflow and a replaced registry dir. 9ns --mntgen [--mount DIR] -- PROGRAM: one FUSE mount at /mnt/9p whose synthetic root lists the posted registry (no connection made); a walk into an unmounted name dials it and runs the existing bridge dispatch in a per-server worker thread, routed by mount index in the node id's top bits (ordinals never reused, cap 4096); a dead server answers EIO on its subtree and is re-dialed on the next walk. The dial watches stop_fd through Tversion (connectWatched). All existing 9ns forms are unchanged. 9proc's unix listener no longer blind-unlinks its path: a foreign non-socket is refused (Occupied), a live server is refused (AlreadyListening), only a refused socket is cleared, and stop() unlinks only the listener's own inode-matched socket. Hardened by adversarial review (GLM 5.3 x2 + DeepSeek V4.1 Flash, all high-thinking): double-bind races on one name (0 in 180k rounds), foreign-file TOCTOU deletions (0 in 4M flips), a 255-byte-name listing panic, inotify queue overflow silently dropped, listenPosted silently overwriting, dial-time Tversion hangs wedging the dispatcher, --debug silently ignored in mntgen, and xattr/statx probes answering EPERM on the synthetic root (broke `ls -l /mnt/9p`). Tests: root 80/80, 9ns 47/47, 9proc 60/60, integration 88/88 + mntgen 37/37, adversarial 213/0, freestanding riscv32 gate green.
* 9ns: --name and /mnt/9p/<name> mounts, qid.path as inode number, interrupts ↵Gabriel Schneider2026-09-19
| | | | | | | | | | | | | | | | | | | | as Tflush - --name NAME (default derived from the transport: socket basename, tcp-IP-PORT, spawned command, fdN) mounts at /mnt/9p/<name>; --mount still overrides. ensureMountpoint walks down and creates missing components, shadowing the deepest unwritable ancestor. NINE_MOUNT is the only exported variable. - The inode number reported to the kernel is the 9P qid.path for every node, root included; a server handing qid.path 1 to a file (Pardes /self) no longer collides with the root. - FUSE_INTERRUPT for the request in flight becomes Tflush; a blocked read returns EINTR when the server answers the flush, chunked transfers return short counts, other requests arriving meanwhile are stashed and served next. Servers ignoring Tflush still block until they answer. - 9ns-test now covers nine/bridge/fuse; new adv_bridge_interrupt suite (28); 9ns-itest grows to 88 checks. Co-Authored-By: Claude Fable 5.1 <[email protected]>
* Rename programs: 9player -> 9ns, introspect -> 9proc, app -> web (9web)Gabriel Schneider2026-09-19
Directories, binaries, build options (-D9ns, -D9proc), step names, module name (9proc), thread and fs names, env var NINEPLAYER_MOUNT -> NINE_MOUNT, docs and test scripts. Browser assets move to web/static. Co-Authored-By: Claude Fable 5.1 <[email protected]>