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

[libvirt] [PATCH 3/3] qemu: add usb-net support



Libvirt XML sample:
  <devices>
    <interface type='user'>
      <mac address='52:54:00:32:6a:91'/>
      <model type='usb-net'/>
      <alias name='net1'/>
      <address type='usb' bus='0' port='1'/>
    </interface>
  </devices>

qemu commandline:

qemu ${other_vm_args}
    -netdev user,id=hostnet1 \
    -device usb-net,netdev=hostnet1,id=net1,\
      mac=52:54:00:32:6a:91,bus=usb.0,port=1
---
 docs/formatdomain.html.in |  4 +++-
 src/conf/domain_conf.c    | 18 +++++++++++++-----
 src/qemu/qemu_command.c   |  8 +++++++-
 3 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 45d7593..fbd77f2 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -2952,7 +2952,9 @@ qemu-kvm -net nic,model=? /dev/null
 
     <p>
       Typical values for QEMU and KVM include:
-      ne2k_isa i82551 i82557b i82559er ne2k_pci pcnet rtl8139 e1000 virtio
+      ne2k_isa i82551 i82557b i82559er ne2k_pci pcnet rtl8139 e1000 virtio.
+      Besides above, there is a model of usb-net which is a QEMU USB Network interface
+      <span class="since">Since 1.0.2 (QEMU and KVM only)</span>
     </p>
 
     <h5><a name="elementsDriverBackendOptions">Setting NIC driver-specific options</a></h5>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 70c1ee7..94cd059 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5131,14 +5131,15 @@ virDomainNetDefParseXML(virCapsPtr caps,
             goto error;
     }
 
-    /* XXX what about ISA/USB based NIC models - once we support
+    /* XXX what about ISA based NIC models - once we support
      * them we should make sure address type is correct */
     if (def->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
         def->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO &&
         def->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390 &&
-        def->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
+        def->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI &&
+        def->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("Network interfaces must use 'pci' address type"));
+                       _("Network interfaces have incorrect address type"));
         goto error;
     }
 
@@ -5301,9 +5302,16 @@ virDomainNetDefParseXML(virCapsPtr caps,
             virReportError(VIR_ERR_INVALID_ARG, "%s",
                            _("Model name contains invalid characters"));
             goto error;
+        } else if (STREQ(model, "usb-net") &&
+                   def->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
+                   def->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("Interface of usb-net model requires address of usb type"));
+            goto error;
+        } else {
+            def->model = model;
+            model = NULL;
         }
-        def->model = model;
-        model = NULL;
     }
 
     if (def->model && STREQ(def->model, "virtio")) {
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 8a3de09..b3ce76a 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1558,7 +1558,8 @@ qemuAssignDevicePCISlots(virDomainDefPtr def,
          * instead of here.
          */
         if ((def->nets[i]->type == VIR_DOMAIN_NET_TYPE_HOSTDEV) ||
-            (def->nets[i]->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE)) {
+            (def->nets[i]->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) ||
+            (STREQ_NULLABLE(def->nets[i]->model, "usb-net"))) {
             continue;
         }
         if (qemuDomainPCIAddressSetNextAddr(addrs, &def->nets[i]->info) < 0)
@@ -3180,6 +3181,11 @@ qemuBuildNicDevStr(virDomainNetDefPtr net,
             nic = "virtio-net-pci";
         }
         usingVirtio = true;
+    } else if (STREQ(net->model, "usb-net") &&
+               !qemuCapsGet(caps, QEMU_CAPS_DEVICE_USB_NET)) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("usb-net is not supported in this QEMU binary"));
+        goto error;
     } else {
         nic = net->model;
     }
-- 
1.7.11.4


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