From nobody Thu Dec 18 14:17:31 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1743773494; cv=none; d=zohomail.com; s=zohoarc; b=N590VEOpIgY1zoS5lEfAyQhuvKwTDoAxqP8e9JqcntvEO0zL7V0tXksN9lh4jv/CFeE1IhsXhZ+Df41ck2RjpWlXf7f9Ps0C2b1WJifGglGSWVb+sIYe8kcQqfhPOW9TFk2mTCqgZkU7A8WsGbWjIeCE8OkgizpPRdPQ/SD8bVs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1743773494; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=z14KI++fXbIyjdyO3i6arBx4MXJ9YK5buuNoxXPdq7g=; b=WpwPDU/iwjcIGlwz0og5Tiy/9KjllPOL0DuZtxxxZ3E12PGqW8iRo2syu7zMQa2zEhH6UylJJ6aMdVzrnxPYcWj8N7/Er6AllGYp+6+Pmj1OY+NhEXTwM8HefwEYkibLIqNF+pz8Mg4BiwFsrDTXAwnK6P2yhK11uD6ZO4jDVuY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1743773494340730.9971918748056; Fri, 4 Apr 2025 06:31:34 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id B5A05CA9; Fri, 4 Apr 2025 09:31:33 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 1569F15F0; Fri, 4 Apr 2025 09:28:27 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 53B2D12BB; Fri, 4 Apr 2025 09:28:22 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id CF58815BC for ; Fri, 4 Apr 2025 09:28:12 -0400 (EDT) Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-212-8koNFYXvMCm3x9H_du89Bg-1; Fri, 04 Apr 2025 09:28:11 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7A3B1195608F for ; Fri, 4 Apr 2025 13:28:10 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.3.236]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C3AB41955BC7 for ; Fri, 4 Apr 2025 13:28:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1743773292; h=from:from: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; bh=Gne21kRB94J5X1E6pL3snzP6sLJh5P14NqHLTs/YIvA=; b=FMZlh6WM53gFFRV3C0qlJxDiSbwOppV/3rFi2c2ASR/WRWXnlQAmjMt8FUUS4TWJb/G5th 87AT26SiyW/Poaf5EpNo1DUHF3ZzHA3QeV3F2SalikKYq+vq3Xp1czyExBYYY0i7gK08QQ J608aCl1rT9Rf8KOHyEXN7Ar/zA3bZg= X-MC-Unique: 8koNFYXvMCm3x9H_du89Bg-1 X-Mimecast-MFC-AGG-ID: 8koNFYXvMCm3x9H_du89Bg_1743773290 To: devel@lists.libvirt.org Subject: [PATCH 6/8] vbox: Move parts of vboxSnapshotRedefine() into a separate function Date: Fri, 4 Apr 2025 15:27:58 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: vFSkU9qwpR_IInpzBQJgxnnfUq6MA9E3danBZ3n2mV4_1743773290 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: VY6CVMUUCM7SEH2DJB52HUQ6CVMF3HLR X-Message-ID-Hash: VY6CVMUUCM7SEH2DJB52HUQ6CVMF3HLR X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: From: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1743773495017019000 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik There's too much happening inside of vboxSnapshotRedefine(). Not only it makes the function hard to read, but it also increases stack size of the function. Move one part into a separate function: vboxSnapshotAddRWDisks() Signed-off-by: Michal Privoznik --- src/vbox/vbox_common.c | 227 ++++++++++++++++++++++------------------- 1 file changed, 124 insertions(+), 103 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index e5490304d8..9ed972e52e 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -4782,6 +4782,127 @@ vboxSnapshotAddDisksToMediaRegistry(struct _vboxDri= ver *data, } =20 =20 +static int +vboxSnapshotAddRWDisks(struct _vboxDriver *data, + virDomainSnapshotDef *def, + virVBoxSnapshotConfMachine *snapshotMachineDesc, + bool needToChangeStorageController) +{ + int it =3D 0; + + for (it =3D 0; it < def->ndisks; it++) { + IMedium *medium =3D NULL; + PRUnichar *locationUtf16 =3D NULL; + virVBoxSnapshotConfHardDisk *disk =3D NULL; + PRUnichar *formatUtf16 =3D NULL; + char *format =3D NULL; + char *uuid =3D NULL; + IMedium *parentDisk =3D NULL; + char *parentUuid =3D NULL; + vboxIID iid, parentiid; + nsresult rc; + + VBOX_IID_INITIALIZE(&iid); + VBOX_IID_INITIALIZE(&parentiid); + VBOX_UTF8_TO_UTF16(def->disks[it].src->path, &locationUtf16); + rc =3D gVBoxAPI.UIVirtualBox.OpenMedium(data->vboxObj, + locationUtf16, + DeviceType_HardDisk, + AccessMode_ReadWrite, + &medium); + if (NS_FAILED(rc)) { + vboxReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unable to open HardDisk")); + return -1; + } + VBOX_UTF16_FREE(locationUtf16); + + disk =3D g_new0(virVBoxSnapshotConfHardDisk, 1); + + rc =3D gVBoxAPI.UIMedium.GetFormat(medium, &formatUtf16); + if (NS_FAILED(rc)) { + vboxReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unable to get disk format")); + VIR_FREE(disk); + return -1; + } + + VBOX_UTF16_TO_UTF8(formatUtf16, &format); + disk->format =3D format; + VBOX_UTF16_FREE(formatUtf16); + + disk->location =3D g_strdup(def->disks[it].src->path); + + rc =3D gVBoxAPI.UIMedium.GetId(medium, &iid); + if (NS_FAILED(rc)) { + vboxReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unable to get disk uuid")); + VIR_FREE(disk); + return -1; + } + gVBoxAPI.UIID.vboxIIDToUtf8(data, &iid, &uuid); + disk->uuid =3D uuid; + vboxIIDUnalloc(&iid); + + rc =3D gVBoxAPI.UIMedium.GetParent(medium, &parentDisk); + if (NS_FAILED(rc)) { + vboxReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unable to get disk parent")); + VIR_FREE(disk); + return -1; + } + + gVBoxAPI.UIMedium.GetId(parentDisk, &parentiid); + gVBoxAPI.UIID.vboxIIDToUtf8(data, &parentiid, &parentUuid); + vboxIIDUnalloc(&parentiid); + if (virVBoxSnapshotConfAddHardDiskToMediaRegistry(disk, + snapshotMachineD= esc->mediaRegistry, + parentUuid) < 0)= { + vboxReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unable to add hard disk to the media regist= ry")); + VIR_FREE(disk); + return -1; + } + + if (needToChangeStorageController) { + /* We need to append this disk in the storage controller */ + g_auto(GStrv) searchResultTab =3D NULL; + char *tmp =3D NULL; + ssize_t resultSize =3D 0; + + resultSize =3D virStringSearch(snapshotMachineDesc->storageCon= troller, + VBOX_UUID_REGEX, + it + 1, + &searchResultTab); + if (resultSize !=3D it + 1) { + vboxReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to find UUID %1$s"), searchResul= tTab[it]); + return -1; + } + + tmp =3D virStringReplace(snapshotMachineDesc->storageControlle= r, + searchResultTab[it], + disk->uuid); + VIR_FREE(snapshotMachineDesc->storageController); + if (!tmp) + return -1; + snapshotMachineDesc->storageController =3D g_strdup(tmp); + + VIR_FREE(tmp); + } + /* Close disk */ + rc =3D gVBoxAPI.UIMedium.Close(medium); + if (NS_FAILED(rc)) { + vboxReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unable to close HardDisk")); + return -1; + } + } + + return 0; +} + + static int vboxSnapshotRedefine(virDomainPtr dom, virDomainSnapshotDef *def, @@ -5097,109 +5218,9 @@ vboxSnapshotRedefine(virDomainPtr dom, * If the snapshot to redefine is the current snapshot, we add rea= d-write disks in * the machine storage controllers. */ - for (it =3D 0; it < def->ndisks; it++) { - IMedium *medium =3D NULL; - PRUnichar *locationUtf16 =3D NULL; - virVBoxSnapshotConfHardDisk *disk =3D NULL; - PRUnichar *formatUtf16 =3D NULL; - char *format =3D NULL; - char *uuid =3D NULL; - IMedium *parentDisk =3D NULL; - char *parentUuid =3D NULL; - vboxIID iid, parentiid; - - VBOX_IID_INITIALIZE(&iid); - VBOX_IID_INITIALIZE(&parentiid); - VBOX_UTF8_TO_UTF16(def->disks[it].src->path, &locationUtf16); - rc =3D gVBoxAPI.UIVirtualBox.OpenMedium(data->vboxObj, - locationUtf16, - DeviceType_HardDisk, - AccessMode_ReadWrite, - &medium); - if (NS_FAILED(rc)) { - vboxReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Unable to open HardDisk")); - goto cleanup; - } - VBOX_UTF16_FREE(locationUtf16); - - disk =3D g_new0(virVBoxSnapshotConfHardDisk, 1); - - rc =3D gVBoxAPI.UIMedium.GetFormat(medium, &formatUtf16); - if (NS_FAILED(rc)) { - vboxReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Unable to get disk format")); - VIR_FREE(disk); - goto cleanup; - } - - VBOX_UTF16_TO_UTF8(formatUtf16, &format); - disk->format =3D format; - VBOX_UTF16_FREE(formatUtf16); - - disk->location =3D g_strdup(def->disks[it].src->path); - - rc =3D gVBoxAPI.UIMedium.GetId(medium, &iid); - if (NS_FAILED(rc)) { - vboxReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Unable to get disk uuid")); - VIR_FREE(disk); - goto cleanup; - } - gVBoxAPI.UIID.vboxIIDToUtf8(data, &iid, &uuid); - disk->uuid =3D uuid; - vboxIIDUnalloc(&iid); - - rc =3D gVBoxAPI.UIMedium.GetParent(medium, &parentDisk); - if (NS_FAILED(rc)) { - vboxReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Unable to get disk parent")); - VIR_FREE(disk); - goto cleanup; - } - - gVBoxAPI.UIMedium.GetId(parentDisk, &parentiid); - gVBoxAPI.UIID.vboxIIDToUtf8(data, &parentiid, &parentUuid); - vboxIIDUnalloc(&parentiid); - if (virVBoxSnapshotConfAddHardDiskToMediaRegistry(disk, - snapshotMachineDesc->mediaRegis= try, - parentUuid) < 0) { - vboxReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Unable to add hard disk to the media re= gistry")); - VIR_FREE(disk); - goto cleanup; - } - - if (needToChangeStorageController) { - /* We need to append this disk in the storage controller */ - char *tmp =3D NULL; - resultSize =3D virStringSearch(snapshotMachineDesc->storag= eController, - VBOX_UUID_REGEX, - it + 1, - &searchResultTab); - if (resultSize !=3D it + 1) { - vboxReportError(VIR_ERR_INTERNAL_ERROR, - _("Unable to find UUID %1$s"), searchR= esultTab[it]); - goto cleanup; - } - - tmp =3D virStringReplace(snapshotMachineDesc->storageContr= oller, - searchResultTab[it], - disk->uuid); - VIR_FREE(snapshotMachineDesc->storageController); - if (!tmp) - goto cleanup; - snapshotMachineDesc->storageController =3D g_strdup(tmp); - - VIR_FREE(tmp); - } - /* Close disk */ - rc =3D gVBoxAPI.UIMedium.Close(medium); - if (NS_FAILED(rc)) { - vboxReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Unable to close HardDisk")); - goto cleanup; - } + if (vboxSnapshotAddRWDisks(data, def, snapshotMachineDesc, + needToChangeStorageController) < 0) { + goto cleanup; } } else { char *snapshotContent; --=20 2.49.0