qemu_command.c: reduce qemuBuildNicDevStr() if clauses

We have a lot of "if (usingVirtio)" checks being done while
constructing the NIC command line. Let's put all of them in
a single "if".

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
Daniel Henrique Barboza 2020-10-09 11:48:24 -03:00
parent edee4290c9
commit 31ac666454

View File

@ -3306,8 +3306,9 @@ qemuBuildNicDevStr(virDomainDefPtr def,
virBufferAddStr(&buf, virDomainNetGetModelString(net));
}
if (usingVirtio && net->driver.virtio.txmode) {
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_TX_ALG)) {
if (usingVirtio) {
if (net->driver.virtio.txmode &&
virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_TX_ALG)) {
virBufferAddLit(&buf, ",tx=");
switch (net->driver.virtio.txmode) {
case VIR_DOMAIN_NET_VIRTIO_TX_MODE_IOTHREAD:
@ -3331,8 +3332,6 @@ qemuBuildNicDevStr(virDomainDefPtr def,
return NULL;
}
}
}
if (usingVirtio) {
qemuBuildIoEventFdStr(&buf, net->driver.virtio.ioeventfd, qemuCaps);
if (net->driver.virtio.event_idx &&
virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_NET_EVENT_IDX)) {
@ -3387,8 +3386,8 @@ qemuBuildNicDevStr(virDomainDefPtr def,
virBufferAsprintf(&buf, ",guest_ufo=%s",
virTristateSwitchTypeToString(net->driver.virtio.guest.ufo));
}
}
if (usingVirtio && vhostfdSize > 1) {
if (vhostfdSize > 1) {
if (net->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW) {
/* ccw provides a one to one relation of fds to queues and
* does not support the vectors option
@ -3402,17 +3401,18 @@ qemuBuildNicDevStr(virDomainDefPtr def,
}
}
if (usingVirtio && net->driver.virtio.rx_queue_size)
if (net->driver.virtio.rx_queue_size)
virBufferAsprintf(&buf, ",rx_queue_size=%u", net->driver.virtio.rx_queue_size);
if (usingVirtio && net->driver.virtio.tx_queue_size)
if (net->driver.virtio.tx_queue_size)
virBufferAsprintf(&buf, ",tx_queue_size=%u", net->driver.virtio.tx_queue_size);
if (usingVirtio && net->mtu)
if (net->mtu)
virBufferAsprintf(&buf, ",host_mtu=%u", net->mtu);
if (usingVirtio && net->teaming.type == VIR_DOMAIN_NET_TEAMING_TYPE_PERSISTENT)
if (net->teaming.type == VIR_DOMAIN_NET_TEAMING_TYPE_PERSISTENT)
virBufferAddLit(&buf, ",failover=on");
}
virBufferAsprintf(&buf, ",netdev=host%s", net->info.alias);
virBufferAsprintf(&buf, ",id=%s", net->info.alias);