-
Notifications
You must be signed in to change notification settings - Fork 3k
littlefs: Fix issue with immediate exhaustion and small unaligned storage #5761
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
Conversation
@@ -2040,8 +2040,8 @@ int lfs_mount(lfs_t *lfs, const struct lfs_config *cfg) { | |||
} | |||
|
|||
// setup free lookahead | |||
lfs->free.begin = -lfs->cfg->lookahead; | |||
lfs->free.off = lfs->cfg->lookahead; | |||
lfs->free.begin = -lfs_min(lfs->cfg->lookahead, lfs->cfg->block_count); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be good to have a comment here as to why you are doing this ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be updated
…torage This was a small hole in the logic that handles initializing the lookahead buffer. To imitate exhaustion (so the block allocator will trigger a scan), the lookahead buffer is rewound a full lookahead and set up to look like it is exhausted. However, unlike normal allocation, this rewind was not kept aligned to a multiple of the scan size, which is limited by both the lookahead buffer and the total storage size. This bug went unnoticed for so long because it only causes problems when the block device is both: 1. Not aligned to the lookahead buffer (not a power of 2) 2. Smaller than the lookahead buffer While this seems like a strange corner case for a block device, this turned out to be very common for internal flash, especially when a handleful of blocks are reserved for code.
3781597
to
5e7c097
Compare
Waiting for one review update, meantime /morph build |
/morph build |
Build : FAILUREBuild number : 870 |
license server error /morph build |
Build : SUCCESSBuild number : 876 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 547 |
Test : SUCCESSBuild number : 723 |
This was a small hole in the logic that handles initializing the lookahead buffer. To imitate exhaustion (so the block allocator will trigger a scan), the lookahead buffer is rewound a full lookahead and set up to look like it is exhausted. However, unlike normal allocation, this rewind was not kept aligned to a multiple of the scan size, which is limited by both the lookahead buffer and the total storage size.
This bug went unnoticed for so long because it only causes problems when the block device is both:
While this seems like a strange corner case for a block device, this turned out to be very common for internal flash, especially when a handful of blocks are reserved for code.
note: intended for patch
cc @marcuschangarm