156
155
will have to reply with a flag field of its own before the extra flags
157
156
are sent. This is not yet implemented.
158
Fixed 'new' style handshake
159
---------------------------
161
Unfortunately, due to a mistake on my end, the server would immediately
162
close the connection when it saw an option it did not understand, rather
163
than signalling this fact to the client, which would've allowed it to
164
retry; and replies from the server were not structured either, which
165
meant that if the server were to send something the client did not
166
understand, it would have to abort negotiation as well.
168
To fix these two issues, the handshake has been extended once more:
170
- The server will set bit 0 of its first set of reserved flags, to
171
signal that it supports this version of the protocol.
172
- The client should reply with bit 0 set in its reserved field too,
173
though its side of the protocol does not change incompatibly.
174
- The client may now send other options to the server as appropriate, in
175
the generic format for sending an option as described above.
176
- The server will reply to any option apart from NBD_OPT_EXPORT_NAME
177
with reply packets in the following format:
179
S: 64 bits, 0x3e889045565a9 (magic number for replies)
180
S: 32 bits, the option as sent by the client to which this is a reply
182
S: 32 bits, denoting reply type (e.g., NBD_REP_ACK to denote successful
183
completion, or NBD_REP_ERR_UNSUP to denote use of an option not known
185
S: 32 bits, length of the reply. This may be zero for some replies, in
186
which case the next field is not sent
187
S: any data as required by the reply (e.g., an export name in the case
190
As there is no unique number for client requests, clients who want to
191
differentiate between answers to two instances of the same option during
192
any negotiation must make sure they've seen the answer to an outstanding
193
request before sending the next one of the same type.
198
This section describes the meaning of constants (other than magic
199
numbers) in the protocol handshake.
162
bit 0 - NBD_FLAG_HAS_FLAGS
165
bit 1 - NBD_FLAG_READ_ONLY
166
should be set to 1 if the export is read-only
168
bit 2 - NBD_FLAG_SEND_FLUSH
169
should be set to 1 if the server supports NBD_CMD_FLUSH commands
171
bit 3 - NBD_FLAG_SEND_FUA
172
should be set to 1 if the server supports the NBD_CMD_FLAG_FUA flag
174
bit 4 - NBD_FLAG_ROTATIONAL
175
should be set to 1 to let the client schedule I/O accesses as for a
178
bit 5 - NBD_FLAG_SEND_TRIM
179
should be set to 1 if the server supports NBD_CMD_TRIM commands
204
* Per-export (16 bits, sent after option haggling, or immediately after
205
the global flag field in oldstyle negotiation):
207
bit 0 - NBD_FLAG_HAS_FLAGS
210
bit 1 - NBD_FLAG_READ_ONLY
211
should be set to 1 if the export is read-only
213
bit 2 - NBD_FLAG_SEND_FLUSH
214
should be set to 1 if the server supports NBD_CMD_FLUSH commands
216
bit 3 - NBD_FLAG_SEND_FUA
217
should be set to 1 if the server supports the NBD_CMD_FLAG_FUA flag
219
bit 4 - NBD_FLAG_ROTATIONAL
220
should be set to 1 to let the client schedule I/O accesses as for a
223
bit 5 - NBD_FLAG_SEND_TRIM
224
should be set to 1 if the server supports NBD_CMD_TRIM commands
226
* Global flag bits (16 bits, after initial connection):
228
bit 0 - NBD_FLAG_FIXED_NEWSTYLE
229
should be set by servers that support the fixed newstyle protocol
231
* Client (after initial connection and after receiving flags from
234
bit 0 - NBD_FLAG_C_FIXED_NEWSTYLE
235
Should be set by clients that support the fixed newstyle protocol.
236
Servers may choose to honour fixed newstyle from clients that didn't
237
set this bit, but relying on this isn't recommended.
242
* NBD_OPT_EXPORT_NAME (1)
243
Choose the export which the client would like to use, and end option
244
haggling. Data: name of the export, free-form UTF8 text (subject to
245
limitations by server implementation). If the chosen export does not
246
exist, the server closes the connection.
249
Returns a number of NBD_REP_SERVER replies, one for each export,
250
followed by an NBD_REP_ACK.
253
Abort negotiation and close the connection. Optional.
259
Will be sent by the server when it accepts the option, or when sending
260
data related to the option (in the case of NBD_OPT_LIST) has finished.
264
A description of an export. Data:
265
- 32 bits, length of name
266
- Name of the export, as expected by NBD_OPT_EXPORT_NAME
267
- If length of name < (length of reply as sent in the reply packet
268
header - 4), then the rest of the data contains some undefined
269
implementation-specific details about the export. This is not
270
currently implemented, but future versions of nbd-server may send
271
along some details about the export. If the client did not
272
explicitly request otherwise, these details are defined to be UTF-8
273
encoded data suitable for direct display to a human being.
275
There are a number of error reply types, all of which are denoted by
276
having bit 31 set. All error replies may have some data set, in which
277
case that data is an error message suitable for display to the user.
279
* NBD_REP_ERR_UNSUP (2^31 + 1)
280
The option sent by the client is unknown by this server
281
implementation (e.g., because the server is too old, or from another
284
* NBD_REP_ERR_POLICY (2^31 + 2)
285
The option sent by the client is known by this server and
286
syntactically valid, but server-side policy forbids the server to
287
allow the option (e.g., the client sent NBD_OPT_LIST but server
288
configuration has that disabled)
290
* NBD_REP_ERR_INVALID (2^31 + 3)
291
The option sent by the client is know by this server, but was
292
determined by the server to be syntactically invalid. For instance,
293
the client sent an NBD_OPT_LIST with nonzero data length.
295
* NBD_REP_ERR_PLATFORM (2^31 + 4)
296
The option sent by the client is not supported on the platform on
297
which the server is running. Not currently used.