]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: storage: Report errors when source host data is missing
authorPeter Krempa <pkrempa@redhat.com>
Mon, 19 Jun 2017 12:47:41 +0000 (14:47 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 20 Jun 2017 06:40:18 +0000 (08:40 +0200)
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

index 9af0cdbcd357393553aba95c3405a9ea50b6fdb8..0bbbba650cc9207f0993b760ad32ba9724b3d824 100644 (file)
@@ -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,17 @@ 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;
+
+    if (!json) {
+        virReportError(VIR_ERR_INVALID_ARG, "%s",
+                       _("missing remote server specification in JSON "
+                         "backing volume definition"));
+        return -1;
+    }
 
-    if (!type) {
+    if (!(type = virJSONValueObjectGetString(json, "type"))) {
         virReportError(VIR_ERR_INVALID_ARG, "%s",
                        _("missing socket address type in "
                          "JSON backing volume definition"));
@@ -2838,7 +2855,7 @@ virStorageSourceParseBackingJSONSocketAddress(virStorageNetHostDefPtr host,
     } else if (STREQ(type, "unix")) {
         host->transport = 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"));