Skip to content

Commit 11b036c

Browse files
committed
Prevented unnecessary superblock rewrites if old version in superblock chain
Because multiple, out-of-date superblocks can exist in our superblock chain, we need to be careful to make sure newer superblock entries override older superblock entries. If we see an older on-disk minor version in the superblock chain, we were correctly overriding the on-disk minor version, but we were also leaving the "needs superblock" bit set in our consistency state. This isn't a hard-error, but would lead to a superblock rewrite every mount. The rewrite would make no progress, as the out-of-date version is effectively immutable at this point, and just waste prog cycles. This should fix that by clearing the "needs superblock" bit if we see a newer on-disk minor version.
1 parent 25ee90f commit 11b036c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lfs.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4469,17 +4469,19 @@ static int lfs_mount_(lfs_t *lfs, const struct lfs_config *cfg) {
44694469
// found older minor version? set an in-device only bit in the
44704470
// gstate so we know we need to rewrite the superblock before
44714471
// the first write
4472+
bool needssuperblock = false;
44724473
if (minor_version < lfs_fs_disk_version_minor(lfs)) {
44734474
LFS_DEBUG("Found older minor version "
44744475
"v%"PRIu16".%"PRIu16" < v%"PRIu16".%"PRIu16,
44754476
major_version,
44764477
minor_version,
44774478
lfs_fs_disk_version_major(lfs),
44784479
lfs_fs_disk_version_minor(lfs));
4479-
// note this bit is reserved on disk, so fetching more gstate
4480-
// will not interfere here
4481-
lfs_fs_prepsuperblock(lfs, true);
4480+
needssuperblock = true;
44824481
}
4482+
// note this bit is reserved on disk, so fetching more gstate
4483+
// will not interfere here
4484+
lfs_fs_prepsuperblock(lfs, needssuperblock);
44834485

44844486
// check superblock configuration
44854487
if (superblock.name_max) {

0 commit comments

Comments
 (0)