kobako 0.30.0 → 0.31.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/.release-please-manifest.json +1 -1
- data/CHANGELOG.md +335 -0
- data/Cargo.lock +469 -11
- data/README.md +43 -3
- data/ROADMAP.md +1 -1
- data/crates/kobako-runtime/CHANGELOG.md +219 -0
- data/crates/kobako-runtime/Cargo.toml +51 -3
- data/crates/kobako-runtime/README.md +7 -4
- data/crates/kobako-runtime/src/cred.rs +124 -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/lookup.rs +52 -14
- data/crates/kobako-runtime/src/filesystem/bind/walk.rs +19 -20
- data/crates/kobako-runtime/src/filesystem/bind.rs +437 -245
- 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 +9 -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 +121 -37
- data/crates/kobako-runtime/src/filesystem/overlay.rs +302 -343
- data/crates/kobako-runtime/src/filesystem/pipe.rs +12 -9
- data/crates/kobako-runtime/src/filesystem/rdir.rs +15 -32
- 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 +172 -160
- data/crates/kobako-runtime/src/filesystem/wrap.rs +36 -52
- data/crates/kobako-runtime/src/filesystem.rs +6 -3
- data/crates/kobako-runtime/src/fork.rs +96 -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 +195 -0
- data/crates/kobako-runtime/src/locking.rs +10 -0
- data/crates/kobako-runtime/src/memcg.rs +383 -0
- data/crates/kobako-runtime/src/mount.rs +67 -9
- data/crates/kobako-runtime/src/net/backends.rs +43 -0
- data/crates/kobako-runtime/src/net/connections.rs +179 -0
- data/crates/kobako-runtime/src/net/credential.rs +125 -0
- data/crates/kobako-runtime/src/net/egress.rs +160 -0
- data/crates/kobako-runtime/src/net/family.rs +181 -0
- data/crates/kobako-runtime/src/net/http.rs +2733 -0
- data/crates/kobako-runtime/src/net/lookup.rs +285 -0
- data/crates/kobako-runtime/src/net/mock.rs +251 -0
- data/crates/kobako-runtime/src/net/namespace.rs +1366 -0
- data/crates/kobako-runtime/src/net/reactor.rs +531 -0
- data/crates/kobako-runtime/src/net/resolv/darwin.rs +275 -0
- data/crates/kobako-runtime/src/net/resolv/stub/tests.rs +469 -0
- data/crates/kobako-runtime/src/net/resolv/stub.rs +536 -0
- data/crates/kobako-runtime/src/net/resolv/windows.rs +248 -0
- data/crates/kobako-runtime/src/net/resolv.rs +227 -0
- data/crates/kobako-runtime/src/net/socket.rs +870 -0
- data/crates/kobako-runtime/src/net/tcp.rs +1588 -0
- data/crates/kobako-runtime/src/net/tls.rs +58 -0
- data/crates/kobako-runtime/src/net/transport.rs +279 -0
- data/crates/kobako-runtime/src/net/udp.rs +1003 -0
- data/crates/kobako-runtime/src/net.rs +42 -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 +130 -29
- 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 +101 -196
- 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 +143 -89
- data/crates/kobako-runtime/src/vfs/file.rs +199 -203
- data/crates/kobako-runtime/src/vfs/inode.rs +41 -45
- data/crates/kobako-runtime/src/vfs/kern_path.rs +38 -42
- data/crates/kobako-runtime/src/vfs/mount.rs +10 -9
- data/crates/kobako-runtime/src/vfs/namei.rs +829 -700
- data/crates/kobako-runtime/src/vfs/namespace.rs +162 -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 +159 -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 +9 -6
- data/crates/kobako-runtime/src/wait.rs +356 -0
- data/crates/kobako-transport/CHANGELOG.md +31 -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 +161 -0
- data/crates/kobako-wasmtime/Cargo.toml +26 -7
- data/crates/kobako-wasmtime/README.md +3 -2
- data/crates/kobako-wasmtime/build/preview2.rs +1339 -0
- data/crates/kobako-wasmtime/build.rs +16 -0
- data/crates/kobako-wasmtime/src/abi.rs +17 -37
- data/crates/kobako-wasmtime/src/ambient.rs +33 -18
- data/crates/kobako-wasmtime/src/cache.rs +23 -15
- data/crates/kobako-wasmtime/src/config.rs +52 -68
- data/crates/kobako-wasmtime/src/driver.rs +48 -63
- 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 +74 -12
- data/crates/kobako-wasmtime/src/lib.rs +5 -3
- data/crates/kobako-wasmtime/src/limiter.rs +70 -5
- data/crates/kobako-wasmtime/src/preview1/descriptors.rs +309 -0
- data/crates/kobako-wasmtime/src/preview1/differential/mount.rs +5 -15
- 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 +327 -296
- 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 +231 -217
- data/crates/kobako-wasmtime/src/preview1/path.rs +56 -121
- data/crates/kobako-wasmtime/src/preview1/poll.rs +244 -120
- data/crates/kobako-wasmtime/src/preview1/sock.rs +10 -8
- data/crates/kobako-wasmtime/src/preview1/testsuite.rs +5 -15
- data/crates/kobako-wasmtime/src/preview1.rs +46 -42
- 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 +3959 -0
- data/crates/kobako-wasmtime/src/preview2/http.rs +1503 -0
- data/crates/kobako-wasmtime/src/preview2/io.rs +315 -0
- data/crates/kobako-wasmtime/src/preview2/sockets.rs +379 -0
- data/crates/kobako-wasmtime/src/preview2/table.rs +305 -0
- data/crates/kobako-wasmtime/src/preview2.rs +57 -0
- data/crates/kobako-wasmtime/src/trap.rs +24 -9
- data/crates/kobako-wasmtime/src/wasi.rs +210 -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/data/kobako.wasm +0 -0
- data/ext/kobako/Cargo.toml +1 -1
- data/ext/kobako/src/{runtime/errors.rs → errors.rs} +34 -26
- data/ext/kobako/src/{runtime/escape.rs → escape.rs} +42 -11
- data/ext/kobako/src/{runtime/filesystem → filesystem}/grants.rs +30 -26
- data/ext/kobako/src/{runtime/filesystem → filesystem}/ruby.rs +149 -168
- data/ext/kobako/src/{runtime/filesystem.rs → filesystem.rs} +24 -15
- data/ext/kobako/src/gvl.rs +306 -0
- data/ext/kobako/src/lib.rs +64 -3
- data/ext/kobako/src/network/mock.rs +187 -0
- data/ext/kobako/src/network.rs +591 -0
- data/ext/kobako/src/runtime/bridge.rs +30 -29
- data/ext/kobako/src/runtime/snapshot.rs +4 -4
- data/ext/kobako/src/runtime.rs +221 -143
- 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 +5 -27
- 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 +4 -4
- data/lib/kobako/codec/ext_types.rb +3 -3
- data/lib/kobako/codec/handle_walk.rb +3 -43
- data/lib/kobako/codec/value_budget.rb +132 -40
- data/lib/kobako/codec.rb +1 -1
- data/lib/kobako/context.rb +24 -11
- data/lib/kobako/errors.rb +15 -12
- data/lib/kobako/extension.rb +3 -2
- data/lib/kobako/filesystem.rb +9 -2
- data/lib/kobako/handle.rb +2 -2
- data/lib/kobako/names.rb +28 -0
- data/lib/kobako/network.rb +210 -0
- data/lib/kobako/outcome.rb +7 -7
- data/lib/kobako/pool.rb +45 -23
- data/lib/kobako/runtime.rb +3 -2
- data/lib/kobako/sandbox.rb +92 -35
- data/lib/kobako/sandbox_options.rb +41 -106
- 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/version.rb +1 -1
- data/lib/kobako.rb +6 -2
- data/release-please-config.json +15 -0
- data/sig/core/thread.rbs +6 -0
- data/sig/kobako/catalog/extensions.rbs +2 -0
- data/sig/kobako/catalog/grants.rbs +7 -4
- data/sig/kobako/catalog/handles.rbs +0 -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/value_budget.rbs +47 -4
- data/sig/kobako/context.rbs +3 -1
- data/sig/kobako/errors.rbs +4 -4
- data/sig/kobako/filesystem.rbs +21 -3
- data/sig/kobako/network.rbs +115 -0
- data/sig/kobako/outcome.rbs +1 -1
- data/sig/kobako/pool.rbs +7 -3
- data/sig/kobako/runtime.rbs +32 -3
- data/sig/kobako/sandbox.rbs +19 -2
- data/sig/kobako/sandbox_options.rbs +29 -38
- 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 +84 -35
- 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/gvl.rs +0 -147
- data/lib/kobako/constant_name.rb +0 -8
- data/sig/kobako/constant_name.rbs +0 -3
- /data/ext/kobako/src/{runtime/pinned_value.rs → pinned_value.rs} +0 -0
|
@@ -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,9 +2,10 @@
|
|
|
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::{
|
|
5
|
+
use crate::cred::Cred;
|
|
6
|
+
use crate::memcg::MemoryCharge;
|
|
7
|
+
use crate::vfs::{Dentry, DirContext, DirEntry, FileType};
|
|
8
|
+
use crate::Errno;
|
|
8
9
|
|
|
9
10
|
/// The entries a listing began with, `.` and `..` first, on the open directory
|
|
10
11
|
/// until it reaches its end, counted against who holds them.
|
|
@@ -14,32 +15,14 @@ pub struct Rdir(Option<Listing>);
|
|
|
14
15
|
struct Listing {
|
|
15
16
|
entries: Vec<DirEntry>,
|
|
16
17
|
/// Gives the entries' bytes back once the listing goes.
|
|
17
|
-
_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,
|
|
18
|
+
_charge: MemoryCharge,
|
|
25
19
|
}
|
|
26
20
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
}
|
|
21
|
+
/// Charge the bytes `entries` hold to `cred` for as long as the listing holds
|
|
22
|
+
/// them.
|
|
23
|
+
fn charge(cred: &Cred, entries: &[DirEntry]) -> Result<MemoryCharge, Errno> {
|
|
24
|
+
let names: usize = entries.iter().map(|entry| entry.name.capacity()).sum();
|
|
25
|
+
MemoryCharge::new(cred.memory_budget(), size_of_val(entries) + names)
|
|
43
26
|
}
|
|
44
27
|
|
|
45
28
|
impl Rdir {
|
|
@@ -52,12 +35,12 @@ impl Rdir {
|
|
|
52
35
|
/// listing ends, as `ovl_cache_get` and `v9fs_alloc_rdir_buf` allocate before
|
|
53
36
|
/// the first `dir_emit`: past what a security module allows, the listing
|
|
54
37
|
/// answers out of memory before it hands any entry.
|
|
55
|
-
pub fn
|
|
38
|
+
pub fn iterate_shared(
|
|
56
39
|
&mut self,
|
|
57
40
|
dentry: &Dentry,
|
|
58
41
|
ctx: &mut DirContext<'_>,
|
|
59
|
-
read: impl FnOnce() -> Result<Vec<DirEntry>,
|
|
60
|
-
) -> Result<(),
|
|
42
|
+
read: impl FnOnce() -> Result<Vec<DirEntry>, Errno>,
|
|
43
|
+
) -> Result<(), Errno> {
|
|
61
44
|
let listing = match self.0.take().filter(|_| ctx.pos() != 0) {
|
|
62
45
|
Some(held) => held,
|
|
63
46
|
None => {
|
|
@@ -65,7 +48,7 @@ impl Rdir {
|
|
|
65
48
|
let mut entries = dots(dentry)?;
|
|
66
49
|
entries.extend(read);
|
|
67
50
|
entries.shrink_to_fit();
|
|
68
|
-
let _charge =
|
|
51
|
+
let _charge = charge(ctx.cred(), &entries)?;
|
|
69
52
|
Listing { entries, _charge }
|
|
70
53
|
}
|
|
71
54
|
};
|
|
@@ -78,7 +61,7 @@ impl Rdir {
|
|
|
78
61
|
|
|
79
62
|
/// `.` and `..` as a stat of `dentry` and of what stands above it reports them,
|
|
80
63
|
/// `..` naming `dentry` itself at the root.
|
|
81
|
-
fn dots(dentry: &Dentry) -> Result<Vec<DirEntry>,
|
|
64
|
+
fn dots(dentry: &Dentry) -> Result<Vec<DirEntry>, Errno> {
|
|
82
65
|
let dot = dentry.getattr()?;
|
|
83
66
|
let dotdot = dentry.parent().getattr()?;
|
|
84
67
|
Ok(vec![
|
|
@@ -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
|