提交 159cb2b9 编写于 作者: D Daniel P. Berrange

Added support for network interface model setting

上级 303277a8
Tue Apr 29 08:13:28 EST 2008 Daniel P. Berrange <berrange@redhat.com>
* src/qemu_conf.c, src/qemu_conf.h, src/xend_internal.c,
src/xm_internal.c, src/xml.c: Added support for network
interface model type setting
* tests/qemuxml2argvtest.c, tests/qemuxml2xmltest.c,
tests/sexpr2xmltest.c, tests/xmconfigtest.c,
tests/xml2sexprtest.c: Added test cases for NIC model type
* tests/qemuxml2argvdata/qemuxml2argv-net-virtio.{xml,args},
tests/sexpr2xmldata/sexpr2xml-net-e1000.{sexpr,xml},
tests/xml2sexprdata/xml2sexpr-net-e1000.{sexpr,xml},
tests/xmconfigdata/test-paravirt-net-e1000.{cfg,xml}: Added
new data files for test cases
Tue Apr 29 21:43:28 CEST 2008 Jim Meyering <meyering@redhat.com>
Fix build errors.
......
......@@ -714,6 +714,7 @@ static int qemudParseInterfaceXML(virConnectPtr conn,
xmlChar *script = NULL;
xmlChar *address = NULL;
xmlChar *port = NULL;
xmlChar *model = NULL;
net->type = QEMUD_NET_USER;
......@@ -775,6 +776,8 @@ static int qemudParseInterfaceXML(virConnectPtr conn,
(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;
......@@ -934,6 +937,39 @@ static int qemudParseInterfaceXML(virConnectPtr conn,
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, (const char*) model, len);
net->model[len] = '\0';
xmlFree (model);
model = NULL;
} else
net->model[0] = '\0';
return 0;
error:
......@@ -943,6 +979,7 @@ static int qemudParseInterfaceXML(virConnectPtr conn,
xmlFree(ifname);
xmlFree(script);
xmlFree(bridge);
xmlFree(model);
return -1;
}
......@@ -2271,11 +2308,13 @@ int qemudBuildCommandLine(virConnectPtr conn,
while (net) {
char nic[100];
if (snprintf(nic, sizeof(nic), "nic,macaddr=%02x:%02x:%02x:%02x:%02x:%02x,vlan=%d",
if (snprintf(nic, sizeof(nic),
"nic,macaddr=%02x:%02x:%02x:%02x:%02x:%02x,vlan=%d%s%s",
net->mac[0], net->mac[1],
net->mac[2], net->mac[3],
net->mac[4], net->mac[5],
vlan) >= sizeof(nic))
vlan,
(net->model[0] ? ",model=" : ""), net->model) >= sizeof(nic))
goto error;
if (!((*argv)[++n] = strdup("-net")))
......@@ -3395,7 +3434,6 @@ static int qemudGenerateXMLChar(virBufferPtr buf,
virBufferVSprintf(buf, " <source mode='connect' service='%s'/>\n",
dev->srcData.udp.connectService);
}
break;
case QEMUD_CHR_SRC_TYPE_TCP:
......@@ -3609,6 +3647,11 @@ char *qemudGenerateXML(virConnectPtr conn,
net->dst.socket.port);
}
if (net->model && net->model[0] != '\0') {
virBufferVSprintf(&buf, " <model type='%s'/>\n",
net->model);
}
virBufferAddLit(&buf, " </interface>\n");
net = net->next;
......
......@@ -68,6 +68,7 @@ struct qemud_vm_disk_def {
};
#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
......@@ -97,6 +98,7 @@ enum qemud_vm_net_forward_type {
struct qemud_vm_net_def {
int type;
unsigned char mac[QEMUD_MAC_ADDRESS_LEN];
char model[QEMUD_MODEL_MAX_LEN];
union {
struct {
char ifname[BR_IFNAME_MAXLEN];
......
......@@ -1893,9 +1893,10 @@ xend_parse_sexp_desc(virConnectPtr conn, struct sexpr *root,
free(drvName);
free(drvType);
} else if (sexpr_lookup(node, "device/vif")) {
const char *tmp2;
const char *tmp2, *model;
tmp2 = sexpr_node(node, "device/vif/script");
tmp = sexpr_node(node, "device/vif/bridge");
model = sexpr_node(node, "device/vif/model");
if ((tmp2 && strstr(tmp2, "bridge")) || tmp) {
virBufferAddLit(&buf, " <interface type='bridge'>\n");
if (tmp != NULL)
......@@ -1924,6 +1925,10 @@ xend_parse_sexp_desc(virConnectPtr conn, struct sexpr *root,
virBufferVSprintf(&buf, " <script path='%s'/>\n",
tmp2);
if (model)
virBufferVSprintf(&buf, " <model type='%s'/>\n",
model);
virBufferAddLit(&buf, " </interface>\n");
vif_index++;
} else if (sexpr_lookup(node, "device/vfb")) {
......
......@@ -845,6 +845,7 @@ char *xenXMDomainFormatXML(virConnectPtr conn, virConfPtr conf) {
while (list) {
int type = -1;
char script[PATH_MAX];
char model[10];
char ip[16];
char mac[18];
char bridge[50];
......@@ -854,6 +855,7 @@ char *xenXMDomainFormatXML(virConnectPtr conn, virConfPtr conf) {
mac[0] = '\0';
script[0] = '\0';
ip[0] = '\0';
model[0] = '\0';
if ((list->type != VIR_CONF_STRING) || (list->str == NULL))
goto skipnic;
......@@ -886,6 +888,12 @@ char *xenXMDomainFormatXML(virConnectPtr conn, virConfPtr conf) {
len = PATH_MAX-1;
strncpy(script, data, len);
script[len] = '\0';
} else if (!strncmp(key, "model=", 6)) {
int len = nextkey ? (nextkey - data) : sizeof(model)-1;
if (len > (sizeof(model)-1))
len = sizeof(model)-1;
strncpy(model, data, len);
model[len] = '\0';
} else if (!strncmp(key, "ip=", 3)) {
int len = nextkey ? (nextkey - data) : 15;
if (len > 15)
......@@ -915,6 +923,8 @@ char *xenXMDomainFormatXML(virConnectPtr conn, virConfPtr conf) {
virBufferVSprintf(&buf, " <script path='%s'/>\n", script);
if (ip[0])
virBufferVSprintf(&buf, " <ip address='%s'/>\n", ip);
if (model[0])
virBufferVSprintf(&buf, " <model type='%s'/>\n", model);
virBufferAddLit(&buf, " </interface>\n");
skipnic:
......@@ -1772,6 +1782,7 @@ static char *xenXMParseXMLVif(virConnectPtr conn, xmlNodePtr node, int hvm) {
xmlChar *source = NULL;
xmlChar *mac = NULL;
xmlChar *script = NULL;
xmlChar *model = NULL;
xmlChar *ip = NULL;
int typ = 0;
char *buf = NULL;
......@@ -1803,6 +1814,9 @@ static char *xenXMParseXMLVif(virConnectPtr conn, xmlNodePtr node, int hvm) {
} else if ((mac == NULL) &&
(xmlStrEqual(cur->name, BAD_CAST "mac"))) {
mac = xmlGetProp(cur, BAD_CAST "address");
} else if ((model == NULL) &&
(xmlStrEqual(cur->name, BAD_CAST "model"))) {
model = xmlGetProp(cur, BAD_CAST "type");
} else if ((ip == NULL) &&
(xmlStrEqual(cur->name, BAD_CAST "ip"))) {
ip = xmlGetProp(cur, BAD_CAST "address");
......@@ -1838,6 +1852,8 @@ static char *xenXMParseXMLVif(virConnectPtr conn, xmlNodePtr node, int hvm) {
buflen += 11;
if (script)
buflen += 8 + strlen((const char*)script);
if (model)
buflen += 7 + strlen((const char*)model);
if (ip)
buflen += 4 + strlen((const char*)ip);
......@@ -1865,6 +1881,10 @@ static char *xenXMParseXMLVif(virConnectPtr conn, xmlNodePtr node, int hvm) {
strcat(buf, ",script=");
strcat(buf, (const char*)script);
}
if (model) {
strcat(buf, ",model=");
strcat(buf, (const char*)model);
}
if (ip) {
strcat(buf, ",ip=");
strcat(buf, (const char*)ip);
......@@ -1876,6 +1896,7 @@ static char *xenXMParseXMLVif(virConnectPtr conn, xmlNodePtr node, int hvm) {
xmlFree(source);
xmlFree(script);
xmlFree(ip);
xmlFree(model);
return buf;
}
......
......@@ -1373,6 +1373,7 @@ virDomainParseXMLIfDesc(virConnectPtr conn ATTRIBUTE_UNUSED,
xmlChar *source = NULL;
xmlChar *mac = NULL;
xmlChar *script = NULL;
xmlChar *model = NULL;
xmlChar *ip = NULL;
int typ = 0;
int ret = -1;
......@@ -1404,6 +1405,9 @@ virDomainParseXMLIfDesc(virConnectPtr conn ATTRIBUTE_UNUSED,
} else if ((script == NULL) &&
(xmlStrEqual(cur->name, BAD_CAST "script"))) {
script = xmlGetProp(cur, BAD_CAST "path");
} else if ((model == NULL) &&
(xmlStrEqual(cur->name, BAD_CAST "model"))) {
model = xmlGetProp(cur, BAD_CAST "type");
} else if ((ip == NULL) &&
(xmlStrEqual(cur->name, BAD_CAST "ip"))) {
/* XXX in future expect to need to have > 1 ip
......@@ -1449,6 +1453,8 @@ virDomainParseXMLIfDesc(virConnectPtr conn ATTRIBUTE_UNUSED,
}
if (script != NULL)
virBufferVSprintf(buf, "(script '%s')", script);
if (model != NULL)
virBufferVSprintf(buf, "(model '%s')", model);
if (ip != NULL)
virBufferVSprintf(buf, "(ip '%s')", ip);
/*
......@@ -1465,6 +1471,7 @@ virDomainParseXMLIfDesc(virConnectPtr conn ATTRIBUTE_UNUSED,
xmlFree(source);
xmlFree(script);
xmlFree(ip);
xmlFree(model);
return (ret);
}
......
/usr/bin/qemu -M pc -m 214 -smp 1 -nographic -monitor pty -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -net nic,macaddr=00:11:22:33:44:55,vlan=0,model=virtio -net user,vlan=0 -serial none -parallel none -usb
\ No newline at end of file
<domain type='qemu'>
<name>QEMUGuest1</name>
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
<memory>219200</memory>
<currentMemory>219200</currentMemory>
<vcpu>1</vcpu>
<os>
<type arch='i686' machine='pc'>hvm</type>
<boot dev='hd'/>
</os>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu</emulator>
<disk type='block' device='disk'>
<source dev='/dev/HostVG/QEMUGuest1'/>
<target dev='hda'/>
</disk>
<interface type='user'>
<mac address='00:11:22:33:44:55'/>
<model type='virtio'/>
</interface>
</devices>
</domain>
......@@ -146,6 +146,7 @@ main(int argc, char **argv)
DO_TEST("misc-acpi");
DO_TEST("misc-no-reboot");
DO_TEST("net-user");
DO_TEST("net-virtio");
DO_TEST("serial-vc");
DO_TEST("serial-pty");
......
......@@ -109,6 +109,7 @@ main(int argc, char **argv)
DO_TEST("misc-acpi");
DO_TEST("misc-no-reboot");
DO_TEST("net-user");
DO_TEST("net-virtio");
DO_TEST("serial-vc");
DO_TEST("serial-pty");
......
(domain (domid 6)(name 'pvtest')(memory 420)(maxmem 420)(vcpus 2)(uuid '596a5d2171f48fb2e068e2386a5c413e')(on_poweroff 'destroy')(on_reboot 'destroy')(on_crash 'destroy')(image (linux (kernel '/var/lib/xen/vmlinuz.2Dn2YT')(ramdisk '/var/lib/xen/initrd.img.0u-Vhq')(args ' method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test/5.91/x86_64/os ')))(device (vbd (dev 'xvda')(uname 'file:/root/some.img')(mode 'w')))(device (vif (mac '00:11:22:33:44:55')(bridge 'xenbr2')(script 'vif-bridge')(model 'e1000'))))
<domain type='xen' id='6'>
<name>pvtest</name>
<uuid>596a5d21-71f4-8fb2-e068-e2386a5c413e</uuid>
<os>
<type>linux</type>
<kernel>/var/lib/xen/vmlinuz.2Dn2YT</kernel>
<initrd>/var/lib/xen/initrd.img.0u-Vhq</initrd>
<cmdline> method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test/5.91/x86_64/os </cmdline>
</os>
<memory>430080</memory>
<vcpu>2</vcpu>
<on_poweroff>destroy</on_poweroff>
<on_reboot>destroy</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/root/some.img'/>
<target dev='xvda'/>
</disk>
<interface type='bridge'>
<source bridge='xenbr2'/>
<target dev='vif6.0'/>
<mac address='00:11:22:33:44:55'/>
<script path='vif-bridge'/>
<model type='e1000'/>
</interface>
<console type='pty'>
<target port='0'/>
</console>
</devices>
</domain>
......@@ -116,6 +116,7 @@ main(int argc, char **argv)
DO_TEST("curmem", "curmem", 1);
DO_TEST("net-routed", "net-routed", 2);
DO_TEST("net-bridged", "net-bridged", 2);
DO_TEST("net-e1000", "net-e1000", 2);
DO_TEST("no-source-cdrom", "no-source-cdrom", 1);
DO_TEST("fv-utc", "fv-utc", 1);
......
......@@ -23,6 +23,7 @@
#include <fcntl.h>
#include <limits.h>
#include "testutils.h"
#include "internal.h"
#ifdef HAVE_PATHS_H
#include <paths.h>
......@@ -231,23 +232,27 @@ int virtTestDifference(FILE *stream,
const char *expectEnd = expect + (strlen(expect)-1);
const char *actualStart = actual;
const char *actualEnd = actual + (strlen(actual)-1);
const char *debug;
if (getenv("DEBUG_TESTS") == NULL)
if ((debug = getenv("DEBUG_TESTS")) == NULL)
return 0;
/* Skip to first character where they differ */
while (*expectStart && *actualStart &&
*actualStart == *expectStart) {
actualStart++;
expectStart++;
}
if (STREQ(debug, "") ||
STREQ(debug, "1")) {
/* Skip to first character where they differ */
while (*expectStart && *actualStart &&
*actualStart == *expectStart) {
actualStart++;
expectStart++;
}
/* Work backwards to last character where they differ */
while (actualEnd > actualStart &&
expectEnd > expectStart &&
*actualEnd == *expectEnd) {
actualEnd--;
expectEnd--;
/* Work backwards to last character where they differ */
while (actualEnd > actualStart &&
expectEnd > expectStart &&
*actualEnd == *expectEnd) {
actualEnd--;
expectEnd--;
}
}
/* Show the trimmed differences */
......
name = "XenGuest1"
uuid = "c7a5fdb0-cdaf-9455-926a-d65c16db1809"
maxmem = 579
memory = 394
vcpus = 1
bootloader = "/usr/bin/pygrub"
on_poweroff = "destroy"
on_reboot = "restart"
on_crash = "restart"
vfb = [ "type=vnc,vncunused=1,vnclisten=127.0.0.1,vncpasswd=123poi" ]
disk = [ "phy:/dev/HostVG/XenGuest1,xvda,w" ]
vif = [ "mac=00:16:3E:66:94:9C,model=e1000,ip=192.168.0.9" ]
<domain type='xen'>
<name>XenGuest1</name>
<uuid>c7a5fdb0-cdaf-9455-926a-d65c16db1809</uuid>
<bootloader>/usr/bin/pygrub</bootloader>
<currentMemory>403456</currentMemory>
<memory>592896</memory>
<vcpu>1</vcpu>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
<disk type='block' device='disk'>
<driver name='phy'/>
<source dev='/dev/HostVG/XenGuest1'/>
<target dev='xvda'/>
</disk>
<interface type='bridge'>
<mac address='00:16:3E:66:94:9C'/>
<ip address='192.168.0.9'/>
<model type='e1000'/>
</interface>
<input type='mouse' bus='xen'/>
<graphics type='vnc' port='-1' listen='127.0.0.1' passwd='123poi'/>
<console type='pty'>
<target port='0'/>
</console>
</devices>
</domain>
......@@ -202,6 +202,7 @@ main(int argc, char **argv)
DO_TEST("paravirt-old-pvfb", 2);
DO_TEST("paravirt-new-pvfb", 3);
DO_TEST("paravirt-net-e1000", 3);
DO_TEST("fullvirt-old-cdrom", 1);
DO_TEST("fullvirt-new-cdrom", 2);
DO_TEST("fullvirt-utc", 2);
......
(vm (name 'pvtest')(memory 420)(maxmem 420)(vcpus 2)(uuid '596a5d2171f48fb2e068e2386a5c413e')(on_poweroff 'destroy')(on_reboot 'destroy')(on_crash 'destroy')(image (linux (kernel '/var/lib/xen/vmlinuz.2Dn2YT')(ramdisk '/var/lib/xen/initrd.img.0u-Vhq')(args ' method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test/5.91/x86_64/os ')))(device (vbd (dev 'xvda')(uname 'file:/root/some.img')(mode 'w')))(device (vif (mac '00:11:22:33:44:55')(bridge 'xenbr2')(script 'vif-bridge')(model 'e1000'))))
\ No newline at end of file
<domain type='xen' id='15'>
<name>pvtest</name>
<uuid>596a5d2171f48fb2e068e2386a5c413e</uuid>
<os>
<type>linux</type>
<kernel>/var/lib/xen/vmlinuz.2Dn2YT</kernel>
<initrd>/var/lib/xen/initrd.img.0u-Vhq</initrd>
<cmdline> method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test/5.91/x86_64/os </cmdline>
</os>
<memory>430080</memory>
<vcpu>2</vcpu>
<on_poweroff>destroy</on_poweroff>
<on_reboot>destroy</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<disk type='file' device='disk'>
<source file='/root/some.img'/>
<target dev='xvda'/>
</disk>
<interface type="bridge">
<mac address="00:11:22:33:44:55"/>
<source bridge="xenbr2"/>
<script path="vif-bridge"/>
<model type='e1000'/>
<target dev="vif4.0"/>
</interface>
<console tty='/dev/pts/4'/>
</devices>
</domain>
......@@ -123,6 +123,7 @@ main(int argc, char **argv)
DO_TEST("curmem", "curmem", "rhel5", 2);
DO_TEST("net-routed", "net-routed", "pvtest", 2);
DO_TEST("net-bridged", "net-bridged", "pvtest", 2);
DO_TEST("net-e1000", "net-e1000", "pvtest", 2);
DO_TEST("no-source-cdrom", "no-source-cdrom", "test", 2);
DO_TEST("fv-utc", "fv-utc", "fvtest", 1);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册