summaryrefslogtreecommitdiff
path: root/core/fs.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/fs.zig')
-rw-r--r--core/fs.zig78
1 files changed, 76 insertions, 2 deletions
diff --git a/core/fs.zig b/core/fs.zig
index 6e5829e1..6b43ba67 100644
--- a/core/fs.zig
+++ b/core/fs.zig
@@ -830,6 +830,16 @@ pub const EditHold = struct {
return req.op == .write and req.tag == h.tag and req.node == h.node and req.handle == h.handle;
}
+ /// The held write asked again by a retry of its park, as the listener
+ /// answers it, never a step (no replica holds it): still waiting, or
+ /// its answer; null for any other request.
+ pub fn retried(ns: *Namespace, req: tree.Req) ?tree.Reply {
+ const h = if (ns.edit_hold) |*held| held else return null;
+ if (!h.names(req)) return null;
+ if (!h.done) return .{ .tag = req.tag, .status = .again };
+ return answer(ns);
+ }
+
/// Its answer, the held record let go: the words copied out first.
pub fn answer(ns: *Namespace) tree.Reply {
const h = ns.edit_hold.?;
@@ -841,6 +851,32 @@ pub const EditHold = struct {
};
pub const Namespace = struct {
+ /// What a step reads that 9P requests made (every request an input
+ /// each replica replays) is the core's like any state: the open
+ /// records (a command pane a script reads is not taken again:
+ /// exec.leased), the panes the last look or exec touched (a new open's
+ /// own), the writes held to go in as one edit and a header tag's
+ /// truncation, digested and dumped (a client's join takes them from
+ /// the dump; a session revived from one drops the opens with the
+ /// connections that held them: dump.zig `loadAndRevive`). The rest is
+ /// the server's (core/walk.zig): its sockets and the mounts (dumped
+ /// on their own), the log and what a reader or a listener is answered
+ /// with, and the request being served's own flags, set and read in
+ /// its step, and `edit_hold`: the listener's, which answers a retry
+ /// of the held write from it, no step (`EditHold.retried`).
+ pub const replica = .{
+ .authority = .{
+ "socket_path", "tcp_address", "mounts", "node_name", "os_paths", "out",
+ "listeners", "origin", "no_prompt", "session_write", "unlogged", "capturing",
+ "serving", "refused", "failure", "failure_len", "no_pane_slot", "no_pane_slot_len",
+ "said", "said_len", "said_at", "late_failure", "late_failure_len",
+ "lsp_answer_at", "edit_started", "edit_hold", "edit_said", "lsp_result", "write_room",
+ "write_waits", "log_full_hash", "pages", "closed_lines", "ran_at", "refilled",
+ "failures", "ename", "news", "hanging_up", "log", "plumb_held",
+ "started",
+ },
+ .len = .{ .{ "opens", "opens_len" }, .{ "results", "results_len" } },
+ };
socket_path: []const u8 = "",
tcp_address: ?std.Io.net.IpAddress = null,
mounts: std.ArrayList(Mount) = .empty,
@@ -848,6 +884,11 @@ pub const Namespace = struct {
os_paths: std.ArrayList(OsPath) = .empty,
/// What each open holds between its open and its release.
opens: [tree.open_slots]tree.Open = @splat(.{}),
+ /// The records past it are nothing: a digest, a dump and a replica's
+ /// rollback copy take the opens this far (an idle session's none), and
+ /// nothing reads or frees one past it (a rollback leaves there what
+ /// its epoch freed).
+ opens_len: u8 = 0,
out: std.ArrayList(u8) = .empty,
listeners: u16 = 0,
origin: u8 = 'K',
@@ -902,7 +943,7 @@ pub const Namespace = struct {
/// commands run off the loop (edit_cmd.zig): the listener holds it.
edit_started: bool = false,
/// That write, held: answered once `done` (9p_io answerHeld), or
- /// asked again by a retry of its park (Pardes.serveFs); a flush or a
+ /// asked again by a retry of its park (`EditHold.retried`); a flush or a
/// hang-up stops the Edit (9p_io watchEdit).
edit_hold: ?EditHold = null,
/// The words a held Edit write was refused with, kept for its answer.
@@ -985,7 +1026,7 @@ pub const Namespace = struct {
st.mounts.deinit(gpa);
for (st.os_paths.items) |entry| gpa.free(entry.path);
st.os_paths.deinit(gpa);
- for (&st.opens) |*o| o.deinit(gpa);
+ for (st.opens[0..st.opens_len]) |*o| o.deinit(gpa);
for (st.pages.items) |*page| page.bytes.deinit(gpa);
st.pages.deinit(gpa);
for (st.closed_lines.items) |*line| line.bytes.deinit(gpa);
@@ -995,6 +1036,39 @@ pub const Namespace = struct {
st.out.deinit(gpa);
}
+ /// Its digest (core/walk.zig): the opens in use, and writes held by
+ /// their length (their bytes are the same writes on every side; a
+ /// stream of 8 KB appends hashed whole cost each its length again;
+ /// none held, the rest of `batch` is nothing a step reads), the panes
+ /// the last look or exec touched, a header's truncation. Nothing at
+ /// all for a session no script holds anything of.
+ pub fn digest(st: *const Namespace, h: *pardes.walk.Hasher) void {
+ comptime if (pardes.walk.fieldNames(Namespace).len != 8) @compileError("Namespace.digest: hash every field the walk does not leave out");
+ for (st.opens[0..st.opens_len]) |*o| pardes.walk.hash(tree.Open, o, h);
+ h.update(std.mem.sliceAsBytes(st.results[0..st.results_len]));
+ if (st.header_rewrite != null or st.header_trunc_pending != null or st.header_held) {
+ const words = [_]u64{ st.header_rewrite orelse std.math.maxInt(u64), st.header_trunc_pending orelse std.math.maxInt(u64), @intFromBool(st.header_held) };
+ h.update(std.mem.asBytes(&words));
+ }
+ const b = &st.batch;
+ if (b.bytes.items.len == 0) return;
+ const words = [_]u64{ b.serial, b.node, b.handle, b.at, b.bytes.items.len, b.last_ns };
+ h.update(std.mem.asBytes(&words));
+ }
+
+ /// What the requests of connections gone made, let go: a session
+ /// revived from a dump has none of the connections that held its opens.
+ pub fn forget(st: *Namespace, gpa: std.mem.Allocator) void {
+ for (st.opens[0..st.opens_len]) |*o| o.deinit(gpa);
+ st.opens_len = 0;
+ st.results_len = 0;
+ st.batch.bytes.deinit(gpa);
+ st.batch = .{};
+ st.header_rewrite = null;
+ st.header_trunc_pending = null;
+ st.header_held = false;
+ }
+
pub fn mount(st: *Namespace, gpa: std.mem.Allocator, name: []const u8, dial: []const u8) !void {
if (!validMountName(name)) return error.BadMountName;
try ninep_io.Client.validateDial(dial);