Add new function to manage adding the serial device options to the
command line removing that task from the mainline qemuBuildCommandLine.
Using const virDomainDef causes collateral damage in other called APIs
which need to make the similar adjustment
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/qemu/qemu_capabilities.c | 2 +-
src/qemu/qemu_capabilities.h | 2 +-
src/qemu/qemu_command.c | 111 ++++++++++++++++++++++++-------------------
src/qemu/qemu_command.h | 2 +-
4 files changed, 65 insertions(+), 52 deletions(-)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 3099e34..9524a21 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -3828,7 +3828,7 @@ virQEMUCapsCacheFree(virQEMUCapsCachePtr cache)
bool
-virQEMUCapsSupportsChardev(virDomainDefPtr def,
+virQEMUCapsSupportsChardev(const virDomainDef *def,
virQEMUCapsPtr qemuCaps,
virDomainChrDefPtr chr)
{
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index e5353de..7f259b7 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -442,7 +442,7 @@ int virQEMUCapsParseDeviceStr(virQEMUCapsPtr qemuCaps, const char
*str);
VIR_ENUM_DECL(virQEMUCaps);
-bool virQEMUCapsSupportsChardev(virDomainDefPtr def,
+bool virQEMUCapsSupportsChardev(const virDomainDef *def,
virQEMUCapsPtr qemuCaps,
virDomainChrDefPtr chr);
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 05b6554..44fefc3 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -4448,7 +4448,7 @@ qemuBuildMonitorCommandLine(virCommandPtr cmd,
static char *
-qemuBuildVirtioSerialPortDevStr(virDomainDefPtr def,
+qemuBuildVirtioSerialPortDevStr(const virDomainDef *def,
virDomainChrDefPtr dev,
virQEMUCapsPtr qemuCaps)
{
@@ -7553,7 +7553,7 @@ qemuBuildShmemCommandLine(virCommandPtr cmd,
static int
qemuBuildChrDeviceCommandLine(virCommandPtr cmd,
- virDomainDefPtr def,
+ const virDomainDef *def,
virDomainChrDefPtr chr,
virQEMUCapsPtr qemuCaps)
{
@@ -7567,6 +7567,60 @@ qemuBuildChrDeviceCommandLine(virCommandPtr cmd,
return 0;
}
+
+static int
+qemuBuildSerialCommandLine(virCommandPtr cmd,
+ const virDomainDef *def,
+ virQEMUCapsPtr qemuCaps)
+{
+ size_t i;
+ int actualSerials = 0;
+ bool havespice = false;
+
+ if (def->nserials) {
+ for (i = 0; i < def->ngraphics && !havespice; i++) {
+ if (def->graphics[i]->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE)
+ havespice = true;
+ }
+ }
+
+ for (i = 0; i < def->nserials; i++) {
+ virDomainChrDefPtr serial = def->serials[i];
+ char *devstr;
+
+ if (serial->source.type == VIR_DOMAIN_CHR_TYPE_SPICEPORT &&
!havespice)
+ continue;
+
+ /* Use -chardev with -device if they are available */
+ if (virQEMUCapsSupportsChardev(def, qemuCaps, serial)) {
+ virCommandAddArg(cmd, "-chardev");
+ if (!(devstr = qemuBuildChrChardevStr(&serial->source,
+ serial->info.alias,
+ qemuCaps)))
+ return -1;
+ virCommandAddArg(cmd, devstr);
+ VIR_FREE(devstr);
+
+ if (qemuBuildChrDeviceCommandLine(cmd, def, serial, qemuCaps) < 0)
+ return -1;
+ } else {
+ virCommandAddArg(cmd, "-serial");
+ if (!(devstr = qemuBuildChrArgStr(&serial->source, NULL)))
+ return -1;
+ virCommandAddArg(cmd, devstr);
+ VIR_FREE(devstr);
+ }
+ actualSerials++;
+ }
+
+ /* If we have -device, then we set -nodefault already */
+ if (!actualSerials && !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE))
+ virCommandAddArgList(cmd, "-serial", "none", NULL);
+
+ return 0;
+}
+
+
static int
qemuBuildDomainLoaderCommandLine(virCommandPtr cmd,
virDomainDefPtr def,
@@ -7981,10 +8035,8 @@ qemuBuildCommandLine(virConnectPtr conn,
virErrorPtr originalError = NULL;
size_t i, j;
char uuid[VIR_UUID_STRING_BUFLEN];
- bool havespice = false;
virCommandPtr cmd = NULL;
bool emitBootindex = false;
- int actualSerials = 0;
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
int bootHostdevNet = 0;
@@ -8119,47 +8171,8 @@ qemuBuildCommandLine(virConnectPtr conn,
if (qemuBuildSmartcardCommandLine(cmd, def, qemuCaps) < 0)
goto error;
- if (def->nserials) {
- for (i = 0; i < def->ngraphics; i++) {
- if (def->graphics[i]->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
- havespice = true;
- break;
- }
- }
- }
-
- for (i = 0; i < def->nserials; i++) {
- virDomainChrDefPtr serial = def->serials[i];
- char *devstr;
-
- if (serial->source.type == VIR_DOMAIN_CHR_TYPE_SPICEPORT &&
!havespice)
- continue;
-
- /* Use -chardev with -device if they are available */
- if (virQEMUCapsSupportsChardev(def, qemuCaps, serial)) {
- virCommandAddArg(cmd, "-chardev");
- if (!(devstr = qemuBuildChrChardevStr(&serial->source,
- serial->info.alias,
- qemuCaps)))
- goto error;
- virCommandAddArg(cmd, devstr);
- VIR_FREE(devstr);
-
- if (qemuBuildChrDeviceCommandLine(cmd, def, serial, qemuCaps) < 0)
- goto error;
- } else {
- virCommandAddArg(cmd, "-serial");
- if (!(devstr = qemuBuildChrArgStr(&serial->source, NULL)))
- goto error;
- virCommandAddArg(cmd, devstr);
- VIR_FREE(devstr);
- }
- actualSerials++;
- }
-
- /* If we have -device, then we set -nodefault already */
- if (!actualSerials && !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE))
- virCommandAddArgList(cmd, "-serial", "none", NULL);
+ if (qemuBuildSerialCommandLine(cmd, def, qemuCaps) < 0)
+ goto error;
if (!def->nparallels) {
/* If we have -device, then we set -nodefault already */
@@ -9051,7 +9064,7 @@ qemuBuildCommandLine(virConnectPtr conn,
*/
static int
qemuBuildSerialChrDeviceStr(char **deviceStr,
- virDomainDefPtr def,
+ const virDomainDef *def,
virDomainChrDefPtr serial,
virQEMUCapsPtr qemuCaps,
virArch arch,
@@ -9146,7 +9159,7 @@ qemuBuildParallelChrDeviceStr(char **deviceStr,
static int
qemuBuildChannelChrDeviceStr(char **deviceStr,
- virDomainDefPtr def,
+ const virDomainDef *def,
virDomainChrDefPtr chr,
virQEMUCapsPtr qemuCaps)
{
@@ -9186,7 +9199,7 @@ qemuBuildChannelChrDeviceStr(char **deviceStr,
static int
qemuBuildConsoleChrDeviceStr(char **deviceStr,
- virDomainDefPtr def,
+ const virDomainDef *def,
virDomainChrDefPtr chr,
virQEMUCapsPtr qemuCaps)
{
@@ -9226,7 +9239,7 @@ qemuBuildConsoleChrDeviceStr(char **deviceStr,
int
qemuBuildChrDeviceStr(char **deviceStr,
- virDomainDefPtr vmdef,
+ const virDomainDef *vmdef,
virDomainChrDefPtr chr,
virQEMUCapsPtr qemuCaps)
{
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index 2a71ac6..be5a4c4 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -77,7 +77,7 @@ virCommandPtr qemuBuildCommandLine(virConnectPtr conn,
/* Generate '-device' string for chardev device */
int
qemuBuildChrDeviceStr(char **deviceStr,
- virDomainDefPtr vmdef,
+ const virDomainDef *vmdef,
virDomainChrDefPtr chr,
virQEMUCapsPtr qemuCaps);
--
2.5.0