render / rpms / libvirt

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