[libvirt] [PATCH v5 4/4] qemu: unlink the error report from VIR_STRDUP.

Julio Faracco posted 4 patches 6 years ago
[libvirt] [PATCH v5 4/4] qemu: unlink the error report from VIR_STRDUP.
Posted by Julio Faracco 6 years ago
The function to retrieve the file system info using QEMU-GA is using
some conditionals to retrieve the info. This is wrong because the error
of some conditionals will be raised if VIR_STRDUP return errors and not
if some problem occurred with JSON.

Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
---
 src/qemu/qemu_agent.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index ac728becef..36dc18d72f 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -1836,6 +1836,7 @@ qemuAgentGetFSInfo(qemuAgentPtr mon, virDomainFSInfoPtr **info,
     virJSONValuePtr data;
     virDomainFSInfoPtr *info_ret = NULL;
     virPCIDeviceAddress pci_address;
+    const char *result = NULL;
 
     cmd = qemuAgentMakeCommand("guest-get-fsinfo", NULL);
     if (!cmd)
@@ -1881,28 +1882,34 @@ qemuAgentGetFSInfo(qemuAgentPtr mon, virDomainFSInfoPtr **info,
         if (VIR_ALLOC(info_ret[i]) < 0)
             goto cleanup;
 
-        if (VIR_STRDUP(info_ret[i]->mountpoint,
-                       virJSONValueObjectGetString(entry, "mountpoint")) < 0) {
+        if (!(result = virJSONValueObjectGetString(entry, "mountpoint"))) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("'mountpoint' missing in reply of "
                              "guest-get-fsinfo"));
             goto cleanup;
         }
 
-        if (VIR_STRDUP(info_ret[i]->name,
-                       virJSONValueObjectGetString(entry, "name")) < 0) {
+        if (VIR_STRDUP(info_ret[i]->mountpoint, result) < 0)
+            goto cleanup;
+
+        if (!(result = virJSONValueObjectGetString(entry, "name"))) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("'name' missing in reply of guest-get-fsinfo"));
             goto cleanup;
         }
 
-        if (VIR_STRDUP(info_ret[i]->fstype,
-                       virJSONValueObjectGetString(entry, "type")) < 0) {
+        if (VIR_STRDUP(info_ret[i]->name, result) < 0)
+            goto cleanup;
+
+        if (!(result = virJSONValueObjectGetString(entry, "type"))) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("'type' missing in reply of guest-get-fsinfo"));
             goto cleanup;
         }
 
+        if (VIR_STRDUP(info_ret[i]->fstype, result) < 0)
+            goto cleanup;
+
         if (!(entry = virJSONValueObjectGet(entry, "disk"))) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("'disk' missing in reply of guest-get-fsinfo"));
-- 
2.17.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v5 4/4] qemu: unlink the error report from VIR_STRDUP.
Posted by John Ferlan 6 years ago

On 09/05/2018 12:20 AM, Julio Faracco wrote:
> The function to retrieve the file system info using QEMU-GA is using
> some conditionals to retrieve the info. This is wrong because the error
> of some conditionals will be raised if VIR_STRDUP return errors and not
> if some problem occurred with JSON.
> 
> Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
> ---
>  src/qemu/qemu_agent.c | 19 +++++++++++++------
>  1 file changed, 13 insertions(+), 6 deletions(-)
> 
> diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
> index ac728becef..36dc18d72f 100644
> --- a/src/qemu/qemu_agent.c
> +++ b/src/qemu/qemu_agent.c
> @@ -1836,6 +1836,7 @@ qemuAgentGetFSInfo(qemuAgentPtr mon, virDomainFSInfoPtr **info,
>      virJSONValuePtr data;
>      virDomainFSInfoPtr *info_ret = NULL;
>      virPCIDeviceAddress pci_address;
> +    const char *result = NULL;

This can move inside the for loop...

I can move before pushing...

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 4/4] qemu: unlink the error report from VIR_STRDUP.
Posted by Ján Tomko 6 years ago
The '.' at the end of the summary is not necessary

On Wed, Sep 05, 2018 at 01:20:56AM -0300, Julio Faracco wrote:
>The function to retrieve the file system info using QEMU-GA is using
>some conditionals to retrieve the info. This is wrong because the error
>of some conditionals will be raised if VIR_STRDUP return errors and not
>if some problem occurred with JSON.
>
>Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
>---
> src/qemu/qemu_agent.c | 19 +++++++++++++------
> 1 file changed, 13 insertions(+), 6 deletions(-)
>

This patch is unrelated to the rest of the series and can be pushed
separately.

Reviewed-by: Ján Tomko <jtomko@redhat.com>

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