From 8a263fb6c5219364908a35101321d604ac639a45 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Fri, 24 May 2024 02:15:12 -0500 Subject: [PATCH] Allowed mdir overcompaction if we run out of space This should allow mdir commits that would normally trigger a relocation to continue if lfsr_mdir_alloc__ return LFS_ERR_NOSPC, though at least with a logged warning. This seems preferable to the alternative: locking up the filesystem. Though this doesn't have tests yet, so take it with a grain of salt... Code changes minimal: code stack before: 33470 2640 after: 33474 (+0.0%) 2640 (+0.0%) --- lfs.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lfs.c b/lfs.c index d06200ee..16399f3f 100644 --- a/lfs.c +++ b/lfs.c @@ -5931,7 +5931,17 @@ static int lfsr_mdir_swap__(lfs_t *lfs, lfsr_mdir_t *mdir_, // decide if we need to relocate if (!force && lfsr_rev_needsrelocation(lfs, rev)) { // alloc a new mdir - return lfsr_mdir_alloc__(lfs, mdir_, mdir->mid); + err = lfsr_mdir_alloc__(lfs, mdir_, mdir->mid); + if (err != LFS_ERR_NOSPC) { + return err; + } + + // no more blocks? wear-leveling falls apart here, but + // we can not relocate + LFS_WARN("Overcompacting mdir %"PRId32" " + "0x{%"PRIx32",%"PRIx32"}", + mdir->mid >> lfs->mdir_bits, + mdir->rbyd.blocks[0], mdir->rbyd.blocks[1]); } // swap our blocks