From nobody Mon Nov 23 04:28:06 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793107923; cv=none; d=zohomail.com; s=zohoarc; b=FWQ/Ne6jfeLUZ4eRWLtT3XeEP/rqxUlycKXhb4SwPHo17FotxMNYxyL0UqziDCcejzUgMbPBDDMleiu6drsRa5UpkK+YKPgDyRFz7m51/A4NW+Iu4tr40S12zo7u+ZG96QEfhh0YV7+jJqsBx2xL4hkUXQMTBnO67UbcCClKqoA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793107923; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=nnDjgW97vP60byO5e2+j7cMYce/RN9nf/dWP/aptmyo=; b=d1qJkeLy9xqltD9EBMiQbe3A/5+eUCrc5XjX+auxAScM6PXxuAkZvSe2iOe2tAPJ03cPjL0A37imiS/eHpk6QL0sy5tpFI5jdGF3FCaOXlRIrGgMAwCd0rKJFkQNF3K/haZU2AtLtrGMxy0PD5IWJjoavcXfLeUtwVglVlgschM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793107923360142.38877383766055; Tue, 27 Oct 2026 06:32:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLhGb-0002if-8M; Tue, 27 Oct 2026 09:31:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLhGY-0002iJ-CO for qemu-devel@nongnu.org; Tue, 27 Oct 2026 09:31:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLhGV-0007bh-DI for qemu-devel@nongnu.org; Tue, 27 Oct 2026 09:31:02 -0400 Received: from mx-prod-mc-03.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-671-uTpz2nSIOV-pHcBhz5WwyQ-1; Tue, 27 Oct 2026 09:30:54 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 69F901954B0A; Tue, 27 Oct 2026 13:30:53 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4683B30000E7; Tue, 27 Oct 2026 13:30:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793107856; 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; bh=nnDjgW97vP60byO5e2+j7cMYce/RN9nf/dWP/aptmyo=; b=HZVi38JQDGz3gD27DiwSHSd8R/2/aG6pqxGBPMGWITCN/weSLo1MAuy4HbR9k6G42d9oTA bK3v33LmfYoUQAI5rtIGY4gCe0iNRI3QS/t5+rjxRTJkHpYhaz5EUkiVrD5t4jAXsRPcWd 6CJAUdM44m1nZs1miBRG20G7FWdjuvA= X-MC-Unique: uTpz2nSIOV-pHcBhz5WwyQ-1 X-Mimecast-MFC-AGG-ID: uTpz2nSIOV-pHcBhz5WwyQ_1793107853 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: kkostiuk@redhat.com, gillian.anton@cohesity.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , qemu-stable@nongnu.org, Michael Roth Subject: [PATCH] qga/vss: fix provider handling of snapshots Date: Tue, 27 Oct 2026 17:30:50 +0400 Message-ID: <20261027133049.2522944-2-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1793107927387158500 From: Marc-Andr=C3=A9 Lureau Since commit 374f4676788c, the provider's GetSnapshotProperties() returns S_OK for any snapshot ID without filling in the properties. VSS consults every registered provider when a requester looks up a snapshot, so lookups of snapshots owned by other providers now succeed with an all-zero VSS_SNAPSHOT_PROP. Backup software relying on it fails, e.g. Veeam: "Original volume name is not specified for the shadow (shadow volume id: '{00000000-0000-0000-0000-000000000000}')". Simply reverting is not an option: 374f4676788c switched to S_OK because returning VSS_E_OBJECT_NOT_FOUND unconditionally broke qemu-ga's own snapshot sets. The provider must answer for its own snapshots only. It does not create real shadow copies, but it does take part in the snapshot set during qemu-ga fsfreeze cycles. Remember the snapshot IDs received in BeginPrepareSnapshot(), return their (minimal) properties, and return VSS_E_OBJECT_NOT_FOUND for anything else. Entries are dropped when VSS deletes the snapshots or the set, or when the set is aborted (AbortSnapshots()). COM+ may hand out several CQGAVssProvider instances (and serve several client processes), so this registry is module-global. It is per-process by design and safe because the COM+ application is hosted by a single NT service (see CreateServiceForApplication() in install.cpp): COM+ forbids pooling and recycling for service-hosted applications, so exactly one surrogate process ever hosts the provider. On the requester side, the snapshot set is created in the persistent VSS_CTX_APP_ROLLBACK context, so VSS keeps it after the freeze/thaw cycle and may keep querying providers about it. The provider registry does not outlive the cycle (requester_thaw() stops the hosting service, and the provider process with it), so later queries would get "not found" for a set VSS still believes exists. Make requester_thaw() delete the snapshot set explicitly at the end of the cycle, whatever its outcome (including BackupComplete() failure and aborted snapshot sets). A failure to delete is only logged, since the guest filesystems have already been thawed. Cc: qemu-stable@nongnu.org Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4584 Buglink: https://redhat.atlassian.net/browse/RHEL-250662 Fixes: 374f4676788c ("qga: Fix VSS provider GetSnapshotProperties return va= lue") Signed-off-by: Marc-Andr=C3=A9 Lureau --- qga/vss-win32/install.cpp | 1 + qga/vss-win32/provider.cpp | 153 +++++++++++++++++++++++++++++++++++- qga/vss-win32/requester.cpp | 26 ++++++ 3 files changed, 179 insertions(+), 1 deletion(-) diff --git a/qga/vss-win32/install.cpp b/qga/vss-win32/install.cpp index 09d94edd4f53..3b58dc840520 100644 --- a/qga/vss-win32/install.cpp +++ b/qga/vss-win32/install.cpp @@ -331,6 +331,7 @@ STDAPI COMRegister(void) chk(put_Value(pObj, L"Authentication", short(6))); chk(put_Value(pObj, L"AuthenticationCapability", short(2))); chk(put_Value(pObj, L"ImpersonationLevel", short(2))); + /* NT-service-hosted apps have ConcurrentApps=3D1 enforced */ chk(pApps->SaveChanges(&n)); =20 /* The app should be deleted if something fails after SaveChanges */ diff --git a/qga/vss-win32/provider.cpp b/qga/vss-win32/provider.cpp index 1c8eb236e57f..ad2f3ee763e6 100644 --- a/qga/vss-win32/provider.cpp +++ b/qga/vss-win32/provider.cpp @@ -11,6 +11,11 @@ */ =20 #include "qemu/osdep.h" + +#include +#include +#include + #include "vss-common.h" #include "vss-debug.h" #ifdef HAVE_VSS_SDK @@ -138,6 +143,123 @@ STDMETHODIMP CQGAVSSEnumObject::Clone(IVssEnumObject = **ppenum) return E_NOTIMPL; } =20 +/* Registry of the snapshot IDs for this provider */ +class QGAVssSnapshotRegistry +{ +public: + bool Track(VSS_ID set_id, VSS_ID snapshot_id, + VSS_PWSZ volume_name, LONG context); + HRESULT GetProperties(VSS_ID snapshot_id, VSS_SNAPSHOT_PROP *prop) con= st; + LONG RemoveSet(VSS_ID set_id); /* returns how many were removed */ + bool Remove(VSS_ID snapshot_id); + +private: + struct Entry { + VSS_ID set_id; + VSS_ID snapshot_id; + std::wstring volume_name; + LONG context; + }; + + std::vector m_entries; + mutable SRWLOCK m_lock =3D SRWLOCK_INIT; +}; + +static QGAVssSnapshotRegistry qga_vss_registry; + +bool QGAVssSnapshotRegistry::Track(VSS_ID set_id, VSS_ID snapshot_id, + VSS_PWSZ volume_name, LONG context) +{ + bool ok; + + AcquireSRWLockExclusive(&m_lock); + try { + m_entries.push_back(Entry { set_id, snapshot_id, volume_name, + context }); + ok =3D true; + } catch (...) { + ok =3D false; + } + ReleaseSRWLockExclusive(&m_lock); + return ok; +} + +HRESULT QGAVssSnapshotRegistry::GetProperties(VSS_ID snapshot_id, + VSS_SNAPSHOT_PROP *prop) con= st +{ + HRESULT hr =3D S_OK; + + AcquireSRWLockShared(&m_lock); + auto it =3D std::find_if(m_entries.begin(), m_entries.end(), + [&](const Entry &e) { + return IsEqualGUID(e.snapshot_id, snapshot_id); + }); + if (it =3D=3D m_entries.end()) { + hr =3D VSS_E_OBJECT_NOT_FOUND; + goto out; + } + + { + const Entry &e =3D *it; + size_t len =3D (e.volume_name.size() + 1) * sizeof(WCHAR); + VSS_PWSZ volume =3D (VSS_PWSZ)CoTaskMemAlloc(len); + + if (!volume) { + hr =3D E_OUTOFMEMORY; + goto out; + } + memcpy(volume, e.volume_name.c_str(), len); + + /* not a real snapshot: no device object, exposure or timestamp */ + memset(prop, 0, sizeof(*prop)); + prop->m_SnapshotId =3D e.snapshot_id; + prop->m_SnapshotSetId =3D e.set_id; + prop->m_lSnapshotsCount =3D std::count_if(m_entries.begin(), + m_entries.end(), [&](const Entry &o) { + return IsEqualGUID(o.set_id, e.set_id); + }); + prop->m_pwszOriginalVolumeName =3D volume; + prop->m_ProviderId =3D g_gProviderId; + prop->m_lSnapshotAttributes =3D e.context; + prop->m_eStatus =3D VSS_SS_CREATED; + } + +out: + ReleaseSRWLockShared(&m_lock); + return hr; +} + +LONG QGAVssSnapshotRegistry::RemoveSet(VSS_ID set_id) +{ + LONG removed; + + AcquireSRWLockExclusive(&m_lock); + auto it =3D std::remove_if(m_entries.begin(), m_entries.end(), + [&](const Entry &e) { + return IsEqualGUID(e.set_id, set_id); + }); + removed =3D m_entries.end() - it; + m_entries.erase(it, m_entries.end()); + ReleaseSRWLockExclusive(&m_lock); + return removed; +} + +bool QGAVssSnapshotRegistry::Remove(VSS_ID snapshot_id) +{ + bool found; + + AcquireSRWLockExclusive(&m_lock); + auto it =3D std::find_if(m_entries.begin(), m_entries.end(), + [&](const Entry &e) { + return IsEqualGUID(e.snapshot_id, snapshot_id); + }); + found =3D it !=3D m_entries.end(); + if (found) { + m_entries.erase(it); + } + ReleaseSRWLockExclusive(&m_lock); + return found; +} =20 /* QGAVssProvider */ =20 @@ -266,7 +388,7 @@ STDMETHODIMP CQGAVssProvider::SetContext(LONG lContext) STDMETHODIMP CQGAVssProvider::GetSnapshotProperties( VSS_ID SnapshotId, VSS_SNAPSHOT_PROP *pProp) { - return S_OK; + return qga_vss_registry.GetProperties(SnapshotId, pProp); } =20 STDMETHODIMP CQGAVssProvider::Query( @@ -286,6 +408,27 @@ STDMETHODIMP CQGAVssProvider::DeleteSnapshots( VSS_ID SourceObjectId, VSS_OBJECT_TYPE eSourceObjectType, BOOL bForceDelete, LONG *plDeletedSnapshots, VSS_ID *pNondeletedSnapsh= otID) { + LONG deleted =3D 0; + + switch (eSourceObjectType) { + case VSS_OBJECT_SNAPSHOT: + if (qga_vss_registry.Remove(SourceObjectId)) { + deleted =3D 1; + } + break; + case VSS_OBJECT_SNAPSHOT_SET: + deleted =3D qga_vss_registry.RemoveSet(SourceObjectId); + break; + default: + break; + } + + if (deleted > 0) { + *plDeletedSnapshots =3D deleted; + *pNondeletedSnapshotID =3D GUID_NULL; + return S_OK; + } + *plDeletedSnapshots =3D 0; *pNondeletedSnapshotID =3D SourceObjectId; return S_OK; @@ -295,6 +438,13 @@ STDMETHODIMP CQGAVssProvider::BeginPrepareSnapshot( VSS_ID SnapshotSetId, VSS_ID SnapshotId, VSS_PWSZ pwszVolumeName, LONG lNewContext) { + if (!pwszVolumeName) { + return E_INVALIDARG; + } + if (!qga_vss_registry.Track(SnapshotSetId, SnapshotId, + pwszVolumeName, lNewContext)) { + return E_OUTOFMEMORY; + } return S_OK; } =20 @@ -411,6 +561,7 @@ STDMETHODIMP CQGAVssProvider::PostFinalCommitSnapshots(= VSS_ID SnapshotSetId) =20 STDMETHODIMP CQGAVssProvider::AbortSnapshots(VSS_ID SnapshotSetId) { + qga_vss_registry.RemoveSet(SnapshotSetId); return S_OK; } =20 diff --git a/qga/vss-win32/requester.cpp b/qga/vss-win32/requester.cpp index 1b0155c691ef..565eefcfb283 100644 --- a/qga/vss-win32/requester.cpp +++ b/qga/vss-win32/requester.cpp @@ -52,6 +52,7 @@ static t_VssFreeSnapshotProperties pVssFreeSnapshotProper= ties; static struct QGAVSSContext { IVssBackupComponents *pVssbc; /* VSS requester interface */ IVssAsync *pAsyncSnapshot; /* async info of VSS snapshot operation= */ + VSS_ID idSnapshotSet; /* snapshot set created for this cycle = */ HANDLE hEventFrozen; /* notify fs/writer freeze from provide= r */ HANDLE hEventThaw; /* request provider to thaw */ HANDLE hEventTimeout; /* notify timeout in provider */ @@ -116,6 +117,7 @@ static void requester_cleanup(void) vss_ctx.pVssbc->Release(); vss_ctx.pVssbc =3D NULL; } + vss_ctx.idSnapshotSet =3D GUID_NULL; vss_ctx.cFrozenVols =3D 0; qga_debug_end; } @@ -446,6 +448,7 @@ void requester_freeze(int *num_vols, void *mountpoints,= ErrorSet *errset) err_set(errset, hr, "failed to start snapshot set"); goto out; } + vss_ctx.idSnapshotSet =3D guidSnapshotSet; =20 if (mountpoints) { PWCHAR volume_name_wchar; @@ -680,6 +683,29 @@ void requester_thaw(int *num_vols, void *mountpints, E= rrorSet *errset) err_set(errset, hr, "failed to do snapshot set"); } =20 + /* + * The snapshot set is created in VSS_CTX_APP_ROLLBACK context, so + * it is persistent: if it was committed, VSS keeps it (and keeps + * querying providers about it) until it is explicitly deleted. The + * freeze/thaw cycle is over whatever the outcome above, so delete + * it now. Failure is not fatal here, only log it. + */ + { + LONG lDeletedSnapshots =3D 0; + VSS_ID idNonDeletedSnapshot; + HRESULT hrDelete; + + hrDelete =3D vss_ctx.pVssbc->DeleteSnapshots(vss_ctx.idSnapshotSet, + VSS_OBJECT_SNAPSHOT_SET, + TRUE, + &lDeletedSnapshots, + &idNonDeletedSnapshot); + if (FAILED(hrDelete)) { + qga_debug("failed to delete snapshot set after thaw," + " hr=3D0x%08lx", hrDelete); + } + } + if (err_is_set(errset)) { vss_ctx.pVssbc->AbortBackup(); } --=20 2.56.0.116.g6de20f6092dc