From nobody Sun Feb 8 22:57:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1613736008; cv=none; d=zohomail.com; s=zohoarc; b=ROJ8nB4tY+SsEi6JwRrQinp0zptLW+whwsj8T9sbcpVQW11CTja9/VLPBXG9YWfYi92xAq5A402YSOAgKPJy2FX43zpuRfB0UXHHoyKTyDLt17QrFZAU2FX62nJpPS8LD+FveL0ZI96/30KIbG65WQBUiNrJVF9e0wO9YhyhZqw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613736008; 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=ZW33DeuwDOzvUqD0oG88DBk98YwFQkUyQawFpNFA4Zw=; b=XfXL9xsqs6P/Jupd4KbCUEfmzesda+TxT+GiIKJFcglG+WdXqdBfjMsnIlHcO0C0UeLdGgaa3jY330nwbtlNJV0VlB49vx9yjwpyQ7nmRgdmTjmLT1WHkq4bR+sK4adKfI43xgG9AyHyNzAUVxvxKHcGscFUb5Se+19KTU1M7VI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1613736007701809.2622893809219; Fri, 19 Feb 2021 04:00:07 -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-189-nV8qSGgvOy6jwJoaISX60g-1; Fri, 19 Feb 2021 06:59:09 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B6CDD107ACE6; Fri, 19 Feb 2021 11:59:03 +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 8E2896085D; Fri, 19 Feb 2021 11:59:03 +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 51BA758077; Fri, 19 Feb 2021 11:59:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 11JBx2dD008459 for ; Fri, 19 Feb 2021 06:59:02 -0500 Received: by smtp.corp.redhat.com (Postfix) id 427E86085D; Fri, 19 Feb 2021 11:59:02 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id A62FE60873 for ; Fri, 19 Feb 2021 11:58:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613736005; 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=ZW33DeuwDOzvUqD0oG88DBk98YwFQkUyQawFpNFA4Zw=; b=OR09Emj6dIzp6rAezln0YttbUKnM9lW4u9ciyyDSD+FQ2epqA7Zub72yAZsUp540yeF1At DGfoT7mzNKNlATXvJN+XPQJWaLQFL7YX2o0pxARjl8vkH6qlQZa8ZUJwAyaJwbeVsbireJ mbVg7Hgwk1XUiTAErKuwVI6J2+Cybbs= X-MC-Unique: nV8qSGgvOy6jwJoaISX60g-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH v2 09/15] qemu: migration_cookie: Add helpers for transforming the cookie into migration params Date: Fri, 19 Feb 2021 12:58:21 +0100 Message-Id: <2cd5d144340fbe95ede75dfc64ba466e2f7c547f.1613735605.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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.13 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 | 8 +++ 2 files changed, 123 insertions(+) diff --git a/src/qemu/qemu_migration_cookie.c b/src/qemu/qemu_migration_coo= kie.c index 0f8555cbb0..186fe7bc9e 100644 --- a/src/qemu/qemu_migration_cookie.c +++ b/src/qemu/qemu_migration_cookie.c @@ -1580,3 +1580,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..e50dee7ba7 100644 --- a/src/qemu/qemu_migration_cookie.h +++ b/src/qemu/qemu_migration_cookie.h @@ -226,3 +226,11 @@ 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