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
|
@@ -19,7 +19,7 @@ use std::sync::Arc;
|
|
|
19
19
|
|
|
20
20
|
use super::rdir::Rdir;
|
|
21
21
|
use super::{
|
|
22
|
-
DentryOperations, FileOperations, FileSystemType, FileType, Filesystem,
|
|
22
|
+
DentryOperations, Errno, FileOperations, FileSystemType, FileType, Filesystem, Iattr,
|
|
23
23
|
InodeOperations, Kstat, Lookup, OpenHow, RenameFlag, Tmpfs,
|
|
24
24
|
};
|
|
25
25
|
use crate::vfs::{
|
|
@@ -64,17 +64,14 @@ impl Overlay {
|
|
|
64
64
|
/// Layers, a stack too deep, and one instance as two Layers, as
|
|
65
65
|
/// overlayfs answers overlapping layers; as gVisor's does, it refuses an
|
|
66
66
|
/// upper that is no Tmpfs.
|
|
67
|
-
pub fn new(
|
|
68
|
-
lower: Vec<Arc<Filesystem>>,
|
|
69
|
-
upper: Option<Arc<Filesystem>>,
|
|
70
|
-
) -> Result<Self, FilesystemError> {
|
|
67
|
+
pub fn new(lower: Vec<Arc<Filesystem>>, upper: Option<Arc<Filesystem>>) -> Result<Self, Errno> {
|
|
71
68
|
let layers: Vec<_> = lower.iter().chain(&upper).collect();
|
|
72
69
|
let overlapping = layers
|
|
73
70
|
.iter()
|
|
74
71
|
.enumerate()
|
|
75
72
|
.any(|(at, layer)| layers[..at].iter().any(|seen| Arc::ptr_eq(seen, layer)));
|
|
76
73
|
if overlapping {
|
|
77
|
-
return Err(
|
|
74
|
+
return Err(Errno::InvalidInput);
|
|
78
75
|
}
|
|
79
76
|
let too_few = if upper.is_some() { 1 } else { 2 };
|
|
80
77
|
let upper_tmpfs = upper.as_ref().is_none_or(|upper| {
|
|
@@ -96,7 +93,7 @@ impl Overlay {
|
|
|
96
93
|
|| !upper_tmpfs
|
|
97
94
|
|| stack_depth > MAX_STACK_DEPTH
|
|
98
95
|
{
|
|
99
|
-
return Err(
|
|
96
|
+
return Err(Errno::InvalidInput);
|
|
100
97
|
}
|
|
101
98
|
Ok(Self {
|
|
102
99
|
fs: OverlayFs::new(lower, upper)?,
|
|
@@ -115,7 +112,7 @@ fn real_of(dentry: &Dentry) -> Option<(Arc<Dentry>, Arc<Inode>)> {
|
|
|
115
112
|
|
|
116
113
|
/// Whether `real`, a Layer's dentry, still names what it recorded, as
|
|
117
114
|
/// `ovl_revalidate_real` asks it.
|
|
118
|
-
fn ovl_revalidate_real(real: &Dentry) -> Result<bool,
|
|
115
|
+
fn ovl_revalidate_real(real: &Dentry) -> Result<bool, Errno> {
|
|
119
116
|
match real.ops() {
|
|
120
117
|
Some(ops) => ops.revalidate(real.parent().inode_ops()?.as_ref(), real),
|
|
121
118
|
None => Ok(true),
|
|
@@ -127,11 +124,7 @@ fn ovl_revalidate_real(real: &Dentry) -> Result<bool, FilesystemError> {
|
|
|
127
124
|
/// stands for what each Layer holds there, as `ovl_clear_empty` drops a dentry
|
|
128
125
|
/// whose upper no longer matches.
|
|
129
126
|
impl DentryOperations for Overlay {
|
|
130
|
-
fn revalidate(
|
|
131
|
-
&self,
|
|
132
|
-
_dir: &dyn InodeOperations,
|
|
133
|
-
dentry: &Dentry,
|
|
134
|
-
) -> Result<bool, FilesystemError> {
|
|
127
|
+
fn revalidate(&self, _dir: &dyn InodeOperations, dentry: &Dentry) -> Result<bool, Errno> {
|
|
135
128
|
let Some(inode) = dentry.inode() else {
|
|
136
129
|
return Ok(matches!(self.lookup(dentry)?, Lookup::Absent));
|
|
137
130
|
};
|
|
@@ -192,8 +185,8 @@ impl Overlay {
|
|
|
192
185
|
|
|
193
186
|
/// What the Layer the entry's name is found in reports, under the identity
|
|
194
187
|
/// the view recorded.
|
|
195
|
-
fn real_getattr(&self, dentry: &Dentry) -> Result<Kstat,
|
|
196
|
-
let (real, inode) = real_of(dentry).ok_or(
|
|
188
|
+
fn real_getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
189
|
+
let (real, inode) = real_of(dentry).ok_or(Errno::NotFound)?;
|
|
197
190
|
let found = real.getattr()?;
|
|
198
191
|
Ok(match inode.identity() {
|
|
199
192
|
Some(identity) => identity.onto(found),
|
|
@@ -203,18 +196,18 @@ impl Overlay {
|
|
|
203
196
|
}
|
|
204
197
|
|
|
205
198
|
impl InodeOperations for OverlayRegular {
|
|
206
|
-
fn getattr(&self, dentry: &Dentry) -> Result<Kstat,
|
|
199
|
+
fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
207
200
|
self.0.real_getattr(dentry)
|
|
208
201
|
}
|
|
209
202
|
|
|
210
203
|
/// Copied up first, as `ovl_setattr` does, so a lower Layer stays as it
|
|
211
204
|
/// was whatever its Filesystem would keep.
|
|
212
|
-
fn setattr(&self, dentry: &Dentry, attr: &Iattr) -> Result<(),
|
|
205
|
+
fn setattr(&self, dentry: &Dentry, attr: &Iattr) -> Result<(), Errno> {
|
|
213
206
|
let overlay = &self.0;
|
|
214
207
|
overlay
|
|
215
208
|
.fs
|
|
216
209
|
.copy_up_file(&overlay.fs.parent(dentry)?, dentry, false)?;
|
|
217
|
-
let (real, _) = real_of(dentry).ok_or(
|
|
210
|
+
let (real, _) = real_of(dentry).ok_or(Errno::NotFound)?;
|
|
218
211
|
// The open's truncate never reached the upper's open, so the upper must
|
|
219
212
|
// empty the file itself, and the view's open file is none of the upper's,
|
|
220
213
|
// as `ovl_setattr` clears `ATTR_OPEN` and `ATTR_FILE`.
|
|
@@ -230,24 +223,20 @@ impl InodeOperations for OverlayRegular {
|
|
|
230
223
|
)
|
|
231
224
|
}
|
|
232
225
|
|
|
233
|
-
fn open(
|
|
234
|
-
&self,
|
|
235
|
-
dentry: &Dentry,
|
|
236
|
-
how: &OpenHow,
|
|
237
|
-
) -> Result<Box<dyn FileOperations>, FilesystemError> {
|
|
226
|
+
fn open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
|
|
238
227
|
let fs = &self.0.fs;
|
|
239
228
|
fs.open(&fs.parent(dentry)?, dentry, how)
|
|
240
229
|
}
|
|
241
230
|
}
|
|
242
231
|
|
|
243
232
|
impl InodeOperations for OverlayLink {
|
|
244
|
-
fn getattr(&self, dentry: &Dentry) -> Result<Kstat,
|
|
233
|
+
fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
245
234
|
self.0.real_getattr(dentry)
|
|
246
235
|
}
|
|
247
236
|
|
|
248
237
|
/// Where the link points, as `ovl_get_link` asks the real dentry.
|
|
249
|
-
fn get_link(&self, dentry: &Dentry) -> Result<String,
|
|
250
|
-
let (real, _) = real_of(dentry).ok_or(
|
|
238
|
+
fn get_link(&self, dentry: &Dentry) -> Result<String, Errno> {
|
|
239
|
+
let (real, _) = real_of(dentry).ok_or(Errno::NotFound)?;
|
|
251
240
|
real.get_link()
|
|
252
241
|
}
|
|
253
242
|
}
|
|
@@ -257,7 +246,7 @@ impl FileSystemType for Overlay {
|
|
|
257
246
|
/// Its root takes the identity its topmost Layer's root recorded, as
|
|
258
247
|
/// `ovl_get_root` reads a real root's `i_ino`, so making the view asks no
|
|
259
248
|
/// Layer anything.
|
|
260
|
-
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(),
|
|
249
|
+
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
|
|
261
250
|
sb.set_default_d_op(self.clone());
|
|
262
251
|
if !self.fs.has_upper() {
|
|
263
252
|
sb.set_rdonly();
|
|
@@ -279,13 +268,13 @@ impl FileSystemType for Overlay {
|
|
|
279
268
|
/// is handed, as `ovl_dir_inode_operations` answers for one.
|
|
280
269
|
impl InodeOperations for Overlay {
|
|
281
270
|
/// It reports its merged Layers.
|
|
282
|
-
fn getattr(&self, dentry: &Dentry) -> Result<Kstat,
|
|
271
|
+
fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
283
272
|
self.fs.dir_getattr(&self.fs.dir(dentry)?.level())
|
|
284
273
|
}
|
|
285
274
|
|
|
286
275
|
/// Copied up first, as `ovl_setattr` does for any entry, so a lower Layer
|
|
287
276
|
/// stays as it was.
|
|
288
|
-
fn setattr(&self, dentry: &Dentry, attr: &Iattr) -> Result<(),
|
|
277
|
+
fn setattr(&self, dentry: &Dentry, attr: &Iattr) -> Result<(), Errno> {
|
|
289
278
|
let upper = self.fs.upper_dir(&self.fs.dir(dentry)?)?;
|
|
290
279
|
let held = upper.dentry().inode_lock()?;
|
|
291
280
|
notify_change(upper.dentry(), &held, attr)
|
|
@@ -294,11 +283,11 @@ impl InodeOperations for Overlay {
|
|
|
294
283
|
/// The entry as a Layer spells it, as `ovl_lookup` hands
|
|
295
284
|
/// `d_splice_alias` the inode it made, a name no Layer could hold refused
|
|
296
285
|
/// before any is asked, as it compares `namelen`.
|
|
297
|
-
fn lookup(&self, dentry: &Dentry) -> Result<Lookup,
|
|
286
|
+
fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
|
|
298
287
|
let level = self.fs.parent(dentry)?.level();
|
|
299
288
|
let name = dentry.name();
|
|
300
289
|
if name.len() > NAME_MAX {
|
|
301
|
-
return Err(
|
|
290
|
+
return Err(Errno::InvalidFilename);
|
|
302
291
|
}
|
|
303
292
|
let Some(found) = self.fs.lookup_layer(&level, &name)? else {
|
|
304
293
|
return Ok(Lookup::Absent);
|
|
@@ -316,11 +305,7 @@ impl InodeOperations for Overlay {
|
|
|
316
305
|
}
|
|
317
306
|
}
|
|
318
307
|
|
|
319
|
-
fn open(
|
|
320
|
-
&self,
|
|
321
|
-
dentry: &Dentry,
|
|
322
|
-
_how: &OpenHow,
|
|
323
|
-
) -> Result<Box<dyn FileOperations>, FilesystemError> {
|
|
308
|
+
fn open(&self, dentry: &Dentry, _how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
|
|
324
309
|
let _real = self
|
|
325
310
|
.fs
|
|
326
311
|
.dir(dentry)?
|
|
@@ -339,24 +324,24 @@ impl InodeOperations for Overlay {
|
|
|
339
324
|
|
|
340
325
|
/// What was made is found through the view's own lookup, as `ovl_instantiate`
|
|
341
326
|
/// records the inode for the real dentry.
|
|
342
|
-
fn create(&self, dentry: &Dentry) -> Result<(),
|
|
327
|
+
fn create(&self, dentry: &Dentry) -> Result<(), Errno> {
|
|
343
328
|
self.fs.create(&self.fs.parent(dentry)?, &dentry.name())?;
|
|
344
329
|
match self.lookup(dentry)? {
|
|
345
330
|
Lookup::Found(inode) => dentry.add(Some(inode)),
|
|
346
|
-
_ => return Err(
|
|
331
|
+
_ => return Err(Errno::NotFound),
|
|
347
332
|
}
|
|
348
333
|
Ok(())
|
|
349
334
|
}
|
|
350
335
|
|
|
351
|
-
fn mkdir(&self, dentry: &Dentry) -> Result<(),
|
|
336
|
+
fn mkdir(&self, dentry: &Dentry) -> Result<(), Errno> {
|
|
352
337
|
self.fs.mkdir(&self.fs.parent(dentry)?, &dentry.name())
|
|
353
338
|
}
|
|
354
339
|
|
|
355
|
-
fn rmdir(&self, dentry: &Dentry) -> Result<(),
|
|
340
|
+
fn rmdir(&self, dentry: &Dentry) -> Result<(), Errno> {
|
|
356
341
|
self.fs.rmdir(&self.fs.parent(dentry)?, dentry)
|
|
357
342
|
}
|
|
358
343
|
|
|
359
|
-
fn unlink(&self, dentry: &Dentry) -> Result<(),
|
|
344
|
+
fn unlink(&self, dentry: &Dentry) -> Result<(), Errno> {
|
|
360
345
|
self.fs.unlink(&self.fs.parent(dentry)?, dentry)
|
|
361
346
|
}
|
|
362
347
|
|
|
@@ -364,16 +349,16 @@ impl InodeOperations for Overlay {
|
|
|
364
349
|
/// it are open. Only its upper takes a flag, which it asks itself.
|
|
365
350
|
fn rename(
|
|
366
351
|
&self,
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
) -> Result<(),
|
|
372
|
-
if
|
|
373
|
-
return Err(
|
|
352
|
+
old: &Dentry,
|
|
353
|
+
_new_dir: &dyn InodeOperations,
|
|
354
|
+
new: &Dentry,
|
|
355
|
+
flags: Option<RenameFlag>,
|
|
356
|
+
) -> Result<(), Errno> {
|
|
357
|
+
if flags.is_some() {
|
|
358
|
+
return Err(Errno::InvalidInput);
|
|
374
359
|
}
|
|
375
360
|
self.fs
|
|
376
|
-
.rename(&self.fs.parent(
|
|
361
|
+
.rename(&self.fs.parent(old)?, old, &self.fs.parent(new)?, new)
|
|
377
362
|
}
|
|
378
363
|
}
|
|
379
364
|
|
|
@@ -394,31 +379,27 @@ impl FileOperations for OverlayDir {
|
|
|
394
379
|
pos: u64,
|
|
395
380
|
offset: i64,
|
|
396
381
|
whence: Whence,
|
|
397
|
-
) -> Result<u64,
|
|
382
|
+
) -> Result<u64, Errno> {
|
|
398
383
|
generic_file_llseek(dentry, pos, offset, whence)
|
|
399
384
|
}
|
|
400
385
|
|
|
401
|
-
fn read_iter(
|
|
402
|
-
&mut self,
|
|
403
|
-
_iocb: &mut super::Kiocb,
|
|
404
|
-
_buf: &mut [u8],
|
|
405
|
-
) -> Result<usize, FilesystemError> {
|
|
386
|
+
fn read_iter(&mut self, _iocb: &mut super::Kiocb, _buf: &mut [u8]) -> Result<usize, Errno> {
|
|
406
387
|
generic_read_dir()
|
|
407
388
|
}
|
|
408
389
|
|
|
409
|
-
fn
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
) -> Result<(),
|
|
390
|
+
fn has_iterate_shared(&self) -> bool {
|
|
391
|
+
true
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
fn iterate_shared(&mut self, dentry: &Dentry, ctx: &mut DirContext<'_>) -> Result<(), Errno> {
|
|
414
395
|
let (fs, cache) = (&self.fs, &mut self.cache);
|
|
415
|
-
cache.
|
|
396
|
+
cache.iterate_shared(dentry, ctx, || fs.dir_read_merged(&fs.dir(dentry)?.level()))
|
|
416
397
|
}
|
|
417
398
|
|
|
418
399
|
/// Its Layers answer for what they hold, and its upper is a Tmpfs, so
|
|
419
400
|
/// nothing is left to make durable, as `ovl_dir_fsync` finds with no upper
|
|
420
401
|
/// of its own to sync.
|
|
421
|
-
fn fsync(&mut self, _datasync: bool) -> Result<(),
|
|
402
|
+
fn fsync(&mut self, _datasync: bool) -> Result<(), Errno> {
|
|
422
403
|
Ok(())
|
|
423
404
|
}
|
|
424
405
|
}
|
|
@@ -451,11 +432,7 @@ mod tests {
|
|
|
451
432
|
struct CountsLookups(AtomicUsize);
|
|
452
433
|
|
|
453
434
|
impl Hook for CountsLookups {
|
|
454
|
-
fn lookup(
|
|
455
|
-
&self,
|
|
456
|
-
inner: &dyn InodeOperations,
|
|
457
|
-
dentry: &Dentry,
|
|
458
|
-
) -> Result<Lookup, FilesystemError> {
|
|
435
|
+
fn lookup(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<Lookup, Errno> {
|
|
459
436
|
self.0.fetch_add(1, Ordering::SeqCst);
|
|
460
437
|
inner.lookup(dentry)
|
|
461
438
|
}
|
|
@@ -470,11 +447,9 @@ mod tests {
|
|
|
470
447
|
let lower: Tmpfs = [("file", "x")].into_iter().collect();
|
|
471
448
|
let counts = Arc::new(CountsLookups::default());
|
|
472
449
|
let view = at(Overlay::new(
|
|
473
|
-
vec![
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
],
|
|
477
|
-
Some(Filesystem::new(Arc::new(Tmpfs::new())).expect("the instance must stand")),
|
|
450
|
+
vec![Filesystem::new(Wrap::new(Arc::new(lower), counts.clone()))
|
|
451
|
+
.expect("the instance must stand")],
|
|
452
|
+
Some(Filesystem::new(Tmpfs::new()).expect("the instance must stand")),
|
|
478
453
|
)
|
|
479
454
|
.expect("the Overlay must stack"));
|
|
480
455
|
let asks = |path: &str| {
|
|
@@ -505,9 +480,9 @@ mod tests {
|
|
|
505
480
|
on(&upper).vfs_lstat("upper/dir").err(),
|
|
506
481
|
),
|
|
507
482
|
(
|
|
508
|
-
Some(
|
|
509
|
-
Some(
|
|
510
|
-
Some(
|
|
483
|
+
Some(Errno::InvalidFilename),
|
|
484
|
+
Some(Errno::InvalidFilename),
|
|
485
|
+
Some(Errno::NotFound),
|
|
511
486
|
),
|
|
512
487
|
"a stat and a make of a name past NAME_MAX in a lower directory, through an Overlay, \
|
|
513
488
|
must answer ENAMETOOLONG and leave that directory uncopied"
|
|
@@ -520,8 +495,8 @@ mod tests {
|
|
|
520
495
|
let lower: Tmpfs = [("file", "x")].into_iter().collect();
|
|
521
496
|
let upper = Tmpfs::new();
|
|
522
497
|
let overlay = at(Overlay::new(
|
|
523
|
-
vec![Filesystem::new(
|
|
524
|
-
Some(Filesystem::new(
|
|
498
|
+
vec![Filesystem::new(lower).expect("the instance must stand")],
|
|
499
|
+
Some(Filesystem::new(upper).expect("the instance must stand")),
|
|
525
500
|
)
|
|
526
501
|
.expect("the Overlay must stack"));
|
|
527
502
|
assert_eq!(
|
|
@@ -552,7 +527,7 @@ mod tests {
|
|
|
552
527
|
fn read_from(file: &mut dyn FileOperations) -> Vec<u8> {
|
|
553
528
|
let mut buf = vec![0; 64];
|
|
554
529
|
let read = file
|
|
555
|
-
.read_iter(&mut Kiocb::
|
|
530
|
+
.read_iter(&mut Kiocb::new(0), &mut buf)
|
|
556
531
|
.expect("the file must read");
|
|
557
532
|
buf.truncate(read);
|
|
558
533
|
buf
|
|
@@ -562,7 +537,7 @@ mod tests {
|
|
|
562
537
|
read_from(open_to_read(fs, path).as_mut())
|
|
563
538
|
}
|
|
564
539
|
|
|
565
|
-
fn write(fs: &KernPath, path: &str, contents: &[u8]) -> Result<(),
|
|
540
|
+
fn write(fs: &KernPath, path: &str, contents: &[u8]) -> Result<(), Errno> {
|
|
566
541
|
fs.open_or_create(
|
|
567
542
|
path,
|
|
568
543
|
&OpenHow {
|
|
@@ -571,19 +546,19 @@ mod tests {
|
|
|
571
546
|
..OpenHow::default()
|
|
572
547
|
},
|
|
573
548
|
)?
|
|
574
|
-
.write_iter(&mut Kiocb::
|
|
549
|
+
.write_iter(&mut Kiocb::new(0), contents)
|
|
575
550
|
.map(drop)
|
|
576
551
|
}
|
|
577
552
|
|
|
578
553
|
/// Write at the start of what stands at `path`, so a copy up brings its
|
|
579
554
|
/// bytes along.
|
|
580
|
-
fn write_over(fs: &KernPath, path: &str, contents: &[u8]) -> Result<(),
|
|
555
|
+
fn write_over(fs: &KernPath, path: &str, contents: &[u8]) -> Result<(), Errno> {
|
|
581
556
|
let how = OpenHow {
|
|
582
557
|
write: true,
|
|
583
558
|
..OpenHow::default()
|
|
584
559
|
};
|
|
585
560
|
fs.open(path, &how)?
|
|
586
|
-
.write_iter(&mut Kiocb::
|
|
561
|
+
.write_iter(&mut Kiocb::new(0), contents)
|
|
587
562
|
.map(drop)
|
|
588
563
|
}
|
|
589
564
|
|
|
@@ -609,6 +584,19 @@ mod tests {
|
|
|
609
584
|
Arc::new([(path, contents)].into_iter().collect())
|
|
610
585
|
}
|
|
611
586
|
|
|
587
|
+
/// Set every time of what stands at `path` to a moment long past, so a
|
|
588
|
+
/// time a later change sets differs from it whatever the clock's
|
|
589
|
+
/// resolution.
|
|
590
|
+
fn set_long_ago(fs: &KernPath, path: &str) {
|
|
591
|
+
let long_ago = std::time::SystemTime::UNIX_EPOCH + Duration::from_secs(1);
|
|
592
|
+
let at = Some(crate::vfs::SetTime::At(long_ago));
|
|
593
|
+
let attr = Iattr {
|
|
594
|
+
ctime: Some(long_ago),
|
|
595
|
+
..Iattr::for_times(at, at)
|
|
596
|
+
};
|
|
597
|
+
fs.setattr(path, &attr).expect("the times must be set");
|
|
598
|
+
}
|
|
599
|
+
|
|
612
600
|
// A helper beneath the VFS skips the super block's read-only answer, so only
|
|
613
601
|
// the view's own upper standing empty keeps the change off its lower Layers.
|
|
614
602
|
// @behavior FS-197
|
|
@@ -621,10 +609,7 @@ mod tests {
|
|
|
621
609
|
overlay.vfs_mkdir("made").err(),
|
|
622
610
|
on(&top).vfs_lstat("made").err()
|
|
623
611
|
),
|
|
624
|
-
(
|
|
625
|
-
Some(FilesystemError::ReadOnlyFilesystem),
|
|
626
|
-
Some(FilesystemError::NotFound)
|
|
627
|
-
),
|
|
612
|
+
(Some(Errno::ReadOnlyFilesystem), Some(Errno::NotFound)),
|
|
628
613
|
"OverlayFs::mkdir with no upper, reached beneath the VFS's read-only answer, must \
|
|
629
614
|
answer EROFS and make nothing in its topmost lower Layer"
|
|
630
615
|
);
|
|
@@ -634,12 +619,8 @@ mod tests {
|
|
|
634
619
|
/// let change.
|
|
635
620
|
struct RecordsChanges(Arc<Mutex<Vec<String>>>);
|
|
636
621
|
|
|
637
|
-
impl crate::
|
|
638
|
-
fn inode_permission(
|
|
639
|
-
&self,
|
|
640
|
-
dentry: &Dentry,
|
|
641
|
-
mask: crate::vfs::Mask,
|
|
642
|
-
) -> Result<(), FilesystemError> {
|
|
622
|
+
impl crate::security::SecurityOperations for RecordsChanges {
|
|
623
|
+
fn inode_permission(&self, dentry: &Dentry, mask: crate::vfs::Mask) -> Result<(), Errno> {
|
|
643
624
|
if mask.contains(crate::vfs::Mask::WRITE) {
|
|
644
625
|
self.0.lock().expect("never poisoned").push(dentry.name());
|
|
645
626
|
}
|
|
@@ -655,12 +636,12 @@ mod tests {
|
|
|
655
636
|
let overlay = over(tmpfs_with("f", "x"), Arc::new(Tmpfs::new()));
|
|
656
637
|
let mount = crate::mount::Mount::new(
|
|
657
638
|
"/data",
|
|
658
|
-
Filesystem::new(
|
|
639
|
+
Filesystem::new(overlay).expect("the instance must stand"),
|
|
659
640
|
crate::mount::Access::ReadWrite,
|
|
660
641
|
)
|
|
661
642
|
.expect("/data is a guest path");
|
|
662
643
|
let asked = Arc::new(Mutex::new(Vec::new()));
|
|
663
|
-
let cred = crate::
|
|
644
|
+
let cred = crate::cred::Cred::new(vec![Arc::new(RecordsChanges(asked.clone()))]);
|
|
664
645
|
let root = crate::vfs::Path::root(mount.mnt());
|
|
665
646
|
let made = crate::vfs::filename_mkdirat(&cred, &root, "d");
|
|
666
647
|
assert_eq!(
|
|
@@ -694,10 +675,8 @@ mod tests {
|
|
|
694
675
|
/// A host directory holding `target`, `dir/inner`, and the links `link`
|
|
695
676
|
/// to `target`, `dirlink` to `dir`, and `dangling` to nothing, removed
|
|
696
677
|
/// when it drops.
|
|
697
|
-
#[cfg(unix)]
|
|
698
678
|
struct LinkTree(std::path::PathBuf);
|
|
699
679
|
|
|
700
|
-
#[cfg(unix)]
|
|
701
680
|
impl LinkTree {
|
|
702
681
|
fn new(name: &str) -> Self {
|
|
703
682
|
let path =
|
|
@@ -711,7 +690,7 @@ mod tests {
|
|
|
711
690
|
("dir", "dirlink"),
|
|
712
691
|
("missing", "dangling"),
|
|
713
692
|
] {
|
|
714
|
-
|
|
693
|
+
crate::filesystem::testing::symlink(target, path.join(link));
|
|
715
694
|
}
|
|
716
695
|
Self(path)
|
|
717
696
|
}
|
|
@@ -735,7 +714,6 @@ mod tests {
|
|
|
735
714
|
// so only merging directory over directory keeps the lower link's
|
|
736
715
|
// target out of the view.
|
|
737
716
|
// @behavior FS-113
|
|
738
|
-
#[cfg(unix)]
|
|
739
717
|
#[test]
|
|
740
718
|
fn a_lower_layers_link_beneath_an_upper_directory_is_not_merged() {
|
|
741
719
|
let tree = LinkTree::new("not-merged");
|
|
@@ -748,13 +726,12 @@ mod tests {
|
|
|
748
726
|
kind(&overlay, "dirlink/inner"),
|
|
749
727
|
names(&overlay, "dirlink").len()
|
|
750
728
|
),
|
|
751
|
-
(Err(
|
|
729
|
+
(Err(Errno::NotFound), 0),
|
|
752
730
|
"a name beneath a directory an upper Layer holds, where a lower Layer holds a link, \
|
|
753
731
|
through vfs_lstat and its listing must show nothing the link leads to"
|
|
754
732
|
);
|
|
755
733
|
}
|
|
756
734
|
|
|
757
|
-
#[cfg(unix)]
|
|
758
735
|
impl Drop for LinkTree {
|
|
759
736
|
fn drop(&mut self) {
|
|
760
737
|
let _ = std::fs::remove_dir_all(&self.0);
|
|
@@ -764,7 +741,6 @@ mod tests {
|
|
|
764
741
|
// The link stands in the Bind Layer beneath a Tmpfs one, so only
|
|
765
742
|
// the Overlay asking that Layer without following refuses it.
|
|
766
743
|
// @behavior FS-100
|
|
767
|
-
#[cfg(unix)]
|
|
768
744
|
#[test]
|
|
769
745
|
fn an_overlay_opens_no_link_as_a_directory_where_asked_not_to_follow() {
|
|
770
746
|
let host = LinkTree::new("nofollow");
|
|
@@ -774,14 +750,13 @@ mod tests {
|
|
|
774
750
|
overlay.open_dir("dirlink").map(drop),
|
|
775
751
|
overlay.vfs_readlink("dirlink")
|
|
776
752
|
),
|
|
777
|
-
(Err(
|
|
753
|
+
(Err(Errno::FilesystemLoop), Ok("dir".to_string())),
|
|
778
754
|
"a link a Bind Layer holds, opened through Overlay::open_dir, must be a \
|
|
779
755
|
link loop, and through vfs_readlink must answer where it points"
|
|
780
756
|
);
|
|
781
757
|
}
|
|
782
758
|
|
|
783
759
|
// @behavior FS-049
|
|
784
|
-
#[cfg(unix)]
|
|
785
760
|
#[test]
|
|
786
761
|
fn an_overlay_reports_a_link_its_layer_holds_as_a_link() {
|
|
787
762
|
let host = LinkTree::new("lstat");
|
|
@@ -798,7 +773,6 @@ mod tests {
|
|
|
798
773
|
// A link to a directory follows to one, and a dangling link follows to
|
|
799
774
|
// nothing, so only judging each link itself lets both go.
|
|
800
775
|
// @behavior FS-050
|
|
801
|
-
#[cfg(unix)]
|
|
802
776
|
#[test]
|
|
803
777
|
fn an_overlay_removes_a_link_its_read_only_layer_holds_as_itself() {
|
|
804
778
|
let host = LinkTree::new("unlink");
|
|
@@ -817,9 +791,9 @@ mod tests {
|
|
|
817
791
|
host.0.join("dirlink").is_symlink()
|
|
818
792
|
),
|
|
819
793
|
(
|
|
820
|
-
(Err(
|
|
821
|
-
Some(
|
|
822
|
-
Some(
|
|
794
|
+
(Err(Errno::NotADirectory), Ok(()), Ok(())),
|
|
795
|
+
Some(Errno::NotFound),
|
|
796
|
+
Some(Errno::NotFound),
|
|
823
797
|
true
|
|
824
798
|
),
|
|
825
799
|
"a link a read-only Bind Layer holds, removed through vfs_rmdir and \
|
|
@@ -847,10 +821,7 @@ mod tests {
|
|
|
847
821
|
write(&overlay, "pipe", b"upper"),
|
|
848
822
|
overlay.rename("pipe", &overlay, "moved")
|
|
849
823
|
),
|
|
850
|
-
(
|
|
851
|
-
Err(FilesystemError::PermissionDenied),
|
|
852
|
-
Err(FilesystemError::CrossesDevices)
|
|
853
|
-
),
|
|
824
|
+
(Err(Errno::PermissionDenied), Err(Errno::CrossesDevices)),
|
|
854
825
|
"a FIFO a read-only Bind Layer holds, written or renamed through an Overlay, must \
|
|
855
826
|
be refused as permission denied and as crossing devices"
|
|
856
827
|
);
|
|
@@ -882,8 +853,8 @@ mod tests {
|
|
|
882
853
|
file_type("made"),
|
|
883
854
|
),
|
|
884
855
|
(
|
|
885
|
-
Err(
|
|
886
|
-
Err(
|
|
856
|
+
Err(Errno::IsADirectory),
|
|
857
|
+
Err(Errno::NotADirectory),
|
|
887
858
|
Ok(FileType::Fifo),
|
|
888
859
|
Ok(FileType::Dir)
|
|
889
860
|
),
|
|
@@ -897,21 +868,21 @@ mod tests {
|
|
|
897
868
|
struct KeepsTimes(Arc<AtomicUsize>);
|
|
898
869
|
|
|
899
870
|
impl FileSystemType for KeepsTimes {
|
|
900
|
-
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(),
|
|
871
|
+
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
|
|
901
872
|
sb.d_make_root(Inode::new(&Kstat::new(FileType::Dir, 0), self));
|
|
902
873
|
Ok(())
|
|
903
874
|
}
|
|
904
875
|
}
|
|
905
876
|
|
|
906
877
|
impl InodeOperations for KeepsTimes {
|
|
907
|
-
fn getattr(&self, dentry: &Dentry) -> Result<Kstat,
|
|
878
|
+
fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
908
879
|
Ok(match dentry.name().as_str() {
|
|
909
880
|
"file" => Kstat::new(FileType::RegFile, 0).with_identity(1, 2),
|
|
910
881
|
_ => Kstat::new(FileType::Dir, 0).with_identity(1, 1),
|
|
911
882
|
})
|
|
912
883
|
}
|
|
913
884
|
|
|
914
|
-
fn lookup(&self, dentry: &Dentry) -> Result<Lookup,
|
|
885
|
+
fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
|
|
915
886
|
Ok(match dentry.name().as_str() {
|
|
916
887
|
"file" => Lookup::Found(Inode::new(
|
|
917
888
|
&Kstat::new(FileType::RegFile, 0).with_identity(1, 2),
|
|
@@ -921,23 +892,19 @@ mod tests {
|
|
|
921
892
|
})
|
|
922
893
|
}
|
|
923
894
|
|
|
924
|
-
fn setattr(&self, _dentry: &Dentry, _attr: &Iattr) -> Result<(),
|
|
895
|
+
fn setattr(&self, _dentry: &Dentry, _attr: &Iattr) -> Result<(), Errno> {
|
|
925
896
|
self.0.fetch_add(1, Ordering::SeqCst);
|
|
926
897
|
Ok(())
|
|
927
898
|
}
|
|
928
899
|
|
|
929
|
-
fn open(
|
|
930
|
-
&self,
|
|
931
|
-
_dentry: &Dentry,
|
|
932
|
-
_how: &OpenHow,
|
|
933
|
-
) -> Result<Box<dyn FileOperations>, FilesystemError> {
|
|
900
|
+
fn open(&self, _dentry: &Dentry, _how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
|
|
934
901
|
struct Empty;
|
|
935
902
|
impl FileOperations for Empty {
|
|
936
903
|
fn read_iter(
|
|
937
904
|
&mut self,
|
|
938
905
|
_iocb: &mut Kiocb,
|
|
939
906
|
_buf: &mut [u8],
|
|
940
|
-
) -> Result<usize,
|
|
907
|
+
) -> Result<usize, Errno> {
|
|
941
908
|
Ok(0)
|
|
942
909
|
}
|
|
943
910
|
}
|
|
@@ -952,14 +919,13 @@ mod tests {
|
|
|
952
919
|
let asked = Arc::new(AtomicUsize::new(0));
|
|
953
920
|
let upper = Arc::new(Tmpfs::new());
|
|
954
921
|
let overlay = Overlay::new(
|
|
955
|
-
vec![Filesystem::new(
|
|
956
|
-
.expect("the instance must stand")],
|
|
922
|
+
vec![Filesystem::new(KeepsTimes(asked.clone())).expect("the instance must stand")],
|
|
957
923
|
Some(Filesystem::new(upper.clone()).expect("the instance must stand")),
|
|
958
924
|
)
|
|
959
925
|
.unwrap_or_else(|_| panic!("the Overlay must make"));
|
|
960
926
|
let mount = crate::mount::Mount::new(
|
|
961
927
|
"/data",
|
|
962
|
-
Filesystem::new(
|
|
928
|
+
Filesystem::new(overlay).expect("the instance must stand"),
|
|
963
929
|
crate::mount::Access::ReadWrite,
|
|
964
930
|
)
|
|
965
931
|
.expect("/data is a guest path");
|
|
@@ -968,7 +934,7 @@ mod tests {
|
|
|
968
934
|
&crate::vfs::Path::root(mount.mnt()),
|
|
969
935
|
"file",
|
|
970
936
|
false,
|
|
971
|
-
&Iattr::
|
|
937
|
+
&Iattr::for_times(None, Some(crate::filesystem::SetTime::Now)),
|
|
972
938
|
);
|
|
973
939
|
assert_eq!(
|
|
974
940
|
(
|
|
@@ -990,8 +956,11 @@ mod tests {
|
|
|
990
956
|
let deep = vec!["a"; 1500].join("/");
|
|
991
957
|
let lower: Tmpfs = [(format!("{deep}/file"), "x")].into_iter().collect();
|
|
992
958
|
let overlay = Overlay::new(
|
|
993
|
-
vec![Filesystem::new(
|
|
994
|
-
Some(
|
|
959
|
+
vec![Filesystem::new(lower).expect("the instance must stand")],
|
|
960
|
+
Some(
|
|
961
|
+
Filesystem::new(Tmpfs::new().with_nr_inodes(None))
|
|
962
|
+
.expect("the instance must stand"),
|
|
963
|
+
),
|
|
995
964
|
)
|
|
996
965
|
.unwrap_or_else(|_| panic!("the Overlay must make"));
|
|
997
966
|
let made = std::thread::Builder::new()
|
|
@@ -1015,7 +984,6 @@ mod tests {
|
|
|
1015
984
|
|
|
1016
985
|
// The upper is a Tmpfs, which holds no link, so a link cannot land there.
|
|
1017
986
|
// @behavior FS-051
|
|
1018
|
-
#[cfg(unix)]
|
|
1019
987
|
#[test]
|
|
1020
988
|
fn an_overlay_refuses_to_move_a_link_its_read_only_layer_holds() {
|
|
1021
989
|
let host = LinkTree::new("through");
|
|
@@ -1025,7 +993,7 @@ mod tests {
|
|
|
1025
993
|
overlay.rename("link", &overlay, "moved"),
|
|
1026
994
|
read(&overlay, "target")
|
|
1027
995
|
),
|
|
1028
|
-
(Err(
|
|
996
|
+
(Err(Errno::CrossesDevices), b"lower".to_vec()),
|
|
1029
997
|
"a rename of a link a read-only Bind Layer holds, through an Overlay, must be refused \
|
|
1030
998
|
as crossing devices and leave the target as it was"
|
|
1031
999
|
);
|
|
@@ -1034,7 +1002,6 @@ mod tests {
|
|
|
1034
1002
|
// The lower Tmpfs holds a readable `dangling`, so only the upper
|
|
1035
1003
|
// link standing at that path can keep the read from reaching it.
|
|
1036
1004
|
// @behavior FS-053
|
|
1037
|
-
#[cfg(unix)]
|
|
1038
1005
|
#[test]
|
|
1039
1006
|
fn a_link_a_layer_holds_hides_what_the_layers_below_hold_there() {
|
|
1040
1007
|
let host = LinkTree::new("shadow");
|
|
@@ -1052,7 +1019,7 @@ mod tests {
|
|
|
1052
1019
|
}
|
|
1053
1020
|
)
|
|
1054
1021
|
.map(drop),
|
|
1055
|
-
Err(
|
|
1022
|
+
Err(Errno::FilesystemLoop),
|
|
1056
1023
|
"a lower file beneath a dangling link a higher Bind Layer holds at its path, \
|
|
1057
1024
|
opened through Overlay::open, must be refused as the link, the file unreached"
|
|
1058
1025
|
);
|
|
@@ -1061,7 +1028,6 @@ mod tests {
|
|
|
1061
1028
|
// The lower Tmpfs holds `dirlink/x` beside where the upper link points,
|
|
1062
1029
|
// so only the link hiding everything beneath it keeps `x` out.
|
|
1063
1030
|
// @behavior FS-057
|
|
1064
|
-
#[cfg(unix)]
|
|
1065
1031
|
#[test]
|
|
1066
1032
|
fn a_link_a_layer_holds_hides_what_the_layers_below_hold_beneath_it() {
|
|
1067
1033
|
let host = LinkTree::new("shadow-beneath");
|
|
@@ -1076,7 +1042,7 @@ mod tests {
|
|
|
1076
1042
|
.map(|metadata| metadata.file_type),
|
|
1077
1043
|
overlay.open_dir("dirlink").map(drop)
|
|
1078
1044
|
),
|
|
1079
|
-
(Ok(FileType::Symlink), Err(
|
|
1045
|
+
(Ok(FileType::Symlink), Err(Errno::FilesystemLoop)),
|
|
1080
1046
|
"a directory a higher Bind Layer holds as a link, looked up and opened through an \
|
|
1081
1047
|
Overlay, must stand as the link, so none of a lower Layer's entries beneath it show"
|
|
1082
1048
|
);
|
|
@@ -1096,7 +1062,7 @@ mod tests {
|
|
|
1096
1062
|
overlay.vfs_lstat("f").err(),
|
|
1097
1063
|
on(&lower).vfs_lstat("f/g").is_ok()
|
|
1098
1064
|
),
|
|
1099
|
-
(Ok(()), Some(
|
|
1065
|
+
(Ok(()), Some(Errno::NotFound), true),
|
|
1100
1066
|
"a file a higher Layer holds over a lower Layer's directory, removed through \
|
|
1101
1067
|
vfs_unlink, must leave the path gone from the view and the lower \
|
|
1102
1068
|
directory as it was"
|
|
@@ -1150,7 +1116,7 @@ mod tests {
|
|
|
1150
1116
|
.and_then(|dir| dir.iterate_dir())
|
|
1151
1117
|
.map(|entries| entries.len())
|
|
1152
1118
|
),
|
|
1153
|
-
(Ok(()), Some(
|
|
1119
|
+
(Ok(()), Some(Errno::NotFound), Ok(0)),
|
|
1154
1120
|
"a directory made again through an Overlay where a lower Layer's one was removed, \
|
|
1155
1121
|
renamed through Overlay::rename, must move and leave nothing of the lower one behind"
|
|
1156
1122
|
);
|
|
@@ -1162,7 +1128,7 @@ mod tests {
|
|
|
1162
1128
|
let (overlay, _) = overlay_on(Arc::new(Tmpfs::new()));
|
|
1163
1129
|
assert_eq!(
|
|
1164
1130
|
overlay.rename("dir/file", &overlay, "dir/file/x"),
|
|
1165
|
-
Err(
|
|
1131
|
+
Err(Errno::NotADirectory),
|
|
1166
1132
|
"a file renamed through Overlay::rename to a path beneath itself must be refused as \
|
|
1167
1133
|
no directory, as rename(2) refuses it"
|
|
1168
1134
|
);
|
|
@@ -1171,7 +1137,6 @@ mod tests {
|
|
|
1171
1137
|
// The link points at nothing, so only the link itself can be what an
|
|
1172
1138
|
// exclusive create or a new directory finds there.
|
|
1173
1139
|
// @behavior FS-052
|
|
1174
|
-
#[cfg(unix)]
|
|
1175
1140
|
#[test]
|
|
1176
1141
|
fn an_overlay_finds_a_dangling_link_where_a_new_entry_would_go() {
|
|
1177
1142
|
let host = LinkTree::new("dangling");
|
|
@@ -1185,10 +1150,7 @@ mod tests {
|
|
|
1185
1150
|
overlay.create("dangling", &exclusive).map(drop),
|
|
1186
1151
|
overlay.vfs_mkdir("dangling")
|
|
1187
1152
|
),
|
|
1188
|
-
(
|
|
1189
|
-
Err(FilesystemError::AlreadyExists),
|
|
1190
|
-
Err(FilesystemError::AlreadyExists)
|
|
1191
|
-
),
|
|
1153
|
+
(Err(Errno::AlreadyExists), Err(Errno::AlreadyExists)),
|
|
1192
1154
|
"an exclusive create and a create_dir at a dangling link a lower Bind Layer \
|
|
1193
1155
|
holds, through an Overlay, must find it already there"
|
|
1194
1156
|
);
|
|
@@ -1242,7 +1204,7 @@ mod tests {
|
|
|
1242
1204
|
.expect("the file must be removed");
|
|
1243
1205
|
assert_eq!(
|
|
1244
1206
|
overlay.vfs_lstat("dir/file"),
|
|
1245
|
-
Err(
|
|
1207
|
+
Err(Errno::NotFound),
|
|
1246
1208
|
"a lower file removed through vfs_unlink must no longer be found there"
|
|
1247
1209
|
);
|
|
1248
1210
|
}
|
|
@@ -1283,7 +1245,7 @@ mod tests {
|
|
|
1283
1245
|
overwrite(&overlay, "new", b"made");
|
|
1284
1246
|
assert_eq!(
|
|
1285
1247
|
(read(&on(&upper), "upper/new"), on(&lower).vfs_lstat("new")),
|
|
1286
|
-
(b"made".to_vec(), Err(
|
|
1248
|
+
(b"made".to_vec(), Err(Errno::NotFound)),
|
|
1287
1249
|
"a file created through Overlay::open must land in the upper alone"
|
|
1288
1250
|
);
|
|
1289
1251
|
}
|
|
@@ -1316,7 +1278,7 @@ mod tests {
|
|
|
1316
1278
|
let lower = Arc::new([("dir/old", "x")].into_iter().collect::<Tmpfs>());
|
|
1317
1279
|
let overlay = Arc::new(over(lower.clone(), Arc::new(Tmpfs::new())));
|
|
1318
1280
|
let filesystem = Filesystem::new(overlay.clone()).expect("the instance must stand");
|
|
1319
|
-
let root = filesystem.
|
|
1281
|
+
let root = filesystem.root().expect(crate::vfs::MADE_ROOT).clone();
|
|
1320
1282
|
let dir = lookup_one_unlocked(&Default::default(), &filesystem, &root, "dir")
|
|
1321
1283
|
.expect("the directory must be found");
|
|
1322
1284
|
let layer = on(&lower);
|
|
@@ -1356,7 +1318,7 @@ mod tests {
|
|
|
1356
1318
|
let lower = Arc::new([("dir/file", "x")].into_iter().collect::<Tmpfs>());
|
|
1357
1319
|
let overlay = Arc::new(over(lower, Arc::new(Tmpfs::new())));
|
|
1358
1320
|
let filesystem = Filesystem::new(overlay.clone()).expect("the instance must stand");
|
|
1359
|
-
let root = filesystem.
|
|
1321
|
+
let root = filesystem.root().expect(crate::vfs::MADE_ROOT).clone();
|
|
1360
1322
|
let dir = lookup_one_unlocked(&Default::default(), &filesystem, &root, "dir")
|
|
1361
1323
|
.expect("the directory must be found");
|
|
1362
1324
|
let file = lookup_one_unlocked(&Default::default(), &filesystem, &dir, "file")
|
|
@@ -1398,7 +1360,7 @@ mod tests {
|
|
|
1398
1360
|
let rebuilt = at(over(lower, upper));
|
|
1399
1361
|
assert_eq!(
|
|
1400
1362
|
rebuilt.vfs_lstat("dir/file"),
|
|
1401
|
-
Err(
|
|
1363
|
+
Err(Errno::NotFound),
|
|
1402
1364
|
"a lower file removed through an Overlay over a Tmpfs must stay gone from a new Overlay over the same Layers"
|
|
1403
1365
|
);
|
|
1404
1366
|
}
|
|
@@ -1460,7 +1422,7 @@ mod tests {
|
|
|
1460
1422
|
});
|
|
1461
1423
|
assert_ne!(
|
|
1462
1424
|
answered,
|
|
1463
|
-
Some(
|
|
1425
|
+
Some(Errno::Interrupted),
|
|
1464
1426
|
"vfs::filename_renameat2 through an Overlay whose upper another Mount changed must \
|
|
1465
1427
|
answer within its bound"
|
|
1466
1428
|
);
|
|
@@ -1507,7 +1469,7 @@ mod tests {
|
|
|
1507
1469
|
let overlay = lowers(tmpfs_with("dir/file", "lower"), Arc::new(Tmpfs::new()));
|
|
1508
1470
|
let mount = crate::mount::Mount::new(
|
|
1509
1471
|
"/data",
|
|
1510
|
-
Filesystem::new(
|
|
1472
|
+
Filesystem::new(overlay).expect("the instance must stand"),
|
|
1511
1473
|
crate::mount::Access::ReadWrite,
|
|
1512
1474
|
)
|
|
1513
1475
|
.expect("/data is a guest path");
|
|
@@ -1526,7 +1488,7 @@ mod tests {
|
|
|
1526
1488
|
let written = crate::vfs::kern_path::filp_open(&Arc::default(), &root, "dir/file", &how);
|
|
1527
1489
|
assert_eq!(
|
|
1528
1490
|
(written.err(), mount.mnt().is_readonly()),
|
|
1529
|
-
(Some(
|
|
1491
|
+
(Some(Errno::ReadOnlyFilesystem), true),
|
|
1530
1492
|
"a file opened to write through an Overlay with no upper on a read-write Mount must \
|
|
1531
1493
|
be refused as read-only"
|
|
1532
1494
|
);
|
|
@@ -1537,13 +1499,9 @@ mod tests {
|
|
|
1537
1499
|
struct RefusesLongName;
|
|
1538
1500
|
|
|
1539
1501
|
impl crate::filesystem::wrap::Hook for RefusesLongName {
|
|
1540
|
-
fn lookup(
|
|
1541
|
-
&self,
|
|
1542
|
-
inner: &dyn InodeOperations,
|
|
1543
|
-
dentry: &Dentry,
|
|
1544
|
-
) -> Result<Lookup, FilesystemError> {
|
|
1502
|
+
fn lookup(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<Lookup, Errno> {
|
|
1545
1503
|
match dentry.name().as_str() {
|
|
1546
|
-
"long" => Err(
|
|
1504
|
+
"long" => Err(Errno::InvalidFilename),
|
|
1547
1505
|
_ => inner.lookup(dentry),
|
|
1548
1506
|
}
|
|
1549
1507
|
}
|
|
@@ -1616,7 +1574,6 @@ mod tests {
|
|
|
1616
1574
|
// Bind reports the same identity for both names, so without the view keeping
|
|
1617
1575
|
// them apart the VFS would answer the move as having nothing to do.
|
|
1618
1576
|
// @behavior FS-170
|
|
1619
|
-
#[cfg(unix)]
|
|
1620
1577
|
#[test]
|
|
1621
1578
|
fn a_lower_layers_hard_link_moves_onto_the_other_as_two_entries() {
|
|
1622
1579
|
let host = LinkTree::new("hard-link");
|
|
@@ -1633,11 +1590,7 @@ mod tests {
|
|
|
1633
1590
|
read(&overlay, "b"),
|
|
1634
1591
|
std::fs::read(host.0.join("b")).expect("the host file must be read"),
|
|
1635
1592
|
),
|
|
1636
|
-
(
|
|
1637
|
-
Err(FilesystemError::NotFound),
|
|
1638
|
-
b"two".to_vec(),
|
|
1639
|
-
b"one".to_vec()
|
|
1640
|
-
),
|
|
1593
|
+
(Err(Errno::NotFound), b"two".to_vec(), b"one".to_vec()),
|
|
1641
1594
|
"a hard link in a lower Layer written and moved onto its other name through an \
|
|
1642
1595
|
Overlay must leave only the new name, holding what was written, and the lower Layer \
|
|
1643
1596
|
as it was"
|
|
@@ -1652,7 +1605,7 @@ mod tests {
|
|
|
1652
1605
|
use crate::vfs::{filename_renameat2, filename_rmdir, filename_unlinkat};
|
|
1653
1606
|
let (_mount, root) = mounted_with_no_upper();
|
|
1654
1607
|
let cred = Arc::default();
|
|
1655
|
-
let read_only = || Err(
|
|
1608
|
+
let read_only = || Err(Errno::ReadOnlyFilesystem);
|
|
1656
1609
|
assert_eq!(
|
|
1657
1610
|
(
|
|
1658
1611
|
filename_renameat2(&cred, &root, "dir/file", &root, "dir/file"),
|
|
@@ -1669,7 +1622,7 @@ mod tests {
|
|
|
1669
1622
|
fn refusal(
|
|
1670
1623
|
lower: Vec<Arc<dyn FileSystemType>>,
|
|
1671
1624
|
upper: Option<Arc<dyn FileSystemType>>,
|
|
1672
|
-
) -> Option<
|
|
1625
|
+
) -> Option<Errno> {
|
|
1673
1626
|
let instance = |fs| Filesystem::new(fs).expect("the instance must stand");
|
|
1674
1627
|
Overlay::new(
|
|
1675
1628
|
lower.into_iter().map(instance).collect(),
|
|
@@ -1687,7 +1640,7 @@ mod tests {
|
|
|
1687
1640
|
let bind = super::super::Bind::new(&host).expect("the host directory must open");
|
|
1688
1641
|
assert_eq!(
|
|
1689
1642
|
refusal(vec![Arc::new(Tmpfs::new())], Some(Arc::new(bind))),
|
|
1690
|
-
Some(
|
|
1643
|
+
Some(Errno::InvalidInput),
|
|
1691
1644
|
"Overlay::new with a Bind as its upper must be refused as invalid input"
|
|
1692
1645
|
);
|
|
1693
1646
|
}
|
|
@@ -1697,17 +1650,14 @@ mod tests {
|
|
|
1697
1650
|
// @behavior FS-148
|
|
1698
1651
|
#[test]
|
|
1699
1652
|
fn an_overlay_refuses_one_instance_as_two_layers() {
|
|
1700
|
-
let instance = || Filesystem::new(
|
|
1653
|
+
let instance = || Filesystem::new(Tmpfs::new()).expect("the instance must stand");
|
|
1701
1654
|
let (shared, doubled) = (instance(), instance());
|
|
1702
1655
|
assert_eq!(
|
|
1703
1656
|
(
|
|
1704
1657
|
Overlay::new(vec![shared.clone()], Some(shared)).err(),
|
|
1705
1658
|
Overlay::new(vec![doubled.clone(), doubled, instance()], None).err(),
|
|
1706
1659
|
),
|
|
1707
|
-
(
|
|
1708
|
-
Some(FilesystemError::InvalidInput),
|
|
1709
|
-
Some(FilesystemError::InvalidInput),
|
|
1710
|
-
),
|
|
1660
|
+
(Some(Errno::InvalidInput), Some(Errno::InvalidInput),),
|
|
1711
1661
|
"Overlay::new with one instance as its upper and a lower Layer, or as two lower \
|
|
1712
1662
|
Layers, must be refused as invalid input"
|
|
1713
1663
|
);
|
|
@@ -1718,7 +1668,7 @@ mod tests {
|
|
|
1718
1668
|
fn an_overlay_without_an_upper_needs_two_lower_layers() {
|
|
1719
1669
|
assert_eq!(
|
|
1720
1670
|
refusal(vec![Arc::new(Tmpfs::new())], None),
|
|
1721
|
-
Some(
|
|
1671
|
+
Some(Errno::InvalidInput),
|
|
1722
1672
|
"Overlay::new with one lower Layer and no upper must be refused as invalid input"
|
|
1723
1673
|
);
|
|
1724
1674
|
}
|
|
@@ -1735,7 +1685,7 @@ mod tests {
|
|
|
1735
1685
|
refusal(vec![first], Some(Arc::new(Tmpfs::new()))),
|
|
1736
1686
|
refusal(vec![second], Some(Arc::new(Tmpfs::new())))
|
|
1737
1687
|
),
|
|
1738
|
-
(None, Some(
|
|
1688
|
+
(None, Some(Errno::InvalidInput)),
|
|
1739
1689
|
"Overlay::new over an Overlay must make a view, and over an Overlay over an Overlay \
|
|
1740
1690
|
must be refused as invalid input"
|
|
1741
1691
|
);
|
|
@@ -1751,7 +1701,7 @@ mod tests {
|
|
|
1751
1701
|
};
|
|
1752
1702
|
assert_eq!(
|
|
1753
1703
|
(refusal(layers(500), None), refusal(layers(501), None)),
|
|
1754
|
-
(None, Some(
|
|
1704
|
+
(None, Some(Errno::InvalidInput)),
|
|
1755
1705
|
"Overlay::new must take 500 lower Layers and refuse 501 as invalid input"
|
|
1756
1706
|
);
|
|
1757
1707
|
}
|
|
@@ -1761,7 +1711,7 @@ mod tests {
|
|
|
1761
1711
|
fn an_overlay_needs_a_lower_layer() {
|
|
1762
1712
|
assert_eq!(
|
|
1763
1713
|
refusal(Vec::new(), Some(Arc::new(Tmpfs::new()))),
|
|
1764
|
-
Some(
|
|
1714
|
+
Some(Errno::InvalidInput),
|
|
1765
1715
|
"Overlay::new with an upper and no lower Layer must be refused as invalid input"
|
|
1766
1716
|
);
|
|
1767
1717
|
}
|
|
@@ -1786,17 +1736,13 @@ mod tests {
|
|
|
1786
1736
|
overlay.vfs_lstat("dir/file"),
|
|
1787
1737
|
read(&on(&lower), "dir/file"),
|
|
1788
1738
|
),
|
|
1789
|
-
(
|
|
1790
|
-
b"lower".to_vec(),
|
|
1791
|
-
Err(FilesystemError::NotFound),
|
|
1792
|
-
b"lower".to_vec()
|
|
1793
|
-
),
|
|
1739
|
+
(b"lower".to_vec(), Err(Errno::NotFound), b"lower".to_vec()),
|
|
1794
1740
|
);
|
|
1795
1741
|
}
|
|
1796
1742
|
|
|
1797
1743
|
/// Another call through the VFS at `overlay`, started once on a thread
|
|
1798
|
-
/// of its own and
|
|
1799
|
-
/// before the call starting it went on.
|
|
1744
|
+
/// of its own and held for until it waits or finishes, recording whether
|
|
1745
|
+
/// it finished before the call starting it went on.
|
|
1800
1746
|
#[derive(Default)]
|
|
1801
1747
|
struct Interleave {
|
|
1802
1748
|
overlay: Mutex<Option<crate::vfs::Path>>,
|
|
@@ -1811,7 +1757,11 @@ mod tests {
|
|
|
1811
1757
|
};
|
|
1812
1758
|
let finished = Arc::new(AtomicUsize::new(0));
|
|
1813
1759
|
let marker = finished.clone();
|
|
1760
|
+
let (counted, counts) = std::sync::mpsc::channel();
|
|
1814
1761
|
let handle = thread::spawn(move || {
|
|
1762
|
+
counted
|
|
1763
|
+
.send(crate::sched::testing::count_waits())
|
|
1764
|
+
.expect("the call starting it takes the count");
|
|
1815
1765
|
let how = crate::vfs::OpenHow {
|
|
1816
1766
|
write: true,
|
|
1817
1767
|
create: true,
|
|
@@ -1821,10 +1771,10 @@ mod tests {
|
|
|
1821
1771
|
crate::vfs::kern_path::filp_open(&Arc::default(), &overlay, "dir/new", &how);
|
|
1822
1772
|
marker.store(1, Ordering::SeqCst);
|
|
1823
1773
|
});
|
|
1824
|
-
let
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
}
|
|
1774
|
+
let waits = counts.recv().expect("the other call counts its waits");
|
|
1775
|
+
crate::sched::testing::wait_until("the other call waiting or finishing", || {
|
|
1776
|
+
waits.load(Ordering::SeqCst) > 0 || finished.load(Ordering::SeqCst) == 1
|
|
1777
|
+
});
|
|
1828
1778
|
*self.finished_inside.lock().unwrap() = Some(finished.load(Ordering::SeqCst) == 1);
|
|
1829
1779
|
*self.other.lock().unwrap() = Some(handle);
|
|
1830
1780
|
}
|
|
@@ -1838,8 +1788,8 @@ mod tests {
|
|
|
1838
1788
|
inner: &dyn InodeOperations,
|
|
1839
1789
|
dentry: &Dentry,
|
|
1840
1790
|
how: &OpenHow,
|
|
1841
|
-
) -> Result<Box<dyn FileOperations>,
|
|
1842
|
-
if dentry.
|
|
1791
|
+
) -> Result<Box<dyn FileOperations>, Errno> {
|
|
1792
|
+
if dentry.file_type() == Ok(FileType::Dir) && !dentry.is_root() {
|
|
1843
1793
|
self.start();
|
|
1844
1794
|
}
|
|
1845
1795
|
inner.open(dentry, how)
|
|
@@ -1859,10 +1809,10 @@ mod tests {
|
|
|
1859
1809
|
.expect("the seed must go");
|
|
1860
1810
|
let mount = crate::mount::Mount::new(
|
|
1861
1811
|
"/data",
|
|
1862
|
-
Filesystem::new(
|
|
1812
|
+
Filesystem::new(over(
|
|
1863
1813
|
Arc::new(Wrap::new(tmpfs, interleave.clone())),
|
|
1864
1814
|
Arc::new(Tmpfs::new()),
|
|
1865
|
-
))
|
|
1815
|
+
))
|
|
1866
1816
|
.expect("the instance must stand"),
|
|
1867
1817
|
crate::mount::Access::ReadWrite,
|
|
1868
1818
|
)
|
|
@@ -1892,7 +1842,7 @@ mod tests {
|
|
|
1892
1842
|
// @behavior FS-038
|
|
1893
1843
|
#[test]
|
|
1894
1844
|
fn a_change_through_an_overlay_from_inside_one_answers_a_deadlock() {
|
|
1895
|
-
type Answers = (bool, Result<(),
|
|
1845
|
+
type Answers = (bool, Result<(), Errno>);
|
|
1896
1846
|
|
|
1897
1847
|
struct Reenters {
|
|
1898
1848
|
overlay: Mutex<Option<crate::vfs::Path>>,
|
|
@@ -1904,7 +1854,7 @@ mod tests {
|
|
|
1904
1854
|
&self,
|
|
1905
1855
|
inner: &dyn InodeOperations,
|
|
1906
1856
|
dentry: &Dentry,
|
|
1907
|
-
) -> Result<Kstat,
|
|
1857
|
+
) -> Result<Kstat, Errno> {
|
|
1908
1858
|
let reentering = self.overlay.lock().unwrap().take();
|
|
1909
1859
|
if let Some(overlay) = reentering {
|
|
1910
1860
|
*self.answer.lock().unwrap() = Some((
|
|
@@ -1924,10 +1874,10 @@ mod tests {
|
|
|
1924
1874
|
let tmpfs: Tmpfs = [("note", "x")].into_iter().collect();
|
|
1925
1875
|
let mount = crate::mount::Mount::new(
|
|
1926
1876
|
"/data",
|
|
1927
|
-
Filesystem::new(
|
|
1877
|
+
Filesystem::new(over(
|
|
1928
1878
|
Arc::new(Wrap::new(Arc::new(tmpfs), layer.clone())),
|
|
1929
1879
|
Arc::new(Tmpfs::new()),
|
|
1930
|
-
))
|
|
1880
|
+
))
|
|
1931
1881
|
.expect("the instance must stand"),
|
|
1932
1882
|
crate::mount::Access::ReadWrite,
|
|
1933
1883
|
)
|
|
@@ -1939,7 +1889,7 @@ mod tests {
|
|
|
1939
1889
|
let answers = layer.answer.lock().unwrap().take();
|
|
1940
1890
|
assert_eq!(
|
|
1941
1891
|
answers,
|
|
1942
|
-
Some((true, Err(
|
|
1892
|
+
Some((true, Err(Errno::Deadlock))),
|
|
1943
1893
|
"a read through an Overlay made from inside one of its own reads on the same thread \
|
|
1944
1894
|
must answer, and a change must answer Deadlock rather than wait forever"
|
|
1945
1895
|
);
|
|
@@ -1968,7 +1918,7 @@ mod tests {
|
|
|
1968
1918
|
let (overlay, _) = full_over_lower(&[("dir/file", "upper")], 2);
|
|
1969
1919
|
assert_eq!(
|
|
1970
1920
|
(overlay.vfs_unlink("dir/file"), read(&overlay, "dir/file")),
|
|
1971
|
-
(Err(
|
|
1921
|
+
(Err(Errno::StorageFull), b"upper".to_vec()),
|
|
1972
1922
|
"a file removed through vfs_unlink whose whiteout finds no room must stay as \
|
|
1973
1923
|
it was"
|
|
1974
1924
|
);
|
|
@@ -1990,10 +1940,7 @@ mod tests {
|
|
|
1990
1940
|
.expect("the directory must be removed");
|
|
1991
1941
|
assert_eq!(
|
|
1992
1942
|
(overlay.vfs_mkdir("gone"), overlay.vfs_lstat("gone")),
|
|
1993
|
-
(
|
|
1994
|
-
Err(FilesystemError::StorageFull),
|
|
1995
|
-
Err(FilesystemError::NotFound)
|
|
1996
|
-
),
|
|
1943
|
+
(Err(Errno::StorageFull), Err(Errno::NotFound)),
|
|
1997
1944
|
"a directory made through vfs_mkdir over a whiteout, with no room left, \
|
|
1998
1945
|
must be refused as out of space and leave the name hidden"
|
|
1999
1946
|
);
|
|
@@ -2012,8 +1959,8 @@ mod tests {
|
|
|
2012
1959
|
read(&overlay, "dir/file")
|
|
2013
1960
|
),
|
|
2014
1961
|
(
|
|
2015
|
-
Err(
|
|
2016
|
-
Err(
|
|
1962
|
+
Err(Errno::StorageFull),
|
|
1963
|
+
Err(Errno::NotFound),
|
|
2017
1964
|
b"lower".to_vec()
|
|
2018
1965
|
),
|
|
2019
1966
|
"a file renamed through Overlay::rename whose whiteout finds no room must stay where \
|
|
@@ -2030,10 +1977,7 @@ mod tests {
|
|
|
2030
1977
|
overlay.rename("dir", &overlay, "moved"),
|
|
2031
1978
|
overlay.vfs_lstat("moved")
|
|
2032
1979
|
),
|
|
2033
|
-
(
|
|
2034
|
-
Err(FilesystemError::CrossesDevices),
|
|
2035
|
-
Err(FilesystemError::NotFound)
|
|
2036
|
-
),
|
|
1980
|
+
(Err(Errno::CrossesDevices), Err(Errno::NotFound)),
|
|
2037
1981
|
"a directory a lower Layer holds renamed through Overlay::rename must be refused \
|
|
2038
1982
|
as crossing devices, as overlayfs refuses it"
|
|
2039
1983
|
);
|
|
@@ -2057,8 +2001,8 @@ mod tests {
|
|
|
2057
2001
|
read(&overlay, "dir/file")
|
|
2058
2002
|
),
|
|
2059
2003
|
(
|
|
2060
|
-
Err(
|
|
2061
|
-
Err(
|
|
2004
|
+
Err(Errno::IsADirectory),
|
|
2005
|
+
Err(Errno::DirectoryNotEmpty),
|
|
2062
2006
|
b"lower".to_vec()
|
|
2063
2007
|
),
|
|
2064
2008
|
"a rename through Overlay::rename onto a directory only a lower Layer shows must \
|
|
@@ -2129,7 +2073,7 @@ mod tests {
|
|
|
2129
2073
|
.expect("the emptied directory must be removed");
|
|
2130
2074
|
assert_eq!(
|
|
2131
2075
|
(names(&on(&upper), "work"), kind(&overlay, "dir")),
|
|
2132
|
-
(Vec::<String>::new(), Err(
|
|
2076
|
+
(Vec::<String>::new(), Err(Errno::NotFound)),
|
|
2133
2077
|
"vfs_rmdir of a lower directory whose file vfs_unlink removed \
|
|
2134
2078
|
must leave the upper Tmpfs's work empty and the directory gone"
|
|
2135
2079
|
);
|
|
@@ -2141,10 +2085,10 @@ mod tests {
|
|
|
2141
2085
|
#[test]
|
|
2142
2086
|
fn a_copy_up_keeps_the_lower_files_times() {
|
|
2143
2087
|
let lower = tmpfs_with("dir/file", "lower");
|
|
2088
|
+
set_long_ago(&on(&lower), "dir/file");
|
|
2144
2089
|
let before = on(&lower)
|
|
2145
2090
|
.vfs_lstat("dir/file")
|
|
2146
2091
|
.expect("the lower file must stand");
|
|
2147
|
-
std::thread::sleep(Duration::from_millis(10));
|
|
2148
2092
|
let overlay = at(over(lower, Arc::new(Tmpfs::new())));
|
|
2149
2093
|
overlay
|
|
2150
2094
|
.open(
|
|
@@ -2171,11 +2115,11 @@ mod tests {
|
|
|
2171
2115
|
let lower: Arc<Tmpfs> = Arc::new([("dir/a", "a"), ("dir/b", "b")].into_iter().collect());
|
|
2172
2116
|
let overlay = at(over(lower, Arc::new(Tmpfs::new())));
|
|
2173
2117
|
overwrite(&overlay, "dir/a", b"changed");
|
|
2118
|
+
set_long_ago(&overlay, "dir");
|
|
2174
2119
|
let before = overlay
|
|
2175
2120
|
.vfs_lstat("dir")
|
|
2176
2121
|
.expect("the directory must stand")
|
|
2177
2122
|
.mtime;
|
|
2178
|
-
std::thread::sleep(Duration::from_millis(10));
|
|
2179
2123
|
overlay
|
|
2180
2124
|
.open(
|
|
2181
2125
|
"dir/b",
|
|
@@ -2196,9 +2140,9 @@ mod tests {
|
|
|
2196
2140
|
/// An Overlay over an empty lower Layer under the Tmpfs `upper`, and
|
|
2197
2141
|
/// that same Tmpfs mounted on its own, each reached through the VFS.
|
|
2198
2142
|
fn beside_its_upper(upper: Tmpfs) -> (crate::vfs::Path, crate::vfs::Path) {
|
|
2199
|
-
let upper = Filesystem::new(
|
|
2143
|
+
let upper = Filesystem::new(upper).expect("the instance must stand");
|
|
2200
2144
|
let overlay = Overlay::new(
|
|
2201
|
-
vec![Filesystem::new(
|
|
2145
|
+
vec![Filesystem::new(Tmpfs::new()).expect("the instance must stand")],
|
|
2202
2146
|
Some(upper.clone()),
|
|
2203
2147
|
)
|
|
2204
2148
|
.expect("an upper over a lower Layer must make a view");
|
|
@@ -2209,7 +2153,7 @@ mod tests {
|
|
|
2209
2153
|
crate::vfs::Path::root(mount.mnt())
|
|
2210
2154
|
};
|
|
2211
2155
|
(
|
|
2212
|
-
root(Filesystem::new(
|
|
2156
|
+
root(Filesystem::new(overlay).expect("the instance must stand")),
|
|
2213
2157
|
root(upper),
|
|
2214
2158
|
)
|
|
2215
2159
|
}
|
|
@@ -2259,46 +2203,6 @@ mod tests {
|
|
|
2259
2203
|
);
|
|
2260
2204
|
}
|
|
2261
2205
|
|
|
2262
|
-
// The make holds only the directory it makes in, so only the removal
|
|
2263
|
-
// holding that directory too, and removing it only once empty, keeps
|
|
2264
|
-
// what the make made from going with it. The two land in the same
|
|
2265
|
-
// instant only a few times in this many tries.
|
|
2266
|
-
// @behavior FS-132
|
|
2267
|
-
#[test]
|
|
2268
|
-
fn a_removal_through_an_overlay_waits_for_a_change_in_that_directory() {
|
|
2269
|
-
let (overlay, upper) = beside_its_upper([("upper/a/.keep", "")].into_iter().collect());
|
|
2270
|
-
let stop = Arc::new(AtomicBool::new(false));
|
|
2271
|
-
let churning = {
|
|
2272
|
-
let stop = stop.clone();
|
|
2273
|
-
thread::spawn(move || {
|
|
2274
|
-
while !stop.load(Ordering::SeqCst) {
|
|
2275
|
-
let _ = crate::vfs::filename_mkdirat(&Arc::default(), &overlay, "a/b");
|
|
2276
|
-
let _ = crate::vfs::filename_rmdir(&Arc::default(), &overlay, "a/b");
|
|
2277
|
-
}
|
|
2278
|
-
})
|
|
2279
|
-
};
|
|
2280
|
-
let mut lost = 0;
|
|
2281
|
-
for _ in 0..100_000 {
|
|
2282
|
-
if crate::vfs::filename_mkdirat(&Arc::default(), &upper, "upper/a/b/made").is_ok() {
|
|
2283
|
-
match crate::vfs::vfs_fstatat(&Arc::default(), &upper, "upper/a/b/made", false) {
|
|
2284
|
-
Ok(_) => {
|
|
2285
|
-
let _ =
|
|
2286
|
-
crate::vfs::filename_rmdir(&Arc::default(), &upper, "upper/a/b/made");
|
|
2287
|
-
}
|
|
2288
|
-
Err(_) => lost += 1,
|
|
2289
|
-
}
|
|
2290
|
-
}
|
|
2291
|
-
}
|
|
2292
|
-
stop.store(true, Ordering::SeqCst);
|
|
2293
|
-
churning.join().expect("the Overlay's calls must not panic");
|
|
2294
|
-
assert_eq!(
|
|
2295
|
-
lost, 0,
|
|
2296
|
-
"vfs::filename_mkdirat in a directory through a Mount of an Overlay's upper Tmpfs, while \
|
|
2297
|
-
vfs::filename_rmdir removes that directory through the Overlay, must leave every \
|
|
2298
|
-
directory it made standing"
|
|
2299
|
-
);
|
|
2300
|
-
}
|
|
2301
|
-
|
|
2302
2206
|
// The upper has room for the copy's entry but for less than
|
|
2303
2207
|
// the lower file's bytes, so the copy fails part way.
|
|
2304
2208
|
// @behavior FS-046
|
|
@@ -2313,8 +2217,8 @@ mod tests {
|
|
|
2313
2217
|
read(&overlay, "dir/file")
|
|
2314
2218
|
),
|
|
2315
2219
|
(
|
|
2316
|
-
Err(
|
|
2317
|
-
Err(
|
|
2220
|
+
Err(Errno::StorageFull),
|
|
2221
|
+
Err(Errno::NotFound),
|
|
2318
2222
|
b"lower".to_vec()
|
|
2319
2223
|
),
|
|
2320
2224
|
"a write through Overlay::open whose copy up runs out of room must leave no partial \
|
|
@@ -2322,18 +2226,249 @@ mod tests {
|
|
|
2322
2226
|
);
|
|
2323
2227
|
}
|
|
2324
2228
|
|
|
2229
|
+
// The run's deadline has passed before the write asks, so the copy up
|
|
2230
|
+
// stops before its first chunk.
|
|
2231
|
+
// @behavior FS-213
|
|
2232
|
+
#[test]
|
|
2233
|
+
fn a_copy_up_past_its_runs_deadline_answers_eintr() {
|
|
2234
|
+
let upper = Arc::new(Tmpfs::new());
|
|
2235
|
+
let (overlay, _) = overlay_on(upper.clone());
|
|
2236
|
+
let written = crate::sched::run_task(Some(std::time::Instant::now()), || {
|
|
2237
|
+
write_over(&overlay, "dir/file", b"x")
|
|
2238
|
+
});
|
|
2239
|
+
assert_eq!(
|
|
2240
|
+
(
|
|
2241
|
+
written,
|
|
2242
|
+
on(&upper).vfs_lstat("upper/dir/file"),
|
|
2243
|
+
read(&overlay, "dir/file")
|
|
2244
|
+
),
|
|
2245
|
+
(
|
|
2246
|
+
Err(Errno::Interrupted),
|
|
2247
|
+
Err(Errno::NotFound),
|
|
2248
|
+
b"lower".to_vec()
|
|
2249
|
+
),
|
|
2250
|
+
"a write through Overlay::open whose run's deadline passed must answer EINTR before \
|
|
2251
|
+
copying, and leave the lower file showing"
|
|
2252
|
+
);
|
|
2253
|
+
}
|
|
2254
|
+
|
|
2255
|
+
/// A host directory holding `dir/a`, `dir/b`, and `dir/c`, removed when it
|
|
2256
|
+
/// drops.
|
|
2257
|
+
struct HostDir(std::path::PathBuf);
|
|
2258
|
+
|
|
2259
|
+
impl HostDir {
|
|
2260
|
+
fn new(name: &str) -> Self {
|
|
2261
|
+
let path =
|
|
2262
|
+
std::env::temp_dir().join(format!("kobako-overlay-{name}-{}", std::process::id()));
|
|
2263
|
+
let _ = std::fs::remove_dir_all(&path);
|
|
2264
|
+
std::fs::create_dir_all(path.join("dir")).expect("the host directory must be made");
|
|
2265
|
+
for file in ["a", "b", "c"] {
|
|
2266
|
+
std::fs::write(path.join("dir").join(file), "x").expect("the file must be made");
|
|
2267
|
+
}
|
|
2268
|
+
Self(path)
|
|
2269
|
+
}
|
|
2270
|
+
}
|
|
2271
|
+
|
|
2272
|
+
impl Drop for HostDir {
|
|
2273
|
+
fn drop(&mut self) {
|
|
2274
|
+
let _ = std::fs::remove_dir_all(&self.0);
|
|
2275
|
+
}
|
|
2276
|
+
}
|
|
2277
|
+
|
|
2278
|
+
/// `dir` of a `Tmpfs`, of a `Bind` of `host`, and of an `Overlay`, each holding
|
|
2279
|
+
/// `a`, `b`, and `c`, opened to list.
|
|
2280
|
+
fn listed_kinds(host: &HostDir) -> Vec<(&'static str, KernPath)> {
|
|
2281
|
+
let files = || -> Tmpfs {
|
|
2282
|
+
["dir/a", "dir/b", "dir/c"]
|
|
2283
|
+
.map(|path| (path, "x"))
|
|
2284
|
+
.into_iter()
|
|
2285
|
+
.collect()
|
|
2286
|
+
};
|
|
2287
|
+
let bind = super::super::Bind::new(&host.0).expect("the host directory must open");
|
|
2288
|
+
[
|
|
2289
|
+
("Tmpfs", at(files())),
|
|
2290
|
+
("Bind", at(bind)),
|
|
2291
|
+
(
|
|
2292
|
+
"Overlay",
|
|
2293
|
+
at(over(Arc::new(files()), Arc::new(Tmpfs::new()))),
|
|
2294
|
+
),
|
|
2295
|
+
]
|
|
2296
|
+
.map(|(kind, fs)| (kind, fs.open_dir("dir").expect("dir must open")))
|
|
2297
|
+
.into()
|
|
2298
|
+
}
|
|
2299
|
+
|
|
2300
|
+
// @behavior FS-232
|
|
2301
|
+
#[test]
|
|
2302
|
+
fn a_listing_past_its_runs_deadline_answers_eintr() {
|
|
2303
|
+
let host = HostDir::new("listing-deadline");
|
|
2304
|
+
let answers: Vec<_> = listed_kinds(&host)
|
|
2305
|
+
.iter()
|
|
2306
|
+
.map(|(kind, dir)| {
|
|
2307
|
+
let listed = crate::sched::run_task(Some(Instant::now()), || dir.iterate_dir());
|
|
2308
|
+
(*kind, listed.err())
|
|
2309
|
+
})
|
|
2310
|
+
.collect();
|
|
2311
|
+
assert_eq!(
|
|
2312
|
+
answers,
|
|
2313
|
+
["Tmpfs", "Bind", "Overlay"].map(|kind| (kind, Some(Errno::Interrupted))),
|
|
2314
|
+
"iterate_shared of each built-in Filesystem in a run past its deadline must answer \
|
|
2315
|
+
EINTR before its next entry"
|
|
2316
|
+
);
|
|
2317
|
+
}
|
|
2318
|
+
|
|
2319
|
+
// @behavior FS-233
|
|
2320
|
+
#[test]
|
|
2321
|
+
fn a_listing_hands_a_pending_signal_over_once() {
|
|
2322
|
+
let host = HostDir::new("listing-signal");
|
|
2323
|
+
let answers: Vec<_> = listed_kinds(&host)
|
|
2324
|
+
.iter()
|
|
2325
|
+
.map(|(kind, dir)| {
|
|
2326
|
+
let handled = crate::sched::testing::count_signals();
|
|
2327
|
+
let names = crate::sched::run_task(None, || {
|
|
2328
|
+
crate::sched::Task::current().signal();
|
|
2329
|
+
dir.iterate_dir()
|
|
2330
|
+
})
|
|
2331
|
+
.map(|entries| {
|
|
2332
|
+
let mut names: Vec<_> = entries.into_iter().map(|entry| entry.name).collect();
|
|
2333
|
+
names.sort();
|
|
2334
|
+
names
|
|
2335
|
+
});
|
|
2336
|
+
(*kind, handled.load(Ordering::SeqCst), names)
|
|
2337
|
+
})
|
|
2338
|
+
.collect();
|
|
2339
|
+
let all = || Ok(vec!["a".to_string(), "b".to_string(), "c".to_string()]);
|
|
2340
|
+
assert_eq!(
|
|
2341
|
+
answers,
|
|
2342
|
+
vec![
|
|
2343
|
+
("Tmpfs", 1, all()),
|
|
2344
|
+
("Bind", 1, all()),
|
|
2345
|
+
("Overlay", 1, all())
|
|
2346
|
+
],
|
|
2347
|
+
"iterate_shared of each built-in Filesystem with a signal pending must hand it to the \
|
|
2348
|
+
Blocking once and list every entry"
|
|
2349
|
+
);
|
|
2350
|
+
}
|
|
2351
|
+
|
|
2352
|
+
// @behavior FS-234
|
|
2353
|
+
#[test]
|
|
2354
|
+
fn a_copy_up_of_ancestors_past_its_runs_deadline_answers_eintr() {
|
|
2355
|
+
let upper = Arc::new(Tmpfs::new());
|
|
2356
|
+
let overlay = at(over(tmpfs_with("a/b/f", "lower"), upper.clone()));
|
|
2357
|
+
let made =
|
|
2358
|
+
crate::sched::run_task(Some(Instant::now()), || write(&overlay, "a/b/new", b"x"));
|
|
2359
|
+
assert_eq!(
|
|
2360
|
+
(made, on(&upper).vfs_lstat("upper/a").err()),
|
|
2361
|
+
(Err(Errno::Interrupted), Some(Errno::NotFound)),
|
|
2362
|
+
"a create through an Overlay whose run's deadline passed must answer EINTR before it \
|
|
2363
|
+
copies up the first ancestor, as ovl_copy_up_flags climbs them one at a time"
|
|
2364
|
+
);
|
|
2365
|
+
}
|
|
2366
|
+
|
|
2367
|
+
/// A layer whose files signal the run reading them as they hand over their
|
|
2368
|
+
/// first chunk.
|
|
2369
|
+
struct SignalsOnRead(Arc<AtomicUsize>);
|
|
2370
|
+
|
|
2371
|
+
impl Hook for SignalsOnRead {
|
|
2372
|
+
fn open(
|
|
2373
|
+
&self,
|
|
2374
|
+
inner: &dyn InodeOperations,
|
|
2375
|
+
dentry: &Dentry,
|
|
2376
|
+
how: &OpenHow,
|
|
2377
|
+
) -> Result<Box<dyn FileOperations>, Errno> {
|
|
2378
|
+
Ok(Box::new(SignalsFirstRead(
|
|
2379
|
+
inner.open(dentry, how)?,
|
|
2380
|
+
self.0.clone(),
|
|
2381
|
+
)))
|
|
2382
|
+
}
|
|
2383
|
+
}
|
|
2384
|
+
|
|
2385
|
+
/// A file signalling its reader on the first read, counting the reads.
|
|
2386
|
+
struct SignalsFirstRead(Box<dyn FileOperations>, Arc<AtomicUsize>);
|
|
2387
|
+
|
|
2388
|
+
impl FileOperations for SignalsFirstRead {
|
|
2389
|
+
fn read_iter(&mut self, iocb: &mut Kiocb, buf: &mut [u8]) -> Result<usize, Errno> {
|
|
2390
|
+
if self.1.fetch_add(1, Ordering::SeqCst) == 0 {
|
|
2391
|
+
crate::sched::Task::current().signal();
|
|
2392
|
+
}
|
|
2393
|
+
self.0.read_iter(iocb, buf)
|
|
2394
|
+
}
|
|
2395
|
+
}
|
|
2396
|
+
|
|
2397
|
+
// The signal arrives as the copy reads, since every walk to the file hands
|
|
2398
|
+
// one over first.
|
|
2399
|
+
// @behavior FS-235
|
|
2400
|
+
#[test]
|
|
2401
|
+
fn a_copy_up_hands_a_pending_signal_over_between_chunks() {
|
|
2402
|
+
let upper = Arc::new(Tmpfs::new());
|
|
2403
|
+
let contents = "x".repeat(3 * 64 * 1024);
|
|
2404
|
+
let reads = Arc::new(AtomicUsize::new(0));
|
|
2405
|
+
let lower = Wrap::new(
|
|
2406
|
+
tmpfs_with("big", &contents),
|
|
2407
|
+
Arc::new(SignalsOnRead(reads.clone())),
|
|
2408
|
+
);
|
|
2409
|
+
let overlay = at(over(Arc::new(lower), upper.clone()));
|
|
2410
|
+
let read_when_handled = Arc::new(Mutex::new(Vec::new()));
|
|
2411
|
+
crate::sched::testing::on_signal({
|
|
2412
|
+
let (reads, seen) = (reads.clone(), read_when_handled.clone());
|
|
2413
|
+
move || {
|
|
2414
|
+
seen.lock()
|
|
2415
|
+
.expect("never poisoned")
|
|
2416
|
+
.push(reads.load(Ordering::SeqCst))
|
|
2417
|
+
}
|
|
2418
|
+
});
|
|
2419
|
+
let written = crate::sched::run_task(None, || write_over(&overlay, "big", b"y"));
|
|
2420
|
+
crate::sched::testing::on_signal(|| {});
|
|
2421
|
+
assert_eq!(
|
|
2422
|
+
(
|
|
2423
|
+
written,
|
|
2424
|
+
read_when_handled.lock().expect("never poisoned").clone(),
|
|
2425
|
+
on(&upper).vfs_lstat("upper/big").map(|stat| stat.size)
|
|
2426
|
+
),
|
|
2427
|
+
(Ok(()), vec![1], Ok(contents.len() as u64)),
|
|
2428
|
+
"a copy up whose run is signalled as it reads must hand the signal to the Blocking \
|
|
2429
|
+
before its next chunk and copy the whole file"
|
|
2430
|
+
);
|
|
2431
|
+
}
|
|
2432
|
+
|
|
2433
|
+
/// A Tmpfs reporting `file` two bytes long, though it holds more.
|
|
2434
|
+
struct ReportsTwoBytes;
|
|
2435
|
+
|
|
2436
|
+
impl Hook for ReportsTwoBytes {
|
|
2437
|
+
fn getattr(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
2438
|
+
let mut stat = inner.getattr(dentry)?;
|
|
2439
|
+
if dentry.name() == "file" {
|
|
2440
|
+
stat.size = 2;
|
|
2441
|
+
}
|
|
2442
|
+
Ok(stat)
|
|
2443
|
+
}
|
|
2444
|
+
}
|
|
2445
|
+
|
|
2446
|
+
// The lower file reads past the size its stat reported, as one growing
|
|
2447
|
+
// while it is copied does.
|
|
2448
|
+
// @behavior FS-214
|
|
2449
|
+
#[test]
|
|
2450
|
+
fn a_copy_up_takes_the_size_the_lower_file_reported() {
|
|
2451
|
+
let tmpfs: Tmpfs = [("file", "lower")].into_iter().collect();
|
|
2452
|
+
let lower = Wrap::new(Arc::new(tmpfs), Arc::new(ReportsTwoBytes));
|
|
2453
|
+
let upper = Arc::new(Tmpfs::new());
|
|
2454
|
+
let overlay = at(over(Arc::new(lower), upper.clone()));
|
|
2455
|
+
write_over(&overlay, "file", b"L").expect("the copy up and the write must land");
|
|
2456
|
+
assert_eq!(
|
|
2457
|
+
read(&on(&upper), "upper/file"),
|
|
2458
|
+
b"Lo".to_vec(),
|
|
2459
|
+
"a lower file copied up through Overlay::open must bring the bytes its stat reported, \
|
|
2460
|
+
not all it reads"
|
|
2461
|
+
);
|
|
2462
|
+
}
|
|
2463
|
+
|
|
2325
2464
|
/// A Tmpfs answering a stat of `dir` at any depth with an I/O failure,
|
|
2326
2465
|
/// though it opens `dir` as any other directory.
|
|
2327
2466
|
struct StatsNoDir;
|
|
2328
2467
|
|
|
2329
2468
|
impl Hook for StatsNoDir {
|
|
2330
|
-
fn getattr(
|
|
2331
|
-
&self,
|
|
2332
|
-
inner: &dyn InodeOperations,
|
|
2333
|
-
dentry: &Dentry,
|
|
2334
|
-
) -> Result<Kstat, FilesystemError> {
|
|
2469
|
+
fn getattr(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
2335
2470
|
if dentry.name() == "dir" {
|
|
2336
|
-
return Err(
|
|
2471
|
+
return Err(Errno::Other("dir has no stat".to_string()));
|
|
2337
2472
|
}
|
|
2338
2473
|
inner.getattr(dentry)
|
|
2339
2474
|
}
|
|
@@ -2347,13 +2482,9 @@ mod tests {
|
|
|
2347
2482
|
}
|
|
2348
2483
|
|
|
2349
2484
|
impl Hook for Vanishes {
|
|
2350
|
-
fn getattr(
|
|
2351
|
-
&self,
|
|
2352
|
-
inner: &dyn InodeOperations,
|
|
2353
|
-
dentry: &Dentry,
|
|
2354
|
-
) -> Result<Kstat, FilesystemError> {
|
|
2485
|
+
fn getattr(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
2355
2486
|
if dentry.name() == "file" && self.seen.swap(true, Ordering::SeqCst) {
|
|
2356
|
-
return Err(
|
|
2487
|
+
return Err(Errno::NotFound);
|
|
2357
2488
|
}
|
|
2358
2489
|
inner.getattr(dentry)
|
|
2359
2490
|
}
|
|
@@ -2382,32 +2513,36 @@ mod tests {
|
|
|
2382
2513
|
struct FoldedDir(KernPath);
|
|
2383
2514
|
|
|
2384
2515
|
impl FileOperations for FoldedDir {
|
|
2516
|
+
fn has_iterate_shared(&self) -> bool {
|
|
2517
|
+
true
|
|
2518
|
+
}
|
|
2519
|
+
|
|
2385
2520
|
fn iterate_shared(
|
|
2386
2521
|
&mut self,
|
|
2387
2522
|
dentry: &Dentry,
|
|
2388
2523
|
ctx: &mut DirContext<'_>,
|
|
2389
|
-
) -> Result<(),
|
|
2524
|
+
) -> Result<(), Errno> {
|
|
2390
2525
|
let entries = match folded_path_of(dentry).as_str() {
|
|
2391
2526
|
"" => self.0.iterate_dir(),
|
|
2392
2527
|
at => self.0.open_dir(at)?.iterate_dir(),
|
|
2393
2528
|
}?;
|
|
2394
|
-
crate::filesystem::Rdir::default().
|
|
2529
|
+
crate::filesystem::Rdir::default().iterate_shared(dentry, ctx, || Ok(entries))
|
|
2395
2530
|
}
|
|
2396
2531
|
}
|
|
2397
2532
|
|
|
2398
2533
|
impl FileSystemType for FoldsCase {
|
|
2399
|
-
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(),
|
|
2534
|
+
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
|
|
2400
2535
|
sb.d_make_root(Inode::new(&Kstat::new(FileType::Dir, 0), self));
|
|
2401
2536
|
Ok(())
|
|
2402
2537
|
}
|
|
2403
2538
|
}
|
|
2404
2539
|
|
|
2405
2540
|
impl InodeOperations for FoldsCase {
|
|
2406
|
-
fn getattr(&self, dentry: &Dentry) -> Result<Kstat,
|
|
2541
|
+
fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
2407
2542
|
self.root.vfs_lstat(&folded_path_of(dentry))
|
|
2408
2543
|
}
|
|
2409
2544
|
|
|
2410
|
-
fn lookup(&self, dentry: &Dentry) -> Result<Lookup,
|
|
2545
|
+
fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
|
|
2411
2546
|
let name = dentry.name();
|
|
2412
2547
|
let lower = name.to_lowercase();
|
|
2413
2548
|
match self.root.vfs_lstat(&folded_path_of(dentry)) {
|
|
@@ -2416,23 +2551,19 @@ mod tests {
|
|
|
2416
2551
|
inode: Inode::new(&found, Arc::new(self.clone())),
|
|
2417
2552
|
}),
|
|
2418
2553
|
Ok(found) => Ok(Lookup::Found(Inode::new(&found, Arc::new(self.clone())))),
|
|
2419
|
-
Err(
|
|
2554
|
+
Err(Errno::NotFound) => Ok(Lookup::Absent),
|
|
2420
2555
|
Err(err) => Err(err),
|
|
2421
2556
|
}
|
|
2422
2557
|
}
|
|
2423
2558
|
|
|
2424
|
-
fn open(
|
|
2425
|
-
|
|
2426
|
-
dentry: &Dentry,
|
|
2427
|
-
how: &OpenHow,
|
|
2428
|
-
) -> Result<Box<dyn FileOperations>, FilesystemError> {
|
|
2429
|
-
if dentry.kind() == Ok(FileType::Dir) {
|
|
2559
|
+
fn open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
|
|
2560
|
+
if dentry.file_type() == Ok(FileType::Dir) {
|
|
2430
2561
|
return Ok(Box::new(FoldedDir(self.root.clone())));
|
|
2431
2562
|
}
|
|
2432
2563
|
self.root.open(&folded_path_of(dentry), how)
|
|
2433
2564
|
}
|
|
2434
2565
|
|
|
2435
|
-
fn atomic_open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Finish,
|
|
2566
|
+
fn atomic_open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Finish, Errno> {
|
|
2436
2567
|
if dentry.in_lookup() {
|
|
2437
2568
|
let found = self.lookup(dentry)?;
|
|
2438
2569
|
if !how.create || !matches!(found, Lookup::Absent) {
|
|
@@ -2449,32 +2580,32 @@ mod tests {
|
|
|
2449
2580
|
})
|
|
2450
2581
|
}
|
|
2451
2582
|
|
|
2452
|
-
fn mkdir(&self, dentry: &Dentry) -> Result<(),
|
|
2583
|
+
fn mkdir(&self, dentry: &Dentry) -> Result<(), Errno> {
|
|
2453
2584
|
self.root.vfs_mkdir(&folded_path_of(dentry))
|
|
2454
2585
|
}
|
|
2455
2586
|
|
|
2456
|
-
fn rmdir(&self, dentry: &Dentry) -> Result<(),
|
|
2587
|
+
fn rmdir(&self, dentry: &Dentry) -> Result<(), Errno> {
|
|
2457
2588
|
self.root.vfs_rmdir(&folded_path_of(dentry))
|
|
2458
2589
|
}
|
|
2459
2590
|
|
|
2460
|
-
fn unlink(&self, dentry: &Dentry) -> Result<(),
|
|
2591
|
+
fn unlink(&self, dentry: &Dentry) -> Result<(), Errno> {
|
|
2461
2592
|
self.root.vfs_unlink(&folded_path_of(dentry))
|
|
2462
2593
|
}
|
|
2463
2594
|
|
|
2464
2595
|
fn rename(
|
|
2465
2596
|
&self,
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
) -> Result<(),
|
|
2597
|
+
old: &Dentry,
|
|
2598
|
+
_new_dir: &dyn InodeOperations,
|
|
2599
|
+
new: &Dentry,
|
|
2600
|
+
_flags: Option<RenameFlag>,
|
|
2601
|
+
) -> Result<(), Errno> {
|
|
2471
2602
|
self.root
|
|
2472
|
-
.rename(&folded_path_of(
|
|
2603
|
+
.rename(&folded_path_of(old), &self.root, &folded_path_of(new))
|
|
2473
2604
|
}
|
|
2474
2605
|
}
|
|
2475
2606
|
|
|
2476
2607
|
/// What `path` names through `fs`, or why it names nothing.
|
|
2477
|
-
fn kind(fs: &KernPath, path: &str) -> Result<FileType,
|
|
2608
|
+
fn kind(fs: &KernPath, path: &str) -> Result<FileType, Errno> {
|
|
2478
2609
|
fs.vfs_lstat(path).map(|metadata| metadata.file_type)
|
|
2479
2610
|
}
|
|
2480
2611
|
|
|
@@ -2504,7 +2635,7 @@ mod tests {
|
|
|
2504
2635
|
(
|
|
2505
2636
|
Ok(FileType::RegFile),
|
|
2506
2637
|
Ok(FileType::RegFile),
|
|
2507
|
-
Err(
|
|
2638
|
+
Err(Errno::NotFound)
|
|
2508
2639
|
),
|
|
2509
2640
|
"files made through directories Overlay::open_dir opened before Overlay::rename moved \
|
|
2510
2641
|
the outer one must stand beneath its new path"
|
|
@@ -2525,7 +2656,7 @@ mod tests {
|
|
|
2525
2656
|
dir.iterate_dir().map(|entries| entries.len()),
|
|
2526
2657
|
names(&overlay, "dir").len()
|
|
2527
2658
|
),
|
|
2528
|
-
(Err(
|
|
2659
|
+
(Err(Errno::NotFound), Ok(0), 0),
|
|
2529
2660
|
"a directory Overlay::open_dir opened, once vfs_rmdir removed it and another \
|
|
2530
2661
|
was made in its place, must make nothing, list nothing, and leave the new one empty"
|
|
2531
2662
|
);
|
|
@@ -2569,7 +2700,7 @@ mod tests {
|
|
|
2569
2700
|
inner: &dyn InodeOperations,
|
|
2570
2701
|
dentry: &Dentry,
|
|
2571
2702
|
how: &OpenHow,
|
|
2572
|
-
) -> Result<Box<dyn FileOperations>,
|
|
2703
|
+
) -> Result<Box<dyn FileOperations>, Errno> {
|
|
2573
2704
|
let opened = inner.open(dentry, how);
|
|
2574
2705
|
let run = self.0.lock().expect("never poisoned").take();
|
|
2575
2706
|
if let Some(run) = run {
|
|
@@ -2610,14 +2741,13 @@ mod tests {
|
|
|
2610
2741
|
use crate::vfs::{self, OpenHow, Path};
|
|
2611
2742
|
let asked = Arc::new(AtomicUsize::new(0));
|
|
2612
2743
|
let overlay = Overlay::new(
|
|
2613
|
-
vec![Filesystem::new(
|
|
2614
|
-
|
|
2615
|
-
Some(Filesystem::new(Arc::new(Tmpfs::new())).expect("the instance must stand")),
|
|
2744
|
+
vec![Filesystem::new(KeepsTimes(asked.clone())).expect("the instance must stand")],
|
|
2745
|
+
Some(Filesystem::new(Tmpfs::new()).expect("the instance must stand")),
|
|
2616
2746
|
)
|
|
2617
2747
|
.expect("the Overlay must stack");
|
|
2618
2748
|
let mount = Mount::new(
|
|
2619
2749
|
"/data",
|
|
2620
|
-
Filesystem::new(
|
|
2750
|
+
Filesystem::new(overlay).expect("the instance must stand"),
|
|
2621
2751
|
Access::ReadWrite,
|
|
2622
2752
|
)
|
|
2623
2753
|
.expect("/data is a guest path");
|
|
@@ -2641,11 +2771,11 @@ mod tests {
|
|
|
2641
2771
|
let answer = vfs::do_utimes_fd(
|
|
2642
2772
|
&cred,
|
|
2643
2773
|
held.path(),
|
|
2644
|
-
&Iattr::
|
|
2774
|
+
&Iattr::for_times(None, Some(crate::vfs::SetTime::Now)),
|
|
2645
2775
|
);
|
|
2646
2776
|
assert_eq!(
|
|
2647
2777
|
(answer, asked.load(Ordering::SeqCst)),
|
|
2648
|
-
(Err(
|
|
2778
|
+
(Err(Errno::AlreadyExists), 0),
|
|
2649
2779
|
"vfs::do_utimes_fd on a held lower file whose name another entry took must answer \
|
|
2650
2780
|
EEXIST and leave the lower Layer unasked"
|
|
2651
2781
|
);
|
|
@@ -2660,13 +2790,13 @@ mod tests {
|
|
|
2660
2790
|
use crate::vfs::{self, OpenHow, Path};
|
|
2661
2791
|
let lower: Tmpfs = [("d/f", "removed")].into_iter().collect();
|
|
2662
2792
|
let overlay = Overlay::new(
|
|
2663
|
-
vec![Filesystem::new(
|
|
2664
|
-
Some(Filesystem::new(
|
|
2793
|
+
vec![Filesystem::new(lower).expect("the instance must stand")],
|
|
2794
|
+
Some(Filesystem::new(Tmpfs::new()).expect("the instance must stand")),
|
|
2665
2795
|
)
|
|
2666
2796
|
.expect("the Overlay must stack");
|
|
2667
2797
|
let mount = Mount::new(
|
|
2668
2798
|
"/data",
|
|
2669
|
-
Filesystem::new(
|
|
2799
|
+
Filesystem::new(overlay).expect("the instance must stand"),
|
|
2670
2800
|
Access::ReadWrite,
|
|
2671
2801
|
)
|
|
2672
2802
|
.expect("/data is a guest path");
|
|
@@ -2684,34 +2814,40 @@ mod tests {
|
|
|
2684
2814
|
let answer = vfs::do_utimes_fd(
|
|
2685
2815
|
&cred,
|
|
2686
2816
|
held.path(),
|
|
2687
|
-
&Iattr::
|
|
2817
|
+
&Iattr::for_times(None, Some(crate::vfs::SetTime::Now)),
|
|
2688
2818
|
);
|
|
2689
2819
|
assert_eq!(
|
|
2690
2820
|
(
|
|
2691
2821
|
answer,
|
|
2692
2822
|
vfs::vfs_fstatat(&cred, &root, "d/f", false).map(|_| ())
|
|
2693
2823
|
),
|
|
2694
|
-
(
|
|
2695
|
-
Err(FilesystemError::NotFound),
|
|
2696
|
-
Err(FilesystemError::NotFound)
|
|
2697
|
-
),
|
|
2824
|
+
(Err(Errno::NotFound), Err(Errno::NotFound)),
|
|
2698
2825
|
"vfs::do_utimes_fd on a held lower file whose directory was removed and made again \
|
|
2699
2826
|
must answer ENOENT and leave the file out of the view"
|
|
2700
2827
|
);
|
|
2701
2828
|
}
|
|
2702
2829
|
|
|
2703
|
-
///
|
|
2704
|
-
///
|
|
2705
|
-
|
|
2830
|
+
/// Holds the first ask about the directory `e` once armed, as a copy up
|
|
2831
|
+
/// holding the view's lock of it asks, until another thread waits in
|
|
2832
|
+
/// line for that lock or its open ended, so a second copy up of it finds
|
|
2833
|
+
/// the first under way.
|
|
2834
|
+
#[derive(Default)]
|
|
2835
|
+
struct HoldsDirectory {
|
|
2836
|
+
lock: Mutex<Option<Arc<crate::locking::RwSemaphore>>>,
|
|
2837
|
+
ended: AtomicUsize,
|
|
2838
|
+
}
|
|
2706
2839
|
|
|
2707
|
-
impl Hook for
|
|
2708
|
-
fn getattr(
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
if
|
|
2714
|
-
|
|
2840
|
+
impl Hook for HoldsDirectory {
|
|
2841
|
+
fn getattr(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
2842
|
+
let armed = match dentry.name() == "e" {
|
|
2843
|
+
true => self.lock.lock().unwrap().take(),
|
|
2844
|
+
false => None,
|
|
2845
|
+
};
|
|
2846
|
+
if let Some(lock) = armed {
|
|
2847
|
+
crate::sched::testing::wait_until(
|
|
2848
|
+
"the other open waiting for the directory this one copies up, or ending",
|
|
2849
|
+
|| lock.queued() > 0 || self.ended.load(Ordering::SeqCst) > 0,
|
|
2850
|
+
);
|
|
2715
2851
|
}
|
|
2716
2852
|
inner.getattr(dentry)
|
|
2717
2853
|
}
|
|
@@ -2726,18 +2862,16 @@ mod tests {
|
|
|
2726
2862
|
use crate::mount::{Access, Mount};
|
|
2727
2863
|
use crate::vfs::{self, OpenHow, Path};
|
|
2728
2864
|
let lower: Tmpfs = [("d/e/f", "1"), ("d/e/g", "2")].into_iter().collect();
|
|
2729
|
-
let hook = Arc::new(
|
|
2865
|
+
let hook = Arc::new(HoldsDirectory::default());
|
|
2730
2866
|
let overlay = Overlay::new(
|
|
2731
|
-
vec![
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
],
|
|
2735
|
-
Some(Filesystem::new(Arc::new(Tmpfs::new())).expect("the instance must stand")),
|
|
2867
|
+
vec![Filesystem::new(Wrap::new(Arc::new(lower), hook.clone()))
|
|
2868
|
+
.expect("the instance must stand")],
|
|
2869
|
+
Some(Filesystem::new(Tmpfs::new()).expect("the instance must stand")),
|
|
2736
2870
|
)
|
|
2737
2871
|
.expect("the Overlay must stack");
|
|
2738
2872
|
let mount = Mount::new(
|
|
2739
2873
|
"/data",
|
|
2740
|
-
Filesystem::new(
|
|
2874
|
+
Filesystem::new(overlay).expect("the instance must stand"),
|
|
2741
2875
|
Access::ReadWrite,
|
|
2742
2876
|
)
|
|
2743
2877
|
.expect("/data is a guest path");
|
|
@@ -2750,12 +2884,28 @@ mod tests {
|
|
|
2750
2884
|
for name in ["d/e/f", "d/e/g"] {
|
|
2751
2885
|
vfs::vfs_fstatat(&cred, &root, name, false).expect("the file stands");
|
|
2752
2886
|
}
|
|
2753
|
-
|
|
2887
|
+
let read_dir = OpenHow {
|
|
2888
|
+
read: true,
|
|
2889
|
+
directory: true,
|
|
2890
|
+
..OpenHow::default()
|
|
2891
|
+
};
|
|
2892
|
+
let Ok(held) = vfs::kern_path::filp_open(&cred, &root, "d/e", &read_dir) else {
|
|
2893
|
+
panic!("the directory must open");
|
|
2894
|
+
};
|
|
2895
|
+
let inode = held
|
|
2896
|
+
.path()
|
|
2897
|
+
.dentry()
|
|
2898
|
+
.inode()
|
|
2899
|
+
.expect("the directory has an inode");
|
|
2900
|
+
let view = OverlayDirInode::of(&inode).expect("the view holds the directory");
|
|
2901
|
+
*hook.lock.lock().unwrap() = Some(view.lock.clone());
|
|
2902
|
+
let open = |name| {
|
|
2903
|
+
let opened = vfs::kern_path::filp_open(&cred, &root, name, &write).map(drop);
|
|
2904
|
+
hook.ended.fetch_add(1, Ordering::SeqCst);
|
|
2905
|
+
opened
|
|
2906
|
+
};
|
|
2754
2907
|
let opened = thread::scope(|scope| {
|
|
2755
|
-
let (first, second) = (
|
|
2756
|
-
scope.spawn(|| vfs::kern_path::filp_open(&cred, &root, "d/e/f", &write).map(drop)),
|
|
2757
|
-
scope.spawn(|| vfs::kern_path::filp_open(&cred, &root, "d/e/g", &write).map(drop)),
|
|
2758
|
-
);
|
|
2908
|
+
let (first, second) = (scope.spawn(|| open("d/e/f")), scope.spawn(|| open("d/e/g")));
|
|
2759
2909
|
(
|
|
2760
2910
|
crate::sched::testing::join_scoped("the first open", first),
|
|
2761
2911
|
crate::sched::testing::join_scoped("the second open", second),
|
|
@@ -2776,19 +2926,16 @@ mod tests {
|
|
|
2776
2926
|
|
|
2777
2927
|
/// What a removal and an open to write answer racing over one lower file,
|
|
2778
2928
|
/// with what the descriptor the open made reports of itself.
|
|
2779
|
-
fn race_removal_with_a_write() -> (
|
|
2780
|
-
Result<(), FilesystemError>,
|
|
2781
|
-
Option<Result<FileType, FilesystemError>>,
|
|
2782
|
-
) {
|
|
2929
|
+
fn race_removal_with_a_write() -> (Result<(), Errno>, Option<Result<FileType, Errno>>) {
|
|
2783
2930
|
let lower: Tmpfs = [("d/f", "lower")].into_iter().collect();
|
|
2784
2931
|
let overlay = Overlay::new(
|
|
2785
|
-
vec![Filesystem::new(
|
|
2786
|
-
Some(Filesystem::new(
|
|
2932
|
+
vec![Filesystem::new(lower).expect("the instance must stand")],
|
|
2933
|
+
Some(Filesystem::new(Tmpfs::new()).expect("the instance must stand")),
|
|
2787
2934
|
)
|
|
2788
2935
|
.expect("the Overlay must stack");
|
|
2789
2936
|
let mount = Mount::new(
|
|
2790
2937
|
"/data",
|
|
2791
|
-
Filesystem::new(
|
|
2938
|
+
Filesystem::new(overlay).expect("the instance must stand"),
|
|
2792
2939
|
Access::ReadWrite,
|
|
2793
2940
|
)
|
|
2794
2941
|
.expect("/data is a guest path");
|
|
@@ -2819,6 +2966,46 @@ mod tests {
|
|
|
2819
2966
|
})
|
|
2820
2967
|
}
|
|
2821
2968
|
|
|
2969
|
+
// The make holds only the directory it makes in, so only the removal
|
|
2970
|
+
// holding that directory too, and removing it only once empty, keeps
|
|
2971
|
+
// what the make made from going with it. The two land in the same
|
|
2972
|
+
// instant only a few times in this many tries.
|
|
2973
|
+
// @behavior FS-132
|
|
2974
|
+
#[test]
|
|
2975
|
+
#[ignore = "a stress witness; run by rake crates:stress"]
|
|
2976
|
+
fn a_removal_through_an_overlay_waits_for_a_change_in_that_directory() {
|
|
2977
|
+
let (overlay, upper) = beside_its_upper([("upper/a/.keep", "")].into_iter().collect());
|
|
2978
|
+
let stop = Arc::new(AtomicBool::new(false));
|
|
2979
|
+
let churning = {
|
|
2980
|
+
let stop = stop.clone();
|
|
2981
|
+
thread::spawn(move || {
|
|
2982
|
+
while !stop.load(Ordering::SeqCst) {
|
|
2983
|
+
let _ = vfs::filename_mkdirat(&Arc::default(), &overlay, "a/b");
|
|
2984
|
+
let _ = vfs::filename_rmdir(&Arc::default(), &overlay, "a/b");
|
|
2985
|
+
}
|
|
2986
|
+
})
|
|
2987
|
+
};
|
|
2988
|
+
let mut lost = 0;
|
|
2989
|
+
for _ in 0..100_000 {
|
|
2990
|
+
if vfs::filename_mkdirat(&Arc::default(), &upper, "upper/a/b/made").is_ok() {
|
|
2991
|
+
match vfs::vfs_fstatat(&Arc::default(), &upper, "upper/a/b/made", false) {
|
|
2992
|
+
Ok(_) => {
|
|
2993
|
+
let _ = vfs::filename_rmdir(&Arc::default(), &upper, "upper/a/b/made");
|
|
2994
|
+
}
|
|
2995
|
+
Err(_) => lost += 1,
|
|
2996
|
+
}
|
|
2997
|
+
}
|
|
2998
|
+
}
|
|
2999
|
+
stop.store(true, Ordering::SeqCst);
|
|
3000
|
+
churning.join().expect("the Overlay's calls must not panic");
|
|
3001
|
+
assert_eq!(
|
|
3002
|
+
lost, 0,
|
|
3003
|
+
"vfs::filename_mkdirat in a directory through a Mount of an Overlay's upper \
|
|
3004
|
+
Tmpfs, while vfs::filename_rmdir removes that directory through the Overlay, \
|
|
3005
|
+
must leave every directory it made standing"
|
|
3006
|
+
);
|
|
3007
|
+
}
|
|
3008
|
+
|
|
2822
3009
|
// A removal deciding how to hide the name before the copy up landed asked
|
|
2823
3010
|
// the rename to find nothing there.
|
|
2824
3011
|
// @behavior FS-182
|
|
@@ -2860,21 +3047,21 @@ mod tests {
|
|
|
2860
3047
|
struct HoldsFifo(Arc<AtomicUsize>);
|
|
2861
3048
|
|
|
2862
3049
|
impl FileSystemType for HoldsFifo {
|
|
2863
|
-
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(),
|
|
3050
|
+
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
|
|
2864
3051
|
sb.d_make_root(Inode::new(&Kstat::new(FileType::Dir, 0), self));
|
|
2865
3052
|
Ok(())
|
|
2866
3053
|
}
|
|
2867
3054
|
}
|
|
2868
3055
|
|
|
2869
3056
|
impl InodeOperations for HoldsFifo {
|
|
2870
|
-
fn getattr(&self, dentry: &Dentry) -> Result<Kstat,
|
|
3057
|
+
fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
2871
3058
|
Ok(match dentry.name().as_str() {
|
|
2872
3059
|
"pipe" => Kstat::new(FileType::Fifo, 0).with_identity(1, 2),
|
|
2873
3060
|
_ => Kstat::new(FileType::Dir, 0).with_identity(1, 1),
|
|
2874
3061
|
})
|
|
2875
3062
|
}
|
|
2876
3063
|
|
|
2877
|
-
fn lookup(&self, dentry: &Dentry) -> Result<Lookup,
|
|
3064
|
+
fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
|
|
2878
3065
|
Ok(match dentry.name().as_str() {
|
|
2879
3066
|
"pipe" => Lookup::Found(Inode::new(
|
|
2880
3067
|
&Kstat::new(FileType::Fifo, 0).with_identity(1, 2),
|
|
@@ -2884,13 +3071,9 @@ mod tests {
|
|
|
2884
3071
|
})
|
|
2885
3072
|
}
|
|
2886
3073
|
|
|
2887
|
-
fn open(
|
|
2888
|
-
&self,
|
|
2889
|
-
_dentry: &Dentry,
|
|
2890
|
-
_how: &OpenHow,
|
|
2891
|
-
) -> Result<Box<dyn FileOperations>, FilesystemError> {
|
|
3074
|
+
fn open(&self, _dentry: &Dentry, _how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
|
|
2892
3075
|
self.0.fetch_add(1, Ordering::SeqCst);
|
|
2893
|
-
Err(
|
|
3076
|
+
Err(Errno::Interrupted)
|
|
2894
3077
|
}
|
|
2895
3078
|
}
|
|
2896
3079
|
|
|
@@ -2903,14 +3086,13 @@ mod tests {
|
|
|
2903
3086
|
use crate::vfs::{self, Path};
|
|
2904
3087
|
let opened = Arc::new(AtomicUsize::new(0));
|
|
2905
3088
|
let overlay = Overlay::new(
|
|
2906
|
-
vec![Filesystem::new(
|
|
2907
|
-
|
|
2908
|
-
Some(Filesystem::new(Arc::new(Tmpfs::new())).expect("the instance must stand")),
|
|
3089
|
+
vec![Filesystem::new(HoldsFifo(opened.clone())).expect("the instance must stand")],
|
|
3090
|
+
Some(Filesystem::new(Tmpfs::new()).expect("the instance must stand")),
|
|
2909
3091
|
)
|
|
2910
3092
|
.expect("the Overlay must stack");
|
|
2911
3093
|
let mount = Mount::new(
|
|
2912
3094
|
"/data",
|
|
2913
|
-
Filesystem::new(
|
|
3095
|
+
Filesystem::new(overlay).expect("the instance must stand"),
|
|
2914
3096
|
Access::ReadWrite,
|
|
2915
3097
|
)
|
|
2916
3098
|
.expect("/data is a guest path");
|
|
@@ -2919,11 +3101,11 @@ mod tests {
|
|
|
2919
3101
|
&Path::root(mount.mnt()),
|
|
2920
3102
|
"pipe",
|
|
2921
3103
|
false,
|
|
2922
|
-
&Iattr::
|
|
3104
|
+
&Iattr::for_times(None, Some(crate::vfs::SetTime::Now)),
|
|
2923
3105
|
);
|
|
2924
3106
|
assert_eq!(
|
|
2925
3107
|
(answer, opened.load(Ordering::SeqCst)),
|
|
2926
|
-
(Err(
|
|
3108
|
+
(Err(Errno::PermissionDenied), 0),
|
|
2927
3109
|
"vfs::do_utimes_pathon a FIFO a lower Layer holds through an Overlay must answer EACCES \
|
|
2928
3110
|
and open nothing"
|
|
2929
3111
|
);
|
|
@@ -2936,10 +3118,10 @@ mod tests {
|
|
|
2936
3118
|
#[test]
|
|
2937
3119
|
fn a_whiteout_in_a_directory_one_layer_shows_names_nothing() {
|
|
2938
3120
|
let lower: Tmpfs = [("file", "x")].into_iter().collect();
|
|
2939
|
-
let first_upper = Filesystem::new(
|
|
3121
|
+
let first_upper = Filesystem::new(Tmpfs::new()).expect("the instance must stand");
|
|
2940
3122
|
let first = kern_path(Arc::new(
|
|
2941
3123
|
Overlay::new(
|
|
2942
|
-
vec![Filesystem::new(
|
|
3124
|
+
vec![Filesystem::new(lower).expect("the instance must stand")],
|
|
2943
3125
|
Some(first_upper.clone()),
|
|
2944
3126
|
)
|
|
2945
3127
|
.expect("the Overlay must stack"),
|
|
@@ -2947,12 +3129,12 @@ mod tests {
|
|
|
2947
3129
|
first.vfs_unlink("file").expect("the file must be removed");
|
|
2948
3130
|
let second = at(Overlay::new(
|
|
2949
3131
|
vec![first_upper],
|
|
2950
|
-
Some(Filesystem::new(
|
|
3132
|
+
Some(Filesystem::new(Tmpfs::new()).expect("the instance must stand")),
|
|
2951
3133
|
)
|
|
2952
3134
|
.expect("the Overlay must stack"));
|
|
2953
3135
|
assert_eq!(
|
|
2954
3136
|
second.vfs_lstat("upper/file").err(),
|
|
2955
|
-
Some(
|
|
3137
|
+
Some(Errno::NotFound),
|
|
2956
3138
|
"a stat through an Overlay of a whiteout in a directory one Layer shows must answer \
|
|
2957
3139
|
ENOENT, as the listing shows nothing there"
|
|
2958
3140
|
);
|
|
@@ -2969,7 +3151,7 @@ mod tests {
|
|
|
2969
3151
|
let overlay = at(over(Arc::new(lower), Arc::new(Tmpfs::new())));
|
|
2970
3152
|
assert_eq!(
|
|
2971
3153
|
overlay.rename("dir", &overlay, "full"),
|
|
2972
|
-
Err(
|
|
3154
|
+
Err(Errno::CrossesDevices),
|
|
2973
3155
|
"a rename through an Overlay of a lower Layer's directory onto one holding entries \
|
|
2974
3156
|
must answer EXDEV, as ovl_rename_start asks whether it can move first"
|
|
2975
3157
|
);
|
|
@@ -2985,13 +3167,13 @@ mod tests {
|
|
|
2985
3167
|
let lower: Tmpfs = [("file", vec![b'x'; 1 << 20])].into_iter().collect();
|
|
2986
3168
|
let upper = Tmpfs::new().with_size(Some(4096)).with_nr_inodes(None);
|
|
2987
3169
|
let overlay = Overlay::new(
|
|
2988
|
-
vec![Filesystem::new(
|
|
2989
|
-
Some(Filesystem::new(
|
|
3170
|
+
vec![Filesystem::new(lower).expect("the instance must stand")],
|
|
3171
|
+
Some(Filesystem::new(upper).expect("the instance must stand")),
|
|
2990
3172
|
)
|
|
2991
3173
|
.expect("the Overlay must stack");
|
|
2992
3174
|
let mount = Mount::new(
|
|
2993
3175
|
"/data",
|
|
2994
|
-
Filesystem::new(
|
|
3176
|
+
Filesystem::new(overlay).expect("the instance must stand"),
|
|
2995
3177
|
Access::ReadWrite,
|
|
2996
3178
|
)
|
|
2997
3179
|
.expect("/data is a guest path");
|
|
@@ -3026,18 +3208,18 @@ mod tests {
|
|
|
3026
3208
|
std::fs::create_dir_all(&deep).expect("the host tree must be made");
|
|
3027
3209
|
std::fs::create_dir_all(host.join("held")).expect("the host tree must be made");
|
|
3028
3210
|
std::fs::write(host.join("held/f"), "x").expect("the host file must be written");
|
|
3029
|
-
let lower = Filesystem::new(
|
|
3211
|
+
let lower = Filesystem::new(
|
|
3030
3212
|
crate::filesystem::Bind::new(&host).expect("the host directory must open"),
|
|
3031
|
-
)
|
|
3213
|
+
)
|
|
3032
3214
|
.expect("the instance must stand");
|
|
3033
3215
|
let overlay = Overlay::new(
|
|
3034
3216
|
vec![lower],
|
|
3035
|
-
Some(Filesystem::new(
|
|
3217
|
+
Some(Filesystem::new(Tmpfs::new()).expect("the instance must stand")),
|
|
3036
3218
|
)
|
|
3037
3219
|
.expect("the Overlay must stack");
|
|
3038
3220
|
let mount = Mount::new(
|
|
3039
3221
|
"/data",
|
|
3040
|
-
Filesystem::new(
|
|
3222
|
+
Filesystem::new(overlay).expect("the instance must stand"),
|
|
3041
3223
|
Access::Read,
|
|
3042
3224
|
)
|
|
3043
3225
|
.expect("/data is a guest path");
|
|
@@ -3160,8 +3342,8 @@ mod tests {
|
|
|
3160
3342
|
_inner: &dyn InodeOperations,
|
|
3161
3343
|
_dentry: &Dentry,
|
|
3162
3344
|
_how: &OpenHow,
|
|
3163
|
-
) -> Result<Box<dyn FileOperations>,
|
|
3164
|
-
Err(
|
|
3345
|
+
) -> Result<Box<dyn FileOperations>, Errno> {
|
|
3346
|
+
Err(Errno::PermissionDenied)
|
|
3165
3347
|
}
|
|
3166
3348
|
}
|
|
3167
3349
|
|
|
@@ -3179,7 +3361,7 @@ mod tests {
|
|
|
3179
3361
|
);
|
|
3180
3362
|
let mount = Mount::new(
|
|
3181
3363
|
"/data",
|
|
3182
|
-
Filesystem::new(
|
|
3364
|
+
Filesystem::new(overlay).expect("the instance must stand"),
|
|
3183
3365
|
Access::Read,
|
|
3184
3366
|
)
|
|
3185
3367
|
.expect("/data is a guest path");
|
|
@@ -3196,7 +3378,7 @@ mod tests {
|
|
|
3196
3378
|
);
|
|
3197
3379
|
assert_eq!(
|
|
3198
3380
|
answer.err(),
|
|
3199
|
-
Some(
|
|
3381
|
+
Some(Errno::PermissionDenied),
|
|
3200
3382
|
"vfs::do_file_open of an Overlay's directory whose Layer refuses its open must answer \
|
|
3201
3383
|
what the Layer answered"
|
|
3202
3384
|
);
|
|
@@ -3210,7 +3392,7 @@ mod tests {
|
|
|
3210
3392
|
let overlay = at(over(Arc::new(lower), Arc::new(Tmpfs::new())));
|
|
3211
3393
|
assert_eq!(
|
|
3212
3394
|
overlay.rename("file", &overlay, "moved"),
|
|
3213
|
-
Err(
|
|
3395
|
+
Err(Errno::NotFound),
|
|
3214
3396
|
"a file renamed through Overlay::rename that its Layer loses during the call must \
|
|
3215
3397
|
answer not found"
|
|
3216
3398
|
);
|
|
@@ -3290,40 +3472,47 @@ mod tests {
|
|
|
3290
3472
|
);
|
|
3291
3473
|
}
|
|
3292
3474
|
|
|
3293
|
-
/// A Tmpfs whose first open
|
|
3294
|
-
|
|
3295
|
-
struct
|
|
3475
|
+
/// A `Tmpfs` whose first open holds, flagging that it began, until `waits`
|
|
3476
|
+
/// counts a wait.
|
|
3477
|
+
struct HoldsFirstOpen {
|
|
3296
3478
|
opening: AtomicBool,
|
|
3479
|
+
waits: Arc<AtomicUsize>,
|
|
3297
3480
|
}
|
|
3298
3481
|
|
|
3299
|
-
impl Hook for
|
|
3482
|
+
impl Hook for HoldsFirstOpen {
|
|
3300
3483
|
fn open(
|
|
3301
3484
|
&self,
|
|
3302
3485
|
inner: &dyn InodeOperations,
|
|
3303
3486
|
dentry: &Dentry,
|
|
3304
3487
|
how: &OpenHow,
|
|
3305
|
-
) -> Result<Box<dyn FileOperations>,
|
|
3488
|
+
) -> Result<Box<dyn FileOperations>, Errno> {
|
|
3306
3489
|
if !self.opening.swap(true, Ordering::SeqCst) {
|
|
3307
|
-
|
|
3490
|
+
crate::sched::testing::wait_until(
|
|
3491
|
+
"the second copy up waiting for the first one's lock",
|
|
3492
|
+
|| self.waits.load(Ordering::SeqCst) > 0,
|
|
3493
|
+
);
|
|
3308
3494
|
}
|
|
3309
3495
|
inner.open(dentry, how)
|
|
3310
3496
|
}
|
|
3311
3497
|
}
|
|
3312
3498
|
|
|
3313
|
-
// The first copy up holds the file's lock while its lower open
|
|
3499
|
+
// The first copy up holds the file's lock while its lower open holds,
|
|
3314
3500
|
// so the second, of the same file, finds the lock held and waits.
|
|
3315
3501
|
// @behavior FS-039
|
|
3316
3502
|
#[test]
|
|
3317
3503
|
fn a_contended_copy_up_waits_through_the_registered_blocking() {
|
|
3318
3504
|
let counts = crate::sched::testing::count_waits();
|
|
3319
|
-
let
|
|
3320
|
-
|
|
3505
|
+
let holds = Arc::new(HoldsFirstOpen {
|
|
3506
|
+
opening: AtomicBool::new(false),
|
|
3507
|
+
waits: counts.clone(),
|
|
3508
|
+
});
|
|
3509
|
+
let lower = Wrap::new(tmpfs_with("note", "lower"), holds.clone());
|
|
3321
3510
|
let overlay = over(Arc::new(lower), Arc::new(Tmpfs::new()));
|
|
3322
3511
|
let first = at(overlay);
|
|
3323
3512
|
let second = first.clone();
|
|
3324
3513
|
let copying = thread::spawn(move || write_over(&first, "note", b"first"));
|
|
3325
3514
|
crate::sched::testing::wait_until("the first copy up opening its lower file", || {
|
|
3326
|
-
|
|
3515
|
+
holds.opening.load(Ordering::SeqCst)
|
|
3327
3516
|
});
|
|
3328
3517
|
let waited =
|
|
3329
3518
|
crate::sched::testing::within_max_wait(|| write_over(&second, "note", b"later"));
|
|
@@ -3361,15 +3550,16 @@ mod tests {
|
|
|
3361
3550
|
);
|
|
3362
3551
|
}
|
|
3363
3552
|
|
|
3364
|
-
// The upper
|
|
3365
|
-
// the two report different times and only the upper's
|
|
3553
|
+
// The upper layer's directory changes now, and the lower one's times are
|
|
3554
|
+
// long past, so the two report different times and only the upper's
|
|
3555
|
+
// matches.
|
|
3366
3556
|
// @behavior FS-117
|
|
3367
3557
|
#[test]
|
|
3368
3558
|
fn an_overlay_reports_a_merged_directory_as_overlayfs_does() {
|
|
3369
3559
|
let lower: Arc<Tmpfs> = Arc::new([("dir/a.txt", "a")].into_iter().collect());
|
|
3560
|
+
set_long_ago(&on(&lower), "dir");
|
|
3370
3561
|
let upper: Arc<Tmpfs> = Arc::new(Tmpfs::new());
|
|
3371
3562
|
let overlay = at(over(lower.clone(), upper.clone()));
|
|
3372
|
-
std::thread::sleep(std::time::Duration::from_millis(10));
|
|
3373
3563
|
write(&overlay, "dir/b.txt", b"b").expect("the upper must take a write");
|
|
3374
3564
|
let merged = overlay.vfs_lstat("dir").expect("the directory must stand");
|
|
3375
3565
|
let modified = |layer: &Arc<Tmpfs>, path: &str| {
|
|
@@ -3394,7 +3584,7 @@ mod tests {
|
|
|
3394
3584
|
tmpfs_with("dir/lower", "x"),
|
|
3395
3585
|
tmpfs_with("upper/dir/upper", "x"),
|
|
3396
3586
|
));
|
|
3397
|
-
let identity = |metadata: Result<Kstat,
|
|
3587
|
+
let identity = |metadata: Result<Kstat, Errno>| {
|
|
3398
3588
|
let metadata = metadata.expect("the directory must stand");
|
|
3399
3589
|
(metadata.dev, metadata.ino)
|
|
3400
3590
|
};
|
|
@@ -3418,15 +3608,15 @@ mod tests {
|
|
|
3418
3608
|
inner: &dyn InodeOperations,
|
|
3419
3609
|
dentry: &Dentry,
|
|
3420
3610
|
mask: Mask,
|
|
3421
|
-
) -> Result<(),
|
|
3611
|
+
) -> Result<(), Errno> {
|
|
3422
3612
|
if dentry.name() == self.name && mask.contains(self.mask) {
|
|
3423
|
-
return Err(
|
|
3613
|
+
return Err(Errno::PermissionDenied);
|
|
3424
3614
|
}
|
|
3425
3615
|
inner.permission(dentry, mask)
|
|
3426
3616
|
}
|
|
3427
3617
|
}
|
|
3428
3618
|
|
|
3429
|
-
type LayerCall = fn(&KernPath) -> Result<(),
|
|
3619
|
+
type LayerCall = fn(&KernPath) -> Result<(), Errno>;
|
|
3430
3620
|
|
|
3431
3621
|
// Only a Layer of the Host App's own answers `permission`, so each call is
|
|
3432
3622
|
// made over a lower Layer refusing just the one ask that call makes of it.
|
|
@@ -3459,7 +3649,7 @@ mod tests {
|
|
|
3459
3649
|
let view = at(over(Arc::new(lower), Arc::new(Tmpfs::new())));
|
|
3460
3650
|
assert_eq!(
|
|
3461
3651
|
run(&view),
|
|
3462
|
-
Err(
|
|
3652
|
+
Err(Errno::PermissionDenied),
|
|
3463
3653
|
"{call} through an Overlay over a Layer whose permission refuses {mask:?} of \
|
|
3464
3654
|
`{name}` must answer that refusal, as overlayfs asks inode_permission of the \
|
|
3465
3655
|
real inode"
|