mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-25 22:15:20 +00:00
qemu: support setting vlan tag for <interface type='hostdev'>
The underlying function to set the vlan tag of an SR-IOV network device was already in place (although an extra patch to save/restore the original vlan tag was needed), and recent patches added the ability to configure a vlan tag. This patch just ties those two together. An SR-IOV device doesn't support vlan trunking, so if anyone tries to configure more than a single tag, or set the trunk flag, and error is logged.
This commit is contained in:
parent
e979226ba2
commit
3fdd85bf53
@ -301,6 +301,7 @@ qemuDomainHostdevNetConfigReplace(virDomainHostdevDefPtr hostdev,
|
|||||||
char *stateDir)
|
char *stateDir)
|
||||||
{
|
{
|
||||||
char *linkdev = NULL;
|
char *linkdev = NULL;
|
||||||
|
virNetDevVlanPtr vlan;
|
||||||
virNetDevVPortProfilePtr virtPort;
|
virNetDevVPortProfilePtr virtPort;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
int vf = -1;
|
int vf = -1;
|
||||||
@ -319,19 +320,46 @@ qemuDomainHostdevNetConfigReplace(virDomainHostdevDefPtr hostdev,
|
|||||||
if (qemuDomainHostdevNetDevice(hostdev, &linkdev, &vf) < 0)
|
if (qemuDomainHostdevNetDevice(hostdev, &linkdev, &vf) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
vlan = virDomainNetGetActualVlan(hostdev->parent.data.net);
|
||||||
virtPort = virDomainNetGetActualVirtPortProfile(
|
virtPort = virDomainNetGetActualVirtPortProfile(
|
||||||
hostdev->parent.data.net);
|
hostdev->parent.data.net);
|
||||||
if (virtPort)
|
if (virtPort) {
|
||||||
|
if (vlan) {
|
||||||
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
|
_("direct setting of the vlan tag is not allowed "
|
||||||
|
"for hostdev devices using %s mode"),
|
||||||
|
virNetDevVPortTypeToString(virtPort->virtPortType));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
ret = qemuDomainHostdevNetConfigVirtPortProfile(linkdev, vf,
|
ret = qemuDomainHostdevNetConfigVirtPortProfile(linkdev, vf,
|
||||||
virtPort, &hostdev->parent.data.net->mac, uuid,
|
virtPort, &hostdev->parent.data.net->mac, uuid,
|
||||||
port_profile_associate);
|
port_profile_associate);
|
||||||
else
|
} else {
|
||||||
/* Set only mac */
|
/* Set only mac and vlan */
|
||||||
ret = virNetDevReplaceNetConfig(linkdev, vf,
|
if (vlan) {
|
||||||
&hostdev->parent.data.net->mac, vlanid,
|
if (vlan->nTags != 1 || vlan->trunk) {
|
||||||
stateDir);
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
VIR_FREE(linkdev);
|
_("vlan trunking is not supported "
|
||||||
|
"by SR-IOV network devices"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
if (vf == -1) {
|
||||||
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
|
_("vlan can only be set for SR-IOV VFs, but "
|
||||||
|
"%s is not a VF"), linkdev);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
vlanid = vlan->tag[0];
|
||||||
|
} else if (vf >= 0) {
|
||||||
|
vlanid = 0; /* assure any current vlan tag is reset */
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = virNetDevReplaceNetConfig(linkdev, vf,
|
||||||
|
&hostdev->parent.data.net->mac,
|
||||||
|
vlanid, stateDir);
|
||||||
|
}
|
||||||
|
cleanup:
|
||||||
|
VIR_FREE(linkdev);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user