From nobody Sun Oct 26 00:03:06 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521636159041422.4374151740142; Wed, 21 Mar 2018 05:42:39 -0700 (PDT) Received: from localhost ([::1]:54637 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eyd4c-00030B-1Z for importer@patchew.org; Wed, 21 Mar 2018 08:42:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54981) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eycib-00061e-3y for qemu-devel@nongnu.org; Wed, 21 Mar 2018 08:19:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eyciW-0005ic-VE for qemu-devel@nongnu.org; Wed, 21 Mar 2018 08:19:49 -0400 Received: from relay.sw.ru ([185.231.240.75]:54940) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eyciW-0005hl-NH; Wed, 21 Mar 2018 08:19:44 -0400 Received: from msk-vpn.virtuozzo.com ([195.214.232.6] helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.90_1) (envelope-from ) id 1eyciT-00064u-Em; Wed, 21 Mar 2018 15:19:41 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Wed, 21 Mar 2018 15:19:38 +0300 Message-Id: <20180321121940.39426-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20180321121940.39426-1-vsementsov@virtuozzo.com> References: <20180321121940.39426-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 2/4] nbd/server: add nbd_meta_single_query helper X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, armbru@redhat.com, mreitz@redhat.com, den@openvz.org, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The helper will be reused for bitmaps namespace. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- nbd/server.c | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index b830997114..8fe53ffd4b 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -733,44 +733,59 @@ static int nbd_negotiate_send_meta_context(NBDClient = *client, return qio_channel_writev_all(client->ioc, iov, 2, errp) < 0 ? -EIO : = 0; } =20 -/* 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 check matching to the pattern. + * @match is set to true on empty query for _LIST_ and for query matching = the + * @pattern. @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 *m= eta, - 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 =3D strlen("allocation"); + char *query; =20 if (len =3D=3D 0) { if (client->opt =3D=3D NBD_OPT_LIST_META_CONTEXT) { - meta->base_allocation =3D true; + *match =3D true; } return 1; } =20 - if (len !=3D alen) { + if (len !=3D strlen(pattern)) { return nbd_opt_skip(client, len, errp); } =20 + query =3D g_malloc(len); ret =3D nbd_opt_read(client, query, len, errp); if (ret <=3D 0) { + g_free(query); return ret; } =20 - if (strncmp(query, "allocation", alen) =3D=3D 0) { - meta->base_allocation =3D true; + if (strncmp(query, pattern, len) =3D=3D 0) { + *match =3D true; } + g_free(query); =20 return 1; } =20 +/* 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 *m= eta, + uint32_t len, Error **errp) +{ + return nbd_meta_single_query(client, "allocation", len, + &meta->base_allocation, errp); +} + struct { const char *ns; int (*func)(NBDClient *, NBDExportMetaContexts *, uint32_t, Error **); --=20 2.11.1