[libvirt] [PATCH v2 resend 4/4] qemu: add usb-net support

Guannan Ren gren at redhat.com
Mon Feb 25 11:07:37 UTC 2013


For USB device, the <address> is optional, so is usb-net.
Currently, we couldn't assign default usb address to usb
devices, so we definitly ignore it during the assignment of PCI
address.

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 | 29 +++++++++++------------------
 src/conf/domain_conf.c    | 15 ++++++++++++---
 src/conf/domain_conf.h    |  1 +
 src/qemu/qemu_command.c   |  8 +++++++-
 4 files changed, 31 insertions(+), 22 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index a9003d7..eb7b5dc 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -2960,24 +2960,17 @@
 
     <p>
       For hypervisors which support this, you can set the model of
-      emulated network interface card.
-    </p>
-
-    <p>
-      The values for <code>type</code> aren't defined specifically by
-      libvirt, but by what the underlying hypervisor supports (if
-      any).  For QEMU and KVM you can get a list of supported models
-      with these commands:
-    </p>
-
-<pre>
-qemu -net nic,model=? /dev/null
-qemu-kvm -net nic,model=? /dev/null
-</pre>
-
-    <p>
-      Typical values for QEMU and KVM include:
-      ne2k_isa i82551 i82557b i82559er ne2k_pci pcnet rtl8139 e1000 virtio
+      emulated network interface card. For QEMU and KVM, the supported NIC models
+      are virtio, ne2k_isa, ne2k_pci, pcnet, rtl8139, e1000, usb-net
+      <span class="since">(since 1.0.3)</span>, spapr-vlan(only PPC64).
+      For Xen, there are ne2k_isa, ne2k_pci, pcnet, rtl8139, e1000, netfront. For VMWare,
+      vlance, vmxnet, vmxnet2, vmxnet3 are supported. And for Vbox, Am79C970A, Am79C973,
+      82540EM, 82545EM, 82543GC are its supported models.
+      (All of these models are PCI devices, except usb-net which emulates a Netchip
+       Linux-USB Ethernet/RNDIS usb ethernet device). For models of PCI type, a sub-element
+      <code><address></code> with <code>type='pci'</code> can be used to tie
+      the device to a particular PCI slot. It is <code>type='usb'</code> for usb-net
+      to tie to USB controller. <a href="#elementsAddress">documented above</a>.
     </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 96203e2..78a9a77 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -708,6 +708,7 @@ VIR_ENUM_IMPL(virDomainNICModel,
               VIR_DOMAIN_NIC_MODEL_LAST,
               "default",
               "spapr-vlan", /* qemu */
+              "usb-net",
 
               "virtio",     /* qemu and vbox */
 
@@ -5427,15 +5428,16 @@ 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_CCW &&
         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;
     }
 
@@ -5642,6 +5644,13 @@ virDomainNetDefParseXML(virCapsPtr caps,
             }
             def->driver.virtio.event_idx = idx;
         }
+    } else if (def->model == VIR_DOMAIN_NIC_MODEL_USB_NET) {
+        if (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;
+        }
     }
 
     def->linkstate = VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DEFAULT;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 687032b..8ef044e 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -785,6 +785,7 @@ struct _virDomainFSDef {
 enum virDomainNICModel {
     VIR_DOMAIN_NIC_MODEL_DEFAULT = 0,
     VIR_DOMAIN_NIC_MODEL_SPAPR_VLAN,
+    VIR_DOMAIN_NIC_MODEL_USB_NET,
     VIR_DOMAIN_NIC_MODEL_VIRTIO,
     VIR_DOMAIN_NIC_MODEL_NE2K_ISA,
     VIR_DOMAIN_NIC_MODEL_NE2K_PCI,
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 3a98566..ad4ffec 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1530,7 +1530,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) ||
+            (def->nets[i]->model == VIR_DOMAIN_NIC_MODEL_USB_NET)) {
             continue;
         }
         if (qemuDomainPCIAddressSetNextAddr(addrs, &def->nets[i]->info) < 0)
@@ -3167,6 +3168,11 @@ qemuBuildNicDevStr(virDomainNetDefPtr net,
             nic = "virtio-net-pci";
         }
         usingVirtio = true;
+    } else if ((net->model == VIR_DOMAIN_NIC_MODEL_USB_NET) &&
+               !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_USB_NET)) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("usb-net is not supported in this QEMU binary"));
+        goto error;
     } else {
         nic = virDomainNICModelTypeToString(net->model);
     }
-- 
1.7.11.2




More information about the libvir-list mailing list