kobako 0.31.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 +125 -0
- data/Cargo.lock +457 -494
- data/README.md +2 -3
- data/ROADMAP.md +0 -1
- data/crates/kobako-runtime/CHANGELOG.md +90 -0
- data/crates/kobako-runtime/Cargo.toml +14 -15
- data/crates/kobako-runtime/README.md +1 -1
- data/crates/kobako-runtime/src/cred.rs +32 -20
- data/crates/kobako-runtime/src/filesystem/bind/fid.rs +300 -22
- data/crates/kobako-runtime/src/filesystem/bind/lookup.rs +56 -22
- data/crates/kobako-runtime/src/filesystem/bind/unicode.rs +109 -0
- data/crates/kobako-runtime/src/filesystem/bind/walk.rs +33 -14
- data/crates/kobako-runtime/src/filesystem/bind.rs +393 -220
- data/crates/kobako-runtime/src/filesystem/overlay/stack/copy_up.rs +2 -0
- data/crates/kobako-runtime/src/filesystem/overlay/stack.rs +9 -10
- data/crates/kobako-runtime/src/filesystem/overlay.rs +277 -46
- data/crates/kobako-runtime/src/filesystem/rdir.rs +8 -27
- data/crates/kobako-runtime/src/filesystem/testing.rs +31 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs.rs +47 -13
- data/crates/kobako-runtime/src/filesystem.rs +2 -0
- data/crates/kobako-runtime/src/fork.rs +239 -16
- data/crates/kobako-runtime/src/limits.rs +17 -41
- data/crates/kobako-runtime/src/locking/seqlock.rs +29 -3
- data/crates/kobako-runtime/src/locking.rs +508 -113
- data/crates/kobako-runtime/src/memcg.rs +83 -160
- data/crates/kobako-runtime/src/mount.rs +0 -30
- data/crates/kobako-runtime/src/net/connections.rs +53 -13
- data/crates/kobako-runtime/src/net/egress.rs +44 -24
- data/crates/kobako-runtime/src/net/http.rs +888 -456
- data/crates/kobako-runtime/src/net/lookup.rs +150 -50
- data/crates/kobako-runtime/src/net/namespace.rs +97 -95
- data/crates/kobako-runtime/src/net/reactor.rs +298 -203
- data/crates/kobako-runtime/src/net/resolv/darwin.rs +8 -3
- data/crates/kobako-runtime/src/net/resolv/stub/tests.rs +50 -0
- data/crates/kobako-runtime/src/net/resolv/stub.rs +29 -23
- data/crates/kobako-runtime/src/net/resolv/windows.rs +14 -44
- data/crates/kobako-runtime/src/net/resolv.rs +39 -15
- data/crates/kobako-runtime/src/net/skbuff.rs +109 -0
- data/crates/kobako-runtime/src/net/socket.rs +51 -52
- data/crates/kobako-runtime/src/net/task.rs +223 -0
- data/crates/kobako-runtime/src/net/tcp.rs +410 -158
- data/crates/kobako-runtime/src/net/tls.rs +65 -3
- data/crates/kobako-runtime/src/net/transport.rs +72 -47
- data/crates/kobako-runtime/src/net/udp.rs +231 -129
- data/crates/kobako-runtime/src/net.rs +3 -0
- data/crates/kobako-runtime/src/sched.rs +244 -58
- data/crates/kobako-runtime/src/security.rs +27 -16
- data/crates/kobako-runtime/src/vfs/dentry.rs +80 -41
- data/crates/kobako-runtime/src/vfs/file.rs +52 -53
- data/crates/kobako-runtime/src/vfs/kern_path.rs +24 -11
- data/crates/kobako-runtime/src/vfs/namei.rs +399 -184
- data/crates/kobako-runtime/src/vfs/namespace.rs +123 -40
- data/crates/kobako-runtime/src/vfs/stat.rs +105 -16
- data/crates/kobako-runtime/src/vfs.rs +1 -0
- data/crates/kobako-runtime/src/wait.rs +75 -50
- data/crates/kobako-transport/CHANGELOG.md +7 -0
- data/crates/kobako-transport/Cargo.toml +1 -1
- data/crates/kobako-transport/README.md +1 -1
- data/crates/kobako-wasmtime/CHANGELOG.md +47 -0
- data/crates/kobako-wasmtime/Cargo.toml +27 -6
- data/crates/kobako-wasmtime/README.md +3 -3
- data/crates/kobako-wasmtime/src/abi.rs +2 -1
- data/crates/kobako-wasmtime/src/ambient.rs +11 -2
- 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 +88 -103
- data/crates/kobako-wasmtime/src/driver.rs +40 -27
- data/crates/kobako-wasmtime/src/invocation.rs +21 -7
- data/crates/kobako-wasmtime/src/lib.rs +2 -0
- data/crates/kobako-wasmtime/src/limiter.rs +78 -25
- data/crates/kobako-wasmtime/src/preview1/descriptors.rs +13 -17
- data/crates/kobako-wasmtime/src/preview1/differential/mount.rs +4 -5
- data/crates/kobako-wasmtime/src/preview1/differential.rs +1 -1
- data/crates/kobako-wasmtime/src/preview1/fd.rs +23 -19
- data/crates/kobako-wasmtime/src/preview1/mount_view.rs +130 -197
- data/crates/kobako-wasmtime/src/preview1/path.rs +3 -3
- data/crates/kobako-wasmtime/src/preview1/poll.rs +28 -22
- data/crates/kobako-wasmtime/src/preview1/random.rs +125 -0
- data/crates/kobako-wasmtime/src/preview1/testing.rs +31 -0
- data/crates/kobako-wasmtime/src/preview1.rs +85 -9
- data/crates/kobako-wasmtime/src/preview2/filesystem.rs +2 -2
- data/crates/kobako-wasmtime/src/preview2/host.rs +609 -249
- data/crates/kobako-wasmtime/src/preview2/http.rs +299 -215
- data/crates/kobako-wasmtime/src/preview2/io.rs +17 -4
- data/crates/kobako-wasmtime/src/preview2/table.rs +24 -72
- data/crates/kobako-wasmtime/src/trap.rs +68 -23
- data/crates/kobako-wasmtime/src/waits.rs +59 -0
- data/crates/kobako-wasmtime/src/wasi.rs +91 -10
- 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/escape.rs +332 -26
- data/ext/kobako/src/filesystem/grants.rs +5 -7
- data/ext/kobako/src/filesystem/ruby.rs +10 -3
- data/ext/kobako/src/filesystem.rs +47 -8
- data/ext/kobako/src/fork.rs +72 -0
- data/ext/kobako/src/gvl.rs +499 -76
- data/ext/kobako/src/handoff.rs +490 -0
- data/ext/kobako/src/lib.rs +10 -0
- data/ext/kobako/src/network.rs +5 -3
- data/ext/kobako/src/pinned_value.rs +28 -15
- data/ext/kobako/src/runtime/bridge.rs +32 -25
- data/ext/kobako/src/runtime.rs +74 -43
- data/lib/kobako/catalog/handles.rb +9 -5
- data/lib/kobako/codec/decoder.rb +1 -1
- data/lib/kobako/codec/state.rb +2 -18
- data/lib/kobako/codec/value_budget.rb +4 -4
- data/lib/kobako/codec.rb +5 -6
- data/lib/kobako/errors.rb +4 -7
- data/lib/kobako/filesystem.rb +1 -1
- data/lib/kobako/fork.rb +42 -0
- data/lib/kobako/handle.rb +1 -2
- data/lib/kobako/sandbox.rb +17 -36
- data/lib/kobako/sandbox_options.rb +7 -9
- data/lib/kobako/usage.rb +4 -2
- data/lib/kobako/version.rb +1 -1
- data/lib/kobako.rb +2 -2
- data/sig/kobako/catalog/handles.rbs +2 -0
- data/sig/kobako/codec/state.rbs +0 -4
- data/sig/kobako/codec/value_budget.rbs +1 -1
- data/sig/kobako/codec.rbs +2 -2
- data/sig/kobako/errors.rbs +0 -3
- data/sig/kobako/fork.rbs +17 -0
- data/sig/kobako/runtime.rbs +2 -2
- data/sig/kobako/sandbox.rbs +3 -12
- data/sig/kobako/sandbox_options.rbs +0 -2
- metadata +15 -4
- data/lib/kobako/pool.rb +0 -162
- data/sig/core/thread.rbs +0 -6
- data/sig/kobako/pool.rbs +0 -46
|
@@ -9,13 +9,11 @@
|
|
|
9
9
|
//! started from, as `openat2`'s `RESOLVE_BENEATH` keeps a resolution: one
|
|
10
10
|
//! leading out of it, or to an absolute path, escapes it.
|
|
11
11
|
|
|
12
|
-
use std::cell::Cell;
|
|
13
12
|
use std::collections::VecDeque;
|
|
14
|
-
use std::rc::Rc;
|
|
15
13
|
use std::sync::Arc;
|
|
16
14
|
|
|
17
15
|
use super::attr::notify_change;
|
|
18
|
-
use super::dentry::
|
|
16
|
+
use super::dentry::Dentry;
|
|
19
17
|
use super::file::{do_dentry_open, FMode, File, FileOperations};
|
|
20
18
|
use super::inode::{Finish, Inode, Mask, RenameFlag};
|
|
21
19
|
use super::mount::VfsMount;
|
|
@@ -40,6 +38,13 @@ enum LastType {
|
|
|
40
38
|
DotDot,
|
|
41
39
|
}
|
|
42
40
|
|
|
41
|
+
/// Where a walk stood when it stepped onto a mount.
|
|
42
|
+
struct Crossed {
|
|
43
|
+
mnt: Arc<VfsMount>,
|
|
44
|
+
dir: Arc<Dentry>,
|
|
45
|
+
r_seq: usize,
|
|
46
|
+
}
|
|
47
|
+
|
|
43
48
|
/// A path walked beneath a directory, as Linux's `nameidata` carries
|
|
44
49
|
/// one walk from where it starts to the call it ends in: the directories
|
|
45
50
|
/// it stands in, the names still to walk, the last name left for the call to
|
|
@@ -50,26 +55,26 @@ pub(crate) struct Nameidata {
|
|
|
50
55
|
/// The directory the walk started from, which no `..` climbs above, as
|
|
51
56
|
/// `nd->root` holds it for `RESOLVE_BENEATH`.
|
|
52
57
|
root: Arc<Dentry>,
|
|
53
|
-
/// Where
|
|
58
|
+
/// Where the rename lock of the Filesystem the walk stands on stood when
|
|
59
|
+
/// the walk stepped onto it, as `nd->r_seq`. It is that instance's alone,
|
|
60
|
+
/// since only a move on it carries the directories a `..` reads there.
|
|
54
61
|
r_seq: usize,
|
|
55
62
|
/// The directory the walk stands in, which holds the last name.
|
|
56
63
|
dir: Arc<Dentry>,
|
|
57
64
|
/// Where the walk stood each time it stepped onto a mount, innermost last,
|
|
58
|
-
/// so a `..` from that mount's root climbs
|
|
59
|
-
/// follows `mnt_parent`. The walk keeps them
|
|
60
|
-
/// its parent holds no entry for it.
|
|
61
|
-
|
|
65
|
+
/// with the `r_seq` it held there, so a `..` from that mount's root climbs
|
|
66
|
+
/// back, as `choose_mountpoint` follows `mnt_parent`. The walk keeps them
|
|
67
|
+
/// itself: a mount may stand where its parent holds no entry for it. Each
|
|
68
|
+
/// keeps its own `r_seq` even where one instance is mounted twice along the
|
|
69
|
+
/// walk, so a move landing between the two is still learned of below.
|
|
70
|
+
crossed: Vec<Crossed>,
|
|
62
71
|
pending: VecDeque<String>,
|
|
63
72
|
/// The links followed through every walk of one call, as Linux's
|
|
64
73
|
/// `total_link_count` carries into a walk made again for ESTALE.
|
|
65
|
-
total_link_count:
|
|
66
|
-
///
|
|
67
|
-
///
|
|
68
|
-
|
|
69
|
-
pub(crate) trail: Vec<Arc<Dentry>>,
|
|
70
|
-
/// Whether this walk keeps its `trail`, as only one placing a mount
|
|
71
|
-
/// reads it.
|
|
72
|
-
keeps_trail: bool,
|
|
74
|
+
total_link_count: usize,
|
|
75
|
+
/// Whether a link anywhere on the path answers ELOOP instead of being
|
|
76
|
+
/// followed, as `LOOKUP_NO_SYMLINKS`.
|
|
77
|
+
lookup_no_symlinks: bool,
|
|
73
78
|
/// The last name, as Linux's `nd->last`, empty unless it is a `Norm` one.
|
|
74
79
|
pub(crate) last: String,
|
|
75
80
|
last_type: LastType,
|
|
@@ -101,7 +106,7 @@ impl Nameidata {
|
|
|
101
106
|
/// carried a directory out from under it.
|
|
102
107
|
fn complete_walk(&self) -> Result<(), Errno> {
|
|
103
108
|
let ended = match self.crossed.first() {
|
|
104
|
-
Some(
|
|
109
|
+
Some(below_start) => &below_start.dir,
|
|
105
110
|
None => self.path.as_ref().unwrap_or(&self.dir),
|
|
106
111
|
};
|
|
107
112
|
match ended.is_subdir(&self.root) {
|
|
@@ -110,6 +115,19 @@ impl Nameidata {
|
|
|
110
115
|
}
|
|
111
116
|
}
|
|
112
117
|
|
|
118
|
+
/// Begin the walk of `path` again from `start`, as Linux's `path_init`
|
|
119
|
+
/// readies the same `nameidata` for a walk made again: the links followed
|
|
120
|
+
/// so far and what the caller asked of the walk carry over.
|
|
121
|
+
fn path_init(&mut self, start: &impl Start, path: &str) -> Result<(), Errno> {
|
|
122
|
+
let again = set_nameidata(&self.cred, start, path)?;
|
|
123
|
+
*self = Nameidata {
|
|
124
|
+
total_link_count: self.total_link_count,
|
|
125
|
+
lookup_no_symlinks: self.lookup_no_symlinks,
|
|
126
|
+
..again
|
|
127
|
+
};
|
|
128
|
+
Ok(())
|
|
129
|
+
}
|
|
130
|
+
|
|
113
131
|
/// The dentry the walk ended on, as Linux's `do_open` and `vfs_getattr`
|
|
114
132
|
/// act on what the walk found without looking it up again, so a change
|
|
115
133
|
/// made since cannot lead the call anywhere but where the walk stands.
|
|
@@ -155,7 +173,7 @@ pub(crate) fn d_revalidate(
|
|
|
155
173
|
if dentry.d_mountpoint() {
|
|
156
174
|
return Ok(true);
|
|
157
175
|
}
|
|
158
|
-
let asked =
|
|
176
|
+
let asked = dentry.rename_lock().read_seqbegin();
|
|
159
177
|
let valid = match dentry.ops() {
|
|
160
178
|
Some(ops) => ops.revalidate(dir.inode_ops()?.as_ref(), dentry)?,
|
|
161
179
|
None => true,
|
|
@@ -345,9 +363,12 @@ impl Nameidata {
|
|
|
345
363
|
/// point down to what is mounted there, however many stand on it.
|
|
346
364
|
fn traverse_mounts(&mut self, mnt: Arc<VfsMount>) {
|
|
347
365
|
let mnt = self.cred.mnt_ns().topmost_overmount(&mnt);
|
|
348
|
-
let
|
|
349
|
-
self.crossed
|
|
350
|
-
|
|
366
|
+
let r_seq = mnt.root().rename_lock().read_seqbegin();
|
|
367
|
+
self.crossed.push(Crossed {
|
|
368
|
+
dir: std::mem::replace(&mut self.dir, mnt.root().clone()),
|
|
369
|
+
mnt: std::mem::replace(&mut self.mnt, mnt),
|
|
370
|
+
r_seq: std::mem::replace(&mut self.r_seq, r_seq),
|
|
371
|
+
});
|
|
351
372
|
}
|
|
352
373
|
|
|
353
374
|
/// Step into the directory `name` names, or onto the mount standing there,
|
|
@@ -355,7 +376,6 @@ impl Nameidata {
|
|
|
355
376
|
fn walk_component(&mut self, name: &str) -> Result<(), Errno> {
|
|
356
377
|
let dentry = lookup_dentry(self.mnt.sb(), self.dentry(), name)?;
|
|
357
378
|
if let Some(mnt) = self.lookup_mnt(&dentry) {
|
|
358
|
-
self.record_step(&dentry);
|
|
359
379
|
self.traverse_mounts(mnt);
|
|
360
380
|
return Ok(());
|
|
361
381
|
}
|
|
@@ -363,7 +383,6 @@ impl Nameidata {
|
|
|
363
383
|
match inode.file_type() {
|
|
364
384
|
FileType::Symlink => self.pick_link(&dentry),
|
|
365
385
|
FileType::Dir => {
|
|
366
|
-
self.record_step(&dentry);
|
|
367
386
|
self.dir = dentry;
|
|
368
387
|
Ok(())
|
|
369
388
|
}
|
|
@@ -371,19 +390,11 @@ impl Nameidata {
|
|
|
371
390
|
}
|
|
372
391
|
}
|
|
373
392
|
|
|
374
|
-
/// Add `dentry` to the trail of a walk that keeps one.
|
|
375
|
-
fn record_step(&mut self, dentry: &Arc<Dentry>) {
|
|
376
|
-
if self.keeps_trail {
|
|
377
|
-
self.trail.push(Arc::clone(dentry));
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
|
|
381
393
|
/// Walk on through where the link `dentry` names points, before
|
|
382
394
|
/// whatever is left of the path.
|
|
383
395
|
fn pick_link(&mut self, dentry: &Arc<Dentry>) -> Result<(), Errno> {
|
|
384
|
-
self.total_link_count
|
|
385
|
-
self.
|
|
386
|
-
if self.total_link_count.get() > MAXSYMLINKS {
|
|
396
|
+
self.total_link_count += 1;
|
|
397
|
+
if self.lookup_no_symlinks || self.total_link_count > MAXSYMLINKS {
|
|
387
398
|
return Err(Errno::FilesystemLoop);
|
|
388
399
|
}
|
|
389
400
|
let target = dentry.get_link()?;
|
|
@@ -409,20 +420,24 @@ impl Nameidata {
|
|
|
409
420
|
/// started from, or a mount's root it never stepped onto, no `..` holds a
|
|
410
421
|
/// capability, as `RESOLVE_BENEATH` refuses a caller's and a link's alike.
|
|
411
422
|
fn follow_dotdot(&mut self) -> Result<(), Errno> {
|
|
412
|
-
|
|
423
|
+
// Only the mount the walk started on holds where it started, as
|
|
424
|
+
// `path_equal` compares the mount too: the same Filesystem mounted
|
|
425
|
+
// again beneath has the same root dentry.
|
|
426
|
+
if self.crossed.is_empty() && Arc::ptr_eq(&self.dir, &self.root) {
|
|
413
427
|
return Err(Errno::Escape);
|
|
414
428
|
}
|
|
415
429
|
if self.dir.is_root() {
|
|
416
|
-
let
|
|
417
|
-
self.mnt = mnt;
|
|
418
|
-
self.dir = dir;
|
|
430
|
+
let crossed = self.crossed.pop().ok_or(Errno::Escape)?;
|
|
431
|
+
self.mnt = crossed.mnt;
|
|
432
|
+
self.dir = crossed.dir;
|
|
433
|
+
self.r_seq = crossed.r_seq;
|
|
419
434
|
} else {
|
|
420
435
|
self.dir = self.dir.parent();
|
|
421
436
|
}
|
|
422
|
-
// A move
|
|
423
|
-
// so the caller makes the call again, as
|
|
424
|
-
// however the `..` was taken.
|
|
425
|
-
if
|
|
437
|
+
// A move on the Filesystem it now stands on may have carried `..` above
|
|
438
|
+
// where the walk started, so the caller makes the call again, as
|
|
439
|
+
// `handle_dots` answers a scoped walk however the `..` was taken.
|
|
440
|
+
if self.dir.rename_lock().read_seqretry(self.r_seq) {
|
|
426
441
|
return Err(Errno::WouldBlock);
|
|
427
442
|
}
|
|
428
443
|
Ok(())
|
|
@@ -713,13 +728,7 @@ fn sb_permission(sb: &SuperBlock, dentry: &Dentry, mask: Mask) -> Result<(), Err
|
|
|
713
728
|
/// `set_nameidata` and `path_init` make one. A path no call can take answers
|
|
714
729
|
/// first, wherever it starts; an absolute one is not the caller's to reach, so
|
|
715
730
|
/// no start is looked for; and a walk starts from nothing but a directory.
|
|
716
|
-
|
|
717
|
-
fn set_nameidata(
|
|
718
|
-
cred: &Arc<Cred>,
|
|
719
|
-
start: &impl Start,
|
|
720
|
-
path: &str,
|
|
721
|
-
total_link_count: &Rc<Cell<usize>>,
|
|
722
|
-
) -> Result<Nameidata, Errno> {
|
|
731
|
+
fn set_nameidata(cred: &Arc<Cred>, start: &impl Start, path: &str) -> Result<Nameidata, Errno> {
|
|
723
732
|
getname(path)?;
|
|
724
733
|
if path.starts_with('/') {
|
|
725
734
|
return Err(Errno::Escape);
|
|
@@ -732,13 +741,12 @@ fn set_nameidata(
|
|
|
732
741
|
mnt: start.mnt().clone(),
|
|
733
742
|
cred: cred.clone(),
|
|
734
743
|
root: start.dentry().clone(),
|
|
735
|
-
r_seq:
|
|
744
|
+
r_seq: start.dentry().rename_lock().read_seqbegin(),
|
|
736
745
|
dir: start.dentry().clone(),
|
|
737
746
|
crossed: Vec::new(),
|
|
738
747
|
pending: parts(path),
|
|
739
|
-
total_link_count:
|
|
740
|
-
|
|
741
|
-
keeps_trail: false,
|
|
748
|
+
total_link_count: 0,
|
|
749
|
+
lookup_no_symlinks: false,
|
|
742
750
|
last: String::new(),
|
|
743
751
|
last_type: LastType::Dot,
|
|
744
752
|
trailing_slash: false,
|
|
@@ -755,22 +763,29 @@ pub(crate) fn filename_parentat(
|
|
|
755
763
|
start: &impl Start,
|
|
756
764
|
path: &str,
|
|
757
765
|
) -> Result<Nameidata, Errno> {
|
|
758
|
-
let
|
|
759
|
-
walk_with_reval(
|
|
760
|
-
let mut nd = set_nameidata(cred, start, path, &total_link_count)?;
|
|
766
|
+
let mut nd = set_nameidata(cred, start, path)?;
|
|
767
|
+
walk_with_reval(&mut nd, start, path, |nd| {
|
|
761
768
|
nd.link_path_walk()?;
|
|
762
|
-
nd.complete_walk()
|
|
763
|
-
|
|
764
|
-
|
|
769
|
+
nd.complete_walk()
|
|
770
|
+
})?;
|
|
771
|
+
Ok(nd)
|
|
765
772
|
}
|
|
766
773
|
|
|
767
|
-
/// What `walk` answers
|
|
768
|
-
/// `filename_lookup` walks again with `LOOKUP_REVAL`, so a
|
|
769
|
-
/// moving meanwhile is reached where it went. Every walk asks
|
|
770
|
-
/// what it holds already, so the second takes no flag.
|
|
771
|
-
fn walk_with_reval<T>(
|
|
772
|
-
|
|
773
|
-
|
|
774
|
+
/// What `walk` answers on `nd`, walked once more from `start` where it answers
|
|
775
|
+
/// ESTALE, as Linux's `filename_lookup` walks again with `LOOKUP_REVAL`, so a
|
|
776
|
+
/// directory found moving meanwhile is reached where it went. Every walk asks
|
|
777
|
+
/// `revalidate` of what it holds already, so the second takes no flag.
|
|
778
|
+
fn walk_with_reval<T>(
|
|
779
|
+
nd: &mut Nameidata,
|
|
780
|
+
start: &impl Start,
|
|
781
|
+
path: &str,
|
|
782
|
+
mut walk: impl FnMut(&mut Nameidata) -> Result<T, Errno>,
|
|
783
|
+
) -> Result<T, Errno> {
|
|
784
|
+
match walk(nd) {
|
|
785
|
+
Err(Errno::StaleNetworkFileHandle) => {
|
|
786
|
+
nd.path_init(start, path)?;
|
|
787
|
+
walk(nd)
|
|
788
|
+
}
|
|
774
789
|
answered => answered,
|
|
775
790
|
}
|
|
776
791
|
}
|
|
@@ -799,28 +814,28 @@ pub(crate) fn filename_lookup(
|
|
|
799
814
|
path: &str,
|
|
800
815
|
follow: bool,
|
|
801
816
|
) -> Result<Nameidata, Errno> {
|
|
802
|
-
let
|
|
803
|
-
walk_with_reval(
|
|
817
|
+
let mut nd = set_nameidata(cred, start, path)?;
|
|
818
|
+
walk_with_reval(&mut nd, start, path, |nd| path_lookupat(nd, follow))?;
|
|
819
|
+
Ok(nd)
|
|
804
820
|
}
|
|
805
821
|
|
|
806
|
-
/// Walk `path` beneath `start` to where a mount is to stand,
|
|
807
|
-
///
|
|
808
|
-
///
|
|
822
|
+
/// Walk `path` beneath `start` to where a mount is to stand, as `do_mount`
|
|
823
|
+
/// looks its target up, but with `LOOKUP_NO_SYMLINKS`: each Invocation places
|
|
824
|
+
/// the mount by its path again, and a link another Filesystem changed meanwhile
|
|
825
|
+
/// would move it off what it hides.
|
|
809
826
|
pub(crate) fn walk_mountpoint(
|
|
810
827
|
cred: &Arc<Cred>,
|
|
811
828
|
start: &impl Start,
|
|
812
829
|
path: &str,
|
|
813
830
|
) -> Result<Nameidata, Errno> {
|
|
814
|
-
let
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
path_lookupat(nd, true)
|
|
819
|
-
})
|
|
831
|
+
let mut nd = set_nameidata(cred, start, path)?;
|
|
832
|
+
nd.lookup_no_symlinks = true;
|
|
833
|
+
walk_with_reval(&mut nd, start, path, |nd| path_lookupat(nd, true))?;
|
|
834
|
+
Ok(nd)
|
|
820
835
|
}
|
|
821
836
|
|
|
822
837
|
/// Walk `nd` to what its path names, as Linux's `path_lookupat`.
|
|
823
|
-
fn path_lookupat(
|
|
838
|
+
fn path_lookupat(nd: &mut Nameidata, follow: bool) -> Result<(), Errno> {
|
|
824
839
|
nd.link_path_walk()?;
|
|
825
840
|
nd.lookup_last(follow)?;
|
|
826
841
|
nd.complete_walk()?;
|
|
@@ -828,7 +843,7 @@ fn path_lookupat(mut nd: Nameidata, follow: bool) -> Result<Nameidata, Errno> {
|
|
|
828
843
|
if nd.lookup_directory && kind != FileType::Dir {
|
|
829
844
|
return Err(Errno::NotADirectory);
|
|
830
845
|
}
|
|
831
|
-
Ok(
|
|
846
|
+
Ok(())
|
|
832
847
|
}
|
|
833
848
|
|
|
834
849
|
/// Open `path` beneath `start` as `op` asks, as Linux's `do_file_open`
|
|
@@ -841,13 +856,13 @@ pub fn do_file_open(
|
|
|
841
856
|
path: &str,
|
|
842
857
|
op: &OpenFlags,
|
|
843
858
|
) -> Result<File, Errno> {
|
|
844
|
-
let
|
|
845
|
-
walk_with_reval(
|
|
859
|
+
let mut nd = set_nameidata(cred, start, path)?;
|
|
860
|
+
walk_with_reval(&mut nd, start, path, |nd| path_openat(nd, op))
|
|
846
861
|
}
|
|
847
862
|
|
|
848
863
|
/// Walk `nd` to its last name and open it as `op` asks, as Linux's
|
|
849
864
|
/// `path_openat`.
|
|
850
|
-
fn path_openat(
|
|
865
|
+
fn path_openat(nd: &mut Nameidata, op: &OpenFlags) -> Result<File, Errno> {
|
|
851
866
|
let how = op.open_flag();
|
|
852
867
|
nd.lookup_directory = op.lookup_directory();
|
|
853
868
|
let mode = FMode::of(how);
|
|
@@ -857,15 +872,15 @@ fn path_openat(mut nd: Nameidata, op: &OpenFlags) -> Result<File, Errno> {
|
|
|
857
872
|
nd.link_path_walk()?;
|
|
858
873
|
let opened = nd.open_last_lookups(how, mode, op.lookup_follow())?;
|
|
859
874
|
let child = nd.path()?;
|
|
860
|
-
do_open(
|
|
875
|
+
do_open(nd, child, opened, op)
|
|
861
876
|
}
|
|
862
877
|
|
|
863
878
|
/// Stand for what `nd` names without opening it, as Linux's `do_o_path` walks
|
|
864
879
|
/// with `path_lookupat` and opens nothing: no permission is asked and nothing
|
|
865
880
|
/// is made or emptied.
|
|
866
|
-
fn do_o_path(nd: Nameidata, op: &OpenFlags) -> Result<File, Errno> {
|
|
881
|
+
fn do_o_path(nd: &mut Nameidata, op: &OpenFlags) -> Result<File, Errno> {
|
|
867
882
|
let how = op.open_flag();
|
|
868
|
-
|
|
883
|
+
path_lookupat(nd, op.lookup_follow())?;
|
|
869
884
|
let child = nd.path()?;
|
|
870
885
|
let kind = child.file_type()?;
|
|
871
886
|
let (f_op, security) = on_path(&nd.mnt, &child, |path| {
|
|
@@ -1693,46 +1708,6 @@ mod tests {
|
|
|
1693
1708
|
);
|
|
1694
1709
|
}
|
|
1695
1710
|
|
|
1696
|
-
// Holding it shared again past the waiting writer stands in for what a walk
|
|
1697
|
-
// does when a Ruby Filesystem reaches its own Mount, which must never hang.
|
|
1698
|
-
// @behavior RT-253
|
|
1699
|
-
#[test]
|
|
1700
|
-
fn a_writer_goes_ahead_of_readers_arriving_after_it() {
|
|
1701
|
-
use crate::locking::RwSemaphore;
|
|
1702
|
-
let rwsem: Arc<RwSemaphore> = Arc::default();
|
|
1703
|
-
let order = Arc::new(Mutex::new(Vec::new()));
|
|
1704
|
-
let held = rwsem.down_read().expect("the first reader holds it");
|
|
1705
|
-
let writer = {
|
|
1706
|
-
let (rwsem, order) = (rwsem.clone(), order.clone());
|
|
1707
|
-
thread::spawn(move || {
|
|
1708
|
-
let _held = rwsem.down_write().expect("the writer holds it");
|
|
1709
|
-
order.lock().expect("never poisoned").push("writer");
|
|
1710
|
-
})
|
|
1711
|
-
};
|
|
1712
|
-
crate::sched::testing::wait_until("the writer queueing behind the reader", || {
|
|
1713
|
-
rwsem.writer_waits()
|
|
1714
|
-
});
|
|
1715
|
-
let reader = {
|
|
1716
|
-
let (rwsem, order) = (rwsem.clone(), order.clone());
|
|
1717
|
-
thread::spawn(move || {
|
|
1718
|
-
let _held = rwsem.down_read().expect("the reader holds it");
|
|
1719
|
-
order.lock().expect("never poisoned").push("reader");
|
|
1720
|
-
})
|
|
1721
|
-
};
|
|
1722
|
-
let again = rwsem.down_read().map(drop);
|
|
1723
|
-
thread::sleep(Duration::from_millis(50));
|
|
1724
|
-
let before = order.lock().expect("never poisoned").clone();
|
|
1725
|
-
drop(held);
|
|
1726
|
-
crate::sched::testing::join("the writer", writer);
|
|
1727
|
-
crate::sched::testing::join("the reader", reader);
|
|
1728
|
-
assert_eq!(
|
|
1729
|
-
(again, before, order.lock().expect("never poisoned").clone()),
|
|
1730
|
-
(Ok(()), Vec::new(), vec!["writer", "reader"]),
|
|
1731
|
-
"a reader arriving behind a waiting writer must wait for it, as \
|
|
1732
|
-
rwsem_down_read_slowpath queues, while one already holding it takes it again"
|
|
1733
|
-
);
|
|
1734
|
-
}
|
|
1735
|
-
|
|
1736
1711
|
/// A security module recording the hooks a call reaches, by name.
|
|
1737
1712
|
#[derive(Default)]
|
|
1738
1713
|
struct RecordsHooks(Mutex<Vec<String>>);
|
|
@@ -3417,13 +3392,7 @@ mod tests {
|
|
|
3417
3392
|
let root = moves_as_walked(&[("a/b/keep", "k"), ("z/c", "moved")], "a/b", "z/b");
|
|
3418
3393
|
let cred = Arc::default();
|
|
3419
3394
|
let during = vfs::vfs_fstatat(&cred, &root, "a/b/l/../c", false);
|
|
3420
|
-
|
|
3421
|
-
// and tests beside this one make them.
|
|
3422
|
-
let mut after = Err(Errno::WouldBlock);
|
|
3423
|
-
crate::sched::testing::wait_until("the call made again answering", || {
|
|
3424
|
-
after = vfs::vfs_fstatat(&cred, &root, "z/b/../c", false);
|
|
3425
|
-
after != Err(Errno::WouldBlock)
|
|
3426
|
-
});
|
|
3395
|
+
let after = vfs::vfs_fstatat(&cred, &root, "z/b/../c", false);
|
|
3427
3396
|
assert_eq!(
|
|
3428
3397
|
(during.map(|_| ()), after.map(|stat| stat.size)),
|
|
3429
3398
|
(Err(Errno::WouldBlock), Ok(5)),
|
|
@@ -3474,15 +3443,9 @@ mod tests {
|
|
|
3474
3443
|
&crate::grant::Grant::Mount(inner),
|
|
3475
3444
|
],
|
|
3476
3445
|
)
|
|
3477
|
-
.expect("every
|
|
3446
|
+
.expect("every mount stands");
|
|
3478
3447
|
let during = vfs::vfs_fstatat(&cred, &outer_root, "inner/l/../y/c", false);
|
|
3479
|
-
|
|
3480
|
-
// make them.
|
|
3481
|
-
let mut after = Err(Errno::WouldBlock);
|
|
3482
|
-
crate::sched::testing::wait_until("the call made again answering", || {
|
|
3483
|
-
after = vfs::vfs_fstatat(&cred, &outer_root, "inner/../y/c", false);
|
|
3484
|
-
after != Err(Errno::WouldBlock)
|
|
3485
|
-
});
|
|
3448
|
+
let after = vfs::vfs_fstatat(&cred, &outer_root, "inner/../y/c", false);
|
|
3486
3449
|
assert_eq!(
|
|
3487
3450
|
(during.map(|_| ()), after.map(|stat| stat.size)),
|
|
3488
3451
|
(Err(Errno::WouldBlock), Ok(5)),
|
|
@@ -3491,6 +3454,138 @@ mod tests {
|
|
|
3491
3454
|
);
|
|
3492
3455
|
}
|
|
3493
3456
|
|
|
3457
|
+
/// A filesystem of `files` whose link `l` moves `from` to `to` through
|
|
3458
|
+
/// `moved`, which is set once that mount stands.
|
|
3459
|
+
fn moving_link_filesystem(
|
|
3460
|
+
files: &[(&'static str, &'static str)],
|
|
3461
|
+
moved: &Arc<OnceLock<Path>>,
|
|
3462
|
+
from: &'static str,
|
|
3463
|
+
to: &'static str,
|
|
3464
|
+
) -> Arc<Filesystem> {
|
|
3465
|
+
let link = MovesWhenFollowed {
|
|
3466
|
+
cred: Arc::default(),
|
|
3467
|
+
root: moved.clone(),
|
|
3468
|
+
from,
|
|
3469
|
+
to,
|
|
3470
|
+
};
|
|
3471
|
+
let tmpfs: Tmpfs = files.iter().copied().collect();
|
|
3472
|
+
let wrapped = Wrap::new(Arc::new(tmpfs), Arc::new(LinkAtL(Arc::new(link))));
|
|
3473
|
+
Filesystem::new(wrapped).expect("the instance must stand")
|
|
3474
|
+
}
|
|
3475
|
+
|
|
3476
|
+
fn mount_at(path: &str, filesystem: &Arc<Filesystem>) -> Mount {
|
|
3477
|
+
Mount::new(path, filesystem.clone(), Access::ReadWrite).expect("a guest path")
|
|
3478
|
+
}
|
|
3479
|
+
|
|
3480
|
+
// @behavior RT-409
|
|
3481
|
+
#[test]
|
|
3482
|
+
fn a_dotdot_a_move_on_another_filesystem_landed_before_goes_on() {
|
|
3483
|
+
let elsewhere = mount_at(
|
|
3484
|
+
"/other",
|
|
3485
|
+
&Filesystem::new(Tmpfs::from_iter([("x/k", "k")])).unwrap(),
|
|
3486
|
+
);
|
|
3487
|
+
let moved = Arc::new(OnceLock::new());
|
|
3488
|
+
moved
|
|
3489
|
+
.set(Path::root(elsewhere.mnt()))
|
|
3490
|
+
.ok()
|
|
3491
|
+
.expect("set only here");
|
|
3492
|
+
let walked = mount_at(
|
|
3493
|
+
"/data",
|
|
3494
|
+
&moving_link_filesystem(&[("a/keep", "k"), ("c", "stays")], &moved, "x", "y"),
|
|
3495
|
+
);
|
|
3496
|
+
let stat = vfs::vfs_fstatat(
|
|
3497
|
+
&Arc::default(),
|
|
3498
|
+
&Path::root(walked.mnt()),
|
|
3499
|
+
"a/l/../c",
|
|
3500
|
+
false,
|
|
3501
|
+
);
|
|
3502
|
+
assert_eq!(
|
|
3503
|
+
stat.map(|stat| stat.size),
|
|
3504
|
+
Ok(5),
|
|
3505
|
+
"a stat through `..` with a move landing on another filesystem during the walk \
|
|
3506
|
+
must reach the file, since that move cannot carry any directory the walk stands in"
|
|
3507
|
+
);
|
|
3508
|
+
}
|
|
3509
|
+
|
|
3510
|
+
// A host app may mount one filesystem into two sandboxes; the move here goes
|
|
3511
|
+
// through a mount the walk never touches.
|
|
3512
|
+
// @behavior RT-240
|
|
3513
|
+
#[test]
|
|
3514
|
+
fn a_dotdot_a_move_through_another_mount_of_its_filesystem_landed_before_asks_again() {
|
|
3515
|
+
let moved = Arc::new(OnceLock::new());
|
|
3516
|
+
let shared = moving_link_filesystem(
|
|
3517
|
+
&[("a/keep", "k"), ("x/k", "k"), ("c", "stays")],
|
|
3518
|
+
&moved,
|
|
3519
|
+
"x",
|
|
3520
|
+
"y",
|
|
3521
|
+
);
|
|
3522
|
+
let other_sandbox = mount_at("/data", &shared);
|
|
3523
|
+
moved
|
|
3524
|
+
.set(Path::root(other_sandbox.mnt()))
|
|
3525
|
+
.ok()
|
|
3526
|
+
.expect("set only here");
|
|
3527
|
+
let walked = mount_at("/data", &shared);
|
|
3528
|
+
let stat = vfs::vfs_fstatat(
|
|
3529
|
+
&Arc::default(),
|
|
3530
|
+
&Path::root(walked.mnt()),
|
|
3531
|
+
"a/l/../c",
|
|
3532
|
+
false,
|
|
3533
|
+
);
|
|
3534
|
+
assert_eq!(
|
|
3535
|
+
stat.map(|_| ()),
|
|
3536
|
+
Err(Errno::WouldBlock),
|
|
3537
|
+
"a stat through `..` with a move landing through another mount of the same \
|
|
3538
|
+
filesystem during the walk must answer EAGAIN, as the move may carry its directories"
|
|
3539
|
+
);
|
|
3540
|
+
}
|
|
3541
|
+
|
|
3542
|
+
// `again` mounts the walk's own filesystem a second time, after the link moved
|
|
3543
|
+
// a directory of it, so only the `r_seq` kept for the first mount knows of the
|
|
3544
|
+
// move once the walk climbs back there.
|
|
3545
|
+
// @behavior RT-240
|
|
3546
|
+
#[test]
|
|
3547
|
+
fn a_dotdot_back_onto_a_filesystem_mounted_twice_learns_of_a_move_between() {
|
|
3548
|
+
let outer = Filesystem::new(Tmpfs::from_iter([("inner/keep", "k"), ("x/k", "k")])).unwrap();
|
|
3549
|
+
let moved = Arc::new(OnceLock::new());
|
|
3550
|
+
let inner = moving_link_filesystem(&[("again/keep", "k")], &moved, "x", "y");
|
|
3551
|
+
let mounts = [
|
|
3552
|
+
mount_at("/data", &outer),
|
|
3553
|
+
mount_at("/data/inner", &inner),
|
|
3554
|
+
mount_at("/data/inner/again", &outer),
|
|
3555
|
+
];
|
|
3556
|
+
let outer_root = Path::root(mounts[0].mnt());
|
|
3557
|
+
moved.set(outer_root.clone()).ok().expect("set only here");
|
|
3558
|
+
let grants: Vec<_> = mounts.into_iter().map(crate::grant::Grant::Mount).collect();
|
|
3559
|
+
let cred = crate::security::restrict_self(&Arc::default(), grants.iter())
|
|
3560
|
+
.expect("every mount stands");
|
|
3561
|
+
let stat = vfs::vfs_fstatat(&cred, &outer_root, "inner/l/again/../../inner", false);
|
|
3562
|
+
assert_eq!(
|
|
3563
|
+
stat.map(|_| ()),
|
|
3564
|
+
Err(Errno::WouldBlock),
|
|
3565
|
+
"a stat through `..` back onto a filesystem mounted twice along the walk, with a \
|
|
3566
|
+
move on it landing between the two mounts, must answer EAGAIN"
|
|
3567
|
+
);
|
|
3568
|
+
}
|
|
3569
|
+
|
|
3570
|
+
// @behavior RT-410
|
|
3571
|
+
#[test]
|
|
3572
|
+
fn a_dotdot_out_of_the_walks_own_filesystem_mounted_again_climbs_back() {
|
|
3573
|
+
let outer =
|
|
3574
|
+
Filesystem::new(Tmpfs::from_iter([("m/keep", "k"), ("note", "the note")])).unwrap();
|
|
3575
|
+
let mounts = [mount_at("/data", &outer), mount_at("/data/m", &outer)];
|
|
3576
|
+
let outer_root = Path::root(mounts[0].mnt());
|
|
3577
|
+
let grants: Vec<_> = mounts.into_iter().map(crate::grant::Grant::Mount).collect();
|
|
3578
|
+
let cred = crate::security::restrict_self(&Arc::default(), grants.iter())
|
|
3579
|
+
.expect("every mount stands");
|
|
3580
|
+
let stat = vfs::vfs_fstatat(&cred, &outer_root, "m/../note", false);
|
|
3581
|
+
assert_eq!(
|
|
3582
|
+
stat.map(|stat| stat.size),
|
|
3583
|
+
Ok(8),
|
|
3584
|
+
"a stat of `m/../note` from a filesystem's root, with that filesystem mounted \
|
|
3585
|
+
again at `m`, must climb back out of `m` and reach `note`"
|
|
3586
|
+
);
|
|
3587
|
+
}
|
|
3588
|
+
|
|
3494
3589
|
// @behavior RT-241
|
|
3495
3590
|
#[test]
|
|
3496
3591
|
fn a_walk_carried_out_from_under_its_start_answers_an_escape() {
|
|
@@ -3721,6 +3816,10 @@ mod tests {
|
|
|
3721
3816
|
struct FoldedDir(KernPath);
|
|
3722
3817
|
|
|
3723
3818
|
impl FileOperations for FoldedDir {
|
|
3819
|
+
fn has_iterate_shared(&self) -> bool {
|
|
3820
|
+
true
|
|
3821
|
+
}
|
|
3822
|
+
|
|
3724
3823
|
fn iterate_shared(
|
|
3725
3824
|
&mut self,
|
|
3726
3825
|
dentry: &Dentry,
|
|
@@ -3863,7 +3962,7 @@ mod tests {
|
|
|
3863
3962
|
&crate::security::prepare_creds(&[], None),
|
|
3864
3963
|
[&crate::grant::Grant::Mount(mount.clone())],
|
|
3865
3964
|
)
|
|
3866
|
-
.expect("every
|
|
3965
|
+
.expect("every mount stands");
|
|
3867
3966
|
let root = Path::root(mount.mnt());
|
|
3868
3967
|
[
|
|
3869
3968
|
vfs::filename_mkdirat(&cred, &root, "dir"),
|
|
@@ -4023,7 +4122,7 @@ mod tests {
|
|
|
4023
4122
|
&crate::grant::Grant::Mount(links.clone()),
|
|
4024
4123
|
],
|
|
4025
4124
|
)
|
|
4026
|
-
.expect("every
|
|
4125
|
+
.expect("every mount stands");
|
|
4027
4126
|
let (plain, links) = (Path::root(plain.mnt()), Path::root(links.mnt()));
|
|
4028
4127
|
assert_eq!(
|
|
4029
4128
|
(
|
|
@@ -4118,7 +4217,7 @@ mod tests {
|
|
|
4118
4217
|
assert_eq!(
|
|
4119
4218
|
vfs::kern_path::filp_open(
|
|
4120
4219
|
&crate::security::restrict_self(&crate::security::prepare_creds(&[], None), [])
|
|
4121
|
-
.expect("every
|
|
4220
|
+
.expect("every mount stands"),
|
|
4122
4221
|
&root,
|
|
4123
4222
|
"w",
|
|
4124
4223
|
&how
|
|
@@ -4152,16 +4251,18 @@ mod tests {
|
|
|
4152
4251
|
|
|
4153
4252
|
#[test]
|
|
4154
4253
|
fn a_directory_made_while_another_is_removed_in_its_place_stays_alive() {
|
|
4254
|
+
let counts = count_waits();
|
|
4155
4255
|
let (removed, removing) = mpsc::channel();
|
|
4156
4256
|
let (made, making) = mpsc::channel::<()>();
|
|
4157
4257
|
let (removed, making) = (Mutex::new(removed), Mutex::new(making));
|
|
4158
4258
|
let hooked = HookedTmpfs {
|
|
4159
4259
|
removed: Some(Box::new(move || {
|
|
4160
4260
|
removed.lock().expect("unpoisoned").send(()).ok();
|
|
4161
|
-
let
|
|
4162
|
-
|
|
4163
|
-
|
|
4164
|
-
.
|
|
4261
|
+
let making = making.lock().expect("unpoisoned");
|
|
4262
|
+
crate::sched::testing::wait_until(
|
|
4263
|
+
"the make waiting for the removal, or made",
|
|
4264
|
+
|| counts.load(Ordering::SeqCst) > 0 || making.try_recv().is_ok(),
|
|
4265
|
+
);
|
|
4165
4266
|
Ok(())
|
|
4166
4267
|
})),
|
|
4167
4268
|
..HookedTmpfs::default()
|
|
@@ -4189,22 +4290,27 @@ mod tests {
|
|
|
4189
4290
|
}
|
|
4190
4291
|
|
|
4191
4292
|
/// A Policy allowing everything that holds its first answer until the
|
|
4192
|
-
///
|
|
4293
|
+
/// removal waits through the `Blocking`, as `waits` counts, or lands.
|
|
4193
4294
|
struct PausesFirst {
|
|
4194
4295
|
answered: AtomicBool,
|
|
4195
4296
|
reached: Mutex<mpsc::Sender<()>>,
|
|
4196
|
-
|
|
4297
|
+
waits: Arc<OnceLock<Arc<AtomicUsize>>>,
|
|
4298
|
+
removed: Arc<AtomicBool>,
|
|
4197
4299
|
}
|
|
4198
4300
|
|
|
4199
4301
|
impl Policy<MountRequest<'_>> for PausesFirst {
|
|
4200
4302
|
fn allows(&self, _request: &MountRequest<'_>) -> bool {
|
|
4201
4303
|
if !self.answered.swap(true, Ordering::SeqCst) {
|
|
4202
4304
|
self.reached.lock().expect("unpoisoned").send(()).ok();
|
|
4203
|
-
|
|
4204
|
-
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4305
|
+
crate::sched::testing::wait_until(
|
|
4306
|
+
"the removal waiting for the open, or landing",
|
|
4307
|
+
|| {
|
|
4308
|
+
self.waits
|
|
4309
|
+
.get()
|
|
4310
|
+
.is_some_and(|waits| waits.load(Ordering::SeqCst) > 0)
|
|
4311
|
+
|| self.removed.load(Ordering::SeqCst)
|
|
4312
|
+
},
|
|
4313
|
+
);
|
|
4208
4314
|
}
|
|
4209
4315
|
true
|
|
4210
4316
|
}
|
|
@@ -4217,11 +4323,12 @@ mod tests {
|
|
|
4217
4323
|
#[test]
|
|
4218
4324
|
fn a_create_opens_the_file_it_finds_or_makes_one() {
|
|
4219
4325
|
let (reached, reaching) = mpsc::channel();
|
|
4220
|
-
let (
|
|
4326
|
+
let (waits, removed) = (Arc::<OnceLock<_>>::default(), Arc::<AtomicBool>::default());
|
|
4221
4327
|
let policy = PausesFirst {
|
|
4222
4328
|
answered: AtomicBool::new(false),
|
|
4223
4329
|
reached: Mutex::new(reached),
|
|
4224
|
-
|
|
4330
|
+
waits: waits.clone(),
|
|
4331
|
+
removed: removed.clone(),
|
|
4225
4332
|
};
|
|
4226
4333
|
let tmpfs: Tmpfs = [("f", "x")].into_iter().collect();
|
|
4227
4334
|
let mount = Mount::new(
|
|
@@ -4236,7 +4343,7 @@ mod tests {
|
|
|
4236
4343
|
&crate::security::prepare_creds(&[], None),
|
|
4237
4344
|
[&crate::grant::Grant::Mount(mount.clone())],
|
|
4238
4345
|
)
|
|
4239
|
-
.expect("every
|
|
4346
|
+
.expect("every mount stands");
|
|
4240
4347
|
let opener = {
|
|
4241
4348
|
let (root, cred) = (root.clone(), cred.clone());
|
|
4242
4349
|
thread::spawn(move || {
|
|
@@ -4252,8 +4359,9 @@ mod tests {
|
|
|
4252
4359
|
.recv_timeout(crate::sched::testing::MAX_WAIT)
|
|
4253
4360
|
.expect("the open must reach the Policy");
|
|
4254
4361
|
let remover = thread::spawn(move || {
|
|
4362
|
+
let _ = waits.set(count_waits());
|
|
4255
4363
|
let answer = vfs::filename_unlinkat(&cred, &root, "f");
|
|
4256
|
-
removed.
|
|
4364
|
+
removed.store(true, Ordering::SeqCst);
|
|
4257
4365
|
answer
|
|
4258
4366
|
});
|
|
4259
4367
|
let opened = crate::sched::testing::join("the open", opener);
|
|
@@ -4392,12 +4500,9 @@ mod tests {
|
|
|
4392
4500
|
renamed.lock().expect("unpoisoned").send(()).ok();
|
|
4393
4501
|
// Bounded, so a make that never waits fails the assertion
|
|
4394
4502
|
// rather than hanging the test.
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
}
|
|
4399
|
-
thread::sleep(Duration::from_millis(1));
|
|
4400
|
-
}
|
|
4503
|
+
crate::sched::testing::holds_within_max_wait(|| {
|
|
4504
|
+
counts.load(Ordering::SeqCst) > 0
|
|
4505
|
+
});
|
|
4401
4506
|
Ok(())
|
|
4402
4507
|
}
|
|
4403
4508
|
})),
|
|
@@ -4438,12 +4543,9 @@ mod tests {
|
|
|
4438
4543
|
removed.lock().expect("unpoisoned").send(()).ok();
|
|
4439
4544
|
// Bounded, so a call that never waits fails the count
|
|
4440
4545
|
// rather than hanging the test.
|
|
4441
|
-
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
}
|
|
4445
|
-
thread::sleep(Duration::from_millis(1));
|
|
4446
|
-
}
|
|
4546
|
+
crate::sched::testing::holds_within_max_wait(|| {
|
|
4547
|
+
counts.load(Ordering::SeqCst) > 0
|
|
4548
|
+
});
|
|
4447
4549
|
Ok(())
|
|
4448
4550
|
}
|
|
4449
4551
|
})),
|
|
@@ -4483,12 +4585,7 @@ mod tests {
|
|
|
4483
4585
|
reached.lock().expect("unpoisoned").send(()).ok();
|
|
4484
4586
|
// Bounded, so a removal that never waits fails the count
|
|
4485
4587
|
// rather than hanging the test.
|
|
4486
|
-
|
|
4487
|
-
if counts.load(Ordering::SeqCst) > 0 {
|
|
4488
|
-
break;
|
|
4489
|
-
}
|
|
4490
|
-
thread::sleep(Duration::from_millis(1));
|
|
4491
|
-
}
|
|
4588
|
+
crate::sched::testing::holds_within_max_wait(|| counts.load(Ordering::SeqCst) > 0);
|
|
4492
4589
|
Ok(())
|
|
4493
4590
|
}
|
|
4494
4591
|
}));
|
|
@@ -5089,7 +5186,7 @@ mod tests {
|
|
|
5089
5186
|
&crate::security::prepare_creds(&[], None),
|
|
5090
5187
|
[&crate::grant::Grant::Mount(mount.clone())],
|
|
5091
5188
|
)
|
|
5092
|
-
.expect("every
|
|
5189
|
+
.expect("every mount stands");
|
|
5093
5190
|
vfs::kern_path::filp_open(&cred, &Path::root(mount.mnt()), path, how).err()
|
|
5094
5191
|
}
|
|
5095
5192
|
|
|
@@ -5378,6 +5475,77 @@ mod tests {
|
|
|
5378
5475
|
);
|
|
5379
5476
|
}
|
|
5380
5477
|
|
|
5478
|
+
/// A directory whose first lookup holds until told to go on and then
|
|
5479
|
+
/// panics, every later one finding nothing, counting each lookup.
|
|
5480
|
+
struct PanicsOnce(HoldsLookup);
|
|
5481
|
+
|
|
5482
|
+
impl FileSystemType for PanicsOnce {
|
|
5483
|
+
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
|
|
5484
|
+
sb.d_make_root(vfs::Inode::new(&Kstat::new(FileType::Dir, 0), self));
|
|
5485
|
+
Ok(())
|
|
5486
|
+
}
|
|
5487
|
+
}
|
|
5488
|
+
|
|
5489
|
+
impl InodeOperations for PanicsOnce {
|
|
5490
|
+
fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
5491
|
+
Ok(Kstat::new(FileType::Dir, 0))
|
|
5492
|
+
}
|
|
5493
|
+
|
|
5494
|
+
fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
|
|
5495
|
+
if self.0.asked.load(Ordering::SeqCst) > 0 {
|
|
5496
|
+
return Ok(Lookup::Absent);
|
|
5497
|
+
}
|
|
5498
|
+
self.0.lookup(dentry)?;
|
|
5499
|
+
panic!("the first lookup panics");
|
|
5500
|
+
}
|
|
5501
|
+
}
|
|
5502
|
+
|
|
5503
|
+
// @behavior RT-406
|
|
5504
|
+
#[test]
|
|
5505
|
+
fn a_walk_waiting_on_a_lookup_that_panics_asks_the_filesystem_itself() {
|
|
5506
|
+
let (reached, reaching) = mpsc::channel();
|
|
5507
|
+
let (go_on, going) = mpsc::channel();
|
|
5508
|
+
let filesystem = Arc::new(PanicsOnce(HoldsLookup {
|
|
5509
|
+
asked: AtomicUsize::new(0),
|
|
5510
|
+
reached: Mutex::new(reached),
|
|
5511
|
+
go_on: Mutex::new(going),
|
|
5512
|
+
}));
|
|
5513
|
+
let root = root_of(Filesystem::new(filesystem.clone()).expect("the instance must stand"));
|
|
5514
|
+
let stat = |root: &Path| vfs::vfs_fstatat(&Arc::default(), root, "x", false).err();
|
|
5515
|
+
let first = {
|
|
5516
|
+
let root = root.clone();
|
|
5517
|
+
thread::spawn(move || stat(&root))
|
|
5518
|
+
};
|
|
5519
|
+
reaching
|
|
5520
|
+
.recv_timeout(crate::sched::testing::MAX_WAIT)
|
|
5521
|
+
.expect("the first walk must ask");
|
|
5522
|
+
let (counted, counting) = mpsc::channel();
|
|
5523
|
+
let second = {
|
|
5524
|
+
let root = root.clone();
|
|
5525
|
+
thread::spawn(move || {
|
|
5526
|
+
counted.send(count_waits()).ok();
|
|
5527
|
+
crate::sched::testing::within_max_wait(|| stat(&root))
|
|
5528
|
+
})
|
|
5529
|
+
};
|
|
5530
|
+
let waits = counting
|
|
5531
|
+
.recv_timeout(crate::sched::testing::MAX_WAIT)
|
|
5532
|
+
.expect("the second walk must start");
|
|
5533
|
+
crate::sched::testing::wait_until("the second walk waiting", || {
|
|
5534
|
+
waits.load(Ordering::SeqCst) > 0
|
|
5535
|
+
});
|
|
5536
|
+
go_on.send(()).ok();
|
|
5537
|
+
crate::sched::testing::wait_until("the first walk ending", || first.is_finished());
|
|
5538
|
+
assert_eq!(
|
|
5539
|
+
(
|
|
5540
|
+
first.join().is_err(),
|
|
5541
|
+
crate::sched::testing::join("the second walk", second),
|
|
5542
|
+
),
|
|
5543
|
+
(true, Some(Errno::NotFound)),
|
|
5544
|
+
"a stat waiting on another walk's lookup of the name must, once that lookup \
|
|
5545
|
+
panics, ask the filesystem itself and answer, rather than wait on"
|
|
5546
|
+
);
|
|
5547
|
+
}
|
|
5548
|
+
|
|
5381
5549
|
/// A directory finding nothing at any name, keeping which walk asked.
|
|
5382
5550
|
#[derive(Default)]
|
|
5383
5551
|
struct RecordsAsker(Mutex<Vec<thread::ThreadId>>);
|
|
@@ -5572,7 +5740,7 @@ mod tests {
|
|
|
5572
5740
|
|
|
5573
5741
|
// Linux's waits on a directory and on a name in lookup are killable, so a
|
|
5574
5742
|
// run whose deadline passed or whose thread was interrupted stops waiting
|
|
5575
|
-
// while the
|
|
5743
|
+
// while the owner still holds.
|
|
5576
5744
|
// @behavior RT-267
|
|
5577
5745
|
#[test]
|
|
5578
5746
|
fn a_wait_ends_once_its_run_is_to_stop() {
|
|
@@ -5618,6 +5786,45 @@ mod tests {
|
|
|
5618
5786
|
);
|
|
5619
5787
|
}
|
|
5620
5788
|
|
|
5789
|
+
// A signal the frontend handles without interrupting the task leaves a
|
|
5790
|
+
// killable wait asleep, as Linux restarts a call a handled signal woke.
|
|
5791
|
+
// @behavior RT-405
|
|
5792
|
+
#[test]
|
|
5793
|
+
fn a_wait_goes_on_past_a_signal_that_is_not_fatal() {
|
|
5794
|
+
use crate::sched::testing::{count_signals, join, wait_until};
|
|
5795
|
+
use crate::sched::{run_task, Task};
|
|
5796
|
+
|
|
5797
|
+
let root = root_of(Filesystem::new(Tmpfs::new()).expect("the instance must stand"));
|
|
5798
|
+
let held = root.dentry().inode_lock().expect("the test holds the root");
|
|
5799
|
+
let (task, tasked) = mpsc::channel();
|
|
5800
|
+
let waiting = {
|
|
5801
|
+
let root = root.clone();
|
|
5802
|
+
thread::spawn(move || {
|
|
5803
|
+
let handled = count_signals();
|
|
5804
|
+
run_task(None, || {
|
|
5805
|
+
task.send((Task::current(), handled)).ok();
|
|
5806
|
+
vfs::filename_mkdirat(&Arc::default(), &root, "late")
|
|
5807
|
+
})
|
|
5808
|
+
})
|
|
5809
|
+
};
|
|
5810
|
+
let (task, handled) = tasked
|
|
5811
|
+
.recv_timeout(crate::sched::testing::MAX_WAIT)
|
|
5812
|
+
.expect("the run must start");
|
|
5813
|
+
task.signal();
|
|
5814
|
+
wait_until("the signal being handled", || {
|
|
5815
|
+
handled.load(Ordering::SeqCst) > 0
|
|
5816
|
+
});
|
|
5817
|
+
let woke_early = waiting.is_finished();
|
|
5818
|
+
drop(held);
|
|
5819
|
+
assert_eq!(
|
|
5820
|
+
(woke_early, join("the signalled wait", waiting)),
|
|
5821
|
+
(false, Ok(())),
|
|
5822
|
+
"a mkdir waiting on a directory another thread holds, its thread signalled and \
|
|
5823
|
+
the signal handled without an interrupt, must go on waiting and make the \
|
|
5824
|
+
directory once the other lets go"
|
|
5825
|
+
);
|
|
5826
|
+
}
|
|
5827
|
+
|
|
5621
5828
|
// @behavior RT-267
|
|
5622
5829
|
#[test]
|
|
5623
5830
|
fn a_wait_for_a_name_in_lookup_ends_once_its_run_is_to_stop() {
|
|
@@ -5693,8 +5900,7 @@ mod tests {
|
|
|
5693
5900
|
// to `a/x`. A writer with no Policy renames it within `a` meanwhile, which
|
|
5694
5901
|
// takes no rename lock. A dentry taken before the wait would follow it to
|
|
5695
5902
|
// the name the Policy refuses, so only a name found under the lock answers
|
|
5696
|
-
// ENOENT. The
|
|
5697
|
-
// assertion passes on, never one it fails.
|
|
5903
|
+
// ENOENT. The writer renames only once the move waits through the `Blocking`.
|
|
5698
5904
|
// @behavior RT-211
|
|
5699
5905
|
#[test]
|
|
5700
5906
|
fn a_move_acts_on_what_stands_at_its_names_once_it_holds_them() {
|
|
@@ -5718,9 +5924,9 @@ mod tests {
|
|
|
5718
5924
|
&crate::security::prepare_creds(&[], None),
|
|
5719
5925
|
[&crate::grant::Grant::Mount(mount.clone())],
|
|
5720
5926
|
)
|
|
5721
|
-
.expect("every
|
|
5927
|
+
.expect("every mount stands");
|
|
5722
5928
|
let root = Path::root(mount.mnt());
|
|
5723
|
-
let
|
|
5929
|
+
let owner = {
|
|
5724
5930
|
let root = root.clone();
|
|
5725
5931
|
thread::spawn(move || {
|
|
5726
5932
|
vfs::filename_renameat2(&Arc::default(), &root, "c/k", &root, "d/k")
|
|
@@ -5729,14 +5935,23 @@ mod tests {
|
|
|
5729
5935
|
reaching
|
|
5730
5936
|
.recv_timeout(crate::sched::testing::MAX_WAIT)
|
|
5731
5937
|
.expect("the held move must reach its Filesystem");
|
|
5938
|
+
let (counted, counts) = mpsc::channel();
|
|
5732
5939
|
let mover = {
|
|
5733
5940
|
let (cred, root) = (cred.clone(), root.clone());
|
|
5734
|
-
thread::spawn(move ||
|
|
5941
|
+
thread::spawn(move || {
|
|
5942
|
+
counted
|
|
5943
|
+
.send(count_waits())
|
|
5944
|
+
.expect("the test takes the count");
|
|
5945
|
+
vfs::filename_renameat2(&cred, &root, "a/x", &root, "b/y")
|
|
5946
|
+
})
|
|
5735
5947
|
};
|
|
5736
|
-
|
|
5948
|
+
let waits = counts.recv().expect("the move counts its waits");
|
|
5949
|
+
crate::sched::testing::wait_until("the move waiting for the rename lock", || {
|
|
5950
|
+
waits.load(Ordering::SeqCst) > 0
|
|
5951
|
+
});
|
|
5737
5952
|
let renamed = vfs::filename_renameat2(&Arc::default(), &root, "a/x", &root, "a/moved");
|
|
5738
5953
|
go_on.send(()).expect("the held move must be waiting");
|
|
5739
|
-
crate::sched::testing::join("the
|
|
5954
|
+
crate::sched::testing::join("the owner", owner)
|
|
5740
5955
|
.unwrap_or_else(|_| panic!("the held move must land"));
|
|
5741
5956
|
let moved = crate::sched::testing::join("the mover", mover);
|
|
5742
5957
|
let stands = |path| vfs::vfs_fstatat(&cred, &root, path, false).is_ok();
|