[PATCH 1/2] qga-vss: Replace asserts with condition and report error

Kostiantyn Kostiuk posted 2 patches 2 months, 3 weeks ago
Maintainers: Kostiantyn Kostiuk <kkostiuk@redhat.com>, Michael Roth <michael.roth@amd.com>
[PATCH 1/2] qga-vss: Replace asserts with condition and report error
Posted by Kostiantyn Kostiuk 2 months, 3 weeks ago
Signed-off-by: Kostiantyn Kostiuk <kkostiuk@redhat.com>
---
 qga/vss-win32/requester.cpp | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/qga/vss-win32/requester.cpp b/qga/vss-win32/requester.cpp
index 4401d55e3a..bc260abb96 100644
--- a/qga/vss-win32/requester.cpp
+++ b/qga/vss-win32/requester.cpp
@@ -347,7 +347,12 @@ void requester_freeze(int *num_vols, void *mountpoints, ErrorSet *errset)
         goto out;
     }
 
-    assert(pCreateVssBackupComponents != NULL);
+    if (!pCreateVssBackupComponents) {
+        err_set(errset, (HRESULT)ERROR_PROC_NOT_FOUND,
+                "CreateVssBackupComponents proc address absent. Did you call requester_init()?");
+        goto out;
+    }
+
     hr = pCreateVssBackupComponents(&vss_ctx.pVssbc);
     if (FAILED(hr)) {
         err_set(errset, hr, "failed to create VSS backup components");
@@ -579,8 +584,16 @@ void requester_thaw(int *num_vols, void *mountpints, ErrorSet *errset)
     /* Tell the provider that the snapshot is finished. */
     SetEvent(vss_ctx.hEventThaw);
 
-    assert(vss_ctx.pVssbc);
-    assert(vss_ctx.pAsyncSnapshot);
+    if (!vss_ctx.pVssbc) {
+        err_set(errset, (HRESULT)VSS_E_BAD_STATE,
+                "CreateVssBackupComponents is missing. Did you freeze the volumes?");
+        return;
+    }
+    if (!vss_ctx.pAsyncSnapshot) {
+        err_set(errset, (HRESULT)VSS_E_BAD_STATE,
+                "AsyncSnapshot set is missing. Did you freeze the volumes?");
+        return;
+    }
 
     HRESULT hr = WaitForAsync(vss_ctx.pAsyncSnapshot);
     switch (hr) {
-- 
2.50.1
Re: [PATCH 1/2] qga-vss: Replace asserts with condition and report error
Posted by Yan Vugenfirer 2 months, 2 weeks ago
On Mon, Aug 25, 2025 at 5:52 PM Kostiantyn Kostiuk <kkostiuk@redhat.com> wrote:
>
> Signed-off-by: Kostiantyn Kostiuk <kkostiuk@redhat.com>
> ---
>  qga/vss-win32/requester.cpp | 19 ++++++++++++++++---
>  1 file changed, 16 insertions(+), 3 deletions(-)
>
> diff --git a/qga/vss-win32/requester.cpp b/qga/vss-win32/requester.cpp
> index 4401d55e3a..bc260abb96 100644
> --- a/qga/vss-win32/requester.cpp
> +++ b/qga/vss-win32/requester.cpp
> @@ -347,7 +347,12 @@ void requester_freeze(int *num_vols, void *mountpoints, ErrorSet *errset)
>          goto out;
>      }
>
> -    assert(pCreateVssBackupComponents != NULL);
> +    if (!pCreateVssBackupComponents) {
> +        err_set(errset, (HRESULT)ERROR_PROC_NOT_FOUND,
> +                "CreateVssBackupComponents proc address absent. Did you call requester_init()?");
> +        goto out;
> +    }
> +
>      hr = pCreateVssBackupComponents(&vss_ctx.pVssbc);
>      if (FAILED(hr)) {
>          err_set(errset, hr, "failed to create VSS backup components");
> @@ -579,8 +584,16 @@ void requester_thaw(int *num_vols, void *mountpints, ErrorSet *errset)
>      /* Tell the provider that the snapshot is finished. */
>      SetEvent(vss_ctx.hEventThaw);
>
> -    assert(vss_ctx.pVssbc);
> -    assert(vss_ctx.pAsyncSnapshot);
> +    if (!vss_ctx.pVssbc) {
> +        err_set(errset, (HRESULT)VSS_E_BAD_STATE,
> +                "CreateVssBackupComponents is missing. Did you freeze the volumes?");
> +        return;
> +    }
> +    if (!vss_ctx.pAsyncSnapshot) {
> +        err_set(errset, (HRESULT)VSS_E_BAD_STATE,
> +                "AsyncSnapshot set is missing. Did you freeze the volumes?");
> +        return;
> +    }
>
>      HRESULT hr = WaitForAsync(vss_ctx.pAsyncSnapshot);
>      switch (hr) {
> --
> 2.50.1
>

Reviewed-by: Yan Vugenfirer <yvugenfi@redhat.com>