@@ -58,6 +58,15 @@ typedef struct QObjectInputVisitor QObjectInputVisitor;
*/
Visitor *qobject_input_visitor_new(QObject *obj);
+/*
+ * 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 input visitor for @obj for use with keyval_parse()
*
@@ -113,6 +113,9 @@ struct Visitor
The core takes care of the return type in the public interface. */
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);
@@ -459,6 +459,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?
*
@@ -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);
@@ -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;
@@ -666,6 +668,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);
@@ -700,6 +719,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);
@@ -722,6 +742,14 @@ Visitor *qobject_input_visitor_new(QObject *obj)
return &v->visitor;
}
+Visitor *qobject_input_visitor_new_qmp(QObject *obj)
+{
+ QObjectInputVisitor *v = to_qiv(qobject_input_visitor_new(obj));
+
+ v->deprecated_policy = compat_policy.deprecated_input;
+ return &v->visitor;
+}
+
Visitor *qobject_input_visitor_new_keyval(QObject *obj)
{
QObjectInputVisitor *v = qobject_input_visitor_base_new(obj);
@@ -299,6 +299,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' }";
@@ -399,6 +422,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);
@@ -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"
@@ -121,7 +121,7 @@ def gen_marshal(name, arg_type, boxed, ret_type):
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;
}
@@ -63,6 +63,9 @@ bool visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **errp)
push_indent()
if deprecated:
ret += mcgen('''
+ if (!visit_deprecated_accept(v, "%(name)s", errp)) {
+ return false;
+ }
if (visit_deprecated(v, "%(name)s")) {
''',
name=memb.name)
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> --- include/qapi/qobject-input-visitor.h | 9 +++++++++ include/qapi/visitor-impl.h | 3 +++ include/qapi/visitor.h | 9 +++++++++ qapi/qapi-visit-core.c | 9 +++++++++ qapi/qobject-input-visitor.c | 28 ++++++++++++++++++++++++++++ tests/test-qmp-cmds.c | 25 +++++++++++++++++++++++++ qapi/trace-events | 1 + scripts/qapi/commands.py | 2 +- scripts/qapi/visit.py | 3 +++ 9 files changed, 88 insertions(+), 1 deletion(-)