From nobody Tue Oct 22 23:32:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1692005885; cv=none; d=zohomail.com; s=zohoarc; b=gnOW5bT5R+0iXXVdasuT3ORU9CMjxHM8BCeWa9vehEVzchgKDKeLMsr0sorV5pIlIOKipas56QvcftADc4b35IzrdcsnLcM26fQpIejHx3h1YftPRXSi16ac43xRNIDHx3bkWM8Gt30Tgr+97I79AefqCuFjFVGJlcTE5ol3Mds= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692005885; 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=4vYM7ubAgPfJMOpCXt3DOj7H5fYnf/YWyzdLMJCx8Po=; b=Kq9wchuvAUpISw4GL6rzGSbMIjhbaP1F3dT4aIU+v2FZmnYPAVMx+fCk5OQM3jxFLTVOq5L9bdzaBQINdZT9mvxRha8EN8xgSo1MZBWg54FkrInP75hnn3meaYX/B0WDsm5aZDRU33pJHSnK6W527sdIq/JvVfvIz1qpygWbp8o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1692005885729404.07121862287306; Mon, 14 Aug 2023 02:38:05 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-639-6PS3p5v0Pf2v5jTfVWAxyQ-1; Mon, 14 Aug 2023 05:36:47 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2701C80D0BB; Mon, 14 Aug 2023 09:36:44 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id E5748403169; Mon, 14 Aug 2023 09:36:43 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id A34701946A7E; Mon, 14 Aug 2023 09:36:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 9821E19465A3 for ; Mon, 14 Aug 2023 09:36:37 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id CC9E140C2073; Mon, 14 Aug 2023 09:36:27 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.45.226.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6EFE640C207F for ; Mon, 14 Aug 2023 09:36:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692005884; 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=4vYM7ubAgPfJMOpCXt3DOj7H5fYnf/YWyzdLMJCx8Po=; b=S5jFNieZe11OIWhikdKX+uABDhP4RQ7kwuTFEEg9ZfM6d/Xe+9vF2zKxPsoO/eKg29UXws 0wxdAy3RQpTvnKVO8EUIoIJhY46ovtq7giV9uI3wIs+gkCBXIBcXVrpL5hJ/k5FHiUbXgl 3nDCOLJbxQkoAXSOGhnufjMyETYsMi4= X-MC-Unique: 6PS3p5v0Pf2v5jTfVWAxyQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v3 15/25] qemu_snapshot: add merge to external snapshot delete prepare data Date: Mon, 14 Aug 2023 11:36:07 +0200 Message-ID: <3b37dacf66a01a39a27624dfc331002df0402c03.1692005543.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1692005887170100003 Content-Type: text/plain; charset="utf-8"; x-default="true" Before external snapshot revert every delete operation did block commit in order to delete a snapshot. But now when user reverts to non-leaf snapshot deleting leaf snapshot will not have any overlay files so we can just simply delete the snapshot images. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/qemu/qemu_snapshot.c | 84 +++++++++++++++++++++++++--------------- 1 file changed, 52 insertions(+), 32 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index c3d17b4cee..d47dc72709 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -2622,9 +2622,26 @@ qemuSnapshotFindParentSnapForDisk(virDomainMomentObj= *snap, } =20 =20 +/** + * qemuSnapshotDeleteExternalPrepareData: + * @vm: domain object + * @snap: snapshot object + * @merge: whether we are just deleting image or not + * @externalData: prepared data to delete external snapshot + * + * Validate if we can delete selected snapshot @snap and prepare all neces= sary + * data that will be used when deleting snapshot as @externalData. + * + * If @merge is set to true we will merge the deleted snapshot into parent= one + * instead of just deleting it. This is necessary when operating on snapsh= ot + * that has existing overlay files. + * + * Returns -1 on error, 0 on success. + */ static int qemuSnapshotDeleteExternalPrepareData(virDomainObj *vm, virDomainMomentObj *snap, + bool merge, GSList **externalData) { ssize_t i; @@ -2648,10 +2665,6 @@ qemuSnapshotDeleteExternalPrepareData(virDomainObj *= vm, data =3D g_new0(qemuSnapshotDeleteExternalData, 1); data->snapDisk =3D snapDisk; =20 - data->domDisk =3D qemuDomainDiskByName(vm->def, snapDisk->name); - if (!data->domDisk) - return -1; - data->parentDomDisk =3D virDomainDiskByTarget(snapdef->parent.dom, data->snapDisk->name); if (!data->parentDomDisk) { @@ -2661,39 +2674,46 @@ qemuSnapshotDeleteExternalPrepareData(virDomainObj = *vm, return -1; } =20 - if (virDomainObjIsActive(vm)) { - data->diskSrc =3D virStorageSourceChainLookupBySource(data->do= mDisk->src, - data->snap= Disk->src, - &data->pre= vDiskSrc); - if (!data->diskSrc) + if (merge) { + data->domDisk =3D qemuDomainDiskByName(vm->def, snapDisk->name= ); + if (!data->domDisk) return -1; =20 - if (!virStorageSourceIsSameLocation(data->diskSrc, data->snapD= isk->src)) { - virReportError(VIR_ERR_OPERATION_FAILED, "%s", - _("VM disk source and snapshot disk source = are not the same")); - return -1; - } + if (virDomainObjIsActive(vm)) { + data->diskSrc =3D virStorageSourceChainLookupBySource(data= ->domDisk->src, + data->= snapDisk->src, + &data-= >prevDiskSrc); + if (!data->diskSrc) + return -1; =20 - data->parentDiskSrc =3D data->diskSrc->backingStore; - if (!virStorageSourceIsBacking(data->parentDiskSrc)) { - virReportError(VIR_ERR_OPERATION_FAILED, "%s", - _("failed to find parent disk source in bac= king chain")); - return -1; - } + if (!virStorageSourceIsSameLocation(data->diskSrc, data->s= napDisk->src)) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("VM disk source and snapshot disk sou= rce are not the same")); + return -1; + } =20 - if (!virStorageSourceIsSameLocation(data->parentDiskSrc, data-= >parentDomDisk->src)) { - virReportError(VIR_ERR_OPERATION_FAILED, "%s", - _("snapshot VM disk source and parent disk = source are not the same")); - return -1; + data->parentDiskSrc =3D data->diskSrc->backingStore; + if (!virStorageSourceIsBacking(data->parentDiskSrc)) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("failed to find parent disk source in= backing chain")); + return -1; + } + + if (!virStorageSourceIsSameLocation(data->parentDiskSrc, + data->parentDomDisk->s= rc)) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("snapshot VM disk source and parent d= isk source are not the same")); + return -1; + } } - } =20 - data->parentSnap =3D qemuSnapshotFindParentSnapForDisk(snap, data-= >snapDisk); + data->parentSnap =3D qemuSnapshotFindParentSnapForDisk(snap, d= ata->snapDisk); =20 - if (data->parentSnap && !virDomainSnapshotIsExternal(data->parentS= nap)) { - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", - _("deleting external snapshot that has internal= snapshot as parent not supported")); - return -1; + if (data->parentSnap && !virDomainSnapshotIsExternal(data->par= entSnap)) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("deleting external snapshot that has inte= rnal snapshot as parent not supported")); + return -1; + } } =20 ret =3D g_slist_prepend(ret, g_steal_pointer(&data)); @@ -2740,7 +2760,7 @@ qemuSnapshotDeleteExternalPrepare(virDomainObj *vm, } =20 /* this also serves as validation whether the snapshot can be deleted = */ - if (qemuSnapshotDeleteExternalPrepareData(vm, snap, &tmpData) < 0) + if (qemuSnapshotDeleteExternalPrepareData(vm, snap, true, &tmpData) < = 0) return -1; =20 if (!virDomainObjIsActive(vm)) { @@ -2755,7 +2775,7 @@ qemuSnapshotDeleteExternalPrepare(virDomainObj *vm, =20 /* Call the prepare again as some data require that the VM is * running to get everything we need. */ - if (qemuSnapshotDeleteExternalPrepareData(vm, snap, externalData) = < 0) + if (qemuSnapshotDeleteExternalPrepareData(vm, snap, true, external= Data) < 0) return -1; } else { qemuDomainJobPrivate *jobPriv =3D vm->job->privateData; --=20 2.41.0