Skip to content

Commit

Permalink
block/backup: deal with zero detection
Browse files Browse the repository at this point in the history
We have detect_zeroes option, so at least for blockdev-backup user
should define it if zero-detection is needed. For drive-backup leave
detection enabled by default but do it through existing option instead
of open-coding.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: John Snow <jsnow@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Message-id: 20190730163251.755248-2-vsementsov@virtuozzo.com
Signed-off-by: John Snow <jsnow@redhat.com>
  • Loading branch information
Vladimir Sementsov-Ogievskiy authored and jnsnow committed Aug 16, 2019
1 parent 590a63d commit 319bd5e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
15 changes: 6 additions & 9 deletions block/backup.c
Expand Up @@ -113,7 +113,10 @@ static int coroutine_fn backup_cow_with_bounce_buffer(BackupBlockJob *job,
BlockBackend *blk = job->common.blk;
int nbytes;
int read_flags = is_write_notifier ? BDRV_REQ_NO_SERIALISING : 0;
int write_flags = job->serialize_target_writes ? BDRV_REQ_SERIALISING : 0;
int write_flags =
(job->serialize_target_writes ? BDRV_REQ_SERIALISING : 0) |
(job->compress ? BDRV_REQ_WRITE_COMPRESSED : 0);


assert(QEMU_IS_ALIGNED(start, job->cluster_size));
bdrv_reset_dirty_bitmap(job->copy_bitmap, start, job->cluster_size);
Expand All @@ -131,14 +134,8 @@ static int coroutine_fn backup_cow_with_bounce_buffer(BackupBlockJob *job,
goto fail;
}

if (buffer_is_zero(*bounce_buffer, nbytes)) {
ret = blk_co_pwrite_zeroes(job->target, start,
nbytes, write_flags | BDRV_REQ_MAY_UNMAP);
} else {
ret = blk_co_pwrite(job->target, start,
nbytes, *bounce_buffer, write_flags |
(job->compress ? BDRV_REQ_WRITE_COMPRESSED : 0));
}
ret = blk_co_pwrite(job->target, start, nbytes, *bounce_buffer,
write_flags);
if (ret < 0) {
trace_backup_do_cow_write_fail(job, start, ret);
if (error_is_read) {
Expand Down
8 changes: 4 additions & 4 deletions blockdev.c
Expand Up @@ -3615,7 +3615,7 @@ static BlockJob *do_drive_backup(DriveBackup *backup, JobTxn *txn,
BlockDriverState *source = NULL;
BlockJob *job = NULL;
AioContext *aio_context;
QDict *options = NULL;
QDict *options;
Error *local_err = NULL;
int flags;
int64_t size;
Expand Down Expand Up @@ -3688,10 +3688,10 @@ static BlockJob *do_drive_backup(DriveBackup *backup, JobTxn *txn,
goto out;
}

options = qdict_new();
qdict_put_str(options, "discard", "unmap");
qdict_put_str(options, "detect-zeroes", "unmap");
if (backup->format) {
if (!options) {
options = qdict_new();
}
qdict_put_str(options, "driver", backup->format);
}

Expand Down

0 comments on commit 319bd5e

Please sign in to comment.