From nobody Mon Feb 9 16:54:12 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=1606911363; cv=none; d=zohomail.com; s=zohoarc; b=AmnxlnAo3F7Xa2DJwusvwKaa1FidbD2kMn+RH2F3Ass0ps7ydM5NZt7H0sJCWXYA2mnhJFy29iay7b8Fi0pfdHVtcqhTmHLbNXfJ9urrGt8thNC8MCkA4xuxOCuoJArD0Tcr5cN+lNsYRlnbGCeuoxJ+w5PHY5UTf1MpBEWH2z8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606911363; 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=gC9vc+pMl5s2JI48te2ku0XF633ZI0atHZNfm7x2sqc=; b=L1pNyVMxkQQHqPfH7f96nez0Zxpd69pXQcgp+Xbppoce4n8PgPEY4FdijYwY5s44xbdobY7y+sXCrYUVJ/RPn6dlydcMdma8g36fIy/KTmdGeM2x8uqZGTzP+rYEUAdiThCCAt81FlWISuMexV/AKFeNlhRRCDI3pw1iaWhZg+I= 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 1606911363609462.4871498529259; Wed, 2 Dec 2020 04:16:03 -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-244-O64Is5KJNC622nQuDw0QEQ-1; Wed, 02 Dec 2020 07:15:32 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 55617805BEC; Wed, 2 Dec 2020 12:15:24 +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 341995C224; Wed, 2 Dec 2020 12:15:24 +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 F2EFA5002F; Wed, 2 Dec 2020 12:15:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B2CFLrT031899 for ; Wed, 2 Dec 2020 07:15:21 -0500 Received: by smtp.corp.redhat.com (Postfix) id D5A4E189B6; Wed, 2 Dec 2020 12:15:21 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 24BB9189A5 for ; Wed, 2 Dec 2020 12:15:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606911362; 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=gC9vc+pMl5s2JI48te2ku0XF633ZI0atHZNfm7x2sqc=; b=CxFrfXCPna5U0M9mhxVqODfFPDvR2qizXsouMG8i9g+slWXGf+j1OxRtXvaWlyr2acMdvE U8Sk1U7AUGbys+CzU9PioAzewYc0MtcN0wm8yXcvX8tMO+SPbsvPORfAg1JYZmHqCMnBxO xUyfGqDLlFtWRT+nOnvCJRBwJ4elp24= X-MC-Unique: O64Is5KJNC622nQuDw0QEQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 07/11] virDomainCheckpointAlignDisks: refactor extension to all disks Date: Wed, 2 Dec 2020 13:14:57 +0100 Message-Id: <3256daf81945e97af35e2939a298eb302381728b.1606911231.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.16 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" Similarly to d3c029bb105 where we've refactored virDomainSnapshotAlignDisks, modify the extension algorithm to avoid use of the 'idx' variable and sorting of the array. Signed-off-by: Peter Krempa --- src/conf/checkpoint_conf.c | 53 +++++++++++++++----------------------- 1 file changed, 21 insertions(+), 32 deletions(-) diff --git a/src/conf/checkpoint_conf.c b/src/conf/checkpoint_conf.c index 3213097f4f..bd0a673757 100644 --- a/src/conf/checkpoint_conf.c +++ b/src/conf/checkpoint_conf.c @@ -274,16 +274,6 @@ virDomainCheckpointDefAssignBitmapNames(virDomainCheck= pointDefPtr def) } -static int -virDomainCheckpointCompareDiskIndex(const void *a, const void *b) -{ - const virDomainCheckpointDiskDef *diska =3D a; - const virDomainCheckpointDiskDef *diskb =3D b; - - /* Integer overflow shouldn't be a problem here. */ - return diska->idx - diskb->idx; -} - /* Align def->disks to def->domain. Sort the list of def->disks, * filling in any missing disks with appropriate default. Convert * paths to disk targets for uniformity. Issue an error and return -1 @@ -293,9 +283,9 @@ int virDomainCheckpointAlignDisks(virDomainCheckpointDefPtr chkdef) { virDomainDefPtr domdef =3D chkdef->parent.dom; - g_autoptr(virBitmap) map =3D NULL; + g_autoptr(GHashTable) map =3D virHashNew(NULL); + g_autofree virDomainCheckpointDiskDefPtr olddisks =3D NULL; size_t i; - int ndisks; int checkpoint_default =3D VIR_DOMAIN_CHECKPOINT_TYPE_NONE; if (!domdef) { @@ -322,8 +312,6 @@ virDomainCheckpointAlignDisks(virDomainCheckpointDefPtr= chkdef) if (!chkdef->ndisks) checkpoint_default =3D VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP; - map =3D virBitmapNew(domdef->ndisks); - /* Double check requested disks. */ for (i =3D 0; i < chkdef->ndisks; i++) { virDomainCheckpointDiskDefPtr chkdisk =3D &chkdef->disks[i]; @@ -338,13 +326,16 @@ virDomainCheckpointAlignDisks(virDomainCheckpointDefP= tr chkdef) domdisk =3D domdef->disks[idx]; - if (virBitmapIsBitSet(map, idx)) { + if (virHashHasEntry(map, domdisk->dst)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("disk '%s' specified twice"), chkdisk->name); return -1; } + if (virHashAddEntry(map, domdisk->dst, chkdisk) < 0) + return -1; + if ((virStorageSourceIsEmpty(domdisk->src) || domdisk->src->readonly) && chkdisk->type !=3D VIR_DOMAIN_CHECKPOINT_TYPE_NONE) { @@ -353,8 +344,6 @@ virDomainCheckpointAlignDisks(virDomainCheckpointDefPtr= chkdef) chkdisk->name); return -1; } - ignore_value(virBitmapSetBit(map, idx)); - chkdisk->idx =3D idx; if (STRNEQ(chkdisk->name, domdisk->dst)) { VIR_FREE(chkdisk->name); @@ -362,32 +351,32 @@ virDomainCheckpointAlignDisks(virDomainCheckpointDefP= tr chkdef) } } - /* Provide defaults for all remaining disks. */ - ndisks =3D chkdef->ndisks; - if (VIR_EXPAND_N(chkdef->disks, chkdef->ndisks, - domdef->ndisks - chkdef->ndisks) < 0) - return -1; + olddisks =3D g_steal_pointer(&chkdef->disks); + chkdef->disks =3D g_new0(virDomainCheckpointDiskDef, domdef->ndisks); + chkdef->ndisks =3D domdef->ndisks; for (i =3D 0; i < domdef->ndisks; i++) { - virDomainCheckpointDiskDefPtr chkdisk; + virDomainDiskDefPtr domdisk =3D domdef->disks[i]; + virDomainCheckpointDiskDefPtr chkdisk =3D chkdef->disks + i; + virDomainCheckpointDiskDefPtr existing; - if (virBitmapIsBitSet(map, i)) + /* copy existing disks */ + if ((existing =3D virHashLookup(map, domdisk->dst))) { + memcpy(chkdisk, existing, sizeof(*chkdisk)); continue; - chkdisk =3D &chkdef->disks[ndisks++]; - chkdisk->name =3D g_strdup(domdef->disks[i]->dst); - chkdisk->idx =3D i; + } + + /* Provide defaults for all remaining disks. */ + chkdisk->name =3D g_strdup(domdisk->dst); /* Don't checkpoint empty or readonly drives */ - if (virStorageSourceIsEmpty(domdef->disks[i]->src) || - domdef->disks[i]->src->readonly) + if (virStorageSourceIsEmpty(domdisk->src) || + domdisk->src->readonly) chkdisk->type =3D VIR_DOMAIN_CHECKPOINT_TYPE_NONE; else chkdisk->type =3D checkpoint_default; } - qsort(&chkdef->disks[0], chkdef->ndisks, sizeof(chkdef->disks[0]), - virDomainCheckpointCompareDiskIndex); - /* Generate default bitmap names for checkpoint */ if (virDomainCheckpointDefAssignBitmapNames(chkdef) < 0) return -1; --=20 2.28.0