[libvirt] [PATCH v2 1/4] virsh: net-port-create: log errors for non-existent xml file

morecache@gmail.com posted 4 patches 5 years, 4 months ago
[libvirt] [PATCH v2 1/4] virsh: net-port-create: log errors for non-existent xml file
Posted by morecache@gmail.com 5 years, 4 months ago
From: Lin Ma <lma@suse.de>

Signed-off-by: Lin Ma <lma@suse.de>
---
 tools/virsh-network.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/virsh-network.c b/tools/virsh-network.c
index 0351a93f19..24bc9107fc 100644
--- a/tools/virsh-network.c
+++ b/tools/virsh-network.c
@@ -1523,6 +1523,7 @@ cmdNetworkPortCreate(vshControl *ctl, const vshCmd *cmd)
 
     ret = true;
  cleanup:
+    vshSaveLibvirtError();
     VIR_FREE(buffer);
     if (port)
         virNetworkPortFree(port);
-- 
2.26.0

Re: [libvirt] [PATCH v2 1/4] virsh: net-port-create: log errors for non-existent xml file
Posted by Michal Privoznik 5 years, 4 months ago
On 9/16/20 9:17 AM, morecache@gmail.com wrote:
> From: Lin Ma <lma@suse.de>
> 
> Signed-off-by: Lin Ma <lma@suse.de>
> ---
>   tools/virsh-network.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/tools/virsh-network.c b/tools/virsh-network.c
> index 0351a93f19..24bc9107fc 100644
> --- a/tools/virsh-network.c
> +++ b/tools/virsh-network.c
> @@ -1523,6 +1523,7 @@ cmdNetworkPortCreate(vshControl *ctl, const vshCmd *cmd)
>   
>       ret = true;
>    cleanup:
> +    vshSaveLibvirtError();

I believe this must go under virFileReadAll():

     if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
         vshSaveLibvirtError();
         goto cleanup;
     }

We don't want to be reporting libvirt error every time we reach the 
label, because not all jumps onto that label are direct result of a 
failing function that uses virReportError().

Michal