All of lore.kernel.org
 help / color / mirror / Atom feed
* [PULL 0/5] QAPI patches patches for 2021-08-05
@ 2021-08-05 14:08 Markus Armbruster
  2021-08-05 14:08 ` [PULL 1/5] docs/devel/qapi-code-gen: Update examples to match current code Markus Armbruster
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Markus Armbruster @ 2021-08-05 14:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell

The following changes since commit cb2f4b8750b7e1c954570d19b104d4fdbeb8739a:

  Merge remote-tracking branch 'remotes/thuth-gitlab/tags/pull-request-2021-08-03' into staging (2021-08-03 19:50:43 +0100)

are available in the Git repository at:

  git://repo.or.cz/qemu/armbru.git tags/pull-qapi-2021-08-05

for you to fetch changes up to 68e6dc594a44a7077657f2ea878806e38dfa50cf:

  docs: convert writing-qmp-commands.txt to writing-qmp-commands.rst (2021-08-04 11:18:05 +0200)

----------------------------------------------------------------
QAPI patches patches for 2021-08-05

----------------------------------------------------------------
John Snow (4):
      docs: convert qapi-code-gen.txt to ReST
      docs/qapi-code-gen: Beautify formatting
      docs/qapi-code-gen: add cross-references
      docs: convert writing-qmp-commands.txt to writing-qmp-commands.rst

Markus Armbruster (1):
      docs/devel/qapi-code-gen: Update examples to match current code

 docs/devel/index.rst                               |   2 +
 .../devel/{qapi-code-gen.txt => qapi-code-gen.rst} | 823 ++++++++++++---------
 ...g-qmp-commands.txt => writing-qmp-commands.rst} | 567 +++++++-------
 3 files changed, 754 insertions(+), 638 deletions(-)
 rename docs/devel/{qapi-code-gen.txt => qapi-code-gen.rst} (75%)
 rename docs/devel/{writing-qmp-commands.txt => writing-qmp-commands.rst} (61%)

-- 
2.31.1



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PULL 1/5] docs/devel/qapi-code-gen: Update examples to match current code
  2021-08-05 14:08 [PULL 0/5] QAPI patches patches for 2021-08-05 Markus Armbruster
@ 2021-08-05 14:08 ` Markus Armbruster
  2021-08-05 14:08 ` [PULL 2/5] docs: convert qapi-code-gen.txt to ReST Markus Armbruster
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Markus Armbruster @ 2021-08-05 14:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, John Snow

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20210712150214.624281-1-armbru@redhat.com>
Acked-by: John Snow <jsnow@redhat.com>
---
 docs/devel/qapi-code-gen.txt | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt
index c1cb6f987d..233022184b 100644
--- a/docs/devel/qapi-code-gen.txt
+++ b/docs/devel/qapi-code-gen.txt
@@ -1496,8 +1496,12 @@ Example:
 
 
     bool visit_type_UserDefOne_members(Visitor *v, UserDefOne *obj, Error **errp);
-    bool visit_type_UserDefOne(Visitor *v, const char *name, UserDefOne **obj, Error **errp);
-    bool visit_type_UserDefOneList(Visitor *v, const char *name, UserDefOneList **obj, Error **errp);
+
+    bool visit_type_UserDefOne(Visitor *v, const char *name,
+                     UserDefOne **obj, Error **errp);
+
+    bool visit_type_UserDefOneList(Visitor *v, const char *name,
+                     UserDefOneList **obj, Error **errp);
 
     bool visit_type_q_obj_my_command_arg_members(Visitor *v, q_obj_my_command_arg *obj, Error **errp);
 
@@ -1518,7 +1522,8 @@ Example:
         return true;
     }
 
-    bool visit_type_UserDefOne(Visitor *v, const char *name, UserDefOne **obj, Error **errp)
+    bool visit_type_UserDefOne(Visitor *v, const char *name,
+                     UserDefOne **obj, Error **errp)
     {
         bool ok = false;
 
@@ -1528,6 +1533,7 @@ Example:
         if (!*obj) {
             /* incomplete */
             assert(visit_is_dealloc(v));
+            ok = true;
             goto out_obj;
         }
         if (!visit_type_UserDefOne_members(v, *obj, errp)) {
@@ -1543,7 +1549,8 @@ Example:
         return ok;
     }
 
-    bool visit_type_UserDefOneList(Visitor *v, const char *name, UserDefOneList **obj, Error **errp)
+    bool visit_type_UserDefOneList(Visitor *v, const char *name,
+                     UserDefOneList **obj, Error **errp)
     {
         bool ok = false;
         UserDefOneList *tail;
@@ -1628,11 +1635,13 @@ Example:
     $ cat qapi-generated/example-qapi-commands.c
 [Uninteresting stuff omitted...]
 
-    static void qmp_marshal_output_UserDefOne(UserDefOne *ret_in, QObject **ret_out, Error **errp)
+
+    static void qmp_marshal_output_UserDefOne(UserDefOne *ret_in,
+                                    QObject **ret_out, Error **errp)
     {
         Visitor *v;
 
-        v = qobject_output_visitor_new(ret_out);
+        v = qobject_output_visitor_new_qmp(ret_out);
         if (visit_type_UserDefOne(v, "unused", &ret_in, errp)) {
             visit_complete(v, ret_out);
         }
@@ -1650,7 +1659,7 @@ Example:
         UserDefOne *retval;
         q_obj_my_command_arg arg = {0};
 
-        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;
         }
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PULL 2/5] docs: convert qapi-code-gen.txt to ReST
  2021-08-05 14:08 [PULL 0/5] QAPI patches patches for 2021-08-05 Markus Armbruster
  2021-08-05 14:08 ` [PULL 1/5] docs/devel/qapi-code-gen: Update examples to match current code Markus Armbruster
@ 2021-08-05 14:08 ` Markus Armbruster
  2021-08-05 14:09 ` [PULL 3/5] docs/qapi-code-gen: Beautify formatting Markus Armbruster
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Markus Armbruster @ 2021-08-05 14:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, John Snow

From: John Snow <jsnow@redhat.com>

This is a very rudimentary conversion from .txt to .rst changing as
little as possible, but getting it to render somewhat nicely; without
using any Sphinx directives. (It is 'native' ReST.)

Further patches will add cross-references and Sphinx-specific extensions
to make it sparkle.

Signed-off-by: John Snow <jsnow@redhat.com>
Message-Id: <20210720235619.2048797-2-jsnow@redhat.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 docs/devel/index.rst                          |   1 +
 .../{qapi-code-gen.txt => qapi-code-gen.rst}  | 559 ++++++++++--------
 2 files changed, 312 insertions(+), 248 deletions(-)
 rename docs/devel/{qapi-code-gen.txt => qapi-code-gen.rst} (86%)

diff --git a/docs/devel/index.rst b/docs/devel/index.rst
index 153979caf4..bfba3a8daa 100644
--- a/docs/devel/index.rst
+++ b/docs/devel/index.rst
@@ -42,3 +42,4 @@ modifying QEMU's source code.
    multi-process
    ebpf_rss
    vfio-migration
+   qapi-code-gen
diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.rst
similarity index 86%
rename from docs/devel/qapi-code-gen.txt
rename to docs/devel/qapi-code-gen.rst
index 233022184b..9155dba262 100644
--- a/docs/devel/qapi-code-gen.txt
+++ b/docs/devel/qapi-code-gen.rst
@@ -1,12 +1,17 @@
-= How to use the QAPI code generator =
+==================================
+How to use the QAPI code generator
+==================================
 
-Copyright IBM Corp. 2011
-Copyright (C) 2012-2016 Red Hat, Inc.
+..
+   Copyright IBM Corp. 2011
+   Copyright (C) 2012-2016 Red Hat, Inc.
 
-This work is licensed under the terms of the GNU GPL, version 2 or
-later.  See the COPYING file in the top-level directory.
+   This work is licensed under the terms of the GNU GPL, version 2 or
+   later.  See the COPYING file in the top-level directory.
 
-== Introduction ==
+
+Introduction
+============
 
 QAPI is a native C API within QEMU which provides management-level
 functionality to internal and external users.  For external
@@ -23,7 +28,8 @@ Protocol and to C.  It additionally provides guidance on maintaining
 Client JSON Protocol compatibility.
 
 
-== The QAPI schema language ==
+The QAPI schema language
+========================
 
 The QAPI schema defines the Client JSON Protocol's commands and
 events, as well as types used by them.  Forward references are
@@ -39,9 +45,10 @@ complex types (structs and two flavors of unions), and alternate types
 (a choice between other types).
 
 
-=== Schema syntax ===
+Schema syntax
+-------------
 
-Syntax is loosely based on JSON (http://www.ietf.org/rfc/rfc8259.txt).
+Syntax is loosely based on `JSON <http://www.ietf.org/rfc/rfc8259.txt>`_.
 Differences:
 
 * Comments: start with a hash character (#) that is not part of a
@@ -79,7 +86,7 @@ syntax in an EBNF-like notation:
 The order of members within JSON objects does not matter unless
 explicitly noted.
 
-A QAPI schema consists of a series of top-level expressions:
+A QAPI schema consists of a series of top-level expressions::
 
     SCHEMA = TOP-LEVEL-EXPR...
 
@@ -87,11 +94,11 @@ The top-level expressions are all JSON objects.  Code and
 documentation is generated in schema definition order.  Code order
 should not matter.
 
-A top-level expressions is either a directive or a definition:
+A top-level expressions is either a directive or a definition::
 
     TOP-LEVEL-EXPR = DIRECTIVE | DEFINITION
 
-There are two kinds of directives and six kinds of definitions:
+There are two kinds of directives and six kinds of definitions::
 
     DIRECTIVE = INCLUDE | PRAGMA
     DEFINITION = ENUM | STRUCT | UNION | ALTERNATE | COMMAND | EVENT
@@ -99,9 +106,10 @@ There are two kinds of directives and six kinds of definitions:
 These are discussed in detail below.
 
 
-=== Built-in Types ===
+Built-in Types
+--------------
 
-The following types are predefined, and map to C as follows:
+The following types are predefined, and map to C as follows::
 
   Schema    C          JSON
   str       char *     any JSON string, UTF-8
@@ -124,12 +132,14 @@ The following types are predefined, and map to C as follows:
   QType     QType      JSON string matching enum QType values
 
 
-=== Include directives ===
+Include directives
+------------------
+
+Syntax::
 
-Syntax:
     INCLUDE = { 'include': STRING }
 
-The QAPI schema definitions can be modularized using the 'include' directive:
+The QAPI schema definitions can be modularized using the 'include' directive::
 
  { 'include': 'path/to/file.json' }
 
@@ -144,9 +154,11 @@ an outer file.  The parser may be made stricter in the future to
 prevent incomplete include files.
 
 
-=== Pragma directives ===
+Pragma directives
+-----------------
+
+Syntax::
 
-Syntax:
     PRAGMA = { 'pragma': {
                    '*doc-required': BOOL,
                    '*command-name-exceptions': [ STRING, ... ],
@@ -172,9 +184,11 @@ names may contain uppercase letters, and '_' instead of '-'.  Default
 is none.
 
 
-=== Enumeration types ===
+Enumeration types
+-----------------
+
+Syntax::
 
-Syntax:
     ENUM = { 'enum': STRING,
              'data': [ ENUM-VALUE, ... ],
              '*prefix': STRING,
@@ -189,7 +203,7 @@ Each member of the 'data' array defines a value of the enumeration
 type.  The form STRING is shorthand for { 'name': STRING }.  The
 'name' values must be be distinct.
 
-Example:
+Example::
 
  { 'enum': 'MyEnum', 'data': [ 'value1', 'value2', 'value3' ] }
 
@@ -218,9 +232,11 @@ The optional 'features' member specifies features.  See "Features"
 below for more on this.
 
 
-=== Type references and array types ===
+Type references and array types
+-------------------------------
+
+Syntax::
 
-Syntax:
     TYPE-REF = STRING | ARRAY-TYPE
     ARRAY-TYPE = [ STRING ]
 
@@ -230,9 +246,11 @@ A one-element array containing a string denotes an array of the type
 named by the string.  Example: ['int'] denotes an array of 'int'.
 
 
-=== Struct types ===
+Struct types
+------------
+
+Syntax::
 
-Syntax:
     STRUCT = { 'struct': STRING,
                'data': MEMBERS,
                '*base': STRING,
@@ -254,7 +272,7 @@ struct member name.  If '*' is present, the member is optional.
 The MEMBER's value defines its properties, in particular its type.
 The form TYPE-REF is shorthand for { 'type': TYPE-REF }.
 
-Example:
+Example::
 
  { 'struct': 'MyType',
    'data': { 'member1': 'str', 'member2': ['int'], '*member3': 'str' } }
@@ -265,7 +283,7 @@ The C struct's members are generated in QAPI schema order.
 The optional 'base' member names a struct type whose members are to be
 included in this type.  They go first in the C struct.
 
-Example:
+Example::
 
  { 'struct': 'BlockdevOptionsGenericFormat',
    'data': { 'file': 'str' } }
@@ -274,7 +292,7 @@ Example:
    'data': { '*backing': 'str' } }
 
 An example BlockdevOptionsGenericCOWFormat object on the wire could use
-both members like this:
+both members like this::
 
  { "file": "/some/place/my-image",
    "backing": "/some/place/my-backing-file" }
@@ -286,9 +304,11 @@ The optional 'features' member specifies features.  See "Features"
 below for more on this.
 
 
-=== Union types ===
+Union types
+-----------
+
+Syntax::
 
-Syntax:
     UNION = { 'union': STRING,
               'data': BRANCHES,
               '*if': COND,
@@ -317,7 +337,7 @@ The BRANCH's value defines the branch's properties, in particular its
 type.  The form TYPE-REF is shorthand for { 'type': TYPE-REF }.
 
 A simple union type defines a mapping from automatic discriminator
-values to data types like in this example:
+values to data types like in this example::
 
  { 'struct': 'BlockdevOptionsFile', 'data': { 'filename': 'str' } }
  { 'struct': 'BlockdevOptionsQcow2',
@@ -330,7 +350,7 @@ values to data types like in this example:
 In the Client JSON Protocol, a simple union is represented by an
 object that contains the 'type' member as a discriminator, and a
 'data' member that is of the specified data type corresponding to the
-discriminator value, as in these examples:
+discriminator value, as in these examples::
 
  { "type": "file", "data": { "filename": "/some/place/my-image" } }
  { "type": "qcow2", "data": { "backing": "/some/place/my-image",
@@ -361,7 +381,7 @@ struct.
 The following example enhances the above simple union example by
 adding an optional common member 'read-only', renaming the
 discriminator to something more applicable than the simple union's
-default of 'type', and reducing the number of {} required on the wire:
+default of 'type', and reducing the number of {} required on the wire::
 
  { 'enum': 'BlockdevDriver', 'data': [ 'file', 'qcow2' ] }
  { 'union': 'BlockdevOptions',
@@ -370,7 +390,7 @@ default of 'type', and reducing the number of {} required on the wire:
    'data': { 'file': 'BlockdevOptionsFile',
              'qcow2': 'BlockdevOptionsQcow2' } }
 
-Resulting in these JSON objects:
+Resulting in these JSON objects::
 
  { "driver": "file", "read-only": true,
    "filename": "/some/place/my-image" }
@@ -390,11 +410,11 @@ struct.
 
 A simple union can always be re-written as a flat union where the base
 class has a single member named 'type', and where each branch of the
-union has a struct with a single member named 'data'.  That is,
+union has a struct with a single member named 'data'.  That is, ::
 
  { 'union': 'Simple', 'data': { 'one': 'str', 'two': 'int' } }
 
-is identical on the wire to:
+is identical on the wire to::
 
  { 'enum': 'Enum', 'data': ['one', 'two'] }
  { 'struct': 'Branch1', 'data': { 'data': 'str' } }
@@ -409,9 +429,11 @@ The optional 'features' member specifies features.  See "Features"
 below for more on this.
 
 
-=== Alternate types ===
+Alternate types
+---------------
+
+Syntax::
 
-Syntax:
     ALTERNATE = { 'alternate': STRING,
                   'data': ALTERNATIVES,
                   '*if': COND,
@@ -430,7 +452,7 @@ The ALTERNATIVE's STRING name is the branch name.
 The ALTERNATIVE's value defines the branch's properties, in particular
 its type.  The form STRING is shorthand for { 'type': STRING }.
 
-Example:
+Example::
 
  { 'alternate': 'BlockdevRef',
    'data': { 'definition': 'BlockdevOptions',
@@ -449,7 +471,7 @@ as the 'null' built-in, it accepts JSON null; and if it is typed as a
 complex type (struct or union), it accepts a JSON object.
 
 The example alternate declaration above allows using both of the
-following example objects:
+following example objects::
 
  { "file": "my_existing_block_device_id" }
  { "file": { "driver": "file",
@@ -463,9 +485,11 @@ The optional 'features' member specifies features.  See "Features"
 below for more on this.
 
 
-=== Commands ===
+Commands
+--------
+
+Syntax::
 
-Syntax:
     COMMAND = { 'command': STRING,
                 (
                 '*data': ( MEMBERS | STRING ),
@@ -508,7 +532,7 @@ member is the command name.  The value of the "arguments" member then
 has to conform to the arguments, and the value of the success
 response's "return" member will conform to the return type.
 
-Some example commands:
+Some example commands::
 
  { 'command': 'my-first-command',
    'data': { 'arg1': 'str', '*arg2': 'str' } }
@@ -516,7 +540,7 @@ Some example commands:
  { 'command': 'my-second-command',
    'returns': [ 'MyType' ] }
 
-which would validate this Client JSON Protocol transaction:
+which would validate this Client JSON Protocol transaction::
 
  => { "execute": "my-first-command",
       "arguments": { "arg1": "hello" } }
@@ -543,7 +567,7 @@ In rare cases, QAPI cannot express a type-safe representation of a
 corresponding Client JSON Protocol command.  You then have to suppress
 generation of a marshalling function by including a member 'gen' with
 boolean value false, and instead write your own function.  For
-example:
+example::
 
  { 'command': 'netdev_add',
    'data': {'type': 'str', 'id': 'str'},
@@ -561,7 +585,7 @@ the command definition includes the optional member 'success-response'
 with boolean value false.  So far, only QGA makes use of this member.
 
 Member 'allow-oob' declares whether the command supports out-of-band
-(OOB) execution.  It defaults to false.  For example:
+(OOB) execution.  It defaults to false.  For example::
 
  { 'command': 'migrate_recover',
    'data': { 'uri': 'str' }, 'allow-oob': true }
@@ -594,7 +618,7 @@ other "slow" lock.
 When in doubt, do not implement OOB execution support.
 
 Member 'allow-preconfig' declares whether the command is available
-before the machine is built.  It defaults to false.  For example:
+before the machine is built.  It defaults to false.  For example::
 
  { 'enum': 'QMPCapability',
    'data': [ 'oob' ] }
@@ -640,9 +664,11 @@ The optional 'features' member specifies features.  See "Features"
 below for more on this.
 
 
-=== Events ===
+Events
+------
+
+Syntax::
 
-Syntax:
     EVENT = { 'event': STRING,
               (
               '*data': ( MEMBERS | STRING ),
@@ -665,16 +691,16 @@ data just like a struct type's 'data' defines struct type members.
 If 'data' is a STRING, then STRING names a complex type whose members
 are the event-specific data.  A union type requires 'boxed': true.
 
-An example event is:
+An example event is::
 
-{ 'event': 'EVENT_C',
-  'data': { '*a': 'int', 'b': 'str' } }
+ { 'event': 'EVENT_C',
+   'data': { '*a': 'int', 'b': 'str' } }
 
-Resulting in this JSON object:
+Resulting in this JSON object::
 
-{ "event": "EVENT_C",
-  "data": { "b": "test string" },
-  "timestamp": { "seconds": 1267020223, "microseconds": 435656 } }
+ { "event": "EVENT_C",
+   "data": { "b": "test string" },
+   "timestamp": { "seconds": 1267020223, "microseconds": 435656 } }
 
 The generator emits a function to send the event.  When member 'boxed'
 is absent, it takes event-specific data one by one, in QAPI schema
@@ -688,9 +714,11 @@ The optional 'features' member specifies features.  See "Features"
 below for more on this.
 
 
-=== Features ===
+Features
+--------
+
+Syntax::
 
-Syntax:
     FEATURES = [ FEATURE, ... ]
     FEATURE = STRING
             | { 'name': STRING, '*if': COND }
@@ -701,17 +729,17 @@ that previously resulted in an error).  QMP clients may still need to
 know whether the extension is available.
 
 For this purpose, a list of features can be specified for a command or
-struct type.  Each list member can either be { 'name': STRING, '*if':
-COND }, or STRING, which is shorthand for { 'name': STRING }.
+struct type.  Each list member can either be ``{ 'name': STRING, '*if':
+COND }``, or STRING, which is shorthand for ``{ 'name': STRING }``.
 
 The optional 'if' member specifies a conditional.  See "Configuring
 the schema" below for more on this.
 
-Example:
+Example::
 
-{ 'struct': 'TestType',
-  'data': { 'number': 'int' },
-  'features': [ 'allow-negative-numbers' ] }
+ { 'struct': 'TestType',
+   'data': { 'number': 'int' },
+   'features': [ 'allow-negative-numbers' ] }
 
 The feature strings are exposed to clients in introspection, as
 explained in section "Client JSON Protocol introspection".
@@ -720,20 +748,22 @@ Intended use is to have each feature string signal that this build of
 QEMU shows a certain behaviour.
 
 
-==== Special features ====
+Special features
+~~~~~~~~~~~~~~~~
 
 Feature "deprecated" marks a command, event, or struct member as
 deprecated.  It is not supported elsewhere so far.
 
 
-=== Naming rules and reserved names ===
+Naming rules and reserved names
+-------------------------------
 
 All names must begin with a letter, and contain only ASCII letters,
 digits, hyphen, and underscore.  There are two exceptions: enum values
 may start with a digit, and names that are downstream extensions (see
 section Downstream extensions) start with underscore.
 
-Names beginning with 'q_' are reserved for the generator, which uses
+Names beginning with 'q\_' are reserved for the generator, which uses
 them for munging QMP names that resemble C keywords or other
 problematic strings.  For example, a member named "default" in qapi
 becomes "q_default" in the generated C code.
@@ -753,7 +783,7 @@ consistency is preferred over blindly avoiding underscore.
 
 Event names should be ALL_CAPS with words separated by underscore.
 
-Member name 'u' and names starting with 'has-' or 'has_' are reserved
+Member name 'u' and names starting with 'has-' or 'has\_' are reserved
 for the generator, which uses them for unions and for tracking
 optional members.
 
@@ -765,7 +795,8 @@ Pragmas 'command-name-exceptions' and 'member-name-exceptions' let you
 violate naming rules.  Use for new code is strongly discouraged.
 
 
-=== Downstream extensions ===
+Downstream extensions
+---------------------
 
 QAPI schema names that are externally visible, say in the Client JSON
 Protocol, need to be managed with care.  Names starting with a
@@ -777,9 +808,11 @@ Example: Red Hat, Inc. controls redhat.com, and may therefore add a
 downstream command __com.redhat_drive-mirror.
 
 
-=== Configuring the schema ===
+Configuring the schema
+----------------------
+
+Syntax::
 
-Syntax:
     COND = STRING
          | [ STRING, ... ]
 
@@ -788,12 +821,12 @@ string or a list of strings.  A string is shorthand for a list
 containing just that string.  The code generated for the definition
 will then be guarded by #if STRING for each STRING in the COND list.
 
-Example: a conditional struct
+Example: a conditional struct ::
 
  { 'struct': 'IfStruct', 'data': { 'foo': 'int' },
    'if': ['defined(CONFIG_FOO)', 'defined(HAVE_BAR)'] }
 
-gets its generated code guarded like this:
+gets its generated code guarded like this::
 
  #if defined(CONFIG_FOO)
  #if defined(HAVE_BAR)
@@ -806,11 +839,11 @@ event-specific data can also be made conditional.  This requires the
 longhand form of MEMBER.
 
 Example: a struct type with unconditional member 'foo' and conditional
-member 'bar'
+member 'bar' ::
 
-{ 'struct': 'IfStruct', 'data':
-  { 'foo': 'int',
-    'bar': { 'type': 'int', 'if': 'defined(IFCOND)'} } }
+ { 'struct': 'IfStruct', 'data':
+   { 'foo': 'int',
+     'bar': { 'type': 'int', 'if': 'defined(IFCOND)'} } }
 
 A union's discriminator may not be conditional.
 
@@ -818,21 +851,21 @@ Likewise, individual enumeration values be conditional.  This requires
 the longhand form of ENUM-VALUE.
 
 Example: an enum type with unconditional value 'foo' and conditional
-value 'bar'
+value 'bar' ::
 
-{ 'enum': 'IfEnum', 'data':
-  [ 'foo',
-    { 'name' : 'bar', 'if': 'defined(IFCOND)' } ] }
+ { 'enum': 'IfEnum', 'data':
+   [ 'foo',
+     { 'name' : 'bar', 'if': 'defined(IFCOND)' } ] }
 
 Likewise, features can be conditional.  This requires the longhand
 form of FEATURE.
 
-Example: a struct with conditional feature 'allow-negative-numbers'
+Example: a struct with conditional feature 'allow-negative-numbers' ::
 
-{ 'struct': 'TestType',
-  'data': { 'number': 'int' },
-  'features': [ { 'name': 'allow-negative-numbers',
-                  'if': 'defined(IFCOND)' } ] }
+ { 'struct': 'TestType',
+   'data': { 'number': 'int' },
+   'features': [ { 'name': 'allow-negative-numbers',
+                   'if': 'defined(IFCOND)' } ] }
 
 Please note that you are responsible to ensure that the C code will
 compile with an arbitrary combination of conditions, since the
@@ -843,12 +876,13 @@ shows a conditional entity only when the condition is satisfied in
 this particular build.
 
 
-=== Documentation comments ===
+Documentation comments
+----------------------
 
 A multi-line comment that starts and ends with a '##' line is a
 documentation comment.
 
-If the documentation comment starts like
+If the documentation comment starts like ::
 
     ##
     # @SYMBOL:
@@ -861,10 +895,12 @@ See below for more on definition documentation.
 Free-form documentation may be used to provide additional text and
 structuring content.
 
-==== Headings and subheadings ====
+
+Headings and subheadings
+~~~~~~~~~~~~~~~~~~~~~~~~
 
 A free-form documentation comment containing a line which starts with
-some '=' symbols and then a space defines a section heading:
+some '=' symbols and then a space defines a section heading::
 
     ##
     # = This is a top level heading
@@ -883,17 +919,19 @@ comment block.
 Section headings must always be correctly nested, so you can only
 define a third-level heading inside a second-level heading, and so on.
 
-==== Documentation markup ====
+
+Documentation markup
+~~~~~~~~~~~~~~~~~~~~
 
 Documentation comments can use most rST markup.  In particular,
-a '::' literal block can be used for examples:
+a '::' literal block can be used for examples::
 
     # ::
     #
     #   Text of the example, may span
     #   multiple lines
 
-'*' starts an itemized list:
+'*' starts an itemized list::
 
     # * First item, may span
     #   multiple lines
@@ -901,7 +939,7 @@ a '::' literal block can be used for examples:
 
 You can also use '-' instead of '*'.
 
-A decimal number followed by '.' starts a numbered list:
+A decimal number followed by '.' starts a numbered list::
 
     # 1. First item, may span
     #    multiple lines
@@ -920,24 +958,25 @@ backslash-escape it.  As an extension beyond the usual rST syntax, you
 can also use '@foo' to reference a name in the schema; this is
 rendered the same way as '``foo``'.
 
-Example:
+Example::
 
-##
-# Some text foo with **bold** and *emphasis*
-# 1. with a list
-# 2. like that
-#
-# And some code:
-#
-# ::
-#
-#   $ echo foo
-#   -> do this
-#   <- get that
-##
+ ##
+ # Some text foo with **bold** and *emphasis*
+ # 1. with a list
+ # 2. like that
+ #
+ # And some code:
+ #
+ # ::
+ #
+ #   $ echo foo
+ #   -> do this
+ #   <- get that
+ ##
 
 
-==== Definition documentation ====
+Definition documentation
+~~~~~~~~~~~~~~~~~~~~~~~~
 
 Definition documentation, if present, must immediately precede the
 definition it documents.
@@ -956,14 +995,14 @@ text can start on the line following the '@argname:', in which case it
 must not be indented at all.  It can also start on the same line as
 the '@argname:'.  In this case if it spans multiple lines then second
 and subsequent lines must be indented to line up with the first
-character of the first line of the description:
+character of the first line of the description::
 
-# @argone:
-# This is a two line description
-# in the first style.
-#
-# @argtwo: This is a two line description
-#          in the second style.
+ # @argone:
+ # This is a two line description
+ # in the first style.
+ #
+ # @argtwo: This is a two line description
+ #          in the second style.
 
 The number of spaces between the ':' and the text is not significant.
 
@@ -997,52 +1036,53 @@ An 'Example' or 'Examples' section is automatically rendered
 entirely as literal fixed-width text.  In other sections,
 the text is formatted, and rST markup can be used.
 
-For example:
+For example::
 
-##
-# @BlockStats:
-#
-# Statistics of a virtual block device or a block backing device.
-#
-# @device: If the stats are for a virtual block device, the name
-#          corresponding to the virtual block device.
-#
-# @node-name: The node name of the device. (since 2.3)
-#
-# ... more members ...
-#
-# Since: 0.14.0
-##
-{ 'struct': 'BlockStats',
-  'data': {'*device': 'str', '*node-name': 'str',
-           ... more members ... } }
+ ##
+ # @BlockStats:
+ #
+ # Statistics of a virtual block device or a block backing device.
+ #
+ # @device: If the stats are for a virtual block device, the name
+ #          corresponding to the virtual block device.
+ #
+ # @node-name: The node name of the device. (since 2.3)
+ #
+ # ... more members ...
+ #
+ # Since: 0.14.0
+ ##
+ { 'struct': 'BlockStats',
+   'data': {'*device': 'str', '*node-name': 'str',
+            ... more members ... } }
 
-##
-# @query-blockstats:
-#
-# Query the @BlockStats for all virtual block devices.
-#
-# @query-nodes: If true, the command will query all the
-#               block nodes ... explain, explain ...  (since 2.3)
-#
-# Returns: A list of @BlockStats for each virtual block devices.
-#
-# Since: 0.14.0
-#
-# Example:
-#
-# -> { "execute": "query-blockstats" }
-# <- {
-#      ... lots of output ...
-#    }
-#
-##
-{ 'command': 'query-blockstats',
-  'data': { '*query-nodes': 'bool' },
-  'returns': ['BlockStats'] }
+ ##
+ # @query-blockstats:
+ #
+ # Query the @BlockStats for all virtual block devices.
+ #
+ # @query-nodes: If true, the command will query all the
+ #               block nodes ... explain, explain ...  (since 2.3)
+ #
+ # Returns: A list of @BlockStats for each virtual block devices.
+ #
+ # Since: 0.14.0
+ #
+ # Example:
+ #
+ # -> { "execute": "query-blockstats" }
+ # <- {
+ #      ... lots of output ...
+ #    }
+ #
+ ##
+ { 'command': 'query-blockstats',
+   'data': { '*query-nodes': 'bool' },
+   'returns': ['BlockStats'] }
 
 
-== Client JSON Protocol introspection ==
+Client JSON Protocol introspection
+==================================
 
 Clients of a Client JSON Protocol commonly need to figure out what
 exactly the server (QEMU) supports.
@@ -1114,13 +1154,13 @@ If the command takes no arguments, "arg-type" names an object type
 without members.  Likewise, if the command returns nothing, "ret-type"
 names an object type without members.
 
-Example: the SchemaInfo for command query-qmp-schema
+Example: the SchemaInfo for command query-qmp-schema ::
 
-    { "name": "query-qmp-schema", "meta-type": "command",
-      "arg-type": "q_empty", "ret-type": "SchemaInfoList" }
+ { "name": "query-qmp-schema", "meta-type": "command",
+   "arg-type": "q_empty", "ret-type": "SchemaInfoList" }
 
-    Type "q_empty" is an automatic object type without members, and type
-    "SchemaInfoList" is the array of SchemaInfo type.
+   Type "q_empty" is an automatic object type without members, and type
+   "SchemaInfoList" is the array of SchemaInfo type.
 
 The SchemaInfo for an event has meta-type "event", and variant member
 "arg-type".  On the wire, a "data" member that the server passes in an
@@ -1133,7 +1173,7 @@ the wire then.
 Each command or event defined with 'data' as MEMBERS object in the
 QAPI schema implicitly defines an object type.
 
-Example: the SchemaInfo for EVENT_C from section Events
+Example: the SchemaInfo for EVENT_C from section Events ::
 
     { "name": "EVENT_C", "meta-type": "event",
       "arg-type": "q_obj-EVENT_C-arg" }
@@ -1157,7 +1197,7 @@ extensions.  The "members" array is in no particular order; clients
 must search the entire object when learning whether a particular
 member is supported.
 
-Example: the SchemaInfo for MyType from section Struct types
+Example: the SchemaInfo for MyType from section Struct types ::
 
     { "name": "MyType", "meta-type": "object",
       "members": [
@@ -1168,7 +1208,7 @@ Example: the SchemaInfo for MyType from section Struct types
 "features" exposes the command's feature strings as a JSON array of
 strings.
 
-Example: the SchemaInfo for TestType from section Features:
+Example: the SchemaInfo for TestType from section Features::
 
     { "name": "TestType", "meta-type": "object",
       "members": [
@@ -1184,7 +1224,7 @@ that provides the variant members for this type tag value).  The
 list cases in the same order as the corresponding "tag" enum type.
 
 Example: the SchemaInfo for flat union BlockdevOptions from section
-Union types
+Union types ::
 
     { "name": "BlockdevOptions", "meta-type": "object",
       "members": [
@@ -1205,7 +1245,7 @@ A simple union implicitly defines an object type for each of its
 variants.
 
 Example: the SchemaInfo for simple union BlockdevOptionsSimple from section
-Union types
+Union types ::
 
     { "name": "BlockdevOptionsSimple", "meta-type": "object",
       "members": [
@@ -1225,7 +1265,7 @@ a JSON object with member "type", which names a type.  Values of the
 alternate type conform to exactly one of its member types.  There is
 no guarantee on the order in which "members" will be listed.
 
-Example: the SchemaInfo for BlockdevRef from section Alternate types
+Example: the SchemaInfo for BlockdevRef from section Alternate types ::
 
     { "name": "BlockdevRef", "meta-type": "alternate",
       "members": [
@@ -1239,7 +1279,7 @@ resemble the element type; however, clients should examine member
 "element-type" instead of making assumptions based on parsing member
 "name".
 
-Example: the SchemaInfo for ['str']
+Example: the SchemaInfo for ['str'] ::
 
     { "name": "[str]", "meta-type": "array",
       "element-type": "str" }
@@ -1249,7 +1289,7 @@ variant member "values".  The values are listed in no particular
 order; clients must search the entire enum when learning whether a
 particular value is supported.
 
-Example: the SchemaInfo for MyEnum from section Enumeration types
+Example: the SchemaInfo for MyEnum from section Enumeration types ::
 
     { "name": "MyEnum", "meta-type": "enum",
       "values": [ "value1", "value2", "value3" ] }
@@ -1259,7 +1299,7 @@ the QAPI schema (see section Built-in Types), with one exception
 detailed below.  It has variant member "json-type" that shows how
 values of this type are encoded on the wire.
 
-Example: the SchemaInfo for str
+Example: the SchemaInfo for str ::
 
     { "name": "str", "meta-type": "builtin", "json-type": "string" }
 
@@ -1273,7 +1313,8 @@ the names of built-in types.  Clients should examine member
 "json-type" instead of hard-coding names of built-in types.
 
 
-== Compatibility considerations ==
+Compatibility considerations
+============================
 
 Maintaining backward compatibility at the Client JSON Protocol level
 while evolving the schema requires some care.  This section is about
@@ -1333,7 +1374,8 @@ may be freely renamed.  Even certain refactorings are invisible, such
 as splitting members from one type into a common base type.
 
 
-== Code generation ==
+Code generation
+===============
 
 The QAPI code generator qapi-gen.py generates code and documentation
 from the schema.  Together with the core QAPI libraries, this code
@@ -1347,7 +1389,7 @@ As an example, we'll use the following schema, which describes a
 single complex user-defined type, along with command which takes a
 list of that type as a parameter, and returns a single element of that
 type.  The user is responsible for writing the implementation of
-qmp_my_command(); everything else is produced by the generator.
+qmp_my_command(); everything else is produced by the generator. ::
 
     $ cat example-schema.json
     { 'struct': 'UserDefOne',
@@ -1359,7 +1401,7 @@ qmp_my_command(); everything else is produced by the generator.
 
     { 'event': 'MY_EVENT' }
 
-We run qapi-gen.py like this:
+We run qapi-gen.py like this::
 
     $ python scripts/qapi-gen.py --output-dir="qapi-generated" \
     --prefix="example-" example-schema.json
@@ -1369,24 +1411,27 @@ tests/qapi-schema/qapi-schema-tests.json that covers more examples of
 what the generator will accept, and compiles the resulting C code as
 part of 'make check-unit'.
 
-=== Code generated for QAPI types ===
+
+Code generated for QAPI types
+-----------------------------
 
 The following files are created:
 
-$(prefix)qapi-types.h - C types corresponding to types defined in
-                        the schema
+ ``$(prefix)qapi-types.h``
+     C types corresponding to types defined in the schema
 
-$(prefix)qapi-types.c - Cleanup functions for the above C types
+ ``$(prefix)qapi-types.c``
+     Cleanup functions for the above C types
 
 The $(prefix) is an optional parameter used as a namespace to keep the
 generated code from one schema/code-generation separated from others so code
 can be generated/used from multiple schemas without clobbering previously
 created code.
 
-Example:
+Example::
 
     $ cat qapi-generated/example-qapi-types.h
-[Uninteresting stuff omitted...]
+    [Uninteresting stuff omitted...]
 
     #ifndef EXAMPLE_QAPI_TYPES_H
     #define EXAMPLE_QAPI_TYPES_H
@@ -1422,7 +1467,7 @@ Example:
 
     #endif /* EXAMPLE_QAPI_TYPES_H */
     $ cat qapi-generated/example-qapi-types.c
-[Uninteresting stuff omitted...]
+    [Uninteresting stuff omitted...]
 
     void qapi_free_UserDefOne(UserDefOne *obj)
     {
@@ -1450,22 +1495,26 @@ Example:
         visit_free(v);
     }
 
-[Uninteresting stuff omitted...]
+    [Uninteresting stuff omitted...]
 
 For a modular QAPI schema (see section Include directives), code for
-each sub-module SUBDIR/SUBMODULE.json is actually generated into
+each sub-module SUBDIR/SUBMODULE.json is actually generated into ::
 
-SUBDIR/$(prefix)qapi-types-SUBMODULE.h
-SUBDIR/$(prefix)qapi-types-SUBMODULE.c
+ SUBDIR/$(prefix)qapi-types-SUBMODULE.h
+ SUBDIR/$(prefix)qapi-types-SUBMODULE.c
 
 If qapi-gen.py is run with option --builtins, additional files are
 created:
 
-qapi-builtin-types.h - C types corresponding to built-in types
+ ``qapi-builtin-types.h``
+     C types corresponding to built-in types
 
-qapi-builtin-types.c - Cleanup functions for the above C types
+ ``qapi-builtin-types.c``
+     Cleanup functions for the above C types
 
-=== Code generated for visiting QAPI types ===
+
+Code generated for visiting QAPI types
+--------------------------------------
 
 These are the visitor functions used to walk through and convert
 between a native QAPI C data structure and some other format (such as
@@ -1474,19 +1523,18 @@ visit_type_FOO_members().
 
 The following files are generated:
 
-$(prefix)qapi-visit.c: Visitor function for a particular C type, used
-                       to automagically convert QObjects into the
-                       corresponding C type and vice-versa, as well
-                       as for deallocating memory for an existing C
-                       type
+ ``$(prefix)qapi-visit.c``
+     Visitor function for a particular C type, used to automagically
+     convert QObjects into the corresponding C type and vice-versa, as
+     well as for deallocating memory for an existing C type
 
-$(prefix)qapi-visit.h: Declarations for previously mentioned visitor
-                       functions
+ ``$(prefix)qapi-visit.h``
+     Declarations for previously mentioned visitor functions
 
-Example:
+Example::
 
     $ cat qapi-generated/example-qapi-visit.h
-[Uninteresting stuff omitted...]
+    [Uninteresting stuff omitted...]
 
     #ifndef EXAMPLE_QAPI_VISIT_H
     #define EXAMPLE_QAPI_VISIT_H
@@ -1507,7 +1555,7 @@ Example:
 
     #endif /* EXAMPLE_QAPI_VISIT_H */
     $ cat qapi-generated/example-qapi-visit.c
-[Uninteresting stuff omitted...]
+    [Uninteresting stuff omitted...]
 
     bool visit_type_UserDefOne_members(Visitor *v, UserDefOne *obj, Error **errp)
     {
@@ -1585,22 +1633,26 @@ Example:
         return true;
     }
 
-[Uninteresting stuff omitted...]
+    [Uninteresting stuff omitted...]
 
 For a modular QAPI schema (see section Include directives), code for
-each sub-module SUBDIR/SUBMODULE.json is actually generated into
+each sub-module SUBDIR/SUBMODULE.json is actually generated into ::
 
-SUBDIR/$(prefix)qapi-visit-SUBMODULE.h
-SUBDIR/$(prefix)qapi-visit-SUBMODULE.c
+ SUBDIR/$(prefix)qapi-visit-SUBMODULE.h
+ SUBDIR/$(prefix)qapi-visit-SUBMODULE.c
 
 If qapi-gen.py is run with option --builtins, additional files are
 created:
 
-qapi-builtin-visit.h - Visitor functions for built-in types
+ ``qapi-builtin-visit.h``
+     Visitor functions for built-in types
 
-qapi-builtin-visit.c - Declarations for these visitor functions
+ ``qapi-builtin-visit.c``
+     Declarations for these visitor functions
 
-=== Code generated for commands ===
+
+Code generated for commands
+---------------------------
 
 These are the marshaling/dispatch functions for the commands defined
 in the schema.  The generated code provides qmp_marshal_COMMAND(), and
@@ -1608,20 +1660,23 @@ declares qmp_COMMAND() that the user must implement.
 
 The following files are generated:
 
-$(prefix)qapi-commands.c: Command marshal/dispatch functions for each
-                          QMP command defined in the schema
+ ``$(prefix)qapi-commands.c``
+     Command marshal/dispatch functions for each QMP command defined in
+     the schema
 
-$(prefix)qapi-commands.h: Function prototypes for the QMP commands
-                          specified in the schema
+ ``$(prefix)qapi-commands.h``
+     Function prototypes for the QMP commands specified in the schema
 
-$(prefix)qapi-init-commands.h - Command initialization prototype
+ ``$(prefix)qapi-init-commands.h``
+     Command initialization prototype
 
-$(prefix)qapi-init-commands.c - Command initialization code
+ ``$(prefix)qapi-init-commands.c``
+     Command initialization code
 
-Example:
+Example::
 
     $ cat qapi-generated/example-qapi-commands.h
-[Uninteresting stuff omitted...]
+    [Uninteresting stuff omitted...]
 
     #ifndef EXAMPLE_QAPI_COMMANDS_H
     #define EXAMPLE_QAPI_COMMANDS_H
@@ -1633,7 +1688,7 @@ Example:
 
     #endif /* EXAMPLE_QAPI_COMMANDS_H */
     $ cat qapi-generated/example-qapi-commands.c
-[Uninteresting stuff omitted...]
+    [Uninteresting stuff omitted...]
 
 
     static void qmp_marshal_output_UserDefOne(UserDefOne *ret_in,
@@ -1688,9 +1743,9 @@ Example:
         visit_free(v);
     }
 
-[Uninteresting stuff omitted...]
+    [Uninteresting stuff omitted...]
     $ cat qapi-generated/example-qapi-init-commands.h
-[Uninteresting stuff omitted...]
+    [Uninteresting stuff omitted...]
     #ifndef EXAMPLE_QAPI_INIT_COMMANDS_H
     #define EXAMPLE_QAPI_INIT_COMMANDS_H
 
@@ -1700,7 +1755,7 @@ Example:
 
     #endif /* EXAMPLE_QAPI_INIT_COMMANDS_H */
     $ cat qapi-generated/example-qapi-init-commands.c
-[Uninteresting stuff omitted...]
+    [Uninteresting stuff omitted...]
     void example_qmp_init_marshal(QmpCommandList *cmds)
     {
         QTAILQ_INIT(cmds);
@@ -1708,34 +1763,39 @@ Example:
         qmp_register_command(cmds, "my-command",
                              qmp_marshal_my_command, QCO_NO_OPTIONS);
     }
-[Uninteresting stuff omitted...]
+    [Uninteresting stuff omitted...]
 
 For a modular QAPI schema (see section Include directives), code for
-each sub-module SUBDIR/SUBMODULE.json is actually generated into
+each sub-module SUBDIR/SUBMODULE.json is actually generated into::
 
-SUBDIR/$(prefix)qapi-commands-SUBMODULE.h
-SUBDIR/$(prefix)qapi-commands-SUBMODULE.c
+ SUBDIR/$(prefix)qapi-commands-SUBMODULE.h
+ SUBDIR/$(prefix)qapi-commands-SUBMODULE.c
 
-=== Code generated for events ===
+
+Code generated for events
+-------------------------
 
 This is the code related to events defined in the schema, providing
 qapi_event_send_EVENT().
 
 The following files are created:
 
-$(prefix)qapi-events.h - Function prototypes for each event type
+ ``$(prefix)qapi-events.h``
+     Function prototypes for each event type
 
-$(prefix)qapi-events.c - Implementation of functions to send an event
+ ``$(prefix)qapi-events.c``
+     Implementation of functions to send an event
 
-$(prefix)qapi-emit-events.h - Enumeration of all event names, and
-                              common event code declarations
+ ``$(prefix)qapi-emit-events.h``
+     Enumeration of all event names, and common event code declarations
 
-$(prefix)qapi-emit-events.c - Common event code definitions
+ ``$(prefix)qapi-emit-events.c``
+     Common event code definitions
 
-Example:
+Example::
 
     $ cat qapi-generated/example-qapi-events.h
-[Uninteresting stuff omitted...]
+    [Uninteresting stuff omitted...]
 
     #ifndef EXAMPLE_QAPI_EVENTS_H
     #define EXAMPLE_QAPI_EVENTS_H
@@ -1747,7 +1807,7 @@ Example:
 
     #endif /* EXAMPLE_QAPI_EVENTS_H */
     $ cat qapi-generated/example-qapi-events.c
-[Uninteresting stuff omitted...]
+    [Uninteresting stuff omitted...]
 
     void qapi_event_send_my_event(void)
     {
@@ -1760,9 +1820,9 @@ Example:
         qobject_unref(qmp);
     }
 
-[Uninteresting stuff omitted...]
+    [Uninteresting stuff omitted...]
     $ cat qapi-generated/example-qapi-emit-events.h
-[Uninteresting stuff omitted...]
+    [Uninteresting stuff omitted...]
 
     #ifndef EXAMPLE_QAPI_EMIT_EVENTS_H
     #define EXAMPLE_QAPI_EMIT_EVENTS_H
@@ -1783,7 +1843,7 @@ Example:
 
     #endif /* EXAMPLE_QAPI_EMIT_EVENTS_H */
     $ cat qapi-generated/example-qapi-emit-events.c
-[Uninteresting stuff omitted...]
+    [Uninteresting stuff omitted...]
 
     const QEnumLookup example_QAPIEvent_lookup = {
         .array = (const char *const[]) {
@@ -1792,27 +1852,30 @@ Example:
         .size = EXAMPLE_QAPI_EVENT__MAX
     };
 
-[Uninteresting stuff omitted...]
+    [Uninteresting stuff omitted...]
 
 For a modular QAPI schema (see section Include directives), code for
-each sub-module SUBDIR/SUBMODULE.json is actually generated into
+each sub-module SUBDIR/SUBMODULE.json is actually generated into ::
 
-SUBDIR/$(prefix)qapi-events-SUBMODULE.h
-SUBDIR/$(prefix)qapi-events-SUBMODULE.c
+ SUBDIR/$(prefix)qapi-events-SUBMODULE.h
+ SUBDIR/$(prefix)qapi-events-SUBMODULE.c
 
-=== Code generated for introspection ===
+
+Code generated for introspection
+--------------------------------
 
 The following files are created:
 
-$(prefix)qapi-introspect.c - Defines a string holding a JSON
-                            description of the schema
+ ``$(prefix)qapi-introspect.c``
+     Defines a string holding a JSON description of the schema
 
-$(prefix)qapi-introspect.h - Declares the above string
+ ``$(prefix)qapi-introspect.h``
+     Declares the above string
 
-Example:
+Example::
 
     $ cat qapi-generated/example-qapi-introspect.h
-[Uninteresting stuff omitted...]
+    [Uninteresting stuff omitted...]
 
     #ifndef EXAMPLE_QAPI_INTROSPECT_H
     #define EXAMPLE_QAPI_INTROSPECT_H
@@ -1823,7 +1886,7 @@ Example:
 
     #endif /* EXAMPLE_QAPI_INTROSPECT_H */
     $ cat qapi-generated/example-qapi-introspect.c
-[Uninteresting stuff omitted...]
+    [Uninteresting stuff omitted...]
 
     const QLitObject example_qmp_schema_qlit = QLIT_QLIST(((QLitObject[]) {
         QLIT_QDICT(((QLitDictEntry[]) {
@@ -1903,4 +1966,4 @@ Example:
         {}
     }));
 
-[Uninteresting stuff omitted...]
+    [Uninteresting stuff omitted...]
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PULL 3/5] docs/qapi-code-gen: Beautify formatting
  2021-08-05 14:08 [PULL 0/5] QAPI patches patches for 2021-08-05 Markus Armbruster
  2021-08-05 14:08 ` [PULL 1/5] docs/devel/qapi-code-gen: Update examples to match current code Markus Armbruster
  2021-08-05 14:08 ` [PULL 2/5] docs: convert qapi-code-gen.txt to ReST Markus Armbruster
@ 2021-08-05 14:09 ` Markus Armbruster
  2021-08-05 14:09 ` [PULL 4/5] docs/qapi-code-gen: add cross-references Markus Armbruster
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Markus Armbruster @ 2021-08-05 14:09 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, John Snow

From: John Snow <jsnow@redhat.com>

Mostly, add ``literal`` markers to a lot of things like C types, add
code blocks, and fix the way a few things render.

Signed-off-by: John Snow <jsnow@redhat.com>
Message-Id: <20210720235619.2048797-3-jsnow@redhat.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 docs/devel/qapi-code-gen.rst | 172 ++++++++++++++++++-----------------
 1 file changed, 90 insertions(+), 82 deletions(-)

diff --git a/docs/devel/qapi-code-gen.rst b/docs/devel/qapi-code-gen.rst
index 9155dba262..07b11e2a40 100644
--- a/docs/devel/qapi-code-gen.rst
+++ b/docs/devel/qapi-code-gen.rst
@@ -40,7 +40,7 @@ by any commands or events, for the side effect of generated C code
 used internally.
 
 There are several kinds of types: simple types (a number of built-in
-types, such as 'int' and 'str'; as well as enumerations), arrays,
+types, such as ``int`` and ``str``; as well as enumerations), arrays,
 complex types (structs and two flavors of unions), and alternate types
 (a choice between other types).
 
@@ -51,37 +51,37 @@ Schema syntax
 Syntax is loosely based on `JSON <http://www.ietf.org/rfc/rfc8259.txt>`_.
 Differences:
 
-* Comments: start with a hash character (#) that is not part of a
+* Comments: start with a hash character (``#``) that is not part of a
   string, and extend to the end of the line.
 
-* Strings are enclosed in 'single quotes', not "double quotes".
+* Strings are enclosed in ``'single quotes'``, not ``"double quotes"``.
 
 * Strings are restricted to printable ASCII, and escape sequences to
-  just '\\'.
+  just ``\\``.
 
-* Numbers and null are not supported.
+* Numbers and ``null`` are not supported.
 
 A second layer of syntax defines the sequences of JSON texts that are
 a correctly structured QAPI schema.  We provide a grammar for this
 syntax in an EBNF-like notation:
 
-* Production rules look like non-terminal = expression
-* Concatenation: expression A B matches expression A, then B
-* Alternation: expression A | B matches expression A or B
-* Repetition: expression A... matches zero or more occurrences of
-  expression A
-* Repetition: expression A, ... matches zero or more occurrences of
-  expression A separated by ,
-* Grouping: expression ( A ) matches expression A
-* JSON's structural characters are terminals: { } [ ] : ,
-* JSON's literal names are terminals: false true
-* String literals enclosed in 'single quotes' are terminal, and match
-  this JSON string, with a leading '*' stripped off
-* When JSON object member's name starts with '*', the member is
+* Production rules look like ``non-terminal = expression``
+* Concatenation: expression ``A B`` matches expression ``A``, then ``B``
+* Alternation: expression ``A | B`` matches expression ``A`` or ``B``
+* Repetition: expression ``A...`` matches zero or more occurrences of
+  expression ``A``
+* Repetition: expression ``A, ...`` matches zero or more occurrences of
+  expression ``A`` separated by ``,``
+* Grouping: expression ``( A )`` matches expression ``A``
+* JSON's structural characters are terminals: ``{ } [ ] : ,``
+* JSON's literal names are terminals: ``false true``
+* String literals enclosed in ``'single quotes'`` are terminal, and match
+  this JSON string, with a leading ``*`` stripped off
+* When JSON object member's name starts with ``*``, the member is
   optional.
-* The symbol STRING is a terminal, and matches any JSON string
-* The symbol BOOL is a terminal, and matches JSON false or true
-* ALL-CAPS words other than STRING are non-terminals
+* The symbol ``STRING`` is a terminal, and matches any JSON string
+* The symbol ``BOOL`` is a terminal, and matches JSON ``false`` or ``true``
+* ALL-CAPS words other than ``STRING`` are non-terminals
 
 The order of members within JSON objects does not matter unless
 explicitly noted.
@@ -109,27 +109,30 @@ These are discussed in detail below.
 Built-in Types
 --------------
 
-The following types are predefined, and map to C as follows::
+The following types are predefined, and map to C as follows:
 
-  Schema    C          JSON
-  str       char *     any JSON string, UTF-8
-  number    double     any JSON number
-  int       int64_t    a JSON number without fractional part
-                       that fits into the C integer type
-  int8      int8_t     likewise
-  int16     int16_t    likewise
-  int32     int32_t    likewise
-  int64     int64_t    likewise
-  uint8     uint8_t    likewise
-  uint16    uint16_t   likewise
-  uint32    uint32_t   likewise
-  uint64    uint64_t   likewise
-  size      uint64_t   like uint64_t, except StringInputVisitor
-                       accepts size suffixes
-  bool      bool       JSON true or false
-  null      QNull *    JSON null
-  any       QObject *  any JSON value
-  QType     QType      JSON string matching enum QType values
+  ============= ============== ============================================
+  Schema        C              JSON
+  ============= ============== ============================================
+  ``str``       ``char *``     any JSON string, UTF-8
+  ``number``    ``double``     any JSON number
+  ``int``       ``int64_t``    a JSON number without fractional part
+                               that fits into the C integer type
+  ``int8``      ``int8_t``     likewise
+  ``int16``     ``int16_t``    likewise
+  ``int32``     ``int32_t``    likewise
+  ``int64``     ``int64_t``    likewise
+  ``uint8``     ``uint8_t``    likewise
+  ``uint16``    ``uint16_t``   likewise
+  ``uint32``    ``uint32_t``   likewise
+  ``uint64``    ``uint64_t``   likewise
+  ``size``      ``uint64_t``   like ``uint64_t``, except
+                               ``StringInputVisitor`` accepts size suffixes
+  ``bool``      ``bool``       JSON ``true`` or ``false``
+  ``null``      ``QNull *``    JSON ``null``
+  ``any``       ``QObject *``  any JSON value
+  ``QType``     ``QType``      JSON string matching enum ``QType`` values
+  ============= ============== ============================================
 
 
 Include directives
@@ -174,14 +177,14 @@ Pragma 'doc-required' takes a boolean value.  If true, documentation
 is required.  Default is false.
 
 Pragma 'command-name-exceptions' takes a list of commands whose names
-may contain '_' instead of '-'.  Default is none.
+may contain ``"_"`` instead of ``"-"``.  Default is none.
 
 Pragma 'command-returns-exceptions' takes a list of commands that may
 violate the rules on permitted return types.  Default is none.
 
 Pragma 'member-name-exceptions' takes a list of types whose member
-names may contain uppercase letters, and '_' instead of '-'.  Default
-is none.
+names may contain uppercase letters, and ``"_"`` instead of ``"-"``.
+Default is none.
 
 
 Enumeration types
@@ -200,7 +203,7 @@ Syntax::
 Member 'enum' names the enum type.
 
 Each member of the 'data' array defines a value of the enumeration
-type.  The form STRING is shorthand for { 'name': STRING }.  The
+type.  The form STRING is shorthand for :code:`{ 'name': STRING }`.  The
 'name' values must be be distinct.
 
 Example::
@@ -243,7 +246,7 @@ Syntax::
 A string denotes the type named by the string.
 
 A one-element array containing a string denotes an array of the type
-named by the string.  Example: ['int'] denotes an array of 'int'.
+named by the string.  Example: ``['int']`` denotes an array of ``int``.
 
 
 Struct types
@@ -266,11 +269,11 @@ Member 'struct' names the struct type.
 
 Each MEMBER of the 'data' object defines a member of the struct type.
 
-The MEMBER's STRING name consists of an optional '*' prefix and the
-struct member name.  If '*' is present, the member is optional.
+The MEMBER's STRING name consists of an optional ``*`` prefix and the
+struct member name.  If ``*`` is present, the member is optional.
 
 The MEMBER's value defines its properties, in particular its type.
-The form TYPE-REF is shorthand for { 'type': TYPE-REF }.
+The form TYPE-REF is shorthand for :code:`{ 'type': TYPE-REF }`.
 
 Example::
 
@@ -334,7 +337,7 @@ union must have at least one branch.
 The BRANCH's STRING name is the branch name.
 
 The BRANCH's value defines the branch's properties, in particular its
-type.  The form TYPE-REF is shorthand for { 'type': TYPE-REF }.
+type.  The form TYPE-REF is shorthand for :code:`{ 'type': TYPE-REF }`.
 
 A simple union type defines a mapping from automatic discriminator
 values to data types like in this example::
@@ -381,7 +384,7 @@ struct.
 The following example enhances the above simple union example by
 adding an optional common member 'read-only', renaming the
 discriminator to something more applicable than the simple union's
-default of 'type', and reducing the number of {} required on the wire::
+default of 'type', and reducing the number of ``{}`` required on the wire::
 
  { 'enum': 'BlockdevDriver', 'data': [ 'file', 'qcow2' ] }
  { 'union': 'BlockdevOptions',
@@ -450,7 +453,7 @@ alternate.  An alternate must have at least one branch.
 The ALTERNATIVE's STRING name is the branch name.
 
 The ALTERNATIVE's value defines the branch's properties, in particular
-its type.  The form STRING is shorthand for { 'type': STRING }.
+its type.  The form STRING is shorthand for :code:`{ 'type': STRING }`.
 
 Example::
 
@@ -515,7 +518,7 @@ If 'data' is a MEMBERS object, then MEMBERS defines arguments just
 like a struct type's 'data' defines struct type members.
 
 If 'data' is a STRING, then STRING names a complex type whose members
-are the arguments.  A union type requires 'boxed': true.
+are the arguments.  A union type requires ``'boxed': true``.
 
 Member 'returns' defines the command's return type.  It defaults to an
 empty struct type.  It must normally be a complex type or an array of
@@ -555,7 +558,7 @@ section "Code generated for commands" for examples.
 The function returns the return type.  When member 'boxed' is absent,
 it takes the command arguments as arguments one by one, in QAPI schema
 order.  Else it takes them wrapped in the C struct generated for the
-complex argument type.  It takes an additional Error ** argument in
+complex argument type.  It takes an additional ``Error **`` argument in
 either case.
 
 The generator also emits a marshalling function that extracts
@@ -638,11 +641,11 @@ blocking the guest and other background operations.
 Coroutine safety can be hard to prove, similar to thread safety.  Common
 pitfalls are:
 
-- The global mutex isn't held across qemu_coroutine_yield(), so
+- The global mutex isn't held across ``qemu_coroutine_yield()``, so
   operations that used to assume that they execute atomically may have
   to be more careful to protect against changes in the global state.
 
-- Nested event loops (AIO_WAIT_WHILE() etc.) are problematic in
+- Nested event loops (``AIO_WAIT_WHILE()`` etc.) are problematic in
   coroutine context and can easily lead to deadlocks.  They should be
   replaced by yielding and reentering the coroutine when the condition
   becomes false.
@@ -650,9 +653,9 @@ pitfalls are:
 Since the command handler may assume coroutine context, any callers
 other than the QMP dispatcher must also call it in coroutine context.
 In particular, HMP commands calling such a QMP command handler must be
-marked .coroutine = true in hmp-commands.hx.
+marked ``.coroutine = true`` in hmp-commands.hx.
 
-It is an error to specify both 'coroutine': true and 'allow-oob': true
+It is an error to specify both ``'coroutine': true`` and ``'allow-oob': true``
 for a command.  We don't currently have a use case for both together and
 without a use case, it's not entirely clear what the semantics should
 be.
@@ -689,7 +692,7 @@ If 'data' is a MEMBERS object, then MEMBERS defines event-specific
 data just like a struct type's 'data' defines struct type members.
 
 If 'data' is a STRING, then STRING names a complex type whose members
-are the event-specific data.  A union type requires 'boxed': true.
+are the event-specific data.  A union type requires ``'boxed': true``.
 
 An example event is::
 
@@ -763,16 +766,16 @@ digits, hyphen, and underscore.  There are two exceptions: enum values
 may start with a digit, and names that are downstream extensions (see
 section Downstream extensions) start with underscore.
 
-Names beginning with 'q\_' are reserved for the generator, which uses
+Names beginning with ``q_`` are reserved for the generator, which uses
 them for munging QMP names that resemble C keywords or other
-problematic strings.  For example, a member named "default" in qapi
-becomes "q_default" in the generated C code.
+problematic strings.  For example, a member named ``default`` in qapi
+becomes ``q_default`` in the generated C code.
 
 Types, commands, and events share a common namespace.  Therefore,
 generally speaking, type definitions should always use CamelCase for
 user-defined type names, while built-in types are lowercase.
 
-Type names ending with 'Kind' or 'List' are reserved for the
+Type names ending with ``Kind`` or ``List`` are reserved for the
 generator, which uses them for implicit union enums and array types,
 respectively.
 
@@ -783,15 +786,15 @@ consistency is preferred over blindly avoiding underscore.
 
 Event names should be ALL_CAPS with words separated by underscore.
 
-Member name 'u' and names starting with 'has-' or 'has\_' are reserved
+Member name ``u`` and names starting with ``has-`` or ``has_`` are reserved
 for the generator, which uses them for unions and for tracking
 optional members.
 
 Any name (command, event, type, member, or enum value) beginning with
-"x-" is marked experimental, and may be withdrawn or changed
+``x-`` is marked experimental, and may be withdrawn or changed
 incompatibly in a future release.
 
-Pragmas 'command-name-exceptions' and 'member-name-exceptions' let you
+Pragmas ``command-name-exceptions`` and ``member-name-exceptions`` let you
 violate naming rules.  Use for new code is strongly discouraged.
 
 
@@ -805,7 +808,7 @@ who controls the valid, reverse fully qualified domain name RFQDN.
 RFQDN may only contain ASCII letters, digits, hyphen and period.
 
 Example: Red Hat, Inc. controls redhat.com, and may therefore add a
-downstream command __com.redhat_drive-mirror.
+downstream command ``__com.redhat_drive-mirror``.
 
 
 Configuring the schema
@@ -879,7 +882,7 @@ this particular build.
 Documentation comments
 ----------------------
 
-A multi-line comment that starts and ends with a '##' line is a
+A multi-line comment that starts and ends with a ``##`` line is a
 documentation comment.
 
 If the documentation comment starts like ::
@@ -887,7 +890,7 @@ If the documentation comment starts like ::
     ##
     # @SYMBOL:
 
-it documents the definition if SYMBOL, else it's free-form
+it documents the definition of SYMBOL, else it's free-form
 documentation.
 
 See below for more on definition documentation.
@@ -900,7 +903,7 @@ Headings and subheadings
 ~~~~~~~~~~~~~~~~~~~~~~~~
 
 A free-form documentation comment containing a line which starts with
-some '=' symbols and then a space defines a section heading::
+some ``=`` symbols and then a space defines a section heading::
 
     ##
     # = This is a top level heading
@@ -924,22 +927,22 @@ Documentation markup
 ~~~~~~~~~~~~~~~~~~~~
 
 Documentation comments can use most rST markup.  In particular,
-a '::' literal block can be used for examples::
+a ``::`` literal block can be used for examples::
 
     # ::
     #
     #   Text of the example, may span
     #   multiple lines
 
-'*' starts an itemized list::
+``*`` starts an itemized list::
 
     # * First item, may span
     #   multiple lines
     # * Second item
 
-You can also use '-' instead of '*'.
+You can also use ``-`` instead of ``*``.
 
-A decimal number followed by '.' starts a numbered list::
+A decimal number followed by ``.`` starts a numbered list::
 
     # 1. First item, may span
     #    multiple lines
@@ -952,11 +955,11 @@ If a list item's text spans multiple lines, then the second and
 subsequent lines must be correctly indented to line up with the
 first character of the first line.
 
-The usual '**strong**', '*emphasised*' and '``literal``' markup should
-be used.  If you need a single literal '*' you will need to
+The usual ****strong****, *\*emphasized\** and ````literal```` markup
+should be used.  If you need a single literal ``*``, you will need to
 backslash-escape it.  As an extension beyond the usual rST syntax, you
-can also use '@foo' to reference a name in the schema; this is
-rendered the same way as '``foo``'.
+can also use ``@foo`` to reference a name in the schema; this is rendered
+the same way as ````foo````.
 
 Example::
 
@@ -991,9 +994,9 @@ alternates), or value (for enums), and finally optional tagged
 sections.
 
 Descriptions of arguments can span multiple lines.  The description
-text can start on the line following the '@argname:', in which case it
+text can start on the line following the '\@argname:', in which case it
 must not be indented at all.  It can also start on the same line as
-the '@argname:'.  In this case if it spans multiple lines then second
+the '\@argname:'.  In this case if it spans multiple lines then second
 and subsequent lines must be indented to line up with the first
 character of the first line of the description::
 
@@ -1006,8 +1009,13 @@ character of the first line of the description::
 
 The number of spaces between the ':' and the text is not significant.
 
-FIXME: the parser accepts these things in almost any order.
-FIXME: union branches should be described, too.
+.. admonition:: FIXME
+
+   The parser accepts these things in almost any order.
+
+.. admonition:: FIXME
+
+   union branches should be described, too.
 
 Extensions added after the definition was first released carry a
 '(since x.y.z)' comment.
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PULL 4/5] docs/qapi-code-gen: add cross-references
  2021-08-05 14:08 [PULL 0/5] QAPI patches patches for 2021-08-05 Markus Armbruster
                   ` (2 preceding siblings ...)
  2021-08-05 14:09 ` [PULL 3/5] docs/qapi-code-gen: Beautify formatting Markus Armbruster
@ 2021-08-05 14:09 ` Markus Armbruster
  2021-08-05 14:09 ` [PULL 5/5] docs: convert writing-qmp-commands.txt to writing-qmp-commands.rst Markus Armbruster
  2021-08-05 19:34 ` [PULL 0/5] QAPI patches patches for 2021-08-05 Peter Maydell
  5 siblings, 0 replies; 7+ messages in thread
From: Markus Armbruster @ 2021-08-05 14:09 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, John Snow

From: John Snow <jsnow@redhat.com>

Add clickables to many places.

Signed-off-by: John Snow <jsnow@redhat.com>
Message-Id: <20210720235619.2048797-4-jsnow@redhat.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 docs/devel/qapi-code-gen.rst | 107 +++++++++++++++++++----------------
 1 file changed, 58 insertions(+), 49 deletions(-)

diff --git a/docs/devel/qapi-code-gen.rst b/docs/devel/qapi-code-gen.rst
index 07b11e2a40..26c62b0e7b 100644
--- a/docs/devel/qapi-code-gen.rst
+++ b/docs/devel/qapi-code-gen.rst
@@ -156,6 +156,7 @@ from making a forward reference to a type that is only introduced by
 an outer file.  The parser may be made stricter in the future to
 prevent incomplete include files.
 
+.. _pragma:
 
 Pragma directives
 -----------------
@@ -186,6 +187,7 @@ Pragma 'member-name-exceptions' takes a list of types whose member
 names may contain uppercase letters, and ``"_"`` instead of ``"-"``.
 Default is none.
 
+.. _ENUM-VALUE:
 
 Enumeration types
 -----------------
@@ -228,13 +230,15 @@ additional enumeration constant PREFIX__MAX with value N.
 Do not use string or an integer type when an enumeration type can do
 the job satisfactorily.
 
-The optional 'if' member specifies a conditional.  See "Configuring
-the schema" below for more on this.
+The optional 'if' member specifies a conditional.  See `Configuring the
+schema`_ below for more on this.
 
-The optional 'features' member specifies features.  See "Features"
+The optional 'features' member specifies features.  See Features_
 below for more on this.
 
 
+.. _TYPE-REF:
+
 Type references and array types
 -------------------------------
 
@@ -269,11 +273,13 @@ Member 'struct' names the struct type.
 
 Each MEMBER of the 'data' object defines a member of the struct type.
 
+.. _MEMBERS:
+
 The MEMBER's STRING name consists of an optional ``*`` prefix and the
 struct member name.  If ``*`` is present, the member is optional.
 
 The MEMBER's value defines its properties, in particular its type.
-The form TYPE-REF is shorthand for :code:`{ 'type': TYPE-REF }`.
+The form TYPE-REF_ is shorthand for :code:`{ 'type': TYPE-REF }`.
 
 Example::
 
@@ -300,10 +306,10 @@ both members like this::
  { "file": "/some/place/my-image",
    "backing": "/some/place/my-backing-file" }
 
-The optional 'if' member specifies a conditional.  See "Configuring
-the schema" below for more on this.
+The optional 'if' member specifies a conditional.  See `Configuring
+the schema`_ below for more on this.
 
-The optional 'features' member specifies features.  See "Features"
+The optional 'features' member specifies features.  See Features_
 below for more on this.
 
 
@@ -337,7 +343,7 @@ union must have at least one branch.
 The BRANCH's STRING name is the branch name.
 
 The BRANCH's value defines the branch's properties, in particular its
-type.  The form TYPE-REF is shorthand for :code:`{ 'type': TYPE-REF }`.
+type.  The form TYPE-REF_ is shorthand for :code:`{ 'type': TYPE-REF }`.
 
 A simple union type defines a mapping from automatic discriminator
 values to data types like in this example::
@@ -368,12 +374,12 @@ Flat unions permit arbitrary common members that occur in all variants
 of the union, not just a discriminator.  Their discriminators need not
 be named 'type'.  They also avoid nesting on the wire.
 
-The 'base' member defines the common members.  If it is a MEMBERS
+The 'base' member defines the common members.  If it is a MEMBERS_
 object, it defines common members just like a struct type's 'data'
 member defines struct type members.  If it is a STRING, it names a
 struct type whose members are the common members.
 
-All flat union branches must be of struct type.
+All flat union branches must be `Struct types`_.
 
 In the Client JSON Protocol, a flat union is represented by an object
 with the common members (from the base type) and the selected branch's
@@ -425,10 +431,10 @@ is identical on the wire to::
  { 'union': 'Flat', 'base': { 'type': 'Enum' }, 'discriminator': 'type',
    'data': { 'one': 'Branch1', 'two': 'Branch2' } }
 
-The optional 'if' member specifies a conditional.  See "Configuring
-the schema" below for more on this.
+The optional 'if' member specifies a conditional.  See `Configuring
+the schema`_ below for more on this.
 
-The optional 'features' member specifies features.  See "Features"
+The optional 'features' member specifies features.  See Features_
 below for more on this.
 
 
@@ -481,10 +487,10 @@ following example objects::
              "read-only": false,
              "filename": "/tmp/mydisk.qcow2" } }
 
-The optional 'if' member specifies a conditional.  See "Configuring
-the schema" below for more on this.
+The optional 'if' member specifies a conditional.  See `Configuring
+the schema`_ below for more on this.
 
-The optional 'features' member specifies features.  See "Features"
+The optional 'features' member specifies features.  See Features_
 below for more on this.
 
 
@@ -511,10 +517,10 @@ Syntax::
 
 Member 'command' names the command.
 
-Member 'data' defines the arguments.  It defaults to an empty MEMBERS
+Member 'data' defines the arguments.  It defaults to an empty MEMBERS_
 object.
 
-If 'data' is a MEMBERS object, then MEMBERS defines arguments just
+If 'data' is a MEMBERS_ object, then MEMBERS defines arguments just
 like a struct type's 'data' defines struct type members.
 
 If 'data' is a STRING, then STRING names a complex type whose members
@@ -553,7 +559,7 @@ which would validate this Client JSON Protocol transaction::
 
 The generator emits a prototype for the C function implementing the
 command.  The function itself needs to be written by hand.  See
-section "Code generated for commands" for examples.
+section `Code generated for commands`_ for examples.
 
 The function returns the return type.  When member 'boxed' is absent,
 it takes the command arguments as arguments one by one, in QAPI schema
@@ -660,10 +666,10 @@ for a command.  We don't currently have a use case for both together and
 without a use case, it's not entirely clear what the semantics should
 be.
 
-The optional 'if' member specifies a conditional.  See "Configuring
-the schema" below for more on this.
+The optional 'if' member specifies a conditional.  See `Configuring
+the schema`_ below for more on this.
 
-The optional 'features' member specifies features.  See "Features"
+The optional 'features' member specifies features.  See Features_
 below for more on this.
 
 
@@ -708,15 +714,17 @@ Resulting in this JSON object::
 The generator emits a function to send the event.  When member 'boxed'
 is absent, it takes event-specific data one by one, in QAPI schema
 order.  Else it takes them wrapped in the C struct generated for the
-complex type.  See section "Code generated for events" for examples.
+complex type.  See section `Code generated for events`_ for examples.
 
-The optional 'if' member specifies a conditional.  See "Configuring
-the schema" below for more on this.
+The optional 'if' member specifies a conditional.  See `Configuring
+the schema`_ below for more on this.
 
-The optional 'features' member specifies features.  See "Features"
+The optional 'features' member specifies features.  See Features_
 below for more on this.
 
 
+.. _FEATURE:
+
 Features
 --------
 
@@ -735,8 +743,8 @@ For this purpose, a list of features can be specified for a command or
 struct type.  Each list member can either be ``{ 'name': STRING, '*if':
 COND }``, or STRING, which is shorthand for ``{ 'name': STRING }``.
 
-The optional 'if' member specifies a conditional.  See "Configuring
-the schema" below for more on this.
+The optional 'if' member specifies a conditional.  See `Configuring
+the schema`_ below for more on this.
 
 Example::
 
@@ -745,7 +753,7 @@ Example::
    'features': [ 'allow-negative-numbers' ] }
 
 The feature strings are exposed to clients in introspection, as
-explained in section "Client JSON Protocol introspection".
+explained in section `Client JSON Protocol introspection`_.
 
 Intended use is to have each feature string signal that this build of
 QEMU shows a certain behaviour.
@@ -764,7 +772,7 @@ Naming rules and reserved names
 All names must begin with a letter, and contain only ASCII letters,
 digits, hyphen, and underscore.  There are two exceptions: enum values
 may start with a digit, and names that are downstream extensions (see
-section Downstream extensions) start with underscore.
+section `Downstream extensions`_) start with underscore.
 
 Names beginning with ``q_`` are reserved for the generator, which uses
 them for munging QMP names that resemble C keywords or other
@@ -794,8 +802,9 @@ Any name (command, event, type, member, or enum value) beginning with
 ``x-`` is marked experimental, and may be withdrawn or changed
 incompatibly in a future release.
 
-Pragmas ``command-name-exceptions`` and ``member-name-exceptions`` let you
-violate naming rules.  Use for new code is strongly discouraged.
+Pragmas ``command-name-exceptions`` and ``member-name-exceptions`` let
+you violate naming rules.  Use for new code is strongly discouraged. See
+`Pragma directives`_ for details.
 
 
 Downstream extensions
@@ -851,7 +860,7 @@ member 'bar' ::
 A union's discriminator may not be conditional.
 
 Likewise, individual enumeration values be conditional.  This requires
-the longhand form of ENUM-VALUE.
+the longhand form of ENUM-VALUE_.
 
 Example: an enum type with unconditional value 'foo' and conditional
 value 'bar' ::
@@ -861,7 +870,7 @@ value 'bar' ::
      { 'name' : 'bar', 'if': 'defined(IFCOND)' } ] }
 
 Likewise, features can be conditional.  This requires the longhand
-form of FEATURE.
+form of FEATURE_.
 
 Example: a struct with conditional feature 'allow-negative-numbers' ::
 
@@ -893,7 +902,7 @@ If the documentation comment starts like ::
 it documents the definition of SYMBOL, else it's free-form
 documentation.
 
-See below for more on definition documentation.
+See below for more on `Definition documentation`_.
 
 Free-form documentation may be used to provide additional text and
 structuring content.
@@ -984,7 +993,7 @@ Definition documentation
 Definition documentation, if present, must immediately precede the
 definition it documents.
 
-When documentation is required (see pragma 'doc-required'), every
+When documentation is required (see pragma_ 'doc-required'), every
 definition must have documentation.
 
 Definition documentation starts with a line naming the definition,
@@ -1181,7 +1190,7 @@ the wire then.
 Each command or event defined with 'data' as MEMBERS object in the
 QAPI schema implicitly defines an object type.
 
-Example: the SchemaInfo for EVENT_C from section Events ::
+Example: the SchemaInfo for EVENT_C from section Events_ ::
 
     { "name": "EVENT_C", "meta-type": "event",
       "arg-type": "q_obj-EVENT_C-arg" }
@@ -1205,7 +1214,7 @@ extensions.  The "members" array is in no particular order; clients
 must search the entire object when learning whether a particular
 member is supported.
 
-Example: the SchemaInfo for MyType from section Struct types ::
+Example: the SchemaInfo for MyType from section `Struct types`_ ::
 
     { "name": "MyType", "meta-type": "object",
       "members": [
@@ -1216,7 +1225,7 @@ Example: the SchemaInfo for MyType from section Struct types ::
 "features" exposes the command's feature strings as a JSON array of
 strings.
 
-Example: the SchemaInfo for TestType from section Features::
+Example: the SchemaInfo for TestType from section Features_::
 
     { "name": "TestType", "meta-type": "object",
       "members": [
@@ -1232,7 +1241,7 @@ that provides the variant members for this type tag value).  The
 list cases in the same order as the corresponding "tag" enum type.
 
 Example: the SchemaInfo for flat union BlockdevOptions from section
-Union types ::
+`Union types`_ ::
 
     { "name": "BlockdevOptions", "meta-type": "object",
       "members": [
@@ -1247,13 +1256,13 @@ Note that base types are "flattened": its members are included in the
 "members" array.
 
 A simple union implicitly defines an enumeration type for its implicit
-discriminator (called "type" on the wire, see section Union types).
+discriminator (called "type" on the wire, see section `Union types`_).
 
 A simple union implicitly defines an object type for each of its
 variants.
 
 Example: the SchemaInfo for simple union BlockdevOptionsSimple from section
-Union types ::
+`Union types`_ ::
 
     { "name": "BlockdevOptionsSimple", "meta-type": "object",
       "members": [
@@ -1273,7 +1282,7 @@ a JSON object with member "type", which names a type.  Values of the
 alternate type conform to exactly one of its member types.  There is
 no guarantee on the order in which "members" will be listed.
 
-Example: the SchemaInfo for BlockdevRef from section Alternate types ::
+Example: the SchemaInfo for BlockdevRef from section `Alternate types`_ ::
 
     { "name": "BlockdevRef", "meta-type": "alternate",
       "members": [
@@ -1297,13 +1306,13 @@ variant member "values".  The values are listed in no particular
 order; clients must search the entire enum when learning whether a
 particular value is supported.
 
-Example: the SchemaInfo for MyEnum from section Enumeration types ::
+Example: the SchemaInfo for MyEnum from section `Enumeration types`_ ::
 
     { "name": "MyEnum", "meta-type": "enum",
       "values": [ "value1", "value2", "value3" ] }
 
 The SchemaInfo for a built-in type has the same name as the type in
-the QAPI schema (see section Built-in Types), with one exception
+the QAPI schema (see section `Built-in Types`_), with one exception
 detailed below.  It has variant member "json-type" that shows how
 values of this type are encoded on the wire.
 
@@ -1505,7 +1514,7 @@ Example::
 
     [Uninteresting stuff omitted...]
 
-For a modular QAPI schema (see section Include directives), code for
+For a modular QAPI schema (see section `Include directives`_), code for
 each sub-module SUBDIR/SUBMODULE.json is actually generated into ::
 
  SUBDIR/$(prefix)qapi-types-SUBMODULE.h
@@ -1643,7 +1652,7 @@ Example::
 
     [Uninteresting stuff omitted...]
 
-For a modular QAPI schema (see section Include directives), code for
+For a modular QAPI schema (see section `Include directives`_), code for
 each sub-module SUBDIR/SUBMODULE.json is actually generated into ::
 
  SUBDIR/$(prefix)qapi-visit-SUBMODULE.h
@@ -1773,7 +1782,7 @@ Example::
     }
     [Uninteresting stuff omitted...]
 
-For a modular QAPI schema (see section Include directives), code for
+For a modular QAPI schema (see section `Include directives`_), code for
 each sub-module SUBDIR/SUBMODULE.json is actually generated into::
 
  SUBDIR/$(prefix)qapi-commands-SUBMODULE.h
@@ -1862,7 +1871,7 @@ Example::
 
     [Uninteresting stuff omitted...]
 
-For a modular QAPI schema (see section Include directives), code for
+For a modular QAPI schema (see section `Include directives`_), code for
 each sub-module SUBDIR/SUBMODULE.json is actually generated into ::
 
  SUBDIR/$(prefix)qapi-events-SUBMODULE.h
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PULL 5/5] docs: convert writing-qmp-commands.txt to writing-qmp-commands.rst
  2021-08-05 14:08 [PULL 0/5] QAPI patches patches for 2021-08-05 Markus Armbruster
                   ` (3 preceding siblings ...)
  2021-08-05 14:09 ` [PULL 4/5] docs/qapi-code-gen: add cross-references Markus Armbruster
@ 2021-08-05 14:09 ` Markus Armbruster
  2021-08-05 19:34 ` [PULL 0/5] QAPI patches patches for 2021-08-05 Peter Maydell
  5 siblings, 0 replies; 7+ messages in thread
From: Markus Armbruster @ 2021-08-05 14:09 UTC (permalink / raw)
  To: qemu-devel; +Cc: Connor Kuehl, peter.maydell, John Snow

From: John Snow <jsnow@redhat.com>

This does about the bare minimum, converting section headers to ReST
ones and adding an indent for code blocks.

Signed-off-by: John Snow <jsnow@redhat.com>
Message-Id: <20210721165015.2180311-1-jsnow@redhat.com>
Reviewed-by: Connor Kuehl <ckuehl@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 docs/devel/index.rst                          |   1 +
 ...-commands.txt => writing-qmp-commands.rst} | 567 +++++++++---------
 2 files changed, 297 insertions(+), 271 deletions(-)
 rename docs/devel/{writing-qmp-commands.txt => writing-qmp-commands.rst} (61%)

diff --git a/docs/devel/index.rst b/docs/devel/index.rst
index bfba3a8daa..5522db7241 100644
--- a/docs/devel/index.rst
+++ b/docs/devel/index.rst
@@ -43,3 +43,4 @@ modifying QEMU's source code.
    ebpf_rss
    vfio-migration
    qapi-code-gen
+   writing-qmp-commands
diff --git a/docs/devel/writing-qmp-commands.txt b/docs/devel/writing-qmp-commands.rst
similarity index 61%
rename from docs/devel/writing-qmp-commands.txt
rename to docs/devel/writing-qmp-commands.rst
index b1e31d56c0..6a10a06c48 100644
--- a/docs/devel/writing-qmp-commands.txt
+++ b/docs/devel/writing-qmp-commands.rst
@@ -1,4 +1,5 @@
-= How to write QMP commands using the QAPI framework =
+How to write QMP commands using the QAPI framework
+==================================================
 
 This document is a step-by-step guide on how to write new QMP commands using
 the QAPI framework. It also shows how to implement new style HMP commands.
@@ -10,7 +11,9 @@ For an in-depth introduction to the QAPI framework, please refer to
 docs/devel/qapi-code-gen.txt. For documentation about the QMP protocol,
 start with docs/interop/qmp-intro.txt.
 
-== Overview ==
+
+Overview
+--------
 
 Generally speaking, the following steps should be taken in order to write a
 new QMP command.
@@ -31,55 +34,59 @@ new QMP command.
 The following sections will demonstrate each of the steps above. We will start
 very simple and get more complex as we progress.
 
-=== Testing ===
+
+Testing
+-------
 
 For all the examples in the next sections, the test setup is the same and is
 shown here.
 
-First, QEMU should be started like this:
+First, QEMU should be started like this::
 
-# qemu-system-TARGET [...] \
-    -chardev socket,id=qmp,port=4444,host=localhost,server=on \
-    -mon chardev=qmp,mode=control,pretty=on
+ # qemu-system-TARGET [...] \
+     -chardev socket,id=qmp,port=4444,host=localhost,server=on \
+     -mon chardev=qmp,mode=control,pretty=on
 
-Then, in a different terminal:
+Then, in a different terminal::
 
-$ telnet localhost 4444
-Trying 127.0.0.1...
-Connected to localhost.
-Escape character is '^]'.
-{
-    "QMP": {
-        "version": {
-            "qemu": {
-                "micro": 50, 
-                "minor": 15, 
-                "major": 0
-            }, 
-            "package": ""
-        }, 
-        "capabilities": [
-        ]
-    }
-}
+ $ telnet localhost 4444
+ Trying 127.0.0.1...
+ Connected to localhost.
+ Escape character is '^]'.
+ {
+     "QMP": {
+         "version": {
+             "qemu": {
+                 "micro": 50,
+                 "minor": 15,
+                 "major": 0
+             },
+             "package": ""
+         },
+         "capabilities": [
+         ]
+     }
+ }
 
 The above output is the QMP server saying you're connected. The server is
-actually in capabilities negotiation mode. To enter in command mode type:
+actually in capabilities negotiation mode. To enter in command mode type::
 
-{ "execute": "qmp_capabilities" }
+ { "execute": "qmp_capabilities" }
 
-Then the server should respond:
+Then the server should respond::
 
-{
-    "return": {
-    }
-}
+ {
+     "return": {
+     }
+ }
 
 Which is QMP's way of saying "the latest command executed OK and didn't return
 any data". Now you're ready to enter the QMP example commands as explained in
 the following sections.
 
-== Writing a command that doesn't return data ==
+
+Writing a command that doesn't return data
+------------------------------------------
 
 That's the most simple QMP command that can be written. Usually, this kind of
 command carries some meaningful action in QEMU but here it will just print
@@ -90,9 +97,9 @@ return any data.
 
 The first step is defining the command in the appropriate QAPI schema
 module.  We pick module qapi/misc.json, and add the following line at
-the bottom:
+the bottom::
 
-{ 'command': 'hello-world' }
+ { 'command': 'hello-world' }
 
 The "command" keyword defines a new QMP command. It's an JSON object. All
 schema entries are JSON objects. The line above will instruct the QAPI to
@@ -102,19 +109,19 @@ protocol data.
 The next step is to write the "hello-world" implementation. As explained
 earlier, it's preferable for commands to live in QEMU subsystems. But
 "hello-world" doesn't pertain to any, so we put its implementation in
-monitor/qmp-cmds.c:
+monitor/qmp-cmds.c::
 
-void qmp_hello_world(Error **errp)
-{
-    printf("Hello, world!\n");
-}
+ void qmp_hello_world(Error **errp)
+ {
+     printf("Hello, world!\n");
+ }
 
 There are a few things to be noticed:
 
-1. QMP command implementation functions must be prefixed with "qmp_"
+1. QMP command implementation functions must be prefixed with "qmp\_"
 2. qmp_hello_world() returns void, this is in accordance with the fact that the
    command doesn't return any data
-3. It takes an "Error **" argument. This is required. Later we will see how to
+3. It takes an "Error \*\*" argument. This is required. Later we will see how to
    return errors and take additional arguments. The Error argument should not
    be touched if the command doesn't return errors
 4. We won't add the function's prototype. That's automatically done by the QAPI
@@ -122,23 +129,25 @@ There are a few things to be noticed:
    because it's the easiest way to demonstrate a QMP command
 
 You're done. Now build qemu, run it as suggested in the "Testing" section,
-and then type the following QMP command:
+and then type the following QMP command::
 
-{ "execute": "hello-world" }
+ { "execute": "hello-world" }
 
 Then check the terminal running qemu and look for the "Hello, world" string. If
 you don't see it then something went wrong.
 
-=== Arguments ===
+
+Arguments
+~~~~~~~~~
 
 Let's add an argument called "message" to our "hello-world" command. The new
 argument will contain the string to be printed to stdout. It's an optional
 argument, if it's not present we print our default "Hello, World" string.
 
 The first change we have to do is to modify the command specification in the
-schema file to the following:
+schema file to the following::
 
-{ 'command': 'hello-world', 'data': { '*message': 'str' } }
+ { 'command': 'hello-world', 'data': { '*message': 'str' } }
 
 Notice the new 'data' member in the schema. It's an JSON object whose each
 element is an argument to the command in question. Also notice the asterisk,
@@ -147,80 +156,82 @@ for mandatory arguments). Finally, 'str' is the argument's type, which
 stands for "string". The QAPI also supports integers, booleans, enumerations
 and user defined types.
 
-Now, let's update our C implementation in monitor/qmp-cmds.c:
+Now, let's update our C implementation in monitor/qmp-cmds.c::
 
-void qmp_hello_world(bool has_message, const char *message, Error **errp)
-{
-    if (has_message) {
-        printf("%s\n", message);
-    } else {
-        printf("Hello, world\n");
-    }
-}
+ void qmp_hello_world(bool has_message, const char *message, Error **errp)
+ {
+     if (has_message) {
+         printf("%s\n", message);
+     } else {
+         printf("Hello, world\n");
+     }
+ }
 
 There are two important details to be noticed:
 
-1. All optional arguments are accompanied by a 'has_' boolean, which is set
+1. All optional arguments are accompanied by a 'has\_' boolean, which is set
    if the optional argument is present or false otherwise
 2. The C implementation signature must follow the schema's argument ordering,
    which is defined by the "data" member
 
 Time to test our new version of the "hello-world" command. Build qemu, run it as
-described in the "Testing" section and then send two commands:
+described in the "Testing" section and then send two commands::
 
-{ "execute": "hello-world" }
-{
-    "return": {
-    }
-}
+ { "execute": "hello-world" }
+ {
+     "return": {
+     }
+ }
 
-{ "execute": "hello-world", "arguments": { "message": "We love qemu" } }
-{
-    "return": {
-    }
-}
+ { "execute": "hello-world", "arguments": { "message": "We love qemu" } }
+ {
+     "return": {
+     }
+ }
 
 You should see "Hello, world" and "We love qemu" in the terminal running qemu,
 if you don't see these strings, then something went wrong.
 
-=== Errors ===
+
+Errors
+~~~~~~
 
 QMP commands should use the error interface exported by the error.h header
 file. Basically, most errors are set by calling the error_setg() function.
 
 Let's say we don't accept the string "message" to contain the word "love". If
-it does contain it, we want the "hello-world" command to return an error:
+it does contain it, we want the "hello-world" command to return an error::
 
-void qmp_hello_world(bool has_message, const char *message, Error **errp)
-{
-    if (has_message) {
-        if (strstr(message, "love")) {
-            error_setg(errp, "the word 'love' is not allowed");
-            return;
-        }
-        printf("%s\n", message);
-    } else {
-        printf("Hello, world\n");
-    }
-}
+ void qmp_hello_world(bool has_message, const char *message, Error **errp)
+ {
+     if (has_message) {
+         if (strstr(message, "love")) {
+             error_setg(errp, "the word 'love' is not allowed");
+             return;
+         }
+         printf("%s\n", message);
+     } else {
+         printf("Hello, world\n");
+     }
+ }
 
 The first argument to the error_setg() function is the Error pointer
 to pointer, which is passed to all QMP functions. The next argument is a human
 description of the error, this is a free-form printf-like string.
 
 Let's test the example above. Build qemu, run it as defined in the "Testing"
-section, and then issue the following command:
+section, and then issue the following command::
 
-{ "execute": "hello-world", "arguments": { "message": "all you need is love" } }
+ { "execute": "hello-world", "arguments": { "message": "all you need is love" } }
 
-The QMP server's response should be:
+The QMP server's response should be::
 
-{
-    "error": {
-        "class": "GenericError",
-        "desc": "the word 'love' is not allowed"
-    }
-}
+ {
+     "error": {
+         "class": "GenericError",
+         "desc": "the word 'love' is not allowed"
+     }
+ }
 
 Note that error_setg() produces a "GenericError" class.  In general,
 all QMP errors should have that error class.  There are two exceptions
@@ -234,34 +245,38 @@ to this rule:
 If the failure you want to report falls into one of the two cases above,
 use error_set() with a second argument of an ErrorClass value.
 
-=== Command Documentation ===
+
+Command Documentation
+~~~~~~~~~~~~~~~~~~~~~
 
 There's only one step missing to make "hello-world"'s implementation complete,
 and that's its documentation in the schema file.
 
 There are many examples of such documentation in the schema file already, but
-here goes "hello-world"'s new entry for qapi/misc.json:
+here goes "hello-world"'s new entry for qapi/misc.json::
 
-##
-# @hello-world:
-#
-# Print a client provided string to the standard output stream.
-#
-# @message: string to be printed
-#
-# Returns: Nothing on success.
-#
-# Notes: if @message is not provided, the "Hello, world" string will
-#        be printed instead
-#
-# Since: <next qemu stable release, eg. 1.0>
-##
-{ 'command': 'hello-world', 'data': { '*message': 'str' } }
+ ##
+ # @hello-world:
+ #
+ # Print a client provided string to the standard output stream.
+ #
+ # @message: string to be printed
+ #
+ # Returns: Nothing on success.
+ #
+ # Notes: if @message is not provided, the "Hello, world" string will
+ #        be printed instead
+ #
+ # Since: <next qemu stable release, eg. 1.0>
+ ##
+ { 'command': 'hello-world', 'data': { '*message': 'str' } }
 
 Please, note that the "Returns" clause is optional if a command doesn't return
 any data nor any errors.
 
-=== Implementing the HMP command ===
+
+Implementing the HMP command
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 Now that the QMP command is in place, we can also make it available in the human
 monitor (HMP).
@@ -270,20 +285,20 @@ With the introduction of the QAPI, HMP commands make QMP calls. Most of the
 time HMP commands are simple wrappers. All HMP commands implementation exist in
 the monitor/hmp-cmds.c file.
 
-Here's the implementation of the "hello-world" HMP command:
+Here's the implementation of the "hello-world" HMP command::
 
-void hmp_hello_world(Monitor *mon, const QDict *qdict)
-{
-    const char *message = qdict_get_try_str(qdict, "message");
-    Error *err = NULL;
+ void hmp_hello_world(Monitor *mon, const QDict *qdict)
+ {
+     const char *message = qdict_get_try_str(qdict, "message");
+     Error *err = NULL;
 
-    qmp_hello_world(!!message, message, &err);
-    if (err) {
-        monitor_printf(mon, "%s\n", error_get_pretty(err));
-        error_free(err);
-        return;
-    }
-}
+     qmp_hello_world(!!message, message, &err);
+     if (err) {
+         monitor_printf(mon, "%s\n", error_get_pretty(err));
+         error_free(err);
+         return;
+     }
+ }
 
 Also, you have to add the function's prototype to the hmp.h file.
 
@@ -299,7 +314,7 @@ There are three important points to be noticed:
    QMP call
 
 There's one last step to actually make the command available to monitor users,
-we should add it to the hmp-commands.hx file:
+we should add it to the hmp-commands.hx file::
 
     {
         .name       = "hello-world",
@@ -309,11 +324,13 @@ we should add it to the hmp-commands.hx file:
         .cmd        = hmp_hello_world,
     },
 
-STEXI
-@item hello_world @var{message}
-@findex hello_world
-Print message to the standard output
-ETEXI
+::
+
+ STEXI
+ @item hello_world @var{message}
+ @findex hello_world
+ Print message to the standard output
+ ETEXI
 
 To test this you have to open a user monitor and issue the "hello-world"
 command. It might be instructive to check the command's documentation with
@@ -322,7 +339,9 @@ HMP's "help" command.
 Please, check the "-monitor" command-line option to know how to open a user
 monitor.
 
-== Writing a command that returns data ==
+
+Writing a command that returns data
+-----------------------------------
 
 A QMP command is capable of returning any data the QAPI supports like integers,
 strings, booleans, enumerations and user defined types.
@@ -330,7 +349,9 @@ strings, booleans, enumerations and user defined types.
 In this section we will focus on user defined types. Please, check the QAPI
 documentation for information about the other types.
 
-=== User Defined Types ===
+
+User Defined Types
+~~~~~~~~~~~~~~~~~~
 
 FIXME This example needs to be redone after commit 6d32717
 
@@ -344,63 +365,63 @@ returned as a string, the latter is an integer in nanoseconds (which is not
 very useful in practice, as the timer has probably already fired when the
 information reaches the client).
 
-The best way to return that data is to create a new QAPI type, as shown below:
+The best way to return that data is to create a new QAPI type, as shown below::
 
-##
-# @QemuAlarmClock
-#
-# QEMU alarm clock information.
-#
-# @clock-name: The alarm clock method's name.
-#
-# @next-deadline: The time (in nanoseconds) the next alarm will fire.
-#
-# Since: 1.0
-##
-{ 'type': 'QemuAlarmClock',
-  'data': { 'clock-name': 'str', '*next-deadline': 'int' } }
+ ##
+ # @QemuAlarmClock
+ #
+ # QEMU alarm clock information.
+ #
+ # @clock-name: The alarm clock method's name.
+ #
+ # @next-deadline: The time (in nanoseconds) the next alarm will fire.
+ #
+ # Since: 1.0
+ ##
+ { 'type': 'QemuAlarmClock',
+   'data': { 'clock-name': 'str', '*next-deadline': 'int' } }
 
 The "type" keyword defines a new QAPI type. Its "data" member contains the
 type's members. In this example our members are the "clock-name" and the
 "next-deadline" one, which is optional.
 
-Now let's define the query-alarm-clock command:
+Now let's define the query-alarm-clock command::
 
-##
-# @query-alarm-clock
-#
-# Return information about QEMU's alarm clock.
-#
-# Returns a @QemuAlarmClock instance describing the alarm clock method
-# being currently used by QEMU (this is usually set by the '-clock'
-# command-line option).
-#
-# Since: 1.0
-##
-{ 'command': 'query-alarm-clock', 'returns': 'QemuAlarmClock' }
+ ##
+ # @query-alarm-clock
+ #
+ # Return information about QEMU's alarm clock.
+ #
+ # Returns a @QemuAlarmClock instance describing the alarm clock method
+ # being currently used by QEMU (this is usually set by the '-clock'
+ # command-line option).
+ #
+ # Since: 1.0
+ ##
+ { 'command': 'query-alarm-clock', 'returns': 'QemuAlarmClock' }
 
 Notice the "returns" keyword. As its name suggests, it's used to define the
 data returned by a command.
 
 It's time to implement the qmp_query_alarm_clock() function, you can put it
-in the qemu-timer.c file:
+in the qemu-timer.c file::
 
-QemuAlarmClock *qmp_query_alarm_clock(Error **errp)
-{
-    QemuAlarmClock *clock;
-    int64_t deadline;
+ QemuAlarmClock *qmp_query_alarm_clock(Error **errp)
+ {
+     QemuAlarmClock *clock;
+     int64_t deadline;
 
-    clock = g_malloc0(sizeof(*clock));
+     clock = g_malloc0(sizeof(*clock));
 
-    deadline = qemu_next_alarm_deadline();
-    if (deadline > 0) {
-        clock->has_next_deadline = true;
-        clock->next_deadline = deadline;
-    }
-    clock->clock_name = g_strdup(alarm_timer->name);
+     deadline = qemu_next_alarm_deadline();
+     if (deadline > 0) {
+         clock->has_next_deadline = true;
+         clock->next_deadline = deadline;
+     }
+     clock->clock_name = g_strdup(alarm_timer->name);
 
-    return clock;
-}
+     return clock;
+ }
 
 There are a number of things to be noticed:
 
@@ -423,40 +444,42 @@ There are a number of things to be noticed:
 6. You have to include "qapi/qapi-commands-misc.h" in qemu-timer.c
 
 Time to test the new command. Build qemu, run it as described in the "Testing"
-section and try this:
+section and try this::
 
-{ "execute": "query-alarm-clock" }
-{
-    "return": {
-        "next-deadline": 2368219,
-        "clock-name": "dynticks"
-    }
-}
+ { "execute": "query-alarm-clock" }
+ {
+     "return": {
+         "next-deadline": 2368219,
+         "clock-name": "dynticks"
+     }
+ }
 
-==== The HMP command ====
 
-Here's the HMP counterpart of the query-alarm-clock command:
+The HMP command
+~~~~~~~~~~~~~~~
 
-void hmp_info_alarm_clock(Monitor *mon)
-{
-    QemuAlarmClock *clock;
-    Error *err = NULL;
+Here's the HMP counterpart of the query-alarm-clock command::
 
-    clock = qmp_query_alarm_clock(&err);
-    if (err) {
-        monitor_printf(mon, "Could not query alarm clock information\n");
-        error_free(err);
-        return;
-    }
+ void hmp_info_alarm_clock(Monitor *mon)
+ {
+     QemuAlarmClock *clock;
+     Error *err = NULL;
 
-    monitor_printf(mon, "Alarm clock method in use: '%s'\n", clock->clock_name);
-    if (clock->has_next_deadline) {
-        monitor_printf(mon, "Next alarm will fire in %" PRId64 " nanoseconds\n",
-                       clock->next_deadline);
-    }
+     clock = qmp_query_alarm_clock(&err);
+     if (err) {
+         monitor_printf(mon, "Could not query alarm clock information\n");
+         error_free(err);
+         return;
+     }
 
-   qapi_free_QemuAlarmClock(clock); 
-}
+     monitor_printf(mon, "Alarm clock method in use: '%s'\n", clock->clock_name);
+     if (clock->has_next_deadline) {
+         monitor_printf(mon, "Next alarm will fire in %" PRId64 " nanoseconds\n",
+                        clock->next_deadline);
+     }
+
+    qapi_free_QemuAlarmClock(clock);
+ }
 
 It's important to notice that hmp_info_alarm_clock() calls
 qapi_free_QemuAlarmClock() to free the data returned by qmp_query_alarm_clock().
@@ -471,7 +494,7 @@ it's good practice to always check for errors.
 
 Another important detail is that HMP's "info" commands don't go into the
 hmp-commands.hx. Instead, they go into the info_cmds[] table, which is defined
-in the monitor/misc.c file. The entry for the "info alarmclock" follows:
+in the monitor/misc.c file. The entry for the "info alarmclock" follows::
 
     {
         .name       = "alarmclock",
@@ -483,63 +506,65 @@ in the monitor/misc.c file. The entry for the "info alarmclock" follows:
 
 To test this, run qemu and type "info alarmclock" in the user monitor.
 
-=== Returning Lists ===
+
+Returning Lists
+~~~~~~~~~~~~~~~
 
 For this example, we're going to return all available methods for the timer
 alarm, which is pretty much what the command-line option "-clock ?" does,
 except that we're also going to inform which method is in use.
 
-This first step is to define a new type:
+This first step is to define a new type::
 
-##
-# @TimerAlarmMethod
-#
-# Timer alarm method information.
-#
-# @method-name: The method's name.
-#
-# @current: true if this alarm method is currently in use, false otherwise
-#
-# Since: 1.0
-##
-{ 'type': 'TimerAlarmMethod',
-  'data': { 'method-name': 'str', 'current': 'bool' } }
+ ##
+ # @TimerAlarmMethod
+ #
+ # Timer alarm method information.
+ #
+ # @method-name: The method's name.
+ #
+ # @current: true if this alarm method is currently in use, false otherwise
+ #
+ # Since: 1.0
+ ##
+ { 'type': 'TimerAlarmMethod',
+   'data': { 'method-name': 'str', 'current': 'bool' } }
 
 The command will be called "query-alarm-methods", here is its schema
-specification:
+specification::
 
-##
-# @query-alarm-methods
-#
-# Returns information about available alarm methods.
-#
-# Returns: a list of @TimerAlarmMethod for each method
-#
-# Since: 1.0
-##
-{ 'command': 'query-alarm-methods', 'returns': ['TimerAlarmMethod'] }
+ ##
+ # @query-alarm-methods
+ #
+ # Returns information about available alarm methods.
+ #
+ # Returns: a list of @TimerAlarmMethod for each method
+ #
+ # Since: 1.0
+ ##
+ { 'command': 'query-alarm-methods', 'returns': ['TimerAlarmMethod'] }
 
 Notice the syntax for returning lists "'returns': ['TimerAlarmMethod']", this
 should be read as "returns a list of TimerAlarmMethod instances".
 
-The C implementation follows:
+The C implementation follows::
 
-TimerAlarmMethodList *qmp_query_alarm_methods(Error **errp)
-{
-    TimerAlarmMethodList *method_list = NULL;
-    const struct qemu_alarm_timer *p;
-    bool current = true;
+ TimerAlarmMethodList *qmp_query_alarm_methods(Error **errp)
+ {
+     TimerAlarmMethodList *method_list = NULL;
+     const struct qemu_alarm_timer *p;
+     bool current = true;
 
-    for (p = alarm_timers; p->name; p++) {
-        TimerAlarmMethod *value = g_malloc0(*value);
-        value->method_name = g_strdup(p->name);
-        value->current = current;
-        QAPI_LIST_PREPEND(method_list, value);
-        current = false;
-    }
+     for (p = alarm_timers; p->name; p++) {
+         TimerAlarmMethod *value = g_malloc0(*value);
+         value->method_name = g_strdup(p->name);
+         value->current = current;
+         QAPI_LIST_PREPEND(method_list, value);
+         current = false;
+     }
 
-    return method_list;
-}
+     return method_list;
+ }
 
 The most important difference from the previous examples is the
 TimerAlarmMethodList type, which is automatically generated by the QAPI from
@@ -557,41 +582,41 @@ first element of the alarm_timers array. Also notice that QAPI lists are handled
 by hand and we return the head of the list.
 
 Now Build qemu, run it as explained in the "Testing" section and try our new
-command:
+command::
 
-{ "execute": "query-alarm-methods" }
-{
-    "return": [
-        {
-            "current": false, 
-            "method-name": "unix"
-        }, 
-        {
-            "current": true, 
-            "method-name": "dynticks"
-        }
-    ]
-}
+ { "execute": "query-alarm-methods" }
+ {
+     "return": [
+         {
+             "current": false,
+             "method-name": "unix"
+         },
+         {
+             "current": true,
+             "method-name": "dynticks"
+         }
+     ]
+ }
 
 The HMP counterpart is a bit more complex than previous examples because it
-has to traverse the list, it's shown below for reference:
+has to traverse the list, it's shown below for reference::
 
-void hmp_info_alarm_methods(Monitor *mon)
-{
-    TimerAlarmMethodList *method_list, *method;
-    Error *err = NULL;
+ void hmp_info_alarm_methods(Monitor *mon)
+ {
+     TimerAlarmMethodList *method_list, *method;
+     Error *err = NULL;
 
-    method_list = qmp_query_alarm_methods(&err);
-    if (err) {
-        monitor_printf(mon, "Could not query alarm methods\n");
-        error_free(err);
-        return;
-    }
+     method_list = qmp_query_alarm_methods(&err);
+     if (err) {
+         monitor_printf(mon, "Could not query alarm methods\n");
+         error_free(err);
+         return;
+     }
 
-    for (method = method_list; method; method = method->next) {
-        monitor_printf(mon, "%c %s\n", method->value->current ? '*' : ' ',
-                                       method->value->method_name);
-    }
+     for (method = method_list; method; method = method->next) {
+         monitor_printf(mon, "%c %s\n", method->value->current ? '*' : ' ',
+                                        method->value->method_name);
+     }
 
-    qapi_free_TimerAlarmMethodList(method_list);
-}
+     qapi_free_TimerAlarmMethodList(method_list);
+ }
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PULL 0/5] QAPI patches patches for 2021-08-05
  2021-08-05 14:08 [PULL 0/5] QAPI patches patches for 2021-08-05 Markus Armbruster
                   ` (4 preceding siblings ...)
  2021-08-05 14:09 ` [PULL 5/5] docs: convert writing-qmp-commands.txt to writing-qmp-commands.rst Markus Armbruster
@ 2021-08-05 19:34 ` Peter Maydell
  5 siblings, 0 replies; 7+ messages in thread
From: Peter Maydell @ 2021-08-05 19:34 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: QEMU Developers

On Thu, 5 Aug 2021 at 15:09, Markus Armbruster <armbru@redhat.com> wrote:
>
> The following changes since commit cb2f4b8750b7e1c954570d19b104d4fdbeb8739a:
>
>   Merge remote-tracking branch 'remotes/thuth-gitlab/tags/pull-request-2021-08-03' into staging (2021-08-03 19:50:43 +0100)
>
> are available in the Git repository at:
>
>   git://repo.or.cz/qemu/armbru.git tags/pull-qapi-2021-08-05
>
> for you to fetch changes up to 68e6dc594a44a7077657f2ea878806e38dfa50cf:
>
>   docs: convert writing-qmp-commands.txt to writing-qmp-commands.rst (2021-08-04 11:18:05 +0200)
>
> ----------------------------------------------------------------
> QAPI patches patches for 2021-08-05
>

Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/6.1
for any user-visible changes.

-- PMM


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-08-05 19:38 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-05 14:08 [PULL 0/5] QAPI patches patches for 2021-08-05 Markus Armbruster
2021-08-05 14:08 ` [PULL 1/5] docs/devel/qapi-code-gen: Update examples to match current code Markus Armbruster
2021-08-05 14:08 ` [PULL 2/5] docs: convert qapi-code-gen.txt to ReST Markus Armbruster
2021-08-05 14:09 ` [PULL 3/5] docs/qapi-code-gen: Beautify formatting Markus Armbruster
2021-08-05 14:09 ` [PULL 4/5] docs/qapi-code-gen: add cross-references Markus Armbruster
2021-08-05 14:09 ` [PULL 5/5] docs: convert writing-qmp-commands.txt to writing-qmp-commands.rst Markus Armbruster
2021-08-05 19:34 ` [PULL 0/5] QAPI patches patches for 2021-08-05 Peter Maydell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.