[libvirt] [PATCH v3 4/6] virStream*All: Preserve reported error

Michal Privoznik posted 6 patches 8 years, 8 months ago
There is a newer version of this series
[libvirt] [PATCH v3 4/6] virStream*All: Preserve reported error
Posted by Michal Privoznik 8 years, 8 months ago
If one these four functions fail (virStreamRecvAll,
virStreamSendAll, virStreamSparseRecvAll, virStreamSparseSendAll)
the stream is aborted by calling virStreamAbort(). This is,
however, an public API - therefore the first thing it does is
error reset. At that point any error that caused us to abort
stream in the first place is gone.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/libvirt-stream.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/src/libvirt-stream.c b/src/libvirt-stream.c
index bff0a0571..1594ed212 100644
--- a/src/libvirt-stream.c
+++ b/src/libvirt-stream.c
@@ -614,7 +614,12 @@ virStreamSendAll(virStreamPtr stream,
     VIR_FREE(bytes);
 
     if (ret != 0) {
+        virErrorPtr orig_err = virSaveLastError();
         virStreamAbort(stream);
+        if (orig_err) {
+            virSetError(orig_err);
+            virFreeError(orig_err);
+        }
         virDispatchError(stream->conn);
     }
 
@@ -769,7 +774,12 @@ int virStreamSparseSendAll(virStreamPtr stream,
     VIR_FREE(bytes);
 
     if (ret != 0) {
+        virErrorPtr orig_err = virSaveLastError();
         virStreamAbort(stream);
+        if (orig_err) {
+            virSetError(orig_err);
+            virFreeError(orig_err);
+        }
         virDispatchError(stream->conn);
     }
 
@@ -863,7 +873,12 @@ virStreamRecvAll(virStreamPtr stream,
     VIR_FREE(bytes);
 
     if (ret != 0) {
+        virErrorPtr orig_err = virSaveLastError();
         virStreamAbort(stream);
+        if (orig_err) {
+            virSetError(orig_err);
+            virFreeError(orig_err);
+        }
         virDispatchError(stream->conn);
     }
 
@@ -983,7 +998,12 @@ virStreamSparseRecvAll(virStreamPtr stream,
     VIR_FREE(bytes);
 
     if (ret != 0) {
+        virErrorPtr orig_err = virSaveLastError();
         virStreamAbort(stream);
+        if (orig_err) {
+            virSetError(orig_err);
+            virFreeError(orig_err);
+        }
         virDispatchError(stream->conn);
     }
 
-- 
2.13.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v3 4/6] virStream*All: Preserve reported error
Posted by John Ferlan 8 years, 8 months ago

On 06/05/2017 04:22 AM, Michal Privoznik wrote:
> If one these four functions fail (virStreamRecvAll,
> virStreamSendAll, virStreamSparseRecvAll, virStreamSparseSendAll)
> the stream is aborted by calling virStreamAbort(). This is,
> however, an public API - therefore the first thing it does is

s/This is, however, an/This is a/
s/ - therefore/; therefore,/

> error reset. At that point any error that caused us to abort
> stream in the first place is gone.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  src/libvirt-stream.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 

Almost makes me wonder why we don't have a local/static helper that will
do the save, abort, restore rather than the repetition.

Reviewed-by: John Ferlan <jferlan@redhat.com>


John

> diff --git a/src/libvirt-stream.c b/src/libvirt-stream.c
> index bff0a0571..1594ed212 100644
> --- a/src/libvirt-stream.c
> +++ b/src/libvirt-stream.c
> @@ -614,7 +614,12 @@ virStreamSendAll(virStreamPtr stream,
>      VIR_FREE(bytes);
>  
>      if (ret != 0) {
> +        virErrorPtr orig_err = virSaveLastError();
>          virStreamAbort(stream);
> +        if (orig_err) {
> +            virSetError(orig_err);
> +            virFreeError(orig_err);
> +        }
>          virDispatchError(stream->conn);
>      }
>  
> @@ -769,7 +774,12 @@ int virStreamSparseSendAll(virStreamPtr stream,
>      VIR_FREE(bytes);
>  
>      if (ret != 0) {
> +        virErrorPtr orig_err = virSaveLastError();
>          virStreamAbort(stream);
> +        if (orig_err) {
> +            virSetError(orig_err);
> +            virFreeError(orig_err);
> +        }
>          virDispatchError(stream->conn);
>      }
>  
> @@ -863,7 +873,12 @@ virStreamRecvAll(virStreamPtr stream,
>      VIR_FREE(bytes);
>  
>      if (ret != 0) {
> +        virErrorPtr orig_err = virSaveLastError();
>          virStreamAbort(stream);
> +        if (orig_err) {
> +            virSetError(orig_err);
> +            virFreeError(orig_err);
> +        }
>          virDispatchError(stream->conn);
>      }
>  
> @@ -983,7 +998,12 @@ virStreamSparseRecvAll(virStreamPtr stream,
>      VIR_FREE(bytes);
>  
>      if (ret != 0) {
> +        virErrorPtr orig_err = virSaveLastError();
>          virStreamAbort(stream);
> +        if (orig_err) {
> +            virSetError(orig_err);
> +            virFreeError(orig_err);
> +        }
>          virDispatchError(stream->conn);
>      }
>  
> 

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list