提交 f43b7d60 编写于 作者: P Peter Krempa

util: json: Don't remove the 'file' subobject when deflattening

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.
上级 de75de7c
...@@ -2012,17 +2012,24 @@ virJSONValueObjectDeflattenWorker(const char *key, ...@@ -2012,17 +2012,24 @@ virJSONValueObjectDeflattenWorker(const char *key,
virJSONValuePtr virJSONValuePtr
virJSONValueObjectDeflatten(virJSONValuePtr json) virJSONValueObjectDeflatten(virJSONValuePtr json)
{ {
virJSONValuePtr ret; virJSONValuePtr deflattened;
virJSONValuePtr ret = NULL;
if (!(ret = virJSONValueNewObject())) if (!(deflattened = virJSONValueNewObject()))
return NULL; return NULL;
if (virJSONValueObjectForeachKeyValue(json, if (virJSONValueObjectForeachKeyValue(json,
virJSONValueObjectDeflattenWorker, virJSONValueObjectDeflattenWorker,
ret) < 0) { deflattened) < 0)
virJSONValueFree(ret); goto cleanup;
return NULL;
} if (virJSONValueObjectCreate(&ret, "a:file", deflattened, NULL) < 0)
goto cleanup;
deflattened = NULL;
cleanup:
virJSONValueFree(deflattened);
return ret; return ret;
} }
...@@ -3260,7 +3260,13 @@ virStorageSourceParseBackingJSONInternal(virStorageSourcePtr src, ...@@ -3260,7 +3260,13 @@ virStorageSourceParseBackingJSONInternal(virStorageSourcePtr src,
if (!(fixedroot = virJSONValueObjectDeflatten(json))) if (!(fixedroot = virJSONValueObjectDeflatten(json)))
goto cleanup; 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"))) { if (!(drvname = virJSONValueObjectGetString(file, "driver"))) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册