[PATCH 1/3] libxl: Introduce domain def validate callback

Jim Fehlig jfehlig at suse.com
Fri Jun 4 17:27:46 UTC 2021


Introduce libxlDomainDefValidate and move the existing validation
check from libxlDomainDefPostParse. Additional validation will be
introduced in subsequent patches.

Signed-off-by: Jim Fehlig <jfehlig at suse.com>
---
 src/libxl/libxl_domain.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index 625e04a9b0..9630f12568 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -379,17 +379,9 @@ libxlDomainDeviceDefPostParse(virDomainDeviceDef *dev,
 static int
 libxlDomainDefPostParse(virDomainDef *def,
                         unsigned int parseFlags G_GNUC_UNUSED,
-                        void *opaque,
+                        void *opaque G_GNUC_UNUSED,
                         void *parseOpaque G_GNUC_UNUSED)
 {
-    libxlDriverPrivate *driver = opaque;
-    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
-
-    if (!virCapabilitiesDomainSupported(cfg->caps, def->os.type,
-                                        def->os.arch,
-                                        def->virtType))
-        return -1;
-
     /* Xen PV domains always have a PV console, so add one to the domain config
      * via post-parse callback if not explicitly specified in the XML. */
     if (def->os.type != VIR_DOMAIN_OSTYPE_HVM && def->nconsoles == 0) {
@@ -441,11 +433,28 @@ libxlDomainDefPostParse(virDomainDef *def,
     return 0;
 }
 
+static int
+libxlDomainDefValidate(const virDomainDef *def,
+                       void *opaque,
+                       void *parseOpaque G_GNUC_UNUSED)
+{
+    libxlDriverPrivate *driver = opaque;
+    g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
+
+    if (!virCapabilitiesDomainSupported(cfg->caps, def->os.type,
+                                        def->os.arch,
+                                        def->virtType))
+        return -1;
+
+    return 0;
+}
+
 virDomainDefParserConfig libxlDomainDefParserConfig = {
     .macPrefix = { 0x00, 0x16, 0x3e },
     .netPrefix = LIBXL_GENERATED_PREFIX_XEN,
     .devicesPostParseCallback = libxlDomainDeviceDefPostParse,
     .domainPostParseCallback = libxlDomainDefPostParse,
+    .domainValidateCallback = libxlDomainDefValidate,
     .features = VIR_DOMAIN_DEF_FEATURE_NET_MODEL_STRING,
 };
 
-- 
2.31.1





More information about the libvir-list mailing list