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

littlefs: Fix issue with immediate exhaustion and small unaligned storage #5761

Merged
merged 1 commit into from Jan 18, 2018

Conversation

Projects
None yet
5 participants
@geky
Member

geky commented Dec 27, 2017

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 (< 64 blocks)

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

@geky geky added the needs: review label Dec 29, 2017

@@ -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);

This comment has been minimized.

@adbridge

adbridge Jan 2, 2018

Contributor

Would be good to have a comment here as to why you are doing this ...

This comment has been minimized.

@geky

geky Jan 4, 2018

Member

Should be updated

@0xc0170 0xc0170 added needs: work and removed needs: review labels Jan 3, 2018

littlefs: Fixed issue with immediate exhaustion and small unaligned s…
…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.

@geky geky force-pushed the geky:littlefs-fix-lookahead-rewind branch from 3781597 to 5e7c097 Jan 4, 2018

@geky geky added needs: review and removed needs: work labels Jan 4, 2018

@0xc0170

0xc0170 approved these changes Jan 4, 2018

@0xc0170 0xc0170 added needs: CI and removed needs: review labels Jan 12, 2018

@0xc0170

This comment has been minimized.

Member

0xc0170 commented Jan 12, 2018

Waiting for one review update, meantime

/morph build

@0xc0170

This comment has been minimized.

Member

0xc0170 commented Jan 15, 2018

/morph build

@mbed-ci

This comment has been minimized.

mbed-ci commented Jan 15, 2018

@0xc0170

This comment has been minimized.

Member

0xc0170 commented Jan 16, 2018

license server error

/morph build

@mbed-ci

This comment has been minimized.

mbed-ci commented Jan 16, 2018

Build : SUCCESS

Build number : 876
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/5761/

Triggering tests

/morph test
/morph uvisor-test
/morph export-build

@mbed-ci

This comment has been minimized.

@mbed-ci

This comment has been minimized.

@0xc0170 0xc0170 added ready for merge and removed needs: CI labels Jan 17, 2018

@cmonr cmonr merged commit b8abbab into ARMmbed:master Jan 18, 2018

19 checks passed

ARM mbed CI Verification build successful.
Details
AWS-CI uVisor Build & Test Success
Details
ci-morph-build build completed
Details
ci-morph-exporter build completed
Details
ci-morph-test test completed
Details
continuous-integration/jenkins/pr-head This commit looks good
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
travis-ci/docs Local docs testing has passed
Details
travis-ci/events Local events testing has passed
Details
travis-ci/littlefs Local littlefs testing has passed
Details
travis-ci/mbed2-ATMEL Local mbed2-ATMEL testing has passed
Details
travis-ci/mbed2-MAXIM Local mbed2-MAXIM testing has passed
Details
travis-ci/mbed2-NORDIC Local mbed2-NORDIC testing has passed
Details
travis-ci/mbed2-NUVOTON Local mbed2-NUVOTON testing has passed
Details
travis-ci/mbed2-NXP Local mbed2-NXP testing has passed
Details
travis-ci/mbed2-RENESAS Local mbed2-RENESAS testing has passed
Details
travis-ci/mbed2-SILICON_LABS Local mbed2-SILICON_LABS testing has passed
Details
travis-ci/mbed2-STM Local mbed2-STM testing has passed
Details
travis-ci/tools Local tools testing has passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment