-
Notifications
You must be signed in to change notification settings - Fork 797
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
lfs_fs_forceconsistency()->lfs_fs_deorphan() doesn't commit updated gstate #604
Comments
Hi, |
Hi @kasper0, thanks for creating an issue, this is good feedback. The motivation for delaying the gstate commit is that we effectively write the gstate for free in the common case of being followed by a commit. This can be significant on storage with large prog_sizes (SD, NAND, mostly). If a function fails before it can commit, the pending gstate should at least still be saved in Though it makes sense to me to add a public |
@geky Thank you for your answer, but every time I open a file in the 'RDWR' mode, it takes a long time. The following is the time I printed out for each function.
|
Thank you for your prompt reply. I tried the 2.4.2 version of lfs and did not find this problem. I found that the |
This does look like a bug and deserves more scrutiny. In theory the line you found in Lines 4599 to 4602 in 6a53d76
I'm guessing we've somehow ended up in a state where there are no orphans in the filesystem, but the orphan flag is set. This shouldn't happen normally, since we atomically clear the orphan flag when cleaning up orphans, but that's not an excuse for handling this case poorly. I'll try to reproduce this on my end, it would be good to have tests asserting that
I think you're on to something, that found variable does look useless and problematic. It may be left over from a previous There are two ways One main goal of littlefs is to not require recursion, and since each metadata block has effectively two parents (one directory parent and one linked-list predecessor), this gets a bit tricky. At the same time, we really don't want to call the expensive The solution is to use an internal 10-bit counter stored in some of the reserved bits of the gstate to track the number of orphan. If we weren't able to fix all orphans when relocating, we fall back to In theory it's possible to exit If you're able to reproduce this bug consistently, it would be interesting to know if eba5553 fixes the underlying orphan counting issue. This was found in a PR adding more testing and was recently merged into the devel branch (staging area for an upcoming release). |
I was able to artificially reproduce the repeatedly-deorphaning issue in the case there are no orphans in the filesystem, and went ahead and pushed up a fix+test here: I think this should help your case @Ldd309, |
Thank you very much for your help, I will try it soon |
Hi,
while debugging the lfs, I've noticed that lfs_fs_forceconsistency()->lfs_fs_deorphan() doesn't commit updated gstate after fixing orphans. The responsibility for saving new gstate lies with a function calling lfs_fs_forceconsistency(), but it fails if the function returns before making a commit (e.g. mkdir() when the directory already exists).
Unfortunately, it takes a long time to perform the consistency check on systems with limited resources and dozens of files. As a result, if the issue mentioned above occurs followed by a reboot or power outage, time will be wasted on another consistency check (in my case, 1600 files/ 30minutes).
Moreover, it would be great to perform the consistency check directly from API without using the side effect of mkdir/open/remove/rename.
The text was updated successfully, but these errors were encountered: