aboutsummaryrefslogtreecommitdiff
path: root/qapi
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2021-03-18 16:55:18 +0100
committerMarkus Armbruster <armbru@redhat.com>2021-03-19 16:05:11 +0100
commitdb29164103e53ae7c112086127e3d1c92b1d4d89 (patch)
tree97d0238e1d19d87ee0ca9dbc09e3dd46a1a93eda /qapi
parentd2032598c434fe385145ee6ea58007a19ef7e723 (diff)
qapi: Implement deprecated-input=reject for QMP command arguments
This policy rejects deprecated input, and thus permits "testing the future". Implement it for QMP command arguments: reject commands with deprecated ones. Example: when QEMU is run with -compat deprecated-input=reject, then {"execute": "eject", "arguments": {"device": "cd"}} fails like this {"error": {"class": "GenericError", "desc": "Deprecated parameter 'device' disabled by policy"}} When the deprecated parameter is removed, the error will change to {"error": {"class": "GenericError", "desc": "Parameter 'device' is unexpected"}} Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <20210318155519.1224118-11-armbru@redhat.com>
Diffstat (limited to 'qapi')
-rw-r--r--qapi/qapi-visit-core.c9
-rw-r--r--qapi/qmp-dispatch.c9
-rw-r--r--qapi/qobject-input-visitor.c28
-rw-r--r--qapi/trace-events1
4 files changed, 47 insertions, 0 deletions
diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c
index d9726ecaa1..a641adec51 100644
--- a/qapi/qapi-visit-core.c
+++ b/qapi/qapi-visit-core.c
@@ -135,6 +135,15 @@ bool visit_optional(Visitor *v, const char *name, bool *present)
return *present;
}
+bool visit_deprecated_accept(Visitor *v, const char *name, Error **errp)
+{
+ trace_visit_deprecated_accept(v, name);
+ if (v->deprecated_accept) {
+ return v->deprecated_accept(v, name, errp);
+ }
+ return true;
+}
+
bool visit_deprecated(Visitor *v, const char *name)
{
trace_visit_deprecated(v, name);
diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c
index bcb790d876..797df33be4 100644
--- a/qapi/qmp-dispatch.c
+++ b/qapi/qmp-dispatch.c
@@ -19,6 +19,7 @@
#include "qapi/qmp/dispatch.h"
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qjson.h"
+#include "qapi/qobject-input-visitor.h"
#include "qapi/qobject-output-visitor.h"
#include "sysemu/runstate.h"
#include "qapi/qmp/qbool.h"
@@ -27,6 +28,14 @@
CompatPolicy compat_policy;
+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);
+ return v;
+}
+
Visitor *qobject_output_visitor_new_qmp(QObject **result)
{
Visitor *v = qobject_output_visitor_new(result);
diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c
index 23843b242e..bd94cf187a 100644
--- a/qapi/qobject-input-visitor.c
+++ b/qapi/qobject-input-visitor.c
@@ -14,6 +14,7 @@
#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"
@@ -43,6 +44,7 @@ typedef struct StackObject {
struct QObjectInputVisitor {
Visitor visitor;
+ CompatPolicyInput deprecated_policy;
/* Root of visit at visitor creation. */
QObject *root;
@@ -662,6 +664,23 @@ static void qobject_input_optional(Visitor *v, const char *name, bool *present)
*present = true;
}
+static bool qobject_input_deprecated_accept(Visitor *v, const char *name,
+ Error **errp)
+{
+ QObjectInputVisitor *qiv = to_qiv(v);
+
+ switch (qiv->deprecated_policy) {
+ case COMPAT_POLICY_INPUT_ACCEPT:
+ return true;
+ case COMPAT_POLICY_INPUT_REJECT:
+ error_setg(errp, "Deprecated parameter '%s' disabled by policy",
+ name);
+ return false;
+ default:
+ abort();
+ }
+}
+
static void qobject_input_free(Visitor *v)
{
QObjectInputVisitor *qiv = to_qiv(v);
@@ -696,6 +715,7 @@ static QObjectInputVisitor *qobject_input_visitor_base_new(QObject *obj)
v->visitor.end_list = qobject_input_end_list;
v->visitor.start_alternate = qobject_input_start_alternate;
v->visitor.optional = qobject_input_optional;
+ v->visitor.deprecated_accept = qobject_input_deprecated_accept;
v->visitor.free = qobject_input_free;
v->root = qobject_ref(obj);
@@ -718,6 +738,14 @@ 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/trace-events b/qapi/trace-events
index eff1fbd199..3cabe912ae 100644
--- a/qapi/trace-events
+++ b/qapi/trace-events
@@ -17,6 +17,7 @@ visit_start_alternate(void *v, const char *name, void *obj, size_t size) "v=%p n
visit_end_alternate(void *v, void *obj) "v=%p obj=%p"
visit_optional(void *v, const char *name, bool *present) "v=%p name=%s present=%p"
+visit_deprecated_accept(void *v, const char *name) "v=%p name=%s"
visit_deprecated(void *v, const char *name) "v=%p name=%s"
visit_type_enum(void *v, const char *name, int *obj) "v=%p name=%s obj=%p"