qom-get [for 2.8]
cover qom-get [for 2.8]
From: "Dr. David Alan Gilbert" <[email protected]>
Hi,
I'd noticed a while ago the lack of qom-get and
was about to implement it, when I noticed Andreas
had implemented it back in March 2015 as part of the larger patch series 'qom: HMP commands to supersede info qtree' ( [email protected] ) which was a v2 of a series from 2014 of his.
Here is a forward ported version of just the pair of patches that are needed for qom-get.
Usage examples:
(qemu) qom-get /backend/console[0]/device/vga.rom[0] size 65536 (0x10000)
(qemu) qom-get /machine smm
"auto"
(qemu) qom-get /machine rtc-time
struct type not implemented
Dave
Dr. David Alan Gilbert (2):
qapi: Stub out StringOutputVisitor struct support
qom: Implement qom-get HMP command
hmp-commands.hx | 13 +++++++++++++ hmp.c | 23 +++++++++++++++++++++++ hmp.h | 1 + qapi/string-output-visitor.c | 13 +++++++++++++ 4 files changed, 50 insertions(+)
Signature · 1 line
2.7.4
PATCH 1/2 qapi: Stub out StringOutputVisitor struct support
From: "Dr. David Alan Gilbert" <[email protected]>
Avoid a segfault when visiting, e.g., the QOM rtc-time property, by implementing the struct callbacks and raising an Error.
Updated for changed interface:
--- qapi/string-output-visitor.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
qapi/string-output-visitor.c +13 -0
@@ -12,6 +12,7 @@#include "qemu/osdep.h" #include "qemu-common.h" +#include "qapi/error.h" #include "qapi/string-output-visitor.h" #include "qapi/visitor-impl.h" #include "qemu/host-utils.h"
@@ -266,6 +267,16 @@ static void print_type_number(Visitor *v, const char *name, double *obj,string_output_set (sov,g_strdup_printf ("%f" , *obj)); } +static void start_struct (Visitor *v,const char *name,void **obj,size_t size, +Error **errp) +{ +error_setg (errp,"struct type not implemented" ); +} + +static void end_struct (Visitor *v,void **obj) +{ +} +static void start_list (Visitor *v,const char *name,GenericList **list,size_t size,Error **errp)
@@ -356,6 +367,8 @@ Visitor *string_output_visitor_new(bool human, char **result) v->visitor.end_list = end_list; v->visitor.complete = string_output_complete; v->visitor.free = string_output_free; + v->visitor.start_struct = start_struct; + v->visitor.end_struct = end_struct;return &v->visitor; }
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH 1/2] qapi: Stub out StringOutputVisitor struct support
Quoted 29 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
Avoid a segfault when visiting, e.g., the QOM rtc-time property, by implementing the struct callbacks and raising an Error.
Signed-off-by Andreas Färber <[email protected]>Updated for changed interface:
Signed-off-by Dr. David Alan Gilbert <[email protected]>--- qapi/string-output-visitor.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)qapi/string-output-visitor.c +1
-0@@ -12,6 +12,7 @@#include "qemu/osdep.h" #include "qemu-common.h" +#include "qapi/error.h" #include "qapi/string-output-visitor.h" #include "qapi/visitor-impl.h" #include "qemu/host-utils.h" @@ -266,6 +267,16 @@ static void print_type_number(Visitor *v, const char *name, double *obj,string_output_set (sov,g_strdup_printf ("%f" , *obj)); }
qapi/string-output-visitor.c static void print_type_number(Visitor *v, const char *name, double *obj, · line 279
Quoted 10 lines
qapi/string-output-visitor.c +10
-0+static void start_struct (Visitor *v,const char *name,void **obj,size_t size, +Error **errp) +{ +error_setg (errp,"struct type not implemented" ); +} + +static void end_struct (Visitor *v,void **obj) +{ +} +
This is just one of the several things this visitor doesn't implement. See the comment in string-output-visitor.h.
String input visitor and options visitor have similar holes; see the comments in string-input-visitor.h and opts-visitor.h.
Should we change all of them together to report errors instead of crash? With common "error out because this isn't implemented" methods?
Quoted 12 lines
qapi/string-output-visitor.c +2
-0static void start_list (Visitor *v,const char *name,GenericList **list,size_t size,Error **errp)@@ -356,6 +367,8 @@ Visitor *string_output_visitor_new(bool human, char **result) v->visitor.end_list = end_list; v->visitor.complete = string_output_complete; v->visitor.free = string_output_free; + v->visitor.start_struct = start_struct; + v->visitor.end_struct = end_struct;return &v->visitor; }
Re: [Qemu-devel] [PATCH 1/2] qapi: Stub out StringOutputVisitor struct support
Quoted 45 lines · * Markus Armbruster ([email protected]) wrote:
Quoted 29 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
Avoid a segfault when visiting, e.g., the QOM rtc-time property, by implementing the struct callbacks and raising an Error.
Signed-off-by Andreas Färber <[email protected]>Updated for changed interface:
Signed-off-by Dr. David Alan Gilbert <[email protected]>--- qapi/string-output-visitor.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)qapi/string-output-visitor.c +1
-0@@ -12,6 +12,7 @@#include "qemu/osdep.h" #include "qemu-common.h" +#include "qapi/error.h" #include "qapi/string-output-visitor.h" #include "qapi/visitor-impl.h" #include "qemu/host-utils.h" @@ -266,6 +267,16 @@ static void print_type_number(Visitor *v, const char *name, double *obj,string_output_set (sov,g_strdup_printf ("%f" , *obj)); }qapi/string-output-visitor.c static void print_type_number(Visitor *v, const char *name, double *obj, · line 279
Quoted 10 lines
qapi/string-output-visitor.c +10
-0+static void start_struct (Visitor *v,const char *name,void **obj,size_t size, +Error **errp) +{ +error_setg (errp,"struct type not implemented" ); +} + +static void end_struct (Visitor *v,void **obj) +{ +} +This is just one of the several things this visitor doesn't implement. See the comment in
string-output-visitor.h.
Quoted 5 lines
String input visitor and options visitor have similar holes; see the comments in
string-input-visitor.handopts-visitor.h.Should we change all of them together to report errors instead of crash? With common "error out because this isn't implemented" methods?
In that case wouldn't it be best to change visit_start_struct/visit_end_struct to do the check (Like visit_check_struct does).
Dave
Quoted 11 lines
Quoted 11 lines
qapi/string-output-visitor.c +2
-0static void start_list (Visitor *v,const char *name,GenericList **list,size_t size,Error **errp)@@ -356,6 +367,8 @@ Visitor *string_output_visitor_new(bool human, char **result) v->visitor.end_list = end_list; v->visitor.complete = string_output_complete; v->visitor.free = string_output_free; + v->visitor.start_struct = start_struct; + v->visitor.end_struct = end_struct;
Quoted 2 lines
qapi/string-output-visitor.c Visitor *string_output_visitor_new(bool human, char **result) · line 374
Quoted 2 lines
qapi/string-output-visitor.c +0
-0return &v->visitor; }
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH 1/2] qapi: Stub out StringOutputVisitor struct support
Quoted 46 lines · Dr. David Alan Gilbert
Quoted 45 lines · * Markus Armbruster ([email protected]) wrote:
Quoted 29 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
Avoid a segfault when visiting, e.g., the QOM rtc-time property, by implementing the struct callbacks and raising an Error.
Signed-off-by Andreas Färber <[email protected]>Updated for changed interface:
Signed-off-by Dr. David Alan Gilbert <[email protected]>--- qapi/string-output-visitor.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)qapi/string-output-visitor.c +1
-0@@ -12,6 +12,7 @@#include "qemu/osdep.h" #include "qemu-common.h" +#include "qapi/error.h" #include "qapi/string-output-visitor.h" #include "qapi/visitor-impl.h" #include "qemu/host-utils.h" @@ -266,6 +267,16 @@ static void print_type_number(Visitor *v, const char *name, double *obj,string_output_set (sov,g_strdup_printf ("%f" , *obj)); }qapi/string-output-visitor.c static void print_type_number(Visitor *v, const char *name, double *obj, · line 279
Quoted 10 lines
qapi/string-output-visitor.c +10
-0+static void start_struct (Visitor *v,const char *name,void **obj,size_t size, +Error **errp) +{ +error_setg (errp,"struct type not implemented" ); +} + +static void end_struct (Visitor *v,void **obj) +{ +} +This is just one of the several things this visitor doesn't implement. See the comment in
string-output-visitor.h.
Quoted 8 lines
Quoted 5 lines
String input visitor and options visitor have similar holes; see the comments in
string-input-visitor.handopts-visitor.h.Should we change all of them together to report errors instead of crash? With common "error out because this isn't implemented" methods?
In that case wouldn't it be best to change visit_start_struct/visit_end_struct to do the check (Like
visit_check_structdoes).
In my opinion.
if (v->foo) {
v->foo(...);
} else {
... default action ...
}is an anti-pattern. Wrap the default action in a default method, and put that in the function pointer.
Re: [Qemu-devel] [PATCH 1/2] qapi: Stub out StringOutputVisitor struct support
Quoted 59 lines · * Markus Armbruster ([email protected]) wrote:
Quoted 46 lines · Dr. David Alan Gilbert
Quoted 45 lines · * Markus Armbruster ([email protected]) wrote:
Quoted 29 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
Avoid a segfault when visiting, e.g., the QOM rtc-time property, by implementing the struct callbacks and raising an Error.
Signed-off-by Andreas Färber <[email protected]>Updated for changed interface:
Signed-off-by Dr. David Alan Gilbert <[email protected]>--- qapi/string-output-visitor.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)qapi/string-output-visitor.c +1
-0@@ -12,6 +12,7 @@#include "qemu/osdep.h" #include "qemu-common.h" +#include "qapi/error.h" #include "qapi/string-output-visitor.h" #include "qapi/visitor-impl.h" #include "qemu/host-utils.h" @@ -266,6 +267,16 @@ static void print_type_number(Visitor *v, const char *name, double *obj,string_output_set (sov,g_strdup_printf ("%f" , *obj)); }qapi/string-output-visitor.c static void print_type_number(Visitor *v, const char *name, double *obj, · line 279
Quoted 10 lines
qapi/string-output-visitor.c +10
-0+static void start_struct (Visitor *v,const char *name,void **obj,size_t size, +Error **errp) +{ +error_setg (errp,"struct type not implemented" ); +} + +static void end_struct (Visitor *v,void **obj) +{ +} +This is just one of the several things this visitor doesn't implement. See the comment in
string-output-visitor.h.Quoted 8 lines
Quoted 5 lines
String input visitor and options visitor have similar holes; see the comments in
string-input-visitor.handopts-visitor.h.Should we change all of them together to report errors instead of crash? With common "error out because this isn't implemented" methods?
In that case wouldn't it be best to change visit_start_struct/visit_end_struct to do the check (Like
visit_check_structdoes).In my opinion.
Quoted 8 lines
if (v->foo) { v->foo(...); } else { ... default action ... }is an anti-pattern. Wrap the default action in a default method, and put that in the function pointer.
I've got some sympathy to that, but with the way our visitors are built that's a pain.
Lets say you add a new eat_struct method, and a eat_struct_default implementation, now you have to go around and fix all the visitor implementations to initialise
their eat_struct member to eat_struct_default. Of course you'll forget some
and then we'll end up segging when you fall down the NULL pointer.
Now, if our visitors had nice shared constructor functions that wouldn't be a problem, and you wouldn't need most of the visit_ wrapper functions;
but they don't, so the if (v->foo) { ... } else { error; } is the
current cleanest we can do.
Dave
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH 1/2] qapi: Stub out StringOutputVisitor struct support
Quoted 77 lines · Dr. David Alan Gilbert
Quoted 59 lines · * Markus Armbruster ([email protected]) wrote:
Quoted 46 lines · Dr. David Alan Gilbert
Quoted 45 lines · * Markus Armbruster ([email protected]) wrote:
Quoted 29 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
Avoid a segfault when visiting, e.g., the QOM rtc-time property, by implementing the struct callbacks and raising an Error.
Signed-off-by Andreas Färber <[email protected]>Updated for changed interface:
Signed-off-by Dr. David Alan Gilbert <[email protected]>--- qapi/string-output-visitor.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)qapi/string-output-visitor.c +1
-0@@ -12,6 +12,7 @@#include "qemu/osdep.h" #include "qemu-common.h" +#include "qapi/error.h" #include "qapi/string-output-visitor.h" #include "qapi/visitor-impl.h" #include "qemu/host-utils.h" @@ -266,6 +267,16 @@ static void print_type_number(Visitor *v, const char *name, double *obj,string_output_set (sov,g_strdup_printf ("%f" , *obj)); }qapi/string-output-visitor.c static void print_type_number(Visitor *v, const char *name, double *obj, · line 279
Quoted 10 lines
qapi/string-output-visitor.c +10
-0+static void start_struct (Visitor *v,const char *name,void **obj,size_t size, +Error **errp) +{ +error_setg (errp,"struct type not implemented" ); +} + +static void end_struct (Visitor *v,void **obj) +{ +} +This is just one of the several things this visitor doesn't implement. See the comment in
string-output-visitor.h.Quoted 8 lines
Quoted 5 lines
String input visitor and options visitor have similar holes; see the comments in
string-input-visitor.handopts-visitor.h.Should we change all of them together to report errors instead of crash? With common "error out because this isn't implemented" methods?
In that case wouldn't it be best to change visit_start_struct/visit_end_struct to do the check (Like
visit_check_structdoes).In my opinion.
Quoted 8 lines
if (v->foo) { v->foo(...); } else { ... default action ... }is an anti-pattern. Wrap the default action in a default method, and put that in the function pointer.
I've got some sympathy to that, but with the way our visitors are built that's a pain.
Lets say you add a new
eat_structmethod, and aeat_struct_defaultimplementation, now you have to go around and fix all the visitor implementations to initialise
theireat_structmember toeat_struct_default. Of course you'll forget some
and then we'll end up segging when you fall down the NULL pointer.
Quoted 4 lines
Now, if our visitors had nice shared constructor functions that wouldn't be a problem, and you wouldn't need most of the
visit_wrapper functions;
but they don't, so the if (v->foo) { ... } else { error; } is the
current cleanest we can do.
Well, it's the cleanest we can do as long as we constrain ourselves not to do much :)
We currently have seven visitors. Every single one defines a FOO_visitor_new() function that basically looks like this:
Visitor *FOO_visitor_new(... whatever ...)
{
FOOVisitor v = g_malloc0(sizeof(*v));
v->visitor.type = ...
... initialize more of v->visitor ...
... initialize other members of *v, if any ...
return &v->visitor;
}I grant you that putting sensible defaults into v->visitor by initializing them correctly in all the FOO_visitor_new() functions is a bit of pain. Not much pain; there are only seven. Anyway, there are several obvious ways to do this without pain:
(1) Have a visitor core function to set the defaults, call it first.
(2) Replace g_malloc0() by a visitor core function that additionally sets the defaults. Basically fusing g_malloc0() into (1)'s function.
(3) Have a visitor core function that replaces null methods by defaults, and call it last. This function can also check you filled out in the mandatory bits. Have it return the visitor, so you can make it a tail call: return visitor_check(&v->visitor).
Re: [Qemu-devel] [PATCH 1/2] qapi: Stub out StringOutputVisitor struct support
Quoted 79 lines · * Markus Armbruster ([email protected]) wrote:
Quoted 77 lines · Dr. David Alan Gilbert
Quoted 59 lines · * Markus Armbruster ([email protected]) wrote:
Quoted 46 lines · Dr. David Alan Gilbert
Quoted 45 lines · * Markus Armbruster ([email protected]) wrote:
Quoted 29 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
Avoid a segfault when visiting, e.g., the QOM rtc-time property, by implementing the struct callbacks and raising an Error.
Signed-off-by Andreas Färber <[email protected]>Updated for changed interface:
Signed-off-by Dr. David Alan Gilbert <[email protected]>--- qapi/string-output-visitor.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)qapi/string-output-visitor.c +1
-0@@ -12,6 +12,7 @@#include "qemu/osdep.h" #include "qemu-common.h" +#include "qapi/error.h" #include "qapi/string-output-visitor.h" #include "qapi/visitor-impl.h" #include "qemu/host-utils.h" @@ -266,6 +267,16 @@ static void print_type_number(Visitor *v, const char *name, double *obj,string_output_set (sov,g_strdup_printf ("%f" , *obj)); }qapi/string-output-visitor.c static void print_type_number(Visitor *v, const char *name, double *obj, · line 279
Quoted 10 lines
qapi/string-output-visitor.c +10
-0+static void start_struct (Visitor *v,const char *name,void **obj,size_t size, +Error **errp) +{ +error_setg (errp,"struct type not implemented" ); +} + +static void end_struct (Visitor *v,void **obj) +{ +} +This is just one of the several things this visitor doesn't implement. See the comment in
string-output-visitor.h.Quoted 8 lines
Quoted 5 lines
String input visitor and options visitor have similar holes; see the comments in
string-input-visitor.handopts-visitor.h.Should we change all of them together to report errors instead of crash? With common "error out because this isn't implemented" methods?
In that case wouldn't it be best to change visit_start_struct/visit_end_struct to do the check (Like
visit_check_structdoes).In my opinion.
Quoted 8 lines
if (v->foo) { v->foo(...); } else { ... default action ... }is an anti-pattern. Wrap the default action in a default method, and put that in the function pointer.
I've got some sympathy to that, but with the way our visitors are built that's a pain.
Lets say you add a new
eat_structmethod, and aeat_struct_defaultimplementation, now you have to go around and fix all the visitor implementations to initialise
theireat_structmember toeat_struct_default. Of course you'll forget some
and then we'll end up segging when you fall down the NULL pointer.
Quoted 7 lines
Quoted 4 lines
Now, if our visitors had nice shared constructor functions that wouldn't be a problem, and you wouldn't need most of the
visit_wrapper functions;
but they don't, so the if (v->foo) { ... } else { error; } is the
current cleanest we can do.Well, it's the cleanest we can do as long as we constrain ourselves not to do much :)
Yes, although I hate to turn a patchset for a tiny feature into a fix-all-the-broken-stuff set!
Quoted 19 lines
We currently have seven visitors. Every single one defines a
FOO_visitor_new()function that basically looks like this:Visitor *FOO_visitor_new(... whatever ...) { FOOVisitor v = g_malloc0(sizeof(*v)); v->visitor.type = ... ... initialize more of v->visitor ... ... initialize other members of *v, if any ... return &v->visitor; }I grant you that putting sensible defaults into
v->visitorby initializing them correctly in all theFOO_visitor_new()functions is a bit of pain. Not much pain; there are only seven. Anyway, there are several obvious ways to do this without pain:
Quoted 5 lines
(1) Have a visitor core function to set the defaults, call it first.
(2) Replace
g_malloc0()by a visitor core function that additionally sets the defaults. Basically fusingg_malloc0()into (1)'s function.
That's my preferred way of doing it, chaining constructors.
Dave
Quoted 4 lines
(3) Have a visitor core function that replaces null methods by defaults, and call it last. This function can also check you filled out in the mandatory bits. Have it return the visitor, so you can make it a tail call: return
visitor_check(&v->visitor).
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH 1/2] qapi: Stub out StringOutputVisitor struct support
Quoted 85 lines · Dr. David Alan Gilbert
Quoted 84 lines · * Markus Armbruster ([email protected]) wrote:
Quoted 81 lines · Dr. David Alan Gilbert
Quoted 59 lines · * Markus Armbruster ([email protected]) wrote:
Quoted 46 lines · Dr. David Alan Gilbert
Quoted 45 lines · * Markus Armbruster ([email protected]) wrote:
Quoted 29 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
Avoid a segfault when visiting, e.g., the QOM rtc-time property, by implementing the struct callbacks and raising an Error.
Signed-off-by Andreas Färber <[email protected]>Updated for changed interface:
Signed-off-by Dr. David Alan Gilbert <[email protected]>--- qapi/string-output-visitor.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)qapi/string-output-visitor.c +1
-0@@ -12,6 +12,7 @@#include "qemu/osdep.h" #include "qemu-common.h" +#include "qapi/error.h" #include "qapi/string-output-visitor.h" #include "qapi/visitor-impl.h" #include "qemu/host-utils.h" @@ -266,6 +267,16 @@ static void print_type_number(Visitor *v, const char *name, double *obj,string_output_set (sov,g_strdup_printf ("%f" , *obj)); }qapi/string-output-visitor.c static void print_type_number(Visitor *v, const char *name, double *obj, · line 279
Quoted 10 lines
qapi/string-output-visitor.c +10
-0+static void start_struct (Visitor *v,const char *name,void **obj,size_t size, +Error **errp) +{ +error_setg (errp,"struct type not implemented" ); +} + +static void end_struct (Visitor *v,void **obj) +{ +} +This is just one of the several things this visitor doesn't implement. See the comment in
string-output-visitor.h.Quoted 8 lines
Quoted 5 lines
String input visitor and options visitor have similar holes; see the comments in
string-input-visitor.handopts-visitor.h.Should we change all of them together to report errors instead of crash? With common "error out because this isn't implemented" methods?
In that case wouldn't it be best to change visit_start_struct/visit_end_struct to do the check (Like
visit_check_structdoes).In my opinion.
Quoted 8 lines
if (v->foo) { v->foo(...); } else { ... default action ... }is an anti-pattern. Wrap the default action in a default method, and put that in the function pointer.
I've got some sympathy to that, but with the way our visitors are built that's a pain.
Lets say you add a new
eat_structmethod, and aeat_struct_defaultimplementation, now you have to go around and fix all the visitor implementations to initialise
theireat_structmember toeat_struct_default. Of course you'll forget some
and then we'll end up segging when you fall down the NULL pointer.Now, if our visitors had nice shared constructor functions that wouldn't be a problem, and you wouldn't need most of the
visit_wrapper functions;
but they don't, so the if (v->foo) { ... } else { error; } is the
current cleanest we can do.
Quoted 5 lines
Quoted 2 lines
Well, it's the cleanest we can do as long as we constrain ourselves not to do much :)
Yes, although I hate to turn a patchset for a tiny feature into a fix-all-the-broken-stuff set!
I know the feeling...
I'd love to accommodate you, but I'm afraid the work is too incomplete in its current state. The string output visitor doesn't implement a number of things besides structs. To convince me that your qom-get won't crash because of that, you'd have to show that these other things cannot happen with qom-get. Implementing the missing parts instead would probably be easier. And then one of the general solutions discussed below would hardly be more work, for more value.
Quoted 19 lines
Quoted 19 lines
We currently have seven visitors. Every single one defines a
FOO_visitor_new()function that basically looks like this:Visitor *FOO_visitor_new(... whatever ...) { FOOVisitor v = g_malloc0(sizeof(*v)); v->visitor.type = ... ... initialize more of v->visitor ... ... initialize other members of *v, if any ... return &v->visitor; }I grant you that putting sensible defaults into
v->visitorby initializing them correctly in all theFOO_visitor_new()functions is a bit of pain. Not much pain; there are only seven. Anyway, there are several obvious ways to do this without pain:
Quoted 7 lines
Quoted 5 lines
(1) Have a visitor core function to set the defaults, call it first.
(2) Replace
g_malloc0()by a visitor core function that additionally sets the defaults. Basically fusingg_malloc0()into (1)'s function.That's my preferred way of doing it, chaining constructors.
It's a fine way of doing it when you only ever create the things in one way. Here, with g_malloc0().
Would you like to wait for the Dan's visitor work? Perhaps the problem goes away there...
Quoted 8 lines
Dave
Quoted 4 lines
(3) Have a visitor core function that replaces null methods by defaults, and call it last. This function can also check you filled out in the mandatory bits. Have it return the visitor, so you can make it a tail call: return
visitor_check(&v->visitor).--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH 1/2] qapi: Stub out StringOutputVisitor struct support
Quoted 128 lines · * Markus Armbruster ([email protected]) wrote:
Quoted 85 lines · Dr. David Alan Gilbert
Quoted 84 lines · * Markus Armbruster ([email protected]) wrote:
Quoted 81 lines · Dr. David Alan Gilbert
Quoted 59 lines · * Markus Armbruster ([email protected]) wrote:
Quoted 46 lines · Dr. David Alan Gilbert
Quoted 45 lines · * Markus Armbruster ([email protected]) wrote:
Quoted 29 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
Avoid a segfault when visiting, e.g., the QOM rtc-time property, by implementing the struct callbacks and raising an Error.
Signed-off-by Andreas Färber <[email protected]>Updated for changed interface:
Signed-off-by Dr. David Alan Gilbert <[email protected]>--- qapi/string-output-visitor.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)qapi/string-output-visitor.c +1
-0@@ -12,6 +12,7 @@#include "qemu/osdep.h" #include "qemu-common.h" +#include "qapi/error.h" #include "qapi/string-output-visitor.h" #include "qapi/visitor-impl.h" #include "qemu/host-utils.h" @@ -266,6 +267,16 @@ static void print_type_number(Visitor *v, const char *name, double *obj,string_output_set (sov,g_strdup_printf ("%f" , *obj)); }qapi/string-output-visitor.c static void print_type_number(Visitor *v, const char *name, double *obj, · line 279
Quoted 10 lines
qapi/string-output-visitor.c +10
-0+static void start_struct (Visitor *v,const char *name,void **obj,size_t size, +Error **errp) +{ +error_setg (errp,"struct type not implemented" ); +} + +static void end_struct (Visitor *v,void **obj) +{ +} +This is just one of the several things this visitor doesn't implement. See the comment in
string-output-visitor.h.Quoted 8 lines
Quoted 5 lines
String input visitor and options visitor have similar holes; see the comments in
string-input-visitor.handopts-visitor.h.Should we change all of them together to report errors instead of crash? With common "error out because this isn't implemented" methods?
In that case wouldn't it be best to change visit_start_struct/visit_end_struct to do the check (Like
visit_check_structdoes).In my opinion.
Quoted 8 lines
if (v->foo) { v->foo(...); } else { ... default action ... }is an anti-pattern. Wrap the default action in a default method, and put that in the function pointer.
I've got some sympathy to that, but with the way our visitors are built that's a pain.
Lets say you add a new
eat_structmethod, and aeat_struct_defaultimplementation, now you have to go around and fix all the visitor implementations to initialise
theireat_structmember toeat_struct_default. Of course you'll forget some
and then we'll end up segging when you fall down the NULL pointer.Now, if our visitors had nice shared constructor functions that wouldn't be a problem, and you wouldn't need most of the
visit_wrapper functions;
but they don't, so the if (v->foo) { ... } else { error; } is the
current cleanest we can do.Quoted 5 lines
Quoted 2 lines
Well, it's the cleanest we can do as long as we constrain ourselves not to do much :)
Yes, although I hate to turn a patchset for a tiny feature into a fix-all-the-broken-stuff set!
I know the feeling...
I'd love to accommodate you, but I'm afraid the work is too incomplete in its current state. The string output visitor doesn't implement a number of things besides structs. To convince me that your qom-get won't crash because of that, you'd have to show that these other things cannot happen with qom-get. Implementing the missing parts instead would probably be easier. And then one of the general solutions discussed below would hardly be more work, for more value.
Quoted 25 lines
Quoted 24 lines
We currently have seven visitors. Every single one defines a
FOO_visitor_new()function that basically looks like this:Visitor *FOO_visitor_new(... whatever ...) { FOOVisitor v = g_malloc0(sizeof(*v)); v->visitor.type = ... ... initialize more of v->visitor ... ... initialize other members of *v, if any ... return &v->visitor; }I grant you that putting sensible defaults into
v->visitorby initializing them correctly in all theFOO_visitor_new()functions is a bit of pain. Not much pain; there are only seven. Anyway, there are several obvious ways to do this without pain:(1) Have a visitor core function to set the defaults, call it first.
(2) Replace
g_malloc0()by a visitor core function that additionally sets the defaults. Basically fusingg_malloc0()into (1)'s function.
Quoted 7 lines
Quoted 1 line
That's my preferred way of doing it, chaining constructors.
It's a fine way of doing it when you only ever create the things in one way. Here, with
g_malloc0().Would you like to wait for the Dan's visitor work? Perhaps the problem goes away there...
Will it ?
Dave
Quoted 8 lines
Quoted 8 lines
Dave
Quoted 4 lines
(3) Have a visitor core function that replaces null methods by defaults, and call it last. This function can also check you filled out in the mandatory bits. Have it return the visitor, so you can make it a tail call: return
visitor_check(&v->visitor).--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
PATCH 2/2 qom: Implement qom-get HMP command
In reply to Dr. David Alan Gilbert (git)From: "Dr. David Alan Gilbert" <[email protected]>
Reimplement it based on qmp_qom_get() to avoid converting QObjects back to strings.
Slight fix for bit-rot:
--- hmp-commands.hx | 13 +++++++++++++ hmp.c | 23 +++++++++++++++++++++++ hmp.h | 1 + 3 files changed, 37 insertions(+)
hmp-commands.hx +13 -0
@@ -1736,6 +1736,19 @@ Print QOM properties of object at location @var{path} ETEXI { + .name = "qom-get", + .args_type = "path:s,property:s", + .params = "path property", + .help = "print QOM property", + .mhandler.cmd = hmp_qom_get, + }, + +STEXI +@item qom-get @var{path} @var{property} +Print QOM property @var{property} of object at location @var{path} +ETEXI + + { .name = "qom-set", .args_type = "path:s,property:s,value:s", .params = "path property value",
hmp.c +23 -0
@@ -2064,6 +2064,29 @@ void hmp_qom_list(Monitor *mon, const QDict *qdict)hmp_handle_error (mon, &err); } +void hmp_qom_get (Monitor *mon,const QDict *qdict) +{ +const char *path =qdict_get_str (qdict,"path" ); +const char *property =qdict_get_str (qdict,"property" ); +Error *err =NULL ; +Object *obj; +char *value; + + obj =object_resolve_path (path,NULL ); +if (obj ==NULL ) { +error_set (&err,ERROR_CLASS_DEVICE_NOT_FOUND , +"Device '%s' not found" , path); +hmp_handle_error (mon, &err); +return ; + } + value =object_property_print (obj, property, true, &err); +if (err ==NULL ) { +monitor_printf (mon,"%s\n" , value); +g_free (value); + } +hmp_handle_error (mon, &err); +} +void hmp_qom_set (Monitor *mon,const QDict *qdict) {const char *path =qdict_get_str (qdict,"path" );
hmp.h +1 -0
@@ -103,6 +103,7 @@ void hmp_object_del(Monitor *mon, const QDict *qdict);void hmp_info_memdev (Monitor *mon,const QDict *qdict);void hmp_info_memory_devices (Monitor *mon,const QDict *qdict);void hmp_qom_list (Monitor *mon,const QDict *qdict); +void hmp_qom_get (Monitor *mon,const QDict *qdict);void hmp_qom_set (Monitor *mon,const QDict *qdict);void object_add_completion (ReadLineState *rs,int nb_args,const char *str);void object_del_completion (ReadLineState *rs,int nb_args,const char *str);
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH 2/2] qom: Implement qom-get HMP command
Quoted 4 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
Reimplement it based on
qmp_qom_get()to avoid converting QObjects back to strings.
It's not using qmp_qom_get(), though. That's a sign our abstractions aren't quite right. HMP command handlers should be implemented as mostly trivial wrappers around the QMP handlers, or the two handlers should be mostly trivial wrappers around a common helper function. For a more detailed explanation, see below.
Hmm, existing hmp_qom_set() has the same issue. I'm not demanding you clean this up.
Quoted 19 lines
Inspired-by Paolo Bonzini <[email protected]>Signed-off-by Andreas Färber <[email protected]>Slight fix for bit-rot:
Signed-off-by Dr. David Alan Gilbert <[email protected]>--- hmp-commands.hx | 13 +++++++++++++ hmp.c | 23 +++++++++++++++++++++++ hmp.h | 1 + 3 files changed, 37 insertions(+)hmp-commands.hx +0
-0@@ -1736,6 +1736,19 @@ Print QOM properties of object at location @var{path} ETEXI {
hmp-commands.hx Print QOM properties of object at location @var{path} · line 1748
Quoted 10 lines
hmp-commands.hx +10
-0+ .name = "qom-get", + .args_type = "path:s,property:s", + .params = "path property", + .help = "print QOM property", + .mhandler.cmd = hmp_qom_get, + }, + +STEXI +@item qom-get @var{path} @var{property} +Print QOM property @var{property} of object at location @var{path}
This is a bit terse, but existing qom-list and qom-set are no less terse. The QAPI schema has more detail, perhaps we can adapt it for the manual. Not a blocker for me.
Quoted 27 lines
hmp-commands.hx +3
-0+ETEXI + + { .name = "qom-set", .args_type = "path:s,property:s,value:s", .params = "path property value",hmp.c +13
-0@@ -2064,6 +2064,29 @@ void hmp_qom_list(Monitor *mon, const QDict *qdict)hmp_handle_error (mon, &err); } +void hmp_qom_get (Monitor *mon,const QDict *qdict) +{ +const char *path =qdict_get_str (qdict,"path" ); +const char *property =qdict_get_str (qdict,"property" ); +Error *err =NULL ; +Object *obj; +char *value; + + obj =object_resolve_path (path,NULL ); +if (obj ==NULL ) { +error_set (&err,ERROR_CLASS_DEVICE_NOT_FOUND , +"Device '%s' not found" , path); +hmp_handle_error (mon, &err);
hmp.c void hmp_qom_list(Monitor *mon, const QDict *qdict) · line 2089
Quoted 10 lines
hmp.c +10
-0+return ; + } + value =object_property_print (obj, property, true, &err); +if (err ==NULL ) { +monitor_printf (mon,"%s\n" , value); +g_free (value); + } +hmp_handle_error (mon, &err); +} +
Compare:
QObject *qmp_qom_get(const char *path, const char *property, Error **errp)
{
Object *obj; obj = object_resolve_path(path, NULL);
if (!obj) {
error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
"Device '%s' not found", path);
return NULL;
}
return object_property_get_qobject(obj, property, errp);}
The missing piece seems to be a function that prints the result of object_property_get_qobject(). Since converting to QObject just for printing is stupid, a common helper function seems more appropriate. qmp_qom_get() would pass it the QMP output visitor to get a QObject, and hmp_qom_get() would pass it the string output visitor to get a string.
Quoted 15 lines
hmp.c +0
-0void hmp_qom_set (Monitor *mon,const QDict *qdict) {const char *path =qdict_get_str (qdict,"path" );hmp.h +1
-0@@ -103,6 +103,7 @@ void hmp_object_del(Monitor *mon, const QDict *qdict);void hmp_info_memdev (Monitor *mon,const QDict *qdict);void hmp_info_memory_devices (Monitor *mon,const QDict *qdict);void hmp_qom_list (Monitor *mon,const QDict *qdict); +void hmp_qom_get (Monitor *mon,const QDict *qdict);void hmp_qom_set (Monitor *mon,const QDict *qdict);void object_add_completion (ReadLineState *rs,int nb_args,const char *str);void object_del_completion (ReadLineState *rs,int nb_args,const char *str);
Quoted 9 lines · Dr. David Alan Gilbert (git)
(qemu) qom-get /backend/console[0]/device/vga.rom[0] size 65536 (
0x10000)(qemu) qom-get /machine smm
"auto"(qemu) qom-get /machine rtc-time
struct type not implemented
Looks nice. Perhaps instead of using the "human" interface we could just print it as JSON and avoid the error.
Paolo
Quoted 7 lines · * Paolo Bonzini ([email protected]) wrote:
Quoted 4 lines · Dr. David Alan Gilbert (git)
(qemu) qom-get /backend/console[0]/device/vga.rom[0] size 65536 (
0x10000)
Quoted 8 lines
Quoted 5 lines
(qemu) qom-get /machine smm
"auto"(qemu) qom-get /machine rtc-time
struct type not implementedLooks nice. Perhaps instead of using the "human" interface we could just print it as JSON and avoid the error.
I can't see a sane place to glue a fallback to the JSON code in; or do you mean use the JSON output even in the simple case?
What's really needed is for the string-output-visitor to be forcibly reworked for proper nesting, but that's a bit of work.
Dave
Quoted 2 lines
Paolo
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Quoted 11 lines · Dr. David Alan Gilbert
Quoted 10 lines · * Paolo Bonzini ([email protected]) wrote:
Quoted 7 lines · Dr. David Alan Gilbert (git)
(qemu) qom-get /backend/console[0]/device/vga.rom[0] size 65536 (
0x10000)(qemu) qom-get /machine smm
"auto"
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
(qemu) qom-get /machine rtc-time
struct type not implementedLooks nice. Perhaps instead of using the "human" interface we could just print it as JSON and avoid the error.
I can't see a sane place to glue a fallback to the JSON code in; or do you mean use the JSON output even in the simple case?
Yeah. I think it makes sense for a low level command such as qom-get. All that you lose is the automatic hex conversion in the first example.
Paolo
Quoted 17 lines · * Paolo Bonzini ([email protected]) wrote:
Quoted 14 lines · Dr. David Alan Gilbert
Quoted 13 lines · * Paolo Bonzini ([email protected]) wrote:
Quoted 9 lines · Dr. David Alan Gilbert (git)
(qemu) qom-get /backend/console[0]/device/vga.rom[0] size 65536 (
0x10000)(qemu) qom-get /machine smm
"auto"(qemu) qom-get /machine rtc-time
struct type not implemented
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Looks nice. Perhaps instead of using the "human" interface we could just print it as JSON and avoid the error.
I can't see a sane place to glue a fallback to the JSON code in; or do you mean use the JSON output even in the simple case?
Yeah. I think it makes sense for a low level command such as qom-get. All that you lose is the automatic hex conversion in the first example.
Hmm yes, it does - v2 coming up.
Dave
Quoted 2 lines
Paolo
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK