From: Michal Privoznik
+... +<devices> + <interface type='network'> + <source network='default'/> + <target dev='vnet0'/> + <mtu size='1500'/> + </interface> +</devices> +...+ +
+ This element provides means of setting MTU of the virtual network link.
+ Currently there is just one attribute size which accepts a
+ non-negative integer which specifies the MTU size for the interface.
+ Since 3.1.0
+
...
diff --git a/docs/news.xml b/docs/news.xml
index ef7e2db861..fdbb80f441 100644
--- a/docs/news.xml
+++ b/docs/news.xml
@@ -24,6 +24,14 @@
options in order to print just the --name and/or --uuid of pools.
+
+
+ Introduce MTU to domain <interface/>
+
+
+ Allow setting MTU size for some types of domain interface.
+
+
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 4d76315b09..cc6e0d0c0d 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -2465,6 +2465,9 @@
+
+
+
diff --git a/docs/schemas/networkcommon.rng b/docs/schemas/networkcommon.rng
index a334b83e3b..26995556d4 100644
--- a/docs/schemas/networkcommon.rng
+++ b/docs/schemas/networkcommon.rng
@@ -260,10 +260,19 @@
+
kernel
libvirt
+
+
+
+
+
+
+
+
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 26bb0fdd0a..a2b72cb9c5 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -10050,6 +10050,12 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
goto error;
}
+ if (virXPathUInt("string(./mtu/@size)", ctxt, &def->mtu) < -1) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("malformed mtu size"));
+ goto error;
+ }
+
cleanup:
ctxt->node = oldnode;
VIR_FREE(macaddr);
@@ -21769,6 +21775,10 @@ virDomainNetDefFormat(virBufferPtr buf,
virBufferAsprintf(buf, "\n",
virDomainNetInterfaceLinkStateTypeToString(def->linkstate));
}
+
+ if (def->mtu)
+ virBufferAsprintf(buf, " \n", def->mtu);
+
if (virDomainDeviceInfoFormat(buf, &def->info,
flags | VIR_DOMAIN_DEF_FORMAT_ALLOW_BOOT
| VIR_DOMAIN_DEF_FORMAT_ALLOW_ROM) < 0)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 78a3db4e12..4d830c51d4 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1009,6 +1009,7 @@ struct _virDomainNetDef {
virNetDevVlan vlan;
int trustGuestRxFilters; /* enum virTristateBool */
int linkstate;
+ unsigned int mtu;
};
/* Used for prefix of ifname of any network name generated dynamically
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 2ed45ab176..26ca899306 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2868,6 +2868,14 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
_("rx_queue_size has to be a power of two"));
goto cleanup;
}
+
+ if (net->mtu &&
+ !qemuDomainNetSupportsMTU(net->type)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("setting MTU on interface type %s is not supported yet"),
+ virDomainNetTypeToString(net->type));
+ goto cleanup;
+ }
}
ret = 0;
@@ -6529,6 +6537,27 @@ qemuDomainSupportsNetdev(virDomainDefPtr def,
return virQEMUCapsGet(qemuCaps, QEMU_CAPS_NETDEV);
}
+bool
+qemuDomainNetSupportsMTU(virDomainNetType type)
+{
+ switch (type) {
+ case VIR_DOMAIN_NET_TYPE_USER:
+ case VIR_DOMAIN_NET_TYPE_ETHERNET:
+ case VIR_DOMAIN_NET_TYPE_VHOSTUSER:
+ case VIR_DOMAIN_NET_TYPE_SERVER:
+ case VIR_DOMAIN_NET_TYPE_CLIENT:
+ case VIR_DOMAIN_NET_TYPE_MCAST:
+ case VIR_DOMAIN_NET_TYPE_NETWORK:
+ case VIR_DOMAIN_NET_TYPE_BRIDGE:
+ case VIR_DOMAIN_NET_TYPE_INTERNAL:
+ case VIR_DOMAIN_NET_TYPE_DIRECT:
+ case VIR_DOMAIN_NET_TYPE_HOSTDEV:
+ case VIR_DOMAIN_NET_TYPE_UDP:
+ case VIR_DOMAIN_NET_TYPE_LAST:
+ break;
+ }
+ return false;
+}
int
qemuDomainNetVLAN(virDomainNetDefPtr def)
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 88b5869725..041149167c 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -708,6 +708,8 @@ bool qemuDomainSupportsNetdev(virDomainDefPtr def,
virQEMUCapsPtr qemuCaps,
virDomainNetDefPtr net);
+bool qemuDomainNetSupportsMTU(virDomainNetType type);
+
int qemuDomainNetVLAN(virDomainNetDefPtr def);
int qemuDomainSetPrivatePaths(virQEMUDriverPtr driver,
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-net-mtu.xml b/tests/qemuxml2argvdata/qemuxml2argv-net-mtu.xml
new file mode 100644
index 0000000000..6063224633
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-net-mtu.xml
@@ -0,0 +1,60 @@
+
+ test
+ 15d091de-0181-456b-9554-e4382dc1f1ab
+ 1048576
+ 1048576
+ 1
+
+ hvm
+
+
+
+
+
+ destroy
+ restart
+ restart
+
+ /usr/bin/qemu
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+