]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
Added support for XenD 3.0.3 style HVM cdrom config
authorDaniel P. Berrange <berrange@redhat.com>
Tue, 12 Sep 2006 01:16:22 +0000 (01:16 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Tue, 12 Sep 2006 01:16:22 +0000 (01:16 +0000)
33 files changed:
.cvsignore
ChangeLog
configure.in
src/xend_internal.c
src/xend_internal.h
src/xml.c
src/xml.h
tests/Makefile.am
tests/sexpr2xml-fv.sexpr [deleted file]
tests/sexpr2xml-fv.xml [deleted file]
tests/sexpr2xml-pv.sexpr [deleted file]
tests/sexpr2xml-pv.xml [deleted file]
tests/sexpr2xmldata/.cvsignore [new file with mode: 0644]
tests/sexpr2xmldata/Makefile.am [new file with mode: 0644]
tests/sexpr2xmldata/sexpr2xml-fv-v2.sexpr [new file with mode: 0644]
tests/sexpr2xmldata/sexpr2xml-fv-v2.xml [new file with mode: 0644]
tests/sexpr2xmldata/sexpr2xml-fv.sexpr [new file with mode: 0644]
tests/sexpr2xmldata/sexpr2xml-fv.xml [new file with mode: 0644]
tests/sexpr2xmldata/sexpr2xml-pv.sexpr [new file with mode: 0644]
tests/sexpr2xmldata/sexpr2xml-pv.xml [new file with mode: 0644]
tests/sexpr2xmltest.c
tests/xml2sexpr-fv.sexpr [deleted file]
tests/xml2sexpr-fv.xml [deleted file]
tests/xml2sexpr-pv.sexpr [deleted file]
tests/xml2sexpr-pv.xml [deleted file]
tests/xml2sexprdata/.cvsignore [new file with mode: 0644]
tests/xml2sexprdata/Makefile.am [new file with mode: 0644]
tests/xml2sexprdata/xml2sexpr-fv-v2.sexpr [new file with mode: 0644]
tests/xml2sexprdata/xml2sexpr-fv.sexpr [new file with mode: 0644]
tests/xml2sexprdata/xml2sexpr-fv.xml [new file with mode: 0644]
tests/xml2sexprdata/xml2sexpr-pv.sexpr [new file with mode: 0644]
tests/xml2sexprdata/xml2sexpr-pv.xml [new file with mode: 0644]
tests/xml2sexprtest.c

index dc4aaa6f7a194cd0bda843dcd0a6a0c463f6347c..3603807043ab5fa3c5c0fdc2206e6a3521b84ee2 100644 (file)
@@ -19,3 +19,4 @@ ltmain.sh
 update.log
 libvirt.pc
 libvirt.spec
+COPYING
\ No newline at end of file
index 21a94a7935cd3ec59cae1de29a689346bce417b1..32a06bd0ae8dbc50f69e45f2daa2ee672f64cc43 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.*:
index 1bcec8d628389ed97bea52792b3b4635c3c18167..217cd88c4d93009a09ef7782ee77720d1ebb8771 100644 (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)
index ce3580b8cd39714c0c5aa5501e184d4e224cbff3..463da1a192e96521cd5aac4249b63ab70bde6d5d 100644 (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);
index eff24628b2f8991e73558e32a6dd5fba7382d767..11c54136da98b749c9b55362e66131ef79a9eeec 100644 (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);
index cc6d9dd887c6dd79419ca8009d0849440bc2af7b..8623a5fce025b8a7079c2f8cc50c7bd58c1855d3 100644 (file)
--- a/src/xml.c
+++ b/src/xml.c
@@ -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;
            }
index 78e086c014f4ad879599e19ded544298af6a6f9b..5e91abec1b37b4cef7ab40a51c44f1f09d6ddfc2 100644 (file)
--- a/src/xml.h
+++ b/src/xml.h
@@ -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
index 3a71a9b45fce5662383233887ee191259223da5b..98e7d4402a420e881edada95af1a1c25d05996ab 100644 (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
 
diff --git a/tests/sexpr2xml-fv.sexpr b/tests/sexpr2xml-fv.sexpr
deleted file mode 100644 (file)
index 4c5540f..0000000
+++ /dev/null
@@ -1 +0,0 @@
-(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)(cdrom '/root/boot.iso')(acpi 1)(vnc 1)))(device (vbd (dev 'ioemu:hda')(uname 'file:/root/foo.img')(mode 'w')))(device (vif (mac '00:16:3e:1b:b1:47')(bridge 'xenbr0')(script 'vif-bridge')(type ioemu))))
diff --git a/tests/sexpr2xml-fv.xml b/tests/sexpr2xml-fv.xml
deleted file mode 100644 (file)
index 08a5ee1..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-<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='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>
-    <disk type='file' device='cdrom'>
-      <source file='/root/boot.iso'/>
-      <target dev='hdc'/>
-      <readonly/>
-    </disk>
-    <graphics type='vnc' port='5903'/>
-  </devices>
-</domain>
diff --git a/tests/sexpr2xml-pv.sexpr b/tests/sexpr2xml-pv.sexpr
deleted file mode 100644 (file)
index 74c9e01..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-(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'))))
-
diff --git a/tests/sexpr2xml-pv.xml b/tests/sexpr2xml-pv.xml
deleted file mode 100644 (file)
index 66d6fe0..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-<domain type='xen' id='6'>
-  <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>
-  </devices>
-</domain>
diff --git a/tests/sexpr2xmldata/.cvsignore b/tests/sexpr2xmldata/.cvsignore
new file mode 100644 (file)
index 0000000..282522d
--- /dev/null
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/tests/sexpr2xmldata/Makefile.am b/tests/sexpr2xmldata/Makefile.am
new file mode 100644 (file)
index 0000000..43117d5
--- /dev/null
@@ -0,0 +1,2 @@
+
+EXTRA_DIST = $(wildcard *.xml) $(wildcard *.sexpr)
diff --git a/tests/sexpr2xmldata/sexpr2xml-fv-v2.sexpr b/tests/sexpr2xmldata/sexpr2xml-fv-v2.sexpr
new file mode 100644 (file)
index 0000000..398ebca
--- /dev/null
@@ -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))))
diff --git a/tests/sexpr2xmldata/sexpr2xml-fv-v2.xml b/tests/sexpr2xmldata/sexpr2xml-fv-v2.xml
new file mode 100644 (file)
index 0000000..6ea0896
--- /dev/null
@@ -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>
diff --git a/tests/sexpr2xmldata/sexpr2xml-fv.sexpr b/tests/sexpr2xmldata/sexpr2xml-fv.sexpr
new file mode 100644 (file)
index 0000000..4c5540f
--- /dev/null
@@ -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)(cdrom '/root/boot.iso')(acpi 1)(vnc 1)))(device (vbd (dev 'ioemu:hda')(uname 'file:/root/foo.img')(mode 'w')))(device (vif (mac '00:16:3e:1b:b1:47')(bridge 'xenbr0')(script 'vif-bridge')(type ioemu))))
diff --git a/tests/sexpr2xmldata/sexpr2xml-fv.xml b/tests/sexpr2xmldata/sexpr2xml-fv.xml
new file mode 100644 (file)
index 0000000..08a5ee1
--- /dev/null
@@ -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='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>
+    <disk type='file' device='cdrom'>
+      <source file='/root/boot.iso'/>
+      <target dev='hdc'/>
+      <readonly/>
+    </disk>
+    <graphics type='vnc' port='5903'/>
+  </devices>
+</domain>
diff --git a/tests/sexpr2xmldata/sexpr2xml-pv.sexpr b/tests/sexpr2xmldata/sexpr2xml-pv.sexpr
new file mode 100644 (file)
index 0000000..74c9e01
--- /dev/null
@@ -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/5.91/x86_64/os  ')))(device (vbd (dev 'xvda')(uname 'file:/root/some.img')(mode 'w'))))
+
diff --git a/tests/sexpr2xmldata/sexpr2xml-pv.xml b/tests/sexpr2xmldata/sexpr2xml-pv.xml
new file mode 100644 (file)
index 0000000..66d6fe0
--- /dev/null
@@ -0,0 +1,21 @@
+<domain type='xen' id='6'>
+  <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>
+  </devices>
+</domain>
index 17fb4b9370bdac382f9b9d43e9c4ed9fa7a40fc9..158999bf3722da1489aae48fe5c1e3e4a1753fee 100644 (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 (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", 
-                   1, testCompareFV, NULL) != 0)
+    if (virtTestRun("SEXPR-2-XML FV config  (version 2)", 
+                   1, testCompareFVversion2, NULL) != 0)
         ret = -1;
 
     exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
diff --git a/tests/xml2sexpr-fv.sexpr b/tests/xml2sexpr-fv.sexpr
deleted file mode 100644 (file)
index 62513df..0000000
+++ /dev/null
@@ -1 +0,0 @@
-(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)(cdrom '/root/boot.iso')(acpi 1)(vnc 1)))(device (vbd (dev 'ioemu:hda')(uname 'file:/root/foo.img')(mode 'w')))(device (vif (mac '00:16:3e:1b:b1:47')(bridge 'xenbr0')(script 'vif-bridge')(type ioemu))))
\ No newline at end of file
diff --git a/tests/xml2sexpr-fv.xml b/tests/xml2sexpr-fv.xml
deleted file mode 100644 (file)
index 68aef91..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-<domain type='xen'>
-  <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>
-    <interface type='bridge'>
-      <source bridge='xenbr0'/>
-      <mac address='00:16:3e:1b:b1:47'/>
-      <script path='vif-bridge'/>
-    </interface>
-    <disk type='file' device='cdrom'>
-      <source file='/root/boot.iso'/>
-      <target dev='hdc'/>
-      <readonly/>
-    </disk>
-    <disk type='file'>
-      <source file='/root/foo.img'/>
-      <target dev='ioemu:hda'/>
-    </disk>
-    <graphics type='vnc' port='5917'/>
-  </devices>
-</domain>
-
diff --git a/tests/xml2sexpr-pv.sexpr b/tests/xml2sexpr-pv.sexpr
deleted file mode 100644 (file)
index 3ab1a83..0000000
+++ /dev/null
@@ -1 +0,0 @@
-(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'))))
\ No newline at end of file
diff --git a/tests/xml2sexpr-pv.xml b/tests/xml2sexpr-pv.xml
deleted file mode 100644 (file)
index 938682b..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-<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>
-    <console tty='/dev/pts/4'/>
-  </devices>
-</domain>
-
diff --git a/tests/xml2sexprdata/.cvsignore b/tests/xml2sexprdata/.cvsignore
new file mode 100644 (file)
index 0000000..282522d
--- /dev/null
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/tests/xml2sexprdata/Makefile.am b/tests/xml2sexprdata/Makefile.am
new file mode 100644 (file)
index 0000000..43117d5
--- /dev/null
@@ -0,0 +1,2 @@
+
+EXTRA_DIST = $(wildcard *.xml) $(wildcard *.sexpr)
diff --git a/tests/xml2sexprdata/xml2sexpr-fv-v2.sexpr b/tests/xml2sexprdata/xml2sexpr-fv-v2.sexpr
new file mode 100644 (file)
index 0000000..190c218
--- /dev/null
@@ -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))))
\ No newline at end of file
diff --git a/tests/xml2sexprdata/xml2sexpr-fv.sexpr b/tests/xml2sexprdata/xml2sexpr-fv.sexpr
new file mode 100644 (file)
index 0000000..62513df
--- /dev/null
@@ -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)(cdrom '/root/boot.iso')(acpi 1)(vnc 1)))(device (vbd (dev 'ioemu:hda')(uname 'file:/root/foo.img')(mode 'w')))(device (vif (mac '00:16:3e:1b:b1:47')(bridge 'xenbr0')(script 'vif-bridge')(type ioemu))))
\ No newline at end of file
diff --git a/tests/xml2sexprdata/xml2sexpr-fv.xml b/tests/xml2sexprdata/xml2sexpr-fv.xml
new file mode 100644 (file)
index 0000000..68aef91
--- /dev/null
@@ -0,0 +1,36 @@
+<domain type='xen'>
+  <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>
+    <interface type='bridge'>
+      <source bridge='xenbr0'/>
+      <mac address='00:16:3e:1b:b1:47'/>
+      <script path='vif-bridge'/>
+    </interface>
+    <disk type='file' device='cdrom'>
+      <source file='/root/boot.iso'/>
+      <target dev='hdc'/>
+      <readonly/>
+    </disk>
+    <disk type='file'>
+      <source file='/root/foo.img'/>
+      <target dev='ioemu:hda'/>
+    </disk>
+    <graphics type='vnc' port='5917'/>
+  </devices>
+</domain>
+
diff --git a/tests/xml2sexprdata/xml2sexpr-pv.sexpr b/tests/xml2sexprdata/xml2sexpr-pv.sexpr
new file mode 100644 (file)
index 0000000..3ab1a83
--- /dev/null
@@ -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/5.91/x86_64/os  ')))(device (vbd (dev 'xvda')(uname 'file:/root/some.img')(mode 'w'))))
\ No newline at end of file
diff --git a/tests/xml2sexprdata/xml2sexpr-pv.xml b/tests/xml2sexprdata/xml2sexpr-pv.xml
new file mode 100644 (file)
index 0000000..938682b
--- /dev/null
@@ -0,0 +1,23 @@
+<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>
+    <console tty='/dev/pts/4'/>
+  </devices>
+</domain>
+
index 335145c735546b7624a5b6be99323d342a47a8e3..90b19d25a7bdc09432a544b47c4f675816a777c0 100644 (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 (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", 
-                   1, testCompareFV, NULL) != 0)
+    if (virtTestRun("XML-2-SEXPR FV config (format 2)", 
+                   1, testCompareFVversion2, NULL) != 0)
         ret = -1;
 
     exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);