[libvirt] [PATCH 05/10] util: storage: Report errors when source host data is missing

Peter Krempa posted 10 patches 7 years, 11 months ago
There is a newer version of this series
[libvirt] [PATCH 05/10] util: storage: Report errors when source host data is missing
Posted by Peter Krempa 7 years, 11 months ago
Merge the reporting of the missing source host data into the parser
functions so that callers don't have to do it separately.
---
 src/util/virstoragefile.c | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index c7632808e..c0aa4e4c6 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -2798,8 +2798,18 @@ static int
 virStorageSourceParseBackingJSONInetSocketAddress(virStorageNetHostDefPtr host,
                                                   virJSONValuePtr json)
 {
-    const char *hostname = virJSONValueObjectGetString(json, "host");
-    const char *port = virJSONValueObjectGetString(json, "port");
+    const char *hostname;
+    const char *port;
+
+    if (!json) {
+        virReportError(VIR_ERR_INVALID_ARG, "%s",
+                       _("missing remote server specification in JSON "
+                         "backing volume definition"));
+        return -1;
+    }
+
+    hostname = virJSONValueObjectGetString(json, "host");
+    port = virJSONValueObjectGetString(json, "port");

     if (!hostname) {
         virReportError(VIR_ERR_INVALID_ARG, "%s",
@@ -2822,10 +2832,19 @@ static int
 virStorageSourceParseBackingJSONSocketAddress(virStorageNetHostDefPtr host,
                                               virJSONValuePtr json)
 {
-    const char *type = virJSONValueObjectGetString(json, "type");
-    const char *socket = virJSONValueObjectGetString(json, "socket");
+    const char *type;
+    const char *socket;
     int transport;

+    if (!json) {
+        virReportError(VIR_ERR_INVALID_ARG, "%s",
+                       _("missing remote server specification in JSON "
+                         "backing volume definition"));
+        return -1;
+    }
+
+    type = virJSONValueObjectGetString(json, "type");
+
     if ((transport = virStorageNetHostTransportTypeFromString(type)) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("unknown backing store transport protocol '%s'"), type);
@@ -2839,14 +2858,13 @@ virStorageSourceParseBackingJSONSocketAddress(virStorageNetHostDefPtr host,
         return virStorageSourceParseBackingJSONInetSocketAddress(host, json);

     case VIR_STORAGE_NET_HOST_TRANS_UNIX:
-        if (!socket) {
+        if (!(socket = virJSONValueObjectGetString(json, "socket"))) {
             virReportError(VIR_ERR_INVALID_ARG, "%s",
                            _("missing socket path for udp backing server in "
                              "JSON backing volume definition"));
             return -1;
         }

-
         if (VIR_STRDUP(host->socket, socket) < 0)
             return -1;
         break;
-- 
2.12.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 05/10] util: storage: Report errors when source host data is missing
Posted by Pavel Hrdina 7 years, 11 months ago
On Fri, Jun 16, 2017 at 05:29:42PM +0200, Peter Krempa wrote:
> Merge the reporting of the missing source host data into the parser
> functions so that callers don't have to do it separately.
> ---
>  src/util/virstoragefile.c | 30 ++++++++++++++++++++++++------
>  1 file changed, 24 insertions(+), 6 deletions(-)
> 
> diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
> index c7632808e..c0aa4e4c6 100644
> --- a/src/util/virstoragefile.c
> +++ b/src/util/virstoragefile.c

[...]

> @@ -2839,14 +2858,13 @@ virStorageSourceParseBackingJSONSocketAddress(virStorageNetHostDefPtr host,
>          return virStorageSourceParseBackingJSONInetSocketAddress(host, json);
> 
>      case VIR_STORAGE_NET_HOST_TRANS_UNIX:
> -        if (!socket) {
> +        if (!(socket = virJSONValueObjectGetString(json, "socket"))) {
>              virReportError(VIR_ERR_INVALID_ARG, "%s",
>                             _("missing socket path for udp backing server in "
>                               "JSON backing volume definition"));
>              return -1;
>          }
> 
> -

Spurious line removal :)

>          if (VIR_STRDUP(host->socket, socket) < 0)
>              return -1;

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list