kobako 0.30.0 → 0.32.0
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.
- checksums.yaml +4 -4
- data/.githooks/linux-tests.sh +29 -0
- data/.release-please-manifest.json +1 -1
- data/CHANGELOG.md +460 -0
- data/Cargo.lock +868 -447
- data/README.md +43 -4
- data/ROADMAP.md +1 -2
- data/crates/kobako-runtime/CHANGELOG.md +309 -0
- data/crates/kobako-runtime/Cargo.toml +58 -11
- data/crates/kobako-runtime/README.md +7 -4
- data/crates/kobako-runtime/src/cred.rs +136 -0
- data/crates/kobako-runtime/src/dispatch.rs +4 -5
- data/crates/kobako-runtime/src/endpoint/buffer.rs +153 -44
- data/crates/kobako-runtime/src/endpoint/dispatch.rs +80 -41
- data/crates/kobako-runtime/src/endpoint/invoke.rs +23 -36
- data/crates/kobako-runtime/src/endpoint.rs +137 -36
- data/crates/kobako-runtime/src/errno.rs +391 -0
- data/crates/kobako-runtime/src/error.rs +31 -10
- data/crates/kobako-runtime/src/filesystem/anon_inodes.rs +52 -0
- data/crates/kobako-runtime/src/filesystem/bind/fid.rs +300 -22
- data/crates/kobako-runtime/src/filesystem/bind/lookup.rs +101 -29
- data/crates/kobako-runtime/src/filesystem/bind/unicode.rs +109 -0
- data/crates/kobako-runtime/src/filesystem/bind/walk.rs +52 -34
- data/crates/kobako-runtime/src/filesystem/bind.rs +812 -447
- data/crates/kobako-runtime/src/filesystem/overlay/file.rs +6 -6
- data/crates/kobako-runtime/src/filesystem/overlay/path.rs +43 -65
- data/crates/kobako-runtime/src/filesystem/overlay/stack/copy_up.rs +11 -16
- data/crates/kobako-runtime/src/filesystem/overlay/stack/dir.rs +47 -72
- data/crates/kobako-runtime/src/filesystem/overlay/stack/namei.rs +12 -12
- data/crates/kobako-runtime/src/filesystem/overlay/stack/readdir.rs +4 -7
- data/crates/kobako-runtime/src/filesystem/overlay/stack.rs +120 -37
- data/crates/kobako-runtime/src/filesystem/overlay.rs +578 -388
- data/crates/kobako-runtime/src/filesystem/pipe.rs +12 -9
- data/crates/kobako-runtime/src/filesystem/rdir.rs +14 -50
- data/crates/kobako-runtime/src/filesystem/testing.rs +31 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs/seed.rs +32 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs/tmpfile.rs +3 -3
- data/crates/kobako-runtime/src/filesystem/tmpfs/whiteout.rs +57 -35
- data/crates/kobako-runtime/src/filesystem/tmpfs/xattr.rs +2 -2
- data/crates/kobako-runtime/src/filesystem/tmpfs.rs +219 -173
- data/crates/kobako-runtime/src/filesystem/wrap.rs +36 -52
- data/crates/kobako-runtime/src/filesystem.rs +8 -3
- data/crates/kobako-runtime/src/fork.rs +319 -0
- data/crates/kobako-runtime/src/grant.rs +3 -0
- data/crates/kobako-runtime/src/hashtable.rs +4 -2
- data/crates/kobako-runtime/src/lib.rs +18 -7
- data/crates/kobako-runtime/src/limits.rs +171 -0
- data/crates/kobako-runtime/src/locking/seqlock.rs +29 -3
- data/crates/kobako-runtime/src/locking.rs +518 -113
- data/crates/kobako-runtime/src/memcg.rs +306 -0
- data/crates/kobako-runtime/src/mount.rs +37 -9
- data/crates/kobako-runtime/src/net/backends.rs +43 -0
- data/crates/kobako-runtime/src/net/connections.rs +219 -0
- data/crates/kobako-runtime/src/net/credential.rs +125 -0
- data/crates/kobako-runtime/src/net/egress.rs +180 -0
- data/crates/kobako-runtime/src/net/family.rs +181 -0
- data/crates/kobako-runtime/src/net/http.rs +3165 -0
- data/crates/kobako-runtime/src/net/lookup.rs +385 -0
- data/crates/kobako-runtime/src/net/mock.rs +251 -0
- data/crates/kobako-runtime/src/net/namespace.rs +1368 -0
- data/crates/kobako-runtime/src/net/reactor.rs +626 -0
- data/crates/kobako-runtime/src/net/resolv/darwin.rs +280 -0
- data/crates/kobako-runtime/src/net/resolv/stub/tests.rs +519 -0
- data/crates/kobako-runtime/src/net/resolv/stub.rs +542 -0
- data/crates/kobako-runtime/src/net/resolv/windows.rs +218 -0
- data/crates/kobako-runtime/src/net/resolv.rs +251 -0
- data/crates/kobako-runtime/src/net/skbuff.rs +109 -0
- data/crates/kobako-runtime/src/net/socket.rs +869 -0
- data/crates/kobako-runtime/src/net/task.rs +223 -0
- data/crates/kobako-runtime/src/net/tcp.rs +1840 -0
- data/crates/kobako-runtime/src/net/tls.rs +120 -0
- data/crates/kobako-runtime/src/net/transport.rs +304 -0
- data/crates/kobako-runtime/src/net/udp.rs +1105 -0
- data/crates/kobako-runtime/src/net.rs +45 -0
- data/crates/kobako-runtime/src/network/builder.rs +177 -0
- data/crates/kobako-runtime/src/network/ruleset.rs +777 -0
- data/crates/kobako-runtime/src/network.rs +551 -0
- data/crates/kobako-runtime/src/policy.rs +16 -0
- data/crates/kobako-runtime/src/profile.rs +29 -144
- data/crates/kobako-runtime/src/runtime.rs +3 -5
- data/crates/kobako-runtime/src/sched.rs +338 -51
- data/crates/kobako-runtime/src/security/entry_policy.rs +22 -0
- data/crates/kobako-runtime/src/{vfs/cred.rs → security/hooks.rs} +52 -144
- data/crates/kobako-runtime/src/security/mount_policy.rs +158 -0
- data/crates/kobako-runtime/src/security.rs +125 -209
- data/crates/kobako-runtime/src/snapshot.rs +121 -2
- data/crates/kobako-runtime/src/vfs/attr.rs +5 -5
- data/crates/kobako-runtime/src/vfs/dentry.rs +210 -117
- data/crates/kobako-runtime/src/vfs/file.rs +243 -248
- data/crates/kobako-runtime/src/vfs/inode.rs +41 -45
- data/crates/kobako-runtime/src/vfs/kern_path.rs +62 -53
- data/crates/kobako-runtime/src/vfs/mount.rs +10 -9
- data/crates/kobako-runtime/src/vfs/namei.rs +1162 -818
- data/crates/kobako-runtime/src/vfs/namespace.rs +245 -0
- data/crates/kobako-runtime/src/vfs/open_files.rs +69 -0
- data/crates/kobako-runtime/src/vfs/openat2.rs +3 -3
- data/crates/kobako-runtime/src/vfs/path.rs +6 -6
- data/crates/kobako-runtime/src/vfs/readdir.rs +6 -6
- data/crates/kobako-runtime/src/vfs/stat.rs +248 -23
- data/crates/kobako-runtime/src/vfs/super_block.rs +18 -14
- data/crates/kobako-runtime/src/vfs/utimes.rs +37 -27
- data/crates/kobako-runtime/src/vfs.rs +10 -6
- data/crates/kobako-runtime/src/wait.rs +381 -0
- data/crates/kobako-transport/CHANGELOG.md +38 -0
- data/crates/kobako-transport/Cargo.toml +1 -1
- data/crates/kobako-transport/README.md +3 -4
- data/crates/kobako-transport/src/abi.rs +78 -72
- data/crates/kobako-transport/src/envelope/bytes.rs +17 -6
- data/crates/kobako-transport/src/envelope/call.rs +32 -4
- data/crates/kobako-transport/src/envelope/error_record.rs +21 -0
- data/crates/kobako-transport/src/envelope/name.rs +99 -0
- data/crates/kobako-transport/src/envelope/outcome.rs +9 -9
- data/crates/kobako-transport/src/envelope/preamble.rs +24 -21
- data/crates/kobako-transport/src/envelope/reply.rs +27 -27
- data/crates/kobako-transport/src/envelope/unsupported.rs +10 -10
- data/crates/kobako-transport/src/envelope.rs +13 -8
- data/crates/kobako-wasmtime/CHANGELOG.md +208 -0
- data/crates/kobako-wasmtime/Cargo.toml +47 -7
- data/crates/kobako-wasmtime/README.md +4 -3
- data/crates/kobako-wasmtime/build/preview2.rs +1339 -0
- data/crates/kobako-wasmtime/build.rs +16 -0
- data/crates/kobako-wasmtime/src/abi.rs +18 -37
- data/crates/kobako-wasmtime/src/ambient.rs +43 -19
- data/crates/kobako-wasmtime/src/cache/unix.rs +95 -0
- data/crates/kobako-wasmtime/src/cache/windows.rs +359 -0
- data/crates/kobako-wasmtime/src/cache.rs +106 -113
- data/crates/kobako-wasmtime/src/config.rs +52 -68
- data/crates/kobako-wasmtime/src/driver.rs +80 -82
- data/crates/kobako-wasmtime/src/exports.rs +143 -17
- data/crates/kobako-wasmtime/src/guest.rs +12 -6
- data/crates/kobako-wasmtime/src/guest_binary.rs +14 -0
- data/crates/kobako-wasmtime/src/imports.rs +42 -18
- data/crates/kobako-wasmtime/src/instance_pre.rs +4 -4
- data/crates/kobako-wasmtime/src/invocation.rs +91 -15
- data/crates/kobako-wasmtime/src/lib.rs +7 -3
- data/crates/kobako-wasmtime/src/limiter.rs +130 -12
- data/crates/kobako-wasmtime/src/preview1/descriptors.rs +305 -0
- data/crates/kobako-wasmtime/src/preview1/differential/mount.rs +9 -20
- data/crates/kobako-wasmtime/src/preview1/differential.rs +27 -31
- data/crates/kobako-wasmtime/src/preview1/errno.rs +55 -66
- data/crates/kobako-wasmtime/src/preview1/fd.rs +347 -312
- data/crates/kobako-wasmtime/src/preview1/memory.rs +21 -12
- data/crates/kobako-wasmtime/src/preview1/mount_view/wrap.rs +34 -53
- data/crates/kobako-wasmtime/src/preview1/mount_view.rs +335 -388
- data/crates/kobako-wasmtime/src/preview1/path.rs +56 -121
- data/crates/kobako-wasmtime/src/preview1/poll.rs +255 -125
- data/crates/kobako-wasmtime/src/preview1/random.rs +125 -0
- data/crates/kobako-wasmtime/src/preview1/sock.rs +10 -8
- data/crates/kobako-wasmtime/src/preview1/testing.rs +31 -0
- data/crates/kobako-wasmtime/src/preview1/testsuite.rs +5 -15
- data/crates/kobako-wasmtime/src/preview1.rs +131 -51
- data/crates/kobako-wasmtime/src/preview2/abi.rs +227 -0
- data/crates/kobako-wasmtime/src/preview2/error.rs +118 -0
- data/crates/kobako-wasmtime/src/preview2/filesystem.rs +122 -0
- data/crates/kobako-wasmtime/src/preview2/host.rs +4319 -0
- data/crates/kobako-wasmtime/src/preview2/http.rs +1587 -0
- data/crates/kobako-wasmtime/src/preview2/io.rs +328 -0
- data/crates/kobako-wasmtime/src/preview2/sockets.rs +379 -0
- data/crates/kobako-wasmtime/src/preview2/table.rs +257 -0
- data/crates/kobako-wasmtime/src/preview2.rs +57 -0
- data/crates/kobako-wasmtime/src/trap.rs +88 -28
- data/crates/kobako-wasmtime/src/waits.rs +59 -0
- data/crates/kobako-wasmtime/src/wasi.rs +291 -81
- data/crates/kobako-wasmtime/wit/deps/cli.wit +233 -0
- data/crates/kobako-wasmtime/wit/deps/clocks.wit +162 -0
- data/crates/kobako-wasmtime/wit/deps/filesystem.wit +589 -0
- data/crates/kobako-wasmtime/wit/deps/http.wit +733 -0
- data/crates/kobako-wasmtime/wit/deps/io.wit +299 -0
- data/crates/kobako-wasmtime/wit/deps/random.wit +92 -0
- data/crates/kobako-wasmtime/wit/deps/sockets.wit +949 -0
- data/crates/kobako-wasmtime/witx/wasi_snapshot_preview1.witx +13 -0
- data/data/kobako.wasm +0 -0
- data/ext/kobako/Cargo.toml +6 -2
- data/ext/kobako/src/{runtime/errors.rs → errors.rs} +34 -26
- data/ext/kobako/src/escape.rs +404 -0
- data/ext/kobako/src/{runtime/filesystem → filesystem}/grants.rs +34 -32
- data/ext/kobako/src/{runtime/filesystem → filesystem}/ruby.rs +158 -170
- data/ext/kobako/src/{runtime/filesystem.rs → filesystem.rs} +71 -23
- data/ext/kobako/src/fork.rs +72 -0
- data/ext/kobako/src/gvl.rs +729 -0
- data/ext/kobako/src/handoff.rs +490 -0
- data/ext/kobako/src/lib.rs +74 -3
- data/ext/kobako/src/network/mock.rs +187 -0
- data/ext/kobako/src/network.rs +593 -0
- data/ext/kobako/src/pinned_value.rs +44 -0
- data/ext/kobako/src/runtime/bridge.rs +58 -50
- data/ext/kobako/src/runtime/snapshot.rs +4 -4
- data/ext/kobako/src/runtime.rs +272 -163
- data/ext/kobako/src/wire.rs +42 -0
- data/lib/kobako/catalog/extensions.rb +14 -2
- data/lib/kobako/catalog/flags.rb +3 -5
- data/lib/kobako/catalog/grants.rb +5 -4
- data/lib/kobako/catalog/handles.rb +14 -32
- data/lib/kobako/catalog/mount.rb +11 -3
- data/lib/kobako/catalog/network.rb +35 -0
- data/lib/kobako/catalog/replacements.rb +28 -0
- data/lib/kobako/catalog/services.rb +5 -19
- data/lib/kobako/catalog/snippets.rb +3 -18
- data/lib/kobako/catalog.rb +3 -0
- data/lib/kobako/codec/{utils.rb → boundary.rb} +4 -2
- data/lib/kobako/codec/decoder.rb +5 -5
- data/lib/kobako/codec/ext_types.rb +3 -3
- data/lib/kobako/codec/handle_walk.rb +3 -43
- data/lib/kobako/codec/state.rb +2 -18
- data/lib/kobako/codec/value_budget.rb +133 -41
- data/lib/kobako/codec.rb +6 -7
- data/lib/kobako/context.rb +24 -11
- data/lib/kobako/errors.rb +18 -18
- data/lib/kobako/extension.rb +3 -2
- data/lib/kobako/filesystem.rb +10 -3
- data/lib/kobako/fork.rb +42 -0
- data/lib/kobako/handle.rb +2 -3
- data/lib/kobako/names.rb +28 -0
- data/lib/kobako/network.rb +210 -0
- data/lib/kobako/outcome.rb +7 -7
- data/lib/kobako/runtime.rb +3 -2
- data/lib/kobako/sandbox.rb +73 -35
- data/lib/kobako/sandbox_options.rb +42 -109
- data/lib/kobako/transport/argument_wrap.rb +64 -0
- data/lib/kobako/transport/block_failure.rb +1 -1
- data/lib/kobako/transport/dispatcher.rb +6 -6
- data/lib/kobako/transport/exposure.rb +26 -15
- data/lib/kobako/transport/reflection.rb +21 -4
- data/lib/kobako/transport/run.rb +8 -23
- data/lib/kobako/transport/yielder.rb +2 -9
- data/lib/kobako/transport.rb +1 -0
- data/lib/kobako/usage.rb +4 -2
- data/lib/kobako/version.rb +1 -1
- data/lib/kobako.rb +8 -4
- data/release-please-config.json +15 -0
- data/sig/kobako/catalog/extensions.rbs +2 -0
- data/sig/kobako/catalog/grants.rbs +7 -4
- data/sig/kobako/catalog/handles.rbs +2 -2
- data/sig/kobako/catalog/mount.rbs +3 -1
- data/sig/kobako/catalog/network.rbs +20 -0
- data/sig/kobako/catalog/replacements.rbs +14 -0
- data/sig/kobako/catalog/services.rbs +0 -4
- data/sig/kobako/catalog/snippets.rbs +0 -2
- data/sig/kobako/codec/{utils.rbs → boundary.rbs} +2 -2
- data/sig/kobako/codec/handle_walk.rbs +0 -6
- data/sig/kobako/codec/state.rbs +0 -4
- data/sig/kobako/codec/value_budget.rbs +48 -5
- data/sig/kobako/codec.rbs +2 -2
- data/sig/kobako/context.rbs +3 -1
- data/sig/kobako/errors.rbs +4 -7
- data/sig/kobako/filesystem.rbs +21 -3
- data/sig/kobako/fork.rbs +17 -0
- data/sig/kobako/network.rbs +115 -0
- data/sig/kobako/outcome.rbs +1 -1
- data/sig/kobako/runtime.rbs +32 -3
- data/sig/kobako/sandbox.rbs +10 -2
- data/sig/kobako/sandbox_options.rbs +29 -40
- data/sig/kobako/transport/argument_wrap.rbs +15 -0
- data/sig/kobako/transport/error.rbs +1 -1
- data/sig/kobako/transport/exposure.rbs +2 -4
- data/sig/kobako/transport/reflection.rbs +10 -0
- data/sig/kobako/transport/run.rbs +0 -2
- data/sig/kobako/transport/yielder.rbs +0 -3
- data/sig/kobako/transport.rbs +1 -1
- data/sig/kobako.rbs +13 -0
- metadata +97 -37
- data/crates/kobako-runtime/src/endpoint/capture.rs +0 -115
- data/crates/kobako-runtime/src/endpoint/memory_cap.rs +0 -238
- data/crates/kobako-runtime/src/filesystem/path.rs +0 -21
- data/crates/kobako-runtime/src/vfs/errno.rs +0 -153
- data/crates/kobako-runtime/tests/linux_baseline/calls.rs +0 -171
- data/crates/kobako-runtime/tests/linux_baseline/concurrent.rs +0 -276
- data/crates/kobako-runtime/tests/linux_baseline/kobako.rs +0 -323
- data/crates/kobako-runtime/tests/linux_baseline/linux-baseline-expected.txt +0 -16
- data/crates/kobako-runtime/tests/linux_baseline/linux.rs +0 -449
- data/crates/kobako-runtime/tests/linux_baseline/main.rs +0 -611
- data/crates/kobako-runtime/tests/linux_baseline/permissions.rs +0 -236
- data/crates/kobako-wasmtime/src/descriptors.rs +0 -200
- data/crates/kobako-wasmtime/tests/integration/compile_posture.rs +0 -43
- data/crates/kobako-wasmtime/tests/integration/guest_file.rs +0 -1085
- data/crates/kobako-wasmtime/tests/integration/main.rs +0 -29
- data/crates/kobako-wasmtime/tests/integration/preamble_flags.rs +0 -70
- data/crates/kobako-wasmtime/tests/integration/snippet_compile.rs +0 -95
- data/crates/kobako-wasmtime/tests/integration/support/mod.rs +0 -30
- data/crates/kobako-wasmtime/tests/integration/unanswered_call.rs +0 -86
- data/crates/kobako-wasmtime/tests/integration/unsupported_call.rs +0 -51
- data/ext/kobako/src/runtime/escape.rs +0 -67
- data/ext/kobako/src/runtime/gvl.rs +0 -147
- data/ext/kobako/src/runtime/pinned_value.rs +0 -31
- data/lib/kobako/constant_name.rb +0 -8
- data/lib/kobako/pool.rb +0 -140
- data/sig/kobako/constant_name.rbs +0 -3
- data/sig/kobako/pool.rbs +0 -42
|
@@ -5,15 +5,18 @@
|
|
|
5
5
|
|
|
6
6
|
use std::sync::{Arc, LazyLock, Mutex, PoisonError};
|
|
7
7
|
|
|
8
|
+
use crate::cred::Cred;
|
|
8
9
|
use crate::vfs::{
|
|
9
|
-
alloc_file_pseudo,
|
|
10
|
-
|
|
10
|
+
alloc_file_pseudo, Dentry, FMode, File, FileOperations, FileSystemType, FileType, Inode,
|
|
11
|
+
InodeOperations, Kiocb, Kstat, OpenHow, PollMask, SuperBlock, VfsMount,
|
|
11
12
|
};
|
|
13
|
+
use crate::wait::PollTable;
|
|
14
|
+
use crate::Errno;
|
|
12
15
|
|
|
13
16
|
/// The one Filesystem every pipe stands on, as Linux's `pipe_mnt`. No path
|
|
14
17
|
/// reaches it: a pipe is only ever open.
|
|
15
18
|
static PIPE_MNT: LazyLock<Arc<VfsMount>> = LazyLock::new(|| {
|
|
16
|
-
let sb = SuperBlock::new(
|
|
19
|
+
let sb = SuperBlock::new(PipeFs).expect("pipefs fills in nothing that can fail");
|
|
17
20
|
VfsMount::kern_mount(sb)
|
|
18
21
|
});
|
|
19
22
|
|
|
@@ -21,14 +24,14 @@ static PIPE_MNT: LazyLock<Arc<VfsMount>> = LazyLock::new(|| {
|
|
|
21
24
|
struct PipeFs;
|
|
22
25
|
|
|
23
26
|
impl FileSystemType for PipeFs {
|
|
24
|
-
fn fill_super(self: Arc<Self>, sb: &mut SuperBlock) -> Result<(),
|
|
27
|
+
fn fill_super(self: Arc<Self>, sb: &mut SuperBlock) -> Result<(), Errno> {
|
|
25
28
|
sb.d_make_root(Inode::new(&Kstat::new(FileType::Dir, 0), self));
|
|
26
29
|
Ok(())
|
|
27
30
|
}
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
impl InodeOperations for PipeFs {
|
|
31
|
-
fn getattr(&self, _dentry: &Dentry) -> Result<Kstat,
|
|
34
|
+
fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
32
35
|
Ok(Kstat::new(FileType::Fifo, 0))
|
|
33
36
|
}
|
|
34
37
|
}
|
|
@@ -82,7 +85,7 @@ impl FileOperations for AnonPipe {
|
|
|
82
85
|
/// A pipe has no offsets, so a read takes what comes next. A drained pipe
|
|
83
86
|
/// reads nothing, as a closed writer's does, and so does a read into no
|
|
84
87
|
/// room, as `pipe_read` answers one.
|
|
85
|
-
fn read_iter(&mut self, _iocb: &mut Kiocb, buf: &mut [u8]) -> Result<usize,
|
|
88
|
+
fn read_iter(&mut self, _iocb: &mut Kiocb, buf: &mut [u8]) -> Result<usize, Errno> {
|
|
86
89
|
let mut state = self.0.state();
|
|
87
90
|
let start = state.read;
|
|
88
91
|
let rest = &state.bytes[start..];
|
|
@@ -95,19 +98,19 @@ impl FileOperations for AnonPipe {
|
|
|
95
98
|
/// A pipe has no offsets, so a write lands after the last. A write past
|
|
96
99
|
/// the capacity keeps what fit and answers a failure, which is how a
|
|
97
100
|
/// capture one past its limit learns it was truncated.
|
|
98
|
-
fn write_iter(&mut self, _iocb: &mut Kiocb, buf: &[u8]) -> Result<usize,
|
|
101
|
+
fn write_iter(&mut self, _iocb: &mut Kiocb, buf: &[u8]) -> Result<usize, Errno> {
|
|
99
102
|
let mut state = self.0.state();
|
|
100
103
|
let take = buf.len().min(self.0.capacity - state.bytes.len());
|
|
101
104
|
state.bytes.extend_from_slice(&buf[..take]);
|
|
102
105
|
if take < buf.len() {
|
|
103
|
-
return Err(
|
|
106
|
+
return Err(Errno::Other("the pipe is full".to_string()));
|
|
104
107
|
}
|
|
105
108
|
Ok(take)
|
|
106
109
|
}
|
|
107
110
|
|
|
108
111
|
/// Each end is ready for what it was opened for, as `pipe_poll` reads
|
|
109
112
|
/// `f_mode`; nothing here waits for the other end.
|
|
110
|
-
fn poll(&self, mode: FMode) -> PollMask {
|
|
113
|
+
fn poll(&self, mode: FMode, _table: Option<&mut PollTable>) -> PollMask {
|
|
111
114
|
match mode.contains(FMode::READ) {
|
|
112
115
|
true => PollMask::IN,
|
|
113
116
|
false => PollMask::OUT,
|
|
@@ -2,75 +2,39 @@
|
|
|
2
2
|
//! goes on, as 9p's `fid->rdir` holds what its server sent, so a caller reading in
|
|
3
3
|
//! small steps costs one listing, not one per step.
|
|
4
4
|
|
|
5
|
-
use
|
|
6
|
-
|
|
7
|
-
use crate::vfs::{Cred, Dentry, DirContext, DirEntry, FileType, FilesystemError};
|
|
5
|
+
use crate::vfs::{Dentry, DirContext, DirEntry, FileType};
|
|
6
|
+
use crate::Errno;
|
|
8
7
|
|
|
9
8
|
/// The entries a listing began with, `.` and `..` first, on the open directory
|
|
10
|
-
/// until it reaches its end
|
|
9
|
+
/// until it reaches its end.
|
|
11
10
|
#[derive(Default)]
|
|
12
|
-
pub struct Rdir(Option<
|
|
13
|
-
|
|
14
|
-
struct Listing {
|
|
15
|
-
entries: Vec<DirEntry>,
|
|
16
|
-
/// Gives the entries' bytes back once the listing goes.
|
|
17
|
-
_charge: Charge,
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/// Bytes a listing counts for as long as it holds them, as shmem pairs
|
|
21
|
-
/// `shmem_acct_size` with `shmem_unacct_size`.
|
|
22
|
-
struct Charge {
|
|
23
|
-
cred: Arc<Cred>,
|
|
24
|
-
bytes: usize,
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
impl Charge {
|
|
28
|
-
fn account(cred: &Arc<Cred>, entries: &[DirEntry]) -> Result<Self, FilesystemError> {
|
|
29
|
-
let names: usize = entries.iter().map(|entry| entry.name.capacity()).sum();
|
|
30
|
-
let bytes = size_of_val(entries) + names;
|
|
31
|
-
cred.security_vm_enough_memory(bytes)?;
|
|
32
|
-
Ok(Self {
|
|
33
|
-
cred: cred.clone(),
|
|
34
|
-
bytes,
|
|
35
|
-
})
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
impl Drop for Charge {
|
|
40
|
-
fn drop(&mut self) {
|
|
41
|
-
self.cred.vm_unacct_memory(self.bytes);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
11
|
+
pub struct Rdir(Option<Vec<DirEntry>>);
|
|
44
12
|
|
|
45
13
|
impl Rdir {
|
|
46
14
|
/// Hand `ctx` the directory from its position. A listing from the start
|
|
47
15
|
/// reads the directory through `read`, then stats it and what stands above
|
|
48
16
|
/// it for `.` and `..`, as 9p and FUSE take those from their server and
|
|
49
17
|
/// `ovl_cache_update` asks `vfs_getattr`; a failure of either answers before
|
|
50
|
-
/// any entry. A listing going on reads what that listing began with
|
|
51
|
-
///
|
|
52
|
-
|
|
53
|
-
/// the first `dir_emit`: past what a security module allows, the listing
|
|
54
|
-
/// answers out of memory before it hands any entry.
|
|
55
|
-
pub fn iterate(
|
|
18
|
+
/// any entry. A listing going on reads what that listing began with, as
|
|
19
|
+
/// `ovl_cache_get` and `v9fs_alloc_rdir_buf` keep it until the listing ends.
|
|
20
|
+
pub fn iterate_shared(
|
|
56
21
|
&mut self,
|
|
57
22
|
dentry: &Dentry,
|
|
58
23
|
ctx: &mut DirContext<'_>,
|
|
59
|
-
read: impl FnOnce() -> Result<Vec<DirEntry>,
|
|
60
|
-
) -> Result<(),
|
|
61
|
-
let
|
|
24
|
+
read: impl FnOnce() -> Result<Vec<DirEntry>, Errno>,
|
|
25
|
+
) -> Result<(), Errno> {
|
|
26
|
+
let entries = match self.0.take().filter(|_| ctx.pos() != 0) {
|
|
62
27
|
Some(held) => held,
|
|
63
28
|
None => {
|
|
64
29
|
let read = read()?;
|
|
65
30
|
let mut entries = dots(dentry)?;
|
|
66
31
|
entries.extend(read);
|
|
67
32
|
entries.shrink_to_fit();
|
|
68
|
-
|
|
69
|
-
Listing { entries, _charge }
|
|
33
|
+
entries
|
|
70
34
|
}
|
|
71
35
|
};
|
|
72
|
-
if !emit_from(ctx, &
|
|
73
|
-
self.0 = Some(
|
|
36
|
+
if !emit_from(ctx, &entries) {
|
|
37
|
+
self.0 = Some(entries);
|
|
74
38
|
}
|
|
75
39
|
Ok(())
|
|
76
40
|
}
|
|
@@ -78,7 +42,7 @@ impl Rdir {
|
|
|
78
42
|
|
|
79
43
|
/// `.` and `..` as a stat of `dentry` and of what stands above it reports them,
|
|
80
44
|
/// `..` naming `dentry` itself at the root.
|
|
81
|
-
fn dots(dentry: &Dentry) -> Result<Vec<DirEntry>,
|
|
45
|
+
fn dots(dentry: &Dentry) -> Result<Vec<DirEntry>, Errno> {
|
|
82
46
|
let dot = dentry.getattr()?;
|
|
83
47
|
let dotdot = dentry.parent().getattr()?;
|
|
84
48
|
Ok(vec![
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//! Host links the Filesystem tests stage beneath a Bind.
|
|
2
|
+
|
|
3
|
+
use std::path::Path;
|
|
4
|
+
|
|
5
|
+
/// Make a host link at `at` leading to `target`, spelled as a unix path.
|
|
6
|
+
/// Windows makes a link to a directory apart from one to a file, so there
|
|
7
|
+
/// the kind follows what `target` names now, a file where nothing stands,
|
|
8
|
+
/// and `target` takes the host's separator.
|
|
9
|
+
pub(crate) fn symlink(target: impl AsRef<Path>, at: impl AsRef<Path>) {
|
|
10
|
+
let (target, at) = (target.as_ref(), at.as_ref());
|
|
11
|
+
#[cfg(unix)]
|
|
12
|
+
let made = std::os::unix::fs::symlink(target, at);
|
|
13
|
+
#[cfg(windows)]
|
|
14
|
+
let made = {
|
|
15
|
+
let target = std::path::PathBuf::from(target.to_string_lossy().replace('/', "\\"));
|
|
16
|
+
let beside = at.parent().unwrap_or(Path::new(""));
|
|
17
|
+
if beside.join(&target).is_dir() {
|
|
18
|
+
std::os::windows::fs::symlink_dir(&target, at)
|
|
19
|
+
} else {
|
|
20
|
+
std::os::windows::fs::symlink_file(&target, at)
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
made.unwrap_or_else(|err| {
|
|
24
|
+
panic!(
|
|
25
|
+
"the host must make a link at {} to {}: {err}; a Windows host makes one only \
|
|
26
|
+
in Developer Mode or with the privilege to create symbolic links",
|
|
27
|
+
at.display(),
|
|
28
|
+
target.display()
|
|
29
|
+
)
|
|
30
|
+
});
|
|
31
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//! The paths a Host App seeds a Tmpfs with, components joined by `/` and the
|
|
2
|
+
//! empty path being the root.
|
|
3
|
+
|
|
4
|
+
use super::SeedError;
|
|
5
|
+
|
|
6
|
+
/// The last name of `path`, within its parent.
|
|
7
|
+
pub(super) fn name(path: &str) -> &str {
|
|
8
|
+
path.rsplit_once('/').map_or(path, |(_, name)| name)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/// Every directory above `path`, outermost first, the root left out.
|
|
12
|
+
pub(super) fn ancestors(path: &str) -> impl Iterator<Item = &str> {
|
|
13
|
+
path.match_indices('/').map(move |(end, _)| &path[..end])
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/// `path` in the form a Tmpfs holds it: no leading `/`, and no empty or
|
|
17
|
+
/// `.` component. The root, and a `..` that would leave the Tmpfs, are
|
|
18
|
+
/// refused.
|
|
19
|
+
pub(super) fn normalize(path: &str) -> Result<String, SeedError> {
|
|
20
|
+
let path = path
|
|
21
|
+
.split('/')
|
|
22
|
+
.filter(|component| !component.is_empty() && *component != ".")
|
|
23
|
+
.collect::<Vec<_>>()
|
|
24
|
+
.join("/");
|
|
25
|
+
if path.is_empty() {
|
|
26
|
+
return Err(SeedError::Root);
|
|
27
|
+
}
|
|
28
|
+
if path.split('/').any(|name| name == "..") {
|
|
29
|
+
return Err(SeedError::DotDot(path));
|
|
30
|
+
}
|
|
31
|
+
Ok(path)
|
|
32
|
+
}
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
//! `shmem_tmpfile` and `linkat` let overlayfs copy a file up unseen, and
|
|
3
3
|
//! the times set on what it copies.
|
|
4
4
|
|
|
5
|
-
use super::super::{
|
|
5
|
+
use super::super::{Errno, Iattr};
|
|
6
6
|
use super::{lock, Content, Node, Tmpfs, TmpfsFile};
|
|
7
7
|
|
|
8
8
|
impl Tmpfs {
|
|
9
9
|
/// An empty file with no name yet, as `O_TMPFILE` opens one. Dropped
|
|
10
10
|
/// unnamed, it gives its room back.
|
|
11
|
-
pub(crate) fn tmpfile(&self) -> Result<TmpfsFile,
|
|
11
|
+
pub(crate) fn tmpfile(&self) -> Result<TmpfsFile, Errno> {
|
|
12
12
|
Ok(TmpfsFile {
|
|
13
13
|
data: Content::create(&self.tree)?,
|
|
14
14
|
})
|
|
@@ -16,7 +16,7 @@ impl Tmpfs {
|
|
|
16
16
|
|
|
17
17
|
/// Name `file` `name` in this directory, as `simple_link` names a file
|
|
18
18
|
/// `O_TMPFILE` opened once `vfs_link` found the name free.
|
|
19
|
-
pub(crate) fn link(&self, file: &TmpfsFile, name: &str) -> Result<(),
|
|
19
|
+
pub(crate) fn link(&self, file: &TmpfsFile, name: &str) -> Result<(), Errno> {
|
|
20
20
|
self.dir.state().insert(name, Node::File(file.data.clone()));
|
|
21
21
|
Ok(())
|
|
22
22
|
}
|
|
@@ -3,16 +3,39 @@
|
|
|
3
3
|
//! `shmem_rename2` takes `RENAME_NOREPLACE`, `RENAME_EXCHANGE`, and
|
|
4
4
|
//! `RENAME_WHITEOUT`.
|
|
5
5
|
|
|
6
|
-
use std::sync::
|
|
6
|
+
use std::sync::atomic::Ordering;
|
|
7
|
+
use std::sync::{Arc, Mutex, MutexGuard, PoisonError};
|
|
7
8
|
|
|
8
|
-
use super::super::
|
|
9
|
-
use super::{Node, Space, Tmpfs};
|
|
10
|
-
use crate::vfs::RenameFlag;
|
|
9
|
+
use super::super::Errno;
|
|
10
|
+
use super::{Node, Space, Times, Tmpfs};
|
|
11
|
+
use crate::vfs::{FileType, Kstat, RenameFlag};
|
|
11
12
|
|
|
12
13
|
/// A whiteout, counting one inode for as long as it stands, as the
|
|
13
|
-
/// character device
|
|
14
|
+
/// character device `shmem_mknod` makes for one does: an inode of its own,
|
|
15
|
+
/// with its own times.
|
|
14
16
|
pub(super) struct Whiteout {
|
|
15
17
|
space: Arc<Space>,
|
|
18
|
+
dev: u64,
|
|
19
|
+
ino: u64,
|
|
20
|
+
times: Mutex<Times>,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
impl Whiteout {
|
|
24
|
+
pub(super) fn getattr(&self) -> Kstat {
|
|
25
|
+
self.times().report(
|
|
26
|
+
Kstat::new(FileType::Chrdev, 0)
|
|
27
|
+
.with_identity(self.dev, self.ino)
|
|
28
|
+
.with_nlink(1),
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
pub(super) fn ino(&self) -> u64 {
|
|
33
|
+
self.ino
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
pub(super) fn times(&self) -> MutexGuard<'_, Times> {
|
|
37
|
+
self.times.lock().unwrap_or_else(PoisonError::into_inner)
|
|
38
|
+
}
|
|
16
39
|
}
|
|
17
40
|
|
|
18
41
|
impl Drop for Whiteout {
|
|
@@ -22,64 +45,63 @@ impl Drop for Whiteout {
|
|
|
22
45
|
}
|
|
23
46
|
|
|
24
47
|
impl Tmpfs {
|
|
25
|
-
fn new_whiteout(&self) -> Result<Node,
|
|
48
|
+
fn new_whiteout(&self) -> Result<Node, Errno> {
|
|
26
49
|
self.tree.space.inodes.take(1)?;
|
|
27
|
-
Ok(Node::Whiteout {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
50
|
+
Ok(Node::Whiteout(Arc::new(Whiteout {
|
|
51
|
+
space: self.tree.space.clone(),
|
|
52
|
+
dev: self.tree.dev,
|
|
53
|
+
ino: self.tree.next_ino.fetch_add(1, Ordering::Relaxed),
|
|
54
|
+
times: Mutex::new(Times::now()),
|
|
55
|
+
})))
|
|
32
56
|
}
|
|
33
57
|
|
|
34
58
|
/// Whether a whiteout stands at `name`, as overlayfs's
|
|
35
59
|
/// `ovl_is_whiteout` reads a character device 0:0.
|
|
36
60
|
pub(crate) fn is_whiteout(&self, name: &str) -> bool {
|
|
37
|
-
matches!(self.dir.get(name), Ok(Node::Whiteout
|
|
61
|
+
matches!(self.dir.get(name), Ok(Node::Whiteout(_)))
|
|
38
62
|
}
|
|
39
63
|
|
|
40
64
|
/// Make a whiteout at `name`, as `shmem_mknod` makes the character
|
|
41
65
|
/// device 0:0 `vfs_whiteout` asks for.
|
|
42
|
-
pub(crate) fn whiteout(&self, name: &str) -> Result<(),
|
|
66
|
+
pub(crate) fn whiteout(&self, name: &str) -> Result<(), Errno> {
|
|
43
67
|
let whiteout = self.new_whiteout()?;
|
|
44
68
|
self.dir.state().insert(name, whiteout);
|
|
45
69
|
Ok(())
|
|
46
70
|
}
|
|
47
71
|
|
|
48
|
-
/// Move `
|
|
49
|
-
/// `
|
|
50
|
-
/// changes. Without one, what stands at `
|
|
72
|
+
/// Move `old_name` to `new_name` in `target` as `shmem_rename2` does with
|
|
73
|
+
/// `flags`, the entry taking all it holds, so no name beneath it
|
|
74
|
+
/// changes. Without one, what stands at `new_name` goes as rename(2)
|
|
51
75
|
/// replaces it, once the VFS found the move fits what stands on each
|
|
52
76
|
/// side.
|
|
53
77
|
pub(super) fn rename_at(
|
|
54
78
|
&self,
|
|
55
|
-
|
|
79
|
+
old_name: &str,
|
|
56
80
|
target: &Tmpfs,
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
) -> Result<(),
|
|
60
|
-
let (
|
|
61
|
-
let moving =
|
|
62
|
-
let replaced =
|
|
63
|
-
if
|
|
64
|
-
let replaced = replaced.ok_or(
|
|
65
|
-
|
|
66
|
-
|
|
81
|
+
new_name: &str,
|
|
82
|
+
flags: Option<RenameFlag>,
|
|
83
|
+
) -> Result<(), Errno> {
|
|
84
|
+
let (old_dir, new_dir) = (&self.dir, &target.dir);
|
|
85
|
+
let moving = old_dir.get(old_name)?;
|
|
86
|
+
let replaced = new_dir.get(new_name).ok();
|
|
87
|
+
if flags == Some(RenameFlag::Exchange) {
|
|
88
|
+
let replaced = replaced.ok_or(Errno::NotFound)?;
|
|
89
|
+
old_dir.state().exchange(old_name, replaced);
|
|
90
|
+
new_dir.state().exchange(new_name, moving);
|
|
67
91
|
return Ok(());
|
|
68
92
|
}
|
|
69
|
-
if let Some(
|
|
70
|
-
|
|
71
|
-
return Err(FilesystemError::DirectoryNotEmpty);
|
|
72
|
-
}
|
|
93
|
+
if let Some(replaced) = &replaced {
|
|
94
|
+
replaced.ensure_empty()?;
|
|
73
95
|
}
|
|
74
|
-
let left = match
|
|
96
|
+
let left = match flags {
|
|
75
97
|
Some(RenameFlag::Whiteout) => Some(self.new_whiteout()?),
|
|
76
98
|
_ => None,
|
|
77
99
|
};
|
|
78
100
|
match left {
|
|
79
|
-
Some(left) =>
|
|
80
|
-
None =>
|
|
101
|
+
Some(left) => old_dir.state().exchange(old_name, left),
|
|
102
|
+
None => old_dir.state().take(old_name),
|
|
81
103
|
}
|
|
82
|
-
|
|
104
|
+
new_dir.state().insert(new_name, moving);
|
|
83
105
|
Ok(())
|
|
84
106
|
}
|
|
85
107
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//! A directory's extended attributes, as tmpfs keeps the `trusted.*`
|
|
2
2
|
//! ones overlayfs marks a directory opaque with.
|
|
3
3
|
|
|
4
|
-
use super::super::
|
|
4
|
+
use super::super::Errno;
|
|
5
5
|
use super::Tmpfs;
|
|
6
6
|
|
|
7
7
|
impl Tmpfs {
|
|
@@ -12,7 +12,7 @@ impl Tmpfs {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
/// Set the attribute `name` on this directory, as `setxattr` does.
|
|
15
|
-
pub(crate) fn setxattr(&self, name: &str, value: &[u8]) -> Result<(),
|
|
15
|
+
pub(crate) fn setxattr(&self, name: &str, value: &[u8]) -> Result<(), Errno> {
|
|
16
16
|
self.dir
|
|
17
17
|
.state()
|
|
18
18
|
.xattrs
|