From nobody Mon Nov 23 04:18:31 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=1793208277; cv=none; d=zohomail.com; s=zohoarc; b=l8LvEp1EfgnOWwT6aZRzTrVKCNWBesHPQ5xEQeZeTpkClMDv6+bw9ytIjU3lWmbzjnWcOalhEUVgEAbauemevFCGISVD8GpbE4lF4Gr/8Qmu0sCt9RkI6++11a3ssKTHvcQ82YcsolCM+ojDO4VxObwjDx4AZUW47Nw9jZic2h8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793208277; h=Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To: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:Cc; bh=mPGvaIEGY9937KE7Q0ZokV9FarrUDshyAGcLN2e4QFk=; b=AysM40THm8fsUEww3uwQD/1g4NocdA1O82EQZaAMZQyVuVZJH9JH+7K500HkDnfziRwKCrWO7l7ZwN7Zl4h+nWnorSQImnbUCZonZfa9nw94MAqDaquGNeBfL96ULH0I//CQXRC1tGcTCirdaG0Vnh/ngooYrE/2hrgY/1J0C0w= 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 1793208277770113.23810135365568; Wed, 28 Oct 2026 10:24:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xM7Nz-000523-Sf; Wed, 28 Oct 2026 13:24:31 -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 1xM7NX-0004lZ-Da for qemu-devel@nongnu.org; Wed, 28 Oct 2026 13:24:04 -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 1xM7NV-0004zL-JI for qemu-devel@nongnu.org; Wed, 28 Oct 2026 13:23:59 -0400 Received: from mx-prod-mc-06.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-541-a4Bp7nscMeqMMNvLSp6C8w-1; Wed, 28 Oct 2026 13:23:50 -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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 613FF18005BA; Wed, 28 Oct 2026 17:23:48 +0000 (UTC) Received: from Kostiantyns-MacBook-Pro.redhat.com (unknown [10.44.32.20]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 31465195608D; Wed, 28 Oct 2026 17:23:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793208233; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mPGvaIEGY9937KE7Q0ZokV9FarrUDshyAGcLN2e4QFk=; b=EP/84NmjU+vb66w0kKDG6XMWAjsIqj3sRz3EUXbqZuvcdEjEKUDK/2HkQRgu2lrfGZKEl0 TlE3qBFZSWw3on6T156A9IEK91DocgMquidClICPMpqFVFMHwbTQJBQwfWsZmIsV+UCErk vrqk4wLOWxW+TQl2SGh4TmlXh3kBBr8= X-MC-Unique: a4Bp7nscMeqMMNvLSp6C8w-1 X-Mimecast-MFC-AGG-ID: a4Bp7nscMeqMMNvLSp6C8w_1793208228 From: Kostiantyn Kostiuk To: qemu-devel@nongnu.org, Peter Maydell , Richard Henderson Subject: [PULL 1/2] qga: do not run hwclock(8) on non-Linux POSIX OSes Date: Wed, 28 Oct 2026 19:23:41 +0200 Message-ID: <20261028172342.96036-2-kkostiuk@redhat.com> In-Reply-To: <20261028172342.96036-1-kkostiuk@redhat.com> References: <20261028172342.96036-1-kkostiuk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=kkostiuk@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham 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: 1793208280008154100 Content-Type: text/plain; charset="utf-8" From: Roman Bogorodskiy Currently, qmp_guest_set_time() sets system time using the settimeofday(2) system call and then runs the hwclock(8) util to set hardware time. hwclock(8) is Linux only, so current implementation always fails while trying to run it on non-Linux POSIX OSes, such as BSDs (FreeBSD, OpenBSD, NetBSD) and illumos. Update the code not to run it on non-Linux. The settimeofday(2) call sets both system and hardware time on these systems. For example, on FreeBSD settimeofday() calls settime() which calls resettodr() [1] which updates RTC clock [2]. It is similar on OpenBSD and NetBSD, though implementations differ a bit. Additional detail: on FreeBSD RTC clock setting can be disabled with the `machdep.disable_rtc_set` sysctl. As we cannot do anything about it, do not handle that case separately. Non-Linux POSIX OSes do not provide a common utility equivalent to hwclock -s, so report an unsupported operation when no time is supplied. 1: https://cgit.freebsd.org/src/tree/sys/kern/kern_time.c 2: https://cgit.freebsd.org/src/tree/sys/kern/subr_rtc.c Signed-off-by: Roman Bogorodskiy Reviewed-by: Kostiantyn Kostiuk Link: https://lore.kernel.org/qemu-devel/20261015142342.50436-1-bogorodskiy= @gmail.com Signed-off-by: Kostiantyn Kostiuk --- qga/commands-posix.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index dcc683f6c9..cfa5627a61 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -322,6 +322,20 @@ void qmp_guest_set_time(bool has_time, int64_t time_ns= , Error **errp) } } =20 +#if !defined(CONFIG_LINUX) + /* + * BSDs (FreeBSD, OpenBSD, NetBSD) and illumos do not have the + * hwclock(8) tool. These systems update hardware clock when + * settimeofday() sets system time, so no additional actions + * are needed. Setting system time from RTC is not supported. + */ + if (!has_time) { + error_setg(errp, "Setting system time from RTC is not supported"); + } + + return; +#endif + /* Now, if user has passed a time to set and the system time is set, we * just need to synchronize the hardware clock. However, if no time was * passed, user is requesting the opposite: set the system time from t= he --=20 2.54.0 (Apple Git-157) From nobody Mon Nov 23 04:18:31 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=1793208310; cv=none; d=zohomail.com; s=zohoarc; b=jjZYan9Y4/VUKqr+ULi6JdPLt5lGCe0sOMcfecw/fzbraII3hFHm1xFduKzaD5QPCvUGkvjxV/b4SOBeIc4dN8RQUMzT65Gb2emB7tudS9qlK1rHcGww8RnuOzYOsVWPJsjcZeyCYUkVy3mh1Tgb0uoLw+om8go8ebiUceUa9i8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793208310; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To: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:Cc; bh=PFcAr6/aE50M+7rVT8l3cEh7YIP/JkjqUfA1WCLxqFY=; b=d6u2GN31Zc+sii/nhbDp0oznRiaun9dG0vlMtDLN09nA389RiDBjoZUGWcBYwc7Py+MbxkKwwHej8rBjhCUoFhT6KRCL/zirrlXbIOBmgYNkD2L4eU2JEPr8nDBbYmYZUh4h8KtvSOUyM106fnfqfn6G57VoOgXkwgpsmkxvKxQ= 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 1793208310785744.2944776796573; Wed, 28 Oct 2026 10:25:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xM7OZ-0005Q8-Ub; Wed, 28 Oct 2026 13:25:04 -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 1xM7Nb-0004qS-3R for qemu-devel@nongnu.org; Wed, 28 Oct 2026 13:24:07 -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 1xM7NY-0004zz-3K for qemu-devel@nongnu.org; Wed, 28 Oct 2026 13:24:02 -0400 Received: from mx-prod-mc-06.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-557-8TKwqKiqMs2m8bjFoFi9uw-1; Wed, 28 Oct 2026 13:23:51 -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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3DF771800597; Wed, 28 Oct 2026 17:23:50 +0000 (UTC) Received: from Kostiantyns-MacBook-Pro.redhat.com (unknown [10.44.32.20]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 09137195608D; Wed, 28 Oct 2026 17:23:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793208239; 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=PFcAr6/aE50M+7rVT8l3cEh7YIP/JkjqUfA1WCLxqFY=; b=HINXr5jgyTL7LsnqB5WpUrJ5mDj7rQSQvIKXFFhmINU38yOkMsMyEpVk0honZjAZkK8B5u 7+v+SenMfUJfotQJGIHes5ElPRRffRh01UblDtiuLefWFLeebc6YDDEw+LWQCSG7s7qpMA fU8pOkEBMuhGMuausQ/5SeKwFyRhvXo= X-MC-Unique: 8TKwqKiqMs2m8bjFoFi9uw-1 X-Mimecast-MFC-AGG-ID: 8TKwqKiqMs2m8bjFoFi9uw_1793208230 From: Kostiantyn Kostiuk To: qemu-devel@nongnu.org, Peter Maydell , Richard Henderson Subject: [PULL 2/2] qga/vss: fix provider handling of snapshots Date: Wed, 28 Oct 2026 19:23:42 +0200 Message-ID: <20261028172342.96036-3-kkostiuk@redhat.com> In-Reply-To: <20261028172342.96036-1-kkostiuk@redhat.com> References: <20261028172342.96036-1-kkostiuk@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=kkostiuk@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham 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: 1793208312231158500 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 Link: https://lore.kernel.org/qemu-devel/20261027160606.2668607-2-marcandre= .lureau@redhat.com Reviewed-by: Kostiantyn Kostiuk Signed-off-by: Kostiantyn Kostiuk --- 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 431fcd1cbe..df00588c92 100644 --- a/qga/vss-win32/install.cpp +++ b/qga/vss-win32/install.cpp @@ -422,6 +422,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 1c8eb236e5..bbc30dd57d 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 1b0155c691..565eefcfb2 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.54.0 (Apple Git-157)