]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: Extract helper to retrieve default port for network protocol
authorPeter Krempa <pkrempa@redhat.com>
Fri, 7 Jul 2017 13:21:04 +0000 (15:21 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 14 Jul 2017 14:05:46 +0000 (16:05 +0200)
Make the stuff hardcoded in qemu a global helper so that other parts of
the code can determine the default port too.

src/libvirt_private.syms
src/qemu/qemu_command.c
src/util/virstoragefile.c
src/util/virstoragefile.h

index 3f94521df0ca70d8a4caec75833e65cb0b9bfc71..3198aef2c03959fa90be6ec73eed62868a13400e 100644 (file)
@@ -2617,6 +2617,7 @@ virStorageSourceIsBlockLocal;
 virStorageSourceIsEmpty;
 virStorageSourceIsLocalStorage;
 virStorageSourceIsRelative;
+virStorageSourceNetworkDefaultPort;
 virStorageSourceNewFromBacking;
 virStorageSourceNewFromBackingAbsolute;
 virStorageSourceParseRBDColonString;
index 3f4108a5485863b82900e63f910e49be8d9aba8c..880b014ac6acb1da438b71ca2eee757a62b07bfe 100644 (file)
@@ -482,55 +482,18 @@ qemuNetworkDriveGetPort(int protocol,
 {
     int ret = 0;
 
-    if (port) {
-        if (virStrToLong_i(port, NULL, 10, &ret) < 0 || ret < 0) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("failed to parse port number '%s'"),
-                           port);
-            return -1;
-        }
-
-        return ret;
-    }
-
-    switch ((virStorageNetProtocol) protocol) {
-        case VIR_STORAGE_NET_PROTOCOL_HTTP:
-            return 80;
-
-        case VIR_STORAGE_NET_PROTOCOL_HTTPS:
-            return 443;
-
-        case VIR_STORAGE_NET_PROTOCOL_FTP:
-            return 21;
-
-        case VIR_STORAGE_NET_PROTOCOL_FTPS:
-            return 990;
-
-        case VIR_STORAGE_NET_PROTOCOL_TFTP:
-            return 69;
-
-        case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG:
-            return 7000;
-
-        case VIR_STORAGE_NET_PROTOCOL_NBD:
-            return 10809;
-
-        case VIR_STORAGE_NET_PROTOCOL_SSH:
-            return 22;
-
-        case VIR_STORAGE_NET_PROTOCOL_ISCSI:
-        case VIR_STORAGE_NET_PROTOCOL_GLUSTER:
-            /* no default port specified */
-            return 0;
+    if (!port &&
+        !(port = virStorageSourceNetworkDefaultPort(protocol)))
+        return -1;
 
-        case VIR_STORAGE_NET_PROTOCOL_RBD:
-        case VIR_STORAGE_NET_PROTOCOL_LAST:
-        case VIR_STORAGE_NET_PROTOCOL_NONE:
-            /* not applicable */
-            return -1;
+    if (virStrToLong_i(port, NULL, 10, &ret) < 0 || ret < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("failed to parse port number '%s'"),
+                       port);
+        return -1;
     }
 
-    return -1;
+    return ret;
 }
 
 
index 6b814a675b1436e19da899ba4731a361931b3b9a..1e94f3ab4637d60baec87198f166f20c7d6b210c 100644 (file)
@@ -3959,3 +3959,46 @@ virStorageSourceFindByNodeName(virStorageSourcePtr top,
         *idx = 0;
     return NULL;
 }
+
+
+const char *
+virStorageSourceNetworkDefaultPort(virStorageNetProtocol protocol)
+{
+    switch (protocol) {
+        case VIR_STORAGE_NET_PROTOCOL_HTTP:
+            return "80";
+
+        case VIR_STORAGE_NET_PROTOCOL_HTTPS:
+            return "443";
+
+        case VIR_STORAGE_NET_PROTOCOL_FTP:
+            return "21";
+
+        case VIR_STORAGE_NET_PROTOCOL_FTPS:
+            return "990";
+
+        case VIR_STORAGE_NET_PROTOCOL_TFTP:
+            return "69";
+
+        case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG:
+            return "7000";
+
+        case VIR_STORAGE_NET_PROTOCOL_NBD:
+            return "10809";
+
+        case VIR_STORAGE_NET_PROTOCOL_SSH:
+            return "22";
+
+        case VIR_STORAGE_NET_PROTOCOL_ISCSI:
+        case VIR_STORAGE_NET_PROTOCOL_GLUSTER:
+            /* no default port specified */
+            return "0";
+
+        case VIR_STORAGE_NET_PROTOCOL_RBD:
+        case VIR_STORAGE_NET_PROTOCOL_LAST:
+        case VIR_STORAGE_NET_PROTOCOL_NONE:
+            return NULL;
+    }
+
+    return NULL;
+}
index 0bff8671f7887c135d9953f58052bae35192f935..877c3af4dd7e45a6a909623250f057d963a01a6a 100644 (file)
@@ -406,4 +406,7 @@ virStorageSourceFindByNodeName(virStorageSourcePtr top,
                                unsigned int *index)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
 
+const char *
+virStorageSourceNetworkDefaultPort(virStorageNetProtocol protocol);
+
 #endif /* __VIR_STORAGE_FILE_H__ */