am 280cb6e9: Merge "Zero blocks before BLKDISCARD"
* commit '280cb6e90c3379072d7677101564b23dfb70182c': Zero blocks before BLKDISCARD
This commit is contained in:
@@ -1465,6 +1465,7 @@ pcdout:
|
||||
static int PerformCommandErase(CommandParameters* params) {
|
||||
char* range = NULL;
|
||||
int i;
|
||||
int j;
|
||||
int rc = -1;
|
||||
RangeSet* tgt = NULL;
|
||||
struct stat st;
|
||||
@@ -1491,7 +1492,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;
|
||||
}
|
||||
|
||||
@@ -1500,7 +1501,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
|
||||
|
||||
Reference in New Issue
Block a user