Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/architecture/core/compare-and-merge/merge.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ consumer.
| Part | Rule | Source |
| --- | --- | --- |
| Plan | Values, fresh serials and changed names as point records keyed by serial and name. | [`build.rs`](../../../../core/crates/layerfs-content/src/merge/build.rs), [`rows.rs`](../../../../core/crates/layerfs-content/src/merge/rows.rs) |
| Fresh serials | From the caller's `fresh` callback; a file value keeps its source serial only when that cannot give one serial two values. | [`build.rs`](../../../../core/crates/layerfs-content/src/merge/build.rs) |
| Fresh serials | From the caller's `fresh` callback; a file value keeps its source serial only when that cannot give one serial two values. A mounted Workspace that installs the result may still have the old serial held by its kernel (a cwd, an open descriptor): each request that names it answers ESTALE and the mount keeps serving ([kernel routes](../../engine/kernel-routes/fuse.md#requests-and-replies-request-attributesrs)). | [`build.rs`](../../../../core/crates/layerfs-content/src/merge/build.rs), [`eval.rs`](../../../../engine/crates/layerfs-workspace/src/mutation/eval.rs) |
| Spill | Runs of at most 60 KiB chunks; up to 8 MiB held in memory, then the caller's `IndexedConstructionBacking` records. Without records a `Resident` store is used. | [`spill.rs`](../../../../core/crates/layerfs-content/src/merge/spill.rs) |
| Result | One backed update of `into`, the same canonical producer and route as a Workspace Commit. No plan rows: `into`'s root unchanged. | [`build.rs`](../../../../core/crates/layerfs-content/src/merge/build.rs) |
| Outcome | Conflicts and `.lww` decisions sorted by path; `clean()` is true when there are no conflicts. | [`entry.rs`](../../../../core/crates/layerfs-content/src/merge/entry.rs), [`types.rs`](../../../../core/crates/layerfs-content/src/merge/types.rs) |
Expand Down
4 changes: 4 additions & 0 deletions docs/architecture/engine/kernel-routes/fuse.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ installed a root other than the one shown, for each `Stale::Inode` or
Retained(error) or panic -> failure kept, mount terminal
```

A request that ends itself (fenced, failed base demand, stale serial) is
`Complete`, not `Retained`, so it never makes the mount terminal.

| Item | Meaning | Source |
| --- | --- | --- |
| `MountRequests` | Per-mount request owner: counts, retained failures, parked threads, its `Fence`; no daemon-wide dispatcher | [`requests.rs`](../../../../engine/crates/layerfs-fuse/src/dispatch/requests.rs) |
Expand All @@ -109,6 +112,7 @@ reader holds its loop; two loops let one request proceed while another waits.
| --- | --- | --- |
| Fenced step (forced teardown) | `ENOTCONN`, counted on the fence | [`terminal.rs`](../../../../engine/crates/layerfs-fuse/src/request/terminal.rs) |
| Failed base demand of this request | `EIO`; the mount keeps serving | [`terminal.rs`](../../../../engine/crates/layerfs-fuse/src/request/terminal.rs) |
| Stale serial: a LOOKUP, GETATTR, OPEN, OPENDIR, READ, READLINK or READDIR names a serial that neither a local row nor the base has, because an install dropped it while the kernel held it (a merge rebuilt that directory or file under a fresh serial, or took the other side's removal) | `ESTALE` for that request alone; nothing is retained and the mount keeps serving. Only the engine's own `Stale` answer counts (`ports::stale`): an uncertain, retained or owner failure that carries one stays retained. A name that binds an absent inode, or a count leaving its range, is still corruption and still retained | [`terminal.rs`](../../../../engine/crates/layerfs-fuse/src/request/terminal.rs), [`ports.rs`](../../../../engine/crates/layerfs-mount-ports/src/ports.rs), [`eval.rs`](../../../../engine/crates/layerfs-workspace/src/mutation/eval.rs) |
| `Refusal` | `EEXIST`, `ENOENT`, `ENOTDIR`, `EISDIR`, `ENOTEMPTY`, `EPERM`, `EOPNOTSUPP`, `EINVAL`, `EMLINK`, `EFBIG` | [`attributes.rs`](../../../../engine/crates/layerfs-fuse/src/attributes.rs) |
| `Declined::NoSpace`, `Contended`, `TargetTooLong` | `ENOSPC`, `EAGAIN`, `ENAMETOOLONG` | [`attributes.rs`](../../../../engine/crates/layerfs-fuse/src/attributes.rs) |
| Missing LOOKUP name | Negative entry (node 0), 60 s entry TTL; every create, link, mkdir, symlink or rename through the mount replaces it | [`reply.rs`](../../../../engine/crates/layerfs-fuse/src/request/reply.rs) |
Expand Down
2 changes: 1 addition & 1 deletion docs/architecture/engine/overlay/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ commits or rolls back with that job's SQL through undo journals.

| Map | Holds | Source |
| --- | --- | --- |
| `mount`, `kernel`, `parents` | One kernel connection, `(mount, serial)` lookup counts, retained directory parents | [`open/kernel.rs`](../../../../engine/crates/layerfs-overlay/src/open/kernel.rs) |
| `mount`, `kernel`, `parents` | One kernel connection, `(mount, serial)` lookup counts, retained directory parents with the name each was recorded under (an install rewrites none; `kernel_ancestors` returns the links for the caller to check against its view) | [`open/kernel.rs`](../../../../engine/crates/layerfs-overlay/src/open/kernel.rs) |
| `files`, `directories`, `cookies` | Open descriptors, open directories and published READDIR cookie pages | same, [`open/directories.rs`](../../../../engine/crates/layerfs-overlay/src/open/directories.rs) |
| `reads`, `lookups`, `operations`, `captured` | Read windows, lookup references, operation owners, captured readers | [`open/kernel.rs`](../../../../engine/crates/layerfs-overlay/src/open/kernel.rs) |
| `custody`, `sources`, `orphans` | Per-serial opens, lookups and readers; held `BaseSource` windows; orphans | same |
Expand Down
15 changes: 13 additions & 2 deletions docs/architecture/engine/workspace/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ What each filesystem operation on a [Workspace](README.md) reads and publishes,
| --- | --- |
| A removed inode keeps a row with `nlink` 0, so serial-addressed access does not fall through to the base | [`remove.rs`](../../../../engine/crates/layerfs-workspace/src/operations/namespace/remove.rs) |
| Moving a directory to another parent needs ancestry evidence: a path caller passes `destination_path`, walked from the root and verified; a kernel caller uses the connection's retained parent index | [`rename.rs`](../../../../engine/crates/layerfs-workspace/src/operations/namespace/rename.rs), [`types.rs`](../../../../engine/crates/layerfs-workspace/src/operations/types.rs) |
| The retained parent index keeps, per kernel-known directory, its parent and its name there, written by LOOKUP, MKDIR, a READDIRPLUS handle and a rename (to another parent or in place). An install rewrites none of it, and a merged install can move a directory the kernel holds as a cwd or descriptor with no LOOKUP to follow. So a kernel rename of a directory checks every link from the destination up to the root against the current view (the parent must still bind that name to that directory) before its cycle check; a link that no longer holds is `AncestryMismatch` (EINVAL), and the next LOOKUP of that directory records its current place | [`rename.rs`](../../../../engine/crates/layerfs-workspace/src/operations/namespace/rename.rs), [`kernel_mutation.rs`](../../../../engine/crates/layerfs-overlay/src/lifetime/kernel_mutation.rs), [`kernel_directory.rs`](../../../../engine/crates/layerfs-overlay/src/lifetime/kernel_directory.rs) |
| Renaming one name of an inode onto another name of the same inode succeeds and changes nothing | [`rename.rs`](../../../../engine/crates/layerfs-workspace/src/operations/namespace/rename.rs) |
| A file renamed over a file records a `predecessor`, offered to Commit as a delta base | same |
| Parent `entries` and `subdirs` move in the same row as the binding; leaving range is an error, never clamped | [`eval.rs`](../../../../engine/crates/layerfs-workspace/src/mutation/eval.rs) |
Expand All @@ -59,7 +60,12 @@ What each filesystem operation on a [Workspace](README.md) reads and publishes,
window, whiteouts included, so a window can be empty and still continue. A
name bound for the whole enumeration is returned exactly once; names changed
meanwhile may or may not appear. A directory created above the installed
floor makes no base demand
floor makes no base demand. The base page may spend `PAGE_ROWS` rows of the
longest name, as the directory reader charges them (`NAME_LENGTH_BYTES` +
`DIRECTORY_LEAF_SERIAL_BYTES` + 255 bytes each), so it ends on its row bound.
Should a base page still end with a continuation before the window's other
keys, the merge stops at the base's last fetched name: a local key past it
would skip the base names between
([`namespace/list.rs`](../../../../engine/crates/layerfs-workspace/src/operations/namespace/list.rs)).

## Attributes
Expand Down Expand Up @@ -143,7 +149,12 @@ Facts carried between visits are used only while the Workspace still has the
base they came from, so an install between visits costs another read, never
a stale answer. OPEN names an inode the kernel still references, so a file
whose last name is gone stays openable. A data visit holds nothing after its
job.
job. A serial the kernel names by itself (GETATTR, OPEN, OPENDIR, a LOOKUP's
directory, READ, READLINK and READDIR of an open handle) that no local row or
base inode has any more was dropped by an install while the kernel held it:
the request fails with `OverlayError::Stale` (ESTALE on FUSE, `NFS3ERR_STALE`
on NFS) and nothing else changes (`Eval::held`). A name bound to an absent
inode is still `InvalidRecord`.

## Kernel directories

Expand Down
146 changes: 146 additions & 0 deletions engine/crates/layerfs-daemon/tests/stale_handles.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
//! A merged install changes what a held cwd names, and the mount serves on.
//!
//! Each case holds a directory of Workspace A as a process's cwd. Another
//! Workspace publishes a change to that directory, and A's next Commit merges
//! it and installs the merged root. No path walk refreshes the held cwd: the
//! kernel still names it by its old inode. The held process makes the checked
//! requests itself, from that cwd, once it is released.
//!
//! - The merge drops the directory's serial: GETATTR, OPENDIR and LOOKUP
//! through the cwd answer ESTALE for each request alone, nothing is retained
//! and the mount keeps serving (review finding #7).
//! - The merge moves the directory under another one: a rename of that other
//! directory into the cwd is refused instead of making a cycle cut off from
//! the root, and the kernel parent index follows the next LOOKUP (#17).
#![cfg(target_os = "linux")]
#[allow(dead_code)]
#[path = "support/installed_store.rs"]
mod installed;
#[allow(dead_code)]
#[path = "support/namespace_model.rs"]
mod model;
#[allow(dead_code)]
#[path = "support/mounted.rs"]
mod mounted;
#[allow(dead_code)]
#[path = "support/mounted_commit.rs"]
mod rig;
use layerfs_bridge::control::{ReadyMount, Reply};
use mounted::COMMAND;
use rig::{bash_in, passed, root, Background, Rig};

/// A's Commit merges with the other Workspace's and installs the result.
fn merged(rig: &Rig, a: &ReadyMount) {
passed(
&bash_in(COMMAND, root(a), "printf alpha > from-a"),
"A changes another file",
);
let done = rig.commit(a.token).expect("A commits");
assert!(
matches!(done.reply, Reply::MergeCommitted(_)),
"A's Commit merges: {:?}",
done.reply
);
}
/// No request of the mount was retained: it is not terminal.
fn serving(rig: &Rig, a: &ReadyMount, what: &str) {
let work = rig.harness.status(a.token).kernel.unwrap().work.unwrap();
assert_eq!(work.retained, 0, "{what}: {work:?}");
}
/// The held process waits for its release, then runs `checks` in its cwd;
/// a failed check is reported on its standard error.
fn held(directory: &std::path::Path, checks: &str) -> Background {
let script = format!("read line; set -u\n{checks}");
Background::spawn(COMMAND, directory, &script)
}

#[test]
fn a_held_directory_the_merge_dropped_answers_estale_and_the_mount_serves_on() {
let rig = Rig::new("stale-dropped-serial");
let a = rig.mount(1);
passed(
&bash_in(
COMMAND,
root(&a),
"mkdir -p doomed/inner && printf x > doomed/f",
),
"A makes doomed",
);
rig.committed(a.token, "A publishes doomed");
let b = rig.mount(2);
// GETATTR, OPENDIR and LOOKUP of the dropped directory, from inside it.
let process = held(
&root(&a).join("doomed"),
"stale() { case $1 in *'Stale file handle'*) ;; *) echo \"$2: $1\" >&2; exit 1;; esac; }
out=$(stat . 2>&1) && { echo \"stat passed: $out\" >&2; exit 1; }; stale \"$out\" stat
out=$(ls . 2>&1) && { echo \"ls passed: $out\" >&2; exit 1; }; stale \"$out\" ls
out=$(stat f 2>&1) && { echo \"lookup passed: $out\" >&2; exit 1; }; stale \"$out\" lookup
exit 0",
);
passed(
&bash_in(COMMAND, root(&b), "rm -rf doomed"),
"B removes doomed",
);
rig.committed(b.token, "B publishes the removal");
merged(&rig, &a);
let status = process.release();
assert!(status.success(), "the held cwd was not stale: {status:?}");
serving(&rig, &a, "after the stale requests");
passed(
&bash_in(
COMMAND,
root(&a),
"test \"$(cat from-a)\" = alpha && test ! -e doomed \
&& printf beta > after && test \"$(cat after)\" = beta",
),
"the mount serves on",
);
serving(&rig, &a, "after serving on");
rig.unmount(&a);
rig.unmount(&b);
rig.finish();
}

#[test]
fn a_rename_into_a_held_directory_the_merge_moved_makes_no_cycle() {
let rig = Rig::new("stale-parent-index");
let a = rig.mount(1);
passed(&bash_in(COMMAND, root(&a), "mkdir x y"), "A makes x and y");
rig.committed(a.token, "A publishes x and y");
let b = rig.mount(2);
// A's kernel still holds y as the cwd it looked up at the root. Moving x
// into it would make x and y a cycle cut off from the root. The first
// attempt runs before any LOOKUP of y's new place, so only the checked
// parent index can refuse it; after `test -d x/y` it is a known cycle.
let mount = root(&a).display().to_string();
let process = held(
&root(&a).join("y"),
&format!(
"m={mount}
refused() {{ case $1 in *'Invalid argument'*|*'subdirectory of itself'*) ;; *) echo \"$2: $1\" >&2; exit 1;; esac; }}
out=$(mv -T $m/x x2 2>&1) && {{ echo 'stale index: x moved into y' >&2; exit 1; }}; refused \"$out\" stale
test -d $m/x && test ! -e x2 || {{ echo 'x moved' >&2; exit 1; }}
test -d $m/x/y || {{ echo 'y is not under x' >&2; exit 1; }}
out=$(mv -T $m/x x2 2>&1) && {{ echo 'cycle: x moved into y' >&2; exit 1; }}; refused \"$out\" cycle
mkdir $m/z && mv -T $m/z z && test -d $m/x/y/z || {{ echo 'z did not move in' >&2; exit 1; }}
exit 0"
),
);
passed(&bash_in(COMMAND, root(&b), "mv y x/y"), "B moves y under x");
rig.committed(b.token, "B publishes the move");
merged(&rig, &a);
let status = process.release();
assert!(status.success(), "a rename made a cycle: {status:?}");
serving(&rig, &a, "after the refused renames");
passed(
&bash_in(
COMMAND,
root(&a),
"test \"$(cat from-a)\" = alpha && test -d x/y/z && test ! -e y",
),
"the mount serves on",
);
rig.unmount(&a);
rig.unmount(&b);
rig.finish();
}
10 changes: 8 additions & 2 deletions engine/crates/layerfs-fuse/src/request/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ impl KernelFilesystem {
reply.error(Errno::EINVAL);
RequestDisposition::Complete
}
// The open directory's serial was dropped by an install:
// this request alone answers ESTALE.
Ok(Err(failure)) if failure.stale() => {
reply.error(Errno::ESTALE);
terminal::directory(&fence, failure).await
}
// The typed failure still owns whatever was acquired.
Ok(Err(failure)) if failure.fenced() => {
reply.error(terminal::STOPPED);
Expand Down Expand Up @@ -173,7 +179,7 @@ async fn enumerate(
}
Ok(DirectoryStep::Batch(batch)) => batch,
Err(error) => {
reply.error(terminal::errno(error.fenced()));
reply.error(terminal::errno(error.fenced(), error.stale()));
return terminal::directory(fence, error).await;
}
};
Expand Down Expand Up @@ -215,7 +221,7 @@ async fn enumerate(
// A fenced publication published nothing: the offered entries
// are never sent. Any other failure here is retained.
Err(error) => {
reply.error(terminal::errno(error.fenced()));
reply.error(terminal::errno(error.fenced(), error.stale()));
return terminal::directory(fence, error).await;
}
};
Expand Down
2 changes: 1 addition & 1 deletion engine/crates/layerfs-fuse/src/request/mutate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl MutationReply {
let mutation = match KernelMutation::perform(services, request).await {
Ok(mutation) => mutation,
Err(failure) => {
self.error(terminal::errno(failure.fenced()));
self.error(terminal::errno(failure.fenced(), false));
return terminal::mutation(&fence, failure).await;
}
};
Expand Down
4 changes: 2 additions & 2 deletions engine/crates/layerfs-fuse/src/request/reply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl ReadReply {
RequestDisposition::Complete
}
Err(error) => {
reply.error(terminal::errno(error.fenced()));
reply.error(terminal::errno(error.fenced(), error.stale()));
terminal::read(&fence, error).await
}
}
Expand All @@ -108,7 +108,7 @@ impl ReadReply {
{
Ok(answer) => answer,
Err(error) => {
self.error(terminal::errno(error.fenced()));
self.error(terminal::errno(error.fenced(), error.stale()));
return terminal::read(&fence, error).await;
}
};
Expand Down
Loading