From nobody Sun Feb 8 23:50:17 2026 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 17279634552442.017392928170011; Thu, 3 Oct 2024 06:50:55 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 2EF671521; Thu, 3 Oct 2024 09:50:54 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 1EB991430; Thu, 3 Oct 2024 09:47:16 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id DD0EE15BB; Thu, 3 Oct 2024 09:47:12 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 E965514CB for ; Thu, 3 Oct 2024 09:46:56 -0400 (EDT) Received: from mx-prod-mc-01.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-177-ppeM5WH6O7alOJe7LxP0Xg-1; Thu, 03 Oct 2024 09:46:55 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 681A51956077; Thu, 3 Oct 2024 13:46:54 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.12]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CA2DB19560A3; Thu, 3 Oct 2024 13:46:52 +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_H3,RCVD_IN_MSPIKE_WL,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=1727963216; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cVG1tNpjpg3rIjGMkflSLRs/9+KHzZynCPDn4cPF0m0=; b=d7Uq57Vwmrhw7UZrNqp4go0GcbD01/+OUcseP3Wwx3zzZMYUZPbraF3qufowfCwQetgrwK XSsE5gUDJp6zBtux+cwusXPVD3S5aalK7EPqxMq3PYp+R6AF3mAwOysRspYp32FVknG8Ke ensQSlXLMp+cNkG1MBNgDAL8CLeFHyc= X-MC-Unique: ppeM5WH6O7alOJe7LxP0Xg-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH v3 08/10] qemuSnapshotActiveInternalDeleteGetDevices: Add warning when deleting inconsistent snapshot Date: Thu, 3 Oct 2024 15:46:34 +0200 Message-ID: <059b50e50eb462dd3f43e875013608bbf209e1c5.1727962906.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: TWUCAAJF6RD36OC5KKCQCPV5N22WE234 X-Message-ID-Hash: TWUCAAJF6RD36OC5KKCQCPV5N22WE234 X-MailFrom: pkrempa@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 CC: nikolai.barybin@virtuozzo.com, den@openvz.org 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: 1727963456048116600 Content-Type: text/plain; charset="utf-8" As explained in the commit which added the new internal snapshot deletion code we don't want to do any form of strict checking whether the libvirt metadata is consistent with the on-disk state as we didn't historically do that. In order to be able to spot the cases add a warning into the logs if such state is encountered. While warnings are easy to miss it's the only reasonable way to do that. Users will be encouraged to file an issue with the information, without requiring them to enable debug logs as the reproduction of that issue may include very old historical state. The checker is deliberately added separately so that it can be easily reverted once it's no longer needed. Signed-off-by: Peter Krempa --- src/qemu/qemu_snapshot.c | 54 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 4927ca0bfc..02c876c881 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -3731,6 +3731,14 @@ qemuSnapshotActiveInternalDeleteGetDevices(virDomain= Obj *vm, g_auto(GStrv) devices =3D g_new0(char *, vm->def->ndisks + 2); size_t ndevs =3D 0; size_t i =3D 0; + /* variables below are used for checking of corner cases */ + g_autoptr(GHashTable) foundDisks =3D virHashNew(NULL); + g_auto(virBuffer) errMissingSnap =3D VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) errUnexpectedSnap =3D VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) errExtraDisks =3D VIR_BUFFER_INITIALIZER; + GHashTableIter htitr; + void *key; + bool warn =3D false; if (!(blockNamedNodeData =3D qemuBlockGetNamedNodeData(vm, VIR_ASYNC_J= OB_SNAPSHOT))) return NULL; @@ -3759,6 +3767,7 @@ qemuSnapshotActiveInternalDeleteGetDevices(virDomainO= bj *vm, continue; devices[ndevs++] =3D g_strdup(format_nodename); + g_hash_table_insert(foundDisks, g_strdup(domdisk->dst), NULL); } if (vm->def->os.loader && @@ -3775,6 +3784,51 @@ qemuSnapshotActiveInternalDeleteGetDevices(virDomain= Obj *vm, } } + /* We currently don't want this code to become stricter than what 'del= vm' + * did thus we'll report if the on-disk state mismatches the snapshot + * definition only as a warning */ + for (i =3D 0; i < snapdef->ndisks; i++) { + virDomainSnapshotDiskDef *snapdisk =3D snapdef->disks + i; + + switch (snapdisk->snapshot) { + case VIR_DOMAIN_SNAPSHOT_LOCATION_INTERNAL: + if (g_hash_table_contains(foundDisks, snapdisk->name)) { + g_hash_table_remove(foundDisks, snapdisk->name); + } else { + virBufferAsprintf(&errMissingSnap, "%s ", snapdisk->name); + warn =3D true; + } + break; + + case VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL: + case VIR_DOMAIN_SNAPSHOT_LOCATION_MANUAL: + case VIR_DOMAIN_SNAPSHOT_LOCATION_NO: + case VIR_DOMAIN_SNAPSHOT_LOCATION_DEFAULT: + case VIR_DOMAIN_SNAPSHOT_LOCATION_LAST: + if (g_hash_table_contains(foundDisks, snapdisk->name)) { + virBufferAsprintf(&errUnexpectedSnap, "%s ", snapdisk->nam= e); + warn =3D true; + } else { + g_hash_table_remove(foundDisks, snapdisk->name); + } + } + } + + g_hash_table_iter_init(&htitr, foundDisks); + + while (g_hash_table_iter_next(&htitr, &key, NULL)) { + warn =3D true; + virBufferAsprintf(&errExtraDisks, "%s ", (const char *) key); + } + + if (warn) { + VIR_WARN("inconsistent internal snapshot state (deletion): VM=3D'%= s' snapshot=3D'%s' missing=3D'%s' unexpected=3D'%s' extra=3D'%s", + vm->def->name, snapname, + virBufferCurrentContent(&errMissingSnap), + virBufferCurrentContent(&errUnexpectedSnap), + virBufferCurrentContent(&errExtraDisks)); + } + return g_steal_pointer(&devices); } --=20 2.46.0