Skip to content

Commit

Permalink
Server: explain why it's OK to disconnect in case of any read error
Browse files Browse the repository at this point in the history
Signed-off-by: Gabor Igloi <gabor.igloi@citrix.com>
  • Loading branch information
gaborigloi committed Oct 6, 2017
1 parent b91a424 commit deaa220
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,15 @@ let serve t (type t) ?(read_only=false) block (b:t) =
end
>>= loop
| { ty = Command.Read; from; len; handle } ->
(* It is okay to disconnect here in case of errors. The NBD protocol
documentation says about NBD_CMD_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., signalling no
error), the server MUST immediately initiate a hard disconnect; it
MUST NOT send any further data to the client." *)
if Int64.(rem from (of_int info.Block.sector_size)) <> 0L || Int64.(rem (of_int32 len) (of_int info.Block.sector_size) <> 0L)
then error t handle `EINVAL
else begin
Expand All @@ -249,12 +258,6 @@ let serve t (type t) ?(read_only=false) block (b:t) =
Block.read b Int64.(div offset (of_int info.Block.sector_size)) [ subblock ]
>>= function
| `Error e ->
(* The NBD protocol documentation says about NBD_CMD_READ:
"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.,
signalling no error), the server MUST immediately initiate a
hard disconnect; it MUST NOT send any further data to the
client." *)
Lwt.fail_with (Printf.sprintf "Partial failure during a Block.read: %s; terminating the session" (Block_error_printer.to_string e))
| `Ok () ->
t.channel.write subblock
Expand Down

0 comments on commit deaa220

Please sign in to comment.