Closed BrianPugh closed 1 year ago
@geky I think this is ready now!
what are our thoughts on this? It's less invasive than the other PRs. It's also a backwards compatible change. Any future changes (such as if we allow lfs_config_t
to be mutable) are compatible with this PR. In that example, we'd just remove the newly introduced lfs->block_count
field and have all the pointers point back to the now mutable lfs->config->block_count
.
I'm looking forward to some form of block_count
autodetection so that I can publish my cli tool that manages littlefs partitions to PyPI.
Hi @BrianPugh, thanks for this. I left some feedback.
I'm not sure fetching the block_count
from disk during lfs_format
makes sense. I left an in-code comment about that.
I think we should also add block_count
(and maybe block_size
for completeness) to lfs_fs_stat
, so the block_count
is available to the user after mounting. This should just mean another assignment in lfs_fs_rawstat
: here.
I'm also curious if the test_superblocks_fewer_blocks
and test_superblocks_more_blocks
tests from #753 can be ported over to this. They provide coverage for a few more corner cases, and should cover changes to lfs_fs_stat
well enough.
I'm also thinking I'll try to get lfs_fs_grow
(#753, #702) in on the same minor release as this, since they are closely related. Though that doesn't affect this PR.
@geky currently this is set as a draft as I want to write more unit tests, but need some advice on how to debug. Currently one of the test permutations hangs; I don't quite understand what the permutations are or how to debug.
Were you able to figure out debugging with the test framework? It's unfortunately a bit dense not documented well.
If a test permutation fails in CI:
tests/test_compat.toml:1296:failure: test_compat_major_incompat:1g12gg2 (PROG_SIZE=16, BLOCK_SIZE=512) failed
You should be able to rerun it locally like so:
# build the test runner
$ make test-runner -j
# run the failing test
$ ./scripts/test.py runners/test_runner test_compat_major_incompat:1g12gg2
Though for the Valgrind tests you need to pass the valgrind flag:
$ ./scripts/test.py runners/test_runner test_compat_major_incompat:1g12gg2 --valgrind
Note the test framework expects quite a bit more from the dev environment than littlefs itself. It's unlikely to work with a non-GCC/Clang compiler...
I'll add the lfs_fs_stat
functionality and investigate the unit tests you recommended
@geky-bot copying over the tests from #753 ALMOST works, but it would also involve copying over all the runner and related changes. I feel like that might balloon this PR and make a bunch of unnecessary merge conflicts. Waiting for your advice before performing more actions.
Since your last review I:
lfs_fs_stat
along with the related struct fields.so whats the conclusion on this? Does the PR seem good? Waiting to bundle it with other PRs for a release?
This is looking good, thanks for the updates. I'm currently planning to bring this in on the next minor release.
I'm still wanting to look into the extra tests in https://github.com/littlefs-project/littlefs/pull/753, which as you point likely come with baggage, and lfs_fs_grow
(https://github.com/littlefs-project/littlefs/pull/753, https://github.com/littlefs-project/littlefs/pull/702) since it is closely related. But I think these would be more appropriate in separate PRs.
I've gone ahead and reverted the lfs_scan_for_superblocks
and lfs_scan_for_state_updates
refactor. The new code path would have led to scanning the superblock chain twice, when we only need to scan it once.
Let me know if you see anything wrong with this.
@geky that's fine by me since we no longer invoke lfs_scan_for_superblocks
at multiple places 👍 . It also does make this PR a lot more terse :D
I've also gone ahead and adopted the block-device/runner changes in https://github.com/littlefs-project/littlefs/pull/753. I realize this is probably pushing the scope of this PR, but it lets us adopt the tests in https://github.com/littlefs-project/littlefs/pull/753, and is probably a good long-term change.
I also tweaked lfs_fsinfo
a bit, mainly to make the struct fields follow the order found in the superblock for consistency. I realize this is really nitpicky.
If you're ok with these changes this looks good to me for the next minor release.
Also the now-dependent lfs_fs_grow
API is here: https://github.com/littlefs-project/littlefs/pull/872
all seems good to me!
This is on master now, thanks for the PR!
Whoops, meant to respond to this one: https://github.com/littlefs-project/littlefs/pull/886. Well this is technically on master as well so...
This pull request attempts to autodetect the
block_count
from the superblock if not provided inlfs_config
(i.e.cfg->block_count == 0
).This PR slightly increases RAM usage by increasing the
lfs_t
struct by 4 bytes.~I think this PR could also negatively impact mounting performance (I refactored it so that the superblock search and the gstate search are independent), but I think those are super fast anyways. A possible organization improvement would be to abstract the traversal to another function, but that might reduce readability. We can leave that for another PR.~
~@geky currently this is set as a draft as I want to write more unit tests, but need some advice on how to debug. Currently one of the test permutations hangs; I don't quite understand what the permutations are or how to debug.~
Related issues & PRs: #865, #753
For ease of review, the biggest commit (73285278b98e0b15a608325b3f7e4c5b8e0c6b75) just moves the identical traversal into 2 functions (superblock, gstate), and moves the superblock validation to a separate function. There's no real logic change in that commit, except that the superblock is found first, then the gstate is updated (rather than at the same time).