@threadedstack/wmd-web 0.1.27 → 0.1.29
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/README.md +29 -0
- package/RELEASE.json +19 -14
- package/guest/arm64/Image +1 -1
- package/guest/arm64/Image-4k +1 -1
- package/guest/arm64/features +4 -0
- package/guest/arm64/initramfs.cpio.gz +0 -0
- package/package.json +3 -3
- package/src/boot.js +12 -1
- package/src/build/builder.js +4 -2
- package/src/host/ckpt.js +2 -1
- package/src/host/ctl.js +3 -1
- package/src/host/p9mount.js +283 -5
- package/wmdpack.wasm +0 -0
package/README.md
CHANGED
|
@@ -2708,3 +2708,32 @@ command in a keep-running container that has none running (browser only: for a b
|
|
|
2708
2708
|
After a restore, attach the main process again with `onCommand`: the guest sends the restored machine's state.
|
|
2709
2709
|
Guide: `../docs/keep-running.md`. Tests: `test/unit/ctl-keep-running.test.js`, `test/b9/b9keep.spec.js`
|
|
2710
2710
|
(`bunx playwright test -c test/b9 b9keep`, under the boot lock; 4 tests, passing in Chromium, Firefox and WebKit).
|
|
2711
|
+
|
|
2712
|
+
## The root mount's `names` option (X23, issue #68)
|
|
2713
|
+
|
|
2714
|
+
The guest kernel can carry `guest/linux/patches/common/0006-9p-names-mount-option.patch`. Its mount option `names` keeps the names and
|
|
2715
|
+
attributes the guest has seen across a cache drop (the page's `ck.dropNames()`), which makes the Go build about a third faster in Chromium.
|
|
2716
|
+
|
|
2717
|
+
- The guest folder says whether its kernel has the option: `features` (next to `initramfs.cpio.gz`; `guest/linux/features`) has the word
|
|
2718
|
+
`p9-names`. Only a kernel build with the patch writes it (every kernel the guest build links applies `patches/common`).
|
|
2719
|
+
- What the page mounts when nothing is named (`src/host/p9mount.js`, `p9CacheDefault`): `P9_NAMES_DEFAULT` is on, so `cache=mmap,names` on a kernel with the word
|
|
2720
|
+
and plain `cache=mmap` on a kernel without it (no refusal, no error). Switch it off in `p9mount.js` or name `?p9cache=mmap`. Pages that call `p9MountOptions()` with no
|
|
2721
|
+
features (wmn, net, w71, bk-spike, netsw, b7, base) stay plain; `ckpt.html` (the speed suite and the browser tests), `build.html` and `disk.html` take the default.
|
|
2722
|
+
- `?p9cache=mmap` is plain whatever the kernel has. `?p9cache=mmapnames` on a kernel without the word refuses the start.
|
|
2723
|
+
- A restore that names no option runs with the option its checkpoint was taken with (`ck.bootFromOpfs`), so a checkpoint made before the
|
|
2724
|
+
default changed (plain) still restores into a default page. A restore that names a different option is refused as `stale` (the option is in the boot key).
|
|
2725
|
+
- An embedder of `src/boot.js`: `bootWmd` reads the guest folder's `features` (the sibling of the initramfs URL; or pass `features`: the file's text,
|
|
2726
|
+
an array or a Set) and the machine has `vm.features` and `vm.p9MountOptions({msize?, cache?})`. Send `vm.p9MountOptions()` as the run request's
|
|
2727
|
+
`p9opts` and the machine gets the default of its kernel. `p9MountOptions({features})` does the same without a machine; `p9MountOptions()` alone is plain.
|
|
2728
|
+
- The read of `features` cannot hold a boot: a request with no answer in 10 s (`P9_FEATURES_LIMIT_MS`) is aborted and counts as no file, with a console
|
|
2729
|
+
warning; the boot mounts plain. A file with a line that is not a word (letters, digits, `.`, `_`, `-`), such as a server's own page sent for a missing
|
|
2730
|
+
file, has no word at all. `ckpt.html` asks for the file once per boot, and not at all when `p9cache` is named.
|
|
2731
|
+
- How the read ended is kept (fix 5): `readGuestFeatures(url)` gives `{words, how}` with `how` one of `read`, `none` (no file), `bad` (no features file, or
|
|
2732
|
+
over 64 KiB, `P9_FEATURES_MAX_BYTES`), `error` and `late`; a machine has `vm.featuresHow` (also `given`), `ckpt.html` has `ck.featuresHow` (also `skipped`)
|
|
2733
|
+
and an event `features`. After `error` or `late` (`p9FeaturesLost`) the page boots plain although the kernel may have names: the speed suite's cell
|
|
2734
|
+
(`test/b9/b9w30.spec.js`) refuses such a run, and one whose mount line has no `names` when the features file had the word (`p9RunRefusal`), and
|
|
2735
|
+
writes `p9opts` and `featuresHow` into its JSON.
|
|
2736
|
+
- The `wmd-web` package carries `guest/arm64/features` (`scripts/web-release.py`), so an embedder that gives `bootWmd` the package's files by URL gets
|
|
2737
|
+
the default of its kernel. One that gives the files as bytes passes the file's text as `features`.
|
|
2738
|
+
- `scripts/speed-suite/p9count.sh` prints `P9C-RAN names|plain`, read from the guest's own mount line, and discards a run whose line does not match
|
|
2739
|
+
what the query named.
|
package/RELEASE.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wmd-web",
|
|
3
3
|
"version": "0.5.1",
|
|
4
|
-
"commit": "
|
|
4
|
+
"commit": "965e79897093369d1dd263b5588efc3619d47c7b",
|
|
5
5
|
"previous": null,
|
|
6
6
|
"decisions": [
|
|
7
7
|
"D-388",
|
|
@@ -74,34 +74,39 @@
|
|
|
74
74
|
"bytes": 1567615
|
|
75
75
|
},
|
|
76
76
|
"Image": {
|
|
77
|
-
"sha256": "
|
|
77
|
+
"sha256": "52986d5f07de886c57d8d083c26f5af0877cc9faa096d0dbdb68c859d2acd52a",
|
|
78
78
|
"bytes": 39049224
|
|
79
79
|
},
|
|
80
80
|
"Image-4k": {
|
|
81
|
-
"sha256": "
|
|
81
|
+
"sha256": "497815d8a0afc7afbef2bd574c24e96d3c6724aef1bae9617016c0c8a99846fc",
|
|
82
82
|
"bytes": 38828040
|
|
83
83
|
},
|
|
84
84
|
"initramfs.cpio.gz": {
|
|
85
|
-
"sha256": "
|
|
86
|
-
"bytes":
|
|
85
|
+
"sha256": "ec74f162155e20aabb6fe1f3bea592c03a85f07bee8844fd302a5285b20b4de1",
|
|
86
|
+
"bytes": 4686052
|
|
87
|
+
},
|
|
88
|
+
"features": {
|
|
89
|
+
"sha256": "02693b8b6c099e10fdb7a092394102ee92971ce1e39d0d6e5327ff8be1d0ee74",
|
|
90
|
+
"bytes": 113
|
|
87
91
|
}
|
|
88
92
|
}
|
|
89
93
|
},
|
|
90
94
|
"files": {
|
|
91
|
-
"README.md": "
|
|
95
|
+
"README.md": "adf0a05d69ab165a996717bda5ac68f716e00bef175b7162fccb4df1796a4e1b",
|
|
92
96
|
"export-page/coi-sw.js": "0300e670b413cb2e0aae35843fc583546bbf6687df971ab6df41cfa3b0d494d7",
|
|
93
97
|
"export-page/index.html": "f5450c89e63601bbbbffef421f03491b231d1f143070012c1c5315d4b0059f43",
|
|
94
98
|
"export-page/run.css": "b57adf1e76553549c1f89ff157b7973409dedc21889cd3932948cd05b51adc6f",
|
|
95
99
|
"export-page/run.js": "717636a632a40469106ddf1383e198eaac5d83651b5866d0699ec04b82462b7f",
|
|
96
|
-
"guest/arm64/Image": "
|
|
97
|
-
"guest/arm64/Image-4k": "
|
|
98
|
-
"guest/arm64/
|
|
100
|
+
"guest/arm64/Image": "52986d5f07de886c57d8d083c26f5af0877cc9faa096d0dbdb68c859d2acd52a",
|
|
101
|
+
"guest/arm64/Image-4k": "497815d8a0afc7afbef2bd574c24e96d3c6724aef1bae9617016c0c8a99846fc",
|
|
102
|
+
"guest/arm64/features": "02693b8b6c099e10fdb7a092394102ee92971ce1e39d0d6e5327ff8be1d0ee74",
|
|
103
|
+
"guest/arm64/initramfs.cpio.gz": "ec74f162155e20aabb6fe1f3bea592c03a85f07bee8844fd302a5285b20b4de1",
|
|
99
104
|
"guest/arm64/vm.wasm": "1553b50b591cc579d2ce24e79c3fd72360db34a8a337c108e25e515a5eb920b6",
|
|
100
105
|
"package.json": "7d43c05047d0a3ea56b4a7709f48a60de32e15c3bdf328d55435c46637981b40",
|
|
101
106
|
"src/base.js": "982f8e46dbb727ec542a494ebdb884ccd19a31ff4e091425b2d1fc01b0d4754a",
|
|
102
107
|
"src/blob.js": "bb2a2f0d87ce236280a7be2f246c926010dfe07f649c27da5e70d8eb5eaf7061",
|
|
103
|
-
"src/boot.js": "
|
|
104
|
-
"src/build/builder.js": "
|
|
108
|
+
"src/boot.js": "6b3ccc21d18ff6f78a42d90e3bc5f76f83566f5e44aafea33be749227d394fd6",
|
|
109
|
+
"src/build/builder.js": "0e5823e377966eecb69a9d5cd8130bf9adf254fcde2c90ba897eafadbc138127",
|
|
105
110
|
"src/build/context.js": "d38097c61dbdadc4d41290c010425a4422f499aba473fa2b83f2a5c41e543571",
|
|
106
111
|
"src/build/dockerfile.js": "5957fe3d4ac8ff8b312f980ee04bd1d98ad4373a61f9a33e02f1ff1108b6ea53",
|
|
107
112
|
"src/build/dockerignore.js": "8fc03d09da020f43ea483979b1183891b71d76f012379ab7813838ea0e53c546",
|
|
@@ -131,9 +136,9 @@
|
|
|
131
136
|
"src/host/ckpt-io.js": "3fbe74f0254c597f10d088c85e8ba72725502d86ae4dd8c6d2bf0821a93c873f",
|
|
132
137
|
"src/host/ckpt-point.js": "42bc16b3f754de3cd4e39f37a0feca2ffd8b4231cd72ec32bd6e1ea734c3c8c7",
|
|
133
138
|
"src/host/ckpt-save.js": "e222571033ae74a4439596c5e90e03b2aa9a5516665dd290f8dd243712294523",
|
|
134
|
-
"src/host/ckpt.js": "
|
|
139
|
+
"src/host/ckpt.js": "b34123726820de8de022f1c410b200b102877953e9105e398ff715fd5d846241",
|
|
135
140
|
"src/host/clock.js": "aba6af3a8b1a985ae340892222e4b482d33afe20f5c8b3a4c7403ce87d1e247c",
|
|
136
|
-
"src/host/ctl.js": "
|
|
141
|
+
"src/host/ctl.js": "77a2f0e868b094adcc56e19ba3a62940e5e81f8b0837ef2fb9fce3d31661bd7c",
|
|
137
142
|
"src/host/disk-map.js": "3d7e0d7d488ce25fc6a0e4dc0a9b1c8fc2af96bac1c03491a1d30be392af268b",
|
|
138
143
|
"src/host/disk-worker.js": "6e82bfeb4aa3f8b02bd7cb2de7427def26114e016f6b05196c8485d7fc8315ee",
|
|
139
144
|
"src/host/disk.js": "e941e62cc2d9a83582d53c80c09c5f0f682508f77390237bedff4051c489b2cd",
|
|
@@ -148,7 +153,7 @@
|
|
|
148
153
|
"src/host/jit.js": "72ef7334506fde2b3724cee93b52a987fbd6d45473b8de93d914db8a80ae9e17",
|
|
149
154
|
"src/host/layout.js": "d5bc5aa9292630b204438df5d6278fda6daa2a65acc061e1c57e0272b32fecc8",
|
|
150
155
|
"src/host/monitor.js": "ae1741ba35668bcc6192642246494433b175668933921634c699af5a0a69acc0",
|
|
151
|
-
"src/host/p9mount.js": "
|
|
156
|
+
"src/host/p9mount.js": "cd27abd769b19ed8b26050ddd8b6d61f81faa5a431924217dd0bf2593258d5b9",
|
|
152
157
|
"src/host/ram-mem.js": "bf4036d5d12be1d5d2f5223e526b0b8e225bc702ae7e60a2a59fdfe9fbbb49e3",
|
|
153
158
|
"src/host/stdio.js": "43973675578eb1d324c2c6d7078e51a6a1f121190ada5ef14a5551364b8c7f5e",
|
|
154
159
|
"src/host/threads.js": "952381940e7f43114867e9a9714528f2f20c8064b6b0f2018ab075128dc601be",
|
package/guest/arm64/Image
CHANGED
package/guest/arm64/Image-4k
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@threadedstack/wmd-web",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.29",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"homepage": "https://github.com/threadedstack/wmd-releases",
|
|
6
6
|
"repository": {
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
},
|
|
10
10
|
"description": "Browser host for wmd's guest vm.wasm (Web Workers + shared memory + WASI preview1)",
|
|
11
11
|
"wmd": {
|
|
12
|
-
"tag": "v0.1.
|
|
13
|
-
"commit": "
|
|
12
|
+
"tag": "v0.1.29",
|
|
13
|
+
"commit": "965e79897093369d1dd263b5588efc3619d47c7b",
|
|
14
14
|
"web": "0.5.1"
|
|
15
15
|
},
|
|
16
16
|
"type": "module",
|
package/src/boot.js
CHANGED
|
@@ -54,7 +54,8 @@ export { CheckpointError, memoryStore, opfsStore } from './host/ckpt.js'
|
|
|
54
54
|
export { DiskError, deleteDisk, openDisk, sweepDisks } from './host/disk.js'
|
|
55
55
|
export { NetSwitch } from './net/switch.js'
|
|
56
56
|
export { ImageFiles, openImage, parseGroup, parsePasswd, resolveUser } from './image-files.js'
|
|
57
|
-
export { P9_CACHE_DEFAULT, p9InitCmdline, p9MountOptions } from './host/p9mount.js'
|
|
57
|
+
export { P9_CACHE_DEFAULT, P9_FEATURES_LIMIT_MS, P9_FEATURES_MAX_BYTES, P9_NAMES_DEFAULT, P9_NAMES_FEATURE, fetchGuestFeatures, p9CacheDefault, p9FeaturesLost, p9InitCmdline, p9MountOptions, p9RunRefusal, parseGuestFeatures, readGuestFeatures } from './host/p9mount.js'
|
|
58
|
+
import { bootGuestFeatures, p9HandleFields } from './host/p9mount.js'
|
|
58
59
|
export { loadImageTar } from './registry/load-tar.js'
|
|
59
60
|
|
|
60
61
|
const PAGE = 65536
|
|
@@ -694,6 +695,10 @@ export async function bootWmd(o) {
|
|
|
694
695
|
// 1. Downloads (in parallel). vm.wasm is compiled from its bytes so the compile
|
|
695
696
|
// time is measured on its own.
|
|
696
697
|
const names = Object.keys(o.files)
|
|
698
|
+
// X23 fix round 3: what the guest folder says its kernel has (the `features` file next to the initramfs): o.features (text, array or Set) when
|
|
699
|
+
// the caller has it, else the sibling of the initramfs URL; nothing found is an empty set. The caller builds the root mount's options with
|
|
700
|
+
// vm.p9MountOptions(), which takes the default (`names` on a kernel that has it) from it.
|
|
701
|
+
const featuresP = bootGuestFeatures(o)
|
|
697
702
|
// P-B9: o.assets is what an earlier boot of this handle already had (vm.restore passes it): vm.wasm's bytes and compiled
|
|
698
703
|
// Module, the boot files and the packs, and the boot's keys. Nothing is downloaded, hashed or compiled again, and the
|
|
699
704
|
// old machine is not stopped until the new one's inputs are in hand.
|
|
@@ -2012,6 +2017,12 @@ export async function bootWmd(o) {
|
|
|
2012
2017
|
return {
|
|
2013
2018
|
exited,
|
|
2014
2019
|
timings,
|
|
2020
|
+
/**
|
|
2021
|
+
* X23: `features` (the words of the guest folder's `features` file, empty when it has none), `featuresHow` (how its read ended:
|
|
2022
|
+
* 'given', 'read', 'none', 'bad', 'error' or 'late'; p9FeaturesLost) and `p9MountOptions({msize?, cache?})`, the options of the
|
|
2023
|
+
* container's root mount for this machine's kernel (no cache: the default, see p9CacheDefault).
|
|
2024
|
+
*/
|
|
2025
|
+
...p9HandleFields(await featuresP),
|
|
2015
2026
|
/** The shared memory, for post-mortem reads; null after dispose(). */
|
|
2016
2027
|
get memory() {
|
|
2017
2028
|
return memory
|
package/src/build/builder.js
CHANGED
|
@@ -10,7 +10,7 @@ import { blobBytes } from '../blob.js'
|
|
|
10
10
|
import { bootWmd, isWebKit } from '../boot.js'
|
|
11
11
|
import { MAIN_PROC_ID, containerBundle, fillRunRequest } from '../host/ctl.js'
|
|
12
12
|
import { DiskError, deleteDisk, openDisk, sweepDisks } from '../host/disk.js'
|
|
13
|
-
import {
|
|
13
|
+
import { p9OptsOfVm } from '../host/p9mount.js'
|
|
14
14
|
import { loadImageTar } from '../registry/load-tar.js'
|
|
15
15
|
import { packContext, readTarFile } from './context.js'
|
|
16
16
|
import { BUILDER_PINS } from './pin.js'
|
|
@@ -389,6 +389,7 @@ function aborted(signal) {
|
|
|
389
389
|
* Boots a builder machine.
|
|
390
390
|
* @param {object} o
|
|
391
391
|
* @param {string|Uint8Array} o.vmUrl vm.wasm (as bootWmd)
|
|
392
|
+
* @param {string|string[]|Set<string>} [o.features] X23: the guest folder's `features` file (text) or its words; the machine's root mount takes its default from it (vm.p9MountOptions)
|
|
392
393
|
* @param {object} o.files guest files for o.arch: {'guest/Image' (arm64) or 'guest/bzImage' (amd64), 'guest/initramfs.cpio.gz'}
|
|
393
394
|
* @param {'arm64'|'amd64'} [o.arch]
|
|
394
395
|
* @param {object} o.image {index, packs} or {tar, sha256} (web/builder: `make web-builder`); a tar's sha256 must be
|
|
@@ -568,6 +569,7 @@ export async function createBuilder(o) {
|
|
|
568
569
|
vm = await bootWmd({
|
|
569
570
|
vmUrl: o.vmUrl,
|
|
570
571
|
files: o.files,
|
|
572
|
+
...(o.features !== undefined ? { features: o.features } : {}), // X23: the guest folder's `features` (text, array or Set) when the files are bytes; with URLs bootWmd reads the folder's file
|
|
571
573
|
args,
|
|
572
574
|
// X24: with o.ramInMemory0 === true (boot.js's rule: only exactly true) a RAM above 1536 MiB up to the engine's limit stays in memory 0 (boot.js decides); above it, flat
|
|
573
575
|
...(o.ramInMemory0 === true ? { ramInMemory0: true } : ram > 1536 ? { flatRam: true } : {}),
|
|
@@ -624,7 +626,7 @@ export async function createBuilder(o) {
|
|
|
624
626
|
}
|
|
625
627
|
try {
|
|
626
628
|
await Promise.race([ctl.waitSession(600_000), ended.then(r => Promise.reject(new Error(`the builder machine ended before its control session: ${r.code} ${r.reason}\n${stderr.slice(-2000)}`)))])
|
|
627
|
-
const main = ctl.run(fillRunRequest({ id: MAIN_PROC_ID, args: argv, env, cwd: '/' }, { p9opts:
|
|
629
|
+
const main = ctl.run(fillRunRequest({ id: MAIN_PROC_ID, args: argv, env, cwd: '/' }, { p9opts: p9OptsOfVm(vm) }), { onStdout: onMain, onStderr: onMain })
|
|
628
630
|
main.exited.then(r => readyRej(new Error(`the builder's start script ended (${r.code}) before buildkitd answered\n${mainLog.tail.slice(-3000)}`)))
|
|
629
631
|
await Promise.race([ready, ended.then(r => Promise.reject(new Error(`the builder machine ended: ${r.code} ${r.reason}`))), aborted(o.signal)])
|
|
630
632
|
} catch (e) {
|
package/src/host/ckpt.js
CHANGED
|
@@ -80,7 +80,8 @@ export async function bootKeyOf({ vmKey, argv, env, preopen, files, services, ma
|
|
|
80
80
|
}
|
|
81
81
|
// W56: a guest on an in-page switch has a network, and its address is in its memory (a restore must give it the same one)
|
|
82
82
|
const sw = s.switch ? { ip: s.switch.address(s.name, s.ip) } : {}
|
|
83
|
-
|
|
83
|
+
// X23: the root mount's options when the page chose them (p9cache=mmapnames): a checkpoint restores only into a boot with the same ones (absent: as before)
|
|
84
|
+
svc.push({ port: s.port, kind: s.kind, at: s.at || '', yamux: !!s.yamux, net: !!(s.relay || s.switch), ...sw, ...(s.p9opts ? { p9opts: s.p9opts } : {}), layers, bundle })
|
|
84
85
|
}
|
|
85
86
|
const desc = { vmKey, argv, env, preopen, files: fileKeys, services: svc, maxPages }
|
|
86
87
|
return { key: await sha256Hex(new TextEncoder().encode(JSON.stringify(desc))), desc }
|
package/src/host/ctl.js
CHANGED
|
@@ -77,7 +77,9 @@ export function fillRunRequest(req, { p9opts, now = Date.now(), random = globalT
|
|
|
77
77
|
if (!p9opts) throw new Error('fillRunRequest: p9opts is required (the init refuses a first run without it)')
|
|
78
78
|
const seed = new Uint8Array(32)
|
|
79
79
|
random.getRandomValues(seed)
|
|
80
|
-
|
|
80
|
+
// now_ns: the same moment to the millisecond; the init prefers it to the whole seconds of `now` (issue #75). Build the request when the
|
|
81
|
+
// control session is up, not before the boot: the guest sets its clock to this value when the request arrives.
|
|
82
|
+
return { ...req, now: Math.floor(now / 1000), now_ns: now * 1e6, seed, p9tag: 'wmdroot', p9opts }
|
|
81
83
|
}
|
|
82
84
|
|
|
83
85
|
function cat(a, b) {
|
package/src/host/p9mount.js
CHANGED
|
@@ -16,12 +16,290 @@
|
|
|
16
16
|
export const P9_CACHE_DEFAULT = 'mmap'
|
|
17
17
|
export const P9_MSIZE_DEFAULT = 262144
|
|
18
18
|
|
|
19
|
-
/**
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
/**
|
|
20
|
+
* X23 fix round 3: the word guest/linux/features carries when the guest kernel has the 9P `names` option
|
|
21
|
+
* (guest/linux/patches/common/0006-9p-names-mount-option.patch). The guest folder's `features` file sits next to its initramfs.
|
|
22
|
+
*/
|
|
23
|
+
export const P9_NAMES_FEATURE = 'p9-names'
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* X23 fix round 3: whether a page that names no p9cache option mounts with `names` when the guest kernel has it. Off: the default is
|
|
27
|
+
* P9_CACHE_DEFAULT whatever the kernel can do. On: a kernel with the word mounts `mmap,names`, a kernel without it mounts `mmap`
|
|
28
|
+
* (no refusal, no error). An explicit `p9cache=mmap` stays plain; an explicit `p9cache=mmapnames` on a kernel without the word is
|
|
29
|
+
* still refused (p9NamesRefusal).
|
|
30
|
+
*/
|
|
31
|
+
export const P9_NAMES_DEFAULT = true
|
|
32
|
+
|
|
33
|
+
/** The largest `features` file a page reads (fix 5): a longer answer is no features file. The real file is a few words. */
|
|
34
|
+
export const P9_FEATURES_MAX_BYTES = 65536
|
|
35
|
+
|
|
36
|
+
/** The words of a `features` file as a Set, or null when the text is no features file (a line that is no word, or more than P9_FEATURES_MAX_BYTES). */
|
|
37
|
+
function featuresWords(text) {
|
|
38
|
+
const t = String(text ?? '')
|
|
39
|
+
if (t.length > P9_FEATURES_MAX_BYTES || new TextEncoder().encode(t).length > P9_FEATURES_MAX_BYTES) return null
|
|
40
|
+
const out = new Set()
|
|
41
|
+
for (const line of t.split('\n')) {
|
|
42
|
+
const w = line.trim()
|
|
43
|
+
if (!w || w.startsWith('#')) continue
|
|
44
|
+
if (!/^[A-Za-z0-9._-]+$/.test(w)) return null
|
|
45
|
+
out.add(w)
|
|
46
|
+
}
|
|
47
|
+
return out
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The words of a `features` file ('#' lines and blank lines left out) as a Set. A word is letters, digits, '.', '_' and '-'. A file with any
|
|
52
|
+
* other line is not a features file (a server's own page answered for a missing file, say) and has no word at all.
|
|
53
|
+
*/
|
|
54
|
+
export function parseGuestFeatures(text) {
|
|
55
|
+
return featuresWords(text) ?? new Set()
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Accepts a Set, an array, the text of a `features` file or nothing; always returns a Set. */
|
|
59
|
+
export function asGuestFeatures(f) {
|
|
60
|
+
if (f instanceof Set) return f
|
|
61
|
+
if (Array.isArray(f)) return new Set(f)
|
|
62
|
+
return parseGuestFeatures(typeof f === 'string' ? f : '')
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** The cache mode a boot takes when nothing names one: `mmap,names` when P9_NAMES_DEFAULT is on and the kernel has the word, else P9_CACHE_DEFAULT. */
|
|
66
|
+
export function p9CacheDefault(features, namesDefault = P9_NAMES_DEFAULT) {
|
|
67
|
+
return namesDefault && asGuestFeatures(features).has(P9_NAMES_FEATURE) ? 'mmap,names' : P9_CACHE_DEFAULT
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Where the `features` file of a guest folder is when one of its files is at `url`: its sibling. null when there is no folder in the url. */
|
|
71
|
+
export function guestFeaturesUrl(url) {
|
|
72
|
+
const s = String(url)
|
|
73
|
+
const i = s.lastIndexOf('/')
|
|
74
|
+
return i < 0 ? null : `${s.slice(0, i + 1)}features`
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** How long a boot waits for the guest folder's `features` file. A request that takes longer counts as no file: the boot goes on and mounts plain. */
|
|
78
|
+
export const P9_FEATURES_LIMIT_MS = 10000
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Fix 5: the body of a features answer as text, or null when it has more than P9_FEATURES_MAX_BYTES. A body that is a stream is read
|
|
82
|
+
* piece by piece and cancelled at the limit, so an endless or huge answer is not taken into memory. An answer with no stream is read whole.
|
|
83
|
+
*/
|
|
84
|
+
/** Fix 5b: tells the browser to stop taking a body nobody will read (`from` is a response body or its reader). It never throws or rejects. */
|
|
85
|
+
function dropBody(from) {
|
|
86
|
+
try {
|
|
87
|
+
from?.cancel?.()?.catch?.(() => {})
|
|
88
|
+
} catch {}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async function featuresText(r) {
|
|
92
|
+
const rd = r.body?.getReader?.()
|
|
93
|
+
if (!rd) return r.text()
|
|
94
|
+
const parts = []
|
|
95
|
+
let n = 0
|
|
96
|
+
for (;;) {
|
|
97
|
+
const { done, value } = await rd.read()
|
|
98
|
+
if (done) break
|
|
99
|
+
n += value.byteLength
|
|
100
|
+
if (n > P9_FEATURES_MAX_BYTES) {
|
|
101
|
+
dropBody(rd)
|
|
102
|
+
return null
|
|
103
|
+
}
|
|
104
|
+
parts.push(value)
|
|
105
|
+
}
|
|
106
|
+
const all = new Uint8Array(n)
|
|
107
|
+
let at = 0
|
|
108
|
+
for (const part of parts) {
|
|
109
|
+
all.set(part, at)
|
|
110
|
+
at += part.byteLength
|
|
111
|
+
}
|
|
112
|
+
return new TextDecoder().decode(all)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Fix 5: the read of the guest folder's `features` file behind `url` (any file of the folder), with how it ended: {words, how}.
|
|
117
|
+
* `how` is 'read' (the file was read; it may have no word), 'none' (no folder in the url, nothing to ask with, or an answer that is not
|
|
118
|
+
* a 200: the folder has no file), 'bad' (an answer that is no features file, or one over P9_FEATURES_MAX_BYTES), 'error' (the request or
|
|
119
|
+
* its body failed) or 'late' (no answer or no end of the body within `limitMs`; the request is aborted at the limit). An answer that is
|
|
120
|
+
* rejected before its body is read (not a 200, an announced length over the limit) has its body cancelled and its request aborted. Every way but
|
|
121
|
+
* 'read' has no word, so the page mounts as it always did; 'error' and 'late' say nothing about the folder (p9FeaturesLost).
|
|
122
|
+
*/
|
|
123
|
+
export async function readGuestFeatures(url, fetchFn = globalThis.fetch, limitMs = P9_FEATURES_LIMIT_MS) {
|
|
124
|
+
const none = how => ({ words: new Set(), how })
|
|
125
|
+
const u = guestFeaturesUrl(url)
|
|
126
|
+
if (!u || !fetchFn) return none('none')
|
|
127
|
+
const ac = typeof AbortController === 'function' ? new AbortController() : null
|
|
128
|
+
let timer
|
|
129
|
+
const late = new Promise(resolve => {
|
|
130
|
+
timer = setTimeout(() => {
|
|
131
|
+
ac?.abort()
|
|
132
|
+
globalThis.console?.warn?.(`wmd: ${u} did not answer in ${limitMs} ms; the guest is taken to have no features`)
|
|
133
|
+
resolve(none('late'))
|
|
134
|
+
}, limitMs)
|
|
135
|
+
})
|
|
136
|
+
const read = (async () => {
|
|
137
|
+
try {
|
|
138
|
+
const r = await fetchFn(u, ac ? { signal: ac.signal } : undefined)
|
|
139
|
+
// Fix 5b: an answer that is rejected by its status or its announced length is not read; its download is stopped, not left to run.
|
|
140
|
+
const rejected = how => {
|
|
141
|
+
dropBody(r?.body)
|
|
142
|
+
ac?.abort()
|
|
143
|
+
return none(how)
|
|
144
|
+
}
|
|
145
|
+
if (!r || !r.ok) return rejected('none')
|
|
146
|
+
if (Number(r.headers?.get?.('content-length')) > P9_FEATURES_MAX_BYTES) return rejected('bad')
|
|
147
|
+
const text = await featuresText(r)
|
|
148
|
+
const words = text === null ? null : featuresWords(text)
|
|
149
|
+
return words ? { words, how: 'read' } : none('bad')
|
|
150
|
+
} catch {
|
|
151
|
+
return none('error')
|
|
152
|
+
}
|
|
153
|
+
})()
|
|
154
|
+
try {
|
|
155
|
+
return await Promise.race([read, late])
|
|
156
|
+
} finally {
|
|
157
|
+
clearTimeout(timer)
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* The features of the guest folder behind `url` (any file of it): the words of readGuestFeatures. Any failure (no file, a network error, a
|
|
163
|
+
* non-200 answer, no answer or no end of the body within `limitMs`) gives an empty set: a folder that says nothing has no feature, so the
|
|
164
|
+
* page mounts as it always did.
|
|
165
|
+
*/
|
|
166
|
+
export async function fetchGuestFeatures(url, fetchFn = globalThis.fetch, limitMs = P9_FEATURES_LIMIT_MS) {
|
|
167
|
+
return (await readGuestFeatures(url, fetchFn, limitMs)).words
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Fix 5: true when a read of the features file ended in a way that says nothing about the folder ('late' or 'error'): the kernel may have
|
|
172
|
+
* `names` and the page mounted plain. A page still boots; a timed run must not be recorded as the default's (test/b9/b9w30.spec.js refuses it).
|
|
173
|
+
*/
|
|
174
|
+
export function p9FeaturesLost(how) {
|
|
175
|
+
return how === 'late' || how === 'error'
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Fix 5: why a run on a page must not be recorded as a run of the page's chosen mount, or null. `s` is what the page says: `featuresHow`
|
|
180
|
+
* (ck.featuresHow), `p9opts` (ck.p9opts) and `events` (ck.events). A lost read of the features file (p9FeaturesLost) left the machine plain
|
|
181
|
+
* whatever its kernel has; a `p9cache` event with `names: false` is a machine whose mount line has no names although names was chosen.
|
|
182
|
+
* A page that says none of it (older than fix 5) is not refused.
|
|
183
|
+
*/
|
|
184
|
+
export function p9RunRefusal(s) {
|
|
185
|
+
if (p9FeaturesLost(s?.featuresHow)) return `the read of the guest folder's features file was lost (${s.featuresHow}); the machine mounted ${s.p9opts}`
|
|
186
|
+
const lost = (s?.events || []).filter(e => e?.t === 'p9cache' && e.names === false)
|
|
187
|
+
if (lost.length) return `the root mount has no names option although ${lost[0].opts} was chosen (${lost[0].mount})`
|
|
188
|
+
return null
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Fix 5: the features read of a bootWmd call, {words, how}: `o.features` (text, array or Set) when the caller has it ('given', nothing is
|
|
193
|
+
* asked), else the sibling of the initramfs when `o.files` names it by URL (readGuestFeatures), else no word ('none': files given as bytes
|
|
194
|
+
* have no folder to ask).
|
|
195
|
+
*/
|
|
196
|
+
export function bootGuestFeatures(o, fetchFn = globalThis.fetch) {
|
|
197
|
+
if (o?.features !== undefined) return Promise.resolve({ words: asGuestFeatures(o.features), how: 'given' })
|
|
198
|
+
const files = o?.files || {}
|
|
199
|
+
const initrd = Object.keys(files).find(n => /initramfs\.cpio(\.gz)?$/.test(n) && typeof files[n] === 'string')
|
|
200
|
+
return initrd ? readGuestFeatures(files[initrd], fetchFn) : Promise.resolve({ words: new Set(), how: 'none' })
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Fix 5: what a machine handle says about its guest folder's features: `features` (the words), `featuresHow` (how the read ended, see
|
|
205
|
+
* readGuestFeatures and bootGuestFeatures) and `p9MountOptions({msize?, cache?})`, the options of the container's root mount for this
|
|
206
|
+
* machine's kernel (no cache: the default, see p9CacheDefault).
|
|
207
|
+
*/
|
|
208
|
+
export function p9HandleFields(read) {
|
|
209
|
+
return {
|
|
210
|
+
features: read.words,
|
|
211
|
+
featuresHow: read.how,
|
|
212
|
+
p9MountOptions: (opts = {}) => p9MountOptions({ ...opts, features: read.words }),
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** Fix 5: the `p9opts` of a run request on machine `vm`: the machine's own (vm.p9MountOptions()), or the plain default for a handle that has none. */
|
|
217
|
+
export function p9OptsOfVm(vm) {
|
|
218
|
+
return typeof vm?.p9MountOptions === 'function' ? vm.p9MountOptions() : p9MountOptions()
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Whether a page with this query needs the guest folder's `features` file to choose its cache mode: only when it names no `p9cache`
|
|
223
|
+
* (p9CacheFromQuery takes the default from the features then). A named option is decided by the option alone, so no request is made.
|
|
224
|
+
*/
|
|
225
|
+
export function p9NeedsFeatures(q) {
|
|
226
|
+
const v = q.get('p9cache')
|
|
227
|
+
return v === null || v === ''
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** "trans=virtio,version=9p2000.L,msize=...,cache=..." for mount -t 9p. `cache` unset: p9CacheDefault(features). */
|
|
231
|
+
export function p9MountOptions({ msize = P9_MSIZE_DEFAULT, cache, features } = {}) {
|
|
232
|
+
return `trans=virtio,version=9p2000.L,msize=${msize},cache=${cache ?? p9CacheDefault(features)}`
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* X23 fix round 3: the cache mode a checkpoint's boot key records for its container root mount (`p9opts`, the full option string), or
|
|
237
|
+
* P9_CACHE_DEFAULT when the key has none: a boot whose options were the plain default never wrote one, and every checkpoint made before
|
|
238
|
+
* `names` was the default is of that kind. A page that names no option restores a checkpoint with this mode.
|
|
239
|
+
*/
|
|
240
|
+
export function p9CacheOfOptions(opts) {
|
|
241
|
+
const m = /(?:^|,)cache=(.*)$/.exec(String(opts || ''))
|
|
242
|
+
return m ? m[1] : P9_CACHE_DEFAULT
|
|
22
243
|
}
|
|
23
244
|
|
|
24
245
|
/** Kernel command line words for wmd's Go init (cmdline.go wmd.p9msize / wmd.p9cache). */
|
|
25
|
-
export function p9InitCmdline({ msize = P9_MSIZE_DEFAULT, cache
|
|
26
|
-
return `wmd.p9msize=${msize} wmd.p9cache=${cache}`
|
|
246
|
+
export function p9InitCmdline({ msize = P9_MSIZE_DEFAULT, cache, features } = {}) {
|
|
247
|
+
return `wmd.p9msize=${msize} wmd.p9cache=${cache ?? p9CacheDefault(features)}`
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* X23: the cache mode a test page asks for with `?p9cache=mmap|loose|mmapnames`. Absent or empty: p9CacheDefault(features) (P9_CACHE_DEFAULT
|
|
252
|
+
* unless P9_NAMES_DEFAULT is on and the kernel has the word). `mmap` named is plain whatever the kernel has. Any other value throws (a typo must not silently measure mmap).
|
|
253
|
+
*/
|
|
254
|
+
export function p9CacheFromQuery(q, features, namesDefault = P9_NAMES_DEFAULT) {
|
|
255
|
+
const v = q.get('p9cache')
|
|
256
|
+
if (v === null || v === '') return p9CacheDefault(features, namesDefault)
|
|
257
|
+
if (v === 'mmapnames') return 'mmap,names' // X23 gate 2 draft: cache=mmap plus the guest kernel's `names` option (guest/linux/patches/common/0006)
|
|
258
|
+
if (v !== 'mmap' && v !== 'loose') throw new Error(`p9cache must be mmap, loose or mmapnames, not ${JSON.stringify(v)}`)
|
|
259
|
+
return v
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* X23: true when the page asked for the `names` option, that is `?p9cache=mmapnames` (p9CacheFromQuery gives `mmap,names`).
|
|
264
|
+
* The page uses it for what only a kernel with guest/linux/patches/common/0006 can honour.
|
|
265
|
+
*/
|
|
266
|
+
export function p9WantsNames(cache) {
|
|
267
|
+
return typeof cache === 'string' && cache.split(',').includes('names')
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* X23: the options field of a 9p line of /proc/mounts ("wmdroot / 9p rw,dirsync,relatime,mmap,names,access=client,... 0 0") as a list,
|
|
272
|
+
* or null when the text has no 9p line. A kernel without the patch accepts `names` and does not print it (item 4 of the independent check).
|
|
273
|
+
*/
|
|
274
|
+
export function p9MountedOptions(text) {
|
|
275
|
+
for (const line of String(text).split('\n')) {
|
|
276
|
+
const f = line.trim().split(/\s+/)
|
|
277
|
+
if (f.length >= 4 && f[2] === '9p') return f[3].split(',')
|
|
278
|
+
}
|
|
279
|
+
return null
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* X23: what the page does when it asked for `names` and the guest's mount line says otherwise: the start is refused (the caller throws
|
|
284
|
+
* this message). The page never carries on as plain mmap with a note: a timed run would be recorded as a `names` run, and a
|
|
285
|
+
* typo in the cache name is refused for the same reason (p9CacheFromQuery). Returns '' when the mount is what was asked for.
|
|
286
|
+
*/
|
|
287
|
+
export function p9NamesRefusal(cache, mountText) {
|
|
288
|
+
if (!p9WantsNames(cache)) return ''
|
|
289
|
+
const opts = p9MountedOptions(mountText)
|
|
290
|
+
if (opts === null) return `p9cache=mmapnames was asked for, but the guest has no 9p mount (/proc/mounts: ${JSON.stringify(String(mountText).slice(0, 200))})`
|
|
291
|
+
if (opts.includes('names')) return ''
|
|
292
|
+
return `p9cache=mmapnames was asked for, but the guest's root mount does not have the names option (${opts.join(',')}): the guest kernel has no guest/linux/patches/common/0006-9p-names-mount-option.patch, it accepted the word and ignores it. A run would be plain mmap under the name names; the start is refused`
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* X23: makes a guest whose root mount has `names` look again at every name and attribute it keeps, the way the guest's own
|
|
297
|
+
* `echo 2 > /proc/sys/vm/drop_caches` does. Call it after the host changed the container's tree while the guest runs (X5's node
|
|
298
|
+
* frame, X6's compiler twin): until it is called the guest answers from what it saw. The control channel's resync op writes the
|
|
299
|
+
* number to drop_caches in the init's own /proc (a container's /proc/sys is read only), and the 9p `names` patch starts a new
|
|
300
|
+
* generation on that write (v9fs_names_new_generation): each inode and name older than it is asked of the server on its next
|
|
301
|
+
* use, also those a process holds open. It costs nothing until names are used again. Resolves with the control reply.
|
|
302
|
+
*/
|
|
303
|
+
export function p9DropNames(ctl) {
|
|
304
|
+
return ctl.simple({ op: 'resync', drop_caches: 2 })
|
|
27
305
|
}
|
package/wmdpack.wasm
CHANGED
|
Binary file
|