nbd/server: Fix structured read of length 0
commitef8c887ee01a4e4c8c5c28c86ea5b45162c51bcd
authorEric Blake <eblake@redhat.com>
Wed, 8 Nov 2017 21:57:03 +0000 (8 15:57 -0600)
committerEric Blake <eblake@redhat.com>
Thu, 9 Nov 2017 16:25:11 +0000 (9 10:25 -0600)
treee6eaa1e3a1825c56e6da57211be6d4b61d59a8e3
parentb4176cb314995ad225d6c2b531568801feb04f3f
nbd/server: Fix structured read of length 0

The NBD spec was recently clarified to state that a read of length 0
should not be attempted by a compliant client; but that a server must
still handle it correctly in an unspecified manner (that is, either
a successful no-op or an error reply, but not a crash) [1].  However,
it also implies that NBD_REPLY_TYPE_OFFSET_DATA must have a non-zero
payload length, but our existing code was replying with a chunk
that a picky client could reject as invalid because it was missing
a payload (our own client implementation was recently patched to be
that picky, after first fixing it to not send 0-length requests).

We are already doing successful no-ops for 0-length writes and for
non-structured reads; so for consistency, we want structured reply
reads to also be a no-op.  The easiest way to do this is to return
a NBD_REPLY_TYPE_NONE chunk; this is best done via a new helper
function (especially since future patches for other structured
replies may benefit from using the same helper).

[1] https://github.com/NetworkBlockDevice/nbd/commit/ee926037

Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <20171108215703.9295-8-eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
nbd/server.c
nbd/trace-events