From nobody Tue Mar 24 01:12:53 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=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1772835318; cv=none; d=zohomail.com; s=zohoarc; b=J8JQWCy8TwijC19+vav3ztiNHgBZaBm0Oqb7pfdZATnl6vlJNOVAv39pPmcdG4DYJnVzWx0MkRfpa2Y3M43nDDI6OVZRGD+Pcqdsc5UFkQPoqF+siTaFNbzhmPjrySPw72GdTemICYGy/n8nJrRiH+z7gbKE4GZ6QxpLZZA5g1A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772835318; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=2ZlEqp6H2qubAliwzUAH3S4/GJtQA6BiqkZxw4geFM0=; b=I/Dg0gdKmVT31STcHJo/BVxxdZcdd6QJdcaEqtip8mm19RA35VKvxAEt9IW9DG9raQPLcIxYjbAvecNC7nhY+MAj1HZDMJb3NXyqPqvSspVneBx7SBWo5h6fusjwP024Mc0AyDcSMf12m78oL5wwd2TIN7cp8Uxq/oolva3AbBQ= ARC-Authentication-Results: i=1; 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=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1772835318329329.7543745686769; Fri, 6 Mar 2026 14:15:18 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id C2C4D4193C; Fri, 6 Mar 2026 17:15:17 -0500 (EST) Received: from [172.19.199.12] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 14E4741BB6; Fri, 6 Mar 2026 17:13:08 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id B20B6418DB; Fri, 6 Mar 2026 17:12:57 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 632863F8A5 for ; Fri, 6 Mar 2026 17:12:57 -0500 (EST) Received: from mx-prod-mc-05.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-237-tHOegUiROS6WsSbv4D0AQg-1; Fri, 06 Mar 2026 17:12:55 -0500 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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 013BB1956089 for ; Fri, 6 Mar 2026 22:12:55 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.81.168]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 936161958DC5 for ; Fri, 6 Mar 2026 22:12:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HELO_MISC_IP,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1772835177; h=from:from: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; bh=2ZlEqp6H2qubAliwzUAH3S4/GJtQA6BiqkZxw4geFM0=; b=MK+X8zT3uixu7eOgdTiVoUGfuBAWjGX1jj57Ox9h9/7c9bJ1B06WGrdKnr456Y1vB7Y68q tKhgqWprZbm+GdbarkAAzOwp1IYZm3iY4dyYAErs/9zIsO4Q/PsSO08zJUKs5Gfp2/ERCf Lh+741WKi7GZM19XXPAcjLzBzsnA3nc= X-MC-Unique: tHOegUiROS6WsSbv4D0AQg-1 X-Mimecast-MFC-AGG-ID: tHOegUiROS6WsSbv4D0AQg_1772835175 To: devel@lists.libvirt.org Subject: [PATCH 2/5] hyperv: implement virDomainListAllSnapshots()/virDomainSnapshotNum() Date: Fri, 6 Mar 2026 16:12:48 -0600 Message-ID: <20260306221251.929040-3-jjongsma@redhat.com> In-Reply-To: <20260306221251.929040-1-jjongsma@redhat.com> References: <20260306221251.929040-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: rax7U9YAKjaldGdIgOAVIFHpNWpF6MFIF5Akl4GqVOA_1772835175 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: E6BVLVY62HC3KDJUK6MHGNOLLQEBPYTZ X-Message-ID-Hash: E6BVLVY62HC3KDJUK6MHGNOLLQEBPYTZ X-MailFrom: jjongsma@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Jonathon Jongsma via Devel Reply-To: Jonathon Jongsma X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1772835320604154100 Content-Type: text/plain; charset="utf-8"; x-default="true" Signed-off-by: Jonathon Jongsma --- src/hyperv/hyperv_driver.c | 82 ++++++++++++++++++++++++++++++++++++++ src/hyperv/hyperv_wmi.c | 20 ++++++++++ src/hyperv/hyperv_wmi.h | 4 ++ 3 files changed, 106 insertions(+) diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index 44b671b45e..8a1cc4b453 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -4129,6 +4129,86 @@ hypervDomainSnapshotLookupByName(virDomainPtr domain, } =20 =20 +static int +hypervDomainListAllSnapshots(virDomainPtr domain, + virDomainSnapshotPtr **snaps, + unsigned int flags) +{ + hypervPrivate *priv =3D domain->conn->privateData; + g_autoptr(Msvm_VirtualSystemSettingData) snapshots =3D NULL; + Msvm_VirtualSystemSettingData *snapshot =3D NULL; + g_autoptr(GList) filtered =3D NULL; + virDomainSnapshotPtr *snapshotsRet =3D NULL; + char uuid_string[VIR_UUID_STRING_BUFLEN]; + int count =3D 0; + int ret =3D -1; + + virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS | + VIR_DOMAIN_SNAPSHOT_LIST_METADATA | + VIR_DOMAIN_SNAPSHOT_LIST_NO_METADATA, -1); + + /* libvirt does not maintain any metadata for hyper-v snapshots */ + if (flags & VIR_DOMAIN_SNAPSHOT_LIST_METADATA) + return 0; + + virUUIDFormat(domain->uuid, uuid_string); + + if (hypervGetDomainSnapshotsSD(priv, uuid_string, &snapshots) < 0) + return -1; + + /* filter snapshots */ + for (snapshot =3D snapshots; snapshot; snapshot =3D snapshot->next) { + if ((flags & VIR_DOMAIN_SNAPSHOT_LIST_ROOTS) && snapshot->data->Pa= rent) + continue; + + filtered =3D g_list_append(filtered, snapshot); + } + + count =3D g_list_length(filtered); + + if (!snaps) + return count; + + if (count > 0) { + GList *l =3D NULL; + int idx =3D 0; + + snapshotsRet =3D g_new0(virDomainSnapshotPtr, count); + + for (l =3D filtered; l; l =3D l->next) { + Msvm_VirtualSystemSettingData *vssd =3D l->data; + snapshotsRet[idx] =3D virGetDomainSnapshot(domain, vssd->data-= >InstanceID); + if (!snapshotsRet[idx]) + goto cleanup; + idx++; + } + } + + *snaps =3D snapshotsRet; + ret =3D count; + + cleanup: + if (ret < 0) { + size_t i; + for (i =3D 0; i < count; i++) { + if (snapshotsRet[i]) + virObjectUnref(snapshotsRet[i]); + } + VIR_FREE(snapshotsRet); + } + + return ret; +} + + +static int +hypervDomainSnapshotNum(virDomainPtr domain, + unsigned int flags) +{ + return hypervDomainListAllSnapshots(domain, NULL, flags); +} + + static virHypervisorDriver hypervHypervisorDriver =3D { .name =3D "Hyper-V", .connectOpen =3D hypervConnectOpen, /* 0.9.5 */ @@ -4196,6 +4276,8 @@ static virHypervisorDriver hypervHypervisorDriver =3D= { .domainInterfaceAddresses =3D hypervDomainInterfaceAddresses, /* 12.1.= 0 */ .domainGetBlockInfo =3D hypervDomainGetBlockInfo, /* 12.1.0 */ .domainSnapshotLookupByName =3D hypervDomainSnapshotLookupByName, /* 1= 2.2.0 */ + .domainListAllSnapshots =3D hypervDomainListAllSnapshots, /* 12.2.0 */ + .domainSnapshotNum =3D hypervDomainSnapshotNum, /* 12.2.0 */ }; =20 =20 diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c index 7ae3afc40a..94a4789913 100644 --- a/src/hyperv/hyperv_wmi.c +++ b/src/hyperv/hyperv_wmi.c @@ -1406,6 +1406,26 @@ hypervGetMsvmVirtualSystemSettingDataFromUUID(hyperv= Private *priv, } =20 =20 +int +hypervGetDomainSnapshotsSD(hypervPrivate *priv, + const char *domain_uuid_string, + Msvm_VirtualSystemSettingData **list) +{ + g_auto(virBuffer) query =3D VIR_BUFFER_INITIALIZER; + + virBufferAsprintf(&query, + "ASSOCIATORS OF {Msvm_ComputerSystem.CreationClassNa= me=3D'Msvm_ComputerSystem',Name=3D'%s'} " + "WHERE AssocClass =3D Msvm_SnapshotOfVirtualSystem " + "ResultClass =3D Msvm_VirtualSystemSettingData", + domain_uuid_string); + + if (hypervGetWmiClass(Msvm_VirtualSystemSettingData, list) < 0) + return -1; + + return 0; +} + + #define hypervGetSettingData(type, id, out) \ g_auto(virBuffer) query =3D VIR_BUFFER_INITIALIZER; \ virBufferEscapeSQL(&query, \ diff --git a/src/hyperv/hyperv_wmi.h b/src/hyperv/hyperv_wmi.h index d577dbcecb..134d8894e6 100644 --- a/src/hyperv/hyperv_wmi.h +++ b/src/hyperv/hyperv_wmi.h @@ -240,6 +240,10 @@ int hypervGetMsvmVirtualSystemSettingDataFromUUID(hype= rvPrivate *priv, const char *uuid_string, Msvm_VirtualSystemSettin= gData **list); =20 +int hypervGetDomainSnapshotsSD(hypervPrivate *priv, + const char *domain_uuid_string, + Msvm_VirtualSystemSettingData **list); + int hypervGetResourceAllocationSD(hypervPrivate *priv, const char *id, Msvm_ResourceAllocationSettingData **dat= a); --=20 2.53.0