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
This commit is contained in:
Mark Salyzyn
2019-01-10 08:36:34 -08:00
parent c777eaa779
commit 60a716fe8c

View File

@@ -428,16 +428,21 @@ def BuildImage(in_dir, prop_dict, out_file, target_out=None):
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(