[PATCH 3/4] domain_conf: Introduce <mtu/> to <interface/>

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



So far we allow to set MTU for libvirt networks. However, not all
domain interfaces have to be plugged into a libvirt network and
even if they are, they might want to have a different MTU (e.g.
for testing purposes).

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 docs/formatdomain.html.in                       | 19 ++++++++
 docs/schemas/domaincommon.rng                   |  3 ++
 docs/schemas/networkcommon.rng                  |  9 ++++
 src/conf/domain_conf.c                          | 10 +++++
 src/conf/domain_conf.h                          |  1 +
 src/qemu/qemu_domain.c                          | 29 ++++++++++++
 src/qemu/qemu_domain.h                          |  2 +
 tests/qemuxml2argvdata/qemuxml2argv-net-mtu.xml | 60 +++++++++++++++++++++++++
 8 files changed, 133 insertions(+)
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-net-mtu.xml

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 3f7f87524..1bbece0e5 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -5215,6 +5215,25 @@ qemu-kvm -net nic,model=? /dev/null
       <span class="since">Since 0.9.5</span>
     </p>
 
+    <h5><a name="mtu">MTU configuration</a></h5>
+<pre>
+...
+&lt;devices&gt;
+  &lt;interface type='network'&gt;
+    &lt;source network='default'/&gt;
+    &lt;target dev='vnet0'/&gt;
+    <b>&lt;mtu size='1500'/&gt;</b>
+  &lt;/interface&gt;
+&lt;/devices&gt;
+...</pre>
+
+    <p>
+      This element provides means of setting MTU of the virtual network link.
+      Currently there is just one attribute <code>size</code> which accepts a
+      non-negative integer which specifies the MTU size for the interface.
+      <span class="since">Since 3.1.0</span>
+    </p>
+
     <h5><a name="ipconfig">IP configuration</a></h5>
 <pre>
 ...
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 4d76315b0..cc6e0d0c0 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -2465,6 +2465,9 @@
           <empty/>
         </element>
       </optional>
+      <optional>
+        <ref name="mtu"/>
+      </optional>
       <optional>
         <element name="target">
           <attribute name="dev">
diff --git a/docs/schemas/networkcommon.rng b/docs/schemas/networkcommon.rng
index a334b83e3..26995556d 100644
--- a/docs/schemas/networkcommon.rng
+++ b/docs/schemas/networkcommon.rng
@@ -260,10 +260,19 @@
       </optional>
     </element>
   </define>
+
   <define name="macTableManager">
     <choice>
       <value>kernel</value>
       <value>libvirt</value>
     </choice>
   </define>
+
+  <define name="mtu">
+    <element name="mtu">
+      <attribute name="size">
+        <ref name="unsignedShort"/>
+      </attribute>
+    </element>
+  </define>
 </grammar>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 26bb0fdd0..a2b72cb9c 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, "<link state='%s'/>\n",
                           virDomainNetInterfaceLinkStateTypeToString(def->linkstate));
     }
+
+    if (def->mtu)
+        virBufferAsprintf(buf, "<mtu size='%u'/>\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 78a3db4e1..4d830c51d 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 2ed45ab17..26ca89930 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 88b586972..041149167 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 000000000..606322463
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-net-mtu.xml
@@ -0,0 +1,60 @@
+<domain type='qemu'>
+  <name>test</name>
+  <uuid>15d091de-0181-456b-9554-e4382dc1f1ab</uuid>
+  <memory unit='KiB'>1048576</memory>
+  <currentMemory unit='KiB'>1048576</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='x86_64' machine='pc-0.13'>hvm</type>
+    <boot dev='cdrom'/>
+    <boot dev='hd'/>
+    <bootmenu enable='yes'/>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>restart</on_crash>
+  <devices>
+    <emulator>/usr/bin/qemu</emulator>
+    <disk type='file' device='disk'>
+      <driver name='qemu' type='qcow2' event_idx='on'/>
+      <source file='/var/lib/libvirt/images/f14.img'/>
+      <target dev='vda' bus='virtio'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
+    </disk>
+    <disk type='file' device='cdrom'>
+      <driver name='qemu' type='raw'/>
+      <source file='/var/lib/libvirt/Fedora-14-x86_64-Live-KDE.iso'/>
+      <target dev='hdc' bus='ide'/>
+      <readonly/>
+      <address type='drive' controller='0' bus='1' target='0' unit='0'/>
+    </disk>
+    <controller type='usb' index='0'/>
+    <controller type='virtio-serial' index='0'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
+    </controller>
+    <controller type='ide' index='0'/>
+    <controller type='pci' index='0' model='pci-root'/>
+    <interface type='network'>
+      <source network='default'/>
+      <mac address='52:54:00:e5:48:58'/>
+      <model type='virtio'/>
+      <mtu size='1500'/>
+    </interface>
+    <interface type='network'>
+      <source network='default'/>
+      <mac address='52:54:00:e5:48:59'/>
+      <model type='virtio'/>
+      <mtu size='9000'/>
+    </interface>
+    <serial type='pty'>
+      <target port='0'/>
+    </serial>
+    <console type='pty'>
+      <target type='serial' port='0'/>
+    </console>
+    <input type='mouse' bus='ps2'/>
+    <input type='keyboard' bus='ps2'/>
+    <memballoon model='virtio'/>
+  </devices>
+</domain>
-- 
2.11.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux