diff options
| -rw-r--r-- | core/dump.zig | 26 | ||||
| -rw-r--r-- | core/replica.zig | 20 |
2 files changed, 30 insertions, 16 deletions
diff --git a/core/dump.zig b/core/dump.zig index c3742a21..82098449 100644 --- a/core/dump.zig +++ b/core/dump.zig @@ -259,13 +259,26 @@ pub fn image(p: *Pardes, name: []const u8) ![]u8 { /// out and noted in `deferred` (they are the session's, alive while pinned: /// memory.zig `pin`), each terminal whole (as the join's step reloaded it /// on every side: panes.reloadTerminals), its sequence in flight with it. -/// What is left is the session's mutable state, made in its step. -pub fn dumpJoin(p: *Pardes, deferred: *std.ArrayListUnmanaged(walk.Deferred)) ![]u8 { +/// What is left is the session's mutable state, made in its step. With it +/// the session's digest at that moment, which the client checks its load +/// by. +/// +/// One moment: nothing in it gives up the turn (pardes.turn: a host call +/// does, tape.out), or a 9P request answered meanwhile is in the dump and +/// in the client's next unit both, and moves the core between the dump and +/// the digest: the client then refused its own load and went (a script +/// reading /screen at a rejoin, 2026-11-22). So a join's dump asks the host +/// nothing (`on_disk`, a revival's, is none in it). +pub fn dumpJoin(p: *Pardes, deferred: *std.ArrayListUnmanaged(walk.Deferred)) !struct { bytes: []u8, digest: u64 } { // The join's file reads are the session's host's, between its steps: // with its io, which the core's tape holds (a walk's hook takes no more). join_files = p.tape.io; defer join_files = null; - return dumpWith(p, deferred); + const yields = pardes.turn.yields; + const bytes = try dumpWith(p, deferred); + errdefer p.gpa.free(bytes); + if (pardes.turn.yields != yields) return error.TurnGivenUp; + return .{ .bytes = bytes, .digest = pardes.tape.digestOf(p) }; } /// `dumpExit`'s: a terminal dumps its size, not its emulator. @@ -281,10 +294,9 @@ fn dumpWith(p: *Pardes, deferred: ?*std.ArrayListUnmanaged(walk.Deferred)) ![]u8 try d.put(Pardes, p); const mounts: []const filesystem.Mount = p.fs.mounts.items; try d.put([]const filesystem.Mount, &mounts); - var on_disk: OnDisk = @splat(false); - for (p.panes, &on_disk) |slot, *on| if (slot) |pane| { - on.* = onDisk(p.tape, pane); - }; + // Which files were on disk is a revival's (`image`): a client's load + // never reads it, and a join asks the host nothing. + const on_disk: OnDisk = @splat(false); try d.put(OnDisk, &on_disk); const theme: []const u8 = colors.themes[@min(p.settings.theme, colors.themes.len - 1)].name; try d.put([]const u8, &theme); diff --git a/core/replica.zig b/core/replica.zig index 957e6d5f..75aa94e1 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -296,7 +296,8 @@ pub const Authority = struct { const u = try a.unit(0, a.seq); var blobs: std.ArrayListUnmanaged(walk.Deferred) = .empty; defer blobs.deinit(a.core.gpa); - const state = try pardes.dump.dumpJoin(a.core, &blobs); + const dumped = try pardes.dump.dumpJoin(a.core, &blobs); + const state = dumped.bytes; defer a.core.gpa.free(state); tape.resync(&a.t); var whole: std.ArrayListUnmanaged(u8) = .empty; @@ -308,7 +309,7 @@ pub const Authority = struct { pos = b.at; } try whole.appendSlice(a.gpa, state[pos..]); - return .{ .view = k, .unit = u, .dump = try whole.toOwnedSlice(a.gpa), .digest = tape.digestOf(a.core) }; + return .{ .view = k, .unit = u, .dump = try whole.toOwnedSlice(a.gpa), .digest = dumped.digest }; } /// Client `client` gone as `Peers.leave` lets one go: its view kept for @@ -1978,7 +1979,7 @@ pub const Peers = struct { // undo, registers) left out, pinned, and streamed by the client's // writer thread: the step pays for the state, not for the text. var blobs: std.ArrayListUnmanaged(walk.Deferred) = .empty; - const bytes = pardes.dump.dumpJoin(core, &blobs) catch |err| { + const dumped = pardes.dump.dumpJoin(core, &blobs) catch |err| { blobs.deinit(core.gpa); core.undrawn &= ~(@as(u8, 1) << @intCast(k)); core.closeView(.at(k)); @@ -1987,6 +1988,7 @@ pub const Peers = struct { var why: [96]u8 = undefined; return daemon.refuseReplica(fd, std.fmt.bufPrint(&why, "that session could not be dumped: {t}", .{err}) catch "that session could not be dumped"); }; + const bytes = dumped.bytes; var whole = bytes.len; for (blobs.items) |b| { pardes.memory.pin(b.bytes); @@ -2008,7 +2010,7 @@ pub const Peers = struct { if (ps.next_id == 0) ps.next_id = 1; // The session's digest as dumped, for the joiner to check its load by // (a pair's client, its own boot: `writeJoin`). - const digest = tape.digestOf(core); + const digest = dumped.digest; peer.digest = digest; peer.welcome_len = (wire.encodeServer(&peer.welcome, .{ .welcome = .{ .pid = @intCast(libc.getpid()), .session = ps.name[0..@min(ps.name.len, wire.max_name)], .client = peer.id, .view = peer.view, .dump_len = whole, .gmtoff = gmtoff(), .digest = digest, .semantics = wire.semantics, .blobs = @intCast(blobs.items.len) } }) catch unreachable).len; if (ps.threads) peer.writer = std.Thread.spawn(.{}, Peer.writeLoop, .{peer}) catch null; @@ -3380,11 +3382,11 @@ fn farJoinOnce(ps: *Peers, core: *Pardes, have: ?*Have) !Joined { var fds: [2]c_int = undefined; if (libc.socketpair(libc.AF.UNIX, libc.SOCK.STREAM | libc.SOCK.CLOEXEC, 0, &fds) != 0) return error.NoSocket; var blobs: std.ArrayListUnmanaged(walk.Deferred) = .empty; - const state = pardes.dump.dumpJoin(core, &blobs) catch |err| { + const state = (pardes.dump.dumpJoin(core, &blobs) catch |err| { _ = libc.close(fds[0]); _ = libc.close(fds[1]); return err; - }; + }).bytes; var whole = state.len; for (blobs.items) |b| whole += b.bytes.len; const peer = try ps.gpa.create(Peer); @@ -3431,7 +3433,7 @@ fn joinedNow(a: *Authority, id: u16, view: u8) !*Replica { const was = Stepping.begin(&a.t, null); var blobs: std.ArrayListUnmanaged(walk.Deferred) = .empty; defer blobs.deinit(a.core.gpa); - const state = try pardes.dump.dumpJoin(a.core, &blobs); + const state = (try pardes.dump.dumpJoin(a.core, &blobs)).bytes; defer a.core.gpa.free(state); tape.resync(&a.t); was.end(); @@ -4857,7 +4859,7 @@ test "a join's dump, its blobs put back where they go, is the session's dump" { defer a.core.gpa.free(whole); var blobs: std.ArrayListUnmanaged(walk.Deferred) = .empty; defer blobs.deinit(a.core.gpa); - const state = try pardes.dump.dumpJoin(a.core, &blobs); + const state = (try pardes.dump.dumpJoin(a.core, &blobs)).bytes; defer a.core.gpa.free(state); try std.testing.expect(blobs.items.len > 0); try std.testing.expect(state.len + 20000 <= whole.len); @@ -4990,7 +4992,7 @@ test "a far join is sent each blob once: joined again with them on disk or in th // What the session's list will say: its blobs, those of one text once. var listed: std.ArrayListUnmanaged(walk.Deferred) = .empty; defer listed.deinit(a.core.gpa); - a.core.gpa.free(try pardes.dump.dumpJoin(a.core, &listed)); + a.core.gpa.free((try pardes.dump.dumpJoin(a.core, &listed)).bytes); var distinct: std.AutoHashMapUnmanaged([32]u8, usize) = .empty; defer distinct.deinit(gpa); var distinct_bytes: u64 = 0; |
