[libvirt] [PATCH 3/3] libvirt-qemu: Dispatch errors from virDomainQemuAgentCommand()

Martin Kletzander mkletzan at redhat.com
Mon Jun 3 15:22:48 UTC 2013


On 06/03/2013 04:35 PM, Peter Krempa wrote:
> The original implementation didn't follow the established pattern and
> did not dispatch errors in case of failure.
> ---
>  src/libvirt-qemu.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/src/libvirt-qemu.c b/src/libvirt-qemu.c
> index 747488d..e884e32 100644
> --- a/src/libvirt-qemu.c
> +++ b/src/libvirt-qemu.c
> @@ -211,6 +211,7 @@ virDomainQemuAgentCommand(virDomainPtr domain,
>                            unsigned int flags)
>  {
>      virConnectPtr conn;
> +    char *ret;
> 
>      VIR_DEBUG("domain=%p, cmd=%s, timeout=%d, flags=%x",
>                domain, cmd, timeout, flags);
> @@ -228,13 +229,17 @@ virDomainQemuAgentCommand(virDomainPtr domain,
>      conn = domain->conn;
> 
>      if (conn->driver->domainQemuAgentCommand) {
> -        return conn->driver->domainQemuAgentCommand(domain, cmd,
> -                                                    timeout, flags);
> +        ret = conn->driver->domainQemuAgentCommand(domain, cmd,
> +                                                   timeout, flags);
> +        if (!ret)
> +            goto error;
> +        return ret;
>      }
> 
>      virLibConnError(conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
> 
>      /* Copy to connection error object for back compatibility */
> +error:
>      virDispatchError(conn);
>      return NULL;
>  }
> 

One more fix would fit here, so ACK with this squashed in:

diff --git a/src/libvirt-qemu.c b/src/libvirt-qemu.c
index e884e32..9dd76dd 100644
--- a/src/libvirt-qemu.c
+++ b/src/libvirt-qemu.c
@@ -221,13 +221,14 @@ virDomainQemuAgentCommand(virDomainPtr domain,
         virDispatchError(NULL);
         return NULL;
     }
+
+    conn = domain->conn;
+
     if (domain->conn->flags & VIR_CONNECT_RO) {
         virLibDomainError(NULL, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
-        return NULL;
+        goto error;
     }

-    conn = domain->conn;
-
     if (conn->driver->domainQemuAgentCommand) {
         ret = conn->driver->domainQemuAgentCommand(domain, cmd,
                                                    timeout, flags);
--

Martin




More information about the libvir-list mailing list