From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: qemu-devel@nongnu.org, qemu-block@nongnu.org
Cc: mreitz@redhat.com, kwolf@redhat.com, den@openvz.org,
vsementsov@virtuozzo.com, pbonzini@redhat.com, eblake@redhat.com,
armbru@redhat.com, jsnow@redhat.com
Subject: [Qemu-devel] [PATCH v2 1/3] nbd/server: add nbd_meta_single_query helper
Date: Fri, 13 Apr 2018 21:13:59 +0300 [thread overview]
Message-ID: <20180413181401.46318-2-vsementsov@virtuozzo.com> (raw)
In-Reply-To: <20180413181401.46318-1-vsementsov@virtuozzo.com>
The helper will be reused for bitmaps namespace.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
nbd/server.c | 40 +++++++++++++++++++++++++++-------------
1 file changed, 27 insertions(+), 13 deletions(-)
diff --git a/nbd/server.c b/nbd/server.c
index cea158913b..c169c11b3e 100644
--- a/nbd/server.c
+++ b/nbd/server.c
@@ -733,44 +733,58 @@ static int nbd_negotiate_send_meta_context(NBDClient *client,
return qio_channel_writev_all(client->ioc, iov, 2, errp) < 0 ? -EIO : 0;
}
-/* nbd_meta_base_query
- *
- * Handle query to 'base' namespace. For now, only base:allocation context is
- * available in it. 'len' is the amount of text remaining to be read from
- * the current name, after the 'base:' portion has been stripped.
+/* Read @len bytes, and set @match to true if they match @pattern, or if @len
+ * is 0 and the client is performing _LIST_. @match is never set to false.
*
* Return -errno on I/O error, 0 if option was completely handled by
* sending a reply about inconsistent lengths, or 1 on success. */
-static int nbd_meta_base_query(NBDClient *client, NBDExportMetaContexts *meta,
- uint32_t len, Error **errp)
+static int nbd_meta_single_query(NBDClient *client, const char *pattern,
+ uint32_t len, bool *match, Error **errp)
{
int ret;
- char query[sizeof("allocation") - 1];
- size_t alen = strlen("allocation");
+ char *query;
if (len == 0) {
if (client->opt == NBD_OPT_LIST_META_CONTEXT) {
- meta->base_allocation = true;
+ *match = true;
}
return 1;
}
- if (len != alen) {
+ if (len != strlen(pattern)) {
return nbd_opt_skip(client, len, errp);
}
+ query = g_malloc(len);
ret = nbd_opt_read(client, query, len, errp);
if (ret <= 0) {
+ g_free(query);
return ret;
}
- if (strncmp(query, "allocation", alen) == 0) {
- meta->base_allocation = true;
+ if (strncmp(query, pattern, len) == 0) {
+ *match = true;
}
+ g_free(query);
return 1;
}
+/* nbd_meta_base_query
+ *
+ * Handle query to 'base' namespace. For now, only base:allocation context is
+ * available in it. 'len' is the amount of text remaining to be read from
+ * the current name, after the 'base:' portion has been stripped.
+ *
+ * Return -errno on I/O error, 0 if option was completely handled by
+ * sending a reply about inconsistent lengths, or 1 on success. */
+static int nbd_meta_base_query(NBDClient *client, NBDExportMetaContexts *meta,
+ uint32_t len, Error **errp)
+{
+ return nbd_meta_single_query(client, "allocation", len,
+ &meta->base_allocation, errp);
+}
+
/* nbd_negotiate_meta_query
*
* Parse namespace name and call corresponding function to parse body of the
--
2.11.1
next prev parent reply other threads:[~2018-04-13 18:14 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-13 18:13 [Qemu-devel] [PATCH v2 0/3] NBD export bitmaps Vladimir Sementsov-Ogievskiy
2018-04-13 18:13 ` Vladimir Sementsov-Ogievskiy [this message]
2018-04-13 18:14 ` [Qemu-devel] [PATCH v2 2/3] nbd/server: implement dirty bitmap export Vladimir Sementsov-Ogievskiy
2018-04-18 14:05 ` Eric Blake
2018-04-19 8:31 ` Vladimir Sementsov-Ogievskiy
2018-04-13 18:14 ` [Qemu-devel] [PATCH v2 3/3] qapi: new qmp command nbd-server-add-bitmap Vladimir Sementsov-Ogievskiy
2018-04-30 21:22 ` [Qemu-devel] [PATCH v2 0/3] NBD export bitmaps Eric Blake
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=20180413181401.46318-2-vsementsov@virtuozzo.com \
--to=vsementsov@virtuozzo.com \
--cc=armbru@redhat.com \
--cc=den@openvz.org \
--cc=eblake@redhat.com \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/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).