On Thu, Dec 04, 2008 at 02:16:06PM +0100, Daniel Veillard wrote: > On Thu, Dec 04, 2008 at 01:15:23PM +0100, Guido Günther wrote: > > On Thu, Dec 04, 2008 at 10:56:25AM +0000, Daniel P. Berrange wrote: > > > On Wed, Dec 03, 2008 at 06:20:12PM +0100, Guido G?nther wrote: > > > > On Sun, Nov 30, 2008 at 12:43:48PM +0100, Guido Günther wrote: > > > > > >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. > > > > O.k. to commit this part as a start so you can readily use it vor lxc? > > > > > > ACK, assuming 'make check' still passes. > > It does here, sure. Patch Applied now. I've added the flag to the > > functions currently needed for qemu but if nobody objects I'd like to > > add them to: > > > > virDomainDeviceDefParse > > virDomainDefParseString > > virDomainHostdevSubsysUsbDefParseXML > > virDomainDiskDefParseXML > > virDomainFSDefParseXML > > virDomainNetDefParseXML > > virDomainInputDefParseXML > > virDomainSoundDefParseXML > > virDomainHostdevDefParseXML > > virDomainChrDefParseXML > > I'm about to release an intermediate 0.5.1 release with the bug and > small improvement fixes since 0.5.0, I assume the more generic patch > can wait after that, but that sounds right to me in principle. Attached patch adds a flag parameter to the above functions and passes VIR_DOMAIN_XML_INACTIVE from the upper levels. I see two advantages in this: * symmetric interfaces to the XML parsing functions (why has virDomainDefParseFile a flags argument while virDomainDefParseString hasn't) * other drivers can use this very easily (IIRC lxc has some use for it) otherwise there's not too much gain so I'm a bit undecided if this is actually necessary. -- Guido
>From 3a0c8a73591f616bcbf0287142b3fefb240464c1 Mon Sep 17 00:00:00 2001 From: =?utf-8?q?Guido=20G=C3=BCnther?= <agx@xxxxxxxxxxx> Date: Tue, 23 Dec 2008 23:36:10 +0100 Subject: [PATCH] pass flags to all virDomain*DefParse* functions --- src/domain_conf.c | 79 +++++++++++++++++++++++++++++----------------- src/domain_conf.h | 6 ++- src/lxc_driver.c | 6 ++- src/openvz_driver.c | 6 ++- src/qemu_driver.c | 20 +++++++----- src/test.c | 13 +++++-- src/uml_driver.c | 6 ++- src/xend_internal.c | 6 ++- tests/qemuxml2xmltest.c | 3 +- 9 files changed, 93 insertions(+), 52 deletions(-) diff --git a/src/domain_conf.c b/src/domain_conf.c index f63b846..95b5736 100644 --- a/src/domain_conf.c +++ b/src/domain_conf.c @@ -534,7 +534,8 @@ int virDomainDiskCompare(virDomainDiskDefPtr a, */ static virDomainDiskDefPtr virDomainDiskDefParseXML(virConnectPtr conn, - xmlNodePtr node) { + xmlNodePtr node, + int flags ATTRIBUTE_UNUSED) { virDomainDiskDefPtr def; xmlNodePtr cur; char *type = NULL; @@ -721,7 +722,8 @@ cleanup: */ static virDomainFSDefPtr virDomainFSDefParseXML(virConnectPtr conn, - xmlNodePtr node) { + xmlNodePtr node, + int flags ATTRIBUTE_UNUSED) { virDomainFSDefPtr def; xmlNodePtr cur; char *type = NULL; @@ -807,7 +809,8 @@ cleanup: static virDomainNetDefPtr virDomainNetDefParseXML(virConnectPtr conn, virCapsPtr caps, - xmlNodePtr node) { + xmlNodePtr node, + int flags ATTRIBUTE_UNUSED) { virDomainNetDefPtr def; xmlNodePtr cur; char *macaddr = NULL; @@ -1038,7 +1041,8 @@ error: */ static virDomainChrDefPtr virDomainChrDefParseXML(virConnectPtr conn, - xmlNodePtr node) { + xmlNodePtr node, + int flags ATTRIBUTE_UNUSED) { xmlNodePtr cur; char *type = NULL; char *bindHost = NULL; @@ -1257,7 +1261,8 @@ error: static virDomainInputDefPtr virDomainInputDefParseXML(virConnectPtr conn, const char *ostype, - xmlNodePtr node) { + xmlNodePtr node, + int flags ATTRIBUTE_UNUSED) { virDomainInputDefPtr def; char *type = NULL; char *bus = NULL; @@ -1436,7 +1441,8 @@ error: static virDomainSoundDefPtr virDomainSoundDefParseXML(virConnectPtr conn, - const xmlNodePtr node) { + const xmlNodePtr node, + int flags ATTRIBUTE_UNUSED) { char *model; virDomainSoundDefPtr def; @@ -1467,7 +1473,8 @@ error: static int virDomainHostdevSubsysUsbDefParseXML(virConnectPtr conn, const xmlNodePtr node, - virDomainHostdevDefPtr def) { + virDomainHostdevDefPtr def, + int flags ATTRIBUTE_UNUSED) { int ret = -1; xmlNodePtr cur; @@ -1574,7 +1581,8 @@ out: static virDomainHostdevDefPtr virDomainHostdevDefParseXML(virConnectPtr conn, - const xmlNodePtr node) { + const xmlNodePtr node, + int flags) { xmlNodePtr cur; virDomainHostdevDefPtr def; @@ -1616,7 +1624,8 @@ virDomainHostdevDefParseXML(virConnectPtr conn, if (xmlStrEqual(cur->name, BAD_CAST "source")) { if (def->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && def->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) { - if (virDomainHostdevSubsysUsbDefParseXML(conn, cur, def) < 0) + if (virDomainHostdevSubsysUsbDefParseXML(conn, cur, + def, flags) < 0) goto error; } } else { @@ -1665,7 +1674,8 @@ static int virDomainLifecycleParseXML(virConnectPtr conn, virDomainDeviceDefPtr virDomainDeviceDefParse(virConnectPtr conn, virCapsPtr caps, const virDomainDefPtr def, - const char *xmlStr) + const char *xmlStr, + int flags) { xmlDocPtr xml; xmlNodePtr node; @@ -1692,27 +1702,28 @@ virDomainDeviceDefPtr virDomainDeviceDefParse(virConnectPtr conn, if (xmlStrEqual(node->name, BAD_CAST "disk")) { dev->type = VIR_DOMAIN_DEVICE_DISK; - if (!(dev->data.disk = virDomainDiskDefParseXML(conn, node))) + if (!(dev->data.disk = virDomainDiskDefParseXML(conn, node, flags))) goto error; } else if (xmlStrEqual(node->name, BAD_CAST "filesystem")) { dev->type = VIR_DOMAIN_DEVICE_FS; - if (!(dev->data.fs = virDomainFSDefParseXML(conn, node))) + if (!(dev->data.fs = virDomainFSDefParseXML(conn, node, flags))) goto error; } else if (xmlStrEqual(node->name, BAD_CAST "interface")) { dev->type = VIR_DOMAIN_DEVICE_NET; - if (!(dev->data.net = virDomainNetDefParseXML(conn, caps, node))) + if (!(dev->data.net = virDomainNetDefParseXML(conn, caps, node, flags))) goto error; } else if (xmlStrEqual(node->name, BAD_CAST "input")) { dev->type = VIR_DOMAIN_DEVICE_INPUT; - if (!(dev->data.input = virDomainInputDefParseXML(conn, def->os.type, node))) + if (!(dev->data.input = virDomainInputDefParseXML(conn, def->os.type, + node, flags))) goto error; } else if (xmlStrEqual(node->name, BAD_CAST "sound")) { dev->type = VIR_DOMAIN_DEVICE_SOUND; - if (!(dev->data.sound = virDomainSoundDefParseXML(conn, node))) + if (!(dev->data.sound = virDomainSoundDefParseXML(conn, node, flags))) goto error; } else if (xmlStrEqual(node->name, BAD_CAST "hostdev")) { dev->type = VIR_DOMAIN_DEVICE_HOSTDEV; - if (!(dev->data.hostdev = virDomainHostdevDefParseXML(conn, node))) + if (!(dev->data.hostdev = virDomainHostdevDefParseXML(conn, node, flags))) goto error; } else { virDomainReportError(conn, VIR_ERR_XML_ERROR, @@ -1991,8 +2002,9 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn, if (n && VIR_ALLOC_N(def->disks, n) < 0) goto no_memory; for (i = 0 ; i < n ; i++) { - virDomainDiskDefPtr disk = virDomainDiskDefParseXML(conn, - nodes[i]); + virDomainDiskDefPtr disk = virDomainDiskDefParseXML(conn, + nodes[i], + flags); if (!disk) goto error; @@ -2012,7 +2024,8 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn, goto no_memory; for (i = 0 ; i < n ; i++) { virDomainFSDefPtr fs = virDomainFSDefParseXML(conn, - nodes[i]); + nodes[i], + flags); if (!fs) goto error; @@ -2031,7 +2044,8 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn, for (i = 0 ; i < n ; i++) { virDomainNetDefPtr net = virDomainNetDefParseXML(conn, caps, - nodes[i]); + nodes[i], + flags); if (!net) goto error; @@ -2051,7 +2065,8 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn, for (i = 0 ; i < n ; i++) { virDomainChrDefPtr chr = virDomainChrDefParseXML(conn, - nodes[i]); + nodes[i], + flags); if (!chr) goto error; @@ -2070,7 +2085,8 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn, for (i = 0 ; i < n ; i++) { virDomainChrDefPtr chr = virDomainChrDefParseXML(conn, - nodes[i]); + nodes[i], + flags); if (!chr) goto error; @@ -2081,7 +2097,8 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn, if ((node = virXPathNode(conn, "./devices/console[1]", ctxt)) != NULL) { virDomainChrDefPtr chr = virDomainChrDefParseXML(conn, - node); + node, + flags); if (!chr) goto error; @@ -2119,7 +2136,8 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn, for (i = 0 ; i < n ; i++) { virDomainInputDefPtr input = virDomainInputDefParseXML(conn, def->os.type, - nodes[i]); + nodes[i], + flags); if (!input) goto error; @@ -2194,7 +2212,8 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn, for (i = 0 ; i < n ; i++) { int collision = 0, j; virDomainSoundDefPtr sound = virDomainSoundDefParseXML(conn, - nodes[i]); + nodes[i], + flags); if (!sound) goto error; @@ -2221,7 +2240,9 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn, if (n && VIR_ALLOC_N(def->hostdevs, n) < 0) goto no_memory; for (i = 0 ; i < n ; i++) { - virDomainHostdevDefPtr hostdev = virDomainHostdevDefParseXML(conn, nodes[i]); + virDomainHostdevDefPtr hostdev = virDomainHostdevDefParseXML(conn, + nodes[i], + flags); if (!hostdev) goto error; @@ -2265,7 +2286,8 @@ catchXMLError (void *ctx, const char *msg ATTRIBUTE_UNUSED, ...) virDomainDefPtr virDomainDefParseString(virConnectPtr conn, virCapsPtr caps, - const char *xmlStr) + const char *xmlStr, + int flags) { xmlParserCtxtPtr pctxt; xmlDocPtr xml = NULL; @@ -2296,8 +2318,7 @@ virDomainDefPtr virDomainDefParseString(virConnectPtr conn, goto cleanup; } - def = virDomainDefParseNode(conn, caps, xml, root, - VIR_DOMAIN_XML_INACTIVE); + def = virDomainDefParseNode(conn, caps, xml, root, flags); cleanup: xmlFreeParserCtxt (pctxt); diff --git a/src/domain_conf.h b/src/domain_conf.h index 3ad518b..7320609 100644 --- a/src/domain_conf.h +++ b/src/domain_conf.h @@ -525,10 +525,12 @@ void virDomainRemoveInactive(virDomainObjListPtr doms, virDomainDeviceDefPtr virDomainDeviceDefParse(virConnectPtr conn, virCapsPtr caps, const virDomainDefPtr def, - const char *xmlStr); + const char *xmlStr, + int flags); virDomainDefPtr virDomainDefParseString(virConnectPtr conn, virCapsPtr caps, - const char *xmlStr); + const char *xmlStr, + int flags); virDomainDefPtr virDomainDefParseFile(virConnectPtr conn, virCapsPtr caps, const char *filename, diff --git a/src/lxc_driver.c b/src/lxc_driver.c index 97e297a..13afae0 100644 --- a/src/lxc_driver.c +++ b/src/lxc_driver.c @@ -275,7 +275,8 @@ static virDomainPtr lxcDomainDefine(virConnectPtr conn, const char *xml) virDomainPtr dom = NULL; lxcDriverLock(driver); - if (!(def = virDomainDefParseString(conn, driver->caps, xml))) + if (!(def = virDomainDefParseString(conn, driver->caps, xml, + VIR_DOMAIN_XML_INACTIVE))) goto cleanup; if ((def->nets != NULL) && !(driver->have_netns)) { @@ -1002,7 +1003,8 @@ lxcDomainCreateAndStart(virConnectPtr conn, virDomainPtr dom = NULL; lxcDriverLock(driver); - if (!(def = virDomainDefParseString(conn, driver->caps, xml))) + if (!(def = virDomainDefParseString(conn, driver->caps, xml, + VIR_DOMAIN_XML_INACTIVE))) goto cleanup; if ((def->nets != NULL) && !(driver->have_netns)) { diff --git a/src/openvz_driver.c b/src/openvz_driver.c index 284ffb2..d646f58 100644 --- a/src/openvz_driver.c +++ b/src/openvz_driver.c @@ -653,7 +653,8 @@ openvzDomainDefineXML(virConnectPtr conn, const char *xml) prog[0] = NULL; openvzDriverLock(driver); - if ((vmdef = virDomainDefParseString(conn, driver->caps, xml)) == NULL) + if ((vmdef = virDomainDefParseString(conn, driver->caps, xml, + VIR_DOMAIN_XML_INACTIVE)) == NULL) goto cleanup; if (vmdef->os.init == NULL && @@ -729,7 +730,8 @@ openvzDomainCreateXML(virConnectPtr conn, const char *xml, progcreate[0] = NULL; openvzDriverLock(driver); - if ((vmdef = virDomainDefParseString(conn, driver->caps, xml)) == NULL) + if ((vmdef = virDomainDefParseString(conn, driver->caps, xml, + VIR_DOMAIN_XML_INACTIVE)) == NULL) goto cleanup; if (vmdef->os.init == NULL && diff --git a/src/qemu_driver.c b/src/qemu_driver.c index 9a12b0b..c764e3d 100644 --- a/src/qemu_driver.c +++ b/src/qemu_driver.c @@ -1698,7 +1698,8 @@ static virDomainPtr qemudDomainCreate(virConnectPtr conn, const char *xml, virDomainEventPtr event = NULL; qemuDriverLock(driver); - if (!(def = virDomainDefParseString(conn, driver->caps, xml))) + if (!(def = virDomainDefParseString(conn, driver->caps, xml, + VIR_DOMAIN_XML_INACTIVE))) goto cleanup; vm = virDomainFindByName(&driver->domains, def->name); @@ -2583,7 +2584,8 @@ static int qemudDomainRestore(virConnectPtr conn, } /* Create a domain from this XML */ - if (!(def = virDomainDefParseString(conn, driver->caps, xml))) { + if (!(def = virDomainDefParseString(conn, driver->caps, xml, + VIR_DOMAIN_XML_INACTIVE))) { qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_FAILED, "%s", _("failed to parse XML")); goto cleanup; @@ -2770,7 +2772,8 @@ static virDomainPtr qemudDomainDefine(virConnectPtr conn, const char *xml) { int newVM = 1; qemuDriverLock(driver); - if (!(def = virDomainDefParseString(conn, driver->caps, xml))) + if (!(def = virDomainDefParseString(conn, driver->caps, xml, + VIR_DOMAIN_XML_INACTIVE))) goto cleanup; vm = virDomainFindByName(&driver->domains, def->name); @@ -3232,9 +3235,8 @@ static int qemudDomainAttachDevice(virDomainPtr dom, goto cleanup; } - dev = virDomainDeviceDefParse(dom->conn, - driver->caps, - vm->def, xml); + dev = virDomainDeviceDefParse(dom->conn, driver->caps, vm->def, xml, + VIR_DOMAIN_XML_INACTIVE); qemuDriverUnlock(driver); if (dev == NULL) goto cleanup; @@ -3370,7 +3372,8 @@ static int qemudDomainDetachDevice(virDomainPtr dom, goto cleanup; } - dev = virDomainDeviceDefParse(dom->conn, driver->caps, vm->def, xml); + dev = virDomainDeviceDefParse(dom->conn, driver->caps, vm->def, xml, + VIR_DOMAIN_XML_INACTIVE); qemuDriverUnlock(driver); if (dev == NULL) goto cleanup; @@ -4006,7 +4009,8 @@ qemudDomainMigratePrepare2 (virConnectPtr dconn, } /* Parse the domain XML. */ - if (!(def = virDomainDefParseString(dconn, driver->caps, dom_xml))) { + if (!(def = virDomainDefParseString(dconn, driver->caps, dom_xml, + VIR_DOMAIN_XML_INACTIVE))) { qemudReportError (dconn, NULL, NULL, VIR_ERR_OPERATION_FAILED, "%s", _("failed to parse XML")); goto cleanup; diff --git a/src/test.c b/src/test.c index 5d23dc1..8333018 100644 --- a/src/test.c +++ b/src/test.c @@ -237,7 +237,9 @@ static int testOpenDefault(virConnectPtr conn) { privconn->nextDomID = 1; - if (!(domdef = virDomainDefParseString(conn, privconn->caps, defaultDomainXML))) + if (!(domdef = virDomainDefParseString(conn, privconn->caps, + defaultDomainXML, + VIR_DOMAIN_XML_INACTIVE))) goto error; if (!(domobj = virDomainAssignDef(conn, &privconn->domains, domdef))) { virDomainDefFree(domdef); @@ -720,7 +722,8 @@ testDomainCreateXML(virConnectPtr conn, const char *xml, virDomainObjPtr dom = NULL; testDriverLock(privconn); - if ((def = virDomainDefParseString(conn, privconn->caps, xml)) == NULL) + if ((def = virDomainDefParseString(conn, privconn->caps, xml, + VIR_DOMAIN_XML_INACTIVE)) == NULL) goto cleanup; if ((dom = virDomainAssignDef(conn, &privconn->domains, @@ -1212,7 +1215,8 @@ static int testDomainRestore(virConnectPtr conn, xml[len] = '\0'; testDriverLock(privconn); - def = virDomainDefParseString(conn, privconn->caps, xml); + def = virDomainDefParseString(conn, privconn->caps, xml, + VIR_DOMAIN_XML_INACTIVE); if (!def) goto cleanup; @@ -1492,7 +1496,8 @@ static virDomainPtr testDomainDefineXML(virConnectPtr conn, virDomainObjPtr dom = NULL; testDriverLock(privconn); - if ((def = virDomainDefParseString(conn, privconn->caps, xml)) == NULL) + if ((def = virDomainDefParseString(conn, privconn->caps, xml, + VIR_DOMAIN_XML_INACTIVE)) == NULL) goto cleanup; if ((dom = virDomainAssignDef(conn, &privconn->domains, diff --git a/src/uml_driver.c b/src/uml_driver.c index 1562042..1b70a48 100644 --- a/src/uml_driver.c +++ b/src/uml_driver.c @@ -1206,7 +1206,8 @@ static virDomainPtr umlDomainCreate(virConnectPtr conn, const char *xml, virDomainPtr dom = NULL; umlDriverLock(driver); - if (!(def = virDomainDefParseString(conn, driver->caps, xml))) + if (!(def = virDomainDefParseString(conn, driver->caps, xml, + VIR_DOMAIN_XML_INACTIVE))) goto cleanup; vm = virDomainFindByName(&driver->domains, def->name); @@ -1581,7 +1582,8 @@ static virDomainPtr umlDomainDefine(virConnectPtr conn, const char *xml) { virDomainPtr dom = NULL; umlDriverLock(driver); - if (!(def = virDomainDefParseString(conn, driver->caps, xml))) + if (!(def = virDomainDefParseString(conn, driver->caps, xml, + VIR_DOMAIN_XML_INACTIVE))) goto cleanup; if (!(vm = virDomainAssignDef(conn, diff --git a/src/xend_internal.c b/src/xend_internal.c index 39a92ff..2b15592 100644 --- a/src/xend_internal.c +++ b/src/xend_internal.c @@ -3772,7 +3772,8 @@ xenDaemonCreateXML(virConnectPtr conn, const char *xmlDesc, if (!(def = virDomainDefParseString(conn, priv->caps, - xmlDesc))) + xmlDesc, + VIR_DOMAIN_XML_INACTIVE))) return (NULL); if (!(sexpr = xenDaemonFormatSxpr(conn, def, priv->xendConfigVersion))) { @@ -4248,7 +4249,8 @@ virDomainPtr xenDaemonDomainDefineXML(virConnectPtr conn, const char *xmlDesc) { if (priv->xendConfigVersion < 3) return(NULL); - if (!(def = virDomainDefParseString(conn, priv->caps, xmlDesc))) { + if (!(def = virDomainDefParseString(conn, priv->caps, xmlDesc, + VIR_DOMAIN_XML_INACTIVE))) { virXendError(conn, VIR_ERR_XML_ERROR, "%s", _("failed to parse domain description")); return (NULL); diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 613926a..bc02b5d 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -32,7 +32,8 @@ static int testCompareXMLToXMLFiles(const char *xml) { if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0) goto fail; - if (!(vmdef = virDomainDefParseString(NULL, driver.caps, xmlData))) + if (!(vmdef = virDomainDefParseString(NULL, driver.caps, xmlData, + VIR_DOMAIN_XML_INACTIVE))) goto fail; if (!(actual = virDomainDefFormat(NULL, vmdef, 0))) -- 1.6.0.3
-- Libvir-list mailing list Libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list