[PATCH 1/3] virStorageSourceParseBackingURI: Preserve query parts of URI

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



For non-NBD URIs we need to preserve the query part as it may be
important to refer to the image. If the query doesn't start with
'socket=' concatenate it to the name of the image.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/util/virstoragefile.c | 15 +++++++++++----
 tests/virstoragetest.c    |  4 ++--
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index c43e52d1f6..caf5de2d2c 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -2818,6 +2818,7 @@ virStorageSourceParseBackingURI(virStorageSourcePtr src,
 {
     g_autoptr(virURI) uri = NULL;
     const char *path = NULL;
+    g_autofree char *pathquery = NULL;
     VIR_AUTOSTRINGLIST scheme = NULL;

     if (!(uri = virURIParse(uristr))) {
@@ -2851,10 +2852,6 @@ virStorageSourceParseBackingURI(virStorageSourcePtr src,
         return -1;
     }

-    /* handle socket stored as a query */
-    if (uri->query)
-        src->hosts->socket = g_strdup(STRSKIP(uri->query, "socket="));
-
     /* uri->path is NULL if the URI does not contain slash after host:
      * transport://host:port */
     if (uri->path)
@@ -2862,6 +2859,16 @@ virStorageSourceParseBackingURI(virStorageSourcePtr src,
     else
         path = "";

+    /* handle socket stored as a query */
+    if (uri->query) {
+        if (STRPREFIX(uri->query, "socket=")) {
+            src->hosts->socket = g_strdup(STRSKIP(uri->query, "socket="));
+        } else {
+            pathquery = g_strdup_printf("%s?%s", path, uri->query);
+            path = pathquery;
+        }
+    }
+
     /* possibly skip the leading slash  */
     if (path[0] == '/')
         path++;
diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
index 10d5421150..f0bb46a04c 100644
--- a/tests/virstoragetest.c
+++ b/tests/virstoragetest.c
@@ -1632,7 +1632,7 @@ mymain(void)
                                    "\"file.url\": \"https://host/folder/esx6.5-rhel7.7-x86%5f64/esx6.5-rhel7.7-x86%5f64-flat.vmdk?dcPath=data&dsName=esx6.5-matrix\",";
                                    "\"file.timeout\": 2000"
                                  "}",
-                           "<source protocol='https' name='folder/esx6.5-rhel7.7-x86_64/esx6.5-rhel7.7-x86_64-flat.vmdk'>\n"
+                           "<source protocol='https' name='folder/esx6.5-rhel7.7-x86_64/esx6.5-rhel7.7-x86_64-flat.vmdk?dcPath=data&amp;dsName=esx6.5-matrix'>\n"
                            "  <host name='host' port='443'/>\n"
                            "  <ssl verify='no'/>\n"
                            "  <cookies>\n"
@@ -1647,7 +1647,7 @@ mymain(void)
                                    "\"file.url\": \"https://host/folder/esx6.5-rhel7.7-x86%5f64/esx6.5-rhel7.7-x86%5f64-flat.vmdk?dcPath=data&dsName=esx6.5-matrix\",";
                                    "\"file.timeout\": 2000"
                                  "}",
-                           "<source protocol='https' name='folder/esx6.5-rhel7.7-x86_64/esx6.5-rhel7.7-x86_64-flat.vmdk'>\n"
+                           "<source protocol='https' name='folder/esx6.5-rhel7.7-x86_64/esx6.5-rhel7.7-x86_64-flat.vmdk?dcPath=data&amp;dsName=esx6.5-matrix'>\n"
                            "  <host name='host' port='443'/>\n"
                            "  <ssl verify='no'/>\n"
                            "  <cookies>\n"
-- 
2.24.1





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux