qapi: Move compat policy from QObject to generic visitor

The next commit needs to access compat policy from the generic visitor
core.  Move it there from qobject input and output visitor.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20211025042405.3762351-4-armbru@redhat.com>
This commit is contained in:
Markus Armbruster 2021-10-25 06:24:03 +02:00
parent b6c18755e4
commit ed29bb28f8
8 changed files with 25 additions and 36 deletions

View File

@ -15,7 +15,6 @@
#ifndef QOBJECT_INPUT_VISITOR_H
#define QOBJECT_INPUT_VISITOR_H
#include "qapi/qapi-types-compat.h"
#include "qapi/visitor.h"
typedef struct QObjectInputVisitor QObjectInputVisitor;
@ -59,9 +58,6 @@ 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()
*

View File

@ -15,7 +15,6 @@
#define QOBJECT_OUTPUT_VISITOR_H
#include "qapi/visitor.h"
#include "qapi/qapi-types-compat.h"
typedef struct QObjectOutputVisitor QObjectOutputVisitor;
@ -54,7 +53,4 @@ typedef struct QObjectOutputVisitor QObjectOutputVisitor;
*/
Visitor *qobject_output_visitor_new(QObject **result);
void qobject_output_visitor_set_policy(Visitor *v,
CompatPolicyOutput deprecated);
#endif

View File

@ -122,6 +122,9 @@ struct Visitor
/* Must be set */
VisitorType type;
/* Optional */
struct CompatPolicy compat_policy;
/* Must be set for output visitors, optional otherwise. */
void (*complete)(Visitor *v, void *opaque);

View File

@ -16,6 +16,7 @@
#define QAPI_VISITOR_H
#include "qapi/qapi-builtin-types.h"
#include "qapi/qapi-types-compat.h"
/*
* The QAPI schema defines both a set of C data types, and a QMP wire
@ -477,6 +478,14 @@ bool visit_deprecated_accept(Visitor *v, const char *name, Error **errp);
*/
bool visit_deprecated(Visitor *v, const char *name);
/*
* Set policy for handling deprecated management interfaces.
*
* Intended use: call visit_set_policy(v, &compat_policy) when
* visiting management interface input or output.
*/
void visit_set_policy(Visitor *v, CompatPolicy *policy);
/*
* Visit an enum value.
*

View File

@ -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;

View File

@ -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;
}

View File

@ -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);

View File

@ -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;
}