]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu_conf: split out virQEMUDriverConfigLoadRemoteDisplayEntry
authorJán Tomko <jtomko@redhat.com>
Mon, 14 Jan 2019 20:53:01 +0000 (21:53 +0100)
committerJán Tomko <jtomko@redhat.com>
Fri, 18 Jan 2019 11:55:07 +0000 (12:55 +0100)
Split out parts of the config parsing code to make
the parent function easier to read.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
src/qemu/qemu_conf.c

index 61d6d619dc3f2bcfa12f5557bba2f8f3634d2618..dfdaf129a34a49462d0d0ffad965fbaf1293754c 100644 (file)
@@ -423,6 +423,77 @@ virQEMUDriverConfigHugeTLBFSInit(virHugeTLBFSPtr hugetlbfs,
 }
 
 
+static int
+virQEMUDriverConfigLoadRemoteDisplayEntry(virQEMUDriverConfigPtr cfg,
+                                          virConfPtr conf,
+                                          const char *filename)
+{
+    if (virConfGetValueUInt(conf, "remote_websocket_port_min", &cfg->webSocketPortMin) < 0)
+        return -1;
+    if (cfg->webSocketPortMin < QEMU_WEBSOCKET_PORT_MIN) {
+        /* if the port is too low, we can't get the display name
+         * to tell to vnc (usually subtract 5700, e.g. localhost:1
+         * for port 5701) */
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("%s: remote_websocket_port_min: port must be greater "
+                         "than or equal to %d"),
+                        filename, QEMU_WEBSOCKET_PORT_MIN);
+        return -1;
+    }
+
+    if (virConfGetValueUInt(conf, "remote_websocket_port_max", &cfg->webSocketPortMax) < 0)
+        return -1;
+    if (cfg->webSocketPortMax > QEMU_WEBSOCKET_PORT_MAX ||
+        cfg->webSocketPortMax < cfg->webSocketPortMin) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                        _("%s: remote_websocket_port_max: port must be between "
+                          "the minimal port and %d"),
+                       filename, QEMU_WEBSOCKET_PORT_MAX);
+        return -1;
+    }
+
+    if (cfg->webSocketPortMin > cfg->webSocketPortMax) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                        _("%s: remote_websocket_port_min: min port must not be "
+                          "greater than max port"), filename);
+        return -1;
+    }
+
+    if (virConfGetValueUInt(conf, "remote_display_port_min", &cfg->remotePortMin) < 0)
+        return -1;
+    if (cfg->remotePortMin < QEMU_REMOTE_PORT_MIN) {
+        /* if the port is too low, we can't get the display name
+         * to tell to vnc (usually subtract 5900, e.g. localhost:1
+         * for port 5901) */
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("%s: remote_display_port_min: port must be greater "
+                         "than or equal to %d"),
+                        filename, QEMU_REMOTE_PORT_MIN);
+        return -1;
+    }
+
+    if (virConfGetValueUInt(conf, "remote_display_port_max", &cfg->remotePortMax) < 0)
+        return -1;
+    if (cfg->remotePortMax > QEMU_REMOTE_PORT_MAX ||
+        cfg->remotePortMax < cfg->remotePortMin) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                        _("%s: remote_display_port_max: port must be between "
+                          "the minimal port and %d"),
+                       filename, QEMU_REMOTE_PORT_MAX);
+        return -1;
+    }
+
+    if (cfg->remotePortMin > cfg->remotePortMax) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                        _("%s: remote_display_port_min: min port must not be "
+                          "greater than max port"), filename);
+        return -1;
+    }
+
+    return 0;
+}
+
+
 static int
 virQEMUDriverConfigLoadSaveEntry(virQEMUDriverConfigPtr cfg,
                                  virConfPtr conf)
@@ -928,67 +999,8 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
 
 #undef GET_CONFIG_TLS_CERTINFO
 
-    if (virConfGetValueUInt(conf, "remote_websocket_port_min", &cfg->webSocketPortMin) < 0)
-        goto cleanup;
-    if (cfg->webSocketPortMin < QEMU_WEBSOCKET_PORT_MIN) {
-        /* if the port is too low, we can't get the display name
-         * to tell to vnc (usually subtract 5700, e.g. localhost:1
-         * for port 5701) */
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("%s: remote_websocket_port_min: port must be greater "
-                         "than or equal to %d"),
-                        filename, QEMU_WEBSOCKET_PORT_MIN);
-        goto cleanup;
-    }
-
-    if (virConfGetValueUInt(conf, "remote_websocket_port_max", &cfg->webSocketPortMax) < 0)
-        goto cleanup;
-    if (cfg->webSocketPortMax > QEMU_WEBSOCKET_PORT_MAX ||
-        cfg->webSocketPortMax < cfg->webSocketPortMin) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                        _("%s: remote_websocket_port_max: port must be between "
-                          "the minimal port and %d"),
-                       filename, QEMU_WEBSOCKET_PORT_MAX);
-        goto cleanup;
-    }
-
-    if (cfg->webSocketPortMin > cfg->webSocketPortMax) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                        _("%s: remote_websocket_port_min: min port must not be "
-                          "greater than max port"), filename);
-        goto cleanup;
-    }
-
-    if (virConfGetValueUInt(conf, "remote_display_port_min", &cfg->remotePortMin) < 0)
-        goto cleanup;
-    if (cfg->remotePortMin < QEMU_REMOTE_PORT_MIN) {
-        /* if the port is too low, we can't get the display name
-         * to tell to vnc (usually subtract 5900, e.g. localhost:1
-         * for port 5901) */
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("%s: remote_display_port_min: port must be greater "
-                         "than or equal to %d"),
-                        filename, QEMU_REMOTE_PORT_MIN);
-        goto cleanup;
-    }
-
-    if (virConfGetValueUInt(conf, "remote_display_port_max", &cfg->remotePortMax) < 0)
-        goto cleanup;
-    if (cfg->remotePortMax > QEMU_REMOTE_PORT_MAX ||
-        cfg->remotePortMax < cfg->remotePortMin) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                        _("%s: remote_display_port_max: port must be between "
-                          "the minimal port and %d"),
-                       filename, QEMU_REMOTE_PORT_MAX);
+    if (virQEMUDriverConfigLoadRemoteDisplayEntry(cfg, conf, filename) < 0)
         goto cleanup;
-    }
-
-    if (cfg->remotePortMin > cfg->remotePortMax) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                        _("%s: remote_display_port_min: min port must not be "
-                          "greater than max port"), filename);
-        goto cleanup;
-    }
 
     if (virQEMUDriverConfigLoadSaveEntry(cfg, conf) < 0)
         goto cleanup;