All the helper functions for building command line arguments
now return a 'char *', instead of acepting a 'char **' or
virBufferPtr argument
* qemu/qemu_conf.c: Standardize syntax for building args
* qemu/qemu_conf.h: Export all functions for building args
* qemu/qemu_driver.c: Update for changed syntax for building
NIC/hostnet args
---
src/qemu/qemu_conf.c | 341 +++++++++++++++++++++++-------------------------
src/qemu/qemu_conf.h | 56 ++++++--
src/qemu/qemu_driver.c | 6 +-
3 files changed, 211 insertions(+), 192 deletions(-)
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index f4a6c08..e11ec35 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -2056,10 +2056,10 @@ error:
return NULL;
}
-static int
+
+char *
qemuBuildDriveDevStr(virConnectPtr conn,
- virDomainDiskDefPtr disk,
- char **str)
+ virDomainDiskDefPtr disk)
{
virBuffer opt = VIR_BUFFER_INITIALIZER;
const char *bus = virDomainDiskQEMUBusTypeToString(disk->bus);
@@ -2100,17 +2100,20 @@ qemuBuildDriveDevStr(virConnectPtr conn,
virBufferVSprintf(&opt, ",drive=drive-%s", disk->info.alias);
virBufferVSprintf(&opt, ",id=%s", disk->info.alias);
- *str = virBufferContentAndReset(&opt);
- return 0;
+ if (virBufferError(&opt)) {
+ virReportOOMError(NULL);
+ goto error;
+ }
+
+ return virBufferContentAndReset(&opt);
error:
virBufferFreeAndReset(&opt);
- *str = NULL;
- return -1;
+ return NULL;
}
-static char *
+char *
qemuBuildControllerDevStr(virDomainControllerDefPtr def)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
@@ -2133,8 +2136,10 @@ qemuBuildControllerDevStr(virDomainControllerDefPtr def)
if (qemuBuildDeviceAddressStr(&buf, &def->info) < 0)
goto error;
- if (virBufferError(&buf))
+ if (virBufferError(&buf)) {
+ virReportOOMError(NULL);
goto error;
+ }
return virBufferContentAndReset(&buf);
@@ -2144,14 +2149,14 @@ error:
}
-int
+char *
qemuBuildNicStr(virConnectPtr conn,
virDomainNetDefPtr net,
const char *prefix,
- int vlan,
- char **str)
+ int vlan)
{
- if (virAsprintf(str,
+ char *str;
+ if (virAsprintf(&str,
"%smacaddr=%02x:%02x:%02x:%02x:%02x:%02x,vlan=%d%s%s%s%s",
prefix ? prefix : "",
net->mac[0], net->mac[1],
@@ -2163,13 +2168,14 @@ qemuBuildNicStr(virConnectPtr conn,
(net->info.alias ? ",name=" : ""),
(net->info.alias ? net->info.alias : "")) < 0) {
virReportOOMError(conn);
- return -1;
+ return NULL;
}
- return 0;
+ return str;
}
-static char *
+
+char *
qemuBuildNicDevStr(virDomainNetDefPtr net)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
@@ -2204,23 +2210,25 @@ error:
return NULL;
}
-int
+
+char *
qemuBuildHostNetStr(virConnectPtr conn,
virDomainNetDefPtr net,
char type_sep,
int vlan,
- const char *tapfd,
- char **str)
+ const char *tapfd)
{
+ char *str = NULL;
+
switch (net->type) {
case VIR_DOMAIN_NET_TYPE_NETWORK:
case VIR_DOMAIN_NET_TYPE_BRIDGE:
- if (virAsprintf(str, "tap%cfd=%s,vlan=%d%s%s",
+ if (virAsprintf(&str, "tap%cfd=%s,vlan=%d%s%s",
type_sep, tapfd, vlan,
(net->hostnet_name ? ",name=" : ""),
(net->hostnet_name ? net->hostnet_name : ""))
< 0) {
virReportOOMError(conn);
- return -1;
+ return NULL;
}
break;
@@ -2247,10 +2255,10 @@ qemuBuildHostNetStr(virConnectPtr conn,
if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf);
virReportOOMError(conn);
- return -1;
+ return NULL;
}
- *str = virBufferContentAndReset(&buf);
+ str = virBufferContentAndReset(&buf);
}
break;
@@ -2272,7 +2280,7 @@ qemuBuildHostNetStr(virConnectPtr conn,
break;
}
- if (virAsprintf(str, "socket%c%s=%s:%d,vlan=%d%s%s",
+ if (virAsprintf(&str, "socket%c%s=%s:%d,vlan=%d%s%s",
type_sep, mode,
net->data.socket.address,
net->data.socket.port,
@@ -2280,40 +2288,41 @@ qemuBuildHostNetStr(virConnectPtr conn,
(net->hostnet_name ? ",name=" : ""),
(net->hostnet_name ? net->hostnet_name : ""))
< 0) {
virReportOOMError(conn);
- return -1;
+ return NULL;
}
}
break;
case VIR_DOMAIN_NET_TYPE_USER:
default:
- if (virAsprintf(str, "user%cvlan=%d%s%s",
+ if (virAsprintf(&str, "user%cvlan=%d%s%s",
type_sep, vlan,
(net->hostnet_name ? ",name=" : ""),
(net->hostnet_name ? net->hostnet_name : ""))
< 0) {
virReportOOMError(conn);
- return -1;
+ return NULL;
}
break;
}
- return 0;
+ return str;
}
-static int
+char *
qemuBuildNetDevStr(virConnectPtr conn,
virDomainNetDefPtr net,
- const char *tapfd,
- char **str)
+ const char *tapfd)
{
+ char *str = NULL;
+
switch (net->type) {
case VIR_DOMAIN_NET_TYPE_NETWORK:
case VIR_DOMAIN_NET_TYPE_BRIDGE:
- if (virAsprintf(str, "tap,fd=%s,id=%s",
+ if (virAsprintf(&str, "tap,fd=%s,id=%s",
tapfd, net->hostnet_name) < 0) {
virReportOOMError(conn);
- return -1;
+ return NULL;
}
break;
@@ -2333,10 +2342,10 @@ qemuBuildNetDevStr(virConnectPtr conn,
if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf);
virReportOOMError(conn);
- return -1;
+ return NULL;
}
- *str = virBufferContentAndReset(&buf);
+ str = virBufferContentAndReset(&buf);
}
break;
@@ -2358,32 +2367,33 @@ qemuBuildNetDevStr(virConnectPtr conn,
break;
}
- if (virAsprintf(str, "socket,%s=%s:%d,id=%s",
+ if (virAsprintf(&str, "socket,%s=%s:%d,id=%s",
mode,
net->data.socket.address,
net->data.socket.port,
net->hostnet_name) < 0) {
virReportOOMError(conn);
- return -1;
+ return NULL;
}
}
break;
case VIR_DOMAIN_NET_TYPE_USER:
default:
- if (virAsprintf(str, "user,id=%s",
+ if (virAsprintf(&str, "user,id=%s",
net->hostnet_name) < 0) {
virReportOOMError(conn);
- return -1;
+ return NULL;
}
break;
}
- return 0;
+ return str;
}
-static char *qemuBuildWatchdogDevStr(virDomainWatchdogDefPtr dev)
+char *
+qemuBuildWatchdogDevStr(virDomainWatchdogDefPtr dev)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
@@ -2412,7 +2422,8 @@ error:
}
-static char *qemuBuildUSBInputDevStr(virDomainInputDefPtr dev)
+char *
+qemuBuildUSBInputDevStr(virDomainInputDefPtr dev)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
@@ -2434,7 +2445,7 @@ error:
}
-static char *
+char *
qemuBuildSoundDevStr(virDomainSoundDefPtr sound)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
@@ -2470,7 +2481,7 @@ error:
}
-static char *
+char *
qemuBuildPCIHostdevDevStr(virDomainHostdevDefPtr dev)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
@@ -2496,43 +2507,46 @@ error:
return NULL;
}
+
/* This function outputs a -chardev command line option which describes only the
* host side of the character device */
-static void qemudBuildCommandLineChrDevChardevStr(virDomainChrDefPtr dev,
- virBufferPtr buf)
+char *
+qemuBuildChrChardevStr(virDomainChrDefPtr dev)
{
+ virBuffer buf = VIR_BUFFER_INITIALIZER;
bool telnet;
+
switch(dev->type) {
case VIR_DOMAIN_CHR_TYPE_NULL:
- virBufferVSprintf(buf, "null,id=%s", dev->info.alias);
+ virBufferVSprintf(&buf, "null,id=%s", dev->info.alias);
break;
case VIR_DOMAIN_CHR_TYPE_VC:
- virBufferVSprintf(buf, "vc,id=%s", dev->info.alias);
+ virBufferVSprintf(&buf, "vc,id=%s", dev->info.alias);
break;
case VIR_DOMAIN_CHR_TYPE_PTY:
- virBufferVSprintf(buf, "pty,id=%s", dev->info.alias);
+ virBufferVSprintf(&buf, "pty,id=%s", dev->info.alias);
break;
case VIR_DOMAIN_CHR_TYPE_DEV:
- virBufferVSprintf(buf, "tty,id=%s,path=%s", dev->info.alias,
dev->data.file.path);
+ virBufferVSprintf(&buf, "tty,id=%s,path=%s", dev->info.alias,
dev->data.file.path);
break;
case VIR_DOMAIN_CHR_TYPE_FILE:
- virBufferVSprintf(buf, "file,id=%s,path=%s", dev->info.alias,
dev->data.file.path);
+ virBufferVSprintf(&buf, "file,id=%s,path=%s", dev->info.alias,
dev->data.file.path);
break;
case VIR_DOMAIN_CHR_TYPE_PIPE:
- virBufferVSprintf(buf, "pipe,id=%s,path=%s", dev->info.alias,
dev->data.file.path);
+ virBufferVSprintf(&buf, "pipe,id=%s,path=%s", dev->info.alias,
dev->data.file.path);
break;
case VIR_DOMAIN_CHR_TYPE_STDIO:
- virBufferVSprintf(buf, "stdio,id=%s", dev->info.alias);
+ virBufferVSprintf(&buf, "stdio,id=%s", dev->info.alias);
break;
case VIR_DOMAIN_CHR_TYPE_UDP:
- virBufferVSprintf(buf,
+ virBufferVSprintf(&buf,
"udp,id=%s,host=%s,port=%s,localaddr=%s,localport=%s",
dev->info.alias,
dev->data.udp.connectHost,
@@ -2543,7 +2557,7 @@ static void qemudBuildCommandLineChrDevChardevStr(virDomainChrDefPtr
dev,
case VIR_DOMAIN_CHR_TYPE_TCP:
telnet = dev->data.tcp.protocol == VIR_DOMAIN_CHR_TCP_PROTOCOL_TELNET;
- virBufferVSprintf(buf,
+ virBufferVSprintf(&buf,
"socket,id=%s,host=%s,port=%s%s%s",
dev->info.alias,
dev->data.tcp.host,
@@ -2553,49 +2567,66 @@ static void
qemudBuildCommandLineChrDevChardevStr(virDomainChrDefPtr dev,
break;
case VIR_DOMAIN_CHR_TYPE_UNIX:
- virBufferVSprintf(buf,
+ virBufferVSprintf(&buf,
"socket,id=%s,path=%s%s",
dev->info.alias,
dev->data.nix.path,
dev->data.nix.listen ? ",server,nowait" :
"");
break;
}
+
+ if (virBufferError(&buf)) {
+ virReportOOMError(NULL);
+ goto error;
+ }
+
+ return virBufferContentAndReset(&buf);
+
+error:
+ virBufferFreeAndReset(&buf);
+ return NULL;
}
-static void qemudBuildCommandLineChrDevStr(virDomainChrDefPtr dev,
- virBufferPtr buf)
+
+char *
+qemuBuildChrArgStr(virDomainChrDefPtr dev, const char *prefix)
{
+ virBuffer buf = VIR_BUFFER_INITIALIZER;
+
+ if (prefix)
+ virBufferAdd(&buf, prefix, strlen(prefix));
+
switch (dev->type) {
case VIR_DOMAIN_CHR_TYPE_NULL:
- virBufferAddLit(buf, "null");
+ virBufferAddLit(&buf, "null");
break;
case VIR_DOMAIN_CHR_TYPE_VC:
- virBufferAddLit(buf, "vc");
+ virBufferAddLit(&buf, "vc");
break;
case VIR_DOMAIN_CHR_TYPE_PTY:
- virBufferAddLit(buf, "pty");
+ virBufferAddLit(&buf, "pty");
break;
case VIR_DOMAIN_CHR_TYPE_DEV:
- virBufferStrcat(buf, dev->data.file.path, NULL);
+ virBufferStrcat(&buf, dev->data.file.path, NULL);
break;
case VIR_DOMAIN_CHR_TYPE_FILE:
- virBufferVSprintf(buf, "file:%s", dev->data.file.path);
+ virBufferVSprintf(&buf, "file:%s", dev->data.file.path);
break;
case VIR_DOMAIN_CHR_TYPE_PIPE:
- virBufferVSprintf(buf, "pipe:%s", dev->data.file.path);
+ virBufferVSprintf(&buf, "pipe:%s", dev->data.file.path);
break;
case VIR_DOMAIN_CHR_TYPE_STDIO:
- virBufferAddLit(buf, "stdio");
+ virBufferAddLit(&buf, "stdio");
break;
case VIR_DOMAIN_CHR_TYPE_UDP:
- virBufferVSprintf(buf, "udp:%s:%s@%s:%s",
+ virBufferVSprintf(&buf, "udp:%s:%s@%s:%s",
dev->data.udp.connectHost,
dev->data.udp.connectService,
dev->data.udp.bindHost,
@@ -2604,12 +2635,12 @@ static void qemudBuildCommandLineChrDevStr(virDomainChrDefPtr
dev,
case VIR_DOMAIN_CHR_TYPE_TCP:
if (dev->data.tcp.protocol == VIR_DOMAIN_CHR_TCP_PROTOCOL_TELNET) {
- virBufferVSprintf(buf, "telnet:%s:%s%s",
+ virBufferVSprintf(&buf, "telnet:%s:%s%s",
dev->data.tcp.host,
dev->data.tcp.service,
dev->data.tcp.listen ? ",server,nowait" :
"");
} else {
- virBufferVSprintf(buf, "tcp:%s:%s%s",
+ virBufferVSprintf(&buf, "tcp:%s:%s%s",
dev->data.tcp.host,
dev->data.tcp.service,
dev->data.tcp.listen ? ",server,nowait" :
"");
@@ -2617,21 +2648,32 @@ static void qemudBuildCommandLineChrDevStr(virDomainChrDefPtr
dev,
break;
case VIR_DOMAIN_CHR_TYPE_UNIX:
- virBufferVSprintf(buf, "unix:%s%s",
+ virBufferVSprintf(&buf, "unix:%s%s",
dev->data.nix.path,
dev->data.nix.listen ? ",server,nowait" :
"");
break;
}
+
+ if (virBufferError(&buf)) {
+ virReportOOMError(NULL);
+ goto error;
+ }
+
+ return virBufferContentAndReset(&buf);
+
+error:
+ virBufferFreeAndReset(&buf);
+ return NULL;
}
static int
-qemudBuildCommandLineCPU(virConnectPtr conn,
- const struct qemud_driver *driver,
- const virDomainDefPtr def,
- const char *emulator,
- const struct utsname *ut,
- char **opt)
+qemuBuildCpuArgStr(virConnectPtr conn,
+ const struct qemud_driver *driver,
+ const virDomainDefPtr def,
+ const char *emulator,
+ const struct utsname *ut,
+ char **opt)
{
const virCPUDefPtr host = driver->caps->host.cpu;
virCPUDefPtr guest = NULL;
@@ -2717,9 +2759,9 @@ no_memory:
}
static char *
-qemudBuildCommandLineSmp(virConnectPtr conn,
- const virDomainDefPtr def,
- int qemuCmdFlags)
+qemuBuildSmpArgStr(virConnectPtr conn,
+ const virDomainDefPtr def,
+ int qemuCmdFlags)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
@@ -2949,7 +2991,7 @@ int qemudBuildCommandLine(virConnectPtr conn,
ADD_ARG_LIT(def->os.machine);
}
- if (qemudBuildCommandLineCPU(conn, driver, def, emulator, &ut, &cpu) < 0)
+ if (qemuBuildCpuArgStr(conn, driver, def, emulator, &ut, &cpu) < 0)
goto error;
if (cpu) {
@@ -2989,7 +3031,7 @@ int qemudBuildCommandLine(virConnectPtr conn,
}
ADD_ARG_LIT("-smp");
- if (!(smp = qemudBuildCommandLineSmp(conn, def, qemuCmdFlags)))
+ if (!(smp = qemuBuildSmpArgStr(conn, def, qemuCmdFlags)))
goto error;
ADD_ARG(smp);
@@ -3033,25 +3075,14 @@ int qemudBuildCommandLine(virConnectPtr conn,
ADD_ARG_LIT("-nodefaults");
if (monitor_chr) {
- virBuffer buf = VIR_BUFFER_INITIALIZER;
-
+ char *chrdev;
/* Use -chardev if it's available */
if (qemuCmdFlags & QEMUD_CMD_FLAG_CHARDEV) {
- qemudBuildCommandLineChrDevChardevStr(monitor_chr, &buf);
- if (virBufferError(&buf)) {
- virBufferFreeAndReset(&buf);
- goto no_memory;
- }
ADD_ARG_LIT("-chardev");
- ADD_ARG(virBufferContentAndReset(&buf));
-
- virBufferVSprintf(&buf, "chardev=%s",
monitor_chr->info.alias);
-
- if (virBufferError(&buf)) {
- virBufferFreeAndReset(&buf);
- goto no_memory;
- }
+ if (!(chrdev = qemuBuildChrChardevStr(monitor_chr)))
+ goto error;
+ ADD_ARG(chrdev);
ADD_ARG_LIT("-mon");
if (monitor_json)
@@ -3059,18 +3090,14 @@ int qemudBuildCommandLine(virConnectPtr conn,
else
ADD_ARG_LIT("chardev=monitor,mode=readline");
} else {
+ const char *prefix = NULL;
if (monitor_json)
- virBufferAddLit(&buf, "control,");
-
- qemudBuildCommandLineChrDevStr(monitor_chr, &buf);
-
- if (virBufferError(&buf)) {
- virBufferFreeAndReset(&buf);
- goto no_memory;
- }
+ prefix = "control,";
ADD_ARG_LIT("-monitor");
- ADD_ARG(virBufferContentAndReset(&buf));
+ if (!(chrdev = qemuBuildChrArgStr(monitor_chr, prefix)))
+ goto error;
+ ADD_ARG(chrdev);
}
}
@@ -3239,7 +3266,7 @@ int qemudBuildCommandLine(virConnectPtr conn,
} else {
ADD_ARG_LIT("-device");
- if (qemuBuildDriveDevStr(conn, disk, &optstr) < 0)
+ if (!(optstr = qemuBuildDriveDevStr(conn, disk)))
goto error;
ADD_ARG(optstr);
}
@@ -3346,7 +3373,7 @@ int qemudBuildCommandLine(virConnectPtr conn,
if (qemuCmdFlags & QEMUD_CMD_FLAG_DEVICE) {
ADD_ARG_LIT("-netdev");
- if (qemuBuildNetDevStr(conn, net, tapfd_name, &host) < 0)
+ if (!(host = qemuBuildNetDevStr(conn, net, tapfd_name)))
goto error;
ADD_ARG(host);
@@ -3356,13 +3383,13 @@ int qemudBuildCommandLine(virConnectPtr conn,
ADD_ARG(nic);
} else {
ADD_ARG_LIT("-net");
- if (qemuBuildNicStr(conn, net, "nic,", net->vlan, &nic)
< 0)
+ if (!(nic = qemuBuildNicStr(conn, net, "nic,", net->vlan)))
goto error;
ADD_ARG(nic);
ADD_ARG_LIT("-net");
- if (qemuBuildHostNetStr(conn, net, ',',
- net->vlan, tapfd_name, &host) < 0)
+ if (!(host = qemuBuildHostNetStr(conn, net, ',',
+ net->vlan, tapfd_name)))
goto error;
ADD_ARG(host);
}
@@ -3377,40 +3404,26 @@ int qemudBuildCommandLine(virConnectPtr conn,
}
} else {
for (i = 0 ; i < def->nserials ; i++) {
- virBuffer buf = VIR_BUFFER_INITIALIZER;
virDomainChrDefPtr serial = def->serials[i];
+ char *devstr;
/* Use -chardev with -device if they are available */
if ((qemuCmdFlags & QEMUD_CMD_FLAG_CHARDEV) &&
(qemuCmdFlags & QEMUD_CMD_FLAG_DEVICE)) {
- qemudBuildCommandLineChrDevChardevStr(serial, &buf);
- if (virBufferError(&buf)) {
- virBufferFreeAndReset(&buf);
- goto no_memory;
- }
-
ADD_ARG_LIT("-chardev");
- ADD_ARG(virBufferContentAndReset(&buf));
-
- virBufferVSprintf(&buf, "isa-serial,chardev=%s",
serial->info.alias);
- if (virBufferError(&buf)) {
- virBufferFreeAndReset(&buf);
- goto no_memory;
- }
+ if (!(devstr = qemuBuildChrChardevStr(serial)))
+ goto error;
+ ADD_ARG(devstr);
ADD_ARG_LIT("-device");
- ADD_ARG(virBufferContentAndReset(&buf));
- }
-
- else {
- qemudBuildCommandLineChrDevStr(serial, &buf);
- if (virBufferError(&buf)) {
- virBufferFreeAndReset(&buf);
+ if (virAsprintf(&devstr, "isa-serial,chardev=%s",
serial->info.alias) < 0)
goto no_memory;
- }
-
+ ADD_ARG(devstr);
+ } else {
ADD_ARG_LIT("-serial");
- ADD_ARG(virBufferContentAndReset(&buf));
+ if (!(devstr = qemuBuildChrArgStr(serial, NULL)))
+ goto error;
+ ADD_ARG(devstr);
}
}
}
@@ -3423,47 +3436,33 @@ int qemudBuildCommandLine(virConnectPtr conn,
}
} else {
for (i = 0 ; i < def->nparallels ; i++) {
- virBuffer buf = VIR_BUFFER_INITIALIZER;
virDomainChrDefPtr parallel = def->parallels[i];
+ char *devstr;
/* Use -chardev with -device if they are available */
if ((qemuCmdFlags & QEMUD_CMD_FLAG_CHARDEV) &&
(qemuCmdFlags & QEMUD_CMD_FLAG_DEVICE)) {
- qemudBuildCommandLineChrDevChardevStr(parallel, &buf);
- if (virBufferError(&buf)) {
- virBufferFreeAndReset(&buf);
- goto no_memory;
- }
-
ADD_ARG_LIT("-chardev");
- ADD_ARG(virBufferContentAndReset(&buf));
-
- virBufferVSprintf(&buf, "isa-parallel,chardev=%s",
parallel->info.alias);
- if (virBufferError(&buf)) {
- virBufferFreeAndReset(&buf);
- goto no_memory;
- }
+ if (!(devstr = qemuBuildChrChardevStr(parallel)))
+ goto error;
+ ADD_ARG(devstr);
ADD_ARG_LIT("-device");
- ADD_ARG(virBufferContentAndReset(&buf));
- }
-
- else {
- qemudBuildCommandLineChrDevStr(parallel, &buf);
- if (virBufferError(&buf)) {
- virBufferFreeAndReset(&buf);
+ if (virAsprintf(&devstr, "isa-parallel,chardev=%s",
parallel->info.alias) < 0)
goto no_memory;
- }
-
+ ADD_ARG(devstr);
+ } else {
ADD_ARG_LIT("-parallel");
- ADD_ARG(virBufferContentAndReset(&buf));
+ if (!(devstr = qemuBuildChrArgStr(parallel, NULL)))
+ goto error;
+ ADD_ARG(devstr);
}
}
}
for (i = 0 ; i < def->nchannels ; i++) {
- virBuffer buf = VIR_BUFFER_INITIALIZER;
virDomainChrDefPtr channel = def->channels[i];
+ char *devstr;
switch(channel->targetType) {
case VIR_DOMAIN_CHR_TARGET_TYPE_GUESTFWD:
@@ -3474,30 +3473,22 @@ int qemudBuildCommandLine(virConnectPtr conn,
goto error;
}
- qemudBuildCommandLineChrDevChardevStr(channel, &buf);
- if (virBufferError(&buf)) {
- virBufferFreeAndReset(&buf);
- goto no_memory;
- }
-
ADD_ARG_LIT("-chardev");
- ADD_ARG(virBufferContentAndReset(&buf));
+ if (!(devstr = qemuBuildChrChardevStr(channel)))
+ goto error;
+ ADD_ARG(devstr);
- const char *addr = virSocketFormatAddr(channel->target.addr);
+ char *addr = virSocketFormatAddr(channel->target.addr);
int port = virSocketGetPort(channel->target.addr);
ADD_ARG_LIT("-netdev");
- virBufferVSprintf(&buf,
"user,guestfwd=tcp:%s:%i,chardev=%s,id=user-%s",
- addr, port, channel->info.alias,
channel->info.alias);
-
- VIR_FREE(addr);
-
- if (virBufferError(&buf)) {
- virBufferFreeAndReset(&buf);
+ if (virAsprintf(&devstr,
"user,guestfwd=tcp:%s:%i,chardev=%s,id=user-%s",
+ addr, port, channel->info.alias, channel->info.alias)
< 0) {
+ VIR_FREE(addr);
goto no_memory;
}
-
- ADD_ARG(virBufferContentAndReset(&buf));
+ VIR_FREE(addr);
+ ADD_ARG(devstr);
}
}
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index 2530813..b6f128f 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -188,23 +188,51 @@ int qemudBuildCommandLine (virConnectPtr conn,
int *ntapfds,
const char *migrateFrom);
-int qemuBuildHostNetStr (virConnectPtr conn,
- virDomainNetDefPtr net,
- char type_sep,
- int vlan,
- const char *tapfd,
- char **str);
+/* Legacy, pre device support */
+char * qemuBuildHostNetStr(virConnectPtr conn,
+ virDomainNetDefPtr net,
+ char type_sep,
+ int vlan,
+ const char *tapfd);
-int qemuBuildNicStr (virConnectPtr conn,
- virDomainNetDefPtr net,
- const char *prefix,
- int vlan,
- char **str);
+/* Current, best practice */
+char * qemuBuildNetDevStr(virConnectPtr conn,
+ virDomainNetDefPtr net,
+ const char *tapfd);
+
+
+/* Legacy, pre device support */
+char * qemuBuildNicStr(virConnectPtr conn,
+ virDomainNetDefPtr net,
+ const char *prefix,
+ int vlan);
+
+/* Current, best practice */
+char * qemuBuildNicDevStr(virDomainNetDefPtr net);
+
+/* Both legacy & current support support */
+char *qemuBuildDriveStr(virDomainDiskDefPtr disk,
+ int bootable,
+ int qemuCmdFlags);
+
+/* Current, best practice */
+char * qemuBuildDriveDevStr(virConnectPtr conn,
+ virDomainDiskDefPtr disk);
+/* Current, best practice */
+char * qemuBuildControllerDevStr(virDomainControllerDefPtr def);
+
+char * qemuBuildWatchdogDevStr(virDomainWatchdogDefPtr dev);
+
+char * qemuBuildUSBInputDevStr(virDomainInputDefPtr dev);
+
+char * qemuBuildSoundDevStr(virDomainSoundDefPtr sound);
+
+char * qemuBuildPCIHostdevDevStr(virDomainHostdevDefPtr dev);
+
+char * qemuBuildChrChardevStr(virDomainChrDefPtr dev);
+char * qemuBuildChrArgStr(virDomainChrDefPtr dev, const char *prefix);
-char * qemuBuildDriveStr (virDomainDiskDefPtr disk,
- int bootable,
- int qemuCmdFlags);
int qemudNetworkIfaceConnect (virConnectPtr conn,
struct qemud_driver *driver,
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index adf962a..bf21923 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -5515,8 +5515,8 @@ static int qemudDomainAttachNetDevice(virConnectPtr conn,
qemuDomainObjExitMonitorWithDriver(driver, vm);
}
- if (qemuBuildHostNetStr(conn, net, ' ',
- net->vlan, tapfd_name, &netstr) < 0)
+ if (!(netstr = qemuBuildHostNetStr(conn, net, ' ',
+ net->vlan, tapfd_name)))
goto try_tapfd_close;
qemuDomainObjEnterMonitorWithDriver(driver, vm);
@@ -5530,7 +5530,7 @@ static int qemudDomainAttachNetDevice(virConnectPtr conn,
close(tapfd);
tapfd = -1;
- if (qemuBuildNicStr(conn, net, NULL, net->vlan, &nicstr) < 0)
+ if (!(nicstr = qemuBuildNicStr(conn, net, NULL, net->vlan)))
goto try_remove;
qemuDomainObjEnterMonitorWithDriver(driver, vm);
--
1.6.5.2