From c25b2bf45812736631834138e478e7648714ebd7 Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Wed, 16 Jan 2019 08:03:10 -0800 Subject: [PATCH] build_image: right-sizing at least some spare inode To address problems creating real tiny filesystem placeholders, make sure extra spare inodes margin is greater than 0. For initial estimate we add 4% of total we request at least 8. For second pass estimate we add 0.2% of total we request at least 1. We bumped up the margin for zie on the second pass to 0.3% as the value was too close on one of the builds. Test: build Bug: 122328872 Change-Id: I41707bb6fcc8bbfbdda143a9ce62446cad9c1533 --- tools/releasetools/build_image.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tools/releasetools/build_image.py b/tools/releasetools/build_image.py index 6aaff6bfa5..ad0432d504 100755 --- a/tools/releasetools/build_image.py +++ b/tools/releasetools/build_image.py @@ -76,7 +76,12 @@ def GetInodeUsage(path): cmd = ["find", path, "-print"] output = common.RunAndCheckOutput(cmd, verbose=False) # increase by > 4% as number of files and directories is not whole picture. - return output.count('\n') * 25 // 24 + inodes = output.count('\n') + spare_inodes = inodes * 4 // 100 + min_spare_inodes = 8 + if spare_inodes < min_spare_inodes: + spare_inodes = min_spare_inodes + return inodes + spare_inodes def GetFilesystemCharacteristics(image_path, sparse_image=True): @@ -436,8 +441,8 @@ def BuildImage(in_dir, prop_dict, out_file, target_out=None): size -= free_size size += reserved_size if reserved_size == 0: - # add .2% margin - size = size * 1002 // 1000 + # add .3% margin + size = size * 1003 // 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) @@ -448,8 +453,12 @@ def BuildImage(in_dir, prop_dict, out_file, target_out=None): 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 + # add .2% margin or 1 inode, whichever is greater + spare_inodes = inodes * 2 // 1000 + min_spare_inodes = 1 + if spare_inodes < min_spare_inodes: + spare_inodes = min_spare_inodes + inodes += spare_inodes prop_dict["extfs_inode_count"] = str(inodes) prop_dict["partition_size"] = str(size) logger.info(