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.
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;
}
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"))) {