From nobody Tue Jan 21 04:09:14 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=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 1736518908390783.0462872551626; Fri, 10 Jan 2025 06:21:48 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 653551633; Fri, 10 Jan 2025 09:21:47 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id C156C1619; Fri, 10 Jan 2025 09:21:29 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id EB520160B; Fri, 10 Jan 2025 09:21:26 -0500 (EST) 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 72C7C1593 for ; Fri, 10 Jan 2025 09:21:26 -0500 (EST) Received: from mx-prod-mc-02.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-578-9xOhKsyBMm6P9u8Lv0vutw-1; Fri, 10 Jan 2025 09:21:24 -0500 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5949D1955DCF for ; Fri, 10 Jan 2025 14:21:23 +0000 (UTC) Received: from antique-laptop.redhat.com (unknown [10.45.224.141]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9898C19560BC for ; Fri, 10 Jan 2025 14:21:22 +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.5 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,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=1736518886; 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; bh=JvGQ8molYm8jBnrPBVQV2767SegVpmjHs0VvqdAzu2s=; b=UWaIEPJx8k7HgNpDvxyy124nJGHmmXTfDnTzMoCXa5MSvR6emwXouAz+izmm+72EGFYWPz hgtYJt5ZLo6Gco3G02abCF/mMqVBDh7Uui+hnhwy2h5U8LDb9i5KEgjpbb8JhXVACQAuFk ESu6cUSrGejf3FQABxEJg2qkrcKtMTY= X-MC-Unique: 9xOhKsyBMm6P9u8Lv0vutw-1 X-Mimecast-MFC-AGG-ID: 9xOhKsyBMm6P9u8Lv0vutw From: Pavel Hrdina To: devel@lists.libvirt.org Subject: [libvirt PATCH] qemu: snapshot: delete disk image only if parent snapshot is external Date: Fri, 10 Jan 2025 15:21:21 +0100 Message-ID: <296d8b7be7908564bc05a776c47ff8068842b275.1736518455.git.phrdina@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: vXGsuGwYchuc9qa-BELVBVBghpBN6CR5mjteabfwhDo_1736518883 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: Z2FSVWZOK2E3JUI62KYV555P4A4PWKLG X-Message-ID-Hash: Z2FSVWZOK2E3JUI62KYV555P4A4PWKLG X-MailFrom: phrdina@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: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1736518910287116600 Content-Type: text/plain; charset="utf-8"; x-default="true" When we are deleting external snapshot that is not active we only need to delete overlay disk image of the parent snapshot. This works correctly even if parent snapshot is external and active as it will have another overlay created when user reverted to that snapshot. In case the parent snapshot is internal there are no overlay disk images created as everything is stored internally within the disk image. In this case we would delete the actual disk image storing internal snapshots and most likely the original disk image as well resulting in data loss once the VM is shutoff. Fixes: https://gitlab.com/libvirt/libvirt/-/issues/734 Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/qemu/qemu_snapshot.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 18b2e478f6..80cd54bf33 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -3144,6 +3144,8 @@ qemuSnapshotDeleteExternalPrepareData(virDomainObj *v= m, return -1; } =20 + data->parentSnap =3D qemuSnapshotFindParentSnapForDisk(snap, data-= >snapDisk); + if (data->merge) { virStorageSource *snapDiskSrc =3D NULL; =20 @@ -3185,8 +3187,6 @@ qemuSnapshotDeleteExternalPrepareData(virDomainObj *v= m, qemuSnapshotGetDisksWithBackingStore(vm, snap, data); } =20 - data->parentSnap =3D qemuSnapshotFindParentSnapForDisk(snap, d= ata->snapDisk); - 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")); @@ -3642,10 +3642,12 @@ qemuSnapshotDiscardExternal(virDomainObj *vm, if (!data->job) goto error; } else { - if (virStorageSourceInit(data->parentDomDisk->src) < 0 || - virStorageSourceUnlink(data->parentDomDisk->src) < 0) { - VIR_WARN("Failed to remove snapshot image '%s'", - data->snapDisk->name); + if (data->parentSnap && virDomainSnapshotIsExternal(data->pare= ntSnap)) { + if (virStorageSourceInit(data->parentDomDisk->src) < 0 || + virStorageSourceUnlink(data->parentDomDisk->src) < 0) { + VIR_WARN("Failed to remove snapshot image '%s'", + data->snapDisk->name); + } } } } --=20 2.47.1