]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuDomainValidateStorageSource: Rework protocol validation into a switch statement
authorPeter Krempa <pkrempa@redhat.com>
Fri, 23 May 2025 13:25:31 +0000 (15:25 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 3 Jun 2025 11:11:02 +0000 (13:11 +0200)
Move the validation of TFTP and NFS into a new switch statement which
will be used for validating also other protocol config in the future.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
src/qemu/qemu_domain.c

index cc3ab0a298c985748dd17dcad3cc9864d53a166c..11f08b8ded1532046252adee4f24a742676dd90d 100644 (file)
@@ -4525,34 +4525,54 @@ qemuDomainValidateStorageSource(virStorageSource *src,
         return -1;
     }
 
-    /* TFTP protocol is not supported since QEMU 2.8.0 */
-    if (actualType == VIR_STORAGE_TYPE_NETWORK &&
-        src->protocol == VIR_STORAGE_NET_PROTOCOL_TFTP) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("'tftp' protocol is not supported with this QEMU binary"));
-        return -1;
-    }
+    if (actualType == VIR_STORAGE_TYPE_NETWORK) {
+        switch ((virStorageNetProtocol) src->protocol) {
+        case VIR_STORAGE_NET_PROTOCOL_GLUSTER:
+        case VIR_STORAGE_NET_PROTOCOL_VXHS:
+        case VIR_STORAGE_NET_PROTOCOL_HTTP:
+        case VIR_STORAGE_NET_PROTOCOL_HTTPS:
+        case VIR_STORAGE_NET_PROTOCOL_FTP:
+        case VIR_STORAGE_NET_PROTOCOL_FTPS:
+        case VIR_STORAGE_NET_PROTOCOL_ISCSI:
+        case VIR_STORAGE_NET_PROTOCOL_NBD:
+        case VIR_STORAGE_NET_PROTOCOL_RBD:
+        case VIR_STORAGE_NET_PROTOCOL_SSH:
+        case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG:
+            break;
 
-    if (actualType == VIR_STORAGE_TYPE_NETWORK &&
-        src->protocol == VIR_STORAGE_NET_PROTOCOL_NFS) {
-        /* NFS protocol must have exactly one host */
-        if (src->nhosts != 1) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("'nfs' protocol requires the usage of exactly one host"));
-            return -1;
-        }
+        case VIR_STORAGE_NET_PROTOCOL_NFS:
+            /* NFS protocol must have exactly one host */
+            if (src->nhosts != 1) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                               _("'nfs' protocol requires the usage of exactly one host"));
+                return -1;
+            }
 
-        /* NFS can only use a TCP protocol */
-        if (src->hosts[0].transport != VIR_STORAGE_NET_HOST_TRANS_TCP) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("'nfs' host must use TCP protocol"));
+            /* NFS can only use a TCP protocol */
+            if (src->hosts[0].transport != VIR_STORAGE_NET_HOST_TRANS_TCP) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                               _("'nfs' host must use TCP protocol"));
+                return -1;
+            }
+
+            /* NFS host cannot have a port */
+            if (src->hosts[0].port != 0) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                               _("port cannot be specified in 'nfs' protocol host"));
+                return -1;
+            }
+            break;
+
+        /* TFTP protocol is not supported since QEMU 2.8.0 */
+        case VIR_STORAGE_NET_PROTOCOL_TFTP:
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("storage protocol '%1$s' is not supported by this QEMU"),
+                           virStorageNetProtocolTypeToString(src->protocol));
             return -1;
-        }
 
-        /* NFS host cannot have a port */
-        if (src->hosts[0].port != 0) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("port cannot be specified in 'nfs' protocol host"));
+        case VIR_STORAGE_NET_PROTOCOL_NONE:
+        case VIR_STORAGE_NET_PROTOCOL_LAST:
+            virReportEnumRangeError(virStorageNetProtocol, src->protocol);
             return -1;
         }
     }