[haiku-commits] Change in haiku[master]: bfs: don't allocate more than the maximum in an AllocationGroup

  • From: Gerrit <review@xxxxxxxxxxxxxxxxxxx>
  • To: waddlesplash <waddlesplash@xxxxxxxxx>, haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 27 Jun 2022 18:05:17 +0000

From Jérôme Duval <jerome.duval@xxxxxxxxx>:

Jérôme Duval has uploaded this change for review. ( 
https://review.haiku-os.org/c/haiku/+/5417 ;)


Change subject: bfs: don't allocate more than the maximum in an AllocationGroup
......................................................................

bfs: don't allocate more than the maximum in an AllocationGroup

* The reserved blocks could exhaust the first allocation group, so iterate as 
much as needed.
* fix #11753
---
M src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp
1 file changed, 10 insertions(+), 4 deletions(-)



  git pull ssh://git.haiku-os.org:22/haiku refs/changes/17/5417/1

diff --git a/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp 
b/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp
index af0bdaa..949e9a6 100644
--- a/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp
+++ b/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp
@@ -597,10 +597,16 @@

        // reserve the boot block, the log area, and the block bitmap itself
        uint32 reservedBlocks = fVolume->Log().Start() + 
fVolume->Log().Length();
-
-       if (fGroups[0].Allocate(transaction, 0, reservedBlocks) < B_OK) {
-               FATAL(("could not allocate reserved space for block 
bitmap/log!\n"));
-               return B_ERROR;
+       uint32 blocksToReserve = reservedBlocks;
+       for (int32 i = 0; i < fNumGroups; i++) {
+               int32 reservedBlocksInGroup = min_c(blocksToReserve, numBits);
+               if (fGroups[i].Allocate(transaction, 0, reservedBlocksInGroup) 
< B_OK) {
+                       FATAL(("could not allocate reserved space for block 
bitmap/log!\n"));
+                       return B_ERROR;
+               }
+               blocksToReserve -= reservedBlocksInGroup;
+               if (blocksToReserve == 0)
+                       break;
        }
        fVolume->SuperBlock().used_blocks
                = HOST_ENDIAN_TO_BFS_INT64(reservedBlocks);

--
To view, visit https://review.haiku-os.org/c/haiku/+/5417
To unsubscribe, or for help writing mail filters, visit 
https://review.haiku-os.org/settings

Gerrit-Project: haiku
Gerrit-Branch: master
Gerrit-Change-Id: Ib1d7f87946f7b96dfcade8f5778a14065d965f6b
Gerrit-Change-Number: 5417
Gerrit-PatchSet: 1
Gerrit-Owner: Jérôme Duval <jerome.duval@xxxxxxxxx>
Gerrit-MessageType: newchange

Other related posts:

  • » [haiku-commits] Change in haiku[master]: bfs: don't allocate more than the maximum in an AllocationGroup - Gerrit