[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH 6/8] nbd-client: Short-circuit 0-length operations
From: |
Eric Blake |
Subject: |
[Qemu-block] [PATCH 6/8] nbd-client: Short-circuit 0-length operations |
Date: |
Mon, 6 Nov 2017 21:02:34 -0600 |
The NBD spec is being clarified to state that clients should
not send 0-length requests to the server, as the server behavior
is undefined. While such requests are unlikely to occur from
real guest behavior, qemu-io can force the driver to perform them;
avoid any questionable server implementations by short-circuiting
such operations as a no-op success (we are relying on the block
layer for already filtering out things like invalid offset, write
to a read-only volume, and so forth).
Signed-off-by: Eric Blake <address@hidden>
---
block/nbd-client.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/block/nbd-client.c b/block/nbd-client.c
index c35aad59b0..d8ad2ba57c 100644
--- a/block/nbd-client.c
+++ b/block/nbd-client.c
@@ -673,6 +673,9 @@ int nbd_client_co_preadv(BlockDriverState *bs, uint64_t
offset,
assert(bytes <= NBD_MAX_BUFFER_SIZE);
assert(!flags);
+ if (!bytes) {
+ return 0;
+ }
ret = nbd_co_send_request(bs, &request, NULL);
if (ret < 0) {
@@ -705,6 +708,9 @@ int nbd_client_co_pwritev(BlockDriverState *bs, uint64_t
offset,
assert(bytes <= NBD_MAX_BUFFER_SIZE);
+ if (!bytes) {
+ return 0;
+ }
return nbd_co_request(bs, &request, qiov);
}
@@ -731,6 +737,9 @@ int nbd_client_co_pwrite_zeroes(BlockDriverState *bs,
int64_t offset,
request.flags |= NBD_CMD_FLAG_NO_HOLE;
}
+ if (!bytes) {
+ return 0;
+ }
return nbd_co_request(bs, &request, NULL);
}
@@ -759,7 +768,7 @@ int nbd_client_co_pdiscard(BlockDriverState *bs, int64_t
offset, int bytes)
};
assert(!(client->info.flags & NBD_FLAG_READ_ONLY));
- if (!(client->info.flags & NBD_FLAG_SEND_TRIM)) {
+ if (!(client->info.flags & NBD_FLAG_SEND_TRIM) || !bytes) {
return 0;
}
--
2.13.6
- [Qemu-block] [PATCH 0/8] various NBD fixes for 2.11, Eric Blake, 2017/11/06
- [Qemu-block] [PATCH 1/8] nbd-client: Fix error message typos, Eric Blake, 2017/11/06
- [Qemu-block] [PATCH 2/8] nbd/client: Nicer trace of structured reply, Eric Blake, 2017/11/06
- [Qemu-block] [PATCH 3/8] raw: Reflect read-only protocol layer, Eric Blake, 2017/11/06
- [Qemu-block] [PATCH 4/8] nbd-client: Honor server read-only advertisement, Eric Blake, 2017/11/06
- [Qemu-block] [PATCH 5/8] nbd: Fix struct name for structured reads, Eric Blake, 2017/11/06
- [Qemu-block] [PATCH 6/8] nbd-client: Short-circuit 0-length operations,
Eric Blake <=
- [Qemu-block] [PATCH 7/8] nbd-client: Stricter enforcing of structured reply spec, Eric Blake, 2017/11/06
- [Qemu-block] [PATCH 8/8] nbd/server: Fix structured read of length 0, Eric Blake, 2017/11/06