qemu-file: add flush operation

Allow QEMUFiles to specify a function to execute when qemu_fflush is
called.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
savevm: only buffer data for savevm, or while writing devices data

Stop buffering data during migration.  To do this, introduce a new kind
of QEMUFile that adds buffering to a lower-level QEMUFile.  All other
files will send a qemu_put_buffer to the OS or block layer immediately.

The buffering can be transparent (i.e. closing the QEMUFileBuffered also
closes the lower-level file) or manual.

Saving device data is still buffered because it consists of a lot of small
fields; to free the layered QEMUFile without touching the underlying one,
the manual mode is used (close = false in qemu_fopen_buffer).  The transparent
kind is used by savevm, which also uses buffering when writing RAM (because
I'm not sure how QCOW2 likes many unaligned writes).

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Add HAS_SEND_MSG macro

Signed-off-by: Orit Wasserman <owasserm@redhat.com>
Allow using iov_send without the use of sendmsg (even if it supported).

This will be used by live migration code for backward compatibility as
using sendmsg requires the receiver to use recvmsg.

Signed-off-by: Orit Wasserman <owasserm@redhat.com>
Use iov_send_no_sendmsg to send buffer to destination

Send one buffer at a time.

Signed-off-by: Orit Wasserman <owasserm@redhat.com>
Allocate buffer to allow batching of writes

Use a list to keep all allocated buffers, the buffers
will be free after they are sent.
First step in batching iovecs.

Signed-off-by: Orit Wasserman <owasserm@redhat.com>
Add structure to store several iovec to send them later together

Signed-off-by: Orit Wasserman <owasserm@redhat.com>
Add qemu_put_buffer_no_copy

This allows to do copyless put buffer, currently only for
QemuSocketFile.

Signed-off-by: Orit Wasserman <owasserm@redhat.com>
Batching of several iovecs

Currently up to 64 iovecs.

Signed-off-by: Orit Wasserman <owasserm@redhat.com>
qemu-file: add flush operation

Allow QEMUFiles to specify a function to execute when qemu_fflush is
called.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
More optimized qemu_put_be64/32/16

Use cpu_put_be64/32/16wu and put a single buffer per call.

Signed-off-by: Orit Wasserman <owasserm@redhat.com>