9119d9
From 1f343ca2d34c0bd5f012079ab07a7c1cc9bf0fe4 Mon Sep 17 00:00:00 2001
9119d9
Message-Id: <1f343ca2d34c0bd5f012079ab07a7c1cc9bf0fe4@dist-git>
9119d9
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
9119d9
Date: Wed, 17 Sep 2014 19:15:58 +0200
9119d9
Subject: [PATCH] conf: add backend element to interfaces
9119d9
9119d9
https://bugzilla.redhat.com/show_bug.cgi?id=1139362
9119d9
9119d9
For tuning the network, alternative devices
9119d9
for creating tap and vhost devices can be specified via:
9119d9
<backend tap='/dev/net/tun' vhost='/dev/net-vhost'/>
9119d9
9119d9
(cherry picked from commit af8b4a2e6fc264dda4c7fda9b1696a16e59caeb4)
9119d9
9119d9
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
9119d9
---
9119d9
 docs/formatdomain.html.in                         | 20 +++++++++
9119d9
 docs/schemas/domaincommon.rng                     | 10 +++++
9119d9
 src/conf/domain_conf.c                            | 11 +++++
9119d9
 src/conf/domain_conf.h                            |  4 ++
9119d9
 tests/qemuxml2argvdata/qemuxml2argv-tap-vhost.xml | 52 +++++++++++++++++++++++
9119d9
 tests/qemuxml2xmltest.c                           |  2 +
9119d9
 6 files changed, 99 insertions(+)
9119d9
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-tap-vhost.xml
9119d9
9119d9
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
9119d9
index ade40f3..a3ab5cf 100644
9119d9
--- a/docs/formatdomain.html.in
9119d9
+++ b/docs/formatdomain.html.in
9119d9
@@ -3956,6 +3956,26 @@ qemu-kvm -net nic,model=? /dev/null
9119d9
       
9119d9
     
9119d9
 
9119d9
+    
Setting network backend-specific options
9119d9
+
9119d9
+
9119d9
+  ...
9119d9
+  <devices>
9119d9
+    <interface type='network'>
9119d9
+      <source network='default'/>
9119d9
+      <target dev='vnet1'/>
9119d9
+      <model type='virtio'/>
9119d9
+      <backend tap='/dev/net/tun' vhost='/dev/net-vhost'/>
9119d9
+      <driver name='vhost' txmode='iothread' ioeventfd='on' event_idx='off' queues='5'/>
9119d9
+    </interface>
9119d9
+  </devices>
9119d9
+  ...
9119d9
+
9119d9
+    

9119d9
+      For tuning the backend of the network, the backend element
9119d9
+      can be used. Supported attributes are tap and vhost,
9119d9
+      allowing to override the default devices for creating tap and vhost devices.
9119d9
+    

9119d9
     
Overriding the target element
9119d9
 
9119d9
 
9119d9
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
9119d9
index 75006f5..31974ac 100644
9119d9
--- a/docs/schemas/domaincommon.rng
9119d9
+++ b/docs/schemas/domaincommon.rng
9119d9
@@ -2335,6 +2335,16 @@
9119d9
         </element>
9119d9
       </optional>
9119d9
       <optional>
9119d9
+        <element name="backend">
9119d9
+           <attribute name='tap'>
9119d9
+             <ref name='absFilePath'/>
9119d9
+           </attribute>
9119d9
+           <attribute name='vhost'>
9119d9
+             <ref name='absFilePath'/>
9119d9
+           </attribute>
9119d9
+        </element>
9119d9
+      </optional>
9119d9
+      <optional>
9119d9
         <element name="driver">
9119d9
           <choice>
9119d9
             <group>
9119d9
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
9119d9
index ea727a1..7d78b0b 100644
9119d9
--- a/src/conf/domain_conf.c
9119d9
+++ b/src/conf/domain_conf.c
9119d9
@@ -1412,6 +1412,8 @@ void virDomainNetDefFree(virDomainNetDefPtr def)
9119d9
         break;
9119d9
     }
9119d9
 
9119d9
+    VIR_FREE(def->backend.tap);
9119d9
+    VIR_FREE(def->backend.vhost);
9119d9
     VIR_FREE(def->virtPortProfile);
9119d9
     VIR_FREE(def->script);
9119d9
     VIR_FREE(def->ifname);
9119d9
@@ -7033,6 +7035,9 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
9119d9
             } else if (xmlStrEqual(cur->name, BAD_CAST "vlan")) {
9119d9
                 if (virNetDevVlanParse(cur, ctxt, &def->vlan) < 0)
9119d9
                     goto error;
9119d9
+            } else if (xmlStrEqual(cur->name, BAD_CAST "backend")) {
9119d9
+                def->backend.tap = virXMLPropString(cur, "tap");
9119d9
+                def->backend.vhost = virXMLPropString(cur, "vhost");
9119d9
             }
9119d9
         }
9119d9
         cur = cur->next;
9119d9
@@ -16550,6 +16555,12 @@ virDomainNetDefFormat(virBufferPtr buf,
9119d9
             virBufferAddLit(buf, "/>\n");
9119d9
         }
9119d9
     }
9119d9
+    if (def->backend.tap || def->backend.vhost) {
9119d9
+        virBufferAddLit(buf, "
9119d9
+        virBufferEscapeString(buf, " tap='%s'", def->backend.tap);
9119d9
+        virBufferEscapeString(buf, " vhost='%s'", def->backend.vhost);
9119d9
+        virBufferAddLit(buf, "/>\n");
9119d9
+    }
9119d9
     if (def->filter) {
9119d9
         if (virNWFilterFormatParamAttributes(buf, def->filterparams,
9119d9
                                              def->filter) < 0)
9119d9
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
9119d9
index 3316fb6..c93b73c 100644
9119d9
--- a/src/conf/domain_conf.h
9119d9
+++ b/src/conf/domain_conf.h
9119d9
@@ -897,6 +897,10 @@ struct _virDomainNetDef {
9119d9
             unsigned int queues; /* Multiqueue virtio-net */
9119d9
         } virtio;
9119d9
     } driver;
9119d9
+    struct {
9119d9
+        char *tap;
9119d9
+        char *vhost;
9119d9
+    } backend;
9119d9
     union {
9119d9
         struct {
9119d9
             char *dev;
9119d9
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-tap-vhost.xml b/tests/qemuxml2argvdata/qemuxml2argv-tap-vhost.xml
9119d9
new file mode 100644
9119d9
index 0000000..3237c6a
9119d9
--- /dev/null
9119d9
+++ b/tests/qemuxml2argvdata/qemuxml2argv-tap-vhost.xml
9119d9
@@ -0,0 +1,52 @@
9119d9
+<domain type='qemu'>
9119d9
+  <name>test</name>
9119d9
+  <uuid>bba65c0e-c049-934f-b6aa-4e2c0582acdf</uuid>
9119d9
+  <memory unit='KiB'>1048576</memory>
9119d9
+  <currentMemory unit='KiB'>1048576</currentMemory>
9119d9
+  <vcpu placement='static'>1</vcpu>
9119d9
+  <os>
9119d9
+    <type arch='x86_64' machine='pc-0.13'>hvm</type>
9119d9
+    <boot dev='cdrom'/>
9119d9
+    <boot dev='hd'/>
9119d9
+    <bootmenu enable='yes'/>
9119d9
+  </os>
9119d9
+  <clock offset='utc'/>
9119d9
+  <on_poweroff>destroy</on_poweroff>
9119d9
+  <on_reboot>restart</on_reboot>
9119d9
+  <on_crash>restart</on_crash>
9119d9
+  <devices>
9119d9
+    <emulator>/usr/bin/qemu</emulator>
9119d9
+    <disk type='file' device='disk'>
9119d9
+      <driver name='qemu' type='qcow2' event_idx='on'/>
9119d9
+      <source file='/var/lib/libvirt/images/f14.img'/>
9119d9
+      <target dev='vda' bus='virtio'/>
9119d9
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
9119d9
+    </disk>
9119d9
+    <disk type='file' device='cdrom'>
9119d9
+      <driver name='qemu' type='raw'/>
9119d9
+      <source file='/var/lib/libvirt/Fedora-14-x86_64-Live-KDE.iso'/>
9119d9
+      <target dev='hdc' bus='ide'/>
9119d9
+      <readonly/>
9119d9
+      <address type='drive' controller='0' bus='1' target='0' unit='0'/>
9119d9
+    </disk>
9119d9
+    <controller type='usb' index='0'/>
9119d9
+    <controller type='virtio-serial' index='0'>
9119d9
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
9119d9
+    </controller>
9119d9
+    <controller type='ide' index='0'/>
9119d9
+    <controller type='pci' index='0' model='pci-root'/>
9119d9
+    <interface type='user'>
9119d9
+      <mac address='52:54:00:e5:48:58'/>
9119d9
+      <model type='virtio'/>
9119d9
+      <driver name='vhost' queues='5'/>
9119d9
+      <backend tap='/dev/null' vhost='/dev/zero'/>
9119d9
+    </interface>
9119d9
+    <serial type='pty'>
9119d9
+      <target port='0'/>
9119d9
+    </serial>
9119d9
+    <console type='pty'>
9119d9
+      <target type='serial' port='0'/>
9119d9
+    </console>
9119d9
+    <memballoon model='virtio'/>
9119d9
+  </devices>
9119d9
+</domain>
9119d9
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
9119d9
index 180665b..1e06f38 100644
9119d9
--- a/tests/qemuxml2xmltest.c
9119d9
+++ b/tests/qemuxml2xmltest.c
9119d9
@@ -399,6 +399,8 @@ mymain(void)
9119d9
 
9119d9
     DO_TEST("bios-nvram");
9119d9
 
9119d9
+    DO_TEST("tap-vhost");
9119d9
+
9119d9
     virObjectUnref(driver.caps);
9119d9
     virObjectUnref(driver.xmlopt);
9119d9
 
9119d9
-- 
9119d9
2.1.0
9119d9