From nobody Fri Dec 19 06:19:48 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1687878851; cv=none; d=zohomail.com; s=zohoarc; b=nPzWVTaIs6U1jhuMQDsRddl8w7hEE7W4ARJeGYd05JQuLfCm5au/HjdSOYWwUfnUkTFFcPqwGILwriTkca8u+gwmnpWxm2igfGr1uNts2HTHnUkA894OZ3xEur30pQk8nPng/du4zkWX2QlLxy3So8omfQQufueNjoGKx9urMlg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687878851; 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=GH4/5c8YEcZInajpa+Cjd/iIZdsdvCfz2dcSxOVAAmo=; b=GqSgaUb43AhIqP5U2PThMGsoH7ECAQ922GiDnraITxbukaF/2+8NxWuKL2LvhBl33dbz+B8qK50sSXhJ6RS5gDZx+NJeoRR0jM9oNkdRPDVZTsWIFbrXcsf5uKukjBGL/MuhhQRrbOf13VUrby42rRAu49nqNET5uEiiz+7FZ3w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1687878851607112.55953528209; Tue, 27 Jun 2023 08:14:11 -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-21-6mQxYonON5GueSLfETYg_Q-1; Tue, 27 Jun 2023 11:13:48 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 574F11066543; Tue, 27 Jun 2023 15:07:56 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3D06E2166B25; Tue, 27 Jun 2023 15:07:56 +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 C7921194974C; Tue, 27 Jun 2023 15:07:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id EA93C1946586 for ; Tue, 27 Jun 2023 15:07:37 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id DCA28400E88; Tue, 27 Jun 2023 15:07:37 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.45.225.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 80A0748FB01 for ; Tue, 27 Jun 2023 15:07:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687878850; 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=GH4/5c8YEcZInajpa+Cjd/iIZdsdvCfz2dcSxOVAAmo=; b=h4NaJgKbenu6hehG8DPbOjuCQZIdkGEGEgsHQRX+jDnhCwzFPaqeTGtaNck/CmHZU9E8vO RMjnIdLrhqI7Y+rEUhETyyhQipHYAG9Xc4uoLw6B1+qVFLDww0tL2eWFpMvG3HTtOPVyC/ sWz4LZN9yHSTU5okN9JmCA97C4k1aVQ= X-MC-Unique: 6mQxYonON5GueSLfETYg_Q-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v2 15/24] qemu_snapshot: add merge to external snapshot delete prepare data Date: Tue, 27 Jun 2023 17:07:18 +0200 Message-ID: <996a347fa1aac2123b60a17c4fe5ab3f0d38f437.1687877087.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 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.6 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: 1687878851923100003 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 | 93 ++++++++++++++++++++++++++-------------- 1 file changed, 60 insertions(+), 33 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 08cff2a9a2..9c4d26bad5 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -2569,9 +2569,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; @@ -2579,7 +2596,6 @@ qemuSnapshotDeleteExternalPrepareData(virDomainObj *v= m, g_autoslist(qemuSnapshotDeleteExternalData) ret =3D NULL; =20 for (i =3D 0; i < snapdef->ndisks; i++) { - g_autofree qemuSnapshotDeleteExternalData *data =3D NULL; virDomainSnapshotDiskDef *snapDisk =3D &(snapdef->disks[i]); =20 if (snapDisk->snapshot !=3D VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) @@ -2591,14 +2607,18 @@ qemuSnapshotDeleteExternalPrepareData(virDomainObj = *vm, snapDisk->name); return -1; } + } + + for (i =3D 0; i < snapdef->ndisks; i++) { + virDomainSnapshotDiskDef *snapDisk =3D &(snapdef->disks[i]); + g_autofree qemuSnapshotDeleteExternalData *data =3D NULL; + + if (snapDisk->snapshot !=3D VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) + continue; =20 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) { @@ -2608,39 +2628,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)); @@ -2672,7 +2699,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)) { @@ -2687,7 +2714,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