1 Star 0 Fork 71

baijing_0022/libvirt

forked from src-openEuler/libvirt 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
qemuMonitorAddNetdev-Convert-to-the-native-JSON-prop.patch 7.82 KB
一键复制 编辑 原始数据 按行查看 历史
imxcc 提交于 2022-02-22 00:16 . update patch with openeuler !54
From 2d555c8e864c8ba7dbc7a22e37712b70b59e5293 Mon Sep 17 00:00:00 2001
From: Peter Krempa <pkrempa@redhat.com>
Date: Fri, 15 May 2020 11:36:28 +0200
Subject: [PATCH 12/18] qemuMonitorAddNetdev: Convert to the native JSON props
object
Now that all code paths generate JSON props we can remove the conversion
to command line arguments and back in the monitor code.
Note that the test which is removed in this commit will be replaced by a
stronger testsuite later.
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
src/qemu/qemu_hotplug.c | 14 +++-----------
src/qemu/qemu_monitor.c | 8 ++++----
src/qemu/qemu_monitor.h | 2 +-
src/qemu/qemu_monitor_json.c | 15 +++------------
src/qemu/qemu_monitor_json.h | 2 +-
tests/qemumonitorjsontest.c | 2 --
6 files changed, 12 insertions(+), 31 deletions(-)
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 24a898166d..d7bcb6a99f 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1159,7 +1159,6 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
size_t queueSize = 0;
g_autofree char *nicstr = NULL;
g_autoptr(virJSONValue) netprops = NULL;
- g_autofree char *netstr = NULL;
int ret = -1;
bool releaseaddr = false;
bool iface_connected = false;
@@ -1390,9 +1389,6 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
slirpfdName)))
goto cleanup;
- if (!(netstr = virQEMUBuildNetdevCommandlineFromJSON(netprops)))
- goto cleanup;
-
qemuDomainObjEnterMonitor(driver, vm);
if (actualType == VIR_DOMAIN_NET_TYPE_VHOSTUSER) {
@@ -1404,7 +1400,7 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
charDevPlugged = true;
}
- if (qemuMonitorAddNetdev(priv->mon, netstr,
+ if (qemuMonitorAddNetdev(priv->mon, &netprops,
tapfd, tapfdName, tapfdSize,
vhostfd, vhostfdName, vhostfdSize,
slirpfd, slirpfdName) < 0) {
@@ -2114,7 +2110,6 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
virDomainDefPtr vmdef = vm->def;
g_autofree char *devstr = NULL;
g_autoptr(virJSONValue) netdevprops = NULL;
- g_autofree char *netdevstr = NULL;
virDomainChrSourceDefPtr dev = chr->source;
g_autofree char *charAlias = NULL;
bool chardevAttached = false;
@@ -2156,9 +2151,6 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
if (guestfwd) {
if (!(netdevprops = qemuBuildChannelGuestfwdNetdevProps(chr)))
goto cleanup;
-
- if (!(netdevstr = virQEMUBuildNetdevCommandlineFromJSON(netdevprops)))
- goto cleanup;
} else {
if (qemuBuildChrDeviceStr(&devstr, vmdef, chr, priv->qemuCaps) < 0)
goto cleanup;
@@ -2181,8 +2173,8 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
goto exit_monitor;
chardevAttached = true;
- if (netdevstr) {
- if (qemuMonitorAddNetdev(priv->mon, netdevstr,
+ if (netdevprops) {
+ if (qemuMonitorAddNetdev(priv->mon, &netdevprops,
NULL, NULL, 0, NULL, NULL, 0, -1, NULL) < 0)
goto exit_monitor;
}
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index cc62948c9c..9f4432ab3a 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -2667,7 +2667,7 @@ qemuMonitorCloseFileHandle(qemuMonitorPtr mon,
int
qemuMonitorAddNetdev(qemuMonitorPtr mon,
- const char *netdevstr,
+ virJSONValuePtr *props,
int *tapfd, char **tapfdName, int tapfdSize,
int *vhostfd, char **vhostfdName, int vhostfdSize,
int slirpfd, char *slirpfdName)
@@ -2675,10 +2675,10 @@ qemuMonitorAddNetdev(qemuMonitorPtr mon,
int ret = -1;
size_t i = 0, j = 0;
- VIR_DEBUG("netdevstr=%s tapfd=%p tapfdName=%p tapfdSize=%d"
+ VIR_DEBUG("props=%p tapfd=%p tapfdName=%p tapfdSize=%d"
"vhostfd=%p vhostfdName=%p vhostfdSize=%d"
"slirpfd=%d slirpfdName=%s",
- netdevstr, tapfd, tapfdName, tapfdSize,
+ props, tapfd, tapfdName, tapfdSize,
vhostfd, vhostfdName, vhostfdSize, slirpfd, slirpfdName);
QEMU_CHECK_MONITOR(mon);
@@ -2696,7 +2696,7 @@ qemuMonitorAddNetdev(qemuMonitorPtr mon,
qemuMonitorSendFileHandle(mon, slirpfdName, slirpfd) < 0)
goto cleanup;
- ret = qemuMonitorJSONAddNetdev(mon, netdevstr);
+ ret = qemuMonitorJSONAddNetdev(mon, props);
cleanup:
if (ret < 0) {
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 68e21dcaee..7a3240f00a 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -881,7 +881,7 @@ int qemuMonitorCloseFileHandle(qemuMonitorPtr mon,
const char *fdname);
int qemuMonitorAddNetdev(qemuMonitorPtr mon,
- const char *netdevstr,
+ virJSONValuePtr *props,
int *tapfd, char **tapfdName, int tapfdSize,
int *vhostfd, char **vhostfdName, int vhostfdSize,
int slirpfd, char *slirpfdName);
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index e6b5c7140e..c1d92b2009 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -3993,23 +3993,14 @@ int qemuMonitorJSONCloseFileHandle(qemuMonitorPtr mon,
int
qemuMonitorJSONAddNetdev(qemuMonitorPtr mon,
- const char *netdevstr)
+ virJSONValuePtr *props)
{
g_autoptr(virJSONValue) cmd = NULL;
g_autoptr(virJSONValue) reply = NULL;
- g_autoptr(virJSONValue) args = NULL;
-
- cmd = qemuMonitorJSONMakeCommand("netdev_add", NULL);
- if (!cmd)
- return -1;
-
- args = qemuMonitorJSONKeywordStringToJSON(netdevstr, "type");
- if (!args)
- return -1;
+ virJSONValuePtr pr = g_steal_pointer(props);
- if (virJSONValueObjectAppend(cmd, "arguments", args) < 0)
+ if (!(cmd = qemuMonitorJSONMakeCommandInternal("netdev_add", pr)))
return -1;
- args = NULL; /* obj owns reference to args now */
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
return -1;
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index 05a46b4fe2..dd25e5d6e6 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -210,7 +210,7 @@ int qemuMonitorJSONCloseFileHandle(qemuMonitorPtr mon,
const char *fdname);
int qemuMonitorJSONAddNetdev(qemuMonitorPtr mon,
- const char *netdevstr);
+ virJSONValuePtr *props);
int qemuMonitorJSONRemoveNetdev(qemuMonitorPtr mon,
const char *alias);
diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
index 472775a3cf..2ec143f476 100644
--- a/tests/qemumonitorjsontest.c
+++ b/tests/qemumonitorjsontest.c
@@ -1308,7 +1308,6 @@ GEN_TEST_FUNC(qemuMonitorJSONDump, "dummy_protocol", "elf",
true)
GEN_TEST_FUNC(qemuMonitorJSONGraphicsRelocate, VIR_DOMAIN_GRAPHICS_TYPE_SPICE,
"localhost", 12345, 12346, "certsubjectval")
-GEN_TEST_FUNC(qemuMonitorJSONAddNetdev, "id=net0,type=test")
GEN_TEST_FUNC(qemuMonitorJSONRemoveNetdev, "net0")
GEN_TEST_FUNC(qemuMonitorJSONDelDevice, "ide0")
GEN_TEST_FUNC(qemuMonitorJSONAddDevice, "some_dummy_devicestr")
@@ -3192,7 +3191,6 @@ mymain(void)
DO_TEST_GEN(qemuMonitorJSONMigrate);
DO_TEST_GEN(qemuMonitorJSONDump);
DO_TEST_GEN(qemuMonitorJSONGraphicsRelocate);
- DO_TEST_GEN(qemuMonitorJSONAddNetdev);
DO_TEST_GEN(qemuMonitorJSONRemoveNetdev);
DO_TEST_GEN(qemuMonitorJSONDelDevice);
DO_TEST_GEN(qemuMonitorJSONAddDevice);
--
2.23.0.windows.1
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/baijing_0022/libvirt.git
git@gitee.com:baijing_0022/libvirt.git
baijing_0022
libvirt
libvirt
master

搜索帮助