From nobody Mon Feb 9 02:14:26 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1672919344; cv=none; d=zohomail.com; s=zohoarc; b=QIoqj4Bv6VYl0EaobYbSVwT/EzPtGETCA63MSWFENFEZuraeAeot5tr3jzRAvd5QoRem3HrZC12SEnnms5gfEL3PzzQ6Y/2SCVCOBzUG8jRteAFYZcfOHvhOaEhq3y6TbtAUXKDlUMkFlHvaJ3Lef39d0rzgghyFypkHcvcWq98= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1672919344; 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=2ZBcGC4xj2SYehwlROweZI5GY9/jw+HFy5aYlvFoZw8=; b=P7ZH5DqX5g3F9NJscsBrkaMMpewjWJZbBwxKh9c3uqFGeppfE8837kh8zgVW7VuQFQTev/3xNCEZE3b3eYDSEzi61xRN9bUJwEpteRJYlrzRTN6r72kOf77FQHVMZz43wicTK2wZ0G0hQlUEcQ/lopadHmUuJL92XeUJ6UgWIhw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 1672919344899549.138695693192; Thu, 5 Jan 2023 03:49:04 -0800 (PST) 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-562-0WFm3WcGM7msie-KBYoNBQ-1; Thu, 05 Jan 2023 06:47:52 -0500 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 89A5D18E0AC3; Thu, 5 Jan 2023 11:47:48 +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 7180A492B06; Thu, 5 Jan 2023 11:47:48 +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 F2D601946A77; Thu, 5 Jan 2023 11:47:47 +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 3C87E1947B9D for ; Thu, 5 Jan 2023 11:47:45 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 6008E483EC7; Thu, 5 Jan 2023 11:47:34 +0000 (UTC) Received: from localhost.localdomain (ovpn-194-38.brq.redhat.com [10.40.194.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id F22B2483EC4 for ; Thu, 5 Jan 2023 11:47:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1672919343; 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=2ZBcGC4xj2SYehwlROweZI5GY9/jw+HFy5aYlvFoZw8=; b=BIqPC/OHs/6/Tt76iCgqY0AUEfO4Oh7oQmtpYCxqgOlvrLKzvJ4QDtfROZhPp3hm2WnJ5Z FfQWoKKhdFk55M8QYFQzoR/A4m0ApNRtyOQyvmVAKolQb1V5cOrLrRbC8I68sPVvscpu1w Al6z92ULTP4M3qYhDs8zLSmIHer3Czk= X-MC-Unique: 0WFm3WcGM7msie-KBYoNBQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v2 27/31] qemu_snapshot: when deleting snapshot invalidate parent snapshot Date: Thu, 5 Jan 2023 12:47:03 +0100 Message-Id: <4bad663d49c36d0dc6b2a57235d595970e628a78.1672918676.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 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 3.1 on 10.11.54.9 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: 1672919345610100002 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 | 8 ++++++ src/conf/snapshot_conf.h | 1 + src/qemu/qemu_snapshot.c | 60 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+) diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index 4b5b908d66..9bf3c78353 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -158,6 +158,11 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node, return -1; } =20 + if (flags & VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE) { + def->snapshotDeleteInProgress =3D !!virXPathNode("./snapshotDelete= InProgress", + ctxt); + } + if ((cur =3D virXPathNode("./source", ctxt)) && virDomainStorageSourceParse(cur, ctxt, src, flags, xmlopt) < 0) return -1; @@ -744,6 +749,9 @@ virDomainSnapshotDiskDefFormat(virBuffer *buf, virBufferAsprintf(&attrBuf, " snapshot=3D'%s'", virDomainSnapshotLocationTypeToString(disk->snap= shot)); =20 + if (disk->snapshotDeleteInProgress) + 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 fec4a5a912..96c77ef42b 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->snapshotDeleteInProgress) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("snapshot disk '%s' was target of not complet= ed snapshot delete"), + snapDisk->name); + return NULL; + } + data =3D g_new0(qemuSnapshotDeleteExternalData, 1); data->snapDisk =3D snapDisk; =20 @@ -2628,6 +2635,53 @@ qemuSnapshotDeleteBlockJobFinishing(virDomainObj *vm, } =20 =20 +/** + * qemuSnapshotSetInvalid: + * @vm: vm object + * @snap: snapshot object that contains parent disk + * @disk: disk from the snapshot we are deleting + * @invalid: boolean to set/unset invalid state + * + * @snap should point to a ancestor snapshot from the snapshot tree that + * affected the @disk which doesn't have to be the direct parent. + * + * When setting snapshot with parent disk as invalid due to snapshot being + * deleted we should not mark the whole snapshot as invalid but only the + * affected disks because the snapshot can contain other disks that we are + * not modifying at the moment. + * + * Return 0 on success, -1 on error. + * */ +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->snapshotDeleteInProgress =3D invalid; + } + + return qemuDomainSnapshotWriteMetadata(vm, snap, driver->xmlopt, cfg->= snapshotDir); +} + + static int qemuSnapshotDiscardExternal(virDomainObj *vm, GSList *externalData) @@ -2644,6 +2698,9 @@ qemuSnapshotDiscardExternal(virDomainObj *vm, autofinalize =3D VIR_TRISTATE_BOOL_YES; } =20 + if (qemuSnapshotSetInvalid(vm, data->parentSnap, data->snapDisk, t= rue) < 0) + goto error; + data->job =3D qemuBlockCommit(vm, data->domDisk, data->parentDiskSrc, @@ -2694,6 +2751,9 @@ qemuSnapshotDiscardExternal(virDomainObj *vm, } =20 qemuBlockJobSyncEnd(vm, data->job, VIR_ASYNC_JOB_SNAPSHOT); + + if (qemuSnapshotSetInvalid(vm, data->parentSnap, data->snapDisk, f= alse) < 0) + goto error; } =20 return 0; --=20 2.39.0