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 :|