qemu-patch-raspberry4/block
Eric Blake 465fe887cc block: Honor BDRV_REQ_FUA during write_zeroes
The block layer has a couple of cases where it can lose
Force Unit Access semantics when writing a large block of
zeroes, such that the request returns before the zeroes
have been guaranteed to land on underlying media.

SCSI does not support FUA during WRITESAME(10/16); FUA is only
supported if it falls back to WRITE(10/16).  But where the
underlying device is new enough to not need a fallback, it
means that any upper layer request with FUA semantics was
silently ignoring BDRV_REQ_FUA.

Conversely, NBD has situations where it can support FUA but not
ZERO_WRITE; when that happens, the generic block layer fallback
to bdrv_driver_pwritev() (or the older bdrv_co_writev() in qemu
2.6) was losing the FUA flag.

The problem of losing flags unrelated to ZERO_WRITE has been
latent in bdrv_co_do_write_zeroes() since commit aa7bfbff, but
back then, it did not matter because there was no FUA flag.  It
became observable when commit 93f5e6d8 paved the way for flags
that can impact correctness, when we should have been using
bdrv_co_writev_flags() with modified flags.  Compare to commit
9eeb6dd, which got flag manipulation right in
bdrv_co_do_zero_pwritev().

Symptoms: I tested with qemu-io with default writethrough cache
(which is supposed to use FUA semantics on every write), and
targetted an NBD client connected to a server that intentionally
did not advertise NBD_FLAG_SEND_FUA.  When doing 'write 0 512',
the NBD client sent two operations (NBD_CMD_WRITE then
NBD_CMD_FLUSH) to get the fallback FUA semantics; but when doing
'write -z 0 512', the NBD client sent only NBD_CMD_WRITE.

The fix is do to a cleanup bdrv_co_flush() at the end of the
operation if any step in the middle relied on a BDS that does
not natively support FUA for that step (note that we don't
need to flush after every operation, if the operation is broken
into chunks based on bounce-buffer sizing).  Each BDS gains a
new flag .supported_zero_flags, which parallels the use of
.supported_write_flags but only when accessing a zero write
operation (the flags MUST be different, because of SCSI having
different semantics based on WRITE vs. WRITESAME; and also
because BDRV_REQ_MAY_UNMAP only makes sense on zero writes).

Also fix some documentation to describe -ENOTSUP semantics,
particularly since iscsi depends on those semantics.

Down the road, we may want to add a driver where its
.bdrv_co_pwritev() honors all three of BDRV_REQ_FUA,
BDRV_REQ_ZERO_WRITE, and BDRV_REQ_MAY_UNMAP, and advertise
this via bs->supported_write_flags for blocks opened by that
driver; such a driver should NOT supply .bdrv_co_write_zeroes
nor .supported_zero_flags.  But none of the drivers touched
in this patch want to do that (the act of writing zeroes is
different enough from normal writes to deserve a second
callback).

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2016-05-12 15:22:09 +02:00
..
accounting.c block: Clean up includes 2016-01-20 13:36:23 +01:00
archipelago.c util: move declarations out of qemu-common.h 2016-03-22 22:20:17 +01:00
backup.c block: Remove bdrv_(set_)enable_write_cache() 2016-03-30 12:16:03 +02:00
blkdebug.c util: move declarations out of qemu-common.h 2016-03-22 22:20:17 +01:00
blkreplay.c replay: introduce block devices record/replay 2016-03-30 12:15:57 +02:00
blkverify.c util: move declarations out of qemu-common.h 2016-03-22 22:20:17 +01:00
block-backend.c block: Kill unused sector-based blk_* functions 2016-05-12 15:22:09 +02:00
bochs.c bochs: Implement .bdrv_co_preadv() interface 2016-05-12 15:22:08 +02:00
cloop.c cloop: Implement .bdrv_co_preadv() interface 2016-05-12 15:22:08 +02:00
commit.c include/qemu/osdep.h: Don't include qapi/error.h 2016-03-22 22:20:15 +01:00
crypto.c block: Allow BDRV_REQ_FUA through blk_pwrite() 2016-05-12 15:22:08 +02:00
curl.c block: always compile-check debug prints 2016-05-12 15:22:08 +02:00
dirty-bitmap.c include/qemu/osdep.h: Don't include qapi/error.h 2016-03-22 22:20:15 +01:00
dmg.c dmg: Implement .bdrv_co_preadv() interface 2016-05-12 15:22:08 +02:00
gluster.c block/gluster: prevent data loss after i/o error 2016-04-19 12:24:59 -04:00
io.c block: Honor BDRV_REQ_FUA during write_zeroes 2016-05-12 15:22:09 +02:00
iscsi.c block: Honor BDRV_REQ_FUA during write_zeroes 2016-05-12 15:22:09 +02:00
linux-aio.c linux-aio: make it more type safe 2016-05-12 15:22:07 +02:00
Makefile.objs replay: introduce block devices record/replay 2016-03-30 12:15:57 +02:00
mirror.c mirror: Workaround for unexpected iohandler events during completion 2016-04-22 16:44:09 +02:00
nbd-client.c block: Make supported_write_flags a per-bds property 2016-05-12 15:22:09 +02:00
nbd-client.h nbd: Support BDRV_REQ_FUA 2016-03-30 12:16:02 +02:00
nbd.c block: Make supported_write_flags a per-bds property 2016-05-12 15:22:09 +02:00
nfs.c block/nfs: add missing #include "qemu/cutils.h" 2016-03-30 16:50:39 -04:00
null.c block/null-{co,aio}: Implement get_block_status() 2016-03-30 12:16:04 +02:00
parallels.c block: Switch blk_*write_zeroes() to byte interface 2016-05-12 15:22:08 +02:00
qapi.c block/qapi: Use blk_enable_write_cache() 2016-03-30 12:16:02 +02:00
qcow.c block: Allow BDRV_REQ_FUA through blk_pwrite() 2016-05-12 15:22:08 +02:00
qcow2-cache.c block: Clean up includes 2016-01-20 13:36:23 +01:00
qcow2-cluster.c include/qemu/osdep.h: Don't include qapi/error.h 2016-03-22 22:20:15 +01:00
qcow2-refcount.c include/qemu/osdep.h: Don't include qapi/error.h 2016-03-22 22:20:15 +01:00
qcow2-snapshot.c util: move declarations out of qemu-common.h 2016-03-22 22:20:17 +01:00
qcow2.c qcow2: improve qcow2_co_write_zeroes() 2016-05-12 15:22:09 +02:00
qcow2.h qcow2: Add function for refcount order amendment 2015-12-18 14:34:43 +01:00
qed-check.c block: Clean up includes 2016-01-20 13:36:23 +01:00
qed-cluster.c block: Clean up includes 2016-01-20 13:36:23 +01:00
qed-gencb.c block: Clean up includes 2016-01-20 13:36:23 +01:00
qed-l2-cache.c block: Clean up includes 2016-01-20 13:36:23 +01:00
qed-table.c block: Clean up includes 2016-01-20 13:36:23 +01:00
qed.c block: Allow BDRV_REQ_FUA through blk_pwrite() 2016-05-12 15:22:08 +02:00
qed.h util: move declarations out of qemu-common.h 2016-03-22 22:20:17 +01:00
quorum.c quorum: Emit QUORUM_REPORT_BAD for reads in fifo mode 2016-03-17 16:43:30 +01:00
raw-aio.h linux-aio: make it more type safe 2016-05-12 15:22:07 +02:00
raw-posix.c block: Honor BDRV_REQ_FUA during write_zeroes 2016-05-12 15:22:09 +02:00
raw-win32.c util: move declarations out of qemu-common.h 2016-03-22 22:20:17 +01:00
raw_bsd.c block: Honor BDRV_REQ_FUA during write_zeroes 2016-05-12 15:22:09 +02:00
rbd.c util: move declarations out of qemu-common.h 2016-03-22 22:20:17 +01:00
sheepdog.c block: Allow BDRV_REQ_FUA through blk_pwrite() 2016-05-12 15:22:08 +02:00
snapshot.c include/qemu/osdep.h: Don't include qapi/error.h 2016-03-22 22:20:15 +01:00
ssh.c include/qemu/osdep.h: Don't include qapi/error.h 2016-03-22 22:20:15 +01:00
stream.c -----BEGIN PGP SIGNATURE----- 2016-03-29 19:54:49 +01:00
throttle-groups.c block: introduce bdrv_no_throttling_begin/end 2016-05-12 15:22:07 +02:00
vdi.c block: Allow BDRV_REQ_FUA through blk_pwrite() 2016-05-12 15:22:08 +02:00
vhdx-endian.c block: Clean up includes 2016-01-20 13:36:23 +01:00
vhdx-log.c include/qemu/osdep.h: Don't include qapi/error.h 2016-03-22 22:20:15 +01:00
vhdx.c block: Allow BDRV_REQ_FUA through blk_pwrite() 2016-05-12 15:22:08 +02:00
vhdx.h block: vhdx - update PAYLOAD_BLOCK_UNMAPPED value to match 1.00 spec 2014-12-12 15:42:22 +00:00
vmdk.c block: Allow BDRV_REQ_FUA through blk_pwrite() 2016-05-12 15:22:08 +02:00
vpc.c block: Allow BDRV_REQ_FUA through blk_pwrite() 2016-05-12 15:22:08 +02:00
vvfat.c vvfat: Implement .bdrv_co_preadv/pwritev interfaces 2016-05-12 15:22:08 +02:00
win32-aio.c block: Clean up includes 2016-01-20 13:36:23 +01:00
write-threshold.c block: Clean up includes 2016-01-20 13:36:23 +01:00