If the guest tries to write data that results on the allocation of a
new cluster, instead of writing the guest data first and then the data
from the COW regions, write everything together using one single I/O
operation.
This can improve the write performance by 25% or more, depending on
several factors such as the media type, the cluster size and the I/O
request size.
Signed-off-by: Alberto Garcia <address@hidden>
---
block/qcow2-cluster.c | 34 ++++++++++++++++++++++--------
block/qcow2.c | 58
++++++++++++++++++++++++++++++++++++++++++---------
block/qcow2.h | 7 +++++++
3 files changed, 80 insertions(+), 19 deletions(-)
- /* And now we can write everything */
- qemu_iovec_reset(&qiov);
- qemu_iovec_add(&qiov, start_buffer, start->nb_bytes);
- ret = do_perform_cow_write(bs, m->alloc_offset, start->offset, &qiov);
- if (ret < 0) {
- goto fail;
+ /* And now we can write everything. If we have the guest data we
+ * can write everything in one single operation */
+ if (m->data_qiov) {
+ qemu_iovec_reset(&qiov);
+ qemu_iovec_add(&qiov, start_buffer, start->nb_bytes);
+ qemu_iovec_concat(&qiov, m->data_qiov, 0, data_bytes);
+ qemu_iovec_add(&qiov, end_buffer, end->nb_bytes);