From cb4adb43d6bf6944cbea8a128e134545d101d29c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= Date: Mon, 13 Feb 2017 23:53:42 +0100 Subject: [PATCH] util: storage: split function for JSON backing volume parsing in two MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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ý --- src/util/virstoragefile.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 3d4bda7002..715c0429d7 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -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) { -- 2.47.2