summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Krempa <pkrempa@redhat.com>2023-04-19 10:29:14 +0200
committerPeter Krempa <pkrempa@redhat.com>2023-05-02 14:32:47 +0200
commit07652410a7af98ca03281c4bfe20415ced26a44a (patch)
treeeea3ea8a4ede2987b4ce9688ccbadf905736a394
parentb5ee977d179dc7807dceeaeb887d30849e558fe8 (diff)
downloadlibvirt-07652410a7af98ca03281c4bfe20415ced26a44a.tar.gz
virTypedParamsValidate: Allow typed params to be both _UINT and _ULLONG
For certain typed parameters we want to extend the supproted range by switching to VIR_TYPED_PARAM_ULLONG. To preserve compatibility we've added APIs such as 'virTypedParamsGetUnsigned' and 'virTypedParamListAddUnsigned' which automatically select the bigger type if necessary. This patch adds a new internal macro VIR_TYPED_PARAM_UNSIGNED which is used with virTypedParamsValidate to allow both types and adjusts the code to handle it properly. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
-rw-r--r--src/util/virtypedparam.c19
-rw-r--r--src/util/virtypedparam.h9
2 files changed, 23 insertions, 5 deletions
diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c
index 73b9420e5e..3bb8b125e9 100644
--- a/src/util/virtypedparam.c
+++ b/src/util/virtypedparam.c
@@ -63,7 +63,6 @@ virTypedParamsValidate(virTypedParameterPtr params, int nparams, ...)
size_t j;
const char *name;
const char *last_name = NULL;
- int type;
size_t nkeys = 0;
size_t nkeysalloc = 0;
g_autofree virTypedParameterPtr sorted = NULL;
@@ -79,7 +78,7 @@ virTypedParamsValidate(virTypedParameterPtr params, int nparams, ...)
name = va_arg(ap, const char *);
while (name) {
- type = va_arg(ap, int);
+ int type = va_arg(ap, int);
VIR_RESIZE_N(keys, nkeysalloc, nkeys, 1);
if (virStrcpyStatic(keys[nkeys].field, name) < 0) {
@@ -105,6 +104,9 @@ virTypedParamsValidate(virTypedParameterPtr params, int nparams, ...)
if (STRNEQ(sorted[i].field, keys[j].field)) {
j++;
} else {
+ const char *expecttype = virTypedParameterTypeToString(keys[j].type);
+ int type = sorted[i].type;
+
if (STREQ_NULLABLE(last_name, sorted[i].field) &&
!(keys[j].value.i & VIR_TYPED_PARAM_MULTIPLE)) {
virReportError(VIR_ERR_INVALID_ARG,
@@ -112,7 +114,15 @@ virTypedParamsValidate(virTypedParameterPtr params, int nparams, ...)
sorted[i].field);
return -1;
}
- if (sorted[i].type != keys[j].type) {
+
+ if (keys[j].type == VIR_TYPED_PARAM_UNSIGNED &&
+ (type == VIR_TYPED_PARAM_UINT ||
+ type == VIR_TYPED_PARAM_ULLONG)) {
+ type = VIR_TYPED_PARAM_UNSIGNED;
+ expecttype = "uint, ullong";
+ }
+
+ if (type != keys[j].type) {
const char *badtype;
badtype = virTypedParameterTypeToString(sorted[i].type);
@@ -120,8 +130,7 @@ virTypedParamsValidate(virTypedParameterPtr params, int nparams, ...)
badtype = virTypedParameterTypeToString(0);
virReportError(VIR_ERR_INVALID_ARG,
_("invalid type '%1$s' for parameter '%2$s', expected '%3$s'"),
- badtype, sorted[i].field,
- virTypedParameterTypeToString(keys[j].type));
+ badtype, sorted[i].field, expecttype);
return -1;
}
last_name = sorted[i].field;
diff --git a/src/util/virtypedparam.h b/src/util/virtypedparam.h
index c2f58e994c..7454ef3ce0 100644
--- a/src/util/virtypedparam.h
+++ b/src/util/virtypedparam.h
@@ -24,6 +24,15 @@
#include "internal.h"
#include "virenum.h"
+
+/**
+ * VIR_TYPED_PARAM_UNSIGNED:
+ *
+ * Special typed parameter type only used with virTypedParamsValidate to
+ * indicate that both VIR_TYPED_PARAM_UINT and VIR_TYPED_PARAM_ULLONG types
+ * are acceptable for given value.
+ */
+#define VIR_TYPED_PARAM_UNSIGNED (VIR_TYPED_PARAM_LAST + 1)
/**
* VIR_TYPED_PARAM_MULTIPLE:
*