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@xxxxxxxxxx> --- src/conf/domain_conf.c | 2 +- src/conf/storage_conf.c | 13 ++++++++----- src/conf/storage_conf.h | 3 ++- src/storage/storage_driver.c | 4 ++-- src/test/test_driver.c | 4 ++-- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 0328447f87..6127513117 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -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; diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 040a413d0f..c78456695c 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -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); } diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h index 76efaac531..aaecf138d6 100644 --- a/src/conf/storage_conf.h +++ b/src/conf/storage_conf.h @@ -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); diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 6aa10d89f6..37b84d038a 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -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) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index f60ea870db..33bab0f9d3 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -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; -- 2.31.1