diff options
author | Christopher Haster <chaster@utexas.edu> | 2018-02-08 10:30:21 +0300 |
---|---|---|
committer | Christopher Haster <chaster@utexas.edu> | 2018-02-08 10:52:39 +0300 |
commit | e611cf5050fc44acb97057654b6885ec9b060915 (patch) | |
tree | 380ea72c56ad27f1e608c19fd110bc7903196258 /tests | |
parent | a25743a82a5a3c074e492aeba912373ef2e74288 (diff) |
Fix incorrect lookahead population before ack
Rather than tracking all in-flight blocks blocks during a lookahead,
littlefs uses an ack scheme to mark the first allocated block that
hasn't reached the disk yet. littlefs assumes all blocks since the
last ack are bad or in-flight, and uses this to know when it's out
of storage.
However, these unacked allocations were still being populated in the
lookahead buffer. If the whole block device fits in the lookahead
buffer, _and_ littlefs managed to scan around the whole storage while
an unacked block was still in-flight, it would assume the block was
free and misallocate it.
The fix is to only fill the lookahead buffer up to the last ack.
The internal free structure was restructured to simplify the runtime
calculation of lookahead size.
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/test_alloc.sh | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/test_alloc.sh b/tests/test_alloc.sh index aaae655..493270d 100755 --- a/tests/test_alloc.sh +++ b/tests/test_alloc.sh @@ -266,6 +266,40 @@ tests/test.py << TEST lfs_mkdir(&lfs, "exhaustiondir2") => LFS_ERR_NOSPC; TEST +echo "--- Split dir test ---" +rm -rf blocks +tests/test.py << TEST + lfs_format(&lfs, &cfg) => 0; +TEST +tests/test.py << TEST + lfs_mount(&lfs, &cfg) => 0; + + // create one block whole for half a directory + lfs_file_open(&lfs, &file[0], "bump", LFS_O_WRONLY | LFS_O_CREAT) => 0; + lfs_file_write(&lfs, &file[0], (void*)"hi", 2) => 2; + lfs_file_close(&lfs, &file[0]) => 0; + + lfs_file_open(&lfs, &file[0], "exhaustion", LFS_O_WRONLY | LFS_O_CREAT); + size = strlen("blahblahblahblah"); + memcpy(buffer, "blahblahblahblah", size); + for (lfs_size_t i = 0; + i < (cfg.block_count-6)*(cfg.block_size-8); + i += size) { + lfs_file_write(&lfs, &file[0], buffer, size) => size; + } + lfs_file_close(&lfs, &file[0]) => 0; + + // open whole + lfs_remove(&lfs, "bump") => 0; + + lfs_mkdir(&lfs, "splitdir") => 0; + lfs_file_open(&lfs, &file[0], "splitdir/bump", + LFS_O_WRONLY | LFS_O_CREAT) => 0; + lfs_file_write(&lfs, &file[0], buffer, size) => LFS_ERR_NOSPC; + lfs_file_close(&lfs, &file[0]) => 0; + + lfs_unmount(&lfs) => 0; +TEST echo "--- Results ---" tests/stats.py |