From nobody Thu Apr 16 03:31:16 2026 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=1692005811; cv=none; d=zohomail.com; s=zohoarc; b=Pm20MZBFIWQ5+Kp1sT4xbFPij59+GIox28UMrWsdgVV05TrEn9L3IMyMvvyv8tHaSvyrXyVyLxmqHPqM0Evy0tBDWIMRKyfyAZgCSepi4psi3yNgozFIC0woqg2RvQUnk6NQlC0dyGV81NPD6eMcL3uXGzmJzn07s2AYr9OejD4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692005811; 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=wajkSIqgMCinT51pVrY2Vq6iLQSLpSrcYRYnOsbtDQw=; b=UEqzLNt3lSR9VpVZ3uMLujsJ0V4hqV5G06KFNYc2Z6c6zCez97ofwjGw7tr2L5UerDvAolX/TdcDS7XyOeqS2gHSl6FzlVIA+0PLBv4BOS3ccPwuu1MWv5b2Uq/MgZgOY0/qVf8/Y396h4HP6Pg6yEsZIYtK4oicenJHPuP8ZDg= 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 1692005811151226.73857422500373; Mon, 14 Aug 2023 02:36:51 -0700 (PDT) Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-621-i4quy3xNPLGfZG8vxcoXJg-1; Mon, 14 Aug 2023 05:36:47 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0D2961C07263; 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 E3AEF40C206F; Mon, 14 Aug 2023 09:36:40 +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 7B3B61946594; Mon, 14 Aug 2023 09:36:38 +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 9A3F919465B1 for ; Mon, 14 Aug 2023 09:36:37 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id A4F5A40B4CCB; Mon, 14 Aug 2023 09:36:29 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.45.226.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4929140C207D for ; Mon, 14 Aug 2023 09:36:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692005810; 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=wajkSIqgMCinT51pVrY2Vq6iLQSLpSrcYRYnOsbtDQw=; b=atIzHF08m/Uy9mNR1GXyDUAoZsvT97K/gfU6aNWp+7RuOpzU0zONigfLa0dhOXwO91EPbF cK2VO0gCDq/pCXP0ISSic4Hu0GfMFwhmDbyjrpUmdTzoNYWzOcr2E2sEG3gEdddRc8t/Mm TL2LfHDJ2EHMkrOam8AWM08Aah7nQaM= X-MC-Unique: i4quy3xNPLGfZG8vxcoXJg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v3 18/25] qemu_snapshot: delete: properly update parent snapshot with revert data Date: Mon, 14 Aug 2023 11:36:10 +0200 Message-ID: <603c2a7a39cebc8ccc6c136490b3c06471c70694.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.1 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: 1692005811703100001 Content-Type: text/plain; charset="utf-8"; x-default="true" When deleting external snapshot and parent snapshot is the currently active snapshot as user reverted to it we need to properly update the parent snapshot metadata. After the delete is done the new overlay files will be the currently used files created when snapshot revert was done, replacing the original overlay files. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/qemu/qemu_snapshot.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index a67be1ae49..6dd420a53b 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -3229,6 +3229,41 @@ qemuSnapshotDiscardExternal(virDomainObj *vm, } =20 =20 +static int +qemuSnapshotDeleteUpdateParent(virDomainObj *vm, + virDomainMomentObj *parent) +{ + size_t i; + virQEMUDriver *driver =3D QEMU_DOMAIN_PRIVATE(vm)->driver; + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); + virDomainSnapshotDef *parentDef =3D virDomainSnapshotObjGetDef(parent); + + if (!parentDef) + return 0; + + if (!parentDef->revertdisks) + return 0; + + for (i =3D 0; i < parentDef->ndisks; i++) { + virDomainSnapshotDiskDefClear(&parentDef->disks[i]); + } + g_free(parentDef->disks); + + parentDef->disks =3D g_steal_pointer(&parentDef->revertdisks); + parentDef->ndisks =3D parentDef->nrevertdisks; + parentDef->nrevertdisks =3D 0; + + if (qemuDomainSnapshotWriteMetadata(vm, + parent, + driver->xmlopt, + cfg->snapshotDir) < 0) { + return -1; + } + + return 0; +} + + static int qemuSnapshotDiscardMetadata(virDomainObj *vm, virDomainMomentObj *snap, @@ -3268,6 +3303,11 @@ qemuSnapshotDiscardMetadata(virDomainObj *vm, virDomainMomentMoveChildren(snap, snap->parent); } =20 + if (update_parent && snap->parent) { + if (qemuSnapshotDeleteUpdateParent(vm, snap->parent) < 0) + ret =3D -1; + } + snapFile =3D g_strdup_printf("%s/%s/%s.xml", cfg->snapshotDir, vm->def= ->name, snap->def->name); =20 --=20 2.41.0