main-loop: use event notifiers

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
aio: provide platform-independent API

This adds to aio.c a platform-independent API based on EventNotifiers, that
can be used by the portable thread pool.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
aio: add Win32 implementation

The Win32 implementation only accepts EventNotifiers, thus a few
drivers are disabled under Windows.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
linux-aio: use event notifiers

Since linux-aio already uses an eventfd, converting it to use the
EventNotifier-based API simplifies the code even though it is not
meant to be portable.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qemu-thread: add QemuSemaphore

The new thread pool will use semaphores instead of condition
variables, because QemuCond does not have qemu_cond_timedwait.
(I also like it more this way).

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
aio: add generic thread-pool facility

Add a generic thread-pool.  The code is roughly based on posix-aio-compat.c,
with some changes, especially the following:

- use QemuSemaphore instead of QemuCond;

- separate the state of the thread from the return code of the worker
function.  The return code is totally opaque for the thread pool;

- do not busy wait when doing cancellation.

A more generic threadpool (but still specific to I/O so that in the future
it can use special scheduling classes or PI mutexes) can have many uses:
it allows more flexibility in raw-posix.c and can more easily be extended
to Win32, and it will also be used to do an msync of the persistent bitmap.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
block: switch posix-aio-compat to threadpool

This is not meant for portability, but to remove code duplication.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
raw: merge posix-aio-compat.c into block/raw-posix.c

Making the qemu_paiocb specific to raw devices will let us access members
of the BDRVRawState arbitrarily.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
raw-posix: rename raw-posix-aio.h, hide unavailable prototypes

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
raw-win32: add emulated AIO support

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
block: support FALLOC_FL_PUNCH_HOLE trimming

Switch from the XFS-specific ioctl to the more generic
FALLOC_FL_PUNCH_HOLE.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
configure: do not look for xfsctl

We are not using it anymore.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
raw: support discard on block devices

Block devices use a ioctl instead of fallocate, so add a separate
implementation.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
block: make discard asynchronous

This is possible now that we can use s->has_discard from the thread pool.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
ide: fix TRIM with empty range entry

ATA-ACS-3 says "If the two byte range length is zero, then the LBA
Range Entry shall be discarded as padding."  iovecs are used as if
they are linearized, so it is incorrect to discard the rest of
this iovec.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
ide: issue discard asynchronously but serialize the pieces

Now that discard can actually issue writes, make it asynchronous.
At the same time, avoid consuming too much memory while it is
running.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
block: clear dirty bitmap when discarding

Note that resetting bits in the dirty bitmap is done _before_ actually
processing the request.  This way, when there are concurrent write and
discard requests, the outcome will always be that the blocks are
marked dirty.  This scenario should never happen, but it is safer
to do it this way.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qed: make write-zeroes bounce buffer smaller than a single cluster

Currently, a write-zeroes operation could allocates memory for the
whole I/O operation if it is not aligned.  This is not necessary,
because only two unaligned clusters could be written.

This makes the write-zeroes operation slower because it proceeds
one cluster at a time, even if all clusters are currently available
and zero.  However, write-zeroes (and discard) are not fast paths.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
block: pass around qiov for write_zeroes operation

Avoid allocating an extra, useless bounce buffer if possible.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
qemu-ga: make names more generic for mount list functions

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