mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
conf: Add virDomainNetIsVirtioModel
This will be extended in the future, so let's simplify things by centralizing the checks. Reviewed-by: Andrea Bolognani <abologna@redhat.com> Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
parent
cf09ef6cda
commit
ea72bc65df
@ -4735,7 +4735,7 @@ virDomainDeviceDefPostParseCommon(virDomainDeviceDefPtr dev,
|
|||||||
|
|
||||||
if (dev->type == VIR_DOMAIN_DEVICE_NET) {
|
if (dev->type == VIR_DOMAIN_DEVICE_NET) {
|
||||||
virDomainNetDefPtr net = dev->data.net;
|
virDomainNetDefPtr net = dev->data.net;
|
||||||
if (STRNEQ_NULLABLE(net->model, "virtio") &&
|
if (!virDomainNetIsVirtioModel(net) &&
|
||||||
virDomainCheckVirtioOptions(net->virtio) < 0)
|
virDomainCheckVirtioOptions(net->virtio) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -11341,7 +11341,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_NET_TYPE_VHOSTUSER:
|
case VIR_DOMAIN_NET_TYPE_VHOSTUSER:
|
||||||
if (STRNEQ_NULLABLE(def->model, "virtio")) {
|
if (!virDomainNetIsVirtioModel(def)) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("Wrong or no <model> 'type' attribute "
|
_("Wrong or no <model> 'type' attribute "
|
||||||
"specified with <interface type='vhostuser'/>. "
|
"specified with <interface type='vhostuser'/>. "
|
||||||
@ -11570,7 +11570,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (def->type != VIR_DOMAIN_NET_TYPE_HOSTDEV &&
|
if (def->type != VIR_DOMAIN_NET_TYPE_HOSTDEV &&
|
||||||
STREQ_NULLABLE(def->model, "virtio")) {
|
virDomainNetIsVirtioModel(def)) {
|
||||||
if (backend != NULL) {
|
if (backend != NULL) {
|
||||||
if ((val = virDomainNetBackendTypeFromString(backend)) < 0 ||
|
if ((val = virDomainNetBackendTypeFromString(backend)) < 0 ||
|
||||||
val == VIR_DOMAIN_NET_BACKEND_TYPE_DEFAULT) {
|
val == VIR_DOMAIN_NET_BACKEND_TYPE_DEFAULT) {
|
||||||
@ -25465,7 +25465,7 @@ virDomainNetDefFormat(virBufferPtr buf,
|
|||||||
if (def->model) {
|
if (def->model) {
|
||||||
virBufferEscapeString(buf, "<model type='%s'/>\n",
|
virBufferEscapeString(buf, "<model type='%s'/>\n",
|
||||||
def->model);
|
def->model);
|
||||||
if (STREQ(def->model, "virtio")) {
|
if (virDomainNetIsVirtioModel(def)) {
|
||||||
char *str = NULL, *gueststr = NULL, *hoststr = NULL;
|
char *str = NULL, *gueststr = NULL, *hoststr = NULL;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
@ -29719,6 +29719,13 @@ virDomainNetGetActualTrustGuestRxFilters(virDomainNetDefPtr iface)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
virDomainNetIsVirtioModel(const virDomainNetDef *net)
|
||||||
|
{
|
||||||
|
return STREQ_NULLABLE(net->model, "virtio");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Return listens[i] from the appropriate union for the graphics
|
/* Return listens[i] from the appropriate union for the graphics
|
||||||
* type, or NULL if this is an unsuitable type, or the index is out of
|
* type, or NULL if this is an unsuitable type, or the index is out of
|
||||||
* bounds. If force0 is TRUE, i == 0, and there is no listen array,
|
* bounds. If force0 is TRUE, i == 0, and there is no listen array,
|
||||||
|
@ -3217,6 +3217,7 @@ virNetDevBandwidthPtr
|
|||||||
virDomainNetGetActualBandwidth(virDomainNetDefPtr iface);
|
virDomainNetGetActualBandwidth(virDomainNetDefPtr iface);
|
||||||
virNetDevVlanPtr virDomainNetGetActualVlan(virDomainNetDefPtr iface);
|
virNetDevVlanPtr virDomainNetGetActualVlan(virDomainNetDefPtr iface);
|
||||||
bool virDomainNetGetActualTrustGuestRxFilters(virDomainNetDefPtr iface);
|
bool virDomainNetGetActualTrustGuestRxFilters(virDomainNetDefPtr iface);
|
||||||
|
bool virDomainNetIsVirtioModel(const virDomainNetDef *net);
|
||||||
int virDomainNetAppendIPAddress(virDomainNetDefPtr def,
|
int virDomainNetAppendIPAddress(virDomainNetDefPtr def,
|
||||||
const char *address,
|
const char *address,
|
||||||
int family,
|
int family,
|
||||||
|
@ -469,6 +469,7 @@ virDomainNetGetActualType;
|
|||||||
virDomainNetGetActualVirtPortProfile;
|
virDomainNetGetActualVirtPortProfile;
|
||||||
virDomainNetGetActualVlan;
|
virDomainNetGetActualVlan;
|
||||||
virDomainNetInsert;
|
virDomainNetInsert;
|
||||||
|
virDomainNetIsVirtioModel;
|
||||||
virDomainNetNotifyActualDevice;
|
virDomainNetNotifyActualDevice;
|
||||||
virDomainNetReleaseActualDevice;
|
virDomainNetReleaseActualDevice;
|
||||||
virDomainNetRemove;
|
virDomainNetRemove;
|
||||||
|
@ -3654,7 +3654,7 @@ qemuBuildNicDevStr(virDomainDefPtr def,
|
|||||||
bool usingVirtio = false;
|
bool usingVirtio = false;
|
||||||
char macaddr[VIR_MAC_STRING_BUFLEN];
|
char macaddr[VIR_MAC_STRING_BUFLEN];
|
||||||
|
|
||||||
if (STREQ(net->model, "virtio")) {
|
if (virDomainNetIsVirtioModel(net)) {
|
||||||
if (qemuBuildVirtioDevStr(&buf, "virtio-net", net->info.type) < 0)
|
if (qemuBuildVirtioDevStr(&buf, "virtio-net", net->info.type) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
@ -4665,7 +4665,7 @@ qemuDomainDeviceDefValidateNetwork(const virDomainNetDef *net)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (STREQ_NULLABLE(net->model, "virtio")) {
|
if (virDomainNetIsVirtioModel(net)) {
|
||||||
if (net->driver.virtio.rx_queue_size & (net->driver.virtio.rx_queue_size - 1)) {
|
if (net->driver.virtio.rx_queue_size & (net->driver.virtio.rx_queue_size - 1)) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
_("rx_queue_size has to be a power of two"));
|
_("rx_queue_size has to be a power of two"));
|
||||||
|
@ -320,7 +320,7 @@ qemuDomainPrimeVirtioDeviceAddresses(virDomainDefPtr def,
|
|||||||
for (i = 0; i < def->nnets; i++) {
|
for (i = 0; i < def->nnets; i++) {
|
||||||
virDomainNetDefPtr net = def->nets[i];
|
virDomainNetDefPtr net = def->nets[i];
|
||||||
|
|
||||||
if (STREQ_NULLABLE(net->model, "virtio") &&
|
if (virDomainNetIsVirtioModel(net) &&
|
||||||
net->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) {
|
net->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) {
|
||||||
net->info.type = type;
|
net->info.type = type;
|
||||||
}
|
}
|
||||||
|
@ -3710,7 +3710,7 @@ qemuDomainChangeNet(virQEMUDriverPtr driver,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (olddev->model && STREQ(olddev->model, "virtio") &&
|
if (virDomainNetIsVirtioModel(olddev) &&
|
||||||
(olddev->driver.virtio.name != newdev->driver.virtio.name ||
|
(olddev->driver.virtio.name != newdev->driver.virtio.name ||
|
||||||
olddev->driver.virtio.txmode != newdev->driver.virtio.txmode ||
|
olddev->driver.virtio.txmode != newdev->driver.virtio.txmode ||
|
||||||
olddev->driver.virtio.ioeventfd != newdev->driver.virtio.ioeventfd ||
|
olddev->driver.virtio.ioeventfd != newdev->driver.virtio.ioeventfd ||
|
||||||
|
@ -261,7 +261,7 @@ qemuInterfaceDirectConnect(virDomainDefPtr def,
|
|||||||
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
||||||
unsigned int macvlan_create_flags = VIR_NETDEV_MACVLAN_CREATE_WITH_TAP;
|
unsigned int macvlan_create_flags = VIR_NETDEV_MACVLAN_CREATE_WITH_TAP;
|
||||||
|
|
||||||
if (net->model && STREQ(net->model, "virtio"))
|
if (virDomainNetIsVirtioModel(net))
|
||||||
macvlan_create_flags |= VIR_NETDEV_MACVLAN_VNET_HDR;
|
macvlan_create_flags |= VIR_NETDEV_MACVLAN_VNET_HDR;
|
||||||
|
|
||||||
if (virNetDevMacVLanCreateWithVPortProfile(net->ifname,
|
if (virNetDevMacVLanCreateWithVPortProfile(net->ifname,
|
||||||
@ -434,7 +434,7 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def,
|
|||||||
template_ifname = true;
|
template_ifname = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (net->model && STREQ(net->model, "virtio"))
|
if (virDomainNetIsVirtioModel(net))
|
||||||
tap_create_flags |= VIR_NETDEV_TAP_CREATE_VNET_HDR;
|
tap_create_flags |= VIR_NETDEV_TAP_CREATE_VNET_HDR;
|
||||||
|
|
||||||
if (virNetDevTapCreate(&net->ifname, tunpath, tapfd, tapfdSize,
|
if (virNetDevTapCreate(&net->ifname, tunpath, tapfd, tapfdSize,
|
||||||
@ -533,7 +533,7 @@ qemuInterfaceBridgeConnect(virDomainDefPtr def,
|
|||||||
template_ifname = true;
|
template_ifname = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (net->model && STREQ(net->model, "virtio"))
|
if (virDomainNetIsVirtioModel(net))
|
||||||
tap_create_flags |= VIR_NETDEV_TAP_CREATE_VNET_HDR;
|
tap_create_flags |= VIR_NETDEV_TAP_CREATE_VNET_HDR;
|
||||||
|
|
||||||
if (virQEMUDriverIsPrivileged(driver)) {
|
if (virQEMUDriverIsPrivileged(driver)) {
|
||||||
@ -653,7 +653,7 @@ qemuInterfaceOpenVhostNet(virDomainDefPtr def,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* If the nic model isn't virtio, don't try to open. */
|
/* If the nic model isn't virtio, don't try to open. */
|
||||||
if (!(net->model && STREQ(net->model, "virtio"))) {
|
if (!virDomainNetIsVirtioModel(net)) {
|
||||||
if (net->driver.virtio.name == VIR_DOMAIN_NET_BACKEND_TYPE_VHOST) {
|
if (net->driver.virtio.name == VIR_DOMAIN_NET_BACKEND_TYPE_VHOST) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
"%s", _("vhost-net is only supported for "
|
"%s", _("vhost-net is only supported for "
|
||||||
|
@ -1255,7 +1255,7 @@ get_files(vahControl * ctl)
|
|||||||
if (net && net->model) {
|
if (net && net->model) {
|
||||||
if (net->driver.virtio.name == VIR_DOMAIN_NET_BACKEND_TYPE_QEMU)
|
if (net->driver.virtio.name == VIR_DOMAIN_NET_BACKEND_TYPE_QEMU)
|
||||||
continue;
|
continue;
|
||||||
if (STRNEQ(net->model, "virtio"))
|
if (!virDomainNetIsVirtioModel(net))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
needsvhost = true;
|
needsvhost = true;
|
||||||
|
@ -228,7 +228,7 @@ qemuInterfaceOpenVhostNet(virDomainDefPtr def ATTRIBUTE_UNUSED,
|
|||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
if (!(net->model && STREQ(net->model, "virtio"))) {
|
if (!virDomainNetIsVirtioModel(net)) {
|
||||||
*vhostfdSize = 0;
|
*vhostfdSize = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user