qmp: expose list of supported character device backends
PATCH v3 1/1 qmp: expose list of supported character device backends
Introduce 'query-chardev-backends' QMP command which lists all supported character device backends.
---
v3:
- Omit commas at the end of list in JSON
v2:
- Version changed from "1.8.0" to "2.0"
qapi-schema.json | 22 ++++++++++++++++++++++ qemu-char.c | 19 +++++++++++++++++++ qmp-commands.hx | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+)
qapi-schema.json +22 -0
@@ -437,6 +437,28 @@ { 'command': 'query-chardev', 'returns': ['ChardevInfo'] } ## +# @ChardevBackendInfo: +# +# Information about a character device backend +# +# @name: The backend name +# +# Since: 2.0 +## +{ 'type': 'ChardevBackendInfo', 'data': {'name': 'str'} } + +## +# @query-chardev-backends: +# +# Returns information about character device backends. +# +# Returns: a list of @ChardevBackendInfo +# +# Since: 2.0 +## +{ 'command': 'query-chardev-backends', 'returns': ['ChardevBackendInfo'] } + +## # @DataFormat: # # An enumeration of data format.
qemu-char.c +19 -0
@@ -3432,6 +3432,25 @@ ChardevInfoList *qmp_query_chardev(Error **errp)return chr_list; } +ChardevBackendInfoList *qmp_query_chardev_backends (Error **errp) +{ +ChardevBackendInfoList *backend_list =NULL ; +CharDriver *c =NULL ; +GSList *i =NULL ; + +for (i = backends; i; i = i->next) { +ChardevBackendInfoList *info =g_malloc0 (sizeof (*info)); + c = i->data; + info->value =g_malloc0 (sizeof (*info->value)); + info->value->name =g_strdup (c->name); + + info->next = backend_list; + backend_list = info; + } + +return backend_list; +} +CharDriverState *qemu_chr_find (const char *name) {CharDriverState *chr;
qmp-commands.hx +41 -0
47 lines not on this page · raw message
--
1.8.5.3
Quoted 10 lines · Martin Kletzander
Introduce 'query-chardev-backends' QMP command which lists all supported character device backends.
Signed-off-by Martin Kletzander <[email protected]>---
v3:
- Omit commas at the end of list in JSON
v2:
- Version changed from "1.8.0" to "2.0"
Quoted 4 lines
qapi-schema.json | 22 ++++++++++++++++++++++ qemu-char.c | 19 +++++++++++++++++++ qmp-commands.hx | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 22 lines · On Sat, 1 Feb 2014 12:52:42 +0100 Martin Kletzander <[email protected]>…
Introduce 'query-chardev-backends' QMP command which lists all supported character device backends.
Signed-off-by Martin Kletzander <[email protected]>---
v3:
- Omit commas at the end of list in JSON
v2:
- Version changed from "1.8.0" to "2.0"qapi-schema.json | 22 ++++++++++++++++++++++ qemu-char.c | 19 +++++++++++++++++++ qmp-commands.hx | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+)qapi-schema.json +0
-0@@ -437,6 +437,28 @@ { 'command': 'query-chardev', 'returns': ['ChardevInfo'] }
qapi-schema.json line 448
Quoted 10 lines
qapi-schema.json +9
-0## +# @ChardevBackendInfo: +# +# Information about a character device backend +# +# @name: The backend name +# +# Since: 2.0 +## +{ 'type': 'ChardevBackendInfo', 'data': {'name': 'str'} }
We already have ChardevBackend, it's an union though. I'm wondering if you could change it to an enum and use it instead of plain 'str'?
qapi-schema.json line 453
Quoted 5 lines
qapi-schema.json +5
-0+ +## +# @query-chardev-backends: +# +# Returns information about character device backends.
Actually, it returns information about registered backends (registration is done by register_char_driver_qapi(). So, I think it's good thing to mention that this list is about available backends.
Quoted 96 lines
qapi-schema.json +8
-0+# +# Returns: a list of @ChardevBackendInfo +# +# Since: 2.0 +## +{ 'command': 'query-chardev-backends', 'returns': ['ChardevBackendInfo'] } + +## # @DataFormat: # # An enumeration of data format.qemu-char.c +19
-0@@ -3432,6 +3432,25 @@ ChardevInfoList *qmp_query_chardev(Error **errp)return chr_list; } +ChardevBackendInfoList *qmp_query_chardev_backends (Error **errp) +{ +ChardevBackendInfoList *backend_list =NULL ; +CharDriver *c =NULL ; +GSList *i =NULL ; + +for (i = backends; i; i = i->next) { +ChardevBackendInfoList *info =g_malloc0 (sizeof (*info)); + c = i->data; + info->value =g_malloc0 (sizeof (*info->value)); + info->value->name =g_strdup (c->name); + + info->next = backend_list; + backend_list = info; + } + +return backend_list; +} +CharDriverState *qemu_chr_find (const char *name) {CharDriverState *chr;qmp-commands.hx +41
-1@@ -1924,6 +1924,47 @@ EQMP }, SQMP +query-chardev-backends +------------- + +List available character device backends. + +Each backend is represented by a json-object, the returned value is a json-array +of all backends. + +Each json-object contains: + +- "name": backend name (json-string) + +Example: + +-> { "execute": "query-chardev-backends" } +<- { + "return":[ + { + "name":"udp" + }, + { + "name":"tcp" + }, + { + "name":"unix" + }, + { + "name":"spiceport" + } + ] + } + +EQMP + + { + .name = "query-chardev-backends", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_input_query_chardev_backends, + }, + +SQMP query-block ----------- --1.8.5.3
Quoted 6 lines · Luiz Capitulino
Quoted 3 lines · On Sat, 1 Feb 2014 12:52:42 +0100 Martin Kletzander <[email protected]>…
Introduce 'query-chardev-backends' QMP command which lists all supported character device backends.
Quoted 8 lines
qapi-schema.json line 448
Quoted 5 lines
Signed-off-by Martin Kletzander <[email protected]>---
qapi-schema.json +2
-0+## +{ 'type': 'ChardevBackendInfo', 'data': {'name': 'str'} }We already have ChardevBackend, it's an union though. I'm wondering if you could change it to an enum and use it instead of plain 'str'?
Hmm, right now, the ChardevBackend union pre-dates when we added flat unions. For flat unions, we can set a discriminator to be an enum type [1], at which point the code generator then validates that we cover all values of the enum in branches of the union; maybe it's worth retro-fitting simple unions to also take advantage of the additional coverage of the discriminator being an enum.
That is, right now, we have:
{ 'union': 'ChardevBackend', 'data': { 'file' : 'ChardevFile',
'serial' : 'ChardevHostdev',
and we also document in qapi-code-gen.txt that when using 'discriminator', you either have to have a base class (and the discriminator is a string-typed member of that base class), or the discriminator is {} because it is an anonymous union. But I'm asking about yet another situation, of having a typed discriminator with no change to the wire format (no base class), something like:
{ 'enum': 'ChardevBackendTypes', [ 'file', 'serial', ... ] } { 'union': 'ChardevBackend',
'discriminator': 'ChardevBackendTypes',
'data': { 'file': 'ChardevFile', ...
The benefit of such a plan is that we then have an introspectible enum of all possible backends known at compile time (ChardevBackendTypes), and the new addition in this patch becomes:
{ 'type': 'ChardevBackendInfo',
'data': {'name', 'ChardevBackendTypes' } }
rather than raw 'str', while still allowing potential future additions of additional backend info. Note that there would still be a difference between ChardevBackendTypes (an enum of all possible known types at compile time) vs. query-chardev-backends (a runtime list of the possible types that can be used for this particular machine, even if it is a subset of all possible ChardevBackendTypes).
[1] actually, did those patches ever get applied, and we just missed documenting it in qapi-code-gen.txt, or are they still pending review?
Quoted 10 lines
qapi-schema.json line 453
Quoted 6 lines
qapi-schema.json +5
-0+ +## +# @query-chardev-backends: +# +# Returns information about character device backends.Actually, it returns information about registered backends (registration is done by
register_char_driver_qapi(). So, I think it's good thing to mention that this list is about available backends.
Again, it sounds like you want to emphasize an enum of all possible types (compile time, learned via introspection, whenever we get that) vs. registered backends (possibly a subset based on what libraries were used in building this qemu binary, and learned via the new QMP command).
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 16 lines · Eric Blake
Quoted 6 lines · Luiz Capitulino
Quoted 3 lines · On Sat, 1 Feb 2014 12:52:42 +0100 Martin Kletzander <[email protected]>…
Introduce 'query-chardev-backends' QMP command which lists all supported character device backends.
Quoted 8 lines
qapi-schema.json line 448
Quoted 5 lines
Signed-off-by Martin Kletzander <[email protected]>---
qapi-schema.json +2
-0+## +{ 'type': 'ChardevBackendInfo', 'data': {'name': 'str'} }We already have ChardevBackend, it's an union though. I'm wondering if you could change it to an enum and use it instead of plain 'str'?
Quoted 6 lines
Hmm, right now, the ChardevBackend union pre-dates when we added flat unions. For flat unions, we can set a discriminator to be an enum type [1], at which point the code generator then validates that we cover all values of the enum in branches of the union; maybe it's worth retro-fitting simple unions to also take advantage of the additional coverage of the discriminator being an enum.
Yes, and Wenchao Xia has been working towards that: "[PATCH V5 00/10] qapi script: support enum as discriminator and better enum name".
Quoted 31 lines
That is, right now, we have:
{ 'union': 'ChardevBackend', 'data': { 'file' : 'ChardevFile',
'serial' : 'ChardevHostdev',and we also document in qapi-code-gen.txt that when using 'discriminator', you either have to have a base class (and the discriminator is a string-typed member of that base class), or the discriminator is {} because it is an anonymous union. But I'm asking about yet another situation, of having a typed discriminator with no change to the wire format (no base class), something like:
{ 'enum': 'ChardevBackendTypes', [ 'file', 'serial', ... ] } { 'union': 'ChardevBackend',
'discriminator': 'ChardevBackendTypes',
'data': { 'file': 'ChardevFile', ...The benefit of such a plan is that we then have an introspectible enum of all possible backends known at compile time (ChardevBackendTypes), and the new addition in this patch becomes:
{ 'type': 'ChardevBackendInfo',
'data': {'name', 'ChardevBackendTypes' } }rather than raw 'str', while still allowing potential future additions of additional backend info. Note that there would still be a difference between ChardevBackendTypes (an enum of all possible known types at compile time) vs. query-chardev-backends (a runtime list of the possible types that can be used for this particular machine, even if it is a subset of all possible ChardevBackendTypes).
Quoted 2 lines
[1] actually, did those patches ever get applied, and we just missed documenting it in qapi-code-gen.txt, or are they still pending review?
By "those", do you mean Wenchao Xia's patches?
[...]
Quoted 10 lines · Markus Armbruster
Quoted 7 lines · Eric Blake
Hmm, right now, the ChardevBackend union pre-dates when we added flat unions. For flat unions, we can set a discriminator to be an enum type [1], at which point the code generator then validates that we cover all values of the enum in branches of the union; maybe it's worth retro-fitting simple unions to also take advantage of the additional coverage of the discriminator being an enum.
Quoted 8 lines
Yes, and Wenchao Xia has been working towards that: "[PATCH V5 00/10] qapi script: support enum as discriminator and better enum name".
Quoted 2 lines
[1] actually, did those patches ever get applied, and we just missed documenting it in qapi-code-gen.txt, or are they still pending review?
By "those", do you mean Wenchao Xia's patches?
Maybe my [1] to tie together two widely separated paragraphs wasn't obvious, but yes, I meant Wenchao's tests. Plus they just got reposted:
https://lists.gnu.org/archive/html/qemu-devel/2014-02/msg01706.html
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 47 lines · On Mon, 10 Feb 2014 14:36:20 -0700 Eric Blake <[email protected]> wrote:
Quoted 6 lines · Luiz Capitulino
Quoted 3 lines · On Sat, 1 Feb 2014 12:52:42 +0100 Martin Kletzander <[email protected]>…
Introduce 'query-chardev-backends' QMP command which lists all supported character device backends.
Quoted 8 lines
qapi-schema.json line 448
Quoted 5 lines
Signed-off-by Martin Kletzander <[email protected]>---
qapi-schema.json +2
-0+## +{ 'type': 'ChardevBackendInfo', 'data': {'name': 'str'} }We already have ChardevBackend, it's an union though. I'm wondering if you could change it to an enum and use it instead of plain 'str'?
Hmm, right now, the ChardevBackend union pre-dates when we added flat unions. For flat unions, we can set a discriminator to be an enum type [1], at which point the code generator then validates that we cover all values of the enum in branches of the union; maybe it's worth retro-fitting simple unions to also take advantage of the additional coverage of the discriminator being an enum.
That is, right now, we have:
{ 'union': 'ChardevBackend', 'data': { 'file' : 'ChardevFile',
'serial' : 'ChardevHostdev',and we also document in qapi-code-gen.txt that when using 'discriminator', you either have to have a base class (and the discriminator is a string-typed member of that base class), or the discriminator is {} because it is an anonymous union. But I'm asking about yet another situation, of having a typed discriminator with no change to the wire format (no base class), something like:
{ 'enum': 'ChardevBackendTypes', [ 'file', 'serial', ... ] } { 'union': 'ChardevBackend',
'discriminator': 'ChardevBackendTypes',
'data': { 'file': 'ChardevFile', ...The benefit of such a plan is that we then have an introspectible enum of all possible backends known at compile time (ChardevBackendTypes), and the new addition in this patch becomes:
{ 'type': 'ChardevBackendInfo',
'data': {'name', 'ChardevBackendTypes' } }
Quoted 6 lines
rather than raw 'str', while still allowing potential future additions of additional backend info. Note that there would still be a difference between ChardevBackendTypes (an enum of all possible known types at compile time) vs. query-chardev-backends (a runtime list of the possible types that can be used for this particular machine, even if it is a subset of all possible ChardevBackendTypes).
Do you envision whether, by applying Martin's patch now, it would be compatible to do what you suggest on top?
Quoted 20 lines
[1] actually, did those patches ever get applied, and we just missed documenting it in qapi-code-gen.txt, or are they still pending review?
Quoted 10 lines
qapi-schema.json line 453
Quoted 6 lines
qapi-schema.json +5
-0+ +## +# @query-chardev-backends: +# +# Returns information about character device backends.Actually, it returns information about registered backends (registration is done by
register_char_driver_qapi(). So, I think it's good thing to mention that this list is about available backends.Again, it sounds like you want to emphasize an enum of all possible types (compile time, learned via introspection, whenever we get that) vs. registered backends (possibly a subset based on what libraries were used in building this qemu binary, and learned via the new QMP command).
Quoted 33 lines · Luiz Capitulino
Quoted 26 lines
Quoted 5 lines
qapi-schema.json line 448
Quoted 2 lines
qapi-schema.json +2
-0+## +{ 'type': 'ChardevBackendInfo', 'data': {'name': 'str'} }We already have ChardevBackend, it's an union though. I'm wondering if you could change it to an enum and use it instead of plain 'str'?
and we also document in qapi-code-gen.txt that when using 'discriminator', you either have to have a base class (and the discriminator is a string-typed member of that base class), or the discriminator is {} because it is an anonymous union. But I'm asking about yet another situation, of having a typed discriminator with no change to the wire format (no base class), something like:
{ 'enum': 'ChardevBackendTypes', [ 'file', 'serial', ... ] } { 'union': 'ChardevBackend',
'discriminator': 'ChardevBackendTypes',
'data': { 'file': 'ChardevFile', ...The benefit of such a plan is that we then have an introspectible enum of all possible backends known at compile time (ChardevBackendTypes), and the new addition in this patch becomes:
{ 'type': 'ChardevBackendInfo',
'data': {'name', 'ChardevBackendTypes' } }Quoted 6 lines
rather than raw 'str', while still allowing potential future additions of additional backend info. Note that there would still be a difference between ChardevBackendTypes (an enum of all possible known types at compile time) vs. query-chardev-backends (a runtime list of the possible types that can be used for this particular machine, even if it is a subset of all possible ChardevBackendTypes).
Quoted 2 lines
Do you envision whether, by applying Martin's patch now, it would be compatible to do what you suggest on top?
Yes, changing 'str' to an enum type should not cause any change to the actual QMP wire format, so it is an improvement that could be made later. I see nothing preventing us from taking Martin's patch as currently written, even if we do add later patches to make it more typesafe.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Luiz Capitulino
AppliedQuoted 4 lines · On Sat, 1 Feb 2014 12:52:42 +0100 Martin Kletzander <[email protected]>…
Introduce 'query-chardev-backends' QMP command which lists all supported character device backends.
Signed-off-by Martin Kletzander <[email protected]>
Applied to the qmp branch, thanks.
Quoted 129 lines
---
v3:
- Omit commas at the end of list in JSON
v2:
- Version changed from "1.8.0" to "2.0"qapi-schema.json | 22 ++++++++++++++++++++++ qemu-char.c | 19 +++++++++++++++++++ qmp-commands.hx | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+)qapi-schema.json +22
-0@@ -437,6 +437,28 @@ { 'command': 'query-chardev', 'returns': ['ChardevInfo'] } ## +# @ChardevBackendInfo: +# +# Information about a character device backend +# +# @name: The backend name +# +# Since: 2.0 +## +{ 'type': 'ChardevBackendInfo', 'data': {'name': 'str'} } + +## +# @query-chardev-backends: +# +# Returns information about character device backends. +# +# Returns: a list of @ChardevBackendInfo +# +# Since: 2.0 +## +{ 'command': 'query-chardev-backends', 'returns': ['ChardevBackendInfo'] } + +## # @DataFormat: # # An enumeration of data format.qemu-char.c +19
-0@@ -3432,6 +3432,25 @@ ChardevInfoList *qmp_query_chardev(Error **errp)return chr_list; } +ChardevBackendInfoList *qmp_query_chardev_backends (Error **errp) +{ +ChardevBackendInfoList *backend_list =NULL ; +CharDriver *c =NULL ; +GSList *i =NULL ; + +for (i = backends; i; i = i->next) { +ChardevBackendInfoList *info =g_malloc0 (sizeof (*info)); + c = i->data; + info->value =g_malloc0 (sizeof (*info->value)); + info->value->name =g_strdup (c->name); + + info->next = backend_list; + backend_list = info; + } + +return backend_list; +} +CharDriverState *qemu_chr_find (const char *name) {CharDriverState *chr;qmp-commands.hx +41
-1@@ -1924,6 +1924,47 @@ EQMP }, SQMP +query-chardev-backends +------------- + +List available character device backends. + +Each backend is represented by a json-object, the returned value is a json-array +of all backends. + +Each json-object contains: + +- "name": backend name (json-string) + +Example: + +-> { "execute": "query-chardev-backends" } +<- { + "return":[ + { + "name":"udp" + }, + { + "name":"tcp" + }, + { + "name":"unix" + }, + { + "name":"spiceport" + } + ] + } + +EQMP + + { + .name = "query-chardev-backends", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_input_query_chardev_backends, + }, + +SQMP query-block ----------- --1.8.5.3