Fix ext4 size estimates

Currently, EXT4 image building is done in a 2 pass fashion:

First pass: build ext4 image with small margin/headroom, check the
number of block used in the output image

Second pass: Build ext4 image again with an estimated block count from
first pass

The two pass implementation is done to keep image size at a
minimum. Recently some failures in first pass invocation is observed due
to image being undersized. Since we will reduce the image size in 2nd
pass, it's OK to increase the image size estimate during first pass. Add
a headroom 10% of total file size to fix build failures.

Test: cherry pick r.android.com/q/topic:%22aosp_cf_system_x86_64%22 and
m aosp_cf_system_x86_64

Bug: 321003625
Change-Id: I254310c67a08b98b05d2c858d4ab59a48112a07b
This commit is contained in:
Kelvin Zhang
2024-01-24 12:39:36 -08:00
parent ebb0bd4b81
commit 158a5ebbc9

View File

@@ -260,7 +260,7 @@ def CalculateSizeAndReserved(prop_dict, size):
if fs_type.startswith("ext4") and partition_headroom > reserved_size:
reserved_size = partition_headroom
return size + reserved_size
return int(size * 1.1) + reserved_size
def BuildImageMkfs(in_dir, prop_dict, out_file, target_out, fs_config):
@@ -636,7 +636,7 @@ def BuildImage(in_dir, prop_dict, out_file, target_out=None):
size = verity_image_builder.CalculateDynamicPartitionSize(size)
prop_dict["partition_size"] = str(size)
logger.info(
"Allocating %d MB for %s.", size // BYTES_IN_MB, out_file)
"Allocating %d MB for %s", size // BYTES_IN_MB, out_file)
prop_dict["image_size"] = prop_dict["partition_size"]
@@ -979,7 +979,11 @@ def main(argv):
parser.add_argument("target_out",
help="the path to $(TARGET_OUT). Certain tools will use this to look through multiple staging "
"directories for fs config files.")
parser.add_argument("-v", action="store_true",
help="Enable verbose logging", dest="verbose")
args = parser.parse_args()
if args.verbose:
OPTIONS.verbose = True
common.InitLogging()