render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
d76c62
From 45ecbd824c92bd05a46557bfcaff39196f701e6c Mon Sep 17 00:00:00 2001
d76c62
Message-Id: <45ecbd824c92bd05a46557bfcaff39196f701e6c@dist-git>
d76c62
From: Peter Krempa <pkrempa@redhat.com>
d76c62
Date: Mon, 30 Mar 2020 17:21:45 +0200
d76c62
Subject: [PATCH] conf: Add support for http(s) query strings
d76c62
MIME-Version: 1.0
d76c62
Content-Type: text/plain; charset=UTF-8
d76c62
Content-Transfer-Encoding: 8bit
d76c62
d76c62
Add a new attribute for holding the query part for http(s) disks.
d76c62
d76c62
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
d76c62
Reviewed-by: Ján Tomko <jtomko@redhat.com>
d76c62
(cherry picked from commit 56368124728f0d65dde07244c741b459fcd6b939)
d76c62
https://bugzilla.redhat.com/show_bug.cgi?id=1804750
d76c62
Message-Id: <b60abcf1e7711e9e29175e1fdcfe2820d5694a17.1585581552.git.pkrempa@redhat.com>
d76c62
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
d76c62
---
d76c62
 docs/formatdomain.html.in                                  | 7 ++++++-
d76c62
 docs/schemas/domaincommon.rng                              | 6 ++++++
d76c62
 src/conf/domain_conf.c                                     | 5 +++++
d76c62
 src/util/virstoragefile.c                                  | 2 ++
d76c62
 src/util/virstoragefile.h                                  | 1 +
d76c62
 tests/qemuxml2argvdata/disk-network-http.xml               | 2 +-
d76c62
 .../qemuxml2xmloutdata/disk-network-http.x86_64-latest.xml | 2 +-
d76c62
 7 files changed, 22 insertions(+), 3 deletions(-)
d76c62
d76c62
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
d76c62
index 143db21d4d..9c588185df 100644
d76c62
--- a/docs/formatdomain.html.in
d76c62
+++ b/docs/formatdomain.html.in
d76c62
@@ -2837,7 +2837,7 @@
d76c62
   </disk>
d76c62
   <disk type='network' device='cdrom'>
d76c62
     <driver name='qemu' type='raw'/>
d76c62
-    <source protocol="http" name="url_path">
d76c62
+    <source protocol="http" name="url_path" query="foo=bar&amp;baz=flurb>
d76c62
       <host name="hostname" port="80"/>
d76c62
       <cookies>
d76c62
         <cookie name="test">somevalue</cookie>
d76c62
@@ -3103,6 +3103,11 @@
d76c62
               ('tls' Since 4.5.0)
d76c62
               

d76c62
 
d76c62
+              

For protocols http and https an

d76c62
+              optional attribute query specifies the query string.
d76c62
+              (Since 6.2.0)
d76c62
+              

d76c62
+
d76c62
               

For "iscsi" (since 1.0.4), the

d76c62
               name attribute may include a logical unit number,
d76c62
               separated from the target's name by a slash (e.g.,
d76c62
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
d76c62
index e17f7ff8c0..dd8f27243a 100644
d76c62
--- a/docs/schemas/domaincommon.rng
d76c62
+++ b/docs/schemas/domaincommon.rng
d76c62
@@ -1869,6 +1869,9 @@
d76c62
           </choice>
d76c62
         </attribute>
d76c62
         <attribute name="name"/>
d76c62
+        <optional>
d76c62
+          <attribute name="query"/>
d76c62
+        </optional>
d76c62
         <ref name="diskSourceCommon"/>
d76c62
         <ref name="diskSourceNetworkHost"/>
d76c62
         <optional>
d76c62
@@ -1894,6 +1897,9 @@
d76c62
           </choice>
d76c62
         </attribute>
d76c62
         <attribute name="name"/>
d76c62
+        <optional>
d76c62
+          <attribute name="query"/>
d76c62
+        </optional>
d76c62
         <ref name="diskSourceCommon"/>
d76c62
         <ref name="diskSourceNetworkHost"/>
d76c62
         <optional>
d76c62
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
d76c62
index e3755fa285..28160a2967 100644
d76c62
--- a/src/conf/domain_conf.c
d76c62
+++ b/src/conf/domain_conf.c
d76c62
@@ -9382,6 +9382,10 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node,
d76c62
     /* config file currently only works with remote disks */
d76c62
     src->configFile = virXPathString("string(./config/@file)", ctxt);
d76c62
 
d76c62
+    if (src->protocol == VIR_STORAGE_NET_PROTOCOL_HTTP ||
d76c62
+        src->protocol == VIR_STORAGE_NET_PROTOCOL_HTTPS)
d76c62
+        src->query = virXMLPropString(node, "query");
d76c62
+
d76c62
     if (virDomainStorageNetworkParseHosts(node, &src->hosts, &src->nhosts) < 0)
d76c62
         return -1;
d76c62
 
d76c62
@@ -24390,6 +24394,7 @@ virDomainDiskSourceFormatNetwork(virBufferPtr attrBuf,
d76c62
         path = g_strdup_printf("%s/%s", src->volume, src->path);
d76c62
 
d76c62
     virBufferEscapeString(attrBuf, " name='%s'", path ? path : src->path);
d76c62
+    virBufferEscapeString(attrBuf, " query='%s'", src->query);
d76c62
 
d76c62
     if (src->haveTLS != VIR_TRISTATE_BOOL_ABSENT &&
d76c62
         !(flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE &&
d76c62
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
d76c62
index f8d741f040..4082e3f5f7 100644
d76c62
--- a/src/util/virstoragefile.c
d76c62
+++ b/src/util/virstoragefile.c
d76c62
@@ -2418,6 +2418,7 @@ virStorageSourceCopy(const virStorageSource *src,
d76c62
     def->compat = g_strdup(src->compat);
d76c62
     def->tlsAlias = g_strdup(src->tlsAlias);
d76c62
     def->tlsCertdir = g_strdup(src->tlsCertdir);
d76c62
+    def->query = g_strdup(src->query);
d76c62
 
d76c62
     if (src->sliceStorage)
d76c62
         def->sliceStorage = virStorageSourceSliceCopy(src->sliceStorage);
d76c62
@@ -2696,6 +2697,7 @@ virStorageSourceClear(virStorageSourcePtr def)
d76c62
     VIR_FREE(def->volume);
d76c62
     VIR_FREE(def->snapshot);
d76c62
     VIR_FREE(def->configFile);
d76c62
+    VIR_FREE(def->query);
d76c62
     virStorageSourceNetCookiesClear(def);
d76c62
     virStorageSourcePoolDefFree(def->srcpool);
d76c62
     virBitmapFree(def->features);
d76c62
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
d76c62
index 0230f44652..8089d1e07f 100644
d76c62
--- a/src/util/virstoragefile.h
d76c62
+++ b/src/util/virstoragefile.h
d76c62
@@ -285,6 +285,7 @@ struct _virStorageSource {
d76c62
     char *snapshot; /* for storage systems supporting internal snapshots */
d76c62
     char *configFile; /* some storage systems use config file as part of
d76c62
                          the source definition */
d76c62
+    char *query; /* query string for HTTP based protocols */
d76c62
     size_t nhosts;
d76c62
     virStorageNetHostDefPtr hosts;
d76c62
     size_t ncookies;
d76c62
diff --git a/tests/qemuxml2argvdata/disk-network-http.xml b/tests/qemuxml2argvdata/disk-network-http.xml
d76c62
index 93e6617433..3abf499019 100644
d76c62
--- a/tests/qemuxml2argvdata/disk-network-http.xml
d76c62
+++ b/tests/qemuxml2argvdata/disk-network-http.xml
d76c62
@@ -42,7 +42,7 @@
d76c62
     </disk>
d76c62
     <disk type='network' device='disk'>
d76c62
       <driver name='qemu' type='raw'/>
d76c62
-      <source protocol='https' name='test4.img'>
d76c62
+      <source protocol='https' name='test4.img' query='par=val&other=ble'>
d76c62
         <host name='example.org' port='1234'/>
d76c62
         <ssl verify='no'/>
d76c62
         <cookies>
d76c62
diff --git a/tests/qemuxml2xmloutdata/disk-network-http.x86_64-latest.xml b/tests/qemuxml2xmloutdata/disk-network-http.x86_64-latest.xml
d76c62
index 60073c227c..45b01841ec 100644
d76c62
--- a/tests/qemuxml2xmloutdata/disk-network-http.x86_64-latest.xml
d76c62
+++ b/tests/qemuxml2xmloutdata/disk-network-http.x86_64-latest.xml
d76c62
@@ -46,7 +46,7 @@
d76c62
     </disk>
d76c62
     <disk type='network' device='disk'>
d76c62
       <driver name='qemu' type='raw'/>
d76c62
-      <source protocol='https' name='test4.img'>
d76c62
+      <source protocol='https' name='test4.img' query='par=val&other=ble'>
d76c62
         <host name='example.org' port='1234'/>
d76c62
         <ssl verify='no'/>
d76c62
         <cookies>
d76c62
-- 
d76c62
2.26.0
d76c62