1 Star 0 Fork 71

lIshaohui/libvirt

forked from src-openEuler/libvirt 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
qemuBuildChannelChrDeviceStr-Remove-formatting-of-pr.patch 5.49 KB
一键复制 编辑 原始数据 按行查看 历史
imxcc 提交于 2022-02-22 00:16 . update patch with openeuler !54
From f0b20bfdd5e0967da8b98a1c66649c23a94b3d3c Mon Sep 17 00:00:00 2001
From: Peter Krempa <pkrempa@redhat.com>
Date: Thu, 14 May 2020 13:01:59 +0200
Subject: [PATCH 07/18] qemuBuildChannelChrDeviceStr: Remove formatting of
properties for -netdev
The output of the function is fed as argument to '-device' command line
argument or 'device_add' monitor command except for 'guestfwd' channels
where it needs to be fed to -netdev/netdev_add. This is confusing and
error prone. Split it up since the caller needs to know which
command/option to use anyways, so the caller can call the appropriate
function without any magic.
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
src/qemu/qemu_command.c | 36 ++++++++++++++++++++----------------
src/qemu/qemu_command.h | 3 +++
src/qemu/qemu_hotplug.c | 18 +++++++++++++-----
3 files changed, 36 insertions(+), 21 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 579e78ea75..056a74fb60 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -8872,7 +8872,7 @@ qemuBuildChannelsCommandLine(virLogManagerPtr logManager,
switch ((virDomainChrChannelTargetType) channel->targetType) {
case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_GUESTFWD:
- if (qemuBuildChrDeviceStr(&netdevstr, def, channel, qemuCaps) < 0)
+ if (!(netdevstr = qemuBuildChannelGuestfwdNetdevProps(channel)))
return -1;
virCommandAddArgList(cmd, "-netdev", netdevstr, NULL);
break;
@@ -10140,36 +10140,40 @@ qemuBuildParallelChrDeviceStr(char **deviceStr,
return 0;
}
-static int
-qemuBuildChannelChrDeviceStr(char **deviceStr,
- const virDomainDef *def,
- virDomainChrDefPtr chr)
+
+char *
+qemuBuildChannelGuestfwdNetdevProps(virDomainChrDefPtr chr)
{
- int ret = -1;
g_autofree char *addr = NULL;
int port;
- switch ((virDomainChrChannelTargetType)chr->targetType) {
- case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_GUESTFWD:
+ if (!(addr = virSocketAddrFormat(chr->target.addr)))
+ return NULL;
- addr = virSocketAddrFormat(chr->target.addr);
- if (!addr)
- return ret;
- port = virSocketAddrGetPort(chr->target.addr);
+ port = virSocketAddrGetPort(chr->target.addr);
+
+ return g_strdup_printf("user,guestfwd=tcp:%s:%i-chardev:char%s,id=%s",
+ addr, port, chr->info.alias, chr->info.alias);
+}
- *deviceStr = g_strdup_printf("user,guestfwd=tcp:%s:%i-chardev:char%s,id=%s",
- addr, port, chr->info.alias, chr->info.alias);
- break;
+static int
+qemuBuildChannelChrDeviceStr(char **deviceStr,
+ const virDomainDef *def,
+ virDomainChrDefPtr chr)
+{
+ switch ((virDomainChrChannelTargetType)chr->targetType) {
case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO:
if (!(*deviceStr = qemuBuildVirtioSerialPortDevStr(def, chr)))
return -1;
break;
+ case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_GUESTFWD:
+ /* guestfwd is as a netdev handled separately */
case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_XEN:
case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_NONE:
case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_LAST:
- return ret;
+ return -1;
}
return 0;
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index bc3ba44fb3..274084821b 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -86,6 +86,9 @@ qemuBuildChrDeviceStr(char **deviceStr,
virDomainChrDefPtr chr,
virQEMUCapsPtr qemuCaps);
+char *
+qemuBuildChannelGuestfwdNetdevProps(virDomainChrDefPtr chr);
+
char *qemuBuildHostNetStr(virDomainNetDefPtr net,
char **tapfd,
size_t tapfdSize,
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 60d0729f1e..ee97397235 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -2108,6 +2108,7 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
virErrorPtr orig_err;
virDomainDefPtr vmdef = vm->def;
g_autofree char *devstr = NULL;
+ g_autofree char *netdevstr = NULL;
virDomainChrSourceDefPtr dev = chr->source;
g_autofree char *charAlias = NULL;
bool chardevAttached = false;
@@ -2146,8 +2147,13 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
goto cleanup;
teardowncgroup = true;
- if (qemuBuildChrDeviceStr(&devstr, vmdef, chr, priv->qemuCaps) < 0)
- goto cleanup;
+ if (guestfwd) {
+ if (!(netdevstr = qemuBuildChannelGuestfwdNetdevProps(chr)))
+ goto cleanup;
+ } else {
+ if (qemuBuildChrDeviceStr(&devstr, vmdef, chr, priv->qemuCaps) < 0)
+ goto cleanup;
+ }
if (!(charAlias = qemuAliasChardevFromDevAlias(chr->info.alias)))
goto cleanup;
@@ -2166,11 +2172,13 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
goto exit_monitor;
chardevAttached = true;
- if (guestfwd) {
- if (qemuMonitorAddNetdev(priv->mon, devstr,
+ if (netdevstr) {
+ if (qemuMonitorAddNetdev(priv->mon, netdevstr,
NULL, NULL, 0, NULL, NULL, 0, -1, NULL) < 0)
goto exit_monitor;
- } else {
+ }
+
+ if (devstr) {
if (qemuMonitorAddDevice(priv->mon, devstr) < 0)
goto exit_monitor;
}
--
2.23.0.windows.1
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/li-shaohui/libvirt.git
git@gitee.com:li-shaohui/libvirt.git
li-shaohui
libvirt
libvirt
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385