From nobody Sat May 18 23:55:17 2024 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=1602280646; cv=none; d=zohomail.com; s=zohoarc; b=kaZeaGEHncVzu6e+x39cuBi7GefqgIQKakmQMB0sLZXHUnuH1e5qhnzjfQR1bV4Da52dObAgrePEhIX3ChKBs192IbKu2TZQoac9EhEZcXRZYV5kiHQVIa1PwUtVLwdrLfbQxpq/Ct6xj9hM18Mr37hXUlnX1igwFed7gcTqXhQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602280646; 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=2/KCkc3586Mt0J7033zTZKV7uboGJ1dOHBVuL67Dbnc=; b=oBLNkGZj0rX/eNlfNj6frh3As87Q5E+H6bU9OmkjirJpA/GSwzBCWhAVmC+1aevETvL/2RYvgNL7hRQbX9OgGwlzZuEJh98aOd/0mQKpqsBwRGVX/teG2mS9RzzZaC5Hlk4130BtSy64BiJIugezhClOTjIBzJF+MDZxX4/kY68= 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 1602280646422755.6423176847468; Fri, 9 Oct 2020 14:57:26 -0700 (PDT) Received: from localhost ([::1]:46826 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kR0OC-0004FM-Lg for importer@patchew.org; Fri, 09 Oct 2020 17:57:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50114) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kR0Md-0002jK-WB for qemu-devel@nongnu.org; Fri, 09 Oct 2020 17:55:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:54194) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kR0Ma-0003N8-Gv for qemu-devel@nongnu.org; Fri, 09 Oct 2020 17:55:47 -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-307-uZDbTfxOMtyoLr0J7hgzUA-1; Fri, 09 Oct 2020 17:55:40 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 85A9A1009636; Fri, 9 Oct 2020 21:55:39 +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 EA43310013C4; Fri, 9 Oct 2020 21:55:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602280542; 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=2/KCkc3586Mt0J7033zTZKV7uboGJ1dOHBVuL67Dbnc=; b=XJEaGNp+B27Us50YBLFMKMjsKMRGRkh29bL+hhzBCWQyl8/NYvpVnbObTzq3gjwz+BOYWs lI0sGq4bbL9nYy+vVjA+/AlNi5QXQBLyZDhJTFm87w/HlloSWvwk2To9jFg5WmmnXGgkFY cpXbCsxLu0hZhnpqpjMiklxcq8KeCUI= X-MC-Unique: uZDbTfxOMtyoLr0J7hgzUA-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v4 1/7] nbd: Utilize QAPI_CLONE for type conversion Date: Fri, 9 Oct 2020 16:55:27 -0500 Message-Id: <20201009215533.1194742-2-eblake@redhat.com> In-Reply-To: <20201009215533.1194742-1-eblake@redhat.com> References: <20201009215533.1194742-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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/09 02:34:37 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, 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" Rather than open-coding the translation from the deprecated NbdServerAddOptions type to the preferred BlockExportOptionsNbd, it's better to utilize QAPI_CLONE_MEMBERS. This solves a couple of issues: first, if we do any more refactoring of the base type (which an upcoming patch plans to do), we don't have to revisit the open-coding. Second, our assignment to arg->name is fishy: the generated QAPI code currently does not visit it if arg->has_name is false, but if it DID visit it, we would have introduced a double-free situation when arg is finally freed. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- blockdev-nbd.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/blockdev-nbd.c b/blockdev-nbd.c index 8174023e5c47..43856c1058a5 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -14,6 +14,8 @@ #include "sysemu/block-backend.h" #include "hw/block/block.h" #include "qapi/error.h" +#include "qapi/clone-visitor.h" +#include "qapi/qapi-visit-block-export.h" #include "qapi/qapi-commands-block-export.h" #include "block/nbd.h" #include "io/channel-socket.h" @@ -195,7 +197,8 @@ void qmp_nbd_server_add(NbdServerAddOptions *arg, Error= **errp) * the device name as a default here for compatibility. */ if (!arg->has_name) { - arg->name =3D arg->device; + arg->has_name =3D true; + arg->name =3D g_steal_pointer(&arg->device); } export_opts =3D g_new(BlockExportOptions, 1); @@ -205,15 +208,9 @@ void qmp_nbd_server_add(NbdServerAddOptions *arg, Erro= r **errp) .node_name =3D g_strdup(bdrv_get_node_name(bs)), .has_writable =3D arg->has_writable, .writable =3D arg->writable, - .u.nbd =3D { - .has_name =3D true, - .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), - }, }; + QAPI_CLONE_MEMBERS(BlockExportOptionsNbd, &export_opts->u.nbd, + qapi_NbdServerAddOptions_base(arg)); /* * nbd-server-add doesn't complain when a read-only device should be --=20 2.28.0 From nobody Sat May 18 23:55:17 2024 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=1602280834; cv=none; d=zohomail.com; s=zohoarc; b=FnVNrv3tYaxrZNdZkKFJhf0mmzEHWdUXgFNOm2TBZ9LaGH2NcnqFTyEurYrkFZWCLTc1z3NEDOe2Vv67hNTCz1rG0eL0ha21PVXx4C41Ls0c7pq5VCcKTSv88Ya5JvgDzlF0+1uNS9I46Z682v+beqt1L38S1oEpHZyJfAmnGnY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602280834; 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=fG3di8xpIU09MPWDdMqhrALqhYmZf6Mz1zrjeYVU/Lc=; b=CPm24CArflFqT1AezD0zmLP5D22nH8wyQp4N8moR8oTeUzQ50XdQmiNup5lpU6/5//b4EzYBPEA+RHilCMBoyWRod+wHYevWPAauLITdlRUssygR2iA8Xh3aWa2mRgX4pSZc3qxwGayPj8NO7O3ceoeFf0lSbnl68k7GkyGrNdE= 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 1602280834533961.1185048034014; Fri, 9 Oct 2020 15:00:34 -0700 (PDT) Received: from localhost ([::1]:53350 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kR0RF-00072H-1E for importer@patchew.org; Fri, 09 Oct 2020 18:00:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50148) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kR0Mf-0002kI-At for qemu-devel@nongnu.org; Fri, 09 Oct 2020 17:55:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:36621) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kR0Ma-0003P1-Uq for qemu-devel@nongnu.org; Fri, 09 Oct 2020 17:55:48 -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-13-URNEo67lPDqnlmE_VIXJVw-1; Fri, 09 Oct 2020 17:55:41 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6744118829D5; Fri, 9 Oct 2020 21:55:40 +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 BAFDC10013C4; Fri, 9 Oct 2020 21:55:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602280544; 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=fG3di8xpIU09MPWDdMqhrALqhYmZf6Mz1zrjeYVU/Lc=; b=LgW5na0GPPDUs17t5y5tLfVkp1Ob8NhE+HB/mBzza7CG6SQknlw7K2sZn4SsXA9r+4UAMu ONoc+CPeq+tXTpwTl6te9lGbRI99DO+QPzWG/7YLvvmeuPojCsSr2a29R0W8zS0t3ZiWUA GdV69mWYcH3FMcIJ+I1dLKnOGsEqa/A= X-MC-Unique: URNEo67lPDqnlmE_VIXJVw-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v4 2/7] nbd: Add new qemu:allocation-depth metadata context Date: Fri, 9 Oct 2020 16:55:28 -0500 Message-Id: <20201009215533.1194742-3-eblake@redhat.com> In-Reply-To: <20201009215533.1194742-1-eblake@redhat.com> References: <20201009215533.1194742-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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/09 02:34:37 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=unavailable 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, 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" 'qemu-img map' provides a way to determine which extents of an image come from the top layer vs. inherited from a backing chain. This is useful information worth exposing over NBD. There is a proposal to add a QMP command block-dirty-bitmap-populate which can create a dirty bitmap that reflects allocation information, at which point the qemu:dirty-bitmap:NAME metadata context can expose that information via the creation of a temporary bitmap, but we can shorten the effort by adding a new qemu:allocation-depth metadata context that does the same thing without an intermediate bitmap (this patch does not eliminate the need for that proposal, as it will have other uses as well). For this patch, I just encoded a tri-state value (unallocated, from this layer, from any of the backing layers); an obvious extension would be to provide the actual depth in bits 31-4 while keeping bits 1-0 as a tri-state (leaving bits 3-2 unused, for ease of reading depth from a hex number). But adding this extension would require bdrv_is_allocated_above to return a depth number. While documenting things, remember that although the NBD protocol has NBD_OPT_SET_META_CONTEXT, the rest of its documentation refers to 'metadata context', which is a more apt description of what is actually being used by NBD_CMD_BLOCK_STATUS: the user is requesting metadata by passing one or more context names. So I also touched up some existing wording to prefer the term 'metadata context' where it makes sense. Note that this patch does not actually enable any way to request a server to enable this context; that will come in the next patch. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- docs/interop/nbd.txt | 27 ++++++++++--- include/block/nbd.h | 12 ++++-- nbd/server.c | 92 ++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 116 insertions(+), 15 deletions(-) diff --git a/docs/interop/nbd.txt b/docs/interop/nbd.txt index f3b3cacc9621..a55e5a8776c8 100644 --- a/docs/interop/nbd.txt +++ b/docs/interop/nbd.txt @@ -17,19 +17,35 @@ namespace "qemu". =3D=3D "qemu" namespace =3D=3D -The "qemu" namespace currently contains only one type of context, -related to exposing the contents of a dirty bitmap alongside the -associated disk contents. That context has the following form: +The "qemu" namespace currently contains two available metadata context +types. The first is related to exposing the contents of a dirty +bitmap alongside the associated disk contents. That metadata context +is named with the following form: qemu:dirty-bitmap: Each dirty-bitmap metadata context defines only one flag for extents in reply for NBD_CMD_BLOCK_STATUS: - bit 0: NBD_STATE_DIRTY, means that the extent is "dirty" + bit 0: NBD_STATE_DIRTY, set when the extent is "dirty" + +The second is related to exposing the source of various extents within +the image, with a single metadata context named: + + qemu:allocation-depth + +In the allocation depth context, bits 0 and 1 form a tri-state value: + + bits 0-1: 00: NBD_STATE_DEPTH_UNALLOC, the extent is unallocated + 01: NBD_STATE_DEPTH_LOCAL, the extent is allocated in the + top level of the image + 10: NBD_STATE_DEPTH_BACKING, the extent is inherited from a + backing layer + 11: invalid, never returned For NBD_OPT_LIST_META_CONTEXT the following queries are supported -in addition to "qemu:dirty-bitmap:": +in addition to the specific "qemu:allocation-depth" and +"qemu:dirty-bitmap:": * "qemu:" - returns list of all available metadata contexts in the namespace. @@ -55,3 +71,4 @@ the operation of that feature. NBD_CMD_BLOCK_STATUS for "qemu:dirty-bitmap:", NBD_CMD_CACHE * 4.2: NBD_FLAG_CAN_MULTI_CONN for shareable read-only exports, NBD_CMD_FLAG_FAST_ZERO +* 5.2: NBD_CMD_BLOCK_STATUS for "qemu:allocation-depth" diff --git a/include/block/nbd.h b/include/block/nbd.h index 3dd9a04546ec..0bbf92f02951 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016-2019 Red Hat, Inc. + * Copyright (C) 2016-2020 Red Hat, Inc. * Copyright (C) 2005 Anthony Liguori * * Network Block Device @@ -47,7 +47,7 @@ typedef struct NBDOptionReply NBDOptionReply; typedef struct NBDOptionReplyMetaContext { NBDOptionReply h; /* h.type =3D NBD_REP_META_CONTEXT, h.length > 4 */ uint32_t context_id; - /* meta context name follows */ + /* metadata context name follows */ } QEMU_PACKED NBDOptionReplyMetaContext; /* Transmission phase structs @@ -229,7 +229,7 @@ enum { #define NBD_MAX_BUFFER_SIZE (32 * 1024 * 1024) /* - * Maximum size of a protocol string (export name, meta context name, + * Maximum size of a protocol string (export name, metadata context name, * etc.). Use malloc rather than stack allocation for storage of a * string. */ @@ -259,6 +259,12 @@ enum { /* Extent flags for qemu:dirty-bitmap in NBD_REPLY_TYPE_BLOCK_STATUS */ #define NBD_STATE_DIRTY (1 << 0) +/* Extent flags for qemu:allocation-depth in NBD_REPLY_TYPE_BLOCK_STATUS */ +#define NBD_STATE_DEPTH_MASK 0x3 +#define NBD_STATE_DEPTH_UNALLOC 0x0 +#define NBD_STATE_DEPTH_LOCAL 0x1 +#define NBD_STATE_DEPTH_BACKING 0x2 + static inline bool nbd_reply_type_is_error(int type) { return type & (1 << 15); diff --git a/nbd/server.c b/nbd/server.c index e75c825879aa..ae6f8a8e5429 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -27,7 +27,8 @@ #include "qemu/units.h" #define NBD_META_ID_BASE_ALLOCATION 0 -#define NBD_META_ID_DIRTY_BITMAP 1 +#define NBD_META_ID_ALLOCATION_DEPTH 1 +#define NBD_META_ID_DIRTY_BITMAP 2 /* * NBD_MAX_BLOCK_STATUS_EXTENTS: 1 MiB of extents data. An empirical @@ -94,6 +95,7 @@ struct NBDExport { BlockBackend *eject_notifier_blk; Notifier eject_notifier; + bool allocation_depth; BdrvDirtyBitmap *export_bitmap; char *export_bitmap_context; }; @@ -108,6 +110,7 @@ typedef struct NBDExportMetaContexts { bool valid; /* means that negotiation of the option finished without errors */ bool base_allocation; /* export base:allocation context (block status)= */ + bool allocation_depth; /* export qemu:allocation-depth */ bool bitmap; /* export qemu:dirty-bitmap: */ } NBDExportMetaContexts; @@ -852,7 +855,8 @@ static bool nbd_meta_base_query(NBDClient *client, NBDE= xportMetaContexts *meta, /* nbd_meta_qemu_query * * Handle queries to 'qemu' namespace. For now, only the qemu:dirty-bitmap: - * context is available. Return true if @query has been handled. + * and qemu:allocation-depth contexts are available. Return true if @query + * has been handled. */ static bool nbd_meta_qemu_query(NBDClient *client, NBDExportMetaContexts *= meta, const char *query) @@ -864,12 +868,19 @@ static bool nbd_meta_qemu_query(NBDClient *client, NB= DExportMetaContexts *meta, if (!*query) { if (client->opt =3D=3D NBD_OPT_LIST_META_CONTEXT) { + meta->allocation_depth =3D meta->exp->allocation_depth; meta->bitmap =3D !!meta->exp->export_bitmap; } trace_nbd_negotiate_meta_query_parse("empty"); return true; } + if (strcmp(query, "allocation-depth") =3D=3D 0) { + trace_nbd_negotiate_meta_query_parse("allocation-depth"); + meta->allocation_depth =3D meta->exp->allocation_depth; + return true; + } + if (nbd_strshift(&query, "dirty-bitmap:")) { trace_nbd_negotiate_meta_query_parse("dirty-bitmap:"); if (!meta->exp->export_bitmap) { @@ -884,7 +895,7 @@ static bool nbd_meta_qemu_query(NBDClient *client, NBDE= xportMetaContexts *meta, return true; } - trace_nbd_negotiate_meta_query_skip("not dirty-bitmap"); + trace_nbd_negotiate_meta_query_skip("unknown qemu context"); return true; } @@ -984,6 +995,7 @@ static int nbd_negotiate_meta_queries(NBDClient *client, if (client->opt =3D=3D NBD_OPT_LIST_META_CONTEXT && !nb_queries) { /* enable all known contexts */ meta->base_allocation =3D true; + meta->allocation_depth =3D meta->exp->allocation_depth; meta->bitmap =3D !!meta->exp->export_bitmap; } else { for (i =3D 0; i < nb_queries; ++i) { @@ -1003,6 +1015,15 @@ static int nbd_negotiate_meta_queries(NBDClient *cli= ent, } } + if (meta->allocation_depth) { + ret =3D nbd_negotiate_send_meta_context(client, "qemu:allocation-d= epth", + NBD_META_ID_ALLOCATION_DEPTH, + errp); + if (ret < 0) { + return ret; + } + } + if (meta->bitmap) { ret =3D nbd_negotiate_send_meta_context(client, meta->exp->export_bitmap_con= text, @@ -1961,6 +1982,40 @@ static int blockstatus_to_extents(BlockDriverState *= bs, uint64_t offset, return 0; } +static int blockalloc_to_extents(BlockDriverState *bs, uint64_t offset, + uint64_t bytes, NBDExtentArray *ea) +{ + while (bytes) { + uint32_t flags; + int64_t num; + int ret =3D bdrv_is_allocated(bs, offset, bytes, &num); + + if (ret < 0) { + return ret; + } + + if (ret =3D=3D 1) { + flags =3D NBD_STATE_DEPTH_LOCAL; + } else { + ret =3D bdrv_is_allocated_above(bs, NULL, false, offset, num, + &num); + if (ret < 0) { + return ret; + } + flags =3D ret ? NBD_STATE_DEPTH_BACKING : NBD_STATE_DEPTH_UNAL= LOC; + } + + if (nbd_extent_array_add(ea, num, flags) < 0) { + return 0; + } + + offset +=3D num; + bytes -=3D num; + } + + return 0; +} + /* * nbd_co_send_extents * @@ -2000,7 +2055,11 @@ static int nbd_co_send_block_status(NBDClient *clien= t, uint64_t handle, unsigned int nb_extents =3D dont_fragment ? 1 : NBD_MAX_BLOCK_STATUS_E= XTENTS; g_autoptr(NBDExtentArray) ea =3D nbd_extent_array_new(nb_extents); - ret =3D blockstatus_to_extents(bs, offset, length, ea); + if (context_id =3D=3D NBD_META_ID_BASE_ALLOCATION) { + ret =3D blockstatus_to_extents(bs, offset, length, ea); + } else { + ret =3D blockalloc_to_extents(bs, offset, length, ea); + } if (ret < 0) { return nbd_co_send_structured_error( client, handle, -ret, "can't get block status", errp); @@ -2335,16 +2394,20 @@ static coroutine_fn int nbd_handle_request(NBDClien= t *client, } if (client->export_meta.valid && (client->export_meta.base_allocation || + client->export_meta.allocation_depth || client->export_meta.bitmap)) { bool dont_fragment =3D request->flags & NBD_CMD_FLAG_REQ_ONE; + int contexts_remaining =3D client->export_meta.base_allocation= + + client->export_meta.allocation_depth + + client->export_meta.bitmap; if (client->export_meta.base_allocation) { ret =3D nbd_co_send_block_status(client, request->handle, blk_bs(exp->common.blk), request->from, request->len, dont_fragment, - !client->export_meta.bitmap, + !--contexts_remaining, NBD_META_ID_BASE_ALLOCATION, errp); if (ret < 0) { @@ -2352,17 +2415,32 @@ static coroutine_fn int nbd_handle_request(NBDClien= t *client, } } + if (client->export_meta.allocation_depth) { + ret =3D nbd_co_send_block_status(client, request->handle, + blk_bs(exp->common.blk), + request->from, request->len, + dont_fragment, + !--contexts_remaining, + NBD_META_ID_ALLOCATION_DEPT= H, + errp); + if (ret < 0) { + return ret; + } + } + if (client->export_meta.bitmap) { ret =3D nbd_co_send_bitmap(client, request->handle, client->exp->export_bitmap, request->from, request->len, - dont_fragment, - true, NBD_META_ID_DIRTY_BITMAP, e= rrp); + dont_fragment, !--contexts_remain= ing, + NBD_META_ID_DIRTY_BITMAP, errp); if (ret < 0) { return ret; } } + assert(!contexts_remaining); + return 0; } else { return nbd_send_generic_reply(client, request->handle, -EINVAL, --=20 2.28.0 From nobody Sat May 18 23:55:17 2024 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=1602280659; cv=none; d=zohomail.com; s=zohoarc; b=VSbhc5Q45GyOcRs1lEv0KuieGp82M85DjI/etECM9gnWVbM2a8OlmHE80Rexfq7Hm85hj7FYp1mrTyqlwABHh6uX+m13CTfmC9JSQ8v6nGemIvuRvtnFoQwefBOnetpnNeglBmUtJ7igYsTQCgUQN5dHraDrQhrUpg3/ktvAfKU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602280659; 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=xtFbqdgu+FQB9WCHd4+3K/4zhYR7dn02KYNBDh4lN2o=; b=RpltppjgkQ3v8lyHbKTE+pAuM6QoJonxCPLs4lZEJECkpTWCsLoeq8Pmr+aaUv9gvWUzvEzPKbe+V//tBSDdAfoZEy7ySj8mDq/FrPzUDGAv2TVP/REoK11hFvV13QfsWZovQkNZDkJX/4ZLqMQ7kbf0A26zW65GRVqASM3FDkE= 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 1602280659727371.86862327138533; Fri, 9 Oct 2020 14:57:39 -0700 (PDT) Received: from localhost ([::1]:47514 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kR0OQ-0004XH-Bt for importer@patchew.org; Fri, 09 Oct 2020 17:57:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50186) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kR0Mg-0002mF-8N for qemu-devel@nongnu.org; Fri, 09 Oct 2020 17:55:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:57248) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kR0Mb-0003Pu-F5 for qemu-devel@nongnu.org; Fri, 09 Oct 2020 17:55:49 -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-407-3bEi9PndMlWF4IFkP5pzsw-1; Fri, 09 Oct 2020 17:55:42 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 548B21074643; Fri, 9 Oct 2020 21:55:41 +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 A7C6210013C4; Fri, 9 Oct 2020 21:55:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602280544; 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=xtFbqdgu+FQB9WCHd4+3K/4zhYR7dn02KYNBDh4lN2o=; b=KBRAQU3I8IiYsRh+msOJ+VYloU4bW+dLJabJ142az72gW0HZenly4A1VuVsOWzMpbKt65A ixjfhjD1tcsrnptEKVx5Ph1KPHb6ufScS3rkGS6EcfFnDJKh/gC4Ll5/SE/V7gEh0C8nVs wuWLIb5m1Hx7OZSIByTZIBDEZbm3O0k= X-MC-Unique: 3bEi9PndMlWF4IFkP5pzsw-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v4 3/7] nbd: Add 'qemu-nbd -A' to expose allocation depth Date: Fri, 9 Oct 2020 16:55:29 -0500 Message-Id: <20201009215533.1194742-4-eblake@redhat.com> In-Reply-To: <20201009215533.1194742-1-eblake@redhat.com> References: <20201009215533.1194742-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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/09 02:34:37 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, rjones@redhat.com, Markus Armbruster , stefanha@redhat.com, Max Reitz 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" Allow the server to expose an additional metacontext to be requested by savvy clients. qemu-nbd adds a new option -A to expose the qemu:allocation-depth metacontext through NBD_CMD_BLOCK_STATUS; this can also be set via QMP when using block-export-add. qemu as client can be hacked into viewing this new context by using the now-misnamed x-dirty-bitmap option when creating an NBD blockdev (even though our x- naming means we could rename it, I did not think it worth breaking back-compat of tools that have been using it while waiting for a better solution). It is worth noting the decoding of how such context information will appear in 'qemu-img map --output=3Djson': NBD_STATE_DEPTH_UNALLOC =3D> "zero":false, "data":true NBD_STATE_DEPTH_LOCAL =3D> "zero":false, "data":false NBD_STATE_DEPTH_BACKING =3D> "zero":true, "data":true libnbd as client is probably a nicer way to get at the information without having to decipher such hacks in qemu as client. ;) Signed-off-by: Eric Blake Message-Id: <20200930121105.667049-6-eblake@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy [eblake: comment tweak suggested by Vladimir] Signed-off-by: Eric Blake --- docs/tools/qemu-nbd.rst | 8 ++++- qapi/block-core.json | 7 ++-- qapi/block-export.json | 12 +++++-- nbd/server.c | 2 ++ qemu-nbd.c | 26 +++++++++----- tests/qemu-iotests/309 | 73 ++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/309.out | 22 ++++++++++++ tests/qemu-iotests/group | 1 + 8 files changed, 136 insertions(+), 15 deletions(-) create mode 100755 tests/qemu-iotests/309 create mode 100644 tests/qemu-iotests/309.out diff --git a/docs/tools/qemu-nbd.rst b/docs/tools/qemu-nbd.rst index 667861cb22e9..fe41336dc550 100644 --- a/docs/tools/qemu-nbd.rst +++ b/docs/tools/qemu-nbd.rst @@ -72,10 +72,16 @@ driver options if ``--image-opts`` is specified. Export the disk as read-only. +.. option:: -A, --allocation-depth + + Expose allocation depth information via the + ``qemu:allocation-depth`` metadata context accessible through + NBD_OPT_SET_META_CONTEXT. + .. option:: -B, --bitmap=3DNAME If *filename* has a qcow2 persistent bitmap *NAME*, expose - that bitmap via the ``qemu:dirty-bitmap:NAME`` context + that bitmap via the ``qemu:dirty-bitmap:NAME`` metadata context accessible through NBD_OPT_SET_META_CONTEXT. .. option:: -s, --snapshot diff --git a/qapi/block-core.json b/qapi/block-core.json index ee5ebef7f2ce..b6368f5fd9a1 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -3883,9 +3883,12 @@ # # @tls-creds: TLS credentials ID # -# @x-dirty-bitmap: A "qemu:dirty-bitmap:NAME" string to query in place of +# @x-dirty-bitmap: A metadata context name such as "qemu:dirty-bitmap:NAME" +# or "qemu:allocation-depth" to query in place of the # traditional "base:allocation" block status (see -# NBD_OPT_LIST_META_CONTEXT in the NBD protocol) (since 3= .0) +# NBD_OPT_LIST_META_CONTEXT in the NBD protocol; and +# yes, naming this option x-context would have made +# more sense) (since 3.0) # # @reconnect-delay: On an unexpected disconnect, the nbd client tries to # connect again until succeeding or encountering a serio= us diff --git a/qapi/block-export.json b/qapi/block-export.json index 65804834d905..893d5cde5dfe 100644 --- a/qapi/block-export.json +++ b/qapi/block-export.json @@ -75,14 +75,20 @@ # (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) +# NBD client can use NBD_OPT_SET_META_CONTEXT with the +# metadata context name "qemu:dirty-bitmap:NAME" to inspect the +# bitmap. (since 4.0) +# +# @allocation-depth: Also export the allocation depth map for @device, so +# the NBD client can use NBD_OPT_SET_META_CONTEXT with +# the metadata context name "qemu:allocation-depth" to +# inspect allocation details. (since 5.2) # # Since: 5.0 ## { 'struct': 'BlockExportOptionsNbd', 'data': { '*name': 'str', '*description': 'str', - '*bitmap': 'str' } } + '*bitmap': 'str', '*allocation-depth': 'bool' } } ## # @NbdServerAddOptions: diff --git a/nbd/server.c b/nbd/server.c index ae6f8a8e5429..30cfe0eee467 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1597,6 +1597,8 @@ static int nbd_export_create(BlockExport *blk_exp, Bl= ockExportOptions *exp_args, assert(strlen(exp->export_bitmap_context) < NBD_MAX_STRING_SIZE); } + exp->allocation_depth =3D arg->allocation_depth; + blk_add_aio_context_notifier(blk, blk_aio_attached, blk_aio_detach, ex= p); QTAILQ_INSERT_TAIL(&exports, exp, next); diff --git a/qemu-nbd.c b/qemu-nbd.c index bc644a0670b6..847fde435a7f 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -99,6 +99,7 @@ static void usage(const char *name) "\n" "Exposing part of the image:\n" " -o, --offset=3DOFFSET offset into the image\n" +" -A, --allocation-depth expose the allocation depth\n" " -B, --bitmap=3DNAME expose a persistent dirty bitmap\n" "\n" "General purpose options:\n" @@ -519,7 +520,7 @@ int main(int argc, char **argv) char *device =3D NULL; QemuOpts *sn_opts =3D NULL; const char *sn_id_or_name =3D NULL; - const char *sopt =3D "hVb:o:p:rsnc:dvk:e:f:tl:x:T:D:B:L"; + const char *sopt =3D "hVb:o:p:rsnc:dvk:e:f:tl:x:T:D:AB:L"; struct option lopt[] =3D { { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'V' }, @@ -528,6 +529,7 @@ int main(int argc, char **argv) { "socket", required_argument, NULL, 'k' }, { "offset", required_argument, NULL, 'o' }, { "read-only", no_argument, NULL, 'r' }, + { "allocation-depth", no_argument, NULL, 'A' }, { "bitmap", required_argument, NULL, 'B' }, { "connect", required_argument, NULL, 'c' }, { "disconnect", no_argument, NULL, 'd' }, @@ -569,6 +571,7 @@ int main(int argc, char **argv) QDict *options =3D NULL; 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; const char *tlscredsid =3D NULL; bool imageOpts =3D false; @@ -694,6 +697,9 @@ int main(int argc, char **argv) readonly =3D true; flags &=3D ~BDRV_O_RDWR; break; + case 'A': + alloc_depth =3D true; + break; case 'B': bitmap =3D optarg; break; @@ -791,8 +797,8 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } if (export_name || export_description || dev_offset || - device || disconnect || fmt || sn_id_or_name || bitmap || - seen_aio || seen_discard || seen_cache) { + device || disconnect || fmt || sn_id_or_name || alloc_depth || + bitmap || seen_aio || seen_discard || seen_cache) { error_report("List mode is incompatible with per-device settin= gs"); exit(EXIT_FAILURE); } @@ -1072,12 +1078,14 @@ int main(int argc, char **argv) .has_writable =3D true, .writable =3D !readonly, .u.nbd =3D { - .has_name =3D true, - .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_name =3D true, + .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_allocation_depth =3D alloc_depth, + .allocation_depth =3D alloc_depth, }, }; blk_exp_add(export_opts, &error_fatal); diff --git a/tests/qemu-iotests/309 b/tests/qemu-iotests/309 new file mode 100755 index 000000000000..b6734794bb68 --- /dev/null +++ b/tests/qemu-iotests/309 @@ -0,0 +1,73 @@ +#!/usr/bin/env bash +# +# Test qemu-nbd -A +# +# Copyright (C) 2018-2020 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +seq=3D"$(basename $0)" +echo "QA output created by $seq" + +status=3D1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img + nbd_server_stop +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter +. ./common.nbd + +_supported_fmt qcow2 +_supported_proto file +_supported_os Linux +_require_command QEMU_NBD + +echo +echo "=3D=3D=3D Initial image setup =3D=3D=3D" +echo + +TEST_IMG=3D"$TEST_IMG.base" _make_test_img 4M +$QEMU_IO -c 'w 0 2M' -f $IMGFMT "$TEST_IMG.base" | _filter_qemu_io +_make_test_img -b "$TEST_IMG.base" -F $IMGFMT 4M +$QEMU_IO -c 'w 1M 2M' -f $IMGFMT "$TEST_IMG" | _filter_qemu_io + +echo +echo "=3D=3D=3D Check allocation over NBD =3D=3D=3D" +echo + +$QEMU_IMG map --output=3Djson -f qcow2 "$TEST_IMG" +IMG=3D"driver=3Dnbd,server.type=3Dunix,server.path=3D$nbd_unix_socket" +nbd_server_start_unix_socket -r -f qcow2 -A "$TEST_IMG" +# Normal -f raw NBD block status loses access to allocation information +$QEMU_IMG map --output=3Djson --image-opts \ + "$IMG" | _filter_qemu_img_map +# But since we used -A, and use x-dirty-bitmap as a hack for reading bitma= ps, +# we can reconstruct it, by abusing block status to report: +# NBD_STATE_DEPTH_UNALLOC =3D> "zero":false, "data":true +# NBD_STATE_DEPTH_LOCAL =3D> "zero":false, "data":false +# NBD_STATE_DEPTH_BACKING =3D> "zero":true, "data":true +$QEMU_IMG map --output=3Djson --image-opts \ + "$IMG,x-dirty-bitmap=3Dqemu:allocation-depth" | _filter_qemu_img_map + +# success, all done +echo '*** done' +rm -f $seq.full +status=3D0 diff --git a/tests/qemu-iotests/309.out b/tests/qemu-iotests/309.out new file mode 100644 index 000000000000..db75bb6b0df9 --- /dev/null +++ b/tests/qemu-iotests/309.out @@ -0,0 +1,22 @@ +QA output created by 309 + +=3D=3D=3D Initial image setup =3D=3D=3D + +Formatting 'TEST_DIR/t.IMGFMT.base', fmt=3DIMGFMT size=3D4194304 +wrote 2097152/2097152 bytes at offset 0 +2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D4194304 backing_file= =3DTEST_DIR/t.IMGFMT.base backing_fmt=3DIMGFMT +wrote 2097152/2097152 bytes at offset 1048576 +2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +=3D=3D=3D Check allocation over NBD =3D=3D=3D + +[{ "start": 0, "length": 1048576, "depth": 1, "zero": false, "data": true,= "offset": 327680}, +{ "start": 1048576, "length": 2097152, "depth": 0, "zero": false, "data": = true, "offset": 327680}, +{ "start": 3145728, "length": 1048576, "depth": 1, "zero": true, "data": f= alse}] +[{ "start": 0, "length": 3145728, "depth": 0, "zero": false, "data": true,= "offset": OFFSET}, +{ "start": 3145728, "length": 1048576, "depth": 0, "zero": true, "data": f= alse, "offset": OFFSET}] +[{ "start": 0, "length": 1048576, "depth": 0, "zero": true, "data": true, = "offset": OFFSET}, +{ "start": 1048576, "length": 2097152, "depth": 0, "zero": false, "data": = false}, +{ "start": 3145728, "length": 1048576, "depth": 0, "zero": false, "data": = true, "offset": OFFSET}] +*** done diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 9e4f7c01530d..a567fa97d7e5 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -315,3 +315,4 @@ 304 rw quick 305 rw quick 307 rw quick export +309 rw auto quick --=20 2.28.0 From nobody Sat May 18 23:55:17 2024 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=1602280970; cv=none; d=zohomail.com; s=zohoarc; b=bHDwxkBbzMEpfxLCtqHJzbtdr8PrYXhbTYoQ8rR9SXtMVyJd4XB6eJ/NLWMOZPmTzexEJp3U9g4u4lKr9zVl1QKSRIBMvbohmOOQcsFSSl7zLLcfw84+YcYHNxe19bzeMvZ/fknbZhyCCDrWtVRHeWLDg4t7gbiP7IWQFd/Yl8Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602280970; 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=vDhsjOxJJ17oolgE04i0yPAKFi3Ss1MM7vHXvbd8znQ=; b=FSQNi9CtrFPb3p/mPoQNPtILjRxFFgu+vbPDuw1l7NewSoDbxUe+aU0mkJaea8XSwNQEdkvsFCYuKuTLVwEE1obxRq/feU9Wn9jThWZNW2Iciq/0jizS36ns4DdkVMs/loU/yN0U2hr+kMcNX/KUVFZ1wN5F/Y4Q9X8iIV8GsYs= 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 1602280970490183.331149082112; Fri, 9 Oct 2020 15:02:50 -0700 (PDT) Received: from localhost ([::1]:57924 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kR0TQ-0000h3-Vm for importer@patchew.org; Fri, 09 Oct 2020 18:02:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50200) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kR0Mg-0002np-V5 for qemu-devel@nongnu.org; Fri, 09 Oct 2020 17:55:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:51147) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kR0Mb-0003Q5-P9 for qemu-devel@nongnu.org; Fri, 09 Oct 2020 17:55:50 -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-522-PZ9DiLDtM_eirZzuZZmPcw-1; Fri, 09 Oct 2020 17:55:43 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3635F1074648; Fri, 9 Oct 2020 21:55:42 +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 8A27910013C4; Fri, 9 Oct 2020 21:55:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602280545; 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=vDhsjOxJJ17oolgE04i0yPAKFi3Ss1MM7vHXvbd8znQ=; b=HuOD1zot9hEqHZkWZSV46SbyZdn9F8sRqQgHkGgglAp6yrQ/VTSNIZTJlwcMEpoyP3fHpK avj5y1oHlJZayWc+yxvs0ZNM8apcURYLm2YqAUnS9rppUK/ywsI0UT5hSFnxortjkM3dtX TsUh+/CfrvqmzNetebfIG6pi/3Iu5Eo= X-MC-Unique: PZ9DiLDtM_eirZzuZZmPcw-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v4 4/7] nbd: Update qapi to support exporting multiple bitmaps Date: Fri, 9 Oct 2020 16:55:30 -0500 Message-Id: <20201009215533.1194742-5-eblake@redhat.com> In-Reply-To: <20201009215533.1194742-1-eblake@redhat.com> References: <20201009215533.1194742-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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=63.128.21.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/09 02:34:40 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_H5=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 as distinct metadata contexts that the NBD client may request, but the actual support for more than one will require a further patch to the server. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- qapi/block-export.json | 18 ++++++++++++------ blockdev-nbd.c | 14 ++++++++++++++ nbd/server.c | 19 +++++++++++++------ qemu-nbd.c | 13 ++++++++----- 4 files changed, 47 insertions(+), 17 deletions(-) diff --git a/qapi/block-export.json b/qapi/block-export.json index 893d5cde5dfe..c7c749d61097 100644 --- a/qapi/block-export.json +++ b/qapi/block-export.json @@ -74,10 +74,10 @@ # @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 the -# metadata context name "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 +# the metadata context name "qemu:dirty-bitmap:BITMAP" to inspect +# each bitmap. (since 5.2) # # @allocation-depth: Also export the allocation depth map for @device, so # the NBD client can use NBD_OPT_SET_META_CONTEXT with @@ -88,7 +88,7 @@ ## { 'struct': 'BlockExportOptionsNbd', 'data': { '*name': 'str', '*description': 'str', - '*bitmap': 'str', '*allocation-depth': 'bool' } } + '*bitmaps': ['str'], '*allocation-depth': 'bool' } } ## # @NbdServerAddOptions: @@ -100,12 +100,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 the metadata +# context name "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 43856c1058a5..359a198de2c7 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -192,6 +192,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. diff --git a/nbd/server.c b/nbd/server.c index 30cfe0eee467..884ffa00f1bd 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 847fde435a7f..fa5c68749e8f 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_allocation_depth =3D alloc_depth, .allocation_depth =3D alloc_depth, }, --=20 2.28.0 From nobody Sat May 18 23:55:17 2024 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=1602280865; cv=none; d=zohomail.com; s=zohoarc; b=iqmIYEUQ3kbBtiy28kvYEN/lySPtZZeHJmc9QblcxRea9oTlOSDR7TtLXrsJqQtMIDqDFYyDU5viCqjh9KQo00Wq8RITPcq5PEmgTeacPacq7hnKnVJ8yR4MTCh0AkDbIvb5stzOVDfuACcVz4msMZVD+rgs6NU4FA16KBHFGcY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602280865; 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=rSfMFBnZnRAzDs0pTuNNEDvhqb00qLJkPnApeMiPzUM=; b=dcutcLrWsTD8+LynDB4awhcs3DsAuDF7Jhtr3Yq9lZ1MHv17PEb+mge31b5m2kysMt4Y8KKXBXLMJbWwAERFWTkK5S5tEjnjdsYn7L/jUUJNmK6v4Ncj3MdX5vCT+FHMcmjCmiQbg9mSZrqfDIVbX9wW9uCyx17u2QC1q0TRnQs= 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 1602280865834642.2842158359575; Fri, 9 Oct 2020 15:01:05 -0700 (PDT) Received: from localhost ([::1]:53884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kR0Rk-0007Fh-HL for importer@patchew.org; Fri, 09 Oct 2020 18:01:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50198) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kR0Mg-0002nN-Qa for qemu-devel@nongnu.org; Fri, 09 Oct 2020 17:55:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:54308) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kR0Mc-0003Qn-U0 for qemu-devel@nongnu.org; Fri, 09 Oct 2020 17:55:50 -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-526-pyr-Y5B8MA6i_G-N9PIMFw-1; Fri, 09 Oct 2020 17:55:44 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E33201DDE0; Fri, 9 Oct 2020 21:55:42 +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 645C510013C4; Fri, 9 Oct 2020 21:55:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602280545; 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=rSfMFBnZnRAzDs0pTuNNEDvhqb00qLJkPnApeMiPzUM=; b=Q1AtgTV7pjgwvCNIud7UQI8mDNQI2HNVCUtYp/rDd8hYxIw6SYqVBMa+53m51NanZAt6KK xxfYXwtMJNkhVvpluGx7QWIh84xzICdfPopWvIVXrReHX8zyDkxOvUOvTLgmVlW5MzdqVk EMvgjPZ84HPvaTVbkBD4nCaT7UBdRy4= X-MC-Unique: pyr-Y5B8MA6i_G-N9PIMFw-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v4 5/7] nbd: Simplify qemu bitmap context name Date: Fri, 9 Oct 2020 16:55:31 -0500 Message-Id: <20201009215533.1194742-6-eblake@redhat.com> In-Reply-To: <20201009215533.1194742-1-eblake@redhat.com> References: <20201009215533.1194742-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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=63.128.21.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/09 02:34:40 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_H5=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, qemu-block@nongnu.org, vsementsov@virtuozzo.com, rjones@redhat.com, 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" Each dirty bitmap already knows its name; by reducing the scope of the places where we construct "qemu:dirty-bitmap:NAME" strings, tracking the name is more localized, and there are fewer per-export fields to worry about. This in turn will make it easier for an upcoming patch to export more than one bitmap at once. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- nbd/server.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 884ffa00f1bd..05a8154975a1 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -97,7 +97,6 @@ struct NBDExport { bool allocation_depth; BdrvDirtyBitmap *export_bitmap; - char *export_bitmap_context; }; static QTAILQ_HEAD(, NBDExport) exports =3D QTAILQ_HEAD_INITIALIZER(export= s); @@ -882,14 +881,15 @@ static bool nbd_meta_qemu_query(NBDClient *client, NB= DExportMetaContexts *meta, } if (nbd_strshift(&query, "dirty-bitmap:")) { + const char *bm_name; + trace_nbd_negotiate_meta_query_parse("dirty-bitmap:"); if (!meta->exp->export_bitmap) { trace_nbd_negotiate_meta_query_skip("no dirty-bitmap exported"= ); return true; } - if (nbd_meta_empty_or_pattern(client, - meta->exp->export_bitmap_context + - strlen("qemu:dirty-bitmap:"), query)= ) { + bm_name =3D bdrv_dirty_bitmap_name(meta->exp->export_bitmap); + if (nbd_meta_empty_or_pattern(client, bm_name, query)) { meta->bitmap =3D true; } return true; @@ -1025,8 +1025,11 @@ static int nbd_negotiate_meta_queries(NBDClient *cli= ent, } if (meta->bitmap) { - ret =3D nbd_negotiate_send_meta_context(client, - meta->exp->export_bitmap_con= text, + const char *bm_name =3D bdrv_dirty_bitmap_name(meta->exp->export_b= itmap); + g_autofree char *context =3D g_strdup_printf("qemu:dirty-bitmap:%s= ", + bm_name); + + ret =3D nbd_negotiate_send_meta_context(client, context, NBD_META_ID_DIRTY_BITMAP, errp); if (ret < 0) { @@ -1599,9 +1602,6 @@ static int nbd_export_create(BlockExport *blk_exp, Bl= ockExportOptions *exp_args, bdrv_dirty_bitmap_set_busy(bm, true); exp->export_bitmap =3D bm; assert(strlen(bitmap) <=3D BDRV_BITMAP_MAX_NAME_SIZE); - exp->export_bitmap_context =3D g_strdup_printf("qemu:dirty-bitmap:= %s", - bitmap); - assert(strlen(exp->export_bitmap_context) < NBD_MAX_STRING_SIZE); } exp->allocation_depth =3D arg->allocation_depth; @@ -1681,7 +1681,6 @@ static void nbd_export_delete(BlockExport *blk_exp) if (exp->export_bitmap) { bdrv_dirty_bitmap_set_busy(exp->export_bitmap, false); - g_free(exp->export_bitmap_context); } } --=20 2.28.0 From nobody Sat May 18 23:55:17 2024 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=1602281119; cv=none; d=zohomail.com; s=zohoarc; b=Lpr9PYAKz5VW0LpjHvrh54CQrcOb6pZpWuuTzjTi5xnP93hWI1QZzsLmk+MR4J8aScpRyhnn1ybTp1755Sw5ckvrFrcQZXgBfs3Bj9XTvw8EV28vKbw7vxgIY1vA/pucSkaoKLNqXCzIJ6WDsKcCYQp1eBSq17RkTBGbMK/GJmg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602281119; 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=0Eq/ITB/lBTrJF+4U2MK0ADeZ12u6qsK6QK2p7tcG2U=; b=QMu+LnVR+IBr3SxQDs6sVHOGqO/CfAd/btfs3WZdBeoO1Epu3ujtQlz/eMgXxUNaX9CL+P5XyTQtwqphLXQLP0i/YM+ED0e7tQ3iJb7wPqk5whR7qZfzpVoZFiGZLAnMUUkNWVg7huOEnk7QA3km5Ze7CadfpFpv7uqpl/s3Od0= 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 1602281119806989.5079070768792; Fri, 9 Oct 2020 15:05:19 -0700 (PDT) Received: from localhost ([::1]:33958 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kR0Vp-0002WT-Fm for importer@patchew.org; Fri, 09 Oct 2020 18:05:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50216) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kR0Mh-0002q2-OA for qemu-devel@nongnu.org; Fri, 09 Oct 2020 17:55:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:40526) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kR0Md-0003R5-6j for qemu-devel@nongnu.org; Fri, 09 Oct 2020 17:55:51 -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-256-uLDmrEnTPrqF6EeoK3mzFQ-1; Fri, 09 Oct 2020 17:55:44 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9A8451DDE1; Fri, 9 Oct 2020 21:55:43 +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 1860210013C4; Fri, 9 Oct 2020 21:55:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602280546; 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=0Eq/ITB/lBTrJF+4U2MK0ADeZ12u6qsK6QK2p7tcG2U=; b=Uy/TN3dqWBs4ZcDgc38vS7c7ahmIfhYMQVxMrQVf7Q16KpCZ5YaHb5upcycocXKUsMOPJU 2Akhna1z6jFHlBAyj83csCoqwua+1uK4NLaSTVU9Vz2XlYRVfLS9XJrbFZhgXM6Wz1jz9p HKnmXzHznc1ExniB5E+G19CIyifwsOQ= X-MC-Unique: uLDmrEnTPrqF6EeoK3mzFQ-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v4 6/7] nbd: Refactor counting of metadata contexts Date: Fri, 9 Oct 2020 16:55:32 -0500 Message-Id: <20201009215533.1194742-7-eblake@redhat.com> In-Reply-To: <20201009215533.1194742-1-eblake@redhat.com> References: <20201009215533.1194742-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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=63.128.21.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/09 02:34:40 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_H5=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, qemu-block@nongnu.org, vsementsov@virtuozzo.com, rjones@redhat.com, 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" Rather than open-code the count of negotiated contexts at several sites, embed it directly into the struct. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- nbd/server.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 05a8154975a1..27d943529409 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -106,8 +106,7 @@ static QTAILQ_HEAD(, NBDExport) exports =3D QTAILQ_HEAD= _INITIALIZER(exports); * NBD_OPT_LIST_META_CONTEXT. */ typedef struct NBDExportMetaContexts { NBDExport *exp; - bool valid; /* means that negotiation of the option finished without - errors */ + size_t count; /* number of negotiated contexts */ bool base_allocation; /* export base:allocation context (block status)= */ bool allocation_depth; /* export qemu:allocation-depth */ bool bitmap; /* export qemu:dirty-bitmap: */ @@ -448,7 +447,9 @@ static int nbd_negotiate_handle_list(NBDClient *client,= Error **errp) static void nbd_check_meta_export(NBDClient *client) { - client->export_meta.valid &=3D client->exp =3D=3D client->export_meta.= exp; + if (client->exp !=3D client->export_meta.exp) { + client->export_meta.count =3D 0; + } } /* Send a reply to NBD_OPT_EXPORT_NAME. @@ -956,6 +957,7 @@ static int nbd_negotiate_meta_queries(NBDClient *client, NBDExportMetaContexts local_meta; uint32_t nb_queries; int i; + size_t count =3D 0; if (!client->structured_reply) { return nbd_opt_invalid(client, errp, @@ -1013,6 +1015,7 @@ static int nbd_negotiate_meta_queries(NBDClient *clie= nt, if (ret < 0) { return ret; } + count++; } if (meta->allocation_depth) { @@ -1022,6 +1025,7 @@ static int nbd_negotiate_meta_queries(NBDClient *clie= nt, if (ret < 0) { return ret; } + count++; } if (meta->bitmap) { @@ -1035,11 +1039,12 @@ static int nbd_negotiate_meta_queries(NBDClient *cl= ient, if (ret < 0) { return ret; } + count++; } ret =3D nbd_negotiate_send_rep(client, NBD_REP_ACK, errp); if (ret =3D=3D 0) { - meta->valid =3D true; + meta->count =3D count; } return ret; @@ -2400,15 +2405,9 @@ static coroutine_fn int nbd_handle_request(NBDClient= *client, return nbd_send_generic_reply(client, request->handle, -EINVAL, "need non-zero length", errp); } - if (client->export_meta.valid && - (client->export_meta.base_allocation || - client->export_meta.allocation_depth || - client->export_meta.bitmap)) - { + if (client->export_meta.count) { bool dont_fragment =3D request->flags & NBD_CMD_FLAG_REQ_ONE; - int contexts_remaining =3D client->export_meta.base_allocation= + - client->export_meta.allocation_depth + - client->export_meta.bitmap; + int contexts_remaining =3D client->export_meta.count; if (client->export_meta.base_allocation) { ret =3D nbd_co_send_block_status(client, request->handle, --=20 2.28.0 From nobody Sat May 18 23:55:17 2024 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=1602280980; cv=none; d=zohomail.com; s=zohoarc; b=GY9Dp9NnCmSHHRLeQee6lxL0GGjvByxLsERmG4JeahdixjrRVnS13HngZ01A4QZR4yqBVFoQKCQRcTSl2t909T9H3sjhU344wDJKfNEJbmilXQarux1FARgwK0mDugTDNPTM6XkzjeRaaoHDgsqEcPwMEY6G3uMuHbkrmd5pAas= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602280980; 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=XF9Iqxp9drBDNo+yyFLQiBdKbClIc4C0VnXimXDYiNs=; b=U0apEO+gj38LcX+uTruqoKHZkvT8L6Ewm4Y+95saERTxnydSoY9BEO25P97L+D5I6dLYrxDHARb27wEqKhDvbjcjr9nouWxRq+jE10H/gPt0HyCcMt6aaVejA26QzDeuw0gd2p+zB2pPhU1r4itfrKnBsfOSqK9w00K5bJKURfE= 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 160228098047995.59324983795034; Fri, 9 Oct 2020 15:03:00 -0700 (PDT) Received: from localhost ([::1]:58542 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kR0Tb-0000x0-74 for importer@patchew.org; Fri, 09 Oct 2020 18:02:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50238) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kR0Mi-0002sL-Q4 for qemu-devel@nongnu.org; Fri, 09 Oct 2020 17:55:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:50307) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kR0Me-0003Rq-E1 for qemu-devel@nongnu.org; Fri, 09 Oct 2020 17:55:52 -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-320-wh_9vAAPMY61YOk9t3zaag-1; Fri, 09 Oct 2020 17:55:45 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 67D0E8463DD; Fri, 9 Oct 2020 21:55:44 +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 CC8B510013C4; Fri, 9 Oct 2020 21:55:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602280547; 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=XF9Iqxp9drBDNo+yyFLQiBdKbClIc4C0VnXimXDYiNs=; b=Uh5zrxG4NeUk9vTPpwoWKm6jwqjHB7S2tCMLE5gjwcWQmdN8bHtg0HdI9D1GB8c+ortT3i BJZma6QePpGLjTd44yoTE35T9d64JgnB6+mBAgk0UsAcAqIbNQF+nFJhnUf68+xH5fC+EX Cj5UgUY1FK8T6lnMoVfdUTgGDJdV/K0= X-MC-Unique: wh_9vAAPMY61YOk9t3zaag-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v4 7/7] nbd: Allow export of multiple bitmaps for one device Date: Fri, 9 Oct 2020 16:55:33 -0500 Message-Id: <20201009215533.1194742-8-eblake@redhat.com> In-Reply-To: <20201009215533.1194742-1-eblake@redhat.com> References: <20201009215533.1194742-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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=63.128.21.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/09 02:34:40 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_H5=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, 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" With this, 'qemu-nbd -B b0 -B b1 -f qcow2 img.qcow2' can let you sniff out multiple bitmaps from one server. qemu-img as client can still only read one bitmap per client connection, but other NBD clients (hello libnbd) can now read multiple bitmaps in a single pass. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- nbd/server.c | 89 +++++++++++++++++++++++++++++------------- tests/qemu-iotests/291 | 6 +-- 2 files changed, 63 insertions(+), 32 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 27d943529409..8a9455627d25 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -96,7 +96,8 @@ struct NBDExport { Notifier eject_notifier; bool allocation_depth; - BdrvDirtyBitmap *export_bitmap; + BdrvDirtyBitmap **export_bitmaps; + size_t nr_export_bitmaps; }; static QTAILQ_HEAD(, NBDExport) exports =3D QTAILQ_HEAD_INITIALIZER(export= s); @@ -109,7 +110,10 @@ typedef struct NBDExportMetaContexts { size_t count; /* number of negotiated contexts */ bool base_allocation; /* export base:allocation context (block status)= */ bool allocation_depth; /* export qemu:allocation-depth */ - bool bitmap; /* export qemu:dirty-bitmap: */ + bool *bitmaps; /* + * export qemu:dirty-bitmap:, + * sized by exp->nr_export_bitmaps + */ } NBDExportMetaContexts; struct NBDClient { @@ -861,6 +865,8 @@ static bool nbd_meta_base_query(NBDClient *client, NBDE= xportMetaContexts *meta, static bool nbd_meta_qemu_query(NBDClient *client, NBDExportMetaContexts *= meta, const char *query) { + size_t i; + if (!nbd_strshift(&query, "qemu:")) { return false; } @@ -869,7 +875,7 @@ static bool nbd_meta_qemu_query(NBDClient *client, NBDE= xportMetaContexts *meta, if (!*query) { if (client->opt =3D=3D NBD_OPT_LIST_META_CONTEXT) { meta->allocation_depth =3D meta->exp->allocation_depth; - meta->bitmap =3D !!meta->exp->export_bitmap; + memset(meta->bitmaps, 1, meta->exp->nr_export_bitmaps); } trace_nbd_negotiate_meta_query_parse("empty"); return true; @@ -882,17 +888,26 @@ static bool nbd_meta_qemu_query(NBDClient *client, NB= DExportMetaContexts *meta, } if (nbd_strshift(&query, "dirty-bitmap:")) { - const char *bm_name; - trace_nbd_negotiate_meta_query_parse("dirty-bitmap:"); - if (!meta->exp->export_bitmap) { - trace_nbd_negotiate_meta_query_skip("no dirty-bitmap exported"= ); + if (!*query) { + if (client->opt =3D=3D NBD_OPT_LIST_META_CONTEXT) { + memset(meta->bitmaps, 1, meta->exp->nr_export_bitmaps); + } + trace_nbd_negotiate_meta_query_parse("empty"); return true; } - bm_name =3D bdrv_dirty_bitmap_name(meta->exp->export_bitmap); - if (nbd_meta_empty_or_pattern(client, bm_name, query)) { - meta->bitmap =3D true; + + for (i =3D 0; i < meta->exp->nr_export_bitmaps; i++) { + const char *bm_name; + + bm_name =3D bdrv_dirty_bitmap_name(meta->exp->export_bitmaps[i= ]); + if (strcmp(bm_name, query) =3D=3D 0) { + meta->bitmaps[i] =3D true; + trace_nbd_negotiate_meta_query_parse(query); + return true; + } } + trace_nbd_negotiate_meta_query_skip("no dirty-bitmap match"); return true; } @@ -954,9 +969,10 @@ static int nbd_negotiate_meta_queries(NBDClient *clien= t, { int ret; g_autofree char *export_name =3D NULL; - NBDExportMetaContexts local_meta; + g_autofree bool *bitmaps =3D NULL; + NBDExportMetaContexts local_meta =3D {0}; uint32_t nb_queries; - int i; + size_t i; size_t count =3D 0; if (!client->structured_reply) { @@ -971,6 +987,7 @@ static int nbd_negotiate_meta_queries(NBDClient *client, meta =3D &local_meta; } + g_free(meta->bitmaps); memset(meta, 0, sizeof(*meta)); ret =3D nbd_opt_read_name(client, &export_name, NULL, errp); @@ -985,6 +1002,10 @@ static int nbd_negotiate_meta_queries(NBDClient *clie= nt, return nbd_opt_drop(client, NBD_REP_ERR_UNKNOWN, errp, "export '%s' not present", sane_name); } + meta->bitmaps =3D g_new0(bool, meta->exp->nr_export_bitmaps); + if (client->opt =3D=3D NBD_OPT_LIST_META_CONTEXT) { + bitmaps =3D meta->bitmaps; + } ret =3D nbd_opt_read(client, &nb_queries, sizeof(nb_queries), false, e= rrp); if (ret <=3D 0) { @@ -998,7 +1019,7 @@ static int nbd_negotiate_meta_queries(NBDClient *clien= t, /* enable all known contexts */ meta->base_allocation =3D true; meta->allocation_depth =3D meta->exp->allocation_depth; - meta->bitmap =3D !!meta->exp->export_bitmap; + memset(meta->bitmaps, 1, meta->exp->nr_export_bitmaps); } else { for (i =3D 0; i < nb_queries; ++i) { ret =3D nbd_negotiate_meta_query(client, meta, errp); @@ -1028,13 +1049,19 @@ static int nbd_negotiate_meta_queries(NBDClient *cl= ient, count++; } - if (meta->bitmap) { - const char *bm_name =3D bdrv_dirty_bitmap_name(meta->exp->export_b= itmap); - g_autofree char *context =3D g_strdup_printf("qemu:dirty-bitmap:%s= ", - bm_name); + for (i =3D 0; i < meta->exp->nr_export_bitmaps; i++) { + const char *bm_name; + g_autofree char *context =3D NULL; + + if (!meta->bitmaps[i]) { + continue; + } + + bm_name =3D bdrv_dirty_bitmap_name(meta->exp->export_bitmaps[i]); + context =3D g_strdup_printf("qemu:dirty-bitmap:%s", bm_name); ret =3D nbd_negotiate_send_meta_context(client, context, - NBD_META_ID_DIRTY_BITMAP, + NBD_META_ID_DIRTY_BITMAP + i, errp); if (ret < 0) { return ret; @@ -1388,6 +1415,7 @@ void nbd_client_put(NBDClient *client) QTAILQ_REMOVE(&client->exp->clients, client, next); blk_exp_unref(&client->exp->common); } + g_free(client->export_meta.bitmaps); g_free(client); } } @@ -1565,11 +1593,11 @@ static int nbd_export_create(BlockExport *blk_exp, = BlockExportOptions *exp_args, } exp->size =3D QEMU_ALIGN_DOWN(size, BDRV_SECTOR_SIZE); - /* 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) { + exp->nr_export_bitmaps++; } + exp->export_bitmaps =3D g_new0(BdrvDirtyBitmap *, exp->nr_export_bitma= ps); + exp->nr_export_bitmaps =3D 0; for (bitmaps =3D arg->bitmaps; bitmaps; bitmaps =3D bitmaps->next) { const char *bitmap =3D bitmaps->value; BlockDriverState *bs =3D blk_bs(blk); @@ -1605,7 +1633,7 @@ static int nbd_export_create(BlockExport *blk_exp, Bl= ockExportOptions *exp_args, } bdrv_dirty_bitmap_set_busy(bm, true); - exp->export_bitmap =3D bm; + exp->export_bitmaps[exp->nr_export_bitmaps++] =3D bm; assert(strlen(bitmap) <=3D BDRV_BITMAP_MAX_NAME_SIZE); } @@ -1667,6 +1695,7 @@ static void nbd_export_request_shutdown(BlockExport *= blk_exp) static void nbd_export_delete(BlockExport *blk_exp) { + size_t i; NBDExport *exp =3D container_of(blk_exp, NBDExport, common); assert(exp->name =3D=3D NULL); @@ -1684,8 +1713,8 @@ static void nbd_export_delete(BlockExport *blk_exp) blk_aio_detach, exp); } - if (exp->export_bitmap) { - bdrv_dirty_bitmap_set_busy(exp->export_bitmap, false); + for (i =3D 0; i < exp->nr_export_bitmaps; i++) { + bdrv_dirty_bitmap_set_busy(exp->export_bitmaps[i], false); } } @@ -2332,6 +2361,7 @@ static coroutine_fn int nbd_handle_request(NBDClient = *client, int flags; NBDExport *exp =3D client->exp; char *msg; + size_t i; switch (request->type) { case NBD_CMD_CACHE: @@ -2435,12 +2465,15 @@ static coroutine_fn int nbd_handle_request(NBDClien= t *client, } } - if (client->export_meta.bitmap) { + for (i =3D 0; i < client->exp->nr_export_bitmaps; i++) { + if (!client->export_meta.bitmaps[i]) { + continue; + } ret =3D nbd_co_send_bitmap(client, request->handle, - client->exp->export_bitmap, + client->exp->export_bitmaps[i], request->from, request->len, dont_fragment, !--contexts_remain= ing, - NBD_META_ID_DIRTY_BITMAP, errp); + NBD_META_ID_DIRTY_BITMAP + i, err= p); if (ret < 0) { return ret; } diff --git a/tests/qemu-iotests/291 b/tests/qemu-iotests/291 index 4f837b205655..37848ac60bba 100755 --- a/tests/qemu-iotests/291 +++ b/tests/qemu-iotests/291 @@ -107,16 +107,14 @@ echo # x-dirty-bitmap is a hack for reading bitmaps; it abuses block status to # report "data":false for portions of the bitmap which are set IMG=3D"driver=3Dnbd,server.type=3Dunix,server.path=3D$nbd_unix_socket" -nbd_server_start_unix_socket -r -f qcow2 -B b0 "$TEST_IMG" +nbd_server_start_unix_socket -r -f qcow2 \ + -B b0 -B b1 -B b2 -B b3 "$TEST_IMG" $QEMU_IMG map --output=3Djson --image-opts \ "$IMG,x-dirty-bitmap=3Dqemu:dirty-bitmap:b0" | _filter_qemu_img_map -nbd_server_start_unix_socket -r -f qcow2 -B b1 "$TEST_IMG" $QEMU_IMG map --output=3Djson --image-opts \ "$IMG,x-dirty-bitmap=3Dqemu:dirty-bitmap:b1" | _filter_qemu_img_map -nbd_server_start_unix_socket -r -f qcow2 -B b2 "$TEST_IMG" $QEMU_IMG map --output=3Djson --image-opts \ "$IMG,x-dirty-bitmap=3Dqemu:dirty-bitmap:b2" | _filter_qemu_img_map -nbd_server_start_unix_socket -r -f qcow2 -B b3 "$TEST_IMG" $QEMU_IMG map --output=3Djson --image-opts \ "$IMG,x-dirty-bitmap=3Dqemu:dirty-bitmap:b3" | _filter_qemu_img_map --=20 2.28.0