[libvirt] [PATCHv3 00/27] Driver XML conf adjustment callbacks [READ FIRST]

This series implements the driver XML parsing callbacks as Dan suggested. This series may appear to be monstrous but I chose to split some patches to separate ones although the code does not compile afterwards to ease review. !! READ THIS: !! !! The patches starting with the word "fix" will need to be squashed into the !! non "fix" patches predceeding them otherwise it will not compile cleanly. This new version fixes the review comments by Dan, Michal and Laine. There's still outstanding work to do to get rid of all the irrelevant data from virCaps, but I'd like to stabilize the design before doing so. In this series the callback now supports passing opaque data to the callback functions and it's demonstrated in "virCaps: get rid of defaultDiskDriverName". There's also a patch demonstrating doing check that is not covered by the XML schema and thus shouldn't be part of the parser, but is docummented for all drivers and thus should be enforced. This demonstrates the use of the verification function. Peter Krempa (27): virCaps: conf: start splitting out irrelevat data fix fallout in src/conf/ fix fallout in src/esx fix fallout in src/lxc fix fallout in src/openvz fix fallout in src/parallels fix fallout in phyp driver fix fallout in src/qemu/ fix fallout in tests/ fix fallout in src/xen fix fallout in src/vmware fix fallout in src/uml fix fallout in test driver fix fallout in vbox driver fix fallout in aahelper code fix fallout in src/libxl fix fallout in src/xenapi fix fallout in selinux test conf: Add separate defaults addition and validation for XML parsing fix fallout from adding new parameter to internal APIs conf: Add argument to support use of the driver adjust callbacks qemu: Record the default NIC model in the domain XML fix fallout of the change of the network device default virCaps: get rid of "defaultInitPath" value in the virCaps struct virCaps: get rid of defaultDiskDriverName virCaps: get rid of emulatorRequired conf: Enforce ranges on cputune variables src/Makefile.am | 1 + src/conf/capabilities.c | 10 - src/conf/capabilities.h | 17 +- src/conf/domain_conf.c | 387 +++++++++++++++++---- src/conf/domain_conf.h | 71 +++- src/conf/snapshot_conf.c | 3 +- src/conf/snapshot_conf.h | 1 + src/esx/esx_driver.c | 14 +- src/esx/esx_private.h | 2 + src/libvirt_private.syms | 5 +- src/libxl/libxl_conf.h | 1 + src/libxl/libxl_driver.c | 57 +-- src/lxc/lxc_conf.c | 13 +- src/lxc/lxc_conf.h | 2 + src/lxc/lxc_controller.c | 7 +- src/lxc/lxc_domain.c | 26 +- src/lxc/lxc_domain.h | 3 +- src/lxc/lxc_driver.c | 49 +-- src/lxc/lxc_process.c | 9 +- src/openvz/openvz_conf.c | 5 +- src/openvz/openvz_conf.h | 1 + src/openvz/openvz_driver.c | 45 ++- src/parallels/parallels_driver.c | 12 +- src/parallels/parallels_utils.h | 1 + src/phyp/phyp_driver.c | 12 +- src/phyp/phyp_driver.h | 1 + src/qemu/qemu_capabilities.c | 3 - src/qemu/qemu_command.c | 9 +- src/qemu/qemu_command.h | 3 + src/qemu/qemu_conf.c | 14 +- src/qemu/qemu_conf.h | 5 + src/qemu/qemu_domain.c | 108 ++++-- src/qemu/qemu_domain.h | 7 +- src/qemu/qemu_driver.c | 134 ++++--- src/qemu/qemu_migration.c | 22 +- src/qemu/qemu_process.c | 109 +----- src/security/virt-aa-helper.c | 10 +- src/test/test_driver.c | 61 +++- src/uml/uml_conf.h | 1 + src/uml/uml_driver.c | 32 +- src/vbox/vbox_tmpl.c | 27 +- src/vmware/vmware_conf.c | 3 +- src/vmware/vmware_conf.h | 1 + src/vmware/vmware_driver.c | 25 +- src/xen/xen_driver.c | 8 +- src/xen/xen_driver.h | 1 + src/xen/xend_internal.c | 14 +- src/xen/xm_internal.c | 4 +- src/xenapi/xenapi_driver.c | 34 +- src/xenapi/xenapi_driver_private.h | 1 + tests/domainsnapshotxml2xmltest.c | 5 + tests/lxcxml2xmldata/lxc-hostdev.xml | 1 + tests/lxcxml2xmldata/lxc-systemd.xml | 1 + tests/lxcxml2xmltest.c | 7 +- tests/qemuargv2xmltest.c | 8 +- tests/qemumonitorjsontest.c | 29 +- tests/qemumonitortestutils.c | 4 +- tests/qemumonitortestutils.h | 5 +- .../qemuxml2argv-net-bandwidth.xml | 1 + .../qemuxml2argvdata/qemuxml2argv-net-client.args | 4 +- .../qemuxml2argv-net-eth-ifname.args | 4 +- .../qemuxml2argv-net-eth-ifname.xml | 1 + .../qemuxml2argv-net-eth-names.args | 8 +- tests/qemuxml2argvdata/qemuxml2argv-net-eth.args | 4 +- tests/qemuxml2argvdata/qemuxml2argv-net-eth.xml | 1 + .../qemuxml2argvdata/qemuxml2argv-net-hostdev.xml | 1 + tests/qemuxml2argvdata/qemuxml2argv-net-mcast.args | 4 +- .../qemuxml2argv-net-openvswitch.xml | 1 + .../qemuxml2argvdata/qemuxml2argv-net-server.args | 4 +- tests/qemuxml2argvdata/qemuxml2argv-net-user.args | 3 +- tests/qemuxml2argvdata/qemuxml2argv-net-user.xml | 1 + .../qemuxml2argv-net-virtio-network-portgroup.xml | 2 + tests/qemuxml2argvtest.c | 5 +- .../qemuxml2xmlout-graphics-spice-timeout.xml | 1 + tests/qemuxml2xmltest.c | 6 +- tests/qemuxmlnstest.c | 5 +- tests/securityselinuxlabeltest.c | 6 +- tests/testutilsqemu.c | 3 +- tests/testutilsqemu.h | 2 + tests/testutilsxen.c | 6 + tests/testutilsxen.h | 2 + tests/xmconfigtest.c | 8 +- tests/xml2sexprtest.c | 8 +- tests/xml2vmxtest.c | 8 +- 84 files changed, 1034 insertions(+), 516 deletions(-) -- 1.8.1.5

The virCaps structure gathered a ton of irrelevant data over time that. The original reason is that it was propagated to the XML parser functions. This patch aims to create a new data structure virDomainXMLConf that will contain immutable data that are used by the XML parser. This will allow two things we need: 1) Get rid of the stuff from virCaps 2) Allow us to add callbacks to check and add driver specific stuff after domain XML is parsed. This first attempt removes pointers to private data allocation functions to this new structure and update all callers and function that require them. --- Notes: Version 3: - Changed comment at the capabilities structure - virDomainXMLConfGetNamespace now returns a pointer instead of struct - use virDomainXMLPrivateDataCallbacks instead of separate pointers - even more fallout fixed in driver's I wasn't compiling originaly Version 2: - complete rewrite src/conf/capabilities.h | 8 ++---- src/conf/domain_conf.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 27 +++++++++++++++++++ 3 files changed, 100 insertions(+), 6 deletions(-) diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h index 6c67fb3..a70896a 100644 --- a/src/conf/capabilities.h +++ b/src/conf/capabilities.h @@ -160,19 +160,15 @@ struct _virCaps { size_t nguests; size_t nguests_max; virCapsGuestPtr *guests; + + /* Move to virDomainXMLConf later */ unsigned char macPrefix[VIR_MAC_PREFIX_BUFLEN]; unsigned int emulatorRequired : 1; const char *defaultDiskDriverName; int defaultDiskDriverType; /* enum virStorageFileFormat */ int (*defaultConsoleTargetType)(const char *ostype, virArch guestarch); - void *(*privateDataAllocFunc)(void); - void (*privateDataFreeFunc)(void *); - int (*privateDataXMLFormat)(virBufferPtr, void *); - int (*privateDataXMLParse)(xmlXPathContextPtr, void *); bool hasWideScsiBus; const char *defaultInitPath; - - virDomainXMLNamespace ns; }; diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 717fc20..5bec673 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -736,6 +736,77 @@ static int virDomainObjOnceInit(void) VIR_ONCE_GLOBAL_INIT(virDomainObj) + +/* This structure holds various callbacks and data needed + * while parsing and creating domain XMLs */ +struct _virDomainXMLConf { + virObject parent; + + /* domain private data management callbacks */ + virDomainXMLPrivateDataCallbacks privateData; + + /* XML namespace callbacks */ + virDomainXMLNamespace ns; + }; + + + +static virClassPtr virDomainXMLConfClass; + +static int virDomainXMLConfOnceInit(void) +{ + if (!(virDomainXMLConfClass = virClassNew(virClassForObject(), + "virDomainXMLConf", + sizeof(virDomainXMLConf), + NULL))) + return -1; + + return 0; +} + +VIR_ONCE_GLOBAL_INIT(virDomainXMLConf) + +/** + * virDomainXMLConfNew: + * + * Allocate a new domain XML configuration + */ +virDomainXMLConfPtr +virDomainXMLConfNew(virDomainXMLPrivateDataCallbacksPtr priv, + virDomainXMLNamespacePtr xmlns) +{ + virDomainXMLConfPtr xmlconf; + + if (virDomainXMLConfInitialize() < 0) + return NULL; + + if (!(xmlconf = virObjectNew(virDomainXMLConfClass))) + return NULL; + + if (priv) + xmlconf->privateData = *priv; + + if (xmlns) + xmlconf->ns = *xmlns; + + return xmlconf; +} + +/** + * virDomainXMLConfGetNamespace: + * + * @xmlconf: XML parser configuration object + * + * Returns a pointer to the stored namespace structure. + * The lifetime of the pointer is equal to @xmlconf; + */ +virDomainXMLNamespacePtr +virDomainXMLConfGetNamespace(virDomainXMLConfPtr xmlconf) +{ + return &xmlconf->ns; +} + + void virBlkioDeviceWeightArrayClear(virBlkioDeviceWeightPtr deviceWeights, int ndevices) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 2509193..da72981 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1926,6 +1926,33 @@ struct _virDomainObj { typedef struct _virDomainObjList virDomainObjList; typedef virDomainObjList *virDomainObjListPtr; + +/* This structure holds various callbacks and data needed + * while parsing and creating domain XMLs */ +typedef struct _virDomainXMLConf virDomainXMLConf; +typedef virDomainXMLConf *virDomainXMLConfPtr; + +typedef void *(*virDomainXMLPrivateDataAllocFunc)(void); +typedef void (*virDomainXMLPrivateDataFreeFunc)(void *); +typedef int (*virDomainXMLPrivateDataFormatFunc)(virBufferPtr, void *); +typedef int (*virDomainXMLPrivateDataParseFunc)(xmlXPathContextPtr, void *); + +typedef struct _virDomainXMLPrivateDataCallbacks virDomainXMLPrivateDataCallbacks; +typedef virDomainXMLPrivateDataCallbacks *virDomainXMLPrivateDataCallbacksPtr; +struct _virDomainXMLPrivateDataCallbacks { + virDomainXMLPrivateDataAllocFunc alloc; + virDomainXMLPrivateDataFreeFunc free; + virDomainXMLPrivateDataFormatFunc format; + virDomainXMLPrivateDataParseFunc parse; +}; + +virDomainXMLConfPtr +virDomainXMLConfNew(virDomainXMLPrivateDataCallbacksPtr priv, + virDomainXMLNamespacePtr xmlns); + +virDomainXMLNamespacePtr +virDomainXMLConfGetNamespace(virDomainXMLConfPtr xmlconf); + static inline bool virDomainObjIsActive(virDomainObjPtr dom) { -- 1.8.1.5

On Mon, Mar 11, 2013 at 04:06:12PM +0100, Peter Krempa wrote:
The virCaps structure gathered a ton of irrelevant data over time that. The original reason is that it was propagated to the XML parser functions.
This patch aims to create a new data structure virDomainXMLConf that will contain immutable data that are used by the XML parser. This will allow two things we need:
1) Get rid of the stuff from virCaps
2) Allow us to add callbacks to check and add driver specific stuff after domain XML is parsed.
This first attempt removes pointers to private data allocation functions to this new structure and update all callers and function that require them. ---
Notes: Version 3: - Changed comment at the capabilities structure - virDomainXMLConfGetNamespace now returns a pointer instead of struct - use virDomainXMLPrivateDataCallbacks instead of separate pointers - even more fallout fixed in driver's I wasn't compiling originaly Version 2: - complete rewrite
src/conf/capabilities.h | 8 ++---- src/conf/domain_conf.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 27 +++++++++++++++++++ 3 files changed, 100 insertions(+), 6 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 717fc20..5bec673 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -736,6 +736,77 @@ static int virDomainObjOnceInit(void)
VIR_ONCE_GLOBAL_INIT(virDomainObj)
+ +/* This structure holds various callbacks and data needed + * while parsing and creating domain XMLs */ +struct _virDomainXMLConf { + virObject parent; + + /* domain private data management callbacks */ + virDomainXMLPrivateDataCallbacks privateData; + + /* XML namespace callbacks */ + virDomainXMLNamespace ns; + }; + + + +static virClassPtr virDomainXMLConfClass; + +static int virDomainXMLConfOnceInit(void) +{ + if (!(virDomainXMLConfClass = virClassNew(virClassForObject(), + "virDomainXMLConf", + sizeof(virDomainXMLConf), + NULL))) + return -1; + + return 0; +} + +VIR_ONCE_GLOBAL_INIT(virDomainXMLConf)
We already have a VIR_ONCE_GLOBAL_INIT(virDomainObj) in this file. There is no need to have multiple global init fnuctions per file, just put all the functionality in one. ACK aside from that issue Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

--- src/conf/domain_conf.c | 104 +++++++++++++++++++++++++++++------------------ src/conf/domain_conf.h | 20 ++++++--- src/conf/snapshot_conf.c | 3 +- src/conf/snapshot_conf.h | 1 + src/libvirt_private.syms | 2 + 5 files changed, 83 insertions(+), 47 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 5bec673..127629f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -800,7 +800,7 @@ virDomainXMLConfNew(virDomainXMLPrivateDataCallbacksPtr priv, * Returns a pointer to the stored namespace structure. * The lifetime of the pointer is equal to @xmlconf; */ -virDomainXMLNamespacePtr +virDomainXMLNamespacePtr ATTRIBUTE_NONNULL(1) virDomainXMLConfGetNamespace(virDomainXMLConfPtr xmlconf) { return &xmlconf->ns; @@ -1915,8 +1915,8 @@ static void virDomainObjDispose(void *obj) virDomainSnapshotObjListFree(dom->snapshots); } - -virDomainObjPtr virDomainObjNew(virCapsPtr caps) +virDomainObjPtr ATTRIBUTE_NONNULL(1) +virDomainObjNew(virDomainXMLConfPtr xmlconf) { virDomainObjPtr domain; @@ -1926,13 +1926,12 @@ virDomainObjPtr virDomainObjNew(virCapsPtr caps) if (!(domain = virObjectLockableNew(virDomainObjClass))) return NULL; - if (caps && - caps->privateDataAllocFunc) { - if (!(domain->privateData = (caps->privateDataAllocFunc)())) { + if (xmlconf->privateData.alloc) { + if (!(domain->privateData = (xmlconf->privateData.alloc)())) { virReportOOMError(); goto error; } - domain->privateDataFreeFunc = caps->privateDataFreeFunc; + domain->privateDataFreeFunc = xmlconf->privateData.free; } if (!(domain->snapshots = virDomainSnapshotObjListNew())) @@ -1998,7 +1997,7 @@ void virDomainObjAssignDef(virDomainObjPtr domain, */ static virDomainObjPtr virDomainObjListAddLocked(virDomainObjListPtr doms, - virCapsPtr caps, + virDomainXMLConfPtr xmlconf, const virDomainDefPtr def, unsigned int flags, virDomainDefPtr *oldDef) @@ -2048,7 +2047,7 @@ virDomainObjListAddLocked(virDomainObjListPtr doms, goto error; } - if (!(vm = virDomainObjNew(caps))) + if (!(vm = virDomainObjNew(xmlconf))) goto cleanup; vm->def = def; @@ -2069,7 +2068,7 @@ error: virDomainObjPtr virDomainObjListAdd(virDomainObjListPtr doms, - virCapsPtr caps, + virDomainXMLConfPtr xmlconf, const virDomainDefPtr def, unsigned int flags, virDomainDefPtr *oldDef) @@ -2077,7 +2076,7 @@ virDomainObjPtr virDomainObjListAdd(virDomainObjListPtr doms, virDomainObjPtr ret; virObjectLock(doms); - ret = virDomainObjListAddLocked(doms, caps, def, flags, oldDef); + ret = virDomainObjListAddLocked(doms, xmlconf, def, flags, oldDef); virObjectUnlock(doms); return ret; } @@ -2096,6 +2095,7 @@ virDomainObjPtr virDomainObjListAdd(virDomainObjListPtr doms, */ int virDomainObjSetDefTransient(virCapsPtr caps, + virDomainXMLConfPtr xmlconf, virDomainObjPtr domain, bool live) { @@ -2110,7 +2110,7 @@ virDomainObjSetDefTransient(virCapsPtr caps, if (domain->newDef) return 0; - if (!(domain->newDef = virDomainDefCopy(caps, domain->def, false))) + if (!(domain->newDef = virDomainDefCopy(caps, xmlconf, domain->def, false))) goto out; ret = 0; @@ -2128,9 +2128,10 @@ out: */ virDomainDefPtr virDomainObjGetPersistentDef(virCapsPtr caps, + virDomainXMLConfPtr xmlconf, virDomainObjPtr domain) { - if (virDomainObjSetDefTransient(caps, domain, false) < 0) + if (virDomainObjSetDefTransient(caps, xmlconf, domain, false) < 0) return NULL; if (domain->newDef) @@ -2148,6 +2149,7 @@ virDomainObjGetPersistentDef(virCapsPtr caps, */ int virDomainLiveConfigHelperMethod(virCapsPtr caps, + virDomainXMLConfPtr xmlconf, virDomainObjPtr dom, unsigned int *flags, virDomainDefPtr *persistentDef) @@ -2178,7 +2180,7 @@ virDomainLiveConfigHelperMethod(virCapsPtr caps, "transient domain")); goto cleanup; } - if (!(*persistentDef = virDomainObjGetPersistentDef(caps, dom))) { + if (!(*persistentDef = virDomainObjGetPersistentDef(caps, xmlconf, dom))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Get persistent config failed")); goto cleanup; @@ -9265,8 +9267,9 @@ cleanup: } -static virDomainDefPtr +static virDomainDefPtr ATTRIBUTE_NONNULL(2) virDomainDefParseXML(virCapsPtr caps, + virDomainXMLConfPtr xmlconf, xmlDocPtr xml, xmlNodePtr root, xmlXPathContextPtr ctxt, @@ -10869,7 +10872,7 @@ virDomainDefParseXML(virCapsPtr caps, /* we have to make a copy of all of the callback pointers here since * we won't have the virCaps structure available during free */ - def->ns = caps->ns; + def->ns = xmlconf->ns; if (def->ns.parse && (def->ns.parse)(xml, root, ctxt, &def->namespaceData) < 0) @@ -10896,6 +10899,7 @@ error: static virDomainObjPtr virDomainObjParseXML(virCapsPtr caps, + virDomainXMLConfPtr xmlconf, xmlDocPtr xml, xmlXPathContextPtr ctxt, unsigned int expectedVirtTypes, @@ -10911,7 +10915,7 @@ virDomainObjParseXML(virCapsPtr caps, int state; int reason = 0; - if (!(obj = virDomainObjNew(caps))) + if (!(obj = virDomainObjNew(xmlconf))) return NULL; if (!(config = virXPathNode("./domain", ctxt))) { @@ -10922,7 +10926,7 @@ virDomainObjParseXML(virCapsPtr caps, oldnode = ctxt->node; ctxt->node = config; - obj->def = virDomainDefParseXML(caps, xml, config, ctxt, expectedVirtTypes, + obj->def = virDomainDefParseXML(caps, xmlconf, xml, config, ctxt, expectedVirtTypes, flags); ctxt->node = oldnode; if (!obj->def) @@ -10979,8 +10983,8 @@ virDomainObjParseXML(virCapsPtr caps, } VIR_FREE(nodes); - if (caps->privateDataXMLParse && - ((caps->privateDataXMLParse)(ctxt, obj->privateData)) < 0) + if (xmlconf->privateData.parse && + ((xmlconf->privateData.parse)(ctxt, obj->privateData)) < 0) goto error; return obj; @@ -10996,6 +11000,7 @@ static virDomainDefPtr virDomainDefParse(const char *xmlStr, const char *filename, virCapsPtr caps, + virDomainXMLConfPtr xmlconf, unsigned int expectedVirtTypes, unsigned int flags) { @@ -11004,7 +11009,7 @@ virDomainDefParse(const char *xmlStr, int keepBlanksDefault = xmlKeepBlanksDefault(0); if ((xml = virXMLParse(filename, xmlStr, _("(domain_definition)")))) { - def = virDomainDefParseNode(caps, xml, xmlDocGetRootElement(xml), + def = virDomainDefParseNode(caps, xmlconf, xml, xmlDocGetRootElement(xml), expectedVirtTypes, flags); xmlFreeDoc(xml); } @@ -11015,25 +11020,30 @@ virDomainDefParse(const char *xmlStr, virDomainDefPtr virDomainDefParseString(virCapsPtr caps, + virDomainXMLConfPtr xmlconf, const char *xmlStr, unsigned int expectedVirtTypes, unsigned int flags) { - return virDomainDefParse(xmlStr, NULL, caps, expectedVirtTypes, flags); + return virDomainDefParse(xmlStr, NULL, caps, xmlconf, + expectedVirtTypes, flags); } virDomainDefPtr virDomainDefParseFile(virCapsPtr caps, + virDomainXMLConfPtr xmlconf, const char *filename, unsigned int expectedVirtTypes, unsigned int flags) { - return virDomainDefParse(NULL, filename, caps, expectedVirtTypes, flags); + return virDomainDefParse(NULL, filename, caps, xmlconf, + expectedVirtTypes, flags); } virDomainDefPtr virDomainDefParseNode(virCapsPtr caps, + virDomainXMLConfPtr xmlconf, xmlDocPtr xml, xmlNodePtr root, unsigned int expectedVirtTypes, @@ -11057,7 +11067,8 @@ virDomainDefParseNode(virCapsPtr caps, } ctxt->node = root; - def = virDomainDefParseXML(caps, xml, root, ctxt, expectedVirtTypes, flags); + def = virDomainDefParseXML(caps, xmlconf, xml, root, ctxt, + expectedVirtTypes, flags); cleanup: xmlXPathFreeContext(ctxt); @@ -11067,6 +11078,7 @@ cleanup: static virDomainObjPtr virDomainObjParseNode(virCapsPtr caps, + virDomainXMLConfPtr xmlconf, xmlDocPtr xml, xmlNodePtr root, unsigned int expectedVirtTypes, @@ -11089,7 +11101,7 @@ virDomainObjParseNode(virCapsPtr caps, } ctxt->node = root; - obj = virDomainObjParseXML(caps, xml, ctxt, expectedVirtTypes, flags); + obj = virDomainObjParseXML(caps, xmlconf, xml, ctxt, expectedVirtTypes, flags); cleanup: xmlXPathFreeContext(ctxt); @@ -11099,6 +11111,7 @@ cleanup: static virDomainObjPtr virDomainObjParseFile(virCapsPtr caps, + virDomainXMLConfPtr xmlconf, const char *filename, unsigned int expectedVirtTypes, unsigned int flags) @@ -11108,7 +11121,7 @@ virDomainObjParseFile(virCapsPtr caps, int keepBlanksDefault = xmlKeepBlanksDefault(0); if ((xml = virXMLParseFile(filename))) { - obj = virDomainObjParseNode(caps, xml, + obj = virDomainObjParseNode(caps, xmlconf, xml, xmlDocGetRootElement(xml), expectedVirtTypes, flags); xmlFreeDoc(xml); @@ -15071,8 +15084,8 @@ virDomainDefFormat(virDomainDefPtr def, unsigned int flags) } -static char * -virDomainObjFormat(virCapsPtr caps, +static char * ATTRIBUTE_NONNULL(1) +virDomainObjFormat(virDomainXMLConfPtr xmlconf, virDomainObjPtr obj, unsigned int flags) { @@ -15093,8 +15106,8 @@ virDomainObjFormat(virCapsPtr caps, virDomainTaintTypeToString(i)); } - if (caps->privateDataXMLFormat && - ((caps->privateDataXMLFormat)(&buf, obj->privateData)) < 0) + if (xmlconf->privateData.format && + ((xmlconf->privateData.format)(&buf, obj->privateData)) < 0) goto error; virBufferAdjustIndent(&buf, 2); @@ -15217,7 +15230,7 @@ cleanup: } int -virDomainSaveStatus(virCapsPtr caps, +virDomainSaveStatus(virDomainXMLConfPtr xmlconf, const char *statusDir, virDomainObjPtr obj) { @@ -15229,7 +15242,7 @@ virDomainSaveStatus(virCapsPtr caps, int ret = -1; char *xml; - if (!(xml = virDomainObjFormat(caps, obj, flags))) + if (!(xml = virDomainObjFormat(xmlconf, obj, flags))) goto cleanup; if (virDomainSaveXML(statusDir, obj->def, xml)) @@ -15245,6 +15258,7 @@ cleanup: static virDomainObjPtr virDomainObjListLoadConfig(virDomainObjListPtr doms, virCapsPtr caps, + virDomainXMLConfPtr xmlconf, const char *configDir, const char *autostartDir, const char *name, @@ -15260,7 +15274,8 @@ virDomainObjListLoadConfig(virDomainObjListPtr doms, if ((configFile = virDomainConfigFile(configDir, name)) == NULL) goto error; - if (!(def = virDomainDefParseFile(caps, configFile, expectedVirtTypes, + if (!(def = virDomainDefParseFile(caps, xmlconf, configFile, + expectedVirtTypes, VIR_DOMAIN_XML_INACTIVE))) goto error; @@ -15270,7 +15285,7 @@ virDomainObjListLoadConfig(virDomainObjListPtr doms, if ((autostart = virFileLinkPointsTo(autostartLink, configFile)) < 0) goto error; - if (!(dom = virDomainObjListAddLocked(doms, caps, def, 0, &oldDef))) + if (!(dom = virDomainObjListAddLocked(doms, xmlconf, def, 0, &oldDef))) goto error; dom->autostart = autostart; @@ -15293,6 +15308,7 @@ error: static virDomainObjPtr virDomainObjListLoadStatus(virDomainObjListPtr doms, virCapsPtr caps, + virDomainXMLConfPtr xmlconf, const char *statusDir, const char *name, unsigned int expectedVirtTypes, @@ -15306,7 +15322,7 @@ virDomainObjListLoadStatus(virDomainObjListPtr doms, if ((statusFile = virDomainConfigFile(statusDir, name)) == NULL) goto error; - if (!(obj = virDomainObjParseFile(caps, statusFile, expectedVirtTypes, + if (!(obj = virDomainObjParseFile(caps, xmlconf, statusFile, expectedVirtTypes, VIR_DOMAIN_XML_INTERNAL_STATUS | VIR_DOMAIN_XML_INTERNAL_ACTUAL_NET | VIR_DOMAIN_XML_INTERNAL_PCI_ORIG_STATES))) @@ -15339,6 +15355,7 @@ error: int virDomainObjListLoadAllConfigs(virDomainObjListPtr doms, virCapsPtr caps, + virDomainXMLConfPtr xmlconf, const char *configDir, const char *autostartDir, int liveStatus, @@ -15377,6 +15394,7 @@ virDomainObjListLoadAllConfigs(virDomainObjListPtr doms, if (liveStatus) dom = virDomainObjListLoadStatus(doms, caps, + xmlconf, configDir, entry->d_name, expectedVirtTypes, @@ -15385,6 +15403,7 @@ virDomainObjListLoadAllConfigs(virDomainObjListPtr doms, else dom = virDomainObjListLoadConfig(doms, caps, + xmlconf, configDir, autostartDir, entry->d_name, @@ -15780,7 +15799,10 @@ cleanup: * persistent and active, true for transitions across save files or * snapshots). */ virDomainDefPtr -virDomainDefCopy(virCapsPtr caps, virDomainDefPtr src, bool migratable) +virDomainDefCopy(virCapsPtr caps, + virDomainXMLConfPtr xmlconf, + virDomainDefPtr src, + bool migratable) { char *xml; virDomainDefPtr ret; @@ -15794,19 +15816,21 @@ virDomainDefCopy(virCapsPtr caps, virDomainDefPtr src, bool migratable) if (!(xml = virDomainDefFormat(src, write_flags))) return NULL; - ret = virDomainDefParseString(caps, xml, -1, read_flags); + ret = virDomainDefParseString(caps, xmlconf, xml, -1, read_flags); VIR_FREE(xml); return ret; } virDomainDefPtr -virDomainObjCopyPersistentDef(virCapsPtr caps, virDomainObjPtr dom) +virDomainObjCopyPersistentDef(virCapsPtr caps, + virDomainXMLConfPtr xmlconf, + virDomainObjPtr dom) { virDomainDefPtr cur; - cur = virDomainObjGetPersistentDef(caps, dom); - return virDomainDefCopy(caps, cur, false); + cur = virDomainObjGetPersistentDef(caps, xmlconf, dom); + return virDomainDefCopy(caps, xmlconf, cur, false); } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index da72981..8b17f1e 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1959,7 +1959,7 @@ virDomainObjIsActive(virDomainObjPtr dom) return dom->def->id != -1; } -virDomainObjPtr virDomainObjNew(virCapsPtr caps); +virDomainObjPtr virDomainObjNew(virDomainXMLConfPtr caps); virDomainObjListPtr virDomainObjListNew(void); @@ -2034,7 +2034,7 @@ enum { VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE = (1 << 1), }; virDomainObjPtr virDomainObjListAdd(virDomainObjListPtr doms, - virCapsPtr caps, + virDomainXMLConfPtr xmlconf, const virDomainDefPtr def, unsigned int flags, virDomainDefPtr *oldDef); @@ -2043,22 +2043,26 @@ void virDomainObjAssignDef(virDomainObjPtr domain, bool live, virDomainDefPtr *oldDef); int virDomainObjSetDefTransient(virCapsPtr caps, + virDomainXMLConfPtr xmlconf, virDomainObjPtr domain, bool live); virDomainDefPtr virDomainObjGetPersistentDef(virCapsPtr caps, + virDomainXMLConfPtr xmlconf, virDomainObjPtr domain); int virDomainLiveConfigHelperMethod(virCapsPtr caps, + virDomainXMLConfPtr xmlconf, virDomainObjPtr dom, unsigned int *flags, virDomainDefPtr *persistentDef); -virDomainDefPtr virDomainDefCopy(virCapsPtr caps, virDomainDefPtr src, - bool migratable); +virDomainDefPtr virDomainDefCopy(virCapsPtr caps, virDomainXMLConfPtr xmlconf, + virDomainDefPtr src, bool migratable); virDomainDefPtr -virDomainObjCopyPersistentDef(virCapsPtr caps, virDomainObjPtr dom); +virDomainObjCopyPersistentDef(virCapsPtr caps, virDomainXMLConfPtr xmlconf, + virDomainObjPtr dom); void virDomainObjListRemove(virDomainObjListPtr doms, virDomainObjPtr dom); @@ -2068,14 +2072,17 @@ virDomainDeviceDefPtr virDomainDeviceDefParse(virCapsPtr caps, const char *xmlStr, unsigned int flags); virDomainDefPtr virDomainDefParseString(virCapsPtr caps, + virDomainXMLConfPtr xmlconf, const char *xmlStr, unsigned int expectedVirtTypes, unsigned int flags); virDomainDefPtr virDomainDefParseFile(virCapsPtr caps, + virDomainXMLConfPtr xmlconf, const char *filename, unsigned int expectedVirtTypes, unsigned int flags); virDomainDefPtr virDomainDefParseNode(virCapsPtr caps, + virDomainXMLConfPtr xmlconf, xmlDocPtr doc, xmlNodePtr root, unsigned int expectedVirtTypes, @@ -2192,7 +2199,7 @@ int virDomainSaveXML(const char *configDir, int virDomainSaveConfig(const char *configDir, virDomainDefPtr def); -int virDomainSaveStatus(virCapsPtr caps, +int virDomainSaveStatus(virDomainXMLConfPtr xmlconf, const char *statusDir, virDomainObjPtr obj) ATTRIBUTE_RETURN_CHECK; @@ -2202,6 +2209,7 @@ typedef void (*virDomainLoadConfigNotify)(virDomainObjPtr dom, int virDomainObjListLoadAllConfigs(virDomainObjListPtr doms, virCapsPtr caps, + virDomainXMLConfPtr xmlconf, const char *configDir, const char *autostartDir, int liveStatus, diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index fe77bd0..1154202 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -169,6 +169,7 @@ cleanup: virDomainSnapshotDefPtr virDomainSnapshotDefParseString(const char *xmlStr, virCapsPtr caps, + virDomainXMLConfPtr xmlconf, unsigned int expectedVirtTypes, unsigned int flags) { @@ -263,7 +264,7 @@ virDomainSnapshotDefParseString(const char *xmlStr, _("missing domain in snapshot")); goto cleanup; } - def->dom = virDomainDefParseNode(caps, xml, domainNode, + def->dom = virDomainDefParseNode(caps, xmlconf, xml, domainNode, expectedVirtTypes, (VIR_DOMAIN_XML_INACTIVE | VIR_DOMAIN_XML_SECURE)); diff --git a/src/conf/snapshot_conf.h b/src/conf/snapshot_conf.h index f1d5995..e8bd24a 100644 --- a/src/conf/snapshot_conf.h +++ b/src/conf/snapshot_conf.h @@ -101,6 +101,7 @@ typedef enum { virDomainSnapshotDefPtr virDomainSnapshotDefParseString(const char *xmlStr, virCapsPtr caps, + virDomainXMLConfPtr xmlconf, unsigned int expectedVirtTypes, unsigned int flags); void virDomainSnapshotDefFree(virDomainSnapshotDefPtr def); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 599b71e..c9995d7 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -342,6 +342,8 @@ virDomainWatchdogActionTypeFromString; virDomainWatchdogActionTypeToString; virDomainWatchdogModelTypeFromString; virDomainWatchdogModelTypeToString; +virDomainXMLConfGetNamespace; +virDomainXMLConfNew; # conf/domain_event.h -- 1.8.1.5

On Mon, Mar 11, 2013 at 04:06:13PM +0100, Peter Krempa wrote:
--- src/conf/domain_conf.c | 104 +++++++++++++++++++++++++++++------------------ src/conf/domain_conf.h | 20 ++++++--- src/conf/snapshot_conf.c | 3 +- src/conf/snapshot_conf.h | 1 + src/libvirt_private.syms | 2 + 5 files changed, 83 insertions(+), 47 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 5bec673..127629f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -800,7 +800,7 @@ virDomainXMLConfNew(virDomainXMLPrivateDataCallbacksPtr priv, * Returns a pointer to the stored namespace structure. * The lifetime of the pointer is equal to @xmlconf; */ -virDomainXMLNamespacePtr +virDomainXMLNamespacePtr ATTRIBUTE_NONNULL(1)
Any ATTRIBUTE_XXXX statement should be against the function *declaration* in the header, not the implementation, unless it is a static function.
virDomainXMLConfGetNamespace(virDomainXMLConfPtr xmlconf) { return &xmlconf->ns; @@ -1915,8 +1915,8 @@ static void virDomainObjDispose(void *obj) virDomainSnapshotObjListFree(dom->snapshots); }
- -virDomainObjPtr virDomainObjNew(virCapsPtr caps) +virDomainObjPtr ATTRIBUTE_NONNULL(1)
Likewise
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 599b71e..c9995d7 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -342,6 +342,8 @@ virDomainWatchdogActionTypeFromString; virDomainWatchdogActionTypeToString; virDomainWatchdogModelTypeFromString; virDomainWatchdogModelTypeToString; +virDomainXMLConfGetNamespace; +virDomainXMLConfNew;
These functions were added in the previous patch Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

--- src/esx/esx_driver.c | 14 ++++++++++---- src/esx/esx_private.h | 2 ++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index 046035d..fc8a3ae 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -71,6 +71,7 @@ esxFreePrivate(esxPrivate **priv) esxVI_Context_Free(&(*priv)->vCenter); esxUtil_FreeParsedUri(&(*priv)->parsedUri); virObjectUnref((*priv)->caps); + virObjectUnref((*priv)->xmlconf); VIR_FREE(*priv); } @@ -1099,6 +1100,9 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, goto cleanup; } + if (!(priv->xmlconf = virDomainXMLConfNew(NULL, NULL))) + goto cleanup; + conn->privateData = priv; priv = NULL; result = VIR_DRV_OPEN_SUCCESS; @@ -2883,8 +2887,8 @@ esxDomainXMLToNative(virConnectPtr conn, const char *nativeFormat, return NULL; } - def = virDomainDefParseString(priv->caps, domainXml, - 1 << VIR_DOMAIN_VIRT_VMWARE, 0); + def = virDomainDefParseString(priv->caps, priv->xmlconf, + domainXml, 1 << VIR_DOMAIN_VIRT_VMWARE, 0); if (def == NULL) { return NULL; @@ -3099,7 +3103,8 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml) } /* Parse domain XML */ - def = virDomainDefParseString(priv->caps, xml, 1 << VIR_DOMAIN_VIRT_VMWARE, + def = virDomainDefParseString(priv->caps, priv->xmlconf, + xml, 1 << VIR_DOMAIN_VIRT_VMWARE, VIR_DOMAIN_XML_INACTIVE); if (def == NULL) { @@ -4270,7 +4275,8 @@ esxDomainSnapshotCreateXML(virDomainPtr domain, const char *xmlDesc, return NULL; } - def = virDomainSnapshotDefParseString(xmlDesc, NULL, 0, 0); + def = virDomainSnapshotDefParseString(xmlDesc, priv->caps, + priv->xmlconf, 0, 0); if (def == NULL) { return NULL; diff --git a/src/esx/esx_private.h b/src/esx/esx_private.h index f1e7adf..2973130 100644 --- a/src/esx/esx_private.h +++ b/src/esx/esx_private.h @@ -26,6 +26,7 @@ # include "internal.h" # include "virerror.h" # include "capabilities.h" +# include "domain_conf.h" # include "esx_vi.h" typedef struct _esxPrivate { @@ -34,6 +35,7 @@ typedef struct _esxPrivate { esxVI_Context *vCenter; esxUtil_ParsedUri *parsedUri; virCapsPtr caps; + virDomainXMLConfPtr xmlconf; int32_t maxVcpus; esxVI_Boolean supportsVMotion; esxVI_Boolean supportsLongMode; /* aka x86_64 */ -- 1.8.1.5

On Mon, Mar 11, 2013 at 04:06:14PM +0100, Peter Krempa wrote:
--- src/esx/esx_driver.c | 14 ++++++++++---- src/esx/esx_private.h | 2 ++ 2 files changed, 12 insertions(+), 4 deletions(-)
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

--- src/Makefile.am | 1 + src/lxc/lxc_conf.c | 8 ++++++++ src/lxc/lxc_conf.h | 2 ++ src/lxc/lxc_controller.c | 7 ++++++- src/lxc/lxc_domain.c | 13 ++++++------- src/lxc/lxc_domain.h | 2 +- src/lxc/lxc_driver.c | 43 ++++++++++++++++++++++++------------------- src/lxc/lxc_process.c | 9 +++++---- 8 files changed, 53 insertions(+), 32 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index c1659a4..60935f4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -493,6 +493,7 @@ LXC_CONTROLLER_SOURCES = \ lxc/lxc_conf.c lxc/lxc_conf.h \ lxc/lxc_container.c lxc/lxc_container.h \ lxc/lxc_cgroup.c lxc/lxc_cgroup.h \ + lxc/lxc_domain.c lxc/lxc_domain.h \ lxc/lxc_fuse.c lxc/lxc_fuse.h \ lxc/lxc_controller.c diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c index 7b808e7..c723e77 100644 --- a/src/lxc/lxc_conf.c +++ b/src/lxc/lxc_conf.c @@ -27,6 +27,7 @@ #include <config.h> #include "lxc_conf.h" +#include "lxc_domain.h" #include "nodeinfo.h" #include "virerror.h" #include "virconf.h" @@ -154,6 +155,13 @@ error: return NULL; } + +virDomainXMLConfPtr +lxcDomainXMLConfInit(void) +{ + return virDomainXMLConfNew(&virLXCDriverPrivateDataCallbacks, NULL); +} + int lxcLoadDriverConfig(virLXCDriverPtr driver) { char *filename; diff --git a/src/lxc/lxc_conf.h b/src/lxc/lxc_conf.h index 2649cd6..b46dc32 100644 --- a/src/lxc/lxc_conf.h +++ b/src/lxc/lxc_conf.h @@ -51,6 +51,7 @@ struct _virLXCDriver { virMutex lock; virCapsPtr caps; + virDomainXMLConfPtr xmlconf; virCgroupPtr cgroup; @@ -83,6 +84,7 @@ struct _virLXCDriver { int lxcLoadDriverConfig(virLXCDriverPtr driver); virCapsPtr lxcCapsInit(virLXCDriverPtr driver); +virDomainXMLConfPtr lxcDomainXMLConfInit(void); static inline void lxcDriverLock(virLXCDriverPtr driver) { diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index ce46070..50967f3 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -151,6 +151,7 @@ static virLXCControllerPtr virLXCControllerNew(const char *name) { virLXCControllerPtr ctrl = NULL; virCapsPtr caps = NULL; + virDomainXMLConfPtr xmlconf = NULL; char *configFile = NULL; if (VIR_ALLOC(ctrl) < 0) @@ -165,11 +166,14 @@ static virLXCControllerPtr virLXCControllerNew(const char *name) if ((caps = lxcCapsInit(NULL)) == NULL) goto error; + if (!(xmlconf = lxcDomainXMLConfInit())) + goto error; + if ((configFile = virDomainConfigFile(LXC_STATE_DIR, ctrl->name)) == NULL) goto error; - if ((ctrl->def = virDomainDefParseFile(caps, + if ((ctrl->def = virDomainDefParseFile(caps, xmlconf, configFile, 1 << VIR_DOMAIN_VIRT_LXC, 0)) == NULL) @@ -183,6 +187,7 @@ static virLXCControllerPtr virLXCControllerNew(const char *name) cleanup: VIR_FREE(configFile); virObjectUnref(caps); + virObjectUnref(xmlconf); return ctrl; no_memory: diff --git a/src/lxc/lxc_domain.c b/src/lxc/lxc_domain.c index 1b02aa5..08cf8f6 100644 --- a/src/lxc/lxc_domain.c +++ b/src/lxc/lxc_domain.c @@ -73,10 +73,9 @@ static int virLXCDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, void *data) return 0; } -void virLXCDomainSetPrivateDataHooks(virCapsPtr caps) -{ - caps->privateDataAllocFunc = virLXCDomainObjPrivateAlloc; - caps->privateDataFreeFunc = virLXCDomainObjPrivateFree; - caps->privateDataXMLFormat = virLXCDomainObjPrivateXMLFormat; - caps->privateDataXMLParse = virLXCDomainObjPrivateXMLParse; -} +virDomainXMLPrivateDataCallbacks virLXCDriverPrivateDataCallbacks = { + .alloc = virLXCDomainObjPrivateAlloc, + .free = virLXCDomainObjPrivateFree, + .format = virLXCDomainObjPrivateXMLFormat, + .parse = virLXCDomainObjPrivateXMLParse, +}; diff --git a/src/lxc/lxc_domain.h b/src/lxc/lxc_domain.h index 882f34a..007ea84 100644 --- a/src/lxc/lxc_domain.h +++ b/src/lxc/lxc_domain.h @@ -38,6 +38,6 @@ struct _virLXCDomainObjPrivate { pid_t initpid; }; -void virLXCDomainSetPrivateDataHooks(virCapsPtr caps); +extern virDomainXMLPrivateDataCallbacks virLXCDriverPrivateDataCallbacks; #endif /* __LXC_DOMAIN_H__ */ diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index f136df2..59bb786 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -413,7 +413,7 @@ static virDomainPtr lxcDomainDefine(virConnectPtr conn, const char *xml) virDomainDefPtr oldDef = NULL; lxcDriverLock(driver); - if (!(def = virDomainDefParseString(driver->caps, xml, + if (!(def = virDomainDefParseString(driver->caps, driver->xmlconf, xml, 1 << VIR_DOMAIN_VIRT_LXC, VIR_DOMAIN_XML_INACTIVE))) goto cleanup; @@ -428,7 +428,7 @@ static virDomainPtr lxcDomainDefine(virConnectPtr conn, const char *xml) } if (!(vm = virDomainObjListAdd(driver->domains, - driver->caps, + driver->xmlconf, def, 0, &oldDef))) @@ -1069,7 +1069,7 @@ lxcDomainCreateAndStart(virConnectPtr conn, virCheckFlags(VIR_DOMAIN_START_AUTODESTROY, NULL); lxcDriverLock(driver); - if (!(def = virDomainDefParseString(driver->caps, xml, + if (!(def = virDomainDefParseString(driver->caps, driver->xmlconf, xml, 1 << VIR_DOMAIN_VIRT_LXC, VIR_DOMAIN_XML_INACTIVE))) goto cleanup; @@ -1085,7 +1085,7 @@ lxcDomainCreateAndStart(virConnectPtr conn, if (!(vm = virDomainObjListAdd(driver->domains, - driver->caps, + driver->xmlconf, def, VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, NULL))) @@ -1472,7 +1472,8 @@ static int lxcStartup(bool privileged, if ((lxc_driver->caps = lxcCapsInit(lxc_driver)) == NULL) goto cleanup; - virLXCDomainSetPrivateDataHooks(lxc_driver->caps); + if (!(lxc_driver->xmlconf = lxcDomainXMLConfInit())) + goto cleanup; if (virLXCProcessAutoDestroyInit(lxc_driver) < 0) goto cleanup; @@ -1480,6 +1481,7 @@ static int lxcStartup(bool privileged, /* Get all the running persistent or transient configs first */ if (virDomainObjListLoadAllConfigs(lxc_driver->domains, lxc_driver->caps, + lxc_driver->xmlconf, lxc_driver->stateDir, NULL, 1, 1 << VIR_DOMAIN_VIRT_LXC, @@ -1491,6 +1493,7 @@ static int lxcStartup(bool privileged, /* Then inactive persistent configs */ if (virDomainObjListLoadAllConfigs(lxc_driver->domains, lxc_driver->caps, + lxc_driver->xmlconf, lxc_driver->configDir, lxc_driver->autostartDir, 0, 1 << VIR_DOMAIN_VIRT_LXC, @@ -1538,6 +1541,7 @@ lxcReload(void) { lxcDriverLock(lxc_driver); virDomainObjListLoadAllConfigs(lxc_driver->domains, lxc_driver->caps, + lxc_driver->xmlconf, lxc_driver->configDir, lxc_driver->autostartDir, 0, 1 << VIR_DOMAIN_VIRT_LXC, @@ -1561,6 +1565,7 @@ static int lxcShutdown(void) virObjectUnref(lxc_driver->caps); virObjectUnref(lxc_driver->securityManager); + virObjectUnref(lxc_driver->xmlconf); VIR_FREE(lxc_driver->configDir); VIR_FREE(lxc_driver->autostartDir); VIR_FREE(lxc_driver->stateDir); @@ -1782,13 +1787,13 @@ lxcSetSchedulerParametersFlags(virDomainPtr dom, goto cleanup; } - if (virDomainLiveConfigHelperMethod(driver->caps, vm, &flags, - &vmdef) < 0) + if (virDomainLiveConfigHelperMethod(driver->caps, driver->xmlconf, + vm, &flags, &vmdef) < 0) goto cleanup; if (flags & VIR_DOMAIN_AFFECT_CONFIG) { /* Make a copy for updated domain. */ - vmdef = virDomainObjCopyPersistentDef(driver->caps, vm); + vmdef = virDomainObjCopyPersistentDef(driver->caps, driver->xmlconf, vm); if (!vmdef) goto cleanup; } @@ -1854,7 +1859,7 @@ lxcSetSchedulerParametersFlags(virDomainPtr dom, } } - if (virDomainSaveStatus(driver->caps, driver->stateDir, vm) < 0) + if (virDomainSaveStatus(driver->xmlconf, driver->stateDir, vm) < 0) goto cleanup; @@ -1924,8 +1929,8 @@ lxcGetSchedulerParametersFlags(virDomainPtr dom, goto cleanup; } - if (virDomainLiveConfigHelperMethod(driver->caps, vm, &flags, - &persistentDef) < 0) + if (virDomainLiveConfigHelperMethod(driver->caps, driver->xmlconf, + vm, &flags, &persistentDef) < 0) goto cleanup; if (flags & VIR_DOMAIN_AFFECT_CONFIG) { @@ -2037,8 +2042,8 @@ lxcDomainSetBlkioParameters(virDomainPtr dom, goto cleanup; } - if (virDomainLiveConfigHelperMethod(driver->caps, vm, &flags, - &persistentDef) < 0) + if (virDomainLiveConfigHelperMethod(driver->caps, driver->xmlconf, + vm, &flags, &persistentDef) < 0) goto cleanup; if (flags & VIR_DOMAIN_AFFECT_LIVE) { @@ -2142,8 +2147,8 @@ lxcDomainGetBlkioParameters(virDomainPtr dom, goto cleanup; } - if (virDomainLiveConfigHelperMethod(driver->caps, vm, &flags, - &persistentDef) < 0) + if (virDomainLiveConfigHelperMethod(driver->caps, driver->xmlconf, + vm, &flags, &persistentDef) < 0) goto cleanup; if (flags & VIR_DOMAIN_AFFECT_LIVE) { @@ -2508,7 +2513,7 @@ static int lxcDomainSuspend(virDomainPtr dom) VIR_DOMAIN_EVENT_SUSPENDED_PAUSED); } - if (virDomainSaveStatus(driver->caps, driver->stateDir, vm) < 0) + if (virDomainSaveStatus(driver->xmlconf, driver->stateDir, vm) < 0) goto cleanup; ret = 0; @@ -2574,7 +2579,7 @@ static int lxcDomainResume(virDomainPtr dom) VIR_DOMAIN_EVENT_RESUMED_UNPAUSED); } - if (virDomainSaveStatus(driver->caps, driver->stateDir, vm) < 0) + if (virDomainSaveStatus(driver->xmlconf, driver->stateDir, vm) < 0) goto cleanup; ret = 0; @@ -4353,7 +4358,7 @@ lxcDomainModifyDeviceFlags(virDomainPtr dom, const char *xml, goto cleanup; /* Make a copy for updated domain. */ - vmdef = virDomainObjCopyPersistentDef(driver->caps, vm); + vmdef = virDomainObjCopyPersistentDef(driver->caps, driver->xmlconf, vm); if (!vmdef) goto cleanup; switch (action) { @@ -4401,7 +4406,7 @@ lxcDomainModifyDeviceFlags(virDomainPtr dom, const char *xml, * changed even if we failed to attach the device. For example, * a new controller may be created. */ - if (virDomainSaveStatus(driver->caps, driver->stateDir, vm) < 0) { + if (virDomainSaveStatus(driver->xmlconf, driver->stateDir, vm) < 0) { ret = -1; goto cleanup; } diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index d96c69c..cad6402 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -682,7 +682,7 @@ static void virLXCProcessMonitorInitNotify(virLXCMonitorPtr mon ATTRIBUTE_UNUSED } virDomainAuditInit(vm, initpid, inode); - if (virDomainSaveStatus(lxc_driver->caps, lxc_driver->stateDir, vm) < 0) + if (virDomainSaveStatus(lxc_driver->xmlconf, lxc_driver->stateDir, vm) < 0) VIR_WARN("Cannot update XML with PID for LXC %s", vm->def->name); } @@ -1043,7 +1043,7 @@ int virLXCProcessStart(virConnectPtr conn, * report implicit runtime defaults in the XML, like vnc listen/socket */ VIR_DEBUG("Setting current domain def as transient"); - if (virDomainObjSetDefTransient(driver->caps, vm, true) < 0) + if (virDomainObjSetDefTransient(driver->caps, driver->xmlconf, vm, true) < 0) goto cleanup; /* Run an early hook to set-up missing devices */ @@ -1241,7 +1241,8 @@ int virLXCProcessStart(virConnectPtr conn, virLXCProcessAutoDestroyAdd(driver, vm, conn) < 0) goto error; - if (virDomainObjSetDefTransient(driver->caps, vm, false) < 0) + if (virDomainObjSetDefTransient(driver->caps, driver->xmlconf, + vm, false) < 0) goto error; /* Write domain status to disk. @@ -1250,7 +1251,7 @@ int virLXCProcessStart(virConnectPtr conn, * location for the benefit of libvirt_lxc. We're now overwriting * it with the live status XML instead. This is a (currently * harmless) inconsistency we should fix one day */ - if (virDomainSaveStatus(driver->caps, driver->stateDir, vm) < 0) + if (virDomainSaveStatus(driver->xmlconf, driver->stateDir, vm) < 0) goto error; /* finally we can call the 'started' hook script if any */ -- 1.8.1.5

On Mon, Mar 11, 2013 at 04:06:15PM +0100, Peter Krempa wrote:
--- src/Makefile.am | 1 + src/lxc/lxc_conf.c | 8 ++++++++ src/lxc/lxc_conf.h | 2 ++ src/lxc/lxc_controller.c | 7 ++++++- src/lxc/lxc_domain.c | 13 ++++++------- src/lxc/lxc_domain.h | 2 +- src/lxc/lxc_driver.c | 43 ++++++++++++++++++++++++------------------- src/lxc/lxc_process.c | 9 +++++---- 8 files changed, 53 insertions(+), 32 deletions(-)
ACK
diff --git a/src/lxc/lxc_domain.h b/src/lxc/lxc_domain.h index 882f34a..007ea84 100644 --- a/src/lxc/lxc_domain.h +++ b/src/lxc/lxc_domain.h @@ -38,6 +38,6 @@ struct _virLXCDomainObjPrivate { pid_t initpid; };
-void virLXCDomainSetPrivateDataHooks(virCapsPtr caps); +extern virDomainXMLPrivateDataCallbacks virLXCDriverPrivateDataCallbacks;
Do we need a policy on use of 'extern' ? Almost none of our header files use it, so I think we should just delete it from those few which do and forbid it. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

--- src/openvz/openvz_conf.c | 3 ++- src/openvz/openvz_conf.h | 1 + src/openvz/openvz_driver.c | 16 ++++++++++------ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index fde32ce..f175655 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -558,6 +558,7 @@ openvzFreeDriver(struct openvz_driver *driver) if (!driver) return; + virObjectUnref(driver->xmlconf); virObjectUnref(driver->domains); virObjectUnref(driver->caps); VIR_FREE(driver); @@ -648,7 +649,7 @@ int openvzLoadDomains(struct openvz_driver *driver) { flags |= VIR_DOMAIN_OBJ_LIST_ADD_LIVE; if (!(dom = virDomainObjListAdd(driver->domains, - driver->caps, + driver->xmlconf, def, flags, NULL))) diff --git a/src/openvz/openvz_conf.h b/src/openvz/openvz_conf.h index d7f21b3..a030b42 100644 --- a/src/openvz/openvz_conf.h +++ b/src/openvz/openvz_conf.h @@ -45,6 +45,7 @@ struct openvz_driver { virMutex lock; virCapsPtr caps; + virDomainXMLConfPtr xmlconf; virDomainObjListPtr domains; int version; }; diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 3865206..67d66ae 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -955,8 +955,8 @@ openvzDomainDefineXML(virConnectPtr conn, const char *xml) virDomainPtr dom = NULL; openvzDriverLock(driver); - if ((vmdef = virDomainDefParseString(driver->caps, xml, - 1 << VIR_DOMAIN_VIRT_OPENVZ, + if ((vmdef = virDomainDefParseString(driver->caps, driver->xmlconf, + xml, 1 << VIR_DOMAIN_VIRT_OPENVZ, VIR_DOMAIN_XML_INACTIVE)) == NULL) goto cleanup; @@ -968,7 +968,7 @@ openvzDomainDefineXML(virConnectPtr conn, const char *xml) goto cleanup; } if (!(vm = virDomainObjListAdd(driver->domains, - driver->caps, + driver->xmlconf, vmdef, 0, NULL))) goto cleanup; vmdef = NULL; @@ -1042,8 +1042,8 @@ openvzDomainCreateXML(virConnectPtr conn, const char *xml, virCheckFlags(0, NULL); openvzDriverLock(driver); - if ((vmdef = virDomainDefParseString(driver->caps, xml, - 1 << VIR_DOMAIN_VIRT_OPENVZ, + if ((vmdef = virDomainDefParseString(driver->caps, driver->xmlconf, + xml, 1 << VIR_DOMAIN_VIRT_OPENVZ, VIR_DOMAIN_XML_INACTIVE)) == NULL) goto cleanup; @@ -1055,7 +1055,7 @@ openvzDomainCreateXML(virConnectPtr conn, const char *xml, goto cleanup; } if (!(vm = virDomainObjListAdd(driver->domains, - driver->caps, + driver->xmlconf, vmdef, VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, NULL))) @@ -1453,6 +1453,9 @@ static virDrvOpenStatus openvzOpen(virConnectPtr conn, if (!(driver->caps = openvzCapsInit())) goto cleanup; + if (!(driver->xmlconf = virDomainXMLConfNew(NULL, NULL))) + goto cleanup; + if (openvzLoadDomains(driver) < 0) goto cleanup; @@ -2076,6 +2079,7 @@ openvzDomainUpdateDeviceFlags(virDomainPtr dom, const char *xml, } if (virDomainLiveConfigHelperMethod(driver->caps, + driver->xmlconf, vm, &flags, &vmdef) < 0) -- 1.8.1.5

On Mon, Mar 11, 2013 at 04:06:16PM +0100, Peter Krempa wrote:
--- src/openvz/openvz_conf.c | 3 ++- src/openvz/openvz_conf.h | 1 + src/openvz/openvz_driver.c | 16 ++++++++++------ 3 files changed, 13 insertions(+), 7 deletions(-)
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

--- src/parallels/parallels_driver.c | 12 ++++++++---- src/parallels/parallels_utils.h | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c index 8f8fdac..88f41f7 100644 --- a/src/parallels/parallels_driver.c +++ b/src/parallels/parallels_driver.c @@ -831,7 +831,7 @@ parallelsLoadDomain(parallelsConnPtr privconn, virJSONValuePtr jobj) goto cleanup; if (!(dom = virDomainObjListAdd(privconn->domains, - privconn->caps, + privconn->xmlconf, def, 0, NULL))) goto cleanup; /* dom is locked here */ @@ -929,6 +929,9 @@ parallelsOpenDefault(virConnectPtr conn) if (!(privconn->caps = parallelsBuildCapabilities())) goto error; + if (!(privconn->xmlconf = virDomainXMLConfNew(NULL, NULL))) + goto error; + if (!(privconn->domains = virDomainObjListNew())) goto error; @@ -987,6 +990,7 @@ parallelsClose(virConnectPtr conn) parallelsDriverLock(privconn); virObjectUnref(privconn->caps); + virObjectUnref(privconn->xmlconf); virObjectUnref(privconn->domains); conn->privateData = NULL; @@ -2326,8 +2330,8 @@ parallelsDomainDefineXML(virConnectPtr conn, const char *xml) virDomainObjPtr dom = NULL, olddom = NULL; parallelsDriverLock(privconn); - if ((def = virDomainDefParseString(privconn->caps, xml, - 1 << VIR_DOMAIN_VIRT_PARALLELS, + if ((def = virDomainDefParseString(privconn->caps, privconn->xmlconf, + xml, 1 << VIR_DOMAIN_VIRT_PARALLELS, VIR_DOMAIN_XML_INACTIVE)) == NULL) { virReportError(VIR_ERR_INVALID_ARG, "%s", _("Can't parse XML desc")); @@ -2366,7 +2370,7 @@ parallelsDomainDefineXML(virConnectPtr conn, const char *xml) virObjectUnlock(olddom); if (!(dom = virDomainObjListAdd(privconn->domains, - privconn->caps, + privconn->xmlconf, def, 0, NULL))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Can't allocate domobj")); diff --git a/src/parallels/parallels_utils.h b/src/parallels/parallels_utils.h index 910cd8b..59ef18e 100644 --- a/src/parallels/parallels_utils.h +++ b/src/parallels/parallels_utils.h @@ -43,6 +43,7 @@ struct _parallelsConn { virStoragePoolObjList pools; virNetworkObjList networks; virCapsPtr caps; + virDomainXMLConfPtr xmlconf; virDomainEventStatePtr domainEventState; }; -- 1.8.1.5

On Mon, Mar 11, 2013 at 04:06:17PM +0100, Peter Krempa wrote:
--- src/parallels/parallels_driver.c | 12 ++++++++---- src/parallels/parallels_utils.h | 1 + 2 files changed, 9 insertions(+), 4 deletions(-)
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

--- src/phyp/phyp_driver.c | 8 ++++++-- src/phyp/phyp_driver.h | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index 8c67338..59cc1ca 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -1204,6 +1204,9 @@ phypOpen(virConnectPtr conn, goto failure; } + if (!(phyp_driver->xmlconf = virDomainXMLConfNew(NULL, NULL))) + goto failure; + conn->privateData = phyp_driver; conn->networkPrivateData = connection_data; @@ -1252,6 +1255,7 @@ phypClose(virConnectPtr conn) libssh2_session_free(session); virObjectUnref(phyp_driver->caps); + virObjectUnref(phyp_driver->xmlconf); phypUUIDTable_Free(phyp_driver->uuid_table); VIR_FREE(phyp_driver->managed_system); VIR_FREE(phyp_driver); @@ -3633,8 +3637,8 @@ phypDomainCreateAndStart(virConnectPtr conn, virCheckFlags(0, NULL); - if (!(def = virDomainDefParseString(phyp_driver->caps, xml, - 1 << VIR_DOMAIN_VIRT_PHYP, + if (!(def = virDomainDefParseString(phyp_driver->caps, phyp_driver->xmlconf, + xml, 1 << VIR_DOMAIN_VIRT_PHYP, VIR_DOMAIN_XML_SECURE))) goto err; diff --git a/src/phyp/phyp_driver.h b/src/phyp/phyp_driver.h index 8114b67..8d4cc16 100644 --- a/src/phyp/phyp_driver.h +++ b/src/phyp/phyp_driver.h @@ -68,6 +68,7 @@ typedef phyp_driver_t *phyp_driverPtr; struct _phyp_driver { uuid_tablePtr uuid_table; virCapsPtr caps; + virDomainXMLConfPtr xmlconf; int vios_id; /* system_type: -- 1.8.1.5

On Mon, Mar 11, 2013 at 04:06:18PM +0100, Peter Krempa wrote:
--- src/phyp/phyp_driver.c | 8 ++++++-- src/phyp/phyp_driver.h | 1 + 2 files changed, 7 insertions(+), 2 deletions(-)
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

--- src/qemu/qemu_command.c | 9 ++-- src/qemu/qemu_command.h | 3 ++ src/qemu/qemu_conf.c | 10 ++-- src/qemu/qemu_conf.h | 4 ++ src/qemu/qemu_domain.c | 58 +++++++++------------- src/qemu/qemu_domain.h | 6 +-- src/qemu/qemu_driver.c | 123 +++++++++++++++++++++------------------------- src/qemu/qemu_migration.c | 22 ++++----- src/qemu/qemu_process.c | 109 +++++++--------------------------------- 9 files changed, 130 insertions(+), 214 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 201fac1..1a740dc 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -8562,6 +8562,7 @@ qemuParseCommandLineBootDevs(virDomainDefPtr def, const char *str) { * as is practical. This is not an exact science.... */ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, + virDomainXMLConfPtr xmlconf, const char **progenv, const char **progargv, char **pidfile, @@ -9423,7 +9424,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, goto error; if (cmd->num_args || cmd->num_env) { - def->ns = qemuCaps->ns; + def->ns = *virDomainXMLConfGetNamespace(xmlconf); def->namespaceData = cmd; } else @@ -9449,6 +9450,7 @@ error: virDomainDefPtr qemuParseCommandLineString(virCapsPtr qemuCaps, + virDomainXMLConfPtr xmlconf, const char *args, char **pidfile, virDomainChrSourceDefPtr *monConfig, @@ -9462,7 +9464,7 @@ virDomainDefPtr qemuParseCommandLineString(virCapsPtr qemuCaps, if (qemuStringToArgvEnv(args, &progenv, &progargv) < 0) goto cleanup; - def = qemuParseCommandLine(qemuCaps, progenv, progargv, + def = qemuParseCommandLine(qemuCaps, xmlconf, progenv, progargv, pidfile, monConfig, monJSON); cleanup: @@ -9538,6 +9540,7 @@ cleanup: } virDomainDefPtr qemuParseCommandLinePid(virCapsPtr qemuCaps, + virDomainXMLConfPtr xmlconf, pid_t pid, char **pidfile, virDomainChrSourceDefPtr *monConfig, @@ -9557,7 +9560,7 @@ virDomainDefPtr qemuParseCommandLinePid(virCapsPtr qemuCaps, qemuParseProcFileStrings(pid, "environ", &progenv) < 0) goto cleanup; - if (!(def = qemuParseCommandLine(qemuCaps, progenv, progargv, + if (!(def = qemuParseCommandLine(qemuCaps, xmlconf, progenv, progargv, pidfile, monConfig, monJSON))) goto cleanup; diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index e4db000..a1214d8 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -167,17 +167,20 @@ int qemuOpenVhostNet(virDomainDefPtr def, * *must* decide how to fill in a name in this case */ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, + virDomainXMLConfPtr xmlconf, const char **progenv, const char **progargv, char **pidfile, virDomainChrSourceDefPtr *monConfig, bool *monJSON); virDomainDefPtr qemuParseCommandLineString(virCapsPtr qemuCaps, + virDomainXMLConfPtr xmlconf, const char *args, char **pidfile, virDomainChrSourceDefPtr *monConfig, bool *monJSON); virDomainDefPtr qemuParseCommandLinePid(virCapsPtr qemuCaps, + virDomainXMLConfPtr xmlconf, pid_t pid, char **pidfile, virDomainChrSourceDefPtr *monConfig, diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 3ef3499..1beff6d 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -551,6 +551,13 @@ virQEMUDriverConfigPtr virQEMUDriverGetConfig(virQEMUDriverPtr driver) return conf; } +virDomainXMLConfPtr +virQEMUDriverCreateXMLConf(void) +{ + return virDomainXMLConfNew(&virQEMUDriverPrivateDataCallbacks, + &virQEMUDriverDomainXMLNamespace); +} + virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver) { @@ -573,9 +580,6 @@ virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver) caps->defaultDiskDriverType = VIR_STORAGE_FILE_RAW; } - qemuDomainSetPrivateDataHooks(caps); - qemuDomainSetNamespaceHooks(caps); - if (virGetHostUUID(caps->host.host_uuid)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot get the host uuid")); diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 6bb3dee..c5ddaad 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -188,6 +188,9 @@ struct _virQEMUDriver { */ virCapsPtr caps; + /* Immutable pointer, Immutable object */ + virDomainXMLConfPtr xmlconf; + /* Immutable pointer, self-locking APIs */ virQEMUCapsCachePtr qemuCapsCache; @@ -298,5 +301,6 @@ void qemuSharedDiskEntryFree(void *payload, const void *name) ATTRIBUTE_NONNULL(1); int qemuDriverAllocateID(virQEMUDriverPtr driver); +virDomainXMLConfPtr virQEMUDriverCreateXMLConf(void); #endif /* __QEMUD_CONF_H */ diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 0e56596..2be207f 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -205,7 +205,8 @@ qemuDomainTrackJob(enum qemuDomainJob job) } -static void *qemuDomainObjPrivateAlloc(void) +static void +*qemuDomainObjPrivateAlloc(void) { qemuDomainObjPrivatePtr priv; @@ -227,7 +228,8 @@ error: return NULL; } -static void qemuDomainObjPrivateFree(void *data) +static void +qemuDomainObjPrivateFree(void *data) { qemuDomainObjPrivatePtr priv = data; @@ -256,7 +258,8 @@ static void qemuDomainObjPrivateFree(void *data) } -static int qemuDomainObjPrivateXMLFormat(virBufferPtr buf, void *data) +static int +qemuDomainObjPrivateXMLFormat(virBufferPtr buf, void *data) { qemuDomainObjPrivatePtr priv = data; const char *monitorpath; @@ -329,7 +332,8 @@ static int qemuDomainObjPrivateXMLFormat(virBufferPtr buf, void *data) return 0; } -static int qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, void *data) +static int +qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, void *data) { qemuDomainObjPrivatePtr priv = data; char *monitorpath; @@ -482,6 +486,14 @@ error: } +virDomainXMLPrivateDataCallbacks virQEMUDriverPrivateDataCallbacks = { + .alloc = qemuDomainObjPrivateAlloc, + .free = qemuDomainObjPrivateFree, + .parse = qemuDomainObjPrivateXMLParse, + .format = qemuDomainObjPrivateXMLFormat, +}; + + static void qemuDomainDefNamespaceFree(void *nsdata) { @@ -641,42 +653,25 @@ qemuDomainDefNamespaceHref(void) } -void qemuDomainSetPrivateDataHooks(virCapsPtr caps) -{ - /* Domain XML parser hooks */ - caps->privateDataAllocFunc = qemuDomainObjPrivateAlloc; - caps->privateDataFreeFunc = qemuDomainObjPrivateFree; - caps->privateDataXMLFormat = qemuDomainObjPrivateXMLFormat; - caps->privateDataXMLParse = qemuDomainObjPrivateXMLParse; - -} +virDomainXMLNamespace virQEMUDriverDomainXMLNamespace = { + .parse = qemuDomainDefNamespaceParse, + .free = qemuDomainDefNamespaceFree, + .format = qemuDomainDefNamespaceFormatXML, + .href = qemuDomainDefNamespaceHref, +}; -void qemuDomainSetNamespaceHooks(virCapsPtr caps) -{ - /* Domain Namespace XML parser hooks */ - caps->ns.parse = qemuDomainDefNamespaceParse; - caps->ns.free = qemuDomainDefNamespaceFree; - caps->ns.format = qemuDomainDefNamespaceFormatXML; - caps->ns.href = qemuDomainDefNamespaceHref; -} static void qemuDomainObjSaveJob(virQEMUDriverPtr driver, virDomainObjPtr obj) { virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); - virCapsPtr caps = NULL; - - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; if (virDomainObjIsActive(obj)) { - if (virDomainSaveStatus(caps, cfg->stateDir, obj) < 0) + if (virDomainSaveStatus(driver->xmlconf, cfg->stateDir, obj) < 0) VIR_WARN("Failed to save status on vm %s", obj->def->name); } -cleanup: virObjectUnref(cfg); - virObjectUnref(caps); } void @@ -1782,22 +1777,17 @@ qemuDomainSetFakeReboot(virQEMUDriverPtr driver, { qemuDomainObjPrivatePtr priv = vm->privateData; virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); - virCapsPtr caps = NULL; - - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; if (priv->fakeReboot == value) goto cleanup; priv->fakeReboot = value; - if (virDomainSaveStatus(caps, cfg->stateDir, vm) < 0) + if (virDomainSaveStatus(driver->xmlconf, cfg->stateDir, vm) < 0) VIR_WARN("Failed to save status on vm %s", vm->def->name); cleanup: virObjectUnref(cfg); - virObjectUnref(caps); } int diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 7dbbaff..3a12b45 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -180,9 +180,6 @@ void qemuDomainEventFlush(int timer, void *opaque); void qemuDomainEventQueue(virQEMUDriverPtr driver, virDomainEventPtr event); -void qemuDomainSetPrivateDataHooks(virCapsPtr caps); -void qemuDomainSetNamespaceHooks(virCapsPtr caps); - int qemuDomainObjBeginJob(virQEMUDriverPtr driver, virDomainObjPtr obj, enum qemuDomainJob job) @@ -340,4 +337,7 @@ void qemuDomainCleanupRemove(virDomainObjPtr vm, void qemuDomainCleanupRun(virQEMUDriverPtr driver, virDomainObjPtr vm); +extern virDomainXMLPrivateDataCallbacks virQEMUDriverPrivateDataCallbacks; +extern virDomainXMLNamespace virQEMUDriverDomainXMLNamespace; + #endif /* __QEMU_DOMAIN_H__ */ diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index f4bbd74..8e0abc3 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -441,6 +441,7 @@ qemuDomainSnapshotLoad(virDomainObjPtr vm, } def = virDomainSnapshotDefParseString(xmlStr, caps, + qemu_driver->xmlconf, QEMU_EXPECTED_VIRT_TYPES, flags); if (def == NULL) { @@ -722,6 +723,9 @@ qemuStartup(bool privileged, if ((qemu_driver->caps = virQEMUDriverCreateCapabilities(qemu_driver)) == NULL) goto error; + if (!(qemu_driver->xmlconf = virQEMUDriverCreateXMLConf())) + goto error; + /* If hugetlbfs is present, then we need to create a sub-directory within * it, since we can't assume the root mount point has permissions that * will let our spawned QEMU instances use it. @@ -763,6 +767,7 @@ qemuStartup(bool privileged, /* Get all the running persistent or transient configs first */ if (virDomainObjListLoadAllConfigs(qemu_driver->domains, qemu_driver->caps, + qemu_driver->xmlconf, cfg->stateDir, NULL, 1, QEMU_EXPECTED_VIRT_TYPES, @@ -787,6 +792,7 @@ qemuStartup(bool privileged, /* Then inactive persistent configs */ if (virDomainObjListLoadAllConfigs(qemu_driver->domains, qemu_driver->caps, + qemu_driver->xmlconf, cfg->configDir, cfg->autostartDir, 0, QEMU_EXPECTED_VIRT_TYPES, @@ -860,6 +866,7 @@ qemuReload(void) { cfg = virQEMUDriverGetConfig(qemu_driver); virDomainObjListLoadAllConfigs(qemu_driver->domains, caps, + qemu_driver->xmlconf, cfg->configDir, cfg->autostartDir, 0, QEMU_EXPECTED_VIRT_TYPES, @@ -953,6 +960,8 @@ qemuShutdown(void) { virObjectUnref(qemu_driver->domains); virObjectUnref(qemu_driver->remotePorts); + virObjectUnref(qemu_driver->xmlconf); + virSysinfoDefFree(qemu_driver->hostsysinfo); virObjectUnref(qemu_driver->closeCallbacks); @@ -1465,7 +1474,7 @@ static virDomainPtr qemuDomainCreate(virConnectPtr conn, const char *xml, if (!(caps = virQEMUDriverGetCapabilities(driver, false))) goto cleanup; - if (!(def = virDomainDefParseString(caps, xml, + if (!(def = virDomainDefParseString(caps, driver->xmlconf, xml, QEMU_EXPECTED_VIRT_TYPES, VIR_DOMAIN_XML_INACTIVE))) goto cleanup; @@ -1483,7 +1492,7 @@ static virDomainPtr qemuDomainCreate(virConnectPtr conn, const char *xml, goto cleanup; if (!(vm = virDomainObjListAdd(driver->domains, - caps, + driver->xmlconf, def, VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, NULL))) @@ -1551,7 +1560,6 @@ static int qemuDomainSuspend(virDomainPtr dom) { int eventDetail; int state; virQEMUDriverConfigPtr cfg = NULL; - virCapsPtr caps = NULL; vm = virDomainObjListFindByUUID(driver->domains, dom->uuid); @@ -1607,9 +1615,7 @@ static int qemuDomainSuspend(virDomainPtr dom) { eventDetail); } } - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto endjob; - if (virDomainSaveStatus(caps, cfg->stateDir, vm) < 0) + if (virDomainSaveStatus(driver->xmlconf, cfg->stateDir, vm) < 0) goto endjob; ret = 0; @@ -1623,7 +1629,6 @@ cleanup: if (event) qemuDomainEventQueue(driver, event); - virObjectUnref(caps); virObjectUnref(cfg); return ret; } @@ -1679,7 +1684,7 @@ static int qemuDomainResume(virDomainPtr dom) { } if (!(caps = virQEMUDriverGetCapabilities(driver, false))) goto endjob; - if (virDomainSaveStatus(caps, cfg->stateDir, vm) < 0) + if (virDomainSaveStatus(driver->xmlconf, cfg->stateDir, vm) < 0) goto endjob; ret = 0; @@ -2077,7 +2082,7 @@ static int qemuDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem, if (!(caps = virQEMUDriverGetCapabilities(driver, false))) goto endjob; - if (virDomainLiveConfigHelperMethod(caps, vm, &flags, + if (virDomainLiveConfigHelperMethod(caps, driver->xmlconf, vm, &flags, &persistentDef) < 0) goto endjob; @@ -2838,7 +2843,7 @@ qemuDomainSaveInternal(virQEMUDriverPtr driver, virDomainPtr dom, if (xmlin) { virDomainDefPtr def = NULL; - if (!(def = virDomainDefParseString(caps, xmlin, + if (!(def = virDomainDefParseString(caps, driver->xmlconf, xmlin, QEMU_EXPECTED_VIRT_TYPES, VIR_DOMAIN_XML_INACTIVE))) { goto endjob; @@ -3752,7 +3757,7 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus, maximum = (flags & VIR_DOMAIN_VCPU_MAXIMUM) != 0; flags &= ~VIR_DOMAIN_VCPU_MAXIMUM; - if (virDomainLiveConfigHelperMethod(caps, vm, &flags, + if (virDomainLiveConfigHelperMethod(caps, driver->xmlconf, vm, &flags, &persistentDef) < 0) goto endjob; @@ -3858,7 +3863,7 @@ qemuDomainPinVcpuFlags(virDomainPtr dom, if (!(caps = virQEMUDriverGetCapabilities(driver, false))) goto cleanup; - if (virDomainLiveConfigHelperMethod(caps, vm, &flags, + if (virDomainLiveConfigHelperMethod(caps, driver->xmlconf, vm, &flags, &persistentDef) < 0) goto cleanup; @@ -3949,7 +3954,7 @@ qemuDomainPinVcpuFlags(virDomainPtr dom, if (newVcpuPin) virDomainVcpuPinDefArrayFree(newVcpuPin, newVcpuPinNum); - if (virDomainSaveStatus(caps, cfg->stateDir, vm) < 0) + if (virDomainSaveStatus(driver->xmlconf, cfg->stateDir, vm) < 0) goto cleanup; } @@ -4038,7 +4043,7 @@ qemuDomainGetVcpuPinInfo(virDomainPtr dom, if (!(caps = virQEMUDriverGetCapabilities(driver, false))) goto cleanup; - if (virDomainLiveConfigHelperMethod(caps, vm, &flags, + if (virDomainLiveConfigHelperMethod(caps, driver->xmlconf, vm, &flags, &targetDef) < 0) goto cleanup; @@ -4134,7 +4139,7 @@ qemuDomainPinEmulator(virDomainPtr dom, goto cleanup; } - if (virDomainLiveConfigHelperMethod(caps, vm, &flags, + if (virDomainLiveConfigHelperMethod(caps, driver->xmlconf, vm, &flags, &persistentDef) < 0) goto cleanup; @@ -4215,7 +4220,7 @@ qemuDomainPinEmulator(virDomainPtr dom, goto cleanup; } - if (virDomainSaveStatus(caps, cfg->stateDir, vm) < 0) + if (virDomainSaveStatus(driver->xmlconf, cfg->stateDir, vm) < 0) goto cleanup; } @@ -4280,8 +4285,8 @@ qemuDomainGetEmulatorPinInfo(virDomainPtr dom, if (!(caps = virQEMUDriverGetCapabilities(driver, false))) goto cleanup; - if (virDomainLiveConfigHelperMethod(caps, vm, &flags, - &targetDef) < 0) + if (virDomainLiveConfigHelperMethod(caps, driver->xmlconf, + vm, &flags, &targetDef) < 0) goto cleanup; if (flags & VIR_DOMAIN_AFFECT_LIVE) @@ -4437,7 +4442,8 @@ qemuDomainGetVcpusFlags(virDomainPtr dom, unsigned int flags) if (!(caps = virQEMUDriverGetCapabilities(driver, false))) goto cleanup; - if (virDomainLiveConfigHelperMethod(caps, vm, &flags, &def) < 0) + if (virDomainLiveConfigHelperMethod(caps, driver->xmlconf, + vm, &flags, &def) < 0) goto cleanup; if (flags & VIR_DOMAIN_AFFECT_LIVE) { @@ -4749,14 +4755,14 @@ qemuDomainSaveImageOpen(virQEMUDriverPtr driver, header.was_running = state; /* Create a domain from this XML */ - if (!(def = virDomainDefParseString(caps, xml, + if (!(def = virDomainDefParseString(caps, driver->xmlconf, xml, QEMU_EXPECTED_VIRT_TYPES, VIR_DOMAIN_XML_INACTIVE))) goto error; if (xmlin) { virDomainDefPtr def2 = NULL; - if (!(def2 = virDomainDefParseString(caps, xmlin, + if (!(def2 = virDomainDefParseString(caps, driver->xmlconf, xmlin, QEMU_EXPECTED_VIRT_TYPES, VIR_DOMAIN_XML_INACTIVE))) goto error; @@ -4801,10 +4807,6 @@ qemuDomainSaveImageStartVM(virConnectPtr conn, virCommandPtr cmd = NULL; char *errbuf = NULL; virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); - virCapsPtr caps = NULL; - - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; if ((header->version == 2) && (header->compressed != QEMU_SAVE_FORMAT_RAW)) { @@ -4876,7 +4878,7 @@ qemuDomainSaveImageStartVM(virConnectPtr conn, "%s", _("failed to resume domain")); goto cleanup; } - if (virDomainSaveStatus(caps, cfg->stateDir, vm) < 0) { + if (virDomainSaveStatus(driver->xmlconf, cfg->stateDir, vm) < 0) { VIR_WARN("Failed to save status on vm %s", vm->def->name); goto cleanup; } @@ -4898,7 +4900,6 @@ cleanup: if (virSecurityManagerRestoreSavedStateLabel(driver->securityManager, vm->def, path) < 0) VIR_WARN("failed to restore save state label on %s", path); - virObjectUnref(caps); virObjectUnref(cfg); return ret; } @@ -4917,7 +4918,6 @@ qemuDomainRestoreFlags(virConnectPtr conn, virQEMUSaveHeader header; virFileWrapperFdPtr wrapperFd = NULL; int state = -1; - virCapsPtr caps = NULL; virCheckFlags(VIR_DOMAIN_SAVE_BYPASS_CACHE | VIR_DOMAIN_SAVE_RUNNING | @@ -4929,9 +4929,6 @@ qemuDomainRestoreFlags(virConnectPtr conn, else if (flags & VIR_DOMAIN_SAVE_PAUSED) state = 0; - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; - fd = qemuDomainSaveImageOpen(driver, path, &def, &header, (flags & VIR_DOMAIN_SAVE_BYPASS_CACHE) != 0, &wrapperFd, dxml, state, false, false); @@ -4939,7 +4936,7 @@ qemuDomainRestoreFlags(virConnectPtr conn, goto cleanup; if (!(vm = virDomainObjListAdd(driver->domains, - caps, + driver->xmlconf, def, VIR_DOMAIN_OBJ_LIST_ADD_LIVE | VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, @@ -4968,7 +4965,6 @@ cleanup: virFileWrapperFdFree(wrapperFd); if (vm) virObjectUnlock(vm); - virObjectUnref(caps); return ret; } @@ -5221,7 +5217,7 @@ static char *qemuDomainXMLFromNative(virConnectPtr conn, if (!(caps = virQEMUDriverGetCapabilities(driver, false))) goto cleanup; - def = qemuParseCommandLineString(caps, config, + def = qemuParseCommandLineString(caps, driver->xmlconf, config, NULL, NULL, NULL); if (!def) goto cleanup; @@ -5269,7 +5265,7 @@ static char *qemuDomainXMLToNative(virConnectPtr conn, if (!(caps = virQEMUDriverGetCapabilities(driver, false))) goto cleanup; - def = virDomainDefParseString(caps, xmlData, + def = virDomainDefParseString(caps, driver->xmlconf, xmlData, QEMU_EXPECTED_VIRT_TYPES, 0); if (!def) goto cleanup; @@ -5540,7 +5536,7 @@ static virDomainPtr qemuDomainDefine(virConnectPtr conn, const char *xml) { if (!(caps = virQEMUDriverGetCapabilities(driver, false))) goto cleanup; - if (!(def = virDomainDefParseString(caps, xml, + if (!(def = virDomainDefParseString(caps, driver->xmlconf, xml, QEMU_EXPECTED_VIRT_TYPES, VIR_DOMAIN_XML_INACTIVE))) goto cleanup; @@ -5558,7 +5554,7 @@ static virDomainPtr qemuDomainDefine(virConnectPtr conn, const char *xml) { goto cleanup; if (!(vm = virDomainObjListAdd(driver->domains, - caps, + driver->xmlconf, def, 0, &oldDef))) @@ -6479,7 +6475,7 @@ qemuDomainModifyDeviceFlags(virDomainPtr dom, const char *xml, goto endjob; /* Make a copy for updated domain. */ - vmdef = virDomainObjCopyPersistentDef(caps, vm); + vmdef = virDomainObjCopyPersistentDef(caps, driver->xmlconf, vm); if (!vmdef) goto endjob; switch (action) { @@ -6530,7 +6526,7 @@ qemuDomainModifyDeviceFlags(virDomainPtr dom, const char *xml, * changed even if we failed to attach the device. For example, * a new controller may be created. */ - if (virDomainSaveStatus(caps, cfg->stateDir, vm) < 0) { + if (virDomainSaveStatus(driver->xmlconf, cfg->stateDir, vm) < 0) { ret = -1; goto endjob; } @@ -6907,7 +6903,7 @@ qemuDomainSetBlkioParameters(virDomainPtr dom, if (!(caps = virQEMUDriverGetCapabilities(driver, false))) goto cleanup; - if (virDomainLiveConfigHelperMethod(caps, vm, &flags, + if (virDomainLiveConfigHelperMethod(caps, driver->xmlconf, vm, &flags, &persistentDef) < 0) goto cleanup; @@ -7072,7 +7068,7 @@ qemuDomainGetBlkioParameters(virDomainPtr dom, goto cleanup; } - if (virDomainLiveConfigHelperMethod(caps, vm, &flags, + if (virDomainLiveConfigHelperMethod(caps, driver->xmlconf, vm, &flags, &persistentDef) < 0) goto cleanup; @@ -7261,7 +7257,7 @@ qemuDomainSetMemoryParameters(virDomainPtr dom, if (!(caps = virQEMUDriverGetCapabilities(driver, false))) goto cleanup; - if (virDomainLiveConfigHelperMethod(caps, vm, &flags, + if (virDomainLiveConfigHelperMethod(caps, driver->xmlconf, vm, &flags, &persistentDef) < 0) goto cleanup; @@ -7391,7 +7387,7 @@ qemuDomainGetMemoryParameters(virDomainPtr dom, if (!(caps = virQEMUDriverGetCapabilities(driver, false))) goto cleanup; - if (virDomainLiveConfigHelperMethod(caps, vm, &flags, + if (virDomainLiveConfigHelperMethod(caps, driver->xmlconf, vm, &flags, &persistentDef) < 0) goto cleanup; @@ -7557,7 +7553,7 @@ qemuDomainSetNumaParameters(virDomainPtr dom, if (!(caps = virQEMUDriverGetCapabilities(driver, false))) goto cleanup; - if (virDomainLiveConfigHelperMethod(caps, vm, &flags, + if (virDomainLiveConfigHelperMethod(caps, driver->xmlconf, vm, &flags, &persistentDef) < 0) goto cleanup; @@ -7710,7 +7706,7 @@ qemuDomainGetNumaParameters(virDomainPtr dom, if (!(caps = virQEMUDriverGetCapabilities(driver, false))) goto cleanup; - if (virDomainLiveConfigHelperMethod(caps, vm, &flags, + if (virDomainLiveConfigHelperMethod(caps, driver->xmlconf, vm, &flags, &persistentDef) < 0) goto cleanup; @@ -7920,13 +7916,13 @@ qemuSetSchedulerParametersFlags(virDomainPtr dom, if (!(caps = virQEMUDriverGetCapabilities(driver, false))) goto cleanup; - if (virDomainLiveConfigHelperMethod(caps, vm, &flags, + if (virDomainLiveConfigHelperMethod(caps, driver->xmlconf, vm, &flags, &vmdef) < 0) goto cleanup; if (flags & VIR_DOMAIN_AFFECT_CONFIG) { /* Make a copy for updated domain. */ - vmdef = virDomainObjCopyPersistentDef(caps, vm); + vmdef = virDomainObjCopyPersistentDef(caps, driver->xmlconf, vm); if (!vmdef) goto cleanup; } @@ -8021,7 +8017,7 @@ qemuSetSchedulerParametersFlags(virDomainPtr dom, } } - if (virDomainSaveStatus(caps, cfg->stateDir, vm) < 0) + if (virDomainSaveStatus(driver->xmlconf, cfg->stateDir, vm) < 0) goto cleanup; @@ -8206,7 +8202,7 @@ qemuGetSchedulerParametersFlags(virDomainPtr dom, if (!(caps = virQEMUDriverGetCapabilities(driver, false))) goto cleanup; - if (virDomainLiveConfigHelperMethod(caps, vm, &flags, + if (virDomainLiveConfigHelperMethod(caps, driver->xmlconf, vm, &flags, &persistentDef) < 0) goto cleanup; @@ -8736,7 +8732,7 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom, if (!(caps = virQEMUDriverGetCapabilities(driver, false))) goto cleanup; - if (virDomainLiveConfigHelperMethod(caps, vm, &flags, + if (virDomainLiveConfigHelperMethod(caps, driver->xmlconf, vm, &flags, &persistentDef) < 0) goto cleanup; @@ -8902,7 +8898,7 @@ qemuDomainGetInterfaceParameters(virDomainPtr dom, if (!(caps = virQEMUDriverGetCapabilities(driver, false))) goto cleanup; - if (virDomainLiveConfigHelperMethod(caps, vm, &flags, + if (virDomainLiveConfigHelperMethod(caps, driver->xmlconf, vm, &flags, &persistentDef) < 0) goto cleanup; @@ -11207,10 +11203,6 @@ qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr driver, bool reuse = (flags & VIR_DOMAIN_SNAPSHOT_CREATE_REUSE_EXT) != 0; virCgroupPtr cgroup = NULL; virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); - virCapsPtr caps = NULL; - - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; if (!virDomainObjIsActive(vm)) { virReportError(VIR_ERR_OPERATION_INVALID, @@ -11305,11 +11297,10 @@ cleanup: virCgroupFree(&cgroup); if (ret == 0 || !virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_TRANSACTION)) { - if (virDomainSaveStatus(caps, cfg->stateDir, vm) < 0 || + if (virDomainSaveStatus(driver->xmlconf, cfg->stateDir, vm) < 0 || (persist && virDomainSaveConfig(cfg->configDir, vm->newDef) < 0)) ret = -1; } - virObjectUnref(caps); virObjectUnref(cfg); return ret; @@ -11574,7 +11565,7 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain, !virDomainObjIsActive(vm)) parse_flags |= VIR_DOMAIN_SNAPSHOT_PARSE_OFFLINE; - if (!(def = virDomainSnapshotDefParseString(xmlDesc, caps, + if (!(def = virDomainSnapshotDefParseString(xmlDesc, caps, driver->xmlconf, QEMU_EXPECTED_VIRT_TYPES, parse_flags))) goto cleanup; @@ -11750,7 +11741,7 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain, /* Easiest way to clone inactive portion of vm->def is via * conversion in and back out of xml. */ if (!(xml = qemuDomainDefFormatLive(driver, vm->def, true, true)) || - !(def->dom = virDomainDefParseString(caps, xml, + !(def->dom = virDomainDefParseString(caps, driver->xmlconf, xml, QEMU_EXPECTED_VIRT_TYPES, VIR_DOMAIN_XML_INACTIVE))) goto cleanup; @@ -12321,7 +12312,7 @@ static int qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, * than inactive xml? */ snap->def->current = true; if (snap->def->dom) { - config = virDomainDefCopy(caps, snap->def->dom, true); + config = virDomainDefCopy(caps, driver->xmlconf, snap->def->dom, true); if (!config) goto cleanup; } @@ -12781,7 +12772,7 @@ static virDomainPtr qemuDomainAttach(virConnectPtr conn, if (!(caps = virQEMUDriverGetCapabilities(driver, false))) goto cleanup; - if (!(def = qemuParseCommandLinePid(caps, pid, + if (!(def = qemuParseCommandLinePid(caps, driver->xmlconf, pid, &pidfile, &monConfig, &monJSON))) goto cleanup; @@ -12815,7 +12806,7 @@ static virDomainPtr qemuDomainAttach(virConnectPtr conn, goto cleanup; if (!(vm = virDomainObjListAdd(driver->domains, - caps, + driver->xmlconf, def, VIR_DOMAIN_OBJ_LIST_ADD_LIVE | VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, @@ -13895,7 +13886,7 @@ qemuDomainSetBlockIoTune(virDomainPtr dom, if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) goto cleanup; - if (virDomainLiveConfigHelperMethod(caps, vm, &flags, + if (virDomainLiveConfigHelperMethod(caps, driver->xmlconf, vm, &flags, &persistentDef) < 0) goto endjob; @@ -14055,7 +14046,7 @@ qemuDomainGetBlockIoTune(virDomainPtr dom, if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) goto cleanup; - if (virDomainLiveConfigHelperMethod(caps, vm, &flags, + if (virDomainLiveConfigHelperMethod(caps, driver->xmlconf, vm, &flags, &persistentDef) < 0) goto endjob; @@ -14244,7 +14235,7 @@ qemuDomainSetMetadata(virDomainPtr dom, if (!(caps = virQEMUDriverGetCapabilities(driver, false))) goto cleanup; - if (virDomainLiveConfigHelperMethod(caps, vm, &flags, + if (virDomainLiveConfigHelperMethod(caps, driver->xmlconf, vm, &flags, &persistentDef) < 0) goto cleanup; @@ -14341,7 +14332,7 @@ qemuDomainGetMetadata(virDomainPtr dom, if (!(caps = virQEMUDriverGetCapabilities(driver, false))) goto cleanup; - if (virDomainLiveConfigHelperMethod(caps, vm, &flags, &def) < 0) + if (virDomainLiveConfigHelperMethod(caps, driver->xmlconf, vm, &flags, &def) < 0) goto cleanup; /* use correct domain definition according to flags */ diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 4c6d7e1..537b834 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -919,7 +919,8 @@ qemuMigrationCookieXMLParse(qemuMigrationCookiePtr mig, n); goto error; } - mig->persistent = virDomainDefParseNode(caps, doc, nodes[0], + mig->persistent = virDomainDefParseNode(caps, driver->xmlconf, + doc, nodes[0], -1, VIR_DOMAIN_XML_INACTIVE); if (!mig->persistent) { /* virDomainDefParseNode already reported @@ -1923,7 +1924,7 @@ char *qemuMigrationBegin(virQEMUDriverPtr driver, } if (xmlin) { - if (!(def = virDomainDefParseString(caps, xmlin, + if (!(def = virDomainDefParseString(caps, driver->xmlconf, xmlin, QEMU_EXPECTED_VIRT_TYPES, VIR_DOMAIN_XML_INACTIVE))) goto cleanup; @@ -2025,7 +2026,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver, if (!(caps = virQEMUDriverGetCapabilities(driver, false))) goto cleanup; - if (!(def = virDomainDefParseString(caps, dom_xml, + if (!(def = virDomainDefParseString(caps, driver->xmlconf, dom_xml, QEMU_EXPECTED_VIRT_TYPES, VIR_DOMAIN_XML_INACTIVE))) goto cleanup; @@ -2066,7 +2067,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver, virDomainDefPtr newdef; VIR_DEBUG("Using hook-filtered domain XML: %s", xmlout); - newdef = virDomainDefParseString(caps, xmlout, + newdef = virDomainDefParseString(caps, driver->xmlconf, xmlout, QEMU_EXPECTED_VIRT_TYPES, VIR_DOMAIN_XML_INACTIVE); if (!newdef) @@ -2084,7 +2085,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver, } if (!(vm = virDomainObjListAdd(driver->domains, - caps, + driver->xmlconf, def, VIR_DOMAIN_OBJ_LIST_ADD_LIVE | VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, @@ -3883,7 +3884,7 @@ qemuMigrationFinish(virQEMUDriverPtr driver, if (mig->persistent) vm->newDef = vmdef = mig->persistent; else - vmdef = virDomainObjGetPersistentDef(caps, vm); + vmdef = virDomainObjGetPersistentDef(caps, driver->xmlconf, vm); if (!vmdef || virDomainSaveConfig(cfg->configDir, vmdef) < 0) { /* Hmpf. Migration was successful, but making it persistent * was not. If we report successful, then when this domain @@ -3978,7 +3979,7 @@ qemuMigrationFinish(virQEMUDriverPtr driver, } if (virDomainObjIsActive(vm) && - virDomainSaveStatus(caps, cfg->stateDir, vm) < 0) { + virDomainSaveStatus(driver->xmlconf, cfg->stateDir, vm) < 0) { VIR_WARN("Failed to save status on vm %s", vm->def->name); goto endjob; } @@ -4035,7 +4036,6 @@ int qemuMigrationConfirm(virQEMUDriverPtr driver, virDomainEventPtr event = NULL; int rv = -1; virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); - virCapsPtr caps = NULL; VIR_DEBUG("driver=%p, conn=%p, vm=%p, cookiein=%s, cookieinlen=%d, " "flags=%x, retcode=%d", @@ -4044,9 +4044,6 @@ int qemuMigrationConfirm(virQEMUDriverPtr driver, virCheckFlags(QEMU_MIGRATION_FLAGS, -1); - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; - qemuMigrationJobSetPhase(driver, vm, retcode == 0 ? QEMU_MIGRATION_PHASE_CONFIRM3 @@ -4090,7 +4087,7 @@ int qemuMigrationConfirm(virQEMUDriverPtr driver, event = virDomainEventNewFromObj(vm, VIR_DOMAIN_EVENT_RESUMED, VIR_DOMAIN_EVENT_RESUMED_MIGRATED); - if (virDomainSaveStatus(caps, cfg->stateDir, vm) < 0) { + if (virDomainSaveStatus(driver->xmlconf, cfg->stateDir, vm) < 0) { VIR_WARN("Failed to save status on vm %s", vm->def->name); goto cleanup; } @@ -4103,7 +4100,6 @@ done: cleanup: if (event) qemuDomainEventQueue(driver, event); - virObjectUnref(caps); virObjectUnref(cfg); return rv; } diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index efb1298..244e4d7 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -641,13 +641,9 @@ qemuProcessHandleShutdown(qemuMonitorPtr mon ATTRIBUTE_UNUSED, qemuDomainObjPrivatePtr priv; virDomainEventPtr event = NULL; virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); - virCapsPtr caps = NULL; VIR_DEBUG("vm=%p", vm); - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; - virObjectLock(vm); priv = vm->privateData; @@ -671,7 +667,7 @@ qemuProcessHandleShutdown(qemuMonitorPtr mon ATTRIBUTE_UNUSED, VIR_DOMAIN_EVENT_SHUTDOWN, VIR_DOMAIN_EVENT_SHUTDOWN_FINISHED); - if (virDomainSaveStatus(caps, cfg->stateDir, vm) < 0) { + if (virDomainSaveStatus(driver->xmlconf, cfg->stateDir, vm) < 0) { VIR_WARN("Unable to save status on vm %s after state change", vm->def->name); } @@ -683,10 +679,8 @@ qemuProcessHandleShutdown(qemuMonitorPtr mon ATTRIBUTE_UNUSED, unlock: virObjectUnlock(vm); -cleanup: if (event) qemuDomainEventQueue(driver, event); - virObjectUnref(caps); virObjectUnref(cfg); return 0; @@ -700,10 +694,6 @@ qemuProcessHandleStop(qemuMonitorPtr mon ATTRIBUTE_UNUSED, virQEMUDriverPtr driver = qemu_driver; virDomainEventPtr event = NULL; virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); - virCapsPtr caps = NULL; - - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; virObjectLock(vm); if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_RUNNING) { @@ -727,7 +717,7 @@ qemuProcessHandleStop(qemuMonitorPtr mon ATTRIBUTE_UNUSED, VIR_WARN("Unable to release lease on %s", vm->def->name); VIR_DEBUG("Preserving lock state '%s'", NULLSTR(priv->lockState)); - if (virDomainSaveStatus(caps, cfg->stateDir, vm) < 0) { + if (virDomainSaveStatus(driver->xmlconf, cfg->stateDir, vm) < 0) { VIR_WARN("Unable to save status on vm %s after state change", vm->def->name); } @@ -735,11 +725,8 @@ qemuProcessHandleStop(qemuMonitorPtr mon ATTRIBUTE_UNUSED, unlock: virObjectUnlock(vm); - -cleanup: if (event) qemuDomainEventQueue(driver, event); - virObjectUnref(caps); virObjectUnref(cfg); return 0; @@ -753,10 +740,6 @@ qemuProcessHandleResume(qemuMonitorPtr mon ATTRIBUTE_UNUSED, virQEMUDriverPtr driver = qemu_driver; virDomainEventPtr event = NULL; virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); - virCapsPtr caps = NULL; - - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; virObjectLock(vm); if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_PAUSED) { @@ -787,7 +770,7 @@ qemuProcessHandleResume(qemuMonitorPtr mon ATTRIBUTE_UNUSED, } VIR_FREE(priv->lockState); - if (virDomainSaveStatus(caps, cfg->stateDir, vm) < 0) { + if (virDomainSaveStatus(driver->xmlconf, cfg->stateDir, vm) < 0) { VIR_WARN("Unable to save status on vm %s after state change", vm->def->name); } @@ -795,10 +778,8 @@ qemuProcessHandleResume(qemuMonitorPtr mon ATTRIBUTE_UNUSED, unlock: virObjectUnlock(vm); -cleanup: if (event) qemuDomainEventQueue(driver, event); - virObjectUnref(caps); virObjectUnref(cfg); return 0; } @@ -812,10 +793,6 @@ qemuProcessHandleRTCChange(qemuMonitorPtr mon ATTRIBUTE_UNUSED, virQEMUDriverPtr driver = qemu_driver; virDomainEventPtr event = NULL; virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); - virCapsPtr caps = NULL; - - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; virObjectLock(vm); event = virDomainEventRTCChangeNewFromObj(vm, offset); @@ -823,15 +800,13 @@ qemuProcessHandleRTCChange(qemuMonitorPtr mon ATTRIBUTE_UNUSED, if (vm->def->clock.offset == VIR_DOMAIN_CLOCK_OFFSET_VARIABLE) vm->def->clock.data.variable.adjustment = offset; - if (virDomainSaveStatus(caps, cfg->stateDir, vm) < 0) + if (virDomainSaveStatus(driver->xmlconf, cfg->stateDir, vm) < 0) VIR_WARN("unable to save domain status with RTC change"); virObjectUnlock(vm); -cleanup: if (event) qemuDomainEventQueue(driver, event); - virObjectUnref(caps); virObjectUnref(cfg); return 0; } @@ -846,10 +821,6 @@ qemuProcessHandleWatchdog(qemuMonitorPtr mon ATTRIBUTE_UNUSED, virDomainEventPtr watchdogEvent = NULL; virDomainEventPtr lifecycleEvent = NULL; virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); - virCapsPtr caps = NULL; - - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; virObjectLock(vm); watchdogEvent = virDomainEventWatchdogNewFromObj(vm, action); @@ -869,7 +840,7 @@ qemuProcessHandleWatchdog(qemuMonitorPtr mon ATTRIBUTE_UNUSED, VIR_WARN("Unable to release lease on %s", vm->def->name); VIR_DEBUG("Preserving lock state '%s'", NULLSTR(priv->lockState)); - if (virDomainSaveStatus(caps, cfg->stateDir, vm) < 0) { + if (virDomainSaveStatus(driver->xmlconf, cfg->stateDir, vm) < 0) { VIR_WARN("Unable to save status on vm %s after watchdog event", vm->def->name); } @@ -896,14 +867,11 @@ qemuProcessHandleWatchdog(qemuMonitorPtr mon ATTRIBUTE_UNUSED, if (vm) virObjectUnlock(vm); - -cleanup: if (watchdogEvent) qemuDomainEventQueue(driver, watchdogEvent); if (lifecycleEvent) qemuDomainEventQueue(driver, lifecycleEvent); - virObjectUnref(caps); virObjectUnref(cfg); return 0; } @@ -924,10 +892,6 @@ qemuProcessHandleIOError(qemuMonitorPtr mon ATTRIBUTE_UNUSED, const char *devAlias; virDomainDiskDefPtr disk; virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); - virCapsPtr caps = NULL; - - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; virObjectLock(vm); disk = qemuProcessFindDomainDiskByAlias(vm, diskAlias); @@ -958,19 +922,17 @@ qemuProcessHandleIOError(qemuMonitorPtr mon ATTRIBUTE_UNUSED, VIR_WARN("Unable to release lease on %s", vm->def->name); VIR_DEBUG("Preserving lock state '%s'", NULLSTR(priv->lockState)); - if (virDomainSaveStatus(caps, cfg->stateDir, vm) < 0) + if (virDomainSaveStatus(driver->xmlconf, cfg->stateDir, vm) < 0) VIR_WARN("Unable to save status on vm %s after IO error", vm->def->name); } virObjectUnlock(vm); -cleanup: if (ioErrorEvent) qemuDomainEventQueue(driver, ioErrorEvent); if (ioErrorEvent2) qemuDomainEventQueue(driver, ioErrorEvent2); if (lifecycleEvent) qemuDomainEventQueue(driver, lifecycleEvent); - virObjectUnref(caps); virObjectUnref(cfg); return 0; } @@ -1121,10 +1083,6 @@ qemuProcessHandleTrayChange(qemuMonitorPtr mon ATTRIBUTE_UNUSED, virDomainEventPtr event = NULL; virDomainDiskDefPtr disk; virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); - virCapsPtr caps = NULL; - - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; virObjectLock(vm); disk = qemuProcessFindDomainDiskByAlias(vm, devAlias); @@ -1139,17 +1097,15 @@ qemuProcessHandleTrayChange(qemuMonitorPtr mon ATTRIBUTE_UNUSED, else if (reason == VIR_DOMAIN_EVENT_TRAY_CHANGE_CLOSE) disk->tray_status = VIR_DOMAIN_DISK_TRAY_CLOSED; - if (virDomainSaveStatus(caps, cfg->stateDir, vm) < 0) { + if (virDomainSaveStatus(driver->xmlconf, cfg->stateDir, vm) < 0) { VIR_WARN("Unable to save status on vm %s after tray moved event", vm->def->name); } } virObjectUnlock(vm); -cleanup: if (event) qemuDomainEventQueue(driver, event); - virObjectUnref(caps); virObjectUnref(cfg); return 0; } @@ -1162,10 +1118,6 @@ qemuProcessHandlePMWakeup(qemuMonitorPtr mon ATTRIBUTE_UNUSED, virDomainEventPtr event = NULL; virDomainEventPtr lifecycleEvent = NULL; virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); - virCapsPtr caps = NULL; - - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; virObjectLock(vm); event = virDomainEventPMWakeupNewFromObj(vm); @@ -1183,20 +1135,17 @@ qemuProcessHandlePMWakeup(qemuMonitorPtr mon ATTRIBUTE_UNUSED, VIR_DOMAIN_EVENT_STARTED, VIR_DOMAIN_EVENT_STARTED_WAKEUP); - if (virDomainSaveStatus(caps, cfg->stateDir, vm) < 0) { + if (virDomainSaveStatus(driver->xmlconf, cfg->stateDir, vm) < 0) { VIR_WARN("Unable to save status on vm %s after wakeup event", vm->def->name); } } virObjectUnlock(vm); - -cleanup: if (event) qemuDomainEventQueue(driver, event); if (lifecycleEvent) qemuDomainEventQueue(driver, lifecycleEvent); - virObjectUnref(caps); virObjectUnref(cfg); return 0; } @@ -1209,10 +1158,6 @@ qemuProcessHandlePMSuspend(qemuMonitorPtr mon ATTRIBUTE_UNUSED, virDomainEventPtr event = NULL; virDomainEventPtr lifecycleEvent = NULL; virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); - virCapsPtr caps = NULL; - - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; virObjectLock(vm); event = virDomainEventPMSuspendNewFromObj(vm); @@ -1229,7 +1174,7 @@ qemuProcessHandlePMSuspend(qemuMonitorPtr mon ATTRIBUTE_UNUSED, VIR_DOMAIN_EVENT_PMSUSPENDED, VIR_DOMAIN_EVENT_PMSUSPENDED_MEMORY); - if (virDomainSaveStatus(caps, cfg->stateDir, vm) < 0) { + if (virDomainSaveStatus(driver->xmlconf, cfg->stateDir, vm) < 0) { VIR_WARN("Unable to save status on vm %s after suspend event", vm->def->name); } @@ -1240,12 +1185,10 @@ qemuProcessHandlePMSuspend(qemuMonitorPtr mon ATTRIBUTE_UNUSED, virObjectUnlock(vm); -cleanup: if (event) qemuDomainEventQueue(driver, event); if (lifecycleEvent) qemuDomainEventQueue(driver, lifecycleEvent); - virObjectUnref(caps); virObjectUnref(cfg); return 0; } @@ -1258,10 +1201,6 @@ qemuProcessHandleBalloonChange(qemuMonitorPtr mon ATTRIBUTE_UNUSED, virQEMUDriverPtr driver = qemu_driver; virDomainEventPtr event = NULL; virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); - virCapsPtr caps = NULL; - - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; virObjectLock(vm); event = virDomainEventBalloonChangeNewFromObj(vm, actual); @@ -1270,15 +1209,13 @@ qemuProcessHandleBalloonChange(qemuMonitorPtr mon ATTRIBUTE_UNUSED, vm->def->mem.cur_balloon, actual); vm->def->mem.cur_balloon = actual; - if (virDomainSaveStatus(caps, cfg->stateDir, vm) < 0) + if (virDomainSaveStatus(driver->xmlconf, cfg->stateDir, vm) < 0) VIR_WARN("unable to save domain status with balloon change"); virObjectUnlock(vm); -cleanup: if (event) qemuDomainEventQueue(driver, event); - virObjectUnref(caps); virObjectUnref(cfg); return 0; } @@ -1291,10 +1228,6 @@ qemuProcessHandlePMSuspendDisk(qemuMonitorPtr mon ATTRIBUTE_UNUSED, virDomainEventPtr event = NULL; virDomainEventPtr lifecycleEvent = NULL; virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); - virCapsPtr caps = NULL; - - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; virObjectLock(vm); event = virDomainEventPMSuspendDiskNewFromObj(vm); @@ -1311,7 +1244,7 @@ qemuProcessHandlePMSuspendDisk(qemuMonitorPtr mon ATTRIBUTE_UNUSED, VIR_DOMAIN_EVENT_PMSUSPENDED, VIR_DOMAIN_EVENT_PMSUSPENDED_DISK); - if (virDomainSaveStatus(caps, cfg->stateDir, vm) < 0) { + if (virDomainSaveStatus(driver->xmlconf, cfg->stateDir, vm) < 0) { VIR_WARN("Unable to save status on vm %s after suspend event", vm->def->name); } @@ -1322,12 +1255,10 @@ qemuProcessHandlePMSuspendDisk(qemuMonitorPtr mon ATTRIBUTE_UNUSED, virObjectUnlock(vm); -cleanup: if (event) qemuDomainEventQueue(driver, event); if (lifecycleEvent) qemuDomainEventQueue(driver, lifecycleEvent); - virObjectUnref(caps); virObjectUnref(cfg); return 0; @@ -3179,7 +3110,6 @@ qemuProcessReconnect(void *opaque) int state; int reason; virQEMUDriverConfigPtr cfg; - virCapsPtr caps = NULL; size_t i; memcpy(&oldjob, &data->oldjob, sizeof(oldjob)); @@ -3200,9 +3130,6 @@ qemuProcessReconnect(void *opaque) * deleted if qemuConnectMonitor() failed */ virObjectRef(obj); - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto error; - /* XXX check PID liveliness & EXE path */ if (qemuConnectMonitor(driver, obj) < 0) goto error; @@ -3282,7 +3209,7 @@ qemuProcessReconnect(void *opaque) goto error; /* update domain state XML with possibly updated state in virDomainObj */ - if (virDomainSaveStatus(caps, cfg->stateDir, obj) < 0) + if (virDomainSaveStatus(driver->xmlconf, cfg->stateDir, obj) < 0) goto error; /* Run an hook to allow admins to do some magic */ @@ -3314,7 +3241,6 @@ endjob: virConnectClose(conn); virObjectUnref(cfg); - virObjectUnref(caps); return; @@ -3352,7 +3278,6 @@ error: } } virConnectClose(conn); - virObjectUnref(caps); virObjectUnref(cfg); } @@ -3539,7 +3464,7 @@ int qemuProcessStart(virConnectPtr conn, * report implicit runtime defaults in the XML, like vnc listen/socket */ VIR_DEBUG("Setting current domain def as transient"); - if (virDomainObjSetDefTransient(caps, vm, true) < 0) + if (virDomainObjSetDefTransient(caps, driver->xmlconf, vm, true) < 0) goto cleanup; vm->def->id = qemuDriverAllocateID(driver); @@ -3888,7 +3813,7 @@ int qemuProcessStart(virConnectPtr conn, } VIR_DEBUG("Writing early domain status to disk"); - if (virDomainSaveStatus(caps, cfg->stateDir, vm) < 0) { + if (virDomainSaveStatus(driver->xmlconf, cfg->stateDir, vm) < 0) { goto cleanup; } @@ -4039,7 +3964,7 @@ int qemuProcessStart(virConnectPtr conn, goto cleanup; VIR_DEBUG("Writing domain status to disk"); - if (virDomainSaveStatus(caps, cfg->stateDir, vm) < 0) + if (virDomainSaveStatus(driver->xmlconf, cfg->stateDir, vm) < 0) goto cleanup; /* finally we can call the 'started' hook script if any */ @@ -4394,7 +4319,7 @@ int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_UNUSED, * report implicit runtime defaults in the XML, like vnc listen/socket */ VIR_DEBUG("Setting current domain def as transient"); - if (virDomainObjSetDefTransient(caps, vm, true) < 0) + if (virDomainObjSetDefTransient(caps, driver->xmlconf, vm, true) < 0) goto cleanup; vm->def->id = qemuDriverAllocateID(driver); @@ -4538,7 +4463,7 @@ int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_UNUSED, virDomainObjSetState(vm, VIR_DOMAIN_PAUSED, reason); VIR_DEBUG("Writing domain status to disk"); - if (virDomainSaveStatus(caps, cfg->stateDir, vm) < 0) + if (virDomainSaveStatus(driver->xmlconf, cfg->stateDir, vm) < 0) goto cleanup; /* Run an hook to allow admins to do some magic */ -- 1.8.1.5

On Mon, Mar 11, 2013 at 04:06:19PM +0100, Peter Krempa wrote:
--- src/qemu/qemu_command.c | 9 ++-- src/qemu/qemu_command.h | 3 ++ src/qemu/qemu_conf.c | 10 ++-- src/qemu/qemu_conf.h | 4 ++ src/qemu/qemu_domain.c | 58 +++++++++------------- src/qemu/qemu_domain.h | 6 +-- src/qemu/qemu_driver.c | 123 +++++++++++++++++++++------------------------- src/qemu/qemu_migration.c | 22 ++++----- src/qemu/qemu_process.c | 109 +++++++--------------------------------- 9 files changed, 130 insertions(+), 214 deletions(-)
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

--- tests/domainsnapshotxml2xmltest.c | 5 +++++ tests/lxcxml2xmltest.c | 7 ++++++- tests/qemuargv2xmltest.c | 8 ++++++-- tests/qemumonitorjsontest.c | 29 +++++++++++++++-------------- tests/qemumonitortestutils.c | 4 ++-- tests/qemumonitortestutils.h | 5 +++-- tests/qemuxml2argvtest.c | 5 ++++- tests/qemuxml2xmltest.c | 6 +++++- tests/qemuxmlnstest.c | 5 ++++- tests/testutilsqemu.c | 3 +-- tests/testutilsqemu.h | 2 ++ tests/testutilsxen.c | 6 ++++++ tests/testutilsxen.h | 2 ++ tests/xmconfigtest.c | 8 +++++++- tests/xml2sexprtest.c | 8 +++++++- tests/xml2vmxtest.c | 8 +++++++- 16 files changed, 82 insertions(+), 29 deletions(-) diff --git a/tests/domainsnapshotxml2xmltest.c b/tests/domainsnapshotxml2xmltest.c index aeea997..7d95310 100644 --- a/tests/domainsnapshotxml2xmltest.c +++ b/tests/domainsnapshotxml2xmltest.c @@ -34,6 +34,7 @@ testCompareXMLToXMLFiles(const char *inxml, const char *uuid, int internal) if (internal) flags |= VIR_DOMAIN_SNAPSHOT_PARSE_INTERNAL; if (!(def = virDomainSnapshotDefParseString(inXmlData, driver.caps, + driver.xmlconf, QEMU_EXPECTED_VIRT_TYPES, flags))) goto fail; @@ -90,6 +91,9 @@ mymain(void) if ((driver.caps = testQemuCapsInit()) == NULL) return EXIT_FAILURE; + if (!(driver.xmlconf = virQEMUDriverCreateXMLConf())) + return EXIT_FAILURE; + # define DO_TEST(name, uuid, internal) \ do { \ const struct testInfo info = {name, uuid, internal}; \ @@ -113,6 +117,7 @@ mymain(void) DO_TEST("external_vm", "c7a5fdbd-edaf-9455-926a-d65c16db1809", 0); virObjectUnref(driver.caps); + virObjectUnref(driver.xmlconf); return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tests/lxcxml2xmltest.c b/tests/lxcxml2xmltest.c index bfb6092..964d433 100644 --- a/tests/lxcxml2xmltest.c +++ b/tests/lxcxml2xmltest.c @@ -16,6 +16,7 @@ # include "testutilslxc.h" static virCapsPtr caps; +static virDomainXMLConfPtr xmlconf; static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml, bool live) @@ -31,7 +32,7 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml, bool live) if (virtTestLoadFile(outxml, &outXmlData) < 0) goto fail; - if (!(def = virDomainDefParseString(caps, inXmlData, + if (!(def = virDomainDefParseString(caps, xmlconf, inXmlData, 1 << VIR_DOMAIN_VIRT_LXC, live ? 0 : VIR_DOMAIN_XML_INACTIVE))) goto fail; @@ -101,6 +102,9 @@ mymain(void) if ((caps = testLXCCapsInit()) == NULL) return EXIT_FAILURE; + if (!(xmlconf = lxcDomainXMLConfInit())) + return EXIT_FAILURE; + # define DO_TEST_FULL(name, is_different, inactive) \ do { \ const struct testInfo info = {name, is_different, inactive}; \ @@ -124,6 +128,7 @@ mymain(void) DO_TEST("hostdev"); virObjectUnref(caps); + virObjectUnref(xmlconf); return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tests/qemuargv2xmltest.c b/tests/qemuargv2xmltest.c index 3c23010..f7d6019 100644 --- a/tests/qemuargv2xmltest.c +++ b/tests/qemuargv2xmltest.c @@ -46,8 +46,8 @@ static int testCompareXMLToArgvFiles(const char *xml, if (virtTestLoadFile(xml, &expectxml) < 0) goto fail; - if (!(vmdef = qemuParseCommandLineString(driver.caps, cmd, - NULL, NULL, NULL))) + if (!(vmdef = qemuParseCommandLineString(driver.caps, driver.xmlconf, + cmd, NULL, NULL, NULL))) goto fail; if ((log = virtTestLogContentAndReset()) == NULL) @@ -120,6 +120,9 @@ mymain(void) if ((driver.caps = testQemuCapsInit()) == NULL) return EXIT_FAILURE; + if (!(driver.xmlconf = virQEMUDriverCreateXMLConf())) + return EXIT_FAILURE; + # define DO_TEST_FULL(name, extraFlags, migrateFrom) \ do { \ const struct testInfo info = { name, extraFlags, migrateFrom }; \ @@ -244,6 +247,7 @@ mymain(void) virObjectUnref(driver.config); virObjectUnref(driver.caps); + virObjectUnref(driver.xmlconf); return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 04b8f77..639eeb1 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -22,6 +22,7 @@ #include "testutils.h" #include "testutilsqemu.h" #include "qemumonitortestutils.h" +#include "qemu/qemu_conf.h" #include "virthread.h" #include "virerror.h" @@ -31,8 +32,8 @@ static int testQemuMonitorJSONGetStatus(const void *data) { - virCapsPtr caps = (virCapsPtr)data; - qemuMonitorTestPtr test = qemuMonitorTestNew(true, caps); + virDomainXMLConfPtr xmlconf = (virDomainXMLConfPtr)data; + qemuMonitorTestPtr test = qemuMonitorTestNew(true, xmlconf); int ret = -1; bool running = false; virDomainPausedReason reason = 0; @@ -125,8 +126,8 @@ cleanup: static int testQemuMonitorJSONGetVersion(const void *data) { - virCapsPtr caps = (virCapsPtr)data; - qemuMonitorTestPtr test = qemuMonitorTestNew(true, caps); + virDomainXMLConfPtr xmlconf = (virDomainXMLConfPtr)data; + qemuMonitorTestPtr test = qemuMonitorTestNew(true, xmlconf); int ret = -1; int major; int minor; @@ -228,8 +229,8 @@ cleanup: static int testQemuMonitorJSONGetMachines(const void *data) { - virCapsPtr caps = (virCapsPtr)data; - qemuMonitorTestPtr test = qemuMonitorTestNew(true, caps); + virDomainXMLConfPtr xmlconf = (virDomainXMLConfPtr)data; + qemuMonitorTestPtr test = qemuMonitorTestNew(true, xmlconf); int ret = -1; qemuMonitorMachineInfoPtr *info; int ninfo = 0; @@ -310,8 +311,8 @@ cleanup: static int testQemuMonitorJSONGetCPUDefinitions(const void *data) { - virCapsPtr caps = (virCapsPtr)data; - qemuMonitorTestPtr test = qemuMonitorTestNew(true, caps); + virDomainXMLConfPtr xmlconf = (virDomainXMLConfPtr)data; + qemuMonitorTestPtr test = qemuMonitorTestNew(true, xmlconf); int ret = -1; char **cpus = NULL; int ncpus = 0; @@ -376,8 +377,8 @@ cleanup: static int testQemuMonitorJSONGetCommands(const void *data) { - virCapsPtr caps = (virCapsPtr)data; - qemuMonitorTestPtr test = qemuMonitorTestNew(true, caps); + virDomainXMLConfPtr xmlconf = (virDomainXMLConfPtr)data; + qemuMonitorTestPtr test = qemuMonitorTestNew(true, xmlconf); int ret = -1; char **commands = NULL; int ncommands = 0; @@ -442,7 +443,7 @@ static int mymain(void) { int ret = 0; - virCapsPtr caps; + virDomainXMLConfPtr xmlconf; #if !WITH_YAJL fputs("libvirt not compiled with yajl, skipping this test\n", stderr); @@ -450,13 +451,13 @@ mymain(void) #endif if (virThreadInitialize() < 0 || - !(caps = testQemuCapsInit())) + !(xmlconf = virQEMUDriverCreateXMLConf())) return EXIT_FAILURE; virEventRegisterDefaultImpl(); #define DO_TEST(name) \ - if (virtTestRun(# name, 1, testQemuMonitorJSON ## name, caps) < 0) \ + if (virtTestRun(# name, 1, testQemuMonitorJSON ## name, xmlconf) < 0) \ ret = -1 DO_TEST(GetStatus); @@ -465,7 +466,7 @@ mymain(void) DO_TEST(GetCPUDefinitions); DO_TEST(GetCommands); - virObjectUnref(caps); + virObjectUnref(xmlconf); return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c index 979623a..d5bce84 100644 --- a/tests/qemumonitortestutils.c +++ b/tests/qemumonitortestutils.c @@ -450,7 +450,7 @@ static qemuMonitorCallbacks qemuCallbacks = { #define QEMU_TEXT_GREETING "QEMU 1.0,1 monitor - type 'help' for more information" -qemuMonitorTestPtr qemuMonitorTestNew(bool json, virCapsPtr caps) +qemuMonitorTestPtr qemuMonitorTestNew(bool json, virDomainXMLConfPtr xmlconf) { qemuMonitorTestPtr test = NULL; virDomainChrSourceDef src; @@ -482,7 +482,7 @@ qemuMonitorTestPtr qemuMonitorTestNew(bool json, virCapsPtr caps) goto no_memory; test->json = json; - if (!(test->vm = virDomainObjNew(caps))) + if (!(test->vm = virDomainObjNew(xmlconf))) goto error; if (virNetSocketNewListenUNIX(path, diff --git a/tests/qemumonitortestutils.h b/tests/qemumonitortestutils.h index edad103..09914ae 100644 --- a/tests/qemumonitortestutils.h +++ b/tests/qemumonitortestutils.h @@ -20,7 +20,7 @@ #ifndef __VIR_QEMU_MONITOR_TEST_UTILS_H__ # define __VIR_QEMU_MONITOR_TEST_UTILS_H__ -# include "capabilities.h" +# include "domain_conf.h" # include "qemu/qemu_monitor.h" typedef struct _qemuMonitorTest qemuMonitorTest; @@ -32,7 +32,8 @@ qemuMonitorTestAddItem(qemuMonitorTestPtr test, const char *response); qemuMonitorTestPtr qemuMonitorTestNew(bool json, - virCapsPtr caps); + virDomainXMLConfPtr xmlconf); + void qemuMonitorTestFree(qemuMonitorTestPtr test); diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 2354733..888de3c 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -100,7 +100,7 @@ static int testCompareXMLToArgvFiles(const char *xml, goto out; conn->secretDriver = &fakeSecretDriver; - if (!(vmdef = virDomainDefParseFile(driver.caps, xml, + if (!(vmdef = virDomainDefParseFile(driver.caps, driver.xmlconf, xml, QEMU_EXPECTED_VIRT_TYPES, VIR_DOMAIN_XML_INACTIVE))) { if (flags & FLAG_EXPECT_PARSE_ERROR) @@ -294,6 +294,8 @@ mymain(void) if ((driver.caps = testQemuCapsInit()) == NULL) return EXIT_FAILURE; + if (!(driver.xmlconf = virQEMUDriverCreateXMLConf())) + return EXIT_FAILURE; VIR_FREE(driver.config->stateDir); if ((driver.config->stateDir = strdup("/nowhere")) == NULL) return EXIT_FAILURE; @@ -891,6 +893,7 @@ mymain(void) virObjectUnref(driver.config); virObjectUnref(driver.caps); + virObjectUnref(driver.xmlconf); VIR_FREE(map); return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE; diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index d64960f..d77da4e 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -32,7 +32,7 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml, bool live) if (virtTestLoadFile(outxml, &outXmlData) < 0) goto fail; - if (!(def = virDomainDefParseString(driver.caps, inXmlData, + if (!(def = virDomainDefParseString(driver.caps, driver.xmlconf, inXmlData, QEMU_EXPECTED_VIRT_TYPES, live ? 0 : VIR_DOMAIN_XML_INACTIVE))) goto fail; @@ -106,6 +106,9 @@ mymain(void) if ((driver.caps = testQemuCapsInit()) == NULL) return EXIT_FAILURE; + if (!(driver.xmlconf = virQEMUDriverCreateXMLConf())) + return EXIT_FAILURE; + # define DO_TEST_FULL(name, is_different, when) \ do { \ const struct testInfo info = {name, is_different, when}; \ @@ -262,6 +265,7 @@ mymain(void) DO_TEST_DIFFERENT("metadata"); virObjectUnref(driver.caps); + virObjectUnref(driver.xmlconf); return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tests/qemuxmlnstest.c b/tests/qemuxmlnstest.c index 6dae3f4..76a715d 100644 --- a/tests/qemuxmlnstest.c +++ b/tests/qemuxmlnstest.c @@ -51,7 +51,7 @@ static int testCompareXMLToArgvFiles(const char *xml, if (len && expectargv[len - 1] == '\n') expectargv[len - 1] = '\0'; - if (!(vmdef = virDomainDefParseFile(driver.caps, xml, + if (!(vmdef = virDomainDefParseFile(driver.caps, driver.xmlconf, xml, QEMU_EXPECTED_VIRT_TYPES, VIR_DOMAIN_XML_INACTIVE))) goto fail; @@ -204,6 +204,8 @@ mymain(void) driver.config = virQEMUDriverConfigNew(false); if ((driver.caps = testQemuCapsInit()) == NULL) return EXIT_FAILURE; + if (!(driver.xmlconf = virQEMUDriverCreateXMLConf())) + return EXIT_FAILURE; if (virAsprintf(&map, "%s/src/cpu/cpu_map.xml", abs_top_srcdir) < 0 || cpuMapOverride(map) < 0) { VIR_FREE(map); @@ -252,6 +254,7 @@ mymain(void) virObjectUnref(driver.config); virObjectUnref(driver.caps); + virObjectUnref(driver.xmlconf); VIR_FREE(map); return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE; diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index 966527c..27cf647 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -120,6 +120,7 @@ error: return -1; } + virCapsPtr testQemuCapsInit(void) { virCapsPtr caps; virCapsGuestPtr guest; @@ -174,8 +175,6 @@ virCapsPtr testQemuCapsInit(void) { (machines = testQemuAllocMachines(&nmachines)) == NULL) goto cleanup; - qemuDomainSetNamespaceHooks(caps); - if ((guest = virCapabilitiesAddGuest(caps, "hvm", VIR_ARCH_I686, "/usr/bin/qemu", NULL, nmachines, machines)) == NULL || diff --git a/tests/testutilsqemu.h b/tests/testutilsqemu.h index 3d70a2a..932becb 100644 --- a/tests/testutilsqemu.h +++ b/tests/testutilsqemu.h @@ -1,4 +1,6 @@ #include "capabilities.h" +#include "domain_conf.h" virCapsPtr testQemuCapsInit(void); +virDomainXMLConfPtr testQemuXMLConfInit(void); diff --git a/tests/testutilsxen.c b/tests/testutilsxen.c index 6d97925..201ea2a 100644 --- a/tests/testutilsxen.c +++ b/tests/testutilsxen.c @@ -15,6 +15,12 @@ static int testXenDefaultConsoleType(const char *ostype, return VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_XEN; } +virDomainXMLConfPtr +testXenXMLConfInit(void) +{ + return virDomainXMLConfNew(NULL, NULL); +} + virCapsPtr testXenCapsInit(void) { struct utsname utsname; virCapsPtr caps; diff --git a/tests/testutilsxen.h b/tests/testutilsxen.h index 7f27e22..d4576cb 100644 --- a/tests/testutilsxen.h +++ b/tests/testutilsxen.h @@ -1,4 +1,6 @@ #include "capabilities.h" +#include "domain_conf.h" virCapsPtr testXenCapsInit(void); +virDomainXMLConfPtr testXenXMLConfInit(void); diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c index 9f71aa2..a32c11a 100644 --- a/tests/xmconfigtest.c +++ b/tests/xmconfigtest.c @@ -37,6 +37,7 @@ #include "viralloc.h" static virCapsPtr caps; +static virDomainXMLConfPtr xmlconf; static int testCompareParseXML(const char *xmcfg, const char *xml, int xendConfigVersion) @@ -68,7 +69,8 @@ testCompareParseXML(const char *xmcfg, const char *xml, int xendConfigVersion) priv.caps = caps; conn->privateData = &priv; - if (!(def = virDomainDefParseString(caps, xmlData, 1 << VIR_DOMAIN_VIRT_XEN, + if (!(def = virDomainDefParseString(caps, xmlconf, xmlData, + 1 << VIR_DOMAIN_VIRT_XEN, VIR_DOMAIN_XML_INACTIVE))) goto fail; @@ -194,6 +196,9 @@ mymain(void) if (!(caps = testXenCapsInit())) return EXIT_FAILURE; + if (!(xmlconf = testXenXMLConfInit())) + return EXIT_FAILURE; + #define DO_TEST(name, version) \ do { \ struct testInfo info0 = { name, version, 0 }; \ @@ -246,6 +251,7 @@ mymain(void) DO_TEST("pci-devs", 2); virObjectUnref(caps); + virObjectUnref(xmlconf); return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tests/xml2sexprtest.c b/tests/xml2sexprtest.c index a41568a..364601a 100644 --- a/tests/xml2sexprtest.c +++ b/tests/xml2sexprtest.c @@ -15,6 +15,7 @@ #include "testutilsxen.h" static virCapsPtr caps; +static virDomainXMLConfPtr xmlconf; static int testCompareFiles(const char *xml, const char *sexpr, int xendConfigVersion) @@ -31,7 +32,8 @@ testCompareFiles(const char *xml, const char *sexpr, int xendConfigVersion) if (virtTestLoadFile(sexpr, &sexprData) < 0) goto fail; - if (!(def = virDomainDefParseString(caps, xmlData, 1 << VIR_DOMAIN_VIRT_XEN, + if (!(def = virDomainDefParseString(caps, xmlconf, xmlData, + 1 << VIR_DOMAIN_VIRT_XEN, VIR_DOMAIN_XML_INACTIVE))) goto fail; @@ -102,6 +104,9 @@ mymain(void) if (!(caps = testXenCapsInit())) return EXIT_FAILURE; + if (!(xmlconf = testXenXMLConfInit())) + return EXIT_FAILURE; + DO_TEST("pv", "pv", "pvtest", 1); DO_TEST("fv", "fv", "fvtest", 1); DO_TEST("pv", "pv", "pvtest", 2); @@ -169,6 +174,7 @@ mymain(void) DO_TEST("escape", "escape", "fvtest", 1); virObjectUnref(caps); + virObjectUnref(xmlconf); return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tests/xml2vmxtest.c b/tests/xml2vmxtest.c index c46c5a4..800fd2c 100644 --- a/tests/xml2vmxtest.c +++ b/tests/xml2vmxtest.c @@ -13,6 +13,7 @@ static virCapsPtr caps; static virVMXContext ctx; +static virDomainXMLConfPtr xmlconf; static int testDefaultConsoleType(const char *ostype ATTRIBUTE_UNUSED, virArch arch ATTRIBUTE_UNUSED) @@ -72,6 +73,7 @@ testCapsInit(void) failure: virObjectUnref(caps); + virObjectUnref(xmlconf); caps = NULL; } @@ -92,7 +94,8 @@ testCompareFiles(const char *xml, const char *vmx, int virtualHW_version) goto failure; } - def = virDomainDefParseString(caps, xmlData, 1 << VIR_DOMAIN_VIRT_VMWARE, + def = virDomainDefParseString(caps, xmlconf, xmlData, + 1 << VIR_DOMAIN_VIRT_VMWARE, VIR_DOMAIN_XML_INACTIVE); if (def == NULL) { @@ -237,6 +240,9 @@ mymain(void) return EXIT_FAILURE; } + if (!(xmlconf = virDomainXMLConfNew(NULL, NULL))) + return EXIT_FAILURE; + ctx.opaque = NULL; ctx.parseFileName = NULL; ctx.formatFileName = testFormatVMXFileName; -- 1.8.1.5

On Mon, Mar 11, 2013 at 04:06:20PM +0100, Peter Krempa wrote:
--- tests/domainsnapshotxml2xmltest.c | 5 +++++ tests/lxcxml2xmltest.c | 7 ++++++- tests/qemuargv2xmltest.c | 8 ++++++-- tests/qemumonitorjsontest.c | 29 +++++++++++++++-------------- tests/qemumonitortestutils.c | 4 ++-- tests/qemumonitortestutils.h | 5 +++-- tests/qemuxml2argvtest.c | 5 ++++- tests/qemuxml2xmltest.c | 6 +++++- tests/qemuxmlnstest.c | 5 ++++- tests/testutilsqemu.c | 3 +-- tests/testutilsqemu.h | 2 ++ tests/testutilsxen.c | 6 ++++++ tests/testutilsxen.h | 2 ++ tests/xmconfigtest.c | 8 +++++++- tests/xml2sexprtest.c | 8 +++++++- tests/xml2vmxtest.c | 8 +++++++- 16 files changed, 82 insertions(+), 29 deletions(-)
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

--- src/xen/xen_driver.c | 8 ++++++-- src/xen/xen_driver.h | 1 + src/xen/xend_internal.c | 8 ++++---- src/xen/xm_internal.c | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c index d896893..fd20b73 100644 --- a/src/xen/xen_driver.c +++ b/src/xen/xen_driver.c @@ -401,6 +401,9 @@ xenUnifiedOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int flags) goto fail; } + if (!(priv->xmlconf = virDomainXMLConfNew(NULL, NULL))) + goto fail; + #if WITH_XEN_INOTIFY if (xenHavePrivilege()) { VIR_DEBUG("Trying Xen inotify sub-driver"); @@ -448,6 +451,7 @@ xenUnifiedClose(virConnectPtr conn) int i; virObjectUnref(priv->caps); + virObjectUnref(priv->xmlconf); virDomainEventStateFree(priv->domainEvents); for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i) @@ -1430,8 +1434,8 @@ xenUnifiedDomainXMLToNative(virConnectPtr conn, goto cleanup; } - if (!(def = virDomainDefParseString(priv->caps, xmlData, - 1 << VIR_DOMAIN_VIRT_XEN, 0))) + if (!(def = virDomainDefParseString(priv->caps, priv->xmlconf, + xmlData, 1 << VIR_DOMAIN_VIRT_XEN, 0))) goto cleanup; if (STREQ(format, XEN_CONFIG_FORMAT_XM)) { diff --git a/src/xen/xen_driver.h b/src/xen/xen_driver.h index 078980e..8e43db3 100644 --- a/src/xen/xen_driver.h +++ b/src/xen/xen_driver.h @@ -160,6 +160,7 @@ struct _xenUnifiedPrivate { * holding the lock */ virCapsPtr caps; + virDomainXMLConfPtr xmlconf; int handle; /* Xen hypervisor handle */ int xendConfigVersion; /* XenD config version */ diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c index 4995d63..398da0d 100644 --- a/src/xen/xend_internal.c +++ b/src/xen/xend_internal.c @@ -2409,8 +2409,8 @@ xenDaemonCreateXML(virConnectPtr conn, const char *xmlDesc, unsigned int flags) virCheckFlags(0, NULL); - if (!(def = virDomainDefParseString(priv->caps, xmlDesc, - 1 << VIR_DOMAIN_VIRT_XEN, + if (!(def = virDomainDefParseString(priv->caps, priv->xmlconf, + xmlDesc, 1 << VIR_DOMAIN_VIRT_XEN, VIR_DOMAIN_XML_INACTIVE))) return NULL; @@ -3127,8 +3127,8 @@ xenDaemonDomainDefineXML(virConnectPtr conn, const char *xmlDesc) if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) return NULL; - if (!(def = virDomainDefParseString(priv->caps, xmlDesc, - 1 << VIR_DOMAIN_VIRT_XEN, + if (!(def = virDomainDefParseString(priv->caps, priv->xmlconf, + xmlDesc, 1 << VIR_DOMAIN_VIRT_XEN, VIR_DOMAIN_XML_INACTIVE))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("failed to parse domain description")); diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c index dfc8bf6..f6a3593 100644 --- a/src/xen/xm_internal.c +++ b/src/xen/xm_internal.c @@ -1013,7 +1013,7 @@ xenXMDomainDefineXML(virConnectPtr conn, const char *xml) return NULL; } - if (!(def = virDomainDefParseString(priv->caps, xml, + if (!(def = virDomainDefParseString(priv->caps, priv->xmlconf, xml, 1 << VIR_DOMAIN_VIRT_XEN, VIR_DOMAIN_XML_INACTIVE))) { xenUnifiedUnlock(priv); -- 1.8.1.5

On Mon, Mar 11, 2013 at 04:06:21PM +0100, Peter Krempa wrote:
--- src/xen/xen_driver.c | 8 ++++++-- src/xen/xen_driver.h | 1 + src/xen/xend_internal.c | 8 ++++---- src/xen/xm_internal.c | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-)
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

--- src/vmware/vmware_conf.c | 3 ++- src/vmware/vmware_conf.h | 1 + src/vmware/vmware_driver.c | 25 +++++++++++++++++-------- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index a17b2e1..19be62a 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -45,6 +45,7 @@ vmwareFreeDriver(struct vmware_driver *driver) virMutexDestroy(&driver->lock); virObjectUnref(driver->domains); virObjectUnref(driver->caps); + virObjectUnref(driver->xmlconf); VIR_FREE(driver); } @@ -178,7 +179,7 @@ vmwareLoadDomains(struct vmware_driver *driver) } if (!(vm = virDomainObjListAdd(driver->domains, - driver->caps, + driver->xmlconf, vmdef, 0, NULL))) goto cleanup; diff --git a/src/vmware/vmware_conf.h b/src/vmware/vmware_conf.h index 6ab985e..b3ec966 100644 --- a/src/vmware/vmware_conf.h +++ b/src/vmware/vmware_conf.h @@ -36,6 +36,7 @@ struct vmware_driver { virMutex lock; virCapsPtr caps; + virDomainXMLConfPtr xmlconf; virDomainObjListPtr domains; int version; diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index b7905fa..6d82532 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -72,6 +72,15 @@ vmwareDataFreeFunc(void *data) VIR_FREE(dom); } +static virDomainXMLConfPtr +vmwareDomainXMLConfigInit(void) +{ + virDomainXMLPrivateDataCallbacks priv = { .alloc = vmwareDataAllocFunc, + .free = vmwareDataFreeFunc }; + + return virDomainXMLConfNew(&priv, NULL); +} + static virDrvOpenStatus vmwareOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, @@ -134,8 +143,8 @@ vmwareOpen(virConnectPtr conn, if (!(driver->caps = vmwareCapsInit())) goto cleanup; - driver->caps->privateDataAllocFunc = vmwareDataAllocFunc; - driver->caps->privateDataFreeFunc = vmwareDataFreeFunc; + if (!(driver->xmlconf = vmwareDomainXMLConfigInit())) + goto cleanup; if (vmwareLoadDomains(driver) < 0) goto cleanup; @@ -315,8 +324,8 @@ vmwareDomainDefineXML(virConnectPtr conn, const char *xml) ctx.formatFileName = vmwareCopyVMXFileName; vmwareDriverLock(driver); - if ((vmdef = virDomainDefParseString(driver->caps, xml, - 1 << VIR_DOMAIN_VIRT_VMWARE, + if ((vmdef = virDomainDefParseString(driver->caps, driver->xmlconf, + xml, 1 << VIR_DOMAIN_VIRT_VMWARE, VIR_DOMAIN_XML_INACTIVE)) == NULL) goto cleanup; @@ -337,7 +346,7 @@ vmwareDomainDefineXML(virConnectPtr conn, const char *xml) /* assign def */ if (!(vm = virDomainObjListAdd(driver->domains, - driver->caps, + driver->xmlconf, vmdef, VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, NULL))) @@ -586,8 +595,8 @@ vmwareDomainCreateXML(virConnectPtr conn, const char *xml, vmwareDriverLock(driver); - if ((vmdef = virDomainDefParseString(driver->caps, xml, - 1 << VIR_DOMAIN_VIRT_VMWARE, + if ((vmdef = virDomainDefParseString(driver->caps, driver->xmlconf, + xml, 1 << VIR_DOMAIN_VIRT_VMWARE, VIR_DOMAIN_XML_INACTIVE)) == NULL) goto cleanup; @@ -608,7 +617,7 @@ vmwareDomainCreateXML(virConnectPtr conn, const char *xml, /* assign def */ if (!(vm = virDomainObjListAdd(driver->domains, - driver->caps, + driver->xmlconf, vmdef, VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, NULL))) -- 1.8.1.5

On Mon, Mar 11, 2013 at 04:06:22PM +0100, Peter Krempa wrote:
--- src/vmware/vmware_conf.c | 3 ++- src/vmware/vmware_conf.h | 1 + src/vmware/vmware_driver.c | 25 +++++++++++++++++-------- 3 files changed, 20 insertions(+), 9 deletions(-)
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

--- src/uml/uml_conf.h | 1 + src/uml/uml_driver.c | 29 +++++++++++++++++++---------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/uml/uml_conf.h b/src/uml/uml_conf.h index ff71b45..488c1b7 100644 --- a/src/uml/uml_conf.h +++ b/src/uml/uml_conf.h @@ -63,6 +63,7 @@ struct uml_driver { int inotifyWatch; virCapsPtr caps; + virDomainXMLConfPtr xmlconf; /* Event handling */ virDomainEventStatePtr domainEventState; diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index 63a807a..b08212d 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -433,6 +433,11 @@ umlStartup(bool privileged, char *base = NULL; char *userdir = NULL; + virDomainXMLPrivateDataCallbacks privcb = { + .alloc = umlDomainObjPrivateAlloc, + .free = umlDomainObjPrivateFree, + }; + if (VIR_ALLOC(uml_driver) < 0) return -1; @@ -500,8 +505,9 @@ umlStartup(bool privileged, if ((uml_driver->caps = umlCapsInit()) == NULL) goto out_of_memory; - uml_driver->caps->privateDataAllocFunc = umlDomainObjPrivateAlloc; - uml_driver->caps->privateDataFreeFunc = umlDomainObjPrivateFree; + if (!(uml_driver->xmlconf = virDomainXMLConfNew(&privcb, + NULL))) + goto error; if ((uml_driver->inotifyFD = inotify_init()) < 0) { VIR_ERROR(_("cannot initialize inotify")); @@ -537,6 +543,7 @@ umlStartup(bool privileged, if (virDomainObjListLoadAllConfigs(uml_driver->domains, uml_driver->caps, + uml_driver->xmlconf, uml_driver->configDir, uml_driver->autostartDir, 0, 1 << VIR_DOMAIN_VIRT_UML, @@ -592,6 +599,7 @@ umlReload(void) { umlDriverLock(uml_driver); virDomainObjListLoadAllConfigs(uml_driver->domains, uml_driver->caps, + uml_driver->xmlconf, uml_driver->configDir, uml_driver->autostartDir, 0, 1 << VIR_DOMAIN_VIRT_UML, @@ -1055,7 +1063,8 @@ static int umlStartVMDaemon(virConnectPtr conn, * report implicit runtime defaults in the XML, like vnc listen/socket */ VIR_DEBUG("Setting current domain def as transient"); - if (virDomainObjSetDefTransient(driver->caps, vm, true) < 0) { + if (virDomainObjSetDefTransient(driver->caps, driver->xmlconf, + vm, true) < 0) { VIR_FORCE_CLOSE(logfd); return -1; } @@ -1088,7 +1097,7 @@ static int umlStartVMDaemon(virConnectPtr conn, (ret = umlProcessAutoDestroyAdd(driver, vm, conn)) < 0) goto cleanup; - ret = virDomainObjSetDefTransient(driver->caps, vm, false); + ret = virDomainObjSetDefTransient(driver->caps, driver->xmlconf, vm, false); cleanup: VIR_FORCE_CLOSE(logfd); virCommandFree(cmd); @@ -1495,13 +1504,13 @@ static virDomainPtr umlDomainCreate(virConnectPtr conn, const char *xml, virCheckFlags(VIR_DOMAIN_START_AUTODESTROY, NULL); umlDriverLock(driver); - if (!(def = virDomainDefParseString(driver->caps, xml, - 1 << VIR_DOMAIN_VIRT_UML, + if (!(def = virDomainDefParseString(driver->caps, driver->xmlconf, + xml, 1 << VIR_DOMAIN_VIRT_UML, VIR_DOMAIN_XML_INACTIVE))) goto cleanup; if (!(vm = virDomainObjListAdd(driver->domains, - driver->caps, + driver->xmlconf, def, VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, NULL))) @@ -1916,13 +1925,13 @@ static virDomainPtr umlDomainDefine(virConnectPtr conn, const char *xml) { virDomainPtr dom = NULL; umlDriverLock(driver); - if (!(def = virDomainDefParseString(driver->caps, xml, - 1 << VIR_DOMAIN_VIRT_UML, + if (!(def = virDomainDefParseString(driver->caps, driver->xmlconf, + xml, 1 << VIR_DOMAIN_VIRT_UML, VIR_DOMAIN_XML_INACTIVE))) goto cleanup; if (!(vm = virDomainObjListAdd(driver->domains, - driver->caps, + driver->xmlconf, def, 0, NULL))) goto cleanup; -- 1.8.1.5

On Mon, Mar 11, 2013 at 04:06:23PM +0100, Peter Krempa wrote:
--- src/uml/uml_conf.h | 1 + src/uml/uml_driver.c | 29 +++++++++++++++++++---------- 2 files changed, 20 insertions(+), 10 deletions(-)
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

--- src/test/test_driver.c | 61 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 19 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 0037a6f..c5fffb9 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -82,6 +82,7 @@ struct _testConn { char *path; int nextDomID; virCapsPtr caps; + virDomainXMLConfPtr xmlconf; virNodeInfo nodeInfo; virDomainObjListPtr domains; virNetworkObjList networks; @@ -155,6 +156,16 @@ static int testDefaultConsoleType(const char *ostype ATTRIBUTE_UNUSED, return VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL; } + +static virDomainXMLConfPtr +testBuildXMLConfig(void) +{ + virDomainXMLPrivateDataCallbacks priv = { .alloc = testDomainObjPrivateAlloc, + .free = testDomainObjPrivateFree }; + return virDomainXMLConfNew(&priv, NULL); +} + + static virCapsPtr testBuildCapabilities(virConnectPtr conn) { testConnPtr privconn = conn->privateData; @@ -212,9 +223,6 @@ testBuildCapabilities(virConnectPtr conn) { goto no_memory; } - caps->privateDataAllocFunc = testDomainObjPrivateAlloc; - caps->privateDataFreeFunc = testDomainObjPrivateFree; - caps->host.nsecModels = 1; if (VIR_ALLOC_N(caps->host.secModels, caps->host.nsecModels) < 0) goto no_memory; @@ -507,7 +515,9 @@ testDomainStartState(virConnectPtr conn, virDomainObjSetState(dom, VIR_DOMAIN_RUNNING, reason); dom->def->id = privconn->nextDomID++; - if (virDomainObjSetDefTransient(privconn->caps, dom, false) < 0) { + if (virDomainObjSetDefTransient(privconn->caps, + privconn->xmlconf, + dom, false) < 0) { goto cleanup; } @@ -573,9 +583,14 @@ static int testOpenDefault(virConnectPtr conn) { if (!(privconn->caps = testBuildCapabilities(conn))) goto error; + if (!(privconn->xmlconf = testBuildXMLConfig())) + goto error; + privconn->nextDomID = 1; - if (!(domdef = virDomainDefParseString(privconn->caps, defaultDomainXML, + if (!(domdef = virDomainDefParseString(privconn->caps, + privconn->xmlconf, + defaultDomainXML, 1 << VIR_DOMAIN_VIRT_TEST, VIR_DOMAIN_XML_INACTIVE))) goto error; @@ -583,7 +598,7 @@ static int testOpenDefault(virConnectPtr conn) { if (testDomainGenerateIfnames(domdef) < 0) goto error; if (!(domobj = virDomainObjListAdd(privconn->domains, - privconn->caps, + privconn->xmlconf, domdef, 0, NULL))) goto error; domdef = NULL; @@ -802,6 +817,9 @@ static int testOpenFromFile(virConnectPtr conn, if (!(privconn->caps = testBuildCapabilities(conn))) goto error; + if (!(privconn->xmlconf = testBuildXMLConfig())) + goto error; + if (!(xml = virXMLParseFileCtxt(file, &ctxt))) { goto error; } @@ -913,14 +931,16 @@ static int testOpenFromFile(virConnectPtr conn, _("resolving domain filename")); goto error; } - def = virDomainDefParseFile(privconn->caps, absFile, + def = virDomainDefParseFile(privconn->caps, + privconn->xmlconf, absFile, 1 << VIR_DOMAIN_VIRT_TEST, VIR_DOMAIN_XML_INACTIVE); VIR_FREE(absFile); if (!def) goto error; } else { - if ((def = virDomainDefParseNode(privconn->caps, xml, domains[i], + if ((def = virDomainDefParseNode(privconn->caps, privconn->xmlconf, + xml, domains[i], 1 << VIR_DOMAIN_VIRT_TEST, VIR_DOMAIN_XML_INACTIVE)) == NULL) goto error; @@ -928,7 +948,7 @@ static int testOpenFromFile(virConnectPtr conn, if (testDomainGenerateIfnames(def) < 0 || !(dom = virDomainObjListAdd(privconn->domains, - privconn->caps, + privconn->xmlconf, def, 0, NULL))) { virDomainDefFree(def); goto error; @@ -1184,6 +1204,7 @@ static int testClose(virConnectPtr conn) testConnPtr privconn = conn->privateData; testDriverLock(privconn); virObjectUnref(privconn->caps); + virObjectUnref(privconn->xmlconf); virObjectUnref(privconn->domains); virNodeDeviceObjListFree(&privconn->devs); virNetworkObjListFree(&privconn->networks); @@ -1321,15 +1342,15 @@ testDomainCreateXML(virConnectPtr conn, const char *xml, virCheckFlags(0, NULL); testDriverLock(privconn); - if ((def = virDomainDefParseString(privconn->caps, xml, - 1 << VIR_DOMAIN_VIRT_TEST, + if ((def = virDomainDefParseString(privconn->caps, privconn->xmlconf, + xml, 1 << VIR_DOMAIN_VIRT_TEST, VIR_DOMAIN_XML_INACTIVE)) == NULL) goto cleanup; if (testDomainGenerateIfnames(def) < 0) goto cleanup; if (!(dom = virDomainObjListAdd(privconn->domains, - privconn->caps, + privconn->xmlconf, def, VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, NULL))) @@ -1936,8 +1957,8 @@ testDomainRestoreFlags(virConnectPtr conn, } xml[len] = '\0'; - def = virDomainDefParseString(privconn->caps, xml, - 1 << VIR_DOMAIN_VIRT_TEST, + def = virDomainDefParseString(privconn->caps, privconn->xmlconf, + xml, 1 << VIR_DOMAIN_VIRT_TEST, VIR_DOMAIN_XML_INACTIVE); if (!def) goto cleanup; @@ -1945,7 +1966,7 @@ testDomainRestoreFlags(virConnectPtr conn, if (testDomainGenerateIfnames(def) < 0) goto cleanup; if (!(dom = virDomainObjListAdd(privconn->domains, - privconn->caps, + privconn->xmlconf, def, VIR_DOMAIN_OBJ_LIST_ADD_LIVE | VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, @@ -2155,7 +2176,8 @@ testDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags) goto cleanup; } - if (virDomainLiveConfigHelperMethod(privconn->caps, vm, &flags, &def) < 0) + if (virDomainLiveConfigHelperMethod(privconn->caps, privconn->xmlconf, + vm, &flags, &def) < 0) goto cleanup; if (flags & VIR_DOMAIN_AFFECT_LIVE) @@ -2233,6 +2255,7 @@ testDomainSetVcpusFlags(virDomainPtr domain, unsigned int nrCpus, } if (!(persistentDef = virDomainObjGetPersistentDef(privconn->caps, + privconn->xmlconf, privdom))) goto cleanup; @@ -2485,15 +2508,15 @@ static virDomainPtr testDomainDefineXML(virConnectPtr conn, virDomainDefPtr oldDef = NULL; testDriverLock(privconn); - if ((def = virDomainDefParseString(privconn->caps, xml, - 1 << VIR_DOMAIN_VIRT_TEST, + if ((def = virDomainDefParseString(privconn->caps, privconn->xmlconf, + xml, 1 << VIR_DOMAIN_VIRT_TEST, VIR_DOMAIN_XML_INACTIVE)) == NULL) goto cleanup; if (testDomainGenerateIfnames(def) < 0) goto cleanup; if (!(dom = virDomainObjListAdd(privconn->domains, - privconn->caps, + privconn->xmlconf, def, 0, &oldDef))) -- 1.8.1.5

On Mon, Mar 11, 2013 at 04:06:24PM +0100, Peter Krempa wrote:
--- src/test/test_driver.c | 61 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 19 deletions(-)
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

--- src/vbox/vbox_tmpl.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index cd88579..aa7466b 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -193,6 +193,7 @@ typedef struct { unsigned long version; virCapsPtr caps; + virDomainXMLConfPtr xmlconf; IVirtualBox *vboxObj; ISession *vboxSession; @@ -850,6 +851,13 @@ static int vboxDefaultConsoleType(const char *ostype ATTRIBUTE_UNUSED, } +static virDomainXMLConfPtr +vboxXMLConfInit(void) +{ + return virDomainXMLConfNew(NULL, NULL); +} + + static virCapsPtr vboxCapsInit(void) { virCapsPtr caps; @@ -978,6 +986,7 @@ static void vboxUninitialize(vboxGlobalData *data) { data->pFuncs->pfnComUninitialize(); virObjectUnref(data->caps); + virObjectUnref(data->xmlconf); #if VBOX_API_VERSION == 2002 /* No domainEventCallbacks in 2.2.* version */ #else /* !(VBOX_API_VERSION == 2002) */ @@ -1036,7 +1045,8 @@ static virDrvOpenStatus vboxOpen(virConnectPtr conn, if (!(data->caps = vboxCapsInit()) || vboxInitialize(data) < 0 || - vboxExtractVersion(data) < 0) { + vboxExtractVersion(data) < 0 || + !(data->xmlconf = vboxXMLConfInit())) { vboxUninitialize(data); return VIR_DRV_OPEN_ERROR; } @@ -5042,8 +5052,8 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) { #endif nsresult rc; - if (!(def = virDomainDefParseString(data->caps, xml, - 1 << VIR_DOMAIN_VIRT_VBOX, + if (!(def = virDomainDefParseString(data->caps, data->xmlconf, + xml, 1 << VIR_DOMAIN_VIRT_VBOX, VIR_DOMAIN_XML_INACTIVE))) { goto cleanup; } @@ -5921,7 +5931,8 @@ vboxDomainSnapshotCreateXML(virDomainPtr dom, /* VBox has no snapshot metadata, so this flag is trivial. */ virCheckFlags(VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA, NULL); - if (!(def = virDomainSnapshotDefParseString(xmlDesc, NULL, 0, 0))) + if (!(def = virDomainSnapshotDefParseString(xmlDesc, data->caps, + data->xmlconf, 0, 0))) goto cleanup; if (def->ndisks) { -- 1.8.1.5

On Mon, Mar 11, 2013 at 04:06:25PM +0100, Peter Krempa wrote:
--- src/vbox/vbox_tmpl.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

--- src/security/virt-aa-helper.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 8ce1f53..c1a3ec9 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -71,6 +71,7 @@ typedef struct { char *files; /* list of files */ virDomainDefPtr def; /* VM definition */ virCapsPtr caps; /* VM capabilities */ + virDomainXMLConfPtr xmlconf;/* XML parser data */ char *hvm; /* type of hypervisor (eg hvm, xen) */ virArch arch; /* machine architecture */ char *newfile; /* newly added file */ @@ -85,6 +86,7 @@ vahDeinit(vahControl * ctl) VIR_FREE(ctl->def); virObjectUnref(ctl->caps); + virObjectUnref(ctl->xmlconf); VIR_FREE(ctl->files); VIR_FREE(ctl->hvm); VIR_FREE(ctl->newfile); @@ -709,6 +711,11 @@ get_definition(vahControl * ctl, const char *xmlStr) goto exit; } + if (!(ctl->xmlconf = virDomainXMLConfNew(NULL, NULL))) { + vah_error(ctl, 0, _("Failed to create XML config object")); + goto exit; + } + ctl->caps->defaultConsoleTargetType = aaDefaultConsoleType; if ((guest = virCapabilitiesAddGuest(ctl->caps, @@ -722,7 +729,8 @@ get_definition(vahControl * ctl, const char *xmlStr) goto exit; } - ctl->def = virDomainDefParseString(ctl->caps, xmlStr, -1, + ctl->def = virDomainDefParseString(ctl->caps, ctl->xmlconf, + xmlStr, -1, VIR_DOMAIN_XML_INACTIVE); if (ctl->def == NULL) { vah_error(ctl, 0, _("could not parse XML")); -- 1.8.1.5

On Mon, Mar 11, 2013 at 04:06:26PM +0100, Peter Krempa wrote:
--- src/security/virt-aa-helper.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

--- src/libxl/libxl_conf.h | 1 + src/libxl/libxl_driver.c | 51 ++++++++++++++++++++++++++++++------------------ 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/libxl/libxl_conf.h b/src/libxl/libxl_conf.h index 4c3280e..f8602b4 100644 --- a/src/libxl/libxl_conf.h +++ b/src/libxl/libxl_conf.h @@ -54,6 +54,7 @@ typedef libxlDriverPrivate *libxlDriverPrivatePtr; struct _libxlDriverPrivate { virMutex lock; virCapsPtr caps; + virDomainXMLConfPtr xmlconf; unsigned int version; FILE *logger_file; diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 35c9e16..40a7a6b 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -426,6 +426,11 @@ libxlDomainObjPrivateFree(void *data) virObjectUnref(priv); } +virDomainXMLPrivateDataCallbacks libxlDomainXMLPrivateDataCallbacks = { + .alloc = libxlDomainObjPrivateAlloc, + .free = libxlDomainObjPrivateFree, +}; + /* driver must be locked before calling */ static void libxlDomainEventQueue(libxlDriverPrivatePtr driver, virDomainEventPtr event) @@ -558,8 +563,8 @@ libxlSaveImageOpen(libxlDriverPrivatePtr driver, const char *from, goto error; } - if (!(def = virDomainDefParseString(driver->caps, xml, - 1 << VIR_DOMAIN_VIRT_XEN, + if (!(def = virDomainDefParseString(driver->caps, driver->xmlconf, + xml, 1 << VIR_DOMAIN_VIRT_XEN, VIR_DOMAIN_XML_INACTIVE))) goto error; @@ -971,7 +976,7 @@ libxlVmStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm, } - if (virDomainSaveStatus(driver->caps, driver->stateDir, vm) < 0) + if (virDomainSaveStatus(driver->xmlconf, driver->stateDir, vm) < 0) goto error; if (!driver->nactive && driver->inhibitCallback) @@ -1075,6 +1080,7 @@ libxlShutdown(void) libxlDriverLock(libxl_driver); virObjectUnref(libxl_driver->caps); + virObjectUnref(libxl_driver->xmlconf); virObjectUnref(libxl_driver->domains); libxl_ctx_free(libxl_driver->ctx); xtl_logger_destroy(libxl_driver->logger); @@ -1233,12 +1239,14 @@ libxlStartup(bool privileged, goto error; } - libxl_driver->caps->privateDataAllocFunc = libxlDomainObjPrivateAlloc; - libxl_driver->caps->privateDataFreeFunc = libxlDomainObjPrivateFree; + if (!(libxl_driver->xmlconf = virDomainXMLConfNew(&libxlDomainXMLPrivateDataCallbacks, + NULL))) + goto error; /* Load running domains first. */ if (virDomainObjListLoadAllConfigs(libxl_driver->domains, libxl_driver->caps, + libxl_driver->xmlconf, libxl_driver->stateDir, libxl_driver->autostartDir, 1, 1 << VIR_DOMAIN_VIRT_XEN, @@ -1250,6 +1258,7 @@ libxlStartup(bool privileged, /* Then inactive persistent configs */ if (virDomainObjListLoadAllConfigs(libxl_driver->domains, libxl_driver->caps, + libxl_driver->xmlconf, libxl_driver->configDir, libxl_driver->autostartDir, 0, 1 << VIR_DOMAIN_VIRT_XEN, @@ -1287,6 +1296,7 @@ libxlReload(void) libxlDriverLock(libxl_driver); virDomainObjListLoadAllConfigs(libxl_driver->domains, libxl_driver->caps, + libxl_driver->xmlconf, libxl_driver->configDir, libxl_driver->autostartDir, 1, 1 << VIR_DOMAIN_VIRT_XEN, @@ -1444,13 +1454,13 @@ libxlDomainCreateXML(virConnectPtr conn, const char *xml, virCheckFlags(VIR_DOMAIN_START_PAUSED, NULL); libxlDriverLock(driver); - if (!(def = virDomainDefParseString(driver->caps, xml, - 1 << VIR_DOMAIN_VIRT_XEN, + if (!(def = virDomainDefParseString(driver->caps, driver->xmlconf, + xml, 1 << VIR_DOMAIN_VIRT_XEN, VIR_DOMAIN_XML_INACTIVE))) goto cleanup; if (!(vm = virDomainObjListAdd(driver->domains, - driver->caps, + driver->xmlconf, def, VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, NULL))) @@ -1595,7 +1605,7 @@ libxlDomainSuspend(virDomainPtr dom) VIR_DOMAIN_EVENT_SUSPENDED_PAUSED); } - if (virDomainSaveStatus(driver->caps, driver->stateDir, vm) < 0) + if (virDomainSaveStatus(driver->xmlconf, driver->stateDir, vm) < 0) goto cleanup; ret = 0; @@ -1655,7 +1665,7 @@ libxlDomainResume(virDomainPtr dom) VIR_DOMAIN_EVENT_RESUMED_UNPAUSED); } - if (virDomainSaveStatus(driver->caps, driver->stateDir, vm) < 0) + if (virDomainSaveStatus(driver->xmlconf, driver->stateDir, vm) < 0) goto cleanup; ret = 0; @@ -1925,7 +1935,9 @@ libxlDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem, _("cannot change persistent config of a transient domain")); goto cleanup; } - if (!(persistentDef = virDomainObjGetPersistentDef(driver->caps, vm))) + if (!(persistentDef = virDomainObjGetPersistentDef(driver->caps, + driver->xmlconf, + vm))) goto cleanup; } @@ -2230,7 +2242,7 @@ libxlDomainRestoreFlags(virConnectPtr conn, const char *from, goto cleanup; if (!(vm = virDomainObjListAdd(driver->domains, - driver->caps, + driver->xmlconf, def, VIR_DOMAIN_OBJ_LIST_ADD_LIVE | VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, @@ -2568,7 +2580,7 @@ libxlDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus, priv = vm->privateData; - if (!(def = virDomainObjGetPersistentDef(driver->caps, vm))) + if (!(def = virDomainObjGetPersistentDef(driver->caps, driver->xmlconf, vm))) goto cleanup; maplen = VIR_CPU_MAPLEN(nvcpus); @@ -2746,7 +2758,7 @@ libxlDomainPinVcpu(virDomainPtr dom, unsigned int vcpu, unsigned char *cpumap, goto cleanup; } - if (virDomainSaveStatus(driver->caps, driver->stateDir, vm) < 0) + if (virDomainSaveStatus(driver->xmlconf, driver->stateDir, vm) < 0) goto cleanup; ret = 0; @@ -2919,7 +2931,7 @@ libxlDomainXMLToNative(virConnectPtr conn, const char * nativeFormat, goto cleanup; } - if (!(def = virDomainDefParseString(driver->caps, domainXml, + if (!(def = virDomainDefParseString(driver->caps, driver->xmlconf, domainXml, 1 << VIR_DOMAIN_VIRT_XEN, 0))) goto cleanup; @@ -3021,13 +3033,13 @@ libxlDomainDefineXML(virConnectPtr conn, const char *xml) virDomainDefPtr oldDef = NULL; libxlDriverLock(driver); - if (!(def = virDomainDefParseString(driver->caps, xml, + if (!(def = virDomainDefParseString(driver->caps, driver->xmlconf, xml, 1 << VIR_DOMAIN_VIRT_XEN, VIR_DOMAIN_XML_INACTIVE))) goto cleanup; if (!(vm = virDomainObjListAdd(driver->domains, - driver->caps, + driver->xmlconf, def, 0, &oldDef))) @@ -3549,7 +3561,8 @@ libxlDomainModifyDeviceFlags(virDomainPtr dom, const char *xml, goto cleanup; /* Make a copy for updated domain. */ - if (!(vmdef = virDomainObjCopyPersistentDef(driver->caps, vm))) + if (!(vmdef = virDomainObjCopyPersistentDef(driver->caps, + driver->xmlconf, vm))) goto cleanup; switch (action) { @@ -3596,7 +3609,7 @@ libxlDomainModifyDeviceFlags(virDomainPtr dom, const char *xml, * update domain status forcibly because the domain status may be * changed even if we attach the device failed. */ - if (virDomainSaveStatus(driver->caps, driver->stateDir, vm) < 0) + if (virDomainSaveStatus(driver->xmlconf, driver->stateDir, vm) < 0) ret = -1; } -- 1.8.1.5

On Mon, Mar 11, 2013 at 04:06:27PM +0100, Peter Krempa wrote:
--- src/libxl/libxl_conf.h | 1 + src/libxl/libxl_driver.c | 51 ++++++++++++++++++++++++++++++------------------ 2 files changed, 33 insertions(+), 19 deletions(-)
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

--- src/xenapi/xenapi_driver.c | 34 ++++++++++++++++++++++------------ src/xenapi/xenapi_driver_private.h | 1 + 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c index df7ab36..b368f48 100644 --- a/src/xenapi/xenapi_driver.c +++ b/src/xenapi/xenapi_driver.c @@ -169,6 +169,12 @@ xenapiOpen(virConnectPtr conn, virConnectAuthPtr auth, goto error; } + if (!(privP->xmlconf = virDomainXMLConfNew(NULL, NULL))) { + xenapiSessionErrorHandler(conn, VIR_ERR_INTERNAL_ERROR, + _("Failed to create XML conf object")); + goto error; + } + xmlInitParser(); xmlKeepBlanksDefault(0); xen_init(); @@ -208,6 +214,7 @@ xenapiOpen(virConnectPtr conn, virConnectAuthPtr auth, if (privP != NULL) { virObjectUnref(privP->caps); + virObjectUnref(privP->xmlconf); if (privP->session != NULL) xenSessionFree(privP->session); @@ -231,6 +238,7 @@ xenapiClose(virConnectPtr conn) struct _xenapiPrivate *priv = conn->privateData; virObjectUnref(priv->caps); + virObjectUnref(priv->xmlconf); if (priv->session != NULL) { xen_session_logout(priv->session); @@ -425,6 +433,7 @@ xenapiNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info) static char * xenapiGetCapabilities(virConnectPtr conn) { + virCapsPtr caps = ((struct _xenapiPrivate *)(conn->privateData))->caps; if (caps) { char *xml = virCapabilitiesFormatXML(caps); @@ -515,17 +524,17 @@ xenapiDomainCreateXML(virConnectPtr conn, const char *xmlDesc, unsigned int flags) { + struct _xenapiPrivate *priv = conn->privateData; xen_vm_record *record = NULL; xen_vm vm = NULL; virDomainPtr domP = NULL; - xen_session *session = ((struct _xenapiPrivate *)(conn->privateData))->session; - virCapsPtr caps = ((struct _xenapiPrivate *)(conn->privateData))->caps; - if (!caps) + if (!priv->caps) return NULL; virCheckFlags(0, NULL); - virDomainDefPtr defPtr = virDomainDefParseString(caps, xmlDesc, + virDomainDefPtr defPtr = virDomainDefParseString(priv->caps, priv->xmlconf, + xmlDesc, 1 << VIR_DOMAIN_VIRT_XEN, flags); createVMRecordFromXml(conn, defPtr, &record, &vm); @@ -534,7 +543,7 @@ xenapiDomainCreateXML(virConnectPtr conn, unsigned char raw_uuid[VIR_UUID_BUFLEN]; ignore_value(virUUIDParse(record->uuid, raw_uuid)); if (vm) { - if (xen_vm_start(session, vm, false, false)) { + if (xen_vm_start(priv->session, vm, false, false)) { domP = virGetDomain(conn, record->name_label, raw_uuid); if (!domP) { xen_vm_record_free(record); @@ -1672,20 +1681,21 @@ xenapiDomainCreate(virDomainPtr dom) static virDomainPtr xenapiDomainDefineXML(virConnectPtr conn, const char *xml) { + struct _xenapiPrivate *priv = conn->privateData; xen_vm_record *record=NULL; xen_vm vm=NULL; virDomainPtr domP=NULL; - xen_session *session = ((struct _xenapiPrivate *)(conn->privateData))->session; - virCapsPtr caps = ((struct _xenapiPrivate *)(conn->privateData))->caps; - if (!caps) + if (!priv->caps) return NULL; - virDomainDefPtr defPtr = virDomainDefParseString(caps, xml, - 1 << VIR_DOMAIN_VIRT_XEN, 0); + virDomainDefPtr defPtr = virDomainDefParseString(priv->caps, priv->xmlconf, + xml, + 1 << VIR_DOMAIN_VIRT_XEN, + 0); if (!defPtr) return NULL; if (createVMRecordFromXml(conn, defPtr, &record, &vm) != 0) { - if (!session->ok) + if (!priv->session->ok) xenapiSessionErrorHandler(conn, VIR_ERR_INTERNAL_ERROR, NULL); else xenapiSessionErrorHandler(conn, VIR_ERR_INTERNAL_ERROR, @@ -1697,7 +1707,7 @@ xenapiDomainDefineXML(virConnectPtr conn, const char *xml) unsigned char raw_uuid[VIR_UUID_BUFLEN]; ignore_value(virUUIDParse(record->uuid, raw_uuid)); domP = virGetDomain(conn, record->name_label, raw_uuid); - if (!domP && !session->ok) + if (!domP && !priv->session->ok) xenapiSessionErrorHandler(conn, VIR_ERR_NO_DOMAIN, NULL); xen_vm_record_free(record); } diff --git a/src/xenapi/xenapi_driver_private.h b/src/xenapi/xenapi_driver_private.h index 7e5b6e7..92c18fe 100644 --- a/src/xenapi/xenapi_driver_private.h +++ b/src/xenapi/xenapi_driver_private.h @@ -58,6 +58,7 @@ struct _xenapiPrivate { char *url; int noVerify; virCapsPtr caps; + virDomainXMLConfPtr xmlconf; }; #endif /* __VIR_XENAPI_H__ */ -- 1.8.1.5

On Mon, Mar 11, 2013 at 04:06:28PM +0100, Peter Krempa wrote:
--- src/xenapi/xenapi_driver.c | 34 ++++++++++++++++++++++------------ src/xenapi/xenapi_driver_private.h | 1 + 2 files changed, 23 insertions(+), 12 deletions(-)
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

--- tests/securityselinuxlabeltest.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/securityselinuxlabeltest.c b/tests/securityselinuxlabeltest.c index 2454772..405bc2b 100644 --- a/tests/securityselinuxlabeltest.c +++ b/tests/securityselinuxlabeltest.c @@ -44,6 +44,7 @@ #define VIR_FROM_THIS VIR_FROM_NONE static virCapsPtr caps; +static virDomainXMLConfPtr xmlconf; static virSecurityManagerPtr mgr; @@ -165,7 +166,7 @@ testSELinuxLoadDef(const char *testname) goto cleanup; } - if (!(def = virDomainDefParseString(caps, xmlstr, + if (!(def = virDomainDefParseString(caps, xmlconf, xmlstr, QEMU_EXPECTED_VIRT_TYPES, 0))) goto cleanup; @@ -327,6 +328,9 @@ mymain(void) if ((caps = testQemuCapsInit()) == NULL) return EXIT_FAILURE; + if (!(xmlconf = virQEMUDriverCreateXMLConf())) + return EXIT_FAILURE; + #define DO_TEST_LABELING(name) \ if (virtTestRun("Labelling " # name, 1, testSELinuxLabeling, name) < 0) \ ret = -1; \ -- 1.8.1.5

On Mon, Mar 11, 2013 at 04:06:29PM +0100, Peter Krempa wrote:
--- tests/securityselinuxlabeltest.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

This patch adds instrumentation that will ultimately allow to split out filling of defaults and input validation from the XML parser to separate functions. With this patch, after the XML is parsed, a callback to the driver is issued requesing to fill and validate driver specific details of the configuration. This allows to use sensible defaults and checks on a per driver basis at the time the XML is parsed. Three callback pointers are exposed in the new virDomainXMLConf object: * virDomainDeviceDefAdjustCallback - called for a single device parsed and for every single device in a domain config. A virDomainDeviceDefPtr is passed along with the domain definition and virCaps. * virDomainDefAdjustCallback - called if a domain definition is parsed device specific callbacks were called. A virDomainDefPtr is passed along with virCaps. There are two callbacks of this kind, one called before the devices are parsed and one after. Errors may be reported in those callbacks resulting in a XML parsing failure. Additionally internal filler and checker functions are added that are meant to be used forseparating the validation and defaults assignment code from the parser function. --- Notes: Version 3: - added support for opaque data for the callback src/conf/domain_conf.c | 120 +++++++++++++++++++++++++++++++++++++++++++++++-- src/conf/domain_conf.h | 19 ++++++++ 2 files changed, 136 insertions(+), 3 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 127629f..6766775 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -747,18 +747,26 @@ struct _virDomainXMLConf { /* XML namespace callbacks */ virDomainXMLNamespace ns; - }; - + /* Parser data adjust callbacks */ + virDomainDefAdjustCallbacks adjust; + }; static virClassPtr virDomainXMLConfClass; +static void virDoaminXMLConfClassDispose(void *obj) +{ + virDomainXMLConfPtr xmlconf = obj; + + if (xmlconf->adjust.privFree) + (xmlconf->adjust.privFree)(xmlconf->adjust.priv); +} static int virDomainXMLConfOnceInit(void) { if (!(virDomainXMLConfClass = virClassNew(virClassForObject(), "virDomainXMLConf", sizeof(virDomainXMLConf), - NULL))) + virDoaminXMLConfClassDispose))) return -1; return 0; @@ -2450,6 +2458,104 @@ int virDomainDeviceInfoIterate(virDomainDefPtr def, } +static int +virDomainDeviceDefAdjustInternal(virDomainDeviceDefPtr dev ATTRIBUTE_UNUSED, + virDomainDefPtr def ATTRIBUTE_UNUSED, + virCapsPtr caps ATTRIBUTE_UNUSED) +{ + /* not in use yet */ + return 0; +} + + +static int +virDomainDefAdjustInternal(virDomainDefPtr def ATTRIBUTE_UNUSED, + virCapsPtr caps ATTRIBUTE_UNUSED) +{ + /* not in use yet */ + return 0; +} + + +static int +virDomainDeviceDefAdjust(virDomainXMLConfPtr xmlconf, + virDomainDeviceDefPtr dev, + virDomainDefPtr def, + virCapsPtr caps) +{ + int ret; + + if ((ret = virDomainDeviceDefAdjustInternal(dev, def, caps)) < 0) + return ret; + + if (xmlconf && xmlconf->adjust.devices) { + if ((ret = xmlconf->adjust.devices(dev, def, caps, + xmlconf->adjust.priv)) < 0) + return ret; + } + + return 0; +} + + +struct virDomainDefAdjustDeviceIteratorData { + virCapsPtr caps; + virDomainDefPtr def; + virDomainXMLConfPtr xmlconf; +}; + + +static int +virDomainDefAdjustDeviceIterator(virDomainDefPtr def ATTRIBUTE_UNUSED, + virDomainDeviceDefPtr dev, + virDomainDeviceInfoPtr info ATTRIBUTE_UNUSED, + void *opaque) +{ + struct virDomainDefAdjustDeviceIteratorData *data = opaque; + return virDomainDeviceDefAdjust(data->xmlconf, dev, data->def, data->caps); +} + + +static int +virDomainDefAdjust(virDomainXMLConfPtr xmlconf, + virDomainDefPtr def, + virCapsPtr caps) +{ + int ret; + struct virDomainDefAdjustDeviceIteratorData data = { + .caps = caps, + .def = def, + .xmlconf = xmlconf, + }; + + /* first the global changes */ + if ((ret = virDomainDefAdjustInternal(def, caps)) < 0) + return ret; + + /* then call the before-devices callback */ + if (xmlconf && xmlconf->adjust.domainBeforeDevices) { + if ((ret = xmlconf->adjust.domainBeforeDevices(def, caps, + xmlconf->adjust.priv)) < 0) + return ret; + } + + /* iterate the devices */ + if ((ret = virDomainDeviceInfoIterate(def, + virDomainDefAdjustDeviceIterator, + &data)) < 0) + return ret; + + /* call the after-device callback */ + if (xmlconf && xmlconf->adjust.domainAfterDevices) { + if ((ret = xmlconf->adjust.domainAfterDevices(def, caps, + xmlconf->adjust.priv)) < 0) + return ret; + } + + return 0; +} + + void virDomainDefClearPCIAddresses(virDomainDefPtr def) { virDomainDeviceInfoIterate(def, virDomainDeviceInfoClearPCIAddress, NULL); @@ -8361,6 +8467,10 @@ virDomainDeviceDefParse(virCapsPtr caps, goto error; } + /* callback to fill driver specific device aspects */ + if (virDomainDeviceDefAdjust(xmlconf, dev, def, caps) < 0) + goto error; + cleanup: xmlFreeDoc(xml); xmlXPathFreeContext(ctxt); @@ -10882,6 +10992,10 @@ virDomainDefParseXML(virCapsPtr caps, if (virDomainDefAddImplicitControllers(def) < 0) goto error; + /* callback to fill driver specific domain aspects */ + if (virDomainDefAdjust(xmlconf, def, caps) < 0) + goto error; + virBitmapFree(bootMap); return def; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 8b17f1e..98a5c37 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1937,6 +1937,25 @@ typedef void (*virDomainXMLPrivateDataFreeFunc)(void *); typedef int (*virDomainXMLPrivateDataFormatFunc)(virBufferPtr, void *); typedef int (*virDomainXMLPrivateDataParseFunc)(xmlXPathContextPtr, void *); +typedef int (*virDomainDefAdjustCallback)(virDomainDefPtr def, + virCapsPtr caps, + void *opaque); +typedef int (*virDomainDeviceDefAdjustCallback)(virDomainDeviceDefPtr dev, + virDomainDefPtr def, + virCapsPtr caps, + void *opaque); + +typedef struct _virDomainDefAdjustCallbacks virDomainDefAdjustCallbacks; +typedef virDomainDefAdjustCallbacks *virDomainDefAdjustCallbacksPtr; +struct _virDomainDefAdjustCallbacks { + virDomainDefAdjustCallback domainBeforeDevices; + virDomainDeviceDefAdjustCallback devices; + virDomainDefAdjustCallback domainAfterDevices; + + void *priv; + virFreeCallback privFree; +}; + typedef struct _virDomainXMLPrivateDataCallbacks virDomainXMLPrivateDataCallbacks; typedef virDomainXMLPrivateDataCallbacks *virDomainXMLPrivateDataCallbacksPtr; struct _virDomainXMLPrivateDataCallbacks { -- 1.8.1.5

On Mon, Mar 11, 2013 at 04:06:30PM +0100, Peter Krempa wrote:
This patch adds instrumentation that will ultimately allow to split out filling of defaults and input validation from the XML parser to separate functions.
With this patch, after the XML is parsed, a callback to the driver is issued requesing to fill and validate driver specific details of the configuration. This allows to use sensible defaults and checks on a per driver basis at the time the XML is parsed.
Three callback pointers are exposed in the new virDomainXMLConf object:
You say three but only show two here.
* virDomainDeviceDefAdjustCallback - called for a single device parsed and for every single device in a domain config. A virDomainDeviceDefPtr is passed along with the domain definition and virCaps. * virDomainDefAdjustCallback - called if a domain definition is parsed device specific callbacks were called. A virDomainDefPtr is passed along with virCaps. There are two callbacks of this kind, one called before the devices are parsed and one after.
On naming, I think s/Adjust/PostParse/ is better
static virClassPtr virDomainXMLConfClass; +static void virDoaminXMLConfClassDispose(void *obj)
s/Doamin/Domain/
+{ + virDomainXMLConfPtr xmlconf = obj; + + if (xmlconf->adjust.privFree) + (xmlconf->adjust.privFree)(xmlconf->adjust.priv); +}
static int virDomainXMLConfOnceInit(void) { if (!(virDomainXMLConfClass = virClassNew(virClassForObject(), "virDomainXMLConf", sizeof(virDomainXMLConf), - NULL))) + virDoaminXMLConfClassDispose)))
s/Doamin/Domain/
return -1;
return 0; @@ -2450,6 +2458,104 @@ int virDomainDeviceInfoIterate(virDomainDefPtr def, }
+static int +virDomainDeviceDefAdjustInternal(virDomainDeviceDefPtr dev ATTRIBUTE_UNUSED, + virDomainDefPtr def ATTRIBUTE_UNUSED, + virCapsPtr caps ATTRIBUTE_UNUSED) +{ + /* not in use yet */ + return 0; +} + + +static int +virDomainDefAdjustInternal(virDomainDefPtr def ATTRIBUTE_UNUSED, + virCapsPtr caps ATTRIBUTE_UNUSED) +{ + /* not in use yet */ + return 0; +} + + +static int +virDomainDeviceDefAdjust(virDomainXMLConfPtr xmlconf, + virDomainDeviceDefPtr dev, + virDomainDefPtr def, + virCapsPtr caps) +{ + int ret; + + if ((ret = virDomainDeviceDefAdjustInternal(dev, def, caps)) < 0) + return ret; + + if (xmlconf && xmlconf->adjust.devices) { + if ((ret = xmlconf->adjust.devices(dev, def, caps, + xmlconf->adjust.priv)) < 0) + return ret; + } + + return 0; +} + + +struct virDomainDefAdjustDeviceIteratorData { + virCapsPtr caps; + virDomainDefPtr def; + virDomainXMLConfPtr xmlconf; +}; + + +static int +virDomainDefAdjustDeviceIterator(virDomainDefPtr def ATTRIBUTE_UNUSED, + virDomainDeviceDefPtr dev, + virDomainDeviceInfoPtr info ATTRIBUTE_UNUSED, + void *opaque) +{ + struct virDomainDefAdjustDeviceIteratorData *data = opaque; + return virDomainDeviceDefAdjust(data->xmlconf, dev, data->def, data->caps); +} + + +static int +virDomainDefAdjust(virDomainXMLConfPtr xmlconf, + virDomainDefPtr def, + virCapsPtr caps)
s/Adjust/PostParse/ in this function and really all other changes here. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

--- src/conf/domain_conf.c | 4 +++- src/conf/domain_conf.h | 2 ++ src/libxl/libxl_driver.c | 6 ++++-- src/lxc/lxc_driver.c | 6 ++++-- src/openvz/openvz_driver.c | 4 ++-- src/phyp/phyp_driver.c | 4 ++-- src/qemu/qemu_driver.c | 11 +++++++---- src/uml/uml_driver.c | 4 ++-- src/vbox/vbox_tmpl.c | 8 ++++---- src/xen/xend_internal.c | 6 +++--- src/xen/xm_internal.c | 2 ++ 11 files changed, 35 insertions(+), 22 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6766775..39c1eed 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8381,6 +8381,7 @@ virDomainPMStateParseXML(xmlXPathContextPtr ctxt, virDomainDeviceDefPtr virDomainDeviceDefParse(virCapsPtr caps, + virDomainXMLConfPtr xmlconf, virDomainDefPtr def, const char *xmlStr, unsigned int flags) @@ -16385,6 +16386,7 @@ virDomainNetFind(virDomainDefPtr def, const char *device) */ virDomainDeviceDefPtr virDomainDeviceDefCopy(virCapsPtr caps, + virDomainXMLConfPtr xmlconf, const virDomainDefPtr def, virDomainDeviceDefPtr src) { @@ -16453,7 +16455,7 @@ virDomainDeviceDefCopy(virCapsPtr caps, goto cleanup; xmlStr = virBufferContentAndReset(&buf); - ret = virDomainDeviceDefParse(caps, def, xmlStr, flags); + ret = virDomainDeviceDefParse(caps, xmlconf, def, xmlStr, flags); cleanup: VIR_FREE(xmlStr); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 98a5c37..b9bfd31 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2025,6 +2025,7 @@ void virDomainRedirdevDefFree(virDomainRedirdevDefPtr def); void virDomainRedirFilterDefFree(virDomainRedirFilterDefPtr def); void virDomainDeviceDefFree(virDomainDeviceDefPtr def); virDomainDeviceDefPtr virDomainDeviceDefCopy(virCapsPtr caps, + virDomainXMLConfPtr xmlconf, const virDomainDefPtr def, virDomainDeviceDefPtr src); int virDomainDeviceAddressIsValid(virDomainDeviceInfoPtr info, @@ -2087,6 +2088,7 @@ void virDomainObjListRemove(virDomainObjListPtr doms, virDomainObjPtr dom); virDomainDeviceDefPtr virDomainDeviceDefParse(virCapsPtr caps, + virDomainXMLConfPtr xmlconf, virDomainDefPtr def, const char *xmlStr, unsigned int flags); diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 40a7a6b..af1f9a9 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -3556,7 +3556,8 @@ libxlDomainModifyDeviceFlags(virDomainPtr dom, const char *xml, priv = vm->privateData; if (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG) { - if (!(dev = virDomainDeviceDefParse(driver->caps, vm->def, xml, + if (!(dev = virDomainDeviceDefParse(driver->caps, driver->xmlconf, + vm->def, xml, VIR_DOMAIN_XML_INACTIVE))) goto cleanup; @@ -3586,7 +3587,8 @@ libxlDomainModifyDeviceFlags(virDomainPtr dom, const char *xml, if (flags & VIR_DOMAIN_DEVICE_MODIFY_LIVE) { /* If dev exists it was created to modify the domain config. Free it. */ virDomainDeviceDefFree(dev); - if (!(dev = virDomainDeviceDefParse(driver->caps, vm->def, xml, + if (!(dev = virDomainDeviceDefParse(driver->caps, driver->xmlconf, + vm->def, xml, VIR_DOMAIN_XML_INACTIVE))) goto cleanup; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 59bb786..97dd3b4 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -4337,7 +4337,8 @@ lxcDomainModifyDeviceFlags(virDomainPtr dom, const char *xml, goto cleanup; } - dev = dev_copy = virDomainDeviceDefParse(driver->caps, vm->def, xml, + dev = dev_copy = virDomainDeviceDefParse(driver->caps, driver->xmlconf, + vm->def, xml, VIR_DOMAIN_XML_INACTIVE); if (dev == NULL) goto cleanup; @@ -4348,7 +4349,8 @@ lxcDomainModifyDeviceFlags(virDomainPtr dom, const char *xml, * create a deep copy of device as adding * to CONFIG takes one instance. */ - dev_copy = virDomainDeviceDefCopy(driver->caps, vm->def, dev); + dev_copy = virDomainDeviceDefCopy(driver->caps, driver->xmlconf, + vm->def, dev); if (!dev_copy) goto cleanup; } diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 67d66ae..d537185 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -2085,8 +2085,8 @@ openvzDomainUpdateDeviceFlags(virDomainPtr dom, const char *xml, &vmdef) < 0) goto cleanup; - dev = virDomainDeviceDefParse(driver->caps, vmdef, xml, - VIR_DOMAIN_XML_INACTIVE); + dev = virDomainDeviceDefParse(driver->caps, driver->xmlconf, + vmdef, xml, VIR_DOMAIN_XML_INACTIVE); if (!dev) goto cleanup; diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index 59cc1ca..c35417b 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -1754,8 +1754,8 @@ phypAttachDevice(virDomainPtr domain, const char *xml) goto cleanup; } - dev = virDomainDeviceDefParse(phyp_driver->caps, def, xml, - VIR_DOMAIN_XML_INACTIVE); + dev = virDomainDeviceDefParse(phyp_driver->caps, NULL, + def, xml, VIR_DOMAIN_XML_INACTIVE); if (!dev) { goto cleanup; } diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 8e0abc3..6101ee6 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -5774,7 +5774,8 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn, tmp = dev->data.disk; dev->data.disk = orig_disk; - if (!(dev_copy = virDomainDeviceDefCopy(caps, vm->def, dev))) { + if (!(dev_copy = virDomainDeviceDefCopy(caps, driver->xmlconf, + vm->def, dev))) { dev->data.disk = tmp; goto end; } @@ -6050,7 +6051,8 @@ qemuDomainChangeDiskMediaLive(virDomainObjPtr vm, tmp = dev->data.disk; dev->data.disk = orig_disk; - if (!(dev_copy = virDomainDeviceDefCopy(caps, vm->def, dev))) { + if (!(dev_copy = virDomainDeviceDefCopy(caps, driver->xmlconf, + vm->def, dev))) { dev->data.disk = tmp; goto end; } @@ -6449,7 +6451,8 @@ qemuDomainModifyDeviceFlags(virDomainPtr dom, const char *xml, goto endjob; } - dev = dev_copy = virDomainDeviceDefParse(caps, vm->def, xml, + dev = dev_copy = virDomainDeviceDefParse(caps, driver->xmlconf, + vm->def, xml, VIR_DOMAIN_XML_INACTIVE); if (dev == NULL) goto endjob; @@ -6460,7 +6463,7 @@ qemuDomainModifyDeviceFlags(virDomainPtr dom, const char *xml, * create a deep copy of device as adding * to CONFIG takes one instance. */ - dev_copy = virDomainDeviceDefCopy(caps, vm->def, dev); + dev_copy = virDomainDeviceDefCopy(caps, driver->xmlconf, vm->def, dev); if (!dev_copy) goto endjob; } diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index b08212d..3a8a98a 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -2080,7 +2080,7 @@ static int umlDomainAttachDevice(virDomainPtr dom, const char *xml) goto cleanup; } - dev = virDomainDeviceDefParse(driver->caps, vm->def, xml, + dev = virDomainDeviceDefParse(driver->caps, driver->xmlconf, vm->def, xml, VIR_DOMAIN_XML_INACTIVE); if (dev == NULL) @@ -2198,7 +2198,7 @@ static int umlDomainDetachDevice(virDomainPtr dom, const char *xml) { goto cleanup; } - dev = virDomainDeviceDefParse(driver->caps, vm->def, xml, + dev = virDomainDeviceDefParse(driver->caps, driver->xmlconf, vm->def, xml, VIR_DOMAIN_XML_INACTIVE); if (dev == NULL) goto cleanup; diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index aa7466b..7a47067 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -5396,8 +5396,8 @@ static int vboxDomainAttachDeviceImpl(virDomainPtr dom, goto cleanup; } - dev = virDomainDeviceDefParse(data->caps, def, xml, - VIR_DOMAIN_XML_INACTIVE); + dev = virDomainDeviceDefParse(data->caps, data->xmlconf, + def, xml, VIR_DOMAIN_XML_INACTIVE); if (dev == NULL) goto cleanup; @@ -5631,8 +5631,8 @@ static int vboxDomainDetachDevice(virDomainPtr dom, const char *xml) { goto cleanup; } - dev = virDomainDeviceDefParse(data->caps, def, xml, - VIR_DOMAIN_XML_INACTIVE); + dev = virDomainDeviceDefParse(data->caps, data->xmlconf, + def, xml, VIR_DOMAIN_XML_INACTIVE); if (dev == NULL) goto cleanup; diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c index 398da0d..93ba456 100644 --- a/src/xen/xend_internal.c +++ b/src/xen/xend_internal.c @@ -2519,7 +2519,7 @@ xenDaemonAttachDeviceFlags(virDomainPtr domain, NULL))) goto cleanup; - if (!(dev = virDomainDeviceDefParse(priv->caps, + if (!(dev = virDomainDeviceDefParse(priv->caps, priv->xmlconf, def, xml, VIR_DOMAIN_XML_INACTIVE))) goto cleanup; @@ -2679,7 +2679,7 @@ xenDaemonUpdateDeviceFlags(virDomainPtr domain, NULL))) goto cleanup; - if (!(dev = virDomainDeviceDefParse(priv->caps, + if (!(dev = virDomainDeviceDefParse(priv->caps, priv->xmlconf, def, xml, VIR_DOMAIN_XML_INACTIVE))) goto cleanup; @@ -2786,7 +2786,7 @@ xenDaemonDetachDeviceFlags(virDomainPtr domain, NULL))) goto cleanup; - if (!(dev = virDomainDeviceDefParse(priv->caps, + if (!(dev = virDomainDeviceDefParse(priv->caps, priv->xmlconf, def, xml, VIR_DOMAIN_XML_INACTIVE))) goto cleanup; diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c index f6a3593..2a42e0a 100644 --- a/src/xen/xm_internal.c +++ b/src/xen/xm_internal.c @@ -1311,6 +1311,7 @@ xenXMDomainAttachDeviceFlags(virDomainPtr domain, def = entry->def; if (!(dev = virDomainDeviceDefParse(priv->caps, + priv->xmlconf, entry->def, xml, VIR_DOMAIN_XML_INACTIVE))) goto cleanup; @@ -1404,6 +1405,7 @@ xenXMDomainDetachDeviceFlags(virDomainPtr domain, def = entry->def; if (!(dev = virDomainDeviceDefParse(priv->caps, + priv->xmlconf, entry->def, xml, VIR_DOMAIN_XML_INACTIVE))) goto cleanup; -- 1.8.1.5

On Mon, Mar 11, 2013 at 04:06:31PM +0100, Peter Krempa wrote:
--- src/conf/domain_conf.c | 4 +++- src/conf/domain_conf.h | 2 ++ src/libxl/libxl_driver.c | 6 ++++-- src/lxc/lxc_driver.c | 6 ++++-- src/openvz/openvz_driver.c | 4 ++-- src/phyp/phyp_driver.c | 4 ++-- src/qemu/qemu_driver.c | 11 +++++++---- src/uml/uml_driver.c | 4 ++-- src/vbox/vbox_tmpl.c | 8 ++++---- src/xen/xend_internal.c | 6 +++--- src/xen/xm_internal.c | 2 ++ 11 files changed, 35 insertions(+), 22 deletions(-)
ACK, I'm really not finding it helpful to have this code split out for review. Please just post patches which are self-contained and compile. It is not nice reviewing one patch, to identify a problem and then search through later "fixup" patches to see if it is fixed or not. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

This patch adds a argument to the virDomainXMLConfNew constructor to pass the driver adjust callback pointers and fixes the fallout of this change. --- src/conf/domain_conf.c | 4 ++++ src/conf/domain_conf.h | 1 + src/esx/esx_driver.c | 2 +- src/libxl/libxl_driver.c | 2 +- src/lxc/lxc_conf.c | 2 +- src/openvz/openvz_conf.c | 1 + src/openvz/openvz_driver.c | 2 +- src/parallels/parallels_driver.c | 2 +- src/phyp/phyp_driver.c | 2 +- src/qemu/qemu_conf.c | 1 + src/security/virt-aa-helper.c | 2 +- src/test/test_driver.c | 2 +- src/uml/uml_driver.c | 3 +-- src/vbox/vbox_tmpl.c | 2 +- src/vmware/vmware_driver.c | 2 +- src/xen/xen_driver.c | 2 +- src/xenapi/xenapi_driver.c | 2 +- tests/testutilsxen.c | 2 +- tests/xml2vmxtest.c | 2 +- 19 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 39c1eed..ce65eac 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -781,6 +781,7 @@ VIR_ONCE_GLOBAL_INIT(virDomainXMLConf) */ virDomainXMLConfPtr virDomainXMLConfNew(virDomainXMLPrivateDataCallbacksPtr priv, + virDomainDefAdjustCallbacksPtr adjust, virDomainXMLNamespacePtr xmlns) { virDomainXMLConfPtr xmlconf; @@ -794,6 +795,9 @@ virDomainXMLConfNew(virDomainXMLPrivateDataCallbacksPtr priv, if (priv) xmlconf->privateData = *priv; + if (adjust) + xmlconf->adjust = *adjust; + if (xmlns) xmlconf->ns = *xmlns; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index b9bfd31..ab66707 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1967,6 +1967,7 @@ struct _virDomainXMLPrivateDataCallbacks { virDomainXMLConfPtr virDomainXMLConfNew(virDomainXMLPrivateDataCallbacksPtr priv, + virDomainDefAdjustCallbacksPtr adjust, virDomainXMLNamespacePtr xmlns); virDomainXMLNamespacePtr diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index fc8a3ae..2bff60e 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -1100,7 +1100,7 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, goto cleanup; } - if (!(priv->xmlconf = virDomainXMLConfNew(NULL, NULL))) + if (!(priv->xmlconf = virDomainXMLConfNew(NULL, NULL, NULL))) goto cleanup; conn->privateData = priv; diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index af1f9a9..090938c 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -1240,7 +1240,7 @@ libxlStartup(bool privileged, } if (!(libxl_driver->xmlconf = virDomainXMLConfNew(&libxlDomainXMLPrivateDataCallbacks, - NULL))) + NULL, NULL))) goto error; /* Load running domains first. */ diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c index c723e77..4e2306d 100644 --- a/src/lxc/lxc_conf.c +++ b/src/lxc/lxc_conf.c @@ -159,7 +159,7 @@ error: virDomainXMLConfPtr lxcDomainXMLConfInit(void) { - return virDomainXMLConfNew(&virLXCDriverPrivateDataCallbacks, NULL); + return virDomainXMLConfNew(&virLXCDriverPrivateDataCallbacks, NULL, NULL); } int lxcLoadDriverConfig(virLXCDriverPtr driver) diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index f175655..e3e64e5 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -174,6 +174,7 @@ static int openvzDefaultConsoleType(const char *ostype ATTRIBUTE_UNUSED, return VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_OPENVZ; } + virCapsPtr openvzCapsInit(void) { virCapsPtr caps; diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index d537185..a6f4c66 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -1453,7 +1453,7 @@ static virDrvOpenStatus openvzOpen(virConnectPtr conn, if (!(driver->caps = openvzCapsInit())) goto cleanup; - if (!(driver->xmlconf = virDomainXMLConfNew(NULL, NULL))) + if (!(driver->xmlconf = virDomainXMLConfNew(NULL, NULL, NULL))) goto cleanup; if (openvzLoadDomains(driver) < 0) diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c index 88f41f7..ffb86dc 100644 --- a/src/parallels/parallels_driver.c +++ b/src/parallels/parallels_driver.c @@ -929,7 +929,7 @@ parallelsOpenDefault(virConnectPtr conn) if (!(privconn->caps = parallelsBuildCapabilities())) goto error; - if (!(privconn->xmlconf = virDomainXMLConfNew(NULL, NULL))) + if (!(privconn->xmlconf = virDomainXMLConfNew(NULL, NULL, NULL))) goto error; if (!(privconn->domains = virDomainObjListNew())) diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index c35417b..6063256 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -1204,7 +1204,7 @@ phypOpen(virConnectPtr conn, goto failure; } - if (!(phyp_driver->xmlconf = virDomainXMLConfNew(NULL, NULL))) + if (!(phyp_driver->xmlconf = virDomainXMLConfNew(NULL, NULL, NULL))) goto failure; conn->privateData = phyp_driver; diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 1beff6d..ef592cd 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -555,6 +555,7 @@ virDomainXMLConfPtr virQEMUDriverCreateXMLConf(void) { return virDomainXMLConfNew(&virQEMUDriverPrivateDataCallbacks, + NULL, &virQEMUDriverDomainXMLNamespace); } diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index c1a3ec9..866eac3 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -711,7 +711,7 @@ get_definition(vahControl * ctl, const char *xmlStr) goto exit; } - if (!(ctl->xmlconf = virDomainXMLConfNew(NULL, NULL))) { + if (!(ctl->xmlconf = virDomainXMLConfNew(NULL, NULL, NULL))) { vah_error(ctl, 0, _("Failed to create XML config object")); goto exit; } diff --git a/src/test/test_driver.c b/src/test/test_driver.c index c5fffb9..31ac116 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -162,7 +162,7 @@ testBuildXMLConfig(void) { virDomainXMLPrivateDataCallbacks priv = { .alloc = testDomainObjPrivateAlloc, .free = testDomainObjPrivateFree }; - return virDomainXMLConfNew(&priv, NULL); + return virDomainXMLConfNew(&priv, NULL, NULL); } diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index 3a8a98a..a6833fa 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -505,8 +505,7 @@ umlStartup(bool privileged, if ((uml_driver->caps = umlCapsInit()) == NULL) goto out_of_memory; - if (!(uml_driver->xmlconf = virDomainXMLConfNew(&privcb, - NULL))) + if (!(uml_driver->xmlconf = virDomainXMLConfNew(&privcb, NULL, NULL))) goto error; if ((uml_driver->inotifyFD = inotify_init()) < 0) { diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 7a47067..dd96e7b 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -854,7 +854,7 @@ static int vboxDefaultConsoleType(const char *ostype ATTRIBUTE_UNUSED, static virDomainXMLConfPtr vboxXMLConfInit(void) { - return virDomainXMLConfNew(NULL, NULL); + return virDomainXMLConfNew(NULL, NULL, NULL); } diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index 6d82532..c927b18 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -78,7 +78,7 @@ vmwareDomainXMLConfigInit(void) virDomainXMLPrivateDataCallbacks priv = { .alloc = vmwareDataAllocFunc, .free = vmwareDataFreeFunc }; - return virDomainXMLConfNew(&priv, NULL); + return virDomainXMLConfNew(&priv, NULL, NULL); } static virDrvOpenStatus diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c index fd20b73..2ef3609 100644 --- a/src/xen/xen_driver.c +++ b/src/xen/xen_driver.c @@ -401,7 +401,7 @@ xenUnifiedOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int flags) goto fail; } - if (!(priv->xmlconf = virDomainXMLConfNew(NULL, NULL))) + if (!(priv->xmlconf = virDomainXMLConfNew(NULL, NULL, NULL))) goto fail; #if WITH_XEN_INOTIFY diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c index b368f48..941f3bd 100644 --- a/src/xenapi/xenapi_driver.c +++ b/src/xenapi/xenapi_driver.c @@ -169,7 +169,7 @@ xenapiOpen(virConnectPtr conn, virConnectAuthPtr auth, goto error; } - if (!(privP->xmlconf = virDomainXMLConfNew(NULL, NULL))) { + if (!(privP->xmlconf = virDomainXMLConfNew(NULL, NULL, NULL))) { xenapiSessionErrorHandler(conn, VIR_ERR_INTERNAL_ERROR, _("Failed to create XML conf object")); goto error; diff --git a/tests/testutilsxen.c b/tests/testutilsxen.c index 201ea2a..479eec3 100644 --- a/tests/testutilsxen.c +++ b/tests/testutilsxen.c @@ -18,7 +18,7 @@ static int testXenDefaultConsoleType(const char *ostype, virDomainXMLConfPtr testXenXMLConfInit(void) { - return virDomainXMLConfNew(NULL, NULL); + return virDomainXMLConfNew(NULL, NULL, NULL); } virCapsPtr testXenCapsInit(void) { diff --git a/tests/xml2vmxtest.c b/tests/xml2vmxtest.c index 800fd2c..c606036 100644 --- a/tests/xml2vmxtest.c +++ b/tests/xml2vmxtest.c @@ -240,7 +240,7 @@ mymain(void) return EXIT_FAILURE; } - if (!(xmlconf = virDomainXMLConfNew(NULL, NULL))) + if (!(xmlconf = virDomainXMLConfNew(NULL, NULL, NULL))) return EXIT_FAILURE; ctx.opaque = NULL; -- 1.8.1.5

On Mon, Mar 11, 2013 at 04:06:32PM +0100, Peter Krempa wrote:
This patch adds a argument to the virDomainXMLConfNew constructor to pass the driver adjust callback pointers and fixes the fallout of this change. --- src/conf/domain_conf.c | 4 ++++ src/conf/domain_conf.h | 1 + src/esx/esx_driver.c | 2 +- src/libxl/libxl_driver.c | 2 +- src/lxc/lxc_conf.c | 2 +- src/openvz/openvz_conf.c | 1 + src/openvz/openvz_driver.c | 2 +- src/parallels/parallels_driver.c | 2 +- src/phyp/phyp_driver.c | 2 +- src/qemu/qemu_conf.c | 1 + src/security/virt-aa-helper.c | 2 +- src/test/test_driver.c | 2 +- src/uml/uml_driver.c | 3 +-- src/vbox/vbox_tmpl.c | 2 +- src/vmware/vmware_driver.c | 2 +- src/xen/xen_driver.c | 2 +- src/xenapi/xenapi_driver.c | 2 +- tests/testutilsxen.c | 2 +- tests/xml2vmxtest.c | 2 +- 19 files changed, 22 insertions(+), 16 deletions(-)
ACK, though again I think this should just be part of the patch which introduces this functionality, since it is useless without this. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

This patch implements the callback that is used to fill the qemu default network card into the XML if none is specified. Libvirt assumes that the network card for qemu if none specified is the "rtl8139". Record this in the XML using the new callback to avoid user confusion. --- src/qemu/qemu_conf.c | 2 +- src/qemu/qemu_domain.c | 26 ++++++++++++++++++++++++++ src/qemu/qemu_domain.h | 1 + 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index ef592cd..b9b7357 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -555,7 +555,7 @@ virDomainXMLConfPtr virQEMUDriverCreateXMLConf(void) { return virDomainXMLConfNew(&virQEMUDriverPrivateDataCallbacks, - NULL, + &virQEMUDriverDomainDefAdjustCallbacks, &virQEMUDriverDomainXMLNamespace); } diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 2be207f..94d4c01 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -646,6 +646,7 @@ qemuDomainDefNamespaceFormatXML(virBufferPtr buf, return 0; } + static const char * qemuDomainDefNamespaceHref(void) { @@ -661,6 +662,31 @@ virDomainXMLNamespace virQEMUDriverDomainXMLNamespace = { }; +static int +qemuDomainDeviceDefAdjust(virDomainDeviceDefPtr dev, + virDomainDefPtr def ATTRIBUTE_UNUSED, + virCapsPtr caps ATTRIBUTE_UNUSED, + void *opaque ATTRIBUTE_UNUSED) +{ + if (dev->type == VIR_DOMAIN_DEVICE_NET && + dev->data.net->type != VIR_DOMAIN_NET_TYPE_HOSTDEV) { + if (!dev->data.net->model && + !(dev->data.net->model = strdup("rtl8139"))) + goto no_memory; + } + return 0; + +no_memory: + virReportOOMError(); + return -1; +} + + +virDomainDefAdjustCallbacks virQEMUDriverDomainDefAdjustCallbacks = { + .devices = qemuDomainDeviceDefAdjust, +}; + + static void qemuDomainObjSaveJob(virQEMUDriverPtr driver, virDomainObjPtr obj) { diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 3a12b45..05a9daf 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -339,5 +339,6 @@ void qemuDomainCleanupRun(virQEMUDriverPtr driver, extern virDomainXMLPrivateDataCallbacks virQEMUDriverPrivateDataCallbacks; extern virDomainXMLNamespace virQEMUDriverDomainXMLNamespace; +extern virDomainDefAdjustCallbacks virQEMUDriverDomainDefAdjustCallbacks; #endif /* __QEMU_DOMAIN_H__ */ -- 1.8.1.5

On Mon, Mar 11, 2013 at 04:06:33PM +0100, Peter Krempa wrote:
This patch implements the callback that is used to fill the qemu default network card into the XML if none is specified.
Libvirt assumes that the network card for qemu if none specified is the "rtl8139". Record this in the XML using the new callback to avoid user confusion. --- src/qemu/qemu_conf.c | 2 +- src/qemu/qemu_domain.c | 26 ++++++++++++++++++++++++++ src/qemu/qemu_domain.h | 1 + 3 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index ef592cd..b9b7357 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -555,7 +555,7 @@ virDomainXMLConfPtr virQEMUDriverCreateXMLConf(void) { return virDomainXMLConfNew(&virQEMUDriverPrivateDataCallbacks, - NULL, + &virQEMUDriverDomainDefAdjustCallbacks,
s/Adjust/PostParse/
&virQEMUDriverDomainXMLNamespace); }
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

--- tests/qemuxml2argvdata/qemuxml2argv-net-bandwidth.xml | 1 + tests/qemuxml2argvdata/qemuxml2argv-net-client.args | 4 ++-- tests/qemuxml2argvdata/qemuxml2argv-net-eth-ifname.args | 4 ++-- tests/qemuxml2argvdata/qemuxml2argv-net-eth-ifname.xml | 1 + tests/qemuxml2argvdata/qemuxml2argv-net-eth-names.args | 8 ++++---- tests/qemuxml2argvdata/qemuxml2argv-net-eth.args | 4 ++-- tests/qemuxml2argvdata/qemuxml2argv-net-eth.xml | 1 + tests/qemuxml2argvdata/qemuxml2argv-net-hostdev.xml | 1 + tests/qemuxml2argvdata/qemuxml2argv-net-mcast.args | 4 ++-- tests/qemuxml2argvdata/qemuxml2argv-net-openvswitch.xml | 1 + tests/qemuxml2argvdata/qemuxml2argv-net-server.args | 4 ++-- tests/qemuxml2argvdata/qemuxml2argv-net-user.args | 3 ++- tests/qemuxml2argvdata/qemuxml2argv-net-user.xml | 1 + .../qemuxml2argv-net-virtio-network-portgroup.xml | 2 ++ .../qemuxml2xmloutdata/qemuxml2xmlout-graphics-spice-timeout.xml | 1 + 15 files changed, 25 insertions(+), 15 deletions(-) diff --git a/tests/qemuxml2argvdata/qemuxml2argv-net-bandwidth.xml b/tests/qemuxml2argvdata/qemuxml2argv-net-bandwidth.xml index bf7dde5..885e854 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-net-bandwidth.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-net-bandwidth.xml @@ -44,6 +44,7 @@ <interface type='network'> <mac address='52:54:00:24:a5:9f'/> <source network='default'/> + <model type='rtl8139'/> <bandwidth> <inbound average='1000' peak='4000' burst='1024'/> <outbound average='128' peak='256' burst='32768'/> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-net-client.args b/tests/qemuxml2argvdata/qemuxml2argv-net-client.args index 7974f2e..34fab0a 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-net-client.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-net-client.args @@ -1,5 +1,5 @@ LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M \ pc -m 214 -smp 1 -nographic -monitor unix:/tmp/test-monitor,server,nowait \ -no-acpi -boot c -usb -hda /dev/HostVG/QEMUGuest1 -net nic,\ -macaddr=52:54:00:8c:b9:05,vlan=0 -net socket,connect=192.168.0.1:5558,vlan=0 \ --serial none -parallel none +macaddr=52:54:00:8c:b9:05,vlan=0,model=rtl8139 -net socket,\ +connect=192.168.0.1:5558,vlan=0 -serial none -parallel none diff --git a/tests/qemuxml2argvdata/qemuxml2argv-net-eth-ifname.args b/tests/qemuxml2argvdata/qemuxml2argv-net-eth-ifname.args index cced5d5..6aef307 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-net-eth-ifname.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-net-eth-ifname.args @@ -1,5 +1,5 @@ LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M \ pc -m 214 -smp 1 -nographic -monitor unix:/tmp/test-monitor,server,nowait \ -no-acpi -boot c -usb -hda /dev/HostVG/QEMUGuest1 -net nic,\ -macaddr=00:11:22:33:44:55,vlan=0 -net tap,ifname=nic02,script=/etc/qemu-ifup,\ -vlan=0 -serial none -parallel none +macaddr=00:11:22:33:44:55,vlan=0,model=rtl8139 -net tap,ifname=nic02,\ +script=/etc/qemu-ifup,vlan=0 -serial none -parallel none diff --git a/tests/qemuxml2argvdata/qemuxml2argv-net-eth-ifname.xml b/tests/qemuxml2argvdata/qemuxml2argv-net-eth-ifname.xml index 04a4ca4..b150371 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-net-eth-ifname.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-net-eth-ifname.xml @@ -25,6 +25,7 @@ <mac address='00:11:22:33:44:55'/> <script path='/etc/qemu-ifup'/> <target dev='nic02'/> + <model type='rtl8139'/> </interface> <memballoon model='virtio'/> </devices> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-net-eth-names.args b/tests/qemuxml2argvdata/qemuxml2argv-net-eth-names.args index dc15f63..57761c5 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-net-eth-names.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-net-eth-names.args @@ -1,7 +1,7 @@ LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M \ pc -m 214 -smp 1 -nographic -monitor unix:/tmp/test-monitor,server,nowait \ -no-acpi -boot c -usb -hda /dev/HostVG/QEMUGuest1 -net nic,\ -macaddr=00:11:22:33:44:55,vlan=0,name=net0 -net tap,script=/etc/qemu-ifup,\ -vlan=0,name=hostnet0 -net nic,macaddr=00:11:22:33:44:56,vlan=1,model=e1000,\ -name=net1 -net tap,script=/etc/qemu-ifup,vlan=1,name=hostnet1 -serial none \ --parallel none +macaddr=00:11:22:33:44:55,vlan=0,model=rtl8139,name=net0 -net tap,\ +script=/etc/qemu-ifup,vlan=0,name=hostnet0 -net nic,macaddr=00:11:22:33:44:56,\ +vlan=1,model=e1000,name=net1 -net tap,script=/etc/qemu-ifup,vlan=1,name=hostnet1 \ +-serial none -parallel none diff --git a/tests/qemuxml2argvdata/qemuxml2argv-net-eth.args b/tests/qemuxml2argvdata/qemuxml2argv-net-eth.args index a482193..877dac2 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-net-eth.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-net-eth.args @@ -1,5 +1,5 @@ LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M \ pc -m 214 -smp 1 -nographic -monitor unix:/tmp/test-monitor,server,nowait \ -no-acpi -boot c -usb -hda /dev/HostVG/QEMUGuest1 -net nic,\ -macaddr=00:11:22:33:44:55,vlan=0 -net tap,script=/etc/qemu-ifup,vlan=0 -serial \ -none -parallel none +macaddr=00:11:22:33:44:55,vlan=0,model=rtl8139 -net tap,script=/etc/qemu-ifup,\ +vlan=0 -serial none -parallel none diff --git a/tests/qemuxml2argvdata/qemuxml2argv-net-eth.xml b/tests/qemuxml2argvdata/qemuxml2argv-net-eth.xml index 87dd65f..eca5da5 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-net-eth.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-net-eth.xml @@ -24,6 +24,7 @@ <interface type='ethernet'> <mac address='00:11:22:33:44:55'/> <script path='/etc/qemu-ifup'/> + <model type='rtl8139'/> </interface> <memballoon model='virtio'/> </devices> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-net-hostdev.xml b/tests/qemuxml2argvdata/qemuxml2argv-net-hostdev.xml index 81f70d0..9be0d2d 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-net-hostdev.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-net-hostdev.xml @@ -32,6 +32,7 @@ <virtualport type='802.1Qbg'> <parameters managerid='11' typeid='1193047' typeidversion='2' instanceid='09b11c53-8b5c-4eeb-8f00-d84eaa0aaa4f'/> </virtualport> + <model type='rtl8139'/> </interface> <memballoon model='virtio'/> </devices> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-net-mcast.args b/tests/qemuxml2argvdata/qemuxml2argv-net-mcast.args index fc2091b..ed4f01e 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-net-mcast.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-net-mcast.args @@ -1,5 +1,5 @@ LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M \ pc -m 214 -smp 1 -nographic -monitor unix:/tmp/test-monitor,server,nowait \ -no-acpi -boot c -usb -hda /dev/HostVG/QEMUGuest1 -net nic,\ -macaddr=52:54:00:8c:b9:05,vlan=0 -net socket,mcast=192.0.0.1:5558,vlan=0 \ --serial none -parallel none +macaddr=52:54:00:8c:b9:05,vlan=0,model=rtl8139 -net socket,mcast=192.0.0.1:5558,\ +vlan=0 -serial none -parallel none diff --git a/tests/qemuxml2argvdata/qemuxml2argv-net-openvswitch.xml b/tests/qemuxml2argvdata/qemuxml2argv-net-openvswitch.xml index ff09844..9c2c5dc 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-net-openvswitch.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-net-openvswitch.xml @@ -32,6 +32,7 @@ <virtualport type='openvswitch'> <parameters interfaceid='09b11c53-8b5c-4eeb-8f00-d84eaa0aaa4f' profileid='bob'/> </virtualport> + <model type='rtl8139'/> </interface> <memballoon model='virtio'/> </devices> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-net-server.args b/tests/qemuxml2argvdata/qemuxml2argv-net-server.args index 7c9d735..c92a3ff 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-net-server.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-net-server.args @@ -1,5 +1,5 @@ LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M \ pc -m 214 -smp 1 -nographic -monitor unix:/tmp/test-monitor,server,nowait \ -no-acpi -boot c -usb -hda /dev/HostVG/QEMUGuest1 -net nic,\ -macaddr=52:54:00:8c:b9:05,vlan=0 -net socket,listen=192.168.0.1:5558,vlan=0 \ --serial none -parallel none +macaddr=52:54:00:8c:b9:05,vlan=0,model=rtl8139 -net socket,\ +listen=192.168.0.1:5558,vlan=0 -serial none -parallel none diff --git a/tests/qemuxml2argvdata/qemuxml2argv-net-user.args b/tests/qemuxml2argvdata/qemuxml2argv-net-user.args index 7364281..814167b 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-net-user.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-net-user.args @@ -1,4 +1,5 @@ LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M \ pc -m 214 -smp 1 -nographic -monitor unix:/tmp/test-monitor,server,nowait \ -no-acpi -boot c -usb -hda /dev/HostVG/QEMUGuest1 -net nic,\ -macaddr=00:11:22:33:44:55,vlan=0 -net user,vlan=0 -serial none -parallel none +macaddr=00:11:22:33:44:55,vlan=0,model=rtl8139 -net user,vlan=0 -serial none \ +-parallel none diff --git a/tests/qemuxml2argvdata/qemuxml2argv-net-user.xml b/tests/qemuxml2argvdata/qemuxml2argv-net-user.xml index 37e5edf..fe3a271 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-net-user.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-net-user.xml @@ -23,6 +23,7 @@ <controller type='ide' index='0'/> <interface type='user'> <mac address='00:11:22:33:44:55'/> + <model type='rtl8139'/> </interface> <memballoon model='virtio'/> </devices> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-net-virtio-network-portgroup.xml b/tests/qemuxml2argvdata/qemuxml2argv-net-virtio-network-portgroup.xml index c84ed3f..0fb9b2c 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-net-virtio-network-portgroup.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-net-virtio-network-portgroup.xml @@ -38,6 +38,7 @@ <virtualport> <parameters instanceid='09b11c53-8b5c-4eeb-8f00-d84eaa0aaa4f' interfaceid='09b11c53-8b5c-4eeb-8f00-d84eaa0aaa4f'/> </virtualport> + <model type='rtl8139'/> </interface> <interface type='network'> <mac address='22:11:22:33:44:55'/> @@ -45,6 +46,7 @@ <virtualport type='802.1Qbh'> <parameters profileid='testhis99'/> </virtualport> + <model type='rtl8139'/> </interface> <memballoon model='virtio'/> </devices> diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-graphics-spice-timeout.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-graphics-spice-timeout.xml index cd19b64..54b68fa 100644 --- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-graphics-spice-timeout.xml +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-graphics-spice-timeout.xml @@ -62,6 +62,7 @@ <interface type='ethernet'> <mac address='52:54:00:71:70:89'/> <script path='/etc/qemu-ifup'/> + <model type='rtl8139'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/> </interface> <serial type='pty'> -- 1.8.1.5

On Mon, Mar 11, 2013 at 04:06:34PM +0100, Peter Krempa wrote:
--- tests/qemuxml2argvdata/qemuxml2argv-net-bandwidth.xml | 1 + tests/qemuxml2argvdata/qemuxml2argv-net-client.args | 4 ++-- tests/qemuxml2argvdata/qemuxml2argv-net-eth-ifname.args | 4 ++-- tests/qemuxml2argvdata/qemuxml2argv-net-eth-ifname.xml | 1 + tests/qemuxml2argvdata/qemuxml2argv-net-eth-names.args | 8 ++++---- tests/qemuxml2argvdata/qemuxml2argv-net-eth.args | 4 ++-- tests/qemuxml2argvdata/qemuxml2argv-net-eth.xml | 1 + tests/qemuxml2argvdata/qemuxml2argv-net-hostdev.xml | 1 + tests/qemuxml2argvdata/qemuxml2argv-net-mcast.args | 4 ++-- tests/qemuxml2argvdata/qemuxml2argv-net-openvswitch.xml | 1 + tests/qemuxml2argvdata/qemuxml2argv-net-server.args | 4 ++-- tests/qemuxml2argvdata/qemuxml2argv-net-user.args | 3 ++- tests/qemuxml2argvdata/qemuxml2argv-net-user.xml | 1 + .../qemuxml2argv-net-virtio-network-portgroup.xml | 2 ++ .../qemuxml2xmloutdata/qemuxml2xmlout-graphics-spice-timeout.xml | 1 + 15 files changed, 25 insertions(+), 15 deletions(-)
ACK, again just post patches which are self-contained Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

This gets rid of the parameter in favor of using the new callback infrastructure to do the same stuff. This patch implements the domain adjustment callback in the openVZ driver and moves the check from the parser to a new validation method in the callback infrastructure. --- src/conf/capabilities.h | 1 - src/conf/domain_conf.c | 31 +++++++++++++++++++------------ src/openvz/openvz_conf.c | 1 - src/openvz/openvz_driver.c | 27 ++++++++++++++++++++++++++- 4 files changed, 45 insertions(+), 15 deletions(-) diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h index a70896a..43ace12 100644 --- a/src/conf/capabilities.h +++ b/src/conf/capabilities.h @@ -168,7 +168,6 @@ struct _virCaps { int defaultDiskDriverType; /* enum virStorageFileFormat */ int (*defaultConsoleTargetType)(const char *ostype, virArch guestarch); bool hasWideScsiBus; - const char *defaultInitPath; }; diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ce65eac..45558e2 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2481,6 +2481,22 @@ virDomainDefAdjustInternal(virDomainDefPtr def ATTRIBUTE_UNUSED, } +/* this is a place for global assumption checks */ +static int +virDomainDefVerifyInternal(virDomainDefPtr def, + virCapsPtr caps ATTRIBUTE_UNUSED) +{ + /* verify init path for container based domains */ + if (STREQ(def->os.type, "exe") && !def->os.init) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("init binary must be specified")); + return -1; + } + + return 0; +} + + static int virDomainDeviceDefAdjust(virDomainXMLConfPtr xmlconf, virDomainDeviceDefPtr dev, @@ -2556,6 +2572,9 @@ virDomainDefAdjust(virDomainXMLConfPtr xmlconf, return ret; } + if ((ret = virDomainDefVerifyInternal(def, caps)) < 0) + return ret; + return 0; } @@ -10212,18 +10231,6 @@ virDomainDefParseXML(virCapsPtr caps, if (STREQ(def->os.type, "exe")) { def->os.init = virXPathString("string(./os/init[1])", ctxt); - if (!def->os.init) { - if (caps->defaultInitPath) { - def->os.init = strdup(caps->defaultInitPath); - if (!def->os.init) { - goto no_memory; - } - } else { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("init binary must be specified")); - goto error; - } - } def->os.cmdline = virXPathString("string(./os/cmdline[1])", ctxt); if ((n = virXPathNodeSet("./os/initarg", ctxt, &nodes)) < 0) { diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index e3e64e5..05c6113 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -206,7 +206,6 @@ virCapsPtr openvzCapsInit(void) NULL) == NULL) goto no_memory; - caps->defaultInitPath = "/sbin/init"; caps->defaultConsoleTargetType = openvzDefaultConsoleType; return caps; diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index a6f4c66..ef736f3 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -97,6 +97,29 @@ static void cmdExecFree(const char *cmdExec[]) } } + +static int +openvzDomainDefAdjust(virDomainDefPtr def, + virCapsPtr caps ATTRIBUTE_UNUSED, + void *opaque ATTRIBUTE_UNUSED) +{ + /* fill the init path */ + if (STREQ(def->os.type, "exe") && !def->os.init) { + if (!(def->os.init = strdup("/sbin/init"))) { + virReportOOMError(); + return -1; + } + } + + return 0; +} + + +virDomainDefAdjustCallbacks openvzDomainDefAdjustCallbacks = { + .domainBeforeDevices = openvzDomainDefAdjust, +}; + + /* generate arguments to create OpenVZ container return -1 - error 0 - OK @@ -1453,7 +1476,9 @@ static virDrvOpenStatus openvzOpen(virConnectPtr conn, if (!(driver->caps = openvzCapsInit())) goto cleanup; - if (!(driver->xmlconf = virDomainXMLConfNew(NULL, NULL, NULL))) + if (!(driver->xmlconf = virDomainXMLConfNew(NULL, + &openvzDomainDefAdjustCallbacks, + NULL))) goto cleanup; if (openvzLoadDomains(driver) < 0) -- 1.8.1.5

On Mon, Mar 11, 2013 at 04:06:35PM +0100, Peter Krempa wrote:
This gets rid of the parameter in favor of using the new callback infrastructure to do the same stuff.
This patch implements the domain adjustment callback in the openVZ driver and moves the check from the parser to a new validation method in the callback infrastructure. --- src/conf/capabilities.h | 1 - src/conf/domain_conf.c | 31 +++++++++++++++++++------------ src/openvz/openvz_conf.c | 1 - src/openvz/openvz_driver.c | 27 ++++++++++++++++++++++++++- 4 files changed, 45 insertions(+), 15 deletions(-)
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

This patch removes the defaultDiskDriverName from the virCaps structure. This particular default value is used only in the qemu driver so this patch uses the recently added callback to fill the driver name if it's needed instead of propagating it through virCaps. --- src/conf/capabilities.h | 1 - src/conf/domain_conf.c | 8 -------- src/qemu/qemu_conf.c | 5 ++--- src/qemu/qemu_conf.h | 3 ++- src/qemu/qemu_domain.c | 25 ++++++++++++++++++++++--- src/qemu/qemu_driver.c | 2 +- tests/domainsnapshotxml2xmltest.c | 2 +- tests/qemuargv2xmltest.c | 2 +- tests/qemumonitorjsontest.c | 2 +- tests/qemuxml2argvtest.c | 2 +- tests/qemuxml2xmltest.c | 2 +- tests/qemuxmlnstest.c | 2 +- tests/securityselinuxlabeltest.c | 2 +- 13 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h index 43ace12..5fd1bb5 100644 --- a/src/conf/capabilities.h +++ b/src/conf/capabilities.h @@ -164,7 +164,6 @@ struct _virCaps { /* Move to virDomainXMLConf later */ unsigned char macPrefix[VIR_MAC_PREFIX_BUFLEN]; unsigned int emulatorRequired : 1; - const char *defaultDiskDriverName; int defaultDiskDriverType; /* enum virStorageFileFormat */ int (*defaultConsoleTargetType)(const char *ostype, virArch guestarch); bool hasWideScsiBus; diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 45558e2..1cdd9e5 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -4758,11 +4758,6 @@ virDomainDiskDefParseXML(virCapsPtr caps, def->format = caps->defaultDiskDriverType; } - if (!def->driverName && - caps->defaultDiskDriverName && - !(def->driverName = strdup(caps->defaultDiskDriverName))) - goto no_memory; - if (mirrorFormat) { def->mirrorFormat = virStorageFileFormatTypeFromString(mirrorFormat); if (def->mirrorFormat <= 0) { @@ -4825,9 +4820,6 @@ cleanup: ctxt->node = save_ctxt; return def; -no_memory: - virReportOOMError(); - error: virDomainDiskDefFree(def); def = NULL; diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index b9b7357..54e6de9 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -552,8 +552,9 @@ virQEMUDriverConfigPtr virQEMUDriverGetConfig(virQEMUDriverPtr driver) } virDomainXMLConfPtr -virQEMUDriverCreateXMLConf(void) +virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver) { + virQEMUDriverDomainDefAdjustCallbacks.priv = driver; return virDomainXMLConfNew(&virQEMUDriverPrivateDataCallbacks, &virQEMUDriverDomainDefAdjustCallbacks, &virQEMUDriverDomainXMLNamespace); @@ -574,10 +575,8 @@ virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver) goto no_memory; if (cfg->allowDiskFormatProbing) { - caps->defaultDiskDriverName = NULL; caps->defaultDiskDriverType = VIR_STORAGE_FILE_AUTO; } else { - caps->defaultDiskDriverName = "qemu"; caps->defaultDiskDriverType = VIR_STORAGE_FILE_RAW; } diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index c5ddaad..4b917a7 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -301,6 +301,7 @@ void qemuSharedDiskEntryFree(void *payload, const void *name) ATTRIBUTE_NONNULL(1); int qemuDriverAllocateID(virQEMUDriverPtr driver); -virDomainXMLConfPtr virQEMUDriverCreateXMLConf(void); +virDomainXMLConfPtr virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver); + #endif /* __QEMUD_CONF_H */ diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 94d4c01..d7b9b5f 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -666,19 +666,38 @@ static int qemuDomainDeviceDefAdjust(virDomainDeviceDefPtr dev, virDomainDefPtr def ATTRIBUTE_UNUSED, virCapsPtr caps ATTRIBUTE_UNUSED, - void *opaque ATTRIBUTE_UNUSED) + void *opaque) { + int ret = -1; + virQEMUDriverPtr driver = opaque; + virQEMUDriverConfigPtr cfg = NULL; + if (dev->type == VIR_DOMAIN_DEVICE_NET && dev->data.net->type != VIR_DOMAIN_NET_TYPE_HOSTDEV) { if (!dev->data.net->model && !(dev->data.net->model = strdup("rtl8139"))) goto no_memory; } - return 0; + + if (dev->type == VIR_DOMAIN_DEVICE_DISK && + !dev->data.disk->driverName && + driver && + (cfg = virQEMUDriverGetConfig(driver))) { + if (!cfg->allowDiskFormatProbing && + !(dev->data.disk->driverName = strdup("qemu"))) { + goto no_memory; + } + } + + ret = 0; + +cleanup: + virObjectUnref(cfg); + return ret; no_memory: virReportOOMError(); - return -1; + goto cleanup; } diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 6101ee6..c1c155c 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -723,7 +723,7 @@ qemuStartup(bool privileged, if ((qemu_driver->caps = virQEMUDriverCreateCapabilities(qemu_driver)) == NULL) goto error; - if (!(qemu_driver->xmlconf = virQEMUDriverCreateXMLConf())) + if (!(qemu_driver->xmlconf = virQEMUDriverCreateXMLConf(qemu_driver))) goto error; /* If hugetlbfs is present, then we need to create a sub-directory within diff --git a/tests/domainsnapshotxml2xmltest.c b/tests/domainsnapshotxml2xmltest.c index 7d95310..e6bd3a6 100644 --- a/tests/domainsnapshotxml2xmltest.c +++ b/tests/domainsnapshotxml2xmltest.c @@ -91,7 +91,7 @@ mymain(void) if ((driver.caps = testQemuCapsInit()) == NULL) return EXIT_FAILURE; - if (!(driver.xmlconf = virQEMUDriverCreateXMLConf())) + if (!(driver.xmlconf = virQEMUDriverCreateXMLConf(&driver))) return EXIT_FAILURE; # define DO_TEST(name, uuid, internal) \ diff --git a/tests/qemuargv2xmltest.c b/tests/qemuargv2xmltest.c index f7d6019..d216e78 100644 --- a/tests/qemuargv2xmltest.c +++ b/tests/qemuargv2xmltest.c @@ -120,7 +120,7 @@ mymain(void) if ((driver.caps = testQemuCapsInit()) == NULL) return EXIT_FAILURE; - if (!(driver.xmlconf = virQEMUDriverCreateXMLConf())) + if (!(driver.xmlconf = virQEMUDriverCreateXMLConf(&driver))) return EXIT_FAILURE; # define DO_TEST_FULL(name, extraFlags, migrateFrom) \ diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 639eeb1..d6f1d64 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -451,7 +451,7 @@ mymain(void) #endif if (virThreadInitialize() < 0 || - !(xmlconf = virQEMUDriverCreateXMLConf())) + !(xmlconf = virQEMUDriverCreateXMLConf(NULL))) return EXIT_FAILURE; virEventRegisterDefaultImpl(); diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 888de3c..50931e3 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -294,7 +294,7 @@ mymain(void) if ((driver.caps = testQemuCapsInit()) == NULL) return EXIT_FAILURE; - if (!(driver.xmlconf = virQEMUDriverCreateXMLConf())) + if (!(driver.xmlconf = virQEMUDriverCreateXMLConf(&driver))) return EXIT_FAILURE; VIR_FREE(driver.config->stateDir); if ((driver.config->stateDir = strdup("/nowhere")) == NULL) diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index d77da4e..313d688 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -106,7 +106,7 @@ mymain(void) if ((driver.caps = testQemuCapsInit()) == NULL) return EXIT_FAILURE; - if (!(driver.xmlconf = virQEMUDriverCreateXMLConf())) + if (!(driver.xmlconf = virQEMUDriverCreateXMLConf(&driver))) return EXIT_FAILURE; # define DO_TEST_FULL(name, is_different, when) \ diff --git a/tests/qemuxmlnstest.c b/tests/qemuxmlnstest.c index 76a715d..de46993 100644 --- a/tests/qemuxmlnstest.c +++ b/tests/qemuxmlnstest.c @@ -204,7 +204,7 @@ mymain(void) driver.config = virQEMUDriverConfigNew(false); if ((driver.caps = testQemuCapsInit()) == NULL) return EXIT_FAILURE; - if (!(driver.xmlconf = virQEMUDriverCreateXMLConf())) + if (!(driver.xmlconf = virQEMUDriverCreateXMLConf(&driver))) return EXIT_FAILURE; if (virAsprintf(&map, "%s/src/cpu/cpu_map.xml", abs_top_srcdir) < 0 || cpuMapOverride(map) < 0) { diff --git a/tests/securityselinuxlabeltest.c b/tests/securityselinuxlabeltest.c index 405bc2b..f3e8d7c 100644 --- a/tests/securityselinuxlabeltest.c +++ b/tests/securityselinuxlabeltest.c @@ -328,7 +328,7 @@ mymain(void) if ((caps = testQemuCapsInit()) == NULL) return EXIT_FAILURE; - if (!(xmlconf = virQEMUDriverCreateXMLConf())) + if (!(xmlconf = virQEMUDriverCreateXMLConf(NULL))) return EXIT_FAILURE; #define DO_TEST_LABELING(name) \ -- 1.8.1.5

On Mon, Mar 11, 2013 at 04:06:36PM +0100, Peter Krempa wrote:
This patch removes the defaultDiskDriverName from the virCaps structure. This particular default value is used only in the qemu driver so this patch uses the recently added callback to fill the driver name if it's needed instead of propagating it through virCaps. --- src/conf/capabilities.h | 1 - src/conf/domain_conf.c | 8 -------- src/qemu/qemu_conf.c | 5 ++--- src/qemu/qemu_conf.h | 3 ++- src/qemu/qemu_domain.c | 25 ++++++++++++++++++++++--- src/qemu/qemu_driver.c | 2 +- tests/domainsnapshotxml2xmltest.c | 2 +- tests/qemuargv2xmltest.c | 2 +- tests/qemumonitorjsontest.c | 2 +- tests/qemuxml2argvtest.c | 2 +- tests/qemuxml2xmltest.c | 2 +- tests/qemuxmlnstest.c | 2 +- tests/securityselinuxlabeltest.c | 2 +- 13 files changed, 34 insertions(+), 24 deletions(-)
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

This patch removes the emulatorRequired field and associated infrastructure from the virCaps object. Instead the driver specific callbacks are used as this field isn't enforced by all drivers. This patch implements the appropriate callbacks in the qemu and lxc driver and moves to check to that location. --- src/conf/capabilities.c | 10 ---------- src/conf/capabilities.h | 7 ------- src/conf/domain_conf.c | 16 ++++++---------- src/conf/domain_conf.h | 2 ++ src/libvirt_private.syms | 3 +-- src/lxc/lxc_conf.c | 7 +++---- src/lxc/lxc_domain.c | 17 +++++++++++++++++ src/lxc/lxc_domain.h | 1 + src/qemu/qemu_capabilities.c | 3 --- src/qemu/qemu_domain.c | 15 +++++++++++++++ tests/lxcxml2xmldata/lxc-hostdev.xml | 1 + tests/lxcxml2xmldata/lxc-systemd.xml | 1 + 12 files changed, 47 insertions(+), 36 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index d53d5a3..1d29ce6 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -935,13 +935,3 @@ virCapabilitiesGenerateMac(virCapsPtr caps, { virMacAddrGenerate(caps->macPrefix, mac); } - -extern void -virCapabilitiesSetEmulatorRequired(virCapsPtr caps) { - caps->emulatorRequired = 1; -} - -extern unsigned int -virCapabilitiesIsEmulatorRequired(virCapsPtr caps) { - return caps->emulatorRequired; -} diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h index 5fd1bb5..dcf38a8 100644 --- a/src/conf/capabilities.h +++ b/src/conf/capabilities.h @@ -163,7 +163,6 @@ struct _virCaps { /* Move to virDomainXMLConf later */ unsigned char macPrefix[VIR_MAC_PREFIX_BUFLEN]; - unsigned int emulatorRequired : 1; int defaultDiskDriverType; /* enum virStorageFileFormat */ int (*defaultConsoleTargetType)(const char *ostype, virArch guestarch); bool hasWideScsiBus; @@ -186,12 +185,6 @@ extern void virCapabilitiesGenerateMac(virCapsPtr caps, virMacAddrPtr mac); -extern void -virCapabilitiesSetEmulatorRequired(virCapsPtr caps); - -extern unsigned int -virCapabilitiesIsEmulatorRequired(virCapsPtr caps); - extern int virCapabilitiesAddHostFeature(virCapsPtr caps, const char *name); diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1cdd9e5..fbdab9a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -9079,8 +9079,9 @@ virDomainLeaseRemove(virDomainDefPtr def, } -static char *virDomainDefDefaultEmulator(virDomainDefPtr def, - virCapsPtr caps) { +char * +virDomainDefDefaultEmulator(virDomainDefPtr def, + virCapsPtr caps) { const char *type; const char *emulator; char *retemu; @@ -9099,13 +9100,13 @@ static char *virDomainDefDefaultEmulator(virDomainDefPtr def, if (!emulator) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("no emulator for domain %s os type %s on architecture %s"), + _("no emulator for domain %s os type %s " + "on architecture %s"), type, def->os.type, virArchToString(def->os.arch)); return NULL; } - retemu = strdup(emulator); - if (!retemu) + if (!(retemu = strdup(emulator))) virReportOOMError(); return retemu; @@ -10263,11 +10264,6 @@ virDomainDefParseXML(virCapsPtr caps, } def->emulator = virXPathString("string(./devices/emulator[1])", ctxt); - if (!def->emulator && virCapabilitiesIsEmulatorRequired(caps)) { - def->emulator = virDomainDefDefaultEmulator(def, caps); - if (!def->emulator) - goto error; - } /* analysis of the disk devices */ if ((n = virXPathNodeSet("./devices/disk", ctxt, &nodes)) < 0) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index ab66707..0dac95e 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2471,4 +2471,6 @@ int virDomainObjListExport(virDomainObjListPtr doms, virDomainVcpuPinDefPtr virDomainLookupVcpuPin(virDomainDefPtr def, int vcpuid); +char *virDomainDefDefaultEmulator(virDomainDefPtr def, virCapsPtr caps); + #endif /* __DOMAIN_CONF_H */ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c9995d7..af1d0cf 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -21,9 +21,7 @@ virCapabilitiesFormatXML; virCapabilitiesFreeMachines; virCapabilitiesFreeNUMAInfo; virCapabilitiesGenerateMac; -virCapabilitiesIsEmulatorRequired; virCapabilitiesNew; -virCapabilitiesSetEmulatorRequired; virCapabilitiesSetHostCPU; virCapabilitiesSetMacPrefix; @@ -114,6 +112,7 @@ virDomainDefClearDeviceAliases; virDomainDefClearPCIAddresses; virDomainDefCompatibleDevice; virDomainDefCopy; +virDomainDefDefaultEmulator; virDomainDefFormat; virDomainDefFormatInternal; virDomainDefFree; diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c index 4e2306d..4c17e21 100644 --- a/src/lxc/lxc_conf.c +++ b/src/lxc/lxc_conf.c @@ -119,9 +119,6 @@ virCapsPtr lxcCapsInit(virLXCDriverPtr driver) goto error; } - /* LXC Requires an emulator in the XML */ - virCapabilitiesSetEmulatorRequired(caps); - if (driver) { /* Security driver data */ const char *doi, *model; @@ -159,7 +156,9 @@ error: virDomainXMLConfPtr lxcDomainXMLConfInit(void) { - return virDomainXMLConfNew(&virLXCDriverPrivateDataCallbacks, NULL, NULL); + return virDomainXMLConfNew(&virLXCDriverPrivateDataCallbacks, + &virLXCDriverDomainDefAdjustCallbacks, + NULL); } int lxcLoadDriverConfig(virLXCDriverPtr driver) diff --git a/src/lxc/lxc_domain.c b/src/lxc/lxc_domain.c index 08cf8f6..e9041b2 100644 --- a/src/lxc/lxc_domain.c +++ b/src/lxc/lxc_domain.c @@ -79,3 +79,20 @@ virDomainXMLPrivateDataCallbacks virLXCDriverPrivateDataCallbacks = { .format = virLXCDomainObjPrivateXMLFormat, .parse = virLXCDomainObjPrivateXMLParse, }; + +static int +virLXCDomainDefAdjust(virDomainDefPtr def, + virCapsPtr caps, + void *opaque ATTRIBUTE_UNUSED) +{ + /* check for emulator and create a default one if needed */ + if (!def->emulator && + !(def->emulator = virDomainDefDefaultEmulator(def, caps))) + return -1; + + return 0; +} + +virDomainDefAdjustCallbacks virLXCDriverDomainDefAdjustCallbacks = { + .domainBeforeDevices = virLXCDomainDefAdjust, +}; diff --git a/src/lxc/lxc_domain.h b/src/lxc/lxc_domain.h index 007ea84..831358f 100644 --- a/src/lxc/lxc_domain.h +++ b/src/lxc/lxc_domain.h @@ -39,5 +39,6 @@ struct _virLXCDomainObjPrivate { }; extern virDomainXMLPrivateDataCallbacks virLXCDriverPrivateDataCallbacks; +extern virDomainDefAdjustCallbacks virLXCDriverDomainDefAdjustCallbacks; #endif /* __LXC_DOMAIN_H__ */ diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 40022c1..9051df8 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -903,9 +903,6 @@ virCapsPtr virQEMUCapsInit(virQEMUCapsCachePtr cache) i) < 0) goto error; - /* QEMU Requires an emulator in the XML */ - virCapabilitiesSetEmulatorRequired(caps); - caps->defaultConsoleTargetType = virQEMUCapsDefaultConsoleType; return caps; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index d7b9b5f..7e56242 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -663,6 +663,20 @@ virDomainXMLNamespace virQEMUDriverDomainXMLNamespace = { static int +qemuDomainDefAdjust(virDomainDefPtr def, + virCapsPtr caps, + void *opaque ATTRIBUTE_UNUSED) +{ + /* check for emulator and create a default one if needed */ + if (!def->emulator && + !(def->emulator = virDomainDefDefaultEmulator(def, caps))) + return -1; + + return 0; +} + + +static int qemuDomainDeviceDefAdjust(virDomainDeviceDefPtr dev, virDomainDefPtr def ATTRIBUTE_UNUSED, virCapsPtr caps ATTRIBUTE_UNUSED, @@ -702,6 +716,7 @@ no_memory: virDomainDefAdjustCallbacks virQEMUDriverDomainDefAdjustCallbacks = { + .domainBeforeDevices = qemuDomainDefAdjust, .devices = qemuDomainDeviceDefAdjust, }; diff --git a/tests/lxcxml2xmldata/lxc-hostdev.xml b/tests/lxcxml2xmldata/lxc-hostdev.xml index 02a87a7..b022cc7 100644 --- a/tests/lxcxml2xmldata/lxc-hostdev.xml +++ b/tests/lxcxml2xmldata/lxc-hostdev.xml @@ -13,6 +13,7 @@ <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> + <emulator>/usr/libexec/libvirt_lxc</emulator> <filesystem type='mount' accessmode='passthrough'> <source dir='/root/container'/> <target dir='/'/> diff --git a/tests/lxcxml2xmldata/lxc-systemd.xml b/tests/lxcxml2xmldata/lxc-systemd.xml index 2f36eee..fd3a606 100644 --- a/tests/lxcxml2xmldata/lxc-systemd.xml +++ b/tests/lxcxml2xmldata/lxc-systemd.xml @@ -15,6 +15,7 @@ <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> + <emulator>/usr/libexec/libvirt_lxc</emulator> <filesystem type='mount' accessmode='passthrough'> <source dir='/root/container'/> <target dir='/'/> -- 1.8.1.5

On Mon, Mar 11, 2013 at 04:06:37PM +0100, Peter Krempa wrote:
This patch removes the emulatorRequired field and associated infrastructure from the virCaps object. Instead the driver specific callbacks are used as this field isn't enforced by all drivers.
This patch implements the appropriate callbacks in the qemu and lxc driver and moves to check to that location. --- src/conf/capabilities.c | 10 ---------- src/conf/capabilities.h | 7 ------- src/conf/domain_conf.c | 16 ++++++---------- src/conf/domain_conf.h | 2 ++ src/libvirt_private.syms | 3 +-- src/lxc/lxc_conf.c | 7 +++---- src/lxc/lxc_domain.c | 17 +++++++++++++++++ src/lxc/lxc_domain.h | 1 + src/qemu/qemu_capabilities.c | 3 --- src/qemu/qemu_domain.c | 15 +++++++++++++++ tests/lxcxml2xmldata/lxc-hostdev.xml | 1 + tests/lxcxml2xmldata/lxc-systemd.xml | 1 + 12 files changed, 47 insertions(+), 36 deletions(-)
diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index d53d5a3..1d29ce6 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -935,13 +935,3 @@ virCapabilitiesGenerateMac(virCapsPtr caps, { virMacAddrGenerate(caps->macPrefix, mac); } - -extern void -virCapabilitiesSetEmulatorRequired(virCapsPtr caps) { - caps->emulatorRequired = 1; -} - -extern unsigned int -virCapabilitiesIsEmulatorRequired(virCapsPtr caps) { - return caps->emulatorRequired; -} diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h index 5fd1bb5..dcf38a8 100644 --- a/src/conf/capabilities.h +++ b/src/conf/capabilities.h @@ -163,7 +163,6 @@ struct _virCaps {
/* Move to virDomainXMLConf later */ unsigned char macPrefix[VIR_MAC_PREFIX_BUFLEN]; - unsigned int emulatorRequired : 1; int defaultDiskDriverType; /* enum virStorageFileFormat */ int (*defaultConsoleTargetType)(const char *ostype, virArch guestarch); bool hasWideScsiBus; @@ -186,12 +185,6 @@ extern void virCapabilitiesGenerateMac(virCapsPtr caps, virMacAddrPtr mac);
-extern void -virCapabilitiesSetEmulatorRequired(virCapsPtr caps); - -extern unsigned int -virCapabilitiesIsEmulatorRequired(virCapsPtr caps); - extern int virCapabilitiesAddHostFeature(virCapsPtr caps, const char *name); diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1cdd9e5..fbdab9a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -9079,8 +9079,9 @@ virDomainLeaseRemove(virDomainDefPtr def, }
-static char *virDomainDefDefaultEmulator(virDomainDefPtr def, - virCapsPtr caps) { +char * +virDomainDefDefaultEmulator(virDomainDefPtr def, + virCapsPtr caps) { const char *type; const char *emulator; char *retemu; @@ -9099,13 +9100,13 @@ static char *virDomainDefDefaultEmulator(virDomainDefPtr def,
if (!emulator) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("no emulator for domain %s os type %s on architecture %s"), + _("no emulator for domain %s os type %s " + "on architecture %s"), type, def->os.type, virArchToString(def->os.arch)); return NULL; }
- retemu = strdup(emulator); - if (!retemu) + if (!(retemu = strdup(emulator))) virReportOOMError();
return retemu; @@ -10263,11 +10264,6 @@ virDomainDefParseXML(virCapsPtr caps, }
def->emulator = virXPathString("string(./devices/emulator[1])", ctxt); - if (!def->emulator && virCapabilitiesIsEmulatorRequired(caps)) { - def->emulator = virDomainDefDefaultEmulator(def, caps); - if (!def->emulator) - goto error; - }
/* analysis of the disk devices */ if ((n = virXPathNodeSet("./devices/disk", ctxt, &nodes)) < 0) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index ab66707..0dac95e 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2471,4 +2471,6 @@ int virDomainObjListExport(virDomainObjListPtr doms, virDomainVcpuPinDefPtr virDomainLookupVcpuPin(virDomainDefPtr def, int vcpuid);
+char *virDomainDefDefaultEmulator(virDomainDefPtr def, virCapsPtr caps);
s/virDomainDefDefaultEmulator/virDomainDefSetDefaultEmulator) to make it clear that this is a setter function. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On 03/12/13 13:50, Daniel P. Berrange wrote:
On Mon, Mar 11, 2013 at 04:06:37PM +0100, Peter Krempa wrote:
This patch removes the emulatorRequired field and associated infrastructure from the virCaps object. Instead the driver specific callbacks are used as this field isn't enforced by all drivers.
This patch implements the appropriate callbacks in the qemu and lxc driver and moves to check to that location. --- src/conf/capabilities.c | 10 ---------- src/conf/capabilities.h | 7 ------- src/conf/domain_conf.c | 16 ++++++---------- src/conf/domain_conf.h | 2 ++ src/libvirt_private.syms | 3 +-- src/lxc/lxc_conf.c | 7 +++---- src/lxc/lxc_domain.c | 17 +++++++++++++++++ src/lxc/lxc_domain.h | 1 + src/qemu/qemu_capabilities.c | 3 --- src/qemu/qemu_domain.c | 15 +++++++++++++++ tests/lxcxml2xmldata/lxc-hostdev.xml | 1 + tests/lxcxml2xmldata/lxc-systemd.xml | 1 + 12 files changed, 47 insertions(+), 36 deletions(-)
[...]
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index ab66707..0dac95e 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2471,4 +2471,6 @@ int virDomainObjListExport(virDomainObjListPtr doms, virDomainVcpuPinDefPtr virDomainLookupVcpuPin(virDomainDefPtr def, int vcpuid);
+char *virDomainDefDefaultEmulator(virDomainDefPtr def, virCapsPtr caps);
s/virDomainDefDefaultEmulator/virDomainDefSetDefaultEmulator) to make it clear that this is a setter function.
Um, it returns the default emulator as string that is then used to fill a field in the domain definition struct. Do you still consider that as a setter? Also it was called like this before, I just exported it. Should I still change the name? Peter

On Wed, Mar 13, 2013 at 02:01:42PM +0100, Peter Krempa wrote:
On 03/12/13 13:50, Daniel P. Berrange wrote:
On Mon, Mar 11, 2013 at 04:06:37PM +0100, Peter Krempa wrote:
This patch removes the emulatorRequired field and associated infrastructure from the virCaps object. Instead the driver specific callbacks are used as this field isn't enforced by all drivers.
This patch implements the appropriate callbacks in the qemu and lxc driver and moves to check to that location. --- src/conf/capabilities.c | 10 ---------- src/conf/capabilities.h | 7 ------- src/conf/domain_conf.c | 16 ++++++---------- src/conf/domain_conf.h | 2 ++ src/libvirt_private.syms | 3 +-- src/lxc/lxc_conf.c | 7 +++---- src/lxc/lxc_domain.c | 17 +++++++++++++++++ src/lxc/lxc_domain.h | 1 + src/qemu/qemu_capabilities.c | 3 --- src/qemu/qemu_domain.c | 15 +++++++++++++++ tests/lxcxml2xmldata/lxc-hostdev.xml | 1 + tests/lxcxml2xmldata/lxc-systemd.xml | 1 + 12 files changed, 47 insertions(+), 36 deletions(-)
[...]
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index ab66707..0dac95e 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2471,4 +2471,6 @@ int virDomainObjListExport(virDomainObjListPtr doms, virDomainVcpuPinDefPtr virDomainLookupVcpuPin(virDomainDefPtr def, int vcpuid);
+char *virDomainDefDefaultEmulator(virDomainDefPtr def, virCapsPtr caps);
s/virDomainDefDefaultEmulator/virDomainDefSetDefaultEmulator) to make it clear that this is a setter function.
Um, it returns the default emulator as string that is then used to fill a field in the domain definition struct. Do you still consider that as a setter?
Opps, my mistake. Add the word 'Get' in there to clarify that instead. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

The limits are documented at http://libvirt.org/formatdomain.html#elementsCPUTuning . Enforce them when going through XML parsing in addition to being enforced by the API. --- src/conf/domain_conf.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index fbdab9a..be3bf1a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2493,6 +2493,43 @@ virDomainDefVerifyInternal(virDomainDefPtr def, return -1; } + /* enforce range checks for cputune values */ + /* these are not represented in the XML schema, but are documented */ + if (def->cputune.period > 0 && + (def->cputune.period < 1000 || def->cputune.period > 1000000)) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Value of cputune period must be in range " + "[1000, 1000000]")); + return -1; + } + + if (def->cputune.emulator_period > 0 && + (def->cputune.emulator_period < 1000 || + def->cputune.emulator_period > 1000000)) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Value of cputune emulator_period must be in range " + "[1000, 1000000]")); + return -1; + } + + if (def->cputune.quota > 0 && + (def->cputune.quota < 1000 || + def->cputune.quota > 18446744073709551)) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Value of cputune quota must be in range " + "[1000, 18446744073709551]")); + return -1; + } + + if (def->cputune.emulator_quota > 0 && + (def->cputune.emulator_quota < 1000 || + def->cputune.emulator_quota > 18446744073709551)) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Value of cputune emulator_quota must be in range " + "[1000, 18446744073709551]")); + return -1; + } + return 0; } -- 1.8.1.5

On 03/11/13 16:06, Peter Krempa wrote:
The limits are documented at http://libvirt.org/formatdomain.html#elementsCPUTuning . Enforce them when going through XML parsing in addition to being enforced by the API. --- src/conf/domain_conf.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index fbdab9a..be3bf1a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2493,6 +2493,43 @@ virDomainDefVerifyInternal(virDomainDefPtr def, return -1; }
+ /* enforce range checks for cputune values */ + /* these are not represented in the XML schema, but are documented */ + if (def->cputune.period > 0 && + (def->cputune.period < 1000 || def->cputune.period > 1000000)) { + virReportError(VIR_ERR_XML_ERROR, "%s",
Hmm, in retrospect, I think VIR_ERR_CONFIG_UNSUPPORTED will be more appropriate here.
+ _("Value of cputune period must be in range " + "[1000, 1000000]")); + return -1; + }
Peter
participants (2)
-
Daniel P. Berrange
-
Peter Krempa