Skip to content

Commit

Permalink
Improve backwards compatibility.
Browse files Browse the repository at this point in the history
While writing the protocol document, we decided that a server should
always send a payload, even when an error occurred. Only it turned out
that this was not in line with what existing implementations did.

Since
- It seems to make more sense to not send invalid data to a client when
  we know it to be invalid, and
- this is what current implementations do at any rate,

change the spec to say that servers MUST NOT send payload on read error,
and change the implementation to match.
  • Loading branch information
yoe committed Jun 15, 2016
1 parent 06a94f3 commit e6c6fb3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 3 additions & 6 deletions doc/proto.md
Expand Up @@ -887,12 +887,9 @@ The following request types exist:
of data, read from *offset* bytes into the file, unless an error
condition has occurred.

If an error occurs, the server SHOULD set the appropriate error
code in the error field. The server MUST then either initiate
a hard disconnect, or send *length* bytes of data (these bytes MAY be
invalid, in which case they SHOULD be zero); this is true even if
the error is `EINVAL` for bad flags detected before even
attempting to read.
If an error occurs, the server SHOULD set the appropriate error code
in the error field. The server MAY then initiate a hard disconnect.
If it chooses not to, it MUST NOT send any payload for this request.

If an error occurs while reading after the server has already sent
out the reply header with an error field set to zero (i.e.,
Expand Down
4 changes: 3 additions & 1 deletion nbd-server.c
Expand Up @@ -1466,7 +1466,9 @@ static void handle_read(CLIENT* client, struct nbd_request* req) {
}
pthread_mutex_lock(&(client->lock));
writeit(client->net, &rep, sizeof rep);
writeit(client->net, buf, req->len);
if(!rep.error) {
writeit(client->net, buf, req->len);
}
pthread_mutex_unlock(&(client->lock));
free(buf);
}
Expand Down

0 comments on commit e6c6fb3

Please sign in to comment.