aboutsummaryrefslogtreecommitdiff
path: root/qapi
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2021-10-25 06:24:04 +0200
committerMarkus Armbruster <armbru@redhat.com>2021-10-27 17:19:34 +0200
commitaa2370444b62f8f9a809c024d0c41cb40658a5c3 (patch)
tree7b55c4687b9ba2f2c426b106772c14e82761db5a /qapi
parented29bb28f8b0b17e965efcc2535fc32e101e3ceb (diff)
qapi: Implement deprecated-input={reject,crash} for enum values
This copies the code implementing the policy from qapi/qmp-dispatch.c to qapi/qobject-input-visitor.c. Tolerable, but if we acquire more copies, we should look into factoring them out. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Tested-by: Peter Krempa <pkrempa@redhat.com> Acked-by: Peter Krempa <pkrempa@redhat.com> Message-Id: <20211025042405.3762351-5-armbru@redhat.com>
Diffstat (limited to 'qapi')
-rw-r--r--qapi/compat.json3
-rw-r--r--qapi/qapi-visit-core.c18
2 files changed, 17 insertions, 4 deletions
diff --git a/qapi/compat.json b/qapi/compat.json
index 1d2b76f00c..74a8493d3d 100644
--- a/qapi/compat.json
+++ b/qapi/compat.json
@@ -42,7 +42,8 @@
# with feature 'deprecated'. We may want to extend it to cover
# semantic aspects, CLI, and experimental features.
#
-# Limitation: not implemented for deprecated enumeration values.
+# Limitation: deprecated-output policy @hide is not implemented for
+# enumeration values. They behave the same as with policy @accept.
#
# @deprecated-input: how to handle deprecated input (default 'accept')
# @deprecated-output: how to handle deprecated output (default 'accept')
diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c
index 93fb154ef3..617ef3fa46 100644
--- a/qapi/qapi-visit-core.c
+++ b/qapi/qapi-visit-core.c
@@ -393,7 +393,7 @@ static bool input_type_enum(Visitor *v, const char *name, int *obj,
const QEnumLookup *lookup, Error **errp)
{
int64_t value;
- char *enum_str;
+ g_autofree char *enum_str = NULL;
if (!visit_type_str(v, name, &enum_str, errp)) {
return false;
@@ -403,11 +403,23 @@ static bool input_type_enum(Visitor *v, const char *name, int *obj,
if (value < 0) {
error_setg(errp, "Parameter '%s' does not accept value '%s'",
name ? name : "null", enum_str);
- g_free(enum_str);
return false;
}
- g_free(enum_str);
+ if (lookup->flags && (lookup->flags[value] & QAPI_ENUM_DEPRECATED)) {
+ switch (v->compat_policy.deprecated_input) {
+ case COMPAT_POLICY_INPUT_ACCEPT:
+ break;
+ case COMPAT_POLICY_INPUT_REJECT:
+ error_setg(errp, "Deprecated value '%s' disabled by policy",
+ enum_str);
+ return false;
+ case COMPAT_POLICY_INPUT_CRASH:
+ default:
+ abort();
+ }
+ }
+
*obj = value;
return true;
}