]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Add support for 'tlsHostname' setting of virStorageSource
authorPeter Krempa <pkrempa@redhat.com>
Thu, 10 Mar 2022 08:57:09 +0000 (09:57 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 11 Mar 2022 14:17:06 +0000 (15:17 +0100)
Add validation and formatting of the blockdev props.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_block.c
src/qemu/qemu_domain.c

index e5ff653a6032b4fee640400e67263b55e8e182f2..4195883a1eeebbb50c7f80abf3feea3fd4b09f61 100644 (file)
@@ -843,6 +843,7 @@ qemuBlockStorageSourceGetNBDProps(virStorageSource *src,
 {
     g_autoptr(virJSONValue) serverprops = NULL;
     const char *tlsAlias = src->tlsAlias;
+    const char *tlsHostname = src->tlsHostname;
     virJSONValue *ret = NULL;
 
     if (src->nhosts != 1) {
@@ -856,13 +857,16 @@ qemuBlockStorageSourceGetNBDProps(virStorageSource *src,
     if (!serverprops)
         return NULL;
 
-    if (onlytarget)
+    if (onlytarget) {
         tlsAlias = NULL;
+        tlsHostname = NULL;
+    }
 
     if (virJSONValueObjectAdd(&ret,
                               "a:server", &serverprops,
                               "S:export", src->path,
                               "S:tls-creds", tlsAlias,
+                              "S:tls-hostname", tlsHostname,
                               NULL) < 0)
         return NULL;
 
index f61509d00b23ad0f299212560e166e778b55fe9c..b4184285bfc03b6b1f9290e66d62e19babdf71f2 100644 (file)
@@ -4862,6 +4862,21 @@ qemuDomainValidateStorageSource(virStorageSource *src,
         }
     }
 
+    if (src->tlsHostname) {
+        if (actualType != VIR_STORAGE_TYPE_NETWORK ||
+            src->protocol != VIR_STORAGE_NET_PROTOCOL_NBD) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("'tlsHostname' field is supported only with NBD disks"));
+            return -1;
+        }
+
+        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV_NBD_TLS_HOSTNAME)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("'tlsHostname' field is not supported by this QEMU"));
+            return -1;
+        }
+    }
+
     return 0;
 }