From nobody Thu Dec 18 13:59:50 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=1743773539; cv=none; d=zohomail.com; s=zohoarc; b=h809HEfiaot3oGtZ797ptqoB75fxWTQAIp8vQtbha/wnKoIIT9kKuFH8Tfg1ayFRUQSJJ5MwrSzxJ8bsibOrEK0hqwmbtS6eMq7qAND6oH7am06Il/FmkqdOnvNhe09mHV2K2KPnAXZqVACwD5mdH0/wzsw2oP5uDBnq2nEnPxQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1743773539; 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=qbgKmgDN5priO2jC5joyB7Gca9TgV9XcC42yi4/TblE=; b=kpqkQqAQTl8kqadwWTGdAfhV47AO4M4PTZc4ekeVtH9175bCWB/zYSc28WunHhRU7hHNisS/1Ka/VOIUN/pGQ0ETKy2qONVK/I20phVbJlNvvMYOvfqq4rqgbGtB74862AUhDUesGm326zTKmtg3rLLoT4tMMBLXjskqRGHwk1E= 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 1743773539197573.6620074309815; Fri, 4 Apr 2025 06:32:19 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 99ADD15E9; Fri, 4 Apr 2025 09:32:18 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id C30061625; Fri, 4 Apr 2025 09:28:35 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 3857A1509; Fri, 4 Apr 2025 09:28:30 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 E330215EC for ; Fri, 4 Apr 2025 09:28:13 -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-639-eVESsBSfOhaMFRAA4iL4Hw-1; Fri, 04 Apr 2025 09:28:12 -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 990BB19560A2 for ; Fri, 4 Apr 2025 13:28:11 +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 E40441955BC2 for ; Fri, 4 Apr 2025 13:28:10 +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=1743773293; 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=EUFnoO63651k7MqXvd9DjAAjWEYjf96HhMD8cAJzY4s=; b=c0npCWJP80Tlk1fFHhOJ3/tIG1vXlVtb1Xnc1Skv/oBxz9iWdl6UpcHRdXiFMOZJcGz3qR 1z1JV4JqyBBiMCurU86zaA26kfEpT/tsZHxt8vMnBfnCumcTSgOHS5NCXJfeCxlZp6tNbh ZxivGByVbP1gkilzYYHL8bds7ZHz9n0= X-MC-Unique: eVESsBSfOhaMFRAA4iL4Hw-1 X-Mimecast-MFC-AGG-ID: eVESsBSfOhaMFRAA4iL4Hw_1743773291 To: devel@lists.libvirt.org Subject: [PATCH 7/8] vbox: Move parts of vboxSnapshotRedefine() into a separate function Date: Fri, 4 Apr 2025 15:27:59 +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: R68-QvicQ76mvLWxv8n9Dj3yrTLNbfhxJIoBmBj03Hs_1743773291 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 4SG3SEWLWUNJMR5ECRNTXR7V6DP3EHWC X-Message-ID-Hash: 4SG3SEWLWUNJMR5ECRNTXR7V6DP3EHWC 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: 1743773541401019000 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: vboxSnapshotCreateFakeDiffStorage() Signed-off-by: Michal Privoznik --- src/vbox/vbox_common.c | 288 ++++++++++++++++++++++------------------- 1 file changed, 157 insertions(+), 131 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 9ed972e52e..349ac832dc 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -4903,6 +4903,157 @@ vboxSnapshotAddRWDisks(struct _vboxDriver *data, } =20 =20 +static int +vboxSnapshotCreateFakeDiffStorage(struct _vboxDriver *data, + virDomainSnapshotDef *def, + char *machineLocationPath, + virVBoxSnapshotConfMachine *snapshotMach= ineDesc) +{ + virVBoxSnapshotConfHardDisk *newHardDisk =3D NULL; + int it; + int ret =3D -1; + + for (it =3D 0; it < def->parent.dom->ndisks; it++) { + IMedium *medium =3D NULL; + PRUnichar *locationUtf16 =3D NULL; + char *parentUuid =3D NULL; + IMedium *newMedium =3D NULL; + PRUnichar *formatUtf16 =3D NULL; + PRUnichar *newLocation =3D NULL; + char *newLocationUtf8 =3D NULL; + resultCodeUnion resultCode; + char *uuid =3D NULL; + char *format =3D NULL; + char *tmp =3D NULL; + vboxIID iid, parentiid; + IProgress *progress =3D NULL; + PRUint32 tab[1]; + nsresult rc; + g_auto(GStrv) searchResultTab =3D NULL; + ssize_t resultSize =3D 0; + + VBOX_IID_INITIALIZE(&iid); + VBOX_IID_INITIALIZE(&parentiid); + VBOX_UTF8_TO_UTF16(def->parent.dom->disks[it]->src->path, &locatio= nUtf16); + 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")); + VBOX_UTF16_FREE(locationUtf16); + goto cleanup; + } + VBOX_UTF16_FREE(locationUtf16); + + rc =3D gVBoxAPI.UIMedium.GetId(medium, &parentiid); + if (NS_FAILED(rc)) { + vboxReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unable to get hard disk id")); + goto cleanup; + } + gVBoxAPI.UIID.vboxIIDToUtf8(data, &parentiid, &parentUuid); + vboxIIDUnalloc(&parentiid); + VBOX_UTF8_TO_UTF16("VDI", &formatUtf16); + + newLocationUtf8 =3D g_strdup_printf("%sfakedisk-%d.vdi", + machineLocationPath, it); + VBOX_UTF8_TO_UTF16(newLocationUtf8, &newLocation); + rc =3D gVBoxAPI.UIVirtualBox.CreateHardDisk(data->vboxObj, + formatUtf16, + newLocation, + &newMedium); + VBOX_UTF16_FREE(newLocation); + VBOX_UTF16_FREE(formatUtf16); + if (NS_FAILED(rc)) { + vboxReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unable to create HardDisk")); + goto cleanup; + } + + tab[0] =3D MediumVariant_Diff; + gVBoxAPI.UIMedium.CreateDiffStorage(medium, newMedium, 1, tab, &pr= ogress); + + gVBoxAPI.UIProgress.WaitForCompletion(progress, -1); + gVBoxAPI.UIProgress.GetResultCode(progress, &resultCode); + if (RC_FAILED(resultCode)) { + vboxReportError(VIR_ERR_INTERNAL_ERROR, + _("Error while creating diff storage, rc=3D%1$= 08x"), + resultCode.uResultCode); + goto cleanup; + } + VBOX_RELEASE(progress); + /* + * The differential newHardDisk is created, we add it to the + * media registry and the machine storage controllers. + */ + + newHardDisk =3D g_new0(virVBoxSnapshotConfHardDisk, 1); + + rc =3D gVBoxAPI.UIMedium.GetId(newMedium, &iid); + if (NS_FAILED(rc)) { + vboxReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unable to get medium uuid")); + goto cleanup; + } + gVBoxAPI.UIID.vboxIIDToUtf8(data, &iid, &uuid); + newHardDisk->uuid =3D uuid; + vboxIIDUnalloc(&iid); + + newHardDisk->location =3D g_strdup(newLocationUtf8); + + rc =3D gVBoxAPI.UIMedium.GetFormat(newMedium, &formatUtf16); + VBOX_UTF16_TO_UTF8(formatUtf16, &format); + newHardDisk->format =3D format; + VBOX_UTF16_FREE(formatUtf16); + + if (virVBoxSnapshotConfAddHardDiskToMediaRegistry(newHardDisk, + snapshotMachineD= esc->mediaRegistry, + parentUuid) < 0)= { + vboxReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unable to add hard disk to the media regist= ry")); + goto cleanup; + } + newHardDisk =3D NULL; /* Consumed by above */ + /* Adding the fake disk to the machine storage controllers */ + + resultSize =3D virStringSearch(snapshotMachineDesc->storageControl= ler, + VBOX_UUID_REGEX, + it + 1, + &searchResultTab); + if (resultSize !=3D it + 1) { + vboxReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to find UUID %1$s"), searchResultTab= [it]); + goto cleanup; + } + + tmp =3D virStringReplace(snapshotMachineDesc->storageController, + searchResultTab[it], + uuid); + VIR_FREE(snapshotMachineDesc->storageController); + if (!tmp) + goto cleanup; + snapshotMachineDesc->storageController =3D g_strdup(tmp); + + VIR_FREE(tmp); + /* Closing the "fake" disk */ + rc =3D gVBoxAPI.UIMedium.Close(newMedium); + if (NS_FAILED(rc)) { + vboxReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unable to close the new medium")); + goto cleanup; + } + } + + ret =3D 0; + cleanup: + virVboxSnapshotConfHardDiskFree(newHardDisk); + return ret; +} + + static int vboxSnapshotRedefine(virDomainPtr dom, virDomainSnapshotDef *def, @@ -4950,7 +5101,6 @@ vboxSnapshotRedefine(virDomainPtr dom, unsigned char snapshotUuid[VIR_UUID_BUFLEN]; virVBoxSnapshotConfHardDisk **hardDiskToOpen =3D NULL; size_t hardDiskToOpenSize =3D 0; - virVBoxSnapshotConfHardDisk *newHardDisk =3D NULL; g_auto(GStrv) searchResultTab =3D NULL; ssize_t resultSize =3D 0; int it =3D 0; @@ -5224,137 +5374,14 @@ vboxSnapshotRedefine(virDomainPtr dom, } } else { char *snapshotContent; + /* Create a "fake" disk to avoid corrupting children snapshot disk= s. */ - for (it =3D 0; it < def->parent.dom->ndisks; it++) { - IMedium *medium =3D NULL; - PRUnichar *locationUtf16 =3D NULL; - char *parentUuid =3D NULL; - IMedium *newMedium =3D NULL; - PRUnichar *formatUtf16 =3D NULL; - PRUnichar *newLocation =3D NULL; - char *newLocationUtf8 =3D NULL; - resultCodeUnion resultCode; - char *uuid =3D NULL; - char *format =3D NULL; - char *tmp =3D NULL; - vboxIID iid, parentiid; - IProgress *progress =3D NULL; - PRUint32 tab[1]; - - VBOX_IID_INITIALIZE(&iid); - VBOX_IID_INITIALIZE(&parentiid); - VBOX_UTF8_TO_UTF16(def->parent.dom->disks[it]->src->path, &loc= ationUtf16); - 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")); - VBOX_UTF16_FREE(locationUtf16); - goto cleanup; - } - VBOX_UTF16_FREE(locationUtf16); - - rc =3D gVBoxAPI.UIMedium.GetId(medium, &parentiid); - if (NS_FAILED(rc)) { - vboxReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Unable to get hard disk id")); - goto cleanup; - } - gVBoxAPI.UIID.vboxIIDToUtf8(data, &parentiid, &parentUuid); - vboxIIDUnalloc(&parentiid); - VBOX_UTF8_TO_UTF16("VDI", &formatUtf16); - - newLocationUtf8 =3D g_strdup_printf("%sfakedisk-%d.vdi", - machineLocationPath, it); - VBOX_UTF8_TO_UTF16(newLocationUtf8, &newLocation); - rc =3D gVBoxAPI.UIVirtualBox.CreateHardDisk(data->vboxObj, - formatUtf16, - newLocation, - &newMedium); - VBOX_UTF16_FREE(newLocation); - VBOX_UTF16_FREE(formatUtf16); - if (NS_FAILED(rc)) { - vboxReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Unable to create HardDisk")); - goto cleanup; - } - - tab[0] =3D MediumVariant_Diff; - gVBoxAPI.UIMedium.CreateDiffStorage(medium, newMedium, 1, tab,= &progress); - - gVBoxAPI.UIProgress.WaitForCompletion(progress, -1); - gVBoxAPI.UIProgress.GetResultCode(progress, &resultCode); - if (RC_FAILED(resultCode)) { - vboxReportError(VIR_ERR_INTERNAL_ERROR, - _("Error while creating diff storage, rc= =3D%1$08x"), - resultCode.uResultCode); - goto cleanup; - } - VBOX_RELEASE(progress); - /* - * The differential newHardDisk is created, we add it to the - * media registry and the machine storage controllers. - */ - - newHardDisk =3D g_new0(virVBoxSnapshotConfHardDisk, 1); - - rc =3D gVBoxAPI.UIMedium.GetId(newMedium, &iid); - if (NS_FAILED(rc)) { - vboxReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Unable to get medium uuid")); - goto cleanup; - } - gVBoxAPI.UIID.vboxIIDToUtf8(data, &iid, &uuid); - newHardDisk->uuid =3D uuid; - vboxIIDUnalloc(&iid); - - newHardDisk->location =3D g_strdup(newLocationUtf8); - - rc =3D gVBoxAPI.UIMedium.GetFormat(newMedium, &formatUtf16); - VBOX_UTF16_TO_UTF8(formatUtf16, &format); - newHardDisk->format =3D format; - VBOX_UTF16_FREE(formatUtf16); - - if (virVBoxSnapshotConfAddHardDiskToMediaRegistry(newHardDisk, - snapshotMachineDesc->mediaRegis= try, - parentUuid) < 0) { - vboxReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Unable to add hard disk to the media re= gistry")); - goto cleanup; - } - newHardDisk =3D NULL; /* Consumed by above */ - /* Adding the fake disk to the machine storage controllers */ - - 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]); - goto cleanup; - } - - tmp =3D virStringReplace(snapshotMachineDesc->storageControlle= r, - searchResultTab[it], - uuid); - VIR_FREE(snapshotMachineDesc->storageController); - if (!tmp) - goto cleanup; - snapshotMachineDesc->storageController =3D g_strdup(tmp); - - VIR_FREE(tmp); - /* Closing the "fake" disk */ - rc =3D gVBoxAPI.UIMedium.Close(newMedium); - if (NS_FAILED(rc)) { - vboxReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Unable to close the new medium")); - goto cleanup; - } + if (vboxSnapshotCreateFakeDiffStorage(data, def, + machineLocationPath, + snapshotMachineDesc) < 0) { + goto cleanup; } + /* * We save the snapshot xml file to retrieve the real read-write d= isk during the * next define. This file is saved as "'machineLocation'/snapshot-= 'uuid'.xml" @@ -5443,7 +5470,6 @@ vboxSnapshotRedefine(virDomainPtr dom, VIR_FREE(currentSnapshotXmlFilePath); VBOX_UTF16_FREE(machineNameUtf16); VBOX_UTF8_FREE(machineName); - virVboxSnapshotConfHardDiskFree(newHardDisk); VIR_FREE(hardDiskToOpen); VIR_FREE(newSnapshotPtr); VIR_FREE(machineLocationPath); --=20 2.49.0