]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
storage_conf: add validation against schema in pool define
authorKristina Hanicova <khanicov@redhat.com>
Tue, 24 Aug 2021 14:51:09 +0000 (16:51 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 25 Aug 2021 07:57:51 +0000 (09:57 +0200)
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>
src/conf/domain_conf.c
src/conf/storage_conf.c
src/conf/storage_conf.h
src/storage/storage_driver.c
src/test/test_driver.c

index 0328447f8785b7905d75494181143992e94540b7..612751311768655b2bb661f29a7375bca27dee1a 100644 (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;
index 040a413d0f532729330d3cd737d74817e77069e8..c78456695c1848d00f0c5f596a58b8a13404dab9 100644 (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);
 }
 
 
index 76efaac531f47abbc24085e4dd820b04ea2307fb..aaecf138d626e3ac936ade25ec9e6316129e156e 100644 (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);
index 6aa10d89f6185530681f8c2dc27595d9b2eb6fce..37b84d038a8ace7dc74bb75814f7e1ecaaed8211 100644 (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)
index f60ea870db921eb4f1cfb2b0c8ac1badec32d92a..33bab0f9d32ee9ba5d4e6422b0c53d51853a1a74 100644 (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;