Re: [Libvir] [PATCH] Allow selection of the NIC model in QEMU/KVM
On Tue, Apr 08, 2008 at 02:57:15PM +0100, Daniel P. Berrange wrote: This patch seems incomplete - there's no code to include the model tag when dumping the XML. FWIW, The patch I applied in Ubuntu to do this, looks like this. It obviously still lack the test case updates and such, though. Index: docs/libvir.html === --- docs/libvir.html.orig 2008-04-11 12:55:19.672613742 -0500 +++ docs/libvir.html2008-04-11 12:55:57.223628370 -0500 @@ -1041,6 +1041,14 @@ lt;mac address=11:22:33:44:55:66/gt; lt;/interfacegt; /pre +pre +lt;interface type='user'gt; + lt;mac address=11:22:33:44:55:66/gt; + lt;model type=ne2k_pci/gt; +lt;/interfacegt; +/pre +p(where the network card model is one of those supported by + QEMU or KVM - see the relevant manual pages)./p /li liVirtual network pProvides a virtual network using a bridge device in the host. Index: src/qemu_conf.c === --- src/qemu_conf.c.orig2008-04-11 12:55:19.692607157 -0500 +++ src/qemu_conf.c 2008-04-11 12:56:13.688628360 -0500 @@ -605,6 +605,7 @@ xmlChar *script = NULL; xmlChar *address = NULL; xmlChar *port = NULL; +xmlChar *model = NULL; net-type = QEMUD_NET_USER; @@ -666,6 +667,8 @@ (net-type == QEMUD_NET_ETHERNET) xmlStrEqual(cur-name, BAD_CAST script)) { script = xmlGetProp(cur, BAD_CAST path); +} else if (xmlStrEqual (cur-name, BAD_CAST model)) { +model = xmlGetProp (cur, BAD_CAST type); } } cur = cur-next; @@ -823,6 +826,38 @@ xmlFree(address); } +/* NIC model (see -net nic,model=?). We only check that it looks + * reasonable, not that it is a supported NIC type. FWIW kvm + * supports these types as of April 2008: + * i82551 i82557b i82559er ne2k_pci pcnet rtl8139 e1000 virtio + */ +if (model != NULL) { +int i, len, char_ok; + +len = xmlStrlen (model); +if (len = QEMUD_MODEL_MAX_LEN) { +qemudReportError (conn, NULL, NULL, VIR_ERR_INVALID_ARG, + _(Model name '%s' is too long), model); +goto error; +} +for (i = 0; i len; ++i) { +char_ok = +(model[i] = '0' model[i] = '9') || +(model[i] = 'a' model[i] = 'z') || +(model[i] = 'A' model[i] = 'Z') || model[i] == '_'; +if (!char_ok) { +qemudReportError (conn, NULL, NULL, VIR_ERR_INVALID_ARG, + _(Model name contains invalid characters)); +goto error; +} +} +strncpy (net-model, BAD_CAST model, len); +net-model[len] = '\0'; + +xmlFree (model); +} else +net-model[0] = '\0'; + return 0; error: @@ -838,6 +873,8 @@ xmlFree(script); if (bridge) xmlFree(bridge); +if (model) +xmlFree(model); return -1; } @@ -1678,13 +1715,22 @@ } else { int vlan = 0; while (net) { +char model[100]; char nic[100]; -if (snprintf(nic, sizeof(nic), nic,macaddr=%02x:%02x:%02x:%02x:%02x:%02x,vlan=%d, +if (net-model[0] != '\0') { +if (snprintf (model, sizeof (model), ,model=%s, net-model) += sizeof (model)) +goto error; +} else +model[0] = '\0'; + +if (snprintf(nic, sizeof(nic), + nic,macaddr=%02x:%02x:%02x:%02x:%02x:%02x,vlan=%d%s, net-mac[0], net-mac[1], net-mac[2], net-mac[3], net-mac[4], net-mac[5], - vlan) = sizeof(nic)) + vlan, model) = sizeof(nic)) goto error; if (!((*argv)[++n] = strdup(-net))) @@ -2881,6 +2927,11 @@ goto no_memory; } } +if (net-model net-model[0] != '\0') { +if (virBufferVSprintf(buf, model type='%s'/\n, + net-model) 0) +goto no_memory; +} if (virBufferVSprintf(buf, /interface\n) 0) goto no_memory; Index: src/qemu_conf.h === --- src/qemu_conf.h.orig2008-04-11 12:55:19.716629596 -0500 +++ src/qemu_conf.h 2008-04-11 12:55:57.351638875 -0500 @@ -67,6 +67,7 @@ }; #define QEMUD_MAC_ADDRESS_LEN 6 +#define QEMUD_MODEL_MAX_LEN 10 #define QEMUD_OS_TYPE_MAX_LEN 10 #define QEMUD_OS_ARCH_MAX_LEN 10 #define QEMUD_OS_MACHINE_MAX_LEN 10 @@ -90,6 +91,7 @@ struct qemud_vm_net_def { int type;
Re: [Libvir] [PATCH] Allow selection of the NIC model in QEMU/KVM
On Tue, Apr 08, 2008 at 02:17:56PM +0100, Richard W.M. Jones wrote: This patch allows selection of the NIC model for QEMU/KVM domains. The selection is done by adding a model/ element to the XML, as in this example: interface type='user' mac address='00:16:3e:33:b8:d3'/ model type='ne2k_pci'/ /interface The model type string is only checked to make sure it's a short alpha-numeric + underscore, since it seems impractical to extract the actual list of supported models. If you choose a supported model then QEMU starts up with this extra -nic parameter: /usr/bin/qemu-kvm -M pc -m 500 -smp 1 -monitor pty \ -boot c -hda /var/lib/xen/images/rhel51x32kvm.img \ -net nic,macaddr=00:16:3e:33:b8:d3,vlan=0,model=ne2k_pci -net user,vlan=0 \ -usb -vnc 127.0.0.1:0 If you choose a non-existant model then you get the error: libvir: QEMU error : internal error QEMU quit during monitor startup The patch looks fine by me, +1 Daniel -- Red Hat Virtualization group http://redhat.com/virtualization/ Daniel Veillard | virtualization library http://libvirt.org/ [EMAIL PROTECTED] | libxml GNOME XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/ -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [Libvir] [PATCH] Allow selection of the NIC model in QEMU/KVM
On Tue, Apr 08, 2008 at 02:17:56PM +0100, Richard W.M. Jones wrote: This patch allows selection of the NIC model for QEMU/KVM domains. The selection is done by adding a model/ element to the XML, as in this example: interface type='user' mac address='00:16:3e:33:b8:d3'/ model type='ne2k_pci'/ /interface The model type string is only checked to make sure it's a short alpha-numeric + underscore, since it seems impractical to extract the actual list of supported models. If you choose a supported model then QEMU starts up with this extra -nic parameter: /usr/bin/qemu-kvm -M pc -m 500 -smp 1 -monitor pty \ -boot c -hda /var/lib/xen/images/rhel51x32kvm.img \ -net nic,macaddr=00:16:3e:33:b8:d3,vlan=0,model=ne2k_pci -net user,vlan=0 \ -usb -vnc 127.0.0.1:0 If you choose a non-existant model then you get the error: libvir: QEMU error : internal error QEMU quit during monitor startup This patch seems incomplete - there's no code to include the model tag when dumping the XML. We should also implement the same for Xen driver really, since that has the choice of ne2k/rtl8139/e1000 too Regards, Dan. -- |: Red Hat, Engineering, Boston -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :| -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [Libvir] [PATCH] Allow selection of the NIC model in QEMU/KVM
What about when the model name doesn't include an underscore? like e1000 H Richard W.M. Jones wrote: This patch allows selection of the NIC model for QEMU/KVM domains. The selection is done by adding a model/ element to the XML, as in this example: interface type='user' mac address='00:16:3e:33:b8:d3'/ model type='ne2k_pci'/ /interface The model type string is only checked to make sure it's a short alpha-numeric + underscore, since it seems impractical to extract the actual list of supported models. If you choose a supported model then QEMU starts up with this extra -nic parameter: /usr/bin/qemu-kvm -M pc -m 500 -smp 1 -monitor pty \ -boot c -hda /var/lib/xen/images/rhel51x32kvm.img \ -net nic,macaddr=00:16:3e:33:b8:d3,vlan=0,model=ne2k_pci -net user,vlan=0 \ -usb -vnc 127.0.0.1:0 If you choose a non-existant model then you get the error: libvir: QEMU error : internal error QEMU quit during monitor startup Rich. -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [Libvir] [PATCH] Allow selection of the NIC model in QEMU/KVM
I'm sorry , didn't read the patch properly first! Richard W.M. Jones wrote: This patch allows selection of the NIC model for QEMU/KVM domains. The selection is done by adding a model/ element to the XML, as in this example: interface type='user' mac address='00:16:3e:33:b8:d3'/ model type='ne2k_pci'/ /interface The model type string is only checked to make sure it's a short alpha-numeric + underscore, since it seems impractical to extract the actual list of supported models. If you choose a supported model then QEMU starts up with this extra -nic parameter: /usr/bin/qemu-kvm -M pc -m 500 -smp 1 -monitor pty \ -boot c -hda /var/lib/xen/images/rhel51x32kvm.img \ -net nic,macaddr=00:16:3e:33:b8:d3,vlan=0,model=ne2k_pci -net user,vlan=0 \ -usb -vnc 127.0.0.1:0 If you choose a non-existant model then you get the error: libvir: QEMU error : internal error QEMU quit during monitor startup Rich. -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [Libvir] [PATCH] Allow selection of the NIC model in QEMU/KVM
On Tue, Apr 08, 2008 at 02:57:15PM +0100, Daniel P. Berrange wrote: This patch seems incomplete - there's no code to include the model tag when dumping the XML. Yeah, agreed - forgot about that :-( We should also implement the same for Xen driver really, since that has the choice of ne2k/rtl8139/e1000 too I'll have a look. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://et.redhat.com/~rjones/virt-top -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [Libvir] [PATCH] Allow selection of the NIC model in QEMU/KVM
Quoting Richard W.M. Jones [EMAIL PROTECTED]: This patch allows selection of the NIC model for QEMU/KVM domains. The selection is done by adding a model/ element to the XML, as in this example: interface type='user' mac address='00:16:3e:33:b8:d3'/ model type='ne2k_pci'/ /interface The model type string is only checked to make sure it's a short alpha-numeric + underscore, since it seems impractical to extract the actual list of supported models. I've found how to get the list of supported models: [EMAIL PROTECTED]:~$ kvm -net nic,model=? -hda '' Warning: vlan 0 is not connected to host network qemu: Supported ISA NICs: ne2k_isa qemu: Supported PCI NICs: i82551 i82557b i82559er ne2k_pci pcnet rtl8139 e1000 virtio If you choose a supported model then QEMU starts up with this extra -nic parameter: /usr/bin/qemu-kvm -M pc -m 500 -smp 1 -monitor pty \ -boot c -hda /var/lib/xen/images/rhel51x32kvm.img \ -net nic,macaddr=00:16:3e:33:b8:d3,vlan=0,model=ne2k_pci -net user,vlan=0 \ -usb -vnc 127.0.0.1:0 If you choose a non-existant model then you get the error: libvir: QEMU error : internal error QEMU quit during monitor startup -- Pau Garcia i Quiles http://www.elpauer.org (Due to my workload, I may need 10 days to answer) -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [Libvir] [PATCH] Allow selection of the NIC model in QEMU/KVM
On Tue, Apr 08, 2008 at 03:16:08PM +0100, Richard W.M. Jones wrote: On Tue, Apr 08, 2008 at 02:57:15PM +0100, Daniel P. Berrange wrote: This patch seems incomplete - there's no code to include the model tag when dumping the XML. Yeah, agreed - forgot about that :-( Oh, you may also find you need to tweak the test suite too, since that validates the args for QEMU and don't currently include the model= We should also implement the same for Xen driver really, since that has the choice of ne2k/rtl8139/e1000 too I'll have a look. No need to delay the commit of the KVM impl though of course. Dan. -- |: Red Hat, Engineering, Boston -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :| -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list