]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: storage: Always deflatten JSON pseudo-protocol objects
authorPeter Krempa <pkrempa@redhat.com>
Tue, 11 Jul 2017 12:23:08 +0000 (14:23 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 11 Jul 2017 12:23:08 +0000 (14:23 +0200)
Now that the JSON deflattener is working sanely we can always attempt
the deflattening so that we can then parse the tree as expected.

src/util/virstoragefile.c

index ff78bc968eac6379efa4149e8bf8f0c64d38f693..6b814a675b1436e19da899ba4731a361931b3b9a 100644 (file)
@@ -3249,24 +3249,22 @@ static int
 virStorageSourceParseBackingJSONInternal(virStorageSourcePtr src,
                                          virJSONValuePtr json)
 {
-    virJSONValuePtr fixedroot = NULL;
+    virJSONValuePtr deflattened = NULL;
     virJSONValuePtr file;
     const char *drvname;
     char *str = NULL;
     size_t i;
     int ret = -1;
 
-    if (!(file = virJSONValueObjectGetObject(json, "file"))) {
-        if (!(fixedroot = virJSONValueObjectDeflatten(json)))
-            goto cleanup;
+    if (!(deflattened = virJSONValueObjectDeflatten(json)))
+        goto cleanup;
 
-        if (!(file = virJSONValueObjectGetObject(fixedroot, "file"))) {
-            str = virJSONValueToString(json, false);
-            virReportError(VIR_ERR_INVALID_ARG,
-                           _("JSON backing volume defintion '%s' lacks 'file' object"),
-                           NULLSTR(str));
-            goto cleanup;
-        }
+    if (!(file = virJSONValueObjectGetObject(deflattened, "file"))) {
+        str = virJSONValueToString(json, false);
+        virReportError(VIR_ERR_INVALID_ARG,
+                       _("JSON backing volume defintion '%s' lacks 'file' object"),
+                       NULLSTR(str));
+        goto cleanup;
     }
 
     if (!(drvname = virJSONValueObjectGetString(file, "driver"))) {
@@ -3290,7 +3288,7 @@ virStorageSourceParseBackingJSONInternal(virStorageSourcePtr src,
 
  cleanup:
     VIR_FREE(str);
-    virJSONValueFree(fixedroot);
+    virJSONValueFree(deflattened);
     return ret;
 }