storage_conf: add validation against schema in pool define

We need to validate the XML against schema if option '--validate'
was passed to the virsh command. This patch also includes
propagation of flags into the virStoragePoolDefParse() function.

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Kristina Hanicova 2021-08-24 16:51:09 +02:00 committed by Michal Privoznik
parent 7097367b25
commit 59abe66f57
5 changed files with 15 additions and 11 deletions

View File

@ -30707,7 +30707,7 @@ virDomainStorageSourceTranslateSourcePool(virStorageSource *src,
if (!(poolxml = virStoragePoolGetXMLDesc(pool, 0)))
return -1;
if (!(pooldef = virStoragePoolDefParseString(poolxml)))
if (!(pooldef = virStoragePoolDefParseString(poolxml, 0)))
return -1;
src->srcpool->pooltype = pooldef->type;

View File

@ -1004,12 +1004,14 @@ virStoragePoolDefParseNode(xmlDocPtr xml,
static virStoragePoolDef *
virStoragePoolDefParse(const char *xmlStr,
const char *filename)
const char *filename,
unsigned int flags)
{
virStoragePoolDef *ret = NULL;
g_autoptr(xmlDoc) xml = NULL;
if ((xml = virXMLParse(filename, xmlStr, _("(storage_pool_definition)"), NULL, false))) {
if ((xml = virXMLParse(filename, xmlStr, _("(storage_pool_definition)"),
"storagepool.rng", flags & VIR_STORAGE_POOL_DEFINE_VALIDATE))) {
ret = virStoragePoolDefParseNode(xml, xmlDocGetRootElement(xml));
}
@ -1018,16 +1020,17 @@ virStoragePoolDefParse(const char *xmlStr,
virStoragePoolDef *
virStoragePoolDefParseString(const char *xmlStr)
virStoragePoolDefParseString(const char *xmlStr,
unsigned int flags)
{
return virStoragePoolDefParse(xmlStr, NULL);
return virStoragePoolDefParse(xmlStr, NULL, flags);
}
virStoragePoolDef *
virStoragePoolDefParseFile(const char *filename)
{
return virStoragePoolDefParse(NULL, filename);
return virStoragePoolDefParse(NULL, filename, 0);
}

View File

@ -275,7 +275,8 @@ virStoragePoolDef *
virStoragePoolDefParseXML(xmlXPathContextPtr ctxt);
virStoragePoolDef *
virStoragePoolDefParseString(const char *xml);
virStoragePoolDefParseString(const char *xml,
unsigned int flags);
virStoragePoolDef *
virStoragePoolDefParseFile(const char *filename);

View File

@ -737,7 +737,7 @@ storagePoolCreateXML(virConnectPtr conn,
VIR_EXCLUSIVE_FLAGS_RET(VIR_STORAGE_POOL_BUILD_OVERWRITE,
VIR_STORAGE_POOL_BUILD_NO_OVERWRITE, NULL);
if (!(newDef = virStoragePoolDefParseString(xml)))
if (!(newDef = virStoragePoolDefParseString(xml, 0)))
goto cleanup;
if (virStoragePoolCreateXMLEnsureACL(conn, newDef) < 0)
@ -818,7 +818,7 @@ storagePoolDefineXML(virConnectPtr conn,
virCheckFlags(0, NULL);
if (!(newDef = virStoragePoolDefParseString(xml)))
if (!(newDef = virStoragePoolDefParseString(xml, 0)))
goto cleanup;
if (virXMLCheckIllegalChars("name", newDef->name, "\n") < 0)

View File

@ -6645,7 +6645,7 @@ testStoragePoolCreateXML(virConnectPtr conn,
virCheckFlags(0, NULL);
virObjectLock(privconn);
if (!(newDef = virStoragePoolDefParseString(xml)))
if (!(newDef = virStoragePoolDefParseString(xml, 0)))
goto cleanup;
if (!(obj = virStoragePoolObjListAdd(privconn->pools, newDef,
@ -6708,7 +6708,7 @@ testStoragePoolDefineXML(virConnectPtr conn,
virCheckFlags(0, NULL);
virObjectLock(privconn);
if (!(newDef = virStoragePoolDefParseString(xml)))
if (!(newDef = virStoragePoolDefParseString(xml, 0)))
goto cleanup;
newDef->capacity = defaultPoolCap;