From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Kevin Wolf <kwolf@redhat.com>, Max Reitz <mreitz@redhat.com>,
"open list:Network Block Dev..." <qemu-block@nongnu.org>
Subject: [Qemu-devel] [PULL 6/8] nbd-client: Short-circuit 0-length operations
Date: Thu, 9 Nov 2017 10:59:37 -0600 [thread overview]
Message-ID: <20171109165939.23154-7-eblake@redhat.com> (raw)
In-Reply-To: <20171109165939.23154-1-eblake@redhat.com>
The NBD spec was recently clarified to state that clients should
not send 0-length requests to the server, as the server behavior
is undefined [1]. We know that qemu-nbd's behavior is a successful
no-op (once it has filtered for read-only exports), but other NBD
implementations might return an error. To avoid any questionable
server implementations, it is better to just short-circuit such
requests on the client side (we are relying on the block layer to
already filter out requests such as invalid offset, write to a
read-only volume, and so forth); do the short-circuit as late as
possible to still benefit from protections from assertions that
the block layer is not violating our assumptions.
[1] https://github.com/NetworkBlockDevice/nbd/commit/ee926037
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <20171108215703.9295-6-eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
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 daa4392531..0a675d0fab 100644
--- a/block/nbd-client.c
+++ b/block/nbd-client.c
@@ -674,6 +674,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) {
return ret;
@@ -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
next prev parent reply other threads:[~2017-11-09 16:59 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-09 16:59 [Qemu-devel] [PULL 0/8] NBD patches for 2.11-rc1 Eric Blake
2017-11-09 16:59 ` [Qemu-devel] [PULL 1/8] nbd/server: fix nbd_negotiate_handle_info Eric Blake
2017-11-09 16:59 ` [Qemu-devel] [PULL 2/8] nbd-client: Fix error message typos Eric Blake
2017-11-09 16:59 ` [Qemu-devel] [PULL 3/8] nbd-client: Refuse read-only client with BDRV_O_RDWR Eric Blake
2017-12-03 19:01 ` Richard W.M. Jones
2017-11-09 16:59 ` [Qemu-devel] [PULL 4/8] nbd/client: Nicer trace of structured reply Eric Blake
2017-11-09 16:59 ` [Qemu-devel] [PULL 5/8] nbd: Fix struct name for structured reads Eric Blake
2017-11-09 16:59 ` Eric Blake [this message]
2017-11-09 16:59 ` [Qemu-devel] [PULL 7/8] nbd-client: Stricter enforcing of structured reply spec Eric Blake
2017-11-09 16:59 ` [Qemu-devel] [PULL 8/8] nbd/server: Fix structured read of length 0 Eric Blake
2017-11-13 13:53 ` [Qemu-devel] [PULL 0/8] NBD patches for 2.11-rc1 Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171109165939.23154-7-eblake@redhat.com \
--to=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).