mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
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:
parent
7097367b25
commit
59abe66f57
@ -30707,7 +30707,7 @@ virDomainStorageSourceTranslateSourcePool(virStorageSource *src,
|
|||||||
if (!(poolxml = virStoragePoolGetXMLDesc(pool, 0)))
|
if (!(poolxml = virStoragePoolGetXMLDesc(pool, 0)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (!(pooldef = virStoragePoolDefParseString(poolxml)))
|
if (!(pooldef = virStoragePoolDefParseString(poolxml, 0)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
src->srcpool->pooltype = pooldef->type;
|
src->srcpool->pooltype = pooldef->type;
|
||||||
|
@ -1004,12 +1004,14 @@ virStoragePoolDefParseNode(xmlDocPtr xml,
|
|||||||
|
|
||||||
static virStoragePoolDef *
|
static virStoragePoolDef *
|
||||||
virStoragePoolDefParse(const char *xmlStr,
|
virStoragePoolDefParse(const char *xmlStr,
|
||||||
const char *filename)
|
const char *filename,
|
||||||
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
virStoragePoolDef *ret = NULL;
|
virStoragePoolDef *ret = NULL;
|
||||||
g_autoptr(xmlDoc) xml = 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));
|
ret = virStoragePoolDefParseNode(xml, xmlDocGetRootElement(xml));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1018,16 +1020,17 @@ virStoragePoolDefParse(const char *xmlStr,
|
|||||||
|
|
||||||
|
|
||||||
virStoragePoolDef *
|
virStoragePoolDef *
|
||||||
virStoragePoolDefParseString(const char *xmlStr)
|
virStoragePoolDefParseString(const char *xmlStr,
|
||||||
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
return virStoragePoolDefParse(xmlStr, NULL);
|
return virStoragePoolDefParse(xmlStr, NULL, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virStoragePoolDef *
|
virStoragePoolDef *
|
||||||
virStoragePoolDefParseFile(const char *filename)
|
virStoragePoolDefParseFile(const char *filename)
|
||||||
{
|
{
|
||||||
return virStoragePoolDefParse(NULL, filename);
|
return virStoragePoolDefParse(NULL, filename, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -275,7 +275,8 @@ virStoragePoolDef *
|
|||||||
virStoragePoolDefParseXML(xmlXPathContextPtr ctxt);
|
virStoragePoolDefParseXML(xmlXPathContextPtr ctxt);
|
||||||
|
|
||||||
virStoragePoolDef *
|
virStoragePoolDef *
|
||||||
virStoragePoolDefParseString(const char *xml);
|
virStoragePoolDefParseString(const char *xml,
|
||||||
|
unsigned int flags);
|
||||||
|
|
||||||
virStoragePoolDef *
|
virStoragePoolDef *
|
||||||
virStoragePoolDefParseFile(const char *filename);
|
virStoragePoolDefParseFile(const char *filename);
|
||||||
|
@ -737,7 +737,7 @@ storagePoolCreateXML(virConnectPtr conn,
|
|||||||
VIR_EXCLUSIVE_FLAGS_RET(VIR_STORAGE_POOL_BUILD_OVERWRITE,
|
VIR_EXCLUSIVE_FLAGS_RET(VIR_STORAGE_POOL_BUILD_OVERWRITE,
|
||||||
VIR_STORAGE_POOL_BUILD_NO_OVERWRITE, NULL);
|
VIR_STORAGE_POOL_BUILD_NO_OVERWRITE, NULL);
|
||||||
|
|
||||||
if (!(newDef = virStoragePoolDefParseString(xml)))
|
if (!(newDef = virStoragePoolDefParseString(xml, 0)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virStoragePoolCreateXMLEnsureACL(conn, newDef) < 0)
|
if (virStoragePoolCreateXMLEnsureACL(conn, newDef) < 0)
|
||||||
@ -818,7 +818,7 @@ storagePoolDefineXML(virConnectPtr conn,
|
|||||||
|
|
||||||
virCheckFlags(0, NULL);
|
virCheckFlags(0, NULL);
|
||||||
|
|
||||||
if (!(newDef = virStoragePoolDefParseString(xml)))
|
if (!(newDef = virStoragePoolDefParseString(xml, 0)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virXMLCheckIllegalChars("name", newDef->name, "\n") < 0)
|
if (virXMLCheckIllegalChars("name", newDef->name, "\n") < 0)
|
||||||
|
@ -6645,7 +6645,7 @@ testStoragePoolCreateXML(virConnectPtr conn,
|
|||||||
virCheckFlags(0, NULL);
|
virCheckFlags(0, NULL);
|
||||||
|
|
||||||
virObjectLock(privconn);
|
virObjectLock(privconn);
|
||||||
if (!(newDef = virStoragePoolDefParseString(xml)))
|
if (!(newDef = virStoragePoolDefParseString(xml, 0)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(obj = virStoragePoolObjListAdd(privconn->pools, newDef,
|
if (!(obj = virStoragePoolObjListAdd(privconn->pools, newDef,
|
||||||
@ -6708,7 +6708,7 @@ testStoragePoolDefineXML(virConnectPtr conn,
|
|||||||
virCheckFlags(0, NULL);
|
virCheckFlags(0, NULL);
|
||||||
|
|
||||||
virObjectLock(privconn);
|
virObjectLock(privconn);
|
||||||
if (!(newDef = virStoragePoolDefParseString(xml)))
|
if (!(newDef = virStoragePoolDefParseString(xml, 0)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
newDef->capacity = defaultPoolCap;
|
newDef->capacity = defaultPoolCap;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user