-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IterableDir
does not iterate over all contents created after opening (Linux BTRFS)
#17095
Comments
Another data point and observation: I am only able to reproduce this on BTRFS: I created a temporary Ext4 filesystem for testing and I am unable to reproduce the issue there. Possibly related: torvalds/linux@9b378f6 This commit was included in the 6.4.12 kernel released on August 23, which is not too long before the first reported occurrence of the associated package manager bug I'm aware of: zigtools/zls#1428 |
I also use BTRFS, and I just tried downgrading to the linux-lts (6.1.51) kernel on Arch Linux and it solved the issue. |
for the sake of additional data points im on xfs + linux 6.4.11 and have yet to come across the PM bug |
Would this potentially be an upstream Linux / BTRFS bug, then? |
IMO not a bug. For linux/bsd/darwin
I'd caution against any guarantees (to seeing dir changes after the dir is opened) for zig std beyond "unspecified" because there are lots of different underlying platforms and fs in use. |
Thanks, I looked over the man pages for Based on my reading of POSIX, then, calling In any case, this certainly doesn't seem to be a Zig bug, so maybe the issue needs to be retagged as a documentation enhancement or similar (if there were a portable way to "reload" the directory state, as it seems |
Zig does the equivalent of rewinddir during the first Lines 656 to 659 in f33bb02
@ianprime0509 could you test your C code reproduction with a |
@squeek502 yes, unfortunately it still does not work even when using |
One thing off the top of my head is that officially, you need to Searching around for docs I found https://lwn.net/Articles/457667/ which mentions the requirement:
I gave this a try: const std = @import("std");
pub fn main() !void {
var dir = try std.fs.cwd().openIterableDir("test", .{});
defer dir.close();
try dir.dir.writeFile("1", "1");
try dir.dir.writeFile("2", "2");
try std.os.fsync(dir.dir.fd);
var iter = dir.iterate();
while (try iter.next()) |entry| {
std.debug.print("{s}\n", .{entry.name});
}
} And it still prints just |
A patchset was submitted (not by me) to the linux-btrfs mailing list which I've confirmed resolves this issue: https://lore.kernel.org/linux-btrfs/cover.1694260751.git.fdmanana@suse.com/ |
@ianprime0509 It might be a good idea to include btrfs in the title of this issue. |
IterableDir
does not iterate over all contents created after openingIterableDir
does not iterate over all contents created after opening (Linux BTRFS)
@leecannon good idea, thanks, I added a note in the title to clarify that this is limited to Linux BTRFS. |
Maybe fixed on LK 6.5-rc7:
Reference: |
That |
Thanks for reporting this upstream, @ianprime0509! Looks like your efforts have resulted in a kernel fix. |
I'm going to close this because there is nothing actionable for Zig to do, and no workaround is planned to be implemented. There is nothing to do but wait until the affected kernel versions stop being in circulation. Short summary of the situation, for troubleshooters:
Recommend for btrfs users to stick with < 6.4.12 or >= 6.5.6 kernel versions to avoid this bug. |
FYI, the patch that fixes this is included in the recently released Linux 6.5.6: https://lwn.net/Articles/946853/
Apparently, some distros (including Arch) have been including this patch separately in their kernels recently as well. Hopefully, distros tracking the 6.5.x kernel series will pick this up soon, and we might start seeing fewer reports of this. |
Awesome job getting this reported and ultimately fixed, @ianprime0509! |
Currently, the code in |
@perillo Line 656 in 6fd1c64
next after reset ). The issue here was a bug in BTRFS for certain Linux kernels where using rewinddir or lseek to reset to the beginning of the directory didn't actually work, and the only way to completely reset the directory state was to fully reopen the file descriptor.
The workaround in question is only intended to be used on such kernels, when explicitly enabled: Lines 400 to 406 in 6fd1c64
lseek is used to reset the directory state before iterating to compute the hash).
|
@ianprime0509 Thanks for the clarification and sorry for the late response. |
Zig Version
0.12.0-dev.286+b0d9bb0bb
Steps to Reproduce and Observed Behavior
Caveat: this may not necessarily be a bug if this is acceptable platform-specific behavior, but it may be an opportunity for enhanced documentation if it is acceptable. Related to #17064 as the apparent underlying cause of that issue (this pattern appears within
Package.zig
: #17064 (comment)).Given the following Zig code:
Running this code with an initially empty
test
directory yields the following output on my machine:Subsequent runs, after
test
has already been populated with both files, yield the following output:Output of
uname -a
:Expected Behavior
The code should always output
even if those files were not both present when the
IterableDir
was opened, or a note should be added toIterableDir
's documentation mentioning the platform-specific behavior.In support of the view that this is not a bug (at least in Zig), the following C code reproduces the same behavior of excluding
2
from the output of the first run on an initially emptytest
directory:The text was updated successfully, but these errors were encountered: