<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Oct 25, 2021 at 1:25 AM Markus Armbruster <<a href="mailto:armbru@redhat.com">armbru@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">The generated visitor functions call visit_deprecated_accept() and<br>
visit_deprecated() when visiting a struct member with special feature<br>
flag 'deprecated'.  This makes the feature flag visible to the actual<br>
visitors.  I want to make feature flag 'unstable' visible there as<br>
well, so I can add policy for it.<br>
<br>
To let me make it visible, replace these functions by<br>
visit_policy_reject() and visit_policy_skip(), which take the member's<br>
special features as an argument.  Note that the new functions have the<br>
opposite sense, i.e. the return value flips.<br>
<br>
Signed-off-by: Markus Armbruster <<a href="mailto:armbru@redhat.com" target="_blank">armbru@redhat.com</a>><br>
---<br>
 include/qapi/visitor-impl.h   |  6 ++++--<br>
 include/qapi/visitor.h        | 17 +++++++++++++----<br>
 qapi/qapi-forward-visitor.c   | 16 +++++++++-------<br>
 qapi/qapi-visit-core.c        | 22 ++++++++++++----------<br>
 qapi/qobject-input-visitor.c  | 15 ++++++++++-----<br>
 qapi/qobject-output-visitor.c |  9 ++++++---<br>
 qapi/trace-events             |  4 ++--<br>
 scripts/qapi/visit.py         | 14 +++++++-------<br>
 8 files changed, 63 insertions(+), 40 deletions(-)<br>
<br>
diff --git a/include/qapi/visitor-impl.h b/include/qapi/visitor-impl.h<br>
index 72b6537bef..2badec5ba4 100644<br>
--- a/include/qapi/visitor-impl.h<br>
+++ b/include/qapi/visitor-impl.h<br>
@@ -114,10 +114,12 @@ struct Visitor<br>
     void (*optional)(Visitor *v, const char *name, bool *present);<br>
<br>
     /* Optional */<br>
-    bool (*deprecated_accept)(Visitor *v, const char *name, Error **errp);<br>
+    bool (*policy_reject)(Visitor *v, const char *name,<br>
+                          unsigned special_features, Error **errp);<br>
<br>
     /* Optional */<br>
-    bool (*deprecated)(Visitor *v, const char *name);<br>
+    bool (*policy_skip)(Visitor *v, const char *name,<br>
+                        unsigned special_features);<br>
<br>
     /* Must be set */<br>
     VisitorType type;<br>
diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h<br>
index dcb96018a9..d53a84c9ba 100644<br>
--- a/include/qapi/visitor.h<br>
+++ b/include/qapi/visitor.h<br>
@@ -461,22 +461,31 @@ void visit_end_alternate(Visitor *v, void **obj);<br>
 bool visit_optional(Visitor *v, const char *name, bool *present);<br>
<br>
 /*<br>
- * Should we reject deprecated member @name?<br>
+ * Should we reject member @name due to policy?<br>
+ *<br>
+ * @special_features is the member's special features encoded as a<br>
+ * bitset of QapiSpecialFeature.<br>
  *<br>
  * @name must not be NULL.  This function is only useful between<br>
  * visit_start_struct() and visit_end_struct(), since only objects<br>
  * have deprecated members.<br>
  */<br>
-bool visit_deprecated_accept(Visitor *v, const char *name, Error **errp);<br>
+bool visit_policy_reject(Visitor *v, const char *name,<br>
+                         unsigned special_features, Error **errp);<br>
<br>
 /*<br>
- * Should we visit deprecated member @name?<br>
+ *<br>
+ * Should we skip member @name due to policy?<br>
+ *<br>
+ * @special_features is the member's special features encoded as a<br>
+ * bitset of QapiSpecialFeature.<br>
  *<br>
  * @name must not be NULL.  This function is only useful between<br>
  * visit_start_struct() and visit_end_struct(), since only objects<br>
  * have deprecated members.<br>
  */<br>
-bool visit_deprecated(Visitor *v, const char *name);<br>
+bool visit_policy_skip(Visitor *v, const char *name,<br>
+                       unsigned special_features);<br>
<br>
 /*<br>
  * Set policy for handling deprecated management interfaces.<br>
diff --git a/qapi/qapi-forward-visitor.c b/qapi/qapi-forward-visitor.c<br>
index a4b111e22a..25d098aa8a 100644<br>
--- a/qapi/qapi-forward-visitor.c<br>
+++ b/qapi/qapi-forward-visitor.c<br>
@@ -246,25 +246,27 @@ static void forward_field_optional(Visitor *v, const char *name, bool *present)<br>
     visit_optional(ffv->target, name, present);<br>
 }<br>
<br>
-static bool forward_field_deprecated_accept(Visitor *v, const char *name,<br>
-                                            Error **errp)<br>
+static bool forward_field_policy_reject(Visitor *v, const char *name,<br>
+                                        unsigned special_features,<br>
+                                        Error **errp)<br>
 {<br>
     ForwardFieldVisitor *ffv = to_ffv(v);<br>
<br>
     if (!forward_field_translate_name(ffv, &name, errp)) {<br>
         return false;<br>
     }<br>
-    return visit_deprecated_accept(ffv->target, name, errp);<br>
+    return visit_policy_reject(ffv->target, name, special_features, errp);<br>
 }<br>
<br>
-static bool forward_field_deprecated(Visitor *v, const char *name)<br>
+static bool forward_field_policy_skip(Visitor *v, const char *name,<br>
+                                      unsigned special_features)<br>
 {<br>
     ForwardFieldVisitor *ffv = to_ffv(v);<br>
<br>
     if (!forward_field_translate_name(ffv, &name, NULL)) {<br>
         return false;<br>
     }<br>
-    return visit_deprecated(ffv->target, name);<br>
+    return visit_policy_skip(ffv->target, name, special_features);<br>
 }<br>
<br>
 static void forward_field_complete(Visitor *v, void *opaque)<br>
@@ -313,8 +315,8 @@ Visitor *visitor_forward_field(Visitor *target, const char *from, const char *to<br>
     v->visitor.type_any = forward_field_type_any;<br>
     v->visitor.type_null = forward_field_type_null;<br>
     v->visitor.optional = forward_field_optional;<br>
-    v->visitor.deprecated_accept = forward_field_deprecated_accept;<br>
-    v->visitor.deprecated = forward_field_deprecated;<br>
+    v->visitor.policy_reject = forward_field_policy_reject;<br>
+    v->visitor.policy_skip = forward_field_policy_skip;<br>
     v->visitor.complete = forward_field_complete;<br>
     v->visitor.free = forward_field_free;<br>
<br>
diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c<br>
index 49136ae88e..b4a81f1757 100644<br>
--- a/qapi/qapi-visit-core.c<br>
+++ b/qapi/qapi-visit-core.c<br>
@@ -139,22 +139,24 @@ bool visit_optional(Visitor *v, const char *name, bool *present)<br>
     return *present;<br>
 }<br>
<br>
-bool visit_deprecated_accept(Visitor *v, const char *name, Error **errp)<br>
+bool visit_policy_reject(Visitor *v, const char *name,<br>
+                         unsigned special_features, Error **errp)<br>
 {<br>
-    trace_visit_deprecated_accept(v, name);<br>
-    if (v->deprecated_accept) {<br>
-        return v->deprecated_accept(v, name, errp);<br>
+    trace_visit_policy_reject(v, name);<br>
+    if (v->policy_reject) {<br>
+        return v->policy_reject(v, name, special_features, errp);<br>
     }<br>
-    return true;<br>
+    return false;<br>
 }<br>
<br>
-bool visit_deprecated(Visitor *v, const char *name)<br>
+bool visit_policy_skip(Visitor *v, const char *name,<br>
+                       unsigned special_features)<br>
 {<br>
-    trace_visit_deprecated(v, name);<br>
-    if (v->deprecated) {<br>
-        return v->deprecated(v, name);<br>
+    trace_visit_policy_skip(v, name);<br>
+    if (v->policy_skip) {<br>
+        return v->policy_skip(v, name, special_features);<br>
     }<br>
-    return true;<br>
+    return false;<br>
 }<br>
<br>
 void visit_set_policy(Visitor *v, CompatPolicy *policy)<br>
diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c<br>
index 71b24a4429..fda485614b 100644<br>
--- a/qapi/qobject-input-visitor.c<br>
+++ b/qapi/qobject-input-visitor.c<br>
@@ -662,16 +662,21 @@ static void qobject_input_optional(Visitor *v, const char *name, bool *present)<br>
     *present = true;<br>
 }<br>
<br>
-static bool qobject_input_deprecated_accept(Visitor *v, const char *name,<br>
-                                            Error **errp)<br>
+static bool qobject_input_policy_reject(Visitor *v, const char *name,<br>
+                                        unsigned special_features,<br>
+                                        Error **errp)<br>
 {<br>
+    if (!(special_features && 1u << QAPI_DEPRECATED)) {<br>
+        return false;<br>
+    }<br>
+<br>
     switch (v->compat_policy.deprecated_input) {<br>
     case COMPAT_POLICY_INPUT_ACCEPT:<br>
-        return true;<br>
+        return false;<br>
     case COMPAT_POLICY_INPUT_REJECT:<br>
         error_setg(errp, "Deprecated parameter '%s' disabled by policy",<br>
                    name);<br>
-        return false;<br>
+        return true;<br>
     case COMPAT_POLICY_INPUT_CRASH:<br>
     default:<br>
         abort();<br>
@@ -712,7 +717,7 @@ static QObjectInputVisitor *qobject_input_visitor_base_new(QObject *obj)<br>
     v->visitor.end_list = qobject_input_end_list;<br>
     v->visitor.start_alternate = qobject_input_start_alternate;<br>
     v->visitor.optional = qobject_input_optional;<br>
-    v->visitor.deprecated_accept = qobject_input_deprecated_accept;<br>
+    v->visitor.policy_reject = qobject_input_policy_reject;<br>
     v->visitor.free = qobject_input_free;<br>
<br>
     v->root = qobject_ref(obj);<br>
diff --git a/qapi/qobject-output-visitor.c b/qapi/qobject-output-visitor.c<br>
index 9b7f510036..b5c6564cbb 100644<br>
--- a/qapi/qobject-output-visitor.c<br>
+++ b/qapi/qobject-output-visitor.c<br>
@@ -13,6 +13,7 @@<br>
  */<br>
<br>
 #include "qemu/osdep.h"<br>
+#include "qapi/compat-policy.h"<br>
 #include "qapi/qobject-output-visitor.h"<br>
 #include "qapi/visitor-impl.h"<br>
 #include "qemu/queue.h"<br>
@@ -208,9 +209,11 @@ static bool qobject_output_type_null(Visitor *v, const char *name,<br>
     return true;<br>
 }<br>
<br>
-static bool qobject_output_deprecated(Visitor *v, const char *name)<br>
+static bool qobject_output_policy_skip(Visitor *v, const char *name,<br>
+                                       unsigned special_features)<br>
 {<br>
-    return v->compat_policy.deprecated_output != COMPAT_POLICY_OUTPUT_HIDE;<br>
+    return !(special_features && 1u << QAPI_DEPRECATED)<br>
+        || v->compat_policy.deprecated_output == COMPAT_POLICY_OUTPUT_HIDE;<br>
 }<br>
<br>
 /* Finish building, and return the root object.<br>
@@ -262,7 +265,7 @@ Visitor *qobject_output_visitor_new(QObject **result)<br>
     v->visitor.type_number = qobject_output_type_number;<br>
     v->visitor.type_any = qobject_output_type_any;<br>
     v->visitor.type_null = qobject_output_type_null;<br>
-    v->visitor.deprecated = qobject_output_deprecated;<br>
+    v->visitor.policy_skip = qobject_output_policy_skip;<br>
     v->visitor.complete = qobject_output_complete;<br>
     v->visitor.free = qobject_output_free;<br>
<br>
diff --git a/qapi/trace-events b/qapi/trace-events<br>
index cccafc07e5..ab108c4f0e 100644<br>
--- a/qapi/trace-events<br>
+++ b/qapi/trace-events<br>
@@ -17,8 +17,8 @@ visit_start_alternate(void *v, const char *name, void *obj, size_t size) "v=%p n<br>
 visit_end_alternate(void *v, void *obj) "v=%p obj=%p"<br>
<br>
 visit_optional(void *v, const char *name, bool *present) "v=%p name=%s present=%p"<br>
-visit_deprecated_accept(void *v, const char *name) "v=%p name=%s"<br>
-visit_deprecated(void *v, const char *name) "v=%p name=%s"<br>
+visit_policy_reject(void *v, const char *name) "v=%p name=%s"<br>
+visit_policy_skip(void *v, const char *name) "v=%p name=%s"<br>
<br>
 visit_type_enum(void *v, const char *name, int *obj) "v=%p name=%s obj=%p"<br>
 visit_type_int(void *v, const char *name, int64_t *obj) "v=%p name=%s obj=%p"<br>
diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py<br>
index 9d9196a143..e13bbe4292 100644<br>
--- a/scripts/qapi/visit.py<br>
+++ b/scripts/qapi/visit.py<br>
@@ -21,7 +21,7 @@<br>
     indent,<br>
     mcgen,<br>
 )<br>
-from .gen import QAPISchemaModularCVisitor, ifcontext<br>
+from .gen import QAPISchemaModularCVisitor, gen_special_features, ifcontext<br>
 from .schema import (<br>
     QAPISchema,<br>
     QAPISchemaEnumMember,<br>
@@ -76,7 +76,6 @@ def gen_visit_object_members(name: str,<br>
                      c_type=base.c_name())<br>
<br>
     for memb in members:<br>
-        deprecated = 'deprecated' in [<a href="http://f.name" rel="noreferrer" target="_blank">f.name</a> for f in memb.features]<br>
         ret += memb.ifcond.gen_if()<br>
         if memb.optional:<br>
             ret += mcgen('''<br>
@@ -84,14 +83,15 @@ def gen_visit_object_members(name: str,<br>
 ''',<br>
                          name=<a href="http://memb.name" rel="noreferrer" target="_blank">memb.name</a>, c_name=c_name(<a href="http://memb.name" rel="noreferrer" target="_blank">memb.name</a>))<br>
             indent.increase()<br>
-        if deprecated:<br>
+        special_features = gen_special_features(memb.features)<br>
+        if special_features != '0':<br></blockquote></div><div><br></div><div>Would it be possible for gen_special_features to return something false-y instead of '0'? Do we actually *use* the '0' return anywhere other than to test it to see if we should include additional code?</div><div><br></div><div>If you actually use the '0' anywhere: Go ahead and treat this as an ack. If you don't, can we clean this up?</div><div>(Sorry, I find the mcgen stuff hard to read in patch form and I am trying to give you a quick review instead of NO review.)<br></div><div><br></div><div>--js<br></div><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
             ret += mcgen('''<br>
-    if (!visit_deprecated_accept(v, "%(name)s", errp)) {<br>
+    if (visit_policy_reject(v, "%(name)s", %(special_features)s, errp)) {<br>
         return false;<br>
     }<br>
-    if (visit_deprecated(v, "%(name)s")) {<br>
+    if (!visit_policy_skip(v, "%(name)s", %(special_features)s)) {<br>
 ''',<br>
-                         name=<a href="http://memb.name" rel="noreferrer" target="_blank">memb.name</a>)<br>
+                         name=<a href="http://memb.name" rel="noreferrer" target="_blank">memb.name</a>, special_features=special_features)<br>
             indent.increase()<br>
         ret += mcgen('''<br>
     if (!visit_type_%(c_type)s(v, "%(name)s", &obj->%(c_name)s, errp)) {<br>
@@ -100,7 +100,7 @@ def gen_visit_object_members(name: str,<br>
 ''',<br>
                      c_type=memb.type.c_name(), name=<a href="http://memb.name" rel="noreferrer" target="_blank">memb.name</a>,<br>
                      c_name=c_name(<a href="http://memb.name" rel="noreferrer" target="_blank">memb.name</a>))<br>
-        if deprecated:<br>
+        if special_features != '0':<br>
             indent.decrease()<br>
             ret += mcgen('''<br>
     }<br>
-- <br>
2.31.1<br>
<br></blockquote><br><div><br></div></div></div>