Skip to content

macOS: refresh bind-mount names after host deletes and replacements - #402

Open
shuvroroy wants to merge 1 commit into
libracoder:mainfrom
shuvroroy:fix/macos-bind-mount-recreate
Open

shuvroroy wants to merge 1 commit into
libracoder:mainfrom
shuvroroy:fix/macos-bind-mount-recreate

Conversation

@shuvroroy

Copy link
Copy Markdown

What this changes and why

After a Mac deletes or replaces a bind-mounted file, the guest can retain a positive virtiofs dentry for about a second. Recreating the name in a container or reading an editor's atomic save then fails with ENOENT.

Expire cached file names on both D and M events, including without inotify watchers. For modifications, expire before looking up the target and raising notifications, so a watcher reads the replacement. Keep the cached dentry referenced through the fresh lookup to preserve watches on in-place edits. Directories and mount points remain cached.

Add a regression to the Docker compatibility suite covering guest creation after host deletion, host rename-over-file, and host delete/recreate, with and without a watcher. The watcher reads the changed file from its event handler.

Fixes #399, including the replacement-file follow-up.

How you tested it

Tested on: macOS 27.2.1, Apple silicon. The x86_64 guest kernel was cross-compiled; Intel runtime testing was not performed.

Before and after on this Mac:

main @ 5789abe: original recreation regression failed 10/10 attempts (ENOENT)
delete-only fix: host rename and host delete/recreate reads failed 20/20 attempts
final fix: PASS bind recreate and replace, with and without a watcher (30 attempts)
  • cargo xtask host, cargo xtask guest, and cargo xtask disk: passed.
  • cargo xtask kernel and cargo xtask kernel --arch x86_64: passed with the final patch.
  • DOCKER_CONTEXT=kiri-issue399 tests/bind-recreate.sh: all 30 attempts passed, including reads from the watcher's event handler.
  • All 11 bind-mount checks extracted from tests/e2e.sh: passed, including the existing inotify and symlink-repointing checks. The full Docker compatibility suite was not run.
  • A direct file inotify watcher survived two in-place host modifications and received both events.
  • cargo test: 475 passed, 6 ignored.
  • cargo clippy: passed with existing warnings.
  • python3 scripts/ui-test.py with CHROME pointing to Chromium: 542 checks passed across 60 test files.
  • bash -n tests/bind-recreate.sh tests/e2e.sh and git diff --check: passed.

cargo fmt --check reports existing repository-wide formatting differences. This change does not modify Rust source files.

How you found it

  • I use Kiri and ran into this myself
  • I found it by reading the code or comparing with Docker
  • Someone else reported it (link the issue above)

AI tools used to write this change: Yes. Codex investigated and reproduced the issue and follow-up, implemented the kernel patch and regression test, and ran validation.

Checklist

  • I have at most 3 pull requests open on Kiri, this one included
  • cargo fmt, cargo clippy and the tests pass (existing formatting differences described above)
  • It works on macOS, Windows and Linux, or the change only touches one of them (macOS virtiofs guest path)

@shuvroroy
shuvroroy marked this pull request as ready for review November 16, 2026 17:09
@danieljustus

Copy link
Copy Markdown

Thanks for picking this up so quickly. I had prepared the same fix independently (danieljustus/kiri, branch fix/399-drop-deleted-names, commit 56da59c) and won't open a competing PR. Two notes from testing mine, in case they help the review:

  1. Cost without a watcher: here every D and M line runs vfs_path_lookup on the parent even when nobody watches. Inside the cache window that stays in the dcache, but once a parent's entry has expired the walk sends lookups to the Mac, and a container writing many files to a bind mount sends its own changes back as M lines. Mine walks to the name with cached dentries only (d_hash_and_lookup, including ../internal.h as fs/notify/fdinfo.c does), so a batch without a watcher still costs no requests to the Mac.
  2. Holding the reference across the fresh lookup isn't needed to keep file watches: the inotify mark pins the inode and the fresh lookup returns the same one. With a plain drop, a watch on the file itself still got MODIFY and CLOSE_WRITE for three in-place appends on the Mac.

Independent results for the same approach (D and M, watcher or not, directories and mount points left alone) on an M4 Pro, macOS 27.2.1: full tests/e2e.sh 567 passed, 0 failed, 6 skipped (domain checks); reading a replaced file 5/5 vs 1/5 on 0.2.1; recreating after a delete 5/5 vs 2/5. A limit both share: the daemon looks at bind sources once a second, so a change in a container's first second, or while no container uses the folder, sends no line.

@libracoder

Copy link
Copy Markdown
Owner

@shuvroroy thanks for this PR. Before it can be reviewed and merged, every commit needs to be signed. GitHub shows c4d617a as unsigned. Please sign it (GPG or SSH, with the key added to your GitHub account as a signing key), then force-push. GitHub's guide: https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits

@shuvroroy
shuvroroy force-pushed the fix/macos-bind-mount-recreate branch from c4d617a to a47c8da Compare November 16, 2026 18:06
@shuvroroy

Copy link
Copy Markdown
Author

@shuvroroy thanks for this PR. Before it can be reviewed and merged, every commit needs to be signed. GitHub shows c4d617a as unsigned. Please sign it (GPG or SSH, with the key added to your GitHub account as a signing key), then force-push. GitHub's guide: https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits

@libracoder ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

macOS bind mounts: a file deleted or replaced on the Mac gives ENOENT in containers for about 1 s (reading it, or creating it again)

3 participants