diff options
author | Sami Tolvanen <samitolvanen@google.com> | 2015-06-10 17:07:05 +0100 |
---|---|---|
committer | Sami Tolvanen <samitolvanen@google.com> | 2015-06-10 20:36:02 +0100 |
commit | b65f0272c860771f2105668accd175be1ed95ae9 (patch) | |
tree | db8b60589513c712740d2cc517574d25e98ecb55 /updater | |
parent | 6abd52f62be24981398a99ebefc8717eb2294f97 (diff) | |
download | bootable_recovery-b65f0272c860771f2105668accd175be1ed95ae9.zip bootable_recovery-b65f0272c860771f2105668accd175be1ed95ae9.tar.gz bootable_recovery-b65f0272c860771f2105668accd175be1ed95ae9.tar.bz2 |
Zero blocks before BLKDISCARD
Due to observed BLKDISCARD flakiness, overwrite blocks that we want
to discard with zeros first to avoid later issues with dm-verity if
BLKDISCARD is not successful.
Bug: 20614277
Bug: 20881595
Change-Id: I4f6f2db39db990879ff10468c9db41606497bd6f
(cherry picked from commit a3c75e3ea60d61df93461f5c356befe825c429d2)
Diffstat (limited to 'updater')
-rw-r--r-- | updater/blockimg.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/updater/blockimg.c b/updater/blockimg.c index 7b8721d..e184800 100644 --- a/updater/blockimg.c +++ b/updater/blockimg.c @@ -1404,6 +1404,7 @@ pcdout: static int PerformCommandErase(CommandParameters* params) { char* range = NULL; int i; + int j; int rc = -1; RangeSet* tgt = NULL; struct stat st; @@ -1430,7 +1431,7 @@ static int PerformCommandErase(CommandParameters* params) { range = strtok_r(NULL, " ", ¶ms->cpos); if (range == NULL) { - fprintf(stderr, "missing target blocks for zero\n"); + fprintf(stderr, "missing target blocks for erase\n"); goto pceout; } @@ -1439,7 +1440,22 @@ static int PerformCommandErase(CommandParameters* params) { if (params->canwrite) { fprintf(stderr, " erasing %d blocks\n", tgt->size); + allocate(BLOCKSIZE, ¶ms->buffer, ¶ms->bufsize); + memset(params->buffer, 0, BLOCKSIZE); + for (i = 0; i < tgt->count; ++i) { + // Always zero the blocks first to work around possibly flaky BLKDISCARD + // Bug: 20881595 + if (!check_lseek(params->fd, (off64_t) tgt->pos[i * 2] * BLOCKSIZE, SEEK_SET)) { + goto pceout; + } + + for (j = tgt->pos[i * 2]; j < tgt->pos[i * 2 + 1]; ++j) { + if (write_all(params->fd, params->buffer, BLOCKSIZE) == -1) { + goto pceout; + } + } + // offset in bytes blocks[0] = tgt->pos[i * 2] * (uint64_t) BLOCKSIZE; // length in bytes |