gbmap: Added support for gbmap in lfs3_fs_grow

In lfs3_fs_grow, we need to update any gbmaps to match the new disk
size. The actual patch to the gbmap is easy, but it does get a bit
delicate since we need to feed the gbmap with an allocator in the new
disk size.

Fortunately, the opportunistism of the gbmap allocator avoids any
catch-22 issues, as long as we make sure to not trigger any gbmap
rebuilds.

Adds a bit of code, but not much:

                 code          stack          ctx
  before:       37168           2352          684
  after:        37168 (+0.0%)   2352 (+0.0%)  684 (+0.0%)

                 code          stack          ctx
  gbmap before: 39000           2456          800
  gbmap after:  39116 (+0.3%)   2456 (+0.0%)  800 (+0.0%)
This commit is contained in:
Christopher Haster
2025-10-10 13:44:40 -05:00
parent 24d75a24c5
commit 9e45249b29
7 changed files with 196 additions and 112 deletions
+36 -36
View File
@@ -11,7 +11,7 @@ after = [
'test_compat',
]
defines.INIT_BLOCKS = 'LFS3_IFDEF_GBMAP(3, 2)'
defines.FORMAT_BLOCK_COUNT = 'LFS3_IFDEF_YES_GBMAP(3, 2)'
## Single-block badblock tests
@@ -149,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 = INIT_BLOCKS;
for (lfs3_size_t i = FORMAT_BLOCK_COUNT;
i < ((BADBLOCK == -1) ? BLOCK_COUNT : 1);
i++) {
lfs3_size_t badblock = (BADBLOCK == -1) ? i : BADBLOCK;
@@ -267,7 +267,7 @@ fuzz = 'SEED'
if = 'LFS3_IFDEF_CKPROGS(true, !CKPROGS)'
code = '''
// test all possible bad blocks
for (lfs3_size_t i = INIT_BLOCKS;
for (lfs3_size_t i = FORMAT_BLOCK_COUNT;
i < ((BADBLOCK == -1) ? BLOCK_COUNT : 1);
i++) {
lfs3_size_t badblock = (BADBLOCK == -1) ? i : BADBLOCK;
@@ -462,7 +462,7 @@ if = [
]
code = '''
// test all possible bad blocks
for (lfs3_size_t i = INIT_BLOCKS;
for (lfs3_size_t i = FORMAT_BLOCK_COUNT;
i < ((BADBLOCK == -1) ? BLOCK_COUNT : 1);
i++) {
lfs3_size_t badblock = (BADBLOCK == -1) ? i : BADBLOCK;
@@ -576,7 +576,7 @@ if = [
]
code = '''
// test all possible bad blocks
for (lfs3_size_t i = INIT_BLOCKS;
for (lfs3_size_t i = FORMAT_BLOCK_COUNT;
i < ((BADBLOCK == -1) ? BLOCK_COUNT : 1);
i++) {
lfs3_size_t badblock = (BADBLOCK == -1) ? i : BADBLOCK;
@@ -833,7 +833,7 @@ if = [
]
code = '''
// test all possible bad blocks
for (lfs3_size_t i = INIT_BLOCKS;
for (lfs3_size_t i = FORMAT_BLOCK_COUNT;
i < ((BADBLOCK == -1) ? BLOCK_COUNT : 1);
i++) {
lfs3_size_t badblock = (BADBLOCK == -1) ? i : BADBLOCK;
@@ -996,7 +996,7 @@ if = [
]
code = '''
// test all possible bad blocks
for (lfs3_size_t i = INIT_BLOCKS;
for (lfs3_size_t i = FORMAT_BLOCK_COUNT;
i < ((BADBLOCK == -1) ? BLOCK_COUNT : 1);
i++) {
lfs3_size_t badblock = (BADBLOCK == -1) ? i : BADBLOCK;
@@ -1448,7 +1448,7 @@ if = [
]
code = '''
// test all possible bad blocks
for (lfs3_size_t i = INIT_BLOCKS;
for (lfs3_size_t i = FORMAT_BLOCK_COUNT;
i < ((BADBLOCK == -1) ? BLOCK_COUNT : 1);
i++) {
lfs3_size_t badblock = (BADBLOCK == -1) ? i : BADBLOCK;
@@ -2103,11 +2103,11 @@ code = '''
for (lfs3_size_t i = 0; i < BLOCK_COUNT/2; i++) {
// mark our badblock as bad
if (!MIRROR) {
if (i >= INIT_BLOCKS) {
if (i >= FORMAT_BLOCK_COUNT) {
lfs3_emubd_markbad(CFG, i) => 0;
}
} else {
if (i+BLOCK_COUNT/2 >= INIT_BLOCKS) {
if (i+BLOCK_COUNT/2 >= FORMAT_BLOCK_COUNT) {
lfs3_emubd_markbad(CFG, i+BLOCK_COUNT/2) => 0;
}
}
@@ -2222,11 +2222,11 @@ code = '''
for (lfs3_size_t i = 0; i < BLOCK_COUNT/2; i++) {
// mark our badblock as bad
if (!MIRROR) {
if (i >= INIT_BLOCKS) {
if (i >= FORMAT_BLOCK_COUNT) {
lfs3_emubd_markbad(CFG, i) => 0;
}
} else {
if (i+BLOCK_COUNT/2 >= INIT_BLOCKS) {
if (i+BLOCK_COUNT/2 >= FORMAT_BLOCK_COUNT) {
lfs3_emubd_markbad(CFG, i+BLOCK_COUNT/2) => 0;
}
}
@@ -2418,11 +2418,11 @@ code = '''
for (lfs3_size_t i = 0; i < BLOCK_COUNT/2; i++) {
// mark our badblock as bad
if (!MIRROR) {
if (i >= INIT_BLOCKS) {
if (i >= FORMAT_BLOCK_COUNT) {
lfs3_emubd_markbad(CFG, i) => 0;
}
} else {
if (i+BLOCK_COUNT/2 >= INIT_BLOCKS) {
if (i+BLOCK_COUNT/2 >= FORMAT_BLOCK_COUNT) {
lfs3_emubd_markbad(CFG, i+BLOCK_COUNT/2) => 0;
}
}
@@ -2533,11 +2533,11 @@ code = '''
for (lfs3_size_t i = 0; i < BLOCK_COUNT/2; i++) {
// mark our badblock as bad
if (!MIRROR) {
if (i >= INIT_BLOCKS) {
if (i >= FORMAT_BLOCK_COUNT) {
lfs3_emubd_markbad(CFG, i) => 0;
}
} else {
if (i+BLOCK_COUNT/2 >= INIT_BLOCKS) {
if (i+BLOCK_COUNT/2 >= FORMAT_BLOCK_COUNT) {
lfs3_emubd_markbad(CFG, i+BLOCK_COUNT/2) => 0;
}
}
@@ -2791,11 +2791,11 @@ code = '''
for (lfs3_size_t i = 0; i < BLOCK_COUNT/2; i++) {
// mark our badblock as bad
if (!MIRROR) {
if (i >= INIT_BLOCKS) {
if (i >= FORMAT_BLOCK_COUNT) {
lfs3_emubd_markbad(CFG, i) => 0;
}
} else {
if (i+BLOCK_COUNT/2 >= INIT_BLOCKS) {
if (i+BLOCK_COUNT/2 >= FORMAT_BLOCK_COUNT) {
lfs3_emubd_markbad(CFG, i+BLOCK_COUNT/2) => 0;
}
}
@@ -2955,11 +2955,11 @@ code = '''
for (lfs3_size_t i = 0; i < BLOCK_COUNT/2; i++) {
// mark our badblock as bad
if (!MIRROR) {
if (i >= INIT_BLOCKS) {
if (i >= FORMAT_BLOCK_COUNT) {
lfs3_emubd_markbad(CFG, i) => 0;
}
} else {
if (i+BLOCK_COUNT/2 >= INIT_BLOCKS) {
if (i+BLOCK_COUNT/2 >= FORMAT_BLOCK_COUNT) {
lfs3_emubd_markbad(CFG, i+BLOCK_COUNT/2) => 0;
}
}
@@ -3408,11 +3408,11 @@ code = '''
for (lfs3_size_t i = 0; i < BLOCK_COUNT/2; i++) {
// mark our badblock as bad
if (!MIRROR) {
if (i >= INIT_BLOCKS) {
if (i >= FORMAT_BLOCK_COUNT) {
lfs3_emubd_markbad(CFG, i) => 0;
}
} else {
if (i+BLOCK_COUNT/2 >= INIT_BLOCKS) {
if (i+BLOCK_COUNT/2 >= FORMAT_BLOCK_COUNT) {
lfs3_emubd_markbad(CFG, i+BLOCK_COUNT/2) => 0;
}
}
@@ -4060,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 >= INIT_BLOCKS) {
if (2*i+0 >= FORMAT_BLOCK_COUNT) {
lfs3_emubd_markbad(CFG, 2*i+0) => 0;
}
} else {
if (2*i+1 >= INIT_BLOCKS) {
if (2*i+1 >= FORMAT_BLOCK_COUNT) {
lfs3_emubd_markbad(CFG, 2*i+1) => 0;
}
}
@@ -4179,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 >= INIT_BLOCKS) {
if (2*i+0 >= FORMAT_BLOCK_COUNT) {
lfs3_emubd_markbad(CFG, 2*i+0) => 0;
}
} else {
if (2*i+1 >= INIT_BLOCKS) {
if (2*i+1 >= FORMAT_BLOCK_COUNT) {
lfs3_emubd_markbad(CFG, 2*i+1) => 0;
}
}
@@ -4375,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 >= INIT_BLOCKS) {
if (2*i+0 >= FORMAT_BLOCK_COUNT) {
lfs3_emubd_markbad(CFG, 2*i+0) => 0;
}
} else {
if (2*i+1 >= INIT_BLOCKS) {
if (2*i+1 >= FORMAT_BLOCK_COUNT) {
lfs3_emubd_markbad(CFG, 2*i+1) => 0;
}
}
@@ -4490,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 >= INIT_BLOCKS) {
if (2*i+0 >= FORMAT_BLOCK_COUNT) {
lfs3_emubd_markbad(CFG, 2*i+0) => 0;
}
} else {
if (2*i+1 >= INIT_BLOCKS) {
if (2*i+1 >= FORMAT_BLOCK_COUNT) {
lfs3_emubd_markbad(CFG, 2*i+1) => 0;
}
}
@@ -4748,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 >= INIT_BLOCKS) {
if (2*i+0 >= FORMAT_BLOCK_COUNT) {
lfs3_emubd_markbad(CFG, 2*i+0) => 0;
}
} else {
if (2*i+1 >= INIT_BLOCKS) {
if (2*i+1 >= FORMAT_BLOCK_COUNT) {
lfs3_emubd_markbad(CFG, 2*i+1) => 0;
}
}
@@ -4910,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 >= INIT_BLOCKS) {
if (2*i+0 >= FORMAT_BLOCK_COUNT) {
lfs3_emubd_markbad(CFG, 2*i+0) => 0;
}
} else {
if (2*i+1 >= INIT_BLOCKS) {
if (2*i+1 >= FORMAT_BLOCK_COUNT) {
lfs3_emubd_markbad(CFG, 2*i+1) => 0;
}
}
@@ -5363,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 >= INIT_BLOCKS) {
if (2*i+0 >= FORMAT_BLOCK_COUNT) {
lfs3_emubd_markbad(CFG, 2*i+0) => 0;
}
} else {
if (2*i+1 >= INIT_BLOCKS) {
if (2*i+1 >= FORMAT_BLOCK_COUNT) {
lfs3_emubd_markbad(CFG, 2*i+1) => 0;
}
}