diff options
| author | Richard Henderson <richard.henderson@linaro.org> | 2021-10-27 09:42:40 -0700 |
|---|---|---|
| committer | Richard Henderson <richard.henderson@linaro.org> | 2021-10-27 09:42:40 -0700 |
| commit | 5c49c6c241e524b6ba7768de07cab6f2056feb90 (patch) | |
| tree | 7b55c4687b9ba2f2c426b106772c14e82761db5a /qapi/qapi-visit-core.c | |
| parent | 931ce30859176f0f7daac6bac255dae5eb21284e (diff) | |
| parent | aa2370444b62f8f9a809c024d0c41cb40658a5c3 (diff) | |
| download | focaccia-qemu-5c49c6c241e524b6ba7768de07cab6f2056feb90.tar.gz focaccia-qemu-5c49c6c241e524b6ba7768de07cab6f2056feb90.zip | |
Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2021-10-27' into staging
QAPI patches patches for 2021-10-27
# gpg: Signature made Wed 27 Oct 2021 08:21:54 AM PDT
# gpg: using RSA key 354BC8B3D7EB2A6B68674E5F3870B400EB918653
# gpg: issuer "armbru@redhat.com"
# gpg: Good signature from "Markus Armbruster <armbru@redhat.com>" [full]
# gpg: aka "Markus Armbruster <armbru@pond.sub.org>" [full]
* remotes/armbru/tags/pull-qapi-2021-10-27:
qapi: Implement deprecated-input={reject,crash} for enum values
qapi: Move compat policy from QObject to generic visitor
qapi: Add feature flags to enum members
qapi: Enable enum member introspection to show more than name
qapi: Improve input_type_enum()'s error message
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Diffstat (limited to 'qapi/qapi-visit-core.c')
| -rw-r--r-- | qapi/qapi-visit-core.c | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c index a641adec51..617ef3fa46 100644 --- a/qapi/qapi-visit-core.c +++ b/qapi/qapi-visit-core.c @@ -19,6 +19,10 @@ #include "qapi/visitor-impl.h" #include "trace.h" +/* Zero-initialization must result in default policy */ +QEMU_BUILD_BUG_ON(COMPAT_POLICY_INPUT_ACCEPT || COMPAT_POLICY_OUTPUT_ACCEPT); + + void visit_complete(Visitor *v, void *opaque) { assert(v->type != VISITOR_OUTPUT || v->complete); @@ -153,6 +157,11 @@ bool visit_deprecated(Visitor *v, const char *name) return true; } +void visit_set_policy(Visitor *v, CompatPolicy *policy) +{ + v->compat_policy = *policy; +} + bool visit_is_input(Visitor *v) { return v->type == VISITOR_INPUT; @@ -384,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; @@ -392,12 +401,25 @@ static bool input_type_enum(Visitor *v, const char *name, int *obj, value = qapi_enum_parse(lookup, enum_str, -1, NULL); if (value < 0) { - error_setg(errp, QERR_INVALID_PARAMETER, enum_str); - g_free(enum_str); + error_setg(errp, "Parameter '%s' does not accept value '%s'", + name ? name : "null", 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; } |