]> xenbits.xensource.com Git - libvirt.git/commitdiff
Differentiate between active and inactive configs by honoring the
authorGuido Günther <agx@sigxcpu.org>
Thu, 4 Dec 2008 12:02:59 +0000 (12:02 +0000)
committerGuido Günther <agx@sigxcpu.org>
Thu, 4 Dec 2008 12:02:59 +0000 (12:02 +0000)
VIR_DOMAIN_XML_INACTIVE flag.

ChangeLog
src/domain_conf.c
src/domain_conf.h
src/lxc_controller.c
src/lxc_driver.c
src/test.c
tests/qemuxml2argvtest.c

index 06cb6f92395535b552744f18f4b200f537cf3479..24b50425e1c2e39a854ecfa6bf4fec84397c1558 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+Thu, 4 Dec 2008 12:46:01 CET Guido Günther <agx@sigxcpu.org>
+
+       Differentiate between active and inactive configs by honoring the
+       VIR_DOMAIN_XML_INACTIVE flag.
+       * src/domain_conf.c (virDomainDefParseXML): add and pass on flags arg
+       (virDomainDefParseFile): Likewise
+       (virDomainDefParseNode): Likewise
+       (virDomainGraphicsDefParseXML): Likewise
+       * src/domain_conf.c (virDomainDefParseXML): only restore domain id if
+       !VIR_DOMAIN_XML_INACTIVE
+       * src/domain_conf. (virDomainGraphicsDefParseXML): only restore vnc
+       port if !VIR_DOMAIN_XML_INACTIVE
+       * src/lxc_driver.c (lxcStartup): pass 0 flag since we restore life
+       config
+       * src/lxc_controller.c: pass VIR_DOMAIN_XML_INACTIVE
+       * src/test.c: pass VIR_DOMAIN_XML_INACTIVE
+       * tests/qemuxml2argvtest.c: pass VIR_DOMAIN_XML_INACTIVE
+
 Thu, 4 Dec 2008 11:41:12 CET Guido Günther <agx@sigxcpu.org>
 
        * src/qemu_driver.c: also look for /usr/bin/kvm
index 4adab699756a9296271ae06080a03e13c0fa8a70..292cecfaaf1f723ffe6dc8e9e13431da567d3efa 100644 (file)
@@ -1318,7 +1318,7 @@ error:
 /* Parse the XML definition for a graphics device */
 static virDomainGraphicsDefPtr
 virDomainGraphicsDefParseXML(virConnectPtr conn,
-                             xmlNodePtr node) {
+                             xmlNodePtr node, int flags) {
     virDomainGraphicsDefPtr def;
     char *type = NULL;
 
@@ -1355,7 +1355,8 @@ virDomainGraphicsDefParseXML(virConnectPtr conn,
             VIR_FREE(port);
             /* Legacy compat syntax, used -1 for auto-port */
             if (def->data.vnc.port == -1) {
-                def->data.vnc.port = 0;
+                if (flags & VIR_DOMAIN_XML_INACTIVE)
+                    def->data.vnc.port = 0;
                 def->data.vnc.autoport = 1;
             }
         } else {
@@ -1365,7 +1366,8 @@ virDomainGraphicsDefParseXML(virConnectPtr conn,
 
         if ((autoport = virXMLPropString(node, "autoport")) != NULL) {
             if (STREQ(autoport, "yes")) {
-                def->data.vnc.port = 0;
+                if (flags & VIR_DOMAIN_XML_INACTIVE)
+                    def->data.vnc.port = 0;
                 def->data.vnc.autoport = 1;
             }
             VIR_FREE(autoport);
@@ -1699,11 +1701,12 @@ int virDomainDiskQSort(const void *a, const void *b)
 #ifndef PROXY
 static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
                                             virCapsPtr caps,
-                                            xmlXPathContextPtr ctxt)
+                                            xmlXPathContextPtr ctxt, int flags)
 {
     xmlNodePtr *nodes = NULL, node = NULL;
     char *tmp = NULL;
     int i, n;
+    long id = -1;
     virDomainDefPtr def;
 
     if (VIR_ALLOC(def) < 0) {
@@ -1711,7 +1714,11 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
                          "%s", _("failed to allocate space for xmlXPathContext"));
         return NULL;
     }
-    def->id = -1;
+
+    if (!(flags & VIR_DOMAIN_XML_INACTIVE))
+        if((virXPathLong(conn, "string(./@id)", ctxt, &id)) < 0)
+            id = -1;
+    def->id = (int)id;
 
     /* Find out what type of virtualization to use */
     if (!(tmp = virXPathString(conn, "string(./@type)", ctxt))) {
@@ -2101,7 +2108,8 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
     }
     if (n > 0) {
         virDomainGraphicsDefPtr graphics = virDomainGraphicsDefParseXML(conn,
-                                                                        nodes[0]);
+                                                                        nodes[0],
+                                                                        flags);
         if (!graphics)
             goto error;
 
@@ -2247,7 +2255,8 @@ virDomainDefPtr virDomainDefParseString(virConnectPtr conn,
         goto cleanup;
     }
 
-    def = virDomainDefParseNode(conn, caps, xml, root);
+    def = virDomainDefParseNode(conn, caps, xml, root,
+                                VIR_DOMAIN_XML_INACTIVE);
 
 cleanup:
     xmlFreeParserCtxt (pctxt);
@@ -2257,7 +2266,7 @@ cleanup:
 
 virDomainDefPtr virDomainDefParseFile(virConnectPtr conn,
                                       virCapsPtr caps,
-                                      const char *filename)
+                                      const char *filename, int flags)
 {
     xmlParserCtxtPtr pctxt;
     xmlDocPtr xml = NULL;
@@ -2288,7 +2297,7 @@ virDomainDefPtr virDomainDefParseFile(virConnectPtr conn,
         goto cleanup;
     }
 
-    def = virDomainDefParseNode(conn, caps, xml, root);
+    def = virDomainDefParseNode(conn, caps, xml, root, flags);
 
 cleanup:
     xmlFreeParserCtxt (pctxt);
@@ -2300,7 +2309,8 @@ cleanup:
 virDomainDefPtr virDomainDefParseNode(virConnectPtr conn,
                                       virCapsPtr caps,
                                       xmlDocPtr xml,
-                                      xmlNodePtr root)
+                                      xmlNodePtr root,
+                                      int flags)
 {
     xmlXPathContextPtr ctxt = NULL;
     virDomainDefPtr def = NULL;
@@ -2318,7 +2328,7 @@ virDomainDefPtr virDomainDefParseNode(virConnectPtr conn,
     }
 
     ctxt->node = root;
-    def = virDomainDefParseXML(conn, caps, ctxt);
+    def = virDomainDefParseXML(conn, caps, ctxt, flags);
 
 cleanup:
     xmlXPathFreeContext(ctxt);
@@ -3273,7 +3283,8 @@ virDomainObjPtr virDomainLoadConfig(virConnectPtr conn,
     if ((autostart = virFileLinkPointsTo(autostartLink, configFile)) < 0)
         goto error;
 
-    if (!(def = virDomainDefParseFile(conn, caps, configFile)))
+    if (!(def = virDomainDefParseFile(conn, caps, configFile,
+                                      VIR_DOMAIN_XML_INACTIVE)))
         goto error;
 
     if (virDomainFindByName(doms, def->name))
index 084c44852dc5cf1ddd50e6233425125ee3bc67aa..5a5e7ce857798b7518ddc23fe5574d6f30249e06 100644 (file)
@@ -526,11 +526,13 @@ virDomainDefPtr virDomainDefParseString(virConnectPtr conn,
                                         const char *xmlStr);
 virDomainDefPtr virDomainDefParseFile(virConnectPtr conn,
                                       virCapsPtr caps,
-                                      const char *filename);
+                                      const char *filename,
+                                      int flags);
 virDomainDefPtr virDomainDefParseNode(virConnectPtr conn,
                                       virCapsPtr caps,
                                       xmlDocPtr doc,
-                                      xmlNodePtr root);
+                                      xmlNodePtr root,
+                                      int flags);
 #endif
 char *virDomainDefFormat(virConnectPtr conn,
                          virDomainDefPtr def,
index f5d6188df773ad8af504dbe7d27cbcf990e3bce6..da1af4559c1120f3826c574473fdc519e7230e8f 100644 (file)
@@ -593,7 +593,8 @@ int main(int argc, char *argv[])
                                           name)) == NULL)
         goto cleanup;
 
-    if ((def = virDomainDefParseFile(NULL, caps, configFile)) == NULL)
+    if ((def = virDomainDefParseFile(NULL, caps, configFile,
+                                     VIR_DOMAIN_XML_INACTIVE)) == NULL)
         goto cleanup;
 
     if (def->nnets != nveths) {
index 3ec1cb4dad3811b2500bb005f447444b83ae5172..9a191f8192d99705970807ff4b4594a4ce33001e 100644 (file)
@@ -1049,7 +1049,7 @@ static int lxcStartup(void)
             continue;
 
         /* Try and load the live config */
-        tmp = virDomainDefParseFile(NULL, lxc_driver->caps, config);
+        tmp = virDomainDefParseFile(NULL, lxc_driver->caps, config, 0);
         VIR_FREE(config);
         if (tmp) {
             vm->newDef = vm->def;
index 3e942daff7b869f2cfdc7eb93e7c09c7b24fa1fe..734a01746f4682c5bdf23cb22a35ba87b558522e 100644 (file)
@@ -504,12 +504,14 @@ static int testOpenFromFile(virConnectPtr conn,
                 testError(NULL, VIR_ERR_INTERNAL_ERROR, "%s", _("resolving domain filename"));
                 goto error;
             }
-            def = virDomainDefParseFile(conn, privconn->caps, absFile);
+            def = virDomainDefParseFile(conn, privconn->caps, absFile,
+                                        VIR_DOMAIN_XML_INACTIVE);
             VIR_FREE(absFile);
             if (!def)
                 goto error;
         } else {
-            if ((def = virDomainDefParseNode(conn, privconn->caps, xml, domains[i])) == NULL)
+            if ((def = virDomainDefParseNode(conn, privconn->caps, xml, domains[i],
+                                   VIR_DOMAIN_XML_INACTIVE)) == NULL)
                 goto error;
         }
 
index b6a7f68a6d13dd6ee16775fe41da4635b92d25be..6e5355a5248bfceaa360b51428ddb71c34b171b9 100644 (file)
@@ -38,7 +38,8 @@ static int testCompareXMLToArgvFiles(const char *xml,
     if (virtTestLoadFile(cmd, &expectargv, MAX_FILE) < 0)
         goto fail;
 
-    if (!(vmdef = virDomainDefParseFile(NULL, driver.caps, xml)))
+    if (!(vmdef = virDomainDefParseFile(NULL, driver.caps, xml,
+                                        VIR_DOMAIN_XML_INACTIVE)))
         goto fail;
 
     memset(&vm, 0, sizeof vm);