aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/qapi/compat-policy.h9
-rw-r--r--include/qapi/qobject-input-visitor.h4
-rw-r--r--include/qapi/visitor-impl.h3
-rw-r--r--include/qapi/visitor.h9
-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
-rw-r--r--scripts/qapi/commands.py3
-rw-r--r--scripts/qapi/visit.py3
-rw-r--r--tests/unit/test-qmp-cmds.c25
11 files changed, 101 insertions, 2 deletions
diff --git a/include/qapi/compat-policy.h b/include/qapi/compat-policy.h
index 94c8bbd790..1083f95122 100644
--- a/include/qapi/compat-policy.h
+++ b/include/qapi/compat-policy.h
@@ -18,6 +18,15 @@
extern CompatPolicy compat_policy;
/*
+ * Create a QObject input visitor for @obj for use with QMP
+ *
+ * This is like qobject_input_visitor_new(), except it obeys the
+ * policy for handling deprecated management interfaces set with
+ * -compat.
+ */
+Visitor *qobject_input_visitor_new_qmp(QObject *obj);
+
+/*
* Create a QObject output visitor for @obj for use with QMP
*
* This is like qobject_output_visitor_new(), except it obeys the
diff --git a/include/qapi/qobject-input-visitor.h b/include/qapi/qobject-input-visitor.h
index 95985e25e5..8d69388810 100644
--- a/include/qapi/qobject-input-visitor.h
+++ b/include/qapi/qobject-input-visitor.h
@@ -15,6 +15,7 @@
#ifndef QOBJECT_INPUT_VISITOR_H
#define QOBJECT_INPUT_VISITOR_H
+#include "qapi/qapi-types-compat.h"
#include "qapi/visitor.h"
typedef struct QObjectInputVisitor QObjectInputVisitor;
@@ -58,6 +59,9 @@ typedef struct QObjectInputVisitor QObjectInputVisitor;
*/
Visitor *qobject_input_visitor_new(QObject *obj);
+void qobject_input_visitor_set_policy(Visitor *v,
+ CompatPolicyInput deprecated);
+
/*
* Create a QObject input visitor for @obj for use with keyval_parse()
*
diff --git a/include/qapi/visitor-impl.h b/include/qapi/visitor-impl.h
index 2d853255a3..3b950f6e3d 100644
--- a/include/qapi/visitor-impl.h
+++ b/include/qapi/visitor-impl.h
@@ -114,6 +114,9 @@ struct Visitor
void (*optional)(Visitor *v, const char *name, bool *present);
/* Optional */
+ bool (*deprecated_accept)(Visitor *v, const char *name, Error **errp);
+
+ /* Optional */
bool (*deprecated)(Visitor *v, const char *name);
/* Must be set */
diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h
index 4d23b59853..b3c9ef7a81 100644
--- a/include/qapi/visitor.h
+++ b/include/qapi/visitor.h
@@ -460,6 +460,15 @@ void visit_end_alternate(Visitor *v, void **obj);
bool visit_optional(Visitor *v, const char *name, bool *present);
/*
+ * Should we reject deprecated member @name?
+ *
+ * @name must not be NULL. This function is only useful between
+ * visit_start_struct() and visit_end_struct(), since only objects
+ * have deprecated members.
+ */
+bool visit_deprecated_accept(Visitor *v, const char *name, Error **errp);
+
+/*
* Should we visit deprecated member @name?
*
* @name must not be NULL. This function is only useful between
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"
diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py
index c4628517ee..0e13d51054 100644
--- a/scripts/qapi/commands.py
+++ b/scripts/qapi/commands.py
@@ -154,7 +154,7 @@ def gen_marshal(name: str,
ret += mcgen('''
- v = qobject_input_visitor_new(QOBJECT(args));
+ v = qobject_input_visitor_new_qmp(QOBJECT(args));
if (!visit_start_struct(v, NULL, NULL, 0, errp)) {
goto out;
}
@@ -258,7 +258,6 @@ class QAPISchemaGenCommandVisitor(QAPISchemaModularCVisitor):
#include "qapi/compat-policy.h"
#include "qapi/visitor.h"
#include "qapi/qmp/qdict.h"
-#include "qapi/qobject-input-visitor.h"
#include "qapi/dealloc-visitor.h"
#include "qapi/error.h"
#include "%(visit)s.h"
diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py
index 9d83bf650f..9e96f3c566 100644
--- a/scripts/qapi/visit.py
+++ b/scripts/qapi/visit.py
@@ -87,6 +87,9 @@ bool visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **errp)
indent.increase()
if deprecated:
ret += mcgen('''
+ if (!visit_deprecated_accept(v, "%(name)s", errp)) {
+ return false;
+ }
if (visit_deprecated(v, "%(name)s")) {
''',
name=memb.name)
diff --git a/tests/unit/test-qmp-cmds.c b/tests/unit/test-qmp-cmds.c
index cba982154b..266db074b4 100644
--- a/tests/unit/test-qmp-cmds.c
+++ b/tests/unit/test-qmp-cmds.c
@@ -303,6 +303,29 @@ static void test_dispatch_cmd_deprecated(void)
do_qmp_dispatch_error(false, ERROR_CLASS_COMMAND_NOT_FOUND, cmd);
}
+static void test_dispatch_cmd_arg_deprecated(void)
+{
+ const char *cmd = "{ 'execute': 'test-features0',"
+ " 'arguments': { 'fs1': { 'foo': 42 } } }";
+ QDict *ret;
+
+ memset(&compat_policy, 0, sizeof(compat_policy));
+
+ /* accept */
+ ret = qobject_to(QDict, do_qmp_dispatch(false, cmd));
+ assert(ret && qdict_size(ret) == 1);
+ qobject_unref(ret);
+
+ compat_policy.has_deprecated_input = true;
+ compat_policy.deprecated_input = COMPAT_POLICY_INPUT_ACCEPT;
+ ret = qobject_to(QDict, do_qmp_dispatch(false, cmd));
+ assert(ret && qdict_size(ret) == 1);
+ qobject_unref(ret);
+
+ compat_policy.deprecated_input = COMPAT_POLICY_INPUT_REJECT;
+ do_qmp_dispatch_error(false, ERROR_CLASS_GENERIC_ERROR, cmd);
+}
+
static void test_dispatch_cmd_ret_deprecated(void)
{
const char *cmd = "{ 'execute': 'test-features0' }";
@@ -403,6 +426,8 @@ int main(int argc, char **argv)
test_dispatch_cmd_success_response);
g_test_add_func("/qmp/dispatch_cmd_deprecated",
test_dispatch_cmd_deprecated);
+ g_test_add_func("/qmp/dispatch_cmd_arg_deprecated",
+ test_dispatch_cmd_arg_deprecated);
g_test_add_func("/qmp/dispatch_cmd_ret_deprecated",
test_dispatch_cmd_ret_deprecated);
g_test_add_func("/qmp/dealloc_types", test_dealloc_types);