aboutsummaryrefslogtreecommitdiff
path: root/qapi
diff options
context:
space:
mode:
authorRichard Henderson <richard.henderson@linaro.org>2021-10-27 09:42:40 -0700
committerRichard Henderson <richard.henderson@linaro.org>2021-10-27 09:42:40 -0700
commit5c49c6c241e524b6ba7768de07cab6f2056feb90 (patch)
tree7b55c4687b9ba2f2c426b106772c14e82761db5a /qapi
parent931ce30859176f0f7daac6bac255dae5eb21284e (diff)
parentaa2370444b62f8f9a809c024d0c41cb40658a5c3 (diff)
downloadqemu-5c49c6c241e524b6ba7768de07cab6f2056feb90.zip
qemu-5c49c6c241e524b6ba7768de07cab6f2056feb90.tar.gz
qemu-5c49c6c241e524b6ba7768de07cab6f2056feb90.tar.bz2
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')
-rw-r--r--qapi/compat.json3
-rw-r--r--qapi/introspect.json28
-rw-r--r--qapi/qapi-visit-core.c30
-rw-r--r--qapi/qmp-dispatch.c4
-rw-r--r--qapi/qobject-input-visitor.c14
-rw-r--r--qapi/qobject-output-visitor.c14
6 files changed, 59 insertions, 34 deletions
diff --git a/qapi/compat.json b/qapi/compat.json
index ae3afc2..74a8493 100644
--- a/qapi/compat.json
+++ b/qapi/compat.json
@@ -42,6 +42,9 @@
# with feature 'deprecated'. We may want to extend it to cover
# semantic aspects, CLI, and experimental features.
#
+# 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/introspect.json b/qapi/introspect.json
index 39bd303..183148b 100644
--- a/qapi/introspect.json
+++ b/qapi/introspect.json
@@ -142,14 +142,38 @@
#
# Additional SchemaInfo members for meta-type 'enum'.
#
-# @values: the enumeration type's values, in no particular order.
+# @members: the enum type's members, in no particular order
+# (since 6.2).
+#
+# @values: the enumeration type's member names, in no particular order.
+# Redundant with @members. Just for backward compatibility.
+#
+# Features:
+# @deprecated: Member @values is deprecated. Use @members instead.
#
# Values of this type are JSON string on the wire.
#
# Since: 2.5
##
{ 'struct': 'SchemaInfoEnum',
- 'data': { 'values': ['str'] } }
+ 'data': { 'members': [ 'SchemaInfoEnumMember' ],
+ 'values': { 'type': [ 'str' ],
+ 'features': [ 'deprecated' ] } } }
+
+##
+# @SchemaInfoEnumMember:
+#
+# An object member.
+#
+# @name: the member's name, as defined in the QAPI schema.
+#
+# @features: names of features associated with the member, in no
+# particular order.
+#
+# Since: 6.2
+##
+{ 'struct': 'SchemaInfoEnumMember',
+ 'data': { 'name': 'str', '*features': [ 'str' ] } }
##
# @SchemaInfoArray:
diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c
index a641ade..617ef3f 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;
}
diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c
index 5960021..7e943a0 100644
--- a/qapi/qmp-dispatch.c
+++ b/qapi/qmp-dispatch.c
@@ -32,7 +32,7 @@ Visitor *qobject_input_visitor_new_qmp(QObject *obj)
{
Visitor *v = qobject_input_visitor_new(obj);
- qobject_input_visitor_set_policy(v, compat_policy.deprecated_input);
+ visit_set_policy(v, &compat_policy);
return v;
}
@@ -40,7 +40,7 @@ Visitor *qobject_output_visitor_new_qmp(QObject **result)
{
Visitor *v = qobject_output_visitor_new(result);
- qobject_output_visitor_set_policy(v, compat_policy.deprecated_output);
+ visit_set_policy(v, &compat_policy);
return v;
}
diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c
index 04b7904..71b24a4 100644
--- a/qapi/qobject-input-visitor.c
+++ b/qapi/qobject-input-visitor.c
@@ -14,7 +14,6 @@
#include "qemu/osdep.h"
#include <math.h>
-#include "qapi/compat-policy.h"
#include "qapi/error.h"
#include "qapi/qobject-input-visitor.h"
#include "qapi/visitor-impl.h"
@@ -44,7 +43,6 @@ typedef struct StackObject {
struct QObjectInputVisitor {
Visitor visitor;
- CompatPolicyInput deprecated_policy;
/* Root of visit at visitor creation. */
QObject *root;
@@ -667,9 +665,7 @@ static void qobject_input_optional(Visitor *v, const char *name, bool *present)
static bool qobject_input_deprecated_accept(Visitor *v, const char *name,
Error **errp)
{
- QObjectInputVisitor *qiv = to_qiv(v);
-
- switch (qiv->deprecated_policy) {
+ switch (v->compat_policy.deprecated_input) {
case COMPAT_POLICY_INPUT_ACCEPT:
return true;
case COMPAT_POLICY_INPUT_REJECT:
@@ -739,14 +735,6 @@ Visitor *qobject_input_visitor_new(QObject *obj)
return &v->visitor;
}
-void qobject_input_visitor_set_policy(Visitor *v,
- CompatPolicyInput deprecated)
-{
- QObjectInputVisitor *qiv = to_qiv(v);
-
- qiv->deprecated_policy = deprecated;
-}
-
Visitor *qobject_input_visitor_new_keyval(QObject *obj)
{
QObjectInputVisitor *v = qobject_input_visitor_base_new(obj);
diff --git a/qapi/qobject-output-visitor.c b/qapi/qobject-output-visitor.c
index e487330..9b7f510 100644
--- a/qapi/qobject-output-visitor.c
+++ b/qapi/qobject-output-visitor.c
@@ -13,7 +13,6 @@
*/
#include "qemu/osdep.h"
-#include "qapi/compat-policy.h"
#include "qapi/qobject-output-visitor.h"
#include "qapi/visitor-impl.h"
#include "qemu/queue.h"
@@ -32,7 +31,6 @@ typedef struct QStackEntry {
struct QObjectOutputVisitor {
Visitor visitor;
- CompatPolicyOutput deprecated_policy;
QSLIST_HEAD(, QStackEntry) stack; /* Stack of unfinished containers */
QObject *root; /* Root of the output visit */
@@ -212,9 +210,7 @@ static bool qobject_output_type_null(Visitor *v, const char *name,
static bool qobject_output_deprecated(Visitor *v, const char *name)
{
- QObjectOutputVisitor *qov = to_qov(v);
-
- return qov->deprecated_policy != COMPAT_POLICY_OUTPUT_HIDE;
+ return v->compat_policy.deprecated_output != COMPAT_POLICY_OUTPUT_HIDE;
}
/* Finish building, and return the root object.
@@ -275,11 +271,3 @@ Visitor *qobject_output_visitor_new(QObject **result)
return &v->visitor;
}
-
-void qobject_output_visitor_set_policy(Visitor *v,
- CompatPolicyOutput deprecated)
-{
- QObjectOutputVisitor *qov = to_qov(v);
-
- qov->deprecated_policy = deprecated;
-}