[PATCH 4/6] conf: storage: Add support for validating storage vol XML to virStorageVolDefParse

Peter Krempa pkrempa at redhat.com
Thu Oct 20 14:37:53 UTC 2022


Introduce the VIR_VOL_XML_PARSE_VALIDATE parser flag and wire it up into
the validator.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 src/conf/storage_conf.c | 3 ++-
 src/conf/storage_conf.h | 2 ++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 0f4fe1451e..72c53872cb 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1407,9 +1407,10 @@ virStorageVolDefParse(virStoragePoolDef *pool,
 {
     g_autoptr(xmlDoc) xml = NULL;
     g_autoptr(xmlXPathContext) ctxt = NULL;
+    bool validate = flags & VIR_VOL_XML_PARSE_VALIDATE;

     if (!(xml = virXMLParse(filename, xmlStr, _("(storage_volume_definition)"),
-                            "volume", &ctxt, NULL, false)))
+                            "volume", &ctxt, "storagevol.rng", validate)))
         return NULL;

     return virStorageVolDefParseXML(pool, ctxt, flags);
diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h
index bbfdbc2f2f..fc67957cfe 100644
--- a/src/conf/storage_conf.h
+++ b/src/conf/storage_conf.h
@@ -284,6 +284,8 @@ typedef enum {
     VIR_VOL_XML_PARSE_NO_CAPACITY  = 1 << 0,
     /* do not require volume capacity if the volume has a backing store */
     VIR_VOL_XML_PARSE_OPT_CAPACITY = 1 << 1,
+    /* validate the XML against the RNG schema */
+    VIR_VOL_XML_PARSE_VALIDATE = 1 << 2,
 } virStorageVolDefParseFlags;

 virStorageVolDef *
-- 
2.37.3



More information about the libvir-list mailing list