]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: json: Don't remove the 'file' subobject when deflattening
authorPeter Krempa <pkrempa@redhat.com>
Mon, 26 Jun 2017 16:42:07 +0000 (18:42 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 11 Jul 2017 12:10:31 +0000 (14:10 +0200)
Currently the function would deflatten the object by dropping the 'file'
prefix from the attributes. This does not really scale well or adhere to
the documentation.

Until we refactor the worker to properly deflatten everything we at
least simulate it by adding the "file" wrapper object back.

src/util/virjson.c
src/util/virstoragefile.c

index 3c3a54bc7c5360d2d016a1956cfacb6a146ad06b..d55913a14346afd50c3d4d1d958ac7d521e0115d 100644 (file)
@@ -2012,17 +2012,24 @@ virJSONValueObjectDeflattenWorker(const char *key,
 virJSONValuePtr
 virJSONValueObjectDeflatten(virJSONValuePtr json)
 {
-    virJSONValuePtr ret;
+    virJSONValuePtr deflattened;
+    virJSONValuePtr ret = NULL;
 
-    if (!(ret = virJSONValueNewObject()))
+    if (!(deflattened = virJSONValueNewObject()))
         return NULL;
 
     if (virJSONValueObjectForeachKeyValue(json,
                                           virJSONValueObjectDeflattenWorker,
-                                          ret) < 0) {
-        virJSONValueFree(ret);
-        return NULL;
-    }
+                                          deflattened) < 0)
+        goto cleanup;
+
+    if (virJSONValueObjectCreate(&ret, "a:file", deflattened, NULL) < 0)
+        goto cleanup;
+
+    deflattened = NULL;
+
+ cleanup:
+    virJSONValueFree(deflattened);
 
     return ret;
 }
index 52c5301fffd4a34ce956287e65e2413aa8dc55fd..ff78bc968eac6379efa4149e8bf8f0c64d38f693 100644 (file)
@@ -3260,7 +3260,13 @@ virStorageSourceParseBackingJSONInternal(virStorageSourcePtr src,
         if (!(fixedroot = virJSONValueObjectDeflatten(json)))
             goto cleanup;
 
-        file = fixedroot;
+        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 (!(drvname = virJSONValueObjectGetString(file, "driver"))) {