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

The set of patches fixed some typo in network docs and codes and is trying to support usb-net qemu virtual device. The following is an example for use. 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 Guannan Ren(3) [PATCH 1/3] network: fix typos and docs [PATCH 2/3] qemu: add usb-net caps flag [PATCH 3/3] qemu: add usb-net support docs/formatdomain.html.in | 13 +++++++++---- src/conf/domain_conf.c | 22 +++++++++++++++------- src/qemu/qemu_capabilities.c | 2 ++ src/qemu/qemu_capabilities.h | 1 + src/qemu/qemu_command.c | 8 +++++++- tests/qemuhelptest.c | 21 ++++++++++++++------- 6 files changed, 48 insertions(+), 19 deletions(-)

--- docs/formatdomain.html.in | 9 ++++++--- src/conf/domain_conf.c | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 94df6f8..45d7593 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -2546,12 +2546,15 @@ virtualport types (and also to leave out certain attributes); at domain startup time, a complete <code><virtualport></code> element will be constructed by merging together the type and - attributes found in the which will be filled in from the network - or portgroup <code><virtualport></code>) + attributes defined in the network and the portgroup referenced + by the interface. The newly-constructed virtualport is a combination + of them. The attributes from lower virtualport can't make change + to the ones defined in higher virtualport. + Interface takes the highest priority, portgroup is lowest priority. (<span class="since">Since 0.10.0</span>). For example, in order to work properly with both an 802.1Qbh switch and an Open vSwitch switch, you may choose to specify no type, but both - an <code>instanceid</code> (in case the switch is 802.1Qbh) and + an <code>profileid</code> (in case the switch is 802.1Qbh) and an <code>interfaceid</code> (in case the switch is Open vSwitch) (you may also omit the other attributes, such as managerid, typeid, or profileid, to be filled in from the diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 79af087..70c1ee7 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -4994,7 +4994,7 @@ virDomainNetDefParseXML(virCapsPtr caps, def->type == VIR_DOMAIN_NET_TYPE_INTERNAL && xmlStrEqual(cur->name, BAD_CAST "source")) { internal = virXMLPropString(cur, "name"); - } else if (!network && + } else if (!bridge && def->type == VIR_DOMAIN_NET_TYPE_BRIDGE && xmlStrEqual(cur->name, BAD_CAST "source")) { bridge = virXMLPropString(cur, "bridge"); @@ -5028,7 +5028,7 @@ virDomainNetDefParseXML(virCapsPtr caps, " <interface type='%s'>"), type); goto error; } - } else if (!network && + } else if (!address && (def->type == VIR_DOMAIN_NET_TYPE_SERVER || def->type == VIR_DOMAIN_NET_TYPE_CLIENT || def->type == VIR_DOMAIN_NET_TYPE_MCAST) && -- 1.7.11.4

On 01/03/2013 12:13 AM, Guannan Ren wrote:
--- docs/formatdomain.html.in | 9 ++++++--- src/conf/domain_conf.c | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 94df6f8..45d7593 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -2546,12 +2546,15 @@ virtualport types (and also to leave out certain attributes); at domain startup time, a complete <code><virtualport></code> element will be constructed by merging together the type and - attributes found in the which will be filled in from the network - or portgroup <code><virtualport></code>) + attributes defined in the network and the portgroup referenced + by the interface. The newly-constructed virtualport is a combination + of them. The attributes from lower virtualport can't make change
s/make change to/change/
+++ b/src/conf/domain_conf.c @@ -4994,7 +4994,7 @@ virDomainNetDefParseXML(virCapsPtr caps, def->type == VIR_DOMAIN_NET_TYPE_INTERNAL && xmlStrEqual(cur->name, BAD_CAST "source")) { internal = virXMLPropString(cur, "name"); - } else if (!network && + } else if (!bridge && def->type == VIR_DOMAIN_NET_TYPE_BRIDGE && xmlStrEqual(cur->name, BAD_CAST "source")) { bridge = virXMLPropString(cur, "bridge"); @@ -5028,7 +5028,7 @@ virDomainNetDefParseXML(virCapsPtr caps, " <interface type='%s'>"), type); goto error; } - } else if (!network && + } else if (!address &&
Looks okay to me, but you might want to get Laine's ACK as well. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 01/08/2013 07:14 AM, Eric Blake wrote:
On 01/03/2013 12:13 AM, Guannan Ren wrote:
--- docs/formatdomain.html.in | 9 ++++++--- src/conf/domain_conf.c | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 94df6f8..45d7593 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -2546,12 +2546,15 @@ virtualport types (and also to leave out certain attributes); at domain startup time, a complete <code><virtualport></code> element will be constructed by merging together the type and - attributes found in the which will be filled in from the network - or portgroup <code><virtualport></code>) + attributes defined in the network and the portgroup referenced + by the interface. The newly-constructed virtualport is a combination + of them. The attributes from lower virtualport can't make change s/make change to/change/
Fixed.
+++ b/src/conf/domain_conf.c @@ -4994,7 +4994,7 @@ virDomainNetDefParseXML(virCapsPtr caps, def->type == VIR_DOMAIN_NET_TYPE_INTERNAL && xmlStrEqual(cur->name, BAD_CAST "source")) { internal = virXMLPropString(cur, "name"); - } else if (!network && + } else if (!bridge && def->type == VIR_DOMAIN_NET_TYPE_BRIDGE && xmlStrEqual(cur->name, BAD_CAST "source")) { bridge = virXMLPropString(cur, "bridge"); @@ -5028,7 +5028,7 @@ virDomainNetDefParseXML(virCapsPtr caps, " <interface type='%s'>"), type); goto error; } - } else if (!network && + } else if (!address && Looks okay to me, but you might want to get Laine's ACK as well.
Thanks for review. I am gonna push 1/3 and 2/3 and make a new patchset involved 3/3 in Guannan

QEMU_CAPS_DEVICE_USB_NET /* -device usb-net */ --- src/qemu/qemu_capabilities.c | 2 ++ src/qemu/qemu_capabilities.h | 1 + tests/qemuhelptest.c | 21 ++++++++++++++------- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 17e6679..1e1365c 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -199,6 +199,7 @@ VIR_ENUM_IMPL(qemuCaps, QEMU_CAPS_LAST, "cirrus-vga", "vmware-svga", "device-video-primary", + "usb-net", ); struct _qemuCaps { @@ -1343,6 +1344,7 @@ struct qemuCapsStringFlags qemuCapsObjectTypes[] = { { "VGA", QEMU_CAPS_DEVICE_VGA }, { "cirrus-vga", QEMU_CAPS_DEVICE_CIRRUS_VGA }, { "vmware-svga", QEMU_CAPS_DEVICE_VMWARE_SVGA }, + { "usb-net", QEMU_CAPS_DEVICE_USB_NET}, }; diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 3457852..f6d4f1d 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -162,6 +162,7 @@ enum qemuCapsFlags { QEMU_CAPS_DEVICE_VMWARE_SVGA = 122, /* -device vmware-svga */ QEMU_CAPS_DEVICE_VIDEO_PRIMARY = 123, /* safe to use -device XXX for primary video device */ + QEMU_CAPS_DEVICE_USB_NET = 124, /* -device usb-net */ QEMU_CAPS_LAST, /* this must always be the last item */ }; diff --git a/tests/qemuhelptest.c b/tests/qemuhelptest.c index 252ad3a..6941c90 100644 --- a/tests/qemuhelptest.c +++ b/tests/qemuhelptest.c @@ -395,7 +395,8 @@ mymain(void) QEMU_CAPS_DEVICE_QXL, QEMU_CAPS_DEVICE_VGA, QEMU_CAPS_DEVICE_CIRRUS_VGA, - QEMU_CAPS_DEVICE_VMWARE_SVGA); + QEMU_CAPS_DEVICE_VMWARE_SVGA, + QEMU_CAPS_DEVICE_USB_NET); DO_TEST("qemu-kvm-0.12.3", 12003, 1, 0, QEMU_CAPS_VNC_COLON, QEMU_CAPS_NO_REBOOT, @@ -502,7 +503,8 @@ mymain(void) QEMU_CAPS_DEVICE_QXL, QEMU_CAPS_DEVICE_VGA, QEMU_CAPS_DEVICE_CIRRUS_VGA, - QEMU_CAPS_DEVICE_VMWARE_SVGA); + QEMU_CAPS_DEVICE_VMWARE_SVGA, + QEMU_CAPS_DEVICE_USB_NET); DO_TEST("qemu-kvm-0.12.1.2-rhel61", 12001, 1, 0, QEMU_CAPS_VNC_COLON, QEMU_CAPS_NO_REBOOT, @@ -565,7 +567,8 @@ mymain(void) QEMU_CAPS_DEVICE_QXL, QEMU_CAPS_DEVICE_VGA, QEMU_CAPS_DEVICE_CIRRUS_VGA, - QEMU_CAPS_DEVICE_VMWARE_SVGA); + QEMU_CAPS_DEVICE_VMWARE_SVGA, + QEMU_CAPS_DEVICE_USB_NET); DO_TEST("qemu-kvm-0.12.1.2-rhel62-beta", 12001, 1, 0, QEMU_CAPS_VNC_COLON, QEMU_CAPS_NO_REBOOT, @@ -715,7 +718,8 @@ mymain(void) QEMU_CAPS_DEVICE_QXL, QEMU_CAPS_DEVICE_VGA, QEMU_CAPS_DEVICE_CIRRUS_VGA, - QEMU_CAPS_DEVICE_VMWARE_SVGA); + QEMU_CAPS_DEVICE_VMWARE_SVGA, + QEMU_CAPS_DEVICE_USB_NET); DO_TEST("qemu-1.1.0", 1001000, 0, 0, QEMU_CAPS_VNC_COLON, QEMU_CAPS_NO_REBOOT, @@ -801,7 +805,8 @@ mymain(void) QEMU_CAPS_DEVICE_QXL, QEMU_CAPS_DEVICE_VGA, QEMU_CAPS_DEVICE_CIRRUS_VGA, - QEMU_CAPS_DEVICE_VMWARE_SVGA); + QEMU_CAPS_DEVICE_VMWARE_SVGA, + QEMU_CAPS_DEVICE_USB_NET); DO_TEST("qemu-1.2.0", 1002000, 0, 0, QEMU_CAPS_VNC_COLON, QEMU_CAPS_NO_REBOOT, @@ -898,7 +903,8 @@ mymain(void) QEMU_CAPS_DEVICE_VGA, QEMU_CAPS_DEVICE_CIRRUS_VGA, QEMU_CAPS_DEVICE_VMWARE_SVGA, - QEMU_CAPS_DEVICE_VIDEO_PRIMARY); + QEMU_CAPS_DEVICE_VIDEO_PRIMARY, + QEMU_CAPS_DEVICE_USB_NET); DO_TEST("qemu-kvm-1.2.0", 1002000, 1, 0, QEMU_CAPS_VNC_COLON, QEMU_CAPS_NO_REBOOT, @@ -1000,7 +1006,8 @@ mymain(void) QEMU_CAPS_DEVICE_VGA, QEMU_CAPS_DEVICE_CIRRUS_VGA, QEMU_CAPS_DEVICE_VMWARE_SVGA, - QEMU_CAPS_DEVICE_VIDEO_PRIMARY); + QEMU_CAPS_DEVICE_VIDEO_PRIMARY, + QEMU_CAPS_DEVICE_USB_NET); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } -- 1.7.11.4

On 01/03/2013 12:13 AM, Guannan Ren wrote:
QEMU_CAPS_DEVICE_USB_NET /* -device usb-net */ --- src/qemu/qemu_capabilities.c | 2 ++ src/qemu/qemu_capabilities.h | 1 + tests/qemuhelptest.c | 21 ++++++++++++++------- 3 files changed, 17 insertions(+), 7 deletions(-)
+++ b/src/qemu/qemu_capabilities.h @@ -162,6 +162,7 @@ enum qemuCapsFlags { QEMU_CAPS_DEVICE_VMWARE_SVGA = 122, /* -device vmware-svga */ QEMU_CAPS_DEVICE_VIDEO_PRIMARY = 123, /* safe to use -device XXX for primary video device */ + QEMU_CAPS_DEVICE_USB_NET = 124, /* -device usb-net */
Looks like you may be proposing conflicting caps here (you had another series that put QEMU_CAPS_DEVICE_USB_SERIAL for -device usb-serial at 124); the conflict resolution is pretty straightforward, though. ACK. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

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

On 01/03/2013 12:13 AM, Guannan Ren wrote:
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(-)
ACK. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 01/03/2013 02:13 AM, Guannan Ren wrote:
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
ne2k_isa i82551 i82557b i82559er ne2k_pci pcnet rtl8139 e1000 virtio XXXX. (All of these models are PCI devices, except "XXXX" which emulates a $manufacturers-name XXXX usb ethernet device. (A bit off topice, but it's actually kind of starting to bother me that we just blindly pass-through all the other netdev models rather than validating them...)
+ <span class="since">Since 1.0.2
) [so that it's obvious the "since 1.0.2" applies only to the usb device]
(QEMU and KVM only)</span> </p>
<h5><a name="elementsDriverBackendOptions">Setting NIC driver-specific options</a></h5>
You haven't mentioned anything about the (new) possibility of an <interface> having <address type='usb' .../> (of course there is no specific place where it's mentioned that it can have an <address type='pci' .../> either, so I'm not sure where is the best place to put that).
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"));
This is technically correct, but the existing check of detail consistency for virtio devices is done down below, after def->model is already set, rather than combining it into this basic sanity check. That would allow more sanity checks related to this type of device to be added later, without obscuring the character set sanity checking that's being done here.
+ 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"))) {
Hmm. It would be nicer to be able to just check for info.type == PCI, but of course on the initial run that isn't set yet. I guess at some place this type of device (whatever we end up calling it) needs to be determined to be a USB device and we need to assign it an address. How is this done for hostdevs? (I haven't looked, I've only done things with PCI hostdevs)
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; }

On Tue, Jan 08, 2013 at 04:02:02PM -0500, Laine Stump wrote:
On 01/03/2013 02:13 AM, Guannan Ren wrote:
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
ne2k_isa i82551 i82557b i82559er ne2k_pci pcnet rtl8139 e1000 virtio XXXX. (All of these models are PCI devices, except "XXXX" which emulates a $manufacturers-name XXXX usb ethernet device.
(A bit off topice, but it's actually kind of starting to bother me that we just blindly pass-through all the other netdev models rather than validating them...)
Yes, it is overdue to turn that into an enum as we do for other hardware models Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On 01/03/2013 02:13 AM, Guannan Ren wrote:
The set of patches fixed some typo in network docs and codes and is trying to support usb-net qemu virtual device.
The following is an example for use.
Libvirt XML sample: <devices> <interface type='user'> <mac address='52:54:00:32:6a:91'/> <model type='usb-net'/>
Do we really want the model type to be "usb-net"? the "-net" part is already implicit in the type of device, and there is no requirement that it needs to exactly match the qemu commandline parameter (although I suppose that's normally the case). As a matter of fact, <type model='virtio'/> ends up being equivalent to "-device virtio-net-pci".
<alias name='net1'/> <address type='usb' bus='0' port='1'/>
Hmm. As a matter of fact, we know from the address type that it's USB. Maybe the "model type" should, if anything, reflect whatever model of usb hardware is being emulated by qemu (similar to "e1000" or "rtl8139" or whatever). If the guest-side address is type='usb' and no model type is given, we could default to "usb-net" (just like we default to "rtl8139" when it's a PCI address with no model provided). This is just a suggestion though. I'd like to hear some other opinions.

On Tue, Jan 08, 2013 at 03:03:23PM -0500, Laine Stump wrote:
On 01/03/2013 02:13 AM, Guannan Ren wrote:
The set of patches fixed some typo in network docs and codes and is trying to support usb-net qemu virtual device.
The following is an example for use.
Libvirt XML sample: <devices> <interface type='user'> <mac address='52:54:00:32:6a:91'/> <model type='usb-net'/>
Do we really want the model type to be "usb-net"? the "-net" part is already implicit in the type of device, and there is no requirement that it needs to exactly match the qemu commandline parameter (although I suppose that's normally the case). As a matter of fact, <type model='virtio'/> ends up being equivalent to "-device virtio-net-pci".
Indeed, we should really base the name on the actual hardware since there can be many many different USB NICs implemented. Finding a model name in the usb.ids file is a good place to start Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On 01/09/2013 04:09 AM, Daniel P. Berrange wrote:
On Tue, Jan 08, 2013 at 03:03:23PM -0500, Laine Stump wrote:
On 01/03/2013 02:13 AM, Guannan Ren wrote:
The set of patches fixed some typo in network docs and codes and is trying to support usb-net qemu virtual device.
The following is an example for use.
Libvirt XML sample: <devices> <interface type='user'> <mac address='52:54:00:32:6a:91'/> <model type='usb-net'/> Do we really want the model type to be "usb-net"? the "-net" part is already implicit in the type of device, and there is no requirement that it needs to exactly match the qemu commandline parameter (although I suppose that's normally the case). As a matter of fact, <type model='virtio'/> ends up being equivalent to "-device virtio-net-pci". Indeed, we should really base the name on the actual hardware since there can be many many different USB NICs implemented.
Finding a model name in the usb.ids file is a good place to start
Daniel
Okay, I am going to make a v2. Thanks for the review
participants (4)
-
Daniel P. Berrange
-
Eric Blake
-
Guannan Ren
-
Laine Stump