mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
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>
This commit is contained in:
parent
11758f9245
commit
529ad62c0d
@ -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;
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -3986,24 +3986,15 @@ 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;
|
||||
virJSONValuePtr pr = g_steal_pointer(props);
|
||||
|
||||
cmd = qemuMonitorJSONMakeCommand("netdev_add", NULL);
|
||||
if (!cmd)
|
||||
if (!(cmd = qemuMonitorJSONMakeCommandInternal("netdev_add", pr)))
|
||||
return -1;
|
||||
|
||||
args = qemuMonitorJSONKeywordStringToJSON(netdevstr, "type");
|
||||
if (!args)
|
||||
return -1;
|
||||
|
||||
if (virJSONValueObjectAppend(cmd, "arguments", args) < 0)
|
||||
return -1;
|
||||
args = NULL; /* obj owns reference to args now */
|
||||
|
||||
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
||||
return -1;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -1315,7 +1315,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=user")
|
||||
GEN_TEST_FUNC(qemuMonitorJSONRemoveNetdev, "net0")
|
||||
GEN_TEST_FUNC(qemuMonitorJSONDelDevice, "ide0")
|
||||
GEN_TEST_FUNC(qemuMonitorJSONAddDevice, "some_dummy_devicestr")
|
||||
@ -3226,7 +3225,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);
|
||||
|
Loading…
Reference in New Issue
Block a user