sysfs: always reopen directory before readdir #2355
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As POSIX states, if a file is removed from or added to the directory after the most recent call to
opendir()
orrewinddir()
, whether a subsequent call toreaddir()
returns an entry for that file is unspecified.So there is no guarantee that files added after
opendir()
will be visible inreaddir()
. We need toreopendir()
to get the new state of the directory beforereaddir()
.Btrfs
was modified to track the last index number inopendir()
and makereaddir()
never process beyond that index number (torvalds/linux@9b378f6). This change was introduced in Linux 6.4.12 (see https://cdn.kernel.org/pub/linux/kernel/v6.x/ChangeLog-6.4.12). I think this change is the reason of the test failures in #2335.I noticed that there is a similar commit in
tmpfs
(torvalds/linux@64a7ce7).I can reproduce the testing failures on both
btrfs
andtmpfs
filesystems onarchlinux
with6.12.7
kernelThe behavior is not a bug, because the POSIX specification explicitly allows it. The PR sets
reopenDir
totrue
innewOsFile
to always reopen directory beforereaddir
.Fixes #2335
For more information, here are some references:
IterableDir
does not iterate over all contents created after opening (Linux BTRFS) ziglang/zig#17095