1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-22 17:34:18 +03:00

qemu_command: replace vlan= with netdev= for legacy nic

VMs with hardcoded platform network devices are forced to use old
style '-net nic' command line config. Current we use qemu's vlan
option to hook this with the '-netdev' host side of things.

However since qemu 1.2 there is '-net nic,netdev=X' option for
explicitly referencing a netdev ID, which is more inline with
typical VM commandlines, so let's switch to that

Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
Cole Robinson 2018-06-19 11:42:37 -04:00
parent 131ca8f4ff
commit 14781dcde6
4 changed files with 21 additions and 56 deletions

View File

@ -3353,16 +3353,15 @@ qemuBuildMemoryDeviceStr(virDomainMemoryDefPtr mem)
static char *
qemuBuildLegacyNicStr(virDomainNetDefPtr net,
int vlan)
qemuBuildLegacyNicStr(virDomainNetDefPtr net)
{
char *str;
char macaddr[VIR_MAC_STRING_BUFLEN];
ignore_value(virAsprintf(&str,
"nic,macaddr=%s,vlan=%d%s%s%s%s",
"nic,macaddr=%s,netdev=host%s%s%s%s%s",
virMacAddrFormat(&net->mac, macaddr),
vlan,
net->info.alias,
(net->model ? ",model=" : ""),
(net->model ? net->model : ""),
(net->info.alias ? ",name=" : ""),
@ -3374,7 +3373,6 @@ qemuBuildLegacyNicStr(virDomainNetDefPtr net,
char *
qemuBuildNicDevStr(virDomainDefPtr def,
virDomainNetDefPtr net,
int vlan,
unsigned int bootindex,
size_t vhostfdSize,
virQEMUCapsPtr qemuCaps)
@ -3523,10 +3521,7 @@ qemuBuildNicDevStr(virDomainDefPtr def,
virBufferAsprintf(&buf, ",host_mtu=%u", net->mtu);
}
if (vlan == -1)
virBufferAsprintf(&buf, ",netdev=host%s", net->info.alias);
else
virBufferAsprintf(&buf, ",vlan=%d", vlan);
virBufferAsprintf(&buf, ",netdev=host%s", net->info.alias);
virBufferAsprintf(&buf, ",id=%s", net->info.alias);
virBufferAsprintf(&buf, ",mac=%s",
virMacAddrFormat(&net->mac, macaddr));
@ -3555,7 +3550,6 @@ qemuBuildNicDevStr(virDomainDefPtr def,
char *
qemuBuildHostNetStr(virDomainNetDefPtr net,
virQEMUDriverPtr driver,
int vlan,
char **tapfd,
size_t tapfdSize,
char **vhostfd,
@ -3670,13 +3664,7 @@ qemuBuildHostNetStr(virDomainNetDefPtr net,
break;
}
if (vlan >= 0) {
virBufferAsprintf(&buf, "vlan=%d,", vlan);
if (net->info.alias)
virBufferAsprintf(&buf, "name=host%s,", net->info.alias);
} else {
virBufferAsprintf(&buf, "id=host%s,", net->info.alias);
}
virBufferAsprintf(&buf, "id=host%s,", net->info.alias);
if (is_tap) {
if (vhostfdSize) {
@ -8203,7 +8191,6 @@ qemuBuildVhostuserCommandLine(virQEMUDriverPtr driver,
}
if (!(netdev = qemuBuildHostNetStr(net, driver,
-1,
NULL, 0, NULL, 0)))
goto error;
@ -8219,7 +8206,7 @@ qemuBuildVhostuserCommandLine(virQEMUDriverPtr driver,
virCommandAddArg(cmd, netdev);
VIR_FREE(netdev);
if (!(nic = qemuBuildNicDevStr(def, net, -1, bootindex,
if (!(nic = qemuBuildNicDevStr(def, net, bootindex,
queues, qemuCaps))) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("Error generating NIC -device string"));
@ -8248,7 +8235,6 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver,
virDomainDefPtr def,
virDomainNetDefPtr net,
virQEMUCapsPtr qemuCaps,
int vlan,
unsigned int bootindex,
virNetDevVPortProfileOp vmop,
bool standalone,
@ -8494,37 +8480,27 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver,
goto cleanup;
}
if (!(host = qemuBuildHostNetStr(net, driver,
tapfdName, tapfdSize,
vhostfdName, vhostfdSize)))
goto cleanup;
virCommandAddArgList(cmd, "-netdev", host, NULL);
/* Possible combinations:
*
* 1. Old way: -net nic,model=e1000,vlan=1 -net tap,vlan=1
* 2. New way: -netdev type=tap,id=netdev1 -device e1000,id=netdev1
*
* NB: The backend and frontend are reversed above
* Old way: -netdev type=tap,id=netdev1 \
* -net nic,model=e1000,netdev=netdev1
* New way: -netdev type=tap,id=netdev1 -device e1000,id=netdev1
*/
if (qemuDomainSupportsNicdev(def, net)) {
if (!(host = qemuBuildHostNetStr(net, driver,
vlan,
tapfdName, tapfdSize,
vhostfdName, vhostfdSize)))
goto cleanup;
virCommandAddArgList(cmd, "-netdev", host, NULL);
if (!(nic = qemuBuildNicDevStr(def, net, vlan, bootindex,
if (!(nic = qemuBuildNicDevStr(def, net, bootindex,
vhostfdSize, qemuCaps)))
goto cleanup;
virCommandAddArgList(cmd, "-device", nic, NULL);
} else {
if (!(nic = qemuBuildLegacyNicStr(net, vlan)))
if (!(nic = qemuBuildLegacyNicStr(net)))
goto cleanup;
virCommandAddArgList(cmd, "-net", nic, NULL);
if (!(host = qemuBuildHostNetStr(net, driver,
vlan,
tapfdName, tapfdSize,
vhostfdName, vhostfdSize)))
goto cleanup;
virCommandAddArgList(cmd, "-net", host, NULL);
}
ret = 0;
@ -8595,16 +8571,9 @@ qemuBuildNetCommandLine(virQEMUDriverPtr driver,
for (i = 0; i < def->nnets; i++) {
virDomainNetDefPtr net = def->nets[i];
int vlan;
/* VLANs are not used with -netdev and -device, so don't record them */
if (qemuDomainSupportsNicdev(def, net))
vlan = -1;
else
vlan = i;
if (qemuBuildInterfaceCommandLine(driver, logManager, cmd, def, net,
qemuCaps, vlan, bootNet, vmop,
qemuCaps, bootNet, vmop,
standalone, nnicindexes,
nicindexes,
chardevStdioLogd) < 0)

View File

@ -83,10 +83,8 @@ qemuBuildChrDeviceStr(char **deviceStr,
virDomainChrDefPtr chr,
virQEMUCapsPtr qemuCaps);
/* With vlan == -1, use netdev syntax, else old hostnet */
char *qemuBuildHostNetStr(virDomainNetDefPtr net,
virQEMUDriverPtr driver,
int vlan,
char **tapfd,
size_t tapfdSize,
char **vhostfd,
@ -95,7 +93,6 @@ char *qemuBuildHostNetStr(virDomainNetDefPtr net,
/* Current, best practice */
char *qemuBuildNicDevStr(virDomainDefPtr def,
virDomainNetDefPtr net,
int vlan,
unsigned int bootindex,
size_t vhostfdSize,
virQEMUCapsPtr qemuCaps);

View File

@ -994,7 +994,6 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
}
if (!(netstr = qemuBuildHostNetStr(net, driver,
-1,
tapfdName, tapfdSize,
vhostfdName, vhostfdSize)))
goto cleanup;
@ -1027,7 +1026,7 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
for (i = 0; i < vhostfdSize; i++)
VIR_FORCE_CLOSE(vhostfd[i]);
if (!(nicstr = qemuBuildNicDevStr(vm->def, net, -1, 0,
if (!(nicstr = qemuBuildNicDevStr(vm->def, net, 0,
queueSize, priv->qemuCaps)))
goto try_remove;

View File

@ -27,7 +27,7 @@ server,nowait \
-dtb /arm.dtb \
-usb \
-drive file=/arm.raw,format=raw,if=sd,index=0 \
-net nic,macaddr=52:54:00:09:a4:37,vlan=0,model=lan9118,name=net0 \
-net user,vlan=0,name=hostnet0 \
-netdev user,id=hostnet0 \
-net nic,macaddr=52:54:00:09:a4:37,netdev=hostnet0,model=lan9118,name=net0 \
-chardev pty,id=charserial0 \
-serial chardev:charserial0