render / rpms / libvirt

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

fbe740
 
fbe740
+              

For protocols http and https an

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

fbe740
+
fbe740
               

For "iscsi" (since 1.0.4), the

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