Skip to contentSkip to conversation

QMP: TPM QMP and man page documentation updates

PATCH In review Corey Bryant 4 participants 10 messages Mar 15, 2013 – Mar 20, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 QMP: TPM QMP and man page documentation updates

---
 qemu-options.hx |  3 ++-
 qmp-commands.hx | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+), 1 deletion(-)
qemu-options.hx +2 -1
index 30fb85d..3b3cd0f 100644
@@ -2237,7 +2237,8 @@ Backend type must be:
 @option{passthrough}.
 
 The specific backend type will determine the applicable options.
-The @code{-tpmdev} option requires a @code{-device} option.
+The @code{-tpmdev} option creates the TPM backend and requires a
+@code{-device} option that specifies the TPM frontend interface model.
 
 Options to each backend are described below.
 
qmp-commands.hx +59 -0

77 lines not on this page · raw message

Signature · 1 line
1.8.1.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Corey Bryant
---
 qemu-options.hx |  3 ++-
 qmp-commands.hx | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+), 1 deletion(-)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#2 lore raw
In reply to Corey Bryant
Quoted 47 lines · Corey Bryant
---
 qemu-options.hx |  3 ++-
 qmp-commands.hx | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+), 1 deletion(-)
qemu-options.hx +2 -1
index 30fb85d..3b3cd0f 100644
@@ -2237,7 +2237,8 @@ Backend type must be:
 @option{passthrough}.
 
 The specific backend type will determine the applicable options.
-The @code{-tpmdev} option requires a @code{-device} option.
+The @code{-tpmdev} option creates the TPM backend and requires a
+@code{-device} option that specifies the TPM frontend interface model.
 
 Options to each backend are described below.
 
qmp-commands.hx +19 -0
index b370060..4eda5ea 100644
@@ -2721,18 +2721,77 @@ EQMP
         .mhandler.cmd_new = qmp_marshal_input_query_tpm,
     },
 
+SQMP
+query-tpm
+---------
+
+Return information about the TPM device.
+
+Arguments: None
+
+Example:
+
+-> { "execute": "query-tpm" }
+<- { "return":
+     [
+       { "model": "tpm-tis",
+         "tpm-options":
+           { "type": "tpm-passthrough-options",
+             "data":
+               { "cancel-path": "/sys/class/misc/tpm0/device/cancel",
+                 "path": "/dev/tpm0"

qmp-commands.hx EQMP · line 2752

Quoted 10 lines
qmp-commands.hx +10 -0
+               }
+           },
+         "type": "passthrough",
+         "id": "tpm0"
+       }
+     ]
+   }
+
+EQMP
+

"tpm-options" is a discriminated union. How is its discriminator "type" (here: "tpm-passthrough-options") related to the outer "type" (here:
"passthrough")?

[...]

#3 lore raw
Quoted 54 lines · Markus Armbruster
Quoted 52 lines · Corey Bryant
---
  qemu-options.hx |  3 ++-
  qmp-commands.hx | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2 files changed, 61 insertions(+), 1 deletion(-)
qemu-options.hx +2 -1
index 30fb85d..3b3cd0f 100644
@@ -2237,7 +2237,8 @@ Backend type must be:
  @option{passthrough}.
 
  The specific backend type will determine the applicable options.
-The @code{-tpmdev} option requires a @code{-device} option.
+The @code{-tpmdev} option creates the TPM backend and requires a
+@code{-device} option that specifies the TPM frontend interface model.
 
  Options to each backend are described below.
 
qmp-commands.hx +24 -0
index b370060..4eda5ea 100644
@@ -2721,18 +2721,77 @@ EQMP
          .mhandler.cmd_new = qmp_marshal_input_query_tpm,
      },
 
+SQMP
+query-tpm
+---------
+
+Return information about the TPM device.
+
+Arguments: None
+
+Example:
+
+-> { "execute": "query-tpm" }
+<- { "return":
+     [
+       { "model": "tpm-tis",
+         "tpm-options":
+           { "type": "tpm-passthrough-options",
+             "data":
+               { "cancel-path": "/sys/class/misc/tpm0/device/cancel",
+                 "path": "/dev/tpm0"
+               }
+           },
+         "type": "passthrough",
+         "id": "tpm0"
+       }
Quoted 8 lines

qmp-commands.hx EQMP · line 2752

Quoted 5 lines
qmp-commands.hx +5 -0
+     ]
+   }
+
+EQMP
+

"tpm-options" is a discriminated union. How is its discriminator "type" (here: "tpm-passthrough-options") related to the outer "type" (here:
"passthrough")?

It gives you similar information twice. So there is a direct relationship between the two types.

#4 lore raw
Quoted 61 lines · Stefan Berger
Quoted 51 lines · Markus Armbruster
Quoted 49 lines · Corey Bryant
---
  qemu-options.hx |  3 ++-
  qmp-commands.hx | 59
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2 files changed, 61 insertions(+), 1 deletion(-)
qemu-options.hx +2 -1
index 30fb85d..3b3cd0f 100644
@@ -2237,7 +2237,8 @@ Backend type must be:
  @option{passthrough}.
  The specific backend type will determine the applicable options.
-The @code{-tpmdev} option requires a @code{-device} option.
+The @code{-tpmdev} option creates the TPM backend and requires a
+@code{-device} option that specifies the TPM frontend interface model.
  Options to each backend are described below.
qmp-commands.hx +24 -0
index b370060..4eda5ea 100644
@@ -2721,18 +2721,77 @@ EQMP
          .mhandler.cmd_new = qmp_marshal_input_query_tpm,
      },
+SQMP
+query-tpm
+---------
+
+Return information about the TPM device.
+
+Arguments: None
+
+Example:
+
+-> { "execute": "query-tpm" }
+<- { "return":
+     [
+       { "model": "tpm-tis",
+         "tpm-options":
+           { "type": "tpm-passthrough-options",
+             "data":
+               { "cancel-path": "/sys/class/misc/tpm0/device/cancel",
+                 "path": "/dev/tpm0"
+               }
+           },
+         "type": "passthrough",
+         "id": "tpm0"
+       }
Quoted 8 lines

qmp-commands.hx EQMP · line 2752

Quoted 5 lines
qmp-commands.hx +5 -0
+     ]
+   }
+
+EQMP
+

"tpm-options" is a discriminated union. How is its discriminator "type" (here: "tpm-passthrough-options") related to the outer "type" (here:
"passthrough")?

Quoted 3 lines

It gives you similar information twice. So there is a direct relationship between the two types.

The sample above could be the result when the following command line options are in effect:

qemu-system-x86_64
-tpmdev
passthrough,id=tpm0,path=/dev/tpm0,cancel-path=/sys/class/misc/tpm0/device/cancel
-device tpm-tis,tpmdev=tpm0

Signature · 2 lines
Regards,
Corey Bryant
#5 lore raw
In reply to Stefan Berger

[Note cc: Anthony for QAPI schema expertise]

Quoted 61 lines · Stefan Berger
Quoted 51 lines · Markus Armbruster
Quoted 49 lines · Corey Bryant
---
  qemu-options.hx |  3 ++-
  qmp-commands.hx | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2 files changed, 61 insertions(+), 1 deletion(-)
qemu-options.hx +0 -0
index 30fb85d..3b3cd0f 100644
@@ -2237,7 +2237,8 @@ Backend type must be:
  @option{passthrough}.
    The specific backend type will determine the applicable

options.

qemu-options.hx +2 -1
-The @code{-tpmdev} option requires a @code{-device} option.
+The @code{-tpmdev} option creates the TPM backend and requires a
+@code{-device} option that specifies the TPM frontend interface model.
    Options to each backend are described below.
  diff --git a/qmp-commands.hx b/qmp-commands.hx

index b370060..4eda5ea 100644

qmp-commands.hx +23 -0
@@ -2721,18 +2721,77 @@ EQMP
          .mhandler.cmd_new = qmp_marshal_input_query_tpm,
      },
  +SQMP
+query-tpm
+---------
+
+Return information about the TPM device.
+
+Arguments: None
+
+Example:
+
+-> { "execute": "query-tpm" }
+<- { "return":
+     [
+       { "model": "tpm-tis",
+         "tpm-options":
+           { "type": "tpm-passthrough-options",
+             "data":
+               { "cancel-path": "/sys/class/misc/tpm0/device/cancel",
+                 "path": "/dev/tpm0"
+               }
+           },
+         "type": "passthrough",
+         "id": "tpm0"
+       }
Quoted 8 lines

qmp-commands.hx EQMP · line 2752

Quoted 5 lines
qmp-commands.hx +5 -0
+     ]
+   }
+
+EQMP
+

"tpm-options" is a discriminated union. How is its discriminator "type" (here: "tpm-passthrough-options") related to the outer "type" (here:
"passthrough")?

Quoted 2 lines

It gives you similar information twice. So there is a direct relationship between the two types.

Awkward and undocumented.

Relevant parts of qapi-schema.json:

    { 'enum': 'TpmType', 'data': [ 'passthrough' ] }

    { 'union': 'TpmTypeOptions',
       'data': { 'tpm-passthrough-options' : 'TPMPassthroughOptions' } }

    { 'type': 'TPMInfo',
      'data': {'id': 'str',
               'model': 'TpmModel',
               'type': 'TpmType',
               'tpm-options': 'TpmTypeOptions' } }

Type Netdev solves the same problem more elegantly:

    { 'union': 'NetClientOptions',
      'data': {
        'none':     'NetdevNoneOptions',
        'nic':      'NetLegacyNicOptions',
        'user':     'NetdevUserOptions',
        'tap':      'NetdevTapOptions',
        'socket':   'NetdevSocketOptions',
        'vde':      'NetdevVdeOptions',
        'dump':     'NetdevDumpOptions',
        'bridge':   'NetdevBridgeOptions',
        'hubport':  'NetdevHubPortOptions' } }

    { 'type': 'Netdev',
      'data': {
        'id':   'str',
        'opts': 'NetClientOptions' } }

Uses the union's discriminator. Straightforward.

Following Netdev precedence, we get:

    { 'union': 'TpmTypeOptions',
      'data': { 'passthrough' : 'TPMPassthroughOptions' } }

    { 'type': 'TPMInfo',
      'data': {'id': 'str',
               'model': 'TpmModel',
               'opts': 'TpmTypeOptions' } }

Duplication of type is gone. No need for documentation.

Since enum TpmType is used elsewhere, it still gets duplicated in the union's discriminator. Anthony, is there a way to name the implicit discriminator enum type for reference elsewhere in the schema?

#6 lore raw
Quoted 106 lines · Markus Armbruster

[Note cc: Anthony for QAPI schema expertise]

Quoted 61 lines · Stefan Berger
Quoted 51 lines · Markus Armbruster
Quoted 49 lines · Corey Bryant
---
   qemu-options.hx |  3 ++-
   qmp-commands.hx | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   2 files changed, 61 insertions(+), 1 deletion(-)
qemu-options.hx +0 -0
index 30fb85d..3b3cd0f 100644
@@ -2237,7 +2237,8 @@ Backend type must be:
   @option{passthrough}.
     The specific backend type will determine the applicable

options.

qemu-options.hx +2 -1
-The @code{-tpmdev} option requires a @code{-device} option.
+The @code{-tpmdev} option creates the TPM backend and requires a
+@code{-device} option that specifies the TPM frontend interface model.
     Options to each backend are described below.
   diff --git a/qmp-commands.hx b/qmp-commands.hx

index b370060..4eda5ea 100644

qmp-commands.hx +23 -0
@@ -2721,18 +2721,77 @@ EQMP
           .mhandler.cmd_new = qmp_marshal_input_query_tpm,
       },
   +SQMP
+query-tpm
+---------
+
+Return information about the TPM device.
+
+Arguments: None
+
+Example:
+
+-> { "execute": "query-tpm" }
+<- { "return":
+     [
+       { "model": "tpm-tis",
+         "tpm-options":
+           { "type": "tpm-passthrough-options",
+             "data":
+               { "cancel-path": "/sys/class/misc/tpm0/device/cancel",
+                 "path": "/dev/tpm0"
+               }
+           },
+         "type": "passthrough",
+         "id": "tpm0"
+       }
Quoted 8 lines

qmp-commands.hx EQMP · line 2752

Quoted 5 lines
qmp-commands.hx +5 -0
+     ]
+   }
+
+EQMP
+

"tpm-options" is a discriminated union. How is its discriminator "type" (here: "tpm-passthrough-options") related to the outer "type" (here:
"passthrough")?

Quoted 2 lines

It gives you similar information twice. So there is a direct relationship between the two types.

Awkward and undocumented.

Relevant parts of qapi-schema.json:

     { 'enum': 'TpmType', 'data': [ 'passthrough' ] }

     { 'union': 'TpmTypeOptions',
        'data': { 'tpm-passthrough-options' : 'TPMPassthroughOptions' } }

     { 'type': 'TPMInfo',
       'data': {'id': 'str',
                'model': 'TpmModel',
                'type': 'TpmType',
                'tpm-options': 'TpmTypeOptions' } }

Type Netdev solves the same problem more elegantly:

     { 'union': 'NetClientOptions',
       'data': {
         'none':     'NetdevNoneOptions',
         'nic':      'NetLegacyNicOptions',
         'user':     'NetdevUserOptions',
         'tap':      'NetdevTapOptions',
         'socket':   'NetdevSocketOptions',
         'vde':      'NetdevVdeOptions',
         'dump':     'NetdevDumpOptions',
         'bridge':   'NetdevBridgeOptions',
         'hubport':  'NetdevHubPortOptions' } }

     { 'type': 'Netdev',
       'data': {
         'id':   'str',
         'opts': 'NetClientOptions' } }

Uses the union's discriminator. Straightforward.

Following Netdev precedence, we get:

Quoted 8 lines
     { 'union': 'TpmTypeOptions',
       'data': { 'passthrough' : 'TPMPassthroughOptions' } }

     { 'type': 'TPMInfo',
       'data': {'id': 'str',
                'model': 'TpmModel',
                'opts': 'TpmTypeOptions' } }

I can send a patch for this update if you'd like.

Quoted 6 lines

Duplication of type is gone. No need for documentation.

Since enum TpmType is used elsewhere, it still gets duplicated in the union's discriminator. Anthony, is there a way to name the implicit discriminator enum type for reference elsewhere in the schema?

Are you saying it still gets duplicated with this fix? I'm not sure what you mean.

Signature · 2 lines
Regards,
Corey Bryant
#7 lore raw
Quoted 110 lines · Corey Bryant
Quoted 109 lines · Markus Armbruster

[Note cc: Anthony for QAPI schema expertise]

Quoted 61 lines · Stefan Berger
Quoted 51 lines · Markus Armbruster
Quoted 49 lines · Corey Bryant
---
   qemu-options.hx |  3 ++-
   qmp-commands.hx | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   2 files changed, 61 insertions(+), 1 deletion(-)
qemu-options.hx +0 -0
index 30fb85d..3b3cd0f 100644
@@ -2237,7 +2237,8 @@ Backend type must be:
   @option{passthrough}.
     The specific backend type will determine the applicable

options.

qemu-options.hx +2 -1
-The @code{-tpmdev} option requires a @code{-device} option.
+The @code{-tpmdev} option creates the TPM backend and requires a
+@code{-device} option that specifies the TPM frontend interface model.
     Options to each backend are described below.
   diff --git a/qmp-commands.hx b/qmp-commands.hx

index b370060..4eda5ea 100644

qmp-commands.hx +23 -0
@@ -2721,18 +2721,77 @@ EQMP
           .mhandler.cmd_new = qmp_marshal_input_query_tpm,
       },
   +SQMP
+query-tpm
+---------
+
+Return information about the TPM device.
+
+Arguments: None
+
+Example:
+
+-> { "execute": "query-tpm" }
+<- { "return":
+     [
+       { "model": "tpm-tis",
+         "tpm-options":
+           { "type": "tpm-passthrough-options",
+             "data":
+               { "cancel-path": "/sys/class/misc/tpm0/device/cancel",
+                 "path": "/dev/tpm0"
+               }
+           },
+         "type": "passthrough",
+         "id": "tpm0"
+       }
Quoted 8 lines

qmp-commands.hx EQMP · line 2752

Quoted 5 lines
qmp-commands.hx +5 -0
+     ]
+   }
+
+EQMP
+

"tpm-options" is a discriminated union. How is its discriminator "type" (here: "tpm-passthrough-options") related to the outer "type" (here:
"passthrough")?

Quoted 2 lines

It gives you similar information twice. So there is a direct relationship between the two types.

Awkward and undocumented.

Relevant parts of qapi-schema.json:

     { 'enum': 'TpmType', 'data': [ 'passthrough' ] }

     { 'union': 'TpmTypeOptions',
        'data': { 'tpm-passthrough-options' : 'TPMPassthroughOptions' } }

     { 'type': 'TPMInfo',
       'data': {'id': 'str',
                'model': 'TpmModel',
                'type': 'TpmType',
                'tpm-options': 'TpmTypeOptions' } }

Type Netdev solves the same problem more elegantly:

     { 'union': 'NetClientOptions',
       'data': {
         'none':     'NetdevNoneOptions',
         'nic':      'NetLegacyNicOptions',
         'user':     'NetdevUserOptions',
         'tap':      'NetdevTapOptions',
         'socket':   'NetdevSocketOptions',
         'vde':      'NetdevVdeOptions',
         'dump':     'NetdevDumpOptions',
         'bridge':   'NetdevBridgeOptions',
         'hubport':  'NetdevHubPortOptions' } }

     { 'type': 'Netdev',
       'data': {
         'id':   'str',
         'opts': 'NetClientOptions' } }

Uses the union's discriminator. Straightforward.

Following Netdev precedence, we get:

{ 'union': 'TpmTypeOptions',
'data': { 'passthrough' : 'TPMPassthroughOptions' } }

Quoted 7 lines
Quoted 5 lines
     { 'type': 'TPMInfo',
       'data': {'id': 'str',
                'model': 'TpmModel',
                'opts': 'TpmTypeOptions' } }

I can send a patch for this update if you'd like.

Yes, please!

Quoted 9 lines
Quoted 6 lines

Duplication of type is gone. No need for documentation.

Since enum TpmType is used elsewhere, it still gets duplicated in the union's discriminator. Anthony, is there a way to name the implicit discriminator enum type for reference elsewhere in the schema?

Are you saying it still gets duplicated with this fix? I'm not sure what you mean.

A union in the schema implicitely defines an C enumeration type to be used for its discriminator. For instance, union TpmTypeOptions implicitely defines this one:

typedef enum TpmTypeOptionsKind
{
TPM_TYPE_OPTIONS_KIND_TPM_PASSTHROUGH_OPTIONS = 0, TPM_TYPE_OPTIONS_KIND_MAX = 1,
} TpmTypeOptionsKind;

QAPI's discriminated union becomes a C struct containing the discriminator and the union of the members:

    struct TpmTypeOptions
    {
        TpmTypeOptionsKind kind;
        union {
            void *data;
            TPMPassthroughOptions * tpm_passthrough_options;
        };
    };

Enum TpmType and type TpmInfo become:

    typedef enum TpmType
    {
        TPM_TYPE_PASSTHROUGH = 0,
        TPM_TYPE_MAX = 1,
    } TpmType;

    struct TPMInfo
    {
        char * id;
        TpmModel model;
        TpmType type;
        TpmTypeOptions * tpm_options;
    };

With the change I propose, TPM_TYPE_OPTIONS_KIND_TPM_PASSTHROUGH_OPTIONS becomes TPM_TYPE_OPTIONS_KIND_TPM_PASSTHROUGH, and TPMInfo member type goes away.

Because TpmType is still used elsewhere, it doesn't go away, thus still duplicates TpmTypeOptionsKind. My question to Anthony was about ways to avoid that remaining bit of duplication. I don't expect you do answer it :)

#8 lore raw
Quoted 118 lines · Markus Armbruster
Quoted 116 lines · Corey Bryant
Quoted 114 lines · Markus Armbruster

[Note cc: Anthony for QAPI schema expertise]

Quoted 61 lines · Stefan Berger
Quoted 51 lines · Markus Armbruster
Quoted 49 lines · Corey Bryant
---
    qemu-options.hx |  3 ++-
    qmp-commands.hx | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    2 files changed, 61 insertions(+), 1 deletion(-)
qemu-options.hx +0 -0
index 30fb85d..3b3cd0f 100644
@@ -2237,7 +2237,8 @@ Backend type must be:
    @option{passthrough}.
      The specific backend type will determine the applicable

options.

qemu-options.hx +2 -1
-The @code{-tpmdev} option requires a @code{-device} option.
+The @code{-tpmdev} option creates the TPM backend and requires a
+@code{-device} option that specifies the TPM frontend interface model.
      Options to each backend are described below.
    diff --git a/qmp-commands.hx b/qmp-commands.hx

index b370060..4eda5ea 100644

qmp-commands.hx +23 -0
@@ -2721,18 +2721,77 @@ EQMP
            .mhandler.cmd_new = qmp_marshal_input_query_tpm,
        },
    +SQMP
+query-tpm
+---------
+
+Return information about the TPM device.
+
+Arguments: None
+
+Example:
+
+-> { "execute": "query-tpm" }
+<- { "return":
+     [
+       { "model": "tpm-tis",
+         "tpm-options":
+           { "type": "tpm-passthrough-options",
+             "data":
+               { "cancel-path": "/sys/class/misc/tpm0/device/cancel",
+                 "path": "/dev/tpm0"
+               }
+           },
+         "type": "passthrough",
+         "id": "tpm0"
+       }
Quoted 8 lines

qmp-commands.hx EQMP · line 2752

Quoted 5 lines
qmp-commands.hx +5 -0
+     ]
+   }
+
+EQMP
+

"tpm-options" is a discriminated union. How is its discriminator "type" (here: "tpm-passthrough-options") related to the outer "type" (here:
"passthrough")?

Quoted 2 lines

It gives you similar information twice. So there is a direct relationship between the two types.

Awkward and undocumented.

Relevant parts of qapi-schema.json:

      { 'enum': 'TpmType', 'data': [ 'passthrough' ] }

      { 'union': 'TpmTypeOptions',
         'data': { 'tpm-passthrough-options' : 'TPMPassthroughOptions' } }

      { 'type': 'TPMInfo',
        'data': {'id': 'str',
                 'model': 'TpmModel',
                 'type': 'TpmType',
                 'tpm-options': 'TpmTypeOptions' } }

Type Netdev solves the same problem more elegantly:

      { 'union': 'NetClientOptions',
        'data': {
          'none':     'NetdevNoneOptions',
          'nic':      'NetLegacyNicOptions',
          'user':     'NetdevUserOptions',
          'tap':      'NetdevTapOptions',
          'socket':   'NetdevSocketOptions',
          'vde':      'NetdevVdeOptions',
          'dump':     'NetdevDumpOptions',
          'bridge':   'NetdevBridgeOptions',
          'hubport':  'NetdevHubPortOptions' } }

      { 'type': 'Netdev',
        'data': {
          'id':   'str',
          'opts': 'NetClientOptions' } }

Uses the union's discriminator. Straightforward.

Following Netdev precedence, we get:

      { 'union': 'TpmTypeOptions',
        'data': { 'passthrough' : 'TPMPassthroughOptions' } }

      { 'type': 'TPMInfo',
        'data': {'id': 'str',
                 'model': 'TpmModel',
                 'opts': 'TpmTypeOptions' } }
Quoted 4 lines
Quoted 1 line

I can send a patch for this update if you'd like.

Yes, please!

Will do.

Quoted 48 lines
Quoted 9 lines
Quoted 6 lines

Duplication of type is gone. No need for documentation.

Since enum TpmType is used elsewhere, it still gets duplicated in the union's discriminator. Anthony, is there a way to name the implicit discriminator enum type for reference elsewhere in the schema?

Are you saying it still gets duplicated with this fix? I'm not sure what you mean.

A union in the schema implicitely defines an C enumeration type to be used for its discriminator. For instance, union TpmTypeOptions implicitely defines this one:

typedef enum TpmTypeOptionsKind
{
TPM_TYPE_OPTIONS_KIND_TPM_PASSTHROUGH_OPTIONS = 0, TPM_TYPE_OPTIONS_KIND_MAX = 1,
} TpmTypeOptionsKind;

QAPI's discriminated union becomes a C struct containing the discriminator and the union of the members:

     struct TpmTypeOptions
     {
         TpmTypeOptionsKind kind;
         union {
             void *data;
             TPMPassthroughOptions * tpm_passthrough_options;
         };
     };

Enum TpmType and type TpmInfo become:

     typedef enum TpmType
     {
         TPM_TYPE_PASSTHROUGH = 0,
         TPM_TYPE_MAX = 1,
     } TpmType;

     struct TPMInfo
     {
         char * id;
         TpmModel model;
         TpmType type;
         TpmTypeOptions * tpm_options;
     };
Quoted 9 lines

With the change I propose, TPM_TYPE_OPTIONS_KIND_TPM_PASSTHROUGH_OPTIONS becomes TPM_TYPE_OPTIONS_KIND_TPM_PASSTHROUGH, and TPMInfo member type goes away.

Because TpmType is still used elsewhere, it doesn't go away, thus still duplicates TpmTypeOptionsKind. My question to Anthony was about ways to avoid that remaining bit of duplication. I don't expect you do answer it :)

Ok well thanks for the explanation anyway!

Signature · 2 lines
Regards,
Corey Bryant
#9 lore raw
In reply to Corey Bryant

I just resubmitted this patch as part of another series, so please ignore this one.

Signature · 2 lines
Regards,
Corey Bryant
Quoted 103 lines · Corey Bryant
---
  qemu-options.hx |  3 ++-
  qmp-commands.hx | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2 files changed, 61 insertions(+), 1 deletion(-)
qemu-options.hx +2 -1
index 30fb85d..3b3cd0f 100644
@@ -2237,7 +2237,8 @@ Backend type must be:
  @option{passthrough}.
 
  The specific backend type will determine the applicable options.
-The @code{-tpmdev} option requires a @code{-device} option.
+The @code{-tpmdev} option creates the TPM backend and requires a
+@code{-device} option that specifies the TPM frontend interface model.
 
  Options to each backend are described below.
 
qmp-commands.hx +59 -0
index b370060..4eda5ea 100644
@@ -2721,18 +2721,77 @@ EQMP
          .mhandler.cmd_new = qmp_marshal_input_query_tpm,
      },
 
+SQMP
+query-tpm
+---------
+
+Return information about the TPM device.
+
+Arguments: None
+
+Example:
+
+-> { "execute": "query-tpm" }
+<- { "return":
+     [
+       { "model": "tpm-tis",
+         "tpm-options":
+           { "type": "tpm-passthrough-options",
+             "data":
+               { "cancel-path": "/sys/class/misc/tpm0/device/cancel",
+                 "path": "/dev/tpm0"
+               }
+           },
+         "type": "passthrough",
+         "id": "tpm0"
+       }
+     ]
+   }
+
+EQMP
+
      {
          .name       = "query-tpm-models",
          .args_type  = "",
          .mhandler.cmd_new = qmp_marshal_input_query_tpm_models,
      },
 
+SQMP
+query-tpm-models
+----------------
+
+Return a list of supported TPM models.
+
+Arguments: None
+
+Example:
+
+-> { "execute": "query-tpm-models" }
+<- { "return": [ "tpm-tis" ] }
+
+EQMP
+
      {
          .name       = "query-tpm-types",
          .args_type  = "",
          .mhandler.cmd_new = qmp_marshal_input_query_tpm_types,
      },
 
+SQMP
+query-tpm-types
+---------------
+
+Return a list of supported TPM types.
+
+Arguments: None
+
+Example:
+
+-> { "execute": "query-tpm-types" }
+<- { "return": [ "passthrough" ] }
+
+EQMP
+
      {
          .name       = "chardev-add",
          .args_type  = "id:s,backend:q",