From nobody Sun May 12 11:57:22 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1698843766388377.6177660122938; Wed, 1 Nov 2023 06:02:46 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id DBE4817B1; Wed, 1 Nov 2023 09:02:44 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 5E899178A; Wed, 1 Nov 2023 09:01:02 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id E6B61178B; Wed, 1 Nov 2023 09:00:58 -0400 (EDT) Received: from mx1.osci.io (polly.osci.io [8.43.85.229]) (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 333C1178A for ; Wed, 1 Nov 2023 09:00:55 -0400 (EDT) Received: by mx1.osci.io (Postfix, from userid 994) id E747D2177D; Wed, 1 Nov 2023 09:00:54 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by mx1.osci.io (Postfix) with ESMTPS id 1E94121CB2 for ; Wed, 1 Nov 2023 09:00:51 -0400 (EDT) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-271-Cb7bH-pLMMu7Lss9xoFjWg-1; Wed, 01 Nov 2023 09:00:49 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id DB75A3C23FCA for ; Wed, 1 Nov 2023 13:00:48 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.45.225.176]) by smtp.corp.redhat.com (Postfix) with ESMTP id 808AAC1290F for ; Wed, 1 Nov 2023 13:00:48 +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=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: Cb7bH-pLMMu7Lss9xoFjWg-1 From: Pavel Hrdina To: devel@lists.libvirt.org Subject: [libvirt PATCH] qemu_snapshot: fix snapshot deletion that had multiple children Date: Wed, 1 Nov 2023 14:00:47 +0100 Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: HKULCUXAAEA6XVVYDH6GNPAQPD34MEVG X-Message-ID-Hash: HKULCUXAAEA6XVVYDH6GNPAQPD34MEVG X-MailFrom: SRS0=+XEs=GO=redhat.com=phrdina@osci.io 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: X-ZM-MESSAGEID: 1698843822264100001 Content-Type: text/plain; charset="utf-8"; x-default="true" When we revert to non-leaf snapshot and create new branch or branches the overlay in snapshot metadata is no longer usable as a disk source for deletion of that snapshot. We need to use other places to figure out the correct storage source. Fixes: https://gitlab.com/libvirt/libvirt/-/issues/534 Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/qemu/qemu_snapshot.c | 46 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 1962ba4027..ee06e72b11 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -2748,6 +2748,44 @@ qemuSnapshotGetDisksWithBackingStore(virDomainObj *v= m, } =20 =20 +/** + * qemuSnapshotExternalGetSnapDiskSrc: + * @vm: domain object + * @snap: snapshot object + * @snapDisk: disk definition from snapshost + * + * Try to get actual disk source for @snapDisk as the source stored in + * snapshot metadata is not always the correct source we need to work with. + * This happens mainly after reverting to non-leaf snapshot and creating + * new branch with new snapshot. + * + * Returns disk source on success, NULL on error. + */ +static virStorageSource * +qemuSnapshotExternalGetSnapDiskSrc(virDomainObj *vm, + virDomainMomentObj *snap, + virDomainSnapshotDiskDef *snapDisk) +{ + virDomainDiskDef *disk =3D NULL; + + /* Should never happen when deleting external snapshot as for now we do + * not support this specific case for now. */ + if (snap->nchildren > 1) + return snapDisk->src; + + if (snap->first_child) { + disk =3D qemuDomainDiskByName(snap->first_child->def->dom, snapDis= k->name); + } else if (virDomainSnapshotGetCurrent(vm->snapshots) =3D=3D snap) { + disk =3D qemuDomainDiskByName(vm->def, snapDisk->name); + } + + if (disk) + return disk->src; + + return snapDisk->src; +} + + /** * qemuSnapshotDeleteExternalPrepareData: * @vm: domain object @@ -2802,18 +2840,22 @@ qemuSnapshotDeleteExternalPrepareData(virDomainObj = *vm, } =20 if (data->merge) { + virStorageSource *snapDiskSrc =3D NULL; + data->domDisk =3D qemuDomainDiskByName(vm->def, snapDisk->name= ); if (!data->domDisk) return -1; =20 + snapDiskSrc =3D qemuSnapshotExternalGetSnapDiskSrc(vm, snap, d= ata->snapDisk); + if (virDomainObjIsActive(vm)) { data->diskSrc =3D virStorageSourceChainLookupBySource(data= ->domDisk->src, - data->= snapDisk->src, + snapDi= skSrc, &data-= >prevDiskSrc); if (!data->diskSrc) return -1; =20 - if (!virStorageSourceIsSameLocation(data->diskSrc, data->s= napDisk->src)) { + if (!virStorageSourceIsSameLocation(data->diskSrc, snapDis= kSrc)) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("VM disk source and snapshot disk sou= rce are not the same")); return -1; --=20 2.41.0