From nobody Sat Oct 31 01:51:41 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=1793117197; cv=none; d=zohomail.com; s=zohoarc; b=GuJRRSRqgo0q5S4dhXeSeUwXKlcIUtqDT9jz/I3wr7vqaxYw3jezGJIykaAux00aifccL1mzHuv/1KcawEwpCITMcBQzvN3/iRO+uY2XkKshEz2EEdTwlyLQ3OXg+6sg50Tb+8UbhdOGKdV+OlHjWQg0Z6IUn6funKwXtQuFOXY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793117197; 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=VS56UV6NzI7CsMulryM9S6T8x5ukAoqPeZ7mKwwkK6w=; b=eLT/FINFygi2H2NO2Cp0N2G3dJW6AElJ864uJ753aXwUbcDhgMb36FtzGZ8SEjBn6KhQsDX9EOCbJJIcRpLeo9H9q8n4Q6ebNUFjra0reWnQDXvLZhUdkHzKn68vMDZng1SlljzUkCe8mjefUodPEfpicAjzS41aa93X6r26cIk= 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 1793117197275226.53428261475108; Tue, 27 Oct 2026 09:06:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLjgr-0002y7-IB; Tue, 27 Oct 2026 12:06:21 -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 1xLjgp-0002vA-TX for qemu-devel@nongnu.org; Tue, 27 Oct 2026 12:06:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLjgl-0006yG-SP for qemu-devel@nongnu.org; Tue, 27 Oct 2026 12:06:19 -0400 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-232-w7JCWTLXMkiS-Rz8Awyu-Q-1; Tue, 27 Oct 2026 12:06:12 -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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C814A1954206; Tue, 27 Oct 2026 16:06:10 +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 77CC8300019F; Tue, 27 Oct 2026 16:06:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793117174; 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=VS56UV6NzI7CsMulryM9S6T8x5ukAoqPeZ7mKwwkK6w=; b=Rc1HU3GbLcZL//x/ooh5As9kyszl7CACCzPaaRt4M55KGgH0PjV0vTdm5oLooNu6tYsTgQ Qi19Wqbzo1bJXjQaiGv7JhGz9wWlI/nGvFt4Sr+oOTCgTAJs4D4kRt6kJmj40q9eTGPy4A OgOHtDEkQeYPrviwVgsZyRqIhM4ntAM= X-MC-Unique: w7JCWTLXMkiS-Rz8Awyu-Q-1 X-Mimecast-MFC-AGG-ID: w7JCWTLXMkiS-Rz8Awyu-Q_1793117171 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 v2] qga/vss: fix provider handling of snapshots Date: Tue, 27 Oct 2026 20:06:07 +0400 Message-ID: <20261027160606.2668607-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.133.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_H3=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: 1793117200622158500 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 required properties, and return VSS_E_OBJECT_NOT_FOUND for anything else. Fill every required VSS_SNAPSHOT_PROP member except the exposed name and path, which are optional. The snapshot device object is an empty string because the host-side snapshot has no guest-visible device. 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 Reviewed-by: Kostiantyn Kostiuk --- v2: - fill the required VSS_SNAPSHOT_PROP fields --- qga/vss-win32/install.cpp | 1 + qga/vss-win32/provider.cpp | 200 +++++++++++++++++++++++++++++++++++- qga/vss-win32/requester.cpp | 26 +++++ 3 files changed, 226 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..bbc30dd57d85 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,170 @@ STDMETHODIMP CQGAVSSEnumObject::Clone(IVssEnumObject = **ppenum) return E_NOTIMPL; } =20 +static VSS_PWSZ qga_vss_strdup(const WCHAR *value) +{ + size_t len =3D (wcslen(value) + 1) * sizeof(WCHAR); + VSS_PWSZ str =3D (VSS_PWSZ)CoTaskMemAlloc(len); + + if (str) { + memcpy(str, value, len); + } + return str; +} + +static VSS_PWSZ qga_vss_strdup(const std::wstring &value) +{ + return qga_vss_strdup(value.c_str()); +} + +static VSS_TIMESTAMP qga_vss_timestamp(void) +{ + FILETIME ft; + ULARGE_INTEGER value; + + GetSystemTimeAsFileTime(&ft); + value.LowPart =3D ft.dwLowDateTime; + value.HighPart =3D ft.dwHighDateTime; + return value.QuadPart; +} + +/* 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; + VSS_TIMESTAMP timestamp; + }; + + 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, qga_vss_timestamp() }); + 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; + VSS_PWSZ device =3D NULL, original =3D NULL; + VSS_PWSZ originating =3D NULL, service =3D NULL; + + 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; + WCHAR machine[256] =3D L""; + DWORD machine_size =3D ARRAYSIZE(machine); + + if (!GetComputerNameExW(ComputerNameDnsFullyQualified, machine, + &machine_size)) { + *machine =3D L'\0'; + } + + device =3D qga_vss_strdup(L""); + original =3D qga_vss_strdup(e.volume_name); + originating =3D qga_vss_strdup(machine); + service =3D qga_vss_strdup(machine); + if (!device || !original || !originating || !service) { + hr =3D E_OUTOFMEMORY; + goto out; + } + + 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_pwszSnapshotDeviceObject =3D device; + prop->m_pwszOriginalVolumeName =3D original; + prop->m_pwszOriginatingMachine =3D originating; + prop->m_pwszServiceMachine =3D service; + prop->m_ProviderId =3D g_gProviderId; + prop->m_lSnapshotAttributes =3D e.context; + prop->m_tsCreationTimestamp =3D e.timestamp; + prop->m_eStatus =3D VSS_SS_CREATED; + + device =3D original =3D originating =3D service =3D NULL; + } + +out: + CoTaskMemFree(device); + CoTaskMemFree(original); + CoTaskMemFree(originating); + CoTaskMemFree(service); + 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 +435,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 +455,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 +485,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 +608,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