提交 a2c0ca6f 编写于 作者: P Pavel Butsykin 提交者: Kevin Wolf

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: NPavel Butsykin <pbutsykin@virtuozzo.com>
Reviewed-by: NStefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: NDenis V. Lunev <den@openvz.org>
CC: Jeff Cody <jcody@redhat.com>
CC: Markus Armbruster <armbru@redhat.com>
CC: Eric Blake <eblake@redhat.com>
CC: John Snow <jsnow@redhat.com>
CC: Stefan Hajnoczi <stefanha@redhat.com>
CC: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: NKevin Wolf <kwolf@redhat.com>
上级 fcccefc5
......@@ -2554,27 +2554,17 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, uint64_t offset,
return bdrv_truncate(bs->file->bs, cluster_offset);
}
buf = qemu_blockalign(bs, s->cluster_size);
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)
if (bytes > s->cluster_size ||
offset + bytes != bs->total_sectors << BDRV_SECTOR_BITS)
{
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);
qemu_vfree(buf);
return -EINVAL;
}
return ret;
/* Zero-pad last write if image size is not cluster aligned */
memset(buf + bytes, 0, s->cluster_size - bytes);
}
buf = qemu_blockalign(bs, s->cluster_size);
qemu_iovec_to_buf(qiov, 0, buf, s->cluster_size);
out_buf = g_malloc(s->cluster_size);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册