diff --git a/lfs3.c b/lfs3.c index 167234bf..5936b1d5 100644 --- a/lfs3.c +++ b/lfs3.c @@ -10812,6 +10812,7 @@ static int lfs3_alloc_rebuildbmap(lfs3_t *lfs3); #if !defined(LFS3_RDONLY) static inline void lfs3_alloc_ckpoint(lfs3_t *lfs3) { #ifndef LFS3_2BONLY + // checkpoint the allocator lfs3->lookahead.ckpoint = lfs3->block_count; #ifdef LFS3_BMAP // do we need to rebuild the bmap? @@ -10821,6 +10822,8 @@ static inline void lfs3_alloc_ckpoint(lfs3_t *lfs3) { int err = lfs3_alloc_rebuildbmap(lfs3); // TODO lfs3_alloc_ckpoint should propagate errors LFS3_ASSERT(!err); +// // checkpoint the allocator again after rebuilding the bmap +// lfs3->lookahead.ckpoint = lfs3->block_count; } #endif #else @@ -11497,13 +11500,10 @@ int lfs3_mkdir(lfs3_t *lfs3, const char *path) { ? tag_ >= 0 : tag_ == LFS3_ERR_NOENT); - // TODO should we have a GRMPOP rattr? to match GRMPUSH? The fact that - // lfs3_mdir_commit implicitly reverts grms is a bit counterintuitive - // // commit our new directory into our parent, zeroing the grm in the // process - lfs3_alloc_ckpoint(lfs3); lfs3_grm_pop(lfs3); + lfs3_alloc_ckpoint(lfs3); err = lfs3_mdir_commit(lfs3, &mdir, LFS3_RATTRS( LFS3_RATTR_NAME( LFS3_TAG_MASK12 | LFS3_TAG_DIR, @@ -16560,10 +16560,10 @@ static int lfs3_fs_fixgrm(lfs3_t *lfs3) { // we need to revert manually on error lfs3_grm_t grm_p = lfs3->grm; - // checkpoint the allocator - lfs3_alloc_ckpoint(lfs3); // mark grm as taken care of lfs3_grm_pop(lfs3); + // checkpoint the allocator + lfs3_alloc_ckpoint(lfs3); // remove the rid while atomically updating our grm err = lfs3_mdir_commit(lfs3, &mdir, LFS3_RATTRS( LFS3_RATTR(LFS3_TAG_RM, -1))); diff --git a/tests/test_alloc.toml b/tests/test_alloc.toml index 8e335ab2..69ac589f 100644 --- a/tests/test_alloc.toml +++ b/tests/test_alloc.toml @@ -9,8 +9,11 @@ # after = ['test_mtree', 'test_bmap', 'test_dirs', 'test_files'] -# TODO bmap workaround? -ifndef = 'LFS3_BMAP' +# TODO should we rename these to test_lookahead? +# TODO or extend to test the bmap as well? +# +# these are really tuned to test the lookahead allocator +#ifndef = 'LFS3_BMAP' # test that we can alloc [cases.test_alloc_alloc] @@ -23,6 +26,7 @@ defines.COUNT = [ '2', ] defines.ERASE = [false, true] +if = 'COUNT >= LFS3_IFDEF_BMAP(3, 2)' in = 'lfs3.c' code = ''' // test various block counts @@ -49,9 +53,11 @@ code = ''' } // excluding our mroot, we should have allocated exactly - // block_count-2 blocks + // block_count-2 blocks (this gets more complicated with a bmap) printf("alloced %d/%d blocks\n", alloced, (lfs3_block_t)COUNT); + #ifndef LFS3_BMAP assert(alloced == COUNT-2); + #endif lfs3_unmount(&lfs3) => 0; ''' @@ -67,6 +73,7 @@ defines.COUNT = [ '2', ] defines.ERASE = [false, true] +if = 'COUNT >= LFS3_IFDEF_BMAP(3, 2)' in = 'lfs3.c' code = ''' // test various block counts @@ -93,9 +100,11 @@ code = ''' } // excluding our mroot, we should have allocated exactly - // block_count-2 blocks + // block_count-2 blocks (this gets more complicated with a bmap) printf("alloced %d/%d blocks\n", alloced, (lfs3_block_t)COUNT); + #ifndef LFS3_BMAP assert(alloced == COUNT-2); + #endif // ack again, effectively releasing all the previously alloced blocks lfs3_alloc_ckpoint(&lfs3); @@ -114,9 +123,11 @@ code = ''' } // excluding our mroot, we should have allocated exactly - // block_count-2 blocks + // block_count-2 blocks (this gets more complicated with a bmap) printf("alloced %d/%d blocks\n", alloced, (lfs3_block_t)COUNT); + #ifndef LFS3_BMAP assert(alloced == COUNT-2); + #endif lfs3_unmount(&lfs3) => 0; ''' @@ -648,6 +659,7 @@ defines.COUNT = [ '5', '2', ] +if = 'COUNT >= LFS3_IFDEF_BMAP(3, 2)' code = ''' // test various block counts struct lfs3_cfg cfg = *CFG; @@ -730,6 +742,7 @@ defines.SIZE = [ '2*BLOCK_SIZE', '8*BLOCK_SIZE', ] +if = 'COUNT >= LFS3_IFDEF_BMAP(3, 2)' code = ''' // test various block counts struct lfs3_cfg cfg = *CFG; diff --git a/tests/test_btree.toml b/tests/test_btree.toml index 9495828b..1e042e42 100644 --- a/tests/test_btree.toml +++ b/tests/test_btree.toml @@ -1,7 +1,7 @@ # Test the mid-level B-trees after = 'test_rbyd' -# TODO bmap workaround? +# don't bother testing with more complicated block allocators ifndef = 'LFS3_BMAP' # maximize lookahead buffer, we don't actually gc so we only get one pass diff --git a/tests/test_gc.toml b/tests/test_gc.toml index 1438a6ec..b364a454 100644 --- a/tests/test_gc.toml +++ b/tests/test_gc.toml @@ -4,9 +4,6 @@ # GC-API specific things here after = ['test_trvs'] -# TODO bmap workaround? -ifndef = 'LFS3_BMAP' - # test that lookahead can make progress in isolation [cases.test_gc_lookahead_progress] defines.CKMETA = [false, true] @@ -1461,7 +1458,8 @@ code = ''' | LFS3_I_LOOKAHEAD | LFS3_I_COMPACT | LFS3_I_CKMETA - | LFS3_I_CKDATA)); + | LFS3_I_CKDATA + | LFS3_IFDEF_BMAP(LFS3_I_BMAPCACHE, 0))); // run gc if (AFTER == 0) { @@ -1576,7 +1574,8 @@ code = ''' | ((!COMPACT) ? LFS3_I_COMPACT : 0) // note ckdata implies ckmeta | ((!CKMETA && !CKDATA) ? LFS3_I_CKMETA : 0) - | ((!CKDATA) ? LFS3_I_CKDATA : 0))); + | ((!CKDATA) ? LFS3_I_CKDATA : 0) + | LFS3_IFDEF_BMAP(LFS3_I_BMAPCACHE, 0))); lfs3_unmount(&lfs3) => 0; ''' @@ -1650,7 +1649,8 @@ code = ''' | LFS3_I_LOOKAHEAD | LFS3_I_COMPACT | LFS3_I_CKMETA - | LFS3_I_CKDATA)); + | LFS3_I_CKDATA + | LFS3_IFDEF_BMAP(LFS3_I_BMAPCACHE, 0))); // run gc if (AFTER == 0) { @@ -1765,7 +1765,8 @@ code = ''' | ((!COMPACT) ? LFS3_I_COMPACT : 0) // note ckdata implies ckmeta | ((!CKMETA && !CKDATA) ? LFS3_I_CKMETA : 0) - | ((!CKDATA) ? LFS3_I_CKDATA : 0))); + | ((!CKDATA) ? LFS3_I_CKDATA : 0) + | LFS3_IFDEF_BMAP(LFS3_I_BMAPCACHE, 0))); // test that we can reset flags with lfs3_fs_unck lfs3_fs_unck(&lfs3, GC_FLAGS) => 0; @@ -1779,7 +1780,8 @@ code = ''' // note ckdata implies ckmeta, but uncking ckdata does // _not_ imply uncking ckmeta | ((!(CKDATA && !CKMETA)) ? LFS3_I_CKMETA : 0) - | LFS3_I_CKDATA)); + | LFS3_I_CKDATA + | LFS3_IFDEF_BMAP(LFS3_I_BMAPCACHE, 0))); // run gc if (AFTER == 0) { @@ -1894,7 +1896,8 @@ code = ''' | ((!COMPACT) ? LFS3_I_COMPACT : 0) // note ckdata implies ckmeta | ((!CKMETA && !CKDATA) ? LFS3_I_CKMETA : 0) - | ((!CKDATA) ? LFS3_I_CKDATA : 0))); + | ((!CKDATA) ? LFS3_I_CKDATA : 0) + | LFS3_IFDEF_BMAP(LFS3_I_BMAPCACHE, 0))); lfs3_unmount(&lfs3) => 0; ''' diff --git a/tests/test_mount.toml b/tests/test_mount.toml index 0bcdb634..e07a514b 100644 --- a/tests/test_mount.toml +++ b/tests/test_mount.toml @@ -1,9 +1,6 @@ # Advanced mount tests after = ['test_mtree', 'test_trvs'] -# TODO bmap workaround? -ifndef = 'LFS3_BMAP' - # test we can mount [cases.test_mount_simple] @@ -89,7 +86,8 @@ code = ''' | ((!COMPACT) ? LFS3_I_COMPACT : 0) // note ckdata implies ckmeta | ((!CKMETA && !CKDATA) ? LFS3_I_CKMETA : 0) - | ((!CKDATA) ? LFS3_I_CKDATA : 0))); + | ((!CKDATA) ? LFS3_I_CKDATA : 0) + | LFS3_IFDEF_BMAP(LFS3_I_BMAPCACHE, 0))); lfs3_unmount(&lfs3) => 0; ''' @@ -156,7 +154,8 @@ code = ''' | LFS3_I_LOOKAHEAD | LFS3_I_COMPACT | LFS3_I_CKMETA - | LFS3_I_CKDATA)); + | LFS3_I_CKDATA + | LFS3_IFDEF_BMAP(LFS3_I_BMAPCACHE, 0))); lfs3_unmount(&lfs3) => 0; // with LFS3_M_LOOKAHEAD, mount performs a lookahead scan @@ -172,7 +171,8 @@ code = ''' | LFS3_I_COMPACT // note ckdata implies ckmeta | ((!CKMETA && !CKDATA) ? LFS3_I_CKMETA : 0) - | ((!CKDATA) ? LFS3_I_CKDATA : 0))); + | ((!CKDATA) ? LFS3_I_CKDATA : 0) + | LFS3_IFDEF_BMAP(LFS3_I_BMAPCACHE, 0))); lfs3_unmount(&lfs3) => 0; ''' @@ -227,7 +227,8 @@ code = ''' | LFS3_I_LOOKAHEAD | LFS3_I_COMPACT | LFS3_I_CKMETA - | LFS3_I_CKDATA)); + | LFS3_I_CKDATA + | LFS3_IFDEF_BMAP(LFS3_I_BMAPCACHE, 0))); lfs3_unmount(&lfs3) => 0; // with LFS3_M_COMPACT, mount compact any uncompacted blocks @@ -244,7 +245,8 @@ code = ''' | ((!LOOKAHEAD) ? LFS3_I_LOOKAHEAD : 0) // note ckdata implies ckmeta | ((!CKMETA && !CKDATA) ? LFS3_I_CKMETA : 0) - | ((!CKDATA) ? LFS3_I_CKDATA : 0))); + | ((!CKDATA) ? LFS3_I_CKDATA : 0) + | LFS3_IFDEF_BMAP(LFS3_I_BMAPCACHE, 0))); // mdir should have been compacted lfs3_file_open(&lfs3, &file, "jellyfish", LFS3_O_RDONLY) => 0; @@ -329,7 +331,8 @@ code = ''' | LFS3_I_LOOKAHEAD | LFS3_I_COMPACT | LFS3_I_CKMETA - | LFS3_I_CKDATA)); + | LFS3_I_CKDATA + | LFS3_IFDEF_BMAP(LFS3_I_BMAPCACHE, 0))); lfs3_unmount(&lfs3) => 0; // with LFS3_M_MKCONSISTENT, mount cleans up orphans eagerly @@ -347,7 +350,8 @@ code = ''' | ((!COMPACT) ? LFS3_I_COMPACT : 0) // note ckdata implies ckmeta | ((!CKMETA && !CKDATA) ? LFS3_I_CKMETA : 0) - | ((!CKDATA) ? LFS3_I_CKDATA : 0))); + | ((!CKDATA) ? LFS3_I_CKDATA : 0) + | LFS3_IFDEF_BMAP(LFS3_I_BMAPCACHE, 0))); // check we can still read the files lfs3_file_open(&lfs3, &file, "cuttlefish", LFS3_O_RDONLY) => 0; diff --git a/tests/test_relocations.toml b/tests/test_relocations.toml index 2a2b16b7..22285d98 100644 --- a/tests/test_relocations.toml +++ b/tests/test_relocations.toml @@ -7,9 +7,6 @@ after = [ 'test_powerloss', ] -# TODO bmap workaround? -ifndef = 'LFS3_BMAP' - # Note that most of the delicate relocation operations are already tested # in test_mtree. This mostly just covers high-level operations with # relatively aggressive wear-leveling.