1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-25 01:34:11 +03:00

qemuBuildHostNetProps: Move all 'tap' code together

Move the block guarded by 'is_tap' boolean to the only place where
'is_tap' is set to true.

This causes few arguments to change places.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2022-05-09 16:16:35 +02:00
parent 96d6fec8dc
commit 55485c56a4
3 changed files with 27 additions and 32 deletions

View File

@ -4215,7 +4215,6 @@ qemuBuildHostNetProps(virDomainNetDef *net,
size_t vhostfdSize,
const char *slirpfd)
{
bool is_tap = false;
virDomainNetType netType = virDomainNetGetActualType(net);
size_t i;
qemuDomainNetworkPrivate *netpriv = QEMU_DOMAIN_NETWORK_PRIVATE(net);
@ -4260,7 +4259,31 @@ qemuBuildHostNetProps(virDomainNetDef *net,
return NULL;
}
is_tap = true;
if (vhostfdSize) {
if (virJSONValueObjectAppendBoolean(netprops, "vhost", true) < 0)
return NULL;
if (vhostfdSize == 1) {
if (virJSONValueObjectAdd(&netprops, "s:vhostfd", vhostfd[0], NULL) < 0)
return NULL;
} else {
g_auto(virBuffer) fdsbuf = VIR_BUFFER_INITIALIZER;
for (i = 0; i < vhostfdSize; i++)
virBufferAsprintf(&fdsbuf, "%s:", vhostfd[i]);
virBufferTrim(&fdsbuf, ":");
if (virJSONValueObjectAdd(&netprops,
"s:vhostfds", virBufferCurrentContent(&fdsbuf),
NULL) < 0)
return NULL;
}
}
if (net->tune.sndbuf_specified &&
virJSONValueObjectAppendNumberUlong(netprops, "sndbuf", net->tune.sndbuf) < 0)
return NULL;
break;
case VIR_DOMAIN_NET_TYPE_CLIENT:
@ -4373,34 +4396,6 @@ qemuBuildHostNetProps(virDomainNetDef *net,
if (virJSONValueObjectAppendStringPrintf(netprops, "id", "host%s", net->info.alias) < 0)
return NULL;
if (is_tap) {
if (vhostfdSize) {
if (virJSONValueObjectAppendBoolean(netprops, "vhost", true) < 0)
return NULL;
if (vhostfdSize == 1) {
if (virJSONValueObjectAdd(&netprops, "s:vhostfd", vhostfd[0], NULL) < 0)
return NULL;
} else {
g_auto(virBuffer) fdsbuf = VIR_BUFFER_INITIALIZER;
for (i = 0; i < vhostfdSize; i++)
virBufferAsprintf(&fdsbuf, "%s:", vhostfd[i]);
virBufferTrim(&fdsbuf, ":");
if (virJSONValueObjectAdd(&netprops,
"s:vhostfds", virBufferCurrentContent(&fdsbuf),
NULL) < 0)
return NULL;
}
}
if (net->tune.sndbuf_specified &&
virJSONValueObjectAppendNumberUlong(netprops, "sndbuf", net->tune.sndbuf) < 0)
return NULL;
}
return g_steal_pointer(&netprops);
}

View File

@ -29,6 +29,6 @@ QEMU_AUDIO_DRV=none \
-usb \
-drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \
-device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 \
-netdev tap,fd=3,id=hostnet0,vhost=on,vhostfd=44 \
-netdev tap,fd=3,vhost=on,vhostfd=44,id=hostnet0 \
-device virtio-net-pci,netdev=hostnet0,id=net0,mac=fe:11:22:33:44:55,bus=pci.0,addr=0x2 \
-msg timestamp=on

View File

@ -47,7 +47,7 @@ QEMU_AUDIO_DRV=none \
-drive file=/home/zippy/tmp/install-amd64-minimal-20140619.iso,format=raw,if=none,id=drive-ua-WhatAnAwesomeCDROM,readonly=on,cache=none \
-device ide-cd,bus=ide.1,unit=0,drive=drive-ua-WhatAnAwesomeCDROM,id=ua-WhatAnAwesomeCDROM,bootindex=2 \
-global isa-fdc.driveA=drive-ua-myDisk1 \
-netdev tap,fd=3,id=hostua-CheckoutThisNIC,vhost=on,vhostfd=44 \
-netdev tap,fd=3,vhost=on,vhostfd=44,id=hostua-CheckoutThisNIC \
-device virtio-net-pci,netdev=hostua-CheckoutThisNIC,id=ua-CheckoutThisNIC,mac=52:54:00:d6:c0:0b,bus=pci.0,addr=0x3 \
-netdev socket,listen=127.0.0.1:1234,id=hostua-WeCanAlsoDoServerMode \
-device rtl8139,netdev=hostua-WeCanAlsoDoServerMode,id=ua-WeCanAlsoDoServerMode,mac=52:54:00:22:c9:42,bus=pci.0,addr=0x9 \