From nobody Mon Feb 9 09:43:12 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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=1613057950; cv=none; d=zohomail.com; s=zohoarc; b=lRLQqwQ3zjra0W1fGxRhKZ79PXpRH35KX1K/N7VhCtU6WM8YyFLSVhla3t9PUBimVFz+7T2VkrvRE1v6ChqgQFNYRf1xrHsoM0hmJhImWeCfJmx/xrvhBl2xli3a2wsblNw3Vu0RTU/6tbLzbTR22Pv8JVSkHLO7KEwdmEQc31E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613057950; 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=BQ1HoG146U8V8zLQ+Kd5VMgwYDySOROvXxbLzgHvUco=; b=QnOJhAvRrmmFQvNg4K3PspM/nlV3XbKkawLYCpYHoMGaBneaBfHlNENKVsdGuqak+JlrrPxMaj2N98ndOwdQuLpxLiiKmnG1XUyI8giyt7/9TdAfQO0pf5GcWJCuNE0muKkrTuRY5EVjla5XeelN/0yvUPqi2nsR/PF1saBeq9I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1613057950420744.0865119504591; Thu, 11 Feb 2021 07:39:10 -0800 (PST) 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-179-_3LYBj_4Nq-C-fvW5_3i0w-1; Thu, 11 Feb 2021 10:38:47 -0500 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 48DA9BBEE9; Thu, 11 Feb 2021 15:38:35 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2165D10013D7; Thu, 11 Feb 2021 15:38:35 +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 D9CBC18089D9; Thu, 11 Feb 2021 15:38:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 11BFcJlV019211 for ; Thu, 11 Feb 2021 10:38:19 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0218B37A0; Thu, 11 Feb 2021 15:38:19 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4E5305D74F for ; Thu, 11 Feb 2021 15:38:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613057949; 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=BQ1HoG146U8V8zLQ+Kd5VMgwYDySOROvXxbLzgHvUco=; b=ZHg2M0eXf7mvUczCkTep9fyEVvKyBQ03Sbg5ro1kv83qMZO+9oRyZUhFORMQ8bwEpt4CkG 3/mewbIVZh6s/3uuiPF+/y1mbXx6AH8TNBkhtlsqUgYzKFD3NdsNye/wKG2a8oHazhAE5U D2t6lJtU6Fjl/35QS5lR0gQY8Ga9qow= X-MC-Unique: _3LYBj_4Nq-C-fvW5_3i0w-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 13/19] qemu: migration_cookie: Add helpers for transforming the cookie into migration params Date: Thu, 11 Feb 2021 16:37:52 +0100 Message-Id: <1ab1553733cf2218104508727668cf501e317970.1613057278.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com 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" 'qemuMigrationCookieBlockDirtyBitmapsMatchDisks' maps the bitmaps from the migration cookie to actual disk objects definition pointers. 'qemuMigrationCookieBlockDirtyBitmapsToParams' converts the bitmap definitions from the migration cookie into parameters for the 'block-bitmap-mapping' migration parameter. Signed-off-by: Peter Krempa Reviewed-by: Jiri Denemark --- src/qemu/qemu_migration_cookie.c | 115 +++++++++++++++++++++++++++++++ src/qemu/qemu_migration_cookie.h | 7 ++ 2 files changed, 122 insertions(+) diff --git a/src/qemu/qemu_migration_cookie.c b/src/qemu/qemu_migration_coo= kie.c index 94ba9c83d0..ffb7533b6a 100644 --- a/src/qemu/qemu_migration_cookie.c +++ b/src/qemu/qemu_migration_cookie.c @@ -1568,3 +1568,118 @@ qemuMigrationCookieParse(virQEMUDriverPtr driver, return g_steal_pointer(&mig); } + + +/** + * qemuMigrationCookieBlockDirtyBitmapsMatchDisks: + * @def: domain definition + * @disks: list of qemuMigrationBlockDirtyBitmapsDiskPtr + * + * Matches all of the @disks to the actual domain disk definition objects + * by looking up the target. + */ +int +qemuMigrationCookieBlockDirtyBitmapsMatchDisks(virDomainDefPtr def, + GSList *disks) +{ + GSList *next; + + for (next =3D disks; next; next =3D next->next) { + qemuMigrationBlockDirtyBitmapsDiskPtr disk =3D next->data; + + if (!(disk->disk =3D virDomainDiskByTarget(def, disk->target))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Can't find disk '%s' in domain definition"), + disk->target); + return -1; + } + + disk->nodename =3D disk->disk->src->nodeformat; + } + + return 0; +} + + +/** + * qemuMigrationCookieBlockDirtyBitmapsToParams: + * @disks: list of qemuMigrationBlockDirtyBitmapsDisk + * @mapping: filled with resulting mapping + * + * Converts @disks into the arguments for 'block-bitmap-mapping' migration + * parameter. + */ +int +qemuMigrationCookieBlockDirtyBitmapsToParams(GSList *disks, + virJSONValuePtr *mapping) +{ + g_autoptr(virJSONValue) map =3D virJSONValueNewArray(); + bool hasDisks =3D false; + GSList *nextdisk; + + for (nextdisk =3D disks; nextdisk; nextdisk =3D nextdisk->next) { + qemuMigrationBlockDirtyBitmapsDiskPtr disk =3D nextdisk->data; + g_autoptr(virJSONValue) jsondisk =3D NULL; + g_autoptr(virJSONValue) jsonbitmaps =3D virJSONValueNewArray(); + bool hasBitmaps =3D false; + GSList *nextbitmap; + + if (disk->skip || !disk->bitmaps) + continue; + + for (nextbitmap =3D disk->bitmaps; nextbitmap; nextbitmap =3D next= bitmap->next) { + qemuMigrationBlockDirtyBitmapsDiskBitmapPtr bitmap =3D nextbit= map->data; + g_autoptr(virJSONValue) jsonbitmap =3D NULL; + g_autoptr(virJSONValue) transform =3D NULL; + const char *bitmapname =3D bitmap->sourcebitmap; + + if (bitmap->skip) + continue; + + /* if there isn't an override, use the real name */ + if (!bitmapname) + bitmapname =3D bitmap->bitmapname; + + if (bitmap->persistent =3D=3D VIR_TRISTATE_BOOL_YES) { + if (virJSONValueObjectCreate(&transform, + "b:persistent", true, NULL) <= 0) + return -1; + } + + if (virJSONValueObjectCreate(&jsonbitmap, + "s:name", bitmapname, + "s:alias", bitmap->alias, + "A:transform", &transform, + NULL) < 0) + return -1; + + if (virJSONValueArrayAppend(jsonbitmaps, jsonbitmap) < 0) + return -1; + + jsonbitmap =3D NULL; + hasBitmaps =3D true; + } + + if (!hasBitmaps) + continue; + + if (virJSONValueObjectCreate(&jsondisk, + "s:node-name", disk->nodename, + "s:alias", disk->target, + "a:bitmaps", &jsonbitmaps, + NULL) < 0) + return -1; + + if (virJSONValueArrayAppend(map, jsondisk) < 0) + return -1; + + jsondisk =3D NULL; + hasDisks =3D true; + } + + if (!hasDisks) + return 0; + + *mapping =3D g_steal_pointer(&map); + return 0; +} diff --git a/src/qemu/qemu_migration_cookie.h b/src/qemu/qemu_migration_coo= kie.h index 8636f955da..f8393e0ce0 100644 --- a/src/qemu/qemu_migration_cookie.h +++ b/src/qemu/qemu_migration_cookie.h @@ -226,3 +226,10 @@ qemuMigrationCookieXMLFormat(virQEMUDriverPtr driver, virQEMUCapsPtr qemuCaps, virBufferPtr buf, qemuMigrationCookiePtr mig); + +int qemuMigrationCookieBlockDirtyBitmapsMatchDisks(virDomainDefPtr def, + GSList *disks); + +int +qemuMigrationCookieBlockDirtyBitmapsToParams(GSList *disks, + virJSONValuePtr *mapping); --=20 2.29.2