Added support for XenD 3.0.3 style HVM cdrom config

This commit is contained in:
Daniel P. Berrange 2006-09-12 01:16:22 +00:00
parent 786e029cd7
commit 3708258fad
25 changed files with 295 additions and 101 deletions

View File

@ -19,3 +19,4 @@ ltmain.sh
update.log
libvirt.pc
libvirt.spec
COPYING

View File

@ -1,3 +1,13 @@
Tue Sep 11 20:11:05 EDT 2006 Daniel Berrange <berrange@redhat.com>
* src/xend_internal.c, src/xml.c: Added support for new 3.0.3
style XenD cdrom configuration for HVM guests.
* configure.in, tests/Makefile.am: Added new test directories
* tests/xml2sexprdata*, tests/sexpr2xmldata*: Removed config files
for test suite.
* tests/xml2sexprdata/*, tests/sexpr2xmldata/*: New home for test
suite config files
Tue Sep 5 13:50:05 MYT 2006 Daniel Veillard <veillard@redhat.com>
* NEWS configure.in docs//* include/libvirt/libvirt.h libvirt.specx.*:

View File

@ -257,4 +257,6 @@ AC_OUTPUT(Makefile src/Makefile include/Makefile docs/Makefile \
include/libvirt/Makefile include/libvirt/libvirt.h \
python/Makefile python/tests/Makefile \
tests/Makefile proxy/Makefile \
tests/xml2sexprdata/Makefile \
tests/sexpr2xmldata/Makefile \
tests/virshdata/Makefile tests/confdata/Makefile)

View File

@ -1258,6 +1258,36 @@ xend_get_node(virConnectPtr xend)
return node;
}
static int
xend_get_config_version(virConnectPtr conn) {
int ret = -1;
struct sexpr *root;
const char *value;
if (!VIR_IS_CONNECT(conn)) {
virXendError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
return (-1);
}
root = sexpr_get(conn, "/xend/node/");
if (root == NULL)
return (-1);
value = sexpr_node(root, "node/xend_config_format");
if (value) {
return strtol(value, NULL, 10);
} else {
/* Xen prior to 3.0.3 did not have the xend_config_format
field, and is implicitly version 1. */
return 1;
}
sexpr_free(root);
return (ret);
}
#ifndef PROXY
/**
* xend_node_shutdown:
@ -1431,7 +1461,7 @@ xend_parse_sexp_desc_os(struct sexpr *node, virBufferPtr buf, int hvm)
* the caller must free() the returned value.
*/
static char *
xend_parse_sexp_desc(virConnectPtr conn, struct sexpr *root)
xend_parse_sexp_desc(virConnectPtr conn, struct sexpr *root, int xendConfigVersion)
{
char *ret;
struct sexpr *cur, *node;
@ -1525,37 +1555,62 @@ xend_parse_sexp_desc(virConnectPtr conn, struct sexpr *root)
if (tmp == NULL)
continue;
if (!memcmp(tmp, "file:", 5)) {
tmp += 5;
virBufferVSprintf(&buf, " <disk type='file' device='disk'>\n");
virBufferVSprintf(&buf, " <source file='%s'/>\n",
tmp);
tmp = sexpr_node(node, "device/vbd/dev");
if (tmp == NULL) {
int cdrom = 0;
const char *src = tmp+5;
const char *dst = sexpr_node(node, "device/vbd/dev");
if (dst == NULL) {
virXendError(NULL, VIR_ERR_INTERNAL_ERROR,
"domain information incomplete, vbd has no dev");
goto error;
}
if (!strncmp(tmp, "ioemu:", 6))
tmp += 6;
virBufferVSprintf(&buf, " <target dev='%s'/>\n", tmp);
if (!strncmp(dst, "ioemu:", 6))
dst += 6;
/* New style cdrom config from Xen >= 3.0.3 */
if (xendConfigVersion > 1) {
char *offset = rindex(dst, ':');
if (offset && !strcmp(offset, ":cdrom")) {
offset[0] = '\0';
cdrom = 1;
}
}
virBufferVSprintf(&buf, " <disk type='file' device='%s'>\n", cdrom ? "cdrom" : "disk");
virBufferVSprintf(&buf, " <source file='%s'/>\n", src);
virBufferVSprintf(&buf, " <target dev='%s'/>\n", dst);
tmp = sexpr_node(node, "device/vbd/mode");
/* XXX should we force mode == r, if cdrom==1, or assume
xend has already done this ? */
if ((tmp != NULL) && (!strcmp(tmp, "r")))
virBufferVSprintf(&buf, " <readonly/>\n");
virBufferAdd(&buf, " </disk>\n", 12);
} else if (!memcmp(tmp, "phy:", 4)) {
tmp += 4;
virBufferVSprintf(&buf, " <disk type='block' device='disk'>\n");
virBufferVSprintf(&buf, " <source dev='%s'/>\n", tmp);
tmp = sexpr_node(node, "device/vbd/dev");
if (tmp == NULL) {
int cdrom = 0;
const char *src = tmp+4;
const char *dst = sexpr_node(node, "device/vbd/dev");
if (dst == NULL) {
virXendError(NULL, VIR_ERR_INTERNAL_ERROR,
"domain information incomplete, vbd has no dev");
goto error;
}
if (!strncmp(tmp, "ioemu:", 6))
tmp += 6;
virBufferVSprintf(&buf, " <target dev='%s'/>\n", tmp);
if (!strncmp(dst, "ioemu:", 6))
dst += 6;
/* New style cdrom config from Xen >= 3.0.3 */
if (xendConfigVersion > 1) {
char *offset = rindex(dst, ':');
if (offset && !strcmp(offset, ":cdrom")) {
offset[0] = '\0';
cdrom = 1;
}
}
virBufferVSprintf(&buf, " <disk type='block' device='%s'>\n", cdrom ? "cdrom" : "disk");
virBufferVSprintf(&buf, " <source dev='%s'/>\n", src);
virBufferVSprintf(&buf, " <target dev='%s'/>\n", dst);
tmp = sexpr_node(node, "device/vbd/mode");
/* XXX should we force mode == r, if cdrom==1, or assume
xend has already done this ? */
if ((tmp != NULL) && (!strcmp(tmp, "r")))
virBufferVSprintf(&buf, " <readonly/>\n");
virBufferAdd(&buf, " </disk>\n", 12);
@ -1617,14 +1672,17 @@ xend_parse_sexp_desc(virConnectPtr conn, struct sexpr *root)
virBufferAdd(&buf, " <target dev='fdb'/>\n", 26);
virBufferAdd(&buf, " </disk>\n", 12);
}
/* XXX new (3.0.3) Xend puts cdrom devs in usual (devices) block */
tmp = sexpr_node(root, "domain/image/hvm/cdrom");
if ((tmp != NULL) && (tmp[0] != 0)) {
virBufferAdd(&buf, " <disk type='file' device='cdrom'>\n", 38);
virBufferVSprintf(&buf, " <source file='%s'/>\n", tmp);
virBufferAdd(&buf, " <target dev='hdc'/>\n", 26);
virBufferAdd(&buf, " <readonly/>\n", 18);
virBufferAdd(&buf, " </disk>\n", 12);
/* Old style cdrom config from Xen <= 3.0.2 */
if (xendConfigVersion == 1) {
tmp = sexpr_node(root, "domain/image/hvm/cdrom");
if ((tmp != NULL) && (tmp[0] != 0)) {
virBufferAdd(&buf, " <disk type='file' device='cdrom'>\n", 38);
virBufferVSprintf(&buf, " <source file='%s'/>\n", tmp);
virBufferAdd(&buf, " <target dev='hdc'/>\n", 26);
virBufferAdd(&buf, " <readonly/>\n", 18);
virBufferAdd(&buf, " </disk>\n", 12);
}
}
}
@ -1664,14 +1722,14 @@ xend_parse_sexp_desc(virConnectPtr conn, struct sexpr *root)
}
char *
xend_parse_domain_sexp(virConnectPtr conn, char *sexpr) {
xend_parse_domain_sexp(virConnectPtr conn, char *sexpr, int xendConfigVersion) {
struct sexpr *root = string2sexpr(sexpr);
char *data;
if (!root)
return NULL;
data = xend_parse_sexp_desc(conn, root);
data = xend_parse_sexp_desc(conn, root, xendConfigVersion);
sexpr_free(root);
@ -2175,12 +2233,18 @@ xenDaemonDomainDumpXMLByID(virConnectPtr conn, int domid)
{
char *ret = NULL;
struct sexpr *root;
int xendConfigVersion;
root = sexpr_get(conn, "/xend/domain/%d?detail=1", domid);
if (root == NULL)
return (NULL);
ret = xend_parse_sexp_desc(conn, root);
if ((xendConfigVersion = xend_get_config_version(conn)) < 0) {
virXendError(conn, VIR_ERR_INTERNAL_ERROR, "cannot determine xend config version");
return (NULL);
}
ret = xend_parse_sexp_desc(conn, root, xendConfigVersion);
sexpr_free(root);
return (ret);
@ -2724,6 +2788,7 @@ xenDaemonCreateLinux(virConnectPtr conn, const char *xmlDesc,
char *sexpr;
char *name = NULL;
virDomainPtr dom;
int xendConfigVersion;
if (!VIR_IS_CONNECT(conn)) {
virXendError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
@ -2734,7 +2799,12 @@ xenDaemonCreateLinux(virConnectPtr conn, const char *xmlDesc,
return (NULL);
}
sexpr = virDomainParseXMLDesc(xmlDesc, &name);
if ((xendConfigVersion = xend_get_config_version(conn)) < 0) {
virXendError(conn, VIR_ERR_INTERNAL_ERROR, "cannot determine xend config version");
return (NULL);
}
sexpr = virDomainParseXMLDesc(xmlDesc, &name, xendConfigVersion);
if ((sexpr == NULL) || (name == NULL)) {
if (sexpr != NULL)
free(sexpr);

View File

@ -613,7 +613,7 @@ char *xenDaemonDomainDumpXMLByID(virConnectPtr xend,
*/
int xend_log(virConnectPtr xend, char *buffer, size_t n_buffer);
char *xend_parse_domain_sexp(virConnectPtr conn, char *root);
char *xend_parse_domain_sexp(virConnectPtr conn, char *root, int xendConfigVersion);
/* refactored ones */
void xenDaemonRegister(void);

104
src/xml.c
View File

@ -609,6 +609,7 @@ static int virDomainParseXMLGraphicsDesc(xmlNodePtr node, virBufferPtr buf)
* @node: node containing HVM OS description
* @buf: a buffer for the result S-Expr
* @ctxt: a path context representing the XML description
* @xendConfigVersion: xend configuration file format
*
* Parse the OS part of the XML description for an HVM domain and add it to
* the S-Expr in buf. This is a temporary interface as the S-Expr interface
@ -618,7 +619,7 @@ static int virDomainParseXMLGraphicsDesc(xmlNodePtr node, virBufferPtr buf)
* Returns 0 in case of success, -1 in case of error.
*/
static int
virDomainParseXMLOSDescHVM(xmlNodePtr node, virBufferPtr buf, xmlXPathContextPtr ctxt)
virDomainParseXMLOSDescHVM(xmlNodePtr node, virBufferPtr buf, xmlXPathContextPtr ctxt, int xendConfigVersion)
{
xmlXPathObjectPtr obj = NULL;
xmlNodePtr cur, txt;
@ -690,44 +691,46 @@ virDomainParseXMLOSDescHVM(xmlNodePtr node, virBufferPtr buf, xmlXPathContextPtr
obj = xmlXPathEval(BAD_CAST "/domain/devices/disk[@device='floppy' and target/@dev='fda']/source", ctxt);
if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr == 1)) {
cur = obj->nodesetval->nodeTab[0];
virBufferVSprintf(buf, "(fda '%s')",
(const char *) xmlGetProp(cur, BAD_CAST "file"));
cur = NULL;
cur = obj->nodesetval->nodeTab[0];
virBufferVSprintf(buf, "(fda '%s')",
(const char *) xmlGetProp(cur, BAD_CAST "file"));
cur = NULL;
}
if (obj) {
xmlXPathFreeObject(obj);
obj = NULL;
}
xmlXPathFreeObject(obj);
obj = NULL;
}
/* get the 2nd floppy device file */
obj = xmlXPathEval(BAD_CAST "/domain/devices/disk[@device='floppy' and target/@dev='fdb']/source", ctxt);
if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr == 1)) {
cur = obj->nodesetval->nodeTab[0];
virBufferVSprintf(buf, "(fdb '%s')",
(const char *) xmlGetProp(cur, BAD_CAST "file"));
cur = NULL;
cur = obj->nodesetval->nodeTab[0];
virBufferVSprintf(buf, "(fdb '%s')",
(const char *) xmlGetProp(cur, BAD_CAST "file"));
cur = NULL;
}
if (obj) {
xmlXPathFreeObject(obj);
obj = NULL;
xmlXPathFreeObject(obj);
obj = NULL;
}
/* get the cdrom device file */
/* XXX new (3.0.3) Xend puts cdrom devs in usual (devices) block */
obj = xmlXPathEval(BAD_CAST "/domain/devices/disk[@device='cdrom' and target/@dev='hdc']/source", ctxt);
if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr == 1)) {
cur = obj->nodesetval->nodeTab[0];
virBufferVSprintf(buf, "(cdrom '%s')",
(const char *) xmlGetProp(cur, BAD_CAST "file"));
cur = NULL;
}
if (obj) {
xmlXPathFreeObject(obj);
obj = NULL;
/* Only XenD <= 3.0.2 wants cdrom config here */
if (xendConfigVersion == 1) {
obj = xmlXPathEval(BAD_CAST "/domain/devices/disk[@device='cdrom' and target/@dev='hdc']/source", ctxt);
if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr == 1)) {
cur = obj->nodesetval->nodeTab[0];
virBufferVSprintf(buf, "(cdrom '%s')",
(const char *) xmlGetProp(cur, BAD_CAST "file"));
cur = NULL;
}
if (obj) {
xmlXPathFreeObject(obj);
obj = NULL;
}
}
obj = xmlXPathEval(BAD_CAST "/domain/features/acpi", ctxt);
@ -885,6 +888,7 @@ virDomainParseXMLOSDescPV(xmlNodePtr node, virBufferPtr buf, xmlXPathContextPtr
* virDomainParseXMLDiskDesc:
* @node: node containing disk description
* @buf: a buffer for the result S-Expr
* @xendConfigVersion: xend configuration file format
*
* Parse the one disk in the XML description and add it to the S-Expr in buf
* This is a temporary interface as the S-Expr interface
@ -894,7 +898,7 @@ virDomainParseXMLOSDescPV(xmlNodePtr node, virBufferPtr buf, xmlXPathContextPtr
* Returns 0 in case of success, -1 in case of error.
*/
static int
virDomainParseXMLDiskDesc(xmlNodePtr node, virBufferPtr buf, int hvm)
virDomainParseXMLDiskDesc(xmlNodePtr node, virBufferPtr buf, int hvm, int xendConfigVersion)
{
xmlNodePtr cur;
xmlChar *type = NULL;
@ -903,6 +907,7 @@ virDomainParseXMLDiskDesc(xmlNodePtr node, virBufferPtr buf, int hvm)
xmlChar *target = NULL;
int ro = 0;
int typ = 0;
int cdrom = 0;
type = xmlGetProp(node, BAD_CAST "type");
if (type != NULL) {
@ -948,29 +953,43 @@ virDomainParseXMLDiskDesc(xmlNodePtr node, virBufferPtr buf, int hvm)
return (-1);
}
/* Skip floppy/cdrom disk used as the boot device
* since that's incorporated into the HVM kernel
* (image (hvm..)) part of the sexpr, rather than
* the (devices...) bit. Odd Xend HVM config :-(
* XXX This will have to change in Xen 3.0.3
/* Xend (all versions) put the floppy device config
* under the hvm (image (os)) block
*/
if (hvm && device &&
(!strcmp((const char *)device, "floppy") ||
!strcmp((const char *)device, "cdrom"))) {
return 0;
if (hvm &&
device &&
!strcmp((const char *)device, "floppy")) {
return 0;
}
/* Xend <= 3.0.2 doesn't include cdrom config here */
if (hvm &&
device &&
!strcmp((const char *)device, "cdrom")) {
if (xendConfigVersion == 1)
return 0;
else
cdrom = 1;
}
virBufferAdd(buf, "(device ", 8);
virBufferAdd(buf, "(vbd ", 5);
/* XXX ioemu prefix is going away in Xen 3.0.3 */
if (hvm) {
char *tmp = (char *)target;
/* Just in case user mistakenly still puts ioemu: in their XML */
if (!strncmp((const char *) tmp, "ioemu:", 6))
tmp += 6;
virBufferVSprintf(buf, "(dev 'ioemu:%s')", (const char *) tmp);
/* Xend <= 3.0.2 wants a ioemu: prefix on devices for HVM */
if (xendConfigVersion == 1)
virBufferVSprintf(buf, "(dev 'ioemu:%s')", (const char *) tmp);
else /* But newer does not */
virBufferVSprintf(buf, "(dev '%s%s')", (const char *) tmp, cdrom ? ":cdrom" : "");
} else
virBufferVSprintf(buf, "(dev '%s')", (const char *) target);
virBufferVSprintf(buf, "(dev '%s')", (const char *) target);
if (typ == 0)
virBufferVSprintf(buf, "(uname 'file:%s')", source);
else if (typ == 1) {
@ -1069,6 +1088,7 @@ virDomainParseXMLIfDesc(xmlNodePtr node, virBufferPtr buf, int hvm)
/**
* virDomainParseXMLDesc:
* @xmldesc: string with the XML description
* @xendConfigVersion: xend configuration file format
*
* Parse the XML description and turn it into the xend sexp needed to
* create the comain. This is a temporary interface as the S-Expr interface
@ -1079,7 +1099,7 @@ virDomainParseXMLIfDesc(xmlNodePtr node, virBufferPtr buf, int hvm)
* the caller must free() the returned value.
*/
char *
virDomainParseXMLDesc(const char *xmldesc, char **name)
virDomainParseXMLDesc(const char *xmldesc, char **name, int xendConfigVersion)
{
xmlDocPtr xml = NULL;
xmlNodePtr node;
@ -1217,7 +1237,7 @@ virDomainParseXMLDesc(const char *xmldesc, char **name)
res = virDomainParseXMLOSDescPV(obj->nodesetval->nodeTab[0], &buf, ctxt);
} else {
hvm = 1;
res = virDomainParseXMLOSDescHVM(obj->nodesetval->nodeTab[0], &buf, ctxt);
res = virDomainParseXMLOSDescHVM(obj->nodesetval->nodeTab[0], &buf, ctxt, xendConfigVersion);
}
xmlXPathFreeObject(tmpobj);
@ -1235,7 +1255,7 @@ virDomainParseXMLDesc(const char *xmldesc, char **name)
if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) {
for (i = 0; i < obj->nodesetval->nodeNr; i++) {
res = virDomainParseXMLDiskDesc(obj->nodesetval->nodeTab[i], &buf, hvm);
res = virDomainParseXMLDiskDesc(obj->nodesetval->nodeTab[i], &buf, hvm, xendConfigVersion);
if (res != 0) {
goto error;
}

View File

@ -29,7 +29,7 @@ void virBufferFree(virBufferPtr buf);
int virBufferAdd(virBufferPtr buf, const char *str, int len);
int virBufferVSprintf(virBufferPtr buf, const char *format, ...);
int virBufferStrcat(virBufferPtr buf, ...);
char *virDomainParseXMLDesc(const char *xmldesc, char **name);
char *virDomainParseXMLDesc(const char *xmldesc, char **name, int xendConfigVersion);
unsigned char *virParseUUID(char **ptr, const char *uuid);
#ifdef __cplusplus

View File

@ -1,6 +1,6 @@
## Process this file with automake to produce Makefile.in
SUBDIRS = virshdata confdata
SUBDIRS = virshdata confdata sexpr2xmldata xml2sexprdata
LIBVIRT = $(top_builddir)/src/.libs/libvirt.a

View File

@ -0,0 +1,2 @@
Makefile
Makefile.in

View File

@ -0,0 +1,2 @@
EXTRA_DIST = $(wildcard *.xml) $(wildcard *.sexpr)

View File

@ -0,0 +1 @@
(domain (domid 3)(name 'fvtest')(memory 400)(maxmem 400)(vcpus 1)(uuid 'b5d70dd275cdaca517769660b059d8bc')(on_poweroff 'destroy')(on_reboot 'restart')(on_crash 'restart')(image (hvm (kernel '/usr/lib/xen/boot/hvmloader')(device_model '/usr/lib64/xen/bin/qemu-dm')(boot c)(acpi 1)(vnc 1)))(device (vbd (dev 'hdc:cdrom')(uname 'file:/root/boot.iso')(mode 'r')))(device (vbd (dev 'hda')(uname 'file:/root/foo.img')(mode 'w')))(device (vif (mac '00:16:3e:1b:b1:47')(bridge 'xenbr0')(script 'vif-bridge')(type ioemu))))

View File

@ -0,0 +1,35 @@
<domain type='xen' id='3'>
<name>fvtest</name>
<uuid>b5d70dd275cdaca517769660b059d8bc</uuid>
<os>
<type>hvm</type>
<loader>/usr/lib/xen/boot/hvmloader</loader>
<boot dev='hd'/>
</os>
<memory>409600</memory>
<vcpu>1</vcpu>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<features>
<acpi/>
</features>
<devices>
<emulator>/usr/lib64/xen/bin/qemu-dm</emulator>
<disk type='file' device='cdrom'>
<source file='/root/boot.iso'/>
<target dev='hdc'/>
<readonly/>
</disk>
<disk type='file' device='disk'>
<source file='/root/foo.img'/>
<target dev='hda'/>
</disk>
<interface type='bridge'>
<source bridge='xenbr0'/>
<mac address='00:16:3e:1b:b1:47'/>
<script path='vif-bridge'/>
</interface>
<graphics type='vnc' port='5903'/>
</devices>
</domain>

View File

@ -11,7 +11,7 @@ static char *progname;
#define MAX_FILE 4096
static int testCompareFiles(const char *xml, const char *sexpr) {
static int testCompareFiles(const char *xml, const char *sexpr, int xendConfigVersion) {
char xmlData[MAX_FILE];
char sexprData[MAX_FILE];
char *gotxml = NULL;
@ -24,7 +24,7 @@ static int testCompareFiles(const char *xml, const char *sexpr) {
if (virtTestLoadFile(sexpr, &sexprPtr, MAX_FILE) < 0)
return -1;
if (!(gotxml = xend_parse_domain_sexp(NULL, sexprData)))
if (!(gotxml = xend_parse_domain_sexp(NULL, sexprData, xendConfigVersion)))
return -1;
if (getenv("DEBUG_TESTS")) {
@ -37,14 +37,28 @@ static int testCompareFiles(const char *xml, const char *sexpr) {
return 0;
}
static int testComparePV(void *data ATTRIBUTE_UNUSED) {
return testCompareFiles("sexpr2xml-pv.xml",
"sexpr2xml-pv.sexpr");
static int testComparePVversion1(void *data ATTRIBUTE_UNUSED) {
return testCompareFiles("sexpr2xmldata/sexpr2xml-pv.xml",
"sexpr2xmldata/sexpr2xml-pv.sexpr",
1);
}
static int testCompareFV(void *data ATTRIBUTE_UNUSED) {
return testCompareFiles("sexpr2xml-fv.xml",
"sexpr2xml-fv.sexpr");
static int testCompareFVversion1(void *data ATTRIBUTE_UNUSED) {
return testCompareFiles("sexpr2xmldata/sexpr2xml-fv.xml",
"sexpr2xmldata/sexpr2xml-fv.sexpr",
1);
}
static int testComparePVversion2(void *data ATTRIBUTE_UNUSED) {
return testCompareFiles("sexpr2xmldata/sexpr2xml-pv.xml",
"sexpr2xmldata/sexpr2xml-pv.sexpr",
2);
}
static int testCompareFVversion2(void *data ATTRIBUTE_UNUSED) {
return testCompareFiles("sexpr2xmldata/sexpr2xml-fv-v2.xml",
"sexpr2xmldata/sexpr2xml-fv-v2.sexpr",
2);
}
int
@ -59,12 +73,20 @@ main(int argc, char **argv)
exit(EXIT_FAILURE);
}
if (virtTestRun("SEXPR-2-XML PV config",
1, testComparePV, NULL) != 0)
if (virtTestRun("SEXPR-2-XML PV config (version 1)",
1, testComparePVversion1, NULL) != 0)
ret = -1;
if (virtTestRun("SEXPR-2-XML FV config",
1, testCompareFV, NULL) != 0)
if (virtTestRun("SEXPR-2-XML FV config (version 1)",
1, testCompareFVversion1, NULL) != 0)
ret = -1;
if (virtTestRun("SEXPR-2-XML PV config (version 2)",
1, testComparePVversion2, NULL) != 0)
ret = -1;
if (virtTestRun("SEXPR-2-XML FV config (version 2)",
1, testCompareFVversion2, NULL) != 0)
ret = -1;
exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);

View File

@ -0,0 +1,2 @@
Makefile
Makefile.in

View File

@ -0,0 +1,2 @@
EXTRA_DIST = $(wildcard *.xml) $(wildcard *.sexpr)

View File

@ -0,0 +1 @@
(vm (name 'fvtest')(memory 400)(maxmem 400)(vcpus 1)(uuid 'b5d70dd275cdaca517769660b059d8bc')(on_poweroff 'destroy')(on_reboot 'restart')(on_crash 'restart')(image (hvm (kernel '/usr/lib/xen/boot/hvmloader')(device_model '/usr/lib64/xen/bin/qemu-dm')(boot c)(acpi 1)(vnc 1)))(device (vbd (dev 'hdc:cdrom')(uname 'file:/root/boot.iso')(mode 'r')))(device (vbd (dev 'hda')(uname 'file:/root/foo.img')(mode 'w')))(device (vif (mac '00:16:3e:1b:b1:47')(bridge 'xenbr0')(script 'vif-bridge')(type ioemu))))

View File

@ -10,7 +10,7 @@ static char *progname;
#define MAX_FILE 4096
static int testCompareFiles(const char *xml, const char *sexpr, const char *name) {
static int testCompareFiles(const char *xml, const char *sexpr, const char *name, int xendConfigVersion) {
char xmlData[MAX_FILE];
char sexprData[MAX_FILE];
char *gotname = NULL;
@ -24,7 +24,7 @@ static int testCompareFiles(const char *xml, const char *sexpr, const char *name
if (virtTestLoadFile(sexpr, &sexprPtr, MAX_FILE) < 0)
return -1;
if (!(gotsexpr = virDomainParseXMLDesc(xmlData, &gotname)))
if (!(gotsexpr = virDomainParseXMLDesc(xmlData, &gotname, xendConfigVersion)))
return -1;
if (getenv("DEBUG_TESTS")) {
@ -40,16 +40,32 @@ static int testCompareFiles(const char *xml, const char *sexpr, const char *name
return 0;
}
static int testComparePV(void *data ATTRIBUTE_UNUSED) {
return testCompareFiles("xml2sexpr-pv.xml",
"xml2sexpr-pv.sexpr",
"pvtest");
static int testComparePVversion1(void *data ATTRIBUTE_UNUSED) {
return testCompareFiles("xml2sexprdata/xml2sexpr-pv.xml",
"xml2sexprdata/xml2sexpr-pv.sexpr",
"pvtest",
1);
}
static int testCompareFV(void *data ATTRIBUTE_UNUSED) {
return testCompareFiles("xml2sexpr-fv.xml",
"xml2sexpr-fv.sexpr",
"fvtest");
static int testCompareFVversion1(void *data ATTRIBUTE_UNUSED) {
return testCompareFiles("xml2sexprdata/xml2sexpr-fv.xml",
"xml2sexprdata/xml2sexpr-fv.sexpr",
"fvtest",
1);
}
static int testComparePVversion2(void *data ATTRIBUTE_UNUSED) {
return testCompareFiles("xml2sexprdata/xml2sexpr-pv.xml",
"xml2sexprdata/xml2sexpr-pv.sexpr",
"pvtest",
2);
}
static int testCompareFVversion2(void *data ATTRIBUTE_UNUSED) {
return testCompareFiles("xml2sexprdata/xml2sexpr-fv.xml",
"xml2sexprdata/xml2sexpr-fv-v2.sexpr",
"fvtest",
2);
}
int
@ -64,12 +80,20 @@ main(int argc, char **argv)
exit(EXIT_FAILURE);
}
if (virtTestRun("XML-2-SEXPR PV config",
1, testComparePV, NULL) != 0)
if (virtTestRun("XML-2-SEXPR PV config (format 1)",
1, testComparePVversion1, NULL) != 0)
ret = -1;
if (virtTestRun("XML-2-SEXPR FV config",
1, testCompareFV, NULL) != 0)
if (virtTestRun("XML-2-SEXPR FV config (format 1)",
1, testCompareFVversion1, NULL) != 0)
ret = -1;
if (virtTestRun("XML-2-SEXPR PV config (format 2)",
1, testComparePVversion2, NULL) != 0)
ret = -1;
if (virtTestRun("XML-2-SEXPR FV config (format 2)",
1, testCompareFVversion2, NULL) != 0)
ret = -1;
exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);