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
|
@@ -6,16 +6,17 @@
|
|
|
6
6
|
//! bound; the walk asks `revalidate` before trusting it, so what changed behind
|
|
7
7
|
//! the runtime's back is found again.
|
|
8
8
|
|
|
9
|
+
use crate::sched::TaskId;
|
|
9
10
|
use std::any::Any;
|
|
10
11
|
use std::num::NonZeroUsize;
|
|
12
|
+
use std::sync::atomic::{AtomicUsize, Ordering};
|
|
11
13
|
use std::sync::{Arc, Condvar, Mutex, MutexGuard, OnceLock, PoisonError, Weak};
|
|
12
|
-
use std::thread::ThreadId;
|
|
13
14
|
|
|
14
15
|
use lru::LruCache;
|
|
15
16
|
|
|
16
17
|
use super::file::FileOperations;
|
|
17
|
-
use super::inode::{Inode, InodeOperations, Lookup};
|
|
18
|
-
use super::{
|
|
18
|
+
use super::inode::{Identity, Inode, InodeOperations, Lookup};
|
|
19
|
+
use super::{Errno, FileType, Kstat, OpenHow, SuperBlock};
|
|
19
20
|
use crate::hashtable::Hashtable;
|
|
20
21
|
use crate::locking::seqlock::SeqLock;
|
|
21
22
|
use crate::locking::RwSemaphoreGuard;
|
|
@@ -28,11 +29,7 @@ pub trait DentryOperations: Send + Sync {
|
|
|
28
29
|
/// Whether `dentry`, a name the runtime still holds in `dir`, names what
|
|
29
30
|
/// it recorded, as `d_revalidate` answers; `false` has the runtime drop
|
|
30
31
|
/// it and take the name afresh.
|
|
31
|
-
fn revalidate(
|
|
32
|
-
&self,
|
|
33
|
-
dir: &dyn InodeOperations,
|
|
34
|
-
dentry: &Dentry,
|
|
35
|
-
) -> Result<bool, FilesystemError>;
|
|
32
|
+
fn revalidate(&self, dir: &dyn InodeOperations, dentry: &Dentry) -> Result<bool, Errno>;
|
|
36
33
|
|
|
37
34
|
/// Whether `dentry` goes once nothing holds it, rather than stay for the
|
|
38
35
|
/// next walk, as `d_delete` answers. A name whose `revalidate` cannot tell
|
|
@@ -45,11 +42,6 @@ pub trait DentryOperations: Send + Sync {
|
|
|
45
42
|
/// The most names a Filesystem keeps that nothing holds.
|
|
46
43
|
const MAX_CACHED_DENTRIES: NonZeroUsize = NonZeroUsize::new(1024).expect("the bound is not zero");
|
|
47
44
|
|
|
48
|
-
/// Every move of a dentry, as Linux's `rename_lock`, so a walk up its
|
|
49
|
-
/// parents answers where the dentry stood at one instant, and a walk learns of a
|
|
50
|
-
/// move landing meanwhile.
|
|
51
|
-
pub(super) static RENAME_LOCK: SeqLock = SeqLock::new();
|
|
52
|
-
|
|
53
45
|
/// One name of a Filesystem, and where it stands now. Only the VFS makes
|
|
54
46
|
/// one, so a Filesystem reads the name a call is about from it.
|
|
55
47
|
pub struct Dentry {
|
|
@@ -63,12 +55,15 @@ pub struct Dentry {
|
|
|
63
55
|
/// What the Filesystem keeps on the name, set once, as Linux's
|
|
64
56
|
/// `d_fsdata` holds a filesystem's own state for a dentry.
|
|
65
57
|
fsdata: OnceLock<Arc<dyn Any + Send + Sync>>,
|
|
66
|
-
/// What answers about this name, as `d_alloc` copies `
|
|
58
|
+
/// What answers about this name, as `d_alloc` copies `__s_d_op` from the
|
|
67
59
|
/// super block.
|
|
68
60
|
ops: Option<Arc<dyn DentryOperations>>,
|
|
69
61
|
/// Wakes the walks waiting while another looks this name up, as Linux's
|
|
70
62
|
/// `d_wait_lookup` waits for `DCACHE_PAR_LOOKUP` to clear.
|
|
71
63
|
wait: Condvar,
|
|
64
|
+
/// How many mount namespaces stand a mount on it, as Linux's
|
|
65
|
+
/// `DCACHE_MOUNTED` marks a mount point while any mount stands there.
|
|
66
|
+
mounts: AtomicUsize,
|
|
72
67
|
}
|
|
73
68
|
|
|
74
69
|
/// Where a walk asking for a lookup stands, as `d_alloc_parallel` answers.
|
|
@@ -106,9 +101,9 @@ enum LookupState {
|
|
|
106
101
|
Unasked,
|
|
107
102
|
/// In lookup for the walk that made the dentry, which has yet to ask, as
|
|
108
103
|
/// `d_alloc_parallel` marks the dentry it makes.
|
|
109
|
-
Allocated(
|
|
104
|
+
Allocated(TaskId),
|
|
110
105
|
/// The walk asking the Filesystem what stands here, while it asks.
|
|
111
|
-
Asking(
|
|
106
|
+
Asking(TaskId),
|
|
112
107
|
/// A lookup answered for the name, or a call made what stands there.
|
|
113
108
|
Answered,
|
|
114
109
|
}
|
|
@@ -133,9 +128,26 @@ impl Dentry {
|
|
|
133
128
|
fsdata: OnceLock::new(),
|
|
134
129
|
ops,
|
|
135
130
|
wait: Condvar::new(),
|
|
131
|
+
mounts: AtomicUsize::new(0),
|
|
136
132
|
})
|
|
137
133
|
}
|
|
138
134
|
|
|
135
|
+
/// A mount stands on it from now on, as Linux's `d_set_mounted`.
|
|
136
|
+
pub(crate) fn d_set_mounted(&self) {
|
|
137
|
+
self.mounts.fetch_add(1, Ordering::SeqCst);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/// A mount standing on it is gone, as `unpin_mountpoint` lets go of it and
|
|
141
|
+
/// `maybe_free_mountpoint` clears `DCACHE_MOUNTED` once the last one goes.
|
|
142
|
+
pub(crate) fn unpin_mountpoint(&self) {
|
|
143
|
+
self.mounts.fetch_sub(1, Ordering::SeqCst);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/// Whether a mount stands on it, as Linux's `d_mountpoint`.
|
|
147
|
+
pub(crate) fn d_mountpoint(&self) -> bool {
|
|
148
|
+
self.mounts.load(Ordering::SeqCst) > 0
|
|
149
|
+
}
|
|
150
|
+
|
|
139
151
|
/// What answers about this name, the same for every dentry of one
|
|
140
152
|
/// Filesystem.
|
|
141
153
|
pub fn ops(&self) -> Option<&Arc<dyn DentryOperations>> {
|
|
@@ -189,8 +201,8 @@ impl Dentry {
|
|
|
189
201
|
|
|
190
202
|
/// Each name from the Filesystem's root down to this directory, as Linux's
|
|
191
203
|
/// `__dentry_path` walks up until `IS_ROOT`.
|
|
192
|
-
|
|
193
|
-
|
|
204
|
+
fn names(&self) -> Vec<String> {
|
|
205
|
+
self.rename_lock().read(|| {
|
|
194
206
|
let mut names = Vec::new();
|
|
195
207
|
let mut at = self.get();
|
|
196
208
|
while !at.is_root() {
|
|
@@ -205,14 +217,14 @@ impl Dentry {
|
|
|
205
217
|
|
|
206
218
|
/// Hold the directory this names shared, as
|
|
207
219
|
/// `inode_lock_shared(d_inode(dentry))`.
|
|
208
|
-
pub(crate) fn inode_lock_shared(&self) -> Result<RwSemaphoreGuard,
|
|
209
|
-
self.inode().ok_or(
|
|
220
|
+
pub(crate) fn inode_lock_shared(&self) -> Result<RwSemaphoreGuard, Errno> {
|
|
221
|
+
self.inode().ok_or(Errno::NotFound)?.lock_shared()
|
|
210
222
|
}
|
|
211
223
|
|
|
212
224
|
/// Hold the directory this names exclusive, as
|
|
213
225
|
/// `inode_lock(d_inode(dentry))`.
|
|
214
|
-
pub(crate) fn inode_lock(&self) -> Result<RwSemaphoreGuard,
|
|
215
|
-
self.inode().ok_or(
|
|
226
|
+
pub(crate) fn inode_lock(&self) -> Result<RwSemaphoreGuard, Errno> {
|
|
227
|
+
self.inode().ok_or(Errno::NotFound)?.lock()
|
|
216
228
|
}
|
|
217
229
|
|
|
218
230
|
/// Whether the directory this names was removed or replaced, as
|
|
@@ -235,10 +247,10 @@ impl Dentry {
|
|
|
235
247
|
}
|
|
236
248
|
|
|
237
249
|
/// What answers for the entry this names, as `d_inode(dentry)->i_op`.
|
|
238
|
-
pub(crate) fn inode_ops(&self) -> Result<Arc<dyn InodeOperations>,
|
|
250
|
+
pub(crate) fn inode_ops(&self) -> Result<Arc<dyn InodeOperations>, Errno> {
|
|
239
251
|
match self.inode() {
|
|
240
252
|
Some(inode) => Ok(inode.ops().clone()),
|
|
241
|
-
None => Err(
|
|
253
|
+
None => Err(Errno::NotFound),
|
|
242
254
|
}
|
|
243
255
|
}
|
|
244
256
|
|
|
@@ -249,7 +261,7 @@ impl Dentry {
|
|
|
249
261
|
/// must see.
|
|
250
262
|
pub fn add(&self, inode: Option<Arc<Inode>>) {
|
|
251
263
|
match inode {
|
|
252
|
-
Some(inode) => inode.add_hashed(self),
|
|
264
|
+
Some(inode) => self.hashtables.iget5_locked(inode).add_hashed(self),
|
|
253
265
|
None => self.rehash(),
|
|
254
266
|
}
|
|
255
267
|
}
|
|
@@ -301,7 +313,7 @@ impl Dentry {
|
|
|
301
313
|
pub(super) fn __instantiate(&self, inode: Arc<Inode>, held: &mut Weak<Dentry>) {
|
|
302
314
|
let mut state = self.state();
|
|
303
315
|
if state.inode.is_none() {
|
|
304
|
-
if inode.
|
|
316
|
+
if inode.file_type() == FileType::Dir {
|
|
305
317
|
*held = self.this.clone();
|
|
306
318
|
}
|
|
307
319
|
state.inode = Some(inode);
|
|
@@ -346,7 +358,7 @@ impl Dentry {
|
|
|
346
358
|
&self,
|
|
347
359
|
sb: &SuperBlock,
|
|
348
360
|
dir: &Dentry,
|
|
349
|
-
) -> Result<Option<Arc<Dentry>>,
|
|
361
|
+
) -> Result<Option<Arc<Dentry>>, Errno> {
|
|
350
362
|
let asked = self.ask_in_lookup(|| {
|
|
351
363
|
let found = dir.inode_ops()?.lookup(self)?;
|
|
352
364
|
self.splice_alias(sb, found)
|
|
@@ -359,18 +371,14 @@ impl Dentry {
|
|
|
359
371
|
/// holds the dentry in lookup, and `d_lookup_done` ends that.
|
|
360
372
|
pub(crate) fn ask_in_lookup<T>(
|
|
361
373
|
&self,
|
|
362
|
-
ask: impl FnOnce() -> Result<T,
|
|
363
|
-
) -> Result<Option<T>,
|
|
364
|
-
let
|
|
374
|
+
ask: impl FnOnce() -> Result<T, Errno>,
|
|
375
|
+
) -> Result<Option<T>, Errno> {
|
|
376
|
+
let _ends = match self.begin_lookup()? {
|
|
365
377
|
InLookup::Answered => return Ok(None),
|
|
366
|
-
InLookup::Begun =>
|
|
367
|
-
InLookup::Within =>
|
|
378
|
+
InLookup::Begun => Some(LookupDone(self)),
|
|
379
|
+
InLookup::Within => None,
|
|
368
380
|
};
|
|
369
|
-
|
|
370
|
-
if ends {
|
|
371
|
-
self.lookup_done();
|
|
372
|
-
}
|
|
373
|
-
asked.map(Some)
|
|
381
|
+
ask().map(Some)
|
|
374
382
|
}
|
|
375
383
|
|
|
376
384
|
/// Record what a lookup found at this name of `sb`, as Linux's
|
|
@@ -385,9 +393,9 @@ impl Dentry {
|
|
|
385
393
|
&self,
|
|
386
394
|
sb: &SuperBlock,
|
|
387
395
|
found: Lookup,
|
|
388
|
-
) -> Result<Option<Arc<Dentry>>,
|
|
396
|
+
) -> Result<Option<Arc<Dentry>>, Errno> {
|
|
389
397
|
let inode = match found {
|
|
390
|
-
Lookup::Found(inode) => inode,
|
|
398
|
+
Lookup::Found(inode) => self.hashtables.iget5_locked(inode),
|
|
391
399
|
Lookup::Absent => {
|
|
392
400
|
self.add(None);
|
|
393
401
|
return Ok(None);
|
|
@@ -413,7 +421,7 @@ impl Dentry {
|
|
|
413
421
|
sb: &SuperBlock,
|
|
414
422
|
name: &str,
|
|
415
423
|
inode: Arc<Inode>,
|
|
416
|
-
) -> Result<Arc<Dentry>,
|
|
424
|
+
) -> Result<Arc<Dentry>, Errno> {
|
|
417
425
|
let found = sb.dentries().alloc_parallel(&self.parent(), name)?;
|
|
418
426
|
let spliced = found.ask_in_lookup(|| found.splice_alias(sb, Lookup::Found(inode)))?;
|
|
419
427
|
Ok(spliced.flatten().unwrap_or(found))
|
|
@@ -427,22 +435,18 @@ impl Dentry {
|
|
|
427
435
|
/// directory's lock and the instance's `rename_mutex` without waiting,
|
|
428
436
|
/// since the caller holds the lock of the one it looks the name up in,
|
|
429
437
|
/// and answers ESTALE where another call holds either.
|
|
430
|
-
fn unalias(
|
|
431
|
-
self: &Arc<Self>,
|
|
432
|
-
sb: &SuperBlock,
|
|
433
|
-
alias: &Arc<Dentry>,
|
|
434
|
-
) -> Result<(), FilesystemError> {
|
|
438
|
+
fn unalias(self: &Arc<Self>, sb: &SuperBlock, alias: &Arc<Dentry>) -> Result<(), Errno> {
|
|
435
439
|
let (parent, name) = self.parent_and_name();
|
|
436
440
|
let mut table = self.hashtables.dentry_hashtable();
|
|
437
|
-
|
|
441
|
+
self.rename_lock().write(|| {
|
|
438
442
|
if d_ancestor(alias, self) || alias.is_root() {
|
|
439
|
-
return Err(
|
|
443
|
+
return Err(Errno::FilesystemLoop);
|
|
440
444
|
}
|
|
441
445
|
let (old_parent, old_name) = alias.parent_and_name();
|
|
442
446
|
let _held = match Arc::ptr_eq(&old_parent, &parent) {
|
|
443
447
|
true => None,
|
|
444
448
|
false => {
|
|
445
|
-
let stale = ||
|
|
449
|
+
let stale = || Errno::StaleNetworkFileHandle;
|
|
446
450
|
let rename = sb.rename_mutex().down_write_trylock().ok_or_else(stale)?;
|
|
447
451
|
let dir = old_parent
|
|
448
452
|
.inode()
|
|
@@ -467,7 +471,7 @@ impl Dentry {
|
|
|
467
471
|
/// nobody asked yet, once no other walk holds it. A Filesystem asking the
|
|
468
472
|
/// runtime about the name its own lookup is answering asks it again within
|
|
469
473
|
/// that lookup, as it would otherwise wait on itself.
|
|
470
|
-
fn begin_lookup(&self) -> Result<InLookup,
|
|
474
|
+
fn begin_lookup(&self) -> Result<InLookup, Errno> {
|
|
471
475
|
self.wait_lookup()?;
|
|
472
476
|
let mut state = self.state();
|
|
473
477
|
Ok(match state.asked {
|
|
@@ -483,9 +487,10 @@ impl Dentry {
|
|
|
483
487
|
/// Wait while another walk holds this name in lookup, until the walk's run
|
|
484
488
|
/// is to stop, as Linux's `d_wait_lookup` does, answering whether the
|
|
485
489
|
/// calling walk holds it in lookup itself.
|
|
486
|
-
fn wait_lookup(&self) -> Result<bool,
|
|
490
|
+
fn wait_lookup(&self) -> Result<bool, Errno> {
|
|
487
491
|
let current = sched::current();
|
|
488
492
|
loop {
|
|
493
|
+
sched::handle_signal();
|
|
489
494
|
let state = self.state();
|
|
490
495
|
match state.asked {
|
|
491
496
|
LookupState::Allocated(walk) | LookupState::Asking(walk) if walk == current => {
|
|
@@ -494,7 +499,7 @@ impl Dentry {
|
|
|
494
499
|
LookupState::Allocated(_) | LookupState::Asking(_)
|
|
495
500
|
if sched::fatal_signal_pending() =>
|
|
496
501
|
{
|
|
497
|
-
return Err(
|
|
502
|
+
return Err(Errno::Interrupted)
|
|
498
503
|
}
|
|
499
504
|
LookupState::Allocated(_) | LookupState::Asking(_) => {
|
|
500
505
|
drop(state);
|
|
@@ -544,48 +549,55 @@ impl Dentry {
|
|
|
544
549
|
|
|
545
550
|
/// What kind of entry this records, `NotFound` where it records none, as
|
|
546
551
|
/// Linux's `d_is_*` read a dentry without asking its filesystem.
|
|
547
|
-
pub(crate) fn
|
|
552
|
+
pub(crate) fn file_type(&self) -> Result<FileType, Errno> {
|
|
548
553
|
self.inode()
|
|
549
|
-
.map(|inode| inode.
|
|
550
|
-
.ok_or(
|
|
554
|
+
.map(|inode| inode.file_type())
|
|
555
|
+
.ok_or(Errno::NotFound)
|
|
551
556
|
}
|
|
552
557
|
|
|
553
558
|
/// What the entry this records reports of itself, `NotFound` where it
|
|
554
559
|
/// records none, as `vfs_getattr` asks the inode a dentry holds.
|
|
555
|
-
pub(crate) fn getattr(&self) -> Result<Kstat,
|
|
560
|
+
pub(crate) fn getattr(&self) -> Result<Kstat, Errno> {
|
|
556
561
|
match self.inode() {
|
|
557
562
|
Some(inode) => inode.ops().getattr(self),
|
|
558
|
-
None => Err(
|
|
563
|
+
None => Err(Errno::NotFound),
|
|
559
564
|
}
|
|
560
565
|
}
|
|
561
566
|
|
|
562
567
|
/// Open the file this records as `how` asks, as `vfs_open` finds
|
|
563
568
|
/// `f_op->open` on the inode a dentry holds.
|
|
564
|
-
pub(crate) fn open(&self, how: &OpenHow) -> Result<Box<dyn FileOperations>,
|
|
569
|
+
pub(crate) fn open(&self, how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
|
|
565
570
|
match self.inode() {
|
|
566
571
|
Some(inode) => inode.ops().open(self, how),
|
|
567
|
-
None => Err(
|
|
572
|
+
None => Err(Errno::NotFound),
|
|
568
573
|
}
|
|
569
574
|
}
|
|
570
575
|
|
|
571
576
|
/// Where the link this records points, as `vfs_readlink` asks the inode a
|
|
572
577
|
/// dentry holds; anything else refuses as `readlinkat` does.
|
|
573
|
-
pub(crate) fn get_link(&self) -> Result<String,
|
|
578
|
+
pub(crate) fn get_link(&self) -> Result<String, Errno> {
|
|
574
579
|
match self.inode() {
|
|
575
580
|
Some(inode) => inode.ops().get_link(self),
|
|
576
|
-
None => Err(
|
|
581
|
+
None => Err(Errno::NotFound),
|
|
577
582
|
}
|
|
578
583
|
}
|
|
579
584
|
|
|
580
585
|
/// Whether this dentry is `ancestor` or stands beneath it, as Linux's
|
|
581
586
|
/// `is_subdir` answers.
|
|
582
587
|
pub(crate) fn is_subdir(self: &Arc<Self>, ancestor: &Arc<Dentry>) -> bool {
|
|
583
|
-
Arc::ptr_eq(self, ancestor) ||
|
|
588
|
+
Arc::ptr_eq(self, ancestor) || self.rename_lock().read(|| d_ancestor(ancestor, self))
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
/// What every move of a dentry of this Filesystem writes, so a walk up
|
|
592
|
+
/// its parents answers where the dentry stood at one instant, and a walk
|
|
593
|
+
/// learns of a move landing meanwhile.
|
|
594
|
+
pub(super) fn rename_lock(&self) -> &SeqLock {
|
|
595
|
+
&self.hashtables.rename_lock
|
|
584
596
|
}
|
|
585
597
|
}
|
|
586
598
|
|
|
587
599
|
/// Whether `ancestor` stands above `dentry`, as Linux's `d_ancestor` answers.
|
|
588
|
-
/// The caller holds
|
|
600
|
+
/// The caller holds the rename lock, so no move lands during the walk up.
|
|
589
601
|
fn d_ancestor(ancestor: &Arc<Dentry>, dentry: &Arc<Dentry>) -> bool {
|
|
590
602
|
let mut at = dentry.clone();
|
|
591
603
|
while !at.is_root() {
|
|
@@ -597,6 +609,18 @@ fn d_ancestor(ancestor: &Arc<Dentry>, dentry: &Arc<Dentry>) -> bool {
|
|
|
597
609
|
false
|
|
598
610
|
}
|
|
599
611
|
|
|
612
|
+
/// Ends the lookup its walk began on a dentry once it goes, as Linux's
|
|
613
|
+
/// `d_lookup_done` follows every return from `->lookup`. A panic unwinding
|
|
614
|
+
/// past it ends the lookup too, an exit the kernel has no counterpart for, so
|
|
615
|
+
/// the walks waiting on the name go on.
|
|
616
|
+
struct LookupDone<'a>(&'a Dentry);
|
|
617
|
+
|
|
618
|
+
impl Drop for LookupDone<'_> {
|
|
619
|
+
fn drop(&mut self) {
|
|
620
|
+
self.0.lookup_done();
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
|
|
600
624
|
/// A dentry holds the one above it, and moves can stack them as deep as a
|
|
601
625
|
/// Filesystem holds directories, so the last reference lets go of each in a
|
|
602
626
|
/// loop, as Linux's `dput` walks up in one.
|
|
@@ -625,16 +649,52 @@ fn key(parent: &Arc<Dentry>, name: &str) -> Key {
|
|
|
625
649
|
}
|
|
626
650
|
|
|
627
651
|
/// The dentries of one Filesystem a walk finds by the directory above and the
|
|
628
|
-
/// name there.
|
|
652
|
+
/// name there, and the lock every move among them writes.
|
|
629
653
|
struct Hashtables {
|
|
654
|
+
/// Written by every move of a dentry, as Linux's `rename_lock`. It is the
|
|
655
|
+
/// instance's rather than the process's, since a move never crosses
|
|
656
|
+
/// Filesystems: a walk learns only of the moves that could carry its
|
|
657
|
+
/// directories, and a Sandbox learns nothing of another's moves.
|
|
658
|
+
rename_lock: SeqLock,
|
|
630
659
|
/// Those a lookup answered, as Linux's `dentry_hashtable`.
|
|
631
660
|
dentry_hashtable: Mutex<Hashtable<Key, Dentry>>,
|
|
632
661
|
/// Those a walk is still looking up, as Linux's `in_lookup_hashtable`, so
|
|
633
662
|
/// any other walk reaching the name waits for that answer.
|
|
634
663
|
in_lookup_hashtable: Mutex<Hashtable<Key, Dentry>>,
|
|
664
|
+
/// The directories in use, by the identity each reports, as Linux's
|
|
665
|
+
/// `inode_hashtable`, so a directory a Filesystem answers anew is the
|
|
666
|
+
/// inode it already was and keeps its one dentry.
|
|
667
|
+
inode_hashtable: Mutex<Hashtable<Identity, Inode>>,
|
|
635
668
|
}
|
|
636
669
|
|
|
637
670
|
impl Hashtables {
|
|
671
|
+
/// The inode in use for the directory `inode` reports, or `inode` itself,
|
|
672
|
+
/// kept for the next lookup, as `iget5_locked` finds a live inode by its
|
|
673
|
+
/// number before it hands a new one. A directory removed is found no more,
|
|
674
|
+
/// and an entry naming no identity is never kept.
|
|
675
|
+
fn iget5_locked(&self, inode: Arc<Inode>) -> Arc<Inode> {
|
|
676
|
+
let Some(identity) = inode
|
|
677
|
+
.identity()
|
|
678
|
+
.filter(|_| inode.file_type() == FileType::Dir)
|
|
679
|
+
else {
|
|
680
|
+
return inode;
|
|
681
|
+
};
|
|
682
|
+
let mut table = self.inode_hashtable();
|
|
683
|
+
match table.get(&identity) {
|
|
684
|
+
Some(found) if found.file_type() == FileType::Dir && !found.is_deaddir() => found,
|
|
685
|
+
_ => {
|
|
686
|
+
table.insert(identity, &inode);
|
|
687
|
+
inode
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
fn inode_hashtable(&self) -> MutexGuard<'_, Hashtable<Identity, Inode>> {
|
|
693
|
+
self.inode_hashtable
|
|
694
|
+
.lock()
|
|
695
|
+
.unwrap_or_else(PoisonError::into_inner)
|
|
696
|
+
}
|
|
697
|
+
|
|
638
698
|
fn dentry_hashtable(&self) -> MutexGuard<'_, Hashtable<Key, Dentry>> {
|
|
639
699
|
self.dentry_hashtable
|
|
640
700
|
.lock()
|
|
@@ -662,8 +722,10 @@ pub(crate) struct Dentries {
|
|
|
662
722
|
impl Dentries {
|
|
663
723
|
pub(crate) fn new(ops: Option<Arc<dyn DentryOperations>>) -> Self {
|
|
664
724
|
let hashtables = Arc::new(Hashtables {
|
|
725
|
+
rename_lock: SeqLock::new(),
|
|
665
726
|
dentry_hashtable: Mutex::default(),
|
|
666
727
|
in_lookup_hashtable: Mutex::default(),
|
|
728
|
+
inode_hashtable: Mutex::default(),
|
|
667
729
|
});
|
|
668
730
|
Self {
|
|
669
731
|
ops,
|
|
@@ -704,7 +766,7 @@ impl Dentries {
|
|
|
704
766
|
}
|
|
705
767
|
|
|
706
768
|
/// Have every dentry made from now on answer through `ops`, as
|
|
707
|
-
/// `set_default_d_op` sets `
|
|
769
|
+
/// `set_default_d_op` sets `__s_d_op` for each `d_alloc` after it.
|
|
708
770
|
pub(super) fn set_ops(&mut self, ops: Arc<dyn DentryOperations>) {
|
|
709
771
|
self.ops = Some(ops);
|
|
710
772
|
}
|
|
@@ -733,7 +795,7 @@ impl Dentries {
|
|
|
733
795
|
&self,
|
|
734
796
|
parent: &Arc<Dentry>,
|
|
735
797
|
name: &str,
|
|
736
|
-
) -> Result<Arc<Dentry>,
|
|
798
|
+
) -> Result<Arc<Dentry>, Errno> {
|
|
737
799
|
let at = key(parent, name);
|
|
738
800
|
loop {
|
|
739
801
|
let waited = {
|
|
@@ -779,14 +841,21 @@ impl Dentries {
|
|
|
779
841
|
!dentry.is_root() && !dentry.hashed()
|
|
780
842
|
}
|
|
781
843
|
|
|
782
|
-
/// Let go of `dentry`, which no longer names what
|
|
783
|
-
/// of the names kept beneath it, as Linux's
|
|
784
|
-
/// shrinks what is below a positive one.
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
844
|
+
/// Let go of `dentry`, which no longer names what stood at its name when
|
|
845
|
+
/// its rename lock read `asked`, and of the names kept beneath it, as Linux's
|
|
846
|
+
/// `d_invalidate` drops it and shrinks what is below a positive one. One a
|
|
847
|
+
/// move carried elsewhere since stays where it went: every move takes this
|
|
848
|
+
/// table before it writes, so none lands between the check and the drop.
|
|
849
|
+
pub(crate) fn invalidate(&self, dentry: &Arc<Dentry>, asked: usize) {
|
|
850
|
+
{
|
|
851
|
+
let mut table = self.hashtables.dentry_hashtable();
|
|
852
|
+
if self.hashtables.rename_lock.read_seqretry(asked) || !dentry.hashed() {
|
|
853
|
+
return;
|
|
854
|
+
}
|
|
855
|
+
drop_hashed(&mut table, dentry);
|
|
788
856
|
}
|
|
789
|
-
self.
|
|
857
|
+
let kept = self.lru().pop(&(Arc::as_ptr(dentry) as usize));
|
|
858
|
+
drop(kept);
|
|
790
859
|
if dentry.inode().is_some() {
|
|
791
860
|
self.shrink_dcache_parent(dentry);
|
|
792
861
|
}
|
|
@@ -832,7 +901,7 @@ impl Dentries {
|
|
|
832
901
|
let mut table = self.hashtables.dentry_hashtable();
|
|
833
902
|
let (parent, name) = target.parent_and_name();
|
|
834
903
|
let (from, from_name) = dentry.parent_and_name();
|
|
835
|
-
|
|
904
|
+
self.hashtables.rename_lock.write(|| {
|
|
836
905
|
let mut state = dentry.state();
|
|
837
906
|
if state.hashed {
|
|
838
907
|
table.remove(&key(&from, &from_name));
|
|
@@ -850,7 +919,7 @@ impl Dentries {
|
|
|
850
919
|
pub(crate) fn exchange(&self, first: &Arc<Dentry>, second: &Arc<Dentry>) {
|
|
851
920
|
let mut table = self.hashtables.dentry_hashtable();
|
|
852
921
|
let (first_at, second_at) = (first.parent_and_name(), second.parent_and_name());
|
|
853
|
-
|
|
922
|
+
self.hashtables.rename_lock.write(|| {
|
|
854
923
|
let (mut one, mut other) = (first.state(), second.state());
|
|
855
924
|
for (state, (parent, name)) in [(&one, &first_at), (&other, &second_at)] {
|
|
856
925
|
if state.hashed {
|
|
@@ -883,12 +952,12 @@ mod tests {
|
|
|
883
952
|
|
|
884
953
|
use super::{Dentries, Dentry};
|
|
885
954
|
use crate::filesystem::{
|
|
886
|
-
FileOperations, FileType, Filesystem,
|
|
887
|
-
Tmpfs,
|
|
955
|
+
FileOperations, FileType, Filesystem, InodeOperations, Kstat, Lookup, Tmpfs,
|
|
888
956
|
};
|
|
889
957
|
use crate::mount::{Access, Mount};
|
|
890
958
|
use crate::vfs::kern_path::{kern_path, KernPath};
|
|
891
959
|
use crate::vfs::{self, File, Finish, Identity, Inode, OpenHow, Path};
|
|
960
|
+
use crate::Errno;
|
|
892
961
|
|
|
893
962
|
/// A root of `dentries` standing for a directory, as `d_make_root` makes one.
|
|
894
963
|
fn make_dir_root(dentries: &Dentries) -> Arc<Dentry> {
|
|
@@ -923,17 +992,13 @@ mod tests {
|
|
|
923
992
|
/// A name it recorded nothing for is looked up again, as a Ruby Filesystem's
|
|
924
993
|
/// `revalidate` answers, so one it made is found where the make left it.
|
|
925
994
|
impl super::DentryOperations for ByPath {
|
|
926
|
-
fn revalidate(
|
|
927
|
-
&self,
|
|
928
|
-
_dir: &dyn InodeOperations,
|
|
929
|
-
dentry: &Dentry,
|
|
930
|
-
) -> Result<bool, FilesystemError> {
|
|
995
|
+
fn revalidate(&self, _dir: &dyn InodeOperations, dentry: &Dentry) -> Result<bool, Errno> {
|
|
931
996
|
Ok(dentry.inode().is_some())
|
|
932
997
|
}
|
|
933
998
|
}
|
|
934
999
|
|
|
935
1000
|
impl crate::vfs::FileSystemType for ByPath {
|
|
936
|
-
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(),
|
|
1001
|
+
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
|
|
937
1002
|
sb.set_default_d_op(self.clone());
|
|
938
1003
|
sb.d_make_root(Inode::new(&Kstat::new(FileType::Dir, 0), self));
|
|
939
1004
|
Ok(())
|
|
@@ -941,11 +1006,11 @@ mod tests {
|
|
|
941
1006
|
}
|
|
942
1007
|
|
|
943
1008
|
impl InodeOperations for ByPath {
|
|
944
|
-
fn getattr(&self, dentry: &Dentry) -> Result<Kstat,
|
|
1009
|
+
fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
945
1010
|
self.root.vfs_lstat(&at(dentry))
|
|
946
1011
|
}
|
|
947
1012
|
|
|
948
|
-
fn lookup(&self, dentry: &Dentry) -> Result<Lookup,
|
|
1013
|
+
fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
|
|
949
1014
|
match self.root.vfs_lstat(&at(dentry)) {
|
|
950
1015
|
Ok(found) => Ok(Lookup::Found(Inode::new(
|
|
951
1016
|
&found,
|
|
@@ -953,23 +1018,19 @@ mod tests {
|
|
|
953
1018
|
root: self.root.clone(),
|
|
954
1019
|
}),
|
|
955
1020
|
))),
|
|
956
|
-
Err(
|
|
1021
|
+
Err(Errno::NotFound) => Ok(Lookup::Absent),
|
|
957
1022
|
Err(err) => Err(err),
|
|
958
1023
|
}
|
|
959
1024
|
}
|
|
960
1025
|
|
|
961
|
-
fn open(
|
|
962
|
-
|
|
963
|
-
dentry: &Dentry,
|
|
964
|
-
how: &OpenHow,
|
|
965
|
-
) -> Result<Box<dyn FileOperations>, FilesystemError> {
|
|
966
|
-
if dentry.kind() == Ok(FileType::Dir) {
|
|
1026
|
+
fn open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
|
|
1027
|
+
if dentry.file_type() == Ok(FileType::Dir) {
|
|
967
1028
|
return Ok(Box::new(ByPathDir(self.root.clone())));
|
|
968
1029
|
}
|
|
969
1030
|
self.root.open(&at(dentry), how)
|
|
970
1031
|
}
|
|
971
1032
|
|
|
972
|
-
fn atomic_open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Finish,
|
|
1033
|
+
fn atomic_open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Finish, Errno> {
|
|
973
1034
|
if dentry.in_lookup() {
|
|
974
1035
|
let found = self.lookup(dentry)?;
|
|
975
1036
|
if !how.create || !matches!(found, Lookup::Absent) {
|
|
@@ -986,29 +1047,29 @@ mod tests {
|
|
|
986
1047
|
})
|
|
987
1048
|
}
|
|
988
1049
|
|
|
989
|
-
fn mkdir(&self, dentry: &Dentry) -> Result<(),
|
|
1050
|
+
fn mkdir(&self, dentry: &Dentry) -> Result<(), Errno> {
|
|
990
1051
|
self.root.vfs_mkdir(&at(dentry))
|
|
991
1052
|
}
|
|
992
1053
|
|
|
993
|
-
fn rmdir(&self, dentry: &Dentry) -> Result<(),
|
|
1054
|
+
fn rmdir(&self, dentry: &Dentry) -> Result<(), Errno> {
|
|
994
1055
|
self.root.vfs_rmdir(&at(dentry))
|
|
995
1056
|
}
|
|
996
1057
|
|
|
997
|
-
fn unlink(&self, dentry: &Dentry) -> Result<(),
|
|
1058
|
+
fn unlink(&self, dentry: &Dentry) -> Result<(), Errno> {
|
|
998
1059
|
self.root.vfs_unlink(&at(dentry))
|
|
999
1060
|
}
|
|
1000
1061
|
|
|
1001
1062
|
fn rename(
|
|
1002
1063
|
&self,
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
) -> Result<(),
|
|
1008
|
-
(
|
|
1064
|
+
old: &Dentry,
|
|
1065
|
+
new_dir: &dyn InodeOperations,
|
|
1066
|
+
new: &Dentry,
|
|
1067
|
+
_flags: Option<crate::vfs::RenameFlag>,
|
|
1068
|
+
) -> Result<(), Errno> {
|
|
1069
|
+
(new_dir as &dyn Any)
|
|
1009
1070
|
.downcast_ref::<Self>()
|
|
1010
|
-
.ok_or(
|
|
1011
|
-
self.root.rename(&at(
|
|
1071
|
+
.ok_or(Errno::CrossesDevices)?;
|
|
1072
|
+
self.root.rename(&at(old), &self.root, &at(new))
|
|
1012
1073
|
}
|
|
1013
1074
|
}
|
|
1014
1075
|
|
|
@@ -1016,23 +1077,27 @@ mod tests {
|
|
|
1016
1077
|
struct ByPathDir(KernPath);
|
|
1017
1078
|
|
|
1018
1079
|
impl FileOperations for ByPathDir {
|
|
1080
|
+
fn has_iterate_shared(&self) -> bool {
|
|
1081
|
+
true
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1019
1084
|
fn iterate_shared(
|
|
1020
1085
|
&mut self,
|
|
1021
1086
|
dentry: &Dentry,
|
|
1022
1087
|
ctx: &mut vfs::DirContext<'_>,
|
|
1023
|
-
) -> Result<(),
|
|
1088
|
+
) -> Result<(), Errno> {
|
|
1024
1089
|
let entries = match at(dentry).as_str() {
|
|
1025
1090
|
"" => self.0.iterate_dir(),
|
|
1026
1091
|
at => self.0.open_dir(at)?.iterate_dir(),
|
|
1027
1092
|
}?;
|
|
1028
|
-
crate::filesystem::Rdir::default().
|
|
1093
|
+
crate::filesystem::Rdir::default().iterate_shared(dentry, ctx, || Ok(entries))
|
|
1029
1094
|
}
|
|
1030
1095
|
}
|
|
1031
1096
|
|
|
1032
1097
|
fn by_path(tmpfs: &Arc<Tmpfs>) -> Arc<Filesystem> {
|
|
1033
|
-
Filesystem::new(
|
|
1098
|
+
Filesystem::new(ByPath {
|
|
1034
1099
|
root: kern_path(tmpfs.clone()),
|
|
1035
|
-
})
|
|
1100
|
+
})
|
|
1036
1101
|
.expect("the instance must stand")
|
|
1037
1102
|
}
|
|
1038
1103
|
|
|
@@ -1084,16 +1149,44 @@ mod tests {
|
|
|
1084
1149
|
let lock = lock.clone();
|
|
1085
1150
|
thread::spawn(move || lock.read_seqbegin())
|
|
1086
1151
|
};
|
|
1087
|
-
|
|
1152
|
+
crate::sched::testing::wait_until("the walk waiting for the move or answering", || {
|
|
1153
|
+
lock.waiting() == 1 || reader.is_finished()
|
|
1154
|
+
});
|
|
1088
1155
|
let waited = !reader.is_finished();
|
|
1089
1156
|
release.send(()).ok();
|
|
1090
|
-
crate::sched::testing::join("the
|
|
1091
|
-
let begun = crate::sched::testing::join("the
|
|
1157
|
+
crate::sched::testing::join("the move", writer);
|
|
1158
|
+
let begun = crate::sched::testing::join("the walk", reader);
|
|
1092
1159
|
assert_eq!(
|
|
1093
1160
|
(waited, begun, lock.read_seqretry(begun)),
|
|
1094
1161
|
(true, 2, false),
|
|
1095
|
-
"
|
|
1096
|
-
|
|
1162
|
+
"a walk begun while a move is under way must wait for the move to land and begin \
|
|
1163
|
+
where the moves stand after it, which no later walk finds changed"
|
|
1164
|
+
);
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
// @behavior RT-407
|
|
1168
|
+
#[test]
|
|
1169
|
+
fn a_walk_begun_after_a_move_panicked_begins_at_once() {
|
|
1170
|
+
use crate::locking::seqlock::SeqLock;
|
|
1171
|
+
use std::thread;
|
|
1172
|
+
|
|
1173
|
+
let lock = Arc::new(SeqLock::new());
|
|
1174
|
+
let panicked = {
|
|
1175
|
+
let lock = lock.clone();
|
|
1176
|
+
thread::spawn(move || lock.write(|| panic!("the write panics")))
|
|
1177
|
+
.join()
|
|
1178
|
+
.is_err()
|
|
1179
|
+
};
|
|
1180
|
+
let reader = {
|
|
1181
|
+
let lock = lock.clone();
|
|
1182
|
+
thread::spawn(move || lock.read_seqbegin())
|
|
1183
|
+
};
|
|
1184
|
+
let begun = crate::sched::testing::join("the read", reader);
|
|
1185
|
+
assert_eq!(
|
|
1186
|
+
(panicked, begun),
|
|
1187
|
+
(true, 2),
|
|
1188
|
+
"a walk beginning after a move that panicked must go on at once, the move \
|
|
1189
|
+
counted as ended"
|
|
1097
1190
|
);
|
|
1098
1191
|
}
|
|
1099
1192
|
|
|
@@ -1148,9 +1241,9 @@ mod tests {
|
|
|
1148
1241
|
kern_path(tmpfs.clone()).vfs_lstat("dir/made").err()
|
|
1149
1242
|
),
|
|
1150
1243
|
(
|
|
1151
|
-
Err(
|
|
1152
|
-
Err(
|
|
1153
|
-
Some(
|
|
1244
|
+
Err(Errno::NotFound),
|
|
1245
|
+
Err(Errno::NotFound),
|
|
1246
|
+
Some(Errno::NotFound)
|
|
1154
1247
|
),
|
|
1155
1248
|
"vfs::filename_mkdirat and File::iterate_dir through a directory vfs::filename_rmdir removed, over \
|
|
1156
1249
|
a Filesystem answering by path, must each answer NotFound, as Linux asks \
|
|
@@ -1171,7 +1264,7 @@ mod tests {
|
|
|
1171
1264
|
.expect("another directory must be made");
|
|
1172
1265
|
assert_eq!(
|
|
1173
1266
|
vfs::filename_mkdirat(&Arc::default(), &dir, "made"),
|
|
1174
|
-
Err(
|
|
1267
|
+
Err(Errno::NotFound),
|
|
1175
1268
|
"vfs::filename_mkdirat through a directory opened beneath one Mount, once vfs::filename_rmdir \
|
|
1176
1269
|
removed it beneath another Mount of the same Filesystem, must answer NotFound"
|
|
1177
1270
|
);
|
|
@@ -1222,7 +1315,7 @@ mod tests {
|
|
|
1222
1315
|
"leaf",
|
|
1223
1316
|
));
|
|
1224
1317
|
let beside = kept(negative(&dentries, &root, "other"));
|
|
1225
|
-
dentries.invalidate(&dir);
|
|
1318
|
+
dentries.invalidate(&dir, dir.rename_lock().read_seqbegin());
|
|
1226
1319
|
assert_eq!(
|
|
1227
1320
|
(beneath.upgrade().is_some(), beside.upgrade().is_some()),
|
|
1228
1321
|
(false, true),
|