From: Peter Krempa <[email protected]>

Refactor the validation using 'virTypedParamsValidateTemplate' and
export the template so that 'qemuNodeSetMemoryParameters' can expose
them via introspection.

In addition since 'virHostMemSetParameters' is conditionally compiled,
platforms which don't support it will not expose given params.

Signed-off-by: Peter Krempa <[email protected]>
---
 src/libvirt_private.syms |  1 +
 src/qemu/qemu_driver.c   |  4 ++++
 src/util/virhostmem.c    | 24 ++++++++++++++++--------
 src/util/virhostmem.h    |  2 ++
 4 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 20507af7f7..94351fe153 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2605,6 +2605,7 @@ virHostMemGetParameters;
 virHostMemGetStats;
 virHostMemGetTHPSize;
 virHostMemSetParameters;
+virHostMemSetParametersValidation;


 # util/virhostuptime.h
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 82f5febc6b..d64366924c 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -16502,6 +16502,10 @@ qemuNodeSetMemoryParameters(virConnectPtr conn,
 {
     virCheckFlags(0, -1);

+    if (virTypedParamsValidateTemplate(params, nparams,
+                                       virHostMemSetParametersValidation) < 0)
+        return -1;
+
     if (virNodeSetMemoryParametersEnsureACL(conn) < 0)
         return -1;

diff --git a/src/util/virhostmem.c b/src/util/virhostmem.c
index 7d7deac34b..beff114362 100644
--- a/src/util/virhostmem.c
+++ b/src/util/virhostmem.c
@@ -351,21 +351,24 @@ virHostMemParametersAreAllSupported(virTypedParameterPtr 
params,
 }
 #endif

+
 #ifdef __linux__
+const virTypedParamValidationTemplate virHostMemSetParametersValidation[] =
+{
+    { VIR_NODE_MEMORY_SHARED_PAGES_TO_SCAN, VIR_TYPED_PARAM_UINT },
+    { VIR_NODE_MEMORY_SHARED_SLEEP_MILLISECS, VIR_TYPED_PARAM_UINT },
+    { VIR_NODE_MEMORY_SHARED_MERGE_ACROSS_NODES, VIR_TYPED_PARAM_UINT },
+    { "", 0 }
+};
+
 int
 virHostMemSetParameters(virTypedParameterPtr params,
                         int nparams)
 {
     size_t i;

-    if (virTypedParamsValidate(params, nparams,
-                               VIR_NODE_MEMORY_SHARED_PAGES_TO_SCAN,
-                               VIR_TYPED_PARAM_UINT,
-                               VIR_NODE_MEMORY_SHARED_SLEEP_MILLISECS,
-                               VIR_TYPED_PARAM_UINT,
-                               VIR_NODE_MEMORY_SHARED_MERGE_ACROSS_NODES,
-                               VIR_TYPED_PARAM_UINT,
-                               NULL) < 0)
+    if (virTypedParamsValidateTemplate(params, nparams,
+                                       virHostMemSetParametersValidation) < 0)
         return -1;

     if (!virHostMemParametersAreAllSupported(params, nparams))
@@ -379,6 +382,11 @@ virHostMemSetParameters(virTypedParameterPtr params,
     return 0;
 }
 #else
+const virTypedParamValidationTemplate virHostMemSetParametersValidation[] =
+{
+    { "", 0 }
+};
+
 int
 virHostMemSetParameters(virTypedParameterPtr params G_GNUC_UNUSED,
                         int nparams G_GNUC_UNUSED)
diff --git a/src/util/virhostmem.h b/src/util/virhostmem.h
index 4a0d692402..ebe7d26f21 100644
--- a/src/util/virhostmem.h
+++ b/src/util/virhostmem.h
@@ -22,6 +22,7 @@
 #pragma once

 #include "internal.h"
+#include "virtypedparam.h"

 int virHostMemGetStats(int cellNum,
                        virNodeMemoryStatsPtr params,
@@ -35,6 +36,7 @@ int virHostMemGetInfo(unsigned long long *mem,
 int virHostMemGetParameters(virTypedParameterPtr params,
                             int *nparams);

+extern const virTypedParamValidationTemplate 
virHostMemSetParametersValidation[];
 int virHostMemSetParameters(virTypedParameterPtr params,
                             int nparams);

-- 
2.54.0

Reply via email to