提交 11758f92 编写于 作者: P Peter Krempa

qemuBuildChannelGuestfwdNetdevProps: Convert to generating JSON props

Syntax of guestfwd channel also needs to be modified to conform to the
QAPI schema.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NEric Blake <eblake@redhat.com>
上级 da820e1c
...@@ -8577,6 +8577,7 @@ qemuBuildChannelsCommandLine(virLogManagerPtr logManager, ...@@ -8577,6 +8577,7 @@ qemuBuildChannelsCommandLine(virLogManagerPtr logManager,
for (i = 0; i < def->nchannels; i++) { for (i = 0; i < def->nchannels; i++) {
virDomainChrDefPtr channel = def->channels[i]; virDomainChrDefPtr channel = def->channels[i];
g_autofree char *chardevstr = NULL; g_autofree char *chardevstr = NULL;
g_autoptr(virJSONValue) netdevprops = NULL;
g_autofree char *netdevstr = NULL; g_autofree char *netdevstr = NULL;
if (!(chardevstr = qemuBuildChrChardevStr(logManager, secManager, if (!(chardevstr = qemuBuildChrChardevStr(logManager, secManager,
...@@ -8591,8 +8592,12 @@ qemuBuildChannelsCommandLine(virLogManagerPtr logManager, ...@@ -8591,8 +8592,12 @@ qemuBuildChannelsCommandLine(virLogManagerPtr logManager,
switch ((virDomainChrChannelTargetType) channel->targetType) { switch ((virDomainChrChannelTargetType) channel->targetType) {
case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_GUESTFWD: case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_GUESTFWD:
if (!(netdevstr = qemuBuildChannelGuestfwdNetdevProps(channel))) if (!(netdevprops = qemuBuildChannelGuestfwdNetdevProps(channel)))
return -1; return -1;
if (!(netdevstr = virQEMUBuildNetdevCommandlineFromJSON(netdevprops)))
return -1;
virCommandAddArgList(cmd, "-netdev", netdevstr, NULL); virCommandAddArgList(cmd, "-netdev", netdevstr, NULL);
break; break;
...@@ -9860,19 +9865,39 @@ qemuBuildParallelChrDeviceStr(char **deviceStr, ...@@ -9860,19 +9865,39 @@ qemuBuildParallelChrDeviceStr(char **deviceStr,
} }
char * virJSONValuePtr
qemuBuildChannelGuestfwdNetdevProps(virDomainChrDefPtr chr) qemuBuildChannelGuestfwdNetdevProps(virDomainChrDefPtr chr)
{ {
g_autoptr(virJSONValue) guestfwdarr = virJSONValueNewArray();
g_autoptr(virJSONValue) guestfwdstrobj = virJSONValueNewObject();
g_autofree char *addr = NULL; g_autofree char *addr = NULL;
int port; virJSONValuePtr ret = NULL;
if (!(addr = virSocketAddrFormat(chr->target.addr))) if (!(addr = virSocketAddrFormat(chr->target.addr)))
return NULL; return NULL;
port = virSocketAddrGetPort(chr->target.addr); /* this may seem weird, but qemu indeed decided that 'guestfwd' parameter
* is an array of objects which have just one member named 'str' which
* contains the description */
if (virJSONValueObjectAppendStringPrintf(guestfwdstrobj, "str",
"tcp:%s:%i-chardev:char%s",
addr,
virSocketAddrGetPort(chr->target.addr),
chr->info.alias) < 0)
return NULL;
if (virJSONValueArrayAppend(guestfwdarr, guestfwdstrobj) < 0)
return NULL;
guestfwdstrobj = NULL;
return g_strdup_printf("user,guestfwd=tcp:%s:%i-chardev:char%s,id=%s", if (virJSONValueObjectCreate(&ret,
addr, port, chr->info.alias, chr->info.alias); "s:type", "user",
"a:guestfwd", &guestfwdarr,
"s:id", chr->info.alias,
NULL) < 0)
return NULL;
return ret;
} }
......
...@@ -86,7 +86,7 @@ qemuBuildChrDeviceStr(char **deviceStr, ...@@ -86,7 +86,7 @@ qemuBuildChrDeviceStr(char **deviceStr,
virDomainChrDefPtr chr, virDomainChrDefPtr chr,
virQEMUCapsPtr qemuCaps); virQEMUCapsPtr qemuCaps);
char * virJSONValuePtr
qemuBuildChannelGuestfwdNetdevProps(virDomainChrDefPtr chr); qemuBuildChannelGuestfwdNetdevProps(virDomainChrDefPtr chr);
virJSONValuePtr qemuBuildHostNetStr(virDomainNetDefPtr net, virJSONValuePtr qemuBuildHostNetStr(virDomainNetDefPtr net,
......
...@@ -2113,6 +2113,7 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver, ...@@ -2113,6 +2113,7 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
virErrorPtr orig_err; virErrorPtr orig_err;
virDomainDefPtr vmdef = vm->def; virDomainDefPtr vmdef = vm->def;
g_autofree char *devstr = NULL; g_autofree char *devstr = NULL;
g_autoptr(virJSONValue) netdevprops = NULL;
g_autofree char *netdevstr = NULL; g_autofree char *netdevstr = NULL;
virDomainChrSourceDefPtr dev = chr->source; virDomainChrSourceDefPtr dev = chr->source;
g_autofree char *charAlias = NULL; g_autofree char *charAlias = NULL;
...@@ -2153,7 +2154,10 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver, ...@@ -2153,7 +2154,10 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
teardowncgroup = true; teardowncgroup = true;
if (guestfwd) { if (guestfwd) {
if (!(netdevstr = qemuBuildChannelGuestfwdNetdevProps(chr))) if (!(netdevprops = qemuBuildChannelGuestfwdNetdevProps(chr)))
goto cleanup;
if (!(netdevstr = virQEMUBuildNetdevCommandlineFromJSON(netdevprops)))
goto cleanup; goto cleanup;
} else { } else {
if (qemuBuildChrDeviceStr(&devstr, vmdef, chr, priv->qemuCaps) < 0) if (qemuBuildChrDeviceStr(&devstr, vmdef, chr, priv->qemuCaps) < 0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册