bmap: Added error propagation to ckpoints and cleaned up test TODOs

The main change is error propagation in lfs3_alloc_ckpoint. Since
lfs3_alloc_ckpoint writes to disk during bmap rebuilds, it can now fail
in all sorts of ways. Fortunately lfs3_alloc_ckpoint should only ever be
called by write operations, where these errors are be expected.

With bmap rebuild errors now reported correctly, this unblocks most of
the remaining test TODOs:

- Passing test_badblocks
- Passing test_ck
- Passing test_trvs

With this, LFS3_YES_BMAP is now passing all but two tests, which are
still ifndef-disabled as a temporary measure:

- test_btree - We make some low-level assumptions about the lookahead
  allocator when testing btrees. It's probably not worth trying to get
  this passing with the bmap allocator.

- test_grow - This one does need fixing! We currently don't update
  on-disk bmaps correctly when growing the filesystem.

Code changes minimal:

                code          stack          ctx
  before:      36912           2368          684
  after:       36912 (+0.0%)   2368 (+0.0%)  684 (+0.0%)

                code          stack          ctx
  bmap before: 38456           2400          812
  bmap after:  38512 (+0.1%)   2400 (+0.0%)  812 (+0.0%)
This commit is contained in:
Christopher Haster
2025-07-30 11:44:36 -05:00
parent 41be512272
commit 27e3e10634
6 changed files with 580 additions and 172 deletions
+5 -9
View File
@@ -9,11 +9,7 @@
#
after = ['test_mtree', 'test_bmap', 'test_dirs', 'test_files']
# 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'
defines.INIT_BLOCKS = 'LFS3_IFDEF_BMAP(3, 2)'
# test that we can alloc
[cases.test_alloc_alloc]
@@ -26,7 +22,7 @@ defines.COUNT = [
'2',
]
defines.ERASE = [false, true]
if = 'COUNT >= LFS3_IFDEF_BMAP(3, 2)'
if = 'COUNT >= INIT_BLOCKS'
in = 'lfs3.c'
code = '''
// test various block counts
@@ -73,7 +69,7 @@ defines.COUNT = [
'2',
]
defines.ERASE = [false, true]
if = 'COUNT >= LFS3_IFDEF_BMAP(3, 2)'
if = 'COUNT >= INIT_BLOCKS'
in = 'lfs3.c'
code = '''
// test various block counts
@@ -659,7 +655,7 @@ defines.COUNT = [
'5',
'2',
]
if = 'COUNT >= LFS3_IFDEF_BMAP(3, 2)'
if = 'COUNT >= INIT_BLOCKS'
code = '''
// test various block counts
struct lfs3_cfg cfg = *CFG;
@@ -742,7 +738,7 @@ defines.SIZE = [
'2*BLOCK_SIZE',
'8*BLOCK_SIZE',
]
if = 'COUNT >= LFS3_IFDEF_BMAP(3, 2)'
if = 'COUNT >= INIT_BLOCKS'
code = '''
// test various block counts
struct lfs3_cfg cfg = *CFG;
+36 -37
View File
@@ -11,8 +11,7 @@ after = [
'test_compat',
]
# TODO bmap workaround?
ifndef = 'LFS3_BMAP'
defines.INIT_BLOCKS = 'LFS3_IFDEF_BMAP(3, 2)'
## Single-block badblock tests
@@ -150,7 +149,7 @@ defines.N = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]
if = 'LFS3_IFDEF_CKPROGS(true, !CKPROGS)'
code = '''
// test all possible bad blocks
for (lfs3_size_t i = 2;
for (lfs3_size_t i = INIT_BLOCKS;
i < ((BADBLOCK == -1) ? BLOCK_COUNT : 1);
i++) {
lfs3_size_t badblock = (BADBLOCK == -1) ? i : BADBLOCK;
@@ -268,7 +267,7 @@ fuzz = 'SEED'
if = 'LFS3_IFDEF_CKPROGS(true, !CKPROGS)'
code = '''
// test all possible bad blocks
for (lfs3_size_t i = 2;
for (lfs3_size_t i = INIT_BLOCKS;
i < ((BADBLOCK == -1) ? BLOCK_COUNT : 1);
i++) {
lfs3_size_t badblock = (BADBLOCK == -1) ? i : BADBLOCK;
@@ -463,7 +462,7 @@ if = [
]
code = '''
// test all possible bad blocks
for (lfs3_size_t i = 2;
for (lfs3_size_t i = INIT_BLOCKS;
i < ((BADBLOCK == -1) ? BLOCK_COUNT : 1);
i++) {
lfs3_size_t badblock = (BADBLOCK == -1) ? i : BADBLOCK;
@@ -577,7 +576,7 @@ if = [
]
code = '''
// test all possible bad blocks
for (lfs3_size_t i = 2;
for (lfs3_size_t i = INIT_BLOCKS;
i < ((BADBLOCK == -1) ? BLOCK_COUNT : 1);
i++) {
lfs3_size_t badblock = (BADBLOCK == -1) ? i : BADBLOCK;
@@ -834,7 +833,7 @@ if = [
]
code = '''
// test all possible bad blocks
for (lfs3_size_t i = 2;
for (lfs3_size_t i = INIT_BLOCKS;
i < ((BADBLOCK == -1) ? BLOCK_COUNT : 1);
i++) {
lfs3_size_t badblock = (BADBLOCK == -1) ? i : BADBLOCK;
@@ -997,7 +996,7 @@ if = [
]
code = '''
// test all possible bad blocks
for (lfs3_size_t i = 2;
for (lfs3_size_t i = INIT_BLOCKS;
i < ((BADBLOCK == -1) ? BLOCK_COUNT : 1);
i++) {
lfs3_size_t badblock = (BADBLOCK == -1) ? i : BADBLOCK;
@@ -1449,7 +1448,7 @@ if = [
]
code = '''
// test all possible bad blocks
for (lfs3_size_t i = 2;
for (lfs3_size_t i = INIT_BLOCKS;
i < ((BADBLOCK == -1) ? BLOCK_COUNT : 1);
i++) {
lfs3_size_t badblock = (BADBLOCK == -1) ? i : BADBLOCK;
@@ -2104,11 +2103,11 @@ code = '''
for (lfs3_size_t i = 0; i < BLOCK_COUNT/2; i++) {
// mark our badblock as bad
if (!MIRROR) {
if (i >= 2) {
if (i >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, i) => 0;
}
} else {
if (i+BLOCK_COUNT/2 >= 2) {
if (i+BLOCK_COUNT/2 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, i+BLOCK_COUNT/2) => 0;
}
}
@@ -2223,11 +2222,11 @@ code = '''
for (lfs3_size_t i = 0; i < BLOCK_COUNT/2; i++) {
// mark our badblock as bad
if (!MIRROR) {
if (i >= 2) {
if (i >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, i) => 0;
}
} else {
if (i+BLOCK_COUNT/2 >= 2) {
if (i+BLOCK_COUNT/2 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, i+BLOCK_COUNT/2) => 0;
}
}
@@ -2419,11 +2418,11 @@ code = '''
for (lfs3_size_t i = 0; i < BLOCK_COUNT/2; i++) {
// mark our badblock as bad
if (!MIRROR) {
if (i >= 2) {
if (i >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, i) => 0;
}
} else {
if (i+BLOCK_COUNT/2 >= 2) {
if (i+BLOCK_COUNT/2 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, i+BLOCK_COUNT/2) => 0;
}
}
@@ -2534,11 +2533,11 @@ code = '''
for (lfs3_size_t i = 0; i < BLOCK_COUNT/2; i++) {
// mark our badblock as bad
if (!MIRROR) {
if (i >= 2) {
if (i >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, i) => 0;
}
} else {
if (i+BLOCK_COUNT/2 >= 2) {
if (i+BLOCK_COUNT/2 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, i+BLOCK_COUNT/2) => 0;
}
}
@@ -2792,11 +2791,11 @@ code = '''
for (lfs3_size_t i = 0; i < BLOCK_COUNT/2; i++) {
// mark our badblock as bad
if (!MIRROR) {
if (i >= 2) {
if (i >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, i) => 0;
}
} else {
if (i+BLOCK_COUNT/2 >= 2) {
if (i+BLOCK_COUNT/2 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, i+BLOCK_COUNT/2) => 0;
}
}
@@ -2956,11 +2955,11 @@ code = '''
for (lfs3_size_t i = 0; i < BLOCK_COUNT/2; i++) {
// mark our badblock as bad
if (!MIRROR) {
if (i >= 2) {
if (i >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, i) => 0;
}
} else {
if (i+BLOCK_COUNT/2 >= 2) {
if (i+BLOCK_COUNT/2 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, i+BLOCK_COUNT/2) => 0;
}
}
@@ -3409,11 +3408,11 @@ code = '''
for (lfs3_size_t i = 0; i < BLOCK_COUNT/2; i++) {
// mark our badblock as bad
if (!MIRROR) {
if (i >= 2) {
if (i >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, i) => 0;
}
} else {
if (i+BLOCK_COUNT/2 >= 2) {
if (i+BLOCK_COUNT/2 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, i+BLOCK_COUNT/2) => 0;
}
}
@@ -4061,11 +4060,11 @@ code = '''
for (lfs3_size_t i = 0; i < BLOCK_COUNT/2; i++) {
// mark our badblock as bad
if (!MIRROR) {
if (2*i+0 >= 2) {
if (2*i+0 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, 2*i+0) => 0;
}
} else {
if (2*i+1 >= 2) {
if (2*i+1 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, 2*i+1) => 0;
}
}
@@ -4180,11 +4179,11 @@ code = '''
for (lfs3_size_t i = 0; i < BLOCK_COUNT/2; i++) {
// mark our badblock as bad
if (!MIRROR) {
if (2*i+0 >= 2) {
if (2*i+0 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, 2*i+0) => 0;
}
} else {
if (2*i+1 >= 2) {
if (2*i+1 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, 2*i+1) => 0;
}
}
@@ -4376,11 +4375,11 @@ code = '''
for (lfs3_size_t i = 0; i < BLOCK_COUNT/2; i++) {
// mark our badblock as bad
if (!MIRROR) {
if (2*i+0 >= 2) {
if (2*i+0 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, 2*i+0) => 0;
}
} else {
if (2*i+1 >= 2) {
if (2*i+1 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, 2*i+1) => 0;
}
}
@@ -4491,11 +4490,11 @@ code = '''
for (lfs3_size_t i = 0; i < BLOCK_COUNT/2; i++) {
// mark our badblock as bad
if (!MIRROR) {
if (2*i+0 >= 2) {
if (2*i+0 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, 2*i+0) => 0;
}
} else {
if (2*i+1 >= 2) {
if (2*i+1 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, 2*i+1) => 0;
}
}
@@ -4749,11 +4748,11 @@ code = '''
for (lfs3_size_t i = 0; i < BLOCK_COUNT/2; i++) {
// mark our badblock as bad
if (!MIRROR) {
if (2*i+0 >= 2) {
if (2*i+0 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, 2*i+0) => 0;
}
} else {
if (2*i+1 >= 2) {
if (2*i+1 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, 2*i+1) => 0;
}
}
@@ -4911,11 +4910,11 @@ code = '''
for (lfs3_size_t i = 0; i < BLOCK_COUNT/2; i++) {
// mark our badblock as bad
if (!MIRROR) {
if (2*i+0 >= 2) {
if (2*i+0 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, 2*i+0) => 0;
}
} else {
if (2*i+1 >= 2) {
if (2*i+1 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, 2*i+1) => 0;
}
}
@@ -5364,11 +5363,11 @@ code = '''
for (lfs3_size_t i = 0; i < BLOCK_COUNT/2; i++) {
// mark our badblock as bad
if (!MIRROR) {
if (2*i+0 >= 2) {
if (2*i+0 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, 2*i+0) => 0;
}
} else {
if (2*i+1 >= 2) {
if (2*i+1 >= INIT_BLOCKS) {
lfs3_emubd_markbad(CFG, 2*i+1) => 0;
}
}
+14 -9
View File
@@ -1,9 +1,6 @@
# Test checksum validation things
after = ['test_trvs', 'test_gc', 'test_mount']
# TODO bmap workaround?
ifndef = 'LFS3_BMAP'
code = '''
// naive crc32c
@@ -988,6 +985,7 @@ defines.SIZE = [
'2*BLOCK_SIZE',
'8*BLOCK_SIZE',
]
in = 'lfs3.c'
code = '''
for (lfs3_block_t i = 0;; i++) {
// a bit hacky, but this catches infinite loops
@@ -1026,7 +1024,8 @@ code = '''
goto done;
}
if (tinfo.btype == LFS3_BTYPE_BTREE) {
if (tinfo.btype == LFS3_BTYPE_BTREE
&& lfs3_t_tstate(trv.b.h.flags) != LFS3_TSTATE_BMAP) {
if (k == i) {
// clobber this block
printf("clobbering 0x%x\n", tinfo.block);
@@ -1085,6 +1084,7 @@ defines.SIZE = [
'2*BLOCK_SIZE',
'8*BLOCK_SIZE',
]
in = 'lfs3.c'
code = '''
for (lfs3_block_t i = 0;; i++) {
// a bit hacky, but this catches infinite loops
@@ -1123,8 +1123,9 @@ code = '''
goto done;
}
if (tinfo.btype == LFS3_BTYPE_BTREE
|| tinfo.btype == LFS3_BTYPE_DATA) {
if ((tinfo.btype == LFS3_BTYPE_BTREE
|| tinfo.btype == LFS3_BTYPE_DATA)
&& lfs3_t_tstate(trv.b.h.flags) != LFS3_TSTATE_BMAP) {
if (k == i) {
// clobber this block
printf("clobbering 0x%x\n", tinfo.block);
@@ -1188,6 +1189,7 @@ defines.SIZE = [
defines.SEED = 42
defines.M = 100
fuzz = 'SEED'
in = 'lfs3.c'
code = '''
uint32_t prng_ = SEED;
for (lfs3_block_t i = 0;; i++) {
@@ -1228,7 +1230,8 @@ code = '''
goto done;
}
if (tinfo.btype == LFS3_BTYPE_BTREE) {
if (tinfo.btype == LFS3_BTYPE_BTREE
&& lfs3_t_tstate(trv.b.h.flags) != LFS3_TSTATE_BMAP) {
// found an interesting block?
if (k == i) {
badblock = tinfo.block;
@@ -1336,6 +1339,7 @@ defines.SIZE = [
defines.SEED = 42
defines.M = 100
fuzz = 'SEED'
in = 'lfs3.c'
code = '''
uint32_t prng_ = SEED;
for (lfs3_block_t i = 0;; i++) {
@@ -1376,8 +1380,9 @@ code = '''
goto done;
}
if (tinfo.btype == LFS3_BTYPE_BTREE
|| tinfo.btype == LFS3_BTYPE_DATA) {
if ((tinfo.btype == LFS3_BTYPE_BTREE
|| tinfo.btype == LFS3_BTYPE_DATA)
&& lfs3_t_tstate(trv.b.h.flags) != LFS3_TSTATE_BMAP) {
// found an interesting block?
if (k == i) {
badblock = tinfo.block;
+1 -1
View File
@@ -8,7 +8,7 @@ after = [
'test_mount',
]
# TODO bmap workaround?
# TODO!! lfs3_fs_grow needs to be able to adjust an on-disk bmaps
ifndef = 'LFS3_BMAP'
+393 -75
View File
File diff suppressed because it is too large Load Diff