From 2941ddd836bf42d62efd4488626673ab8ec33b03 Mon Sep 17 00:00:00 2001
Message-Id: <2941ddd836bf42d62efd4488626673ab8ec33b03@dist-git>
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= <berrange@redhat.com>
Date: Fri, 6 Jul 2018 15:47:00 +0100
Subject: [PATCH] qemu: consolidate parameters of qemuBuildChrChardevStr into
flags
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
https://bugzilla.redhat.com/show_bug.cgi?id=1597940
There are two boolean parameters passed to qemuBuildChrChardevStr,
and soon there will be a third. It will be clearer to understand
from callers' POV if we use named flags instead.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
(cherry picked from commit 0140d4c59b7fb26432b520bb7e85bd6834f560b0)
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
---
src/qemu/qemu_command.c | 94 ++++++++++++++++++++++++++---------------
1 file changed, 61 insertions(+), 33 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 41050bfea3..0c3ce98caf 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -4934,6 +4934,12 @@ qemuOpenChrChardevUNIXSocket(const virDomainChrSourceDef *dev)
return -1;
}
+
+enum {
+ QEMU_BUILD_CHARDEV_TCP_NOWAIT = (1 << 0),
+ QEMU_BUILD_CHARDEV_FILE_LOGD = (1 << 1),
+};
+
/* This function outputs a -chardev command line option which describes only the
* host side of the character device */
static char *
@@ -4945,8 +4951,7 @@ qemuBuildChrChardevStr(virLogManagerPtr logManager,
const virDomainChrSourceDef *dev,
const char *alias,
virQEMUCapsPtr qemuCaps,
- bool nowait,
- bool chardevStdioLogd)
+ unsigned int flags)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
bool telnet;
@@ -4985,7 +4990,8 @@ qemuBuildChrChardevStr(virLogManagerPtr logManager,
_("append not supported in this QEMU binary"));
goto cleanup;
}
- if (qemuBuildChrChardevFileStr(chardevStdioLogd ? logManager : NULL,
+ if (qemuBuildChrChardevFileStr(flags & QEMU_BUILD_CHARDEV_FILE_LOGD ?
+ logManager : NULL,
cmd, def, &buf,
"path", dev->data.file.path,
"append", dev->data.file.append) < 0)
@@ -5031,8 +5037,11 @@ qemuBuildChrChardevStr(virLogManagerPtr logManager,
dev->data.tcp.service,
telnet ? ",telnet" : "");
- if (dev->data.tcp.listen)
- virBufferAdd(&buf, nowait ? ",server,nowait" : ",server", -1);
+ if (dev->data.tcp.listen) {
+ virBufferAddLit(&buf, ",server");
+ if (flags & QEMU_BUILD_CHARDEV_TCP_NOWAIT)
+ virBufferAddLit(&buf, ",nowait");
+ }
qemuBuildChrChardevReconnectStr(&buf, &dev->data.tcp.reconnect);
@@ -5090,8 +5099,11 @@ qemuBuildChrChardevStr(virLogManagerPtr logManager,
virBufferAsprintf(&buf, "socket,id=%s,path=", charAlias);
virQEMUBuildBufferEscapeComma(&buf, dev->data.nix.path);
}
- if (dev->data.nix.listen)
- virBufferAdd(&buf, nowait ? ",server,nowait" : ",server", -1);
+ if (dev->data.nix.listen) {
+ virBufferAddLit(&buf, ",server");
+ if (flags & QEMU_BUILD_CHARDEV_TCP_NOWAIT)
+ virBufferAddLit(&buf, ",nowait");
+ }
qemuBuildChrChardevReconnectStr(&buf, &dev->data.nix.reconnect);
break;
@@ -5425,6 +5437,9 @@ qemuBuildMonitorCommandLine(virLogManagerPtr logManager,
qemuDomainObjPrivatePtr priv)
{
char *chrdev;
+ unsigned int cdevflags = QEMU_BUILD_CHARDEV_TCP_NOWAIT;
+ if (priv->chardevStdioLogd)
+ cdevflags |= QEMU_BUILD_CHARDEV_FILE_LOGD;
if (!priv->monConfig)
return 0;
@@ -5432,8 +5447,7 @@ qemuBuildMonitorCommandLine(virLogManagerPtr logManager,
if (!(chrdev = qemuBuildChrChardevStr(logManager, secManager,
cmd, cfg, def,
priv->monConfig, "monitor",
- priv->qemuCaps, true,
- priv->chardevStdioLogd)))
+ priv->qemuCaps, cdevflags)))
return -1;
virCommandAddArg(cmd, "-chardev");
virCommandAddArg(cmd, chrdev);
@@ -5558,6 +5572,9 @@ qemuBuildRNGBackendChrdevStr(virLogManagerPtr logManager,
char **chr,
bool chardevStdioLogd)
{
+ unsigned int cdevflags = QEMU_BUILD_CHARDEV_TCP_NOWAIT;
+ if (chardevStdioLogd)
+ cdevflags |= QEMU_BUILD_CHARDEV_FILE_LOGD;
*chr = NULL;
switch ((virDomainRNGBackend) rng->backend) {
@@ -5570,8 +5587,8 @@ qemuBuildRNGBackendChrdevStr(virLogManagerPtr logManager,
if (!(*chr = qemuBuildChrChardevStr(logManager, secManager,
cmd, cfg, def,
rng->source.chardev,
- rng->info.alias, qemuCaps, true,
- chardevStdioLogd)))
+ rng->info.alias, qemuCaps,
+ cdevflags)))
return -1;
}
@@ -8243,8 +8260,7 @@ qemuBuildVhostuserCommandLine(virQEMUDriverPtr driver,
if (!(chardev = qemuBuildChrChardevStr(logManager, secManager,
cmd, cfg, def,
net->data.vhostuser,
- net->info.alias, qemuCaps, false,
- false)))
+ net->info.alias, qemuCaps, 0)))
goto cleanup;
break;
@@ -8724,6 +8740,9 @@ qemuBuildSmartcardCommandLine(virLogManagerPtr logManager,
virBuffer opt = VIR_BUFFER_INITIALIZER;
const char *database;
const char *contAlias = NULL;
+ unsigned int cdevflags = QEMU_BUILD_CHARDEV_TCP_NOWAIT;
+ if (chardevStdioLogd)
+ cdevflags |= QEMU_BUILD_CHARDEV_FILE_LOGD;
if (!def->nsmartcards)
return 0;
@@ -8789,8 +8808,7 @@ qemuBuildSmartcardCommandLine(virLogManagerPtr logManager,
cmd, cfg, def,
smartcard->data.passthru,
smartcard->info.alias,
- qemuCaps, true,
- chardevStdioLogd))) {
+ qemuCaps, cdevflags))) {
virBufferFreeAndReset(&opt);
return -1;
}
@@ -8958,6 +8976,9 @@ qemuBuildShmemCommandLine(virLogManagerPtr logManager,
virBuffer buf = VIR_BUFFER_INITIALIZER;
char *devstr = NULL;
int rc;
+ unsigned int cdevflags = QEMU_BUILD_CHARDEV_TCP_NOWAIT;
+ if (chardevStdioLogd)
+ cdevflags |= QEMU_BUILD_CHARDEV_FILE_LOGD;
if (shmem->size) {
/*
@@ -9021,8 +9042,8 @@ qemuBuildShmemCommandLine(virLogManagerPtr logManager,
devstr = qemuBuildChrChardevStr(logManager, secManager,
cmd, cfg, def,
&shmem->server.chr,
- shmem->info.alias, qemuCaps, true,
- chardevStdioLogd);
+ shmem->info.alias, qemuCaps,
+ cdevflags);
if (!devstr)
return -1;
@@ -9115,6 +9136,9 @@ qemuBuildSerialCommandLine(virLogManagerPtr logManager,
{
size_t i;
bool havespice = false;
+ unsigned int cdevflags = QEMU_BUILD_CHARDEV_TCP_NOWAIT;
+ if (chardevStdioLogd)
+ cdevflags |= QEMU_BUILD_CHARDEV_FILE_LOGD;
if (def->nserials) {
for (i = 0; i < def->ngraphics && !havespice; i++) {
@@ -9134,8 +9158,7 @@ qemuBuildSerialCommandLine(virLogManagerPtr logManager,
cmd, cfg, def,
serial->source,
serial->info.alias,
- qemuCaps, true,
- chardevStdioLogd)))
+ qemuCaps, cdevflags)))
return -1;
virCommandAddArg(cmd, "-chardev");
virCommandAddArg(cmd, devstr);
@@ -9176,6 +9199,9 @@ qemuBuildParallelsCommandLine(virLogManagerPtr logManager,
bool chardevStdioLogd)
{
size_t i;
+ unsigned int cdevflags = QEMU_BUILD_CHARDEV_TCP_NOWAIT;
+ if (chardevStdioLogd)
+ cdevflags |= QEMU_BUILD_CHARDEV_FILE_LOGD;
for (i = 0; i < def->nparallels; i++) {
virDomainChrDefPtr parallel = def->parallels[i];
@@ -9185,8 +9211,7 @@ qemuBuildParallelsCommandLine(virLogManagerPtr logManager,
cmd, cfg, def,
parallel->source,
parallel->info.alias,
- qemuCaps, true,
- chardevStdioLogd)))
+ qemuCaps, cdevflags)))
return -1;
virCommandAddArg(cmd, "-chardev");
virCommandAddArg(cmd, devstr);
@@ -9211,6 +9236,9 @@ qemuBuildChannelsCommandLine(virLogManagerPtr logManager,
bool chardevStdioLogd)
{
size_t i;
+ unsigned int cdevflags = QEMU_BUILD_CHARDEV_TCP_NOWAIT;
+ if (chardevStdioLogd)
+ cdevflags |= QEMU_BUILD_CHARDEV_FILE_LOGD;
for (i = 0; i < def->nchannels; i++) {
virDomainChrDefPtr channel = def->channels[i];
@@ -9222,8 +9250,7 @@ qemuBuildChannelsCommandLine(virLogManagerPtr logManager,
cmd, cfg, def,
channel->source,
channel->info.alias,
- qemuCaps, true,
- chardevStdioLogd)))
+ qemuCaps, cdevflags)))
return -1;
virCommandAddArg(cmd, "-chardev");
virCommandAddArg(cmd, devstr);
@@ -9240,8 +9267,7 @@ qemuBuildChannelsCommandLine(virLogManagerPtr logManager,
cmd, cfg, def,
channel->source,
channel->info.alias,
- qemuCaps, true,
- chardevStdioLogd)))
+ qemuCaps, cdevflags)))
return -1;
virCommandAddArg(cmd, "-chardev");
virCommandAddArg(cmd, devstr);
@@ -9267,6 +9293,9 @@ qemuBuildConsoleCommandLine(virLogManagerPtr logManager,
bool chardevStdioLogd)
{
size_t i;
+ unsigned int cdevflags = QEMU_BUILD_CHARDEV_TCP_NOWAIT;
+ if (chardevStdioLogd)
+ cdevflags |= QEMU_BUILD_CHARDEV_FILE_LOGD;
/* Explicit console devices */
for (i = 0; i < def->nconsoles; i++) {
@@ -9285,8 +9314,7 @@ qemuBuildConsoleCommandLine(virLogManagerPtr logManager,
cmd, cfg, def,
console->source,
console->info.alias,
- qemuCaps, true,
- chardevStdioLogd)))
+ qemuCaps, cdevflags)))
return -1;
virCommandAddArg(cmd, "-chardev");
virCommandAddArg(cmd, devstr);
@@ -9307,8 +9335,7 @@ qemuBuildConsoleCommandLine(virLogManagerPtr logManager,
cmd, cfg, def,
console->source,
console->info.alias,
- qemuCaps, true,
- chardevStdioLogd)))
+ qemuCaps, cdevflags)))
return -1;
virCommandAddArg(cmd, "-chardev");
virCommandAddArg(cmd, devstr);
@@ -9323,8 +9350,7 @@ qemuBuildConsoleCommandLine(virLogManagerPtr logManager,
cmd, cfg, def,
console->source,
console->info.alias,
- qemuCaps, true,
- chardevStdioLogd)))
+ qemuCaps, cdevflags)))
return -1;
virCommandAddArg(cmd, "-chardev");
virCommandAddArg(cmd, devstr);
@@ -9447,6 +9473,9 @@ qemuBuildRedirdevCommandLine(virLogManagerPtr logManager,
bool chardevStdioLogd)
{
size_t i;
+ unsigned int cdevflags = QEMU_BUILD_CHARDEV_TCP_NOWAIT;
+ if (chardevStdioLogd)
+ cdevflags |= QEMU_BUILD_CHARDEV_FILE_LOGD;
for (i = 0; i < def->nredirdevs; i++) {
virDomainRedirdevDefPtr redirdev = def->redirdevs[i];
@@ -9456,8 +9485,7 @@ qemuBuildRedirdevCommandLine(virLogManagerPtr logManager,
cmd, cfg, def,
redirdev->source,
redirdev->info.alias,
- qemuCaps, true,
- chardevStdioLogd))) {
+ qemuCaps, cdevflags))) {
return -1;
}
--
2.18.0