diff options
author | Tao Bao <tbao@google.com> | 2015-05-21 14:09:49 -0700 |
---|---|---|
committer | Tao Bao <tbao@google.com> | 2015-08-26 15:00:38 -0700 |
commit | d47d8e14880132c42a75f41c8041851797c75e35 (patch) | |
tree | f7c8323bce043082d95f80f05eb0382e5ee855bc /tools/releasetools/blockimgdiff.py | |
parent | 8a1fa15844e0ad73d3b327ff567012e485e7896d (diff) | |
download | build-d47d8e14880132c42a75f41c8041851797c75e35.zip build-d47d8e14880132c42a75f41c8041851797c75e35.tar.gz build-d47d8e14880132c42a75f41c8041851797c75e35.tar.bz2 |
Assert the stash size when generating OTAs.
With block-based OTA v2 and v3, it requires stash space on the /cache
partition to back up blocks during an update. We need to ensure that
it doesn't exceed the partition size. Since there might be other files
on /cache as well, we use cache_size * threshold as the maximum allowed
size. The threshold defaults to 0.8, which can be overridden by command
line option '--stash_threshold'.
Change-Id: Ieee5d373c9bfb2ea401d85ca8a3adb491579de76
(cherry picked from commit 23ac4042128e47f6fe1ef176e7cb96f907d8e149)
Diffstat (limited to 'tools/releasetools/blockimgdiff.py')
-rw-r--r-- | tools/releasetools/blockimgdiff.py | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/tools/releasetools/blockimgdiff.py b/tools/releasetools/blockimgdiff.py index 6ed9ca2..a007f81 100644 --- a/tools/releasetools/blockimgdiff.py +++ b/tools/releasetools/blockimgdiff.py @@ -16,6 +16,7 @@ from __future__ import print_function from collections import deque, OrderedDict from hashlib import sha1 +import common import heapq import itertools import multiprocessing @@ -460,9 +461,20 @@ class BlockImageDiff(object): if free_string: out.append("".join(free_string)) - # sanity check: abort if we're going to need more than 512 MB if - # stash space - assert max_stashed_blocks * self.tgt.blocksize < (512 << 20) + if self.version >= 2: + # Sanity check: abort if we're going to need more stash space than + # the allowed size (cache_size * threshold). There are two purposes + # of having a threshold here. a) Part of the cache may have been + # occupied by some recovery logs. b) It will buy us some time to deal + # with the oversize issue. + cache_size = common.OPTIONS.cache_size + stash_threshold = common.OPTIONS.stash_threshold + max_allowed = cache_size * stash_threshold + assert max_stashed_blocks * self.tgt.blocksize < max_allowed, \ + 'Stash size %d (%d * %d) exceeds the limit %d (%d * %.2f)' % ( + max_stashed_blocks * self.tgt.blocksize, max_stashed_blocks, + self.tgt.blocksize, max_allowed, cache_size, + stash_threshold) # Zero out extended blocks as a workaround for bug 20881595. if self.tgt.extended: @@ -489,8 +501,11 @@ class BlockImageDiff(object): f.write(i) if self.version >= 2: - print("max stashed blocks: %d (%d bytes)\n" % ( - max_stashed_blocks, max_stashed_blocks * self.tgt.blocksize)) + max_stashed_size = max_stashed_blocks * self.tgt.blocksize + max_allowed = common.OPTIONS.cache_size * common.OPTIONS.stash_threshold + print("max stashed blocks: %d (%d bytes), limit: %d bytes (%.2f%%)\n" % ( + max_stashed_blocks, max_stashed_size, max_allowed, + max_stashed_size * 100.0 / max_allowed)) def ComputePatches(self, prefix): print("Reticulating splines...") |