build_image: right-sizing add .2% margin for space and inodes
To address flakiness in image creation, add a .2% margin of safety
for both inodes and space for ext filesystems.
Test: build
Bug: 122328872
Change-Id: I6665bd6fe642291b825dba58dfd09cc55628230f
diff --git a/tools/releasetools/build_image.py b/tools/releasetools/build_image.py
index f516309..29d3633 100755
--- a/tools/releasetools/build_image.py
+++ b/tools/releasetools/build_image.py
@@ -428,16 +428,21 @@
else:
size -= free_size
size += reserved_size
+ if reserved_size == 0:
+ # add .2% margin
+ size = size * 1002 // 1000
+ # Use a minimum size, otherwise we will fail to calculate an AVB footer
+ # or fail to construct an ext4 image.
+ size = max(size, 256 * 1024)
if block_size <= 4096:
size = common.RoundUpTo4K(size)
else:
size = ((size + block_size - 1) // block_size) * block_size
- # Use a minimum size, otherwise we will fail to calculate an AVB footer
- # or fail to construct an ext4 image.
- size = max(size, 256 * 1024)
extfs_inode_count = prop_dict["extfs_inode_count"]
inodes = int(fs_dict.get("Inode count", extfs_inode_count))
inodes -= int(fs_dict.get("Free inodes", "0"))
+ # add .2% margin
+ inodes = inodes * 1002 // 1000
prop_dict["extfs_inode_count"] = str(inodes)
prop_dict["partition_size"] = str(size)
logger.info(