From a2c0ca6f55fbf6cbb5540dea9783f22d99aca528 Mon Sep 17 00:00:00 2001 From: Pavel Butsykin Date: Fri, 22 Jul 2016 11:17:44 +0300 Subject: [PATCH] qcow2: cleanup qcow2_co_pwritev_compressed to avoid the recursion Now that the function uses a vector instead of a buffer, there is no need to use recursive code. Signed-off-by: Pavel Butsykin Reviewed-by: Stefan Hajnoczi Signed-off-by: Denis V. Lunev CC: Jeff Cody CC: Markus Armbruster CC: Eric Blake CC: John Snow CC: Stefan Hajnoczi CC: Kevin Wolf Signed-off-by: Kevin Wolf --- block/qcow2.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 1cbaa8f030..adf451491f 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2554,27 +2554,17 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, uint64_t offset, return bdrv_truncate(bs->file->bs, cluster_offset); } - if (bytes != s->cluster_size) { - ret = -EINVAL; - - /* Zero-pad last write if image size is not cluster aligned */ - if (offset + bytes == bs->total_sectors << BDRV_SECTOR_BITS && - bytes < s->cluster_size) - { - uint8_t *pad_buf = qemu_blockalign(bs, s->cluster_size); - memset(pad_buf, 0, s->cluster_size); - qemu_iovec_to_buf(qiov, 0, pad_buf, s->cluster_size); - iov = (struct iovec) { - .iov_base = pad_buf, - .iov_len = s->cluster_size, - }; - qemu_iovec_init_external(&hd_qiov, &iov, 1); - ret = qcow2_co_pwritev_compressed(bs, offset, bytes, &hd_qiov); - qemu_vfree(pad_buf); - } - return ret; - } buf = qemu_blockalign(bs, s->cluster_size); + if (bytes != s->cluster_size) { + if (bytes > s->cluster_size || + offset + bytes != bs->total_sectors << BDRV_SECTOR_BITS) + { + qemu_vfree(buf); + return -EINVAL; + } + /* Zero-pad last write if image size is not cluster aligned */ + memset(buf + bytes, 0, s->cluster_size - bytes); + } qemu_iovec_to_buf(qiov, 0, buf, s->cluster_size); out_buf = g_malloc(s->cluster_size);