Differentiate between active and inactive configs by honoring the

VIR_DOMAIN_XML_INACTIVE flag.
This commit is contained in:
Guido Günther 2008-12-04 12:02:59 +00:00
parent 38b402ce13
commit 1d7d2fae10
7 changed files with 54 additions and 19 deletions

View File

@ -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> Thu, 4 Dec 2008 11:41:12 CET Guido Günther <agx@sigxcpu.org>
* src/qemu_driver.c: also look for /usr/bin/kvm * src/qemu_driver.c: also look for /usr/bin/kvm

View File

@ -1318,7 +1318,7 @@ error:
/* Parse the XML definition for a graphics device */ /* Parse the XML definition for a graphics device */
static virDomainGraphicsDefPtr static virDomainGraphicsDefPtr
virDomainGraphicsDefParseXML(virConnectPtr conn, virDomainGraphicsDefParseXML(virConnectPtr conn,
xmlNodePtr node) { xmlNodePtr node, int flags) {
virDomainGraphicsDefPtr def; virDomainGraphicsDefPtr def;
char *type = NULL; char *type = NULL;
@ -1355,6 +1355,7 @@ virDomainGraphicsDefParseXML(virConnectPtr conn,
VIR_FREE(port); VIR_FREE(port);
/* Legacy compat syntax, used -1 for auto-port */ /* Legacy compat syntax, used -1 for auto-port */
if (def->data.vnc.port == -1) { if (def->data.vnc.port == -1) {
if (flags & VIR_DOMAIN_XML_INACTIVE)
def->data.vnc.port = 0; def->data.vnc.port = 0;
def->data.vnc.autoport = 1; def->data.vnc.autoport = 1;
} }
@ -1365,6 +1366,7 @@ virDomainGraphicsDefParseXML(virConnectPtr conn,
if ((autoport = virXMLPropString(node, "autoport")) != NULL) { if ((autoport = virXMLPropString(node, "autoport")) != NULL) {
if (STREQ(autoport, "yes")) { if (STREQ(autoport, "yes")) {
if (flags & VIR_DOMAIN_XML_INACTIVE)
def->data.vnc.port = 0; def->data.vnc.port = 0;
def->data.vnc.autoport = 1; def->data.vnc.autoport = 1;
} }
@ -1699,11 +1701,12 @@ int virDomainDiskQSort(const void *a, const void *b)
#ifndef PROXY #ifndef PROXY
static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn, static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
virCapsPtr caps, virCapsPtr caps,
xmlXPathContextPtr ctxt) xmlXPathContextPtr ctxt, int flags)
{ {
xmlNodePtr *nodes = NULL, node = NULL; xmlNodePtr *nodes = NULL, node = NULL;
char *tmp = NULL; char *tmp = NULL;
int i, n; int i, n;
long id = -1;
virDomainDefPtr def; virDomainDefPtr def;
if (VIR_ALLOC(def) < 0) { if (VIR_ALLOC(def) < 0) {
@ -1711,7 +1714,11 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
"%s", _("failed to allocate space for xmlXPathContext")); "%s", _("failed to allocate space for xmlXPathContext"));
return NULL; 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 */ /* Find out what type of virtualization to use */
if (!(tmp = virXPathString(conn, "string(./@type)", ctxt))) { if (!(tmp = virXPathString(conn, "string(./@type)", ctxt))) {
@ -2101,7 +2108,8 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
} }
if (n > 0) { if (n > 0) {
virDomainGraphicsDefPtr graphics = virDomainGraphicsDefParseXML(conn, virDomainGraphicsDefPtr graphics = virDomainGraphicsDefParseXML(conn,
nodes[0]); nodes[0],
flags);
if (!graphics) if (!graphics)
goto error; goto error;
@ -2247,7 +2255,8 @@ virDomainDefPtr virDomainDefParseString(virConnectPtr conn,
goto cleanup; goto cleanup;
} }
def = virDomainDefParseNode(conn, caps, xml, root); def = virDomainDefParseNode(conn, caps, xml, root,
VIR_DOMAIN_XML_INACTIVE);
cleanup: cleanup:
xmlFreeParserCtxt (pctxt); xmlFreeParserCtxt (pctxt);
@ -2257,7 +2266,7 @@ cleanup:
virDomainDefPtr virDomainDefParseFile(virConnectPtr conn, virDomainDefPtr virDomainDefParseFile(virConnectPtr conn,
virCapsPtr caps, virCapsPtr caps,
const char *filename) const char *filename, int flags)
{ {
xmlParserCtxtPtr pctxt; xmlParserCtxtPtr pctxt;
xmlDocPtr xml = NULL; xmlDocPtr xml = NULL;
@ -2288,7 +2297,7 @@ virDomainDefPtr virDomainDefParseFile(virConnectPtr conn,
goto cleanup; goto cleanup;
} }
def = virDomainDefParseNode(conn, caps, xml, root); def = virDomainDefParseNode(conn, caps, xml, root, flags);
cleanup: cleanup:
xmlFreeParserCtxt (pctxt); xmlFreeParserCtxt (pctxt);
@ -2300,7 +2309,8 @@ cleanup:
virDomainDefPtr virDomainDefParseNode(virConnectPtr conn, virDomainDefPtr virDomainDefParseNode(virConnectPtr conn,
virCapsPtr caps, virCapsPtr caps,
xmlDocPtr xml, xmlDocPtr xml,
xmlNodePtr root) xmlNodePtr root,
int flags)
{ {
xmlXPathContextPtr ctxt = NULL; xmlXPathContextPtr ctxt = NULL;
virDomainDefPtr def = NULL; virDomainDefPtr def = NULL;
@ -2318,7 +2328,7 @@ virDomainDefPtr virDomainDefParseNode(virConnectPtr conn,
} }
ctxt->node = root; ctxt->node = root;
def = virDomainDefParseXML(conn, caps, ctxt); def = virDomainDefParseXML(conn, caps, ctxt, flags);
cleanup: cleanup:
xmlXPathFreeContext(ctxt); xmlXPathFreeContext(ctxt);
@ -3273,7 +3283,8 @@ virDomainObjPtr virDomainLoadConfig(virConnectPtr conn,
if ((autostart = virFileLinkPointsTo(autostartLink, configFile)) < 0) if ((autostart = virFileLinkPointsTo(autostartLink, configFile)) < 0)
goto error; goto error;
if (!(def = virDomainDefParseFile(conn, caps, configFile))) if (!(def = virDomainDefParseFile(conn, caps, configFile,
VIR_DOMAIN_XML_INACTIVE)))
goto error; goto error;
if (virDomainFindByName(doms, def->name)) if (virDomainFindByName(doms, def->name))

View File

@ -526,11 +526,13 @@ virDomainDefPtr virDomainDefParseString(virConnectPtr conn,
const char *xmlStr); const char *xmlStr);
virDomainDefPtr virDomainDefParseFile(virConnectPtr conn, virDomainDefPtr virDomainDefParseFile(virConnectPtr conn,
virCapsPtr caps, virCapsPtr caps,
const char *filename); const char *filename,
int flags);
virDomainDefPtr virDomainDefParseNode(virConnectPtr conn, virDomainDefPtr virDomainDefParseNode(virConnectPtr conn,
virCapsPtr caps, virCapsPtr caps,
xmlDocPtr doc, xmlDocPtr doc,
xmlNodePtr root); xmlNodePtr root,
int flags);
#endif #endif
char *virDomainDefFormat(virConnectPtr conn, char *virDomainDefFormat(virConnectPtr conn,
virDomainDefPtr def, virDomainDefPtr def,

View File

@ -593,7 +593,8 @@ int main(int argc, char *argv[])
name)) == NULL) name)) == NULL)
goto cleanup; goto cleanup;
if ((def = virDomainDefParseFile(NULL, caps, configFile)) == NULL) if ((def = virDomainDefParseFile(NULL, caps, configFile,
VIR_DOMAIN_XML_INACTIVE)) == NULL)
goto cleanup; goto cleanup;
if (def->nnets != nveths) { if (def->nnets != nveths) {

View File

@ -1049,7 +1049,7 @@ static int lxcStartup(void)
continue; continue;
/* Try and load the live config */ /* Try and load the live config */
tmp = virDomainDefParseFile(NULL, lxc_driver->caps, config); tmp = virDomainDefParseFile(NULL, lxc_driver->caps, config, 0);
VIR_FREE(config); VIR_FREE(config);
if (tmp) { if (tmp) {
vm->newDef = vm->def; vm->newDef = vm->def;

View File

@ -504,12 +504,14 @@ static int testOpenFromFile(virConnectPtr conn,
testError(NULL, VIR_ERR_INTERNAL_ERROR, "%s", _("resolving domain filename")); testError(NULL, VIR_ERR_INTERNAL_ERROR, "%s", _("resolving domain filename"));
goto error; goto error;
} }
def = virDomainDefParseFile(conn, privconn->caps, absFile); def = virDomainDefParseFile(conn, privconn->caps, absFile,
VIR_DOMAIN_XML_INACTIVE);
VIR_FREE(absFile); VIR_FREE(absFile);
if (!def) if (!def)
goto error; goto error;
} else { } 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; goto error;
} }

View File

@ -38,7 +38,8 @@ static int testCompareXMLToArgvFiles(const char *xml,
if (virtTestLoadFile(cmd, &expectargv, MAX_FILE) < 0) if (virtTestLoadFile(cmd, &expectargv, MAX_FILE) < 0)
goto fail; goto fail;
if (!(vmdef = virDomainDefParseFile(NULL, driver.caps, xml))) if (!(vmdef = virDomainDefParseFile(NULL, driver.caps, xml,
VIR_DOMAIN_XML_INACTIVE)))
goto fail; goto fail;
memset(&vm, 0, sizeof vm); memset(&vm, 0, sizeof vm);