From 5dcfade5f102256de787b2157b01293160780411 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 21 Sep 2026 22:37:06 -0300 Subject: Make a pane by opening /pane/new, and a Plan 9 idiom pass The Tcreate that replaced acme's /new was a step away from the idiom dressed up as a step toward it. A pane is named by a server-assigned serial, so the create ignored the client's name: `mkdir /pane/foo` succeeded and left you /pane/12. A mkdir that does not make the directory you named is worse than the read-with-side-effect it replaced, and it broke in the shell workflow that motivated the change. `create` is out of the declared features, so Tcreate is EPERM again; Tremove stays, since `rm` to close a pane is unambiguously right. /pane/new is now opened, not created: the open makes the pane, the read of that fid answers its serial, two reads agree, and closing it leaves the pane. That is /net/tcp/clone's mechanism (kernel/network/ip/devip.c, in ipopen), not acme's, and the difference is deliberate. acme allocates during the walk and lands inside the new window, so /dev/new/body works in one step, and it can afford to list `new` because a Plan 9 directory read carries every entry's stat and nothing walks. A kernel or FUSE mount walks and stats each name a listing gave it, so allocate-on-walk would make a pane per `ls -l`. Allocating on open keeps `new` listed -- a stat is not an open -- at the cost of the one-step new/body. `new` stays unreachable from an editor path, because that resolution serves Look hover previews. The idiom pass behind it, read out of the Plan 9 tree at ~/05-genizah/principia-softwarica rather than recalled: Rerror carries a string, not an errno (man 5 error: `ename[s]`), and acme names every refusal. The five refusals pardes shares with acme now say what they mean; the generic sites keep their bare errno rather than invent strings acme does not have. body and tag declare DMAPPEND, which they had always behaved as (acme(4): "always appended; the file offset is ignored"), checked first against Linux's fs/9p, which never maps the bit. excl stays unset everywhere, because acme sets DMEXCL on nothing. Blocking reads, per-object addr scope and the readable pane ctl were already right. Real stat sizes and qid versions stay: acme reports length 0 and version 0 for everything, and Linux clients need better. One bug fell out of it. open reset the addr range, so `echo '#0,#5' >addr; cat addr` answered `0 0` and `cp addr dot` copied zeros. acme(4) makes the contract explicit -- "a regular expression may be evaluated by writing it to addr and reading it back" -- and acme gets away with resetting on the 0-to-1 open only because its clients hold the fid across both. A shell cannot: that is two opens. The register is cleared by truncating it now. Co-Authored-By: Claude Opus 5 (1M context) --- test/fs.py | 27 +++++++++++++++------------ test/v9fs.py | 29 +++++++++++++---------------- 2 files changed, 28 insertions(+), 28 deletions(-) (limited to 'test') diff --git a/test/fs.py b/test/fs.py index c3ffa440..b20dc8ee 100644 --- a/test/fs.py +++ b/test/fs.py @@ -106,9 +106,8 @@ def newest(client): def new_pane(client, contents): - """mkdir in /pane; the editor names the directory after the new serial.""" - client.mkdir('/pane', 'scratch') - serial = newest(client) + """An open of /pane/new makes a pane; the read names it.""" + serial = int(client.read('/pane/new')) if contents: client.write(f'/pane/{serial}/body', contents) return serial @@ -151,7 +150,7 @@ def discovery(binary, embedded=False): assert ('src' in top) == embedded, (top, embedded) before = client.read('/index') guide = client.read('/README') - assert guide.count(b'\n') <= 45 and b'Msg hello' in guide and b'mkdir' in guide, guide + assert guide.count(b'\n') <= 45 and b'Msg hello' in guide and b'pane/new' in guide, guide assert client.stat('/README')['length'] == len(guide) # ls/stat/find over the whole tree, without opening, creates nothing. seen = walk_tree(client) @@ -183,17 +182,20 @@ def discovery(binary, embedded=False): status = dict(line.split(maxsplit=1) for line in client.read('/status').decode().splitlines()) assert int(status['pid']) > 0 and status['version'] and int(status['panes']) >= 1, status assert client.read('/exec') == b'' - # mkdir makes a pane, named by the serial the editor gives it. + # An open of /pane/new makes a pane and the read names it; each + # open makes another. A stat makes none, which is why new can be + # listed at all: ls -l stats every name a listing gave it. log = client.open('/log') - client.mkdir('/pane', 'one') - first = newest(client) - client.mkdir('/pane', 'two') - second = newest(client) + first = int(client.read('/pane/new')) + assert first == newest(client) + second = int(client.read('/pane/new')) assert first != second and first != fixture, (first, second) - assert 'one' not in client.list('/pane') and 'two' not in client.list('/pane') + assert 'new' in client.list('/pane'), 'new should be visible to ls' + client.stat('/pane/new') + assert newest(client) == second, 'a stat of new made a pane' assert client.read_fid(log) == f'new {first} {root}/+New\n'.encode() assert client.read_fid(log) == f'new {second} {root}/+New\n'.encode() - assert set(client.list('/pane')) == {str(fixture), str(first), str(second)} + assert set(client.list('/pane')) == {'new', str(fixture), str(first), str(second)} client.write(f'/pane/{first}/body', b'first pane', truncate=True) assert client.read(f'/pane/{first}/body') == b'first pane' assert client.read(f'/pane/{second}/body') == b'' @@ -247,6 +249,7 @@ def discovery(binary, embedded=False): refused = [lambda: client.write('/exec', b'Msg a\x00b'), lambda: client.write('/status', b'anything\n'), lambda: client.mkdir('/', 'x'), + lambda: client.mkdir('/pane', 'one'), lambda: client.create('/pane', 'plain-file'), lambda: client.remove('/pane/1/body'), lambda: client.remove('/index')] @@ -262,7 +265,7 @@ def discovery(binary, embedded=False): assert client.read('/src/pardes.zig').startswith(b'const std') assert client.stat('/src/pardes.zig')['mode'] == 0o444 assert b'pub const Pardes' in client.read(f'/pane/{look(client, "/virtual/src/pardes.zig")}/body') - print('9P discovery: listing/stat/find are inert; create, remove, look, exec, name, sel and log behave') + print('9P discovery: listing/stat/find are inert; new, remove, look, exec, name, sel and log behave') def test(binary, quic=False): diff --git a/test/v9fs.py b/test/v9fs.py index fa35388f..30efe9fb 100644 --- a/test/v9fs.py +++ b/test/v9fs.py @@ -45,6 +45,7 @@ def worker(mountpoint, socket, uid, gid, original_namespace): tree = mountpoint assert {'os', 'index', 'pane', 'status', 'look', 'exec', 'log', 'screen', 'README'} <= set(os.listdir(tree)) assert 'self' not in os.listdir(tree) and 'new' not in os.listdir(tree) + assert 'new' not in os.listdir(tree / 'pane'), 'a listing would make a pane per stat' # A direct connection provides independent evidence for VFS reads/writes. with Client(socket) as client: assert (tree / 'index').read_bytes() == client.read('/index') @@ -55,26 +56,22 @@ def worker(mountpoint, socket, uid, gid, original_namespace): subprocess.run(['find', str(tree / 'pane'), '-ls'], check=True, capture_output=True, timeout=5) assert (tree / 'README').read_bytes() == client.read('/README') assert client.read('/index') == before, 'browsing created panes' - # mkdir through the kernel mount opens a pane. The editor names it - # after its serial, not after the name asked for, so the kernel's own - # revalidation of that name may fail; the index is the answer. + # Opening pane/new makes a pane and the read names it, so no trip + # through the index. Whether a repeated path reaches the server at all + # is the kernel's dentry cache's business, so the second pane comes + # over the wire, where the open is exact. def serials(): return {int(row.split()[0]) for row in (tree / 'index').read_bytes().splitlines()} - def mkpane(name): + def mkpane(): known = serials() - try: - (tree / 'pane' / name).mkdir() - except FileNotFoundError: - pass - made = serials() - known - assert len(made) == 1, (name, made) - return made.pop() - - serial = mkpane('kernel-made') - another = mkpane('kernel-made-again') - assert serial != another, 'a second mkdir reused a pane' - assert not (tree / 'pane' / 'kernel-made').exists() + made = int((tree / 'pane' / 'new').read_bytes()) + assert made not in known, 'the open of new made no pane' + return made + + serial = mkpane() + another = int(client.read('/pane/new')) + assert serial != another, 'a second open of new reused a pane' (tree / 'pane' / str(another)).rmdir() assert another not in serials() pane = tree / 'pane' / str(serial) -- cgit v1.3