From: Eric Blake <eblake@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
qemu-devel@nongnu.org, qemu-block@nongnu.org
Cc: armbru@redhat.com, mreitz@redhat.com, kwolf@redhat.com,
pbonzini@redhat.com, den@openvz.org,
nbd list <nbd@other.debian.org>
Subject: Re: [Qemu-devel] [PATCH 1/4] nbd/server: refactor nbd_negotiate_meta_query for several namespaces
Date: Wed, 21 Mar 2018 09:56:36 -0500 [thread overview]
Message-ID: <af833096-cbc3-24db-0cf0-a446f231c5fd@redhat.com> (raw)
In-Reply-To: <20180321121940.39426-2-vsementsov@virtuozzo.com>
[adding NBD list]
On 03/21/2018 07:19 AM, Vladimir Sementsov-Ogievskiy wrote:
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
> nbd/server.c | 60 +++++++++++++++++++++++++++++++++++++++++++-----------------
> 1 file changed, 43 insertions(+), 17 deletions(-)
> +struct {
> + const char *ns;
> + int (*func)(NBDClient *, NBDExportMetaContexts *, uint32_t, Error **);
> +} meta_namespace_handlers[] = {
> + /* namespaces should go in non-decreasing order by name length */
> + {.ns = "base:", .func = nbd_meta_base_query},
> +};
> +
> @@ -787,9 +793,12 @@ static int nbd_negotiate_meta_query(NBDClient *client,
> NBDExportMetaContexts *meta, Error **errp)
> {
> int ret;
> - char query[sizeof("base:") - 1];
> - size_t baselen = strlen("base:");
> + int i;
> uint32_t len;
> + int bytes_done = 0;
> + char *query;
> + int nb_ns = sizeof(meta_namespace_handlers) /
> + sizeof(meta_namespace_handlers[0]);
Use the ARRAY_SIZE() macro here.
> + query = g_malloc(strlen(meta_namespace_handlers[nb_ns - 1].ns));
So this sizes a buffer according to the largest namespace we expect to
handle,...
>
> - len -= baselen;
> - ret = nbd_opt_read(client, query, baselen, errp);
> - if (ret <= 0) {
> - return ret;
> - }
> - if (strncmp(query, "base:", baselen) != 0) {
> - return nbd_opt_skip(client, len, errp);
> + for (i = 0; i < nb_ns; i++) {
> + const char *ns = meta_namespace_handlers[i].ns;
> + int ns_len = strlen(ns);
> + int diff_len = strlen(ns) - bytes_done;
> +
> + assert(diff_len >= 0);
> +
> + if (diff_len > 0) {
> + if (len < diff_len) {
> + ret = nbd_opt_skip(client, len, errp);
> + goto out;
> + }
> +
> + len -= diff_len;
> + ret = nbd_opt_read(client, query + bytes_done, diff_len, errp);
> + if (ret <= 0) {
> + goto out;
> + }
> + }
> +
> + if (!strncmp(query, ns, ns_len)) {
> + ret = meta_namespace_handlers[i].func(client, meta, len, errp);
> + goto out;
> + }
...then you do multiple iterative reads as you step through the list.
You know, if you encounter a ':' at any point in the iterative reads,
you don't have to continue through the rest of the handlers (the query
belongs to a short-named namespace we didn't recognize).
Is it any smarter to just blindly do a single read of MIN(querylen,
maxlen), then strchr() for ':' (if not found, it's not a namespace we
recognize), and then look up if the name matches, at which point we then
read the rest of the query and refactor the namespace handler to be
passed the already-parsed leafname, rather than having to parse the
leafname off the wire in the handler?
I'm STILL wondering if the NBD spec should specify namespace and
leafname as separate fields rather than requiring the server to parse
for ':'. We have only a couple of weeks before the qemu 2.12 release
cements in place an implementation of the BLOCK_STATUS extension. And
we've already discussed that if we make a change, we have to consider
using a different constant for NBD_OPT_SET_META_CONTEXT to play nicely
with the existing Virtuozzo implementation that currently matches what
is slated to land in qemu 2.12 if no further qemu patches are submitted.
Is it worth me proposing a doc change to demonstrate what the
difference would look like, along with corresponding qemu changes to
match, to decide if including it in 2.12 is worth it?
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
next prev parent reply other threads:[~2018-03-21 14:56 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-21 12:19 [Qemu-devel] [PATCH for-2.13 0/4] NBD export bitmaps Vladimir Sementsov-Ogievskiy
2018-03-21 12:19 ` [Qemu-devel] [PATCH 1/4] nbd/server: refactor nbd_negotiate_meta_query for several namespaces Vladimir Sementsov-Ogievskiy
2018-03-21 14:56 ` Eric Blake [this message]
2018-03-21 17:20 ` Wouter Verhelst
2018-03-22 14:35 ` Vladimir Sementsov-Ogievskiy
2018-03-21 12:19 ` [Qemu-devel] [PATCH 2/4] nbd/server: add nbd_meta_single_query helper Vladimir Sementsov-Ogievskiy
2018-03-21 15:05 ` Eric Blake
2018-04-13 17:44 ` Vladimir Sementsov-Ogievskiy
2018-04-13 21:06 ` [Qemu-devel] [Qemu-block] " John Snow
2018-04-16 11:22 ` Vladimir Sementsov-Ogievskiy
2018-03-21 12:19 ` [Qemu-devel] [PATCH 3/4] nbd/server: implement dirty bitmap export Vladimir Sementsov-Ogievskiy
2018-03-21 16:57 ` Eric Blake
2018-03-22 15:26 ` Vladimir Sementsov-Ogievskiy
2018-03-28 10:08 ` Vladimir Sementsov-Ogievskiy
2018-03-22 15:32 ` Vladimir Sementsov-Ogievskiy
2018-03-21 12:19 ` [Qemu-devel] [PATCH 4/4] qapi: new qmp command nbd-server-add-bitmap Vladimir Sementsov-Ogievskiy
2018-03-21 17:33 ` Eric Blake
2018-03-22 15:43 ` Vladimir Sementsov-Ogievskiy
2018-03-22 16:19 ` Eric Blake
2018-03-22 16:45 ` Vladimir Sementsov-Ogievskiy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=af833096-cbc3-24db-0cf0-a446f231c5fd@redhat.com \
--to=eblake@redhat.com \
--cc=armbru@redhat.com \
--cc=den@openvz.org \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=nbd@other.debian.org \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=vsementsov@virtuozzo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).