Skip to content

Commit

Permalink
nbd/client: Relax handling of large NBD_CMD_BLOCK_STATUS reply
Browse files Browse the repository at this point in the history
The NBD spec is proposing a relaxation of NBD_CMD_BLOCK_STATUS
where a server may have the final extent per context give a
length beyond the original request, if it can easily prove that
subsequent bytes have the same status, on the grounds that a
client can take advantage of this information for fewer block
status requests.  Since qemu 2.12 as a client always sends
NBD_CMD_FLAG_REQ_ONE, and rejects a server that sends extra
length, the upstream NBD spec will probably limit this behavior
to clients that don't request REQ_ONE semantics; but it doesn't
hurt to relax qemu to always be permissive of this server
behavior, even if it continues to use REQ_ONE.

CC: qemu-stable@nongnu.org
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180503222626.1303410-1-eblake@redhat.com>
Reviewed-by:  Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
  • Loading branch information
ebblake committed May 4, 2018
1 parent e475d10 commit acfd8f7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions block/nbd-client.c
Expand Up @@ -259,14 +259,18 @@ static int nbd_parse_blockstatus_payload(NBDClientSession *client,

if (extent->length == 0 ||
(client->info.min_block && !QEMU_IS_ALIGNED(extent->length,
client->info.min_block)) ||
extent->length > orig_length)
{
client->info.min_block))) {
error_setg(errp, "Protocol error: server sent status chunk with "
"invalid length");
return -EINVAL;
}

/* The server is allowed to send us extra information on the final
* extent; just clamp it to the length we requested. */
if (extent->length > orig_length) {
extent->length = orig_length;
}

return 0;
}

Expand Down

0 comments on commit acfd8f7

Please sign in to comment.