From patchwork Tue Mar 29 20:39:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Bligh X-Patchwork-Id: 8691001 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A25F99F44D for ; Tue, 29 Mar 2016 20:40:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C3F0620374 for ; Tue, 29 Mar 2016 20:40:03 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E313520361 for ; Tue, 29 Mar 2016 20:40:02 +0000 (UTC) Received: from localhost ([::1]:49898 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1al0Qk-0005dP-4y for patchwork-qemu-devel@patchwork.kernel.org; Tue, 29 Mar 2016 16:40:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38129) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1al0Qc-0005dK-R1 for qemu-devel@nongnu.org; Tue, 29 Mar 2016 16:39:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1al0QY-0004ph-Jc for qemu-devel@nongnu.org; Tue, 29 Mar 2016 16:39:54 -0400 Received: from mail.avalus.com ([89.16.176.221]:42555) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1al0QY-0004pd-Bp for qemu-devel@nongnu.org; Tue, 29 Mar 2016 16:39:50 -0400 Received: by mail.avalus.com (Postfix) with ESMTPSA id D8CB0C5608E; Tue, 29 Mar 2016 21:39:47 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=alex.org.uk; s=mail; t=1459283988; bh=RS3UD3aQeDMX9wyCH6pUFXkMzzvBjaCLhZLmz+inqyo=; h=From:To:Cc:Subject:Date; b=W1RWcNsGIjaeqBR1ehWqp5A+QLJfroPqkLqvuSsBGrTPGmS4Hu98fxSPMVkhOb4tm pVtn/LtZuqNfRxNcav5djFixK+J76DQqa115R4+husrFkHDeg4vpxt5TQYfQjySfkx 1z+k+lsBk6cJMeZvsxPHL54PlEIhJ6zph/IIEiEg= From: Alex Bligh To: Eric Blake , Wouter Verhelst , "nbd-general@lists.sourceforge.net" , "qemu-devel@nongnu.org" Date: Tue, 29 Mar 2016 21:39:43 +0100 Message-Id: <1459283983-11890-1-git-send-email-alex@alex.org.uk> X-Mailer: git-send-email 1.9.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 89.16.176.221 Cc: Alex Bligh Subject: [Qemu-devel] [PATCH] Strawman proposal for NBD structured replies X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Here's a strawman for the structured reply section. I haven't covered negotation. Signed-off-by: Alex Bligh --- doc/proto.md | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 111 insertions(+), 3 deletions(-) diff --git a/doc/proto.md b/doc/proto.md index aaae0a2..2ea81b9 100644 --- a/doc/proto.md +++ b/doc/proto.md @@ -195,15 +195,123 @@ C: 64 bits, offset (unsigned) C: 32 bits, length (unsigned) C: (*length* bytes of data if the request is of type `NBD_CMD_WRITE`) -The server replies with: +Replies take one of two forms. They may either be structured replies, +or unstructured replies. The server MUST NOT send structured replies +unless it has negotiated structured replies with the client using +`NBD_OPT_STUCTURED_REPLIES` (??). Subject to that, structured replies +may be sent in response to any command. + +Unstructured replies are problematic for error handling within +`NBD_CMD_READ`, therefore servers SHOULD support structured replies. + +#### Unstructured replies + +In an unstructured reply, the server replies with: S: 32 bits, 0x67446698, magic (`NBD_REPLY_MAGIC`) S: 32 bits, error S: 64 bits, handle S: (*length* bytes of data if the request is of type `NBD_CMD_READ`) -Replies need not be sent in the same order as requests (i.e., requests -may be handled by the server asynchronously). +#### Structured replies + +A structured reply consists of one or more chunks. The server +MUST send exactly one end chunk chunk (identified by +the chunk type `NBD_CHUNKTYPE_END`), and this MUST be the final +chunk within the reply. + +Each chunk consists of the following: + +S: 32 bits, 0x668e33ef, magic (`NBD_STRUCTURED_REPLY_MAGIC`) +S: 32 bits, flags (including type) +S: 64 bits, handle +S: 32 bits, payload length +S: (*length* bytes of payload data) + +The flags have the following meanings: + +* bits 0-7: `NBD_CHUNKTYPE`, an 8 bit unsigned integer +* bits 8-31: reserved (server MUST set these to zero) + +Possible values of `NBD_CHUNKTYPE` are as follows: + +* 0 = `NBD_CHUNKTYPE_END`: the final chunk +* 1 = `NBD_CHUNKTYPE_DATA`: data that has been read +* 2 = `NBD_CHUNKTYPE_ZERO`: data that should be considered zero + +The format of the payload data for each chunk type is as follows: + +##### `NBD_CHUNKTYPE_END` + +S: 32 bits, error code or zero for success +S: 64 bits, offset of error (if any) + +##### `NBD_CHUNKTYPE_DATA` + +S: 64 bits, offset of data +S: (*length-8* bytes of data as read) + +##### `NBD_CHUNKTYPE_ZERO` + +S: 64 bits, offset of data +S: 32 bits, number of zeroes to which this corresponds + + +Commands that return data (currently `NBD_CMD_READ`) therefore MUST +return zero or more chunks each of type `NBD_CHUNKTYPE_DATA` or +`NBD_CHUNKTYPE_ZERO` (collectively 'data chunks') followed +an `NBD_CHUNKTYPE_END`. + +The server MAY split the reply into any number of data +chunks (provided each consists of at least one byte) and +MAY send the data chunks in any order (though the +`NBD_CHUNKTYPE_END` must be the final chunk). This means the +client is responsible for reassembling the chunks in the correct +order. + +The server MUST NOT send chunks that overlap. The server +MUST NOT send chunks whose data exceeds the length +of data requested (for this purpose counting the data +within `NBD_CHUNKTYPE_ZERO` as the number of zero bytes +specified therein). The server MUST, in the case of a successesful +read send exactly the number of bytes requested (whether +represented by `NBD_CHUNKTYPE_DATA` or `NBD_CHUNKTYPE_ZERO`). +The server MUST NOT, in the case of an errored read, send +more than the number of byte requested. + +In order to avoid the burden of reassembly, the client +MAY send `NBD_CMD_FLAG_DF` (??), which instructs the server +not to fragment the reply. If this flag is set, the server +MUST send either zero or one data chunks and an `NBD_CHUNKTYPE_END` +only. Under such circumstances the server MAY error the command +with `ETOOBIG` if the length read exceeds [65,536 bytes | the +negotiated maximum fragment size]. + +If no errors are detected within an operation, the `NBD_CHUNKTYPE_END` +packet MUST contain an error value of zero and an error offset of +zero. + +If the server detects an error during an operation which it +is serving with a structured reply, it MUST complete +the transmission of the current data chunk if transmission +has started (by padding the current chunk with data +which MUST be zero), after which zero or more other +data chunks may be sent, followed by an `NBD_CHUNKTYPE_END` +chunk. The server MAY set the offset within `NBD_CHUNKTYPE_END` +to the offset of the error; if so, this MUST be within the +length requested. + +#### Ordering of replies + +The server MAY send replies in any order; the order of replies +need not correpsond to the order of requests, i.e., requests +may be handled by the server asynchronously). The server MAY +interleave the chunks relating to a single structured reply +with chunks relating to structured replies relating to +a different handle, or with unstructured replies relating +to a different handle. Note that there is a constraint on +the ordering of chunks within structured replies as set out +above. ## Values