Skip to contentSkip to conversation

RFC: Tweak the NBD_OPT_SET_META_CONTEXT layout

Qemu-devel New Eric Blake 1 participant 4 messages Mar 31, 2018 – Apr 12, 2018

lore
Share & tools
lore

Eric Blake

author
#0 lore raw

As mentioned in earlier email threads, I experimented with an alternative layout to the structs sent across the wire during NBD_OPT_{LIST,SET}_META_CONTEXT, on the grounds that having the namespace and leaf-name combined into one string that requires further parsing on each end is not as nice as having two separate fields. I'm replying to this mail with two RFC patches, one for the NBD spec, and one for the qemu implementation.

If we like the idea, this has to go into qemu 2.12, so we have less than a week. Or, we can ignore the RFC, keep qemu the way it is currently coded, and when it is released, it will be time to promote the NBD extension-blockstatus to current as there will be an existing implementation to be interoperable with.

Note that I intentionally changed the value of NBD_OPT_SET_META_CONTEXT so that the existing Virtuozzo of OPT 10 will not get confused by the new layout (both new server and old client, as well as old server and new client, will merely fail to negotiate block status, and then be unable to use NBD_CMD_BLOCK_STATUS). I didn't bother changing NBD_OPT_LIST_META_CONTEXT, as it looks like the existing Virtuozzo implementation did not use that option as a client.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
author
#1 lore raw

PATCH 1/1 RFC: nbd: Separate namespace from leaf-name for metadata contexts

During implementation of NBD_CMD_BLOCK_STATUS, we found that parsing for the colon that separates namespaces from leaf-names can get awkward. Simplify things slightly by passing the two as separate fields, and noting that since strings are capped to 4k, a 16-bit rather than 32-bit length field is sufficient. On the request (NBD_OPT_{LIST,SET}_META_CONTEXT), the client can send more than one query in a single wire packet, so must include the length of the namespace and leaf per query. On reply (NBD_REP_META_CONTEXT), each context is set as a separate wire packet, and therefore the header length is sufficient to reconstruct the leaf length without having to redundantly send it.

---

As mentioned in the cover letter, this has to go in at the same time as the corresponding NBD patch, and prior to the qemu 2.12 release, if we like it. Or we can ignore it.

 include/block/nbd.h |  9 ++++---
 nbd/client.c        | 72 +++++++++++++++++++++++++++++++++++------------------
 nbd/server.c        | 71 +++++++++++++++++++++++++++++++++-------------------
 nbd/trace-events    |  7 +++---
 4 files changed, 103 insertions(+), 56 deletions(-)
include/block/nbd.h +6 -3
index fcdcd545023..2060c0c666d 100644
@@ -42,9 +42,11 @@ struct NBDOptionReply {
 typedef struct NBDOptionReply NBDOptionReply;
 
 typedef struct NBDOptionReplyMetaContext {
-    NBDOptionReply h; /* h.type = NBD_REP_META_CONTEXT, h.length > 4 */
+    NBDOptionReply h; /* h.type = NBD_REP_META_CONTEXT, h.length > 7 */
     uint32_t context_id;
-    /* meta context name follows */
+    uint16_t namespace_len; /* Must be nonzero */
+    /* namespace follows, length given by namespace_len */
+    /* leaf-name follows, length computed by h.length - 6 - namespace_len */
 } QEMU_PACKED NBDOptionReplyMetaContext;
 
 /* Transmission phase structs
@@ -156,7 +158,8 @@ typedef struct NBDExtent {
 #define NBD_OPT_GO                (7)
 #define NBD_OPT_STRUCTURED_REPLY  (8)
 #define NBD_OPT_LIST_META_CONTEXT (9)
-#define NBD_OPT_SET_META_CONTEXT  (10)
+/* #define NBD_OPT_OLD_META_CONTEXT (10) not in use */
+#define NBD_OPT_SET_META_CONTEXT  (11)
 
 /* Option reply types. */
 #define NBD_REP_ERR(value) ((UINT32_C(1) << 31) | (value))
nbd/client.c +48 -24

128 lines not on this page · raw message

nbd/server.c +45 -26

135 lines not on this page · raw message

nbd/trace-events +4 -3
index cfdbe04b447..585ca7e809d 100644
@@ -10,8 +10,9 @@ nbd_receive_query_exports_start(const char *wantname) "Querying export list for
 nbd_receive_query_exports_success(const char *wantname) "Found desired export name '%s'"
 nbd_receive_starttls_new_client(void) "Setting up TLS"
 nbd_receive_starttls_tls_handshake(void) "Starting TLS handshake"
-nbd_opt_meta_request(const char *context, const char *export) "Requesting to set meta context %s for export %s"
-nbd_opt_meta_reply(const char *context, int id) "Received mapping of context %s to id %d"
+nbd_opt_meta_request(const char *namespace, const char *leaf, const char *export) "Requesting to set meta context %s:%s for export %s"
+nbd_opt_meta_skip(const char *reason) "Could not parse server reply: %s"
+nbd_opt_meta_reply(const char *namespace, const char *leaf, int id) "Received mapping of context %s:%s to id %d"
 nbd_receive_negotiate(void *tlscreds, const char *hostname) "Receiving negotiation tlscreds=%p hostname=%s"
 nbd_receive_negotiate_magic(uint64_t magic) "Magic is 0x%" PRIx64
 nbd_receive_negotiate_server_flags(uint32_t globalflags) "Global flags are 0x%" PRIx32
@@ -49,7 +50,7 @@ nbd_negotiate_handle_starttls_handshake(void) "Starting TLS handshake"
 nbd_negotiate_meta_context(const char *optname, const char *export, int queries) "Client requested %s for export %s, with %d queries"
 nbd_negotiate_meta_query_skip(const char *reason) "Skipping meta query: %s"
 nbd_negotiate_meta_query_parse(const char *query) "Parsed meta query '%s'"
-nbd_negotiate_meta_query_reply(const char *context, unsigned int id) "Replying with meta context '%s' id %d"
+nbd_negotiate_meta_query_reply(const char *namespace, const char *leaf, unsigned int id) "Replying with meta context '%s:%s' id %d"
 nbd_negotiate_options_flags(uint32_t flags) "Received client flags 0x%" PRIx32
 nbd_negotiate_options_check_magic(uint64_t magic) "Checking opts magic 0x%" PRIx64
 nbd_negotiate_options_check_option(uint32_t option, const char *name) "Checking option %" PRIu32 " (%s)"
Signature · 1 line
2.14.3
author
#2 lore raw

PATCH 1/1 RFC: doc: Separate namespace from leaf-name for metadata contexts

In reply to Eric Blake

During implementation of NBD_CMD_BLOCK_STATUS in qemu, it was discovered that parsing for the colon that separates the namespace from the leaf-name can get awkward; a slight tweak to the wire layout produces something a little friendlier to manipulate.

Since NBD strings are capped at 4k each, 16 bits is sufficient for string lengths rather than 32. On the request (in NBD_OPT_LIST_META_CONTEXT and NBD_OPT_SET_META_CONTEXT), the client must send the length of both namespace and leaf-name, as the client is bundling together one or more queries into a single wire transaction. On reply (NBD_REP_META_CONTEXT), each context is sent as a separate wire transaction, and therefore the header length is sufficient to reconstruct the leaf-name length without having to redundantly send that.

Since there is a known implementation of a prior description of experimental block status in the wild (Virtuozzo, which used SET but not LIST), this spec change also bumps the value of NBD_OPT_SET_META_CONTEXT; that way, a mismatch between experimental build and the layout documented here will fail to negotiate meta contexts due to a difference in values, rather than confusing one another with different layout expectations.

---

As mentioned in the cover letter, this has to go in at the same time as the corresponding qemu patch, and prior to the qemu 2.12 release, if we like it. Or we can ignore it.

 doc/proto.md | 78 +++++++++++++++++++++++++++++++++++-------------------------
 1 file changed, 46 insertions(+), 32 deletions(-)
doc/proto.md +46 -32
index 3abcf67..0e00d74 100644
@@ -876,12 +876,13 @@ The reply to the `NBD_CMD_BLOCK_STATUS` request MUST be sent as a
 structured reply; this implies that in order to use metadata querying,
 structured replies MUST be negotiated first.
 
-Metadata contexts are identified by their names. The name MUST
-consist of a namespace, followed by a colon, followed by a leaf-name.
+Metadata contexts are identified by a namespace combined with a leaf-name.
 The namespace must consist entirely of printable non-whitespace
-UTF-8 characters other than colons, and be non-empty. The entire name
-(namespace, colon, and leaf-name) MUST follow the restrictions for
-strings as laid out earlier in this document.
+UTF-8 characters other than colons, and be non-empty. Both the namespace
+and leaf-name MUST follow the restrictions for
+strings as laid out earlier in this document.  For convenience, this
+document describes `namespace:leaf-name` as the name of a metadata
+context, even though the colon is not transmitted over the protocol.
 
 Namespaces MUST be consist of one of the following:
 - `base`, for metadata contexts defined by this document;
@@ -898,11 +899,11 @@ request to the mailing-list. The following additional third-party namespaces
 are currently registered:
 * (none)
 
-Save in respect of the `base:` namespace described below, this specification
+Save in respect of the `base` namespace described below, this specification
 requires no specific semantics of metadata contexts, except that all the
 information they provide MUST be representable within the flags field as
 defined for `NBD_REPLY_TYPE_BLOCK_STATUS`. Likewise, save in respect of
-the `base:` namespace, the syntax of query strings is not specified by this
+the `base` namespace, the syntax of query strings is not specified by this
 document, other than the recommendation that the empty leaf-name makes
 sense as a wildcard for a client query during `NBD_OPT_LIST_META_CONTEXT`,
 but SHOULD NOT select any contexts during `NBD_OPT_SET_META_CONTEXT`.
@@ -911,22 +912,22 @@ Server implementations SHOULD ensure the syntax for query strings they
 support and semantics for resulting metadata context is documented similarly
 to this document.
 
-### The `base:` metadata namespace
+### The `base` metadata namespace
 
-This standard defines exactly one metadata context; it is called
-`base:allocation`, and it provides information on the basic allocation
+This standard defines exactly one namespace, `base`, currently containing
+only one metadata context, `base:allocation`.  It provides information on the basic allocation
 status of extents (that is, whether they are allocated at all in a
 sparse file context).
 
-The query string within the `base:` metadata context can take
+The leaf-name portion of a query against the `base` namespace can take
 one of two forms:
-* `base:` - the server MUST ignore this form during
+* length 0 - the server MUST ignore this form during
   `NBD_OPT_SET_META_CONTEXT`, and MUST support this as a wildcard during
   `NBD_OPT_LIST_META_CONTEXT`, in which case the server's reply will
   contain a response for each supported metadata context within the
-  `base:` namespace (currently just `base:allocation`, although a
+  `base` namespace (currently just `base:allocation`, although a
   future revision of the standard might return multiple contexts); or
-* `base:[leaf-name]` to select `[leaf-name]` as a context leaf-name
+* non-empty string - select a context leaf-name
   that might exist within the `base` namespace.  If a `[leaf-name]`
   requested by the client is not recognized, the server MUST ignore
   it rather than report an error.
@@ -1297,15 +1298,15 @@ of the newstyle negotiation.
       contexts.
     - 32 bits, number of queries
     - Zero or more queries, each being:
-       - 32 bits, length of query.
-       - String, query to list a subset of the available metadata
-         contexts.  The syntax of this query is
-         implementation-defined, except that it MUST start with a
-         namespace and a colon.
+       - 16 bits, length of namespace (MUST be nonzero).
+       - String, namespace to select from.
+       - 16 bits, length of leaf-name (MAY be zero).
+       - String, leaf-name query. The syntax of this query is
+         implementation-defined according to the namespace.
 
-    For details on the query string, see the "Metadata querying"
+    For details on the namespace and query strings, see the "Metadata querying"
     section; note that a namespace may document that a different set
-    of queries are valid for `NBD_OPT_LIST_META_CONTEXT` than for
+    of leaf-name queries are valid for `NBD_OPT_LIST_META_CONTEXT` than for
     `NBD_OPT_SET_META_CONTEXT`, such as when using an empty
     leaf-name for wildcarding.
 
@@ -1313,8 +1314,7 @@ of the newstyle negotiation.
     length that would require reading beyond the original length given
     in the option header), the server MUST fail the request with
     `NBD_REP_ERR_INVALID`.  For requests that are semantically invalid
-    (such as lacking the required colon that delimits the namespace,
-    or using a leaf name that is invalid for a known namespace), the
+    (such as using a leaf name that is invalid for a known namespace), the
     server MAY fail the request with `NBD_REP_ERR_INVALID`.  However,
     the server MUST ignore query strings belonging to an unknown
     namespace.  If none of the query strings find any metadata
@@ -1359,16 +1359,15 @@ of the newstyle negotiation.
     'x-FooBar:') or with a range of values (e.g.
     'x-ModifiedDate:20160310-20161214'). The semantics of
     such a reply are a matter for the definition of the
-    namespace. However each namespace returned MUST begin
-    with the relevant namespace, followed by a colon, and then
-    other UTF-8 characters, with the entire string following the
+    namespace. However each returned context must include the
+    namespace, and the leaf-name must match
     restrictions for strings set out earlier in this
     document.
 
     The metadata context ID in these replies is reserved and SHOULD be
     set to zero; clients MUST disregard it.
 
-* `NBD_OPT_SET_META_CONTEXT` (10)
+* `NBD_OPT_SET_META_CONTEXT` (11)
 
     Change the set of active metadata contexts. Issuing this command
     replaces all previously-set metadata contexts (including when this
@@ -1393,10 +1392,11 @@ of the newstyle negotiation.
       contexts.
     - 32 bits, number of queries
     - Zero or more queries, each being:
-       - 32 bits, length of query
-       - String, query to select metadata contexts. The syntax of this
-         query is implementation-defined, except that it MUST start with a
-         namespace and a colon.
+       - 16 bits, length of namespace (MUST be nonzero).
+       - String, namespace to select from.
+       - 16 bits, length of leaf-name (SHOULD be nonzero).
+       - String, leaf-name query. The syntax of this query is
+         implementation-defined according to the namespace.
 
     If zero queries are sent, the server MUST select no metadata contexts.
 
@@ -1415,6 +1415,17 @@ of the newstyle negotiation.
     context, provided the client then does not attempt to issue
     `NBD_CMD_BLOCK_STATUS` commands.
 
+* Other requests
+
+    Some third-party implementations have experimented with additional
+    options not described in this document. In the interest of
+    interoperability, authors of such implementations SHOULD contact the
+    maintainer of this document, so that these messages can be listed here
+    to avoid conflicting implementations.
+
+    Currently one such message is known: `NBD_OPT_OLD_META_CONTEXT`, with
+    a value of 10, implemented by Virtuozzo.
+
 #### Option reply types
 
 These values are used in the "reply type" field, sent by the server
@@ -1584,7 +1595,10 @@ during option haggling in the fixed newstyle negotiation.
     A description of a metadata context. Data:
 
     - 32 bits, NBD metadata context ID.
-    - String, name of the metadata context. This is not required to be
+    - 16 bits, namespace length (MUST be nonzero)
+    - String, the namespace of the metadata context.
+    - String (length computed from length given in header minus 6 minus
+      the namespace length), the selected metadata leaf-name. This is not required to be
       a human-readable string, but it MUST be valid UTF-8 data.
 
 There are a number of error reply types, all of which are denoted by
Signature · 1 line
2.14.3
author
#3 lore raw

Re: [Qemu-devel] Withdrawn: Tweak the NBD_OPT_SET_META_CONTEXT layout

In reply to Eric Blake
Quoted 8 lines · Eric Blake

As mentioned in earlier email threads, I experimented with an alternative layout to the structs sent across the wire during NBD_OPT_{LIST,SET}_META_CONTEXT, on the grounds that having the namespace and leaf-name combined into one string that requires further parsing on each end is not as nice as having two separate fields.  I'm replying to this mail with two RFC patches, one for the NBD spec, and one for the qemu implementation.

Quoted 5 lines

If we like the idea, this has to go into qemu 2.12, so we have less than a week.  Or, we can ignore the RFC, keep qemu the way it is currently coded, and when it is released, it will be time to promote the NBD extension-blockstatus to current as there will be an existing implementation to be interoperable with.

As I got no comments, and as qemu is now frozen hard at 2.12-rc3, it is officially too late to change the format sent over the wire; qemu's implementation will be the reference implementation, and for nbd.git, I'll be promoting extension-blockstatus to the master branch once qemu 2.12 is officially released.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org