提交 9890a7a1 编写于 作者: P Peter Krempa

conf: Add device def validation callback

Similarly to the domain definition validator add a device validator. The
change to the prototype of the domain validator is necessary as
virDomainDeviceInfoIterateInternal requires a non-const pointer.
上级 0fc1fde2
......@@ -4531,6 +4531,47 @@ virDomainDefPostParse(virDomainDefPtr def,
}
static int
virDomainDeviceDefValidateInternal(const virDomainDeviceDef *dev ATTRIBUTE_UNUSED,
const virDomainDef *def ATTRIBUTE_UNUSED)
{
return 0;
}
static int
virDomainDeviceDefValidate(const virDomainDeviceDef *dev,
const virDomainDef *def,
unsigned int parseFlags,
virDomainXMLOptionPtr xmlopt)
{
/* validate configuration only in certain places */
if (parseFlags & VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE)
return 0;
if (xmlopt->config.deviceValidateCallback &&
xmlopt->config.deviceValidateCallback(dev, def, xmlopt->config.priv))
return -1;
if (virDomainDeviceDefValidateInternal(dev, def) < 0)
return -1;
return 0;
}
static int
virDomainDefValidateDeviceIterator(virDomainDefPtr def,
virDomainDeviceDefPtr dev,
virDomainDeviceInfoPtr info ATTRIBUTE_UNUSED,
void *opaque)
{
struct virDomainDefPostParseDeviceIteratorData *data = opaque;
return virDomainDeviceDefValidate(dev, def,
data->parseFlags, data->xmlopt);
}
static int
virDomainDefValidateInternal(const virDomainDef *def ATTRIBUTE_UNUSED)
{
......@@ -4554,11 +4595,17 @@ virDomainDefValidateInternal(const virDomainDef *def ATTRIBUTE_UNUSED)
* appropriate message.
*/
int
virDomainDefValidate(const virDomainDef *def,
virDomainDefValidate(virDomainDefPtr def,
virCapsPtr caps,
unsigned int parseFlags,
virDomainXMLOptionPtr xmlopt)
{
struct virDomainDefPostParseDeviceIteratorData data = {
.caps = caps,
.xmlopt = xmlopt,
.parseFlags = parseFlags,
};
/* validate configuration only in certain places */
if (parseFlags & VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE)
return 0;
......@@ -4568,6 +4615,12 @@ virDomainDefValidate(const virDomainDef *def,
xmlopt->config.domainValidateCallback(def, caps, xmlopt->config.priv) < 0)
return -1;
/* iterate the devices */
if (virDomainDeviceInfoIterateInternal(def,
virDomainDefValidateDeviceIterator,
true, &data) < 0)
return -1;
if (virDomainDefValidateInternal(def) < 0)
return -1;
......@@ -13179,6 +13232,10 @@ virDomainDeviceDefParse(const char *xmlStr,
if (virDomainDeviceDefPostParse(dev, def, caps, flags, xmlopt) < 0)
goto error;
/* validate the configuration */
if (virDomainDeviceDefValidate(dev, def, flags, xmlopt) < 0)
goto error;
cleanup:
xmlFreeDoc(xml);
xmlXPathFreeContext(ctxt);
......@@ -24234,7 +24291,8 @@ virDomainDeviceDefCopy(virDomainDeviceDefPtr src,
xmlStr = virBufferContentAndReset(&buf);
ret = virDomainDeviceDefParse(xmlStr, def, caps, xmlopt,
VIR_DOMAIN_DEF_PARSE_INACTIVE);
VIR_DOMAIN_DEF_PARSE_INACTIVE |
VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE);
cleanup:
VIR_FREE(xmlStr);
......
......@@ -2368,6 +2368,12 @@ typedef int (*virDomainDefValidateCallback)(const virDomainDef *def,
virCapsPtr caps,
void *opaque);
/* Called once per device, for adjusting per-device settings while
* leaving the overall domain otherwise unchanged. */
typedef int (*virDomainDeviceDefValidateCallback)(const virDomainDeviceDef *dev,
const virDomainDef *def,
void *opaque);
typedef struct _virDomainDefParserConfig virDomainDefParserConfig;
typedef virDomainDefParserConfig *virDomainDefParserConfigPtr;
struct _virDomainDefParserConfig {
......@@ -2378,6 +2384,7 @@ struct _virDomainDefParserConfig {
/* validation callbacks */
virDomainDefValidateCallback domainValidateCallback;
virDomainDeviceDefValidateCallback deviceValidateCallback;
/* private data for the callbacks */
void *priv;
......@@ -2424,7 +2431,7 @@ virDomainDefPostParse(virDomainDefPtr def,
unsigned int parseFlags,
virDomainXMLOptionPtr xmlopt);
int virDomainDefValidate(const virDomainDef *def,
int virDomainDefValidate(virDomainDefPtr def,
virCapsPtr caps,
unsigned int parseFlags,
virDomainXMLOptionPtr xmlopt);
......
......@@ -3742,7 +3742,8 @@ libxlDomainDetachDeviceFlags(virDomainPtr dom, const char *xml,
if (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG) {
if (!(dev = virDomainDeviceDefParse(xml, vm->def,
cfg->caps, driver->xmlopt,
VIR_DOMAIN_DEF_PARSE_INACTIVE)))
VIR_DOMAIN_DEF_PARSE_INACTIVE |
VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE)))
goto endjob;
/* Make a copy for updated domain. */
......@@ -3759,7 +3760,8 @@ libxlDomainDetachDeviceFlags(virDomainPtr dom, const char *xml,
virDomainDeviceDefFree(dev);
if (!(dev = virDomainDeviceDefParse(xml, vm->def,
cfg->caps, driver->xmlopt,
VIR_DOMAIN_DEF_PARSE_INACTIVE)))
VIR_DOMAIN_DEF_PARSE_INACTIVE |
VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE)))
goto endjob;
if (libxlDomainDetachDeviceLive(driver, vm, dev) < 0)
......
......@@ -5317,7 +5317,8 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom,
dev = dev_copy = virDomainDeviceDefParse(xml, vm->def,
caps, driver->xmlopt,
VIR_DOMAIN_DEF_PARSE_INACTIVE);
VIR_DOMAIN_DEF_PARSE_INACTIVE |
VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE);
if (dev == NULL)
goto endjob;
......
......@@ -8422,7 +8422,7 @@ qemuDomainDetachDeviceFlags(virDomainPtr dom,
virDomainDefPtr vmdef = NULL;
virDomainDeviceDefPtr dev = NULL, dev_copy = NULL;
int ret = -1;
unsigned int parse_flags = 0;
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE;
virQEMUCapsPtr qemuCaps = NULL;
qemuDomainObjPrivatePtr priv;
virQEMUDriverConfigPtr cfg = NULL;
......
......@@ -2365,7 +2365,8 @@ static int umlDomainDetachDevice(virDomainPtr dom, const char *xml)
}
dev = virDomainDeviceDefParse(xml, vm->def, driver->caps, driver->xmlopt,
VIR_DOMAIN_DEF_PARSE_INACTIVE);
VIR_DOMAIN_DEF_PARSE_INACTIVE |
VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE);
if (dev == NULL)
goto cleanup;
......
......@@ -4242,7 +4242,8 @@ static int vboxDomainDetachDevice(virDomainPtr dom, const char *xml)
def->os.type = VIR_DOMAIN_OSTYPE_HVM;
dev = virDomainDeviceDefParse(xml, def, data->caps, data->xmlopt,
VIR_DOMAIN_DEF_PARSE_INACTIVE);
VIR_DOMAIN_DEF_PARSE_INACTIVE |
VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE);
if (dev == NULL)
goto cleanup;
......
......@@ -1211,7 +1211,9 @@ static int vzDomainDetachDeviceFlags(virDomainPtr dom, const char *xml,
goto cleanup;
dev = virDomainDeviceDefParse(xml, privdom->def, privconn->driver->caps,
privconn->driver->xmlopt, VIR_DOMAIN_XML_INACTIVE);
privconn->driver->xmlopt,
VIR_DOMAIN_XML_INACTIVE |
VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE);
if (dev == NULL)
goto cleanup;
......
......@@ -2355,7 +2355,8 @@ xenDaemonDetachDeviceFlags(virConnectPtr conn,
goto cleanup;
if (!(dev = virDomainDeviceDefParse(xml, def, priv->caps, priv->xmlopt,
VIR_DOMAIN_DEF_PARSE_INACTIVE)))
VIR_DOMAIN_DEF_PARSE_INACTIVE |
VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE)))
goto cleanup;
if (virDomainXMLDevID(conn, minidef, dev, class, ref, sizeof(ref)))
......
......@@ -1343,7 +1343,8 @@ xenXMDomainDetachDeviceFlags(virConnectPtr conn,
if (!(dev = virDomainDeviceDefParse(xml, entry->def,
priv->caps,
priv->xmlopt,
VIR_DOMAIN_DEF_PARSE_INACTIVE)))
VIR_DOMAIN_DEF_PARSE_INACTIVE |
VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE)))
goto cleanup;
switch (dev->type) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册