diff --git a/docs/architecture/engine/kernel-routes/README.md b/docs/architecture/engine/kernel-routes/README.md
index 938fabffaf..22df27a67d 100644
--- a/docs/architecture/engine/kernel-routes/README.md
+++ b/docs/architecture/engine/kernel-routes/README.md
@@ -132,7 +132,7 @@ so NFS calls charge nothing.
| WRITE count | Full count or an error, never short | Short only after a later window failed; earlier windows stay published | [`coherence/pages.rs`](../../../../engine/crates/layerfs-fuse/src/coherence/pages.rs), [`change.rs`](../../../../engine/crates/layerfs-nfs/src/change.rs) |
| Hard links | Aliases share one serial, so one kernel inode | `fileid` is the serial | [`link.rs`](../../../../engine/crates/layerfs-mount-ports/src/operations/link.rs), [`attributes.rs`](../../../../engine/crates/layerfs-nfs/src/attributes.rs) |
| Ticket release | After the one reply attempt (fuser reports no send result) | After `write_record` returns | [`reply_order.rs`](../../../../engine/crates/layerfs-fuse/src/coherence/reply_order.rs), [`server.rs`](../../../../engine/crates/layerfs-nfs/src/server.rs) |
-| After a Commit installs a root other than the one shown | `inval_inode` / `inval_entry` per stale serial or name before the answer | Mode-preserving SETATTR refresh through the client | [`invalidate.rs`](../../../../engine/crates/layerfs-daemon/src/control/invalidate.rs); [FUSE](fuse.md), [NFS](nfs.md) |
+| After a Commit installs a root other than the one shown | `inval_inode` / `inval_entry` per stale serial or name before the answer | Mode-preserving SETATTR refresh through the client, after the answer and best effort (at most 4,096 inodes) | [`invalidate.rs`](../../../../engine/crates/layerfs-daemon/src/control/invalidate.rs); [FUSE](fuse.md), [NFS](nfs.md) |
| Durability of a reply | `FLUSH`/`FSYNC`/`FSYNCDIR` answer `ENOSYS` once; the kernel then reports success and stops sending them | WRITE answers `FILE_SYNC`, meaning published; the daemon flushes the client before each Commit: the flush helper when set, else the export volume's own flush (`sync_volume_np(
, SYNC_VOLUME_WAIT)` on macOS, `sync(2)` elsewhere); a failed flush refuses the Commit as `Failed` at `commit:flush` | [`flush.rs`](../../../../engine/crates/layerfs-mount-ports/src/operations/flush.rs), [`changing.rs`](../../../../engine/crates/layerfs-nfs/src/changing.rs) |
An install of the Workspace's own captured root sends nothing: the tree the
@@ -188,6 +188,8 @@ stable media.
| [`requests.rs`](../../../../engine/crates/layerfs-fuse/tests/requests.rs) | `cargo +1.85.1 test --locked -p layerfs-fuse --test requests` | any (no kernel) | A parked request resumes on its own thread and drain waits for it; a panic keeps its future and another mount stays usable |
| [`protocol.rs`](../../../../engine/crates/layerfs-nfs/tests/protocol.rs) | `cargo +1.85.1 test --locked -p layerfs-nfs --test protocol` | any (no network) | XDR round trips and bounds, fragment joining and `RECORD_LIMIT`, `AUTH_UNIX` headers, handles stable per mount and stale after it |
| [`write.rs`](../../../../engine/crates/layerfs-nfs/tests/write.rs) | `cargo +1.85.1 test --locked -p layerfs-nfs --test write` | any (in-process loopback export, no kernel mount) | Every changing NFS procedure; tickets released only after the reply; silly renames and AppleDouble names |
+| [`apple_double_view.rs`](../../../../engine/crates/layerfs-nfs/tests/apple_double_view.rs) | `cargo +1.85.1 test --locked -p layerfs-nfs --test apple_double_view` | any (in-process loopback export, no kernel mount) | A `._` file the Workspace holds is listed, read, written, replaced and removed as any other file and committed; a new companion still stays in export memory |
+| [`refresh.rs`](../../../../engine/crates/layerfs-nfs/tests/refresh.rs) | `cargo +1.85.1 test --locked -p layerfs-nfs --test refresh` | any (in-process loopback export, no kernel mount) | A refresh chmod changes nothing; a user chmod inside the mark window is applied and the refresh chmod after it does not undo it |
Run each under a wall timeout of at most 120 s. The nightly lane runs each
kernel binary alone in a container with `--device /dev/fuse --cap-add
diff --git a/docs/architecture/engine/kernel-routes/nfs.md b/docs/architecture/engine/kernel-routes/nfs.md
index ca370bb37d..b5d3d4b3f0 100644
--- a/docs/architecture/engine/kernel-routes/nfs.md
+++ b/docs/architecture/engine/kernel-routes/nfs.md
@@ -154,7 +154,7 @@ drawn once per export; it makes guessing costly and does not authenticate.
| Rule | Source |
| --- | --- |
| One owner visit answers a LOOKUP: the job that resolves a name has already read the directory's own row, so the reply's `dir_attributes` cost no second visit | [`nfs.rs`](../../../../engine/crates/layerfs-nfs/src/nfs.rs), [`kernel.rs`](../../../../engine/crates/layerfs-nfs/src/kernel.rs), [`kernel_read.rs`](../../../../engine/crates/layerfs-workspace/src/operations/kernel_read.rs) |
-| A LOOKUP that fails answers the directory's own fresh facts whenever the job that failed read its row, which is every name this export looks up: a name that binds nothing still read its parent's row in the same visit. `.`, `..`, a silly name, an AppleDouble companion and a refusal decided before any visit read no directory row and send no `dir_attributes`, so the client falls back to its own `actimeo`; RFC 1813 makes both fields optional. No LOOKUP answer repeats the export's last observation of the directory, which nothing ages. A failed LOOKUP's directory row is kept as the export's observation, as a successful one's is | [`nfs.rs`](../../../../engine/crates/layerfs-nfs/src/nfs.rs), [`kernel.rs`](../../../../engine/crates/layerfs-nfs/src/kernel.rs), [`kernel_read.rs`](../../../../engine/crates/layerfs-workspace/src/operations/kernel_read.rs) |
+| A LOOKUP that fails answers the directory's own fresh facts whenever the job that failed read its row, which is every name this export looks up: a name that binds nothing still read its parent's row in the same visit. `.`, `..`, a silly name, an AppleDouble companion (whose LOOKUP asks the view first, and answers the companion only after the view had no such name) and a refusal decided before any visit send no `dir_attributes`, so the client falls back to its own `actimeo`; RFC 1813 makes both fields optional. No LOOKUP answer repeats the export's last observation of the directory, which nothing ages. A failed LOOKUP's directory row is kept as the export's observation, as a successful one's is | [`nfs.rs`](../../../../engine/crates/layerfs-nfs/src/nfs.rs), [`kernel.rs`](../../../../engine/crates/layerfs-nfs/src/kernel.rs), [`kernel_read.rs`](../../../../engine/crates/layerfs-workspace/src/operations/kernel_read.rs) |
| `read.rs` holds what a read answers: the entry, its directory and its descriptors, and the refusal with its status (`NFS3ERR_STALE` for an engine `Stale`, else `NFS3ERR_IO`) and the directory row the job read | [`read.rs`](../../../../engine/crates/layerfs-nfs/src/read.rs) |
| An export remembers the facts it last published or observed for a directory (LOOKUP, GETATTR, OPENDIR, a publishing change) and answers from them only where no job reads that directory: an AppleDouble companion's `wcc_data`, whose change never touches it. A directory listing is not such a place: its reply says only what its own window read | [`kernel.rs`](../../../../engine/crates/layerfs-nfs/src/kernel.rs), [`apple_double.rs`](../../../../engine/crates/layerfs-nfs/src/apple_double.rs) |
@@ -164,30 +164,52 @@ drawn once per export; it makes guessing costly and does not authenticate.
Commit installed R' while the export showed R (R' != R)
Server::installed(): close file and directory descriptors
stale_after_install(R, R') -> serials (at most REFRESHED = 4096)
- Server::refresh(serials): mark them, return their paths
- thread layerfs-nfs-refresh: chmod(path, same mode) per path
- client SETATTR -> marked and mode-only? answer current attrs,
- change nothing -> new post-op attrs -> client drops its cache
+ Server::refresh(serials): (serial, path) of each the export knows
+ Commit reply sent; thread layerfs-nfs-refresh, per path in order:
+ lstat through the mount (skip a symlink, a vanished path, another inode)
+ Refresher::arm(serial, mode the client shows) -- one mark, that mode
+ chmod(path, that mode)
+ client SETATTR -> mode-only, marked, asking the marked mode?
+ answer current attrs, change nothing, take the mark
+ -> new post-op attrs -> client drops its cache
+ any other SETATTR (another mode included) -> applied as always
```
| Rule | Source |
| --- | --- |
-| A mark is taken by one mode-only SETATTR and ends after `MARK_LIFE` (30 s); a serial the client never saw is left out; symlinks and vanished paths are skipped | [`refresh.rs`](../../../../engine/crates/layerfs-nfs/src/refresh.rs), [`export.rs`](../../../../engine/crates/layerfs-daemon/src/control/export.rs) |
+| One inode is marked right before its own refresh chmod, with the exact mode that chmod asks (the one the client shows through the mount point). A mark is taken by one mode-only SETATTR asking that mode and ends after `MARK_LIFE` (30 s); a serial the client never saw is left out; symlinks, vanished paths and paths that now name another inode are skipped; the thread stops once the export is gone or stopping | [`refresh.rs`](../../../../engine/crates/layerfs-nfs/src/refresh.rs), [`server.rs`](../../../../engine/crates/layerfs-nfs/src/server.rs), [`export.rs`](../../../../engine/crates/layerfs-daemon/src/control/export.rs) |
| The refresh never writes into the Workspace and never reverts a mode the install changed | [`refresh.rs`](../../../../engine/crates/layerfs-nfs/src/refresh.rs) |
+| The mark suppresses only the refresh's own chmod. A client SETATTR asking another mode is applied even on a marked inode, and the refresh chmod still on its way is then answered without a change, so it never overwrites the newer mode. The one request the export cannot tell from the refresh's is a client chmod to the very mode just marked, sent in the microseconds between the mark and the refresh's chmod: it is answered unchanged and the refresh's chmod that follows applies that same mode | [`refresh.rs`](../../../../engine/crates/layerfs-nfs/src/refresh.rs) |
+| Best effort: the refresh runs after the Commit reply, so a client may still serve its cached attributes and listings for a moment after it; the walk stops at `REFRESHED` (4,096) stale inodes, and a failed walk, a failed chmod or one the client never sends leaves the rest to `actimeo` and close-to-open | [`export.rs`](../../../../engine/crates/layerfs-daemon/src/control/export.rs) |
| `LAYERFS_NFS_REFRESH=0` leaves the client to `actimeo` and close-to-open | [`export.rs`](../../../../engine/crates/layerfs-daemon/src/control/export.rs) |
## AppleDouble files (`apple_double.rs`, `apple_double/edit.rs`, `apple_double/index.rs`, `apple_double/reclaim.rs`, `apple_double_codec.rs`, `apple_double_spill.rs`)
On NFSv3 the macOS client keeps extended attributes and resource forks in
`._` files (at least one byte after `._`). With `refuse_apple_double`, a
-regular `._` file lives in export state only (`Companions`, serials
-`SERIALS` = 2^62 and above): LOOKUP, GETATTR, ACCESS, READ, WRITE, SETATTR,
-COMMIT, REMOVE and RENAME to another `._` name are served there, READDIR
-never lists it and the engine is never called. Any other kind is
+regular `._` file the client creates under a name the Workspace view does not
+hold lives in export state only (`Companions`, serials `SERIALS` = 2^62 and
+above): LOOKUP, GETATTR, ACCESS, READ, WRITE, SETATTR, COMMIT, REMOVE and
+RENAME to another `._` name are served there, READDIR never lists it and no
+engine mutation is made for it. Any other new kind under a `._` name is
`NFS3ERR_ACCES`. `cp`, `copyfile`, `ditto` and `tar` succeed while nothing
reaches the Workspace, SQLite overlay or a Commit; everything is dropped with
the export.
+A `._` name the view holds (a file committed under that name, or made in the
+view by another route) is an ordinary Workspace file, never hidden: READDIR
+lists it, and LOOKUP, GETATTR, READ, WRITE, SETATTR, REMOVE and RENAME reach
+the engine as for any other name, so the two agree. To decide, LOOKUP, CREATE,
+REMOVE and RENAME of a `._` name ask the view first (one engine LOOKUP, also
+for a name that turns out to be a companion's or absent); only a name the view
+does not hold uses the companions.
+
+| Case | Answer |
+| --- | --- |
+| CREATE of a `._` name the view holds | The ordinary CREATE of that file: UNCHECKED opens it (applying a requested size), GUARDED and EXCLUSIVE answer `NFS3ERR_EXIST`. No companion is made, so nothing shadows it; the attributes a macOS client then stores there go into the Workspace file and a Commit captures them, as on any NFSv3 server |
+| RENAME onto a `._` name the view holds | An ordinary RENAME that replaces it; onto a `._` name the view lacks it stays `NFS3ERR_ACCES` |
+| A companion whose name the view gains later (an install, another route) | The real file answers that name; the companion is unreachable by it and goes with the export or orphan reclamation |
+
| Bound | Value | Over the bound | Source |
| --- | --- | --- | --- |
| `HELD` | 65,536 slotted companion entries | `Companions::admits` decides the bound in one place, before anything is committed: CREATE, and a WRITE, SETATTR or RENAME that needs a new slot, first reclaim the orphan slotted companions outside the companion lock, once, and then answer the whole operation `NFS3ERR_NOSPC` with the body, its length and its name as they were (CREATE also increments `names_refused` and logs at most once per 60 s per export). A call whose commit needs I/O in between (`Companions::reserve`) holds the slot from the decision, so the bound holds when calls race for the last one | [`apple_double.rs`](../../../../engine/crates/layerfs-nfs/src/apple_double.rs) |
diff --git a/engine/crates/layerfs-daemon/src/control/export.rs b/engine/crates/layerfs-daemon/src/control/export.rs
index d4d3f7b262..3915a480fc 100644
--- a/engine/crates/layerfs-daemon/src/control/export.rs
+++ b/engine/crates/layerfs-daemon/src/control/export.rs
@@ -62,19 +62,27 @@ pub const REFRESHED: usize = 4096;
pub const REFRESH: &str = "LAYERFS_NFS_REFRESH";
/// One mode-preserving chmod of each path below `root`, through the host's
-/// NFS client; a symbolic link (chmod would follow it) and a path that is
-/// gone are skipped. The export answers each without a change.
-fn refresh(root: &std::path::Path, paths: &[PathBuf]) {
+/// NFS client, in order and at most once each. A symbolic link (chmod would
+/// follow it), a path that is gone and a path that now names another inode
+/// than its serial are skipped. Each chmod asks the mode the client shows
+/// and is marked with exactly that mode first, so the export answers it
+/// without a change; a client chmod to another mode is still applied, and
+/// stays (see `layerfs_nfs::refresh`). Stops when the export is gone.
+fn refresh(root: &std::path::Path, refresher: &layerfs_nfs::Refresher, paths: &[(u64, PathBuf)]) {
use std::os::unix::fs::{MetadataExt, PermissionsExt};
- for path in paths {
+ for (serial, path) in paths {
let path = root.join(path);
let Ok(metadata) = std::fs::symlink_metadata(&path) else {
continue;
};
- if !metadata.file_type().is_symlink() {
- let mode = std::fs::Permissions::from_mode(metadata.mode() & 0o7777);
- let _ = std::fs::set_permissions(&path, mode);
+ if metadata.file_type().is_symlink() || metadata.ino() != *serial {
+ continue;
+ }
+ let mode = metadata.mode() & 0o7777;
+ if !refresher.arm(*serial, mode) {
+ return;
}
+ let _ = std::fs::set_permissions(&path, std::fs::Permissions::from_mode(mode));
}
}
/// How the host's NFS client mounts, flushes and unmounts an export.
@@ -581,7 +589,9 @@ impl Service {
/// the client may cache are refreshed through the mount point (see
/// `layerfs_nfs::refresh`): a mode-preserving chmod of each, at most
/// [`REFRESHED`], on a thread of its own after this returns, so the
- /// Commit reply never waits on the client. False without an export.
+ /// Commit reply never waits on the client. Best effort: a walk that stops
+ /// at the bound, a chmod that fails or one the client never sends leaves
+ /// the rest to the client's own revalidation. False without an export.
pub(super) fn installed_export(
&self,
token: WorkspaceToken,
@@ -620,9 +630,10 @@ impl Service {
let paths = server.refresh(stale);
if !paths.is_empty() {
let root = PathBuf::from(directory);
+ let refresher = server.refresher();
let _ = std::thread::Builder::new()
.name("layerfs-nfs-refresh".into())
- .spawn(move || refresh(&root, &paths));
+ .spawn(move || refresh(&root, &refresher, &paths));
}
Ok(true)
}
diff --git a/engine/crates/layerfs-nfs/src/apple_double.rs b/engine/crates/layerfs-nfs/src/apple_double.rs
index ae9cd22731..bb5e9dadf5 100644
--- a/engine/crates/layerfs-nfs/src/apple_double.rs
+++ b/engine/crates/layerfs-nfs/src/apple_double.rs
@@ -7,15 +7,25 @@
//! WRITE, SETATTR, COMMIT, REMOVE, a LINK to another AppleDouble name and a
//! RENAME to another AppleDouble name
//! work on it, READDIR does not list it, and no mutation of it ever reaches
-//! the engine, so the Workspace stays clean and no Commit can capture it.
+//! the engine (a LOOKUP of its name in the view is the one engine call), so
+//! the Workspace stays clean and no Commit can capture it.
//! Everything is dropped when the export is released.
//!
-//! The tree is not consulted for such a name: while this mode is on, a
-//! LOOKUP of a `._` name answers `NFS3ERR_NOENT` unless the export holds that
-//! companion, which is what a READDIR of that directory already shows by not
-//! listing them, so the two agree. Such a change also never touches the
-//! directory it names, so its `wcc_data` answers both halves from the last
-//! facts the export saw for it (see [`Kernel::directory_wcc`]).
+//! Only a name the Workspace view does not hold is a companion's: a `._` file
+//! that is really in the tree (committed, or made in the view by another
+//! route) is an ordinary Workspace file, which READDIR lists. So a LOOKUP of
+//! a `._` name asks the view first and answers the companion only when the
+//! view has no such name ([`Kernel::lookup_apple_double`]), and LOOKUP and
+//! READDIR agree. CREATE, REMOVE and RENAME of a `._` name ask the view the
+//! same way: CREATE of a name the view holds is the ordinary CREATE of that
+//! file (UNCHECKED opens it, GUARDED and EXCLUSIVE answer `NFS3ERR_EXIST`),
+//! so no companion is made to shadow it, and the attributes a macOS client
+//! then stores there go into the Workspace file, as on any NFSv3 server; a
+//! RENAME may replace such a file. A companion whose name the view gains
+//! later (an install, another route) is shadowed by the real file and stays
+//! unreachable by that name. A companion change never touches the directory
+//! it names, so its `wcc_data` answers both halves from the last facts the
+//! export saw for it (see [`Kernel::directory_wcc`]).
//!
//! A companion created while the export knows its main file (`` in the
//! same directory) belongs to that inode: any name of the inode reaches it, so
@@ -330,6 +340,36 @@ impl Kernel {
companions.use_serial(serial?);
Some(stat)
}
+ /// LOOKUP of a `._` name while companions are kept: the view answers
+ /// first, so a real Workspace file of that name (one READDIR lists) is
+ /// never hidden or shadowed, and only a name the view does not hold
+ /// answers the companion, if one is held, a companion answering with no
+ /// directory row.
+ pub(crate) fn lookup_apple_double(
+ &self,
+ parent: u64,
+ name: &[u8],
+ ) -> Result<(ViewStat, Option), crate::read::Refused> {
+ match self.lookup_view(parent, name) {
+ Err(refused) if refused.status == Status::NoEnt => {
+ match self.companion_named(parent, name) {
+ Some(stat) => Ok((stat, None)),
+ None => Err(refused),
+ }
+ }
+ answer => answer,
+ }
+ }
+ /// Whether the Workspace view holds `name` in `parent`: such a `._` name
+ /// is an ordinary Workspace file, never a companion's. A view that holds
+ /// it takes the export's one engine reference, as any LOOKUP does.
+ pub(crate) fn view_holds(&self, parent: u64, name: &[u8]) -> Result {
+ match self.lookup_view(parent, name) {
+ Ok(_) => Ok(true),
+ Err(refused) if refused.status == Status::NoEnt => Ok(false),
+ Err(refused) => Err(refused.status),
+ }
+ }
/// CREATE of an already-held companion name: UNCHECKED applies its size,
/// as an open with truncation would; GUARDED and EXCLUSIVE find it taken.
fn companion_open(
diff --git a/engine/crates/layerfs-nfs/src/change.rs b/engine/crates/layerfs-nfs/src/change.rs
index 2456d43b53..142f841aa8 100644
--- a/engine/crates/layerfs-nfs/src/change.rs
+++ b/engine/crates/layerfs-nfs/src/change.rs
@@ -97,6 +97,13 @@ pub enum How {
Exclusive([u8; 8]),
}
/// What a published result must carry for its reply to be composed.
+/// The route of a name while `._` names are kept out (see [`Kernel::kept_name`]).
+#[derive(Clone, Copy, Eq, PartialEq)]
+enum Kept {
+ Ordinary,
+ Workspace,
+ Companion,
+}
#[derive(Clone, Copy)]
enum Expect {
Nothing,
@@ -258,6 +265,19 @@ impl Kernel {
}
PathName::from_bytes(name).map_err(|_| Status::Inval)
}
+ /// Which route a name takes while `._` names are kept out of the
+ /// Workspace: a `._` name the view holds is an ordinary Workspace file,
+ /// one it does not hold is a companion's (see `crate::apple_double`).
+ /// Only a `._` name asks the view.
+ fn kept_name(&self, parent: u64, name: &[u8]) -> Result {
+ if !(self.refuses_apple_double() && names::apple_double(name)) || name.len() > 255 {
+ return Ok(Kept::Ordinary);
+ }
+ Ok(match self.view_holds(parent, name)? {
+ true => Kept::Workspace,
+ false => Kept::Companion,
+ })
+ }
/// The entry a name binds now, or none.
fn existing(&self, parent: u64, name: &[u8]) -> Result