dlcservice: check image size
It is unexpected the generated DLC image is larger than the
pre-allocated size of the backup file. Our build system should be able
to catch this at build time and warn developers accordingly.
So we verify the generated DLC image size is at least the size of the
preallocated size specified by DLC_PREALLOC_BLOCKS in DLC ebuild file.
BUG=chromium:990949
TEST=emerge-$BOARD dummy-dlc
Change-Id: I88660c06a511aedd059ee6e78818d0f91d6995fb
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/1739746
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Nicolas Norvez <norvez@chromium.org>
Tested-by: Xiaochu Liu <xiaochu@chromium.org>
Commit-Queue: Xiaochu Liu <xiaochu@chromium.org>
diff --git a/scripts/build_dlc.py b/scripts/build_dlc.py
index 5adaf60..1f68663 100644
--- a/scripts/build_dlc.py
+++ b/scripts/build_dlc.py
@@ -234,6 +234,23 @@
else:
raise ValueError('Wrong fs type: %s used:' % self.fs_type)
+ self.VerifyImageSize(os.path.getsize(self.dest_image))
+
+ def VerifyImageSize(self, image_bytes):
+ """Verify the image can fit to the reserved file."""
+ preallocated_bytes = self.pre_allocated_blocks * self._BLOCK_SIZE
+ # Verifies the actual size of the DLC image is NOT smaller than the
+ # preallocated space.
+ if preallocated_bytes < image_bytes:
+ raise ValueError(
+ 'The DLC_PREALLOC_BLOCKS (%s) value set in DLC ebuild resulted in a '
+ 'max size of DLC_PREALLOC_BLOCKS * 4K (%s) bytes the DLC image is '
+ 'allowed to occupy. The value is smaller than the actual image size '
+ '(%s) required. Increase DLC_PREALLOC_BLOCKS in your ebuild to at '
+ 'least %d.' % (
+ self.pre_allocated_blocks, preallocated_bytes, image_bytes,
+ image_bytes // self._BLOCK_SIZE))
+
def GetImageloaderJsonContent(self, image_hash, table_hash, blocks):
"""Return the content of imageloader.json file.