kobako 0.30.0 → 0.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.release-please-manifest.json +1 -1
- data/CHANGELOG.md +335 -0
- data/Cargo.lock +469 -11
- data/README.md +43 -3
- data/ROADMAP.md +1 -1
- data/crates/kobako-runtime/CHANGELOG.md +219 -0
- data/crates/kobako-runtime/Cargo.toml +51 -3
- data/crates/kobako-runtime/README.md +7 -4
- data/crates/kobako-runtime/src/cred.rs +124 -0
- data/crates/kobako-runtime/src/dispatch.rs +4 -5
- data/crates/kobako-runtime/src/endpoint/buffer.rs +153 -44
- data/crates/kobako-runtime/src/endpoint/dispatch.rs +80 -41
- data/crates/kobako-runtime/src/endpoint/invoke.rs +23 -36
- data/crates/kobako-runtime/src/endpoint.rs +137 -36
- data/crates/kobako-runtime/src/errno.rs +391 -0
- data/crates/kobako-runtime/src/error.rs +31 -10
- data/crates/kobako-runtime/src/filesystem/anon_inodes.rs +52 -0
- data/crates/kobako-runtime/src/filesystem/bind/lookup.rs +52 -14
- data/crates/kobako-runtime/src/filesystem/bind/walk.rs +19 -20
- data/crates/kobako-runtime/src/filesystem/bind.rs +437 -245
- data/crates/kobako-runtime/src/filesystem/overlay/file.rs +6 -6
- data/crates/kobako-runtime/src/filesystem/overlay/path.rs +43 -65
- data/crates/kobako-runtime/src/filesystem/overlay/stack/copy_up.rs +9 -16
- data/crates/kobako-runtime/src/filesystem/overlay/stack/dir.rs +47 -72
- data/crates/kobako-runtime/src/filesystem/overlay/stack/namei.rs +12 -12
- data/crates/kobako-runtime/src/filesystem/overlay/stack/readdir.rs +4 -7
- data/crates/kobako-runtime/src/filesystem/overlay/stack.rs +121 -37
- data/crates/kobako-runtime/src/filesystem/overlay.rs +302 -343
- data/crates/kobako-runtime/src/filesystem/pipe.rs +12 -9
- data/crates/kobako-runtime/src/filesystem/rdir.rs +15 -32
- data/crates/kobako-runtime/src/filesystem/tmpfs/seed.rs +32 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs/tmpfile.rs +3 -3
- data/crates/kobako-runtime/src/filesystem/tmpfs/whiteout.rs +57 -35
- data/crates/kobako-runtime/src/filesystem/tmpfs/xattr.rs +2 -2
- data/crates/kobako-runtime/src/filesystem/tmpfs.rs +172 -160
- data/crates/kobako-runtime/src/filesystem/wrap.rs +36 -52
- data/crates/kobako-runtime/src/filesystem.rs +6 -3
- data/crates/kobako-runtime/src/fork.rs +96 -0
- data/crates/kobako-runtime/src/grant.rs +3 -0
- data/crates/kobako-runtime/src/hashtable.rs +4 -2
- data/crates/kobako-runtime/src/lib.rs +18 -7
- data/crates/kobako-runtime/src/limits.rs +195 -0
- data/crates/kobako-runtime/src/locking.rs +10 -0
- data/crates/kobako-runtime/src/memcg.rs +383 -0
- data/crates/kobako-runtime/src/mount.rs +67 -9
- data/crates/kobako-runtime/src/net/backends.rs +43 -0
- data/crates/kobako-runtime/src/net/connections.rs +179 -0
- data/crates/kobako-runtime/src/net/credential.rs +125 -0
- data/crates/kobako-runtime/src/net/egress.rs +160 -0
- data/crates/kobako-runtime/src/net/family.rs +181 -0
- data/crates/kobako-runtime/src/net/http.rs +2733 -0
- data/crates/kobako-runtime/src/net/lookup.rs +285 -0
- data/crates/kobako-runtime/src/net/mock.rs +251 -0
- data/crates/kobako-runtime/src/net/namespace.rs +1366 -0
- data/crates/kobako-runtime/src/net/reactor.rs +531 -0
- data/crates/kobako-runtime/src/net/resolv/darwin.rs +275 -0
- data/crates/kobako-runtime/src/net/resolv/stub/tests.rs +469 -0
- data/crates/kobako-runtime/src/net/resolv/stub.rs +536 -0
- data/crates/kobako-runtime/src/net/resolv/windows.rs +248 -0
- data/crates/kobako-runtime/src/net/resolv.rs +227 -0
- data/crates/kobako-runtime/src/net/socket.rs +870 -0
- data/crates/kobako-runtime/src/net/tcp.rs +1588 -0
- data/crates/kobako-runtime/src/net/tls.rs +58 -0
- data/crates/kobako-runtime/src/net/transport.rs +279 -0
- data/crates/kobako-runtime/src/net/udp.rs +1003 -0
- data/crates/kobako-runtime/src/net.rs +42 -0
- data/crates/kobako-runtime/src/network/builder.rs +177 -0
- data/crates/kobako-runtime/src/network/ruleset.rs +777 -0
- data/crates/kobako-runtime/src/network.rs +551 -0
- data/crates/kobako-runtime/src/policy.rs +16 -0
- data/crates/kobako-runtime/src/profile.rs +29 -144
- data/crates/kobako-runtime/src/runtime.rs +3 -5
- data/crates/kobako-runtime/src/sched.rs +130 -29
- data/crates/kobako-runtime/src/security/entry_policy.rs +22 -0
- data/crates/kobako-runtime/src/{vfs/cred.rs → security/hooks.rs} +52 -144
- data/crates/kobako-runtime/src/security/mount_policy.rs +158 -0
- data/crates/kobako-runtime/src/security.rs +101 -196
- data/crates/kobako-runtime/src/snapshot.rs +121 -2
- data/crates/kobako-runtime/src/vfs/attr.rs +5 -5
- data/crates/kobako-runtime/src/vfs/dentry.rs +143 -89
- data/crates/kobako-runtime/src/vfs/file.rs +199 -203
- data/crates/kobako-runtime/src/vfs/inode.rs +41 -45
- data/crates/kobako-runtime/src/vfs/kern_path.rs +38 -42
- data/crates/kobako-runtime/src/vfs/mount.rs +10 -9
- data/crates/kobako-runtime/src/vfs/namei.rs +829 -700
- data/crates/kobako-runtime/src/vfs/namespace.rs +162 -0
- data/crates/kobako-runtime/src/vfs/open_files.rs +69 -0
- data/crates/kobako-runtime/src/vfs/openat2.rs +3 -3
- data/crates/kobako-runtime/src/vfs/path.rs +6 -6
- data/crates/kobako-runtime/src/vfs/readdir.rs +6 -6
- data/crates/kobako-runtime/src/vfs/stat.rs +159 -23
- data/crates/kobako-runtime/src/vfs/super_block.rs +18 -14
- data/crates/kobako-runtime/src/vfs/utimes.rs +37 -27
- data/crates/kobako-runtime/src/vfs.rs +9 -6
- data/crates/kobako-runtime/src/wait.rs +356 -0
- data/crates/kobako-transport/CHANGELOG.md +31 -0
- data/crates/kobako-transport/Cargo.toml +1 -1
- data/crates/kobako-transport/README.md +3 -4
- data/crates/kobako-transport/src/abi.rs +78 -72
- data/crates/kobako-transport/src/envelope/bytes.rs +17 -6
- data/crates/kobako-transport/src/envelope/call.rs +32 -4
- data/crates/kobako-transport/src/envelope/error_record.rs +21 -0
- data/crates/kobako-transport/src/envelope/name.rs +99 -0
- data/crates/kobako-transport/src/envelope/outcome.rs +9 -9
- data/crates/kobako-transport/src/envelope/preamble.rs +24 -21
- data/crates/kobako-transport/src/envelope/reply.rs +27 -27
- data/crates/kobako-transport/src/envelope/unsupported.rs +10 -10
- data/crates/kobako-transport/src/envelope.rs +13 -8
- data/crates/kobako-wasmtime/CHANGELOG.md +161 -0
- data/crates/kobako-wasmtime/Cargo.toml +26 -7
- data/crates/kobako-wasmtime/README.md +3 -2
- data/crates/kobako-wasmtime/build/preview2.rs +1339 -0
- data/crates/kobako-wasmtime/build.rs +16 -0
- data/crates/kobako-wasmtime/src/abi.rs +17 -37
- data/crates/kobako-wasmtime/src/ambient.rs +33 -18
- data/crates/kobako-wasmtime/src/cache.rs +23 -15
- data/crates/kobako-wasmtime/src/config.rs +52 -68
- data/crates/kobako-wasmtime/src/driver.rs +48 -63
- data/crates/kobako-wasmtime/src/exports.rs +143 -17
- data/crates/kobako-wasmtime/src/guest.rs +12 -6
- data/crates/kobako-wasmtime/src/guest_binary.rs +14 -0
- data/crates/kobako-wasmtime/src/imports.rs +42 -18
- data/crates/kobako-wasmtime/src/instance_pre.rs +4 -4
- data/crates/kobako-wasmtime/src/invocation.rs +74 -12
- data/crates/kobako-wasmtime/src/lib.rs +5 -3
- data/crates/kobako-wasmtime/src/limiter.rs +70 -5
- data/crates/kobako-wasmtime/src/preview1/descriptors.rs +309 -0
- data/crates/kobako-wasmtime/src/preview1/differential/mount.rs +5 -15
- data/crates/kobako-wasmtime/src/preview1/differential.rs +27 -31
- data/crates/kobako-wasmtime/src/preview1/errno.rs +55 -66
- data/crates/kobako-wasmtime/src/preview1/fd.rs +327 -296
- data/crates/kobako-wasmtime/src/preview1/memory.rs +21 -12
- data/crates/kobako-wasmtime/src/preview1/mount_view/wrap.rs +34 -53
- data/crates/kobako-wasmtime/src/preview1/mount_view.rs +231 -217
- data/crates/kobako-wasmtime/src/preview1/path.rs +56 -121
- data/crates/kobako-wasmtime/src/preview1/poll.rs +244 -120
- data/crates/kobako-wasmtime/src/preview1/sock.rs +10 -8
- data/crates/kobako-wasmtime/src/preview1/testsuite.rs +5 -15
- data/crates/kobako-wasmtime/src/preview1.rs +46 -42
- data/crates/kobako-wasmtime/src/preview2/abi.rs +227 -0
- data/crates/kobako-wasmtime/src/preview2/error.rs +118 -0
- data/crates/kobako-wasmtime/src/preview2/filesystem.rs +122 -0
- data/crates/kobako-wasmtime/src/preview2/host.rs +3959 -0
- data/crates/kobako-wasmtime/src/preview2/http.rs +1503 -0
- data/crates/kobako-wasmtime/src/preview2/io.rs +315 -0
- data/crates/kobako-wasmtime/src/preview2/sockets.rs +379 -0
- data/crates/kobako-wasmtime/src/preview2/table.rs +305 -0
- data/crates/kobako-wasmtime/src/preview2.rs +57 -0
- data/crates/kobako-wasmtime/src/trap.rs +24 -9
- data/crates/kobako-wasmtime/src/wasi.rs +210 -81
- data/crates/kobako-wasmtime/wit/deps/cli.wit +233 -0
- data/crates/kobako-wasmtime/wit/deps/clocks.wit +162 -0
- data/crates/kobako-wasmtime/wit/deps/filesystem.wit +589 -0
- data/crates/kobako-wasmtime/wit/deps/http.wit +733 -0
- data/crates/kobako-wasmtime/wit/deps/io.wit +299 -0
- data/crates/kobako-wasmtime/wit/deps/random.wit +92 -0
- data/crates/kobako-wasmtime/wit/deps/sockets.wit +949 -0
- data/data/kobako.wasm +0 -0
- data/ext/kobako/Cargo.toml +1 -1
- data/ext/kobako/src/{runtime/errors.rs → errors.rs} +34 -26
- data/ext/kobako/src/{runtime/escape.rs → escape.rs} +42 -11
- data/ext/kobako/src/{runtime/filesystem → filesystem}/grants.rs +30 -26
- data/ext/kobako/src/{runtime/filesystem → filesystem}/ruby.rs +149 -168
- data/ext/kobako/src/{runtime/filesystem.rs → filesystem.rs} +24 -15
- data/ext/kobako/src/gvl.rs +306 -0
- data/ext/kobako/src/lib.rs +64 -3
- data/ext/kobako/src/network/mock.rs +187 -0
- data/ext/kobako/src/network.rs +591 -0
- data/ext/kobako/src/runtime/bridge.rs +30 -29
- data/ext/kobako/src/runtime/snapshot.rs +4 -4
- data/ext/kobako/src/runtime.rs +221 -143
- data/ext/kobako/src/wire.rs +42 -0
- data/lib/kobako/catalog/extensions.rb +14 -2
- data/lib/kobako/catalog/flags.rb +3 -5
- data/lib/kobako/catalog/grants.rb +5 -4
- data/lib/kobako/catalog/handles.rb +5 -27
- data/lib/kobako/catalog/mount.rb +11 -3
- data/lib/kobako/catalog/network.rb +35 -0
- data/lib/kobako/catalog/replacements.rb +28 -0
- data/lib/kobako/catalog/services.rb +5 -19
- data/lib/kobako/catalog/snippets.rb +3 -18
- data/lib/kobako/catalog.rb +3 -0
- data/lib/kobako/codec/{utils.rb → boundary.rb} +4 -2
- data/lib/kobako/codec/decoder.rb +4 -4
- data/lib/kobako/codec/ext_types.rb +3 -3
- data/lib/kobako/codec/handle_walk.rb +3 -43
- data/lib/kobako/codec/value_budget.rb +132 -40
- data/lib/kobako/codec.rb +1 -1
- data/lib/kobako/context.rb +24 -11
- data/lib/kobako/errors.rb +15 -12
- data/lib/kobako/extension.rb +3 -2
- data/lib/kobako/filesystem.rb +9 -2
- data/lib/kobako/handle.rb +2 -2
- data/lib/kobako/names.rb +28 -0
- data/lib/kobako/network.rb +210 -0
- data/lib/kobako/outcome.rb +7 -7
- data/lib/kobako/pool.rb +45 -23
- data/lib/kobako/runtime.rb +3 -2
- data/lib/kobako/sandbox.rb +92 -35
- data/lib/kobako/sandbox_options.rb +41 -106
- data/lib/kobako/transport/argument_wrap.rb +64 -0
- data/lib/kobako/transport/block_failure.rb +1 -1
- data/lib/kobako/transport/dispatcher.rb +6 -6
- data/lib/kobako/transport/exposure.rb +26 -15
- data/lib/kobako/transport/reflection.rb +21 -4
- data/lib/kobako/transport/run.rb +8 -23
- data/lib/kobako/transport/yielder.rb +2 -9
- data/lib/kobako/transport.rb +1 -0
- data/lib/kobako/version.rb +1 -1
- data/lib/kobako.rb +6 -2
- data/release-please-config.json +15 -0
- data/sig/core/thread.rbs +6 -0
- data/sig/kobako/catalog/extensions.rbs +2 -0
- data/sig/kobako/catalog/grants.rbs +7 -4
- data/sig/kobako/catalog/handles.rbs +0 -2
- data/sig/kobako/catalog/mount.rbs +3 -1
- data/sig/kobako/catalog/network.rbs +20 -0
- data/sig/kobako/catalog/replacements.rbs +14 -0
- data/sig/kobako/catalog/services.rbs +0 -4
- data/sig/kobako/catalog/snippets.rbs +0 -2
- data/sig/kobako/codec/{utils.rbs → boundary.rbs} +2 -2
- data/sig/kobako/codec/handle_walk.rbs +0 -6
- data/sig/kobako/codec/value_budget.rbs +47 -4
- data/sig/kobako/context.rbs +3 -1
- data/sig/kobako/errors.rbs +4 -4
- data/sig/kobako/filesystem.rbs +21 -3
- data/sig/kobako/network.rbs +115 -0
- data/sig/kobako/outcome.rbs +1 -1
- data/sig/kobako/pool.rbs +7 -3
- data/sig/kobako/runtime.rbs +32 -3
- data/sig/kobako/sandbox.rbs +19 -2
- data/sig/kobako/sandbox_options.rbs +29 -38
- data/sig/kobako/transport/argument_wrap.rbs +15 -0
- data/sig/kobako/transport/error.rbs +1 -1
- data/sig/kobako/transport/exposure.rbs +2 -4
- data/sig/kobako/transport/reflection.rbs +10 -0
- data/sig/kobako/transport/run.rbs +0 -2
- data/sig/kobako/transport/yielder.rbs +0 -3
- data/sig/kobako/transport.rbs +1 -1
- data/sig/kobako.rbs +13 -0
- metadata +84 -35
- data/crates/kobako-runtime/src/endpoint/capture.rs +0 -115
- data/crates/kobako-runtime/src/endpoint/memory_cap.rs +0 -238
- data/crates/kobako-runtime/src/filesystem/path.rs +0 -21
- data/crates/kobako-runtime/src/vfs/errno.rs +0 -153
- data/crates/kobako-runtime/tests/linux_baseline/calls.rs +0 -171
- data/crates/kobako-runtime/tests/linux_baseline/concurrent.rs +0 -276
- data/crates/kobako-runtime/tests/linux_baseline/kobako.rs +0 -323
- data/crates/kobako-runtime/tests/linux_baseline/linux-baseline-expected.txt +0 -16
- data/crates/kobako-runtime/tests/linux_baseline/linux.rs +0 -449
- data/crates/kobako-runtime/tests/linux_baseline/main.rs +0 -611
- data/crates/kobako-runtime/tests/linux_baseline/permissions.rs +0 -236
- data/crates/kobako-wasmtime/src/descriptors.rs +0 -200
- data/crates/kobako-wasmtime/tests/integration/compile_posture.rs +0 -43
- data/crates/kobako-wasmtime/tests/integration/guest_file.rs +0 -1085
- data/crates/kobako-wasmtime/tests/integration/main.rs +0 -29
- data/crates/kobako-wasmtime/tests/integration/preamble_flags.rs +0 -70
- data/crates/kobako-wasmtime/tests/integration/snippet_compile.rs +0 -95
- data/crates/kobako-wasmtime/tests/integration/support/mod.rs +0 -30
- data/crates/kobako-wasmtime/tests/integration/unanswered_call.rs +0 -86
- data/crates/kobako-wasmtime/tests/integration/unsupported_call.rs +0 -51
- data/ext/kobako/src/runtime/gvl.rs +0 -147
- data/lib/kobako/constant_name.rb +0 -8
- data/sig/kobako/constant_name.rbs +0 -3
- /data/ext/kobako/src/{runtime/pinned_value.rs → pinned_value.rs} +0 -0
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
use std::sync::Arc;
|
|
6
6
|
|
|
7
|
-
use super::super::{
|
|
7
|
+
use super::super::{Errno, FileOperations, Kiocb, OpenHow};
|
|
8
8
|
use super::inode::OverlayFileInode;
|
|
9
9
|
use crate::vfs::{generic_file_llseek, Dentry, Whence};
|
|
10
10
|
|
|
@@ -36,7 +36,7 @@ struct OverlayFile {
|
|
|
36
36
|
|
|
37
37
|
impl OverlayFile {
|
|
38
38
|
/// The file holding the data now, as `ovl_real_file_path` finds it.
|
|
39
|
-
fn real_file(&mut self) -> Result<&mut dyn FileOperations,
|
|
39
|
+
fn real_file(&mut self) -> Result<&mut dyn FileOperations, Errno> {
|
|
40
40
|
if self.upper.is_none() {
|
|
41
41
|
let real = self.inode.path_real();
|
|
42
42
|
if !Arc::ptr_eq(real.dentry(), &self.real) {
|
|
@@ -63,21 +63,21 @@ impl FileOperations for OverlayFile {
|
|
|
63
63
|
pos: u64,
|
|
64
64
|
offset: i64,
|
|
65
65
|
whence: Whence,
|
|
66
|
-
) -> Result<u64,
|
|
66
|
+
) -> Result<u64, Errno> {
|
|
67
67
|
generic_file_llseek(dentry, pos, offset, whence)
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
fn read_iter(&mut self, iocb: &mut Kiocb, buf: &mut [u8]) -> Result<usize,
|
|
70
|
+
fn read_iter(&mut self, iocb: &mut Kiocb, buf: &mut [u8]) -> Result<usize, Errno> {
|
|
71
71
|
self.real_file()?.read_iter(iocb, buf)
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
/// A file open to read flushes what it reads, as `ovl_fsync` syncs the
|
|
75
75
|
/// real file.
|
|
76
|
-
fn fsync(&mut self, datasync: bool) -> Result<(),
|
|
76
|
+
fn fsync(&mut self, datasync: bool) -> Result<(), Errno> {
|
|
77
77
|
self.real_file()?.fsync(datasync)
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
fn flush(&mut self) -> Result<(),
|
|
80
|
+
fn flush(&mut self) -> Result<(), Errno> {
|
|
81
81
|
self.file.flush()
|
|
82
82
|
}
|
|
83
83
|
|
|
@@ -14,20 +14,21 @@ use std::sync::Arc;
|
|
|
14
14
|
|
|
15
15
|
use super::super::tmpfs::TmpfsFile;
|
|
16
16
|
use super::super::{
|
|
17
|
-
DirEntry, FileOperations, FileType, Filesystem,
|
|
18
|
-
|
|
17
|
+
DirEntry, Errno, FileOperations, FileType, Filesystem, Iattr, InodeOperations, Kstat, Lookup,
|
|
18
|
+
OpenHow, SetTime, Tmpfs,
|
|
19
19
|
};
|
|
20
|
+
use crate::cred::Cred;
|
|
20
21
|
use crate::locking::RwSemaphoreGuard;
|
|
21
22
|
use crate::vfs::{
|
|
22
23
|
__start_renaming, inode_permission, lookup_one_unlocked, may_create_dentry, notify_change,
|
|
23
|
-
start_creating, start_removing, vfs_create, vfs_mkdir, vfs_rename, vfs_rmdir, vfs_unlink,
|
|
24
|
+
start_creating, start_removing, vfs_create, vfs_mkdir, vfs_rename, vfs_rmdir, vfs_unlink,
|
|
24
25
|
Dentry, DirContext, DirEmit, Mask, RenameFlag,
|
|
25
26
|
};
|
|
26
27
|
|
|
27
28
|
/// The change setting what `stat` reports of its times, as
|
|
28
29
|
/// `ovl_set_timestamps` sets `ATTR_ATIME_SET` and `ATTR_MTIME_SET`.
|
|
29
30
|
pub(super) fn timestamps(stat: &Kstat) -> Iattr<'static> {
|
|
30
|
-
Iattr::
|
|
31
|
+
Iattr::for_times(stat.atime.map(SetTime::At), stat.mtime.map(SetTime::At))
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
/// The attribute marking a directory opaque, and its value, as
|
|
@@ -48,7 +49,7 @@ impl OverlayPath {
|
|
|
48
49
|
/// The root of the Layer `filesystem` stands for.
|
|
49
50
|
pub(super) fn root(filesystem: &Arc<Filesystem>, creator_cred: &Arc<Cred>) -> Self {
|
|
50
51
|
Self {
|
|
51
|
-
dentry: filesystem.
|
|
52
|
+
dentry: filesystem.root().expect(crate::vfs::MADE_ROOT).clone(),
|
|
52
53
|
filesystem: filesystem.clone(),
|
|
53
54
|
creator_cred: creator_cred.clone(),
|
|
54
55
|
}
|
|
@@ -68,31 +69,25 @@ impl OverlayPath {
|
|
|
68
69
|
|
|
69
70
|
/// The dentry of `name` as this directory stores it, what stands there
|
|
70
71
|
/// recorded on it.
|
|
71
|
-
fn lookup_real(&self, name: &str) -> Result<Arc<Dentry>,
|
|
72
|
+
fn lookup_real(&self, name: &str) -> Result<Arc<Dentry>, Errno> {
|
|
72
73
|
lookup_one_unlocked(&self.creator_cred, &self.filesystem, &self.dentry, name)
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
/// This directory held for making `name`, and its dentry.
|
|
76
|
-
fn start_creating(
|
|
77
|
-
&self,
|
|
78
|
-
name: &str,
|
|
79
|
-
) -> Result<(RwSemaphoreGuard, Arc<Dentry>), FilesystemError> {
|
|
77
|
+
fn start_creating(&self, name: &str) -> Result<(RwSemaphoreGuard, Arc<Dentry>), Errno> {
|
|
80
78
|
start_creating(&self.creator_cred, &self.filesystem, &self.dentry, name)
|
|
81
79
|
}
|
|
82
80
|
|
|
83
81
|
/// This directory held for removing what stands at `name`, and its dentry.
|
|
84
|
-
fn start_removing(
|
|
85
|
-
&self,
|
|
86
|
-
name: &str,
|
|
87
|
-
) -> Result<(RwSemaphoreGuard, Arc<Dentry>), FilesystemError> {
|
|
82
|
+
fn start_removing(&self, name: &str) -> Result<(RwSemaphoreGuard, Arc<Dentry>), Errno> {
|
|
88
83
|
start_removing(&self.creator_cred, &self.filesystem, &self.dentry, name)
|
|
89
84
|
}
|
|
90
85
|
|
|
91
|
-
fn inode_lock_shared(&self) -> Result<RwSemaphoreGuard,
|
|
86
|
+
fn inode_lock_shared(&self) -> Result<RwSemaphoreGuard, Errno> {
|
|
92
87
|
self.dentry.inode_lock_shared()
|
|
93
88
|
}
|
|
94
89
|
|
|
95
|
-
fn inode_lock(&self) -> Result<RwSemaphoreGuard,
|
|
90
|
+
fn inode_lock(&self) -> Result<RwSemaphoreGuard, Errno> {
|
|
96
91
|
self.dentry.inode_lock()
|
|
97
92
|
}
|
|
98
93
|
|
|
@@ -103,8 +98,8 @@ impl OverlayPath {
|
|
|
103
98
|
}
|
|
104
99
|
|
|
105
100
|
/// This directory of the upper, which is always a Tmpfs.
|
|
106
|
-
fn upper(&self) -> Result<Arc<Tmpfs>,
|
|
107
|
-
self.tmpfs().ok_or(
|
|
101
|
+
fn upper(&self) -> Result<Arc<Tmpfs>, Errno> {
|
|
102
|
+
self.tmpfs().ok_or(Errno::ReadOnlyFilesystem)
|
|
108
103
|
}
|
|
109
104
|
|
|
110
105
|
/// Whether a whiteout stands at `name`, as `ovl_is_whiteout` reads the
|
|
@@ -113,13 +108,6 @@ impl OverlayPath {
|
|
|
113
108
|
self.tmpfs().is_some_and(|tmpfs| tmpfs.is_whiteout(name))
|
|
114
109
|
}
|
|
115
110
|
|
|
116
|
-
/// Whether `dentry`, found in this directory, stands for a whiteout, as
|
|
117
|
-
/// `ovl_is_whiteout` reads a dentry, a character device being one only in a
|
|
118
|
-
/// Tmpfs, whose marks an Overlay reads.
|
|
119
|
-
pub(super) fn is_whiteout_dentry(&self, dentry: &Dentry) -> bool {
|
|
120
|
-
dentry.kind() == Ok(FileType::Chrdev) && self.tmpfs().is_some()
|
|
121
|
-
}
|
|
122
|
-
|
|
123
111
|
/// Whether this directory hides the Layers below it.
|
|
124
112
|
pub(super) fn is_opaque(&self) -> bool {
|
|
125
113
|
self.tmpfs()
|
|
@@ -127,47 +115,43 @@ impl OverlayPath {
|
|
|
127
115
|
.is_some_and(|value| value == OPAQUE)
|
|
128
116
|
}
|
|
129
117
|
|
|
130
|
-
pub(super) fn set_opaque(&self) -> Result<(),
|
|
118
|
+
pub(super) fn set_opaque(&self) -> Result<(), Errno> {
|
|
131
119
|
let _held = self.inode_lock()?;
|
|
132
120
|
self.upper()?.setxattr(OPAQUE_XATTR, OPAQUE)
|
|
133
121
|
}
|
|
134
122
|
|
|
135
|
-
pub(super) fn do_whiteout(&self, name: &str) -> Result<(),
|
|
123
|
+
pub(super) fn do_whiteout(&self, name: &str) -> Result<(), Errno> {
|
|
136
124
|
let (_held, dentry) = self.start_creating(name)?;
|
|
137
125
|
may_create_dentry(&self.creator_cred, &self.filesystem, &self.dentry, &dentry)?;
|
|
138
126
|
self.upper()?.whiteout(name)
|
|
139
127
|
}
|
|
140
128
|
|
|
141
|
-
/// Move `
|
|
142
|
-
/// `
|
|
129
|
+
/// Move `old` here to `new` in `new_dir` as `renameat2` does with
|
|
130
|
+
/// `flags`.
|
|
143
131
|
pub(super) fn do_rename(
|
|
144
132
|
&self,
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
) -> Result<(),
|
|
133
|
+
old: &str,
|
|
134
|
+
new_dir: &OverlayPath,
|
|
135
|
+
new: &str,
|
|
136
|
+
flags: Option<RenameFlag>,
|
|
137
|
+
) -> Result<(), Errno> {
|
|
150
138
|
let rd = __start_renaming(
|
|
151
139
|
&self.filesystem,
|
|
152
|
-
(&self.dentry,
|
|
153
|
-
(&
|
|
154
|
-
|
|
140
|
+
(&self.dentry, old),
|
|
141
|
+
(&new_dir.dentry, new),
|
|
142
|
+
flags,
|
|
155
143
|
)?;
|
|
156
144
|
vfs_rename(&self.creator_cred, &self.filesystem, &rd)
|
|
157
145
|
}
|
|
158
146
|
|
|
159
|
-
pub(super) fn do_tmpfile(&self) -> Result<TmpfsFile,
|
|
147
|
+
pub(super) fn do_tmpfile(&self) -> Result<TmpfsFile, Errno> {
|
|
160
148
|
self.upper()?.tmpfile()
|
|
161
149
|
}
|
|
162
150
|
|
|
163
151
|
/// Name `file` here, answering the dentry of what was linked, as
|
|
164
152
|
/// `ovl_do_link` leaves it on the dentry it was handed, so nothing landing at
|
|
165
153
|
/// the name afterwards is taken for it.
|
|
166
|
-
pub(super) fn do_link(
|
|
167
|
-
&self,
|
|
168
|
-
file: &TmpfsFile,
|
|
169
|
-
name: &str,
|
|
170
|
-
) -> Result<Arc<Dentry>, FilesystemError> {
|
|
154
|
+
pub(super) fn do_link(&self, file: &TmpfsFile, name: &str) -> Result<Arc<Dentry>, Errno> {
|
|
171
155
|
let (_held, dentry) = self.start_creating(name)?;
|
|
172
156
|
may_create_dentry(&self.creator_cred, &self.filesystem, &self.dentry, &dentry)?;
|
|
173
157
|
let upper = self.upper()?;
|
|
@@ -180,17 +164,14 @@ impl OverlayPath {
|
|
|
180
164
|
|
|
181
165
|
/// Set this directory's times to those `stat` reports, as
|
|
182
166
|
/// `ovl_set_timestamps` hands `notify_change` the upper dentry.
|
|
183
|
-
pub(super) fn set_timestamps(&self, stat: &Kstat) -> Result<(),
|
|
167
|
+
pub(super) fn set_timestamps(&self, stat: &Kstat) -> Result<(), Errno> {
|
|
184
168
|
let held = self.dentry.inode_lock()?;
|
|
185
169
|
notify_change(&self.dentry, &held, ×tamps(stat))
|
|
186
170
|
}
|
|
187
171
|
|
|
188
172
|
/// `name` as this directory stores it and the dentry standing there, `None`
|
|
189
173
|
/// where nothing does, as `ovl_lookup_single` asks a layer once for a name.
|
|
190
|
-
pub(super) fn lookup_single(
|
|
191
|
-
&self,
|
|
192
|
-
name: &str,
|
|
193
|
-
) -> Result<Option<(String, Arc<Dentry>)>, FilesystemError> {
|
|
174
|
+
pub(super) fn lookup_single(&self, name: &str) -> Result<Option<(String, Arc<Dentry>)>, Errno> {
|
|
194
175
|
let dentry = self.lookup_real(name)?;
|
|
195
176
|
Ok(dentry.inode().is_some().then(|| (dentry.name(), dentry)))
|
|
196
177
|
}
|
|
@@ -204,34 +185,34 @@ impl OverlayPath {
|
|
|
204
185
|
}
|
|
205
186
|
|
|
206
187
|
/// Make the file `name`, holding the directory, as `ovl_do_create` does.
|
|
207
|
-
pub(super) fn do_create(&self, name: &str) -> Result<(),
|
|
188
|
+
pub(super) fn do_create(&self, name: &str) -> Result<(), Errno> {
|
|
208
189
|
let (_held, child) = self.start_creating(name)?;
|
|
209
190
|
vfs_create(&self.creator_cred, &self.filesystem, &self.dentry, &child)
|
|
210
191
|
}
|
|
211
192
|
|
|
212
193
|
/// The directory standing at `name`, a link there refused as a loop, as
|
|
213
194
|
/// `ovl_lookup` follows no link in a Layer.
|
|
214
|
-
pub(super) fn open_dir(&self, name: &str) -> Result<Self,
|
|
195
|
+
pub(super) fn open_dir(&self, name: &str) -> Result<Self, Errno> {
|
|
215
196
|
let dentry = self.lookup_real(name)?;
|
|
216
|
-
let inode = dentry.inode().ok_or(
|
|
217
|
-
match inode.
|
|
197
|
+
let inode = dentry.inode().ok_or(Errno::NotFound)?;
|
|
198
|
+
match inode.file_type() {
|
|
218
199
|
FileType::Dir => Ok(self.beneath(dentry)),
|
|
219
|
-
FileType::Symlink => Err(
|
|
220
|
-
_ => Err(
|
|
200
|
+
FileType::Symlink => Err(Errno::FilesystemLoop),
|
|
201
|
+
_ => Err(Errno::NotADirectory),
|
|
221
202
|
}
|
|
222
203
|
}
|
|
223
204
|
|
|
224
|
-
pub(super) fn getattr(&self) -> Result<Kstat,
|
|
205
|
+
pub(super) fn getattr(&self) -> Result<Kstat, Errno> {
|
|
225
206
|
self.dentry.getattr()
|
|
226
207
|
}
|
|
227
208
|
|
|
228
|
-
pub(super) fn getattr_at(&self, name: &str) -> Result<Kstat,
|
|
209
|
+
pub(super) fn getattr_at(&self, name: &str) -> Result<Kstat, Errno> {
|
|
229
210
|
self.lookup_real(name)?.getattr()
|
|
230
211
|
}
|
|
231
212
|
|
|
232
213
|
/// This directory opened, kept open for whoever holds it, as overlayfs's
|
|
233
214
|
/// `ovl_dir_open` opens the real directory.
|
|
234
|
-
pub(super) fn open_real(&self) -> Result<Box<dyn FileOperations>,
|
|
215
|
+
pub(super) fn open_real(&self) -> Result<Box<dyn FileOperations>, Errno> {
|
|
235
216
|
self.open_realfile(&OpenHow {
|
|
236
217
|
read: true,
|
|
237
218
|
..OpenHow::default()
|
|
@@ -241,10 +222,7 @@ impl OverlayPath {
|
|
|
241
222
|
/// What this dentry names opened as `how` asks, once its Layer lets the
|
|
242
223
|
/// Overlay's creator open it so, as `ovl_open_realfile` asks
|
|
243
224
|
/// `inode_permission` for `MAY_OPEN` and the access before it opens.
|
|
244
|
-
pub(super) fn open_realfile(
|
|
245
|
-
&self,
|
|
246
|
-
how: &OpenHow,
|
|
247
|
-
) -> Result<Box<dyn FileOperations>, FilesystemError> {
|
|
225
|
+
pub(super) fn open_realfile(&self, how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
|
|
248
226
|
let mut mask = Mask::OPEN;
|
|
249
227
|
if how.read {
|
|
250
228
|
mask = mask | Mask::READ;
|
|
@@ -256,7 +234,7 @@ impl OverlayPath {
|
|
|
256
234
|
self.dentry.open(how)
|
|
257
235
|
}
|
|
258
236
|
|
|
259
|
-
pub(super) fn entries(&self) -> Result<Vec<DirEntry>,
|
|
237
|
+
pub(super) fn entries(&self) -> Result<Vec<DirEntry>, Errno> {
|
|
260
238
|
let _held = self.inode_lock_shared()?;
|
|
261
239
|
let mut entries = Vec::new();
|
|
262
240
|
let mut actor = |emit: &DirEmit<'_>| {
|
|
@@ -268,17 +246,17 @@ impl OverlayPath {
|
|
|
268
246
|
Ok(entries)
|
|
269
247
|
}
|
|
270
248
|
|
|
271
|
-
pub(super) fn do_mkdir(&self, name: &str) -> Result<(),
|
|
249
|
+
pub(super) fn do_mkdir(&self, name: &str) -> Result<(), Errno> {
|
|
272
250
|
let (_held, child) = self.start_creating(name)?;
|
|
273
251
|
vfs_mkdir(&self.creator_cred, &self.filesystem, &self.dentry, &child)
|
|
274
252
|
}
|
|
275
253
|
|
|
276
|
-
pub(super) fn do_rmdir(&self, name: &str) -> Result<(),
|
|
254
|
+
pub(super) fn do_rmdir(&self, name: &str) -> Result<(), Errno> {
|
|
277
255
|
let (_held, victim) = self.start_removing(name)?;
|
|
278
256
|
vfs_rmdir(&self.creator_cred, &self.filesystem, &self.dentry, &victim)
|
|
279
257
|
}
|
|
280
258
|
|
|
281
|
-
pub(super) fn do_unlink(&self, name: &str) -> Result<(),
|
|
259
|
+
pub(super) fn do_unlink(&self, name: &str) -> Result<(), Errno> {
|
|
282
260
|
let (_held, victim) = self.start_removing(name)?;
|
|
283
261
|
vfs_unlink(&self.creator_cred, &self.filesystem, &self.dentry, &victim)
|
|
284
262
|
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
use std::sync::Arc;
|
|
7
7
|
|
|
8
|
-
use super::super::super::{
|
|
8
|
+
use super::super::super::{Errno, FileType, OpenHow};
|
|
9
9
|
use super::super::inode::OverlayFileInode;
|
|
10
10
|
use super::super::path::{timestamps, OverlayPath};
|
|
11
11
|
use super::{copy_whole, OverlayFs, ViewDir, UPPER};
|
|
@@ -16,10 +16,7 @@ impl OverlayFs {
|
|
|
16
16
|
/// above it that so far shows only from another Layer, as overlayfs's
|
|
17
17
|
/// `ovl_copy_up_flags` climbs the dentry's parents in a loop to copy up the
|
|
18
18
|
/// topmost first, however deep the Layer's tree is.
|
|
19
|
-
pub(in super::super) fn upper_dir(
|
|
20
|
-
&self,
|
|
21
|
-
dir: &ViewDir,
|
|
22
|
-
) -> Result<OverlayPath, FilesystemError> {
|
|
19
|
+
pub(in super::super) fn upper_dir(&self, dir: &ViewDir) -> Result<OverlayPath, Errno> {
|
|
23
20
|
let mut unmade = Vec::new();
|
|
24
21
|
let mut at = dir.clone();
|
|
25
22
|
let mut made = loop {
|
|
@@ -41,11 +38,7 @@ impl OverlayFs {
|
|
|
41
38
|
/// `ovl_copy_up_workdir` does. Another call may have copied it up while this
|
|
42
39
|
/// one waited, as `ovl_already_copied_up_locked` checks; what else stands at
|
|
43
40
|
/// the name is no copy of this directory, and refuses the move.
|
|
44
|
-
fn copy_up_dir(
|
|
45
|
-
&self,
|
|
46
|
-
dir: &ViewDir,
|
|
47
|
-
parent: &OverlayPath,
|
|
48
|
-
) -> Result<OverlayPath, FilesystemError> {
|
|
41
|
+
fn copy_up_dir(&self, dir: &ViewDir, parent: &OverlayPath) -> Result<OverlayPath, Errno> {
|
|
49
42
|
let name = dir.dentry.name();
|
|
50
43
|
let _held = dir.inode.lock.down_write()?;
|
|
51
44
|
let level = dir.level();
|
|
@@ -56,7 +49,7 @@ impl OverlayFs {
|
|
|
56
49
|
.iter()
|
|
57
50
|
.flatten()
|
|
58
51
|
.next()
|
|
59
|
-
.ok_or(
|
|
52
|
+
.ok_or(Errno::NotFound)?
|
|
60
53
|
.getattr()?;
|
|
61
54
|
let (work, temp) = self.tempname()?;
|
|
62
55
|
work.do_mkdir(&temp)?;
|
|
@@ -67,7 +60,7 @@ impl OverlayFs {
|
|
|
67
60
|
let moved =
|
|
68
61
|
made.and_then(|()| work.do_rename(&temp, parent, &name, Some(RenameFlag::NoReplace)));
|
|
69
62
|
if let Err(err) = moved {
|
|
70
|
-
|
|
63
|
+
self.cleanup_temp(work, &temp);
|
|
71
64
|
return Err(err);
|
|
72
65
|
}
|
|
73
66
|
let _ = parent.set_timestamps(&parent_times);
|
|
@@ -98,14 +91,14 @@ impl OverlayFs {
|
|
|
98
91
|
dir: &ViewDir,
|
|
99
92
|
child: &Dentry,
|
|
100
93
|
truncate: bool,
|
|
101
|
-
) -> Result<(),
|
|
94
|
+
) -> Result<(), Errno> {
|
|
102
95
|
let name = child.name();
|
|
103
96
|
let target_dir = self.upper_dir(dir)?;
|
|
104
97
|
let inode = child
|
|
105
98
|
.inode()
|
|
106
99
|
.as_deref()
|
|
107
100
|
.and_then(OverlayFileInode::of)
|
|
108
|
-
.ok_or(
|
|
101
|
+
.ok_or(Errno::NotFound)?;
|
|
109
102
|
let _held = inode.lock.down_write()?;
|
|
110
103
|
let real = inode.path_real();
|
|
111
104
|
// Another call may have copied it up while this one waited, as
|
|
@@ -115,7 +108,7 @@ impl OverlayFs {
|
|
|
115
108
|
}
|
|
116
109
|
let lower = real.getattr()?;
|
|
117
110
|
if lower.file_type != FileType::RegFile {
|
|
118
|
-
return Err(
|
|
111
|
+
return Err(Errno::PermissionDenied);
|
|
119
112
|
}
|
|
120
113
|
let mut copy = target_dir.do_tmpfile()?;
|
|
121
114
|
if !truncate {
|
|
@@ -123,7 +116,7 @@ impl OverlayFs {
|
|
|
123
116
|
read: true,
|
|
124
117
|
..OpenHow::default()
|
|
125
118
|
})?;
|
|
126
|
-
copy_whole(source.as_mut(), &mut copy)?;
|
|
119
|
+
copy_whole(source.as_mut(), &mut copy, lower.size)?;
|
|
127
120
|
}
|
|
128
121
|
copy.setattr(×tamps(&lower));
|
|
129
122
|
let parent_times = target_dir.getattr()?;
|
|
@@ -4,14 +4,11 @@
|
|
|
4
4
|
//! in the workdir and exchanged into place, so it lands whole or not at
|
|
5
5
|
//! all.
|
|
6
6
|
|
|
7
|
-
use super::super::super::{FileOperations, FileType,
|
|
7
|
+
use super::super::super::{Errno, FileOperations, FileType, OpenHow};
|
|
8
8
|
use super::super::file::ovl_file;
|
|
9
9
|
use super::super::inode::{OverlayDirInode, OverlayFileInode};
|
|
10
10
|
use super::super::path::OverlayPath;
|
|
11
|
-
use super::{
|
|
12
|
-
entry, layer_dir, ovl_cleanup, ovl_cleanup_whiteouts, ovl_lower_positive, OverlayFs, ViewDir,
|
|
13
|
-
UPPER,
|
|
14
|
-
};
|
|
11
|
+
use super::{entry, layer_dir, ovl_cleanup, ovl_lower_positive, OverlayFs, ViewDir, UPPER};
|
|
15
12
|
use crate::vfs::{Dentry, RenameFlag};
|
|
16
13
|
|
|
17
14
|
impl OverlayFs {
|
|
@@ -20,17 +17,17 @@ impl OverlayFs {
|
|
|
20
17
|
/// landing meanwhile is hidden too, as overlayfs's `ovl_cleanup_and_whiteout`
|
|
21
18
|
/// does: only a directory, which no rename replaces while it holds anything,
|
|
22
19
|
/// is exchanged out to be cleaned up.
|
|
23
|
-
fn cleanup_and_whiteout(&self, dir: &OverlayPath, name: &str) -> Result<(),
|
|
20
|
+
fn cleanup_and_whiteout(&self, dir: &OverlayPath, name: &str) -> Result<(), Errno> {
|
|
24
21
|
let (work, temp) = self.tempname()?;
|
|
25
22
|
work.do_whiteout(&temp)?;
|
|
26
23
|
let is_dir = entry(dir, name)?.is_directory();
|
|
27
24
|
let flag = is_dir.then_some(RenameFlag::Exchange);
|
|
28
25
|
if let Err(err) = work.do_rename(&temp, dir, name, flag) {
|
|
29
|
-
|
|
26
|
+
self.cleanup_temp(work, &temp);
|
|
30
27
|
return Err(err);
|
|
31
28
|
}
|
|
32
29
|
if is_dir {
|
|
33
|
-
|
|
30
|
+
self.cleanup_temp(work, &temp);
|
|
34
31
|
}
|
|
35
32
|
Ok(())
|
|
36
33
|
}
|
|
@@ -44,18 +41,16 @@ impl OverlayFs {
|
|
|
44
41
|
&self,
|
|
45
42
|
dir: &OverlayPath,
|
|
46
43
|
name: &str,
|
|
47
|
-
make: impl FnOnce(&OverlayPath, &str) -> Result<T,
|
|
48
|
-
) -> Result<T,
|
|
44
|
+
make: impl FnOnce(&OverlayPath, &str) -> Result<T, Errno>,
|
|
45
|
+
) -> Result<T, Errno> {
|
|
49
46
|
let (work, temp) = self.tempname()?;
|
|
50
47
|
let made = make(work, &temp)
|
|
51
48
|
.and_then(|made| {
|
|
52
49
|
work.do_rename(&temp, dir, name, Some(RenameFlag::Exchange))?;
|
|
53
50
|
Ok(made)
|
|
54
51
|
})
|
|
55
|
-
.inspect_err(|_|
|
|
56
|
-
|
|
57
|
-
})?;
|
|
58
|
-
let _ = ovl_cleanup_whiteouts(work, &temp).and_then(|()| ovl_cleanup(work, &temp));
|
|
52
|
+
.inspect_err(|_| self.cleanup_temp(work, &temp))?;
|
|
53
|
+
self.cleanup_temp(work, &temp);
|
|
59
54
|
Ok(made)
|
|
60
55
|
}
|
|
61
56
|
|
|
@@ -63,11 +58,7 @@ impl OverlayFs {
|
|
|
63
58
|
/// `dir`, as overlayfs's `ovl_clear_empty` does, so the view shows it empty
|
|
64
59
|
/// throughout. A dentry naming a directory there no longer matches, so the next
|
|
65
60
|
/// walk finds the one exchanged in, should what follows fail.
|
|
66
|
-
pub(in super::super) fn clear_empty(
|
|
67
|
-
&self,
|
|
68
|
-
dir: &OverlayPath,
|
|
69
|
-
name: &str,
|
|
70
|
-
) -> Result<(), FilesystemError> {
|
|
61
|
+
pub(in super::super) fn clear_empty(&self, dir: &OverlayPath, name: &str) -> Result<(), Errno> {
|
|
71
62
|
self.exchange_in(dir, name, |work, temp| {
|
|
72
63
|
work.do_mkdir(temp)?;
|
|
73
64
|
work.open_dir(temp)?.set_opaque()
|
|
@@ -97,7 +88,7 @@ impl OverlayFs {
|
|
|
97
88
|
dir: &ViewDir,
|
|
98
89
|
dentry: &Dentry,
|
|
99
90
|
upper_whiteouts: bool,
|
|
100
|
-
) -> Result<(),
|
|
91
|
+
) -> Result<(), Errno> {
|
|
101
92
|
let name = &dentry.name();
|
|
102
93
|
let level = dir.level();
|
|
103
94
|
let shown_below = ovl_lower_positive(&level, name);
|
|
@@ -108,7 +99,7 @@ impl OverlayFs {
|
|
|
108
99
|
match (shown_below, upper_holds) {
|
|
109
100
|
(true, _) => self.cleanup_and_whiteout(&self.upper_dir(dir)?, name),
|
|
110
101
|
(false, true) => ovl_cleanup(layer_dir(&level[UPPER])?, name),
|
|
111
|
-
(false, false) => Err(
|
|
102
|
+
(false, false) => Err(Errno::NotFound),
|
|
112
103
|
}
|
|
113
104
|
}
|
|
114
105
|
|
|
@@ -120,9 +111,9 @@ impl OverlayFs {
|
|
|
120
111
|
dir: &ViewDir,
|
|
121
112
|
child: &Dentry,
|
|
122
113
|
how: &OpenHow,
|
|
123
|
-
) -> Result<Box<dyn FileOperations>,
|
|
124
|
-
let inode = child.inode().ok_or(
|
|
125
|
-
let kept = OverlayFileInode::of(&inode).ok_or(
|
|
114
|
+
) -> Result<Box<dyn FileOperations>, Errno> {
|
|
115
|
+
let inode = child.inode().ok_or(Errno::NotFound)?;
|
|
116
|
+
let kept = OverlayFileInode::of(&inode).ok_or(Errno::IsADirectory)?;
|
|
126
117
|
let real = kept.path_real();
|
|
127
118
|
if self.is_in_upper(real.dentry()) {
|
|
128
119
|
return real.open_realfile(how);
|
|
@@ -136,11 +127,7 @@ impl OverlayFs {
|
|
|
136
127
|
}
|
|
137
128
|
|
|
138
129
|
/// Make the file `name`, where the view shows nothing, in the upper.
|
|
139
|
-
pub(in super::super) fn create(
|
|
140
|
-
&self,
|
|
141
|
-
dir: &ViewDir,
|
|
142
|
-
name: &str,
|
|
143
|
-
) -> Result<(), FilesystemError> {
|
|
130
|
+
pub(in super::super) fn create(&self, dir: &ViewDir, name: &str) -> Result<(), Errno> {
|
|
144
131
|
let upper_dir = self.upper_dir(dir)?;
|
|
145
132
|
match upper_dir.is_whiteout(name) {
|
|
146
133
|
true => self.exchange_in(&upper_dir, name, |work, temp| work.do_create(temp)),
|
|
@@ -150,7 +137,7 @@ impl OverlayFs {
|
|
|
150
137
|
|
|
151
138
|
/// A directory made where a whiteout hid one is marked opaque, so the
|
|
152
139
|
/// lower Layers' entries never show in it.
|
|
153
|
-
pub(in super::super) fn mkdir(&self, dir: &ViewDir, name: &str) -> Result<(),
|
|
140
|
+
pub(in super::super) fn mkdir(&self, dir: &ViewDir, name: &str) -> Result<(), Errno> {
|
|
154
141
|
let upper_dir = self.upper_dir(dir)?;
|
|
155
142
|
match upper_dir.is_whiteout(name) {
|
|
156
143
|
true => self.clear_empty(&upper_dir, name),
|
|
@@ -158,23 +145,15 @@ impl OverlayFs {
|
|
|
158
145
|
}
|
|
159
146
|
}
|
|
160
147
|
|
|
161
|
-
pub(in super::super) fn rmdir(
|
|
162
|
-
&self,
|
|
163
|
-
dir: &ViewDir,
|
|
164
|
-
dentry: &Dentry,
|
|
165
|
-
) -> Result<(), FilesystemError> {
|
|
148
|
+
pub(in super::super) fn rmdir(&self, dir: &ViewDir, dentry: &Dentry) -> Result<(), Errno> {
|
|
166
149
|
let upper_whiteouts = self
|
|
167
150
|
.check_empty_dir(dentry)?
|
|
168
|
-
.ok_or(
|
|
151
|
+
.ok_or(Errno::DirectoryNotEmpty)?;
|
|
169
152
|
self.do_remove(dir, dentry, upper_whiteouts)
|
|
170
153
|
}
|
|
171
154
|
|
|
172
155
|
/// A link is removed as itself, wherever it points.
|
|
173
|
-
pub(in super::super) fn unlink(
|
|
174
|
-
&self,
|
|
175
|
-
dir: &ViewDir,
|
|
176
|
-
dentry: &Dentry,
|
|
177
|
-
) -> Result<(), FilesystemError> {
|
|
156
|
+
pub(in super::super) fn unlink(&self, dir: &ViewDir, dentry: &Dentry) -> Result<(), Errno> {
|
|
178
157
|
self.do_remove(dir, dentry, false)
|
|
179
158
|
}
|
|
180
159
|
|
|
@@ -182,7 +161,7 @@ impl OverlayFs {
|
|
|
182
161
|
/// `ovl_can_move` reads the dentry's entry: a directory only when the upper
|
|
183
162
|
/// alone holds it, a file always, once copied up, and anything else only from
|
|
184
163
|
/// the upper.
|
|
185
|
-
fn can_move(&self, moved: &Dentry, moving: FileType) -> Result<bool,
|
|
164
|
+
fn can_move(&self, moved: &Dentry, moving: FileType) -> Result<bool, Errno> {
|
|
186
165
|
if moving == FileType::Dir {
|
|
187
166
|
let level = self.dir(moved)?.level();
|
|
188
167
|
let lower = level.iter().skip(UPPER + 1).flatten().next().is_some();
|
|
@@ -195,68 +174,64 @@ impl OverlayFs {
|
|
|
195
174
|
/// out of a lower Layer would mean copying up everything beneath it,
|
|
196
175
|
/// so it is refused as crossing devices, as overlayfs refuses it
|
|
197
176
|
/// without `redirect_dir`; so is a link or another kind a lower Layer
|
|
198
|
-
/// holds, which no copy up can make. What the view holds at `
|
|
177
|
+
/// holds, which no copy up can make. What the view holds at `new` is
|
|
199
178
|
/// checked as rename(2) checks it. A directory moved into one a lower
|
|
200
179
|
/// Layer also shows is marked opaque before it moves, and the source leaves
|
|
201
180
|
/// a whiteout as it moves when a lower Layer still shows it, as
|
|
202
181
|
/// overlayfs's `ovl_rename` does.
|
|
203
182
|
pub(in super::super) fn rename(
|
|
204
183
|
&self,
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
) -> Result<(),
|
|
210
|
-
let (
|
|
211
|
-
let
|
|
212
|
-
let moving =
|
|
213
|
-
let
|
|
184
|
+
old_dir: &ViewDir,
|
|
185
|
+
old: &Dentry,
|
|
186
|
+
new_dir: &ViewDir,
|
|
187
|
+
new: &Dentry,
|
|
188
|
+
) -> Result<(), Errno> {
|
|
189
|
+
let (old_name, new_name) = (&old.name(), &new.name());
|
|
190
|
+
let old_level = old_dir.level();
|
|
191
|
+
let moving = old.file_type()?;
|
|
192
|
+
let new_level = new_dir.level();
|
|
214
193
|
let is_dir = moving == FileType::Dir;
|
|
215
194
|
// What cannot move answers first, as `ovl_rename_start` asks
|
|
216
195
|
// `ovl_can_move` before it looks at what would be replaced.
|
|
217
|
-
if !self.can_move(
|
|
218
|
-
return Err(
|
|
196
|
+
if !self.can_move(old, moving)? {
|
|
197
|
+
return Err(Errno::CrossesDevices);
|
|
219
198
|
}
|
|
220
199
|
// Only an empty directory is replaced.
|
|
221
|
-
let upper_whiteouts = match
|
|
222
|
-
true => self
|
|
223
|
-
.check_empty_dir(target)?
|
|
224
|
-
.ok_or(FilesystemError::DirectoryNotEmpty)?,
|
|
200
|
+
let upper_whiteouts = match new.file_type() == Ok(FileType::Dir) {
|
|
201
|
+
true => self.check_empty_dir(new)?.ok_or(Errno::DirectoryNotEmpty)?,
|
|
225
202
|
false => false,
|
|
226
203
|
};
|
|
227
|
-
let shown_below = ovl_lower_positive(&
|
|
204
|
+
let shown_below = ovl_lower_positive(&old_level, old_name);
|
|
228
205
|
if moving == FileType::RegFile {
|
|
229
|
-
self.copy_up_file(
|
|
206
|
+
self.copy_up_file(old_dir, old, false)?;
|
|
230
207
|
}
|
|
231
|
-
let
|
|
208
|
+
let new_upperdir = self.upper_dir(new_dir)?;
|
|
232
209
|
// A directory holding only whiteouts is replaced by an empty one first,
|
|
233
210
|
// as `ovl_rename_upper` calls `ovl_clear_empty` for a list not empty.
|
|
234
211
|
if upper_whiteouts {
|
|
235
|
-
self.clear_empty(&
|
|
212
|
+
self.clear_empty(&new_upperdir, new_name)?;
|
|
236
213
|
}
|
|
237
|
-
let
|
|
238
|
-
.clone()
|
|
239
|
-
.ok_or(FilesystemError::NotFound)?;
|
|
214
|
+
let old_upperdir = old_dir.level()[UPPER].clone().ok_or(Errno::NotFound)?;
|
|
240
215
|
// Nothing below shows a directory the upper alone holds, so a mark left
|
|
241
216
|
// on one by a move that then fails changes nothing, as `ovl_rename`
|
|
242
217
|
// leaves it.
|
|
243
|
-
let into_merged =
|
|
218
|
+
let into_merged = new_level
|
|
244
219
|
.iter()
|
|
245
220
|
.enumerate()
|
|
246
221
|
.any(|(index, dir)| index != UPPER && dir.is_some());
|
|
247
222
|
if is_dir && into_merged {
|
|
248
|
-
|
|
223
|
+
old_upperdir.open_dir(old_name)?.set_opaque()?;
|
|
249
224
|
}
|
|
250
|
-
let onto_whiteout =
|
|
251
|
-
let
|
|
225
|
+
let onto_whiteout = new_upperdir.is_whiteout(new_name);
|
|
226
|
+
let flags = match (shown_below, onto_whiteout) {
|
|
252
227
|
(true, true) => Some(RenameFlag::Exchange),
|
|
253
228
|
(true, false) => Some(RenameFlag::Whiteout),
|
|
254
229
|
(false, true) if is_dir => Some(RenameFlag::Exchange),
|
|
255
230
|
_ => None,
|
|
256
231
|
};
|
|
257
|
-
|
|
258
|
-
if
|
|
259
|
-
|
|
232
|
+
old_upperdir.do_rename(old_name, &new_upperdir, new_name, flags)?;
|
|
233
|
+
if flags == Some(RenameFlag::Exchange) && !shown_below {
|
|
234
|
+
old_upperdir.do_unlink(old_name)?;
|
|
260
235
|
}
|
|
261
236
|
Ok(())
|
|
262
237
|
}
|