On Wed, Nov 26, 2008 at 08:54:40PM +0000, Daniel P. Berrange wrote: [..snip..] > Hmm, interesting idea - we already have a variant for parsing based > off an arbitrary XML node, rather than assuming the root, > > virDomainDefPtr virDomainDefParseNode(virConnectPtr conn, > virCapsPtr caps, > xmlDocPtr doc, > xmlNodePtr root); > > So we could add a wrapper function which writes out a XML doc > > <domstate state="running" pid="1234"> > <monitor path="/dev/pts/4"> > <domain id='32'> > ... normal domain XML config ... > </domain> > </domstate> > > And so have a function > > virDomainObjPtr virDomainObjParse(const char *filename) > > which'd parse the custom QEMU state, and then just invoke the > virDomainDefParseNode for the nested <domain> tag. Yes, nice - this simplifies things. I'll try that. > Now, some things like VNC port, domain ID really are easily tracked > in the regular domain XML - rather than adding VIR_DOMAIN_XML_STATE > I've a slight alternative idea. > > The formatXML methods already accept a flag VIR_DOMAIN_XML_INACTIVE > which when passed causes it to skip some attributes which only > make sense for running VMs - VNC port, ID, VIF name > > The parseXML methods, just hardcode this and always skip these > attributes. We should fix this so the parsing only skips these > attrs if this same VIR_DOMAIN_XML_INACTIVE flag is passed. Then > just make sure all existing code is changed to set this flag > when parsing XML. The code for loading VM from disk can simply > not set this flag. Technically the LXC driver shold be doing > this already, precisely for the VIF name issue. Like the attached patch? -- Guido
>From 87db4a698ed9b49294c0f94137fc6beef13bd4e8 Mon Sep 17 00:00:00 2001 From: =?utf-8?q?Guido=20G=C3=BCnther?= <agx@xxxxxxxxxxx> Date: Tue, 25 Nov 2008 13:02:43 +0100 Subject: [PATCH] differentiate between active and inactive configs by honoring the VIR_DOMAIN_XML_INACTIVE flag. --- src/domain_conf.c | 35 +++++++++++++++++++++++------------ src/domain_conf.h | 6 ++++-- src/lxc_controller.c | 3 ++- src/lxc_driver.c | 2 +- src/test.c | 6 ++++-- tests/qemuxml2argvtest.c | 3 ++- 6 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/domain_conf.c b/src/domain_conf.c index 4adab69..292cecf 100644 --- a/src/domain_conf.c +++ b/src/domain_conf.c @@ -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)) diff --git a/src/domain_conf.h b/src/domain_conf.h index 084c448..5a5e7ce 100644 --- a/src/domain_conf.h +++ b/src/domain_conf.h @@ -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, diff --git a/src/lxc_controller.c b/src/lxc_controller.c index f5d6188..da1af45 100644 --- a/src/lxc_controller.c +++ b/src/lxc_controller.c @@ -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) { diff --git a/src/lxc_driver.c b/src/lxc_driver.c index 3ec1cb4..9a191f8 100644 --- a/src/lxc_driver.c +++ b/src/lxc_driver.c @@ -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; diff --git a/src/test.c b/src/test.c index 7998886..5a7c401 100644 --- a/src/test.c +++ b/src/test.c @@ -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; } diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index b6a7f68..6e5355a 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -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); -- 1.6.0.3
-- Libvir-list mailing list Libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list