raw-posix: support discard on more filesystems

Linux 2.6.38 introduced the filesystem independent interface to
deallocate part of a file. As of Linux 3.7, btrfs, ext4, ocfs2,
tmpfs and xfs support it.

Signed-off-by: Kusanagi Kouichi <slash@ac.auone-net.jp>
raw-posix: remember whether discard failed

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>
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>
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>