提交 9e17d219 编写于 作者: C Christophe Fergeau

qemu: Make all SPICE command-line args optional

The end goal is to avoid adding -spice port=0,addr=127.0.0.1 to QEMU command
line when no SPICE port is specified in libvirt XML.

Currently, the code relies on port=xx to always be present, so subsequent
args can be unconditionally appended with a leading ','. Since port=0
will no longer be added in a subsequent commit, we append a ',' to every
arg instead of prepending, and remove the last one before adding it to
the arg list.
上级 0c724599
...@@ -7389,7 +7389,7 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg, ...@@ -7389,7 +7389,7 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg,
} }
if (port > 0 || tlsPort <= 0) if (port > 0 || tlsPort <= 0)
virBufferAsprintf(&opt, "port=%u", port); virBufferAsprintf(&opt, "port=%u,", port);
if (tlsPort > 0) { if (tlsPort > 0) {
if (!cfg->spiceTLS) { if (!cfg->spiceTLS) {
...@@ -7398,13 +7398,11 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg, ...@@ -7398,13 +7398,11 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg,
" but TLS is disabled in qemu.conf")); " but TLS is disabled in qemu.conf"));
goto error; goto error;
} }
if (port > 0) virBufferAsprintf(&opt, "tls-port=%u,", tlsPort);
virBufferAddChar(&opt, ',');
virBufferAsprintf(&opt, "tls-port=%u", tlsPort);
} }
if (cfg->spiceSASL) { if (cfg->spiceSASL) {
virBufferAddLit(&opt, ",sasl"); virBufferAddLit(&opt, "sasl,");
if (cfg->spiceSASLdir) if (cfg->spiceSASLdir)
virCommandAddEnvPair(cmd, "SASL_CONF_PATH", virCommandAddEnvPair(cmd, "SASL_CONF_PATH",
...@@ -7444,17 +7442,17 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg, ...@@ -7444,17 +7442,17 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg,
if (!listenAddr) if (!listenAddr)
listenAddr = cfg->spiceListen; listenAddr = cfg->spiceListen;
if (listenAddr) if (listenAddr)
virBufferAsprintf(&opt, ",addr=%s", listenAddr); virBufferAsprintf(&opt, "addr=%s,", listenAddr);
VIR_FREE(netAddr); VIR_FREE(netAddr);
if (graphics->data.spice.mousemode) { if (graphics->data.spice.mousemode) {
switch (graphics->data.spice.mousemode) { switch (graphics->data.spice.mousemode) {
case VIR_DOMAIN_GRAPHICS_SPICE_MOUSE_MODE_SERVER: case VIR_DOMAIN_GRAPHICS_SPICE_MOUSE_MODE_SERVER:
virBufferAddLit(&opt, ",agent-mouse=off"); virBufferAddLit(&opt, "agent-mouse=off,");
break; break;
case VIR_DOMAIN_GRAPHICS_SPICE_MOUSE_MODE_CLIENT: case VIR_DOMAIN_GRAPHICS_SPICE_MOUSE_MODE_CLIENT:
virBufferAddLit(&opt, ",agent-mouse=on"); virBufferAddLit(&opt, "agent-mouse=on,");
break; break;
default: default:
break; break;
...@@ -7466,17 +7464,17 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg, ...@@ -7466,17 +7464,17 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg,
* in this bit of the code */ * in this bit of the code */
if (!graphics->data.spice.auth.passwd && if (!graphics->data.spice.auth.passwd &&
!cfg->spicePassword) !cfg->spicePassword)
virBufferAddLit(&opt, ",disable-ticketing"); virBufferAddLit(&opt, "disable-ticketing,");
if (tlsPort > 0) if (tlsPort > 0)
virBufferAsprintf(&opt, ",x509-dir=%s", cfg->spiceTLSx509certdir); virBufferAsprintf(&opt, "x509-dir=%s,", cfg->spiceTLSx509certdir);
switch (defaultMode) { switch (defaultMode) {
case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_SECURE: case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_SECURE:
virBufferAddLit(&opt, ",tls-channel=default"); virBufferAddLit(&opt, "tls-channel=default,");
break; break;
case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_INSECURE: case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_INSECURE:
virBufferAddLit(&opt, ",plaintext-channel=default"); virBufferAddLit(&opt, "plaintext-channel=default,");
break; break;
case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_ANY: case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_ANY:
/* nothing */ /* nothing */
...@@ -7492,7 +7490,7 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg, ...@@ -7492,7 +7490,7 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg,
"but TLS port is not provided")); "but TLS port is not provided"));
goto error; goto error;
} }
virBufferAsprintf(&opt, ",tls-channel=%s", virBufferAsprintf(&opt, "tls-channel=%s,",
virDomainGraphicsSpiceChannelNameTypeToString(i)); virDomainGraphicsSpiceChannelNameTypeToString(i));
break; break;
...@@ -7503,7 +7501,7 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg, ...@@ -7503,7 +7501,7 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg,
"configuration, but plain port is not provided")); "configuration, but plain port is not provided"));
goto error; goto error;
} }
virBufferAsprintf(&opt, ",plaintext-channel=%s", virBufferAsprintf(&opt, "plaintext-channel=%s,",
virDomainGraphicsSpiceChannelNameTypeToString(i)); virDomainGraphicsSpiceChannelNameTypeToString(i));
break; break;
...@@ -7535,29 +7533,30 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg, ...@@ -7535,29 +7533,30 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg,
} }
if (graphics->data.spice.image) if (graphics->data.spice.image)
virBufferAsprintf(&opt, ",image-compression=%s", virBufferAsprintf(&opt, "image-compression=%s,",
virDomainGraphicsSpiceImageCompressionTypeToString(graphics->data.spice.image)); virDomainGraphicsSpiceImageCompressionTypeToString(graphics->data.spice.image));
if (graphics->data.spice.jpeg) if (graphics->data.spice.jpeg)
virBufferAsprintf(&opt, ",jpeg-wan-compression=%s", virBufferAsprintf(&opt, "jpeg-wan-compression=%s,",
virDomainGraphicsSpiceJpegCompressionTypeToString(graphics->data.spice.jpeg)); virDomainGraphicsSpiceJpegCompressionTypeToString(graphics->data.spice.jpeg));
if (graphics->data.spice.zlib) if (graphics->data.spice.zlib)
virBufferAsprintf(&opt, ",zlib-glz-wan-compression=%s", virBufferAsprintf(&opt, "zlib-glz-wan-compression=%s,",
virDomainGraphicsSpiceZlibCompressionTypeToString(graphics->data.spice.zlib)); virDomainGraphicsSpiceZlibCompressionTypeToString(graphics->data.spice.zlib));
if (graphics->data.spice.playback) if (graphics->data.spice.playback)
virBufferAsprintf(&opt, ",playback-compression=%s", virBufferAsprintf(&opt, "playback-compression=%s,",
virTristateSwitchTypeToString(graphics->data.spice.playback)); virTristateSwitchTypeToString(graphics->data.spice.playback));
if (graphics->data.spice.streaming) if (graphics->data.spice.streaming)
virBufferAsprintf(&opt, ",streaming-video=%s", virBufferAsprintf(&opt, "streaming-video=%s,",
virDomainGraphicsSpiceStreamingModeTypeToString(graphics->data.spice.streaming)); virDomainGraphicsSpiceStreamingModeTypeToString(graphics->data.spice.streaming));
if (graphics->data.spice.copypaste == VIR_TRISTATE_BOOL_NO) if (graphics->data.spice.copypaste == VIR_TRISTATE_BOOL_NO)
virBufferAddLit(&opt, ",disable-copy-paste"); virBufferAddLit(&opt, "disable-copy-paste,");
if (graphics->data.spice.filetransfer == VIR_TRISTATE_BOOL_NO) { if (graphics->data.spice.filetransfer == VIR_TRISTATE_BOOL_NO) {
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_SPICE_FILE_XFER_DISABLE)) { if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_SPICE_FILE_XFER_DISABLE)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("This QEMU can't disable file transfers through spice")); _("This QEMU can't disable file transfers through spice"));
goto error; goto error;
} else { } else {
virBufferAddLit(&opt, ",disable-agent-file-xfer"); virBufferAddLit(&opt, "disable-agent-file-xfer,");
} }
} }
...@@ -7570,7 +7569,7 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg, ...@@ -7570,7 +7569,7 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg,
/* spice.gl is a TristateBool, but qemu expects on/off: use /* spice.gl is a TristateBool, but qemu expects on/off: use
* TristateSwitch helper */ * TristateSwitch helper */
virBufferAsprintf(&opt, ",gl=%s", virBufferAsprintf(&opt, "gl=%s,",
virTristateSwitchTypeToString(graphics->data.spice.gl)); virTristateSwitchTypeToString(graphics->data.spice.gl));
} }
...@@ -7579,9 +7578,11 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg, ...@@ -7579,9 +7578,11 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg,
* unconditionally on. If migration destination * unconditionally on. If migration destination
* doesn't support it, it fallbacks to previous * doesn't support it, it fallbacks to previous
* migration algorithm silently. */ * migration algorithm silently. */
virBufferAddLit(&opt, ",seamless-migration=on"); virBufferAddLit(&opt, "seamless-migration=on,");
} }
virBufferTrim(&opt, ",", -1);
virCommandAddArg(cmd, "-spice"); virCommandAddArg(cmd, "-spice");
virCommandAddArgBuffer(cmd, &opt); virCommandAddArgBuffer(cmd, &opt);
if (graphics->data.spice.keymap) if (graphics->data.spice.keymap)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册