[libvirt] [PATCH v5 1/4] qemu: implementing qemuAgentGetHostname() function.

Julio Faracco posted 4 patches 6 years ago
[libvirt] [PATCH v5 1/4] qemu: implementing qemuAgentGetHostname() function.
Posted by Julio Faracco 6 years ago
This commit implements the function qemuAgentGetHostname() that uses
the QEMU guest agent command 'guest-get-host-name' to retrieve the
guest hostname of virtual machine running the QEMU-GA.

Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
---
 src/qemu/qemu_agent.c | 47 +++++++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_agent.h |  4 ++++
 2 files changed, 51 insertions(+)

diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index bf08871f18..ac728becef 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -1683,6 +1683,53 @@ qemuAgentUpdateCPUInfo(unsigned int nvcpus,
 }
 
 
+int
+qemuAgentGetHostname(qemuAgentPtr mon,
+                     char **hostname)
+{
+    int ret = -1;
+    virJSONValuePtr cmd;
+    virJSONValuePtr reply = NULL;
+    virJSONValuePtr data = NULL;
+    const char *result = NULL;
+
+    cmd = qemuAgentMakeCommand("guest-get-host-name",
+                               NULL);
+
+    if (!cmd)
+        return ret;
+
+    if (qemuAgentCommand(mon, cmd, &reply, true,
+                         VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0)
+        goto cleanup;
+
+    if (qemuAgentCheckError(cmd, reply) < 0)
+        goto cleanup;
+
+    if (!(data = virJSONValueObjectGet(reply, "return"))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("malformed return value"));
+        goto cleanup;
+    }
+
+    if (!(result = virJSONValueObjectGetString(data, "host-name"))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("'host-name' missing in guest-get-host-name reply"));
+        goto cleanup;
+    }
+
+    if (VIR_STRDUP(*hostname, result) < 0)
+        goto cleanup;
+
+    ret = 0;
+
+ cleanup:
+    virJSONValueFree(cmd);
+    virJSONValueFree(reply);
+    return ret;
+}
+
+
 int
 qemuAgentGetTime(qemuAgentPtr mon,
                  long long *seconds,
diff --git a/src/qemu/qemu_agent.h b/src/qemu/qemu_agent.h
index 6dd9c702dd..4354b7e0cf 100644
--- a/src/qemu/qemu_agent.h
+++ b/src/qemu/qemu_agent.h
@@ -105,6 +105,10 @@ int qemuAgentUpdateCPUInfo(unsigned int nvcpus,
                            qemuAgentCPUInfoPtr cpuinfo,
                            int ncpuinfo);
 
+int
+qemuAgentGetHostname(qemuAgentPtr mon,
+                     char **hostname);
+
 int qemuAgentGetTime(qemuAgentPtr mon,
                      long long *seconds,
                      unsigned int *nseconds);
-- 
2.17.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v5 1/4] qemu: implementing qemuAgentGetHostname() function.
Posted by John Ferlan 6 years ago

On 09/05/2018 12:20 AM, Julio Faracco wrote:
> This commit implements the function qemuAgentGetHostname() that uses
> the QEMU guest agent command 'guest-get-host-name' to retrieve the
> guest hostname of virtual machine running the QEMU-GA.
> 
> Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
> ---
>  src/qemu/qemu_agent.c | 47 +++++++++++++++++++++++++++++++++++++++++++
>  src/qemu/qemu_agent.h |  4 ++++
>  2 files changed, 51 insertions(+)
> 
> diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
> index bf08871f18..ac728becef 100644
> --- a/src/qemu/qemu_agent.c
> +++ b/src/qemu/qemu_agent.c
> @@ -1683,6 +1683,53 @@ qemuAgentUpdateCPUInfo(unsigned int nvcpus,
>  }
>  
>  
> +int
> +qemuAgentGetHostname(qemuAgentPtr mon,
> +                     char **hostname)
> +{
> +    int ret = -1;
> +    virJSONValuePtr cmd;
> +    virJSONValuePtr reply = NULL;
> +    virJSONValuePtr data = NULL;
> +    const char *result = NULL;
> +
> +    cmd = qemuAgentMakeCommand("guest-get-host-name",
> +                               NULL);
> +
> +    if (!cmd)
> +        return ret;
> +
> +    if (qemuAgentCommand(mon, cmd, &reply, true,
> +                         VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0)
> +        goto cleanup;
> +
> +    if (qemuAgentCheckError(cmd, reply) < 0)
> +        goto cleanup;

Hmmm - I hope my comments weren't misconstrued.  I think your v3 to drop
the call is correct since qemuAgentCommand already does this.

My point there was that there were a couple of other calls that added a
call to qemuAgentCheckError after qemuAgentCommand, but that doesn't
seem "right" based on mkletzan's commit 5b3492fadb.

In any case, I'll remove it in my branch and wait for your 'OK' before
pushing the series.

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

John

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v5 1/4] qemu: implementing qemuAgentGetHostname() function.
Posted by Julio Faracco 6 years ago
I don't remember if I sent any patch to include the check.
But I remember that I saw that @mkletzan put the check right after the
command execution.
So, when you run a command the function automatically check for errors
reported. Nice!

Well, @jferlan you have my Ok. ;-)

--
Julio Cesar Faracco
Em qua, 5 de set de 2018 às 14:08, John Ferlan <jferlan@redhat.com> escreveu:
>
>
>
> On 09/05/2018 12:20 AM, Julio Faracco wrote:
> > This commit implements the function qemuAgentGetHostname() that uses
> > the QEMU guest agent command 'guest-get-host-name' to retrieve the
> > guest hostname of virtual machine running the QEMU-GA.
> >
> > Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
> > ---
> >  src/qemu/qemu_agent.c | 47 +++++++++++++++++++++++++++++++++++++++++++
> >  src/qemu/qemu_agent.h |  4 ++++
> >  2 files changed, 51 insertions(+)
> >
> > diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
> > index bf08871f18..ac728becef 100644
> > --- a/src/qemu/qemu_agent.c
> > +++ b/src/qemu/qemu_agent.c
> > @@ -1683,6 +1683,53 @@ qemuAgentUpdateCPUInfo(unsigned int nvcpus,
> >  }
> >
> >
> > +int
> > +qemuAgentGetHostname(qemuAgentPtr mon,
> > +                     char **hostname)
> > +{
> > +    int ret = -1;
> > +    virJSONValuePtr cmd;
> > +    virJSONValuePtr reply = NULL;
> > +    virJSONValuePtr data = NULL;
> > +    const char *result = NULL;
> > +
> > +    cmd = qemuAgentMakeCommand("guest-get-host-name",
> > +                               NULL);
> > +
> > +    if (!cmd)
> > +        return ret;
> > +
> > +    if (qemuAgentCommand(mon, cmd, &reply, true,
> > +                         VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0)
> > +        goto cleanup;
> > +
> > +    if (qemuAgentCheckError(cmd, reply) < 0)
> > +        goto cleanup;
>
> Hmmm - I hope my comments weren't misconstrued.  I think your v3 to drop
> the call is correct since qemuAgentCommand already does this.
>
> My point there was that there were a couple of other calls that added a
> call to qemuAgentCheckError after qemuAgentCommand, but that doesn't
> seem "right" based on mkletzan's commit 5b3492fadb.
>
> In any case, I'll remove it in my branch and wait for your 'OK' before
> pushing the series.
>
> Reviewed-by: John Ferlan <jferlan@redhat.com>
>
> John
>

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