From nobody Tue Dec 23 08:52:56 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1592241079; cv=none; d=zohomail.com; s=zohoarc; b=Q9d2Vqg9GgC89pxRwMfP2tl7s1Ze592/tH7Pyw18KdA/Wld81WGd/UzLqoKrzyH0oaG9mLel//rtS6I22aC1JaBoJZMOO+h52lFtJz7soi16Y9LVHQmtC4Xh7+K4+gfY66dFvp/oemx1/a4ndw5r04ESSvQXXo9adrgEULvd93I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592241079; h=Content-Type:Content-Transfer-Encoding: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=/2tEbsgoZKyhkql32exhSa3fBEOluNdA3DQIEA3o+/s=; b=PnUFDJ9A5dwHDlkWiXV9EGUIJPtI1SyMQk3D4i77LRlXXLZ0RAGpFi1cy6CEOYJKFM3lD55/0UG7GqgWCD1NtHToRx51InHzL7ilmVhdRFRXCaR4G+/Ye0tyKIFYtzKj0+kmD8aGWM6d6hECaex10s98QEo+17BabGWKuGt2LmY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1592241079687349.00018033682124; Mon, 15 Jun 2020 10:11:19 -0700 (PDT) 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-483-4_s2baPeP-2vsSu45RPXoQ-1; Mon, 15 Jun 2020 13:11:08 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2386F1138320; Mon, 15 Jun 2020 17:11:02 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 03C105D9D5; Mon, 15 Jun 2020 17:11:02 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id C828FB349D; Mon, 15 Jun 2020 17:11:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 05FHArCW004897 for ; Mon, 15 Jun 2020 13:10:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id BE7A5100164D; Mon, 15 Jun 2020 17:10:53 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id 37D43100238C for ; Mon, 15 Jun 2020 17:10:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592241078; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=/2tEbsgoZKyhkql32exhSa3fBEOluNdA3DQIEA3o+/s=; b=HAZAVzKBqwINzYuCZFzbteXwbB9d4HjJfz+laf8A7fxsD3+0EhebHhzJKGTycoE4azwZZg zcvglwCFNczNbDi/udmFMFBLdvw74e2u9fqCX75dLcAKaCvobvcGPfKElzsyeFu9mRXFRN i9mnvL5m3AQBM6Q6iQq3tYGoIdAXpyc= X-MC-Unique: 4_s2baPeP-2vsSu45RPXoQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 22/32] qemu: block: Add universal helper for merging dirty bitmaps for all scenarios Date: Mon, 15 Jun 2020 19:10:09 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Add a function which allows to merge bitmaps according to the new semantics and will allow to replace all the specific ad-hoc functions currently in use for 'backup', 'block commit', 'block copy' and will also be usable in the future for 'block pull' and non-shared storage migration. The semantics are a bit quirky for the 'backup' case but these quirks are documented and will prevent us from having two slightly different algorithms. Signed-off-by: Peter Krempa Reviewed-by: Eric Blake --- src/qemu/qemu_block.c | 172 ++++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_block.h | 10 +++ 2 files changed, 182 insertions(+) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 83e3df9601..86f8410ce7 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -2847,6 +2847,178 @@ qemuBlockGetNamedNodeData(virDomainObjPtr vm, } +/** + * qemuBlockGetBitmapMergeActionsGetBitmaps: + * + * Collect a list of bitmaps which need to be handled in + * qemuBlockGetBitmapMergeActions. The list contains only valid bitmaps in= the + * sub-chain which is being processed. + * + * Note that the returned GSList contains bitmap names string pointers bor= rowed + * from @blockNamedNodeData so they must not be freed. + */ +static GSList * +qemuBlockGetBitmapMergeActionsGetBitmaps(virStorageSourcePtr topsrc, + const char *bitmapname, + virHashTablePtr blockNamedNodeDat= a) +{ + g_autoptr(GSList) ret =3D NULL; + qemuBlockNamedNodeDataPtr entry; + size_t i; + + /* for now it doesn't make sense to consider bitmaps which are not pre= sent + * in @topsrc as we can't recreate a bitmap for a layer if it's missin= g */ + + if (!(entry =3D virHashLookup(blockNamedNodeData, topsrc->nodeformat))) + return NULL; + + for (i =3D 0; i < entry->nbitmaps; i++) { + qemuBlockNamedNodeDataBitmapPtr bitmap =3D entry->bitmaps[i]; + + if (bitmapname && + STRNEQ(bitmapname, bitmap->name)) + continue; + + if (!qemuBlockBitmapChainIsValid(topsrc, bitmap->name, blockNamedN= odeData)) + continue; + + ret =3D g_slist_prepend(ret, bitmap->name); + } + + return g_steal_pointer(&ret); +} + + +/** + * qemuBlockGetBitmapMergeActions: + * @topsrc: top of the chain to merge bitmaps in + * @basesrc: bottom of the chain to merge bitmaps in (NULL for full chain) + * @target: destination storage source of the merge (may be part of origin= al chain) + * @bitmapname: name of bitmap to perform the merge (NULL for all bitmaps) + * @dstbitmapname: name of destination bitmap of the merge (see below for = caveats) + * @writebitmapsrc: storage source corresponding to the node containing th= e write temporary bitmap + * @actions: returns actions for a 'transaction' QMP command for executing= the merge + * @blockNamedNodeData: hash table filled with qemuBlockNamedNodeData + * + * Calculate handling of dirty block bitmaps between @topsrc and @basesrc.= If + * @basesrc is NULL the end of the chain is considered. @target is the des= tination + * storage source definition of the merge and may or may not be part of the + * merged chain. + * + * Specifically the merging algorithm ensures that each considered bitmap = is + * merged with the appropriate bitmaps so that it properly describes + * the state of dirty blocks when looked at from @topsrc based on the depth + * of the backing chain where the bitmap is placed. + * + * If @bitmapname is non-NULL only bitmaps with that name are handled, oth= erwise + * all bitmaps are considered. + * + * If @dstbitmap is non-NULL everything is merged into a bitmap with that = name, + * otherwise each bitmap is merged into a bitmap with the same name into @= target. + * Additionally if @dstbitmap is non-NULL the target bitmap is created as = 'inactive' + * and 'transient' as a special case for the backup operation. + * + * If @writebitmapsrc is non-NULL, the 'libvirt-tmp-activewrite' bitmap fr= om + * given node is merged along with others. This bitmap corresponds to the = writes + * which occured between an active layer job finished and the rest of the = bitmap + * merging. + * + * If the bitmap is not valid somehow (see qemuBlockBitmapChainIsValid) gi= ven + * bitmap is silently skipped, so callers must ensure that given bitmap is= valid + * if they care about it. + * + * The resulting 'transacion' QMP command actions are filled in and return= ed via + * @actions. + * + * Note that @actions may be NULL if no merging is required. + */ +int +qemuBlockGetBitmapMergeActions(virStorageSourcePtr topsrc, + virStorageSourcePtr basesrc, + virStorageSourcePtr target, + const char *bitmapname, + const char *dstbitmapname, + virStorageSourcePtr writebitmapsrc, + virJSONValuePtr *actions, + virHashTablePtr blockNamedNodeData) +{ + g_autoptr(virJSONValue) act =3D virJSONValueNewArray(); + virStorageSourcePtr n; + + g_autoptr(GSList) bitmaps =3D NULL; + GSList *next; + + if (!(bitmaps =3D qemuBlockGetBitmapMergeActionsGetBitmaps(topsrc, bit= mapname, + blockNamedNod= eData))) + return 0; + + for (next =3D bitmaps; next; next =3D next->next) { + const char *curbitmap =3D next->data; + const char *mergebitmapname =3D dstbitmapname; + bool mergebitmappersistent =3D false; + bool mergebitmapdisabled =3D true; + g_autoptr(virJSONValue) merge =3D virJSONValueNewArray(); + unsigned long long granularity =3D 0; + qemuBlockNamedNodeDataBitmapPtr bitmap; + + /* explicitly named destinations mean that we want a temporary + * disabled bitmap only, so undo the default for non-explicit case= s */ + if (!mergebitmapname) { + mergebitmapname =3D curbitmap; + mergebitmappersistent =3D true; + mergebitmapdisabled =3D false; + } + + for (n =3D topsrc; virStorageSourceIsBacking(n) && n !=3D basesrc;= n =3D n->backingStore) { + if (!(bitmap =3D qemuBlockNamedNodeDataGetBitmapByName(blockNa= medNodeData, + n, curbit= map))) + continue; + + if (granularity =3D=3D 0) + granularity =3D bitmap->granularity; + + if (qemuMonitorTransactionBitmapMergeSourceAddBitmap(merge, + n->nodefo= rmat, + bitmap->n= ame) < 0) + return -1; + } + + if (dstbitmapname || + !(bitmap =3D qemuBlockNamedNodeDataGetBitmapByName(blockNamedN= odeData, + target, curbi= tmap))) { + + if (qemuMonitorTransactionBitmapAdd(act, + target->nodeformat, + mergebitmapname, + mergebitmappersistent, + mergebitmapdisabled, + granularity) < 0) + return -1; + } + + if (writebitmapsrc && + qemuMonitorTransactionBitmapMergeSourceAddBitmap(merge, + writebitmapsr= c->nodeformat, + "libvirt-tmp-= activewrite") < 0) + return -1; + + if (qemuMonitorTransactionBitmapMerge(act, target->nodeformat, + mergebitmapname, &merge) < 0) + return -1; + } + + if (writebitmapsrc && + qemuMonitorTransactionBitmapRemove(act, writebitmapsrc->nodeformat, + "libvirt-tmp-activewrite") < 0) + return -1; + + if (virJSONValueArraySize(act) > 0) + *actions =3D g_steal_pointer(&act); + + return 0; +} + + /** * qemuBlockBitmapChainIsValid: * diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h index 2ad2ce1a1f..0f5b4cfaa9 100644 --- a/src/qemu/qemu_block.h +++ b/src/qemu/qemu_block.h @@ -221,6 +221,16 @@ virHashTablePtr qemuBlockGetNamedNodeData(virDomainObjPtr vm, qemuDomainAsyncJob asyncJob); +int +qemuBlockGetBitmapMergeActions(virStorageSourcePtr topsrc, + virStorageSourcePtr basesrc, + virStorageSourcePtr target, + const char *bitmapname, + const char *dstbitmapname, + virStorageSourcePtr writebitmapsrc, + virJSONValuePtr *actions, + virHashTablePtr blockNamedNodeData); + bool qemuBlockBitmapChainIsValid(virStorageSourcePtr src, const char *bitmapname, --=20 2.26.2