提交 cb4adb43 编写于 作者: T Tomáš Golembiovský 提交者: Peter Krempa

util: storage: split function for JSON backing volume parsing in two

Split virStorageSourceParseBackingJSON into two functions so that the
core can be reused by other functions. The new function called
virStorageSourceParseBackingJSONInternal accepts virJSONValuePtr.
Signed-off-by: NTomáš Golembiovský <tgolembi@redhat.com>
上级 b26401fa
......@@ -3053,29 +3053,28 @@ virStorageSourceParseBackingJSONDeflatten(virJSONValuePtr json)
static int
virStorageSourceParseBackingJSON(virStorageSourcePtr src,
const char *json)
virStorageSourceParseBackingJSONInternal(virStorageSourcePtr src,
virJSONValuePtr json)
{
virJSONValuePtr root = NULL;
virJSONValuePtr fixedroot = NULL;
virJSONValuePtr file;
const char *drvname;
char *str = NULL;
size_t i;
int ret = -1;
if (!(root = virJSONValueFromString(json)))
return -1;
if (!(file = virJSONValueObjectGetObject(root, "file"))) {
if (!(fixedroot = virStorageSourceParseBackingJSONDeflatten(root)))
if (!(file = virJSONValueObjectGetObject(json, "file"))) {
if (!(fixedroot = virStorageSourceParseBackingJSONDeflatten(json)))
goto cleanup;
file = fixedroot;
}
if (!(drvname = virJSONValueObjectGetString(file, "driver"))) {
virReportError(VIR_ERR_INVALID_ARG, _("JSON backing volume defintion "
"'%s' lacks driver name"), json);
str = virJSONValueToString(json, false);
virReportError(VIR_ERR_INVALID_ARG,
_("JSON backing volume defintion '%s' lacks driver name"),
NULLSTR(str));
goto cleanup;
}
......@@ -3091,12 +3090,29 @@ virStorageSourceParseBackingJSON(virStorageSourcePtr src,
"driver '%s'"), drvname);
cleanup:
virJSONValueFree(root);
VIR_FREE(str);
virJSONValueFree(fixedroot);
return ret;
}
static int
virStorageSourceParseBackingJSON(virStorageSourcePtr src,
const char *json)
{
virJSONValuePtr root = NULL;
int ret = -1;
if (!(root = virJSONValueFromString(json)))
return -1;
ret = virStorageSourceParseBackingJSONInternal(src, root);
virJSONValueFree(root);
return ret;
}
virStorageSourcePtr
virStorageSourceNewFromBackingAbsolute(const char *path)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册
新手
引导
客服 返回
顶部