Skip to content

fs/macos: preserve the inode a rename overwrites#700

Open
acdtrx wants to merge 1 commit into
containers:mainfrom
acdtrx:macos-virtiofs-rename-preserve-overwritten-inode
Open

fs/macos: preserve the inode a rename overwrites#700
acdtrx wants to merge 1 commit into
containers:mainfrom
acdtrx:macos-virtiofs-rename-preserve-overwritten-inode

Conversation

@acdtrx
Copy link
Copy Markdown

@acdtrx acdtrx commented May 29, 2026

The macOS virtio-fs passthrough addresses inodes by their volfs path ("/.vol/{dev}/{ino}"), which only resolves while the inode still has a directory entry. A rename that REPLACES an existing target drops that target's last link, but unlike do_unlink -- which stashes an fd to the doomed inode in InodeData.unlinked_fd -- rename never preserved the overwritten inode. Any FUSE op the guest later issues on it then resolves a dangling volfs path and returns ENOENT.

This breaks the common atomic write-new-then-rename-over pattern when the guest still holds the old target open: apt/dpkg rewrite /var/lib/dpkg/status this way while apt holds it open, so apt's final close reports "Problem closing the file /var/lib/dpkg/status - close (2: No such file or directory)" even though the install succeeded. It reproduces on any overlayfs upperdir backed by this server.

Mirror do_unlink: grab an fd to the target before renamex_np (replace case only -- not RENAME_SWAP/RENAME_EXCL) and hand it to the displaced inode on success. store_unlinked_fd now reports whether a tracked inode took ownership so the caller closes the fd otherwise instead of leaking it.

Built on macOS/aarch64 and verified in a downstream consumer — apt-based setup recipes that previously failed at dpkg's close now succeed.

The macOS virtio-fs passthrough addresses inodes by their volfs path
("/.vol/{dev}/{ino}"), which only resolves while the inode still has a
directory entry. A rename that REPLACES an existing target drops that
target's last link, but unlike do_unlink -- which stashes an fd to the
doomed inode in InodeData.unlinked_fd -- rename never preserved the
overwritten inode. Any FUSE op the guest later issues on it then resolves
a dangling volfs path and returns ENOENT.

This breaks the common atomic write-new-then-rename-over pattern when the
guest still holds the old target open: apt/dpkg rewrite /var/lib/dpkg/status
this way while apt holds it open, so apt's final close reports
"Problem closing the file /var/lib/dpkg/status - close (2: No such file or
directory)" even though the install succeeded. It reproduces on any
overlayfs upperdir backed by this server.

Mirror do_unlink: grab an fd to the target before renamex_np (replace case
only -- not RENAME_SWAP/RENAME_EXCL) and hand it to the displaced inode on
success. store_unlinked_fd now reports whether a tracked inode took
ownership so the caller closes the fd otherwise instead of leaking it.

Signed-off-by: Alex NOVAC <acdtrx@gmail.com>
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.

1 participant