@ai-ecoverse/slicc-kernel 1.120.0 → 1.120.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/node.js CHANGED
@@ -4319,7 +4319,7 @@ var OpfsFs = class {
4319
4319
  this.rootName = channel;
4320
4320
  this.channel = channel === void 0 ? void 0 : new BroadcastChannel(channel);
4321
4321
  this.remote = channel === void 0 ? void 0 : new RemoteWatch(`${channel}:watch`);
4322
- if (this.remote) this.remote.quiet = () => this.quiet();
4322
+ if (this.remote) this.remote.quiet = () => this.quiet().then(() => this.settle?.());
4323
4323
  if (this.channel) {
4324
4324
  const remote = this.remote;
4325
4325
  meta.listen?.(
@@ -4474,6 +4474,15 @@ var OpfsFs = class {
4474
4474
  if (this.unlocked === 0) for (const done4 of this.idle.splice(0)) done4();
4475
4475
  }
4476
4476
  }
4477
+ settle;
4478
+ onPeer(settle) {
4479
+ this.settle = settle;
4480
+ }
4481
+ peers() {
4482
+ const remote = this.remote;
4483
+ if (!remote) return void 0;
4484
+ return { joined: () => remote.peered(), crowded: () => remote.crowded() };
4485
+ }
4477
4486
  quiet() {
4478
4487
  if (this.unlocked === 0) return Promise.resolve();
4479
4488
  return new Promise((resolve2) => this.idle.push(resolve2));
@@ -6747,7 +6756,7 @@ function satisfies(version, range2) {
6747
6756
  }
6748
6757
 
6749
6758
  // src/version.ts
6750
- var KERNEL_VERSION = true ? "1.120.0" : "0.0.0-dev";
6759
+ var KERNEL_VERSION = true ? "1.120.1" : "0.0.0-dev";
6751
6760
  var OS_RELEASE = "6.0.0-slicc";
6752
6761
  function procVersion() {
6753
6762
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -13739,10 +13748,14 @@ async function flock(req, ctx) {
13739
13748
  if (!locks || !flockOf) throw new KernelError("ENOLCK");
13740
13749
  if (!FLOCK_KINDS.has(req.kind)) throw new KernelError("EINVAL");
13741
13750
  const { key, owner } = await flockOf(req.fd);
13751
+ const granted2 = req.kind !== "unlock";
13752
+ const shared = locks.shared?.() === true;
13753
+ if (shared && !granted2) await ctx.settle?.(req.fd, false);
13742
13754
  if (req.kind !== "unlock" && req.wait)
13743
13755
  await locks.flocks.wait(key, owner, req.kind, ctx.blocking);
13744
13756
  else if (!await locks.flocks.set(key, owner, req.kind)) throw new KernelError("EAGAIN");
13745
- return done2;
13757
+ if (shared && granted2) await ctx.settle?.(req.fd, true);
13758
+ return shared ? json3(true) : done2;
13746
13759
  }
13747
13760
  async function recordLock2(req, ctx) {
13748
13761
  const { locks, fileKey } = ctx;
@@ -13753,6 +13766,7 @@ async function recordLock2(req, ctx) {
13753
13766
  ...req.fd !== void 0 ? { fd: req.fd } : {}
13754
13767
  };
13755
13768
  if (req.op === "lk-close") {
13769
+ if (req.fd !== void 0 && locks.shared?.()) await ctx.settle?.(req.fd, false);
13756
13770
  locks.dropFile(await fileKey(target, "close"), owner);
13757
13771
  return done2;
13758
13772
  }
@@ -13764,13 +13778,16 @@ async function recordLock2(req, ctx) {
13764
13778
  const len = held.end === Number.POSITIVE_INFINITY ? 0 : held.end - held.start;
13765
13779
  return json3({ kind: held.kind, pid: held.owner, start: held.start, len });
13766
13780
  }
13767
- if (req.kind !== "unlock" && req.wait) {
13781
+ const granted2 = req.kind !== "unlock";
13782
+ const shared = locks.shared?.() === true;
13783
+ const fd = shared ? req.fd : void 0;
13784
+ if (!granted2 && fd !== void 0) await ctx.settle?.(fd, false);
13785
+ if (req.kind !== "unlock" && req.wait)
13768
13786
  await locks.wait(key, owner, req.kind, range2, ctx.blocking);
13769
- return done2;
13770
- }
13771
- if (!await locks.set(key, owner, req.kind, range2.start, range2.end))
13787
+ else if (!await locks.set(key, owner, req.kind, range2.start, range2.end))
13772
13788
  throw new KernelError("EAGAIN");
13773
- return done2;
13789
+ if (granted2 && fd !== void 0) await ctx.settle?.(fd, true);
13790
+ return shared ? json3(true) : done2;
13774
13791
  }
13775
13792
 
13776
13793
  // src/kernel/net/loopback-transport.ts
@@ -16922,6 +16939,11 @@ var VfsNode = class {
16922
16939
  holds() {
16923
16940
  return this.dirty;
16924
16941
  }
16942
+ reread() {
16943
+ if (this.dirty || this.orphaned || this.pin || this.revoked) return;
16944
+ this.data = void 0;
16945
+ this.ranged = void 0;
16946
+ }
16925
16947
  replace(contents2) {
16926
16948
  this.ranged = void 0;
16927
16949
  this.data = new Uint8Array(contents2);
@@ -17549,6 +17571,7 @@ function vfsFile(fs, opts, nodes) {
17549
17571
  })),
17550
17572
  known: () => node.known(),
17551
17573
  flush: () => serial(() => node.flush()),
17574
+ reread: () => serial(async () => node.reread()),
17552
17575
  close: () => node.serial(async () => {
17553
17576
  try {
17554
17577
  takeOpenError();
@@ -18031,6 +18054,7 @@ var WasmProcess = class {
18031
18054
  owner: () => this.lockOwner(),
18032
18055
  fileKey: (target, kind, setting) => this.lockKey(target, kind, setting),
18033
18056
  flockOf: (fd) => this.flockOf(fd),
18057
+ settle: (fd, granted2) => this.settle(fd, granted2),
18034
18058
  locks: this.options.locks,
18035
18059
  ops: this.asyncOps,
18036
18060
  blocking: () => this.blockingSignal(cancelled),
@@ -18114,6 +18138,11 @@ var WasmProcess = class {
18114
18138
  else if (this.pathKeys.size < 4096) this.pathKeys.set(path, key);
18115
18139
  return key;
18116
18140
  }
18141
+ async settle(fd, granted2) {
18142
+ const file = this.fds.has(fd) ? this.fds.get(fd).file : void 0;
18143
+ if (granted2) await file?.reread?.();
18144
+ else await file?.flush?.();
18145
+ }
18117
18146
  async flockOf(fd) {
18118
18147
  const open = this.fds.get(fd);
18119
18148
  const { locks } = this.options;
@@ -19799,13 +19828,20 @@ var LockService = class {
19799
19828
  };
19800
19829
  void this.locks.request(this.aliveOf(this.kernel), () => new Promise(() => {
19801
19830
  }));
19802
- this.role = this.elect();
19831
+ const peers = options.peers;
19832
+ this.role = peers ? Promise.all([this.elect(), peers.joined()]).then(() => void 0) : this.elect();
19833
+ this.peers = options.peers;
19803
19834
  this.flocks = {
19804
19835
  set: (key, owner, kind) => this.flockSet(key, owner, kind),
19805
19836
  wait: (key, owner, kind, blocking) => this.flockWait(key, owner, kind, blocking),
19806
19837
  drop: (owner) => this.flockDrop(owner)
19807
19838
  };
19808
19839
  }
19840
+ peers;
19841
+ shared() {
19842
+ if (!this.leader || this.ownerOf.size > 0 || this.tokens.size > 0) return true;
19843
+ return this.peers?.crowded() === true;
19844
+ }
19809
19845
  aliveOf(kernel) {
19810
19846
  return `slicc-locks-alive:${LOCKS_PROTOCOL}:${this.root}:${kernel}`;
19811
19847
  }
@@ -20066,11 +20102,11 @@ var LockService = class {
20066
20102
  this.table.closed(pid, fd);
20067
20103
  }
20068
20104
  };
20069
- function kernelLocks(root) {
20105
+ function kernelLocks(root, peers) {
20070
20106
  const locks = globalThis.navigator?.locks;
20071
20107
  if (root === void 0 || !locks || typeof BroadcastChannel !== "function")
20072
20108
  return new LockTable();
20073
- return new LockService({ root, locks });
20109
+ return new LockService({ root, locks, ...peers ? { peers } : {} });
20074
20110
  }
20075
20111
  var ASK_OPS = /* @__PURE__ */ new Set([
20076
20112
  "set",
@@ -23526,7 +23562,7 @@ var Launcher = class {
23526
23562
  constructor(options) {
23527
23563
  this.usersMode = usersMode(options.users);
23528
23564
  this.rootFs = options.fs;
23529
- this.locks = kernelLocks(options.fs.rootName);
23565
+ this.locks = kernelLocks(options.fs.rootName, options.fs.peers?.());
23530
23566
  this.dac = this.usersMode === "off" ? void 0 : new Dac(this.usersMode, options.onDenial);
23531
23567
  if (this.dac) this.dac.tagOf = (pid) => this.tagOf(pid);
23532
23568
  this.clipboard = new ClipboardBroker(
@@ -23607,6 +23643,7 @@ var Launcher = class {
23607
23643
  this.nodes = new VfsNodes(fs, (path) => this.released(path));
23608
23644
  this.nodes.keepsOnDisk = true;
23609
23645
  this.openFiles.add(this.nodes);
23646
+ options.fs.onPeer?.(() => this.flushOpen());
23610
23647
  const holders = [this.held, this.openFiles];
23611
23648
  this.unlinked = new UnlinkedKeeper(
23612
23649
  fs,
@@ -25267,6 +25304,9 @@ var Launcher = class {
25267
25304
  this.writers ??= this.writerStack();
25268
25305
  return this.writers;
25269
25306
  }
25307
+ async flushOpen() {
25308
+ for (const nodes of this.openFiles) await nodes.flush("/").catch(() => void 0);
25309
+ }
25270
25310
  writerStack() {
25271
25311
  const mounted = this.mounts.wrap(this.unguardedRoot);
25272
25312
  const fs = this.commandFs(this.rooted(mounted));