summaryrefslogtreecommitdiff
path: root/core/ninep
diff options
context:
space:
mode:
Diffstat (limited to 'core/ninep')
-rw-r--r--core/ninep/events.zig4
-rw-r--r--core/ninep/pane.zig22
-rw-r--r--core/ninep/pty.zig1
-rw-r--r--core/ninep/tree.zig96
4 files changed, 88 insertions, 35 deletions
diff --git a/core/ninep/events.zig b/core/ninep/events.zig
index 1951a434..1fd05b54 100644
--- a/core/ninep/events.zig
+++ b/core/ninep/events.zig
@@ -332,7 +332,7 @@ fn newest(p: *Pardes) ?struct { at: usize, seq: u64, text: []const u8 } {
/// Whether a follower has read the record `seq`, or is part way through it.
fn followerRead(p: *Pardes, seq: u64) bool {
- for (p.fs.opens) |o| if (o.node != 0 and o.what == .log) {
+ for (p.fs.opens[0..p.fs.opens_len]) |o| if (o.node != 0 and o.what == .log) {
const l = o.what.log;
if (l.follow and (l.next > seq or (l.next == seq and l.part > 0))) return true;
};
@@ -437,6 +437,8 @@ fn pushLog(p: *Pardes, raw: []u8) void {
/// What an open of /log holds.
pub const LogOpen = struct {
+ /// Its reader's alone: what it is answered with (the log is the session's).
+ pub const replica = .{ .authority = .{ "bytes", "follow", "next", "part", "pos" } };
/// The ring's text when it was opened.
bytes: []const u8 = &.{},
/// This open waits for records after `bytes`, from `next`.
diff --git a/core/ninep/pane.zig b/core/ninep/pane.zig
index 1d514a3c..d47b637b 100644
--- a/core/ninep/pane.zig
+++ b/core/ninep/pane.zig
@@ -30,6 +30,28 @@ const Node = tree.Node;
/// Filesystem state a pane carries beside its editor state.
pub const State = struct {
+ /// What a step reads of it is digested and dumped (fs.Namespace); the
+ /// readers' records and the server's say of them are the session's.
+ pub const replica = .{ .authority = .{ "readers", "event_reader", "events", "tag_snap", "pty_reader", "pty_out", "winsize", "unannounced" } };
+
+ /// Its digest (core/walk.zig): nothing for a pane no script has set
+ /// anything of (most of them, at every unit a replica confirms); the
+ /// rest's fields as one run of bytes, not a hash's call a field.
+ pub fn digest(st: *const State, h: *pardes.walk.Hasher) void {
+ const untouched: State = .{};
+ var touched = false;
+ inline for (comptime pardes.walk.fieldNames(State)) |name| touched = touched or !std.meta.eql(@field(st, name), @field(untouched, name));
+ if (!touched) return;
+ var buf: [256]u8 = undefined;
+ var w: std.Io.Writer = .fixed(&buf);
+ // Longer than the room (a chord's text): field by field.
+ if (encoded(st, &w)) |_| h.update(w.buffered()) else |_| inline for (comptime pardes.walk.fieldNames(State)) |name| pardes.walk.hash(@FieldType(State, name), &@field(st, name), h);
+ }
+
+ fn encoded(st: *const State, w: *std.Io.Writer) std.Io.Writer.Error!void {
+ inline for (comptime pardes.walk.fieldNames(State)) |name| try pardes.walk.encode(@FieldType(State, name), &@field(st, name), w);
+ }
+
/// The range `data` and `xdata` read and write through. acme clears it
/// when the first client opens `addr` (editors/acme/xfid.c:105-108),
/// which suits a client that holds the fid open; a shell cannot, and
diff --git a/core/ninep/pty.zig b/core/ninep/pty.zig
index 4b0cee66..ec752311 100644
--- a/core/ninep/pty.zig
+++ b/core/ninep/pty.zig
@@ -164,6 +164,7 @@ pub const output_rows = output_cap / 8;
/// What an open of run holds (tree.zig's open records).
pub const Run = struct {
+ pub const replica = .{ .len = .{.{ "answer", "len" }} };
/// `waiting`: the line is kept until the shell's first prompt (a new
/// terminal's shell takes a moment to draw it), then sent.
phase: enum { idle, waiting, sent, done } = .idle,
diff --git a/core/ninep/tree.zig b/core/ninep/tree.zig
index 1eaaa8cb..3eeb5d3f 100644
--- a/core/ninep/tree.zig
+++ b/core/ninep/tree.zig
@@ -124,9 +124,45 @@ pub const out_reserve = 4 * 1024;
/// (editors/acme/dat.h:373-385). An open that holds something answers its
/// record's index plus one as the handle; one that holds nothing answers 0.
pub const Open = struct {
+ /// A client's join carries it and the digest covers it (fs.Namespace),
+ /// but what only its reader is answered with: the listener's held
+ /// read and the stream's last answer.
+ pub const replica = .{ .authority = .{ "held", "replay" } };
/// The node it was opened on, which every use checks; 0 is a free record.
node: u64 = 0,
- what: union(enum) {
+ what: What = .{ .snapshot = null },
+ /// What a write to a file of command lines left unfinished: a last line
+ /// with no newline yet, or an Edit block still open. A write through a
+ /// mount is cut at the 9P message size, so one `echo` of many lines may
+ /// come as several writes, cut anywhere; the rest waits for the open's
+ /// next write, or its release, and never runs as a fragment.
+ pending: std.ArrayList(u8) = .empty,
+ /// The panes this open's last write touched, which a read of look or
+ /// exec on it answers, as /net/tcp/clone answers on the open that
+ /// asked; a fresh open holds the session's last, from before it opened.
+ results: Results = .{},
+ /// A read that found nothing yet (`.again`), kept to be answered when
+ /// this open's file has something, the way factotum keeps its log's
+ /// waiting reads and answers them on append (security/auth/factotum/
+ /// log.c:4-52) and acme an event read (editors/acme/xfid.c:994). One at a
+ /// time, as acme's window keeps one `eventx`: a newer read takes the
+ /// place of the older. The listener fills it in and answers it
+ /// (runtime/9p_io.zig, `answerHeld`).
+ held: ?Held = null,
+ /// The last answer a stream open (a followed log, event, pty/data) gave,
+ /// and the offset it was read at. A read at an offset inside it is
+ /// answered from it again: bash's `read` takes a chunk, keeps a line and
+ /// lseeks back to just past it, and a stream has already moved on.
+ replay: ?Replay = null,
+ /// A `name` open has named its pane: one name an open, so a second line
+ /// on it (bash writes `printf 'a\nb\n'` a line at a time) is refused.
+ named: bool = false,
+ /// A line over 1 MiB was refused: what follows of it, through its
+ /// newline, is dropped rather than run as a line of its own.
+ discarding: bool = false,
+
+ /// What it is an open of, and what that holds.
+ pub const What = union(enum) {
/// /screen's frame from the open, a terminal body's history from its
/// first read.
snapshot: ?[]const u8,
@@ -160,40 +196,27 @@ pub const Open = struct {
/// An open reading a plumb port (Plumb.zig's ports, plumber(4)'s):
/// the messages sent to it since the open, packed, a read each.
port: struct { index: u8, queue: events.Queue = .{} },
- } = .{ .snapshot = null },
- /// What a write to a file of command lines left unfinished: a last line
- /// with no newline yet, or an Edit block still open. A write through a
- /// mount is cut at the 9P message size, so one `echo` of many lines may
- /// come as several writes, cut anywhere; the rest waits for the open's
- /// next write, or its release, and never runs as a fragment.
- pending: std.ArrayList(u8) = .empty,
- /// The panes this open's last write touched, which a read of look or
- /// exec on it answers, as /net/tcp/clone answers on the open that
- /// asked; a fresh open holds the session's last, from before it opened.
- results: Results = .{},
- /// A read that found nothing yet (`.again`), kept to be answered when
- /// this open's file has something, the way factotum keeps its log's
- /// waiting reads and answers them on append (security/auth/factotum/
- /// log.c:4-52) and acme an event read (editors/acme/xfid.c:994). One at a
- /// time, as acme's window keeps one `eventx`: a newer read takes the
- /// place of the older. The listener fills it in and answers it
- /// (runtime/9p_io.zig, `answerHeld`).
- held: ?Held = null,
- /// The last answer a stream open (a followed log, event, pty/data) gave,
- /// and the offset it was read at. A read at an offset inside it is
- /// answered from it again: bash's `read` takes a chunk, keeps a line and
- /// lseeks back to just past it, and a stream has already moved on.
- replay: ?Replay = null,
- /// A `name` open has named its pane: one name an open, so a second line
- /// on it (bash writes `printf 'a\nb\n'` a line at a time) is refused.
- named: bool = false,
- /// A line over 1 MiB was refused: what follows of it, through its
- /// newline, is dropped rather than run as a line of its own.
- discarding: bool = false,
+
+ /// What a step reads of it: not the text a reader is answered from
+ /// (a screen, a listing, the log, a port's messages), which each
+ /// process makes of its own state, and a replica never answers.
+ pub fn digest(w: *const What, h: *pardes.walk.Hasher) void {
+ const tag = std.meta.activeTag(w.*);
+ pardes.walk.hash(@TypeOf(tag), &tag, h);
+ switch (w.*) {
+ .run => |*run| pardes.walk.hash(pty.Run, run, h),
+ .event => |*reader| pardes.walk.hash(bool, reader, h),
+ .pager => |*serial| pardes.walk.hash(u32, serial, h),
+ .port => |*port| pardes.walk.hash(u8, &port.index, h),
+ .snapshot, .log, .frozen, .pty_data, .ctl, .lines, .writes, .plumb => {},
+ }
+ }
+ };
pub const Replay = struct { off: u64, bytes: []u8 };
pub const Results = struct {
+ pub const replica = .{ .len = .{.{ "list", "len" }} };
list: [pardes.MAX_PANES]u32 = undefined,
len: u8 = 0,
/// Written on: reads are a stream from the write on, whatever
@@ -230,7 +253,7 @@ pub const open_slots = 64;
/// The record a request's handle names, when it was opened on that node.
pub fn openOf(p: *Pardes, req: Req) ?*Open {
- if (req.handle == 0 or req.handle > p.fs.opens.len) return null;
+ if (req.handle == 0 or req.handle > p.fs.opens_len) return null;
const o = &p.fs.opens[req.handle - 1];
return if (o.node == req.node) o else null;
}
@@ -614,7 +637,7 @@ fn runAttr(p: *Pardes, req: Req, target: Target) ?Reply.Attr {
.top, .col, .port => return null,
};
if (t.file != .pty_run) return null;
- const run = if (req.handle != 0) openOf(p, req) else for (&p.fs.opens) |*o| {
+ const run = if (req.handle != 0) openOf(p, req) else for (p.fs.opens[0..p.fs.opens_len]) |*o| {
if (o.node == req.node and o.what == .run) break o;
} else null;
if ((run orelse return null).what != .run) return null;
@@ -895,7 +918,7 @@ fn open(p: *Pardes, req: Req, target: Target) Reply {
.ctl => if (linesOpen(target, req)) .lines else .{ .frozen = &.{} },
// One writer of the rules at a time, as plumber(4)'s.
.rules, .send => if (req.omode & 3 == 0) return .{ .tag = req.tag } else plumb: {
- if (f == .rules) for (p.fs.opens) |o| if (o.node == req.node and o.what == .plumb) return failText(req.tag, E.BUSY, e_in_use);
+ if (f == .rules) for (p.fs.opens[0..p.fs.opens_len]) |o| if (o.node == req.node and o.what == .plumb) return failText(req.tag, E.BUSY, e_in_use);
break :plumb .plumb;
},
else => if (linesOpen(target, req)) .lines else return .{ .tag = req.tag },
@@ -934,7 +957,11 @@ fn open(p: *Pardes, req: Req, target: Target) Reply {
// record would be another than the session's.
const i = p.tape.authority(freeOpen, .{p}) orelse return Reply.fail(req.tag, E.NFILE);
const o = &p.fs.opens[i];
+ // Past `opens_len` a replica's record may hold what a rollback did not
+ // put back (rollback.zig saves records as far as it says).
+ if (o.node != 0) o.deinit(p.gpa);
o.* = .{ .node = req.node, .what = what };
+ p.fs.opens_len = @max(p.fs.opens_len, @as(u8, @intCast(i + 1)));
if (resultsFile(target)) {
@memcpy(o.results.list[0..p.fs.results_len], p.fs.results[0..p.fs.results_len]);
o.results.len = p.fs.results_len;
@@ -1074,6 +1101,7 @@ fn releaseHandle(p: *Pardes, req: Req) void {
.snapshot, .log, .lines, .writes, .frozen, .pager, .plumb, .port => {},
};
o.deinit(p.gpa);
+ while (p.fs.opens_len > 0 and p.fs.opens[p.fs.opens_len - 1].node == 0) p.fs.opens_len -= 1;
}
fn setattr(p: *Pardes, req: Req, target: Target) Reply {