From nobody Tue Dec 16 11:06:43 2025 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=1673027656; cv=none; d=zohomail.com; s=zohoarc; b=RO5FuGmd0fyuR0wlKHuumA3+05zy8b+Wpz7kiQif6FsNeP/LE0ETsyTnM1zCyfuJ3J8Ee7sWBL5btY8C6RtFksWzUKeGSUrCNQPiI2flPP1tZJ3kjR1Kj9f1xSelZX3qYiYxB0W2htAOS0rFHMY69H+hVWyxLwuHbMyrVenO49g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673027656; 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=SE6R02L4opQ0ZGNSZvDKIEDpizcims6C7pNaWvh0hqc=; b=ZvLIycCjS2rq1BYxgR2ce1UWVEKqqkJGjuNlMGzMAoaDiTq6cthkcg0fIpkYp6Ktdd90GiHxTjW0SaHSIEQB/caF8JuHMgfA0R604tZ24IbDU/448C+Jq8y+j8gAX0lQTY/tVnEEeLmMAA4WeKWwKp2V4qmswkKTk8nfoSMkWn0= 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 1673027656264837.7469367406358; Fri, 6 Jan 2023 09:54:16 -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-587-E4sJqMlXP02e_S3huwNjtw-1; Fri, 06 Jan 2023 12:52:42 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7FDFB855719; Fri, 6 Jan 2023 17:52:35 +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 6A4AF2166B30; Fri, 6 Jan 2023 17:52:35 +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 58D5F19459CB; Fri, 6 Jan 2023 17:52:35 +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 7999E19459C6 for ; Fri, 6 Jan 2023 17:52:32 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 70CA440C2064; Fri, 6 Jan 2023 17:52:32 +0000 (UTC) Received: from antique-work.redhat.com (ovpn-193-172.brq.redhat.com [10.40.193.172]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0EDF140C2004 for ; Fri, 6 Jan 2023 17:52:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673027655; 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=SE6R02L4opQ0ZGNSZvDKIEDpizcims6C7pNaWvh0hqc=; b=CGRdkCCXiF1j5JP+FaVwmeTU/P4jWQmYBz9nICvn2yhcfX6qjxkcgXw3la3a4nkSCYWcCg J1CpYOm7KPKL/b/HF4f8hlqtqBX3bUOfgRd8qoC8nMNsbHkns+iI+GrgyNSMVl/kEPuw4a CNhP98a2lbdWJ60vX2GIg13C55tfVew= X-MC-Unique: E4sJqMlXP02e_S3huwNjtw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH v3 27/32] qemu_snapshot: when deleting snapshot invalidate parent snapshot Date: Fri, 6 Jan 2023 18:52:02 +0100 Message-Id: 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.6 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: 1673027657774100001 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