[PATCH 5/5] qemu: add usb-net support

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

 



For USB device, the <address> is optional, so is usb-net.
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 |  8 +++++++-
 src/conf/domain_conf.c    | 15 ++++++++++++---
 src/conf/domain_conf.h    |  1 +
 src/qemu/qemu_command.c   |  8 +++++++-
 4 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index bb0b199..bc0e7a0 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -2963,7 +2963,13 @@ 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 usb-net.
+      (All of these models are PCI devices, except usb-net which emulates a Netchip
+       Linux-USB Ethernet/RNDIS usb ethernet device). For NICs of PCI type, a sub-element
+      <code>&lt;address&gt;</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
+      <span class="since">(since 1.0.2)</span> 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 fb71f64..ec88ae0 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -715,6 +715,7 @@ VIR_ENUM_IMPL(virDomainNICModel,
               "i82562",
               "i82801",
               "spapr-vlan",
+              "usb-net",
 
               "virtio",   /* qemu and vbox */
 
@@ -5198,14 +5199,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;
     }
 
@@ -5412,6 +5414,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 2921cab..9235b34 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -784,6 +784,7 @@ enum virDomainNICModel {
     VIR_DOMAIN_NIC_MODEL_I82562,
     VIR_DOMAIN_NIC_MODEL_I82801,
     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 fcd7512..89c9668 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1557,7 +1557,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)
@@ -3179,6 +3180,11 @@ qemuBuildNicDevStr(virDomainNetDefPtr net,
             nic = "virtio-net-pci";
         }
         usingVirtio = true;
+    } else if ((net->model == VIR_DOMAIN_NIC_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 = virDomainNICModelTypeToString(net->model);
     }
-- 
1.7.11.2

--
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]