From nobody Tue Mar 24 01:07:52 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=1772835276; cv=none; d=zohomail.com; s=zohoarc; b=M87PuoxcYXOuAktIGU/8Ksc0HmjeHaqxU4E0PkQub3m+uxBpfYivfkz+YdFA9GuHM/KgDTMgWh1oMcOLAIs3+YYCtB5Iknw4B7vDrtOgSwkDFNklr9H4ONkRAY/SftYXsH6lMpRWkG1QD36teU814LKxXn/14SSHZUKCnPdziYg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772835276; 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=3eGxc+ypaxjNrveRdiqgRe1dRnbKwF+T9giqV6E/DP4=; b=idC4covJnOgk/R2pxDMK+6FpKhWtSee5fzYgJwok6hxLi2N9kBg4TrnyhwPP87o9ZCIBFpHo4nPwhDf86Mr9bFFenEjznpHLXhT8mYzDyX3DT7i2DV3+zzDD4XUUEa37wOoT6nbLKHNNd44G5iMPZUTsCGca5l9NnbWyA4RVhDM= 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 1772835276051864.1785343666974; Fri, 6 Mar 2026 14:14:36 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id 85C3A419A3; Fri, 6 Mar 2026 17:14:34 -0500 (EST) Received: from [172.19.199.12] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id A5EEE41919; Fri, 6 Mar 2026 17:13:05 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 4644E418DB; 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 C41A6418DF for ; Fri, 6 Mar 2026 17:12:56 -0500 (EST) Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-513-ePRipvZHN92fD1lAiZBsTQ-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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 52EE118002CA for ; Fri, 6 Mar 2026 22:12:54 +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 E59BB1958DC5 for ; Fri, 6 Mar 2026 22:12:53 +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=1772835176; 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=3eGxc+ypaxjNrveRdiqgRe1dRnbKwF+T9giqV6E/DP4=; b=KW/a1/Glm0EVqv8p7lZOFR9kugtDxXQkq13RtO9rKcLWv3E8me4DaHqMxD1MX2lI0Phv5u o31/QJFGyIROfKpbxb9OuE3f6ebU8kACnQbMy0hKS2GN0tnNiWZWj17twHMAhnCNSFmbev 2m9LDb0hjzcf8ieUV15qO0V8X2ah+6Q= X-MC-Unique: ePRipvZHN92fD1lAiZBsTQ-1 X-Mimecast-MFC-AGG-ID: ePRipvZHN92fD1lAiZBsTQ_1772835174 To: devel@lists.libvirt.org Subject: [PATCH 1/5] hyperv: Implement domainSnapshotLookupByName() Date: Fri, 6 Mar 2026 16:12:47 -0600 Message-ID: <20260306221251.929040-2-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: FONEFll9SxyWmTW7Xsf1Xb_NV5lCI3m_OTI0A3dtRdY_1772835174 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: RPVVVGRPHONK25K5TZLZIOPXQLTB2XWR X-Message-ID-Hash: RPVVVGRPHONK25K5TZLZIOPXQLTB2XWR 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: 1772835278650154100 Content-Type: text/plain; charset="utf-8"; x-default="true" Unfortunately Hyper-V does not enforce any uniqueness constraints on snapshot names (called ElementName in Hyper-V). So it's possible for multiple snapshots of the same domain to have identical ElementNames. Since libvirt uses the domain and snapshot name as a unique key to reference a snapshot, we can't use the hyperv ElementName as the snapshot name in libvirt. So instead I've decided to use the InstanceId of the snapshot as the snapshot name and use the ElementName as the snapshot description. This results in a worse user experience (since the snapshot names end up being something like "Microsoft:$(UUID)"), but guarantees that we will be able to uniquely reference every snapshot. Signed-off-by: Jonathon Jongsma --- src/hyperv/hyperv_driver.c | 53 ++++++++++++++++++++++++++++++++++++++ src/hyperv/hyperv_wmi.h | 3 +++ 2 files changed, 56 insertions(+) diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index 906f6e5d19..44b671b45e 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -4077,6 +4077,58 @@ hypervDomainGetBlockInfo(virDomainPtr domain, } =20 =20 +static Msvm_VirtualSystemSettingData* +hypervDomainLookupSnapshotSD(virDomainPtr domain, const char *snapshot) +{ + hypervPrivate *priv =3D domain->conn->privateData; + g_autoptr(Msvm_VirtualSystemSettingData) vssd =3D NULL; + char domain_uuid_string[VIR_UUID_STRING_BUFLEN]; + g_auto(virBuffer) query =3D VIR_BUFFER_INITIALIZER; + + virUUIDFormat(domain->uuid, domain_uuid_string); + + /* Hyper-V does not enforce unique snapshot names per domain, so we do= n't + * use the Hyper-V snapshot's ElementName field as the libvirt snapsho= t name. + * Instead we use the unique InstanceID as the name, even though it is= not as + * user-friendly */ + virBufferEscapeSQL(&query, + MSVM_VIRTUALSYSTEMSETTINGDATA_WQL_SELECT + "WHERE InstanceID=3D'%s'", + snapshot); + virBufferEscapeSQL(&query, "AND VirtualSystemIdentifier=3D'%s'", domai= n_uuid_string); + virBufferAddLit(&query, "AND VirtualSystemType=3D'" + MSVM_VIRTUALSYSTEMSETTINGDATA_VIRTUALTYPE_SNAPSHOT "'"= ); + + if (hypervGetWmiClass(Msvm_VirtualSystemSettingData, &vssd) < 0) + return NULL; + + if (!vssd) { + virReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT, + _("no domain snapshot with matching name '%1$s'"), = snapshot); + return NULL; + } + + return g_steal_pointer(&vssd); +} + + +static virDomainSnapshotPtr +hypervDomainSnapshotLookupByName(virDomainPtr domain, + const char *name, + unsigned int flags) +{ + g_autoptr(Msvm_VirtualSystemSettingData) vssd =3D NULL; + + virCheckFlags(0, NULL); + + vssd =3D hypervDomainLookupSnapshotSD(domain, name); + if (vssd =3D=3D NULL) + return NULL; + + return virGetDomainSnapshot(domain, name); +} + + static virHypervisorDriver hypervHypervisorDriver =3D { .name =3D "Hyper-V", .connectOpen =3D hypervConnectOpen, /* 0.9.5 */ @@ -4143,6 +4195,7 @@ static virHypervisorDriver hypervHypervisorDriver =3D= { .connectIsAlive =3D hypervConnectIsAlive, /* 0.9.8 */ .domainInterfaceAddresses =3D hypervDomainInterfaceAddresses, /* 12.1.= 0 */ .domainGetBlockInfo =3D hypervDomainGetBlockInfo, /* 12.1.0 */ + .domainSnapshotLookupByName =3D hypervDomainSnapshotLookupByName, /* 1= 2.2.0 */ }; =20 =20 diff --git a/src/hyperv/hyperv_wmi.h b/src/hyperv/hyperv_wmi.h index 65b1211b89..d577dbcecb 100644 --- a/src/hyperv/hyperv_wmi.h +++ b/src/hyperv/hyperv_wmi.h @@ -38,6 +38,9 @@ #define MSVM_IMAGEMANAGEMENTSERVICE_SELECTOR \ "CreationClassName=3DMsvm_ImageManagementService" =20 +#define MSVM_VIRTUALSYSTEMSETTINGDATA_VIRTUALTYPE_SNAPSHOT \ + "Microsoft:Hyper-V:Snapshot:Realized" + int hypervVerifyResponse(WsManClient *client, WsXmlDocH response, const char *detail); =20 --=20 2.53.0