From nobody Sun Feb 8 13:39:22 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=1661272515; cv=none; d=zohomail.com; s=zohoarc; b=iJJWGyO1awORgs7VsPXAWsw31yGv6j3MiMLKCgyrG4vQeSPOhVSwSmmisU2sWzcWdclFj3TvZWzXvSGXrhEw8qPx2fIM3OKta0smgjtMSwXdLrC4o9DAMhskdC3q3Izxk/NVIzeB4rlvMtDNvNwNB9a4gQJADQzRV7YhAkPv6QU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661272515; 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=Eh5Of1RzQW6p0p5IrbAkZLbiV/lNmEtukL6RcD7ObfI=; b=jzkMzbbtxGMNjif5ab3ml8yJ45afuR285x3LNAbn1qGNwpsHQDP7DKyWiSChHrIr4ryDWSE0Hu7jeiRYGyMBU/Q1/7pjIJAp+/b+LuXbH6X4TXAOh5O1sfP8uqthhIllt9HLtaIRPrc9aXtTBaodUkK4sZ8HVLDjU/bTXXU4Rro= 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 1661272515980420.1199677589875; Tue, 23 Aug 2022 09:35:15 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [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-262-VH3Ji4YpN1We2qIYX73iAw-1; Tue, 23 Aug 2022 12:33:13 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 074421C0BC88; Tue, 23 Aug 2022 16:32:53 +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 E588A112132D; Tue, 23 Aug 2022 16:32:52 +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 C8E7B1946A63; Tue, 23 Aug 2022 16:32:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 8107F1946A5A for ; Tue, 23 Aug 2022 16:32:48 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 7690840315A; Tue, 23 Aug 2022 16:32:48 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 17EAD492C3B for ; Tue, 23 Aug 2022 16:32:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661272514; 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=Eh5Of1RzQW6p0p5IrbAkZLbiV/lNmEtukL6RcD7ObfI=; b=XMWG+NpHEv3KcE7oVXf6G5u9AKjkEV0J/pSfSpFrAT8aqXO/WMBtI0F2T8zh7detIjddQi zJX/p2vFwLSokW2VnSgv6g2KtkY+1mEHVsbiJ0MvlShinGv0WtjmzfNrZMOuiy2Jcyk0k6 pzuVh09BdLJ8t99Zt/9Y8BmjdpUldVw= X-MC-Unique: VH3Ji4YpN1We2qIYX73iAw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt RFC 23/24] qemu_snapshot: when deleting snapshot invalidate parent snapshot Date: Tue, 23 Aug 2022 18:32:26 +0200 Message-Id: <7189ec43e3ac3439e87f15c573dc54739c4f8a29.1661271812.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 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 2.78 on 10.11.54.3 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: 1661272518123100001 Content-Type: text/plain; charset="utf-8"; x-default="true" When deleting external snapshots the operation may fail at any point which could lead to situation that some disks finished the block commit operation but for some disks it failed and the libvirt job ends. In order to make sure that the qcow2 images are in consistent state introduce new element "" that will mark the disk in snapshot metadata as invalid until the snapshot delete is completed successfully. This will prevent deleting snapshot with the invalid disk and in future reverting to snapshot with the invalid disk. Signed-off-by: Pavel Hrdina --- src/conf/snapshot_conf.c | 5 +++++ src/conf/snapshot_conf.h | 1 + src/qemu/qemu_snapshot.c | 42 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index ae635edd08..155da42862 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -158,6 +158,8 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node, return -1; } =20 + def->invalid =3D !!virXPathNode("./invalid", ctxt); + if ((cur =3D virXPathNode("./source", ctxt)) && virDomainStorageSourceParse(cur, ctxt, src, flags, xmlopt) < 0) return -1; @@ -761,6 +763,9 @@ virDomainSnapshotDiskDefFormat(virBuffer *buf, virBufferAsprintf(&attrBuf, " snapshot=3D'%s'", virDomainSnapshotLocationTypeToString(disk->snap= shot)); =20 + if (disk->invalid) + virBufferAddLit(&childBuf, "\n"); + if (disk->src->path || disk->src->format !=3D 0) { g_auto(virBuffer) driverAttrBuf =3D VIR_BUFFER_INITIALIZER; g_auto(virBuffer) driverChildBuf =3D VIR_BUFFER_INIT_CHILD(&childB= uf); diff --git a/src/conf/snapshot_conf.h b/src/conf/snapshot_conf.h index 1f787f1a94..de6e420f77 100644 --- a/src/conf/snapshot_conf.h +++ b/src/conf/snapshot_conf.h @@ -52,6 +52,7 @@ typedef struct _virDomainSnapshotDiskDef virDomainSnapsho= tDiskDef; struct _virDomainSnapshotDiskDef { char *name; /* name matching the snapshot =3D=3D VIR_DOMAIN_SNAPSHOT_LOCATION_NO) continue; =20 + if (snapDisk->invalid) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("snapshot is in invalid state")); + return NULL; + } + data =3D g_new0(qemuSnapshotDeleteExternalData, 1); data->snapDisk =3D snapDisk; =20 @@ -2522,6 +2528,36 @@ qemuSnapshotJobFinishing(virDomainObj *vm, } =20 =20 +static int +qemuSnapshotSetInvalid(virDomainObj *vm, + virDomainMomentObj *snap, + virDomainSnapshotDiskDef *disk, + bool invalid) +{ + ssize_t i; + qemuDomainObjPrivate *priv =3D vm->privateData; + virQEMUDriver *driver =3D priv->driver; + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); + virDomainSnapshotDef *snapdef =3D NULL; + + if (!snap) + return 0; + + snapdef =3D virDomainSnapshotObjGetDef(snap); + if (!snapdef) + return 0; + + for (i =3D 0; i < snapdef->ndisks; i++) { + virDomainSnapshotDiskDef *snapDisk =3D &(snapdef->disks[i]); + + if (STREQ(snapDisk->name, disk->name)) + snapDisk->invalid =3D invalid; + } + + return qemuDomainSnapshotWriteMetadata(vm, snap, driver->xmlopt, cfg->= snapshotDir); +} + + static int qemuSnapshotDiscardExternal(virDomainObj *vm, virQEMUDriver *driver, @@ -2539,6 +2575,9 @@ qemuSnapshotDiscardExternal(virDomainObj *vm, autofinalize =3D VIR_TRISTATE_BOOL_YES; } =20 + if (qemuSnapshotSetInvalid(vm, data->parentSnap, data->snapDisk, t= rue) < 0) + return -1; + if (qemuBlockCommitImpl(vm, driver, data->domDisk, data->parentDiskSrc, @@ -2585,6 +2624,9 @@ qemuSnapshotDiscardExternal(virDomainObj *vm, return -1; =20 qemuBlockJobSyncEnd(vm, data->job, VIR_ASYNC_JOB_NONE); + + if (qemuSnapshotSetInvalid(vm, data->parentSnap, data->snapDisk, f= alse) < 0) + return -1; } =20 return 0; --=20 2.37.2