Skip to content

Commit 900703e

Browse files
committed
virtio/fs/macos: keep a fd to unlinked files
On the macOS implementation of passthrough, we avoid keeping an FD open for each dirent entry by accessing the inode using the special directory '/.vol'. But this strategy doesn't work when the inode has been unlinked, and it's completely valid for userspace to keep accessing a file after unlinking it by keeping an FD to it. To fix this without having to keep an FD open as the Linux implementation does (thus risking running out of open handles), here we change do_unlink() to open an FD and store it in InodeData->unlinked_fd. Then we change inode_to_path() to become inode_to_handle(), being able to return either a path accssible through '/.vol' or an FD. Finally, we update every user of inode_to_handle() to be able to operate both with a path and with an FD. The FD stored in InodeData->unlinked_fd is released on forget_one(), which is called when the guest removes the entry from dirent. Instead of wrapping the FD behind an OwnedFd or a File, we operate on it as an integer/RawFd. This allows us to 1) store the value as an atomic operation without a Mutex and 2) save a couple of syscalls everytime we use it. Signed-off-by: Sergio Lopez <slp@redhat.com>
1 parent 4d11a0e commit 900703e

1 file changed

Lines changed: 210 additions & 90 deletions

File tree

0 commit comments

Comments
 (0)