Fixed lfsr_fs_fixorphans not fixing orphans
Turns out things get a bit tricky when mdirs are dropped while iterating
over the mtree.
This was actually broken quite a bit before traversal-related changes,
probably during some mtree refactor, but went unnoticed since no test
actually checked that lfsr_fs_fixorphans did what it said it did.
At least the new test_forphans_cleanup* tests should prevent this from
regressing again in the future.
Code changes:
code stack
before: 35472 2680
after: 35480 (+0.0%) 2680 (+0.0%)
This commit is contained in:
@@ -12752,9 +12752,8 @@ static int lfsr_fs_fixorphans(lfs_t *lfs) {
|
||||
//
|
||||
// note this never takes longer than lfsr_mount
|
||||
//
|
||||
for (lfsr_mid_t mid = 0;
|
||||
mid < lfsr_mtree_weight(lfs);
|
||||
mid += (1 << lfs->mdir_bits)) {
|
||||
lfsr_mid_t mid = 0;
|
||||
while (mid < lfsr_mtree_weight(lfs)) {
|
||||
lfsr_mdir_t mdir;
|
||||
int err = lfsr_mtree_lookup(lfs, mid,
|
||||
&mdir);
|
||||
@@ -12763,10 +12762,16 @@ static int lfsr_fs_fixorphans(lfs_t *lfs) {
|
||||
return err;
|
||||
}
|
||||
|
||||
// clean up orphans
|
||||
err = lfsr_mdir_fixorphans(lfs, &mdir);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
// incremend mid unless we dropped the mdir
|
||||
if (mdir.rbyd.weight > 0) {
|
||||
mid += 1 << lfs->mdir_bits;
|
||||
}
|
||||
}
|
||||
|
||||
// done, no more orphans
|
||||
|
||||
Reference in New Issue
Block a user