From nobody Sun Oct 5 19:25:55 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602209360; cv=none; d=zohomail.com; s=zohoarc; b=PABoGqCtVaP4KOT5d2395wGwOQaYK/diaDxVdUTWdGBmsdoxu20EsVg5TAt+8KiFomM44NLCUDjOuNVx2/rIvjkK3mUQokON5rI5Aee8Hzs7uLVnAn2/pGob/XR9f2VvBFaGy5bqDwXqg8gPezDGrJhn/qZkgMkDI1G4kSCr1GI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602209360; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=T8wFYhrz/v4NI8FMXE3LWRphbgaidPX9Bd0i6MQ1Gp0=; b=PxtJW8pY62RKvbrrRNLA0APOQKaOj4FAfbRqf9C/8drlONCWo7NQh7BF8P596DD0+2wIqfXgo3xHQkNuc6xo/FNe33gza4T056fpsF8uAZN7OzA1hzbTlJ2AJEnkQAOXgYulWolJc4Lml9IMjUwfuiR4daRrhBHQoRbrRODekHI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602209360863290.86641899876736; Thu, 8 Oct 2020 19:09:20 -0700 (PDT) Received: from localhost ([::1]:43824 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQhqR-00080O-Cx for importer@patchew.org; Thu, 08 Oct 2020 22:09:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33034) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQhol-00064P-Tt for qemu-devel@nongnu.org; Thu, 08 Oct 2020 22:07:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:48069) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQhoc-0006rc-Rs for qemu-devel@nongnu.org; Thu, 08 Oct 2020 22:07:35 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-183-dAk286DAPpOFQKKYM0Y4Kw-1; Thu, 08 Oct 2020 22:07:23 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A9DA564143; Fri, 9 Oct 2020 02:07:22 +0000 (UTC) Received: from blue.redhat.com (ovpn-113-14.phx2.redhat.com [10.3.113.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0FEAA76650; Fri, 9 Oct 2020 02:07:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602209245; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T8wFYhrz/v4NI8FMXE3LWRphbgaidPX9Bd0i6MQ1Gp0=; b=dJs60tdh5sOpsv1A+gXLhSErzFA0Cjr1he3yBD4RWUpFg6XZAb10qsltjEXish8USe3LtG 0YzQjaxL7AleLGB1oFrRQXZ174JxMBfMgDMd32T4bMWktgez88Up1mFMqMAFDglrDu4sZp x2FnS4RP0cpWc/bCWLESLa0rkrPBctY= X-MC-Unique: dAk286DAPpOFQKKYM0Y4Kw-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v3 3/6] nbd: Update qapi to support multiple bitmaps Date: Thu, 8 Oct 2020 21:07:11 -0500 Message-Id: <20201009020714.1074061-4-eblake@redhat.com> In-Reply-To: <20201009020714.1074061-1-eblake@redhat.com> References: <20201009020714.1074061-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eblake@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/08 22:07:25 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, qemu-block@nongnu.org, Markus Armbruster , rjones@redhat.com, Max Reitz , stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Since 'nbd-server-add' is deprecated, and 'block-export-add' is new to 5.2, we can still tweak the interface. Allowing 'bitmaps':['str'] is nicer than 'bitmap':'str'. This wires up the qapi and qemu-nbd changes to permit passing multiple bitmaps, but the actual support will require a further patch to the server. Signed-off-by: Eric Blake --- qapi/block-export.json | 16 +++++++++++----- blockdev-nbd.c | 18 ++++++++++++++++-- nbd/server.c | 19 +++++++++++++------ qemu-nbd.c | 13 ++++++++----- 4 files changed, 48 insertions(+), 18 deletions(-) diff --git a/qapi/block-export.json b/qapi/block-export.json index 524cd3a94400..2dc45a54e364 100644 --- a/qapi/block-export.json +++ b/qapi/block-export.json @@ -74,9 +74,9 @@ # @description: Free-form description of the export, up to 4096 bytes. # (Since 5.0) # -# @bitmap: Also export the dirty bitmap reachable from @device, so the -# NBD client can use NBD_OPT_SET_META_CONTEXT with -# "qemu:dirty-bitmap:NAME" to inspect the bitmap. (since 4.0) +# @bitmaps: Also export each of the named dirty bitmaps reachable from +# @device, so the NBD client can use NBD_OPT_SET_META_CONTEXT wi= th +# "qemu:dirty-bitmap:BITMAP" to inspect each bitmap. (since 5.2) # # @alloc: Also export the allocation map for @device, so the NBD client # can use NBD_OPT_SET_META_CONTEXT with "qemu:allocation-depth" @@ -86,7 +86,7 @@ ## { 'struct': 'BlockExportOptionsNbd', 'data': { '*name': 'str', '*description': 'str', - '*bitmap': 'str', '*alloc': 'bool' } } + '*bitmaps': ['str'], '*alloc': 'bool' } } ## # @NbdServerAddOptions: @@ -98,12 +98,18 @@ # @writable: Whether clients should be able to write to the device via the # NBD connection (default false). # +# @bitmap: Also export a single dirty bitmap reachable from @device, so the +# NBD client can use NBD_OPT_SET_META_CONTEXT with +# "qemu:dirty-bitmap:BITMAP" to inspect the bitmap (since 4.0); +# mutually exclusive with @bitmaps, and newer clients should use +# that instead. +# # Since: 5.0 ## { 'struct': 'NbdServerAddOptions', 'base': 'BlockExportOptionsNbd', 'data': { 'device': 'str', - '*writable': 'bool' } } + '*writable': 'bool', '*bitmap': 'str' } } ## # @nbd-server-add: diff --git a/blockdev-nbd.c b/blockdev-nbd.c index f9012f93e2bb..f0a03c830c5f 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -190,6 +190,20 @@ void qmp_nbd_server_add(NbdServerAddOptions *arg, Erro= r **errp) return; } + /* + * New code should use the list 'bitmaps'; but until this code is + * gone, we must support the older single 'bitmap'. Use only one. + */ + if (arg->has_bitmap) { + if (arg->has_bitmaps) { + error_setg(errp, "Can't mix 'bitmap' and 'bitmaps'"); + return; + } + arg->has_bitmaps =3D true; + arg->bitmaps =3D g_new0(strList, 1); + arg->bitmaps->value =3D g_strdup(arg->bitmap); + } + /* * block-export-add would default to the node-name, but we may have to= use * the device name as a default here for compatibility. @@ -210,8 +224,8 @@ void qmp_nbd_server_add(NbdServerAddOptions *arg, Error= **errp) .name =3D g_strdup(arg->name), .has_description =3D arg->has_description, .description =3D g_strdup(arg->description), - .has_bitmap =3D arg->has_bitmap, - .bitmap =3D g_strdup(arg->bitmap), + .has_bitmaps =3D arg->has_bitmaps, + .bitmaps =3D g_steal_pointer(&arg->bitmaps), .has_alloc =3D arg->alloc, .alloc =3D arg->alloc, }, diff --git a/nbd/server.c b/nbd/server.c index e24495d93e2e..ea5de0b503cd 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1495,6 +1495,7 @@ static int nbd_export_create(BlockExport *blk_exp, Bl= ockExportOptions *exp_args, uint64_t perm, shared_perm; bool readonly =3D !exp_args->writable; bool shared =3D !exp_args->writable; + strList *bitmaps; int ret; assert(exp_args->type =3D=3D BLOCK_EXPORT_TYPE_NBD); @@ -1556,12 +1557,18 @@ static int nbd_export_create(BlockExport *blk_exp, = BlockExportOptions *exp_args, } exp->size =3D QEMU_ALIGN_DOWN(size, BDRV_SECTOR_SIZE); - if (arg->bitmap) { + /* XXX Allow more than one bitmap */ + if (arg->bitmaps && arg->bitmaps->next) { + error_setg(errp, "multiple bitmaps per export not supported yet"); + return -EOPNOTSUPP; + } + for (bitmaps =3D arg->bitmaps; bitmaps; bitmaps =3D bitmaps->next) { + const char *bitmap =3D bitmaps->value; BlockDriverState *bs =3D blk_bs(blk); BdrvDirtyBitmap *bm =3D NULL; while (bs) { - bm =3D bdrv_find_dirty_bitmap(bs, arg->bitmap); + bm =3D bdrv_find_dirty_bitmap(bs, bitmap); if (bm !=3D NULL) { break; } @@ -1571,7 +1578,7 @@ static int nbd_export_create(BlockExport *blk_exp, Bl= ockExportOptions *exp_args, if (bm =3D=3D NULL) { ret =3D -ENOENT; - error_setg(errp, "Bitmap '%s' is not found", arg->bitmap); + error_setg(errp, "Bitmap '%s' is not found", bitmap); goto fail; } @@ -1585,15 +1592,15 @@ static int nbd_export_create(BlockExport *blk_exp, = BlockExportOptions *exp_args, ret =3D -EINVAL; error_setg(errp, "Enabled bitmap '%s' incompatible with readonly exp= ort", - arg->bitmap); + bitmap); goto fail; } bdrv_dirty_bitmap_set_busy(bm, true); exp->export_bitmap =3D bm; - assert(strlen(arg->bitmap) <=3D BDRV_BITMAP_MAX_NAME_SIZE); + assert(strlen(bitmap) <=3D BDRV_BITMAP_MAX_NAME_SIZE); exp->export_bitmap_context =3D g_strdup_printf("qemu:dirty-bitmap:= %s", - arg->bitmap); + bitmap); assert(strlen(exp->export_bitmap_context) < NBD_MAX_STRING_SIZE); } diff --git a/qemu-nbd.c b/qemu-nbd.c index e3cff17d6760..8648a39d0ab9 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -572,7 +572,7 @@ int main(int argc, char **argv) const char *export_name =3D NULL; /* defaults to "" later for server m= ode */ const char *export_description =3D NULL; bool alloc_depth =3D false; - const char *bitmap =3D NULL; + strList *bitmaps =3D NULL, *tmp; const char *tlscredsid =3D NULL; bool imageOpts =3D false; bool writethrough =3D true; @@ -701,7 +701,10 @@ int main(int argc, char **argv) alloc_depth =3D true; break; case 'B': - bitmap =3D optarg; + tmp =3D g_new(strList, 1); + tmp->value =3D g_strdup(optarg); + tmp->next =3D bitmaps; + bitmaps =3D tmp; break; case 'k': sockpath =3D optarg; @@ -798,7 +801,7 @@ int main(int argc, char **argv) } if (export_name || export_description || dev_offset || device || disconnect || fmt || sn_id_or_name || alloc_depth || - bitmap || seen_aio || seen_discard || seen_cache) { + bitmaps || seen_aio || seen_discard || seen_cache) { error_report("List mode is incompatible with per-device settin= gs"); exit(EXIT_FAILURE); } @@ -1082,8 +1085,8 @@ int main(int argc, char **argv) .name =3D g_strdup(export_name), .has_description =3D !!export_description, .description =3D g_strdup(export_description), - .has_bitmap =3D !!bitmap, - .bitmap =3D g_strdup(bitmap), + .has_bitmaps =3D !!bitmaps, + .bitmaps =3D bitmaps, .has_alloc =3D alloc_depth, .alloc =3D alloc_depth, }, --=20 2.28.0