diff options
author | Kevin Wolf <kwolf@redhat.com> | 2012-03-20 15:12:58 +0100 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2012-04-20 15:57:30 +0200 |
commit | 621f058940ea9f1ef3d8774ef3203544f1228df1 (patch) | |
tree | bb1d8a76f9d7d737502e6daf68c143420454e3bc /block/qcow2.c | |
parent | ab3a32ad5ea841c313e5f9c5f0d4ec02a8e9ddfc (diff) | |
download | qemu-621f058940ea9f1ef3d8774ef3203544f1228df1.zip qemu-621f058940ea9f1ef3d8774ef3203544f1228df1.tar.gz qemu-621f058940ea9f1ef3d8774ef3203544f1228df1.tar.bz2 |
qcow2: Zero write support
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block/qcow2.c')
-rw-r--r-- | block/qcow2.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/block/qcow2.c b/block/qcow2.c index 41b195d..ad46c03 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1281,6 +1281,26 @@ static int qcow2_make_empty(BlockDriverState *bs) return 0; } +static coroutine_fn int qcow2_co_write_zeroes(BlockDriverState *bs, + int64_t sector_num, int nb_sectors) +{ + int ret; + BDRVQcowState *s = bs->opaque; + + /* Emulate misaligned zero writes */ + if (sector_num % s->cluster_sectors || nb_sectors % s->cluster_sectors) { + return -ENOTSUP; + } + + /* Whatever is left can use real zero clusters */ + qemu_co_mutex_lock(&s->lock); + ret = qcow2_zero_clusters(bs, sector_num << BDRV_SECTOR_BITS, + nb_sectors); + qemu_co_mutex_unlock(&s->lock); + + return ret; +} + static coroutine_fn int qcow2_co_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors) { @@ -1558,6 +1578,7 @@ static BlockDriver bdrv_qcow2 = { .bdrv_co_writev = qcow2_co_writev, .bdrv_co_flush_to_os = qcow2_co_flush_to_os, + .bdrv_co_write_zeroes = qcow2_co_write_zeroes, .bdrv_co_discard = qcow2_co_discard, .bdrv_truncate = qcow2_truncate, .bdrv_write_compressed = qcow2_write_compressed, |