util: hostmem: Make parameters for 'virHostMemSetParameters' introspectable

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 <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa committed 2026-05-14 12:13:10 +02:00
1 parent ccb62a313f
commit 3281beb957
4 files changed
+23 -8

No files matched your search

+1
View File
@@ -2607,6 +2607,7 @@ virHostMemGetParameters;
virHostMemGetStats;
virHostMemGetTHPSize;
virHostMemSetParameters;
virHostMemSetParametersValidation;
# util/virhostuptime.h
+4
View File
@@ -16507,6 +16507,10 @@ qemuNodeSetMemoryParameters(virConnectPtr conn,
{
virCheckFlags(0, -1);
if (virTypedParamsValidateTemplate(params, nparams,
virHostMemSetParametersValidation) < 0)
return -1;
if (virNodeSetMemoryParametersEnsureACL(conn) < 0)
return -1;
+16 -8
View File
@@ -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)
+2
View File
@@ -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);