render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
a41c76
From 5322d68b1c1ce4b8db415e691b666e1aae14ce8b Mon Sep 17 00:00:00 2001
a41c76
Message-Id: <5322d68b1c1ce4b8db415e691b666e1aae14ce8b@dist-git>
a41c76
From: Peter Krempa <pkrempa@redhat.com>
a41c76
Date: Wed, 19 Feb 2020 15:10:06 +0100
a41c76
Subject: [PATCH] virStorageSourceParseBackingJSON: Pass around original
a41c76
 backing file string
a41c76
MIME-Version: 1.0
a41c76
Content-Type: text/plain; charset=UTF-8
a41c76
Content-Transfer-Encoding: 8bit
a41c76
a41c76
There are a few error messages which might want to report the original
a41c76
backing store string. Pass it around rather than trying to re-generate
a41c76
it.
a41c76
a41c76
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
a41c76
Reviewed-by: Ján Tomko <jtomko@redhat.com>
a41c76
(cherry picked from commit 4a6bc568cd485f8f252a4750c5a67735f15ff82d)
a41c76
a41c76
https://bugzilla.redhat.com/show_bug.cgi?id=1791788
a41c76
Message-Id: <09648d6aeb27261a420b144c53360158b1e367d0.1582120424.git.pkrempa@redhat.com>
a41c76
Reviewed-by: Ján Tomko <jtomko@redhat.com>
a41c76
---
a41c76
 src/util/virstoragefile.c | 31 ++++++++++++++++++++-----------
a41c76
 1 file changed, 20 insertions(+), 11 deletions(-)
a41c76
a41c76
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
a41c76
index 7a2af0ad94..05f17224f4 100644
a41c76
--- a/src/util/virstoragefile.c
a41c76
+++ b/src/util/virstoragefile.c
a41c76
@@ -3051,12 +3051,14 @@ virStorageSourceParseBackingColon(virStorageSourcePtr src,
a41c76
 
a41c76
 static int
a41c76
 virStorageSourceParseBackingJSONInternal(virStorageSourcePtr src,
a41c76
-                                         virJSONValuePtr json);
a41c76
+                                         virJSONValuePtr json,
a41c76
+                                         const char *jsonstr);
a41c76
 
a41c76
 
a41c76
 static int
a41c76
 virStorageSourceParseBackingJSONPath(virStorageSourcePtr src,
a41c76
                                      virJSONValuePtr json,
a41c76
+                                     const char *jsonstr G_GNUC_UNUSED,
a41c76
                                      int type)
a41c76
 {
a41c76
     const char *path;
a41c76
@@ -3101,6 +3103,7 @@ virStorageSourceParseBackingJSONUriStr(virStorageSourcePtr src,
a41c76
 static int
a41c76
 virStorageSourceParseBackingJSONUri(virStorageSourcePtr src,
a41c76
                                     virJSONValuePtr json,
a41c76
+                                    const char *jsonstr G_GNUC_UNUSED,
a41c76
                                     int protocol)
a41c76
 {
a41c76
     const char *uri;
a41c76
@@ -3204,6 +3207,7 @@ virStorageSourceParseBackingJSONSocketAddress(virStorageNetHostDefPtr host,
a41c76
 static int
a41c76
 virStorageSourceParseBackingJSONGluster(virStorageSourcePtr src,
a41c76
                                         virJSONValuePtr json,
a41c76
+                                        const char *jsonstr G_GNUC_UNUSED,
a41c76
                                         int opaque G_GNUC_UNUSED)
a41c76
 {
a41c76
     const char *uri = virJSONValueObjectGetString(json, "filename");
a41c76
@@ -3257,6 +3261,7 @@ virStorageSourceParseBackingJSONGluster(virStorageSourcePtr src,
a41c76
 static int
a41c76
 virStorageSourceParseBackingJSONiSCSI(virStorageSourcePtr src,
a41c76
                                       virJSONValuePtr json,
a41c76
+                                      const char *jsonstr G_GNUC_UNUSED,
a41c76
                                       int opaque G_GNUC_UNUSED)
a41c76
 {
a41c76
     const char *transport = virJSONValueObjectGetString(json, "transport");
a41c76
@@ -3326,6 +3331,7 @@ virStorageSourceParseBackingJSONiSCSI(virStorageSourcePtr src,
a41c76
 static int
a41c76
 virStorageSourceParseBackingJSONNbd(virStorageSourcePtr src,
a41c76
                                     virJSONValuePtr json,
a41c76
+                                    const char *jsonstr G_GNUC_UNUSED,
a41c76
                                     int opaque G_GNUC_UNUSED)
a41c76
 {
a41c76
     const char *path = virJSONValueObjectGetString(json, "path");
a41c76
@@ -3373,6 +3379,7 @@ virStorageSourceParseBackingJSONNbd(virStorageSourcePtr src,
a41c76
 static int
a41c76
 virStorageSourceParseBackingJSONSheepdog(virStorageSourcePtr src,
a41c76
                                          virJSONValuePtr json,
a41c76
+                                         const char *jsonstr G_GNUC_UNUSED,
a41c76
                                          int opaque G_GNUC_UNUSED)
a41c76
 {
a41c76
     const char *filename;
a41c76
@@ -3416,6 +3423,7 @@ virStorageSourceParseBackingJSONSheepdog(virStorageSourcePtr src,
a41c76
 static int
a41c76
 virStorageSourceParseBackingJSONSSH(virStorageSourcePtr src,
a41c76
                                     virJSONValuePtr json,
a41c76
+                                    const char *jsonstr G_GNUC_UNUSED,
a41c76
                                     int opaque G_GNUC_UNUSED)
a41c76
 {
a41c76
     const char *path = virJSONValueObjectGetString(json, "path");
a41c76
@@ -3458,6 +3466,7 @@ virStorageSourceParseBackingJSONSSH(virStorageSourcePtr src,
a41c76
 static int
a41c76
 virStorageSourceParseBackingJSONRBD(virStorageSourcePtr src,
a41c76
                                     virJSONValuePtr json,
a41c76
+                                    const char *jsonstr G_GNUC_UNUSED,
a41c76
                                     int opaque G_GNUC_UNUSED)
a41c76
 {
a41c76
     const char *filename;
a41c76
@@ -3509,18 +3518,20 @@ virStorageSourceParseBackingJSONRBD(virStorageSourcePtr src,
a41c76
 static int
a41c76
 virStorageSourceParseBackingJSONRaw(virStorageSourcePtr src,
a41c76
                                     virJSONValuePtr json,
a41c76
+                                    const char *jsonstr,
a41c76
                                     int opaque G_GNUC_UNUSED)
a41c76
 {
a41c76
     /* There are no interesting attributes in raw driver.
a41c76
      * Treat it as pass-through.
a41c76
      */
a41c76
-    return virStorageSourceParseBackingJSONInternal(src, json);
a41c76
+    return virStorageSourceParseBackingJSONInternal(src, json, jsonstr);
a41c76
 }
a41c76
 
a41c76
 
a41c76
 static int
a41c76
 virStorageSourceParseBackingJSONVxHS(virStorageSourcePtr src,
a41c76
                                      virJSONValuePtr json,
a41c76
+                                     const char *jsonstr G_GNUC_UNUSED,
a41c76
                                      int opaque G_GNUC_UNUSED)
a41c76
 {
a41c76
     const char *vdisk_id = virJSONValueObjectGetString(json, "vdisk-id");
a41c76
@@ -3559,7 +3570,7 @@ struct virStorageSourceJSONDriverParser {
a41c76
      * can't be converted to libvirt's configuration (e.g. inline authentication
a41c76
      * credentials are present).
a41c76
      */
a41c76
-    int (*func)(virStorageSourcePtr src, virJSONValuePtr json, int opaque);
a41c76
+    int (*func)(virStorageSourcePtr src, virJSONValuePtr json, const char *jsonstr, int opaque);
a41c76
     int opaque;
a41c76
 };
a41c76
 
a41c76
@@ -3586,36 +3597,34 @@ static const struct virStorageSourceJSONDriverParser jsonParsers[] = {
a41c76
 
a41c76
 static int
a41c76
 virStorageSourceParseBackingJSONInternal(virStorageSourcePtr src,
a41c76
-                                         virJSONValuePtr json)
a41c76
+                                         virJSONValuePtr json,
a41c76
+                                         const char *jsonstr)
a41c76
 {
a41c76
     g_autoptr(virJSONValue) deflattened = NULL;
a41c76
     virJSONValuePtr file;
a41c76
     const char *drvname;
a41c76
     size_t i;
a41c76
-    g_autofree char *str = NULL;
a41c76
 
a41c76
     if (!(deflattened = virJSONValueObjectDeflatten(json)))
a41c76
         return -1;
a41c76
 
a41c76
     if (!(file = virJSONValueObjectGetObject(deflattened, "file"))) {
a41c76
-        str = virJSONValueToString(json, false);
a41c76
         virReportError(VIR_ERR_INVALID_ARG,
a41c76
                        _("JSON backing volume definition '%s' lacks 'file' object"),
a41c76
-                       NULLSTR(str));
a41c76
+                       jsonstr);
a41c76
         return -1;
a41c76
     }
a41c76
 
a41c76
     if (!(drvname = virJSONValueObjectGetString(file, "driver"))) {
a41c76
-        str = virJSONValueToString(json, false);
a41c76
         virReportError(VIR_ERR_INVALID_ARG,
a41c76
                        _("JSON backing volume definition '%s' lacks driver name"),
a41c76
-                       NULLSTR(str));
a41c76
+                       jsonstr);
a41c76
         return -1;
a41c76
     }
a41c76
 
a41c76
     for (i = 0; i < G_N_ELEMENTS(jsonParsers); i++) {
a41c76
         if (STREQ(drvname, jsonParsers[i].drvname))
a41c76
-            return jsonParsers[i].func(src, file, jsonParsers[i].opaque);
a41c76
+            return jsonParsers[i].func(src, file, jsonstr, jsonParsers[i].opaque);
a41c76
     }
a41c76
 
a41c76
     virReportError(VIR_ERR_INTERNAL_ERROR,
a41c76
@@ -3634,7 +3643,7 @@ virStorageSourceParseBackingJSON(virStorageSourcePtr src,
a41c76
     if (!(root = virJSONValueFromString(json)))
a41c76
         return -1;
a41c76
 
a41c76
-    return virStorageSourceParseBackingJSONInternal(src, root);
a41c76
+    return virStorageSourceParseBackingJSONInternal(src, root, json);
a41c76
 }
a41c76
 
a41c76
 
a41c76
-- 
a41c76
2.25.0
a41c76