Skip to content

fs/macos: fix ghost files are double fd closing#544

Merged
slp merged 2 commits intocontainers:mainfrom
slp:fs-macos-fix-opendir
Feb 17, 2026
Merged

fs/macos: fix ghost files are double fd closing#544
slp merged 2 commits intocontainers:mainfrom
slp:fs-macos-fix-opendir

Conversation

@slp
Copy link
Collaborator

@slp slp commented Feb 11, 2026

Ghost files were caused by a bug introduced in #513, while the double fd closing came from using the HandleData->File fd with fdopendir, which takes ownership of the fd.

@pftbest
Copy link
Contributor

pftbest commented Feb 11, 2026

Works on my side. Performance only 6% lower than opendir version in my tests, so that is ok too.

@slp slp force-pushed the fs-macos-fix-opendir branch from a9bb0e6 to f8207e2 Compare February 16, 2026 16:26
slp and others added 2 commits February 16, 2026 17:30
When unlinking an inode, we were grabbing and storing an fd to the inode
without checking if the underlying `unlinkat` operation succeeded or
not. This was wrong, and was leading to us storing an fd in unlinked_fd
even for inodes still linked (i.e. if the guest attempts to unlink a
non-empty directory).

Let's split the action in two steps, first we grab the an fd to the
inode before unlinking it, and then we actually store the fd in
unlinked_fd after checking that `unlinkat` succeeded.

Fixes: containers#541

Signed-off-by: Sergio Lopez <slp@redhat.com>
fdopendir() takes ownership of the fd passed as argument to it, so
passing the fd of the HandleData->File will cause the fd to be closed
twice, first when closedir() is called and second when Arc<HandleData>
is dropped.

If the library is built with debug-assertions enabled, this issue will
trigger an error like:

fatal runtime error: IO Safety violation: owned file descriptor already closed, aborting

To avoid this issue, let's use dup() to obtain a new descriptor from
HandleData->File to be donated to fdopendir().

Fixes: containers#539

Co-authored-by: dorindabassey <53014273+dorindabassey@users.noreply.github.com>
Co-authored-by: Vadzim Dambrouski <pftbest@gmail.com>
Signed-off-by: Sergio Lopez <slp@redhat.com>
@slp slp force-pushed the fs-macos-fix-opendir branch from f8207e2 to 5dc2fee Compare February 16, 2026 16:30
@slp
Copy link
Collaborator Author

slp commented Feb 16, 2026

Applied @dorindabassey's suggestion (thanks!) squashing it in the previous commit (adding her as Co-author) and rebased the series on HEAD.

Copy link
Collaborator

@dorindabassey dorindabassey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Copy link
Collaborator

@mtjhrc mtjhrc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@slp slp merged commit d097303 into containers:main Feb 17, 2026
11 checks passed
@slp slp deleted the fs-macos-fix-opendir branch February 17, 2026 09:40
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.

4 participants