[Libvir] Re: [et-mgmt-tools] [RFE] virtual networks without DHCP
by Richard W.M. Jones
On Sun, Apr 27, 2008 at 02:57:54PM +0200, Geert Jansen wrote:
> I think it would be nice if it were possible to create a virtual network
> with virt-manager without DHCP and DNS services. This is useful when you
> want to use a host-only network for testing a setup that includes a DHCP
> server.
>
> I am not sure whether this is a limitation in virt-manager or in libvirt.
It's a libvirt thing. Replies redirected to libvir-list.
My understanding is that if the network doesn't contain a <ip...>
element in the network XML then no DHCP server will be created.
http://libvirt.org/formatnetwork.html
Rich.
--
Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones
virt-p2v converts physical machines to virtual machines. Boot with a
live CD or over the network (PXE) and turn machines into Xen guests.
http://et.redhat.com/~rjones/virt-p2v
16 years, 6 months
[Libvir] build problems on RHEL5, at least some are now fixed
by Jim Meyering
Daniel Berrange noticed some build problems on RHEL5.
Some were due to my not adding two .m4 files in yesterday's
gnulib update. [excuse time ;-) Normally (in other projects),
the gnulib-update process is automatic, since the imported files
are not version-controlled, but for libvirt I have to identify
new files pulled in by a gnulib update, and obviously didn't
complete that step.
Identifying and adding added files is not hard. Just have to remember
to do it before committing anything. Actually, the trick is (as usual)
to *automate* the process, so we don't have to depend on my memory.
This is now on my list.
Anyhow, I've committed the change.
16 years, 6 months
[Libvir] PATCH: Support network interface model in Xen and QEMU driver
by Daniel P. Berrange
This patch finishes off the work from Rich / Soren to support network
interface model in both Xen and QEMU drivers, and adds test cases for
the new syntax
src/qemu_conf.c | 57 ++++++++++++++++++--
src/qemu_conf.h | 2
src/xend_internal.c | 7 ++
src/xm_internal.c | 22 +++++++
src/xml.c | 8 ++
tests/qemuxml2argvdata/qemuxml2argv-net-virtio.args | 1
tests/qemuxml2argvdata/qemuxml2argv-net-virtio.xml | 26 +++++++++
tests/qemuxml2argvtest.c | 1
tests/qemuxml2xmltest.c | 1
tests/sexpr2xmldata/sexpr2xml-net-e1000.sexpr | 2
tests/sexpr2xmldata/sexpr2xml-net-e1000.xml | 32 +++++++++++
tests/sexpr2xmltest.c | 1
tests/testutils.c | 31 ++++++----
tests/xmconfigdata/test-paravirt-net-e1000.cfg | 12 ++++
tests/xmconfigdata/test-paravirt-net-e1000.xml | 28 +++++++++
tests/xmconfigtest.c | 1
tests/xml2sexprdata/xml2sexpr-net-e1000.sexpr | 1
tests/xml2sexprdata/xml2sexpr-net-e1000.xml | 30 ++++++++++
tests/xml2sexprtest.c | 1
19 files changed, 247 insertions(+), 17 deletions(-)
Dan.
Index: src/qemu_conf.c
===================================================================
RCS file: /data/cvs/libvirt/src/qemu_conf.c,v
retrieving revision 1.50
diff -u -p -r1.50 qemu_conf.c
--- src/qemu_conf.c 28 Apr 2008 15:14:59 -0000 1.50
+++ src/qemu_conf.c 29 Apr 2008 17:15:31 -0000
@@ -718,6 +718,7 @@ static int qemudParseInterfaceXML(virCon
xmlChar *script = NULL;
xmlChar *address = NULL;
xmlChar *port = NULL;
+ xmlChar *model = NULL;
net->type = QEMUD_NET_USER;
@@ -779,6 +780,8 @@ static int qemudParseInterfaceXML(virCon
(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;
@@ -938,6 +941,39 @@ static int qemudParseInterfaceXML(virCon
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:
@@ -953,6 +989,8 @@ static int qemudParseInterfaceXML(virCon
xmlFree(script);
if (bridge)
xmlFree(bridge);
+ if (model)
+ xmlFree(model);
return -1;
}
@@ -2283,13 +2321,22 @@ int qemudBuildCommandLine(virConnectPtr
} 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")))
@@ -3411,7 +3458,6 @@ static int qemudGenerateXMLChar(virBuffe
virBufferVSprintf(buf, " <source mode='connect' service='%s'/>\n",
dev->srcData.udp.connectService);
}
-
break;
case QEMUD_CHR_SRC_TYPE_TCP:
@@ -3625,6 +3671,11 @@ char *qemudGenerateXML(virConnectPtr con
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;
Index: src/qemu_conf.h
===================================================================
RCS file: /data/cvs/libvirt/src/qemu_conf.h,v
retrieving revision 1.23
diff -u -p -r1.23 qemu_conf.h
--- src/qemu_conf.h 25 Apr 2008 20:46:13 -0000 1.23
+++ src/qemu_conf.h 29 Apr 2008 17:15:32 -0000
@@ -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];
Index: src/xend_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/xend_internal.c,v
retrieving revision 1.182
diff -u -p -r1.182 xend_internal.c
--- src/xend_internal.c 28 Apr 2008 15:14:59 -0000 1.182
+++ src/xend_internal.c 29 Apr 2008 17:15:34 -0000
@@ -1893,9 +1893,10 @@ xend_parse_sexp_desc(virConnectPtr conn,
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,
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")) {
Index: src/xm_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/xm_internal.c,v
retrieving revision 1.72
diff -u -p -r1.72 xm_internal.c
--- src/xm_internal.c 28 Apr 2008 15:14:59 -0000 1.72
+++ src/xm_internal.c 29 Apr 2008 17:15:37 -0000
@@ -845,6 +845,7 @@ char *xenXMDomainFormatXML(virConnectPtr
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
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
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
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:
@@ -1777,6 +1787,7 @@ static char *xenXMParseXMLVif(virConnect
xmlChar *source = NULL;
xmlChar *mac = NULL;
xmlChar *script = NULL;
+ xmlChar *model = NULL;
xmlChar *ip = NULL;
int typ = 0;
char *buf = NULL;
@@ -1808,6 +1819,9 @@ static char *xenXMParseXMLVif(virConnect
} 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");
@@ -1843,6 +1857,8 @@ static char *xenXMParseXMLVif(virConnect
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);
@@ -1870,6 +1886,10 @@ static char *xenXMParseXMLVif(virConnect
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);
@@ -1883,6 +1903,8 @@ static char *xenXMParseXMLVif(virConnect
xmlFree(source);
if (script != NULL)
xmlFree(script);
+ if (model != NULL)
+ xmlFree(model);
if (ip != NULL)
xmlFree(ip);
Index: src/xml.c
===================================================================
RCS file: /data/cvs/libvirt/src/xml.c,v
retrieving revision 1.119
diff -u -p -r1.119 xml.c
--- src/xml.c 28 Apr 2008 15:14:59 -0000 1.119
+++ src/xml.c 29 Apr 2008 17:15:38 -0000
@@ -1378,6 +1378,7 @@ virDomainParseXMLIfDesc(virConnectPtr co
xmlChar *source = NULL;
xmlChar *mac = NULL;
xmlChar *script = NULL;
+ xmlChar *model = NULL;
xmlChar *ip = NULL;
int typ = 0;
int ret = -1;
@@ -1409,6 +1410,9 @@ virDomainParseXMLIfDesc(virConnectPtr co
} 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
@@ -1454,6 +1458,8 @@ virDomainParseXMLIfDesc(virConnectPtr co
}
if (script != NULL)
virBufferVSprintf(buf, "(script '%s')", script);
+ if (model != NULL)
+ virBufferVSprintf(buf, "(model '%s')", model);
if (ip != NULL)
virBufferVSprintf(buf, "(ip '%s')", ip);
/*
@@ -1474,6 +1480,8 @@ virDomainParseXMLIfDesc(virConnectPtr co
xmlFree(script);
if (ip != NULL)
xmlFree(ip);
+ if (model != NULL)
+ xmlFree(model);
return (ret);
}
Index: tests/qemuxml2argvtest.c
===================================================================
RCS file: /data/cvs/libvirt/tests/qemuxml2argvtest.c,v
retrieving revision 1.15
diff -u -p -r1.15 qemuxml2argvtest.c
--- tests/qemuxml2argvtest.c 25 Apr 2008 20:46:13 -0000 1.15
+++ tests/qemuxml2argvtest.c 29 Apr 2008 17:15:38 -0000
@@ -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");
Index: tests/qemuxml2xmltest.c
===================================================================
RCS file: /data/cvs/libvirt/tests/qemuxml2xmltest.c,v
retrieving revision 1.13
diff -u -p -r1.13 qemuxml2xmltest.c
--- tests/qemuxml2xmltest.c 25 Apr 2008 20:46:13 -0000 1.13
+++ tests/qemuxml2xmltest.c 29 Apr 2008 17:15:38 -0000
@@ -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");
Index: tests/sexpr2xmltest.c
===================================================================
RCS file: /data/cvs/libvirt/tests/sexpr2xmltest.c,v
retrieving revision 1.26
diff -u -p -r1.26 sexpr2xmltest.c
--- tests/sexpr2xmltest.c 26 Apr 2008 14:22:02 -0000 1.26
+++ tests/sexpr2xmltest.c 29 Apr 2008 17:15:38 -0000
@@ -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);
Index: tests/testutils.c
===================================================================
RCS file: /data/cvs/libvirt/tests/testutils.c,v
retrieving revision 1.12
diff -u -p -r1.12 testutils.c
--- tests/testutils.c 18 Apr 2008 15:05:29 -0000 1.12
+++ tests/testutils.c 29 Apr 2008 17:15:38 -0000
@@ -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 */
Index: tests/xmconfigtest.c
===================================================================
RCS file: /data/cvs/libvirt/tests/xmconfigtest.c,v
retrieving revision 1.15
diff -u -p -r1.15 xmconfigtest.c
--- tests/xmconfigtest.c 26 Apr 2008 14:22:02 -0000 1.15
+++ tests/xmconfigtest.c 29 Apr 2008 17:15:39 -0000
@@ -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);
Index: tests/xml2sexprtest.c
===================================================================
RCS file: /data/cvs/libvirt/tests/xml2sexprtest.c,v
retrieving revision 1.25
diff -u -p -r1.25 xml2sexprtest.c
--- tests/xml2sexprtest.c 26 Apr 2008 14:22:02 -0000 1.25
+++ tests/xml2sexprtest.c 29 Apr 2008 17:15:39 -0000
@@ -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);
Index: tests/qemuxml2argvdata/qemuxml2argv-net-virtio.args
===================================================================
RCS file: tests/qemuxml2argvdata/qemuxml2argv-net-virtio.args
diff -N tests/qemuxml2argvdata/qemuxml2argv-net-virtio.args
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/qemuxml2argvdata/qemuxml2argv-net-virtio.args 29 Apr 2008 17:15:39 -0000
@@ -0,0 +1 @@
+/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
Index: tests/qemuxml2argvdata/qemuxml2argv-net-virtio.xml
===================================================================
RCS file: tests/qemuxml2argvdata/qemuxml2argv-net-virtio.xml
diff -N tests/qemuxml2argvdata/qemuxml2argv-net-virtio.xml
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/qemuxml2argvdata/qemuxml2argv-net-virtio.xml 29 Apr 2008 17:15:39 -0000
@@ -0,0 +1,26 @@
+<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>
Index: tests/sexpr2xmldata/sexpr2xml-net-e1000.sexpr
===================================================================
RCS file: tests/sexpr2xmldata/sexpr2xml-net-e1000.sexpr
diff -N tests/sexpr2xmldata/sexpr2xml-net-e1000.sexpr
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/sexpr2xmldata/sexpr2xml-net-e1000.sexpr 29 Apr 2008 17:15:39 -0000
@@ -0,0 +1,2 @@
+(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... ')))(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'))))
+
Index: tests/sexpr2xmldata/sexpr2xml-net-e1000.xml
===================================================================
RCS file: tests/sexpr2xmldata/sexpr2xml-net-e1000.xml
diff -N tests/sexpr2xmldata/sexpr2xml-net-e1000.xml
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/sexpr2xmldata/sexpr2xml-net-e1000.xml 29 Apr 2008 17:15:39 -0000
@@ -0,0 +1,32 @@
+<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... </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>
Index: tests/xmconfigdata/test-paravirt-net-e1000.cfg
===================================================================
RCS file: tests/xmconfigdata/test-paravirt-net-e1000.cfg
diff -N tests/xmconfigdata/test-paravirt-net-e1000.cfg
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/xmconfigdata/test-paravirt-net-e1000.cfg 29 Apr 2008 17:15:39 -0000
@@ -0,0 +1,12 @@
+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" ]
Index: tests/xmconfigdata/test-paravirt-net-e1000.xml
===================================================================
RCS file: tests/xmconfigdata/test-paravirt-net-e1000.xml
diff -N tests/xmconfigdata/test-paravirt-net-e1000.xml
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/xmconfigdata/test-paravirt-net-e1000.xml 29 Apr 2008 17:15:39 -0000
@@ -0,0 +1,28 @@
+<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>
Index: tests/xml2sexprdata/xml2sexpr-net-e1000.sexpr
===================================================================
RCS file: tests/xml2sexprdata/xml2sexpr-net-e1000.sexpr
diff -N tests/xml2sexprdata/xml2sexpr-net-e1000.sexpr
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/xml2sexprdata/xml2sexpr-net-e1000.sexpr 29 Apr 2008 17:15:39 -0000
@@ -0,0 +1 @@
+(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... ')))(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
Index: tests/xml2sexprdata/xml2sexpr-net-e1000.xml
===================================================================
RCS file: tests/xml2sexprdata/xml2sexpr-net-e1000.xml
diff -N tests/xml2sexprdata/xml2sexpr-net-e1000.xml
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/xml2sexprdata/xml2sexpr-net-e1000.xml 29 Apr 2008 17:15:39 -0000
@@ -0,0 +1,30 @@
+<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... </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>
+
--
|: 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 :|
16 years, 6 months
[Libvir] PATCH: Autogenerate table of contents for docs
by Daniel P. Berrange
Alot of the docs pages have manually written table of contents linking to
headings with the page. I figured this is a good candidate for being
auto-generated.
The basic idea is that given a document with a series of headings
<h2><a name="xxx">Foo</a></h2>
..
<h3><a name="xxx">Bar</a></h3>
..
<h3><a name="xxx">Wizz</a></h3>
..
<h2><a name="xxx">Oooh</a></h2>
..
<h3><a name="xxx">Ahhh</a></h3>
Then, generate a table of contents with a nested set of lists <ul>. THe
XSL below attempts todo this for heading levels h2 -> h6, and splices the
TOC into the page where it sees an <ul id='toc'></ul> element (typically
just after <h1>).
I'm kind of out of practice with XSL, so there's probably a nicer way
to write the 'toc' template below...
Dan.
Index: docs/page.xsl
===================================================================
RCS file: /data/cvs/libvirt/docs/page.xsl,v
retrieving revision 1.7
diff -u -r1.7 page.xsl
--- docs/page.xsl 28 Apr 2008 08:29:35 -0000 1.7
+++ docs/page.xsl 30 Apr 2008 12:55:20 -0000
@@ -59,6 +59,54 @@
</ul>
</xsl:template>
+ <xsl:template name="toc">
+ <ul>
+ <xsl:for-each select="/html/body/h2[count(a) = 1]">
+ <xsl:variable name="thishead" select="."/>
+ <li>
+ <a href="#{a/@name}"><xsl:value-of select="a/text()"/></a>
+ <xsl:if test="count(./following-sibling::h3[preceding-sibling::h2[1] = $thishead and count(a) = 1]) > 0">
+ <ul>
+ <xsl:for-each select="./following-sibling::h3[preceding-sibling::h2[1] = $thishead and count(a) = 1]">
+ <xsl:variable name="thissubhead" select="."/>
+ <li>
+ <a href="#{a/@name}"><xsl:value-of select="a/text()"/></a>
+ <xsl:if test="count(./following-sibling::h4[preceding-sibling::h3[1] = $thissubhead and count(a) = 1]) > 0">
+ <ul>
+ <xsl:for-each select="./following-sibling::h4[preceding-sibling::h3[1] = $thissubhead and count(a) = 1]">
+ <li>
+ <a href="#{a/@name}"><xsl:value-of select="a/text()"/></a>
+ <xsl:if test="count(./following-sibling::h5[preceding-sibling::h4[1] = $thissubhead and count(a) = 1]) > 0">
+ <ul>
+ <xsl:for-each select="./following-sibling::h5[preceding-sibling::h4[1] = $thissubhead and count(a) = 1]">
+ <li>
+ <a href="#{a/@name}"><xsl:value-of select="a/text()"/></a>
+ <xsl:if test="count(./following-sibling::h6[preceding-sibling::h5[1] = $thissubhead and count(a) = 1]) > 0">
+ <ul>
+ <xsl:for-each select="./following-sibling::h6[preceding-sibling::h5[1] = $thissubhead and count(a) = 1]">
+ <li>
+ <a href="#{a/@name}"><xsl:value-of select="a/text()"/></a>
+ </li>
+ </xsl:for-each>
+ </ul>
+ </xsl:if>
+ </li>
+ </xsl:for-each>
+ </ul>
+ </xsl:if>
+ </li>
+ </xsl:for-each>
+ </ul>
+ </xsl:if>
+ </li>
+ </xsl:for-each>
+ </ul>
+ </xsl:if>
+ </li>
+ </xsl:for-each>
+ </ul>
+ </xsl:template>
+
<!-- This is the master page structure -->
<xsl:template match="/" mode="page">
<xsl:param name="pagename"/>
@@ -93,7 +141,16 @@
</xsl:apply-templates>
</div>
<div id="content">
- <xsl:copy-of select="html/body/*"/>
+ <xsl:for-each select="html/body/*">
+ <xsl:choose>
+ <xsl:when test="name() = 'ul' and @id = 'toc'">
+ <xsl:call-template name="toc"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:copy-of select="."/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:for-each>
</div>
</div>
<div id="footer">
--
|: 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 :|
16 years, 6 months
[Daniel Veillard] Re: [Libvir] [PATCH] update from gnulib
by Jim Meyering
Forwarding, on request:
Date: Wed, 30 Apr 2008 04:53:43 -0400
From: Daniel Veillard <veillard(a)redhat.com>
To: Jim Meyering <meyering(a)redhat.com>
Cc: undisclosed-recipients: ;
Subject: Re: [Libvir] [PATCH] update from gnulib
Message-ID: <20080430085343.GF25119(a)redhat.com>
Reply-To: veillard(a)redhat.com
References: <20080430072336.4A4D18E0038(a)hormel.redhat.com>
In-Reply-To: <20080430072336.4A4D18E0038(a)hormel.redhat.com>
User-Agent: Mutt/1.5.13 (2006-09-08)
On Tue, Apr 29, 2008 at 05:57:36PM +0200, Jim Meyering wrote:
>
> Signed-off-by: Jim Meyering <meyering(a)redhat.com>
Hum, to me the gnulib update side is under your control, I don't
feel it's necessary for you to post the patch, unless you know there
may be an associated change for the other developpers. Others may disagree
but I don't think I can really review those :-)
Daniel
--
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard | virtualization library http://libvirt.org/
veillard(a)redhat.com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
16 years, 6 months
[Libvir] [PATCH] remove useless tests before xmlFree
by Jim Meyering
I've just fixed a bug in my useless-if-detecting script,
committed in gnulib. Using that new script with today's
change adding xmlFree to the list exposed a bunch of useless tests.
This first change set removes those tests.
Below it is a separate patch that updates gnulib-related
files, including that script and vc-list-files.
I verified that with these changes "make distcheck" passes.
If no one objects, I'll push these in about 12 hours.
remove useless tests before xmlFree
* src/qemu_conf.c (qemudParseDiskXML, qemudParseInterfaceXML):
(qemudParseInputXML, qemudParseDhcpRangesXML):
* src/remote_internal.c (doRemoteOpen):
* src/storage_conf.c (virStoragePoolDefParseDoc):
* src/xm_internal.c (xenXMParseXMLDisk, xenXMParseXMLVif):
(xenXMParseXMLToConfig, xenXMAttachInterface):
* src/xml.c (virDomainParseXMLDiskDesc, virDomainParseXMLIfDesc):
(virDomainXMLDevID):
Signed-off-by: Jim Meyering <meyering(a)redhat.com>
---
src/qemu_conf.c | 48 ++++++++++++++++--------------------------------
src/remote_internal.c | 8 ++++----
src/storage_conf.c | 3 +--
src/xm_internal.c | 42 ++++++++++++++----------------------------
src/xml.c | 30 ++++++++++--------------------
5 files changed, 45 insertions(+), 86 deletions(-)
diff --git a/src/qemu_conf.c b/src/qemu_conf.c
index 07dfe47..a0c4a8f 100644
--- a/src/qemu_conf.c
+++ b/src/qemu_conf.c
@@ -680,14 +680,10 @@ static int qemudParseDiskXML(virConnectPtr conn,
return 0;
error:
- if (type)
- xmlFree(type);
- if (target)
- xmlFree(target);
- if (source)
- xmlFree(source);
- if (device)
- xmlFree(device);
+ xmlFree(type);
+ xmlFree(target);
+ xmlFree(source);
+ xmlFree(device);
return -1;
}
@@ -941,18 +937,12 @@ static int qemudParseInterfaceXML(virConnectPtr conn,
return 0;
error:
- if (network)
- xmlFree(network);
- if (address)
- xmlFree(address);
- if (port)
- xmlFree(port);
- if (ifname)
- xmlFree(ifname);
- if (script)
- xmlFree(script);
- if (bridge)
- xmlFree(bridge);
+ xmlFree(network);
+ xmlFree(address);
+ xmlFree(port);
+ xmlFree(ifname);
+ xmlFree(script);
+ xmlFree(bridge);
return -1;
}
@@ -1334,18 +1324,14 @@ static int qemudParseInputXML(virConnectPtr conn,
input->bus = QEMU_INPUT_BUS_USB;
}
- if (type)
- xmlFree(type);
- if (bus)
- xmlFree(bus);
+ xmlFree(type);
+ xmlFree(bus);
return 0;
error:
- if (type)
- xmlFree(type);
- if (bus)
- xmlFree(bus);
+ xmlFree(type);
+ xmlFree(bus);
return -1;
}
@@ -2860,10 +2846,8 @@ static int qemudParseDhcpRangesXML(virConnectPtr conn,
free(range);
}
- if (start)
- xmlFree(start);
- if (end)
- xmlFree(end);
+ xmlFree(start);
+ xmlFree(end);
cur = cur->next;
}
diff --git a/src/remote_internal.c b/src/remote_internal.c
index ef34a3a..70aa5e9 100644
--- a/src/remote_internal.c
+++ b/src/remote_internal.c
@@ -434,9 +434,9 @@ doRemoteOpen (virConnectPtr conn,
}
#ifdef HAVE_XMLURI_QUERY_RAW
- if (uri->query_raw) xmlFree (uri->query_raw);
+ xmlFree (uri->query_raw);
#else
- if (uri->query) xmlFree (uri->query);
+ xmlFree (uri->query);
#endif
if ((
@@ -464,10 +464,10 @@ doRemoteOpen (virConnectPtr conn,
transport_str[-1] = '\0';
}
/* Remove the username, server name and port number. */
- if (uri->user) xmlFree (uri->user);
+ xmlFree (uri->user);
uri->user = 0;
- if (uri->server) xmlFree (uri->server);
+ xmlFree (uri->server);
uri->server = 0;
uri->port = 0;
diff --git a/src/storage_conf.c b/src/storage_conf.c
index 4499ae2..be21d3b 100644
--- a/src/storage_conf.c
+++ b/src/storage_conf.c
@@ -357,8 +357,7 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
cleanup:
free(uuid);
- if (type)
- xmlFree(type);
+ xmlFree(type);
virStoragePoolDefFree(ret);
return NULL;
}
diff --git a/src/xm_internal.c b/src/xm_internal.c
index a70436d..08e3e8e 100644
--- a/src/xm_internal.c
+++ b/src/xm_internal.c
@@ -1657,10 +1657,8 @@ static int xenXMParseXMLDisk(xmlNodePtr node, int hvm, int xendConfigVersion, ch
}
if (target == NULL) {
- if (source != NULL)
- xmlFree(source);
- if (device != NULL)
- xmlFree(device);
+ xmlFree(source);
+ xmlFree(device);
return (-1);
}
@@ -1687,10 +1685,8 @@ static int xenXMParseXMLDisk(xmlNodePtr node, int hvm, int xendConfigVersion, ch
}
if (source == NULL && !cdrom) {
- if (target != NULL)
- xmlFree(target);
- if (device != NULL)
- xmlFree(device);
+ xmlFree(target);
+ xmlFree(device);
return (-1);
}
@@ -1765,8 +1761,7 @@ static int xenXMParseXMLDisk(xmlNodePtr node, int hvm, int xendConfigVersion, ch
xmlFree(drvName);
xmlFree(device);
xmlFree(target);
- if(source)
- xmlFree(source);
+ xmlFree(source);
*disk = buf;
return (ret);
@@ -1877,14 +1872,10 @@ static char *xenXMParseXMLVif(virConnectPtr conn, xmlNodePtr node, int hvm) {
cleanup:
free(bridge);
- if (mac != NULL)
- xmlFree(mac);
- if (source != NULL)
- xmlFree(source);
- if (script != NULL)
- xmlFree(script);
- if (ip != NULL)
- xmlFree(ip);
+ xmlFree(mac);
+ xmlFree(source);
+ xmlFree(script);
+ xmlFree(ip);
return buf;
}
@@ -2164,8 +2155,7 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char *xml) {
strcat(val, ",vncdisplay=");
strcat(val, portstr);
}
- if (vncport)
- xmlFree(vncport);
+ xmlFree(vncport);
if (vnclisten) {
strcat(val, ",vnclisten=");
strcat(val, (const char*)vnclisten);
@@ -2310,8 +2300,7 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char *xml) {
error:
if (conf)
virConfFree(conf);
- if (prop != NULL)
- xmlFree(prop);
+ xmlFree(prop);
xmlXPathFreeObject(obj);
xmlXPathFreeContext(ctxt);
if (doc != NULL)
@@ -2960,12 +2949,9 @@ xenXMAttachInterface(virDomainPtr domain, xmlXPathContextPtr ctxt, int hvm,
goto cleanup;
node_cleanup:
- if (node_tmp)
- xmlFree(node_tmp);
- if (attr_node)
- xmlFree(attr_node);
- if (text_node)
- xmlFree(text_node);
+ xmlFree(node_tmp);
+ xmlFree(attr_node);
+ xmlFree(text_node);
cleanup:
free(type);
free(source);
diff --git a/src/xml.c b/src/xml.c
index e889cdd..25eba3d 100644
--- a/src/xml.c
+++ b/src/xml.c
@@ -1341,16 +1341,11 @@ virDomainParseXMLDiskDesc(virConnectPtr conn, xmlNodePtr node,
virBufferAddLit(buf, ")");
cleanup:
- if (drvType)
- xmlFree(drvType);
- if (drvName)
- xmlFree(drvName);
- if (device)
- xmlFree(device);
- if (target)
- xmlFree(target);
- if (source)
- xmlFree(source);
+ xmlFree(drvType);
+ xmlFree(drvName);
+ xmlFree(device);
+ xmlFree(target);
+ xmlFree(source);
return (ret);
}
@@ -1466,14 +1461,10 @@ virDomainParseXMLIfDesc(virConnectPtr conn ATTRIBUTE_UNUSED,
virBufferAddLit(buf, ")");
ret = 0;
error:
- if (mac != NULL)
- xmlFree(mac);
- if (source != NULL)
- xmlFree(source);
- if (script != NULL)
- xmlFree(script);
- if (ip != NULL)
- xmlFree(ip);
+ xmlFree(mac);
+ xmlFree(source);
+ xmlFree(script);
+ xmlFree(ip);
return (ret);
}
@@ -1953,8 +1944,7 @@ virDomainXMLDevID(virDomainPtr domain, const char *xmldesc, char *class,
cleanup:
if (xml != NULL)
xmlFreeDoc(xml);
- if (attr != NULL)
- xmlFree(attr);
+ xmlFree(attr);
return ret;
}
#endif /* WITH_XEN */
--
1.5.5.1.68.gbdcd8
16 years, 6 months
[Libvir] Basic VMWare support
by Marek 'marx' Grac
Hi,
I know that there is no support for VMWare ESX yet but I would like to
know if someone is working on it. I need just three basic operations:
status/power on/power off but I never saw the source code of libvirt :)
Do you think it is possible to write this support (using VMWare API) in
acceptable time? week? month?
Thanks, for any suggestions
m,
--
Marek Grac
Red Hat Czech s.r.o.
16 years, 6 months
[Libvir] Basic VMWare support
by Marek 'marx' Grac
Hi,
I know that there is no support for VMWare ESX yet but I would like to
know if someone is working on it. I need just three basic operations:
status/power on/power off but I never saw the source code of libvirt :)
Do you think it is possible to write this support (using VMWare API) in
acceptable time? week? month?
Thanks, for any suggestions
m,
--
Marek Grac
Red Hat Czech s.r.o.
16 years, 7 months
[Libvir] also check for useless test-before-xmlFree
by Jim Meyering
Some time ago, Daniel Veillard assured me that xmlFree(NULL) is
valid in regular use, and with upstream code since January it's
ok even in a debug mode that's not normally available because
it's ifdef'd out:
http://mail.gnome.org/archives/svn-commits-list/2008-January/msg02233.html
Since the potential NULL-deref in debug mode is now gone,
we can now use this to prevent any new useless tests:
also check for useless test-before-xmlFree
* Makefile.cfg (useless_free_options): Add --name=xmlFree.
diff --git a/Makefile.cfg b/Makefile.cfg
index e0d5528..cbf97c2 100644
--- a/Makefile.cfg
+++ b/Makefile.cfg
@@ -53,5 +53,6 @@ local-checks-to-skip = \
useless_free_options = \
--name=sexpr_free \
+ --name=xmlFree \
--name=xmlXPathFreeContext \
--name=xmlXPathFreeObject
--
1.5.5.1.68.gbdcd8
16 years, 7 months
[Libvir] PATCH: Avoid buffer out of bounds access in Xen capabilities
by Daniel P. Berrange
The Xen driver uses a regex to process the hypervisor capabilities data
"(xen|hvm)-[[:digit:]]+\\.[[:digit:]]+-(x86_32|x86_64|ia64|powerpc64)(p|be)?";
notice how the last match group, however, is optional due to the '?'. The
code processing matches does not check to see if the match is present or
not, and just indexes the string on match 3
if (strncmp (&token[subs[3].rm_so], "p", 1) == 0)
Unfortunately, subs[3].rm_so is -1 if the match was not present, so we're
doing an out of bounds array access here. This is fairly harmless, but it
is still good to fix it. So this patch adds a check for -1 before accessing
the match. I also replace the strncmp() calls with a call to the brand new
STRPREFIX() convenience macro
Dan.
Index: src/xen_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/xen_internal.c,v
retrieving revision 1.119
diff -u -r1.119 xen_internal.c
--- src/xen_internal.c 10 Apr 2008 16:54:54 -0000 1.119
+++ src/xen_internal.c 28 Apr 2008 22:07:12 -0000
@@ -2349,28 +2349,31 @@
if (regexec (&xen_cap_rec, token, sizeof subs / sizeof subs[0],
subs, 0) == 0) {
- int hvm = strncmp (&token[subs[1].rm_so], "hvm", 3) == 0;
+ int hvm = STRPREFIX(&token[subs[1].rm_so], "hvm");
const char *model;
int bits, pae = 0, nonpae = 0, ia64_be = 0;
- if (strncmp (&token[subs[2].rm_so], "x86_32", 6) == 0) {
+
+ if (STRPREFIX(&token[subs[2].rm_so], "x86_32")) {
model = "i686";
bits = 32;
- if (strncmp (&token[subs[3].rm_so], "p", 1) == 0)
+ if (subs[3].rm_so != -1 &&
+ STRPREFIX(&token[subs[3].rm_so], "p"))
pae = 1;
else
nonpae = 1;
}
- else if (strncmp (&token[subs[2].rm_so], "x86_64", 6) == 0) {
+ else if (STRPREFIX(&token[subs[2].rm_so], "x86_64")) {
model = "x86_64";
bits = 64;
}
- else if (strncmp (&token[subs[2].rm_so], "ia64", 4) == 0) {
+ else if (STRPREFIX(&token[subs[2].rm_so], "ia64")) {
model = "ia64";
bits = 64;
- if (strncmp (&token[subs[3].rm_so], "be", 2) == 0)
+ if (subs[3].rm_so != -1 &&
+ STRPREFIX(&token[subs[3].rm_so], "be"))
ia64_be = 1;
}
- else if (strncmp (&token[subs[2].rm_so], "powerpc64", 4) == 0) {
+ else if (STRPREFIX(&token[subs[2].rm_so], "powerpc64")) {
model = "ppc64";
bits = 64;
} else {
@@ -2380,7 +2383,7 @@
/* Search for existing matching (model,hvm) tuple */
for (i = 0 ; i < nr_guest_archs ; i++) {
- if (!strcmp(guest_archs[i].model, model) &&
+ if (STREQ(guest_archs[i].model, model) &&
guest_archs[i].hvm == hvm) {
break;
}
--
|: 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 :|
16 years, 7 months