Fix some ambiguities in the NBD protocol
cover Fix some ambiguities in the NBD protocol
This patch set attempts to fix some ambiguities in the NBD protocol.
Pavel Borzenkov (3):
NBD proto: forbid TRIM command without negotiation NBD proto: document additional error conditions NBD proto: add "Command flags" section
doc/proto.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
PATCH 1/3 NBD proto: forbid TRIM command without negotiation
From: Pavel Borzenkov <[email protected]>
There is a loophole in the protocol that allows a client to send TRIM request even if support for it wasn't negotiated with the server. State explicitly that the client MUST NOT send such command without prior successful negotiation.
--- doc/proto.md | 3 +++ 1 file changed, 3 insertions(+)
doc/proto.md +3 -0
@@ -471,6 +471,9 @@ The following request types exist: about the contents of the export affected by this command, until overwriting it again with `NBD_CMD_WRITE`. + A client MUST NOT send a trim request unless `NBD_FLAG_SEND_TRIM` + was set in the export flags field. + * Other requests Some third-party implementations may require additional protocol
Signature · 1 line
2.1.4
Re: [Qemu-devel] [PATCH 1/3] NBD proto: forbid TRIM command without negotiation
Quoted 22 lines · Denis V. Lunev
From: Pavel Borzenkov <[email protected]>
There is a loophole in the protocol that allows a client to send TRIM request even if support for it wasn't negotiated with the server. State explicitly that the client MUST NOT send such command without prior successful negotiation.
Signed-off-by Pavel Borzenkov <[email protected]>Reviewed-by Roman Kagan <[email protected]>Signed-off-by Denis V. Lunev <[email protected]>CC Wouter Verhelst <[email protected]>CC Eric Blake <[email protected]>CC Alex Bligh <[email protected]>--- doc/proto.md | 3 +++ 1 file changed, 3 insertions(+)doc/proto.md +0
-0
doc/proto.md The following request types exist: · line 476
Quoted 6 lines
doc/proto.md +3
-0@@ -471,6 +471,9 @@ The following request types exist: about the contents of the export affected by this command, until overwriting it again with `NBD_CMD_WRITE`. + A client MUST NOT send a trim request unless `NBD_FLAG_SEND_TRIM` + was set in the export flags field. +
Do we also want to mention that the server SHOULD fail with EINVAL if the client sends it anyway, and similarly if NBD_CMD_FLUSH was sent without the appropriate export flag (but that the client should not rely on that particular failure)?
But as this is a strict improvement,
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [Nbd] [PATCH 1/3] NBD proto: forbid TRIM command without negotiation
Quoted 26 lines · Eric Blake
Quoted 25 lines · Denis V. Lunev
From: Pavel Borzenkov <[email protected]>
There is a loophole in the protocol that allows a client to send TRIM request even if support for it wasn't negotiated with the server. State explicitly that the client MUST NOT send such command without prior successful negotiation.
Signed-off-by Pavel Borzenkov <[email protected]>Reviewed-by Roman Kagan <[email protected]>Signed-off-by Denis V. Lunev <[email protected]>CC Wouter Verhelst <[email protected]>CC Eric Blake <[email protected]>CC Alex Bligh <[email protected]>--- doc/proto.md | 3 +++ 1 file changed, 3 insertions(+)doc/proto.md +0
-0@@ -471,6 +471,9 @@ The following request types exist: about the contents of the export affected by this command, until overwriting it again with `NBD_CMD_WRITE`.
Quoted 8 lines
doc/proto.md The following request types exist: · line 476
Quoted 3 lines
doc/proto.md +3
-0+ A client MUST NOT send a trim request unless `NBD_FLAG_SEND_TRIM` + was set in the export flags field. +Do we also want to mention that the server SHOULD fail with EINVAL if the client sends it anyway, and similarly if
NBD_CMD_FLUSHwas sent without the appropriate export flag (but that the client should not rely on that particular failure)?
I think the protocol should mention that the server MAY fail with EINVAL, rather than SHOULD. Rationale: the robusness principle -- if you didn't negotiate it, you may end up with a server who doesn't know about the feature; but if it just so happens that the server does know about it even though you didn't negotiate it, there is little harm in it following up on the request.
Quoted 2 lines
But as this is a strict improvement,
Reviewed-by Eric Blake <[email protected]>
Signature · 4 lines
< ron> I mean, the main *practical* problem with C++, is there's like a dozen
people in the world who think they really understand all of its rules,
and pretty much all of them are just lying to themselves too.
-- #debian-devel, OFTC, 2016-02-12Re: [Qemu-devel] [Nbd] [PATCH 1/3] NBD proto: forbid TRIM command without negotiation
Quoted 14 lines · Wouter Verhelst
Quoted 5 lines
Quoted 5 lines
+++
b/doc/proto.mddoc/proto.md +0
-0@@ -471,6 +471,9 @@ The following request types exist: about the contents of the export affected by this command, until overwriting it again with `NBD_CMD_WRITE`.Quoted 8 lines
doc/proto.md The following request types exist: · line 476
Quoted 3 lines
doc/proto.md +3
-0+ A client MUST NOT send a trim request unless `NBD_FLAG_SEND_TRIM` + was set in the export flags field. +Do we also want to mention that the server SHOULD fail with EINVAL if the client sends it anyway, and similarly if
NBD_CMD_FLUSHwas sent without the appropriate export flag (but that the client should not rely on that particular failure)?
Quoted 6 lines
I think the protocol should mention that the server MAY fail with EINVAL, rather than SHOULD. Rationale: the robusness principle -- if you didn't negotiate it, you may end up with a server who doesn't know about the feature; but if it just so happens that the server does know about it even though you didn't negotiate it, there is little harm in it following up on the request.
Good point; furthermore, a server is compliant if it accepts and ignores NBD_CMD_TRIM (as that command is only a hint); which is different from NBD_CMD_FLUSH (which must ensure a barrier).
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 2/3 NBD proto: document additional error conditions
In reply to Denis V. LunevFrom: Pavel Borzenkov <[email protected]>
It is unclear what the behaviour of a server should be if it receives an unknown command. Similar uncertainty exists for command flags.
Make it explicit that the server should return EINVAL in all such cases.
--- doc/proto.md | 7 +++++++ 1 file changed, 7 insertions(+)
doc/proto.md +7 -0
@@ -512,6 +512,13 @@ return `EINVAL` if it receives a read or trim request including one or more sectors beyond the size of the device. It also SHOULD map the `EDQUOT` and `EFBIG` errors to `ENOSPC`. Finally, it SHOULD return `EPERM` if it receives a write or trim request on a read-only export. + +The server SHOULD return `EINVAL` if it receives an unknown command. + +The server SHOULD return `EINVAL` if it receives an unknown command flag. It +also SHOULD return `EINVAL` if it receives a request with a flag not explicitly +documented as applicable to the given request. + Which error to return in any other case is not specified by the NBD protocol.
Signature · 1 line
2.1.4
Re: [Qemu-devel] [PATCH 2/3] NBD proto: document additional error conditions
Quoted 6 lines · Denis V. Lunev
From: Pavel Borzenkov <[email protected]>
It is unclear what the behaviour of a server should be if it receives an unknown command. Similar uncertainty exists for command flags.
Make it explicit that the server should return EINVAL in all such cases.
I'd go one step further and document that for backwards compatibility, clients should not rely on this particular error.
Quoted 16 lines
Signed-off-by Pavel Borzenkov <[email protected]>Reviewed-by Roman Kagan <[email protected]>Signed-off-by Denis V. Lunev <[email protected]>CC Wouter Verhelst <[email protected]>CC Eric Blake <[email protected]>CC Alex Bligh <[email protected]>--- doc/proto.md | 7 +++++++ 1 file changed, 7 insertions(+)doc/proto.md +0
-0
doc/proto.md return `EINVAL` if it receives a read or trim request including one or · line 520
Quoted 9 lines
doc/proto.md +6
-0@@ -512,6 +512,13 @@ return `EINVAL` if it receives a read or trim request including one or more sectors beyond the size of the device. It also SHOULD map the `EDQUOT` and `EFBIG` errors to `ENOSPC`. Finally, it SHOULD return `EPERM` if it receives a write or trim request on a read-only export. + +The server SHOULD return `EINVAL` if it receives an unknown command. + +The server SHOULD return `EINVAL` if it receives an unknown command flag. It +also SHOULD return `EINVAL` if it receives a request with a flag not explicitly +documented as applicable to the given request.
In other words, while this is good for the server side, we have proven that existing server implementations did not follow this, and therefore it would probably be good to add a sentence along the lines of:
However, clients should not rely on this particular error, as some historical servers silently ignored invalid commands or flags.
But as what you have proposed is a strict improvement,
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 3/3 NBD proto: add "Command flags" section
In reply to Denis V. LunevFrom: Pavel Borzenkov <[email protected]>
Add separate "Command flags" section to make it clear which flags are currently defined by the protocol.
--- doc/proto.md | 10 ++++++++++ 1 file changed, 10 insertions(+)
doc/proto.md +10 -0
@@ -485,6 +485,16 @@ The following request types exist: Currently one such message is known: `NBD_CMD_CACHE`, with type set to 5, implemented by xnbd. +#### Command flags + +This field of 16 bits is sent by the client with every request and provides +additional information to the server to execute the command. Refer to +aforementioned "Request types" section for information about the flags +supported by particular commands. + +- bit 0, `NBD_CMD_FLAG_FUA`; should be set to 1 if the client requires + "Force Unit Access" mode of operation + #### Error values The error values are used for the error field in the reply message.
Signature · 1 line
2.1.4
Re: [Qemu-devel] [PATCH 3/3] NBD proto: add "Command flags" section
Quoted 20 lines · Denis V. Lunev
From: Pavel Borzenkov <[email protected]>
Add separate "Command flags" section to make it clear which flags are currently defined by the protocol.
Signed-off-by Pavel Borzenkov <[email protected]>Reviewed-by Roman Kagan <[email protected]>Signed-off-by Denis V. Lunev <[email protected]>CC Wouter Verhelst <[email protected]>CC Eric Blake <[email protected]>CC Alex Bligh <[email protected]>--- doc/proto.md | 10 ++++++++++ 1 file changed, 10 insertions(+)doc/proto.md +0
-0
doc/proto.md The following request types exist: · line 492
Quoted 8 lines
doc/proto.md +5
-0@@ -485,6 +485,16 @@ The following request types exist: Currently one such message is known: `NBD_CMD_CACHE`, with type set to 5, implemented by xnbd. +#### Command flags + +This field of 16 bits is sent by the client with every request and provides +additional information to the server to execute the command. Refer to +aforementioned "Request types" section for information about the flags
Maybe:
s/aforementioned "Request types" section/the "Request types" section above/
doc/proto.md The following request types exist: · line 496
Quoted 4 lines
doc/proto.md +4
-0+supported by particular commands. + +- bit 0, `NBD_CMD_FLAG_FUA`; should be set to 1 if the client requires + "Force Unit Access" mode of operation
Trailing dot? Should you also mention which command(s) it is valid with? (NBD_CMD_WRITE for now, until other extension commands are added)
It might also be worth mentioning that the flag should not be sent
unless export flags included NBD_FLAG_SEND_FUA.
Quoted 5 lines
doc/proto.md +1
-0+ #### Error values The error values are used for the error field in the reply message.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [Nbd] [PATCH 3/3] NBD proto: add "Command flags" section
Quoted 34 lines · Eric Blake
Quoted 20 lines · Denis V. Lunev
From: Pavel Borzenkov <[email protected]>
Add separate "Command flags" section to make it clear which flags are currently defined by the protocol.
Signed-off-by Pavel Borzenkov <[email protected]>Reviewed-by Roman Kagan <[email protected]>Signed-off-by Denis V. Lunev <[email protected]>CC Wouter Verhelst <[email protected]>CC Eric Blake <[email protected]>CC Alex Bligh <[email protected]>--- doc/proto.md | 10 ++++++++++ 1 file changed, 10 insertions(+)doc/proto.md +0
-0doc/proto.md The following request types exist: · line 492
Quoted 8 lines
doc/proto.md +5
-0@@ -485,6 +485,16 @@ The following request types exist: Currently one such message is known: `NBD_CMD_CACHE`, with type set to 5, implemented by xnbd. +#### Command flags + +This field of 16 bits is sent by the client with every request and provides +additional information to the server to execute the command. Refer to +aforementioned "Request types" section for information about the flagsMaybe:
s/aforementioned "Request types" section/the "Request types" section above/
Quoted 14 lines
doc/proto.md The following request types exist: · line 496
Quoted 4 lines
doc/proto.md +4
-0+supported by particular commands. + +- bit 0, `NBD_CMD_FLAG_FUA`; should be set to 1 if the client requires + "Force Unit Access" mode of operationTrailing dot? Should you also mention which command(s) it is valid with? (
NBD_CMD_WRITEfor now, until other extension commands are added)
It might also be worth mentioning that the flag should not be sent
unless export flags includedNBD_FLAG_SEND_FUA.Quoted 4 lines
doc/proto.md +1
-0+ #### Error values The error values are used for the error field in the reply message.
Yes, I agree that these are all (typographical, but still) improvements. If you can update with that, I'll happily apply that.
Regards,
Signature · 4 lines
< ron> I mean, the main *practical* problem with C++, is there's like a dozen
people in the world who think they really understand all of its rules,
and pretty much all of them are just lying to themselves too.
-- #debian-devel, OFTC, 2016-02-12Re: [Qemu-devel] [PATCH 3/3] NBD proto: add "Command flags" section
In reply to Denis V. LunevQuoted 20 lines · Denis V. Lunev
From: Pavel Borzenkov <[email protected]>
Add separate "Command flags" section to make it clear which flags are currently defined by the protocol.
Signed-off-by Pavel Borzenkov <[email protected]>Reviewed-by Roman Kagan <[email protected]>Signed-off-by Denis V. Lunev <[email protected]>CC Wouter Verhelst <[email protected]>CC Eric Blake <[email protected]>CC Alex Bligh <[email protected]>--- doc/proto.md | 10 ++++++++++ 1 file changed, 10 insertions(+)doc/proto.md +0
-0
doc/proto.md The following request types exist: · line 489
Quoted 5 lines
doc/proto.md +2
-0@@ -485,6 +485,16 @@ The following request types exist: Currently one such message is known: `NBD_CMD_CACHE`, with type set to 5, implemented by xnbd. +#### Command flags +
I think that this new content would belong better as a subsection under '#### Flag Fields', alongside the mention of all other flags. I'm going to propose a v2 of this patch with that alternate position, for comparison.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 3/3] NBD proto: add "Command flags" section
Quoted 24 lines · Eric Blake
Quoted 23 lines · Denis V. Lunev
From: Pavel Borzenkov <[email protected]>
Add separate "Command flags" section to make it clear which flags are currently defined by the protocol.
Signed-off-by Pavel Borzenkov <[email protected]>Reviewed-by Roman Kagan <[email protected]>Signed-off-by Denis V. Lunev <[email protected]>CC Wouter Verhelst <[email protected]>CC Eric Blake <[email protected]>CC Alex Bligh <[email protected]>--- doc/proto.md | 10 ++++++++++ 1 file changed, 10 insertions(+)doc/proto.md +0
-0@@ -485,6 +485,16 @@ The following request types exist: Currently one such message is known: `NBD_CMD_CACHE`, with type set to 5, implemented by xnbd.
Quoted 6 lines
doc/proto.md The following request types exist: · line 489
Quoted 2 lines
doc/proto.md +2
-0+#### Command flags +I think that this new content would belong better as a subsection under '#### Flag Fields', alongside the mention of all other flags. I'm going to propose a v2 of this patch with that alternate position, for comparison.
Hmm, maybe not. I just looked again, and '#### Flag fields' is a subsection of '### Handshake phase', while you are correct that command flags belong to '### Transmission phase'.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org