mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 21:55:25 +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;
|
size_t queueSize = 0;
|
||||||
g_autofree char *nicstr = NULL;
|
g_autofree char *nicstr = NULL;
|
||||||
g_autoptr(virJSONValue) netprops = NULL;
|
g_autoptr(virJSONValue) netprops = NULL;
|
||||||
g_autofree char *netstr = NULL;
|
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
bool releaseaddr = false;
|
bool releaseaddr = false;
|
||||||
bool iface_connected = false;
|
bool iface_connected = false;
|
||||||
@ -1390,9 +1389,6 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
|
|||||||
slirpfdName)))
|
slirpfdName)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(netstr = virQEMUBuildNetdevCommandlineFromJSON(netprops)))
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
qemuDomainObjEnterMonitor(driver, vm);
|
qemuDomainObjEnterMonitor(driver, vm);
|
||||||
|
|
||||||
if (actualType == VIR_DOMAIN_NET_TYPE_VHOSTUSER) {
|
if (actualType == VIR_DOMAIN_NET_TYPE_VHOSTUSER) {
|
||||||
@ -1404,7 +1400,7 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
|
|||||||
charDevPlugged = true;
|
charDevPlugged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qemuMonitorAddNetdev(priv->mon, netstr,
|
if (qemuMonitorAddNetdev(priv->mon, &netprops,
|
||||||
tapfd, tapfdName, tapfdSize,
|
tapfd, tapfdName, tapfdSize,
|
||||||
vhostfd, vhostfdName, vhostfdSize,
|
vhostfd, vhostfdName, vhostfdSize,
|
||||||
slirpfd, slirpfdName) < 0) {
|
slirpfd, slirpfdName) < 0) {
|
||||||
@ -2114,7 +2110,6 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
|
|||||||
virDomainDefPtr vmdef = vm->def;
|
virDomainDefPtr vmdef = vm->def;
|
||||||
g_autofree char *devstr = NULL;
|
g_autofree char *devstr = NULL;
|
||||||
g_autoptr(virJSONValue) netdevprops = NULL;
|
g_autoptr(virJSONValue) netdevprops = NULL;
|
||||||
g_autofree char *netdevstr = NULL;
|
|
||||||
virDomainChrSourceDefPtr dev = chr->source;
|
virDomainChrSourceDefPtr dev = chr->source;
|
||||||
g_autofree char *charAlias = NULL;
|
g_autofree char *charAlias = NULL;
|
||||||
bool chardevAttached = false;
|
bool chardevAttached = false;
|
||||||
@ -2156,9 +2151,6 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
|
|||||||
if (guestfwd) {
|
if (guestfwd) {
|
||||||
if (!(netdevprops = qemuBuildChannelGuestfwdNetdevProps(chr)))
|
if (!(netdevprops = qemuBuildChannelGuestfwdNetdevProps(chr)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(netdevstr = virQEMUBuildNetdevCommandlineFromJSON(netdevprops)))
|
|
||||||
goto cleanup;
|
|
||||||
} else {
|
} else {
|
||||||
if (qemuBuildChrDeviceStr(&devstr, vmdef, chr, priv->qemuCaps) < 0)
|
if (qemuBuildChrDeviceStr(&devstr, vmdef, chr, priv->qemuCaps) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -2181,8 +2173,8 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
|
|||||||
goto exit_monitor;
|
goto exit_monitor;
|
||||||
chardevAttached = true;
|
chardevAttached = true;
|
||||||
|
|
||||||
if (netdevstr) {
|
if (netdevprops) {
|
||||||
if (qemuMonitorAddNetdev(priv->mon, netdevstr,
|
if (qemuMonitorAddNetdev(priv->mon, &netdevprops,
|
||||||
NULL, NULL, 0, NULL, NULL, 0, -1, NULL) < 0)
|
NULL, NULL, 0, NULL, NULL, 0, -1, NULL) < 0)
|
||||||
goto exit_monitor;
|
goto exit_monitor;
|
||||||
}
|
}
|
||||||
|
@ -2667,7 +2667,7 @@ qemuMonitorCloseFileHandle(qemuMonitorPtr mon,
|
|||||||
|
|
||||||
int
|
int
|
||||||
qemuMonitorAddNetdev(qemuMonitorPtr mon,
|
qemuMonitorAddNetdev(qemuMonitorPtr mon,
|
||||||
const char *netdevstr,
|
virJSONValuePtr *props,
|
||||||
int *tapfd, char **tapfdName, int tapfdSize,
|
int *tapfd, char **tapfdName, int tapfdSize,
|
||||||
int *vhostfd, char **vhostfdName, int vhostfdSize,
|
int *vhostfd, char **vhostfdName, int vhostfdSize,
|
||||||
int slirpfd, char *slirpfdName)
|
int slirpfd, char *slirpfdName)
|
||||||
@ -2675,10 +2675,10 @@ qemuMonitorAddNetdev(qemuMonitorPtr mon,
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
size_t i = 0, j = 0;
|
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"
|
"vhostfd=%p vhostfdName=%p vhostfdSize=%d"
|
||||||
"slirpfd=%d slirpfdName=%s",
|
"slirpfd=%d slirpfdName=%s",
|
||||||
netdevstr, tapfd, tapfdName, tapfdSize,
|
props, tapfd, tapfdName, tapfdSize,
|
||||||
vhostfd, vhostfdName, vhostfdSize, slirpfd, slirpfdName);
|
vhostfd, vhostfdName, vhostfdSize, slirpfd, slirpfdName);
|
||||||
|
|
||||||
QEMU_CHECK_MONITOR(mon);
|
QEMU_CHECK_MONITOR(mon);
|
||||||
@ -2696,7 +2696,7 @@ qemuMonitorAddNetdev(qemuMonitorPtr mon,
|
|||||||
qemuMonitorSendFileHandle(mon, slirpfdName, slirpfd) < 0)
|
qemuMonitorSendFileHandle(mon, slirpfdName, slirpfd) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ret = qemuMonitorJSONAddNetdev(mon, netdevstr);
|
ret = qemuMonitorJSONAddNetdev(mon, props);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
@ -881,7 +881,7 @@ int qemuMonitorCloseFileHandle(qemuMonitorPtr mon,
|
|||||||
const char *fdname);
|
const char *fdname);
|
||||||
|
|
||||||
int qemuMonitorAddNetdev(qemuMonitorPtr mon,
|
int qemuMonitorAddNetdev(qemuMonitorPtr mon,
|
||||||
const char *netdevstr,
|
virJSONValuePtr *props,
|
||||||
int *tapfd, char **tapfdName, int tapfdSize,
|
int *tapfd, char **tapfdName, int tapfdSize,
|
||||||
int *vhostfd, char **vhostfdName, int vhostfdSize,
|
int *vhostfd, char **vhostfdName, int vhostfdSize,
|
||||||
int slirpfd, char *slirpfdName);
|
int slirpfd, char *slirpfdName);
|
||||||
|
@ -3986,24 +3986,15 @@ int qemuMonitorJSONCloseFileHandle(qemuMonitorPtr mon,
|
|||||||
|
|
||||||
int
|
int
|
||||||
qemuMonitorJSONAddNetdev(qemuMonitorPtr mon,
|
qemuMonitorJSONAddNetdev(qemuMonitorPtr mon,
|
||||||
const char *netdevstr)
|
virJSONValuePtr *props)
|
||||||
{
|
{
|
||||||
g_autoptr(virJSONValue) cmd = NULL;
|
g_autoptr(virJSONValue) cmd = NULL;
|
||||||
g_autoptr(virJSONValue) reply = NULL;
|
g_autoptr(virJSONValue) reply = NULL;
|
||||||
g_autoptr(virJSONValue) args = NULL;
|
virJSONValuePtr pr = g_steal_pointer(props);
|
||||||
|
|
||||||
cmd = qemuMonitorJSONMakeCommand("netdev_add", NULL);
|
if (!(cmd = qemuMonitorJSONMakeCommandInternal("netdev_add", pr)))
|
||||||
if (!cmd)
|
|
||||||
return -1;
|
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)
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
@ -210,7 +210,7 @@ int qemuMonitorJSONCloseFileHandle(qemuMonitorPtr mon,
|
|||||||
const char *fdname);
|
const char *fdname);
|
||||||
|
|
||||||
int qemuMonitorJSONAddNetdev(qemuMonitorPtr mon,
|
int qemuMonitorJSONAddNetdev(qemuMonitorPtr mon,
|
||||||
const char *netdevstr);
|
virJSONValuePtr *props);
|
||||||
|
|
||||||
int qemuMonitorJSONRemoveNetdev(qemuMonitorPtr mon,
|
int qemuMonitorJSONRemoveNetdev(qemuMonitorPtr mon,
|
||||||
const char *alias);
|
const char *alias);
|
||||||
|
@ -1315,7 +1315,6 @@ GEN_TEST_FUNC(qemuMonitorJSONDump, "dummy_protocol", "elf",
|
|||||||
true)
|
true)
|
||||||
GEN_TEST_FUNC(qemuMonitorJSONGraphicsRelocate, VIR_DOMAIN_GRAPHICS_TYPE_SPICE,
|
GEN_TEST_FUNC(qemuMonitorJSONGraphicsRelocate, VIR_DOMAIN_GRAPHICS_TYPE_SPICE,
|
||||||
"localhost", 12345, 12346, "certsubjectval")
|
"localhost", 12345, 12346, "certsubjectval")
|
||||||
GEN_TEST_FUNC(qemuMonitorJSONAddNetdev, "id=net0,type=user")
|
|
||||||
GEN_TEST_FUNC(qemuMonitorJSONRemoveNetdev, "net0")
|
GEN_TEST_FUNC(qemuMonitorJSONRemoveNetdev, "net0")
|
||||||
GEN_TEST_FUNC(qemuMonitorJSONDelDevice, "ide0")
|
GEN_TEST_FUNC(qemuMonitorJSONDelDevice, "ide0")
|
||||||
GEN_TEST_FUNC(qemuMonitorJSONAddDevice, "some_dummy_devicestr")
|
GEN_TEST_FUNC(qemuMonitorJSONAddDevice, "some_dummy_devicestr")
|
||||||
@ -3226,7 +3225,6 @@ mymain(void)
|
|||||||
DO_TEST_GEN(qemuMonitorJSONMigrate);
|
DO_TEST_GEN(qemuMonitorJSONMigrate);
|
||||||
DO_TEST_GEN(qemuMonitorJSONDump);
|
DO_TEST_GEN(qemuMonitorJSONDump);
|
||||||
DO_TEST_GEN(qemuMonitorJSONGraphicsRelocate);
|
DO_TEST_GEN(qemuMonitorJSONGraphicsRelocate);
|
||||||
DO_TEST_GEN(qemuMonitorJSONAddNetdev);
|
|
||||||
DO_TEST_GEN(qemuMonitorJSONRemoveNetdev);
|
DO_TEST_GEN(qemuMonitorJSONRemoveNetdev);
|
||||||
DO_TEST_GEN(qemuMonitorJSONDelDevice);
|
DO_TEST_GEN(qemuMonitorJSONDelDevice);
|
||||||
DO_TEST_GEN(qemuMonitorJSONAddDevice);
|
DO_TEST_GEN(qemuMonitorJSONAddDevice);
|
||||||
|
Loading…
Reference in New Issue
Block a user