|
|
fbe740 |
From 3a01f1148ea3da0a572a196f987f29f12e397ec1 Mon Sep 17 00:00:00 2001
|
|
|
fbe740 |
Message-Id: <3a01f1148ea3da0a572a196f987f29f12e397ec1@dist-git>
|
|
|
fbe740 |
From: Peter Krempa <pkrempa@redhat.com>
|
|
|
fbe740 |
Date: Wed, 19 Feb 2020 15:10:09 +0100
|
|
|
fbe740 |
Subject: [PATCH] virStorageSourceParseBackingJSON: Allow 'json:' pseudo URIs
|
|
|
fbe740 |
without 'file' wrapper
|
|
|
fbe740 |
MIME-Version: 1.0
|
|
|
fbe740 |
Content-Type: text/plain; charset=UTF-8
|
|
|
fbe740 |
Content-Transfer-Encoding: 8bit
|
|
|
fbe740 |
|
|
|
fbe740 |
There are two possibilities:
|
|
|
fbe740 |
1) json:{"file":{"driver":...}}
|
|
|
fbe740 |
2) json:{"driver":...}
|
|
|
fbe740 |
|
|
|
fbe740 |
Our code didn't work properly with the second one as it was expecting
|
|
|
fbe740 |
the 'file' wrapper. Conditionalize the removal to only the situation
|
|
|
fbe740 |
when the top level doesn't have "driver".
|
|
|
fbe740 |
|
|
|
fbe740 |
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
|
|
|
fbe740 |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
fbe740 |
(cherry picked from commit f8e097570ea9eb0b446f9ff5159b4e9c337e6b07)
|
|
|
fbe740 |
|
|
|
fbe740 |
https://bugzilla.redhat.com/show_bug.cgi?id=1791788
|
|
|
fbe740 |
Message-Id: <26a21da3bf0642ed6ac80184f97337fba98b0c14.1582120424.git.pkrempa@redhat.com>
|
|
|
fbe740 |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
fbe740 |
---
|
|
|
fbe740 |
src/util/virstoragefile.c | 41 +++++++++++++++++++++++++--------------
|
|
|
fbe740 |
1 file changed, 26 insertions(+), 15 deletions(-)
|
|
|
fbe740 |
|
|
|
fbe740 |
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
|
|
|
fbe740 |
index b6749b150c..dd05de188f 100644
|
|
|
fbe740 |
--- a/src/util/virstoragefile.c
|
|
|
fbe740 |
+++ b/src/util/virstoragefile.c
|
|
|
fbe740 |
@@ -3521,10 +3521,17 @@ virStorageSourceParseBackingJSONRaw(virStorageSourcePtr src,
|
|
|
fbe740 |
const char *jsonstr,
|
|
|
fbe740 |
int opaque G_GNUC_UNUSED)
|
|
|
fbe740 |
{
|
|
|
fbe740 |
- /* There are no interesting attributes in raw driver.
|
|
|
fbe740 |
- * Treat it as pass-through.
|
|
|
fbe740 |
- */
|
|
|
fbe740 |
- return virStorageSourceParseBackingJSONInternal(src, json, jsonstr);
|
|
|
fbe740 |
+ virJSONValuePtr file;
|
|
|
fbe740 |
+
|
|
|
fbe740 |
+ /* 'raw' is a format driver so it can have protocol driver children */
|
|
|
fbe740 |
+ if (!(file = virJSONValueObjectGetObject(json, "file"))) {
|
|
|
fbe740 |
+ virReportError(VIR_ERR_INVALID_ARG,
|
|
|
fbe740 |
+ _("JSON backing volume definition '%s' lacks 'file' object"),
|
|
|
fbe740 |
+ jsonstr);
|
|
|
fbe740 |
+ return -1;
|
|
|
fbe740 |
+ }
|
|
|
fbe740 |
+
|
|
|
fbe740 |
+ return virStorageSourceParseBackingJSONInternal(src, file, jsonstr);
|
|
|
fbe740 |
}
|
|
|
fbe740 |
|
|
|
fbe740 |
|
|
|
fbe740 |
@@ -3601,18 +3608,10 @@ virStorageSourceParseBackingJSONInternal(virStorageSourcePtr src,
|
|
|
fbe740 |
virJSONValuePtr json,
|
|
|
fbe740 |
const char *jsonstr)
|
|
|
fbe740 |
{
|
|
|
fbe740 |
- virJSONValuePtr file;
|
|
|
fbe740 |
const char *drvname;
|
|
|
fbe740 |
size_t i;
|
|
|
fbe740 |
|
|
|
fbe740 |
- if (!(file = virJSONValueObjectGetObject(json, "file"))) {
|
|
|
fbe740 |
- virReportError(VIR_ERR_INVALID_ARG,
|
|
|
fbe740 |
- _("JSON backing volume definition '%s' lacks 'file' object"),
|
|
|
fbe740 |
- jsonstr);
|
|
|
fbe740 |
- return -1;
|
|
|
fbe740 |
- }
|
|
|
fbe740 |
-
|
|
|
fbe740 |
- if (!(drvname = virJSONValueObjectGetString(file, "driver"))) {
|
|
|
fbe740 |
+ if (!(drvname = virJSONValueObjectGetString(json, "driver"))) {
|
|
|
fbe740 |
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
fbe740 |
_("JSON backing volume definition '%s' lacks driver name"),
|
|
|
fbe740 |
jsonstr);
|
|
|
fbe740 |
@@ -3621,7 +3620,7 @@ virStorageSourceParseBackingJSONInternal(virStorageSourcePtr src,
|
|
|
fbe740 |
|
|
|
fbe740 |
for (i = 0; i < G_N_ELEMENTS(jsonParsers); i++) {
|
|
|
fbe740 |
if (STREQ(drvname, jsonParsers[i].drvname))
|
|
|
fbe740 |
- return jsonParsers[i].func(src, file, jsonstr, jsonParsers[i].opaque);
|
|
|
fbe740 |
+ return jsonParsers[i].func(src, json, jsonstr, jsonParsers[i].opaque);
|
|
|
fbe740 |
}
|
|
|
fbe740 |
|
|
|
fbe740 |
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
fbe740 |
@@ -3637,6 +3636,7 @@ virStorageSourceParseBackingJSON(virStorageSourcePtr src,
|
|
|
fbe740 |
{
|
|
|
fbe740 |
g_autoptr(virJSONValue) root = NULL;
|
|
|
fbe740 |
g_autoptr(virJSONValue) deflattened = NULL;
|
|
|
fbe740 |
+ virJSONValuePtr file = NULL;
|
|
|
fbe740 |
|
|
|
fbe740 |
if (!(root = virJSONValueFromString(json)))
|
|
|
fbe740 |
return -1;
|
|
|
fbe740 |
@@ -3644,7 +3644,18 @@ virStorageSourceParseBackingJSON(virStorageSourcePtr src,
|
|
|
fbe740 |
if (!(deflattened = virJSONValueObjectDeflatten(root)))
|
|
|
fbe740 |
return -1;
|
|
|
fbe740 |
|
|
|
fbe740 |
- return virStorageSourceParseBackingJSONInternal(src, deflattened, json);
|
|
|
fbe740 |
+ /* There are 2 possible syntaxes:
|
|
|
fbe740 |
+ * 1) json:{"file":{"driver":...}}
|
|
|
fbe740 |
+ * 2) json:{"driver":...}
|
|
|
fbe740 |
+ * Remove the 'file' wrapper object in case 1.
|
|
|
fbe740 |
+ */
|
|
|
fbe740 |
+ if (!virJSONValueObjectHasKey(deflattened, "driver"))
|
|
|
fbe740 |
+ file = virJSONValueObjectGetObject(deflattened, "file");
|
|
|
fbe740 |
+
|
|
|
fbe740 |
+ if (!file)
|
|
|
fbe740 |
+ file = deflattened;
|
|
|
fbe740 |
+
|
|
|
fbe740 |
+ return virStorageSourceParseBackingJSONInternal(src, file, json);
|
|
|
fbe740 |
}
|
|
|
fbe740 |
|
|
|
fbe740 |
|
|
|
fbe740 |
--
|
|
|
fbe740 |
2.25.0
|
|
|
fbe740 |
|