[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 07/17] nbd/server: Honor FUA request on NBD_CMD_TRIM
From: |
Eric Blake |
Subject: |
[Qemu-devel] [PULL 07/17] nbd/server: Honor FUA request on NBD_CMD_TRIM |
Date: |
Tue, 13 Mar 2018 12:13:35 -0500 |
The NBD spec states that since trim requests can affect disk contents,
then they should allow for FUA semantics just like writes for ensuring
the disk has settled before returning. As bdrv_[co_]pdiscard() does
not support a flags argument, we can't pass FUA down the block layer
stack, and must therefore emulate it with a flush at the NBD layer.
Note that in all reality, generic well-behaved clients will never
send TRIM+FUA (in fact, qemu as a client never does, and we have no
intention to plumb flags into bdrv_pdiscard). This is because the
NBD protocol states that it is unspecified to READ a trimmed area
(you might read stale data, all zeroes, or even random unrelated
data) without first rewriting it, and even the experimental
BLOCK_STATUS extension states that TRIM need not affect reported
status. Thus, in the general case, a client cannot tell the
difference between an arbitrary server that ignores TRIM, a server
that had a power outage without flushing to disk, and a server that
actually affected the disk before returning; so waiting for the
trim actions to flush to disk makes little sense. However, for a
specific client and server pair, where the client knows the server
treats TRIM'd areas as guaranteed reads-zero, waiting for a flush
makes sense, hence why the protocol documents that FUA is valid on
trim. So, even though the NBD protocol doesn't have a way for the
server to advertise what effects (if any) TRIM will actually have,
and thus any client that relies on specific effects is probably
in error, we can at least support a client that requests TRIM+FUA.
Signed-off-by: Eric Blake <address@hidden>
Message-Id: <address@hidden>
---
nbd/server.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/nbd/server.c b/nbd/server.c
index 83f21c55912..4776009a2d1 100644
--- a/nbd/server.c
+++ b/nbd/server.c
@@ -1638,6 +1638,9 @@ static coroutine_fn int nbd_handle_request(NBDClient
*client,
case NBD_CMD_TRIM:
ret = blk_co_pdiscard(exp->blk, request->from + exp->dev_offset,
request->len);
+ if (ret == 0 && request->flags & NBD_CMD_FLAG_FUA) {
+ ret = blk_co_flush(exp->blk);
+ }
return nbd_send_generic_reply(client, request->handle, ret,
"discard failed", errp);
--
2.14.3
- [Qemu-devel] [PULL 00/17] NBD patches for 2018-03-13 (2.12 softfreeze), Eric Blake, 2018/03/13
- [Qemu-devel] [PULL 04/17] nbd/server: fix: check client->closing before sending reply, Eric Blake, 2018/03/13
- [Qemu-devel] [PULL 08/17] block: let blk_add/remove_aio_context_notifier() tolerate BDS changes, Eric Blake, 2018/03/13
- [Qemu-devel] [PULL 02/17] nbd/server: move nbd_co_send_structured_error up, Eric Blake, 2018/03/13
- [Qemu-devel] [PULL 01/17] iotests: Fix stuck NBD process on 33, Eric Blake, 2018/03/13
- [Qemu-devel] [PULL 13/17] block/nbd-client: save first fatal error in nbd_iter_error, Eric Blake, 2018/03/13
- [Qemu-devel] [PULL 07/17] nbd/server: Honor FUA request on NBD_CMD_TRIM,
Eric Blake <=
- [Qemu-devel] [PULL 14/17] nbd: BLOCK_STATUS for standard get_block_status function: client part, Eric Blake, 2018/03/13
- [Qemu-devel] [PULL 03/17] nbd/server: fix sparse read, Eric Blake, 2018/03/13
- [Qemu-devel] [PULL 06/17] nbd/server: refactor nbd_trip: split out nbd_handle_request, Eric Blake, 2018/03/13
- [Qemu-devel] [PULL 05/17] nbd/server: refactor nbd_trip: cmd_read and generic reply, Eric Blake, 2018/03/13
- [Qemu-devel] [PULL 11/17] nbd/server: add nbd_read_opt_name helper, Eric Blake, 2018/03/13
- [Qemu-devel] [PULL 12/17] nbd: BLOCK_STATUS for standard get_block_status function: server part, Eric Blake, 2018/03/13
- [Qemu-devel] [PULL 10/17] nbd/server: add nbd_opt_invalid helper, Eric Blake, 2018/03/13
- [Qemu-devel] [PULL 17/17] iotests: new test 209 for NBD BLOCK_STATUS, Eric Blake, 2018/03/13
- [Qemu-devel] [PULL 09/17] iotests: add 208 nbd-server + blockdev-snapshot-sync test case, Eric Blake, 2018/03/13
- [Qemu-devel] [PULL 16/17] iotests: add file_path helper, Eric Blake, 2018/03/13