mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-23 20:02:21 +00:00
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: Tomáš Golembiovský <tgolembi@redhat.com>
This commit is contained in:
parent
b26401fab3
commit
cb4adb43d6
@ -3053,29 +3053,28 @@ virStorageSourceParseBackingJSONDeflatten(virJSONValuePtr json)
|
|||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virStorageSourceParseBackingJSON(virStorageSourcePtr src,
|
virStorageSourceParseBackingJSONInternal(virStorageSourcePtr src,
|
||||||
const char *json)
|
virJSONValuePtr json)
|
||||||
{
|
{
|
||||||
virJSONValuePtr root = NULL;
|
|
||||||
virJSONValuePtr fixedroot = NULL;
|
virJSONValuePtr fixedroot = NULL;
|
||||||
virJSONValuePtr file;
|
virJSONValuePtr file;
|
||||||
const char *drvname;
|
const char *drvname;
|
||||||
|
char *str = NULL;
|
||||||
size_t i;
|
size_t i;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (!(root = virJSONValueFromString(json)))
|
if (!(file = virJSONValueObjectGetObject(json, "file"))) {
|
||||||
return -1;
|
if (!(fixedroot = virStorageSourceParseBackingJSONDeflatten(json)))
|
||||||
|
|
||||||
if (!(file = virJSONValueObjectGetObject(root, "file"))) {
|
|
||||||
if (!(fixedroot = virStorageSourceParseBackingJSONDeflatten(root)))
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
file = fixedroot;
|
file = fixedroot;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(drvname = virJSONValueObjectGetString(file, "driver"))) {
|
if (!(drvname = virJSONValueObjectGetString(file, "driver"))) {
|
||||||
virReportError(VIR_ERR_INVALID_ARG, _("JSON backing volume defintion "
|
str = virJSONValueToString(json, false);
|
||||||
"'%s' lacks driver name"), json);
|
virReportError(VIR_ERR_INVALID_ARG,
|
||||||
|
_("JSON backing volume defintion '%s' lacks driver name"),
|
||||||
|
NULLSTR(str));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3091,12 +3090,29 @@ virStorageSourceParseBackingJSON(virStorageSourcePtr src,
|
|||||||
"driver '%s'"), drvname);
|
"driver '%s'"), drvname);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virJSONValueFree(root);
|
VIR_FREE(str);
|
||||||
virJSONValueFree(fixedroot);
|
virJSONValueFree(fixedroot);
|
||||||
return ret;
|
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
|
virStorageSourcePtr
|
||||||
virStorageSourceNewFromBackingAbsolute(const char *path)
|
virStorageSourceNewFromBackingAbsolute(const char *path)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user