xref: /qemu/docs/devel/qapi-domain.rst (revision 7c7247b252dd8b3911b96451c0eaaebbc6ac0af0)
142b633dbSJohn Snow======================
242b633dbSJohn SnowThe Sphinx QAPI Domain
342b633dbSJohn Snow======================
442b633dbSJohn Snow
542b633dbSJohn SnowAn extension to the `rST syntax
642b633dbSJohn Snow<https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html>`_
742b633dbSJohn Snowin Sphinx is provided by the QAPI Domain, located in
842b633dbSJohn Snow``docs/sphinx/qapi_domain.py``. This extension is analogous to the
942b633dbSJohn Snow`Python Domain
1042b633dbSJohn Snow<https://www.sphinx-doc.org/en/master/usage/domains/python.html>`_
1142b633dbSJohn Snowincluded with Sphinx, but provides special directives and roles
1242b633dbSJohn Snowspeciically for annotating and documenting QAPI definitions
1342b633dbSJohn Snowspecifically.
1442b633dbSJohn Snow
1542b633dbSJohn SnowA `Domain
1642b633dbSJohn Snow<https://www.sphinx-doc.org/en/master/usage/domains/index.html>`_
1742b633dbSJohn Snowprovides a set of special rST directives and cross-referencing roles to
1842b633dbSJohn SnowSphinx for understanding rST markup written to document a specific
1942b633dbSJohn Snowlanguage. By itself, this QAPI extension is only sufficient to parse rST
2042b633dbSJohn Snowmarkup written by hand; the `autodoc
2142b633dbSJohn Snow<https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html>`_
2242b633dbSJohn Snowfunctionality is provided elsewhere, in ``docs/sphinx/qapidoc.py``, by
2342b633dbSJohn Snowthe "Transmogrifier".
2442b633dbSJohn Snow
2542b633dbSJohn SnowIt is not expected that any developer nor documentation writer would
2642b633dbSJohn Snownever need to write *nor* read these special rST forms. However, in the
2742b633dbSJohn Snowevent that something needs to be debugged, knowing the syntax of the
2842b633dbSJohn Snowdomain is quite handy. This reference may also be useful as a guide for
2942b633dbSJohn Snowunderstanding the QAPI Domain extension code itself. Although most of
3042b633dbSJohn Snowthese forms will not be needed for documentation writing purposes,
3142b633dbSJohn Snowunderstanding the cross-referencing syntax *will* be helpful when
3242b633dbSJohn Snowwriting rST documentation elsewhere, or for enriching the body of
3342b633dbSJohn SnowQAPIDoc blocks themselves.
3442b633dbSJohn Snow
3542b633dbSJohn Snow
3642b633dbSJohn SnowConcepts
3742b633dbSJohn Snow========
3842b633dbSJohn Snow
3942b633dbSJohn SnowThe QAPI Domain itself provides no mechanisms for reading the QAPI
4042b633dbSJohn SnowSchema or generating documentation from code that exists. It is merely
4142b633dbSJohn Snowthe rST syntax used to describe things. For instance, the Sphinx Python
4242b633dbSJohn Snowdomain adds syntax like ``:py:func:`` for describing Python functions in
4342b633dbSJohn Snowdocumentation, but it's the autodoc module that is responsible for
4442b633dbSJohn Snowreading python code and generating such syntax. QAPI is analagous here:
4542b633dbSJohn Snowqapidoc.py is responsible for reading the QAPI Schema and generating rST
4642b633dbSJohn Snowsyntax, and qapi_domain.py is responsible for translating that special
4742b633dbSJohn Snowsyntax and providing APIs for Sphinx internals.
4842b633dbSJohn Snow
4942b633dbSJohn SnowIn other words:
5042b633dbSJohn Snow
5142b633dbSJohn Snowqapi_domain.py adds syntax like ``.. qapi:command::`` to Sphinx, and
5242b633dbSJohn Snowqapidoc.py transforms the documentation in ``qapi/*.json`` into rST
5342b633dbSJohn Snowusing directives defined by the domain.
5442b633dbSJohn Snow
5542b633dbSJohn SnowOr even shorter:
5642b633dbSJohn Snow
5742b633dbSJohn Snow``:py:`` is to ``:qapi:`` as *autodoc* is to *qapidoc*.
5842b633dbSJohn Snow
5942b633dbSJohn Snow
6042b633dbSJohn SnowInfo Field Lists
6142b633dbSJohn Snow================
6242b633dbSJohn Snow
6342b633dbSJohn Snow`Field lists
6442b633dbSJohn Snow<https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#field-lists>`_
6542b633dbSJohn Snoware a standard syntax in reStructuredText. Sphinx `extends that syntax
6642b633dbSJohn Snow<https://www.sphinx-doc.org/en/master/usage/domains/python.html#info-field-lists>`_
6742b633dbSJohn Snowto give certain field list entries special meaning and parsing to, for
6842b633dbSJohn Snowexample, add cross-references. The QAPI Domain takes advantage of this
6942b633dbSJohn Snowfield list extension to document things like Arguments, Members, Values,
7042b633dbSJohn Snowand so on.
7142b633dbSJohn Snow
7242b633dbSJohn SnowThe special parsing and handling of info field lists in Sphinx is provided by
7342b633dbSJohn Snowthree main classes; Field, GroupedField, and TypedField. The behavior
7442b633dbSJohn Snowand formatting for each configured field list entry in the domain
7542b633dbSJohn Snowchanges depending on which class is used.
7642b633dbSJohn Snow
7742b633dbSJohn SnowField:
7842b633dbSJohn Snow  * Creates an ungrouped field: i.e., each entry will create its own
7942b633dbSJohn Snow    section and they will not be combined.
8042b633dbSJohn Snow  * May *optionally* support an argument.
8142b633dbSJohn Snow  * May apply cross-reference roles to *either* the argument *or* the
8242b633dbSJohn Snow    content body, both, or neither.
8342b633dbSJohn Snow
8442b633dbSJohn SnowThis is used primarily for entries which are not expected to be
8542b633dbSJohn Snowrepeated, i.e., items that may only show up at most once. The QAPI
8642b633dbSJohn Snowdomain uses this class for "Errors" section.
8742b633dbSJohn Snow
8842b633dbSJohn SnowGroupedField:
8942b633dbSJohn Snow  * Creates a grouped field: i.e. multiple adjacent entries will be
9042b633dbSJohn Snow    merged into one section, and the content will form a bulleted list.
9142b633dbSJohn Snow  * *Must* take an argument.
9242b633dbSJohn Snow  * May optionally apply a cross-reference role to the argument, but not
9342b633dbSJohn Snow    the body.
9442b633dbSJohn Snow  * Can be configured to remove the bulleted list if there is only a
9542b633dbSJohn Snow    single entry.
9642b633dbSJohn Snow  * All items will be generated with the form: "argument -- body"
9742b633dbSJohn Snow
9842b633dbSJohn SnowThis is used for entries which are expected to be repeated, but aren't
9942b633dbSJohn Snowexpected to have two arguments, i.e. types without names, or names
10042b633dbSJohn Snowwithout types. The QAPI domain uses this class for features, returns,
10142b633dbSJohn Snowand enum values.
10242b633dbSJohn Snow
10342b633dbSJohn SnowTypedField:
10442b633dbSJohn Snow  * Creates a grouped, typed field. Multiple adjacent entres will be
10542b633dbSJohn Snow    merged into one section, and the content will form a bulleted list.
10642b633dbSJohn Snow  * *Must* take at least one argument, but supports up to two -
10742b633dbSJohn Snow    nominally, a name and a type.
10842b633dbSJohn Snow  * May optionally apply a cross-reference role to the type or the name
10942b633dbSJohn Snow    argument, but not the body.
11042b633dbSJohn Snow  * Can be configured to remove the bulleted list if there is only a
11142b633dbSJohn Snow    single entry.
11242b633dbSJohn Snow  * All items will be generated with the form "name (type) -- body"
11342b633dbSJohn Snow
11442b633dbSJohn SnowThis is used for entries that are expected to be repeated and will have
11542b633dbSJohn Snowa name, a type, and a description. The QAPI domain uses this class for
11642b633dbSJohn Snowarguments, alternatives, and members. Wherever type names are referenced
11742b633dbSJohn Snowbelow, They must be a valid, documented type that will be
11842b633dbSJohn Snowcross-referenced in the HTML output; or one of the built-in JSON types
11942b633dbSJohn Snow(string, number, int, boolean, null, value, q_empty).
12042b633dbSJohn Snow
12142b633dbSJohn Snow
12242b633dbSJohn Snow``:feat:``
12342b633dbSJohn Snow----------
12442b633dbSJohn Snow
12542b633dbSJohn SnowDocument a feature attached to a QAPI definition.
12642b633dbSJohn Snow
12742b633dbSJohn Snow:availability: This field list is available in the body of Command,
12842b633dbSJohn Snow               Event, Enum, Object and Alternate directives.
12942b633dbSJohn Snow:syntax: ``:feat name: Lorem ipsum, dolor sit amet...``
13042b633dbSJohn Snow:type: `sphinx.util.docfields.GroupedField
13142b633dbSJohn Snow       <https://pydoc.dev/sphinx/latest/sphinx.util.docfields.GroupedField.html?private=1>`_
13242b633dbSJohn Snow
13342b633dbSJohn SnowExample::
13442b633dbSJohn Snow
13542b633dbSJohn Snow   .. qapi:object:: BlockdevOptionsVirtioBlkVhostVdpa
13642b633dbSJohn Snow      :since: 7.2
13742b633dbSJohn Snow      :ifcond: CONFIG_BLKIO
13842b633dbSJohn Snow
13942b633dbSJohn Snow      Driver specific block device options for the virtio-blk-vhost-vdpa
14042b633dbSJohn Snow      backend.
14142b633dbSJohn Snow
14242b633dbSJohn Snow   :memb string path: path to the vhost-vdpa character device.
14342b633dbSJohn Snow   :feat fdset: Member ``path`` supports the special "/dev/fdset/N" path
14442b633dbSJohn Snow       (since 8.1)
14542b633dbSJohn Snow
14642b633dbSJohn Snow
14742b633dbSJohn Snow``:arg:``
14842b633dbSJohn Snow---------
14942b633dbSJohn Snow
15042b633dbSJohn SnowDocument an argument to a QAPI command.
15142b633dbSJohn Snow
15242b633dbSJohn Snow:availability: This field list is only available in the body of the
15342b633dbSJohn Snow               Command directive.
15442b633dbSJohn Snow:syntax: ``:arg type name: description``
15542b633dbSJohn Snow:type: `sphinx.util.docfields.TypedField
15642b633dbSJohn Snow       <https://pydoc.dev/sphinx/latest/sphinx.util.docfields.TypedField.html?private=1>`_
15742b633dbSJohn Snow
15842b633dbSJohn Snow
15942b633dbSJohn SnowExample::
16042b633dbSJohn Snow
16142b633dbSJohn Snow   .. qapi:command:: job-pause
16242b633dbSJohn Snow      :since: 3.0
16342b633dbSJohn Snow
16442b633dbSJohn Snow      Pause an active job.
16542b633dbSJohn Snow
16642b633dbSJohn Snow      This command returns immediately after marking the active job for
16742b633dbSJohn Snow      pausing.  Pausing an already paused job is an error.
16842b633dbSJohn Snow
16942b633dbSJohn Snow      The job will pause as soon as possible, which means transitioning
17042b633dbSJohn Snow      into the PAUSED state if it was RUNNING, or into STANDBY if it was
17142b633dbSJohn Snow      READY.  The corresponding JOB_STATUS_CHANGE event will be emitted.
17242b633dbSJohn Snow
17342b633dbSJohn Snow      Cancelling a paused job automatically resumes it.
17442b633dbSJohn Snow
17542b633dbSJohn Snow      :arg string id: The job identifier.
17642b633dbSJohn Snow
17742b633dbSJohn Snow
17842b633dbSJohn Snow``:error:``
17942b633dbSJohn Snow-----------
18042b633dbSJohn Snow
18142b633dbSJohn SnowDocument the error condition(s) of a QAPI command.
18242b633dbSJohn Snow
18342b633dbSJohn Snow:availability: This field list is only available in the body of the
18442b633dbSJohn Snow               Command directive.
18542b633dbSJohn Snow:syntax: ``:error: Lorem ipsum dolor sit amet ...``
18642b633dbSJohn Snow:type: `sphinx.util.docfields.Field
18742b633dbSJohn Snow       <https://pydoc.dev/sphinx/latest/sphinx.util.docfields.Field.html?private=1>`_
18842b633dbSJohn Snow
18942b633dbSJohn SnowThe format of the :errors: field list description is free-form rST. The
19042b633dbSJohn Snowalternative spelling ":errors:" is also permitted, but strictly
19142b633dbSJohn Snowanalogous.
19242b633dbSJohn Snow
19342b633dbSJohn SnowExample::
19442b633dbSJohn Snow
19542b633dbSJohn Snow   .. qapi:command:: block-job-set-speed
19642b633dbSJohn Snow      :since: 1.1
19742b633dbSJohn Snow
19842b633dbSJohn Snow      Set maximum speed for a background block operation.
19942b633dbSJohn Snow
20042b633dbSJohn Snow      This command can only be issued when there is an active block job.
20142b633dbSJohn Snow
20242b633dbSJohn Snow      Throttling can be disabled by setting the speed to 0.
20342b633dbSJohn Snow
20442b633dbSJohn Snow      :arg string device: The job identifier.  This used to be a device
20542b633dbSJohn Snow          name (hence the name of the parameter), but since QEMU 2.7 it
20642b633dbSJohn Snow          can have other values.
20742b633dbSJohn Snow      :arg int speed: the maximum speed, in bytes per second, or 0 for
20842b633dbSJohn Snow          unlimited.  Defaults to 0.
20942b633dbSJohn Snow      :error:
21042b633dbSJohn Snow          - If no background operation is active on this device,
21142b633dbSJohn Snow            DeviceNotActive
21242b633dbSJohn Snow
21342b633dbSJohn Snow
21442b633dbSJohn Snow``:return:``
21542b633dbSJohn Snow-------------
21642b633dbSJohn Snow
21742b633dbSJohn SnowDocument the return type(s) and value(s) of a QAPI command.
21842b633dbSJohn Snow
21942b633dbSJohn Snow:availability: This field list is only available in the body of the
22042b633dbSJohn Snow               Command directive.
22142b633dbSJohn Snow:syntax: ``:return type: Lorem ipsum dolor sit amet ...``
22242b633dbSJohn Snow:type: `sphinx.util.docfields.GroupedField
22342b633dbSJohn Snow       <https://pydoc.dev/sphinx/latest/sphinx.util.docfields.GroupedField.html?private=1>`_
22442b633dbSJohn Snow
22542b633dbSJohn Snow
22642b633dbSJohn SnowExample::
22742b633dbSJohn Snow
22842b633dbSJohn Snow   .. qapi:command:: query-replay
22942b633dbSJohn Snow      :since: 5.2
23042b633dbSJohn Snow
23142b633dbSJohn Snow      Retrieve the record/replay information.  It includes current
23242b633dbSJohn Snow      instruction count which may be used for ``replay-break`` and
23342b633dbSJohn Snow      ``replay-seek`` commands.
23442b633dbSJohn Snow
23542b633dbSJohn Snow      :return ReplayInfo: record/replay information.
23642b633dbSJohn Snow
23742b633dbSJohn Snow      .. qmp-example::
23842b633dbSJohn Snow
23942b633dbSJohn Snow          -> { "execute": "query-replay" }
24042b633dbSJohn Snow          <- { "return": {
24142b633dbSJohn Snow                 "mode": "play", "filename": "log.rr", "icount": 220414 }
24242b633dbSJohn Snow             }
24342b633dbSJohn Snow
24442b633dbSJohn Snow
24542b633dbSJohn Snow``:value:``
24642b633dbSJohn Snow-----------
24742b633dbSJohn Snow
24842b633dbSJohn SnowDocument a possible value for a QAPI enum.
24942b633dbSJohn Snow
25042b633dbSJohn Snow:availability: This field list is only available in the body of the Enum
25142b633dbSJohn Snow               directive.
25242b633dbSJohn Snow:syntax: ``:value name: Lorem ipsum, dolor sit amet ...``
25342b633dbSJohn Snow:type: `sphinx.util.docfields.GroupedField
25442b633dbSJohn Snow       <https://pydoc.dev/sphinx/latest/sphinx.util.docfields.GroupedField.html?private=1>`_
25542b633dbSJohn Snow
25642b633dbSJohn SnowExample::
25742b633dbSJohn Snow
25842b633dbSJohn Snow   .. qapi:enum:: QapiErrorClass
25942b633dbSJohn Snow      :since: 1.2
26042b633dbSJohn Snow
26142b633dbSJohn Snow      QEMU error classes
26242b633dbSJohn Snow
26342b633dbSJohn Snow      :value GenericError: this is used for errors that don't require a specific
26442b633dbSJohn Snow          error class.  This should be the default case for most errors
26542b633dbSJohn Snow      :value CommandNotFound: the requested command has not been found
26642b633dbSJohn Snow      :value DeviceNotActive: a device has failed to be become active
26742b633dbSJohn Snow      :value DeviceNotFound: the requested device has not been found
26842b633dbSJohn Snow      :value KVMMissingCap: the requested operation can't be fulfilled because a
26942b633dbSJohn Snow          required KVM capability is missing
27042b633dbSJohn Snow
27142b633dbSJohn Snow
27242b633dbSJohn Snow``:alt:``
27342b633dbSJohn Snow------------
27442b633dbSJohn Snow
27542b633dbSJohn SnowDocument a possible branch for a QAPI alternate.
27642b633dbSJohn Snow
27742b633dbSJohn Snow:availability: This field list is only available in the body of the
27842b633dbSJohn Snow               Alternate directive.
27942b633dbSJohn Snow:syntax: ``:alt type name: Lorem ipsum, dolor sit amet ...``
28042b633dbSJohn Snow:type: `sphinx.util.docfields.TypedField
28142b633dbSJohn Snow       <https://pydoc.dev/sphinx/latest/sphinx.util.docfields.TypedField.html?private=1>`_
28242b633dbSJohn Snow
28342b633dbSJohn SnowAs a limitation of Sphinx, we must document the "name" of the branch in
28442b633dbSJohn Snowaddition to the type, even though this information is not visible on the
28542b633dbSJohn Snowwire in the QMP protocol format. This limitation *may* be lifted at a
28642b633dbSJohn Snowfuture date.
28742b633dbSJohn Snow
28842b633dbSJohn SnowExample::
28942b633dbSJohn Snow
29042b633dbSJohn Snow   .. qapi:alternate:: StrOrNull
29142b633dbSJohn Snow      :since: 2.10
29242b633dbSJohn Snow
29342b633dbSJohn Snow      This is a string value or the explicit lack of a string (null
29442b633dbSJohn Snow      pointer in C).  Intended for cases when 'optional absent' already
29542b633dbSJohn Snow      has a different meaning.
29642b633dbSJohn Snow
29742b633dbSJohn Snow       :alt string s: the string value
29842b633dbSJohn Snow       :alt null n: no string value
29942b633dbSJohn Snow
30042b633dbSJohn Snow
30142b633dbSJohn Snow``:memb:``
30242b633dbSJohn Snow----------
30342b633dbSJohn Snow
30442b633dbSJohn SnowDocument a member of an Event or Object.
30542b633dbSJohn Snow
30642b633dbSJohn Snow:availability: This field list is available in the body of Event or
30742b633dbSJohn Snow               Object directives.
30842b633dbSJohn Snow:syntax: ``:memb type name: Lorem ipsum, dolor sit amet ...``
30942b633dbSJohn Snow:type: `sphinx.util.docfields.TypedField
31042b633dbSJohn Snow       <https://pydoc.dev/sphinx/latest/sphinx.util.docfields.TypedField.html?private=1>`_
31142b633dbSJohn Snow
31242b633dbSJohn SnowThis is fundamentally the same as ``:arg:`` and ``:alt:``, but uses the
31342b633dbSJohn Snow"Members" phrasing for Events and Objects (Structs and Unions).
31442b633dbSJohn Snow
31542b633dbSJohn SnowExample::
31642b633dbSJohn Snow
31742b633dbSJohn Snow   .. qapi:event:: JOB_STATUS_CHANGE
31842b633dbSJohn Snow      :since: 3.0
31942b633dbSJohn Snow
32042b633dbSJohn Snow      Emitted when a job transitions to a different status.
32142b633dbSJohn Snow
32242b633dbSJohn Snow      :memb string id: The job identifier
32342b633dbSJohn Snow      :memb JobStatus status: The new job status
32442b633dbSJohn Snow
32542b633dbSJohn Snow
32642b633dbSJohn SnowArbitrary field lists
32742b633dbSJohn Snow---------------------
32842b633dbSJohn Snow
32942b633dbSJohn SnowOther field list names, while valid rST syntax, are prohibited inside of
33042b633dbSJohn SnowQAPI directives to help prevent accidental misspellings of info field
33142b633dbSJohn Snowlist names. If you want to add a new arbitrary "non-value-added" field
33242b633dbSJohn Snowlist to QAPI documentation, you must add the field name to the allow
33342b633dbSJohn Snowlist in ``docs/conf.py``
33442b633dbSJohn Snow
33542b633dbSJohn SnowFor example::
33642b633dbSJohn Snow
33742b633dbSJohn Snow   qapi_allowed_fields = {
33842b633dbSJohn Snow       "see also",
33942b633dbSJohn Snow   }
34042b633dbSJohn Snow
34142b633dbSJohn SnowWill allow you to add arbitrary field lists in QAPI directives::
34242b633dbSJohn Snow
34342b633dbSJohn Snow   .. qapi:command:: x-fake-command
34442b633dbSJohn Snow
34542b633dbSJohn Snow      :see also: Lorem ipsum, dolor sit amet ...
34642b633dbSJohn Snow
34742b633dbSJohn Snow
34842b633dbSJohn SnowCross-references
34942b633dbSJohn Snow================
35042b633dbSJohn Snow
35142b633dbSJohn SnowCross-reference `roles
35242b633dbSJohn Snow<https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html>`_
35342b633dbSJohn Snowin the QAPI domain are modeled closely after the `Python
35442b633dbSJohn Snowcross-referencing syntax
35542b633dbSJohn Snow<https://www.sphinx-doc.org/en/master/usage/domains/python.html#cross-referencing-python-objects>`_.
35642b633dbSJohn Snow
35742b633dbSJohn SnowQAPI definitions can be referenced using the standard `any
35842b633dbSJohn Snow<https://www.sphinx-doc.org/en/master/usage/referencing.html#role-any>`_
35942b633dbSJohn Snowrole cross-reference syntax, such as with ```query-blockstats```.  In
36042b633dbSJohn Snowthe event that disambiguation is needed, cross-references can also be
36142b633dbSJohn Snowwritten using a number of explicit cross-reference roles:
36242b633dbSJohn Snow
36342b633dbSJohn Snow* ``:qapi:mod:`block-core``` -- Reference a QAPI module. The link will
36442b633dbSJohn Snow  take you to the beginning of that section in the documentation.
36542b633dbSJohn Snow* ``:qapi:cmd:`query-block``` -- Reference a QAPI command.
36642b633dbSJohn Snow* ``:qapi:event:`JOB_STATUS_CHANGE``` -- Reference a QAPI event.
36742b633dbSJohn Snow* ``:qapi:enum:`QapiErrorClass``` -- Reference a QAPI enum.
36842b633dbSJohn Snow* ``:qapi:obj:`BlockdevOptionsVirtioBlkVhostVdpa`` -- Reference a QAPI
36942b633dbSJohn Snow  object (struct or union)
37042b633dbSJohn Snow* ``:qapi:alt:`StrOrNull``` -- Reference a QAPI alternate.
37142b633dbSJohn Snow* ``:qapi:type:`BlockDirtyInfo``` -- Reference *any* QAPI type; this
37242b633dbSJohn Snow  excludes modules, commands, and events.
37342b633dbSJohn Snow* ``:qapi:any:`block-job-set-speed``` -- Reference absolutely any QAPI entity.
37442b633dbSJohn Snow
37542b633dbSJohn SnowType arguments in info field lists are converted into references as if
37642b633dbSJohn Snowyou had used the ``:qapi:type:`` role. All of the special syntax below
37742b633dbSJohn Snowapplies to both info field lists and standalone explicit
37842b633dbSJohn Snowcross-references.
37942b633dbSJohn Snow
38042b633dbSJohn Snow
38142b633dbSJohn SnowType decorations
38242b633dbSJohn Snow----------------
38342b633dbSJohn Snow
38442b633dbSJohn SnowType names in references can be surrounded by brackets, like
38542b633dbSJohn Snow``[typename]``, to indicate an array of that type.  The cross-reference
38642b633dbSJohn Snowwill apply only to the type name between the brackets. For example;
38742b633dbSJohn Snow``:qapi:type:`[Qcow2BitmapInfoFlags]``` renders to:
38842b633dbSJohn Snow:qapi:type:`[Qcow2BitmapInfoFlags]`
38942b633dbSJohn Snow
39042b633dbSJohn SnowTo indicate an optional argument/member in a field list, the type name
39142b633dbSJohn Snowcan be suffixed with ``?``. The cross-reference will be transformed to
39242b633dbSJohn Snow"type, Optional" with the link applying only to the type name. For
39342b633dbSJohn Snowexample; ``:qapi:type:`BitmapSyncMode?``` renders to:
39442b633dbSJohn Snow:qapi:type:`BitmapSyncMode?`
39542b633dbSJohn Snow
39642b633dbSJohn Snow
39742b633dbSJohn SnowNamespaces
39842b633dbSJohn Snow----------
39942b633dbSJohn Snow
40042b633dbSJohn SnowMimicking the `Python domain target specification syntax
40142b633dbSJohn Snow<https://www.sphinx-doc.org/en/master/usage/domains/python.html#target-specification>`_,
40242b633dbSJohn SnowQAPI allows you to specify the fully qualified path for a data
40342b633dbSJohn Snowtype. QAPI enforces globally unique names, so it's unlikely you'll need
40442b633dbSJohn Snowthis specific feature, but it may be extended in the near future to
40542b633dbSJohn Snowallow referencing identically named commands and data types from
40642b633dbSJohn Snowdifferent utilities; i.e. QEMU Storage Daemon vs QMP.
40742b633dbSJohn Snow
40842b633dbSJohn Snow* A module can be explicitly provided;
40942b633dbSJohn Snow  ``:qapi:type:`block-core.BitmapSyncMode``` will render to:
41042b633dbSJohn Snow  :qapi:type:`block-core.BitmapSyncMode`
41142b633dbSJohn Snow* If you don't want to display the "fully qualified" name, it can be
41242b633dbSJohn Snow  prefixed with a tilde; ``:qapi:type:`~block-core.BitmapSyncMode```
41342b633dbSJohn Snow  will render to: :qapi:type:`~block-core.BitmapSyncMode`
41442b633dbSJohn Snow
41542b633dbSJohn Snow
41642b633dbSJohn SnowCustom link text
41742b633dbSJohn Snow----------------
41842b633dbSJohn Snow
41942b633dbSJohn SnowThe name of a cross-reference link can be explicitly overridden like
42042b633dbSJohn Snow`most stock Sphinx references
42142b633dbSJohn Snow<https://www.sphinx-doc.org/en/master/usage/referencing.html#syntax>`_
42242b633dbSJohn Snowusing the ``custom text <target>`` syntax.
42342b633dbSJohn Snow
42442b633dbSJohn SnowFor example, ``:qapi:cmd:`Merge dirty bitmaps
42542b633dbSJohn Snow<block-dirty-bitmap-merge>``` will render as: :qapi:cmd:`Merge dirty
42642b633dbSJohn Snowbitmaps <block-dirty-bitmap-merge>`
42742b633dbSJohn Snow
42842b633dbSJohn Snow
42942b633dbSJohn SnowDirectives
43042b633dbSJohn Snow==========
43142b633dbSJohn Snow
43242b633dbSJohn SnowThe QAPI domain adds a number of custom directives for documenting
43342b633dbSJohn Snowvarious QAPI/QMP entities. The syntax is plain rST, and follows this
43442b633dbSJohn Snowgeneral format::
43542b633dbSJohn Snow
43642b633dbSJohn Snow  .. qapi:directive:: argument
43742b633dbSJohn Snow     :option:
43842b633dbSJohn Snow     :another-option: with an argument
43942b633dbSJohn Snow
44042b633dbSJohn Snow     Content body, arbitrary rST is allowed here.
44142b633dbSJohn Snow
44242b633dbSJohn Snow
44342b633dbSJohn SnowSphinx standard options
44442b633dbSJohn Snow-----------------------
44542b633dbSJohn Snow
44642b633dbSJohn SnowAll QAPI directives inherit a number of `standard options
44742b633dbSJohn Snow<https://www.sphinx-doc.org/en/master/usage/domains/index.html#basic-markup>`_
44842b633dbSJohn Snowfrom Sphinx's ObjectDescription class.
44942b633dbSJohn Snow
45042b633dbSJohn SnowThe dashed spellings of the below options were added in Sphinx 7.2, the
45142b633dbSJohn Snowundashed spellings are currently retained as aliases, but will be
45242b633dbSJohn Snowremoved in a future version.
45342b633dbSJohn Snow
45442b633dbSJohn Snow* ``:no-index:`` and ``:noindex:`` -- Do not add this item into the
45542b633dbSJohn Snow  Index, and do not make it available for cross-referencing.
45642b633dbSJohn Snow* ``no-index-entry:`` and ``:noindexentry:`` -- Do not add this item
45742b633dbSJohn Snow  into the Index, but allow it to be cross-referenced.
45842b633dbSJohn Snow* ``no-contents-entry`` and ``:nocontentsentry:`` -- Exclude this item
45942b633dbSJohn Snow  from the Table of Contents.
46042b633dbSJohn Snow* ``no-typesetting`` -- Create TOC, Index and cross-referencing
46142b633dbSJohn Snow  entities, but don't actually display the content.
46242b633dbSJohn Snow
46342b633dbSJohn Snow
46442b633dbSJohn SnowQAPI standard options
46542b633dbSJohn Snow---------------------
46642b633dbSJohn Snow
467*7c7247b2SJohn SnowAll QAPI directives -- *except* for namespace and module -- support
468*7c7247b2SJohn Snowthese common options.
46942b633dbSJohn Snow
4709ca404f0SJohn Snow* ``:namespace: name`` -- This option allows you to override the
4719ca404f0SJohn Snow  namespace association of a given definition.
47242b633dbSJohn Snow* ``:module: modname`` -- Borrowed from the Python domain, this option allows
47342b633dbSJohn Snow  you to override the module association of a given definition.
47442b633dbSJohn Snow* ``:since: x.y`` -- Allows the documenting of "Since" information, which is
47542b633dbSJohn Snow  displayed in the signature bar.
47642b633dbSJohn Snow* ``:ifcond: CONDITION`` -- Allows the documenting of conditional availability
47742b633dbSJohn Snow  information, which is displayed in an eyecatch just below the
47842b633dbSJohn Snow  signature bar.
47942b633dbSJohn Snow* ``:deprecated:`` -- Adds an eyecatch just below the signature bar that
48042b633dbSJohn Snow  advertises that this definition is deprecated and should be avoided.
48142b633dbSJohn Snow* ``:unstable:`` -- Adds an eyecatch just below the signature bar that
48242b633dbSJohn Snow  advertises that this definition is unstable and should not be used in
48342b633dbSJohn Snow  production code.
48442b633dbSJohn Snow
48542b633dbSJohn Snow
486*7c7247b2SJohn Snowqapi:namespace
487*7c7247b2SJohn Snow--------------
488*7c7247b2SJohn Snow
489*7c7247b2SJohn SnowThe ``qapi:namespace`` directive marks the start of a QAPI namespace. It
490*7c7247b2SJohn Snowdoes not take a content body, nor any options. All subsequent QAPI
491*7c7247b2SJohn Snowdirectives are associated with the most recent namespace. This affects
492*7c7247b2SJohn Snowthe definition's "fully qualified name", allowing two different
493*7c7247b2SJohn Snownamespaces to create an otherwise identically named definition.
494*7c7247b2SJohn Snow
495*7c7247b2SJohn SnowExample::
496*7c7247b2SJohn Snow
497*7c7247b2SJohn Snow   .. qapi:namespace:: QMP
498*7c7247b2SJohn Snow
499*7c7247b2SJohn Snow
500*7c7247b2SJohn SnowThis directive has no visible effect.
501*7c7247b2SJohn Snow
502*7c7247b2SJohn Snow
50342b633dbSJohn Snowqapi:module
50442b633dbSJohn Snow-----------
50542b633dbSJohn Snow
50642b633dbSJohn SnowThe ``qapi:module`` directive marks the start of a QAPI module. It may have
50742b633dbSJohn Snowa content body, but it can be omitted. All subsequent QAPI directives
50842b633dbSJohn Snoware associated with the most recent module; this effects their "fully
50942b633dbSJohn Snowqualified" name, but has no other effect.
51042b633dbSJohn Snow
51142b633dbSJohn SnowExample::
51242b633dbSJohn Snow
51342b633dbSJohn Snow   .. qapi:module:: block-core
51442b633dbSJohn Snow
51542b633dbSJohn Snow      Welcome to the block-core module!
51642b633dbSJohn Snow
51742b633dbSJohn SnowWill be rendered as:
51842b633dbSJohn Snow
51942b633dbSJohn Snow.. qapi:module:: block-core
52042b633dbSJohn Snow   :noindex:
52142b633dbSJohn Snow
52242b633dbSJohn Snow   Welcome to the block-core module!
52342b633dbSJohn Snow
52442b633dbSJohn Snow
52542b633dbSJohn Snowqapi:command
52642b633dbSJohn Snow------------
52742b633dbSJohn Snow
52842b633dbSJohn SnowThis directive documents a QMP command. It may use any of the standard
52942b633dbSJohn SnowSphinx or QAPI options, and the documentation body may contain
53042b633dbSJohn Snow``:arg:``, ``:feat:``, ``:error:``, or ``:return:`` info field list
53142b633dbSJohn Snowentries.
53242b633dbSJohn Snow
53342b633dbSJohn SnowExample::
53442b633dbSJohn Snow
53542b633dbSJohn Snow  .. qapi:command:: x-fake-command
53642b633dbSJohn Snow     :since: 42.0
53742b633dbSJohn Snow     :unstable:
53842b633dbSJohn Snow
53942b633dbSJohn Snow     This command is fake, so it can't hurt you!
54042b633dbSJohn Snow
54142b633dbSJohn Snow     :arg int foo: Your favorite number.
54242b633dbSJohn Snow     :arg string? bar: Your favorite season.
54342b633dbSJohn Snow     :return [string]: A lovely computer-written poem for you.
54442b633dbSJohn Snow
54542b633dbSJohn Snow
54642b633dbSJohn SnowWill be rendered as:
54742b633dbSJohn Snow
54842b633dbSJohn Snow  .. qapi:command:: x-fake-command
54942b633dbSJohn Snow     :noindex:
55042b633dbSJohn Snow     :since: 42.0
55142b633dbSJohn Snow     :unstable:
55242b633dbSJohn Snow
55342b633dbSJohn Snow     This command is fake, so it can't hurt you!
55442b633dbSJohn Snow
55542b633dbSJohn Snow     :arg int foo: Your favorite number.
55642b633dbSJohn Snow     :arg string? bar: Your favorite season.
55742b633dbSJohn Snow     :return [string]: A lovely computer-written poem for you.
55842b633dbSJohn Snow
55942b633dbSJohn Snow
56042b633dbSJohn Snowqapi:event
56142b633dbSJohn Snow----------
56242b633dbSJohn Snow
56342b633dbSJohn SnowThis directive documents a QMP event. It may use any of the standard
56442b633dbSJohn SnowSphinx or QAPI options, and the documentation body may contain
56542b633dbSJohn Snow``:memb:`` or ``:feat:`` info field list entries.
56642b633dbSJohn Snow
56742b633dbSJohn SnowExample::
56842b633dbSJohn Snow
56942b633dbSJohn Snow  .. qapi:event:: COMPUTER_IS_RUINED
57042b633dbSJohn Snow     :since: 0.1
57142b633dbSJohn Snow     :deprecated:
57242b633dbSJohn Snow
57342b633dbSJohn Snow     This event is emitted when your computer is *extremely* ruined.
57442b633dbSJohn Snow
57542b633dbSJohn Snow     :memb string reason: Diagnostics as to what caused your computer to
57642b633dbSJohn Snow        be ruined.
57742b633dbSJohn Snow     :feat sadness: When present, the diagnostic message will also
57842b633dbSJohn Snow        explain how sad the computer is as a result of your wrongdoings.
57942b633dbSJohn Snow
58042b633dbSJohn SnowWill be rendered as:
58142b633dbSJohn Snow
58242b633dbSJohn Snow.. qapi:event:: COMPUTER_IS_RUINED
58342b633dbSJohn Snow   :noindex:
58442b633dbSJohn Snow   :since: 0.1
58542b633dbSJohn Snow   :deprecated:
58642b633dbSJohn Snow
58742b633dbSJohn Snow   This event is emitted when your computer is *extremely* ruined.
58842b633dbSJohn Snow
58942b633dbSJohn Snow   :memb string reason: Diagnostics as to what caused your computer to
59042b633dbSJohn Snow      be ruined.
59142b633dbSJohn Snow   :feat sadness: When present, the diagnostic message will also explain
59242b633dbSJohn Snow      how sad the computer is as a result of your wrongdoings.
59342b633dbSJohn Snow
59442b633dbSJohn Snow
59542b633dbSJohn Snowqapi:enum
59642b633dbSJohn Snow---------
59742b633dbSJohn Snow
59842b633dbSJohn SnowThis directive documents a QAPI enum. It may use any of the standard
59942b633dbSJohn SnowSphinx or QAPI options, and the documentation body may contain
60042b633dbSJohn Snow``:value:`` or ``:feat:`` info field list entries.
60142b633dbSJohn Snow
60242b633dbSJohn SnowExample::
60342b633dbSJohn Snow
60442b633dbSJohn Snow  .. qapi:enum:: Mood
60542b633dbSJohn Snow     :ifcond: LIB_PERSONALITY
60642b633dbSJohn Snow
60742b633dbSJohn Snow     This enum represents your virtual machine's current mood!
60842b633dbSJohn Snow
60942b633dbSJohn Snow     :value Happy: Your VM is content and well-fed.
61042b633dbSJohn Snow     :value Hungry: Your VM needs food.
61142b633dbSJohn Snow     :value Melancholic: Your VM is experiencing existential angst.
61242b633dbSJohn Snow     :value Petulant: Your VM is throwing a temper tantrum.
61342b633dbSJohn Snow
61442b633dbSJohn SnowWill be rendered as:
61542b633dbSJohn Snow
61642b633dbSJohn Snow.. qapi:enum:: Mood
61742b633dbSJohn Snow   :noindex:
61842b633dbSJohn Snow   :ifcond: LIB_PERSONALITY
61942b633dbSJohn Snow
62042b633dbSJohn Snow   This enum represents your virtual machine's current mood!
62142b633dbSJohn Snow
62242b633dbSJohn Snow   :value Happy: Your VM is content and well-fed.
62342b633dbSJohn Snow   :value Hungry: Your VM needs food.
62442b633dbSJohn Snow   :value Melancholic: Your VM is experiencing existential angst.
62542b633dbSJohn Snow   :value Petulant: Your VM is throwing a temper tantrum.
62642b633dbSJohn Snow
62742b633dbSJohn Snow
62842b633dbSJohn Snowqapi:object
62942b633dbSJohn Snow-----------
63042b633dbSJohn Snow
63142b633dbSJohn SnowThis directive documents a QAPI structure or union and represents a QMP
63242b633dbSJohn Snowobject. It may use any of the standard Sphinx or QAPI options, and the
63342b633dbSJohn Snowdocumentation body may contain ``:memb:`` or ``:feat:`` info field list
63442b633dbSJohn Snowentries.
63542b633dbSJohn Snow
63642b633dbSJohn SnowExample::
63742b633dbSJohn Snow
63842b633dbSJohn Snow  .. qapi:object:: BigBlobOfStuff
63942b633dbSJohn Snow
64042b633dbSJohn Snow     This object has a bunch of disparate and unrelated things in it.
64142b633dbSJohn Snow
64242b633dbSJohn Snow     :memb int Birthday: Your birthday, represented in seconds since the
64342b633dbSJohn Snow                         UNIX epoch.
64442b633dbSJohn Snow     :memb [string] Fav-Foods: A list of your favorite foods.
64542b633dbSJohn Snow     :memb boolean? Bizarre-Docs: True if the documentation reference
64642b633dbSJohn Snow        should be strange.
64742b633dbSJohn Snow
64842b633dbSJohn SnowWill be rendered as:
64942b633dbSJohn Snow
65042b633dbSJohn Snow.. qapi:object:: BigBlobOfStuff
65142b633dbSJohn Snow   :noindex:
65242b633dbSJohn Snow
65342b633dbSJohn Snow   This object has a bunch of disparate and unrelated things in it.
65442b633dbSJohn Snow
65542b633dbSJohn Snow   :memb int Birthday: Your birthday, represented in seconds since the
65642b633dbSJohn Snow                       UNIX epoch.
65742b633dbSJohn Snow   :memb [string] Fav-Foods: A list of your favorite foods.
65842b633dbSJohn Snow   :memb boolean? Bizarre-Docs: True if the documentation reference
65942b633dbSJohn Snow      should be strange.
66042b633dbSJohn Snow
66142b633dbSJohn Snow
66242b633dbSJohn Snowqapi:alternate
66342b633dbSJohn Snow--------------
66442b633dbSJohn Snow
66542b633dbSJohn SnowThis directive documents a QAPI alternate. It may use any of the
66642b633dbSJohn Snowstandard Sphinx or QAPI options, and the documentation body may contain
66742b633dbSJohn Snow``:alt:`` or ``:feat:`` info field list entries.
66842b633dbSJohn Snow
66942b633dbSJohn SnowExample::
67042b633dbSJohn Snow
67142b633dbSJohn Snow  .. qapi:alternate:: ErrorCode
67242b633dbSJohn Snow
67342b633dbSJohn Snow     This alternate represents an Error Code from the VM.
67442b633dbSJohn Snow
67542b633dbSJohn Snow     :alt int ec: An error code, like the type you're used to.
67642b633dbSJohn Snow     :alt string em: An expletive-laced error message, if your
67742b633dbSJohn Snow        computer is feeling particularly cranky and tired of your
67842b633dbSJohn Snow        antics.
67942b633dbSJohn Snow
68042b633dbSJohn SnowWill be rendered as:
68142b633dbSJohn Snow
68242b633dbSJohn Snow.. qapi:alternate:: ErrorCode
68342b633dbSJohn Snow   :noindex:
68442b633dbSJohn Snow
68542b633dbSJohn Snow   This alternate represents an Error Code from the VM.
68642b633dbSJohn Snow
68742b633dbSJohn Snow   :alt int ec: An error code, like the type you're used to.
68842b633dbSJohn Snow   :alt string em: An expletive-laced error message, if your
68942b633dbSJohn Snow      computer is feeling particularly cranky and tired of your
69042b633dbSJohn Snow      antics.
691