Fixed incorrect calculation of extra space needed in mdir blocks

Despite the comment being correct, the calculation is somehow off by a word,
meaning something must have been missed. Maybe the space for the move-delete
was missed since that was added later to avoid losing move-deletes during
relocations.

This was found with the new exhaustive power-loss searching added to the
test framework with -P2. The exact failure was
test_dirs_many_reentrant:2gg2cb:k4o6. This must be the first test that
ends up with all possible extra state in a single mdir block.
This commit is contained in:
Christopher Haster
2022-11-19 00:44:40 -06:00
parent eba5553314
commit 0b11ce03b7
+13 -4
View File
@@ -1931,11 +1931,20 @@ static int lfs_dir_splittingcompact(lfs_t *lfs, lfs_mdir_t *dir,
return err;
}
// space is complicated, we need room for tail, crc, gstate,
// cleanup delete, and we cap at half a block to give room
// for metadata updates.
// space is complicated, we need room for:
//
// - tail: 4+2*4 = 12 bytes
// - gstate: 4+3*4 = 16 bytes
// - move delete: 4 = 4 bytes
// - crc: 4+4 = 8 bytes
// total = 40 bytes
//
// And we cap at half a block to avoid degenerate cases with
// nearly-full metadata blocks.
//
if (end - split < 0xff
&& size <= lfs_min(lfs->cfg->block_size - 36,
&& size <= lfs_min(
lfs->cfg->block_size - 40,
lfs_alignup(
(lfs->cfg->metadata_max
? lfs->cfg->metadata_max