From 0b11ce03b7ded49a878f155d49bb3ca9aed2f0a4 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Sat, 19 Nov 2022 00:44:40 -0600 Subject: [PATCH] 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. --- lfs.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lfs.c b/lfs.c index 6099bae9..af460394 100644 --- a/lfs.c +++ b/lfs.c @@ -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