Преглед на файлове

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.
Christopher Haster преди 3 години
родител
ревизия
0b11ce03b7
променени са 1 файла, в които са добавени 13 реда и са изтрити 4 реда
  1. 13 4
      lfs.c

+ 13 - 4
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