Split out parts of the config parsing code to make
the parent function easier to read.
Signed-off-by: Ján Tomko <jtomko(a)redhat.com>
---
src/qemu/qemu_conf.c | 131 +++++++++++++++++++++++--------------------
1 file changed, 71 insertions(+), 60 deletions(-)
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index e03c0b29e3..317756d2a0 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -423,6 +423,76 @@ 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)
@@ -925,67 +995,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);
+ if (virQEMUDriverConfigLoadRemoteDisplayEntry(cfg, conf, filename) < 0)
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);
- 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;
--
2.20.1